1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFontDialog
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "fontdlg.h"
14 #include "wx/fontdlg.h"
18 #include "wx/msgdlg.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 extern void wxapp_install_idle_handler();
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
34 bool gtk_fontdialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
37 wxapp_install_idle_handler();
40 printf( "OnDelete from " );
41 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
42 printf( win->GetClassInfo()->GetClassName() );
51 //-----------------------------------------------------------------------------
52 // "clicked" for OK-button
53 //-----------------------------------------------------------------------------
56 void gtk_fontdialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFontDialog
*dialog
)
59 wxapp_install_idle_handler();
61 GtkFontSelectionDialog
*fontdlg
= GTK_FONT_SELECTION_DIALOG(dialog
->m_widget
);
62 GdkFont
*gfont
= gtk_font_selection_dialog_get_font(fontdlg
);
66 wxMessageBox(_("Please choose a valid font."), _("Error"), wxOK
);
70 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
71 wxFont
font( gfont
, fontname
);
73 dialog
->m_fontData
.SetChosenFont( font
);
75 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
76 event
.SetEventObject( dialog
);
77 dialog
->GetEventHandler()->ProcessEvent( event
);
80 //-----------------------------------------------------------------------------
81 // "clicked" for Cancel-button
82 //-----------------------------------------------------------------------------
85 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
88 wxapp_install_idle_handler();
90 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
91 event
.SetEventObject( dialog
);
92 dialog
->GetEventHandler()->ProcessEvent( event
);
95 //-----------------------------------------------------------------------------
97 //-----------------------------------------------------------------------------
99 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
,wxDialog
)
101 wxFontDialog::wxFontDialog( wxWindow
*parent
, wxFontData
*data
)
103 m_needParent
= FALSE
;
105 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
106 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
,
107 wxDefaultValidator
, _T("fontdialog") ))
109 wxFAIL_MSG( _T("wxXX creation failed") );
113 wxString
m_message( _("Choose font") );
114 m_widget
= gtk_font_selection_dialog_new( m_message
.mbc_str() );
116 int x
= (gdk_screen_width () - 400) / 2;
117 int y
= (gdk_screen_height () - 400) / 2;
118 gtk_widget_set_uposition( m_widget
, x
, y
);
120 GtkFontSelectionDialog
*sel
= GTK_FONT_SELECTION_DIALOG(m_widget
);
122 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
123 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback
), (gpointer
*)this );
125 // strange way to internationalize
126 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel
->ok_button
)->child
), wxConvCurrent
->cWX2MB(_("OK")) );
128 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
129 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback
), (gpointer
*)this );
131 // strange way to internationalize
132 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel
->cancel_button
)->child
), wxConvCurrent
->cWX2MB(_("Cancel")) );
134 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
135 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback
), (gpointer
)this );
138 wxFontDialog::~wxFontDialog()