preferences.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: interface/wx/preferences.h
  3. // Purpose: wxPreferencesEditor class documentation.
  4. // Author: Vaclav Slavik
  5. // Created: 2013-02-26
  6. // Copyright: (c) 2013 Vaclav Slavik <vslavik@fastmail.fm>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. /**
  10. Manage preferences dialog.
  11. This class encapsulates the differences -- both in appearance and
  12. behaviour -- between preferences dialogs on different platforms. In
  13. particular, OS X preferences look very different from the typical notebook
  14. control used on other platforms, and both OS X and GTK+ preferences windows
  15. are modeless unlike Windows options dialogs that are typically modal.
  16. wxPreferencesEditor is able to hide the differences by hiding the creation
  17. of preferences window from the API. Instead, you create an instance of
  18. wxPreferencesEditor and add page descriptions in the form of
  19. wxPreferencesPage using its AddPage() method. After setting up the editor
  20. object, you must call Show() to present preferences to the user.
  21. @note Notice that this class is not derived from wxWindow and hence
  22. doesn't represent a window, even if its Show() method does create one
  23. internally.
  24. @library{wxcore}
  25. @since 2.9.5
  26. */
  27. class wxPreferencesEditor
  28. {
  29. public:
  30. /**
  31. Constructor.
  32. Creates an empty editor, use AddPage() to add controls to it.
  33. @param title The title overriding the default title of the top level
  34. window used by the editor. It is recommended to not specify this
  35. parameter to use the native convention for the preferences dialogs
  36. instead.
  37. */
  38. wxPreferencesEditor(const wxString& title = wxString());
  39. /**
  40. Destructor.
  41. Destroying this object hides the associated preferences window if it is
  42. open at the moment.
  43. The destructor is non-virtual as this class is not supposed to be
  44. derived from.
  45. */
  46. ~wxPreferencesEditor();
  47. /**
  48. Add a new page to the editor.
  49. The editor takes ownership of the page and will delete it from its
  50. destructor (but not sooner).
  51. @see wxPreferencesPage, wxStockPreferencesPage
  52. */
  53. void AddPage(wxPreferencesPage *page);
  54. /**
  55. Show the preferences dialog or bring it to the top if it's already
  56. shown.
  57. Notice that this method may or may not block depending on the platform,
  58. i.e. depending on whether the dialog is modal or not.
  59. @param parent The window that invokes the preferences.
  60. Call Dismiss() before it's destroyed.
  61. */
  62. virtual void Show(wxWindow* parent);
  63. /**
  64. Hide the currently shown dialog, if any.
  65. This is typically called to dismiss the dialog if the object whose
  66. preferences it is editing was closed.
  67. */
  68. void Dismiss();
  69. /**
  70. Returns whether changes to values in preferences pages should be
  71. applied immediately or only when the user clicks the OK button.
  72. Currently, changes are applied immediately on OS X and GTK+.
  73. The preprocessor macro `wxHAS_PREF_EDITOR_APPLY_IMMEDIATELY` is defined
  74. in this case as well.
  75. */
  76. static bool ShouldApplyChangesImmediately()
  77. /**
  78. Returns whether the preferences dialog is shown modally.
  79. If this method returns false, as it currently does in wxGTK and wxOSX,
  80. Show() simply makes the dialog visible and returns immediately. If it
  81. returns true, as it does in wxMSW and under the other platforms, then
  82. the dialog is shown modally, i.e. Show() blocks until the user
  83. dismisses it.
  84. Notice that it isn't necessary to test the return value of this method
  85. to use this class normally, its interface is designed to work in both
  86. cases. However it can sometimes be necessary to call it if the program
  87. needs to handle modal dialogs specially, e.g. perhaps to block some
  88. periodic background update operation while a modal dialog is shown.
  89. */
  90. static bool ShownModally();
  91. };
  92. /**
  93. One page of preferences dialog.
  94. This is the base class for implementation of application's preferences. Its
  95. methods return various properties of the page, such as title or icon. The
  96. actual page is created by CreateWindow().
  97. @see wxStockPreferencesPage
  98. @library{wxcore}
  99. @since 2.9.5
  100. */
  101. class wxPreferencesPage
  102. {
  103. public:
  104. /// Constructor.
  105. wxPreferencesPage();
  106. /// Destructor.
  107. virtual ~wxPreferencesPage();
  108. /**
  109. Return name of the page.
  110. The name is used for notebook tab's label, icon label etc., depending
  111. on the platform.
  112. */
  113. virtual wxString GetName() const = 0;
  114. /**
  115. Return 32x32 icon used for the page on some platforms.
  116. Currently only used on OS X.
  117. @note This method is only pure virtual on platforms that require it
  118. (OS X). On other platforms, it has default implementation that
  119. returns an invalid bitmap. The preprocessor symbol
  120. `wxHAS_PREF_EDITOR_ICONS` is defined if this method must be
  121. implemented.
  122. */
  123. virtual wxBitmap GetLargeIcon() const = 0;
  124. /**
  125. Create a window for this page.
  126. The window will be placed into the preferences dialog in
  127. platform-specific manner. Depending on the platform, this method may
  128. be called before showing the preferences window, when switching to its
  129. tab or even more than once. Don't make assumptions about the number of
  130. times or the specific time when it is called.
  131. The caller takes ownership of the window.
  132. wxPanel is usually used, but doesn't have to be.
  133. @param parent Parent window to use.
  134. */
  135. virtual wxWindow *CreateWindow(wxWindow *parent) = 0;
  136. };
  137. /**
  138. Specialization of wxPreferencesPage useful for certain commonly used
  139. preferences page.
  140. On OS X, preferences pages named "General" and "Advanced" are commonly used
  141. in apps and the OS provides stock icons for them that should be used.
  142. Instead of reimplementing this behavior yourself, you can inherit from
  143. wxStockPreferencesPage and get correct title and icon.
  144. Notice that this class only implements GetName() and GetLargeIcon(), you
  145. still have to provide the rest of wxPreferencesPage implementation.
  146. @library{wxcore}
  147. @since 2.9.5
  148. */
  149. class wxStockPreferencesPage : public wxPreferencesPage
  150. {
  151. public:
  152. /// Kinds of stock pages.
  153. enum Kind
  154. {
  155. /// The "General" page
  156. Kind_General,
  157. /// The "Advanced" page
  158. Kind_Advanced
  159. };
  160. /// Constructor.
  161. wxStockPreferencesPage(Kind kind);
  162. /// Returns the page's kind.
  163. Kind GetKind() const;
  164. /// Reimplemented to return suitable name for the page's kind.
  165. virtual wxString GetName() const;
  166. /// Reimplemented to return stock icon on OS X.
  167. virtual wxBitmap GetLargeIcon() const;
  168. };