]>
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 | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "fontdlg.h" | |
12 | #endif | |
13 | ||
1e6feb95 VZ |
14 | #include "wx/defs.h" |
15 | ||
16 | #if wxUSE_FONTDLG | |
17 | ||
7826e2dd | 18 | #include "wx/fontutil.h" |
6dfaa4e5 RR |
19 | #include "wx/fontdlg.h" |
20 | #include "wx/utils.h" | |
21 | #include "wx/intl.h" | |
22 | #include "wx/debug.h" | |
23 | #include "wx/msgdlg.h" | |
24 | ||
9e691f46 | 25 | #include "wx/gtk/private.h" |
6dfaa4e5 RR |
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 | { | |
0b862e20 | 41 | if (g_isIdle) |
6dfaa4e5 RR |
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 | static | |
61 | void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog ) | |
62 | { | |
0b862e20 | 63 | if (g_isIdle) |
6dfaa4e5 RR |
64 | wxapp_install_idle_handler(); |
65 | ||
66 | GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget); | |
67 | GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg); | |
0b862e20 | 68 | |
6dfaa4e5 RR |
69 | if (!gfont) |
70 | { | |
7826e2dd VZ |
71 | wxMessageBox(_("Please choose a valid font."), _("Error"), |
72 | wxOK | wxICON_ERROR); | |
6dfaa4e5 RR |
73 | return; |
74 | } | |
0b862e20 | 75 | |
6dfaa4e5 | 76 | gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg); |
7beba2fc | 77 | |
dbc65e27 | 78 | dialog->SetChosenFont(fontname); |
7beba2fc | 79 | |
6dfaa4e5 | 80 | g_free( fontname ); |
0b862e20 | 81 | |
6dfaa4e5 RR |
82 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); |
83 | event.SetEventObject( dialog ); | |
84 | dialog->GetEventHandler()->ProcessEvent( event ); | |
85 | } | |
86 | ||
87 | //----------------------------------------------------------------------------- | |
88 | // "clicked" for Cancel-button | |
89 | //----------------------------------------------------------------------------- | |
90 | ||
91 | static | |
92 | void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog ) | |
93 | { | |
0b862e20 | 94 | if (g_isIdle) |
6dfaa4e5 RR |
95 | wxapp_install_idle_handler(); |
96 | ||
97 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
98 | event.SetEventObject( dialog ); | |
99 | dialog->GetEventHandler()->ProcessEvent( event ); | |
100 | } | |
101 | ||
102 | //----------------------------------------------------------------------------- | |
103 | // wxFontDialog | |
104 | //----------------------------------------------------------------------------- | |
105 | ||
dbc65e27 | 106 | IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) |
6dfaa4e5 | 107 | |
dbc65e27 | 108 | bool wxFontDialog::DoCreate(wxWindow *parent) |
6dfaa4e5 RR |
109 | { |
110 | m_needParent = FALSE; | |
111 | ||
112 | if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) || | |
0b862e20 | 113 | !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, |
223d09f6 | 114 | wxDefaultValidator, wxT("fontdialog") )) |
6dfaa4e5 | 115 | { |
dbc65e27 VZ |
116 | wxFAIL_MSG( wxT("wxFontDialog creation failed") ); |
117 | return FALSE; | |
6dfaa4e5 | 118 | } |
dbc65e27 | 119 | |
6dfaa4e5 | 120 | wxString m_message( _("Choose font") ); |
fab591c5 | 121 | m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) ); |
6dfaa4e5 RR |
122 | |
123 | int x = (gdk_screen_width () - 400) / 2; | |
124 | int y = (gdk_screen_height () - 400) / 2; | |
125 | gtk_widget_set_uposition( m_widget, x, y ); | |
126 | ||
127 | GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget); | |
0b862e20 | 128 | |
6dfaa4e5 RR |
129 | gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked", |
130 | GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this ); | |
131 | ||
fab591c5 | 132 | #ifndef __WXGTK20__ |
6dfaa4e5 | 133 | // strange way to internationalize |
fab591c5 RR |
134 | gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->ok_button) ), _("OK") ); |
135 | #endif | |
6dfaa4e5 RR |
136 | |
137 | gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked", | |
138 | GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this ); | |
0b862e20 | 139 | |
fab591c5 | 140 | #ifndef __WXGTK20__ |
6dfaa4e5 | 141 | // strange way to internationalize |
fab591c5 RR |
142 | gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->cancel_button) ), _("Cancel") ); |
143 | #endif | |
0b862e20 | 144 | |
6dfaa4e5 RR |
145 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", |
146 | GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this ); | |
30764ab5 VZ |
147 | |
148 | wxFont font = m_fontData.GetInitialFont(); | |
149 | if( font.Ok() ) | |
150 | { | |
7826e2dd | 151 | wxNativeFontInfo *info = font.GetNativeFontInfo(); |
30764ab5 | 152 | |
7826e2dd VZ |
153 | if ( info ) |
154 | { | |
409d5a58 | 155 | const wxString& fontname = info->GetXFontName(); |
7826e2dd VZ |
156 | if ( !fontname ) |
157 | font.GetInternalFont(); | |
409d5a58 VZ |
158 | gtk_font_selection_dialog_set_font_name |
159 | ( | |
160 | sel, | |
161 | wxConvCurrent->cWX2MB(fontname) | |
162 | ); | |
7826e2dd VZ |
163 | } |
164 | else | |
165 | { | |
166 | // this is not supposed to happen! | |
167 | wxFAIL_MSG(_T("font is ok but no native font info?")); | |
168 | } | |
30764ab5 | 169 | } |
dbc65e27 VZ |
170 | |
171 | return TRUE; | |
6dfaa4e5 RR |
172 | } |
173 | ||
174 | wxFontDialog::~wxFontDialog() | |
175 | { | |
176 | } | |
177 | ||
dbc65e27 VZ |
178 | void wxFontDialog::SetChosenFont(const char *fontname) |
179 | { | |
180 | m_fontData.SetChosenFont(wxFont(fontname)); | |
181 | } | |
182 | ||
1e6feb95 VZ |
183 | #endif // wxUSE_FONTDLG |
184 |