Forgot to add the files.
[wxWidgets.git] / src / gtk / fontdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #ifdef __GNUG__
11 #pragma implementation "fontdlg.h"
12 #endif
13
14 #include "wx/fontdlg.h"
15 #include "wx/utils.h"
16 #include "wx/intl.h"
17 #include "wx/debug.h"
18 #include "wx/msgdlg.h"
19
20 #include "gtk/gtk.h"
21
22 //-----------------------------------------------------------------------------
23 // idle system
24 //-----------------------------------------------------------------------------
25
26 extern void wxapp_install_idle_handler();
27 extern bool g_isIdle;
28
29 //-----------------------------------------------------------------------------
30 // "delete_event"
31 //-----------------------------------------------------------------------------
32
33 static
34 bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
35 {
36 if (g_isIdle)
37 wxapp_install_idle_handler();
38
39 /*
40 printf( "OnDelete from " );
41 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
42 printf( win->GetClassInfo()->GetClassName() );
43 printf( ".\n" );
44 */
45
46 win->Close();
47
48 return TRUE;
49 }
50
51 //-----------------------------------------------------------------------------
52 // "clicked" for OK-button
53 //-----------------------------------------------------------------------------
54
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 GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg);
63
64 if (!gfont)
65 {
66 wxMessageBox(_("Please choose a valid font."), _("Error"), wxOK);
67 return;
68 }
69
70 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
71 wxFont font( gfont, fontname );
72 g_free( fontname );
73 dialog->m_fontData.SetChosenFont( font );
74
75 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
76 event.SetEventObject( dialog );
77 dialog->GetEventHandler()->ProcessEvent( event );
78 }
79
80 //-----------------------------------------------------------------------------
81 // "clicked" for Cancel-button
82 //-----------------------------------------------------------------------------
83
84 static
85 void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
86 {
87 if (g_isIdle)
88 wxapp_install_idle_handler();
89
90 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
91 event.SetEventObject( dialog );
92 dialog->GetEventHandler()->ProcessEvent( event );
93 }
94
95 //-----------------------------------------------------------------------------
96 // wxFontDialog
97 //-----------------------------------------------------------------------------
98
99 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog,wxDialog)
100
101 wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *data )
102 {
103 m_needParent = FALSE;
104
105 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
106 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
107 wxDefaultValidator, _T("fontdialog") ))
108 {
109 wxFAIL_MSG( _T("wxXX creation failed") );
110 return;
111 }
112
113 wxString m_message( _("Choose font") );
114 m_widget = gtk_font_selection_dialog_new( m_message.mbc_str() );
115
116 int x = (gdk_screen_width () - 400) / 2;
117 int y = (gdk_screen_height () - 400) / 2;
118 gtk_widget_set_uposition( m_widget, x, y );
119
120 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
121
122 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
123 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this );
124
125 // strange way to internationalize
126 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->ok_button)->child ), wxConvCurrent->cWX2MB(_("OK")) );
127
128 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
129 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this );
130
131 // strange way to internationalize
132 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->cancel_button)->child ), wxConvCurrent->cWX2MB(_("Cancel")) );
133
134 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
135 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
136 }
137
138 wxFontDialog::~wxFontDialog()
139 {
140 }
141