]> git.saurik.com Git - wxWidgets.git/blob - include/wx/fontpicker.h
set svn properties correctly
[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_bIgnoreNextTextCtrlUpdate(false),
104 m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
105 {
106 }
107
108 virtual ~wxFontPickerCtrl() {}
109
110
111 wxFontPickerCtrl(wxWindow *parent,
112 wxWindowID id,
113 const wxFont& initial = wxNullFont,
114 const wxPoint& pos = wxDefaultPosition,
115 const wxSize& size = wxDefaultSize,
116 long style = wxFNTP_DEFAULT_STYLE,
117 const wxValidator& validator = wxDefaultValidator,
118 const wxString& name = wxFontPickerCtrlNameStr)
119 : m_bIgnoreNextTextCtrlUpdate(false),
120 m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
121 {
122 Create(parent, id, initial, pos, size, style, validator, name);
123 }
124
125 bool Create(wxWindow *parent,
126 wxWindowID id,
127 const wxFont& initial = wxNullFont,
128 const wxPoint& pos = wxDefaultPosition,
129 const wxSize& size = wxDefaultSize,
130 long style = wxFNTP_DEFAULT_STYLE,
131 const wxValidator& validator = wxDefaultValidator,
132 const wxString& name = wxFontPickerCtrlNameStr);
133
134
135 public: // public API
136
137 // get the font chosen
138 wxFont GetSelectedFont() const
139 { return ((wxFontPickerWidget *)m_picker)->GetSelectedFont(); }
140
141 // sets currently displayed font
142 void SetSelectedFont(const wxFont& f);
143
144 // set/get the max pointsize
145 void SetMaxPointSize(unsigned int max)
146 { m_nMaxPointSize=max; }
147 unsigned int GetMaxPointSize() const
148 { return m_nMaxPointSize; }
149
150 public: // internal functions
151
152 void UpdatePickerFromTextCtrl();
153 void UpdateTextCtrlFromPicker();
154
155 // event handler for our picker
156 void OnFontChange(wxFontPickerEvent &);
157
158 // used to convert wxString <-> wxFont
159 virtual wxString Font2String(const wxFont &font);
160 virtual wxFont String2Font(const wxString &font);
161
162 protected:
163
164 // extracts the style for our picker from wxFontPickerCtrl's style
165 long GetPickerStyle(long style) const
166 { return (style & (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)); }
167
168 // true if the next UpdateTextCtrl() call is to ignore
169 bool m_bIgnoreNextTextCtrlUpdate;
170
171 // the maximum pointsize allowed to the user
172 unsigned int m_nMaxPointSize;
173
174 private:
175 DECLARE_DYNAMIC_CLASS(wxFontPickerCtrl)
176 };
177
178
179 // ----------------------------------------------------------------------------
180 // wxFontPickerEvent: used by wxFontPickerCtrl only
181 // ----------------------------------------------------------------------------
182
183 extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_FONTPICKER_CHANGED;
184
185 class WXDLLIMPEXP_CORE wxFontPickerEvent : public wxCommandEvent
186 {
187 public:
188 wxFontPickerEvent() {}
189 wxFontPickerEvent(wxObject *generator, int id, const wxFont &f)
190 : wxCommandEvent(wxEVT_COMMAND_FONTPICKER_CHANGED, id),
191 m_font(f)
192 {
193 SetEventObject(generator);
194 }
195
196 wxFont GetFont() const { return m_font; }
197 void SetFont(const wxFont &c) { m_font = c; }
198
199 // default copy ctor, assignment operator and dtor are ok
200 virtual wxEvent *Clone() const { return new wxFontPickerEvent(*this); }
201
202 private:
203 wxFont m_font;
204
205 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFontPickerEvent)
206 };
207
208 // ----------------------------------------------------------------------------
209 // event types and macros
210 // ----------------------------------------------------------------------------
211
212 typedef void (wxEvtHandler::*wxFontPickerEventFunction)(wxFontPickerEvent&);
213
214 #define wxFontPickerEventHandler(func) \
215 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFontPickerEventFunction, &func)
216
217 #define EVT_FONTPICKER_CHANGED(id, fn) \
218 wx__DECLARE_EVT1(wxEVT_COMMAND_FONTPICKER_CHANGED, id, wxFontPickerEventHandler(fn))
219
220
221 #endif // wxUSE_FONTPICKERCTRL
222
223 #endif
224 // _WX_FONTPICKER_H_BASE_