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