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/gtk1/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
);
72 GdkFont
*gfont
= gtk_font_selection_dialog_get_font(fontdlg
);
76 wxMessageBox(_("Please choose a valid font."), _("Error"),
81 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
82 dialog
->SetChosenFont( fontname
);
86 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
87 event
.SetEventObject( dialog
);
88 dialog
->GetEventHandler()->ProcessEvent( event
);
92 //-----------------------------------------------------------------------------
93 // "clicked" for Cancel-button
94 //-----------------------------------------------------------------------------
98 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
101 wxapp_install_idle_handler();
103 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
104 event
.SetEventObject( dialog
);
105 dialog
->GetEventHandler()->ProcessEvent( event
);
109 //-----------------------------------------------------------------------------
111 //-----------------------------------------------------------------------------
113 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
115 bool wxFontDialog::DoCreate(wxWindow
*parent
)
117 m_needParent
= FALSE
;
119 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
120 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
,
121 wxDefaultValidator
, wxT("fontdialog") ))
123 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
127 wxString
m_message( _("Choose font") );
128 m_widget
= gtk_font_selection_dialog_new( wxGTK_CONV( m_message
) );
131 gtk_window_set_transient_for(GTK_WINDOW(m_widget
),
132 GTK_WINDOW(parent
->m_widget
));
134 GtkFontSelectionDialog
*sel
= GTK_FONT_SELECTION_DIALOG(m_widget
);
136 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
137 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback
), (gpointer
*)this );
139 // strange way to internationalize
140 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->ok_button
) ), _("OK") );
142 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
143 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback
), (gpointer
*)this );
145 // strange way to internationalize
146 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->cancel_button
) ), _("Cancel") );
148 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
149 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback
), (gpointer
)this );
151 wxFont font
= m_fontData
.GetInitialFont();
154 const wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
159 const wxString
& fontname
= info
->GetXFontName();
161 font
.GetInternalFont();
163 gtk_font_selection_dialog_set_font_name(sel
, wxGTK_CONV(fontname
));
167 // this is not supposed to happen!
168 wxFAIL_MSG(_T("font is ok but no native font info?"));
175 wxFontDialog::~wxFontDialog()
179 void wxFontDialog::SetChosenFont(const char *fontname
)
181 m_fontData
.SetChosenFont(wxFont( wxString::FromAscii(fontname
) ));
184 #endif // wxUSE_FONTDLG