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/fontutil.h"
15 #include "wx/fontdlg.h"
19 #include "wx/msgdlg.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 extern void wxapp_install_idle_handler();
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
35 bool gtk_fontdialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
38 wxapp_install_idle_handler();
41 printf( "OnDelete from " );
42 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
43 printf( win->GetClassInfo()->GetClassName() );
52 //-----------------------------------------------------------------------------
53 // "clicked" for OK-button
54 //-----------------------------------------------------------------------------
58 void gtk_fontdialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFontDialog
*dialog
)
61 wxapp_install_idle_handler();
63 GtkFontSelectionDialog
*fontdlg
= GTK_FONT_SELECTION_DIALOG(dialog
->m_widget
);
64 GdkFont
*gfont
= gtk_font_selection_dialog_get_font(fontdlg
);
68 wxMessageBox(_("Please choose a valid font."), _("Error"),
73 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
75 // extract the relevant bits from it
76 wxString xregistry
, xencoding
;
77 char *dash
= strrchr(fontname
, '-'); // find the last dash
82 dash
= strrchr(fontname
, '-'); // the last before one
89 wxFAIL_MSG( wxT("no registry in X font spec?") );
92 // restore the dash we changed to NUL above
93 *(fontname
+ strlen(fontname
)) = '-';
97 wxFAIL_MSG( wxT("no encoding in X font spec?") );
100 // transfer the X registry/encoding to wxFontData - they are used by
101 // wxFontMapper after wxFontDialog returns
102 wxFontData
& fontdata
= dialog
->m_fontData
;
104 // we ignore the facename here - should be enough to choose an arbitrary
105 // one if the registry/encoding are specified
106 fontdata
.EncodingInfo().xregistry
= xregistry
;
107 fontdata
.EncodingInfo().xencoding
= xencoding
;
109 // pass fontdata to wxFont ctor so that it can get the encoding from there
110 // if it is already known (otherwise it will try to deduce it itself)
111 dialog
->m_fontData
.SetChosenFont(wxFont(fontname
, fontdata
.GetEncoding()));
115 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
116 event
.SetEventObject( dialog
);
117 dialog
->GetEventHandler()->ProcessEvent( event
);
119 #endif // GTK+ 1.2 and later only
121 //-----------------------------------------------------------------------------
122 // "clicked" for Cancel-button
123 //-----------------------------------------------------------------------------
126 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
129 wxapp_install_idle_handler();
131 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
132 event
.SetEventObject( dialog
);
133 dialog
->GetEventHandler()->ProcessEvent( event
);
136 //-----------------------------------------------------------------------------
138 //-----------------------------------------------------------------------------
140 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
,wxDialog
)
142 wxFontDialog::wxFontDialog( wxWindow
*parent
, wxFontData
*fontdata
)
143 : m_fontData(*fontdata
)
145 m_needParent
= FALSE
;
147 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
148 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
,
149 wxDefaultValidator
, wxT("fontdialog") ))
151 wxFAIL_MSG( wxT("wxXX creation failed") );
155 wxString
m_message( _("Choose font") );
156 m_widget
= gtk_font_selection_dialog_new( m_message
.mbc_str() );
158 int x
= (gdk_screen_width () - 400) / 2;
159 int y
= (gdk_screen_height () - 400) / 2;
160 gtk_widget_set_uposition( m_widget
, x
, y
);
162 GtkFontSelectionDialog
*sel
= GTK_FONT_SELECTION_DIALOG(m_widget
);
164 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
165 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback
), (gpointer
*)this );
167 // strange way to internationalize
168 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel
->ok_button
)->child
), wxConvCurrent
->cWX2MB(_("OK")) );
170 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
171 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback
), (gpointer
*)this );
173 // strange way to internationalize
174 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel
->cancel_button
)->child
), wxConvCurrent
->cWX2MB(_("Cancel")) );
176 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
177 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback
), (gpointer
)this );
179 wxFont font
= m_fontData
.GetInitialFont();
182 wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
186 const wxString
& fontname
= info
->xFontName
;
188 font
.GetInternalFont();
189 gtk_font_selection_dialog_set_font_name(sel
,
190 wxConvCurrent
->cWX2MB(fontname
));
194 // this is not supposed to happen!
195 wxFAIL_MSG(_T("font is ok but no native font info?"));
200 wxFontDialog::~wxFontDialog()