]>
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 | if (parent) | |
131 | gtk_window_set_transient_for(GTK_WINDOW(m_widget), | |
132 | GTK_WINDOW(parent->m_widget)); | |
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 | wxFont font = m_fontData.GetInitialFont(); | |
156 | if( font.Ok() ) | |
157 | { | |
158 | const wxNativeFontInfo *info = font.GetNativeFontInfo(); | |
159 | ||
160 | if ( info ) | |
161 | { | |
162 | ||
163 | #ifdef __WXGTK20__ | |
164 | const wxString& fontname = info->ToString(); | |
165 | #else | |
166 | const wxString& fontname = info->GetXFontName(); | |
167 | if ( !fontname ) | |
168 | font.GetInternalFont(); | |
169 | #endif | |
170 | gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname)); | |
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 | ||
179 | return TRUE; | |
180 | } | |
181 | ||
182 | wxFontDialog::~wxFontDialog() | |
183 | { | |
184 | } | |
185 | ||
186 | void wxFontDialog::SetChosenFont(const char *fontname) | |
187 | { | |
188 | m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) )); | |
189 | } | |
190 | ||
191 | #endif // wxUSE_FONTDLG | |
192 | ||
193 | #endif // GPE | |
194 |