]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/fontpicker.cpp
don't generate a scroll event when setting scroll position from scroll event handler
[wxWidgets.git] / src / gtk / fontpicker.cpp
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 #include <gdk/gdk.h>
28 #include <gtk/gtk.h>
29
30 // ============================================================================
31 // implementation
32 // ============================================================================
33
34 //-----------------------------------------------------------------------------
35 // "font-set"
36 //-----------------------------------------------------------------------------
37
38 extern "C" {
39 static void gtk_fontbutton_setfont_callback(GtkFontButton *widget,
40 wxFontButton *p)
41 {
42 // update the m_selectedFont member of the wxFontButton
43 wxASSERT(p);
44 p->SetNativeFontInfo(gtk_font_button_get_font_name(widget));
45
46 // fire the colour-changed event
47 wxFontPickerEvent event(p, p->GetId(), p->GetSelectedFont());
48 p->GetEventHandler()->ProcessEvent(event);
49 }
50 }
51
52 //-----------------------------------------------------------------------------
53 // wxFontButton
54 //-----------------------------------------------------------------------------
55
56 IMPLEMENT_DYNAMIC_CLASS(wxFontButton, wxGenericFontButton)
57
58 bool wxFontButton::Create( wxWindow *parent, wxWindowID id,
59 const wxFont &initial,
60 const wxPoint &pos, const wxSize &size,
61 long style, const wxValidator& validator,
62 const wxString &name )
63 {
64 if (!gtk_check_version(2,4,0))
65 {
66 m_needParent = true;
67
68 if (!PreCreation( parent, pos, size ) ||
69 !wxControl::CreateBase(parent, id, pos, size, style, validator, name))
70 {
71 wxFAIL_MSG( wxT("wxFontButton creation failed") );
72 return false;
73 }
74
75 m_widget = gtk_font_button_new();
76
77 // set initial font
78 m_selectedFont = initial;
79 UpdateFont();
80
81 // honour the fontbutton styles
82 bool showall = (style & wxFNTP_FONTDESC_AS_LABEL) != 0,
83 usefont = (style & wxFNTP_USEFONT_FOR_LABEL) != 0;
84 gtk_font_button_set_show_style(GTK_FONT_BUTTON(m_widget), showall);
85 gtk_font_button_set_show_size(GTK_FONT_BUTTON(m_widget), showall);
86
87 gtk_font_button_set_use_size(GTK_FONT_BUTTON(m_widget), usefont);
88 gtk_font_button_set_use_font(GTK_FONT_BUTTON(m_widget), usefont);
89
90 gtk_widget_show( GTK_WIDGET(m_widget) );
91
92 // GtkFontButton signals
93 g_signal_connect(m_widget, "font-set",
94 G_CALLBACK(gtk_fontbutton_setfont_callback), this);
95
96
97 m_parent->DoAddChild( this );
98
99 PostCreation(size);
100 SetBestSize(size);
101 }
102 else
103 return wxGenericFontButton::Create(parent, id, initial, pos, size,
104 style, validator, name);
105 return true;
106 }
107
108 wxFontButton::~wxFontButton()
109 {
110 }
111
112 void wxFontButton::UpdateFont()
113 {
114 if (!gtk_check_version(2,4,0))
115 {
116 const wxNativeFontInfo *info = m_selectedFont.GetNativeFontInfo();
117 wxASSERT_MSG( info, wxT("The fontbutton's internal font is not valid ?") );
118
119 const wxString& fontname = info->ToString();
120 gtk_font_button_set_font_name(GTK_FONT_BUTTON(m_widget), wxGTK_CONV(fontname));
121 }
122 else
123 wxGenericFontButton::UpdateFont();
124 }
125
126 #endif // wxUSE_FONTPICKERCTRL && defined(__WXGTK24__)