]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/fontdlg.cpp
update the selection properly after deleting the page
[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
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2 10#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
6dfaa4e5
RR
11#pragma implementation "fontdlg.h"
12#endif
13
14f355c2
VS
14// For compilers that support precompilation, includes "wx.h".
15#include "wx/wxprec.h"
16
1e6feb95
VZ
17#include "wx/defs.h"
18
19#if wxUSE_FONTDLG
20
7826e2dd 21#include "wx/fontutil.h"
6dfaa4e5
RR
22#include "wx/fontdlg.h"
23#include "wx/utils.h"
24#include "wx/intl.h"
25#include "wx/debug.h"
26#include "wx/msgdlg.h"
27
9e691f46 28#include "wx/gtk/private.h"
6dfaa4e5
RR
29
30//-----------------------------------------------------------------------------
31// idle system
32//-----------------------------------------------------------------------------
33
34extern void wxapp_install_idle_handler();
35extern bool g_isIdle;
36
37//-----------------------------------------------------------------------------
38// "delete_event"
39//-----------------------------------------------------------------------------
40
41static
42bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
43{
0b862e20 44 if (g_isIdle)
6dfaa4e5
RR
45 wxapp_install_idle_handler();
46
47/*
48 printf( "OnDelete from " );
49 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
50 printf( win->GetClassInfo()->GetClassName() );
51 printf( ".\n" );
52*/
53
54 win->Close();
55
56 return TRUE;
57}
58
59//-----------------------------------------------------------------------------
60// "clicked" for OK-button
61//-----------------------------------------------------------------------------
62
63static
64void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
65{
0b862e20 66 if (g_isIdle)
6dfaa4e5
RR
67 wxapp_install_idle_handler();
68
69 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
6e7d0063
RR
70
71#ifndef __WXGTK20__
6dfaa4e5 72 GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg);
0b862e20 73
6dfaa4e5
RR
74 if (!gfont)
75 {
7826e2dd
VZ
76 wxMessageBox(_("Please choose a valid font."), _("Error"),
77 wxOK | wxICON_ERROR);
6dfaa4e5
RR
78 return;
79 }
6e7d0063 80#endif
0b862e20 81
6dfaa4e5 82 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
2b5f62a0 83 dialog->SetChosenFont( fontname);
7beba2fc 84
6dfaa4e5 85 g_free( fontname );
0b862e20 86
6dfaa4e5
RR
87 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
88 event.SetEventObject( dialog );
89 dialog->GetEventHandler()->ProcessEvent( event );
90}
91
92//-----------------------------------------------------------------------------
93// "clicked" for Cancel-button
94//-----------------------------------------------------------------------------
95
96static
97void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
98{
0b862e20 99 if (g_isIdle)
6dfaa4e5
RR
100 wxapp_install_idle_handler();
101
102 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
103 event.SetEventObject( dialog );
104 dialog->GetEventHandler()->ProcessEvent( event );
105}
106
107//-----------------------------------------------------------------------------
108// wxFontDialog
109//-----------------------------------------------------------------------------
110
dbc65e27 111IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
6dfaa4e5 112
dbc65e27 113bool wxFontDialog::DoCreate(wxWindow *parent)
6dfaa4e5
RR
114{
115 m_needParent = FALSE;
116
117 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
0b862e20 118 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
223d09f6 119 wxDefaultValidator, wxT("fontdialog") ))
6dfaa4e5 120 {
dbc65e27
VZ
121 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
122 return FALSE;
6dfaa4e5 123 }
dbc65e27 124
6dfaa4e5 125 wxString m_message( _("Choose font") );
fab591c5 126 m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
6dfaa4e5
RR
127
128 int x = (gdk_screen_width () - 400) / 2;
129 int y = (gdk_screen_height () - 400) / 2;
130 gtk_widget_set_uposition( m_widget, x, y );
131
132 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
0b862e20 133
6dfaa4e5
RR
134 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
135 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this );
136
fab591c5 137#ifndef __WXGTK20__
6dfaa4e5 138 // strange way to internationalize
fab591c5
RR
139 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->ok_button) ), _("OK") );
140#endif
6dfaa4e5
RR
141
142 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
143 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this );
0b862e20 144
fab591c5 145#ifndef __WXGTK20__
6dfaa4e5 146 // strange way to internationalize
fab591c5
RR
147 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->cancel_button) ), _("Cancel") );
148#endif
0b862e20 149
6dfaa4e5
RR
150 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
151 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
30764ab5 152
db16cab4 153#ifndef __WXGTK20__
30764ab5
VZ
154 wxFont font = m_fontData.GetInitialFont();
155 if( font.Ok() )
156 {
74b0216f 157 const wxNativeFontInfo *info = font.GetNativeFontInfo();
30764ab5 158
7826e2dd
VZ
159 if ( info )
160 {
409d5a58 161 const wxString& fontname = info->GetXFontName();
7826e2dd
VZ
162 if ( !fontname )
163 font.GetInternalFont();
409d5a58
VZ
164 gtk_font_selection_dialog_set_font_name
165 (
166 sel,
167 wxConvCurrent->cWX2MB(fontname)
168 );
7826e2dd
VZ
169 }
170 else
171 {
172 // this is not supposed to happen!
173 wxFAIL_MSG(_T("font is ok but no native font info?"));
174 }
30764ab5 175 }
db16cab4 176#endif
dbc65e27
VZ
177
178 return TRUE;
6dfaa4e5
RR
179}
180
181wxFontDialog::~wxFontDialog()
182{
183}
184
dbc65e27
VZ
185void wxFontDialog::SetChosenFont(const char *fontname)
186{
2b5f62a0 187 m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) ));
dbc65e27
VZ
188}
189
1e6feb95
VZ
190#endif // wxUSE_FONTDLG
191