]>
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 | // For compilers that support precompilation, includes "wx.h". | |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #include "wx/defs.h" | |
14 | ||
15 | #if wxUSE_FONTDLG | |
16 | ||
17 | #ifndef __WXGPE__ | |
18 | ||
19 | #include "wx/fontdlg.h" | |
20 | #include "wx/fontutil.h" | |
21 | #include "wx/utils.h" | |
22 | #include "wx/intl.h" | |
23 | #include "wx/debug.h" | |
24 | #include "wx/msgdlg.h" | |
25 | ||
26 | #include "wx/gtk1/private.h" | |
27 | ||
28 | //----------------------------------------------------------------------------- | |
29 | // idle system | |
30 | //----------------------------------------------------------------------------- | |
31 | ||
32 | extern void wxapp_install_idle_handler(); | |
33 | extern bool g_isIdle; | |
34 | ||
35 | //----------------------------------------------------------------------------- | |
36 | // "delete_event" | |
37 | //----------------------------------------------------------------------------- | |
38 | ||
39 | extern "C" { | |
40 | static | |
41 | bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win ) | |
42 | { | |
43 | if (g_isIdle) | |
44 | wxapp_install_idle_handler(); | |
45 | ||
46 | /* | |
47 | printf( "OnDelete from " ); | |
48 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
49 | printf( win->GetClassInfo()->GetClassName() ); | |
50 | printf( ".\n" ); | |
51 | */ | |
52 | ||
53 | win->Close(); | |
54 | ||
55 | return TRUE; | |
56 | } | |
57 | } | |
58 | ||
59 | //----------------------------------------------------------------------------- | |
60 | // "clicked" for OK-button | |
61 | //----------------------------------------------------------------------------- | |
62 | ||
63 | extern "C" { | |
64 | static | |
65 | void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog ) | |
66 | { | |
67 | if (g_isIdle) | |
68 | wxapp_install_idle_handler(); | |
69 | ||
70 | GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget); | |
71 | ||
72 | GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg); | |
73 | ||
74 | if (!gfont) | |
75 | { | |
76 | wxMessageBox(_("Please choose a valid font."), _("Error"), | |
77 | wxOK | wxICON_ERROR); | |
78 | return; | |
79 | } | |
80 | ||
81 | gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg); | |
82 | dialog->SetChosenFont( fontname); | |
83 | ||
84 | g_free( fontname ); | |
85 | ||
86 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); | |
87 | event.SetEventObject( dialog ); | |
88 | dialog->GetEventHandler()->ProcessEvent( event ); | |
89 | } | |
90 | } | |
91 | ||
92 | //----------------------------------------------------------------------------- | |
93 | // "clicked" for Cancel-button | |
94 | //----------------------------------------------------------------------------- | |
95 | ||
96 | extern "C" { | |
97 | static | |
98 | void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog ) | |
99 | { | |
100 | if (g_isIdle) | |
101 | wxapp_install_idle_handler(); | |
102 | ||
103 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
104 | event.SetEventObject( dialog ); | |
105 | dialog->GetEventHandler()->ProcessEvent( event ); | |
106 | } | |
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 | // strange way to internationalize | |
140 | gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->ok_button) ), _("OK") ); | |
141 | ||
142 | gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked", | |
143 | GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this ); | |
144 | ||
145 | // strange way to internationalize | |
146 | gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->cancel_button) ), _("Cancel") ); | |
147 | ||
148 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", | |
149 | GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this ); | |
150 | ||
151 | wxFont font = m_fontData.GetInitialFont(); | |
152 | if( font.Ok() ) | |
153 | { | |
154 | const wxNativeFontInfo *info = font.GetNativeFontInfo(); | |
155 | ||
156 | if ( info ) | |
157 | { | |
158 | ||
159 | const wxString& fontname = info->GetXFontName(); | |
160 | if ( !fontname ) | |
161 | font.GetInternalFont(); | |
162 | ||
163 | gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname)); | |
164 | } | |
165 | else | |
166 | { | |
167 | // this is not supposed to happen! | |
168 | wxFAIL_MSG(_T("font is ok but no native font info?")); | |
169 | } | |
170 | } | |
171 | ||
172 | return TRUE; | |
173 | } | |
174 | ||
175 | wxFontDialog::~wxFontDialog() | |
176 | { | |
177 | } | |
178 | ||
179 | void wxFontDialog::SetChosenFont(const char *fontname) | |
180 | { | |
181 | m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) )); | |
182 | } | |
183 | ||
184 | #endif // wxUSE_FONTDLG | |
185 | ||
186 | #endif // GPE | |
187 |