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