1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
3 // Name: fontpicker.cpp
4 // Purpose: Shows wxFontPickerCtrl
5 // Author: Francesco Montorsi
7 // Copyright: (c) 2006 Francesco Montorsi
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
26 #if wxUSE_FONTPICKERCTRL
28 // for all others, include the necessary headers
32 #include "wx/radiobox.h"
35 #include "wx/artprov.h"
37 #include "wx/stattext.h"
38 #include "wx/checkbox.h"
39 #include "wx/imaglist.h"
41 #include "wx/fontpicker.h"
44 #include "icons/fontpicker.xpm"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
53 PickerPage_Reset
= wxID_HIGHEST
,
58 // ----------------------------------------------------------------------------
59 // FontPickerWidgetsPage
60 // ----------------------------------------------------------------------------
62 class FontPickerWidgetsPage
: public WidgetsPage
65 FontPickerWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
66 virtual ~FontPickerWidgetsPage(){};
68 virtual wxControl
*GetWidget() const { return m_fontPicker
; }
69 virtual void RecreateWidget() { RecreatePicker(); }
71 // lazy creation of the content
72 virtual void CreateContent();
76 // called only once at first construction
79 // called to recreate an existing control
80 void RecreatePicker();
82 // restore the checkboxes state to the initial values
85 // get the initial style for the picker of the given kind
86 long GetPickerStyle();
89 void OnFontChange(wxFontPickerEvent
&ev
);
90 void OnCheckBox(wxCommandEvent
&ev
);
91 void OnButtonReset(wxCommandEvent
&ev
);
94 wxFontPickerCtrl
*m_fontPicker
;
100 wxCheckBox
*m_chkFontTextCtrl
,
101 *m_chkFontDescAsLabel
,
102 *m_chkFontUseFontForLabel
;
106 DECLARE_EVENT_TABLE()
107 DECLARE_WIDGETS_PAGE(FontPickerWidgetsPage
)
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
114 BEGIN_EVENT_TABLE(FontPickerWidgetsPage
, WidgetsPage
)
115 EVT_BUTTON(PickerPage_Reset
, FontPickerWidgetsPage::OnButtonReset
)
117 EVT_FONTPICKER_CHANGED(PickerPage_Font
, FontPickerWidgetsPage::OnFontChange
)
119 EVT_CHECKBOX(wxID_ANY
, FontPickerWidgetsPage::OnCheckBox
)
122 // ============================================================================
124 // ============================================================================
126 #if defined(__WXGTK24__)
127 #define FAMILY_CTRLS NATIVE_CTRLS
129 #define FAMILY_CTRLS GENERIC_CTRLS
132 IMPLEMENT_WIDGETS_PAGE(FontPickerWidgetsPage
, wxT("FontPicker"),
133 PICKER_CTRLS
| FAMILY_CTRLS
);
135 FontPickerWidgetsPage::FontPickerWidgetsPage(WidgetsBookCtrl
*book
,
136 wxImageList
*imaglist
)
137 : WidgetsPage(book
, imaglist
, fontpicker_xpm
)
141 void FontPickerWidgetsPage::CreateContent()
144 wxSizer
*boxleft
= new wxBoxSizer(wxVERTICAL
);
146 wxStaticBoxSizer
*fontbox
= new wxStaticBoxSizer(wxVERTICAL
, this, wxT("&FontPicker style"));
147 m_chkFontTextCtrl
= CreateCheckBoxAndAddToSizer(fontbox
, wxT("With textctrl"));
148 m_chkFontDescAsLabel
= CreateCheckBoxAndAddToSizer(fontbox
, wxT("Font desc as btn label"));
149 m_chkFontUseFontForLabel
= CreateCheckBoxAndAddToSizer(fontbox
, wxT("Use font for label"));
150 boxleft
->Add(fontbox
, 0, wxALL
|wxGROW
, 5);
152 boxleft
->Add(new wxButton(this, PickerPage_Reset
, wxT("&Reset")),
153 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 15);
155 Reset(); // set checkboxes state
162 m_sizer
= new wxBoxSizer(wxVERTICAL
);
163 m_sizer
->Add(1, 1, 1, wxGROW
| wxALL
, 5); // spacer
164 m_sizer
->Add(m_fontPicker
, 0, wxALIGN_CENTER
|wxALL
, 5);
165 m_sizer
->Add(1, 1, 1, wxGROW
| wxALL
, 5); // spacer
168 wxSizer
*sz
= new wxBoxSizer(wxHORIZONTAL
);
169 sz
->Add(boxleft
, 0, wxGROW
|wxALL
, 5);
170 sz
->Add(m_sizer
, 1, wxGROW
|wxALL
, 5);
175 void FontPickerWidgetsPage::CreatePicker()
179 m_fontPicker
= new wxFontPickerCtrl(this, PickerPage_Font
,
181 wxDefaultPosition
, wxDefaultSize
,
185 long FontPickerWidgetsPage::GetPickerStyle()
189 if ( m_chkFontTextCtrl
->GetValue() )
190 style
|= wxFNTP_USE_TEXTCTRL
;
192 if ( m_chkFontUseFontForLabel
->GetValue() )
193 style
|= wxFNTP_USEFONT_FOR_LABEL
;
195 if ( m_chkFontDescAsLabel
->GetValue() )
196 style
|= wxFNTP_FONTDESC_AS_LABEL
;
201 void FontPickerWidgetsPage::RecreatePicker()
205 m_sizer
->Insert(1, m_fontPicker
, 0, wxALIGN_CENTER
|wxALL
, 5);
210 void FontPickerWidgetsPage::Reset()
212 m_chkFontTextCtrl
->SetValue((wxFNTP_DEFAULT_STYLE
& wxFNTP_USE_TEXTCTRL
) != 0);
213 m_chkFontUseFontForLabel
->SetValue((wxFNTP_DEFAULT_STYLE
& wxFNTP_USEFONT_FOR_LABEL
) != 0);
214 m_chkFontDescAsLabel
->SetValue((wxFNTP_DEFAULT_STYLE
& wxFNTP_FONTDESC_AS_LABEL
) != 0);
218 // ----------------------------------------------------------------------------
220 // ----------------------------------------------------------------------------
222 void FontPickerWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
228 void FontPickerWidgetsPage::OnFontChange(wxFontPickerEvent
& event
)
230 wxLogMessage(wxT("The font changed to '%s' with size %d !"),
231 event
.GetFont().GetFaceName().c_str(), event
.GetFont().GetPointSize());
234 void FontPickerWidgetsPage::OnCheckBox(wxCommandEvent
&event
)
236 if (event
.GetEventObject() == m_chkFontTextCtrl
||
237 event
.GetEventObject() == m_chkFontDescAsLabel
||
238 event
.GetEventObject() == m_chkFontUseFontForLabel
)
242 #endif // wxUSE_FONTPICKERCTRL