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