1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/gtk/fontdlg.cpp 
   3 // Purpose:     wxFontDialog 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  10 // For compilers that support precompilation, includes "wx.h". 
  11 #include "wx/wxprec.h" 
  13 #if wxUSE_FONTDLG && !defined(__WXGPE__) 
  15 #include "wx/fontdlg.h" 
  20     #include "wx/msgdlg.h" 
  23 #include "wx/fontutil.h" 
  25 #include "wx/gtk/private.h" 
  27 //----------------------------------------------------------------------------- 
  29 //----------------------------------------------------------------------------- 
  33 bool gtk_fontdialog_delete_callback( GtkWidget 
*WXUNUSED(widget
), GdkEvent 
*WXUNUSED(event
), wxDialog 
*win 
) 
  36         wxapp_install_idle_handler(); 
  39     printf( "OnDelete from " ); 
  40     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
  41         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
); 
  64     gchar 
*fontname 
= gtk_font_selection_dialog_get_font_name(fontdlg
); 
  65     dialog
->SetChosenFont( fontname
); 
  69     wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
); 
  70     event
.SetEventObject( dialog 
); 
  71     dialog
->GetEventHandler()->ProcessEvent( event 
); 
  75 //----------------------------------------------------------------------------- 
  76 // "clicked" for Cancel-button 
  77 //----------------------------------------------------------------------------- 
  81 void gtk_fontdialog_cancel_callback( GtkWidget 
*WXUNUSED(w
), wxFontDialog 
*dialog 
) 
  84         wxapp_install_idle_handler(); 
  86     wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
); 
  87     event
.SetEventObject( dialog 
); 
  88     dialog
->GetEventHandler()->ProcessEvent( event 
); 
  92 //----------------------------------------------------------------------------- 
  94 //----------------------------------------------------------------------------- 
  96 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
) 
  98 bool wxFontDialog::DoCreate(wxWindow 
*parent
) 
 100     m_needParent 
= false; 
 102     if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize 
) || 
 103         !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
, 
 104                      wxDefaultValidator
, wxT("fontdialog") )) 
 106         wxFAIL_MSG( wxT("wxFontDialog creation failed") ); 
 110     wxString 
m_message( _("Choose font") ); 
 111     m_widget 
= gtk_font_selection_dialog_new( wxGTK_CONV( m_message 
) ); 
 114         gtk_window_set_transient_for(GTK_WINDOW(m_widget
), 
 115                                      GTK_WINDOW(parent
->m_widget
)); 
 117     GtkFontSelectionDialog 
*sel 
= GTK_FONT_SELECTION_DIALOG(m_widget
); 
 119     g_signal_connect (sel
->ok_button
, "clicked", 
 120                       G_CALLBACK (gtk_fontdialog_ok_callback
), this); 
 122     g_signal_connect (sel
->cancel_button
, "clicked", 
 123                       G_CALLBACK (gtk_fontdialog_cancel_callback
), this); 
 125     g_signal_connect (m_widget
, "delete_event", 
 126                       G_CALLBACK (gtk_fontdialog_delete_callback
), this); 
 128     wxFont font 
= m_fontData
.GetInitialFont(); 
 131         const wxNativeFontInfo 
*info 
= font
.GetNativeFontInfo(); 
 136             const wxString
& fontname 
= info
->ToString(); 
 137             gtk_font_selection_dialog_set_font_name(sel
, wxGTK_CONV(fontname
)); 
 141             // this is not supposed to happen! 
 142             wxFAIL_MSG(_T("font is ok but no native font info?")); 
 149 wxFontDialog::~wxFontDialog() 
 153 void wxFontDialog::SetChosenFont(const char *fontname
) 
 155     m_fontData
.SetChosenFont(wxFont( wxString::FromAscii(fontname
) )); 
 158 #endif // wxUSE_FONTDLG && !__WXGPE__