1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/preferences.h
3 // Purpose: Declaration of wxPreferencesEditor class.
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2013 Vaclav Slavik <vslavik@fastmail.fm>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_PREFERENCES_H_
11 #define _WX_PREFERENCES_H_
15 #if wxUSE_PREFERENCES_EDITOR
17 #include "wx/bitmap.h"
18 #include "wx/vector.h"
20 class WXDLLIMPEXP_FWD_CORE wxWindow
;
22 class wxPreferencesEditorImpl
;
24 #if defined(__WXOSX_COCOA__)
25 // GetLargeIcon() is used
26 #define wxHAS_PREF_EDITOR_ICONS
27 // Changes should be applied immediately
28 #define wxHAS_PREF_EDITOR_APPLY_IMMEDIATELY
29 // The dialog is shown non-modally.
30 #define wxHAS_PREF_EDITOR_MODELESS
31 #elif defined(__WXGTK__)
32 // Changes should be applied immediately
33 #define wxHAS_PREF_EDITOR_APPLY_IMMEDIATELY
34 // The dialog is shown non-modally.
35 #define wxHAS_PREF_EDITOR_MODELESS
38 // ----------------------------------------------------------------------------
39 // wxPreferencesEditor: Native preferences editing
40 // ----------------------------------------------------------------------------
42 // One page of a preferences window
43 class WXDLLIMPEXP_CORE wxPreferencesPage
46 wxPreferencesPage() {}
47 virtual ~wxPreferencesPage() {}
49 // Name of the page, used e.g. for tabs
50 virtual wxString
GetName() const = 0;
52 // Return 32x32 icon used for the page. Currently only used on OS X, where
53 // implementation is required; unused on other platforms. Because of this,
54 // the method is only pure virtual on platforms that use it.
55 #ifdef wxHAS_PREF_EDITOR_ICONS
56 virtual wxBitmap
GetLargeIcon() const = 0;
58 virtual wxBitmap
GetLargeIcon() const { return wxBitmap(); }
61 // Create a window (usually a wxPanel) for this page. The caller takes
62 // ownership of the returned window.
63 virtual wxWindow
*CreateWindow(wxWindow
*parent
) = 0;
65 wxDECLARE_NO_COPY_CLASS(wxPreferencesPage
);
69 // Helper for implementing some common pages (General, Advanced)
70 class WXDLLIMPEXP_CORE wxStockPreferencesPage
: public wxPreferencesPage
79 wxStockPreferencesPage(Kind kind
) : m_kind(kind
) {}
80 Kind
GetKind() const { return m_kind
; }
82 virtual wxString
GetName() const;
83 #ifdef __WXOSX_COCOA__
84 virtual wxBitmap
GetLargeIcon() const;
92 // Notice that this class does not inherit from wxWindow.
93 class WXDLLIMPEXP_CORE wxPreferencesEditor
96 // Ctor creates an empty editor, use AddPage() to add controls to it.
97 wxPreferencesEditor(const wxString
& title
= wxString());
99 // Dtor destroys the dialog if still shown.
100 virtual ~wxPreferencesEditor();
102 // Add a new page to the editor. The editor takes ownership of the page
103 // and won't delete it until it is destroyed itself.
104 void AddPage(wxPreferencesPage
*page
);
106 // Show the preferences dialog or bring it to the top if it's already
107 // shown. Notice that this method may or may not block depending on the
108 // platform, i.e. depending on whether the dialog is modal or not.
109 virtual void Show(wxWindow
* parent
);
111 // Hide the currently shown dialog, if any. This is typically used to
112 // dismiss the dialog if the object whose preferences it is editing was
116 // Whether changes to values in the pages should be applied immediately
117 // (OS X, GTK+) or only when the user clicks OK/Apply (Windows)
118 static bool ShouldApplyChangesImmediately()
120 #ifdef wxHAS_PREF_EDITOR_APPLY_IMMEDIATELY
127 // Whether the dialog is shown modally, i.e. Show() blocks, or not.
128 static bool ShownModally()
130 #ifdef wxHAS_PREF_EDITOR_MODELESS
138 wxPreferencesEditorImpl
* m_impl
;
140 wxDECLARE_NO_COPY_CLASS(wxPreferencesEditor
);
143 #endif // wxUSE_PREFERENCES_EDITOR
145 #endif // _WX_PREFERENCES_H_