]>
Commit | Line | Data |
---|---|---|
6dfaa4e5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
1e6feb95 | 2 | // Name: gtk/fontdlg.cpp |
6dfaa4e5 RR |
3 | // Purpose: wxFontDialog |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 7 | // Licence: wxWindows licence |
6dfaa4e5 RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 | 10 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
6dfaa4e5 RR |
11 | #pragma implementation "fontdlg.h" |
12 | #endif | |
13 | ||
14f355c2 VS |
14 | // For compilers that support precompilation, includes "wx.h". |
15 | #include "wx/wxprec.h" | |
16 | ||
1e6feb95 VZ |
17 | #include "wx/defs.h" |
18 | ||
19 | #if wxUSE_FONTDLG | |
20 | ||
47e118ba RR |
21 | #ifndef __WXGPE__ |
22 | ||
6dfaa4e5 | 23 | #include "wx/fontdlg.h" |
e1bf3ad3 | 24 | #include "wx/fontutil.h" |
6dfaa4e5 RR |
25 | #include "wx/utils.h" |
26 | #include "wx/intl.h" | |
27 | #include "wx/debug.h" | |
28 | #include "wx/msgdlg.h" | |
29 | ||
9e691f46 | 30 | #include "wx/gtk/private.h" |
6dfaa4e5 RR |
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 | { | |
0b862e20 | 46 | if (g_isIdle) |
6dfaa4e5 RR |
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 | { | |
0b862e20 | 68 | if (g_isIdle) |
6dfaa4e5 RR |
69 | wxapp_install_idle_handler(); |
70 | ||
71 | GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget); | |
6e7d0063 RR |
72 | |
73 | #ifndef __WXGTK20__ | |
6dfaa4e5 | 74 | GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg); |
0b862e20 | 75 | |
6dfaa4e5 RR |
76 | if (!gfont) |
77 | { | |
7826e2dd VZ |
78 | wxMessageBox(_("Please choose a valid font."), _("Error"), |
79 | wxOK | wxICON_ERROR); | |
6dfaa4e5 RR |
80 | return; |
81 | } | |
6e7d0063 | 82 | #endif |
0b862e20 | 83 | |
6dfaa4e5 | 84 | gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg); |
2b5f62a0 | 85 | dialog->SetChosenFont( fontname); |
7beba2fc | 86 | |
6dfaa4e5 | 87 | g_free( fontname ); |
0b862e20 | 88 | |
6dfaa4e5 RR |
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 | { | |
0b862e20 | 101 | if (g_isIdle) |
6dfaa4e5 RR |
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 | ||
dbc65e27 | 113 | IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) |
6dfaa4e5 | 114 | |
dbc65e27 | 115 | bool wxFontDialog::DoCreate(wxWindow *parent) |
6dfaa4e5 RR |
116 | { |
117 | m_needParent = FALSE; | |
118 | ||
119 | if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) || | |
0b862e20 | 120 | !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, |
223d09f6 | 121 | wxDefaultValidator, wxT("fontdialog") )) |
6dfaa4e5 | 122 | { |
dbc65e27 VZ |
123 | wxFAIL_MSG( wxT("wxFontDialog creation failed") ); |
124 | return FALSE; | |
6dfaa4e5 | 125 | } |
dbc65e27 | 126 | |
6dfaa4e5 | 127 | wxString m_message( _("Choose font") ); |
fab591c5 | 128 | m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) ); |
6dfaa4e5 | 129 | |
91cf5865 VS |
130 | if (parent) |
131 | gtk_window_set_transient_for(GTK_WINDOW(m_widget), | |
132 | GTK_WINDOW(parent->m_widget)); | |
6dfaa4e5 RR |
133 | |
134 | GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget); | |
0b862e20 | 135 | |
6dfaa4e5 RR |
136 | gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked", |
137 | GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this ); | |
138 | ||
fab591c5 | 139 | #ifndef __WXGTK20__ |
6dfaa4e5 | 140 | // strange way to internationalize |
fab591c5 RR |
141 | gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->ok_button) ), _("OK") ); |
142 | #endif | |
6dfaa4e5 RR |
143 | |
144 | gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked", | |
145 | GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this ); | |
0b862e20 | 146 | |
fab591c5 | 147 | #ifndef __WXGTK20__ |
6dfaa4e5 | 148 | // strange way to internationalize |
fab591c5 RR |
149 | gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->cancel_button) ), _("Cancel") ); |
150 | #endif | |
0b862e20 | 151 | |
6dfaa4e5 RR |
152 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", |
153 | GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this ); | |
30764ab5 VZ |
154 | |
155 | wxFont font = m_fontData.GetInitialFont(); | |
156 | if( font.Ok() ) | |
157 | { | |
74b0216f | 158 | const wxNativeFontInfo *info = font.GetNativeFontInfo(); |
30764ab5 | 159 | |
7826e2dd VZ |
160 | if ( info ) |
161 | { | |
2f35f36b VS |
162 | |
163 | #ifdef __WXGTK20__ | |
164 | const wxString& fontname = info->ToString(); | |
165 | #else | |
409d5a58 | 166 | const wxString& fontname = info->GetXFontName(); |
7826e2dd VZ |
167 | if ( !fontname ) |
168 | font.GetInternalFont(); | |
2f35f36b VS |
169 | #endif |
170 | gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname)); | |
7826e2dd VZ |
171 | } |
172 | else | |
173 | { | |
174 | // this is not supposed to happen! | |
175 | wxFAIL_MSG(_T("font is ok but no native font info?")); | |
176 | } | |
30764ab5 | 177 | } |
dbc65e27 VZ |
178 | |
179 | return TRUE; | |
6dfaa4e5 RR |
180 | } |
181 | ||
182 | wxFontDialog::~wxFontDialog() | |
183 | { | |
184 | } | |
185 | ||
dbc65e27 VZ |
186 | void wxFontDialog::SetChosenFont(const char *fontname) |
187 | { | |
2b5f62a0 | 188 | m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) )); |
dbc65e27 VZ |
189 | } |
190 | ||
1e6feb95 VZ |
191 | #endif // wxUSE_FONTDLG |
192 | ||
b63b07a8 RL |
193 | #endif // GPE |
194 |