]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/fontdlg.cpp
gtk spinctrl code simplification
[wxWidgets.git] / src / gtk / fontdlg.cpp
CommitLineData
6dfaa4e5 1/////////////////////////////////////////////////////////////////////////////
93763ad5 2// Name: src/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
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
88a7a4e1 13#if wxUSE_FONTDLG && !defined(__WXGPE__)
47e118ba 14
6dfaa4e5 15#include "wx/fontdlg.h"
88a7a4e1
WS
16
17#ifndef WX_PRECOMP
18 #include "wx/intl.h"
de6185e2 19 #include "wx/utils.h"
88a7a4e1
WS
20#endif
21
e1bf3ad3 22#include "wx/fontutil.h"
6dfaa4e5
RR
23#include "wx/debug.h"
24#include "wx/msgdlg.h"
25
9e691f46 26#include "wx/gtk/private.h"
6dfaa4e5 27
6dfaa4e5
RR
28//-----------------------------------------------------------------------------
29// "delete_event"
30//-----------------------------------------------------------------------------
31
865bb325 32extern "C" {
6dfaa4e5
RR
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
93763ad5 48 return true;
6dfaa4e5 49}
865bb325 50}
6dfaa4e5
RR
51
52//-----------------------------------------------------------------------------
53// "clicked" for OK-button
54//-----------------------------------------------------------------------------
55
865bb325 56extern "C" {
6dfaa4e5
RR
57static
58void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
59{
0b862e20 60 if (g_isIdle)
6dfaa4e5
RR
61 wxapp_install_idle_handler();
62
63 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
6e7d0063 64
6dfaa4e5 65 gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
2b5f62a0 66 dialog->SetChosenFont( fontname);
7beba2fc 67
6dfaa4e5 68 g_free( fontname );
0b862e20 69
6dfaa4e5
RR
70 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
71 event.SetEventObject( dialog );
72 dialog->GetEventHandler()->ProcessEvent( event );
73}
865bb325 74}
6dfaa4e5
RR
75
76//-----------------------------------------------------------------------------
77// "clicked" for Cancel-button
78//-----------------------------------------------------------------------------
79
865bb325 80extern "C" {
6dfaa4e5
RR
81static
82void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
83{
0b862e20 84 if (g_isIdle)
6dfaa4e5
RR
85 wxapp_install_idle_handler();
86
87 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
88 event.SetEventObject( dialog );
89 dialog->GetEventHandler()->ProcessEvent( event );
90}
865bb325 91}
6dfaa4e5
RR
92
93//-----------------------------------------------------------------------------
94// wxFontDialog
95//-----------------------------------------------------------------------------
96
dbc65e27 97IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
6dfaa4e5 98
dbc65e27 99bool wxFontDialog::DoCreate(wxWindow *parent)
6dfaa4e5 100{
93763ad5 101 m_needParent = false;
6dfaa4e5
RR
102
103 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
0b862e20 104 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
223d09f6 105 wxDefaultValidator, wxT("fontdialog") ))
6dfaa4e5 106 {
dbc65e27 107 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
93763ad5 108 return false;
6dfaa4e5 109 }
dbc65e27 110
6dfaa4e5 111 wxString m_message( _("Choose font") );
fab591c5 112 m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
6dfaa4e5 113
91cf5865
VS
114 if (parent)
115 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
116 GTK_WINDOW(parent->m_widget));
6dfaa4e5
RR
117
118 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
0b862e20 119
9fa72bd2
MR
120 g_signal_connect (sel->ok_button, "clicked",
121 G_CALLBACK (gtk_fontdialog_ok_callback), this);
6dfaa4e5 122
9fa72bd2
MR
123 g_signal_connect (sel->cancel_button, "clicked",
124 G_CALLBACK (gtk_fontdialog_cancel_callback), this);
0b862e20 125
9fa72bd2
MR
126 g_signal_connect (m_widget, "delete_event",
127 G_CALLBACK (gtk_fontdialog_delete_callback), this);
30764ab5
VZ
128
129 wxFont font = m_fontData.GetInitialFont();
130 if( font.Ok() )
131 {
74b0216f 132 const wxNativeFontInfo *info = font.GetNativeFontInfo();
30764ab5 133
7826e2dd
VZ
134 if ( info )
135 {
2f35f36b 136
2f35f36b 137 const wxString& fontname = info->ToString();
2f35f36b 138 gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname));
7826e2dd
VZ
139 }
140 else
141 {
142 // this is not supposed to happen!
143 wxFAIL_MSG(_T("font is ok but no native font info?"));
144 }
30764ab5 145 }
dbc65e27 146
93763ad5 147 return true;
6dfaa4e5
RR
148}
149
150wxFontDialog::~wxFontDialog()
151{
152}
153
dbc65e27
VZ
154void wxFontDialog::SetChosenFont(const char *fontname)
155{
2b5f62a0 156 m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) ));
dbc65e27
VZ
157}
158
88a7a4e1 159#endif // wxUSE_FONTDLG && !__WXGPE__