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"
21 #include "wx/fontutil.h"
24 #include "wx/msgdlg.h"
26 #include "wx/gtk/private.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
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() );
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
);
65 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
66 dialog
->SetChosenFont( fontname
);
70 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
71 event
.SetEventObject( dialog
);
72 dialog
->GetEventHandler()->ProcessEvent( event
);
76 //-----------------------------------------------------------------------------
77 // "clicked" for Cancel-button
78 //-----------------------------------------------------------------------------
82 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
85 wxapp_install_idle_handler();
87 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
88 event
.SetEventObject( dialog
);
89 dialog
->GetEventHandler()->ProcessEvent( event
);
93 //-----------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------
97 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
99 bool wxFontDialog::DoCreate(wxWindow
*parent
)
101 m_needParent
= false;
103 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
104 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
,
105 wxDefaultValidator
, wxT("fontdialog") ))
107 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
111 wxString
m_message( _("Choose font") );
112 m_widget
= gtk_font_selection_dialog_new( wxGTK_CONV( m_message
) );
115 gtk_window_set_transient_for(GTK_WINDOW(m_widget
),
116 GTK_WINDOW(parent
->m_widget
));
118 GtkFontSelectionDialog
*sel
= GTK_FONT_SELECTION_DIALOG(m_widget
);
120 g_signal_connect (sel
->ok_button
, "clicked",
121 G_CALLBACK (gtk_fontdialog_ok_callback
), this);
123 g_signal_connect (sel
->cancel_button
, "clicked",
124 G_CALLBACK (gtk_fontdialog_cancel_callback
), this);
126 g_signal_connect (m_widget
, "delete_event",
127 G_CALLBACK (gtk_fontdialog_delete_callback
), this);
129 wxFont font
= m_fontData
.GetInitialFont();
132 const wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
137 const wxString
& fontname
= info
->ToString();
138 gtk_font_selection_dialog_set_font_name(sel
, wxGTK_CONV(fontname
));
142 // this is not supposed to happen!
143 wxFAIL_MSG(_T("font is ok but no native font info?"));
150 wxFontDialog::~wxFontDialog()
154 void wxFontDialog::SetChosenFont(const char *fontname
)
156 m_fontData
.SetChosenFont(wxFont( wxString::FromAscii(fontname
) ));
159 #endif // wxUSE_FONTDLG && !__WXGPE__