]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/fontpickerg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/fontpickerg.cpp
3 // Purpose: wxGenericFontButton class implementation
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #if wxUSE_FONTPICKERCTRL
28 #include "wx/fontpicker.h"
30 #include "wx/fontdlg.h"
33 // ============================================================================
35 // ============================================================================
37 IMPLEMENT_DYNAMIC_CLASS(wxGenericFontButton
, wxButton
)
39 // ----------------------------------------------------------------------------
40 // wxGenericFontButton
41 // ----------------------------------------------------------------------------
43 bool wxGenericFontButton::Create( wxWindow
*parent
, wxWindowID id
,
44 const wxFont
&initial
, const wxPoint
&pos
,
45 const wxSize
&size
, long style
,
46 const wxValidator
& validator
, const wxString
&name
)
48 wxString label
= (style
& wxFNTP_FONTDESC_AS_LABEL
) ?
49 wxString() : // label will be updated by UpdateFont
53 if (!wxButton::Create( parent
, id
, label
, pos
,
54 size
, style
, validator
, name
))
56 wxFAIL_MSG( wxT("wxGenericFontButton creation failed") );
60 // and handle user clicks on it
61 Connect(GetId(), wxEVT_BUTTON
,
62 wxCommandEventHandler(wxGenericFontButton::OnButtonClick
),
65 m_selectedFont
= initial
.IsOk() ? initial
: *wxNORMAL_FONT
;
72 void wxGenericFontButton::InitFontData()
74 m_data
.SetAllowSymbols(true);
75 m_data
.SetColour(*wxBLACK
);
76 m_data
.EnableEffects(true);
79 void wxGenericFontButton::OnButtonClick(wxCommandEvent
& WXUNUSED(ev
))
81 // update the wxFontData to be shown in the dialog
82 m_data
.SetInitialFont(m_selectedFont
);
84 // create the font dialog and display it
85 wxFontDialog
dlg(this, m_data
);
86 if (dlg
.ShowModal() == wxID_OK
)
88 m_data
= dlg
.GetFontData();
89 SetSelectedFont(m_data
.GetChosenFont());
92 wxFontPickerEvent
event(this, GetId(), m_selectedFont
);
93 GetEventHandler()->ProcessEvent(event
);
97 void wxGenericFontButton::UpdateFont()
99 if ( !m_selectedFont
.IsOk() )
102 SetForegroundColour(m_data
.GetColour());
104 if (HasFlag(wxFNTP_USEFONT_FOR_LABEL
))
106 // use currently selected font for the label...
107 wxButton::SetFont(m_selectedFont
);
110 if (HasFlag(wxFNTP_FONTDESC_AS_LABEL
))
112 SetLabel(wxString::Format(wxT("%s, %d"),
113 m_selectedFont
.GetFaceName().c_str(),
114 m_selectedFont
.GetPointSize()));
118 #endif // wxUSE_FONTPICKERCTRL