1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/fontpicker.cpp
3 // Purpose: implementation of wxFontButton
4 // Author: Francesco Montorsi
8 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
20 #include "wx/gtk/private.h"
21 #include "wx/fontpicker.h"
23 #include "wx/fontutil.h" // for wxNativeFontInfo
24 #include "wx/gtk/private.h"
31 // ============================================================================
33 // ============================================================================
35 #if wxUSE_FONTPICKERCTRL && defined(__WXGTK24__)
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
42 static void gtk_fontbutton_setfont_callback(GtkFontButton
*widget
,
45 // update the m_selectedFont member of the wxFontButton
47 p
->SetNativeFontInfo(gtk_font_button_get_font_name(widget
));
49 // fire the colour-changed event
50 wxFontPickerEvent
event(p
, p
->GetId(), p
->GetSelectedFont());
51 p
->GetEventHandler()->ProcessEvent(event
);
55 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
59 IMPLEMENT_DYNAMIC_CLASS(wxFontButton
, wxGenericFontButton
)
61 bool wxFontButton::Create( wxWindow
*parent
, wxWindowID id
,
62 const wxFont
&initial
,
63 const wxPoint
&pos
, const wxSize
&size
,
64 long style
, const wxValidator
& validator
,
65 const wxString
&name
)
67 if (!gtk_check_version(2,4,0))
71 if (!PreCreation( parent
, pos
, size
) ||
72 !wxControl::CreateBase(parent
, id
, pos
, size
, style
, validator
, name
))
74 wxFAIL_MSG( wxT("wxFontButton creation failed") );
78 m_widget
= gtk_font_button_new();
81 m_selectedFont
= initial
;
84 // honour the fontbutton styles
85 bool showall
= (style
& wxFNTP_FONTDESC_AS_LABEL
) != 0,
86 usefont
= (style
& wxFNTP_USEFONT_FOR_LABEL
) != 0;
87 gtk_font_button_set_show_style(GTK_FONT_BUTTON(m_widget
), showall
);
88 gtk_font_button_set_show_size(GTK_FONT_BUTTON(m_widget
), showall
);
90 gtk_font_button_set_use_size(GTK_FONT_BUTTON(m_widget
), usefont
);
91 gtk_font_button_set_use_font(GTK_FONT_BUTTON(m_widget
), usefont
);
93 gtk_widget_show( GTK_WIDGET(m_widget
) );
95 // GtkFontButton signals
96 g_signal_connect(m_widget
, "font-set",
97 G_CALLBACK(gtk_fontbutton_setfont_callback
), this);
100 m_parent
->DoAddChild( this );
106 return wxGenericFontButton::Create(parent
, id
, initial
, pos
, size
,
107 style
, validator
, name
);
111 wxFontButton::~wxFontButton()
115 void wxFontButton::UpdateFont()
117 if (!gtk_check_version(2,4,0))
119 const wxNativeFontInfo
*info
= m_selectedFont
.GetNativeFontInfo();
120 wxASSERT_MSG( info
, wxT("The fontbutton's internal font is not valid ?") );
122 const wxString
& fontname
= info
->ToString();
123 gtk_font_button_set_font_name(GTK_FONT_BUTTON(m_widget
), wxGTK_CONV(fontname
));
126 wxGenericFontButton::UpdateFont();
129 #endif // wxUSE_FONTPICKERCTRL