]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/fontdlg.cpp
Fix a number of mingw compile errors.
[wxWidgets.git] / src / gtk / fontdlg.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/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// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#if wxUSE_FONTDLG && !defined(__WXGPE__)
14
15#include "wx/fontdlg.h"
16
17#ifndef WX_PRECOMP
18 #include "wx/intl.h"
19 #include "wx/utils.h"
20 #include "wx/msgdlg.h"
21#endif
22
23#include "wx/fontutil.h"
24
25#include "wx/gtk/private.h"
26
27//-----------------------------------------------------------------------------
28// "delete_event"
29//-----------------------------------------------------------------------------
30
31extern "C" {
32static
33bool gtk_fontdialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
34{
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
44 return true;
45}
46}
47
48//-----------------------------------------------------------------------------
49// "clicked" for OK-button
50//-----------------------------------------------------------------------------
51
52extern "C" {
53static
54void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dialog )
55{
56 GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
57
58 wxGtkString fontname(gtk_font_selection_dialog_get_font_name(fontdlg));
59 dialog->SetChosenFont( fontname);
60
61 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
62 event.SetEventObject( dialog );
63 dialog->HandleWindowEvent( event );
64}
65}
66
67//-----------------------------------------------------------------------------
68// "clicked" for Cancel-button
69//-----------------------------------------------------------------------------
70
71extern "C" {
72static
73void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialog )
74{
75 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
76 event.SetEventObject( dialog );
77 dialog->HandleWindowEvent( event );
78}
79}
80
81//-----------------------------------------------------------------------------
82// wxFontDialog
83//-----------------------------------------------------------------------------
84
85IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
86
87bool wxFontDialog::DoCreate(wxWindow *parent)
88{
89 parent = GetParentForModalDialog(parent, 0);
90
91 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
92 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
93 wxDefaultValidator, wxT("fontdialog") ))
94 {
95 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
96 return false;
97 }
98
99 wxString m_message( _("Choose font") );
100 m_widget = gtk_font_selection_dialog_new( wxGTK_CONV( m_message ) );
101 g_object_ref(m_widget);
102
103 if (parent)
104 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
105 GTK_WINDOW(parent->m_widget));
106
107 GtkFontSelectionDialog *sel = GTK_FONT_SELECTION_DIALOG(m_widget);
108
109 g_signal_connect (gtk_font_selection_dialog_get_ok_button(sel), "clicked",
110 G_CALLBACK (gtk_fontdialog_ok_callback), this);
111
112 g_signal_connect (gtk_font_selection_dialog_get_cancel_button(sel), "clicked",
113 G_CALLBACK (gtk_fontdialog_cancel_callback), this);
114
115 g_signal_connect (m_widget, "delete_event",
116 G_CALLBACK (gtk_fontdialog_delete_callback), this);
117
118 wxFont font = m_fontData.GetInitialFont();
119 if( font.Ok() )
120 {
121 const wxNativeFontInfo *info = font.GetNativeFontInfo();
122
123 if ( info )
124 {
125
126 const wxString& fontname = info->ToString();
127 gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname));
128 }
129 else
130 {
131 // this is not supposed to happen!
132 wxFAIL_MSG(wxT("font is ok but no native font info?"));
133 }
134 }
135
136 return true;
137}
138
139wxFontDialog::~wxFontDialog()
140{
141}
142
143void wxFontDialog::SetChosenFont(const char *fontname)
144{
145 m_fontData.SetChosenFont(wxFont( wxString::FromUTF8(fontname) ));
146}
147
148#endif // wxUSE_FONTDLG && !__WXGPE__