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_nMaxPointSize(wxFNTP_MAXPOINT_SIZE
)
107 virtual ~wxFontPickerCtrl() {}
110 wxFontPickerCtrl(wxWindow
*parent
,
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
)
120 Create(parent
, id
, initial
, pos
, size
, style
, validator
, name
);
123 bool Create(wxWindow
*parent
,
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
);
133 public: // public API
135 // get the font chosen
136 wxFont
GetSelectedFont() const
137 { return ((wxFontPickerWidget
*)m_picker
)->GetSelectedFont(); }
139 // sets currently displayed font
140 void SetSelectedFont(const wxFont
& f
);
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
; }
148 public: // internal functions
150 void UpdatePickerFromTextCtrl();
151 void UpdateTextCtrlFromPicker();
153 // event handler for our picker
154 void OnFontChange(wxFontPickerEvent
&);
156 // used to convert wxString <-> wxFont
157 virtual wxString
Font2String(const wxFont
&font
);
158 virtual wxFont
String2Font(const wxString
&font
);
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
)); }
166 // the maximum pointsize allowed to the user
167 unsigned int m_nMaxPointSize
;
170 DECLARE_DYNAMIC_CLASS(wxFontPickerCtrl
)
174 // ----------------------------------------------------------------------------
175 // wxFontPickerEvent: used by wxFontPickerCtrl only
176 // ----------------------------------------------------------------------------
178 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_FONTPICKER_CHANGED
, wxFontPickerEvent
);
180 class WXDLLIMPEXP_CORE wxFontPickerEvent
: public wxCommandEvent
183 wxFontPickerEvent() {}
184 wxFontPickerEvent(wxObject
*generator
, int id
, const wxFont
&f
)
185 : wxCommandEvent(wxEVT_FONTPICKER_CHANGED
, id
),
188 SetEventObject(generator
);
191 wxFont
GetFont() const { return m_font
; }
192 void SetFont(const wxFont
&c
) { m_font
= c
; }
194 // default copy ctor, assignment operator and dtor are ok
195 virtual wxEvent
*Clone() const { return new wxFontPickerEvent(*this); }
200 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFontPickerEvent
)
203 // ----------------------------------------------------------------------------
204 // event types and macros
205 // ----------------------------------------------------------------------------
207 typedef void (wxEvtHandler::*wxFontPickerEventFunction
)(wxFontPickerEvent
&);
209 #define wxFontPickerEventHandler(func) \
210 wxEVENT_HANDLER_CAST(wxFontPickerEventFunction, func)
212 #define EVT_FONTPICKER_CHANGED(id, fn) \
213 wx__DECLARE_EVT1(wxEVT_FONTPICKER_CHANGED, id, wxFontPickerEventHandler(fn))
215 // old wxEVT_COMMAND_* constants
216 #define wxEVT_COMMAND_FONTPICKER_CHANGED wxEVT_FONTPICKER_CHANGED
219 #endif // wxUSE_FONTPICKERCTRL
222 // _WX_FONTPICKER_H_BASE_