1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/preferences.h
3 // Purpose: Declaration of wxPreferencesEditor class.
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2013 Vaclav Slavik <vslavik@fastmail.fm>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PREFERENCES_H_
12 #define _WX_PREFERENCES_H_
15 #include "wx/bitmap.h"
16 #include "wx/vector.h"
18 class WXDLLIMPEXP_FWD_CORE wxWindow
;
20 class wxPreferencesEditorImpl
;
22 #if defined(__WXOSX_COCOA__)
23 // GetLargeIcon() is used
24 #define wxHAS_PREF_EDITOR_ICONS
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 #elif defined(__WXGTK__)
30 // Changes should be applied immediately
31 #define wxHAS_PREF_EDITOR_APPLY_IMMEDIATELY
32 // The dialog is shown non-modally.
33 #define wxHAS_PREF_EDITOR_MODELESS
36 // ----------------------------------------------------------------------------
37 // wxPreferencesEditor: Native preferences editing
38 // ----------------------------------------------------------------------------
40 // One page of a preferences window
41 class WXDLLIMPEXP_CORE wxPreferencesPage
44 wxPreferencesPage() {}
45 virtual ~wxPreferencesPage() {}
47 // Name of the page, used e.g. for tabs
48 virtual wxString
GetName() const = 0;
50 // Return 32x32 icon used for the page. Currently only used on OS X, where
51 // implementation is required; unused on other platforms. Because of this,
52 // the method is only pure virtual on platforms that use it.
53 #ifdef wxHAS_PREF_EDITOR_ICONS
54 virtual wxBitmap
GetLargeIcon() const = 0;
56 virtual wxBitmap
GetLargeIcon() const { return wxBitmap(); }
59 // Create a window (usually a wxPanel) for this page. The caller takes
60 // ownership of the returned window.
61 virtual wxWindow
*CreateWindow(wxWindow
*parent
) = 0;
63 wxDECLARE_NO_COPY_CLASS(wxPreferencesPage
);
67 // Helper for implementing some common pages (General, Advanced)
68 class WXDLLIMPEXP_CORE wxStockPreferencesPage
: public wxPreferencesPage
77 wxStockPreferencesPage(Kind kind
) : m_kind(kind
) {}
78 Kind
GetKind() const { return m_kind
; }
80 virtual wxString
GetName() const;
81 #ifdef __WXOSX_COCOA__
82 virtual wxBitmap
GetLargeIcon() const;
90 // Notice that this class does not inherit from wxWindow.
91 class WXDLLIMPEXP_CORE wxPreferencesEditor
94 // Ctor creates an empty editor, use AddPage() to add controls to it.
95 wxPreferencesEditor(const wxString
& title
= wxString());
97 // Dtor destroys the dialog if still shown.
98 virtual ~wxPreferencesEditor();
100 // Add a new page to the editor. The editor takes ownership of the page
101 // and won't delete it until it is destroyed itself.
102 void AddPage(wxPreferencesPage
*page
);
104 // Show the preferences dialog or bring it to the top if it's already
105 // shown. Notice that this method may or may not block depending on the
106 // platform, i.e. depending on whether the dialog is modal or not.
107 virtual void Show(wxWindow
* parent
);
109 // Hide the currently shown dialog, if any. This is typically used to
110 // dismiss the dialog if the object whose preferences it is editing was
114 // Whether changes to values in the pages should be applied immediately
115 // (OS X, GTK+) or only when the user clicks OK/Apply (Windows)
116 static bool ShouldApplyChangesImmediately()
118 #ifdef wxHAS_PREF_EDITOR_APPLY_IMMEDIATELY
125 // Whether the dialog is shown modally, i.e. Show() blocks, or not.
126 static bool ShownModally()
128 #ifdef wxHAS_PREF_EDITOR_MODELESS
136 wxPreferencesEditorImpl
* m_impl
;
138 wxDECLARE_NO_COPY_CLASS(wxPreferencesEditor
);
141 #endif // _WX_PREFERENCES_H_