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"
21 #include "wx/fontutil.h"
22 #include "wx/fontdlg.h"
26 #include "wx/msgdlg.h"
28 #include "wx/gtk/private.h"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 extern void wxapp_install_idle_handler();
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
42 bool gtk_fontdialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
45 wxapp_install_idle_handler();
48 printf( "OnDelete from " );
49 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
50 printf( win->GetClassInfo()->GetClassName() );
59 //-----------------------------------------------------------------------------
60 // "clicked" for OK-button
61 //-----------------------------------------------------------------------------
64 void gtk_fontdialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFontDialog
*dialog
)
67 wxapp_install_idle_handler();
69 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"),
82 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
83 dialog
->SetChosenFont( fontname
);
87 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
88 event
.SetEventObject( dialog
);
89 dialog
->GetEventHandler()->ProcessEvent( event
);
92 //-----------------------------------------------------------------------------
93 // "clicked" for Cancel-button
94 //-----------------------------------------------------------------------------
97 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
100 wxapp_install_idle_handler();
102 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
103 event
.SetEventObject( dialog
);
104 dialog
->GetEventHandler()->ProcessEvent( 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
) );
128 int x
= (gdk_screen_width () - 400) / 2;
129 int y
= (gdk_screen_height () - 400) / 2;
130 gtk_widget_set_uposition( m_widget
, x
, y
);
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 );
138 // strange way to internationalize
139 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 );
146 // strange way to internationalize
147 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->cancel_button
) ), _("Cancel") );
150 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
151 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback
), (gpointer
)this );
154 wxFont font
= m_fontData
.GetInitialFont();
157 const wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
161 const wxString
& fontname
= info
->GetXFontName();
163 font
.GetInternalFont();
164 gtk_font_selection_dialog_set_font_name
167 wxConvCurrent
->cWX2MB(fontname
)
172 // this is not supposed to happen!
173 wxFAIL_MSG(_T("font is ok but no native font info?"));
181 wxFontDialog::~wxFontDialog()
185 void wxFontDialog::SetChosenFont(const char *fontname
)
187 m_fontData
.SetChosenFont(wxFont( wxString::FromAscii(fontname
) ));
190 #endif // wxUSE_FONTDLG