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
)
35 // don't need to install idle handler, its done from "event" signal
38 printf( "OnDelete from " );
39 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
40 printf( win->GetClassInfo()->GetClassName() );
50 //-----------------------------------------------------------------------------
51 // "clicked" for OK-button
52 //-----------------------------------------------------------------------------
56 void gtk_fontdialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFontDialog
*dialog
)
59 wxapp_install_idle_handler();
61 GtkFontSelectionDialog
*fontdlg
= GTK_FONT_SELECTION_DIALOG(dialog
->m_widget
);
63 wxGtkString
fontname(gtk_font_selection_dialog_get_font_name(fontdlg
));
64 dialog
->SetChosenFont( fontname
);
66 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
67 event
.SetEventObject( dialog
);
68 dialog
->GetEventHandler()->ProcessEvent( event
);
72 //-----------------------------------------------------------------------------
73 // "clicked" for Cancel-button
74 //-----------------------------------------------------------------------------
78 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
81 wxapp_install_idle_handler();
83 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
84 event
.SetEventObject( dialog
);
85 dialog
->GetEventHandler()->ProcessEvent( event
);
89 //-----------------------------------------------------------------------------
91 //-----------------------------------------------------------------------------
93 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
95 bool wxFontDialog::DoCreate(wxWindow
*parent
)
99 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
100 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
,
101 wxDefaultValidator
, wxT("fontdialog") ))
103 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
107 wxString
m_message( _("Choose font") );
108 m_widget
= gtk_font_selection_dialog_new( wxGTK_CONV( m_message
) );
111 gtk_window_set_transient_for(GTK_WINDOW(m_widget
),
112 GTK_WINDOW(parent
->m_widget
));
114 GtkFontSelectionDialog
*sel
= GTK_FONT_SELECTION_DIALOG(m_widget
);
116 g_signal_connect (sel
->ok_button
, "clicked",
117 G_CALLBACK (gtk_fontdialog_ok_callback
), this);
119 g_signal_connect (sel
->cancel_button
, "clicked",
120 G_CALLBACK (gtk_fontdialog_cancel_callback
), this);
122 g_signal_connect (m_widget
, "delete_event",
123 G_CALLBACK (gtk_fontdialog_delete_callback
), this);
125 wxFont font
= m_fontData
.GetInitialFont();
128 const wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
133 const wxString
& fontname
= info
->ToString();
134 gtk_font_selection_dialog_set_font_name(sel
, wxGTK_CONV(fontname
));
138 // this is not supposed to happen!
139 wxFAIL_MSG(_T("font is ok but no native font info?"));
146 wxFontDialog::~wxFontDialog()
150 void wxFontDialog::SetChosenFont(const char *fontname
)
152 m_fontData
.SetChosenFont(wxFont( wxString::FromAscii(fontname
) ));
155 #endif // wxUSE_FONTDLG && !__WXGPE__