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 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
 
  37 //----------------------------------------------------------------------
 
  40     wxWIZARD_EX_HELPBUTTON,
 
  43 %constant wxEventType wxEVT_WIZARD_PAGE_CHANGED;
 
  44 %constant wxEventType wxEVT_WIZARD_PAGE_CHANGING;
 
  45 %constant wxEventType wxEVT_WIZARD_CANCEL;
 
  46 %constant wxEventType wxEVT_WIZARD_HELP;
 
  47 %constant wxEventType wxEVT_WIZARD_FINISHED;
 
  52 EVT_WIZARD_PAGE_CHANGED  = wx.PyEventBinder( wxEVT_WIZARD_PAGE_CHANGED, 1)
 
  53 EVT_WIZARD_PAGE_CHANGING = wx.PyEventBinder( wxEVT_WIZARD_PAGE_CHANGING, 1)
 
  54 EVT_WIZARD_CANCEL        = wx.PyEventBinder( wxEVT_WIZARD_CANCEL, 1)
 
  55 EVT_WIZARD_HELP          = wx.PyEventBinder( wxEVT_WIZARD_HELP, 1)
 
  56 EVT_WIZARD_FINISHED      = wx.PyEventBinder( wxEVT_WIZARD_FINISHED, 1)
 
  59 //----------------------------------------------------------------------
 
  61 class wxWizardEvent : public wxNotifyEvent
 
  64     wxWizardEvent(wxEventType type = wxEVT_NULL,
 
  66                   bool direction = true,
 
  67                   wxWizardPage* page = NULL);
 
  69     // for EVT_WIZARD_PAGE_CHANGING, return True if we're going forward or
 
  70     // False otherwise and for EVT_WIZARD_PAGE_CHANGED return True if we came
 
  71     // from the previous page and False if we returned from the next one
 
  72     // (this function doesn't make sense for CANCEL events)
 
  73     bool GetDirection() const;
 
  75     wxWizardPage*   GetPage() const;
 
  77     %property(Direction, GetDirection, doc="See `GetDirection`");
 
  78     %property(Page, GetPage, doc="See `GetPage`");
 
  82 //----------------------------------------------------------------------
 
  84 // wxWizardPage is one of the wizards screen: it must know what are the
 
  85 // following and preceding pages (which may be NULL for the first/last page).
 
  87 // Other than GetNext/Prev() functions, wxWizardPage is just a panel and may be
 
  88 // used as such (i.e. controls may be placed directly on it &c).
 
  89 MustHaveApp(wxWizardPage);
 
  90 class wxWizardPage : public wxPanel
 
  93 //     // ctor accepts an optional bitmap which will be used for this page instead
 
  94 //     // of the default one for this wizard (should be of the same size). Notice
 
  95 //     // that no other parameters are needed because the wizard will resize and
 
  96 //     // reposition the page anyhow
 
  97 //     wxWizardPage(wxWizard *parent,
 
  98 //                  const wxBitmap& bitmap = wxNullBitmap,
 
  99 //                  const char* resource = NULL);
 
 100 //     %RenameCtor(PreWizardPage, wxWizardPage());
 
 103         bool Create(wxWizard *parent,
 
 104                     const wxBitmap& bitmap = wxNullBitmap,
 
 105                     const wxString& resource = wxPyEmptyString) {
 
 107             if (resource.length())
 
 108                 res = (wxChar*)resource.c_str();
 
 109             return self->Create(parent, bitmap, res);
 
 114     // these functions are used by the wizard to show another page when the
 
 115     // user chooses "Back" or "Next" button
 
 116     virtual wxWizardPage *GetPrev() const;
 
 117     virtual wxWizardPage *GetNext() const;
 
 119     // default GetBitmap() will just return m_bitmap which is ok in 99% of
 
 120     // cases - override this method if you want to create the bitmap to be used
 
 121     // dynamically or to do something even more fancy. It's ok to return
 
 122     // wxNullBitmap from here - the default one will be used then.
 
 123     virtual wxBitmap GetBitmap() const;
 
 125     %property(Bitmap, GetBitmap, doc="See `GetBitmap`");
 
 126     %property(Next, GetNext, doc="See `GetNext`");
 
 127     %property(Prev, GetPrev, doc="See `GetPrev`");
 
 132 %{  // C++ Version of a Python aware class
 
 133 class wxPyWizardPage : public wxWizardPage {
 
 134     DECLARE_ABSTRACT_CLASS(wxPyWizardPage)
 
 136     wxPyWizardPage() : wxWizardPage() {}
 
 137     wxPyWizardPage(wxWizard *parent,
 
 138                    const wxBitmap& bitmap = wxNullBitmap,
 
 139                    const wxChar* resource = NULL)
 
 140         : wxWizardPage(parent, bitmap, resource) {}
 
 142     DEC_PYCALLBACK_WIZPG__pure(GetPrev);
 
 143     DEC_PYCALLBACK_WIZPG__pure(GetNext);
 
 144     DEC_PYCALLBACK_BITMAP__pure(GetBitmap);
 
 146     DEC_PYCALLBACK_VOID_INT4(DoMoveWindow);
 
 147     DEC_PYCALLBACK_VOID_INT5(DoSetSize);
 
 148     DEC_PYCALLBACK_VOID_INTINT(DoSetClientSize);
 
 149     DEC_PYCALLBACK_VOID_INTINT(DoSetVirtualSize);
 
 151     DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetSize);
 
 152     DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetClientSize);
 
 153     DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetPosition);
 
 155     DEC_PYCALLBACK_SIZE_const(DoGetVirtualSize);
 
 156     DEC_PYCALLBACK_SIZE_const(DoGetBestSize);
 
 158     DEC_PYCALLBACK__(InitDialog);
 
 159     DEC_PYCALLBACK_BOOL_(TransferDataFromWindow);
 
 160     DEC_PYCALLBACK_BOOL_(TransferDataToWindow);
 
 161     DEC_PYCALLBACK_BOOL_(Validate);
 
 163     DEC_PYCALLBACK_BOOL_const(AcceptsFocus);
 
 164     DEC_PYCALLBACK_BOOL_const(AcceptsFocusFromKeyboard);
 
 165     DEC_PYCALLBACK_SIZE_const(GetMaxSize);
 
 167     DEC_PYCALLBACK_VOID_WXWINBASE(AddChild);
 
 168     DEC_PYCALLBACK_VOID_WXWINBASE(RemoveChild);
 
 174 IMPLEMENT_ABSTRACT_CLASS(wxPyWizardPage, wxWizardPage);
 
 176 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetPrev);
 
 177 IMP_PYCALLBACK_WIZPG__pure(wxPyWizardPage, wxWizardPage, GetNext);
 
 178 IMP_PYCALLBACK_BITMAP__pure(wxPyWizardPage, wxWizardPage, GetBitmap);
 
 180 IMP_PYCALLBACK_VOID_INT4(wxPyWizardPage, wxWizardPage, DoMoveWindow);
 
 181 IMP_PYCALLBACK_VOID_INT5(wxPyWizardPage, wxWizardPage, DoSetSize);
 
 182 IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetClientSize);
 
 183 IMP_PYCALLBACK_VOID_INTINT(wxPyWizardPage, wxWizardPage, DoSetVirtualSize);
 
 185 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetSize);
 
 186 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetClientSize);
 
 187 IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWizardPage, wxWizardPage, DoGetPosition);
 
 189 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetVirtualSize);
 
 190 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, DoGetBestSize);
 
 192 IMP_PYCALLBACK__(wxPyWizardPage, wxWizardPage, InitDialog);
 
 193 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataFromWindow);
 
 194 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, TransferDataToWindow);
 
 195 IMP_PYCALLBACK_BOOL_(wxPyWizardPage, wxWizardPage, Validate);
 
 197 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocus);
 
 198 IMP_PYCALLBACK_BOOL_const(wxPyWizardPage, wxWizardPage, AcceptsFocusFromKeyboard);
 
 199 IMP_PYCALLBACK_SIZE_const(wxPyWizardPage, wxWizardPage, GetMaxSize);
 
 201 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, AddChild);
 
 202 IMP_PYCALLBACK_VOID_WXWINBASE(wxPyWizardPage, wxWizardPage, RemoveChild);
 
 208 MustHaveApp(wxPyWizardPage);
 
 210 class wxPyWizardPage : public wxWizardPage {
 
 213     %pythonAppend wxPyWizardPage   "self._setCallbackInfo(self, PyWizardPage);self._setOORInfo(self)"
 
 214     %pythonAppend wxPyWizardPage() ""
 
 215     %typemap(out) wxPyWizardPage*;    // turn off this typemap
 
 217     // ctor accepts an optional bitmap which will be used for this page instead
 
 218     // of the default one for this wizard (should be of the same size). Notice
 
 219     // that no other parameters are needed because the wizard will resize and
 
 220     // reposition the page anyhow
 
 222         wxPyWizardPage(wxWizard *parent,
 
 223                        const wxBitmap* bitmap = &wxNullBitmap,
 
 224                        const wxString* resource = &wxPyEmptyString) {
 
 226             if (resource->length())
 
 227                 res = (wxChar*)resource->c_str();
 
 228             return new wxPyWizardPage(parent, *bitmap, res);
 
 232     %RenameCtor(PrePyWizardPage, wxPyWizardPage());
 
 234     // Turn it back on again
 
 235     %typemap(out) wxPyWizardPage* { $result = wxPyMake_wxObject($1, $owner); }
 
 238         bool Create(wxWizard *parent,
 
 239                     const wxBitmap& bitmap = wxNullBitmap,
 
 240                     const wxString& resource = wxPyEmptyString) {
 
 242             if (resource.length())
 
 243                 res = (wxChar*)resource.c_str();
 
 244             return self->Create(parent, bitmap, res);
 
 248     void _setCallbackInfo(PyObject* self, PyObject* _class);
 
 250     void DoMoveWindow(int x, int y, int width, int height);
 
 251     void DoSetSize(int x, int y, int width, int height,
 
 252                         int sizeFlags = wxSIZE_AUTO);
 
 253     void DoSetClientSize(int width, int height);
 
 254     void DoSetVirtualSize( int x, int y );
 
 257         void, DoGetSize( int *OUTPUT, int *OUTPUT ) const,
 
 258         "DoGetSize() -> (width, height)");
 
 260         void, DoGetClientSize( int *OUTPUT, int *OUTPUT ) const,
 
 261         "DoGetClientSize() -> (width, height)");
 
 263         void, DoGetPosition( int *OUTPUT, int *OUTPUT ) const,
 
 264         "DoGetPosition() -> (x,y)");
 
 266     wxSize DoGetVirtualSize() const;
 
 267     wxSize DoGetBestSize() const;
 
 270     bool TransferDataToWindow();
 
 271     bool TransferDataFromWindow();
 
 274     bool AcceptsFocus() const;
 
 275     bool AcceptsFocusFromKeyboard() const;
 
 276     wxSize GetMaxSize() const;
 
 278     void AddChild(wxWindow* child);
 
 279     void RemoveChild(wxWindow* child);
 
 281     bool ShouldInheritColours() const;
 
 282     wxVisualAttributes GetDefaultAttributes();
 
 284     void OnInternalIdle();
 
 286     %MAKE_BASE_FUNC(PyWizardPage, DoMoveWindow);
 
 287     %MAKE_BASE_FUNC(PyWizardPage, DoSetSize);
 
 288     %MAKE_BASE_FUNC(PyWizardPage, DoSetClientSize);
 
 289     %MAKE_BASE_FUNC(PyWizardPage, DoSetVirtualSize);
 
 290     %MAKE_BASE_FUNC(PyWizardPage, DoGetSize);
 
 291     %MAKE_BASE_FUNC(PyWizardPage, DoGetClientSize);
 
 292     %MAKE_BASE_FUNC(PyWizardPage, DoGetPosition);
 
 293     %MAKE_BASE_FUNC(PyWizardPage, DoGetVirtualSize);
 
 294     %MAKE_BASE_FUNC(PyWizardPage, DoGetBestSize);
 
 295     %MAKE_BASE_FUNC(PyWizardPage, InitDialog);
 
 296     %MAKE_BASE_FUNC(PyWizardPage, TransferDataToWindow);
 
 297     %MAKE_BASE_FUNC(PyWizardPage, TransferDataFromWindow);
 
 298     %MAKE_BASE_FUNC(PyWizardPage, Validate);
 
 299     %MAKE_BASE_FUNC(PyWizardPage, AcceptsFocus);
 
 300     %MAKE_BASE_FUNC(PyWizardPage, AcceptsFocusFromKeyboard);
 
 301     %MAKE_BASE_FUNC(PyWizardPage, GetMaxSize);
 
 302     %MAKE_BASE_FUNC(PyWizardPage, AddChild);
 
 303     %MAKE_BASE_FUNC(PyWizardPage, RemoveChild);
 
 304     %MAKE_BASE_FUNC(PyWizardPage, ShouldInheritColours);
 
 305     %MAKE_BASE_FUNC(PyWizardPage, GetDefaultAttributes);
 
 306     %MAKE_BASE_FUNC(PyWizardPage, OnInternalIdle);
 
 310 //----------------------------------------------------------------------
 
 313 // wxWizardPageSimple just returns the pointers given to the ctor and is useful
 
 314 // to create a simple wizard where the order of pages never changes.
 
 316 // OTOH, it is also possible to dynamicly decide which page to return (i.e.
 
 317 // depending on the user's choices) as the wizard sample shows - in order to do
 
 318 // this, you must derive from wxWizardPage directly.
 
 319 MustHaveApp(wxWizardPageSimple);
 
 320 class wxWizardPageSimple : public wxWizardPage
 
 324     %pythonAppend wxWizardPageSimple   "self._setOORInfo(self)"
 
 325     %pythonAppend wxWizardPageSimple() ""
 
 327     // ctor takes the previous and next pages
 
 328     wxWizardPageSimple(wxWizard *parent,
 
 329                        wxWizardPage *prev = NULL,
 
 330                        wxWizardPage *next = NULL,
 
 331                        const wxBitmap& bitmap = wxNullBitmap,
 
 332                        const wxChar* resource = NULL);
 
 333     %RenameCtor(PreWizardPageSimple, wxWizardPageSimple());
 
 335     bool Create(wxWizard *parent = NULL,
 
 336                 wxWizardPage *prev = NULL,
 
 337                 wxWizardPage *next = NULL,
 
 338                 const wxBitmap& bitmap = wxNullBitmap,
 
 339                 const wxChar* resource = NULL);
 
 341     // the pointers may be also set later - but before starting the wizard
 
 342     void SetPrev(wxWizardPage *prev);
 
 343     void SetNext(wxWizardPage *next);
 
 345     // a convenience function to make the pages follow each other
 
 346     static void Chain(wxWizardPageSimple *first, wxWizardPageSimple *second);
 
 350 //----------------------------------------------------------------------
 
 352 MustHaveApp(wxWizard);
 
 354 class  wxWizard : public wxDialog
 
 357     %pythonAppend wxWizard   "self._setOORInfo(self)"
 
 358     %pythonAppend wxWizard() ""
 
 361     wxWizard(wxWindow *parent,
 
 363              const wxString& title = wxPyEmptyString,
 
 364              const wxBitmap& bitmap = wxNullBitmap,
 
 365              const wxPoint& pos = wxDefaultPosition,
 
 366              long style = wxDEFAULT_DIALOG_STYLE);
 
 367     %RenameCtor(PreWizard, wxWizard());
 
 369     bool Create(wxWindow *parent,
 
 371              const wxString& title = wxPyEmptyString,
 
 372              const wxBitmap& bitmap = wxNullBitmap,
 
 373              const wxPoint& pos = wxDefaultPosition);
 
 378     // executes the wizard starting from the given page, returns True if it was
 
 379     // successfully finished, False if user cancelled it
 
 380     virtual bool RunWizard(wxWizardPage *firstPage);
 
 382     // get the current page (NULL if RunWizard() isn't running)
 
 383     virtual wxWizardPage *GetCurrentPage() const;
 
 385     // set the min size which should be available for the pages: a
 
 386     // wizard will take into account the size of the bitmap (if any)
 
 387     // itself and will never be less than some predefined fixed size
 
 388     virtual void SetPageSize(const wxSize& size);
 
 390     // get the size available for the page: the wizards are not resizeable, so
 
 391     // this size doesn't change
 
 392     virtual wxSize GetPageSize() const;
 
 394     // set the best size for the wizard, i.e. make it big enough to contain all
 
 395     // of the pages starting from the given one
 
 397     // this function may be called several times and possible with different
 
 398     // pages in which case it will only increase the page size if needed (this
 
 399     // may be useful if not all pages are accessible from the first one by
 
 401     virtual void FitToPage(const wxWizardPage *firstPage);
 
 403     // Adding pages to page area sizer enlarges wizard
 
 404     virtual wxSizer *GetPageAreaSizer() const;
 
 406     // Set border around page area. Default is 0 if you add at least one
 
 407     // page to GetPageAreaSizer and 5 if you don't.
 
 408     virtual void SetBorder(int border);
 
 410     // is the wizard running?
 
 411     bool IsRunning() const;
 
 413     // show the prev/next page, but call TransferDataFromWindow on the current
 
 414     // page first and return False without changing the page if
 
 415     // TransferDataFromWindow() returns False - otherwise, returns True
 
 416     bool ShowPage(wxWizardPage *page, bool goingForward = true);
 
 418     bool HasNextPage(wxWizardPage* page);
 
 419     bool HasPrevPage(wxWizardPage* page);
 
 421     %property(CurrentPage, GetCurrentPage, doc="See `GetCurrentPage`");
 
 422     %property(PageAreaSizer, GetPageAreaSizer, doc="See `GetPageAreaSizer`");
 
 423     %property(PageSize, GetPageSize, SetPageSize, doc="See `GetPageSize` and `SetPageSize`");
 
 427 //----------------------------------------------------------------------
 
 432 //---------------------------------------------------------------------------