/* 
 * ©2009 Sun Microsystems, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#ifndef _MFORMS_WIZARD_H_
#define _MFORMS_WIZARD_H_

#include <mforms/base.h>
#include <vector>
#include <sigc++/sigc++.h>

namespace mforms {

  class Wizard;
  class View;

  struct MFORMS_EXPORT WizardImplPtrs
  {
    bool (__stdcall *create)(Wizard *self);
    void (__stdcall *set_title)(Wizard *self, const std::string &title);
    void (__stdcall *run_modal)(Wizard *self);
    void (__stdcall *close)(Wizard *self);

    void (__stdcall *flush_events)(Wizard *self);
    
    void (__stdcall *set_content)(Wizard *self, View *view);
    void (__stdcall *set_heading)(Wizard *self, const std::string &);
    void (__stdcall *set_step_list)(Wizard *self, const std::vector<std::string> &);
    void (__stdcall *set_allow_cancel)(Wizard *self, bool flag);
    void (__stdcall *set_allow_back)(Wizard *self, bool flag);
    void (__stdcall *set_allow_next)(Wizard *self, bool flag);
    void (__stdcall *set_show_extra)(Wizard *self, bool flag);
  
    void (__stdcall *set_extra_caption)(Wizard *self, const std::string &);
    void (__stdcall *set_next_caption)(Wizard *self, const std::string &);
  };


  class MFORMS_EXPORT Wizard : public Object
  {
    friend class ControlFactory;

    WizardImplPtrs *_wizard_impl;
    View *_content;

  public:
    Wizard();

    void flush_events();
    
    virtual void set_title(const std::string &title);
    virtual void run();
    virtual void close();
    
    //! set_content should place view as a wizard's current page.
    //! Note: When view is 0, then content should be removed
    virtual void set_content(View *view);
    void set_heading(const std::string &text);
    // 1st char of each step title must be . for executed tasks, * for current and - for not executed
    void set_step_list(const std::vector<std::string> &steps);
    void set_allow_cancel(bool flag);
    void set_allow_back(bool flag);
    void set_allow_next(bool flag);
    void set_show_extra(bool flag);
    void set_extra_caption(const std::string &caption);
    void set_next_caption(const std::string &caption= "");
    
    void set_cancel_handler(const sigc::slot<bool> &slot);
    sigc::signal<void> signal_next_clicked() { return _next_signal; }
    sigc::signal<void> signal_back_clicked() { return _back_signal; }
    sigc::signal<void> signal_extra_clicked() { return _extra_signal; }

  public:
    void back_clicked()
    {
      _back_signal.emit();
    }
    
    void next_clicked()
    {
      _next_signal.emit();
    }
    
    void extra_clicked()
    {
      _extra_signal.emit();
    }
    
    sigc::slot<bool> _cancel_slot;

  protected:
    sigc::signal<void> _back_signal;
    sigc::signal<void> _next_signal;
    sigc::signal<void> _extra_signal;
  };
};

#endif

