1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/fontpicker.h
3 // Purpose: wxFontPickerCtrl base header
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_FONTPICKER_H_BASE_
13 #define _WX_FONTPICKER_H_BASE_
18 #if wxUSE_FONTPICKERCTRL
20 #include "wx/pickerbase.h"
23 class WXDLLIMPEXP_FWD_CORE wxFontPickerEvent
;
25 extern WXDLLIMPEXP_DATA_CORE(const char) wxFontPickerWidgetNameStr
[];
26 extern WXDLLIMPEXP_DATA_CORE(const char) wxFontPickerCtrlNameStr
[];
29 // ----------------------------------------------------------------------------
30 // wxFontPickerWidgetBase: a generic abstract interface which must be
31 // implemented by controls used by wxFontPickerCtrl
32 // ----------------------------------------------------------------------------
34 class WXDLLIMPEXP_CORE wxFontPickerWidgetBase
37 wxFontPickerWidgetBase() { m_selectedFont
= *wxNORMAL_FONT
; }
38 virtual ~wxFontPickerWidgetBase() {}
40 wxFont
GetSelectedFont() const
41 { return m_selectedFont
; }
42 virtual void SetSelectedFont(const wxFont
&f
)
43 { m_selectedFont
= f
; UpdateFont(); }
47 virtual void UpdateFont() = 0;
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
;
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
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
66 // uses the currently selected font to draw the label of the button
67 #define wxFNTP_USEFONT_FOR_LABEL 0x0010
69 #define wxFONTBTN_DEFAULT_STYLE \
70 (wxFNTP_FONTDESC_AS_LABEL | wxFNTP_USEFONT_FOR_LABEL)
72 // native version currently only exists in wxGTK2
73 #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
74 #include "wx/gtk/fontpicker.h"
75 #define wxFontPickerWidget wxFontButton
77 #include "wx/generic/fontpickerg.h"
78 #define wxFontPickerWidget wxGenericFontButton
82 // ----------------------------------------------------------------------------
83 // wxFontPickerCtrl specific flags
84 // ----------------------------------------------------------------------------
86 #define wxFNTP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
87 #define wxFNTP_DEFAULT_STYLE (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)
89 // not a style but rather the default value of the maximum pointsize allowed
90 #define wxFNTP_MAXPOINT_SIZE 100
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 // ----------------------------------------------------------------------------
99 class WXDLLIMPEXP_CORE wxFontPickerCtrl
: public wxPickerBase
103 : m_bIgnoreNextTextCtrlUpdate(false),
104 m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE
)
108 virtual ~wxFontPickerCtrl() {}
111 wxFontPickerCtrl(wxWindow
*parent
,
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
)
122 Create(parent
, id
, initial
, pos
, size
, style
, validator
, name
);
125 bool Create(wxWindow
*parent
,
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
);
135 public: // public API
137 // get the font chosen
138 wxFont
GetSelectedFont() const
139 { return ((wxFontPickerWidget
*)m_picker
)->GetSelectedFont(); }
141 // sets currently displayed font
142 void SetSelectedFont(const wxFont
& f
);
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
; }
150 public: // internal functions
152 void UpdatePickerFromTextCtrl();
153 void UpdateTextCtrlFromPicker();
155 // event handler for our picker
156 void OnFontChange(wxFontPickerEvent
&);
158 // used to convert wxString <-> wxFont
159 virtual wxString
Font2String(const wxFont
&font
);
160 virtual wxFont
String2Font(const wxString
&font
);
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
)); }
168 // true if the next UpdateTextCtrl() call is to ignore
169 bool m_bIgnoreNextTextCtrlUpdate
;
171 // the maximum pointsize allowed to the user
172 unsigned int m_nMaxPointSize
;
175 DECLARE_DYNAMIC_CLASS(wxFontPickerCtrl
)
179 // ----------------------------------------------------------------------------
180 // wxFontPickerEvent: used by wxFontPickerCtrl only
181 // ----------------------------------------------------------------------------
183 extern WXDLLIMPEXP_CORE
const wxEventType wxEVT_COMMAND_FONTPICKER_CHANGED
;
185 class WXDLLIMPEXP_CORE wxFontPickerEvent
: public wxCommandEvent
188 wxFontPickerEvent() {}
189 wxFontPickerEvent(wxObject
*generator
, int id
, const wxFont
&f
)
190 : wxCommandEvent(wxEVT_COMMAND_FONTPICKER_CHANGED
, id
),
193 SetEventObject(generator
);
196 wxFont
GetFont() const { return m_font
; }
197 void SetFont(const wxFont
&c
) { m_font
= c
; }
199 // default copy ctor, assignment operator and dtor are ok
200 virtual wxEvent
*Clone() const { return new wxFontPickerEvent(*this); }
205 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFontPickerEvent
)
208 // ----------------------------------------------------------------------------
209 // event types and macros
210 // ----------------------------------------------------------------------------
212 typedef void (wxEvtHandler::*wxFontPickerEventFunction
)(wxFontPickerEvent
&);
214 #define wxFontPickerEventHandler(func) \
215 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFontPickerEventFunction, &func)
217 #define EVT_FONTPICKER_CHANGED(id, fn) \
218 wx__DECLARE_EVT1(wxEVT_COMMAND_FONTPICKER_CHANGED, id, wxFontPickerEventHandler(fn))
221 #endif // wxUSE_FONTPICKERCTRL
224 // _WX_FONTPICKER_H_BASE_