]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/fontpicker.cpp
Misc validity fixes to samples/xrc/rc/*.xrc.
[wxWidgets.git] / src / gtk / fontpicker.cpp
CommitLineData
ec376c8f
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/fontpicker.cpp
3// Purpose: implementation of wxFontButton
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// ----------------------------------------------------------------------------
13// headers
14// ----------------------------------------------------------------------------
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
03647350 19#if wxUSE_FONTPICKERCTRL
4ce7b1e4 20
ec376c8f
VZ
21#include "wx/fontpicker.h"
22
23#include "wx/fontutil.h" // for wxNativeFontInfo
24#include "wx/gtk/private.h"
25
ec376c8f
VZ
26// ============================================================================
27// implementation
28// ============================================================================
29
ec376c8f
VZ
30//-----------------------------------------------------------------------------
31// "font-set"
32//-----------------------------------------------------------------------------
33
34extern "C" {
35static void gtk_fontbutton_setfont_callback(GtkFontButton *widget,
36 wxFontButton *p)
37{
38 // update the m_selectedFont member of the wxFontButton
39 wxASSERT(p);
40 p->SetNativeFontInfo(gtk_font_button_get_font_name(widget));
41
42 // fire the colour-changed event
43 wxFontPickerEvent event(p, p->GetId(), p->GetSelectedFont());
937013e0 44 p->HandleWindowEvent(event);
ec376c8f
VZ
45}
46}
47
48//-----------------------------------------------------------------------------
49// wxFontButton
50//-----------------------------------------------------------------------------
51
ff654490 52IMPLEMENT_DYNAMIC_CLASS(wxFontButton, wxButton)
ec376c8f
VZ
53
54bool 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 )
59{
ff654490
VZ
60 if (!PreCreation( parent, pos, size ) ||
61 !wxControl::CreateBase(parent, id, pos, size, style, validator, name))
ec376c8f 62 {
ff654490
VZ
63 wxFAIL_MSG( wxT("wxFontButton creation failed") );
64 return false;
65 }
ec376c8f 66
ff654490 67 m_widget = gtk_font_button_new();
9ff9d30c 68 g_object_ref(m_widget);
ec376c8f 69
ff654490
VZ
70 // set initial font
71 m_selectedFont = initial.IsOk() ? initial : *wxNORMAL_FONT;
72 UpdateFont();
ec376c8f 73
ff654490
VZ
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);
ec376c8f 79
ff654490
VZ
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);
ec376c8f 82
ff654490
VZ
83 // GtkFontButton signals
84 g_signal_connect(m_widget, "font-set",
85 G_CALLBACK(gtk_fontbutton_setfont_callback), this);
ec376c8f
VZ
86
87
ff654490
VZ
88 m_parent->DoAddChild( this );
89
90 PostCreation(size);
91 SetInitialSize(size);
ec376c8f 92
ec376c8f
VZ
93 return true;
94}
95
96wxFontButton::~wxFontButton()
97{
98}
99
100void wxFontButton::UpdateFont()
101{
ff654490
VZ
102 const wxNativeFontInfo *info = m_selectedFont.GetNativeFontInfo();
103 wxASSERT_MSG( info, wxT("The fontbutton's internal font is not valid ?") );
ec376c8f 104
ff654490
VZ
105 const wxString& fontname = info->ToString();
106 gtk_font_button_set_font_name(GTK_FONT_BUTTON(m_widget), wxGTK_CONV(fontname));
ec376c8f
VZ
107}
108
ff654490 109#endif // wxUSE_FONTPICKERCTRL