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 //----------------------------------------------------------------------------- 
  57 void gtk_fontdialog_ok_callback( GtkWidget 
*WXUNUSED(widget
), wxFontDialog 
*dialog 
) 
  60         wxapp_install_idle_handler(); 
  62     GtkFontSelectionDialog 
*fontdlg 
= GTK_FONT_SELECTION_DIALOG(dialog
->m_widget
); 
  63     GdkFont 
*gfont 
= gtk_font_selection_dialog_get_font(fontdlg
); 
  67         wxMessageBox(_("Please choose a valid font."), _("Error"), wxOK
); 
  71     gchar 
*fontname 
= gtk_font_selection_dialog_get_font_name(fontdlg
); 
  73     // extract the relevant bits from it 
  74     wxString xregistry
, xencoding
; 
  75     char *dash 
= strrchr(fontname
, '-');    // find the last dash 
  80         dash 
= strrchr(fontname
, '-');      // the last before one 
  87             wxFAIL_MSG( wxT("no registry in X font spec?") ); 
  90         // restore the dash we changed to NUL above 
  91         *(fontname 
+ strlen(fontname
)) = '-'; 
  95         wxFAIL_MSG( wxT("no encoding in X font spec?") ); 
  98     // transfer the X registry/encoding to wxFontData - they are used by 
  99     // wxFontMapper after wxFontDialog returns 
 100     wxFontData
& fontdata 
= dialog
->m_fontData
; 
 102     // we ignore the facename here - should be enough to choose an arbitrary 
 103     // one if the registry/encoding are specified 
 104     //  dialog->m_fontData.EncodingInfo().facename = xfamily; 
 105     fontdata
.EncodingInfo().xregistry 
= xregistry
; 
 106     fontdata
.EncodingInfo().xencoding 
= xencoding
; 
 108     // pass fontdata to wxFont ctor so that it can get the encoding from there 
 109     // if it is already known (otherwise it will try to deduce it itself) 
 110     dialog
->m_fontData
.SetChosenFont( wxFont(fontname
, fontdata
) ); 
 114     wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
); 
 115     event
.SetEventObject( dialog 
); 
 116     dialog
->GetEventHandler()->ProcessEvent( event 
); 
 118 #endif // GTK+ 1.2 and later only 
 120 //----------------------------------------------------------------------------- 
 121 // "clicked" for Cancel-button 
 122 //----------------------------------------------------------------------------- 
 125 void gtk_fontdialog_cancel_callback( GtkWidget 
*WXUNUSED(w
), wxFontDialog 
*dialog 
) 
 128         wxapp_install_idle_handler(); 
 130     wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
); 
 131     event
.SetEventObject( dialog 
); 
 132     dialog
->GetEventHandler()->ProcessEvent( event 
); 
 135 //----------------------------------------------------------------------------- 
 137 //----------------------------------------------------------------------------- 
 139 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
,wxDialog
) 
 141 wxFontDialog::wxFontDialog( wxWindow 
*parent
, wxFontData 
*fontdata 
) 
 142             : m_fontData(*fontdata
) 
 144     m_needParent 
= FALSE
; 
 146     if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize 
) || 
 147         !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
, 
 148                      wxDefaultValidator
, wxT("fontdialog") )) 
 150         wxFAIL_MSG( wxT("wxXX creation failed") ); 
 154     wxString 
m_message( _("Choose font") ); 
 155     m_widget 
= gtk_font_selection_dialog_new( m_message
.mbc_str() ); 
 157     int x 
= (gdk_screen_width () - 400) / 2; 
 158     int y 
= (gdk_screen_height () - 400) / 2; 
 159     gtk_widget_set_uposition( m_widget
, x
, y 
); 
 161     GtkFontSelectionDialog 
*sel 
= GTK_FONT_SELECTION_DIALOG(m_widget
); 
 163     gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked", 
 164       GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback
), (gpointer
*)this ); 
 166     // strange way to internationalize 
 167     gtk_label_set( GTK_LABEL( GTK_BUTTON(sel
->ok_button
)->child 
), wxConvCurrent
->cWX2MB(_("OK")) ); 
 169     gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked", 
 170       GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback
), (gpointer
*)this ); 
 172     // strange way to internationalize 
 173     gtk_label_set( GTK_LABEL( GTK_BUTTON(sel
->cancel_button
)->child 
), wxConvCurrent
->cWX2MB(_("Cancel")) ); 
 175     gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event", 
 176         GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback
), (gpointer
)this ); 
 179 wxFontDialog::~wxFontDialog()