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