1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     Classes for wxWizard and etc.
 
   7 // Created:     16-Aug-2002
 
   9 // Copyright:   (c) 2002 by Total Control Software
 
  10 // Licence:     wxWindows license
 
  11 /////////////////////////////////////////////////////////////////////////////
 
  14 "`Wizard` is a dialog class that guides the user through a sequence of steps,
 
  18 %module(package="wx", docstring=DOCSTRING) wizard
 
  21 #include "wx/wxPython/wxPython.h"
 
  22 #include "wx/wxPython/pyclasses.h"
 
  23 #include "wx/wxPython/printfw.h"
 
  25 #include <wx/wizard.h>
 
  29 //----------------------------------------------------------------------
 
  32 %pythoncode { wx = _core }
 
  33 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
 
  35 %include _wizard_rename.i
 
  37 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
 
  39 //----------------------------------------------------------------------
 
  42     wxWIZARD_EX_HELPBUTTON,
 
  45 %constant wxEventType wxEVT_WIZARD_PAGE_CHANGED;
 
  46 %constant wxEventType wxEVT_WIZARD_PAGE_CHANGING;
 
  47 %constant wxEventType wxEVT_WIZARD_CANCEL;
 
  48 %constant wxEventType wxEVT_WIZARD_HELP;
 
  49 %constant wxEventType wxEVT_WIZARD_FINISHED;
 
  54 EVT_WIZARD_PAGE_CHANGED  = wx.PyEventBinder( wxEVT_WIZARD_PAGE_CHANGED, 1)
 
  55 EVT_WIZARD_PAGE_CHANGING = wx.PyEventBinder( wxEVT_WIZARD_PAGE_CHANGING, 1)
 
  56 EVT_WIZARD_CANCEL        = wx.PyEventBinder( wxEVT_WIZARD_CANCEL, 1)
 
  57 EVT_WIZARD_HELP          = wx.PyEventBinder( wxEVT_WIZARD_HELP, 1)
 
  58 EVT_WIZARD_FINISHED      = wx.PyEventBinder( wxEVT_WIZARD_FINISHED, 1)
 
  61 //----------------------------------------------------------------------
 
  63 class wxWizardEvent : public wxNotifyEvent
 
  66     wxWizardEvent(wxEventType type = wxEVT_NULL,
 
  68                   bool direction = true,
 
  69                   wxWizardPage* page = NULL);
 
  71     // for EVT_WIZARD_PAGE_CHANGING, return True if we're going forward or
 
  72     // False otherwise and for EVT_WIZARD_PAGE_CHANGED return True if we came
 
  73     // from the previous page and False if we returned from the next one
 
  74     // (this function doesn't make sense for CANCEL events)
 
  75     bool GetDirection() const { return m_direction; }
 
  77     wxWizardPage*   GetPage() const { return m_page; }
 
  81 //----------------------------------------------------------------------
 
  83 // wxWizardPage is one of the wizards screen: it must know what are the
 
  84 // following and preceding pages (which may be NULL for the first/last page).
 
  86 // Other than GetNext/Prev() functions, wxWizardPage is just a panel and may be
 
  87 // used as such (i.e. controls may be placed directly on it &c).
 
  88 MustHaveApp(wxWizardPage);
 
  89 class wxWizardPage : public wxPanel
 
  92 //     // ctor accepts an optional bitmap which will be used for this page instead
 
  93 //     // of the default one for this wizard (should be of the same size). Notice
 
  94 //     // that no other parameters are needed because the wizard will resize and
 
  95 //     // reposition the page anyhow
 
  96 //     wxWizardPage(wxWizard *parent,
 
  97 //                  const wxBitmap& bitmap = wxNullBitmap,
 
  98 //                  const char* resource = NULL);
 
  99 //     %RenameCtor(PreWizardPage, wxWizardPage());
 
 102         bool Create(wxWizard *parent,
 
 103                     const wxBitmap& bitmap = wxNullBitmap,
 
 104                     const wxString& resource = wxPyEmptyString) {
 
 106             if (resource.Length())
 
 107                 res = (wxChar*)resource.c_str();
 
 108             return self->Create(parent, bitmap, res);
 
 113     // these functions are used by the wizard to show another page when the
 
 114     // user chooses "Back" or "Next" button
 
 115     virtual wxWizardPage *GetPrev() const;
 
 116     virtual wxWizardPage *GetNext() const;
 
 118     // default GetBitmap() will just return m_bitmap which is ok in 99% of
 
 119     // cases - override this method if you want to create the bitmap to be used
 
 120     // dynamically or to do something even more fancy. It's ok to return
 
 121     // wxNullBitmap from here - the default one will be used then.
 
 122     virtual wxBitmap GetBitmap() const;
 
 127 %{  // C++ Version of a Python aware class
 
 128 class wxPyWizardPage : public wxWizardPage {
 
 129     DECLARE_ABSTRACT_CLASS(wxPyWizardPage)
 
 131     wxPyWizardPage() : wxWizardPage() {}
 
 132     wxPyWizardPage(wxWizard *parent,
 
 133                    const wxBitmap& bitmap = wxNullBitmap,
 
 134                    const wxChar* resource = NULL)
 
 135         : wxWizardPage(parent, bitmap, resource) {}
 
 137     DEC_PYCALLBACK_WIZPG__pure(GetPrev);
 
 138     DEC_PYCALLBACK_WIZPG__pure(GetNext);
 
 139     DEC_PYCALLBACK_BITMAP__pure(GetBitmap);
 
 141     DEC_PYCALLBACK_VOID_INT4(DoMoveWindow);
 
 142     DEC_PYCALLBACK_VOID_INT5(DoSetSize);
 
 143     DEC_PYCALLBACK_VOID_INTINT(DoSetClientSize);
 
 144     DEC_PYCALLBACK_VOID_INTINT(DoSetVirtualSize);
 
 146     DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetSize);
 
 147     DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetClientSize);
 
 148     DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetPosition);
 
 150     DEC_PYCALLBACK_SIZE_const(DoGetVirtualSize);
 
 151     DEC_PYCALLBACK_SIZE_const(DoGetBestSize);
 
 153     DEC_PYCALLBACK__(InitDialog);
 
 154     DEC_PYCALLBACK_BOOL_(TransferDataFromWindow);
 
 155     DEC_PYCALLBACK_BOOL_(TransferDataToWindow);
 
 156     DEC_PYCALLBACK_BOOL_(Validate);
 
 158     DEC_PYCALLBACK_BOOL_const(AcceptsFocus);
 
 159     DEC_PYCALLBACK_BOOL_const(AcceptsFocusFromKeyboard);
 
 160     DEC_PYCALLBACK_SIZE_const(GetMaxSize);
 
 162     DEC_PYCALLBACK_VOID_WXWINBASE(AddChild);
 
 163     DEC_PYCALLBACK_VOID_WXWINBASE(RemoveChild);
 
 169 IMPLEMENT_ABSTRACT_CLASS(wxPyWizardPage, wxWizardPage);
 
 171 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetPrev);
 
 172 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetNext);
 
 173 IMP_PYCALLBACK_BITMAP__pure(wxPyWizardPage, wxWizardPage, GetBitmap);
 
 175 IMP_PYCALLBACK_VOID_INT4(wxPyWizardPage, wxWizardPage, DoMoveWindow);
 
 176 IMP_PYCALLBACK_VOID_INT5(wxPyWizardPage, wxWizardPage, DoSetSize);
 
 177 IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetClientSize);
 
 178 IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetVirtualSize);
 
 180 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetSize);
 
 181 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetClientSize);
 
 182 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetPosition);
 
 184 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetVirtualSize);
 
 185 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetBestSize);
 
 187 IMP_PYCALLBACK__(wxPyWizardPage, wxWizardPage, InitDialog);
 
 188 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataFromWindow);
 
 189 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataToWindow);
 
 190 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, Validate);
 
 192 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocus);
 
 193 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocusFromKeyboard);
 
 194 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, GetMaxSize);
 
 196 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, AddChild);
 
 197 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, RemoveChild);
 
 203 MustHaveApp(wxPyWizardPage);
 
 205 class wxPyWizardPage : public wxWizardPage {
 
 208     %pythonAppend wxPyWizardPage   "self._setCallbackInfo(self, PyWizardPage);self._setOORInfo(self)"
 
 209     %pythonAppend wxPyWizardPage() ""
 
 210     %typemap(out) wxPyWizardPage*;    // turn off this typemap
 
 212     // ctor accepts an optional bitmap which will be used for this page instead
 
 213     // of the default one for this wizard (should be of the same size). Notice
 
 214     // that no other parameters are needed because the wizard will resize and
 
 215     // reposition the page anyhow
 
 217         wxPyWizardPage(wxWizard *parent,
 
 218                        const wxBitmap* bitmap = &wxNullBitmap,
 
 219                        const wxString* resource = &wxPyEmptyString) {
 
 221             if (resource->Length())
 
 222                 res = (wxChar*)resource->c_str();
 
 223             return new wxPyWizardPage(parent, *bitmap, res);
 
 227     %RenameCtor(PrePyWizardPage, wxPyWizardPage());
 
 229     // Turn it back on again
 
 230     %typemap(out) wxPyWizardPage* { $result = wxPyMake_wxObject($1, $owner); }
 
 233         bool Create(wxWizard *parent,
 
 234                     const wxBitmap& bitmap = wxNullBitmap,
 
 235                     const wxString& resource = wxPyEmptyString) {
 
 237             if (resource.Length())
 
 238                 res = (wxChar*)resource.c_str();
 
 239             return self->Create(parent, bitmap, res);
 
 243     void _setCallbackInfo(PyObject* self, PyObject* _class);
 
 245     void base_DoMoveWindow(int x, int y, int width, int height);
 
 246     void base_DoSetSize(int x, int y, int width, int height,
 
 247                         int sizeFlags = wxSIZE_AUTO);
 
 248     void base_DoSetClientSize(int width, int height);
 
 249     void base_DoSetVirtualSize( int x, int y );
 
 252         void, base_DoGetSize( int *OUTPUT, int *OUTPUT ) const,
 
 253         "base_DoGetSize() -> (width, height)");
 
 255         void, base_DoGetClientSize( int *OUTPUT, int *OUTPUT ) const,
 
 256         "base_DoGetClientSize() -> (width, height)");
 
 258         void, base_DoGetPosition( int *OUTPUT, int *OUTPUT ) const,
 
 259         "base_DoGetPosition() -> (x,y)");
 
 261     wxSize base_DoGetVirtualSize() const;
 
 262     wxSize base_DoGetBestSize() const;
 
 264     void base_InitDialog();
 
 265     bool base_TransferDataToWindow();
 
 266     bool base_TransferDataFromWindow();
 
 267     bool base_Validate();
 
 269     bool base_AcceptsFocus() const;
 
 270     bool base_AcceptsFocusFromKeyboard() const;
 
 271     wxSize base_GetMaxSize() const;
 
 273     void base_AddChild(wxWindow* child);
 
 274     void base_RemoveChild(wxWindow* child);
 
 277 //----------------------------------------------------------------------
 
 280 // wxWizardPageSimple just returns the pointers given to the ctor and is useful
 
 281 // to create a simple wizard where the order of pages never changes.
 
 283 // OTOH, it is also possible to dynamicly decide which page to return (i.e.
 
 284 // depending on the user's choices) as the wizard sample shows - in order to do
 
 285 // this, you must derive from wxWizardPage directly.
 
 286 MustHaveApp(wxWizardPageSimple);
 
 287 class wxWizardPageSimple : public wxWizardPage
 
 291     %pythonAppend wxWizardPageSimple   "self._setOORInfo(self)"
 
 292     %pythonAppend wxWizardPageSimple() ""
 
 294     // ctor takes the previous and next pages
 
 295     wxWizardPageSimple(wxWizard *parent,
 
 296                        wxWizardPage *prev = NULL,
 
 297                        wxWizardPage *next = NULL,
 
 298                        const wxBitmap& bitmap = wxNullBitmap,
 
 299                        const wxChar* resource = NULL);
 
 300     %RenameCtor(PreWizardPageSimple, wxWizardPageSimple());
 
 302     bool Create(wxWizard *parent = NULL,
 
 303                 wxWizardPage *prev = NULL,
 
 304                 wxWizardPage *next = NULL,
 
 305                 const wxBitmap& bitmap = wxNullBitmap,
 
 306                 const wxChar* resource = NULL);
 
 308     // the pointers may be also set later - but before starting the wizard
 
 309     void SetPrev(wxWizardPage *prev);
 
 310     void SetNext(wxWizardPage *next);
 
 312     // a convenience function to make the pages follow each other
 
 313     static void Chain(wxWizardPageSimple *first, wxWizardPageSimple *second);
 
 317 //----------------------------------------------------------------------
 
 319 MustHaveApp(wxWizard);
 
 321 class  wxWizard : public wxDialog
 
 324     %pythonAppend wxWizard   "self._setOORInfo(self)"
 
 325     %pythonAppend wxWizard() ""
 
 328     wxWizard(wxWindow *parent,
 
 330              const wxString& title = wxPyEmptyString,
 
 331              const wxBitmap& bitmap = wxNullBitmap,
 
 332              const wxPoint& pos = wxDefaultPosition,
 
 333              long style = wxDEFAULT_DIALOG_STYLE);
 
 334     %RenameCtor(PreWizard, wxWizard());
 
 336     bool Create(wxWindow *parent,
 
 338              const wxString& title = wxPyEmptyString,
 
 339              const wxBitmap& bitmap = wxNullBitmap,
 
 340              const wxPoint& pos = wxDefaultPosition);
 
 345     // executes the wizard starting from the given page, returns True if it was
 
 346     // successfully finished, False if user cancelled it
 
 347     virtual bool RunWizard(wxWizardPage *firstPage);
 
 349     // get the current page (NULL if RunWizard() isn't running)
 
 350     virtual wxWizardPage *GetCurrentPage() const;
 
 352     // set the min size which should be available for the pages: a
 
 353     // wizard will take into account the size of the bitmap (if any)
 
 354     // itself and will never be less than some predefined fixed size
 
 355     virtual void SetPageSize(const wxSize& size);
 
 357     // get the size available for the page: the wizards are not resizeable, so
 
 358     // this size doesn't change
 
 359     virtual wxSize GetPageSize() const;
 
 361     // set the best size for the wizard, i.e. make it big enough to contain all
 
 362     // of the pages starting from the given one
 
 364     // this function may be called several times and possible with different
 
 365     // pages in which case it will only increase the page size if needed (this
 
 366     // may be useful if not all pages are accessible from the first one by
 
 368     virtual void FitToPage(const wxWizardPage *firstPage);
 
 370     // Adding pages to page area sizer enlarges wizard
 
 371     virtual wxSizer *GetPageAreaSizer() const;
 
 373     // Set border around page area. Default is 0 if you add at least one
 
 374     // page to GetPageAreaSizer and 5 if you don't.
 
 375     virtual void SetBorder(int border);
 
 377     // is the wizard running?
 
 378     bool IsRunning() const { return m_page != NULL; }
 
 380     // show the prev/next page, but call TransferDataFromWindow on the current
 
 381     // page first and return False without changing the page if
 
 382     // TransferDataFromWindow() returns False - otherwise, returns True
 
 383     bool ShowPage(wxWizardPage *page, bool goingForward = true);
 
 385     bool HasNextPage(wxWizardPage* page);
 
 386     bool HasPrevPage(wxWizardPage* page);
 
 390 //----------------------------------------------------------------------
 
 395 //---------------------------------------------------------------------------