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