1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/fontpicker.h
3 // Purpose: wxFontPickerCtrl base header
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_FONTPICKER_H_BASE_
12 #define _WX_FONTPICKER_H_BASE_
17 #if wxUSE_FONTPICKERCTRL
19 #include "wx/pickerbase.h"
22 class WXDLLIMPEXP_FWD_CORE wxFontPickerEvent
;
24 extern WXDLLIMPEXP_DATA_CORE(const char) wxFontPickerWidgetNameStr
[];
25 extern WXDLLIMPEXP_DATA_CORE(const char) wxFontPickerCtrlNameStr
[];
28 // ----------------------------------------------------------------------------
29 // wxFontPickerWidgetBase: a generic abstract interface which must be
30 // implemented by controls used by wxFontPickerCtrl
31 // ----------------------------------------------------------------------------
33 class WXDLLIMPEXP_CORE wxFontPickerWidgetBase
36 wxFontPickerWidgetBase() { m_selectedFont
= *wxNORMAL_FONT
; }
37 virtual ~wxFontPickerWidgetBase() {}
39 wxFont
GetSelectedFont() const
40 { return m_selectedFont
; }
41 virtual void SetSelectedFont(const wxFont
&f
)
42 { m_selectedFont
= f
; UpdateFont(); }
46 virtual void UpdateFont() = 0;
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
;
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
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
65 // uses the currently selected font to draw the label of the button
66 #define wxFNTP_USEFONT_FOR_LABEL 0x0010
68 #define wxFONTBTN_DEFAULT_STYLE \
69 (wxFNTP_FONTDESC_AS_LABEL | wxFNTP_USEFONT_FOR_LABEL)
71 // native version currently only exists in wxGTK2
72 #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
73 #include "wx/gtk/fontpicker.h"
74 #define wxFontPickerWidget wxFontButton
76 #include "wx/generic/fontpickerg.h"
77 #define wxFontPickerWidget wxGenericFontButton
81 // ----------------------------------------------------------------------------
82 // wxFontPickerCtrl specific flags
83 // ----------------------------------------------------------------------------
85 #define wxFNTP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
86 #define wxFNTP_DEFAULT_STYLE (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)
88 // not a style but rather the default value of the maximum pointsize allowed
89 #define wxFNTP_MAXPOINT_SIZE 100
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 // ----------------------------------------------------------------------------
98 class WXDLLIMPEXP_CORE wxFontPickerCtrl
: public wxPickerBase
102 : m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE
)
106 virtual ~wxFontPickerCtrl() {}
109 wxFontPickerCtrl(wxWindow
*parent
,
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
)
119 Create(parent
, id
, initial
, pos
, size
, style
, validator
, name
);
122 bool Create(wxWindow
*parent
,
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
);
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
);
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
)); }
165 // the maximum pointsize allowed to the user
166 unsigned int m_nMaxPointSize
;
169 DECLARE_DYNAMIC_CLASS(wxFontPickerCtrl
)
173 // ----------------------------------------------------------------------------
174 // wxFontPickerEvent: used by wxFontPickerCtrl only
175 // ----------------------------------------------------------------------------
177 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_FONTPICKER_CHANGED
, wxFontPickerEvent
);
179 class WXDLLIMPEXP_CORE wxFontPickerEvent
: public wxCommandEvent
182 wxFontPickerEvent() {}
183 wxFontPickerEvent(wxObject
*generator
, int id
, const wxFont
&f
)
184 : wxCommandEvent(wxEVT_FONTPICKER_CHANGED
, id
),
187 SetEventObject(generator
);
190 wxFont
GetFont() const { return m_font
; }
191 void SetFont(const wxFont
&c
) { m_font
= c
; }
193 // default copy ctor, assignment operator and dtor are ok
194 virtual wxEvent
*Clone() const { return new wxFontPickerEvent(*this); }
199 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFontPickerEvent
)
202 // ----------------------------------------------------------------------------
203 // event types and macros
204 // ----------------------------------------------------------------------------
206 typedef void (wxEvtHandler::*wxFontPickerEventFunction
)(wxFontPickerEvent
&);
208 #define wxFontPickerEventHandler(func) \
209 wxEVENT_HANDLER_CAST(wxFontPickerEventFunction, func)
211 #define EVT_FONTPICKER_CHANGED(id, fn) \
212 wx__DECLARE_EVT1(wxEVT_FONTPICKER_CHANGED, id, wxFontPickerEventHandler(fn))
214 // old wxEVT_COMMAND_* constants
215 #define wxEVT_COMMAND_FONTPICKER_CHANGED wxEVT_FONTPICKER_CHANGED
218 #endif // wxUSE_FONTPICKERCTRL
221 // _WX_FONTPICKER_H_BASE_