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