1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
3 // Name: fontpicker.cpp
4 // Purpose: Shows wxFontPickerCtrl
5 // Author: Francesco Montorsi
8 // Copyright: (c) 2006 Francesco Montorsi
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_FONTPICKERCTRL
29 // for all others, include the necessary headers
33 #include "wx/radiobox.h"
36 #include "wx/artprov.h"
38 #include "wx/stattext.h"
39 #include "wx/checkbox.h"
40 #include "wx/imaglist.h"
42 #include "wx/fontpicker.h"
45 #include "icons/fontpicker.xpm"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
54 PickerPage_Reset
= wxID_HIGHEST
,
59 // ----------------------------------------------------------------------------
60 // FontPickerWidgetsPage
61 // ----------------------------------------------------------------------------
63 class FontPickerWidgetsPage
: public WidgetsPage
66 FontPickerWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
67 virtual ~FontPickerWidgetsPage(){};
69 virtual wxControl
*GetWidget() const { return m_fontPicker
; }
70 virtual void RecreateWidget() { RecreatePicker(); }
72 // lazy creation of the content
73 virtual void CreateContent();
77 // called only once at first construction
80 // called to recreate an existing control
81 void RecreatePicker();
83 // restore the checkboxes state to the initial values
86 // get the initial style for the picker of the given kind
87 long GetPickerStyle();
90 void OnFontChange(wxFontPickerEvent
&ev
);
91 void OnCheckBox(wxCommandEvent
&ev
);
92 void OnButtonReset(wxCommandEvent
&ev
);
95 wxFontPickerCtrl
*m_fontPicker
;
101 wxCheckBox
*m_chkFontTextCtrl
,
102 *m_chkFontDescAsLabel
,
103 *m_chkFontUseFontForLabel
;
107 DECLARE_EVENT_TABLE()
108 DECLARE_WIDGETS_PAGE(FontPickerWidgetsPage
)
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 BEGIN_EVENT_TABLE(FontPickerWidgetsPage
, WidgetsPage
)
116 EVT_BUTTON(PickerPage_Reset
, FontPickerWidgetsPage::OnButtonReset
)
118 EVT_FONTPICKER_CHANGED(PickerPage_Font
, FontPickerWidgetsPage::OnFontChange
)
120 EVT_CHECKBOX(wxID_ANY
, FontPickerWidgetsPage::OnCheckBox
)
123 // ============================================================================
125 // ============================================================================
127 #if defined(__WXGTK24__)
128 #define FAMILY_CTRLS NATIVE_CTRLS
130 #define FAMILY_CTRLS GENERIC_CTRLS
133 IMPLEMENT_WIDGETS_PAGE(FontPickerWidgetsPage
, wxT("FontPicker"),
134 PICKER_CTRLS
| FAMILY_CTRLS
);
136 FontPickerWidgetsPage::FontPickerWidgetsPage(WidgetsBookCtrl
*book
,
137 wxImageList
*imaglist
)
138 : WidgetsPage(book
, imaglist
, fontpicker_xpm
)
142 void FontPickerWidgetsPage::CreateContent()
145 wxSizer
*boxleft
= new wxBoxSizer(wxVERTICAL
);
147 wxStaticBoxSizer
*fontbox
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("&FontPicker style"));
148 m_chkFontTextCtrl
= CreateCheckBoxAndAddToSizer(fontbox
, wxT("With textctrl"));
149 m_chkFontDescAsLabel
= CreateCheckBoxAndAddToSizer(fontbox
, wxT("Font desc as btn label"));
150 m_chkFontUseFontForLabel
= CreateCheckBoxAndAddToSizer(fontbox
, wxT("Use font for label"), false);
151 boxleft
->Add(fontbox
, 0, wxALL
|wxGROW
, 5);
153 boxleft
->Add(new wxButton(this, PickerPage_Reset
, wxT("&Reset")),
154 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 15);
156 Reset(); // set checkboxes state
163 m_sizer
= new wxBoxSizer(wxVERTICAL
);
164 m_sizer
->Add(1, 1, 1, wxGROW
| wxALL
, 5); // spacer
165 m_sizer
->Add(m_fontPicker
, 0, wxALIGN_CENTER
|wxALL
, 5);
166 m_sizer
->Add(1, 1, 1, wxGROW
| wxALL
, 5); // spacer
169 wxSizer
*sz
= new wxBoxSizer(wxHORIZONTAL
);
170 sz
->Add(boxleft
, 0, wxGROW
|wxALL
, 5);
171 sz
->Add(m_sizer
, 1, wxGROW
|wxALL
, 5);
176 void FontPickerWidgetsPage::CreatePicker()
180 m_fontPicker
= new wxFontPickerCtrl(this, PickerPage_Font
,
182 wxDefaultPosition
, wxDefaultSize
,
186 long FontPickerWidgetsPage::GetPickerStyle()
190 if ( m_chkFontTextCtrl
->GetValue() )
191 style
|= wxFNTP_USE_TEXTCTRL
;
193 if ( m_chkFontUseFontForLabel
->GetValue() )
194 style
|= wxFNTP_USEFONT_FOR_LABEL
;
196 if ( m_chkFontDescAsLabel
->GetValue() )
197 style
|= wxFNTP_FONTDESC_AS_LABEL
;
202 void FontPickerWidgetsPage::RecreatePicker()
206 m_sizer
->Insert(1, m_fontPicker
, 0, wxALIGN_CENTER
|wxALL
, 5);
211 void FontPickerWidgetsPage::Reset()
213 m_chkFontTextCtrl
->SetValue((wxFNTP_DEFAULT_STYLE
& wxFNTP_USE_TEXTCTRL
) != 0);
214 m_chkFontUseFontForLabel
->SetValue((wxFNTP_DEFAULT_STYLE
& wxFNTP_USEFONT_FOR_LABEL
) != 0);
215 m_chkFontDescAsLabel
->SetValue((wxFNTP_DEFAULT_STYLE
& wxFNTP_FONTDESC_AS_LABEL
) != 0);
219 // ----------------------------------------------------------------------------
221 // ----------------------------------------------------------------------------
223 void FontPickerWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
229 void FontPickerWidgetsPage::OnFontChange(wxFontPickerEvent
& event
)
231 wxLogMessage(wxT("The font changed to '%s' with size %d !"),
232 event
.GetFont().GetFaceName().c_str(), event
.GetFont().GetPointSize());
235 void FontPickerWidgetsPage::OnCheckBox(wxCommandEvent
&event
)
237 if (event
.GetEventObject() == m_chkFontTextCtrl
||
238 event
.GetEventObject() == m_chkFontDescAsLabel
||
239 event
.GetEventObject() == m_chkFontUseFontForLabel
)
243 #endif // wxUSE_FONTPICKERCTRL