1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/fontdlg.cpp
3 // Purpose: wxFontDialog
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
12 #if wxUSE_FONTDLG && !defined(__WXGPE__)
14 #include "wx/fontdlg.h"
19 #include "wx/msgdlg.h"
22 #include "wx/fontutil.h"
24 #include "wx/gtk1/private.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 extern void wxapp_install_idle_handler();
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
39 bool gtk_fontdialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
42 wxapp_install_idle_handler();
45 printf( "OnDelete from " );
46 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
47 printf( win->GetClassInfo()->GetClassName() );
57 //-----------------------------------------------------------------------------
58 // "clicked" for OK-button
59 //-----------------------------------------------------------------------------
63 void gtk_fontdialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFontDialog
*dialog
)
66 wxapp_install_idle_handler();
68 GtkFontSelectionDialog
*fontdlg
= GTK_FONT_SELECTION_DIALOG(dialog
->m_widget
);
70 GdkFont
*gfont
= gtk_font_selection_dialog_get_font(fontdlg
);
74 wxMessageBox(_("Please choose a valid font."), _("Error"),
79 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
80 dialog
->SetChosenFont( fontname
);
84 wxCommandEvent
event(wxEVT_BUTTON
, wxID_OK
);
85 event
.SetEventObject( dialog
);
86 dialog
->HandleWindowEvent( event
);
90 //-----------------------------------------------------------------------------
91 // "clicked" for Cancel-button
92 //-----------------------------------------------------------------------------
96 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
99 wxapp_install_idle_handler();
101 wxCommandEvent
event(wxEVT_BUTTON
, wxID_CANCEL
);
102 event
.SetEventObject( dialog
);
103 dialog
->HandleWindowEvent( event
);
107 //-----------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------
111 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
113 bool wxFontDialog::DoCreate(wxWindow
*parent
)
115 m_needParent
= false;
117 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
118 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
,
119 wxDefaultValidator
, wxT("fontdialog") ))
121 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
125 wxString
m_message( _("Choose font") );
126 m_widget
= gtk_font_selection_dialog_new( wxGTK_CONV( m_message
) );
129 gtk_window_set_transient_for(GTK_WINDOW(m_widget
),
130 GTK_WINDOW(parent
->m_widget
));
132 GtkFontSelectionDialog
*sel
= GTK_FONT_SELECTION_DIALOG(m_widget
);
134 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
135 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback
), (gpointer
*)this );
137 // strange way to internationalize
138 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->ok_button
) ), _("OK") );
140 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
141 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback
), (gpointer
*)this );
143 // strange way to internationalize
144 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->cancel_button
) ), _("Cancel") );
146 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
147 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback
), (gpointer
)this );
149 wxFont font
= m_fontData
.GetInitialFont();
152 const wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
157 const wxString
& fontname
= info
->GetXFontName();
159 font
.GetInternalFont();
161 gtk_font_selection_dialog_set_font_name(sel
, wxGTK_CONV(fontname
));
165 // this is not supposed to happen!
166 wxFAIL_MSG(wxT("font is ok but no native font info?"));
173 wxFontDialog::~wxFontDialog()
177 void wxFontDialog::SetChosenFont(const char *fontname
)
179 m_fontData
.SetChosenFont(wxFont( wxString::FromAscii(fontname
) ));
182 #endif // wxUSE_FONTDLG && !defined(__WXGPE__)