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"
28 #include "wx/window.h"
31 #include "wx/fontpicker.h"
32 #include "wx/fontdlg.h"
35 // ============================================================================
37 // ============================================================================
39 #if wxUSE_FONTPICKERCTRL
41 wxFontData
wxGenericFontButton::ms_data
;
42 IMPLEMENT_DYNAMIC_CLASS(wxGenericFontButton
, wxButton
)
44 // ----------------------------------------------------------------------------
45 // wxGenericFontButton
46 // ----------------------------------------------------------------------------
48 bool wxGenericFontButton::Create( wxWindow
*parent
, wxWindowID id
,
49 const wxFont
&initial
, const wxPoint
&pos
,
50 const wxSize
&size
, long style
,
51 const wxValidator
& validator
, const wxString
&name
)
53 wxString label
= (style
& wxFNTP_FONTDESC_AS_LABEL
) ?
54 wxEmptyString
: // label will be updated by UpdateFont
58 if (!wxButton::Create( parent
, id
, label
, pos
,
59 size
, style
, validator
, name
))
61 wxFAIL_MSG( wxT("wxGenericFontButton creation failed") );
65 // and handle user clicks on it
66 Connect(wxEVT_COMMAND_BUTTON_CLICKED
,
67 wxCommandEventHandler(wxGenericFontButton::OnButtonClick
),
70 m_selectedFont
= initial
;
77 void wxGenericFontButton::InitFontData()
79 ms_data
.SetAllowSymbols(true);
80 ms_data
.SetColour(*wxBLACK
);
81 ms_data
.EnableEffects(true);
84 void wxGenericFontButton::OnButtonClick(wxCommandEvent
& WXUNUSED(ev
))
86 // update the wxFontData to be shown in the the dialog
87 ms_data
.SetInitialFont(m_selectedFont
);
89 // create the font dialog and display it
90 wxFontDialog
dlg(this, ms_data
);
91 if (dlg
.ShowModal() == wxID_OK
)
93 ms_data
= dlg
.GetFontData();
94 SetSelectedFont(ms_data
.GetChosenFont());
97 wxFontPickerEvent
event(this, GetId(), m_selectedFont
);
98 GetEventHandler()->ProcessEvent(event
);
102 void wxGenericFontButton::UpdateFont()
104 if ( !m_selectedFont
.Ok() )
107 SetForegroundColour(ms_data
.GetColour());
109 if (HasFlag(wxFNTP_USEFONT_FOR_LABEL
))
111 // use currently selected font for the label...
112 wxButton::SetFont(m_selectedFont
);
115 if (HasFlag(wxFNTP_FONTDESC_AS_LABEL
))
117 SetLabel(wxString::Format(wxT("%s, %d"),
118 m_selectedFont
.GetFaceName().c_str(),
119 m_selectedFont
.GetPointSize()));
123 #endif // wxUSE_FONTPICKERCTRL