1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/fontdlg.cpp
3 // Purpose: wxFontDialog
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "fontdlg.h"
18 #include "wx/fontutil.h"
19 #include "wx/fontdlg.h"
23 #include "wx/msgdlg.h"
25 #include "wx/gtk/private.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 extern void wxapp_install_idle_handler();
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
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() );
56 //-----------------------------------------------------------------------------
57 // "clicked" for OK-button
58 //-----------------------------------------------------------------------------
61 void gtk_fontdialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFontDialog
*dialog
)
64 wxapp_install_idle_handler();
66 GtkFontSelectionDialog
*fontdlg
= GTK_FONT_SELECTION_DIALOG(dialog
->m_widget
);
67 GdkFont
*gfont
= gtk_font_selection_dialog_get_font(fontdlg
);
71 wxMessageBox(_("Please choose a valid font."), _("Error"),
76 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
78 dialog
->SetChosenFont(fontname
);
82 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
83 event
.SetEventObject( dialog
);
84 dialog
->GetEventHandler()->ProcessEvent( event
);
87 //-----------------------------------------------------------------------------
88 // "clicked" for Cancel-button
89 //-----------------------------------------------------------------------------
92 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
95 wxapp_install_idle_handler();
97 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
98 event
.SetEventObject( dialog
);
99 dialog
->GetEventHandler()->ProcessEvent( event
);
102 //-----------------------------------------------------------------------------
104 //-----------------------------------------------------------------------------
106 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
108 bool wxFontDialog::DoCreate(wxWindow
*parent
)
110 m_needParent
= FALSE
;
112 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
113 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
,
114 wxDefaultValidator
, wxT("fontdialog") ))
116 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
120 wxString
m_message( _("Choose font") );
121 m_widget
= gtk_font_selection_dialog_new( wxGTK_CONV( m_message
) );
123 int x
= (gdk_screen_width () - 400) / 2;
124 int y
= (gdk_screen_height () - 400) / 2;
125 gtk_widget_set_uposition( m_widget
, x
, y
);
127 GtkFontSelectionDialog
*sel
= GTK_FONT_SELECTION_DIALOG(m_widget
);
129 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
130 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback
), (gpointer
*)this );
133 // strange way to internationalize
134 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->ok_button
) ), _("OK") );
137 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
138 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback
), (gpointer
*)this );
141 // strange way to internationalize
142 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->cancel_button
) ), _("Cancel") );
145 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
146 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback
), (gpointer
)this );
148 wxFont font
= m_fontData
.GetInitialFont();
151 wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
155 const wxString
& fontname
= info
->GetXFontName();
157 font
.GetInternalFont();
158 gtk_font_selection_dialog_set_font_name
161 wxConvCurrent
->cWX2MB(fontname
)
166 // this is not supposed to happen!
167 wxFAIL_MSG(_T("font is ok but no native font info?"));
174 wxFontDialog::~wxFontDialog()
178 void wxFontDialog::SetChosenFont(const char *fontname
)
180 m_fontData
.SetChosenFont(wxFont(fontname
));
183 #endif // wxUSE_FONTDLG