]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/fontdlg.cpp
Make wxRichTextRectArray usable by other parts of wxRTC
[wxWidgets.git] / src / gtk1 / fontdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/fontdlg.cpp
3 // Purpose: wxFontDialog
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
11
12 #if wxUSE_FONTDLG && !defined(__WXGPE__)
13
14 #include "wx/fontdlg.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/intl.h"
18 #include "wx/utils.h"
19 #include "wx/msgdlg.h"
20 #endif
21
22 #include "wx/fontutil.h"
23
24 #include "wx/gtk1/private.h"
25
26 //-----------------------------------------------------------------------------
27 // idle system
28 //-----------------------------------------------------------------------------
29
30 extern void wxapp_install_idle_handler();
31 extern bool g_isIdle;
32
33 //-----------------------------------------------------------------------------
34 // "delete_event"
35 //-----------------------------------------------------------------------------
36
37 extern "C" {
38 static
39 bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
40 {
41 if (g_isIdle)
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 //-----------------------------------------------------------------------------
58 // "clicked" for OK-button
59 //-----------------------------------------------------------------------------
60
61 extern "C" {
62 static
63 void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
64 {
65 if (g_isIdle)
66 wxapp_install_idle_handler();
67
68 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
69
70 GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg);
71
72 if (!gfont)
73 {
74 wxMessageBox(_("Please choose a valid font."), _("Error"),
75 wxOK | wxICON_ERROR);
76 return;
77 }
78
79 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
80 dialog->SetChosenFont( fontname);
81
82 g_free( fontname );
83
84 wxCommandEvent event(wxEVT_BUTTON, wxID_OK);
85 event.SetEventObject( dialog );
86 dialog->HandleWindowEvent( event );
87 }
88 }
89
90 //-----------------------------------------------------------------------------
91 // "clicked" for Cancel-button
92 //-----------------------------------------------------------------------------
93
94 extern "C" {
95 static
96 void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
97 {
98 if (g_isIdle)
99 wxapp_install_idle_handler();
100
101 wxCommandEvent event(wxEVT_BUTTON, wxID_CANCEL);
102 event.SetEventObject( dialog );
103 dialog->HandleWindowEvent( event );
104 }
105 }
106
107 //-----------------------------------------------------------------------------
108 // wxFontDialog
109 //-----------------------------------------------------------------------------
110
111 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
112
113 bool wxFontDialog::DoCreate(wxWindow *parent)
114 {
115 m_needParent = false;
116
117 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
118 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
119 wxDefaultValidator, wxT("fontdialog") ))
120 {
121 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
122 return false;
123 }
124
125 wxString m_message( _("Choose font") );
126 m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
127
128 if (parent)
129 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
130 GTK_WINDOW(parent->m_widget));
131
132 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
133
134 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
135 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this );
136
137 // strange way to internationalize
138 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->ok_button) ), _("OK") );
139
140 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
141 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this );
142
143 // strange way to internationalize
144 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->cancel_button) ), _("Cancel") );
145
146 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
147 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
148
149 wxFont font = m_fontData.GetInitialFont();
150 if( font.IsOk() )
151 {
152 const wxNativeFontInfo *info = font.GetNativeFontInfo();
153
154 if ( info )
155 {
156
157 const wxString& fontname = info->GetXFontName();
158 if ( !fontname )
159 font.GetInternalFont();
160
161 gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname));
162 }
163 else
164 {
165 // this is not supposed to happen!
166 wxFAIL_MSG(wxT("font is ok but no native font info?"));
167 }
168 }
169
170 return true;
171 }
172
173 wxFontDialog::~wxFontDialog()
174 {
175 }
176
177 void wxFontDialog::SetChosenFont(const char *fontname)
178 {
179 m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) ));
180 }
181
182 #endif // wxUSE_FONTDLG && !defined(__WXGPE__)