1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/fontdlg.cpp
3 // Purpose: wxFontDialog
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
19 #include "wx/fontdlg.h"
20 #include "wx/fontutil.h"
24 #include "wx/msgdlg.h"
26 #include "wx/gtk/private.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 extern void wxapp_install_idle_handler();
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
41 bool gtk_fontdialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
44 wxapp_install_idle_handler();
47 printf( "OnDelete from " );
48 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
49 printf( win->GetClassInfo()->GetClassName() );
59 //-----------------------------------------------------------------------------
60 // "clicked" for OK-button
61 //-----------------------------------------------------------------------------
65 void gtk_fontdialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFontDialog
*dialog
)
68 wxapp_install_idle_handler();
70 GtkFontSelectionDialog
*fontdlg
= GTK_FONT_SELECTION_DIALOG(dialog
->m_widget
);
73 GdkFont
*gfont
= gtk_font_selection_dialog_get_font(fontdlg
);
77 wxMessageBox(_("Please choose a valid font."), _("Error"),
83 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
84 dialog
->SetChosenFont( fontname
);
88 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
89 event
.SetEventObject( dialog
);
90 dialog
->GetEventHandler()->ProcessEvent( event
);
94 //-----------------------------------------------------------------------------
95 // "clicked" for Cancel-button
96 //-----------------------------------------------------------------------------
100 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
103 wxapp_install_idle_handler();
105 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
106 event
.SetEventObject( dialog
);
107 dialog
->GetEventHandler()->ProcessEvent( event
);
111 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
115 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
117 bool wxFontDialog::DoCreate(wxWindow
*parent
)
119 m_needParent
= FALSE
;
121 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
122 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
,
123 wxDefaultValidator
, wxT("fontdialog") ))
125 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
129 wxString
m_message( _("Choose font") );
130 m_widget
= gtk_font_selection_dialog_new( wxGTK_CONV( m_message
) );
133 gtk_window_set_transient_for(GTK_WINDOW(m_widget
),
134 GTK_WINDOW(parent
->m_widget
));
136 GtkFontSelectionDialog
*sel
= GTK_FONT_SELECTION_DIALOG(m_widget
);
138 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
139 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback
), (gpointer
*)this );
142 // strange way to internationalize
143 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->ok_button
) ), _("OK") );
146 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
147 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback
), (gpointer
*)this );
150 // strange way to internationalize
151 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->cancel_button
) ), _("Cancel") );
154 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
155 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback
), (gpointer
)this );
157 wxFont font
= m_fontData
.GetInitialFont();
160 const wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
166 const wxString
& fontname
= info
->ToString();
168 const wxString
& fontname
= info
->GetXFontName();
170 font
.GetInternalFont();
172 gtk_font_selection_dialog_set_font_name(sel
, wxGTK_CONV(fontname
));
176 // this is not supposed to happen!
177 wxFAIL_MSG(_T("font is ok but no native font info?"));
184 wxFontDialog::~wxFontDialog()
188 void wxFontDialog::SetChosenFont(const char *fontname
)
190 m_fontData
.SetChosenFont(wxFont( wxString::FromAscii(fontname
) ));
193 #endif // wxUSE_FONTDLG