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 #if wxUSE_FONTPICKERCTRL
22 #include "wx/fontpicker.h"
24 #include "wx/fontutil.h" // for wxNativeFontInfo
25 #include "wx/gtk/private.h"
27 // ============================================================================
29 // ============================================================================
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
36 static void gtk_fontbutton_setfont_callback(GtkFontButton
*widget
,
39 // update the m_selectedFont member of the wxFontButton
41 p
->SetNativeFontInfo(gtk_font_button_get_font_name(widget
));
43 // fire the colour-changed event
44 wxFontPickerEvent
event(p
, p
->GetId(), p
->GetSelectedFont());
45 p
->GetEventHandler()->ProcessEvent(event
);
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
53 IMPLEMENT_DYNAMIC_CLASS(wxFontButton
, wxGenericFontButton
)
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
)
61 if (!gtk_check_version(2,4,0))
63 if (!PreCreation( parent
, pos
, size
) ||
64 !wxControl::CreateBase(parent
, id
, pos
, size
, style
, validator
, name
))
66 wxFAIL_MSG( wxT("wxFontButton creation failed") );
70 m_widget
= gtk_font_button_new();
73 m_selectedFont
= initial
.IsOk() ? initial
: *wxNORMAL_FONT
;
76 // honour the fontbutton styles
77 bool showall
= (style
& wxFNTP_FONTDESC_AS_LABEL
) != 0,
78 usefont
= (style
& wxFNTP_USEFONT_FOR_LABEL
) != 0;
79 gtk_font_button_set_show_style(GTK_FONT_BUTTON(m_widget
), showall
);
80 gtk_font_button_set_show_size(GTK_FONT_BUTTON(m_widget
), showall
);
82 gtk_font_button_set_use_size(GTK_FONT_BUTTON(m_widget
), usefont
);
83 gtk_font_button_set_use_font(GTK_FONT_BUTTON(m_widget
), usefont
);
85 gtk_widget_show(m_widget
);
87 // GtkFontButton signals
88 g_signal_connect(m_widget
, "font-set",
89 G_CALLBACK(gtk_fontbutton_setfont_callback
), this);
92 m_parent
->DoAddChild( this );
98 return wxGenericFontButton::Create(parent
, id
, initial
, pos
, size
,
99 style
, validator
, name
);
103 wxFontButton::~wxFontButton()
107 void wxFontButton::UpdateFont()
109 if (!gtk_check_version(2,4,0))
111 const wxNativeFontInfo
*info
= m_selectedFont
.GetNativeFontInfo();
112 wxASSERT_MSG( info
, wxT("The fontbutton's internal font is not valid ?") );
114 const wxString
& fontname
= info
->ToString();
115 gtk_font_button_set_font_name(GTK_FONT_BUTTON(m_widget
), wxGTK_CONV(fontname
));
118 wxGenericFontButton::UpdateFont();
121 #endif // wxUSE_FONTPICKERCTRL