dialog.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dialog.h
  3. // Purpose: interface of wxDialog
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Modes used for wxDialog::SetLayoutAdaptationMode().
  9. */
  10. enum wxDialogLayoutAdaptationMode
  11. {
  12. wxDIALOG_ADAPTATION_MODE_DEFAULT = 0, ///< Use global adaptation enabled status.
  13. wxDIALOG_ADAPTATION_MODE_ENABLED = 1, ///< Enable this dialog overriding global status.
  14. wxDIALOG_ADAPTATION_MODE_DISABLED = 2 ///< Disable this dialog overriding global status.
  15. };
  16. #define wxDIALOG_NO_PARENT 0x00000020 ///< Don't make owned by apps top window
  17. #define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX)
  18. #define wxDIALOG_ADAPTATION_NONE 0 ///< Don't do any layout adaptation
  19. #define wxDIALOG_ADAPTATION_STANDARD_SIZER 1 ///< Only look for wxStdDialogButtonSizer for non-scrolling part
  20. #define wxDIALOG_ADAPTATION_ANY_SIZER 2 ///< Also look for any suitable sizer for non-scrolling part
  21. #define wxDIALOG_ADAPTATION_LOOSE_BUTTONS 3 ///< Also look for 'loose' standard buttons for non-scrolling part
  22. /**
  23. @class wxDialog
  24. A dialog box is a window with a title bar and sometimes a system menu,
  25. which can be moved around the screen. It can contain controls and other
  26. windows and is often used to allow the user to make some choice or to
  27. answer a question.
  28. Dialogs can be made scrollable, automatically, for computers with low
  29. resolution screens: please see @ref overview_dialog_autoscrolling for
  30. further details.
  31. Dialogs usually contain either a single button allowing to close the
  32. dialog or two buttons, one accepting the changes and the other one
  33. discarding them (such button, if present, is automatically activated if the
  34. user presses the "Esc" key). By default, buttons with the standard wxID_OK
  35. and wxID_CANCEL identifiers behave as expected. Starting with wxWidgets 2.7
  36. it is also possible to use a button with a different identifier instead,
  37. see SetAffirmativeId() and SetEscapeId().
  38. Also notice that the CreateButtonSizer() should be used to create the
  39. buttons appropriate for the current platform and positioned correctly
  40. (including their order which is platform-dependent).
  41. @section dialog_modal Modal and Modeless
  42. There are two kinds of dialog, modal and modeless. A modal dialog blocks
  43. program flow and user input on other windows until it is dismissed, whereas
  44. a modeless dialog behaves more like a frame in that program flow continues,
  45. and input in other windows is still possible. To show a modal dialog you
  46. should use the ShowModal() method while to show a dialog modelessly you
  47. simply use Show(), just as with frames.
  48. Note that the modal dialog is one of the very few examples of
  49. wxWindow-derived objects which may be created on the stack and not on the
  50. heap. In other words, while most windows would be created like this:
  51. @code
  52. void AskUser()
  53. {
  54. MyAskDialog *dlg = new MyAskDialog(...);
  55. if ( dlg->ShowModal() == wxID_OK )
  56. // ...
  57. //else: dialog was cancelled or some another button pressed
  58. dlg->Destroy();
  59. }
  60. @endcode
  61. You can achieve the same result with dialogs by using simpler code:
  62. @code
  63. void AskUser()
  64. {
  65. MyAskDialog dlg(...);
  66. if ( dlg.ShowModal() == wxID_OK )
  67. // ...
  68. // no need to call Destroy() here
  69. }
  70. @endcode
  71. An application can define a wxCloseEvent handler for the dialog to respond
  72. to system close events.
  73. @beginStyleTable
  74. @style{wxCAPTION}
  75. Puts a caption on the dialog box.
  76. @style{wxDEFAULT_DIALOG_STYLE}
  77. Equivalent to a combination of wxCAPTION, wxCLOSE_BOX and
  78. wxSYSTEM_MENU (the last one is not used under Unix).
  79. @style{wxRESIZE_BORDER}
  80. Display a resizable frame around the window.
  81. @style{wxSYSTEM_MENU}
  82. Display a system menu.
  83. @style{wxCLOSE_BOX}
  84. Displays a close box on the frame.
  85. @style{wxMAXIMIZE_BOX}
  86. Displays a maximize box on the dialog.
  87. @style{wxMINIMIZE_BOX}
  88. Displays a minimize box on the dialog.
  89. @style{wxTHICK_FRAME}
  90. Display a thick frame around the window.
  91. @style{wxSTAY_ON_TOP}
  92. The dialog stays on top of all other windows.
  93. @style{wxNO_3D}
  94. This style is obsolete and doesn't do anything any more, don't use
  95. it in any new code.
  96. @style{wxDIALOG_NO_PARENT}
  97. By default, a dialog created with a @NULL parent window will be
  98. given the @ref wxApp::GetTopWindow() "application's top level window"
  99. as parent. Use this style to prevent this from happening and create
  100. an orphan dialog. This is not recommended for modal dialogs.
  101. @style{wxDIALOG_EX_CONTEXTHELP}
  102. Under Windows, puts a query button on the caption. When pressed,
  103. Windows will go into a context-sensitive help mode and wxWidgets
  104. will send a @c wxEVT_HELP event if the user clicked on an application
  105. window. Note that this is an extended style and must be set by
  106. calling SetExtraStyle() before Create is called (two-step
  107. construction).
  108. @style{wxDIALOG_EX_METAL}
  109. On Mac OS X, frames with this style will be shown with a metallic
  110. look. This is an extra style.
  111. @endStyleTable
  112. Under Unix or Linux, MWM (the Motif Window Manager) or other window
  113. managers recognizing the MHM hints should be running for any of these
  114. styles to have an effect.
  115. @beginEventEmissionTable{wxCloseEvent}
  116. @event{EVT_CLOSE(func)}
  117. The dialog is being closed by the user or programmatically (see wxWindow::Close).
  118. The user may generate this event clicking the close button
  119. (typically the 'X' on the top-right of the title bar) if it's present
  120. (see the @c wxCLOSE_BOX style) or by clicking a button with the
  121. @c wxID_CANCEL or @c wxID_OK ids.
  122. @event{EVT_INIT_DIALOG(func)}
  123. Process a @c wxEVT_INIT_DIALOG event. See wxInitDialogEvent.
  124. @endEventTable
  125. @library{wxcore}
  126. @category{cmndlg}
  127. @see @ref overview_dialog, wxFrame, @ref overview_validator
  128. */
  129. class wxDialog : public wxTopLevelWindow
  130. {
  131. public:
  132. /**
  133. Default constructor.
  134. */
  135. wxDialog();
  136. /**
  137. Constructor.
  138. @param parent
  139. Can be @NULL, a frame or another dialog box.
  140. @param id
  141. An identifier for the dialog. A value of -1 is taken to mean a
  142. default.
  143. @param title
  144. The title of the dialog.
  145. @param pos
  146. The dialog position. The value wxDefaultPosition indicates a
  147. default position, chosen by either the windowing system or
  148. wxWidgets, depending on platform.
  149. @param size
  150. The dialog size. The value wxDefaultSize indicates a default size,
  151. chosen by either the windowing system or wxWidgets, depending on
  152. platform.
  153. @param style
  154. The window style.
  155. @param name
  156. Used to associate a name with the window, allowing the application
  157. user to set Motif resource values for individual dialog boxes.
  158. @see Create()
  159. */
  160. wxDialog(wxWindow* parent, wxWindowID id, const wxString& title,
  161. const wxPoint& pos = wxDefaultPosition,
  162. const wxSize& size = wxDefaultSize,
  163. long style = wxDEFAULT_DIALOG_STYLE,
  164. const wxString& name = wxDialogNameStr);
  165. /**
  166. Destructor.
  167. Deletes any child windows before deleting the physical window.
  168. See @ref overview_windowdeletion for more info.
  169. */
  170. virtual ~wxDialog();
  171. /**
  172. Adds an identifier to be regarded as a main button for the
  173. non-scrolling area of a dialog.
  174. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  175. */
  176. void AddMainButtonId(wxWindowID id);
  177. /**
  178. Returns @true if this dialog can and should perform layout adaptation
  179. using DoLayoutAdaptation(), usually if the dialog is too large to fit
  180. on the display.
  181. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  182. */
  183. virtual bool CanDoLayoutAdaptation();
  184. /**
  185. Centres the dialog box on the display.
  186. @param direction
  187. May be wxHORIZONTAL, wxVERTICAL or wxBOTH.
  188. */
  189. void Centre(int direction = wxBOTH);
  190. /**
  191. Used for two-step dialog box construction.
  192. @see wxDialog()
  193. */
  194. bool Create(wxWindow* parent, wxWindowID id, const wxString& title,
  195. const wxPoint& pos = wxDefaultPosition,
  196. const wxSize& size = wxDefaultSize,
  197. long style = wxDEFAULT_DIALOG_STYLE,
  198. const wxString& name = wxDialogNameStr);
  199. /**
  200. Creates a sizer with standard buttons. @a flags is a bit list of the
  201. following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY, wxCLOSE, wxHELP,
  202. wxNO_DEFAULT.
  203. The sizer lays out the buttons in a manner appropriate to the platform.
  204. This function uses CreateStdDialogButtonSizer() internally for most
  205. platforms but doesn't create the sizer at all for the platforms with
  206. hardware buttons (such as smartphones) for which it sets up the
  207. hardware buttons appropriately and returns @NULL, so don't forget to
  208. test that the return value is valid before using it.
  209. */
  210. wxSizer* CreateButtonSizer(long flags);
  211. /**
  212. Creates a sizer with standard buttons using CreateButtonSizer()
  213. separated from the rest of the dialog contents by a horizontal
  214. wxStaticLine.
  215. @note Just like CreateButtonSizer(), this function may return @NULL if
  216. no buttons were created.
  217. This is a combination of CreateButtonSizer() and
  218. CreateSeparatedSizer().
  219. */
  220. wxSizer* CreateSeparatedButtonSizer(long flags);
  221. /**
  222. Returns the sizer containing the given one with a separating
  223. wxStaticLine if necessarily.
  224. This function is useful for creating the sizer containing footer-like
  225. contents in dialog boxes. It will add a separating static line only if
  226. it conforms to the current platform convention (currently it is not
  227. added under Mac where the use of static lines for grouping is
  228. discouraged and is added elsewhere).
  229. @since 2.9.2
  230. @param sizer The sizer to wrap, must be non-@NULL.
  231. @return The sizer wrapping the input one or possibly the input sizer
  232. itself if no wrapping is necessary.
  233. */
  234. wxSizer *CreateSeparatedSizer(wxSizer *sizer);
  235. /**
  236. Creates a wxStdDialogButtonSizer with standard buttons. @a flags is a
  237. bit list of the following flags: wxOK, wxCANCEL, wxYES, wxNO, wxAPPLY,
  238. wxCLOSE, wxHELP, wxNO_DEFAULT.
  239. The sizer lays out the buttons in a manner appropriate to the platform.
  240. */
  241. wxStdDialogButtonSizer* CreateStdDialogButtonSizer(long flags);
  242. /**
  243. Splits text up at newlines and places the lines into wxStaticText
  244. objects in a vertical wxBoxSizer.
  245. */
  246. wxSizer *CreateTextSizer( const wxString& message );
  247. /**
  248. Performs layout adaptation, usually if the dialog is too large to fit
  249. on the display.
  250. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  251. */
  252. virtual bool DoLayoutAdaptation();
  253. /**
  254. This function is called when the titlebar OK button is pressed
  255. (PocketPC only). A command event for the identifier returned by
  256. GetAffirmativeId() is sent by default. You can override this function.
  257. If the function returns @false, wxWidgets will call Close() for the
  258. dialog.
  259. @onlyfor{wxmsw}
  260. */
  261. virtual bool DoOK();
  262. /**
  263. A static function enabling or disabling layout adaptation for all
  264. dialogs.
  265. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  266. */
  267. static void EnableLayoutAdaptation(bool enable);
  268. /**
  269. Ends a modal dialog, passing a value to be returned from the
  270. ShowModal() invocation.
  271. @param retCode
  272. The value that should be returned by ShowModal.
  273. @see ShowModal(), GetReturnCode(), SetReturnCode()
  274. */
  275. virtual void EndModal(int retCode);
  276. /**
  277. Gets the identifier of the button which works like standard OK button
  278. in this dialog.
  279. @see SetAffirmativeId()
  280. */
  281. int GetAffirmativeId() const;
  282. /**
  283. Override this to return a window containing the main content of the
  284. dialog. This is particularly useful when the dialog implements pages,
  285. such as wxPropertySheetDialog, and allows the
  286. @ref overview_dialog "layout adaptation code" to know that only the
  287. pages need to be made scrollable.
  288. */
  289. virtual wxWindow* GetContentWindow() const;
  290. /**
  291. Gets the identifier of the button to map presses of @c ESC button to.
  292. @see SetEscapeId()
  293. */
  294. int GetEscapeId() const;
  295. /**
  296. Returns @true if the dialog has been adapted, usually by making it
  297. scrollable to work with a small display.
  298. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  299. */
  300. bool GetLayoutAdaptationDone() const;
  301. /**
  302. Gets a value representing the aggressiveness of search for buttons and
  303. sizers to be in the non-scrolling part of a layout-adapted dialog. Zero
  304. switches off adaptation, and 3 allows search for standard buttons
  305. anywhere in the dialog.
  306. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  307. */
  308. int GetLayoutAdaptationLevel() const;
  309. /**
  310. Gets the adaptation mode, overriding the global adaptation flag.
  311. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  312. */
  313. wxDialogLayoutAdaptationMode GetLayoutAdaptationMode() const;
  314. /**
  315. A static function getting the current layout adapter object.
  316. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  317. */
  318. static wxDialogLayoutAdapter* GetLayoutAdapter();
  319. /**
  320. Returns an array of identifiers to be regarded as the main buttons for
  321. the non-scrolling area of a dialog.
  322. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  323. */
  324. wxArrayInt& GetMainButtonIds();
  325. /**
  326. Gets the return code for this window.
  327. @remarks A return code is normally associated with a modal dialog,
  328. where ShowModal() returns a code to the application.
  329. @see SetReturnCode(), ShowModal(), EndModal()
  330. */
  331. int GetReturnCode() const;
  332. /**
  333. On PocketPC, a dialog is automatically provided with an empty toolbar.
  334. This function allows you to access the toolbar and add tools to it.
  335. Removing tools and adding arbitrary controls are not currently
  336. supported.
  337. This function is not available on any other platform.
  338. @onlyfor{wxmsw}
  339. */
  340. wxToolBar* GetToolBar() const;
  341. /**
  342. Iconizes or restores the dialog. Windows only.
  343. @param iconize
  344. If @true, iconizes the dialog box; if @false, shows and restores it.
  345. @remarks Note that in Windows, iconization has no effect since dialog
  346. boxes cannot be iconized. However, applications may need to
  347. explicitly restore dialog boxes under Motif which have
  348. user-iconizable frames, and under Windows calling
  349. Iconize(@false) will bring the window to the front, as does
  350. Show(@true).
  351. */
  352. virtual void Iconize(bool iconize = true);
  353. /**
  354. Returns @true if the dialog box is iconized. Windows only.
  355. @remarks Always returns @false under Windows since dialogs cannot be
  356. iconized.
  357. */
  358. virtual bool IsIconized() const;
  359. /**
  360. A static function returning @true if layout adaptation is enabled for
  361. all dialogs.
  362. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  363. */
  364. static bool IsLayoutAdaptationEnabled();
  365. /**
  366. Returns @true if @a id is in the array of identifiers to be regarded as
  367. the main buttons for the non-scrolling area of a dialog.
  368. @onlyfor{wxmsw}
  369. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  370. */
  371. bool IsMainButtonId(wxWindowID id) const;
  372. /**
  373. Returns @true if the dialog box is modal, @false otherwise.
  374. */
  375. virtual bool IsModal() const;
  376. /**
  377. Sets the identifier to be used as OK button. When the button with this
  378. identifier is pressed, the dialog calls wxWindow::Validate() and
  379. wxWindow::TransferDataFromWindow() and, if they both return @true,
  380. closes the dialog with the affirmative id return code.
  381. Also, when the user presses a hardware OK button on the devices having
  382. one or the special OK button in the PocketPC title bar, an event with
  383. this id is generated.
  384. By default, the affirmative id is wxID_OK.
  385. @see GetAffirmativeId(), SetEscapeId()
  386. */
  387. void SetAffirmativeId(int id);
  388. /**
  389. Sets the identifier of the button which should work like the standard
  390. "Cancel" button in this dialog. When the button with this id is
  391. clicked, the dialog is closed. Also, when the user presses @c ESC key
  392. in the dialog or closes the dialog using the close button in the title
  393. bar, this is mapped to the click of the button with the specified id.
  394. By default, the escape id is the special value wxID_ANY meaning that
  395. wxID_CANCEL button is used if it's present in the dialog and otherwise
  396. the button with GetAffirmativeId() is used. Another special value for
  397. @a id is wxID_NONE meaning that @c ESC presses should be ignored. If
  398. any other value is given, it is interpreted as the id of the button to
  399. map the escape key to.
  400. @note This method should be used for custom modal dialog implemented in
  401. wxWidgets itself, native dialogs such as wxMessageDialog or
  402. wxFileDialog, handle @c ESC presses in their own way which cannot be
  403. customized.
  404. */
  405. void SetEscapeId(int id);
  406. /**
  407. Sets the icon for this dialog.
  408. @param icon
  409. The icon to associate with this dialog.
  410. @see wxIcon
  411. */
  412. void SetIcon(const wxIcon& icon);
  413. /**
  414. Sets the icons for this dialog.
  415. @param icons
  416. The icons to associate with this dialog.
  417. @see wxIconBundle
  418. */
  419. void SetIcons(const wxIconBundle& icons);
  420. /**
  421. Marks the dialog as having been adapted, usually by making it
  422. scrollable to work with a small display.
  423. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  424. */
  425. void SetLayoutAdaptationDone(bool done);
  426. /**
  427. Sets the aggressiveness of search for buttons and sizers to be in the
  428. non-scrolling part of a layout-adapted dialog. Zero switches off
  429. adaptation, and 3 allows search for standard buttons anywhere in the
  430. dialog.
  431. @see @ref overview_dialog_autoscrolling (for more on layout adaptation)
  432. */
  433. void SetLayoutAdaptationLevel(int level);
  434. /**
  435. Sets the adaptation mode, overriding the global adaptation flag.
  436. @see wxDialogLayoutAdaptationMode, @ref overview_dialog_autoscrolling
  437. (for more on layout adaptation)
  438. */
  439. void SetLayoutAdaptationMode(wxDialogLayoutAdaptationMode mode);
  440. /**
  441. A static function for setting the current layout adapter object,
  442. returning the old adapter. If you call this, you should delete the old
  443. adapter object.
  444. @see wxDialogLayoutAdapter, @ref overview_dialog_autoscrolling
  445. */
  446. static wxDialogLayoutAdapter* SetLayoutAdapter(wxDialogLayoutAdapter* adapter);
  447. /**
  448. Sets the return code for this window.
  449. A return code is normally associated with a modal dialog, where
  450. ShowModal() returns a code to the application. The function EndModal()
  451. calls SetReturnCode().
  452. @param retCode
  453. The integer return code, usually a control identifier.
  454. @see GetReturnCode(), ShowModal(), EndModal()
  455. */
  456. void SetReturnCode(int retCode);
  457. /**
  458. Hides or shows the dialog. The preferred way of dismissing a modal
  459. dialog is to use EndModal().
  460. @param show
  461. If @true, the dialog box is shown and brought to the front,
  462. otherwise the box is hidden. If @false and the dialog is modal,
  463. control is returned to the calling program.
  464. */
  465. virtual bool Show(bool show = 1);
  466. /**
  467. Shows an application-modal dialog.
  468. Program flow does not return until the dialog has been dismissed with
  469. EndModal().
  470. Notice that it is possible to call ShowModal() for a dialog which had
  471. been previously shown with Show(), this allows to make an existing
  472. modeless dialog modal. However ShowModal() can't be called twice
  473. without intervening EndModal() calls.
  474. Note that this function creates a temporary event loop which takes
  475. precedence over the application's main event loop (see wxEventLoopBase)
  476. and which is destroyed when the dialog is dismissed.
  477. This also results in a call to wxApp::ProcessPendingEvents().
  478. @return The value set with SetReturnCode().
  479. @see ShowWindowModal(), ShowWindowModalThenDo(),
  480. EndModal(), GetReturnCode(), SetReturnCode()
  481. */
  482. virtual int ShowModal();
  483. /**
  484. Shows a dialog modal to the parent top level window only.
  485. Unlike ShowModal(), dialogs shown with this function only prevent the
  486. user from interacting with their parent frame only but not with the
  487. rest of the application. They also don't block the program execution
  488. but instead return immediately, as Show(), and generate a
  489. wxEVT_WINDOW_MODAL_DIALOG_CLOSED event (wxWindowModalDialogEvent)
  490. later when the dialog is closed.
  491. Currently this function is only fully implemented in wxOSX ports, under
  492. the other platforms it behaves like ShowModal() (but also sends the
  493. above mentioned event).
  494. @see wxWindowModalDialogEvent, ShowWindowModalThenDo()
  495. @since 2.9.0
  496. */
  497. void ShowWindowModal();
  498. /**
  499. Shows a dialog modal to the parent top level window only and call a
  500. functor after the dialog is closed.
  501. Same as the other ShowWindowModal() overload, but calls the functor
  502. passed as the argument upon completion, instead of generating the
  503. wxEVT_WINDOW_MODAL_DIALOG_CLOSED event.
  504. This form is particularly useful in combination with C++11 lambdas,
  505. when it allows writing window-modal very similarly to how ShowModal()
  506. is used (with the notable exception of not being able to create
  507. the dialog on stack):
  508. @code
  509. wxWindowPtr<wxDialog> dlg(new wxMessageDialog(this, "Hello!"));
  510. dlg->ShowWindowModalThenDo([this,dlg](int retcode){
  511. if ( retcode == wxID_OK )
  512. DoSomething();
  513. // dlg is implicitly destroyed here, because the pointer was
  514. // explicitly captured by the lambda
  515. });
  516. @endcode
  517. @param onEndModal Function object to call when the dialog is
  518. closed. The functor is called with a single
  519. integer argument, dialog's return code.
  520. @note The dialog instance must not be destroyed until @a onEndModal
  521. is called. The best way to ensure that is to use wxWindowPtr
  522. to hold a pointer and include it in the lambda's capture,
  523. by value (not reference!), as shown in the example above.
  524. @since 3.0
  525. @see wxWindowPtr<T>
  526. */
  527. template<typename Functor>
  528. void ShowWindowModalThenDo(const Functor& onEndModal);
  529. };
  530. /**
  531. @class wxDialogLayoutAdapter
  532. This abstract class is the base for classes that help wxWidgets perform
  533. run-time layout adaptation of dialogs. Principally, this is to cater for
  534. small displays by making part of the dialog scroll, but the application
  535. developer may find other uses for layout adaption.
  536. By default, there is one instance of wxStandardDialogLayoutAdapter which
  537. can perform adaptation for most custom dialogs and dialogs with book
  538. controls such as wxPropertySheetDialog.
  539. @library{wxcore}
  540. @category{winlayout}
  541. @see @ref overview_dialog_autoscrolling
  542. */
  543. class wxDialogLayoutAdapter
  544. {
  545. public:
  546. /**
  547. Default constructor.
  548. */
  549. wxDialogLayoutAdapter();
  550. /**
  551. Override this to returns @true if adaptation can and should be done.
  552. */
  553. virtual bool CanDoLayoutAdaptation(wxDialog* dialog) = 0;
  554. /**
  555. Override this to perform layout adaptation, such as making parts of the
  556. dialog scroll and resizing the dialog to fit the display. Normally this
  557. function will be called just before the dialog is shown.
  558. */
  559. virtual bool DoLayoutAdaptation(wxDialog* dialog) = 0;
  560. };
  561. /**
  562. Event sent by wxDialog::ShowWindowModal() when the dialog closes.
  563. @since 2.9.0
  564. */
  565. class wxWindowModalDialogEvent : public wxCommandEvent
  566. {
  567. public:
  568. /// Constructor
  569. wxWindowModalDialogEvent (wxEventType commandType = wxEVT_NULL, int id = 0);
  570. /// Return the corresponding dialog.
  571. wxDialog *GetDialog() const;
  572. /// Return the dialog's return code.
  573. int GetReturnCode() const;
  574. /// Clone the event.
  575. virtual wxEvent *Clone() const;
  576. };