]> git.saurik.com Git - wxWidgets.git/blame - include/wx/fontpicker.h
support SDK < 10.6, fixes #14902
[wxWidgets.git] / include / wx / fontpicker.h
CommitLineData
ec376c8f
VZ
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// RCS-ID: $Id$
9// Licence: wxWindows Licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_FONTPICKER_H_BASE_
13#define _WX_FONTPICKER_H_BASE_
14
15#include "wx/defs.h"
16
17
18#if wxUSE_FONTPICKERCTRL
19
ec376c8f
VZ
20#include "wx/pickerbase.h"
21
22
b5dbe15d 23class WXDLLIMPEXP_FWD_CORE wxFontPickerEvent;
ec376c8f 24
53a2db12
FM
25extern WXDLLIMPEXP_DATA_CORE(const char) wxFontPickerWidgetNameStr[];
26extern WXDLLIMPEXP_DATA_CORE(const char) wxFontPickerCtrlNameStr[];
ec376c8f
VZ
27
28
29// ----------------------------------------------------------------------------
30// wxFontPickerWidgetBase: a generic abstract interface which must be
31// implemented by controls used by wxFontPickerCtrl
32// ----------------------------------------------------------------------------
33
34class WXDLLIMPEXP_CORE wxFontPickerWidgetBase
35{
36public:
37 wxFontPickerWidgetBase() { m_selectedFont = *wxNORMAL_FONT; }
38 virtual ~wxFontPickerWidgetBase() {}
39
40 wxFont GetSelectedFont() const
41 { return m_selectedFont; }
42 virtual void SetSelectedFont(const wxFont &f)
43 { m_selectedFont = f; UpdateFont(); }
44
45protected:
46
47 virtual void UpdateFont() = 0;
48
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;
52};
53
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
57
58
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
65
66// uses the currently selected font to draw the label of the button
67#define wxFNTP_USEFONT_FOR_LABEL 0x0010
68
ff654490
VZ
69#define wxFONTBTN_DEFAULT_STYLE \
70 (wxFNTP_FONTDESC_AS_LABEL | wxFNTP_USEFONT_FOR_LABEL)
71
72// native version currently only exists in wxGTK2
73#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
ec376c8f
VZ
74 #include "wx/gtk/fontpicker.h"
75 #define wxFontPickerWidget wxFontButton
76#else
77 #include "wx/generic/fontpickerg.h"
78 #define wxFontPickerWidget wxGenericFontButton
79#endif
80
81
82// ----------------------------------------------------------------------------
83// wxFontPickerCtrl specific flags
84// ----------------------------------------------------------------------------
85
556151f5
MW
86#define wxFNTP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
87#define wxFNTP_DEFAULT_STYLE (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)
ec376c8f
VZ
88
89// not a style but rather the default value of the maximum pointsize allowed
90#define wxFNTP_MAXPOINT_SIZE 100
91
92
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// ----------------------------------------------------------------------------
98
99class WXDLLIMPEXP_CORE wxFontPickerCtrl : public wxPickerBase
100{
101public:
102 wxFontPickerCtrl()
44b72116 103 : m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
ec376c8f
VZ
104 {
105 }
106
107 virtual ~wxFontPickerCtrl() {}
108
109
110 wxFontPickerCtrl(wxWindow *parent,
111 wxWindowID id,
305329c2 112 const wxFont& initial = wxNullFont,
ec376c8f
VZ
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)
44b72116 118 : m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
ec376c8f
VZ
119 {
120 Create(parent, id, initial, pos, size, style, validator, name);
121 }
122
123 bool Create(wxWindow *parent,
124 wxWindowID id,
305329c2 125 const wxFont& initial = wxNullFont,
ec376c8f
VZ
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);
131
132
133public: // public API
134
135 // get the font chosen
136 wxFont GetSelectedFont() const
137 { return ((wxFontPickerWidget *)m_picker)->GetSelectedFont(); }
138
139 // sets currently displayed font
140 void SetSelectedFont(const wxFont& f);
141
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; }
147
148public: // internal functions
149
150 void UpdatePickerFromTextCtrl();
151 void UpdateTextCtrlFromPicker();
152
153 // event handler for our picker
154 void OnFontChange(wxFontPickerEvent &);
155
156 // used to convert wxString <-> wxFont
157 virtual wxString Font2String(const wxFont &font);
158 virtual wxFont String2Font(const wxString &font);
159
c757b5fe
PC
160protected:
161
ec376c8f
VZ
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)); }
165
ec376c8f
VZ
166 // the maximum pointsize allowed to the user
167 unsigned int m_nMaxPointSize;
168
169private:
170 DECLARE_DYNAMIC_CLASS(wxFontPickerCtrl)
171};
172
173
174// ----------------------------------------------------------------------------
175// wxFontPickerEvent: used by wxFontPickerCtrl only
176// ----------------------------------------------------------------------------
177
9b11752c 178wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_FONTPICKER_CHANGED, wxFontPickerEvent );
ec376c8f
VZ
179
180class WXDLLIMPEXP_CORE wxFontPickerEvent : public wxCommandEvent
181{
182public:
183 wxFontPickerEvent() {}
184 wxFontPickerEvent(wxObject *generator, int id, const wxFont &f)
185 : wxCommandEvent(wxEVT_COMMAND_FONTPICKER_CHANGED, id),
186 m_font(f)
187 {
188 SetEventObject(generator);
189 }
190
191 wxFont GetFont() const { return m_font; }
192 void SetFont(const wxFont &c) { m_font = c; }
193
258b2ca6
RD
194 // default copy ctor, assignment operator and dtor are ok
195 virtual wxEvent *Clone() const { return new wxFontPickerEvent(*this); }
196
ec376c8f
VZ
197private:
198 wxFont m_font;
199
258b2ca6 200 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFontPickerEvent)
ec376c8f
VZ
201};
202
203// ----------------------------------------------------------------------------
204// event types and macros
205// ----------------------------------------------------------------------------
206
207typedef void (wxEvtHandler::*wxFontPickerEventFunction)(wxFontPickerEvent&);
208
209#define wxFontPickerEventHandler(func) \
3c778901 210 wxEVENT_HANDLER_CAST(wxFontPickerEventFunction, func)
ec376c8f
VZ
211
212#define EVT_FONTPICKER_CHANGED(id, fn) \
213 wx__DECLARE_EVT1(wxEVT_COMMAND_FONTPICKER_CHANGED, id, wxFontPickerEventHandler(fn))
214
ec376c8f
VZ
215
216#endif // wxUSE_FONTPICKERCTRL
217
218#endif
219 // _WX_FONTPICKER_H_BASE_