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