wx/wxprec.h already includes wx/defs.h (with other minor cleaning).
[wxWidgets.git] / src / gtk / fontdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 #if wxUSE_FONTDLG
14
15 #ifndef __WXGPE__
16
17 #include "wx/fontdlg.h"
18 #include "wx/fontutil.h"
19 #include "wx/utils.h"
20 #include "wx/intl.h"
21 #include "wx/debug.h"
22 #include "wx/msgdlg.h"
23
24 #include "wx/gtk/private.h"
25
26 //-----------------------------------------------------------------------------
27 // "delete_event"
28 //-----------------------------------------------------------------------------
29
30 extern "C" {
31 static
32 bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
33 {
34 if (g_isIdle)
35 wxapp_install_idle_handler();
36
37 /*
38 printf( "OnDelete from " );
39 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
40 printf( win->GetClassInfo()->GetClassName() );
41 printf( ".\n" );
42 */
43
44 win->Close();
45
46 return true;
47 }
48 }
49
50 //-----------------------------------------------------------------------------
51 // "clicked" for OK-button
52 //-----------------------------------------------------------------------------
53
54 extern "C" {
55 static
56 void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
57 {
58 if (g_isIdle)
59 wxapp_install_idle_handler();
60
61 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
62
63 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
64 dialog->SetChosenFont( fontname);
65
66 g_free( fontname );
67
68 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
69 event.SetEventObject( dialog );
70 dialog->GetEventHandler()->ProcessEvent( event );
71 }
72 }
73
74 //-----------------------------------------------------------------------------
75 // "clicked" for Cancel-button
76 //-----------------------------------------------------------------------------
77
78 extern "C" {
79 static
80 void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
81 {
82 if (g_isIdle)
83 wxapp_install_idle_handler();
84
85 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
86 event.SetEventObject( dialog );
87 dialog->GetEventHandler()->ProcessEvent( event );
88 }
89 }
90
91 //-----------------------------------------------------------------------------
92 // wxFontDialog
93 //-----------------------------------------------------------------------------
94
95 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
96
97 bool wxFontDialog::DoCreate(wxWindow *parent)
98 {
99 m_needParent = false;
100
101 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
102 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
103 wxDefaultValidator, wxT("fontdialog") ))
104 {
105 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
106 return false;
107 }
108
109 wxString m_message( _("Choose font") );
110 m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
111
112 if (parent)
113 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
114 GTK_WINDOW(parent->m_widget));
115
116 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
117
118 g_signal_connect (sel->ok_button, "clicked",
119 G_CALLBACK (gtk_fontdialog_ok_callback), this);
120
121 g_signal_connect (sel->cancel_button, "clicked",
122 G_CALLBACK (gtk_fontdialog_cancel_callback), this);
123
124 g_signal_connect (m_widget, "delete_event",
125 G_CALLBACK (gtk_fontdialog_delete_callback), this);
126
127 wxFont font = m_fontData.GetInitialFont();
128 if( font.Ok() )
129 {
130 const wxNativeFontInfo *info = font.GetNativeFontInfo();
131
132 if ( info )
133 {
134
135 const wxString& fontname = info->ToString();
136 gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname));
137 }
138 else
139 {
140 // this is not supposed to happen!
141 wxFAIL_MSG(_T("font is ok but no native font info?"));
142 }
143 }
144
145 return true;
146 }
147
148 wxFontDialog::~wxFontDialog()
149 {
150 }
151
152 void wxFontDialog::SetChosenFont(const char *fontname)
153 {
154 m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) ));
155 }
156
157 #endif // wxUSE_FONTDLG
158
159 #endif // GPE