]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/fontdlg.cpp
Fix crash in wxGTK wxPopupWindow when creating it without parent.
[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"
19#endif
20
e1bf3ad3 21#include "wx/fontutil.h"
9e691f46 22#include "wx/gtk/private.h"
6dfaa4e5 23
6dfaa4e5 24//-----------------------------------------------------------------------------
dddda0eb 25// "response"
6dfaa4e5
RR
26//-----------------------------------------------------------------------------
27
865bb325 28extern "C" {
dddda0eb 29static void response(GtkDialog* dialog, int response_id, wxFontDialog* win)
6dfaa4e5 30{
dddda0eb
PC
31 int rc = wxID_CANCEL;
32 if (response_id == GTK_RESPONSE_OK)
33 {
34 rc = wxID_OK;
35#if GTK_CHECK_VERSION(3,2,0)
36 if (gtk_check_version(3,2,0) == NULL)
37 {
38 wxNativeFontInfo info;
39 info.description = gtk_font_chooser_get_font_desc(GTK_FONT_CHOOSER(dialog));
40 win->GetFontData().SetChosenFont(wxFont(info));
41 }
42 else
43#endif
44 {
45 GtkFontSelectionDialog* sel = GTK_FONT_SELECTION_DIALOG(dialog);
46 wxGtkString name(gtk_font_selection_dialog_get_font_name(sel));
47 win->GetFontData().SetChosenFont(wxFont(wxString::FromUTF8(name)));
48 }
49 }
6dfaa4e5 50
dddda0eb
PC
51 if (win->IsModal())
52 win->EndModal(rc);
53 else
54 win->Show(false);
6dfaa4e5 55}
865bb325 56}
6dfaa4e5
RR
57
58//-----------------------------------------------------------------------------
59// wxFontDialog
60//-----------------------------------------------------------------------------
61
dbc65e27 62IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
6dfaa4e5 63
dbc65e27 64bool wxFontDialog::DoCreate(wxWindow *parent)
6dfaa4e5 65{
cdc48273 66 parent = GetParentForModalDialog(parent, 0);
2229243b 67
6dfaa4e5 68 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
0b862e20 69 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
223d09f6 70 wxDefaultValidator, wxT("fontdialog") ))
6dfaa4e5 71 {
dbc65e27 72 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
93763ad5 73 return false;
6dfaa4e5 74 }
dbc65e27 75
dddda0eb
PC
76 const wxString message(_("Choose font"));
77 GtkWindow* gtk_parent = NULL;
91cf5865 78 if (parent)
dddda0eb 79 gtk_parent = GTK_WINDOW(parent->m_widget);
0b862e20 80
dddda0eb
PC
81#if GTK_CHECK_VERSION(3,2,0)
82 if (gtk_check_version(3,2,0) == NULL)
83 m_widget = gtk_font_chooser_dialog_new(wxGTK_CONV(message), gtk_parent);
84 else
85#endif
86 {
87 m_widget = gtk_font_selection_dialog_new(wxGTK_CONV(message));
88 if (gtk_parent)
89 gtk_window_set_transient_for(GTK_WINDOW(m_widget), gtk_parent);
90 }
91 g_object_ref(m_widget);
0b862e20 92
dddda0eb 93 g_signal_connect(m_widget, "response", G_CALLBACK(response), this);
30764ab5
VZ
94
95 wxFont font = m_fontData.GetInitialFont();
a1b806b9 96 if( font.IsOk() )
30764ab5 97 {
74b0216f 98 const wxNativeFontInfo *info = font.GetNativeFontInfo();
30764ab5 99
7826e2dd
VZ
100 if ( info )
101 {
dddda0eb
PC
102#if GTK_CHECK_VERSION(3,2,0)
103 if (gtk_check_version(3,2,0) == NULL)
104 gtk_font_chooser_set_font_desc(GTK_FONT_CHOOSER(m_widget), info->description);
105 else
106#endif
107 {
108 const wxString& fontname = info->ToString();
109 GtkFontSelectionDialog* sel = GTK_FONT_SELECTION_DIALOG(m_widget);
110 gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname));
111 }
7826e2dd
VZ
112 }
113 else
114 {
115 // this is not supposed to happen!
9a83f860 116 wxFAIL_MSG(wxT("font is ok but no native font info?"));
7826e2dd 117 }
30764ab5 118 }
dbc65e27 119
93763ad5 120 return true;
6dfaa4e5
RR
121}
122
123wxFontDialog::~wxFontDialog()
124{
125}
126
88a7a4e1 127#endif // wxUSE_FONTDLG && !__WXGPE__