]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/fontdlg.cpp
More comments about non-native GTH widgets.
[wxWidgets.git] / src / gtk / fontdlg.cpp
CommitLineData
6dfaa4e5 1/////////////////////////////////////////////////////////////////////////////
93763ad5 2// Name: src/gtk/fontdlg.cpp
6dfaa4e5
RR
3// Purpose: wxFontDialog
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
6dfaa4e5
RR
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
88a7a4e1 13#if wxUSE_FONTDLG && !defined(__WXGPE__)
47e118ba 14
6dfaa4e5 15#include "wx/fontdlg.h"
88a7a4e1
WS
16
17#ifndef WX_PRECOMP
18 #include "wx/intl.h"
de6185e2 19 #include "wx/utils.h"
246c5004 20 #include "wx/msgdlg.h"
88a7a4e1
WS
21#endif
22
e1bf3ad3 23#include "wx/fontutil.h"
6dfaa4e5 24
9e691f46 25#include "wx/gtk/private.h"
6dfaa4e5 26
6dfaa4e5
RR
27//-----------------------------------------------------------------------------
28// "delete_event"
29//-----------------------------------------------------------------------------
30
865bb325 31extern "C" {
6dfaa4e5
RR
32static
33bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
34{
14819684 35 // don't need to install idle handler, its done from "event" signal
6dfaa4e5
RR
36
37/*
38 printf( "OnDelete from " );
39 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
40 printf( win->GetClassInfo()->GetClassName() );
41 printf( ".\n" );
42*/
43
44 win->Close();
45
93763ad5 46 return true;
6dfaa4e5 47}
865bb325 48}
6dfaa4e5
RR
49
50//-----------------------------------------------------------------------------
51// "clicked" for OK-button
52//-----------------------------------------------------------------------------
53
865bb325 54extern "C" {
6dfaa4e5
RR
55static
56void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
57{
0b862e20 58 if (g_isIdle)
6dfaa4e5
RR
59 wxapp_install_idle_handler();
60
61 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
6e7d0063 62
6dfaa4e5 63 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
2b5f62a0 64 dialog->SetChosenFont( fontname);
7beba2fc 65
6dfaa4e5 66 g_free( fontname );
0b862e20 67
6dfaa4e5
RR
68 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
69 event.SetEventObject( dialog );
70 dialog->GetEventHandler()->ProcessEvent( event );
71}
865bb325 72}
6dfaa4e5
RR
73
74//-----------------------------------------------------------------------------
75// "clicked" for Cancel-button
76//-----------------------------------------------------------------------------
77
865bb325 78extern "C" {
6dfaa4e5
RR
79static
80void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
81{
0b862e20 82 if (g_isIdle)
6dfaa4e5
RR
83 wxapp_install_idle_handler();
84
85 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
86 event.SetEventObject( dialog );
87 dialog->GetEventHandler()->ProcessEvent( event );
88}
865bb325 89}
6dfaa4e5
RR
90
91//-----------------------------------------------------------------------------
92// wxFontDialog
93//-----------------------------------------------------------------------------
94
dbc65e27 95IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
6dfaa4e5 96
dbc65e27 97bool wxFontDialog::DoCreate(wxWindow *parent)
6dfaa4e5 98{
93763ad5 99 m_needParent = false;
6dfaa4e5
RR
100
101 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
0b862e20 102 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
223d09f6 103 wxDefaultValidator, wxT("fontdialog") ))
6dfaa4e5 104 {
dbc65e27 105 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
93763ad5 106 return false;
6dfaa4e5 107 }
dbc65e27 108
6dfaa4e5 109 wxString m_message( _("Choose font") );
fab591c5 110 m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
6dfaa4e5 111
91cf5865
VS
112 if (parent)
113 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
114 GTK_WINDOW(parent->m_widget));
6dfaa4e5
RR
115
116 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
0b862e20 117
9fa72bd2
MR
118 g_signal_connect (sel->ok_button, "clicked",
119 G_CALLBACK (gtk_fontdialog_ok_callback), this);
6dfaa4e5 120
9fa72bd2
MR
121 g_signal_connect (sel->cancel_button, "clicked",
122 G_CALLBACK (gtk_fontdialog_cancel_callback), this);
0b862e20 123
9fa72bd2
MR
124 g_signal_connect (m_widget, "delete_event",
125 G_CALLBACK (gtk_fontdialog_delete_callback), this);
30764ab5
VZ
126
127 wxFont font = m_fontData.GetInitialFont();
128 if( font.Ok() )
129 {
74b0216f 130 const wxNativeFontInfo *info = font.GetNativeFontInfo();
30764ab5 131
7826e2dd
VZ
132 if ( info )
133 {
2f35f36b 134
2f35f36b 135 const wxString& fontname = info->ToString();
2f35f36b 136 gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname));
7826e2dd
VZ
137 }
138 else
139 {
140 // this is not supposed to happen!
141 wxFAIL_MSG(_T("font is ok but no native font info?"));
142 }
30764ab5 143 }
dbc65e27 144
93763ad5 145 return true;
6dfaa4e5
RR
146}
147
148wxFontDialog::~wxFontDialog()
149{
150}
151
dbc65e27
VZ
152void wxFontDialog::SetChosenFont(const char *fontname)
153{
2b5f62a0 154 m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) ));
dbc65e27
VZ
155}
156
88a7a4e1 157#endif // wxUSE_FONTDLG && !__WXGPE__