]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/fontdlg.cpp
Update for building zlib as an os2 dll
[wxWidgets.git] / src / gtk / fontdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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/fontdlg.h"
15 #include "wx/utils.h"
16 #include "wx/intl.h"
17 #include "wx/debug.h"
18 #include "wx/msgdlg.h"
19
20 #ifdef __VMS__
21 #define gtk_font_selection_dialog_get_type gtk_font_selection_dialog_get_t
22 #define gtk_font_selection_dialog_get_font gtk_font_selection_dialog_get_f
23 #define gtk_font_selection_dialog_get_font_name gtk_font_selection_dialog_getnf
24 #endif
25 #include <gtk/gtk.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 #ifdef __WXGTK12__
61 static
62 void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
63 {
64 if (g_isIdle)
65 wxapp_install_idle_handler();
66
67 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
68 GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg);
69
70 if (!gfont)
71 {
72 wxMessageBox(_("Please choose a valid font."), _("Error"), wxOK);
73 return;
74 }
75
76 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
77
78 // extract the relevant bits from it
79 wxString xregistry, xencoding;
80 char *dash = strrchr(fontname, '-'); // find the last dash
81 if ( dash )
82 {
83 xencoding = dash + 1;
84 *dash = '\0';
85 dash = strrchr(fontname, '-'); // the last before one
86 if ( dash )
87 {
88 xregistry = dash + 1;
89 }
90 else
91 {
92 wxFAIL_MSG( wxT("no registry in X font spec?") );
93 }
94
95 // restore the dash we changed to NUL above
96 *(fontname + strlen(fontname)) = '-';
97 }
98 else
99 {
100 wxFAIL_MSG( wxT("no encoding in X font spec?") );
101 }
102
103 // transfer the X registry/encoding to wxFontData - they are used by
104 // wxFontMapper after wxFontDialog returns
105 wxFontData& fontdata = dialog->m_fontData;
106
107 // we ignore the facename here - should be enough to choose an arbitrary
108 // one if the registry/encoding are specified
109 // dialog->m_fontData.EncodingInfo().facename = xfamily;
110 fontdata.EncodingInfo().xregistry = xregistry;
111 fontdata.EncodingInfo().xencoding = xencoding;
112
113 // pass fontdata to wxFont ctor so that it can get the encoding from there
114 // if it is already known (otherwise it will try to deduce it itself)
115 dialog->m_fontData.SetChosenFont( wxFont(fontname, fontdata) );
116
117 g_free( fontname );
118
119 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
120 event.SetEventObject( dialog );
121 dialog->GetEventHandler()->ProcessEvent( event );
122 }
123 #endif // GTK+ 1.2 and later only
124
125 //-----------------------------------------------------------------------------
126 // "clicked" for Cancel-button
127 //-----------------------------------------------------------------------------
128
129 static
130 void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
131 {
132 if (g_isIdle)
133 wxapp_install_idle_handler();
134
135 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
136 event.SetEventObject( dialog );
137 dialog->GetEventHandler()->ProcessEvent( event );
138 }
139
140 //-----------------------------------------------------------------------------
141 // wxFontDialog
142 //-----------------------------------------------------------------------------
143
144 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog,wxDialog)
145
146 wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
147 : m_fontData(*fontdata)
148 {
149 m_needParent = FALSE;
150
151 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
152 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
153 wxDefaultValidator, wxT("fontdialog") ))
154 {
155 wxFAIL_MSG( wxT("wxXX creation failed") );
156 return;
157 }
158
159 wxString m_message( _("Choose font") );
160 m_widget = gtk_font_selection_dialog_new( m_message.mbc_str() );
161
162 int x = (gdk_screen_width () - 400) / 2;
163 int y = (gdk_screen_height () - 400) / 2;
164 gtk_widget_set_uposition( m_widget, x, y );
165
166 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
167
168 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
169 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this );
170
171 // strange way to internationalize
172 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->ok_button)->child ), wxConvCurrent->cWX2MB(_("OK")) );
173
174 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
175 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this );
176
177 // strange way to internationalize
178 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->cancel_button)->child ), wxConvCurrent->cWX2MB(_("Cancel")) );
179
180 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
181 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
182 }
183
184 wxFontDialog::~wxFontDialog()
185 {
186 }
187