]>
Commit | Line | Data |
---|---|---|
6dfaa4e5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
1e6feb95 | 2 | // Name: gtk/fontdlg.cpp |
6dfaa4e5 RR |
3 | // Purpose: wxFontDialog |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 7 | // Licence: wxWindows licence |
6dfaa4e5 RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
1e6feb95 VZ |
13 | #include "wx/defs.h" |
14 | ||
15 | #if wxUSE_FONTDLG | |
16 | ||
47e118ba RR |
17 | #ifndef __WXGPE__ |
18 | ||
6dfaa4e5 | 19 | #include "wx/fontdlg.h" |
e1bf3ad3 | 20 | #include "wx/fontutil.h" |
6dfaa4e5 RR |
21 | #include "wx/utils.h" |
22 | #include "wx/intl.h" | |
23 | #include "wx/debug.h" | |
24 | #include "wx/msgdlg.h" | |
25 | ||
9e691f46 | 26 | #include "wx/gtk/private.h" |
6dfaa4e5 | 27 | |
6dfaa4e5 RR |
28 | //----------------------------------------------------------------------------- |
29 | // "delete_event" | |
30 | //----------------------------------------------------------------------------- | |
31 | ||
865bb325 | 32 | extern "C" { |
6dfaa4e5 RR |
33 | static |
34 | bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win ) | |
35 | { | |
0b862e20 | 36 | if (g_isIdle) |
6dfaa4e5 RR |
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 | } | |
865bb325 | 50 | } |
6dfaa4e5 RR |
51 | |
52 | //----------------------------------------------------------------------------- | |
53 | // "clicked" for OK-button | |
54 | //----------------------------------------------------------------------------- | |
55 | ||
865bb325 | 56 | extern "C" { |
6dfaa4e5 RR |
57 | static |
58 | void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog ) | |
59 | { | |
0b862e20 | 60 | if (g_isIdle) |
6dfaa4e5 RR |
61 | wxapp_install_idle_handler(); |
62 | ||
63 | GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget); | |
6e7d0063 | 64 | |
6dfaa4e5 | 65 | gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg); |
2b5f62a0 | 66 | dialog->SetChosenFont( fontname); |
7beba2fc | 67 | |
6dfaa4e5 | 68 | g_free( fontname ); |
0b862e20 | 69 | |
6dfaa4e5 RR |
70 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); |
71 | event.SetEventObject( dialog ); | |
72 | dialog->GetEventHandler()->ProcessEvent( event ); | |
73 | } | |
865bb325 | 74 | } |
6dfaa4e5 RR |
75 | |
76 | //----------------------------------------------------------------------------- | |
77 | // "clicked" for Cancel-button | |
78 | //----------------------------------------------------------------------------- | |
79 | ||
865bb325 | 80 | extern "C" { |
6dfaa4e5 RR |
81 | static |
82 | void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog ) | |
83 | { | |
0b862e20 | 84 | if (g_isIdle) |
6dfaa4e5 RR |
85 | wxapp_install_idle_handler(); |
86 | ||
87 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
88 | event.SetEventObject( dialog ); | |
89 | dialog->GetEventHandler()->ProcessEvent( event ); | |
90 | } | |
865bb325 | 91 | } |
6dfaa4e5 RR |
92 | |
93 | //----------------------------------------------------------------------------- | |
94 | // wxFontDialog | |
95 | //----------------------------------------------------------------------------- | |
96 | ||
dbc65e27 | 97 | IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) |
6dfaa4e5 | 98 | |
dbc65e27 | 99 | bool wxFontDialog::DoCreate(wxWindow *parent) |
6dfaa4e5 RR |
100 | { |
101 | m_needParent = FALSE; | |
102 | ||
103 | if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) || | |
0b862e20 | 104 | !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, |
223d09f6 | 105 | wxDefaultValidator, wxT("fontdialog") )) |
6dfaa4e5 | 106 | { |
dbc65e27 VZ |
107 | wxFAIL_MSG( wxT("wxFontDialog creation failed") ); |
108 | return FALSE; | |
6dfaa4e5 | 109 | } |
dbc65e27 | 110 | |
6dfaa4e5 | 111 | wxString m_message( _("Choose font") ); |
fab591c5 | 112 | m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) ); |
6dfaa4e5 | 113 | |
91cf5865 VS |
114 | if (parent) |
115 | gtk_window_set_transient_for(GTK_WINDOW(m_widget), | |
116 | GTK_WINDOW(parent->m_widget)); | |
6dfaa4e5 RR |
117 | |
118 | GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget); | |
0b862e20 | 119 | |
9fa72bd2 MR |
120 | g_signal_connect (sel->ok_button, "clicked", |
121 | G_CALLBACK (gtk_fontdialog_ok_callback), this); | |
6dfaa4e5 | 122 | |
9fa72bd2 MR |
123 | g_signal_connect (sel->cancel_button, "clicked", |
124 | G_CALLBACK (gtk_fontdialog_cancel_callback), this); | |
0b862e20 | 125 | |
9fa72bd2 MR |
126 | g_signal_connect (m_widget, "delete_event", |
127 | G_CALLBACK (gtk_fontdialog_delete_callback), this); | |
30764ab5 VZ |
128 | |
129 | wxFont font = m_fontData.GetInitialFont(); | |
130 | if( font.Ok() ) | |
131 | { | |
74b0216f | 132 | const wxNativeFontInfo *info = font.GetNativeFontInfo(); |
30764ab5 | 133 | |
7826e2dd VZ |
134 | if ( info ) |
135 | { | |
2f35f36b | 136 | |
2f35f36b | 137 | const wxString& fontname = info->ToString(); |
2f35f36b | 138 | gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname)); |
7826e2dd VZ |
139 | } |
140 | else | |
141 | { | |
142 | // this is not supposed to happen! | |
143 | wxFAIL_MSG(_T("font is ok but no native font info?")); | |
144 | } | |
30764ab5 | 145 | } |
dbc65e27 VZ |
146 | |
147 | return TRUE; | |
6dfaa4e5 RR |
148 | } |
149 | ||
150 | wxFontDialog::~wxFontDialog() | |
151 | { | |
152 | } | |
153 | ||
dbc65e27 VZ |
154 | void wxFontDialog::SetChosenFont(const char *fontname) |
155 | { | |
2b5f62a0 | 156 | m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) )); |
dbc65e27 VZ |
157 | } |
158 | ||
1e6feb95 VZ |
159 | #endif // wxUSE_FONTDLG |
160 | ||
b63b07a8 RL |
161 | #endif // GPE |
162 |