]>
Commit | Line | Data |
---|---|---|
ec376c8f VZ |
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 | ||
c757b5fe | 27 | #if wxUSE_FONTPICKERCTRL |
ec376c8f VZ |
28 | |
29 | #include "wx/fontpicker.h" | |
c757b5fe | 30 | |
ec376c8f VZ |
31 | #include "wx/fontdlg.h" |
32 | ||
33 | ||
34 | // ============================================================================ | |
35 | // implementation | |
36 | // ============================================================================ | |
37 | ||
ec376c8f VZ |
38 | IMPLEMENT_DYNAMIC_CLASS(wxGenericFontButton, wxButton) |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
41 | // wxGenericFontButton | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
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) | |
48 | { | |
49 | wxString label = (style & wxFNTP_FONTDESC_AS_LABEL) ? | |
77e82897 VZ |
50 | wxString() : // label will be updated by UpdateFont |
51 | _("Choose font"); | |
ec376c8f VZ |
52 | |
53 | // create this button | |
54 | if (!wxButton::Create( parent, id, label, pos, | |
55 | size, style, validator, name )) | |
56 | { | |
57 | wxFAIL_MSG( wxT("wxGenericFontButton creation failed") ); | |
58 | return false; | |
59 | } | |
60 | ||
61 | // and handle user clicks on it | |
ce7fe42e | 62 | Connect(GetId(), wxEVT_BUTTON, |
ec376c8f VZ |
63 | wxCommandEventHandler(wxGenericFontButton::OnButtonClick), |
64 | NULL, this); | |
65 | ||
305329c2 | 66 | m_selectedFont = initial.IsOk() ? initial : *wxNORMAL_FONT; |
ec376c8f VZ |
67 | UpdateFont(); |
68 | InitFontData(); | |
69 | ||
70 | return true; | |
71 | } | |
72 | ||
73 | void wxGenericFontButton::InitFontData() | |
74 | { | |
3fc69ebc VZ |
75 | m_data.SetAllowSymbols(true); |
76 | m_data.SetColour(*wxBLACK); | |
77 | m_data.EnableEffects(true); | |
ec376c8f VZ |
78 | } |
79 | ||
80 | void wxGenericFontButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev)) | |
81 | { | |
4c51a665 | 82 | // update the wxFontData to be shown in the dialog |
3fc69ebc | 83 | m_data.SetInitialFont(m_selectedFont); |
ec376c8f VZ |
84 | |
85 | // create the font dialog and display it | |
3fc69ebc | 86 | wxFontDialog dlg(this, m_data); |
ec376c8f VZ |
87 | if (dlg.ShowModal() == wxID_OK) |
88 | { | |
3fc69ebc VZ |
89 | m_data = dlg.GetFontData(); |
90 | SetSelectedFont(m_data.GetChosenFont()); | |
ec376c8f VZ |
91 | |
92 | // fire an event | |
93 | wxFontPickerEvent event(this, GetId(), m_selectedFont); | |
94 | GetEventHandler()->ProcessEvent(event); | |
95 | } | |
96 | } | |
97 | ||
98 | void wxGenericFontButton::UpdateFont() | |
99 | { | |
a1b806b9 | 100 | if ( !m_selectedFont.IsOk() ) |
ec376c8f VZ |
101 | return; |
102 | ||
3fc69ebc | 103 | SetForegroundColour(m_data.GetColour()); |
ec376c8f VZ |
104 | |
105 | if (HasFlag(wxFNTP_USEFONT_FOR_LABEL)) | |
106 | { | |
107 | // use currently selected font for the label... | |
108 | wxButton::SetFont(m_selectedFont); | |
109 | } | |
110 | ||
111 | if (HasFlag(wxFNTP_FONTDESC_AS_LABEL)) | |
112 | { | |
113 | SetLabel(wxString::Format(wxT("%s, %d"), | |
114 | m_selectedFont.GetFaceName().c_str(), | |
115 | m_selectedFont.GetPointSize())); | |
116 | } | |
117 | } | |
118 | ||
119 | #endif // wxUSE_FONTPICKERCTRL |