1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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/gtk1/private.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 extern void wxapp_install_idle_handler();
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
40 bool gtk_fontdialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
43 wxapp_install_idle_handler();
46 printf( "OnDelete from " );
47 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
48 printf( win->GetClassInfo()->GetClassName() );
58 //-----------------------------------------------------------------------------
59 // "clicked" for OK-button
60 //-----------------------------------------------------------------------------
64 void gtk_fontdialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFontDialog
*dialog
)
67 wxapp_install_idle_handler();
69 GtkFontSelectionDialog
*fontdlg
= GTK_FONT_SELECTION_DIALOG(dialog
->m_widget
);
71 GdkFont
*gfont
= gtk_font_selection_dialog_get_font(fontdlg
);
75 wxMessageBox(_("Please choose a valid font."), _("Error"),
80 gchar
*fontname
= gtk_font_selection_dialog_get_font_name(fontdlg
);
81 dialog
->SetChosenFont( fontname
);
85 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
86 event
.SetEventObject( dialog
);
87 dialog
->HandleWindowEvent( event
);
91 //-----------------------------------------------------------------------------
92 // "clicked" for Cancel-button
93 //-----------------------------------------------------------------------------
97 void gtk_fontdialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFontDialog
*dialog
)
100 wxapp_install_idle_handler();
102 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
103 event
.SetEventObject( dialog
);
104 dialog
->HandleWindowEvent( event
);
108 //-----------------------------------------------------------------------------
110 //-----------------------------------------------------------------------------
112 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
114 bool wxFontDialog::DoCreate(wxWindow
*parent
)
116 m_needParent
= false;
118 if (!PreCreation( parent
, wxDefaultPosition
, wxDefaultSize
) ||
119 !CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
,
120 wxDefaultValidator
, wxT("fontdialog") ))
122 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
126 wxString
m_message( _("Choose font") );
127 m_widget
= gtk_font_selection_dialog_new( wxGTK_CONV( m_message
) );
130 gtk_window_set_transient_for(GTK_WINDOW(m_widget
),
131 GTK_WINDOW(parent
->m_widget
));
133 GtkFontSelectionDialog
*sel
= GTK_FONT_SELECTION_DIALOG(m_widget
);
135 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
136 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback
), (gpointer
*)this );
138 // strange way to internationalize
139 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->ok_button
) ), _("OK") );
141 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
142 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback
), (gpointer
*)this );
144 // strange way to internationalize
145 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel
->cancel_button
) ), _("Cancel") );
147 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
148 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback
), (gpointer
)this );
150 wxFont font
= m_fontData
.GetInitialFont();
153 const wxNativeFontInfo
*info
= font
.GetNativeFontInfo();
158 const wxString
& fontname
= info
->GetXFontName();
160 font
.GetInternalFont();
162 gtk_font_selection_dialog_set_font_name(sel
, wxGTK_CONV(fontname
));
166 // this is not supposed to happen!
167 wxFAIL_MSG(wxT("font is ok but no native font info?"));
174 wxFontDialog::~wxFontDialog()
178 void wxFontDialog::SetChosenFont(const char *fontname
)
180 m_fontData
.SetChosenFont(wxFont( wxString::FromAscii(fontname
) ));
183 #endif // wxUSE_FONTDLG && !defined(__WXGPE__)