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/control.h"
21 #include "wx/pickerbase.h"
24 class WXDLLIMPEXP_CORE wxFontPickerEvent
;
26 extern WXDLLEXPORT_DATA(const wxChar
) wxFontPickerWidgetNameStr
[];
27 extern WXDLLEXPORT_DATA(const wxChar
) wxFontPickerCtrlNameStr
[];
30 // ----------------------------------------------------------------------------
31 // wxFontPickerWidgetBase: a generic abstract interface which must be
32 // implemented by controls used by wxFontPickerCtrl
33 // ----------------------------------------------------------------------------
35 class WXDLLIMPEXP_CORE wxFontPickerWidgetBase
38 wxFontPickerWidgetBase() { m_selectedFont
= *wxNORMAL_FONT
; }
39 virtual ~wxFontPickerWidgetBase() {}
41 wxFont
GetSelectedFont() const
42 { return m_selectedFont
; }
43 virtual void SetSelectedFont(const wxFont
&f
)
44 { m_selectedFont
= f
; UpdateFont(); }
48 virtual void UpdateFont() = 0;
50 // the current font (may be invalid if none)
51 // NOTE: don't call this m_font as wxWindow::m_font already exists
52 wxFont m_selectedFont
;
55 // Styles which must be supported by all controls implementing wxFontPickerWidgetBase
56 // NB: these styles must be defined to carefully-chosen values to
57 // avoid conflicts with wxButton's styles
60 // keeps the label of the button updated with the fontface name + font size
61 // E.g. choosing "Times New Roman bold, italic with size 10" from the fontdialog,
62 // updates the wxFontButtonGeneric's label (overwriting any previous label)
63 // with the "Times New Roman, 10" text (only fontface + fontsize is displayed
64 // to avoid extralong labels).
65 #define wxFNTP_FONTDESC_AS_LABEL 0x0008
67 // uses the currently selected font to draw the label of the button
68 #define wxFNTP_USEFONT_FOR_LABEL 0x0010
70 #if defined(__WXGTK24__) // since GTK > 2.4, there is GtkFontButton
71 #include "wx/gtk/fontpicker.h"
72 #define wxFontPickerWidget wxFontButton
74 #include "wx/generic/fontpickerg.h"
75 #define wxFontPickerWidget wxGenericFontButton
79 // ----------------------------------------------------------------------------
80 // wxFontPickerCtrl specific flags
81 // ----------------------------------------------------------------------------
83 #define wxFNTP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
84 #define wxFNTP_DEFAULT_STYLE (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)
86 // not a style but rather the default value of the maximum pointsize allowed
87 #define wxFNTP_MAXPOINT_SIZE 100
90 // ----------------------------------------------------------------------------
91 // wxFontPickerCtrl: platform-independent class which embeds the
92 // platform-dependent wxFontPickerWidget andm if wxFNTP_USE_TEXTCTRL style is
93 // used, a textctrl next to it.
94 // ----------------------------------------------------------------------------
96 class WXDLLIMPEXP_CORE wxFontPickerCtrl
: public wxPickerBase
100 : m_bIgnoreNextTextCtrlUpdate(false),
101 m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE
)
105 virtual ~wxFontPickerCtrl() {}
108 wxFontPickerCtrl(wxWindow
*parent
,
110 const wxFont
& initial
= *wxNORMAL_FONT
,
111 const wxPoint
& pos
= wxDefaultPosition
,
112 const wxSize
& size
= wxDefaultSize
,
113 long style
= wxFNTP_DEFAULT_STYLE
,
114 const wxValidator
& validator
= wxDefaultValidator
,
115 const wxString
& name
= wxFontPickerCtrlNameStr
)
116 : m_bIgnoreNextTextCtrlUpdate(false),
117 m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE
)
119 Create(parent
, id
, initial
, pos
, size
, style
, validator
, name
);
122 bool Create(wxWindow
*parent
,
124 const wxFont
& initial
= *wxNORMAL_FONT
,
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
);
132 public: // public API
134 // get the font chosen
135 wxFont
GetSelectedFont() const
136 { return ((wxFontPickerWidget
*)m_picker
)->GetSelectedFont(); }
138 // sets currently displayed font
139 void SetSelectedFont(const wxFont
& f
);
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
; }
147 public: // internal functions
149 void UpdatePickerFromTextCtrl();
150 void UpdateTextCtrlFromPicker();
152 // event handler for our picker
153 void OnFontChange(wxFontPickerEvent
&);
155 // used to convert wxString <-> wxFont
156 virtual wxString
Font2String(const wxFont
&font
);
157 virtual wxFont
String2Font(const wxString
&font
);
159 // extracts the style for our picker from wxFontPickerCtrl's style
160 long GetPickerStyle(long style
) const
161 { return (style
& (wxFNTP_FONTDESC_AS_LABEL
|wxFNTP_USEFONT_FOR_LABEL
)); }
165 // true if the next UpdateTextCtrl() call is to ignore
166 bool m_bIgnoreNextTextCtrlUpdate
;
168 // the maximum pointsize allowed to the user
169 unsigned int m_nMaxPointSize
;
172 DECLARE_DYNAMIC_CLASS(wxFontPickerCtrl
)
176 // ----------------------------------------------------------------------------
177 // wxFontPickerEvent: used by wxFontPickerCtrl only
178 // ----------------------------------------------------------------------------
180 BEGIN_DECLARE_EVENT_TYPES()
181 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE
, wxEVT_COMMAND_FONTPICKER_CHANGED
, 1102)
182 END_DECLARE_EVENT_TYPES()
184 class WXDLLIMPEXP_CORE wxFontPickerEvent
: public wxCommandEvent
187 wxFontPickerEvent() {}
188 wxFontPickerEvent(wxObject
*generator
, int id
, const wxFont
&f
)
189 : wxCommandEvent(wxEVT_COMMAND_FONTPICKER_CHANGED
, id
),
192 SetEventObject(generator
);
195 wxFont
GetFont() const { return m_font
; }
196 void SetFont(const wxFont
&c
) { m_font
= c
; }
201 DECLARE_DYNAMIC_CLASS_NO_COPY(wxFontPickerEvent
)
204 // ----------------------------------------------------------------------------
205 // event types and macros
206 // ----------------------------------------------------------------------------
208 typedef void (wxEvtHandler::*wxFontPickerEventFunction
)(wxFontPickerEvent
&);
210 #define wxFontPickerEventHandler(func) \
211 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFontPickerEventFunction, &func)
213 #define EVT_FONTPICKER_CHANGED(id, fn) \
214 wx__DECLARE_EVT1(wxEVT_COMMAND_FONTPICKER_CHANGED, id, wxFontPickerEventHandler(fn))
216 #ifdef _WX_DEFINE_DATE_EVENTS_
217 DEFINE_EVENT_TYPE(wxEVT_COMMAND_FONTPICKER_CHANGED
)
219 IMPLEMENT_DYNAMIC_CLASS(wxFontPickerEvent
, wxCommandEvent
)
224 #endif // wxUSE_FONTPICKERCTRL
227 // _WX_FONTPICKER_H_BASE_