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/fontutil.h"
24 #include "wx/fontdlg.h"
28 #include "wx/msgdlg.h"
30 #include "wx/gtk/private.h"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 extern void wxapp_install_idle_handler();
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
44 bool gtk_fontdialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
47 wxapp_install_idle_handler();
50 printf( "OnDelete from " );
51 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
52 printf( win->GetClassInfo()->GetClassName() );
61 //-----------------------------------------------------------------------------
62 // "clicked" for OK-button
63 //-----------------------------------------------------------------------------
66 void gtk_fontdialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFontDialog
*dialog
)
69 wxapp_install_idle_handler();
71 GtkFontSelectionDialog
*fontdlg
= GTK_FONT_SELECTION_DIALOG(dialog
->m_widget
);
74 GdkFont
*gfont
= gtk_font_selection_dialog_get_font(fontdlg
);
78 wxMessageBox(_("Please choose a valid font."), _("Error"),
84 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
85 dialog
->SetChosenFont( fontname
);
89 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
90 event
.SetEventObject( dialog
);
91 dialog
->GetEventHandler()->ProcessEvent( event
);
94 //-----------------------------------------------------------------------------
95 // "clicked" for Cancel-button
96 //-----------------------------------------------------------------------------
99 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
102 wxapp_install_idle_handler();
104 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
105 event
.SetEventObject( dialog
);
106 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
) );
130 int x
= (gdk_screen_width () - 400) / 2;
131 int y
= (gdk_screen_height () - 400) / 2;
132 gtk_widget_set_uposition( m_widget
, x
, y
);
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 );
140 // strange way to internationalize
141 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->ok_button
) ), _("OK") );
144 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
145 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback
), (gpointer
*)this );
148 // strange way to internationalize
149 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->cancel_button
) ), _("Cancel") );
152 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
153 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback
), (gpointer
)this );
156 wxFont font
= m_fontData
.GetInitialFont();
159 const wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
163 const wxString
& fontname
= info
->GetXFontName();
165 font
.GetInternalFont();
166 gtk_font_selection_dialog_set_font_name
169 wxConvCurrent
->cWX2MB(fontname
)
174 // this is not supposed to happen!
175 wxFAIL_MSG(_T("font is ok but no native font info?"));
183 wxFontDialog::~wxFontDialog()
187 void wxFontDialog::SetChosenFont(const char *fontname
)
189 m_fontData
.SetChosenFont(wxFont( wxString::FromAscii(fontname
) ));
192 #endif // wxUSE_FONTDLG