]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/fontdlg.cpp
sdasd
[wxWidgets.git] / src / gtk / fontdlg.cpp
CommitLineData
6dfaa4e5
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: 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#ifdef __GNUG__
11#pragma implementation "fontdlg.h"
12#endif
13
14#include "wx/fontdlg.h"
15#include "wx/utils.h"
16#include "wx/intl.h"
17#include "wx/debug.h"
18#include "wx/msgdlg.h"
19
20#include "gtk/gtk.h"
21
22//-----------------------------------------------------------------------------
23// idle system
24//-----------------------------------------------------------------------------
25
26extern void wxapp_install_idle_handler();
27extern bool g_isIdle;
28
29//-----------------------------------------------------------------------------
30// "delete_event"
31//-----------------------------------------------------------------------------
32
33static
34bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
35{
0b862e20 36 if (g_isIdle)
6dfaa4e5
RR
37 wxapp_install_idle_handler();
38
39/*
40 printf( "OnDelete from " );
41 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
42 printf( win->GetClassInfo()->GetClassName() );
43 printf( ".\n" );
44*/
45
46 win->Close();
47
48 return TRUE;
49}
50
51//-----------------------------------------------------------------------------
52// "clicked" for OK-button
53//-----------------------------------------------------------------------------
54
0b862e20 55#ifdef __WXGTK12__
6dfaa4e5
RR
56static
57void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
58{
0b862e20 59 if (g_isIdle)
6dfaa4e5
RR
60 wxapp_install_idle_handler();
61
62 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
63 GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg);
0b862e20 64
6dfaa4e5
RR
65 if (!gfont)
66 {
67 wxMessageBox(_("Please choose a valid font."), _("Error"), wxOK);
68 return;
69 }
0b862e20 70
6dfaa4e5 71 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
7beba2fc
VZ
72
73 // extract the relevant bits from it
74 wxString xregistry, xencoding;
75 char *dash = strrchr(fontname, '-'); // find the last dash
76 if ( dash )
77 {
78 xencoding = dash + 1;
79 *dash = '\0';
80 dash = strrchr(fontname, '-'); // the last before one
81 if ( dash )
82 {
83 xregistry = dash + 1;
84 }
85 else
86 {
87 wxFAIL_MSG(_T("no registry in X font spec?"));
88 }
89
90 // restore the dash we changed to NUL above
91 *(fontname + strlen(fontname)) = '-';
92 }
93 else
94 {
95 wxFAIL_MSG(_T("no encoding in X font spec?"));
96 }
97
98 // transfer the X registry/encoding to wxFontData - they are used by
99 // wxFontMapper after wxFontDialog returns
100 wxFontData& fontdata = dialog->m_fontData;
101
102 // we ignore the facename here - should be enough to choose an arbitrary
103 // one if the registry/encoding are specified
104 // dialog->m_fontData.EncodingInfo().facename = xfamily;
105 fontdata.EncodingInfo().xregistry = xregistry;
106 fontdata.EncodingInfo().xencoding = xencoding;
107
108 // pass fontdata to wxFont ctor so that it can get the encoding from there
109 // if it is already known (otherwise it will try to deduce it itself)
110 dialog->m_fontData.SetChosenFont( wxFont(fontname, fontdata) );
111
6dfaa4e5 112 g_free( fontname );
0b862e20 113
6dfaa4e5
RR
114 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
115 event.SetEventObject( dialog );
116 dialog->GetEventHandler()->ProcessEvent( event );
117}
7beba2fc 118#endif // GTK+ 1.2 and later only
6dfaa4e5
RR
119
120//-----------------------------------------------------------------------------
121// "clicked" for Cancel-button
122//-----------------------------------------------------------------------------
123
124static
125void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
126{
0b862e20 127 if (g_isIdle)
6dfaa4e5
RR
128 wxapp_install_idle_handler();
129
130 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
131 event.SetEventObject( dialog );
132 dialog->GetEventHandler()->ProcessEvent( event );
133}
134
135//-----------------------------------------------------------------------------
136// wxFontDialog
137//-----------------------------------------------------------------------------
138
139IMPLEMENT_DYNAMIC_CLASS(wxFontDialog,wxDialog)
140
7beba2fc
VZ
141wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
142 : m_fontData(*fontdata)
6dfaa4e5
RR
143{
144 m_needParent = FALSE;
145
146 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
0b862e20 147 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
223d09f6 148 wxDefaultValidator, wxT("fontdialog") ))
6dfaa4e5 149 {
223d09f6 150 wxFAIL_MSG( wxT("wxXX creation failed") );
0b862e20 151 return;
6dfaa4e5 152 }
0b862e20 153#ifndef __WXGTK12__
223d09f6 154 wxFAIL_MSG( wxT("TODO") );
0b862e20 155#else // GTK+ 1.2
6dfaa4e5
RR
156 wxString m_message( _("Choose font") );
157 m_widget = gtk_font_selection_dialog_new( m_message.mbc_str() );
158
159 int x = (gdk_screen_width () - 400) / 2;
160 int y = (gdk_screen_height () - 400) / 2;
161 gtk_widget_set_uposition( m_widget, x, y );
162
163 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
0b862e20 164
6dfaa4e5
RR
165 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
166 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this );
167
168 // strange way to internationalize
169 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->ok_button)->child ), wxConvCurrent->cWX2MB(_("OK")) );
170
171 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
172 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this );
0b862e20 173
6dfaa4e5
RR
174 // strange way to internationalize
175 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->cancel_button)->child ), wxConvCurrent->cWX2MB(_("Cancel")) );
0b862e20 176
6dfaa4e5
RR
177 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
178 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
0b862e20 179#endif // GTK+ version
6dfaa4e5
RR
180}
181
182wxFontDialog::~wxFontDialog()
183{
184}
185