]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/fontdlg.cpp
Remove scroll units duplication in wxGrid to fix setting them.
[wxWidgets.git] / src / gtk1 / fontdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #if wxUSE_FONTDLG && !defined(__WXGPE__)
14
15 #include "wx/fontdlg.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/intl.h"
19 #include "wx/utils.h"
20 #include "wx/msgdlg.h"
21 #endif
22
23 #include "wx/fontutil.h"
24
25 #include "wx/gtk1/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 extern "C" {
39 static
40 bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
41 {
42 if (g_isIdle)
43 wxapp_install_idle_handler();
44
45 /*
46 printf( "OnDelete from " );
47 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
48 printf( win->GetClassInfo()->GetClassName() );
49 printf( ".\n" );
50 */
51
52 win->Close();
53
54 return true;
55 }
56 }
57
58 //-----------------------------------------------------------------------------
59 // "clicked" for OK-button
60 //-----------------------------------------------------------------------------
61
62 extern "C" {
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 GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg);
72
73 if (!gfont)
74 {
75 wxMessageBox(_("Please choose a valid font."), _("Error"),
76 wxOK | wxICON_ERROR);
77 return;
78 }
79
80 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
81 dialog->SetChosenFont( fontname);
82
83 g_free( fontname );
84
85 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
86 event.SetEventObject( dialog );
87 dialog->HandleWindowEvent( event );
88 }
89 }
90
91 //-----------------------------------------------------------------------------
92 // "clicked" for Cancel-button
93 //-----------------------------------------------------------------------------
94
95 extern "C" {
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->HandleWindowEvent( event );
105 }
106 }
107
108 //-----------------------------------------------------------------------------
109 // wxFontDialog
110 //-----------------------------------------------------------------------------
111
112 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
113
114 bool wxFontDialog::DoCreate(wxWindow *parent)
115 {
116 m_needParent = false;
117
118 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
119 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
120 wxDefaultValidator, wxT("fontdialog") ))
121 {
122 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
123 return false;
124 }
125
126 wxString m_message( _("Choose font") );
127 m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
128
129 if (parent)
130 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
131 GTK_WINDOW(parent->m_widget));
132
133 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
134
135 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
136 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this );
137
138 // strange way to internationalize
139 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->ok_button) ), _("OK") );
140
141 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
142 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this );
143
144 // strange way to internationalize
145 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->cancel_button) ), _("Cancel") );
146
147 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
148 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
149
150 wxFont font = m_fontData.GetInitialFont();
151 if( font.Ok() )
152 {
153 const wxNativeFontInfo *info = font.GetNativeFontInfo();
154
155 if ( info )
156 {
157
158 const wxString& fontname = info->GetXFontName();
159 if ( !fontname )
160 font.GetInternalFont();
161
162 gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname));
163 }
164 else
165 {
166 // this is not supposed to happen!
167 wxFAIL_MSG(wxT("font is ok but no native font info?"));
168 }
169 }
170
171 return true;
172 }
173
174 wxFontDialog::~wxFontDialog()
175 {
176 }
177
178 void wxFontDialog::SetChosenFont(const char *fontname)
179 {
180 m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) ));
181 }
182
183 #endif // wxUSE_FONTDLG && !defined(__WXGPE__)