1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // wxFormBuilder - A Visual Dialog Editor for wxWidgets.
4 // Copyright (C) 2005 José Antonio Hurtado
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 //
20 // Written by
21 //   Andrea Zanellato - zanellato.andrea@gmail.com
22 //   based on original wizard.h include in wxWidgets source code
23 //
24 ///////////////////////////////////////////////////////////////////////////////
25 #ifndef __WXFB_WIZARD_H__
26 #define __WXFB_WIZARD_H__
27 
28 #include <wx/intl.h>
29 #include <wx/bitmap.h>
30 #include <wx/event.h>
31 #include <wx/image.h>
32 #include <wx/icon.h>
33 #include <wx/statbmp.h>
34 #include <wx/string.h>
35 #include <wx/gdicmn.h>
36 #include <wx/font.h>
37 #include <wx/colour.h>
38 #include <wx/settings.h>
39 #include <wx/sizer.h>
40 #include <wx/statline.h>
41 #include <wx/button.h>
42 #include <wx/panel.h>
43 #include <wx/dynarray.h>
44 #include <wx/wizard.h>
45 
46 class Wizard;
47 class WizardPageSimple;
48 class WizardEvent;
49 
50 WX_DEFINE_ARRAY_PTR( WizardPageSimple*, WizardPages );
51 
52 class WizardPageSimple : public wxPanel
53 {
54 public:
55     WizardPageSimple( Wizard *parent );
56     ~WizardPageSimple();
57 };
58 
59 class Wizard : public wxPanel
60 {
61 public:
62     Wizard( wxWindow *parent, wxWindowID id = wxID_ANY,
63             const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
64             long style = wxTAB_TRAVERSAL );
65     ~Wizard();
66 
GetPageSizer()67     wxBoxSizer* GetPageSizer()  { return m_sizerPage; }
68 //  WizardPageSimple *GetCurrentPage() { return m_page; }
69 
70     // set/get bitmap
71 //  const wxBitmap& GetBitmap() const { return m_bitmap; }
72     void SetBitmap( const wxBitmap& bitmap );
73 
74     void AddPage( WizardPageSimple* page );
GetPage(size_t index)75     WizardPageSimple *GetPage( size_t index ) { return m_pages.Item( index ); }
GetPageCount()76     size_t GetPageCount() { return m_pages.GetCount(); }
GetPageIndex(WizardPageSimple * wizpage)77     size_t GetPageIndex( WizardPageSimple *wizpage ) { return m_pages.Index( wizpage ); }
78     void SetSelection( size_t pageIndex );
ShowHelpButton(bool showhelp)79     void ShowHelpButton( bool showhelp ) { m_btnHelp->Show( showhelp ); }
80 
81 private:
82     void OnBackOrNext( wxCommandEvent& event );
83     void OnHelp( wxCommandEvent& event );
84     void OnCancel( wxCommandEvent& event );
85     void OnWizEvent( WizardEvent& event );
86 
87     wxBoxSizer       *m_sizerBmpAndPage; // Page area sizer will be inserted here with padding
88     wxBoxSizer       *m_sizerPage;       // Actual position and size of pages
89     wxStaticBitmap   *m_statbmp;         // the control for the bitmap
90     wxButton         *m_btnHelp;
91     wxButton         *m_btnPrev;         // the "<Back" button
92     wxButton         *m_btnNext;         // the "Next>" or "Finish" button
93     wxButton         *m_btnCancel;
94     WizardPageSimple *m_page;
95     wxBitmap          m_bitmap;          // the default bitmap to show
96     WizardPages       m_pages;
97 
98 //  DECLARE_EVENT_TABLE()
99 };
100 
101 // ----------------------------------------------------------------------------
102 // WizardEvent class represents an event generated by the wizard: this event
103 // is first sent to the page itself and, if not processed there, goes up the
104 // window hierarchy as usual
105 // ----------------------------------------------------------------------------
106 
107 class WizardEvent : public wxNotifyEvent
108 {
109 public:
110     WizardEvent( wxEventType type = wxEVT_NULL,
111                  int id = wxID_ANY,
112                  bool direction = true,
113                  WizardPageSimple *page = NULL );
114 
115     // for EVT_WXFB_WIZARD_PAGE_CHANGING, return true if we're going forward or
116     // false otherwise and for EVT_WXFB_WIZARD_PAGE_CHANGED return true if we came
117     // from the previous page and false if we returned from the next one
118     // (this function doesn't make sense for CANCEL events)
GetDirection()119     bool GetDirection() const { return m_direction; }
120 
GetPage()121     WizardPageSimple *GetPage() const { return m_page; }
122 
Clone()123     virtual wxEvent *Clone() const { return new WizardEvent( *this ); }
124 
125 private:
126     bool              m_direction;
127     WizardPageSimple *m_page;
128 };
129 
130 // ----------------------------------------------------------------------------
131 // macros for handling WizardEvents
132 // ----------------------------------------------------------------------------
133 #define wxFBDLLIMPEXP
134 
135 BEGIN_DECLARE_EVENT_TYPES()
136     DECLARE_EXPORTED_EVENT_TYPE( wxFBDLLIMPEXP, wxFB_EVT_WIZARD_PAGE_CHANGED, 900 );
137     DECLARE_EXPORTED_EVENT_TYPE( wxFBDLLIMPEXP, wxFB_EVT_WIZARD_PAGE_CHANGING, 901 );
138     DECLARE_EXPORTED_EVENT_TYPE( wxFBDLLIMPEXP, wxFB_EVT_WIZARD_CANCEL, 902 );
139     DECLARE_EXPORTED_EVENT_TYPE( wxFBDLLIMPEXP, wxFB_EVT_WIZARD_HELP, 903 );
140     DECLARE_EXPORTED_EVENT_TYPE( wxFBDLLIMPEXP, wxFB_EVT_WIZARD_FINISHED, 904 );
141 #if wxABI_VERSION >= 20811
142     DECLARE_EXPORTED_EVENT_TYPE( wxFBDLLIMPEXP, wxFB_EVT_WIZARD_PAGE_SHOWN, 905 );
143 #endif
144 END_DECLARE_EVENT_TYPES()
145 
146 typedef void ( wxEvtHandler::*WizardEventFunction )( WizardEvent& );
147 
148 #define WizardEventHandler( func ) \
149     (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent( WizardEventFunction, &func )
150 
151 #define wxFB__DECLARE_WIZARDEVT( evt, id, fn ) \
152     wx__DECLARE_EVT1( wxFB_EVT_WIZARD_ ## evt, id, WizardEventHandler( fn ) )
153 
154 // notifies that the page has just been changed (can't be vetoed)
155 #define EVT_WXFB_WIZARD_PAGE_CHANGED( id, fn ) wxFB__DECLARE_WIZARDEVT( PAGE_CHANGED, id, fn )
156 
157 // the user pressed "<Back" or "Next>" button and the page is going to be
158 // changed - unless the event handler vetoes the event
159 #define EVT_WXFB_WIZARD_PAGE_CHANGING( id, fn ) wxFB__DECLARE_WIZARDEVT( PAGE_CHANGING, id, fn )
160 
161 // the user pressed "Cancel" button and the wizard is going to be dismissed -
162 // unless the event handler vetoes the event
163 #define EVT_WXFB_WIZARD_CANCEL(id, fn) wxFB__DECLARE_WIZARDEVT(CANCEL, id, fn)
164 
165 // the user pressed "Finish" button and the wizard is going to be dismissed -
166 #define EVT_WXFB_WIZARD_FINISHED( id, fn ) wxFB__DECLARE_WIZARDEVT( FINISHED, id, fn )
167 
168 // the user pressed "Help" button
169 #define EVT_WXFB_WIZARD_HELP(id, fn) wxFB__DECLARE_WIZARDEVT( HELP, id, fn )
170 
171 // the page was just shown and laid out
172 #define EVT_WXFB_WIZARD_PAGE_SHOWN( id, fn ) wxFB__DECLARE_WIZARDEVT( PAGE_SHOWN, id, fn )
173 
174 #endif //__WXFB_WIZARD_H__
175