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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "fontdlg.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
23 #include "wx/fontdlg.h"
24 #include "wx/fontutil.h"
28 #include "wx/msgdlg.h"
30 #include "wx/gtk/private.h"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 extern void wxapp_install_idle_handler();
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
45 bool gtk_fontdialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
48 wxapp_install_idle_handler();
51 printf( "OnDelete from " );
52 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
53 printf( win->GetClassInfo()->GetClassName() );
63 //-----------------------------------------------------------------------------
64 // "clicked" for OK-button
65 //-----------------------------------------------------------------------------
69 void gtk_fontdialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFontDialog
*dialog
)
72 wxapp_install_idle_handler();
74 GtkFontSelectionDialog
*fontdlg
= GTK_FONT_SELECTION_DIALOG(dialog
->m_widget
);
77 GdkFont
*gfont
= gtk_font_selection_dialog_get_font(fontdlg
);
81 wxMessageBox(_("Please choose a valid font."), _("Error"),
87 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
88 dialog
->SetChosenFont( fontname
);
92 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
93 event
.SetEventObject( dialog
);
94 dialog
->GetEventHandler()->ProcessEvent( event
);
98 //-----------------------------------------------------------------------------
99 // "clicked" for Cancel-button
100 //-----------------------------------------------------------------------------
104 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
107 wxapp_install_idle_handler();
109 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
110 event
.SetEventObject( dialog
);
111 dialog
->GetEventHandler()->ProcessEvent( event
);
115 //-----------------------------------------------------------------------------
117 //-----------------------------------------------------------------------------
119 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
121 bool wxFontDialog::DoCreate(wxWindow
*parent
)
123 m_needParent
= FALSE
;
125 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
126 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
,
127 wxDefaultValidator
, wxT("fontdialog") ))
129 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
133 wxString
m_message( _("Choose font") );
134 m_widget
= gtk_font_selection_dialog_new( wxGTK_CONV( m_message
) );
137 gtk_window_set_transient_for(GTK_WINDOW(m_widget
),
138 GTK_WINDOW(parent
->m_widget
));
140 GtkFontSelectionDialog
*sel
= GTK_FONT_SELECTION_DIALOG(m_widget
);
142 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
143 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback
), (gpointer
*)this );
146 // strange way to internationalize
147 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->ok_button
) ), _("OK") );
150 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
151 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback
), (gpointer
*)this );
154 // strange way to internationalize
155 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->cancel_button
) ), _("Cancel") );
158 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
159 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback
), (gpointer
)this );
161 wxFont font
= m_fontData
.GetInitialFont();
164 const wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
170 const wxString
& fontname
= info
->ToString();
172 const wxString
& fontname
= info
->GetXFontName();
174 font
.GetInternalFont();
176 gtk_font_selection_dialog_set_font_name(sel
, wxGTK_CONV(fontname
));
180 // this is not supposed to happen!
181 wxFAIL_MSG(_T("font is ok but no native font info?"));
188 wxFontDialog::~wxFontDialog()
192 void wxFontDialog::SetChosenFont(const char *fontname
)
194 m_fontData
.SetChosenFont(wxFont( wxString::FromAscii(fontname
) ));
197 #endif // wxUSE_FONTDLG