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 //-----------------------------------------------------------------------------
62 void gtk_fontdialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFontDialog
*dialog
)
65 wxapp_install_idle_handler();
67 GtkFontSelectionDialog
*fontdlg
= GTK_FONT_SELECTION_DIALOG(dialog
->m_widget
);
68 GdkFont
*gfont
= gtk_font_selection_dialog_get_font(fontdlg
);
72 wxMessageBox(_("Please choose a valid font."), _("Error"),
77 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
79 dialog
->SetChosenFont(fontname
);
83 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
84 event
.SetEventObject( dialog
);
85 dialog
->GetEventHandler()->ProcessEvent( event
);
87 #endif // GTK+ 1.2 and later only
89 //-----------------------------------------------------------------------------
90 // "clicked" for Cancel-button
91 //-----------------------------------------------------------------------------
94 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
97 wxapp_install_idle_handler();
99 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
100 event
.SetEventObject( dialog
);
101 dialog
->GetEventHandler()->ProcessEvent( event
);
104 //-----------------------------------------------------------------------------
106 //-----------------------------------------------------------------------------
108 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
110 bool wxFontDialog::DoCreate(wxWindow
*parent
)
112 m_needParent
= FALSE
;
114 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
115 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
,
116 wxDefaultValidator
, wxT("fontdialog") ))
118 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
122 wxString
m_message( _("Choose font") );
123 m_widget
= gtk_font_selection_dialog_new( m_message
.mbc_str() );
125 int x
= (gdk_screen_width () - 400) / 2;
126 int y
= (gdk_screen_height () - 400) / 2;
127 gtk_widget_set_uposition( m_widget
, x
, y
);
129 GtkFontSelectionDialog
*sel
= GTK_FONT_SELECTION_DIALOG(m_widget
);
131 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
132 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback
), (gpointer
*)this );
134 // strange way to internationalize
135 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->ok_button
) ), wxConvCurrent
->cWX2MB(_("OK")) );
137 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
138 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback
), (gpointer
*)this );
140 // strange way to internationalize
141 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->cancel_button
) ), wxConvCurrent
->cWX2MB(_("Cancel")) );
143 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
144 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback
), (gpointer
)this );
146 wxFont font
= m_fontData
.GetInitialFont();
149 wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
153 const wxString
& fontname
= info
->GetXFontName();
155 font
.GetInternalFont();
156 gtk_font_selection_dialog_set_font_name
159 wxConvCurrent
->cWX2MB(fontname
)
164 // this is not supposed to happen!
165 wxFAIL_MSG(_T("font is ok but no native font info?"));
172 wxFontDialog::~wxFontDialog()
176 void wxFontDialog::SetChosenFont(const char *fontname
)
178 m_fontData
.SetChosenFont(wxFont(fontname
));
181 #endif // wxUSE_FONTDLG