]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/fontpicker.cpp
Better temporary fix.
[wxWidgets.git] / src / gtk / fontpicker.cpp
... / ...
CommitLineData
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 && defined(__WXGTK24__)
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
35extern "C" {
36static 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->GetEventHandler()->ProcessEvent(event);
46}
47}
48
49//-----------------------------------------------------------------------------
50// wxFontButton
51//-----------------------------------------------------------------------------
52
53IMPLEMENT_DYNAMIC_CLASS(wxFontButton, wxGenericFontButton)
54
55bool 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 (!gtk_check_version(2,4,0))
62 {
63 m_needParent = true;
64 m_acceptsFocus = true;
65
66 if (!PreCreation( parent, pos, size ) ||
67 !wxControl::CreateBase(parent, id, pos, size, style, validator, name))
68 {
69 wxFAIL_MSG( wxT("wxFontButton creation failed") );
70 return false;
71 }
72
73 m_widget = gtk_font_button_new();
74
75 // set initial font
76 m_selectedFont = initial;
77 UpdateFont();
78
79 // honour the fontbutton styles
80 bool showall = (style & wxFNTP_FONTDESC_AS_LABEL) != 0,
81 usefont = (style & wxFNTP_USEFONT_FOR_LABEL) != 0;
82 gtk_font_button_set_show_style(GTK_FONT_BUTTON(m_widget), showall);
83 gtk_font_button_set_show_size(GTK_FONT_BUTTON(m_widget), showall);
84
85 gtk_font_button_set_use_size(GTK_FONT_BUTTON(m_widget), usefont);
86 gtk_font_button_set_use_font(GTK_FONT_BUTTON(m_widget), usefont);
87
88 gtk_widget_show( GTK_WIDGET(m_widget) );
89
90 // GtkFontButton signals
91 g_signal_connect(m_widget, "font-set",
92 G_CALLBACK(gtk_fontbutton_setfont_callback), this);
93
94
95 m_parent->DoAddChild( this );
96
97 PostCreation(size);
98 SetBestSize(size);
99 }
100 else
101 return wxGenericFontButton::Create(parent, id, initial, pos, size,
102 style, validator, name);
103 return true;
104}
105
106wxFontButton::~wxFontButton()
107{
108}
109
110void wxFontButton::UpdateFont()
111{
112 if (!gtk_check_version(2,4,0))
113 {
114 const wxNativeFontInfo *info = m_selectedFont.GetNativeFontInfo();
115 wxASSERT_MSG( info, wxT("The fontbutton's internal font is not valid ?") );
116
117 const wxString& fontname = info->ToString();
118 gtk_font_button_set_font_name(GTK_FONT_BUTTON(m_widget), wxGTK_CONV(fontname));
119 }
120 else
121 wxGenericFontButton::UpdateFont();
122}
123
124#endif // wxUSE_FONTPICKERCTRL && defined(__WXGTK24__)