]> git.saurik.com Git - wxWidgets.git/blame - include/wx/fontpicker.h
Made additional error codes available.
[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
23class WXDLLIMPEXP_CORE wxFontPickerEvent;
24
25extern WXDLLEXPORT_DATA(const wxChar) wxFontPickerWidgetNameStr[];
26extern WXDLLEXPORT_DATA(const wxChar) wxFontPickerCtrlNameStr[];
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
69#if defined(__WXGTK24__) // since GTK > 2.4, there is GtkFontButton
70 #include "wx/gtk/fontpicker.h"
71 #define wxFontPickerWidget wxFontButton
72#else
73 #include "wx/generic/fontpickerg.h"
74 #define wxFontPickerWidget wxGenericFontButton
75#endif
76
77
78// ----------------------------------------------------------------------------
79// wxFontPickerCtrl specific flags
80// ----------------------------------------------------------------------------
81
556151f5
MW
82#define wxFNTP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
83#define wxFNTP_DEFAULT_STYLE (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)
ec376c8f
VZ
84
85// not a style but rather the default value of the maximum pointsize allowed
86#define wxFNTP_MAXPOINT_SIZE 100
87
88
89// ----------------------------------------------------------------------------
90// wxFontPickerCtrl: platform-independent class which embeds the
91// platform-dependent wxFontPickerWidget andm if wxFNTP_USE_TEXTCTRL style is
92// used, a textctrl next to it.
93// ----------------------------------------------------------------------------
94
95class WXDLLIMPEXP_CORE wxFontPickerCtrl : public wxPickerBase
96{
97public:
98 wxFontPickerCtrl()
99 : m_bIgnoreNextTextCtrlUpdate(false),
100 m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
101 {
102 }
103
104 virtual ~wxFontPickerCtrl() {}
105
106
107 wxFontPickerCtrl(wxWindow *parent,
108 wxWindowID id,
109 const wxFont& initial = *wxNORMAL_FONT,
110 const wxPoint& pos = wxDefaultPosition,
111 const wxSize& size = wxDefaultSize,
112 long style = wxFNTP_DEFAULT_STYLE,
113 const wxValidator& validator = wxDefaultValidator,
114 const wxString& name = wxFontPickerCtrlNameStr)
115 : m_bIgnoreNextTextCtrlUpdate(false),
116 m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
117 {
118 Create(parent, id, initial, pos, size, style, validator, name);
119 }
120
121 bool Create(wxWindow *parent,
122 wxWindowID id,
123 const wxFont& initial = *wxNORMAL_FONT,
124 const wxPoint& pos = wxDefaultPosition,
125 const wxSize& size = wxDefaultSize,
126 long style = wxFNTP_DEFAULT_STYLE,
127 const wxValidator& validator = wxDefaultValidator,
128 const wxString& name = wxFontPickerCtrlNameStr);
129
130
131public: // public API
132
133 // get the font chosen
134 wxFont GetSelectedFont() const
135 { return ((wxFontPickerWidget *)m_picker)->GetSelectedFont(); }
136
137 // sets currently displayed font
138 void SetSelectedFont(const wxFont& f);
139
140 // set/get the max pointsize
141 void SetMaxPointSize(unsigned int max)
142 { m_nMaxPointSize=max; }
143 unsigned int GetMaxPointSize() const
144 { return m_nMaxPointSize; }
145
146public: // internal functions
147
148 void UpdatePickerFromTextCtrl();
149 void UpdateTextCtrlFromPicker();
150
151 // event handler for our picker
152 void OnFontChange(wxFontPickerEvent &);
153
154 // used to convert wxString <-> wxFont
155 virtual wxString Font2String(const wxFont &font);
156 virtual wxFont String2Font(const wxString &font);
157
c757b5fe
PC
158protected:
159
ec376c8f
VZ
160 // extracts the style for our picker from wxFontPickerCtrl's style
161 long GetPickerStyle(long style) const
162 { return (style & (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)); }
163
ec376c8f
VZ
164 // true if the next UpdateTextCtrl() call is to ignore
165 bool m_bIgnoreNextTextCtrlUpdate;
166
167 // the maximum pointsize allowed to the user
168 unsigned int m_nMaxPointSize;
169
170private:
171 DECLARE_DYNAMIC_CLASS(wxFontPickerCtrl)
172};
173
174
175// ----------------------------------------------------------------------------
176// wxFontPickerEvent: used by wxFontPickerCtrl only
177// ----------------------------------------------------------------------------
178
179BEGIN_DECLARE_EVENT_TYPES()
180 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, wxEVT_COMMAND_FONTPICKER_CHANGED, 1102)
181END_DECLARE_EVENT_TYPES()
182
183class WXDLLIMPEXP_CORE wxFontPickerEvent : public wxCommandEvent
184{
185public:
186 wxFontPickerEvent() {}
187 wxFontPickerEvent(wxObject *generator, int id, const wxFont &f)
188 : wxCommandEvent(wxEVT_COMMAND_FONTPICKER_CHANGED, id),
189 m_font(f)
190 {
191 SetEventObject(generator);
192 }
193
194 wxFont GetFont() const { return m_font; }
195 void SetFont(const wxFont &c) { m_font = c; }
196
197private:
198 wxFont m_font;
199
200 DECLARE_DYNAMIC_CLASS_NO_COPY(wxFontPickerEvent)
201};
202
203// ----------------------------------------------------------------------------
204// event types and macros
205// ----------------------------------------------------------------------------
206
207typedef void (wxEvtHandler::*wxFontPickerEventFunction)(wxFontPickerEvent&);
208
209#define wxFontPickerEventHandler(func) \
210 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFontPickerEventFunction, &func)
211
212#define EVT_FONTPICKER_CHANGED(id, fn) \
213 wx__DECLARE_EVT1(wxEVT_COMMAND_FONTPICKER_CHANGED, id, wxFontPickerEventHandler(fn))
214
215#ifdef _WX_DEFINE_DATE_EVENTS_
216 DEFINE_EVENT_TYPE(wxEVT_COMMAND_FONTPICKER_CHANGED)
217
218 IMPLEMENT_DYNAMIC_CLASS(wxFontPickerEvent, wxCommandEvent)
219#endif
220
221
222
223#endif // wxUSE_FONTPICKERCTRL
224
225#endif
226 // _WX_FONTPICKER_H_BASE_