]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/fontdlg.cpp
Deallocate wxThreadSpecificInfo when wxThread ends.
[wxWidgets.git] / src / gtk1 / fontdlg.cpp
CommitLineData
6dfaa4e5 1/////////////////////////////////////////////////////////////////////////////
93763ad5 2// Name: src/gtk1/fontdlg.cpp
6dfaa4e5
RR
3// Purpose: wxFontDialog
4// Author: Robert Roebling
6dfaa4e5 5// Copyright: (c) 1998 Robert Roebling
65571936 6// Licence: wxWindows licence
6dfaa4e5
RR
7/////////////////////////////////////////////////////////////////////////////
8
14f355c2
VS
9// For compilers that support precompilation, includes "wx.h".
10#include "wx/wxprec.h"
11
88a7a4e1 12#if wxUSE_FONTDLG && !defined(__WXGPE__)
47e118ba 13
6dfaa4e5 14#include "wx/fontdlg.h"
88a7a4e1
WS
15
16#ifndef WX_PRECOMP
17 #include "wx/intl.h"
de6185e2 18 #include "wx/utils.h"
246c5004 19 #include "wx/msgdlg.h"
88a7a4e1
WS
20#endif
21
e1bf3ad3 22#include "wx/fontutil.h"
6dfaa4e5 23
3cbab641 24#include "wx/gtk1/private.h"
6dfaa4e5
RR
25
26//-----------------------------------------------------------------------------
27// idle system
28//-----------------------------------------------------------------------------
29
30extern void wxapp_install_idle_handler();
31extern bool g_isIdle;
32
33//-----------------------------------------------------------------------------
34// "delete_event"
35//-----------------------------------------------------------------------------
36
865bb325 37extern "C" {
6dfaa4e5
RR
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
93763ad5 53 return true;
6dfaa4e5 54}
865bb325 55}
6dfaa4e5
RR
56
57//-----------------------------------------------------------------------------
58// "clicked" for OK-button
59//-----------------------------------------------------------------------------
60
865bb325 61extern "C" {
6dfaa4e5
RR
62static
63void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
64{
0b862e20 65 if (g_isIdle)
6dfaa4e5
RR
66 wxapp_install_idle_handler();
67
68 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
6e7d0063 69
6dfaa4e5 70 GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg);
0b862e20 71
6dfaa4e5
RR
72 if (!gfont)
73 {
7826e2dd
VZ
74 wxMessageBox(_("Please choose a valid font."), _("Error"),
75 wxOK | wxICON_ERROR);
6dfaa4e5
RR
76 return;
77 }
0b862e20 78
6dfaa4e5 79 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
2b5f62a0 80 dialog->SetChosenFont( fontname);
7beba2fc 81
6dfaa4e5 82 g_free( fontname );
0b862e20 83
ce7fe42e 84 wxCommandEvent event(wxEVT_BUTTON, wxID_OK);
6dfaa4e5 85 event.SetEventObject( dialog );
937013e0 86 dialog->HandleWindowEvent( event );
6dfaa4e5 87}
865bb325 88}
6dfaa4e5
RR
89
90//-----------------------------------------------------------------------------
91// "clicked" for Cancel-button
92//-----------------------------------------------------------------------------
93
865bb325 94extern "C" {
6dfaa4e5
RR
95static
96void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
97{
0b862e20 98 if (g_isIdle)
6dfaa4e5
RR
99 wxapp_install_idle_handler();
100
ce7fe42e 101 wxCommandEvent event(wxEVT_BUTTON, wxID_CANCEL);
6dfaa4e5 102 event.SetEventObject( dialog );
937013e0 103 dialog->HandleWindowEvent( event );
6dfaa4e5 104}
865bb325 105}
6dfaa4e5
RR
106
107//-----------------------------------------------------------------------------
108// wxFontDialog
109//-----------------------------------------------------------------------------
110
dbc65e27 111IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
6dfaa4e5 112
dbc65e27 113bool wxFontDialog::DoCreate(wxWindow *parent)
6dfaa4e5 114{
93763ad5 115 m_needParent = false;
6dfaa4e5
RR
116
117 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
0b862e20 118 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
223d09f6 119 wxDefaultValidator, wxT("fontdialog") ))
6dfaa4e5 120 {
dbc65e27 121 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
93763ad5 122 return false;
6dfaa4e5 123 }
dbc65e27 124
6dfaa4e5 125 wxString m_message( _("Choose font") );
fab591c5 126 m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
6dfaa4e5 127
91cf5865
VS
128 if (parent)
129 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
130 GTK_WINDOW(parent->m_widget));
6dfaa4e5
RR
131
132 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
0b862e20 133
6dfaa4e5
RR
134 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
135 GTK_SIGNAL_FUNC(gtk_fontdialog_ok_callback), (gpointer*)this );
136
137 // strange way to internationalize
fab591c5 138 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->ok_button) ), _("OK") );
6dfaa4e5
RR
139
140 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
141 GTK_SIGNAL_FUNC(gtk_fontdialog_cancel_callback), (gpointer*)this );
0b862e20 142
6dfaa4e5 143 // strange way to internationalize
fab591c5 144 gtk_label_set( GTK_LABEL( BUTTON_CHILD(sel->cancel_button) ), _("Cancel") );
0b862e20 145
6dfaa4e5
RR
146 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
147 GTK_SIGNAL_FUNC(gtk_fontdialog_delete_callback), (gpointer)this );
30764ab5
VZ
148
149 wxFont font = m_fontData.GetInitialFont();
a1b806b9 150 if( font.IsOk() )
30764ab5 151 {
74b0216f 152 const wxNativeFontInfo *info = font.GetNativeFontInfo();
30764ab5 153
7826e2dd
VZ
154 if ( info )
155 {
2f35f36b 156
409d5a58 157 const wxString& fontname = info->GetXFontName();
7826e2dd
VZ
158 if ( !fontname )
159 font.GetInternalFont();
3cbab641 160
2f35f36b 161 gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname));
7826e2dd
VZ
162 }
163 else
164 {
165 // this is not supposed to happen!
9a83f860 166 wxFAIL_MSG(wxT("font is ok but no native font info?"));
7826e2dd 167 }
30764ab5 168 }
dbc65e27 169
93763ad5 170 return true;
6dfaa4e5
RR
171}
172
173wxFontDialog::~wxFontDialog()
174{
175}
176
dbc65e27
VZ
177void wxFontDialog::SetChosenFont(const char *fontname)
178{
2b5f62a0 179 m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) ));
dbc65e27
VZ
180}
181
88a7a4e1 182#endif // wxUSE_FONTDLG && !defined(__WXGPE__)