preferences.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/preferences.h
  3. // Purpose: Declaration of wxPreferencesEditor class.
  4. // Author: Vaclav Slavik
  5. // Created: 2013-02-19
  6. // Copyright: (c) 2013 Vaclav Slavik <vslavik@fastmail.fm>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_PREFERENCES_H_
  10. #define _WX_PREFERENCES_H_
  11. #include "wx/defs.h"
  12. #if wxUSE_PREFERENCES_EDITOR
  13. #include "wx/bitmap.h"
  14. #include "wx/vector.h"
  15. class WXDLLIMPEXP_FWD_CORE wxWindow;
  16. class wxPreferencesEditorImpl;
  17. #if defined(__WXOSX_COCOA__)
  18. // GetLargeIcon() is used
  19. #define wxHAS_PREF_EDITOR_ICONS
  20. // Changes should be applied immediately
  21. #define wxHAS_PREF_EDITOR_APPLY_IMMEDIATELY
  22. // The dialog is shown non-modally.
  23. #define wxHAS_PREF_EDITOR_MODELESS
  24. #elif defined(__WXGTK__)
  25. // Changes should be applied immediately
  26. #define wxHAS_PREF_EDITOR_APPLY_IMMEDIATELY
  27. // The dialog is shown non-modally.
  28. #define wxHAS_PREF_EDITOR_MODELESS
  29. #endif
  30. // ----------------------------------------------------------------------------
  31. // wxPreferencesEditor: Native preferences editing
  32. // ----------------------------------------------------------------------------
  33. // One page of a preferences window
  34. class WXDLLIMPEXP_CORE wxPreferencesPage
  35. {
  36. public:
  37. wxPreferencesPage() {}
  38. virtual ~wxPreferencesPage() {}
  39. // Name of the page, used e.g. for tabs
  40. virtual wxString GetName() const = 0;
  41. // Return 32x32 icon used for the page. Currently only used on OS X, where
  42. // implementation is required; unused on other platforms. Because of this,
  43. // the method is only pure virtual on platforms that use it.
  44. #ifdef wxHAS_PREF_EDITOR_ICONS
  45. virtual wxBitmap GetLargeIcon() const = 0;
  46. #else
  47. virtual wxBitmap GetLargeIcon() const { return wxBitmap(); }
  48. #endif
  49. // Create a window (usually a wxPanel) for this page. The caller takes
  50. // ownership of the returned window.
  51. virtual wxWindow *CreateWindow(wxWindow *parent) = 0;
  52. wxDECLARE_NO_COPY_CLASS(wxPreferencesPage);
  53. };
  54. // Helper for implementing some common pages (General, Advanced)
  55. class WXDLLIMPEXP_CORE wxStockPreferencesPage : public wxPreferencesPage
  56. {
  57. public:
  58. enum Kind
  59. {
  60. Kind_General,
  61. Kind_Advanced
  62. };
  63. wxStockPreferencesPage(Kind kind) : m_kind(kind) {}
  64. Kind GetKind() const { return m_kind; }
  65. virtual wxString GetName() const;
  66. #ifdef __WXOSX_COCOA__
  67. virtual wxBitmap GetLargeIcon() const;
  68. #endif
  69. private:
  70. Kind m_kind;
  71. };
  72. // Notice that this class does not inherit from wxWindow.
  73. class WXDLLIMPEXP_CORE wxPreferencesEditor
  74. {
  75. public:
  76. // Ctor creates an empty editor, use AddPage() to add controls to it.
  77. wxPreferencesEditor(const wxString& title = wxString());
  78. // Dtor destroys the dialog if still shown.
  79. virtual ~wxPreferencesEditor();
  80. // Add a new page to the editor. The editor takes ownership of the page
  81. // and won't delete it until it is destroyed itself.
  82. void AddPage(wxPreferencesPage *page);
  83. // Show the preferences dialog or bring it to the top if it's already
  84. // shown. Notice that this method may or may not block depending on the
  85. // platform, i.e. depending on whether the dialog is modal or not.
  86. virtual void Show(wxWindow* parent);
  87. // Hide the currently shown dialog, if any. This is typically used to
  88. // dismiss the dialog if the object whose preferences it is editing was
  89. // closed.
  90. void Dismiss();
  91. // Whether changes to values in the pages should be applied immediately
  92. // (OS X, GTK+) or only when the user clicks OK/Apply (Windows)
  93. static bool ShouldApplyChangesImmediately()
  94. {
  95. #ifdef wxHAS_PREF_EDITOR_APPLY_IMMEDIATELY
  96. return true;
  97. #else
  98. return false;
  99. #endif
  100. }
  101. // Whether the dialog is shown modally, i.e. Show() blocks, or not.
  102. static bool ShownModally()
  103. {
  104. #ifdef wxHAS_PREF_EDITOR_MODELESS
  105. return false;
  106. #else
  107. return true;
  108. #endif
  109. }
  110. private:
  111. wxPreferencesEditorImpl* m_impl;
  112. wxDECLARE_NO_COPY_CLASS(wxPreferencesEditor);
  113. };
  114. #endif // wxUSE_PREFERENCES_EDITOR
  115. #endif // _WX_PREFERENCES_H_