]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/fontpicker.cpp
avoid duplicating wxWindow::HandleCommand() in wxFrame, only handle the commands...
[wxWidgets.git] / src / gtk / fontpicker.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/fontpicker.cpp
3 // Purpose: implementation of wxFontButton
4 // Author: Francesco Montorsi
5 // Modified By:
6 // Created: 15/04/2006
7 // Id: $Id$
8 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12
13 // ----------------------------------------------------------------------------
14 // headers
15 // ----------------------------------------------------------------------------
16
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
19
20 #if wxUSE_FONTPICKERCTRL
21
22 #include "wx/fontpicker.h"
23
24 #include "wx/fontutil.h" // for wxNativeFontInfo
25 #include "wx/gtk/private.h"
26
27 // ============================================================================
28 // implementation
29 // ============================================================================
30
31 //-----------------------------------------------------------------------------
32 // "font-set"
33 //-----------------------------------------------------------------------------
34
35 extern "C" {
36 static void gtk_fontbutton_setfont_callback(GtkFontButton *widget,
37 wxFontButton *p)
38 {
39 // update the m_selectedFont member of the wxFontButton
40 wxASSERT(p);
41 p->SetNativeFontInfo(gtk_font_button_get_font_name(widget));
42
43 // fire the colour-changed event
44 wxFontPickerEvent event(p, p->GetId(), p->GetSelectedFont());
45 p->HandleWindowEvent(event);
46 }
47 }
48
49 //-----------------------------------------------------------------------------
50 // wxFontButton
51 //-----------------------------------------------------------------------------
52
53 IMPLEMENT_DYNAMIC_CLASS(wxFontButton, wxButton)
54
55 bool wxFontButton::Create( wxWindow *parent, wxWindowID id,
56 const wxFont &initial,
57 const wxPoint &pos, const wxSize &size,
58 long style, const wxValidator& validator,
59 const wxString &name )
60 {
61 if (!PreCreation( parent, pos, size ) ||
62 !wxControl::CreateBase(parent, id, pos, size, style, validator, name))
63 {
64 wxFAIL_MSG( wxT("wxFontButton creation failed") );
65 return false;
66 }
67
68 m_widget = gtk_font_button_new();
69
70 // set initial font
71 m_selectedFont = initial.IsOk() ? initial : *wxNORMAL_FONT;
72 UpdateFont();
73
74 // honour the fontbutton styles
75 bool showall = (style & wxFNTP_FONTDESC_AS_LABEL) != 0,
76 usefont = (style & wxFNTP_USEFONT_FOR_LABEL) != 0;
77 gtk_font_button_set_show_style(GTK_FONT_BUTTON(m_widget), showall);
78 gtk_font_button_set_show_size(GTK_FONT_BUTTON(m_widget), showall);
79
80 gtk_font_button_set_use_size(GTK_FONT_BUTTON(m_widget), usefont);
81 gtk_font_button_set_use_font(GTK_FONT_BUTTON(m_widget), usefont);
82
83 gtk_widget_show(m_widget);
84
85 // GtkFontButton signals
86 g_signal_connect(m_widget, "font-set",
87 G_CALLBACK(gtk_fontbutton_setfont_callback), this);
88
89
90 m_parent->DoAddChild( this );
91
92 PostCreation(size);
93 SetInitialSize(size);
94
95 return true;
96 }
97
98 wxFontButton::~wxFontButton()
99 {
100 }
101
102 void wxFontButton::UpdateFont()
103 {
104 const wxNativeFontInfo *info = m_selectedFont.GetNativeFontInfo();
105 wxASSERT_MSG( info, wxT("The fontbutton's internal font is not valid ?") );
106
107 const wxString& fontname = info->ToString();
108 gtk_font_button_set_font_name(GTK_FONT_BUTTON(m_widget), wxGTK_CONV(fontname));
109 }
110
111 #endif // wxUSE_FONTPICKERCTRL