1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/fontpicker.cpp
3 // Purpose: implementation of wxFontButton
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 // ----------------------------------------------------------------------------
14 // ----------------------------------------------------------------------------
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
19 #if wxUSE_FONTPICKERCTRL
21 #include "wx/fontpicker.h"
23 #include "wx/fontutil.h" // for wxNativeFontInfo
24 #include "wx/gtk/private.h"
26 // ============================================================================
28 // ============================================================================
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
35 static void gtk_fontbutton_setfont_callback(GtkFontButton
*widget
,
38 // update the m_selectedFont member of the wxFontButton
40 p
->SetNativeFontInfo(gtk_font_button_get_font_name(widget
));
42 // fire the colour-changed event
43 wxFontPickerEvent
event(p
, p
->GetId(), p
->GetSelectedFont());
44 p
->HandleWindowEvent(event
);
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 IMPLEMENT_DYNAMIC_CLASS(wxFontButton
, wxButton
)
54 bool wxFontButton::Create( wxWindow
*parent
, wxWindowID id
,
55 const wxFont
&initial
,
56 const wxPoint
&pos
, const wxSize
&size
,
57 long style
, const wxValidator
& validator
,
58 const wxString
&name
)
60 if (!PreCreation( parent
, pos
, size
) ||
61 !wxControl::CreateBase(parent
, id
, pos
, size
, style
, validator
, name
))
63 wxFAIL_MSG( wxT("wxFontButton creation failed") );
67 m_widget
= gtk_font_button_new();
68 g_object_ref(m_widget
);
71 m_selectedFont
= initial
.IsOk() ? initial
: *wxNORMAL_FONT
;
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
);
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
);
83 // GtkFontButton signals
84 g_signal_connect(m_widget
, "font-set",
85 G_CALLBACK(gtk_fontbutton_setfont_callback
), this);
88 m_parent
->DoAddChild( this );
96 wxFontButton::~wxFontButton()
100 void wxFontButton::UpdateFont()
102 const wxNativeFontInfo
*info
= m_selectedFont
.GetNativeFontInfo();
103 wxASSERT_MSG( info
, wxT("The fontbutton's internal font is not valid ?") );
105 const wxString
& fontname
= info
->ToString();
106 gtk_font_button_set_font_name(GTK_FONT_BUTTON(m_widget
), wxGTK_CONV(fontname
));
109 #endif // wxUSE_FONTPICKERCTRL