1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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"
19 #include "wx/fontdlg.h"
20 #include "wx/fontutil.h"
24 #include "wx/msgdlg.h"
26 #include "wx/gtk/private.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 extern void wxapp_install_idle_handler();
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
41 bool gtk_fontdialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
44 wxapp_install_idle_handler();
47 printf( "OnDelete from " );
48 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
49 printf( win->GetClassInfo()->GetClassName() );
59 //-----------------------------------------------------------------------------
60 // "clicked" for OK-button
61 //-----------------------------------------------------------------------------
65 void gtk_fontdialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFontDialog
*dialog
)
68 wxapp_install_idle_handler();
70 GtkFontSelectionDialog
*fontdlg
= GTK_FONT_SELECTION_DIALOG(dialog
->m_widget
);
72 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
73 dialog
->SetChosenFont( fontname
);
77 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
78 event
.SetEventObject( dialog
);
79 dialog
->GetEventHandler()->ProcessEvent( event
);
83 //-----------------------------------------------------------------------------
84 // "clicked" for Cancel-button
85 //-----------------------------------------------------------------------------
89 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
92 wxapp_install_idle_handler();
94 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
95 event
.SetEventObject( dialog
);
96 dialog
->GetEventHandler()->ProcessEvent( event
);
100 //-----------------------------------------------------------------------------
102 //-----------------------------------------------------------------------------
104 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
106 bool wxFontDialog::DoCreate(wxWindow
*parent
)
108 m_needParent
= FALSE
;
110 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
111 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
,
112 wxDefaultValidator
, wxT("fontdialog") ))
114 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
118 wxString
m_message( _("Choose font") );
119 m_widget
= gtk_font_selection_dialog_new( wxGTK_CONV( m_message
) );
122 gtk_window_set_transient_for(GTK_WINDOW(m_widget
),
123 GTK_WINDOW(parent
->m_widget
));
125 GtkFontSelectionDialog
*sel
= GTK_FONT_SELECTION_DIALOG(m_widget
);
127 g_signal_connect (sel
->ok_button
, "clicked",
128 G_CALLBACK (gtk_fontdialog_ok_callback
), this);
130 g_signal_connect (sel
->cancel_button
, "clicked",
131 G_CALLBACK (gtk_fontdialog_cancel_callback
), this);
133 g_signal_connect (m_widget
, "delete_event",
134 G_CALLBACK (gtk_fontdialog_delete_callback
), this);
136 wxFont font
= m_fontData
.GetInitialFont();
139 const wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
144 const wxString
& fontname
= info
->ToString();
145 gtk_font_selection_dialog_set_font_name(sel
, wxGTK_CONV(fontname
));
149 // this is not supposed to happen!
150 wxFAIL_MSG(_T("font is ok but no native font info?"));
157 wxFontDialog::~wxFontDialog()
161 void wxFontDialog::SetChosenFont(const char *fontname
)
163 m_fontData
.SetChosenFont(wxFont( wxString::FromAscii(fontname
) ));
166 #endif // wxUSE_FONTDLG