]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/fontdlg.cpp
derive wxComboBox from wxItemContainer (via wxComboBoxBase) in wxGTK (patch 802882)
[wxWidgets.git] / src / gtk / fontdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/fontdlg.cpp
3 // Purpose: wxFontDialog
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "fontdlg.h"
12 #endif
13
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #include "wx/defs.h"
18
19 #if wxUSE_FONTDLG
20
21 #include "wx/fontutil.h"
22 #include "wx/fontdlg.h"
23 #include "wx/utils.h"
24 #include "wx/intl.h"
25 #include "wx/debug.h"
26 #include "wx/msgdlg.h"
27
28 #include "wx/gtk/private.h"
29
30 //-----------------------------------------------------------------------------
31 // idle system
32 //-----------------------------------------------------------------------------
33
34 extern void wxapp_install_idle_handler();
35 extern bool g_isIdle;
36
37 //-----------------------------------------------------------------------------
38 // "delete_event"
39 //-----------------------------------------------------------------------------
40
41 static
42 bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
43 {
44 if (g_isIdle)
45 wxapp_install_idle_handler();
46
47 /*
48 printf( "OnDelete from " );
49 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
50 printf( win->GetClassInfo()->GetClassName() );
51 printf( ".\n" );
52 */
53
54 win->Close();
55
56 return TRUE;
57 }
58
59 //-----------------------------------------------------------------------------
60 // "clicked" for OK-button
61 //-----------------------------------------------------------------------------
62
63 static
64 void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
65 {
66 if (g_isIdle)
67 wxapp_install_idle_handler();
68
69 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
70
71 #ifndef __WXGTK20__
72 GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg);
73
74 if (!gfont)
75 {
76 wxMessageBox(_("Please choose a valid font."), _("Error"),
77 wxOK | wxICON_ERROR);
78 return;
79 }
80 #endif
81
82 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
83 dialog->SetChosenFont( fontname);
84
85 g_free( fontname );
86
87 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
88 event.SetEventObject( dialog );
89 dialog->GetEventHandler()->ProcessEvent( event );
90 }
91
92 //-----------------------------------------------------------------------------
93 // "clicked" for Cancel-button
94 //-----------------------------------------------------------------------------
95
96 static
97 void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
98 {
99 if (g_isIdle)
100 wxapp_install_idle_handler();
101
102 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
103 event.SetEventObject( dialog );
104 dialog->GetEventHandler()->ProcessEvent( event );
105 }
106
107 //-----------------------------------------------------------------------------
108 // wxFontDialog
109 //-----------------------------------------------------------------------------
110
111 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
112
113 bool wxFontDialog::DoCreate(wxWindow *parent)
114 {
115 m_needParent = FALSE;
116
117 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
118 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
119 wxDefaultValidator, wxT("fontdialog") ))
120 {
121 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
122 return FALSE;
123 }
124
125 wxString m_message( _("Choose font") );
126 m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
127
128 int x = (gdk_screen_width () - 400) / 2;
129 int y = (gdk_screen_height () - 400) / 2;
130 gtk_widget_set_uposition( m_widget, x, y );
131
132 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
133
134 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
135 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this );
136
137 #ifndef __WXGTK20__
138 // strange way to internationalize
139 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->ok_button) ), _("OK") );
140 #endif
141
142 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
143 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this );
144
145 #ifndef __WXGTK20__
146 // strange way to internationalize
147 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->cancel_button) ), _("Cancel") );
148 #endif
149
150 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
151 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
152
153 #ifndef __WXGTK20__
154 wxFont font = m_fontData.GetInitialFont();
155 if( font.Ok() )
156 {
157 wxNativeFontInfo *info = font.GetNativeFontInfo();
158
159 if ( info )
160 {
161 const wxString& fontname = info->GetXFontName();
162 if ( !fontname )
163 font.GetInternalFont();
164 gtk_font_selection_dialog_set_font_name
165 (
166 sel,
167 wxConvCurrent->cWX2MB(fontname)
168 );
169 }
170 else
171 {
172 // this is not supposed to happen!
173 wxFAIL_MSG(_T("font is ok but no native font info?"));
174 }
175 }
176 #endif
177
178 return TRUE;
179 }
180
181 wxFontDialog::~wxFontDialog()
182 {
183 }
184
185 void wxFontDialog::SetChosenFont(const char *fontname)
186 {
187 m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) ));
188 }
189
190 #endif // wxUSE_FONTDLG
191