wizard.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wizard.h
  3. // Purpose: interface of wxWizardPage, wxWizardEvent,
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. // Extended style to specify a help button
  8. #define wxWIZARD_EX_HELPBUTTON 0x00000010
  9. // Bitmap placement flags
  10. #define wxWIZARD_VALIGN_TOP 0x01
  11. #define wxWIZARD_VALIGN_CENTRE 0x02
  12. #define wxWIZARD_VALIGN_BOTTOM 0x04
  13. #define wxWIZARD_HALIGN_LEFT 0x08
  14. #define wxWIZARD_HALIGN_CENTRE 0x10
  15. #define wxWIZARD_HALIGN_RIGHT 0x20
  16. #define wxWIZARD_TILE 0x40
  17. /**
  18. @class wxWizardPage
  19. wxWizardPage is one of the screens in wxWizard: it must know what are the
  20. following and preceding pages (which may be @NULL for the first/last page).
  21. Except for this extra knowledge, wxWizardPage is just a
  22. panel, so the controls may be placed directly on it in the usual way.
  23. This class allows the programmer to decide the order of pages in the wizard
  24. dynamically (during run-time) and so provides maximal flexibility.
  25. Usually, however, the order of pages is known in advance in which case
  26. wxWizardPageSimple class is enough and it is simpler to use.
  27. @section wizardpage_virtuals Virtual functions to override
  28. To use this class, you must override wxWizardPage::GetPrev() and
  29. wxWizardPage::GetNext() pure virtual functions (or you may use
  30. wxWizardPageSimple instead).
  31. wxWizardPage::GetBitmap() can also be overridden, but this should be very
  32. rarely needed.
  33. @library{wxadv}
  34. @category{miscwnd}
  35. @see wxWizard, @ref page_samples_wizard
  36. */
  37. class wxWizardPage : public wxPanel
  38. {
  39. public:
  40. /**
  41. Default constructor.
  42. */
  43. wxWizardPage();
  44. /**
  45. Constructor accepts an optional bitmap which will be used for this page
  46. instead of the default one for this wizard (note that all bitmaps used should
  47. be of the same size). Notice that no other parameters are needed because the
  48. wizard will resize and reposition the page anyhow.
  49. @param parent
  50. The parent wizard
  51. @param bitmap
  52. The page-specific bitmap if different from the global one
  53. */
  54. wxWizardPage(wxWizard* parent,
  55. const wxBitmap& bitmap = wxNullBitmap);
  56. /**
  57. Creates the wizard page.
  58. Must be called if the default constructor had been used to create the object.
  59. @param parent
  60. The parent wizard
  61. @param bitmap
  62. The page-specific bitmap if different from the global one
  63. */
  64. bool Create(wxWizard *parent,
  65. const wxBitmap& bitmap = wxNullBitmap);
  66. /**
  67. This method is called by wxWizard to get the bitmap to display alongside the page.
  68. By default, @c m_bitmap member variable which was set in the
  69. @ref wxWizardPage() constructor.
  70. If the bitmap was not explicitly set (i.e. if ::wxNullBitmap is returned),
  71. the default bitmap for the wizard should be used.
  72. The only cases when you would want to override this function is if the page
  73. bitmap depends dynamically on the user choices, i.e. almost never.
  74. */
  75. virtual wxBitmap GetBitmap() const;
  76. /**
  77. Get the page which should be shown when the user chooses the @c "Next"
  78. button: if @NULL is returned, this button will be disabled.
  79. The last page of the wizard will usually return @NULL from here, but
  80. the others will not.
  81. @see GetPrev()
  82. */
  83. virtual wxWizardPage* GetNext() const = 0;
  84. /**
  85. Get the page which should be shown when the user chooses the @c "Back"
  86. button: if @NULL is returned, this button will be disabled.
  87. The first page of the wizard will usually return @NULL from here, but
  88. the others will not.
  89. @see GetNext()
  90. */
  91. virtual wxWizardPage* GetPrev() const = 0;
  92. };
  93. /**
  94. @class wxWizardEvent
  95. wxWizardEvent class represents an event generated by the wxWizard: this event
  96. is first sent to the page itself and, if not processed there, goes up the
  97. window hierarchy as usual.
  98. @beginEventTable{wxWizardEvent}
  99. @event{EVT_WIZARD_PAGE_CHANGED(id, func)}
  100. The page has been just changed (this event cannot be vetoed).
  101. @event{EVT_WIZARD_PAGE_CHANGING(id, func)}
  102. The page is being changed (this event can be vetoed).
  103. @event{EVT_WIZARD_BEFORE_PAGE_CHANGED(id, func)}
  104. Called after Next is clicked but before GetNext is called. Unlike EVT_WIZARD_CHANGING,
  105. the handler for this function can change state that might affect the return value of
  106. GetNext. This event can be vetoed.
  107. @event{EVT_WIZARD_PAGE_SHOWN(id, func)}
  108. The page was shown and laid out (this event cannot be vetoed).
  109. @event{EVT_WIZARD_CANCEL(id, func)}
  110. The user attempted to cancel the wizard (this event may also be vetoed).
  111. @event{EVT_WIZARD_HELP(id, func)}
  112. The wizard help button was pressed.
  113. @event{EVT_WIZARD_FINISHED(id, func)}
  114. The wizard finished button was pressed.
  115. @endEventTable
  116. @library{wxadv}
  117. @category{events}
  118. @see wxWizard, @ref page_samples_wizard
  119. */
  120. class wxWizardEvent : public wxNotifyEvent
  121. {
  122. public:
  123. /**
  124. Constructor.
  125. It is not normally used by the user code as the objects of this
  126. type are constructed by wxWizard.
  127. */
  128. wxWizardEvent(wxEventType type = wxEVT_NULL, int id = wxID_ANY,
  129. bool direction = true, wxWizardPage* page = 0);
  130. /**
  131. Return the direction in which the page is changing: for
  132. @c EVT_WIZARD_PAGE_CHANGING, return @true if we're going forward or
  133. @false otherwise and for @c EVT_WIZARD_PAGE_CHANGED return @true if we
  134. came from the previous page and @false if we returned from the next one.
  135. */
  136. bool GetDirection() const;
  137. /**
  138. Returns the wxWizardPage which was active when this event was generated.
  139. */
  140. wxWizardPage* GetPage() const;
  141. };
  142. wxEventType wxEVT_WIZARD_PAGE_CHANGED;
  143. wxEventType wxEVT_WIZARD_PAGE_CHANGING;
  144. wxEventType wxEVT_WIZARD_CANCEL;
  145. wxEventType wxEVT_WIZARD_HELP;
  146. wxEventType wxEVT_WIZARD_FINISHED;
  147. wxEventType wxEVT_WIZARD_PAGE_SHOWN;
  148. wxEventType wxEVT_WIZARD_BEFORE_PAGE_CHANGED;
  149. /**
  150. @class wxWizardPageSimple
  151. wxWizardPageSimple is the simplest possible wxWizardPage implementation:
  152. it just returns the pointers given to its constructor from wxWizardPage::GetNext()
  153. and wxWizardPage::GetPrev() functions.
  154. This makes it very easy to use the objects of this class in the wizards where
  155. the pages order is known statically - on the other hand, if this is not the
  156. case you must derive your own class from wxWizardPage instead.
  157. @library{wxadv}
  158. @category{miscwnd}
  159. @see wxWizard, @ref page_samples_wizard
  160. */
  161. class wxWizardPageSimple : public wxWizardPage
  162. {
  163. public:
  164. /**
  165. Default constructor.
  166. */
  167. wxWizardPageSimple();
  168. /**
  169. Constructor takes the previous and next pages.
  170. They may be modified later by SetPrev() or SetNext().
  171. */
  172. wxWizardPageSimple(wxWizard* parent,
  173. wxWizardPage* prev = NULL,
  174. wxWizardPage* next = NULL,
  175. const wxBitmap& bitmap = wxNullBitmap);
  176. /**
  177. Creates the wizard page.
  178. Must be called if the default constructor had been used to create the object.
  179. */
  180. bool Create(wxWizard *parent = NULL,
  181. wxWizardPage *prev = NULL,
  182. wxWizardPage *next = NULL,
  183. const wxBitmap& bitmap = wxNullBitmap);
  184. /**
  185. A helper chaining this page with the next one.
  186. Notice that this method returns a reference to the next page, so the
  187. calls to it can, in turn, be chained:
  188. @code
  189. wxWizardPageSimple* firstPage = new FirstPage;
  190. (*firstPage).Chain(new SecondPage)
  191. .Chain(new ThirdPage)
  192. .Chain(new LastPage);
  193. @endcode
  194. This makes this method the simplest way to define the order of changes
  195. in fully static wizards, i.e. in those where the order doesn't depend
  196. on the choices made by the user in the wizard pages during run-time.
  197. @param next A non-@NULL pointer to the next page.
  198. @return Reference to @a next on which Chain() can be called again.
  199. @since 2.9.5
  200. */
  201. wxWizardPageSimple& Chain(wxWizardPageSimple* next);
  202. /**
  203. A convenience function to make the pages follow each other.
  204. Example:
  205. @code
  206. wxRadioboxPage *page3 = new wxRadioboxPage(wizard);
  207. wxValidationPage *page4 = new wxValidationPage(wizard);
  208. wxWizardPageSimple::Chain(page3, page4);
  209. @endcode
  210. */
  211. static void Chain(wxWizardPageSimple* first,
  212. wxWizardPageSimple* second);
  213. /**
  214. Sets the next page.
  215. */
  216. void SetNext(wxWizardPage* next);
  217. /**
  218. Sets the previous page.
  219. */
  220. void SetPrev(wxWizardPage* prev);
  221. };
  222. /**
  223. @class wxWizard
  224. wxWizard is the central class for implementing 'wizard-like' dialogs.
  225. These dialogs are mostly familiar to Windows users and are nothing other than a
  226. sequence of 'pages', each displayed inside a dialog which has the buttons to
  227. navigate to the next (and previous) pages.
  228. The wizards are typically used to decompose a complex dialog into several
  229. simple steps and are mainly useful to the novice users, hence it is important
  230. to keep them as simple as possible.
  231. To show a wizard dialog, you must first create an instance of the wxWizard class
  232. using either the non-default constructor or a default one followed by call to the
  233. wxWizard::Create function. Then you should add all pages you want the wizard to
  234. show and call wxWizard::RunWizard().
  235. Finally, don't forget to call @c "wizard->Destroy()", otherwise your application
  236. will hang on exit due to an undestroyed window.
  237. You can supply a bitmap to display on the left of the wizard, either for all pages
  238. or for individual pages. If you need to have the bitmap resize to the height of
  239. the wizard, call wxWizard::SetBitmapPlacement() and if necessary,
  240. wxWizard::SetBitmapBackgroundColour() and wxWizard::SetMinimumBitmapWidth().
  241. To make wizard pages scroll when the display is too small to fit the whole
  242. dialog, you can switch layout adaptation on globally with
  243. wxDialog::EnableLayoutAdaptation() or per dialog with wxDialog::SetLayoutAdaptationMode().
  244. For more about layout adaptation, see @ref overview_dialog_autoscrolling.
  245. @beginEventEmissionTable{wxWizardEvent}
  246. For some events, Veto() can be called to prevent the event from happening.
  247. @event{EVT_WIZARD_PAGE_CHANGED(id, func)}
  248. The page has just been changed (this event cannot be vetoed).
  249. @event{EVT_WIZARD_PAGE_CHANGING(id, func)}
  250. The page is being changed (this event can be vetoed).
  251. @event{EVT_WIZARD_BEFORE_PAGE_CHANGED(id, func)}
  252. Called after Next is clicked but before GetNext is called. Unlike EVT_WIZARD_CHANGING,
  253. the handler for this function can change state that might affect the return value of
  254. GetNext. This event can be vetoed.
  255. @event{EVT_WIZARD_PAGE_SHOWN(id, func)}
  256. The page was shown and laid out (this event cannot be vetoed).
  257. @event{EVT_WIZARD_CANCEL(id, func)}
  258. The user attempted to cancel the wizard (this event may also be vetoed).
  259. @event{EVT_WIZARD_HELP(id, func)}
  260. The wizard help button was pressed.
  261. @event{EVT_WIZARD_FINISHED(id, func)}
  262. The wizard finished button was pressed.
  263. @endEventTable
  264. @section wizard_extstyles Extended styles
  265. Use the wxWindow::SetExtraStyle() function to set the following style.
  266. You will need to use two-step construction (use the default constructor,
  267. call SetExtraStyle(), then call Create).
  268. @beginExtraStyleTable
  269. @style{wxWIZARD_EX_HELPBUTTON}
  270. Shows a Help button using wxID_HELP.
  271. @endExtraStyleTable
  272. See also wxDialog for other extended styles.
  273. @library{wxadv}
  274. @category{cmndlg}
  275. @see wxWizardEvent, wxWizardPage, @ref page_samples_wizard
  276. */
  277. class wxWizard : public wxDialog
  278. {
  279. public:
  280. /**
  281. Default constructor.
  282. Use this if you wish to derive from wxWizard and then call Create(),
  283. for example if you wish to set an extra style with wxWindow::SetExtraStyle()
  284. between the two calls.
  285. */
  286. wxWizard();
  287. /**
  288. Constructor which really creates the wizard -- if you use this constructor, you
  289. shouldn't call Create().
  290. Notice that unlike almost all other wxWidgets classes, there is no @e size
  291. parameter in the wxWizard constructor because the wizard will have a predefined
  292. default size by default.
  293. If you want to change this, you should use the GetPageAreaSizer() function.
  294. @param parent
  295. The parent window, may be @NULL.
  296. @param id
  297. The id of the dialog, will usually be just wxID_ANY.
  298. @param title
  299. The title of the dialog.
  300. @param bitmap
  301. The default bitmap used in the left side of the wizard. See also GetBitmap().
  302. @param pos
  303. The position of the dialog, it will be centered on the screen by default.
  304. @param style
  305. Window style is passed to wxDialog.
  306. */
  307. wxWizard(wxWindow* parent, int id = wxID_ANY,
  308. const wxString& title = wxEmptyString,
  309. const wxBitmap& bitmap = wxNullBitmap,
  310. const wxPoint& pos = wxDefaultPosition,
  311. long style = wxDEFAULT_DIALOG_STYLE);
  312. /**
  313. Creates the wizard dialog.
  314. Must be called if the default constructor had been used to create the object.
  315. Notice that unlike almost all other wxWidgets classes, there is no @e size
  316. parameter in the wxWizard constructor because the wizard will have a predefined
  317. default size by default.
  318. If you want to change this, you should use the GetPageAreaSizer() function.
  319. @param parent
  320. The parent window, may be @NULL.
  321. @param id
  322. The id of the dialog, will usually be just -1.
  323. @param title
  324. The title of the dialog.
  325. @param bitmap
  326. The default bitmap used in the left side of the wizard. See also GetBitmap().
  327. @param pos
  328. The position of the dialog, it will be centered on the screen by default.
  329. @param style
  330. Window style is passed to wxDialog.
  331. */
  332. bool Create(wxWindow* parent, int id = wxID_ANY,
  333. const wxString& title = wxEmptyString,
  334. const wxBitmap& bitmap = wxNullBitmap,
  335. const wxPoint& pos = wxDefaultPosition, long style = wxDEFAULT_DIALOG_STYLE);
  336. /**
  337. This method is obsolete, use GetPageAreaSizer() instead.
  338. Sets the page size to be big enough for all the pages accessible via the
  339. given @e firstPage, i.e. this page, its next page and so on.
  340. This method may be called more than once and it will only change the page size
  341. if the size required by the new page is bigger than the previously set one.
  342. This is useful if the decision about which pages to show is taken during
  343. run-time, as in this case, the wizard won't be able to get to all pages starting
  344. from a single one and you should call @e Fit separately for the others.
  345. */
  346. virtual void FitToPage(const wxWizardPage* firstPage);
  347. /**
  348. Returns the bitmap used for the wizard.
  349. */
  350. const wxBitmap& GetBitmap() const;
  351. /**
  352. Returns the colour that should be used to fill the area not taken up by the
  353. wizard or page bitmap, if a non-zero bitmap placement flag has been set.
  354. See also SetBitmapPlacement().
  355. */
  356. const wxColour& GetBitmapBackgroundColour() const;
  357. /**
  358. Returns the flags indicating how the wizard or page bitmap should be expanded
  359. and positioned to fit the page height. By default, placement is 0 (no expansion is done).
  360. See also SetBitmapPlacement() for the possible values.
  361. */
  362. int GetBitmapPlacement() const;
  363. /**
  364. Get the current page while the wizard is running.
  365. @NULL is returned if RunWizard() is not being executed now.
  366. */
  367. virtual wxWizardPage* GetCurrentPage() const;
  368. /**
  369. Returns the minimum width for the bitmap that will be constructed to contain
  370. the actual wizard or page bitmap if a non-zero bitmap placement flag has been set.
  371. See also SetBitmapPlacement().
  372. */
  373. int GetMinimumBitmapWidth() const;
  374. /**
  375. Returns pointer to page area sizer. The wizard is laid out using sizers and
  376. the page area sizer is the place-holder for the pages. All pages are resized
  377. before being shown to match the wizard page area.
  378. Page area sizer has a minimal size that is the maximum of several values.
  379. First, all pages (or other objects) added to the sizer. Second, all pages reachable
  380. by repeatedly applying wxWizardPage::GetNext() to any page inserted into the sizer.
  381. Third, the minimal size specified using SetPageSize() and FitToPage().
  382. Fourth, the total wizard height may be increased to accommodate the bitmap height.
  383. Fifth and finally, wizards are never smaller than some built-in minimal size to
  384. avoid wizards that are too small.
  385. The caller can use wxSizer::SetMinSize to enlarge it beyond the minimal size.
  386. If @c wxRESIZE_BORDER was passed to constructor, user can resize wizard and
  387. consequently the page area (but not make it smaller than the minimal size).
  388. It is recommended to add the first page to the page area sizer.
  389. For simple wizards, this will enlarge the wizard to fit the biggest page.
  390. For non-linear wizards, the first page of every separate chain should be added.
  391. Caller-specified size can be accomplished using wxSizer::SetMinSize().
  392. Adding pages to the page area sizer affects the default border width around page
  393. area that can be altered with SetBorder().
  394. */
  395. virtual wxSizer* GetPageAreaSizer() const;
  396. /**
  397. Returns the size available for the pages.
  398. */
  399. virtual wxSize GetPageSize() const;
  400. /**
  401. Return @true if this page is not the last one in the wizard.
  402. The base class version implements this by calling
  403. @ref wxWizardPage::GetNext "page->GetNext" but this could be
  404. undesirable if, for example, the pages are created on demand only.
  405. @see HasPrevPage()
  406. */
  407. virtual bool HasNextPage(wxWizardPage* page);
  408. /**
  409. Returns @true if this page is not the last one in the wizard.
  410. The base class version implements this by calling
  411. @ref wxWizardPage::GetPrev "page->GetPrev" but this could be
  412. undesirable if, for example, the pages are created on demand only.
  413. @see HasNextPage()
  414. */
  415. virtual bool HasPrevPage(wxWizardPage* page);
  416. /**
  417. Executes the wizard starting from the given page, returning @true if it was
  418. successfully finished or @false if user cancelled it.
  419. The @a firstPage cannot be @NULL.
  420. */
  421. virtual bool RunWizard(wxWizardPage* firstPage);
  422. /**
  423. Sets the bitmap used for the wizard.
  424. */
  425. void SetBitmap(const wxBitmap& bitmap);
  426. /**
  427. Sets the colour that should be used to fill the area not taken up by the wizard
  428. or page bitmap, if a non-zero bitmap placement flag has been set.
  429. See also SetBitmapPlacement().
  430. */
  431. void SetBitmapBackgroundColour(const wxColour& colour);
  432. /**
  433. Sets the flags indicating how the wizard or page bitmap should be expanded and
  434. positioned to fit the page height.
  435. By default, placement is 0 (no expansion is done). @a placement is a bitlist with the
  436. following possible values:
  437. - @b wxWIZARD_VALIGN_TOP: Aligns the bitmap at the top.
  438. - @b wxWIZARD_VALIGN_CENTRE: Centres the bitmap vertically.
  439. - @b wxWIZARD_VALIGN_BOTTOM: Aligns the bitmap at the bottom.
  440. - @b wxWIZARD_HALIGN_LEFT: Left-aligns the bitmap.
  441. - @b wxWIZARD_HALIGN_CENTRE: Centres the bitmap horizontally.
  442. - @b wxWIZARD_HALIGN_RIGHT: Right-aligns the bitmap.
  443. - @b wxWIZARD_TILE: @todo describe this
  444. See also SetMinimumBitmapWidth().
  445. */
  446. void SetBitmapPlacement(int placement);
  447. /**
  448. Sets width of border around page area. Default is zero.
  449. For backward compatibility, if there are no pages in GetPageAreaSizer(),
  450. the default is 5 pixels.
  451. If there is a five point border around all controls in a page and the border
  452. around page area is left as zero, a five point white space along all dialog borders
  453. will be added to the control border in order to space page controls ten points
  454. from the dialog border and non-page controls.
  455. */
  456. virtual void SetBorder(int border);
  457. /**
  458. Sets the minimum width for the bitmap that will be constructed to contain the
  459. actual wizard or page bitmap if a non-zero bitmap placement flag has been set.
  460. If this is not set when using bitmap placement, the initial layout may be incorrect.
  461. See also SetBitmapPlacement().
  462. */
  463. void SetMinimumBitmapWidth(int width);
  464. /**
  465. Sets the minimal size to be made available for the wizard pages.
  466. The wizard will take into account the size of the bitmap (if any) itself.
  467. Also, the wizard will never be smaller than the default size.
  468. The recommended way to use this function is to lay out all wizard pages
  469. using the sizers (even though the wizard is not resizable) and then use
  470. wxSizer::CalcMin() in a loop to calculate the maximum of minimal sizes of
  471. the pages and pass it to SetPageSize().
  472. */
  473. virtual void SetPageSize(const wxSize& sizePage);
  474. };