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