1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/fontpickerg.cpp
3 // Purpose: wxGenericFontButton class implementation
4 // Author: Francesco Montorsi
8 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_FONTPICKERCTRL
29 #include "wx/fontpicker.h"
31 #include "wx/fontdlg.h"
34 // ============================================================================
36 // ============================================================================
38 IMPLEMENT_DYNAMIC_CLASS(wxGenericFontButton
, wxButton
)
40 // ----------------------------------------------------------------------------
41 // wxGenericFontButton
42 // ----------------------------------------------------------------------------
44 bool wxGenericFontButton::Create( wxWindow
*parent
, wxWindowID id
,
45 const wxFont
&initial
, const wxPoint
&pos
,
46 const wxSize
&size
, long style
,
47 const wxValidator
& validator
, const wxString
&name
)
49 wxString label
= (style
& wxFNTP_FONTDESC_AS_LABEL
) ?
50 wxEmptyString
: // label will be updated by UpdateFont
54 if (!wxButton::Create( parent
, id
, label
, pos
,
55 size
, style
, validator
, name
))
57 wxFAIL_MSG( wxT("wxGenericFontButton creation failed") );
61 // and handle user clicks on it
62 Connect(GetId(), wxEVT_COMMAND_BUTTON_CLICKED
,
63 wxCommandEventHandler(wxGenericFontButton::OnButtonClick
),
66 m_selectedFont
= initial
.IsOk() ? initial
: *wxNORMAL_FONT
;
73 void wxGenericFontButton::InitFontData()
75 m_data
.SetAllowSymbols(true);
76 m_data
.SetColour(*wxBLACK
);
77 m_data
.EnableEffects(true);
80 void wxGenericFontButton::OnButtonClick(wxCommandEvent
& WXUNUSED(ev
))
82 // update the wxFontData to be shown in the the dialog
83 m_data
.SetInitialFont(m_selectedFont
);
85 // create the font dialog and display it
86 wxFontDialog
dlg(this, m_data
);
87 if (dlg
.ShowModal() == wxID_OK
)
89 m_data
= dlg
.GetFontData();
90 SetSelectedFont(m_data
.GetChosenFont());
93 wxFontPickerEvent
event(this, GetId(), m_selectedFont
);
94 GetEventHandler()->ProcessEvent(event
);
98 void wxGenericFontButton::UpdateFont()
100 if ( !m_selectedFont
.Ok() )
103 SetForegroundColour(m_data
.GetColour());
105 if (HasFlag(wxFNTP_USEFONT_FOR_LABEL
))
107 // use currently selected font for the label...
108 wxButton::SetFont(m_selectedFont
);
111 if (HasFlag(wxFNTP_FONTDESC_AS_LABEL
))
113 SetLabel(wxString::Format(wxT("%s, %d"),
114 m_selectedFont
.GetFaceName().c_str(),
115 m_selectedFont
.GetPointSize()));
119 #endif // wxUSE_FONTPICKERCTRL