]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/fontdlg.cpp
wxDataObejct and related changes (won't compile right now)
[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 #ifdef __WXGTK12__
56 static
57 void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
58 {
59 if (g_isIdle)
60 wxapp_install_idle_handler();
61
62 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
63 GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg);
64
65 if (!gfont)
66 {
67 wxMessageBox(_("Please choose a valid font."), _("Error"), wxOK);
68 return;
69 }
70
71 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
72 wxFont font( gfont, fontname );
73 g_free( fontname );
74 dialog->m_fontData.SetChosenFont( font );
75
76 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
77 event.SetEventObject( dialog );
78 dialog->GetEventHandler()->ProcessEvent( event );
79 }
80 #endif // GTK+ 1.2 andlater only
81
82 //-----------------------------------------------------------------------------
83 // "clicked" for Cancel-button
84 //-----------------------------------------------------------------------------
85
86 static
87 void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
88 {
89 if (g_isIdle)
90 wxapp_install_idle_handler();
91
92 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
93 event.SetEventObject( dialog );
94 dialog->GetEventHandler()->ProcessEvent( event );
95 }
96
97 //-----------------------------------------------------------------------------
98 // wxFontDialog
99 //-----------------------------------------------------------------------------
100
101 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog,wxDialog)
102
103 wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *WXUNUSED(data) )
104 {
105 m_needParent = FALSE;
106
107 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
108 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
109 wxDefaultValidator, wxT("fontdialog") ))
110 {
111 wxFAIL_MSG( wxT("wxXX creation failed") );
112 return;
113 }
114 #ifndef __WXGTK12__
115 wxFAIL_MSG( wxT("TODO") );
116 #else // GTK+ 1.2
117 wxString m_message( _("Choose font") );
118 m_widget = gtk_font_selection_dialog_new( m_message.mbc_str() );
119
120 int x = (gdk_screen_width () - 400) / 2;
121 int y = (gdk_screen_height () - 400) / 2;
122 gtk_widget_set_uposition( m_widget, x, y );
123
124 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
125
126 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
127 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this );
128
129 // strange way to internationalize
130 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->ok_button)->child ), wxConvCurrent->cWX2MB(_("OK")) );
131
132 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
133 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this );
134
135 // strange way to internationalize
136 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->cancel_button)->child ), wxConvCurrent->cWX2MB(_("Cancel")) );
137
138 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
139 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
140 #endif // GTK+ version
141 }
142
143 wxFontDialog::~wxFontDialog()
144 {
145 }
146