1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/fontdlg.cpp
3 // Purpose: wxFontDialog
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
11
12 #if wxUSE_FONTDLG && !defined(__WXGPE__)
13
14 #include "wx/fontdlg.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/intl.h"
18 #endif
19
20 #include "wx/fontutil.h"
21 #include "wx/gtk/private.h"
22
23 //-----------------------------------------------------------------------------
24 // "response"
25 //-----------------------------------------------------------------------------
26
27 extern "C" {
response(GtkDialog * dialog,int response_id,wxFontDialog * win)28 static void response(GtkDialog* dialog, int response_id, wxFontDialog* win)
29 {
30 int rc = wxID_CANCEL;
31 if (response_id == GTK_RESPONSE_OK)
32 {
33 rc = wxID_OK;
34 #if GTK_CHECK_VERSION(3,2,0)
35 if (gtk_check_version(3,2,0) == NULL)
36 {
37 wxNativeFontInfo info;
38 info.description = gtk_font_chooser_get_font_desc(GTK_FONT_CHOOSER(dialog));
39 win->GetFontData().SetChosenFont(wxFont(info));
40 }
41 else
42 #endif
43 {
44 wxGCC_WARNING_SUPPRESS(deprecated-declarations)
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 wxGCC_WARNING_RESTORE()
49 }
50 }
51
52 if (win->IsModal())
53 win->EndModal(rc);
54 else
55 win->Show(false);
56 }
57 }
58
59 //-----------------------------------------------------------------------------
60 // wxFontDialog
61 //-----------------------------------------------------------------------------
62
63 wxIMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog);
64
DoCreate(wxWindow * parent)65 bool wxFontDialog::DoCreate(wxWindow *parent)
66 {
67 parent = GetParentForModalDialog(parent, 0);
68
69 if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
70 !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
71 wxDefaultValidator, wxT("fontdialog") ))
72 {
73 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
74 return false;
75 }
76
77 const wxString message(_("Choose font"));
78 GtkWindow* gtk_parent = NULL;
79 if (parent)
80 gtk_parent = GTK_WINDOW(parent->m_widget);
81
82 #if GTK_CHECK_VERSION(3,2,0)
83 #if GLIB_CHECK_VERSION(2, 34, 0)
84 g_type_ensure(PANGO_TYPE_FONT_FACE);
85 #endif
86 if (gtk_check_version(3,2,0) == NULL)
87 m_widget = gtk_font_chooser_dialog_new(wxGTK_CONV(message), gtk_parent);
88 else
89 #endif
90 {
91 wxGCC_WARNING_SUPPRESS(deprecated-declarations)
92 m_widget = gtk_font_selection_dialog_new(wxGTK_CONV(message));
93 if (gtk_parent)
94 gtk_window_set_transient_for(GTK_WINDOW(m_widget), gtk_parent);
95 wxGCC_WARNING_RESTORE()
96 }
97 g_object_ref(m_widget);
98
99 g_signal_connect(m_widget, "response", G_CALLBACK(response), this);
100
101 wxFont font = m_fontData.GetInitialFont();
102 if( font.IsOk() )
103 {
104 const wxNativeFontInfo *info = font.GetNativeFontInfo();
105
106 if ( info )
107 {
108 #if GTK_CHECK_VERSION(3,2,0)
109 if (gtk_check_version(3,2,0) == NULL)
110 gtk_font_chooser_set_font_desc(GTK_FONT_CHOOSER(m_widget), info->description);
111 else
112 #endif
113 {
114 wxGCC_WARNING_SUPPRESS(deprecated-declarations)
115 const wxString& fontname = info->ToString();
116 GtkFontSelectionDialog* sel = GTK_FONT_SELECTION_DIALOG(m_widget);
117 gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname));
118 wxGCC_WARNING_RESTORE()
119 }
120 }
121 else
122 {
123 // this is not supposed to happen!
124 wxFAIL_MSG(wxT("font is ok but no native font info?"));
125 }
126 }
127
128 return true;
129 }
130
~wxFontDialog()131 wxFontDialog::~wxFontDialog()
132 {
133 }
134
135 #endif // wxUSE_FONTDLG && !__WXGPE__
136