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