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 wxFontData
wxGenericFontButton::ms_data
;
39 IMPLEMENT_DYNAMIC_CLASS(wxGenericFontButton
, wxButton
)
41 // ----------------------------------------------------------------------------
42 // wxGenericFontButton
43 // ----------------------------------------------------------------------------
45 bool wxGenericFontButton::Create( wxWindow
*parent
, wxWindowID id
,
46 const wxFont
&initial
, const wxPoint
&pos
,
47 const wxSize
&size
, long style
,
48 const wxValidator
& validator
, const wxString
&name
)
50 wxString label
= (style
& wxFNTP_FONTDESC_AS_LABEL
) ?
51 wxEmptyString
: // label will be updated by UpdateFont
55 if (!wxButton::Create( parent
, id
, label
, pos
,
56 size
, style
, validator
, name
))
58 wxFAIL_MSG( wxT("wxGenericFontButton creation failed") );
62 // and handle user clicks on it
63 Connect(wxEVT_COMMAND_BUTTON_CLICKED
,
64 wxCommandEventHandler(wxGenericFontButton::OnButtonClick
),
67 m_selectedFont
= initial
;
74 void wxGenericFontButton::InitFontData()
76 ms_data
.SetAllowSymbols(true);
77 ms_data
.SetColour(*wxBLACK
);
78 ms_data
.EnableEffects(true);
81 void wxGenericFontButton::OnButtonClick(wxCommandEvent
& WXUNUSED(ev
))
83 // update the wxFontData to be shown in the the dialog
84 ms_data
.SetInitialFont(m_selectedFont
);
86 // create the font dialog and display it
87 wxFontDialog
dlg(this, ms_data
);
88 if (dlg
.ShowModal() == wxID_OK
)
90 ms_data
= dlg
.GetFontData();
91 SetSelectedFont(ms_data
.GetChosenFont());
94 wxFontPickerEvent
event(this, GetId(), m_selectedFont
);
95 GetEventHandler()->ProcessEvent(event
);
99 void wxGenericFontButton::UpdateFont()
101 if ( !m_selectedFont
.Ok() )
104 SetForegroundColour(ms_data
.GetColour());
106 if (HasFlag(wxFNTP_USEFONT_FOR_LABEL
))
108 // use currently selected font for the label...
109 wxButton::SetFont(m_selectedFont
);
112 if (HasFlag(wxFNTP_FONTDESC_AS_LABEL
))
114 SetLabel(wxString::Format(wxT("%s, %d"),
115 m_selectedFont
.GetFaceName().c_str(),
116 m_selectedFont
.GetPointSize()));
120 #endif // wxUSE_FONTPICKERCTRL