]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/fontdlg.cpp
Separated out book control sizing code
[wxWidgets.git] / src / gtk / fontdlg.cpp
CommitLineData
6dfaa4e5 1/////////////////////////////////////////////////////////////////////////////
1e6feb95 2// Name: 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
1e6feb95
VZ
13#include "wx/defs.h"
14
15#if wxUSE_FONTDLG
16
47e118ba
RR
17#ifndef __WXGPE__
18
6dfaa4e5 19#include "wx/fontdlg.h"
e1bf3ad3 20#include "wx/fontutil.h"
6dfaa4e5
RR
21#include "wx/utils.h"
22#include "wx/intl.h"
23#include "wx/debug.h"
24#include "wx/msgdlg.h"
25
9e691f46 26#include "wx/gtk/private.h"
6dfaa4e5
RR
27
28//-----------------------------------------------------------------------------
29// idle system
30//-----------------------------------------------------------------------------
31
32extern void wxapp_install_idle_handler();
33extern bool g_isIdle;
34
35//-----------------------------------------------------------------------------
36// "delete_event"
37//-----------------------------------------------------------------------------
38
865bb325 39extern "C" {
6dfaa4e5
RR
40static
41bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
42{
0b862e20 43 if (g_isIdle)
6dfaa4e5
RR
44 wxapp_install_idle_handler();
45
46/*
47 printf( "OnDelete from " );
48 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
49 printf( win->GetClassInfo()->GetClassName() );
50 printf( ".\n" );
51*/
52
53 win->Close();
54
55 return TRUE;
56}
865bb325 57}
6dfaa4e5
RR
58
59//-----------------------------------------------------------------------------
60// "clicked" for OK-button
61//-----------------------------------------------------------------------------
62
865bb325 63extern "C" {
6dfaa4e5
RR
64static
65void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
66{
0b862e20 67 if (g_isIdle)
6dfaa4e5
RR
68 wxapp_install_idle_handler();
69
70 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
6e7d0063 71
6dfaa4e5 72 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
2b5f62a0 73 dialog->SetChosenFont( fontname);
7beba2fc 74
6dfaa4e5 75 g_free( fontname );
0b862e20 76
6dfaa4e5
RR
77 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
78 event.SetEventObject( dialog );
79 dialog->GetEventHandler()->ProcessEvent( event );
80}
865bb325 81}
6dfaa4e5
RR
82
83//-----------------------------------------------------------------------------
84// "clicked" for Cancel-button
85//-----------------------------------------------------------------------------
86
865bb325 87extern "C" {
6dfaa4e5
RR
88static
89void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
90{
0b862e20 91 if (g_isIdle)
6dfaa4e5
RR
92 wxapp_install_idle_handler();
93
94 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
95 event.SetEventObject( dialog );
96 dialog->GetEventHandler()->ProcessEvent( event );
97}
865bb325 98}
6dfaa4e5
RR
99
100//-----------------------------------------------------------------------------
101// wxFontDialog
102//-----------------------------------------------------------------------------
103
dbc65e27 104IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
6dfaa4e5 105
dbc65e27 106bool wxFontDialog::DoCreate(wxWindow *parent)
6dfaa4e5
RR
107{
108 m_needParent = FALSE;
109
110 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
0b862e20 111 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
223d09f6 112 wxDefaultValidator, wxT("fontdialog") ))
6dfaa4e5 113 {
dbc65e27
VZ
114 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
115 return FALSE;
6dfaa4e5 116 }
dbc65e27 117
6dfaa4e5 118 wxString m_message( _("Choose font") );
fab591c5 119 m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
6dfaa4e5 120
91cf5865
VS
121 if (parent)
122 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
123 GTK_WINDOW(parent->m_widget));
6dfaa4e5
RR
124
125 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
0b862e20 126
9fa72bd2
MR
127 g_signal_connect (sel->ok_button, "clicked",
128 G_CALLBACK (gtk_fontdialog_ok_callback), this);
6dfaa4e5 129
9fa72bd2
MR
130 g_signal_connect (sel->cancel_button, "clicked",
131 G_CALLBACK (gtk_fontdialog_cancel_callback), this);
0b862e20 132
9fa72bd2
MR
133 g_signal_connect (m_widget, "delete_event",
134 G_CALLBACK (gtk_fontdialog_delete_callback), this);
30764ab5
VZ
135
136 wxFont font = m_fontData.GetInitialFont();
137 if( font.Ok() )
138 {
74b0216f 139 const wxNativeFontInfo *info = font.GetNativeFontInfo();
30764ab5 140
7826e2dd
VZ
141 if ( info )
142 {
2f35f36b 143
2f35f36b 144 const wxString& fontname = info->ToString();
2f35f36b 145 gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname));
7826e2dd
VZ
146 }
147 else
148 {
149 // this is not supposed to happen!
150 wxFAIL_MSG(_T("font is ok but no native font info?"));
151 }
30764ab5 152 }
dbc65e27
VZ
153
154 return TRUE;
6dfaa4e5
RR
155}
156
157wxFontDialog::~wxFontDialog()
158{
159}
160
dbc65e27
VZ
161void wxFontDialog::SetChosenFont(const char *fontname)
162{
2b5f62a0 163 m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) ));
dbc65e27
VZ
164}
165
1e6feb95
VZ
166#endif // wxUSE_FONTDLG
167
b63b07a8
RL
168#endif // GPE
169