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