]>
Commit | Line | Data |
---|---|---|
6dfaa4e5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
93763ad5 | 2 | // Name: src/gtk1/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 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
88a7a4e1 | 13 | #if wxUSE_FONTDLG && !defined(__WXGPE__) |
47e118ba | 14 | |
6dfaa4e5 | 15 | #include "wx/fontdlg.h" |
88a7a4e1 WS |
16 | |
17 | #ifndef WX_PRECOMP | |
18 | #include "wx/intl.h" | |
de6185e2 | 19 | #include "wx/utils.h" |
246c5004 | 20 | #include "wx/msgdlg.h" |
88a7a4e1 WS |
21 | #endif |
22 | ||
e1bf3ad3 | 23 | #include "wx/fontutil.h" |
6dfaa4e5 | 24 | |
3cbab641 | 25 | #include "wx/gtk1/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 | ||
865bb325 | 38 | extern "C" { |
6dfaa4e5 RR |
39 | static |
40 | bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win ) | |
41 | { | |
0b862e20 | 42 | if (g_isIdle) |
6dfaa4e5 RR |
43 | wxapp_install_idle_handler(); |
44 | ||
45 | /* | |
46 | printf( "OnDelete from " ); | |
47 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
48 | printf( win->GetClassInfo()->GetClassName() ); | |
49 | printf( ".\n" ); | |
50 | */ | |
51 | ||
52 | win->Close(); | |
53 | ||
93763ad5 | 54 | return true; |
6dfaa4e5 | 55 | } |
865bb325 | 56 | } |
6dfaa4e5 RR |
57 | |
58 | //----------------------------------------------------------------------------- | |
59 | // "clicked" for OK-button | |
60 | //----------------------------------------------------------------------------- | |
61 | ||
865bb325 | 62 | extern "C" { |
6dfaa4e5 RR |
63 | static |
64 | void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog ) | |
65 | { | |
0b862e20 | 66 | if (g_isIdle) |
6dfaa4e5 RR |
67 | wxapp_install_idle_handler(); |
68 | ||
69 | GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget); | |
6e7d0063 | 70 | |
6dfaa4e5 | 71 | GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg); |
0b862e20 | 72 | |
6dfaa4e5 RR |
73 | if (!gfont) |
74 | { | |
7826e2dd VZ |
75 | wxMessageBox(_("Please choose a valid font."), _("Error"), |
76 | wxOK | wxICON_ERROR); | |
6dfaa4e5 RR |
77 | return; |
78 | } | |
0b862e20 | 79 | |
6dfaa4e5 | 80 | gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg); |
2b5f62a0 | 81 | dialog->SetChosenFont( fontname); |
7beba2fc | 82 | |
6dfaa4e5 | 83 | g_free( fontname ); |
0b862e20 | 84 | |
ce7fe42e | 85 | wxCommandEvent event(wxEVT_BUTTON, wxID_OK); |
6dfaa4e5 | 86 | event.SetEventObject( dialog ); |
937013e0 | 87 | dialog->HandleWindowEvent( event ); |
6dfaa4e5 | 88 | } |
865bb325 | 89 | } |
6dfaa4e5 RR |
90 | |
91 | //----------------------------------------------------------------------------- | |
92 | // "clicked" for Cancel-button | |
93 | //----------------------------------------------------------------------------- | |
94 | ||
865bb325 | 95 | extern "C" { |
6dfaa4e5 RR |
96 | static |
97 | void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog ) | |
98 | { | |
0b862e20 | 99 | if (g_isIdle) |
6dfaa4e5 RR |
100 | wxapp_install_idle_handler(); |
101 | ||
ce7fe42e | 102 | wxCommandEvent event(wxEVT_BUTTON, wxID_CANCEL); |
6dfaa4e5 | 103 | event.SetEventObject( dialog ); |
937013e0 | 104 | dialog->HandleWindowEvent( event ); |
6dfaa4e5 | 105 | } |
865bb325 | 106 | } |
6dfaa4e5 RR |
107 | |
108 | //----------------------------------------------------------------------------- | |
109 | // wxFontDialog | |
110 | //----------------------------------------------------------------------------- | |
111 | ||
dbc65e27 | 112 | IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) |
6dfaa4e5 | 113 | |
dbc65e27 | 114 | bool wxFontDialog::DoCreate(wxWindow *parent) |
6dfaa4e5 | 115 | { |
93763ad5 | 116 | m_needParent = false; |
6dfaa4e5 RR |
117 | |
118 | if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) || | |
0b862e20 | 119 | !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, |
223d09f6 | 120 | wxDefaultValidator, wxT("fontdialog") )) |
6dfaa4e5 | 121 | { |
dbc65e27 | 122 | wxFAIL_MSG( wxT("wxFontDialog creation failed") ); |
93763ad5 | 123 | return false; |
6dfaa4e5 | 124 | } |
dbc65e27 | 125 | |
6dfaa4e5 | 126 | wxString m_message( _("Choose font") ); |
fab591c5 | 127 | m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) ); |
6dfaa4e5 | 128 | |
91cf5865 VS |
129 | if (parent) |
130 | gtk_window_set_transient_for(GTK_WINDOW(m_widget), | |
131 | GTK_WINDOW(parent->m_widget)); | |
6dfaa4e5 RR |
132 | |
133 | GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget); | |
0b862e20 | 134 | |
6dfaa4e5 RR |
135 | gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked", |
136 | GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this ); | |
137 | ||
138 | // strange way to internationalize | |
fab591c5 | 139 | gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->ok_button) ), _("OK") ); |
6dfaa4e5 RR |
140 | |
141 | gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked", | |
142 | GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this ); | |
0b862e20 | 143 | |
6dfaa4e5 | 144 | // strange way to internationalize |
fab591c5 | 145 | gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->cancel_button) ), _("Cancel") ); |
0b862e20 | 146 | |
6dfaa4e5 RR |
147 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", |
148 | GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this ); | |
30764ab5 VZ |
149 | |
150 | wxFont font = m_fontData.GetInitialFont(); | |
a1b806b9 | 151 | if( font.IsOk() ) |
30764ab5 | 152 | { |
74b0216f | 153 | const wxNativeFontInfo *info = font.GetNativeFontInfo(); |
30764ab5 | 154 | |
7826e2dd VZ |
155 | if ( info ) |
156 | { | |
2f35f36b | 157 | |
409d5a58 | 158 | const wxString& fontname = info->GetXFontName(); |
7826e2dd VZ |
159 | if ( !fontname ) |
160 | font.GetInternalFont(); | |
3cbab641 | 161 | |
2f35f36b | 162 | gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname)); |
7826e2dd VZ |
163 | } |
164 | else | |
165 | { | |
166 | // this is not supposed to happen! | |
9a83f860 | 167 | wxFAIL_MSG(wxT("font is ok but no native font info?")); |
7826e2dd | 168 | } |
30764ab5 | 169 | } |
dbc65e27 | 170 | |
93763ad5 | 171 | return true; |
6dfaa4e5 RR |
172 | } |
173 | ||
174 | wxFontDialog::~wxFontDialog() | |
175 | { | |
176 | } | |
177 | ||
dbc65e27 VZ |
178 | void wxFontDialog::SetChosenFont(const char *fontname) |
179 | { | |
2b5f62a0 | 180 | m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) )); |
dbc65e27 VZ |
181 | } |
182 | ||
88a7a4e1 | 183 | #endif // wxUSE_FONTDLG && !defined(__WXGPE__) |