Provide shorter synonyms for wxEVT_XXX constants.
[wxWidgets.git] / include / wx / fontpicker.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/fontpicker.h
3 // Purpose: wxFontPickerCtrl base header
4 // Author: Francesco Montorsi
5 // Modified by:
6 // Created: 14/4/2006
7 // Copyright: (c) Francesco Montorsi
8 // RCS-ID: $Id$
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FONTPICKER_H_BASE_
13 #define _WX_FONTPICKER_H_BASE_
14
15 #include "wx/defs.h"
16
17
18 #if wxUSE_FONTPICKERCTRL
19
20 #include "wx/pickerbase.h"
21
22
23 class WXDLLIMPEXP_FWD_CORE wxFontPickerEvent;
24
25 extern WXDLLIMPEXP_DATA_CORE(const char) wxFontPickerWidgetNameStr[];
26 extern WXDLLIMPEXP_DATA_CORE(const char) wxFontPickerCtrlNameStr[];
27
28
29 // ----------------------------------------------------------------------------
30 // wxFontPickerWidgetBase: a generic abstract interface which must be
31 // implemented by controls used by wxFontPickerCtrl
32 // ----------------------------------------------------------------------------
33
34 class WXDLLIMPEXP_CORE wxFontPickerWidgetBase
35 {
36 public:
37 wxFontPickerWidgetBase() { m_selectedFont = *wxNORMAL_FONT; }
38 virtual ~wxFontPickerWidgetBase() {}
39
40 wxFont GetSelectedFont() const
41 { return m_selectedFont; }
42 virtual void SetSelectedFont(const wxFont &f)
43 { m_selectedFont = f; UpdateFont(); }
44
45 protected:
46
47 virtual void UpdateFont() = 0;
48
49 // the current font (may be invalid if none)
50 // NOTE: don't call this m_font as wxWindow::m_font already exists
51 wxFont m_selectedFont;
52 };
53
54 // Styles which must be supported by all controls implementing wxFontPickerWidgetBase
55 // NB: these styles must be defined to carefully-chosen values to
56 // avoid conflicts with wxButton's styles
57
58
59 // keeps the label of the button updated with the fontface name + font size
60 // E.g. choosing "Times New Roman bold, italic with size 10" from the fontdialog,
61 // updates the wxFontButtonGeneric's label (overwriting any previous label)
62 // with the "Times New Roman, 10" text (only fontface + fontsize is displayed
63 // to avoid extralong labels).
64 #define wxFNTP_FONTDESC_AS_LABEL 0x0008
65
66 // uses the currently selected font to draw the label of the button
67 #define wxFNTP_USEFONT_FOR_LABEL 0x0010
68
69 #define wxFONTBTN_DEFAULT_STYLE \
70 (wxFNTP_FONTDESC_AS_LABEL | wxFNTP_USEFONT_FOR_LABEL)
71
72 // native version currently only exists in wxGTK2
73 #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
74 #include "wx/gtk/fontpicker.h"
75 #define wxFontPickerWidget wxFontButton
76 #else
77 #include "wx/generic/fontpickerg.h"
78 #define wxFontPickerWidget wxGenericFontButton
79 #endif
80
81
82 // ----------------------------------------------------------------------------
83 // wxFontPickerCtrl specific flags
84 // ----------------------------------------------------------------------------
85
86 #define wxFNTP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
87 #define wxFNTP_DEFAULT_STYLE (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)
88
89 // not a style but rather the default value of the maximum pointsize allowed
90 #define wxFNTP_MAXPOINT_SIZE 100
91
92
93 // ----------------------------------------------------------------------------
94 // wxFontPickerCtrl: platform-independent class which embeds the
95 // platform-dependent wxFontPickerWidget andm if wxFNTP_USE_TEXTCTRL style is
96 // used, a textctrl next to it.
97 // ----------------------------------------------------------------------------
98
99 class WXDLLIMPEXP_CORE wxFontPickerCtrl : public wxPickerBase
100 {
101 public:
102 wxFontPickerCtrl()
103 : m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
104 {
105 }
106
107 virtual ~wxFontPickerCtrl() {}
108
109
110 wxFontPickerCtrl(wxWindow *parent,
111 wxWindowID id,
112 const wxFont& initial = wxNullFont,
113 const wxPoint& pos = wxDefaultPosition,
114 const wxSize& size = wxDefaultSize,
115 long style = wxFNTP_DEFAULT_STYLE,
116 const wxValidator& validator = wxDefaultValidator,
117 const wxString& name = wxFontPickerCtrlNameStr)
118 : m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
119 {
120 Create(parent, id, initial, pos, size, style, validator, name);
121 }
122
123 bool Create(wxWindow *parent,
124 wxWindowID id,
125 const wxFont& initial = wxNullFont,
126 const wxPoint& pos = wxDefaultPosition,
127 const wxSize& size = wxDefaultSize,
128 long style = wxFNTP_DEFAULT_STYLE,
129 const wxValidator& validator = wxDefaultValidator,
130 const wxString& name = wxFontPickerCtrlNameStr);
131
132
133 public: // public API
134
135 // get the font chosen
136 wxFont GetSelectedFont() const
137 { return ((wxFontPickerWidget *)m_picker)->GetSelectedFont(); }
138
139 // sets currently displayed font
140 void SetSelectedFont(const wxFont& f);
141
142 // set/get the max pointsize
143 void SetMaxPointSize(unsigned int max)
144 { m_nMaxPointSize=max; }
145 unsigned int GetMaxPointSize() const
146 { return m_nMaxPointSize; }
147
148 public: // internal functions
149
150 void UpdatePickerFromTextCtrl();
151 void UpdateTextCtrlFromPicker();
152
153 // event handler for our picker
154 void OnFontChange(wxFontPickerEvent &);
155
156 // used to convert wxString <-> wxFont
157 virtual wxString Font2String(const wxFont &font);
158 virtual wxFont String2Font(const wxString &font);
159
160 protected:
161
162 // extracts the style for our picker from wxFontPickerCtrl's style
163 long GetPickerStyle(long style) const
164 { return (style & (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)); }
165
166 // the maximum pointsize allowed to the user
167 unsigned int m_nMaxPointSize;
168
169 private:
170 DECLARE_DYNAMIC_CLASS(wxFontPickerCtrl)
171 };
172
173
174 // ----------------------------------------------------------------------------
175 // wxFontPickerEvent: used by wxFontPickerCtrl only
176 // ----------------------------------------------------------------------------
177
178 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FONTPICKER_CHANGED, wxFontPickerEvent );
179
180 class WXDLLIMPEXP_CORE wxFontPickerEvent : public wxCommandEvent
181 {
182 public:
183 wxFontPickerEvent() {}
184 wxFontPickerEvent(wxObject *generator, int id, const wxFont &f)
185 : wxCommandEvent(wxEVT_FONTPICKER_CHANGED, id),
186 m_font(f)
187 {
188 SetEventObject(generator);
189 }
190
191 wxFont GetFont() const { return m_font; }
192 void SetFont(const wxFont &c) { m_font = c; }
193
194 // default copy ctor, assignment operator and dtor are ok
195 virtual wxEvent *Clone() const { return new wxFontPickerEvent(*this); }
196
197 private:
198 wxFont m_font;
199
200 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFontPickerEvent)
201 };
202
203 // ----------------------------------------------------------------------------
204 // event types and macros
205 // ----------------------------------------------------------------------------
206
207 typedef void (wxEvtHandler::*wxFontPickerEventFunction)(wxFontPickerEvent&);
208
209 #define wxFontPickerEventHandler(func) \
210 wxEVENT_HANDLER_CAST(wxFontPickerEventFunction, func)
211
212 #define EVT_FONTPICKER_CHANGED(id, fn) \
213 wx__DECLARE_EVT1(wxEVT_FONTPICKER_CHANGED, id, wxFontPickerEventHandler(fn))
214
215 // old wxEVT_COMMAND_* constants
216 #define wxEVT_COMMAND_FONTPICKER_CHANGED wxEVT_FONTPICKER_CHANGED
217
218
219 #endif // wxUSE_FONTPICKERCTRL
220
221 #endif
222 // _WX_FONTPICKER_H_BASE_