]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/fontdlg.cpp
Hopefully fixed library names generated by wx-config for OS/2's PM port.
[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
6dfaa4e5 23#include "wx/fontdlg.h"
e1bf3ad3 24#include "wx/fontutil.h"
6dfaa4e5
RR
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
865bb325 43extern "C" {
6dfaa4e5
RR
44static
45bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
46{
0b862e20 47 if (g_isIdle)
6dfaa4e5
RR
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}
865bb325 61}
6dfaa4e5
RR
62
63//-----------------------------------------------------------------------------
64// "clicked" for OK-button
65//-----------------------------------------------------------------------------
66
865bb325 67extern "C" {
6dfaa4e5
RR
68static
69void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
70{
0b862e20 71 if (g_isIdle)
6dfaa4e5
RR
72 wxapp_install_idle_handler();
73
74 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
6e7d0063
RR
75
76#ifndef __WXGTK20__
6dfaa4e5 77 GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg);
0b862e20 78
6dfaa4e5
RR
79 if (!gfont)
80 {
7826e2dd
VZ
81 wxMessageBox(_("Please choose a valid font."), _("Error"),
82 wxOK | wxICON_ERROR);
6dfaa4e5
RR
83 return;
84 }
6e7d0063 85#endif
0b862e20 86
6dfaa4e5 87 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
2b5f62a0 88 dialog->SetChosenFont( fontname);
7beba2fc 89
6dfaa4e5 90 g_free( fontname );
0b862e20 91
6dfaa4e5
RR
92 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
93 event.SetEventObject( dialog );
94 dialog->GetEventHandler()->ProcessEvent( event );
95}
865bb325 96}
6dfaa4e5
RR
97
98//-----------------------------------------------------------------------------
99// "clicked" for Cancel-button
100//-----------------------------------------------------------------------------
101
865bb325 102extern "C" {
6dfaa4e5
RR
103static
104void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
105{
0b862e20 106 if (g_isIdle)
6dfaa4e5
RR
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}
865bb325 113}
6dfaa4e5
RR
114
115//-----------------------------------------------------------------------------
116// wxFontDialog
117//-----------------------------------------------------------------------------
118
dbc65e27 119IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
6dfaa4e5 120
dbc65e27 121bool wxFontDialog::DoCreate(wxWindow *parent)
6dfaa4e5
RR
122{
123 m_needParent = FALSE;
124
125 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
0b862e20 126 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
223d09f6 127 wxDefaultValidator, wxT("fontdialog") ))
6dfaa4e5 128 {
dbc65e27
VZ
129 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
130 return FALSE;
6dfaa4e5 131 }
dbc65e27 132
6dfaa4e5 133 wxString m_message( _("Choose font") );
fab591c5 134 m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
6dfaa4e5 135
91cf5865
VS
136 if (parent)
137 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
138 GTK_WINDOW(parent->m_widget));
6dfaa4e5
RR
139
140 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
0b862e20 141
6dfaa4e5
RR
142 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
143 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this );
144
fab591c5 145#ifndef __WXGTK20__
6dfaa4e5 146 // strange way to internationalize
fab591c5
RR
147 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->ok_button) ), _("OK") );
148#endif
6dfaa4e5
RR
149
150 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
151 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this );
0b862e20 152
fab591c5 153#ifndef __WXGTK20__
6dfaa4e5 154 // strange way to internationalize
fab591c5
RR
155 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->cancel_button) ), _("Cancel") );
156#endif
0b862e20 157
6dfaa4e5
RR
158 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
159 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
30764ab5
VZ
160
161 wxFont font = m_fontData.GetInitialFont();
162 if( font.Ok() )
163 {
74b0216f 164 const wxNativeFontInfo *info = font.GetNativeFontInfo();
30764ab5 165
7826e2dd
VZ
166 if ( info )
167 {
2f35f36b
VS
168
169#ifdef __WXGTK20__
170 const wxString& fontname = info->ToString();
171#else
409d5a58 172 const wxString& fontname = info->GetXFontName();
7826e2dd
VZ
173 if ( !fontname )
174 font.GetInternalFont();
2f35f36b
VS
175#endif
176 gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname));
7826e2dd
VZ
177 }
178 else
179 {
180 // this is not supposed to happen!
181 wxFAIL_MSG(_T("font is ok but no native font info?"));
182 }
30764ab5 183 }
dbc65e27
VZ
184
185 return TRUE;
6dfaa4e5
RR
186}
187
188wxFontDialog::~wxFontDialog()
189{
190}
191
dbc65e27
VZ
192void wxFontDialog::SetChosenFont(const char *fontname)
193{
2b5f62a0 194 m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) ));
dbc65e27
VZ
195}
196
1e6feb95
VZ
197#endif // wxUSE_FONTDLG
198
b63b07a8
RL
199#endif // GPE
200