]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/fontdlg.cpp
make it possible to use stock ids for custom message box labels
[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"
246c5004 20 #include "wx/msgdlg.h"
88a7a4e1
WS
21#endif
22
e1bf3ad3 23#include "wx/fontutil.h"
6dfaa4e5 24
9e691f46 25#include "wx/gtk/private.h"
6dfaa4e5 26
6dfaa4e5
RR
27//-----------------------------------------------------------------------------
28// "delete_event"
29//-----------------------------------------------------------------------------
30
865bb325 31extern "C" {
6dfaa4e5
RR
32static
33bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
34{
6dfaa4e5
RR
35/*
36 printf( "OnDelete from " );
37 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
38 printf( win->GetClassInfo()->GetClassName() );
39 printf( ".\n" );
40*/
41
42 win->Close();
43
93763ad5 44 return true;
6dfaa4e5 45}
865bb325 46}
6dfaa4e5
RR
47
48//-----------------------------------------------------------------------------
49// "clicked" for OK-button
50//-----------------------------------------------------------------------------
51
865bb325 52extern "C" {
6dfaa4e5
RR
53static
54void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
55{
6dfaa4e5 56 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
6e7d0063 57
e808cf8a 58 wxGtkString fontname(gtk_font_selection_dialog_get_font_name(fontdlg));
2b5f62a0 59 dialog->SetChosenFont( fontname);
7beba2fc 60
6dfaa4e5
RR
61 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
62 event.SetEventObject( dialog );
937013e0 63 dialog->HandleWindowEvent( event );
6dfaa4e5 64}
865bb325 65}
6dfaa4e5
RR
66
67//-----------------------------------------------------------------------------
68// "clicked" for Cancel-button
69//-----------------------------------------------------------------------------
70
865bb325 71extern "C" {
6dfaa4e5
RR
72static
73void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
74{
6dfaa4e5
RR
75 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
76 event.SetEventObject( dialog );
937013e0 77 dialog->HandleWindowEvent( event );
6dfaa4e5 78}
865bb325 79}
6dfaa4e5
RR
80
81//-----------------------------------------------------------------------------
82// wxFontDialog
83//-----------------------------------------------------------------------------
84
dbc65e27 85IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
6dfaa4e5 86
dbc65e27 87bool wxFontDialog::DoCreate(wxWindow *parent)
6dfaa4e5 88{
2229243b
VZ
89 parent = GetParentForModalDialog(parent);
90
6dfaa4e5 91 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
0b862e20 92 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
223d09f6 93 wxDefaultValidator, wxT("fontdialog") ))
6dfaa4e5 94 {
dbc65e27 95 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
93763ad5 96 return false;
6dfaa4e5 97 }
dbc65e27 98
6dfaa4e5 99 wxString m_message( _("Choose font") );
fab591c5 100 m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
9ff9d30c 101 g_object_ref(m_widget);
6dfaa4e5 102
91cf5865
VS
103 if (parent)
104 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
105 GTK_WINDOW(parent->m_widget));
6dfaa4e5
RR
106
107 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
0b862e20 108
9fa72bd2
MR
109 g_signal_connect (sel->ok_button, "clicked",
110 G_CALLBACK (gtk_fontdialog_ok_callback), this);
6dfaa4e5 111
9fa72bd2
MR
112 g_signal_connect (sel->cancel_button, "clicked",
113 G_CALLBACK (gtk_fontdialog_cancel_callback), this);
0b862e20 114
9fa72bd2
MR
115 g_signal_connect (m_widget, "delete_event",
116 G_CALLBACK (gtk_fontdialog_delete_callback), this);
30764ab5
VZ
117
118 wxFont font = m_fontData.GetInitialFont();
119 if( font.Ok() )
120 {
74b0216f 121 const wxNativeFontInfo *info = font.GetNativeFontInfo();
30764ab5 122
7826e2dd
VZ
123 if ( info )
124 {
2f35f36b 125
2f35f36b 126 const wxString& fontname = info->ToString();
2f35f36b 127 gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname));
7826e2dd
VZ
128 }
129 else
130 {
131 // this is not supposed to happen!
132 wxFAIL_MSG(_T("font is ok but no native font info?"));
133 }
30764ab5 134 }
dbc65e27 135
93763ad5 136 return true;
6dfaa4e5
RR
137}
138
139wxFontDialog::~wxFontDialog()
140{
141}
142
dbc65e27
VZ
143void wxFontDialog::SetChosenFont(const char *fontname)
144{
2b5f62a0 145 m_fontData.SetChosenFont(wxFont( wxString::FromAscii(fontname) ));
dbc65e27
VZ
146}
147
88a7a4e1 148#endif // wxUSE_FONTDLG && !__WXGPE__