]> git.saurik.com Git - wxWidgets.git/blob - src/generic/fontpickerg.cpp
Warning fix.
[wxWidgets.git] / src / generic / fontpickerg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/fontpickerg.cpp
3 // Purpose: wxGenericFontButton class implementation
4 // Author: Francesco Montorsi
5 // Modified by:
6 // Created: 15/04/2006
7 // RCS-ID: $Id$
8 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/window.h"
29 #endif //WX_PRECOMP
30
31 #include "wx/fontpicker.h"
32 #include "wx/fontdlg.h"
33
34
35 // ============================================================================
36 // implementation
37 // ============================================================================
38
39 #if wxUSE_FONTPICKERCTRL
40
41 wxFontData wxGenericFontButton::ms_data;
42 IMPLEMENT_DYNAMIC_CLASS(wxGenericFontButton, wxButton)
43
44 // ----------------------------------------------------------------------------
45 // wxGenericFontButton
46 // ----------------------------------------------------------------------------
47
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)
52 {
53 wxString label = (style & wxFNTP_FONTDESC_AS_LABEL) ?
54 wxEmptyString : // label will be updated by UpdateFont
55 wxT("Choose font");
56
57 // create this button
58 if (!wxButton::Create( parent, id, label, pos,
59 size, style, validator, name ))
60 {
61 wxFAIL_MSG( wxT("wxGenericFontButton creation failed") );
62 return false;
63 }
64
65 // and handle user clicks on it
66 Connect(wxEVT_COMMAND_BUTTON_CLICKED,
67 wxCommandEventHandler(wxGenericFontButton::OnButtonClick),
68 NULL, this);
69
70 m_selectedFont = initial;
71 UpdateFont();
72 InitFontData();
73
74 return true;
75 }
76
77 void wxGenericFontButton::InitFontData()
78 {
79 ms_data.SetAllowSymbols(true);
80 ms_data.SetColour(*wxBLACK);
81 ms_data.EnableEffects(true);
82 }
83
84 void wxGenericFontButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev))
85 {
86 // update the wxFontData to be shown in the the dialog
87 ms_data.SetInitialFont(m_selectedFont);
88
89 // create the font dialog and display it
90 wxFontDialog dlg(this, ms_data);
91 if (dlg.ShowModal() == wxID_OK)
92 {
93 ms_data = dlg.GetFontData();
94 SetSelectedFont(ms_data.GetChosenFont());
95
96 // fire an event
97 wxFontPickerEvent event(this, GetId(), m_selectedFont);
98 GetEventHandler()->ProcessEvent(event);
99 }
100 }
101
102 void wxGenericFontButton::UpdateFont()
103 {
104 if ( !m_selectedFont.Ok() )
105 return;
106
107 SetForegroundColour(ms_data.GetColour());
108
109 if (HasFlag(wxFNTP_USEFONT_FOR_LABEL))
110 {
111 // use currently selected font for the label...
112 wxButton::SetFont(m_selectedFont);
113 }
114
115 if (HasFlag(wxFNTP_FONTDESC_AS_LABEL))
116 {
117 SetLabel(wxString::Format(wxT("%s, %d"),
118 m_selectedFont.GetFaceName().c_str(),
119 m_selectedFont.GetPointSize()));
120 }
121 }
122
123 #endif // wxUSE_FONTPICKERCTRL