dialog.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dialog.h
  3. // Purpose: topic overview
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @page overview_dialog wxDialog Overview
  9. @tableofcontents
  10. Classes: wxDialog, wxDialogLayoutAdapter
  11. A dialog box is similar to a panel, in that it is a window which can be used
  12. for placing controls, with the following exceptions:
  13. @li A surrounding frame is implicitly created.
  14. @li Extra functionality is automatically given to the dialog box, such as
  15. tabbing between items (currently Windows only).
  16. @li If the dialog box is @e modal, the calling program is blocked until the
  17. dialog box is dismissed.
  18. For a set of dialog convenience functions, including file selection, see
  19. @ref group_funcmacro_dialog.
  20. See also wxTopLevelWindow and wxWindow for inherited member functions.
  21. Validation of data in controls is covered in @ref overview_validator.
  22. @section overview_dialog_autoscrolling Automatic Scrolled Dialogs
  23. As an ever greater variety of mobile hardware comes to market, it becomes more
  24. imperative for wxWidgets applications to adapt to these platforms without
  25. putting too much burden on the programmer. One area where wxWidgets can help is
  26. in adapting dialogs for the lower resolution screens that inevitably accompany
  27. a smaller form factor. wxDialog therefore supplies a global
  28. wxDialogLayoutAdapter class that implements automatic scrolling adaptation for
  29. most sizer-based custom dialogs.
  30. Many applications should therefore be able to adapt to small displays with
  31. little or no work, as far as dialogs are concerned. By default this adaptation
  32. is off. To switch scrolling adaptation on globally in your application, call
  33. the static function wxDialog::EnableLayoutAdaptation passing @true. You can
  34. also adjust adaptation on a per-dialog basis by calling
  35. wxDialog::SetLayoutAdaptationMode with one of
  36. @c wxDIALOG_ADAPTATION_MODE_DEFAULT (use the global setting),
  37. @c wxDIALOG_ADAPTATION_MODE_ENABLED or @c wxDIALOG_ADAPTATION_MODE_DISABLED.
  38. The last two modes override the global adaptation setting. With adaptation
  39. enabled, if the display size is too small for the dialog, wxWidgets (or rather
  40. the standard adapter class wxStandardDialogLayoutAdapter) will make part of the
  41. dialog scrolling, leaving standard buttons in a non-scrolling part at the
  42. bottom of the dialog. This is done as follows, in
  43. wxDialogLayoutAdapter::DoLayoutAdaptation called from within wxDialog::Show or
  44. wxDialog::ShowModal:
  45. @li If wxDialog::GetContentWindow returns a window derived from wxBookCtrlBase,
  46. the pages are made scrollable and no other adaptation is done.
  47. @li wxWidgets looks for a wxStdDialogButtonSizer and uses it for the
  48. non-scrolling part.
  49. @li If that search failed, wxWidgets looks for a horizontal wxBoxSizer with one
  50. or more standard buttons, with identifiers such as @c wxID_OK and
  51. @c wxID_CANCEL.
  52. @li If that search failed too, wxWidgets finds 'loose' standard buttons (in any
  53. kind of sizer) and adds them to a wxStdDialogButtonSizer. If no standard
  54. buttons were found, the whole dialog content will scroll.
  55. @li All the children apart from standard buttons are reparented onto a new
  56. ::wxScrolledWindow object, using the old top-level sizer for the scrolled
  57. window and creating a new top-level sizer to lay out the scrolled window
  58. and standard button sizer.
  59. @subsection overview_dialog_autoscrolling_custom Customising Scrolling Adaptation
  60. In addition to switching adaptation on and off globally and per dialog, you can
  61. choose how aggressively wxWidgets will search for standard buttons by setting
  62. wxDialog::SetLayoutAdaptationLevel. By default, all the steps described above
  63. will be performed but by setting the level to 1, for example, you can choose to
  64. only look for wxStdDialogButtonSizer.
  65. You can use wxDialog::AddMainButtonId to add identifiers for buttons that
  66. should also be treated as standard buttons for the non-scrolling area.
  67. You can derive your own class from wxDialogLayoutAdapter or
  68. wxStandardDialogLayoutAdapter and call wxDialog::SetLayoutAdapter, deleting the
  69. old object that this function returns. Override the functions
  70. CanDoLayoutAdaptation and DoLayoutAdaptation to test for adaptation
  71. applicability and perform the adaptation.
  72. You can also override wxDialog::CanDoLayoutAdaptation and
  73. wxDialog::DoLayoutAdaptation in a class derived from wxDialog.
  74. @subsection overview_dialog_autoscrolling_fail Where Scrolling Adaptation May Fail
  75. Because adaptation rearranges your sizer and window hierarchy, it is not
  76. fool-proof, and may fail in the following situations:
  77. @li The dialog doesn't use sizers.
  78. @li The dialog implementation makes assumptions about the window hierarchy,
  79. for example getting the parent of a control and casting to the dialog class.
  80. @li The dialog does custom painting and/or event handling not handled by the scrolled window.
  81. If this problem can be solved globally, you can derive a new adapter class from
  82. wxStandardDialogLayoutAdapter and override its CreateScrolledWindow function to return
  83. an instance of your own class.
  84. @li The dialog has unusual layout, for example a vertical sizer containing a mixture of
  85. standard buttons and other controls.
  86. @li The dialog makes assumptions about the sizer hierarchy, for example to show or hide
  87. children of the top-level sizer. However, the original sizer hierarchy will still hold
  88. until Show or ShowModal is called.
  89. You can help make sure that your dialogs will continue to function after
  90. adaptation by:
  91. @li avoiding the above situations and assumptions;
  92. @li using wxStdDialogButtonSizer;
  93. @li only making assumptions about hierarchy immediately after the dialog is created;
  94. @li using an intermediate sizer under the main sizer, a @false top-level sizer that
  95. can be relied on to exist for the purposes of manipulating child sizers and windows;
  96. @li overriding wxDialog::GetContentWindow to return a book control if your dialog implements
  97. pages: wxWidgets will then only make the pages scrollable.
  98. @subsection overview_dialog_propertysheet wxPropertySheetDialog and wxWizard
  99. Adaptation for wxPropertySheetDialog is always done by simply making the pages
  100. scrollable, since wxDialog::GetContentWindow returns the dialog's book control
  101. and this is handled by the standard layout adapter.
  102. wxWizard uses its own CanDoLayoutAdaptation and DoLayoutAdaptation functions
  103. rather than the global adapter: again, only the wizard pages are made
  104. scrollable.
  105. */