]>
Commit | Line | Data |
---|---|---|
6dfaa4e5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
93763ad5 | 2 | // Name: src/gtk/fontdlg.cpp |
6dfaa4e5 RR |
3 | // Purpose: wxFontDialog |
4 | // Author: Robert Roebling | |
6dfaa4e5 | 5 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 6 | // Licence: wxWindows licence |
6dfaa4e5 RR |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
14f355c2 VS |
9 | // For compilers that support precompilation, includes "wx.h". |
10 | #include "wx/wxprec.h" | |
11 | ||
88a7a4e1 | 12 | #if wxUSE_FONTDLG && !defined(__WXGPE__) |
47e118ba | 13 | |
6dfaa4e5 | 14 | #include "wx/fontdlg.h" |
88a7a4e1 WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/intl.h" | |
18 | #endif | |
19 | ||
e1bf3ad3 | 20 | #include "wx/fontutil.h" |
9e691f46 | 21 | #include "wx/gtk/private.h" |
6dfaa4e5 | 22 | |
6dfaa4e5 | 23 | //----------------------------------------------------------------------------- |
dddda0eb | 24 | // "response" |
6dfaa4e5 RR |
25 | //----------------------------------------------------------------------------- |
26 | ||
865bb325 | 27 | extern "C" { |
dddda0eb | 28 | static void response(GtkDialog* dialog, int response_id, wxFontDialog* win) |
6dfaa4e5 | 29 | { |
dddda0eb PC |
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 | GtkFontSelectionDialog* sel = GTK_FONT_SELECTION_DIALOG(dialog); | |
45 | wxGtkString name(gtk_font_selection_dialog_get_font_name(sel)); | |
46 | win->GetFontData().SetChosenFont(wxFont(wxString::FromUTF8(name))); | |
47 | } | |
48 | } | |
6dfaa4e5 | 49 | |
dddda0eb PC |
50 | if (win->IsModal()) |
51 | win->EndModal(rc); | |
52 | else | |
53 | win->Show(false); | |
6dfaa4e5 | 54 | } |
865bb325 | 55 | } |
6dfaa4e5 RR |
56 | |
57 | //----------------------------------------------------------------------------- | |
58 | // wxFontDialog | |
59 | //----------------------------------------------------------------------------- | |
60 | ||
dbc65e27 | 61 | IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) |
6dfaa4e5 | 62 | |
dbc65e27 | 63 | bool wxFontDialog::DoCreate(wxWindow *parent) |
6dfaa4e5 | 64 | { |
cdc48273 | 65 | parent = GetParentForModalDialog(parent, 0); |
2229243b | 66 | |
6dfaa4e5 | 67 | if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) || |
0b862e20 | 68 | !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, |
223d09f6 | 69 | wxDefaultValidator, wxT("fontdialog") )) |
6dfaa4e5 | 70 | { |
dbc65e27 | 71 | wxFAIL_MSG( wxT("wxFontDialog creation failed") ); |
93763ad5 | 72 | return false; |
6dfaa4e5 | 73 | } |
dbc65e27 | 74 | |
dddda0eb PC |
75 | const wxString message(_("Choose font")); |
76 | GtkWindow* gtk_parent = NULL; | |
91cf5865 | 77 | if (parent) |
dddda0eb | 78 | gtk_parent = GTK_WINDOW(parent->m_widget); |
0b862e20 | 79 | |
dddda0eb PC |
80 | #if GTK_CHECK_VERSION(3,2,0) |
81 | if (gtk_check_version(3,2,0) == NULL) | |
82 | m_widget = gtk_font_chooser_dialog_new(wxGTK_CONV(message), gtk_parent); | |
83 | else | |
84 | #endif | |
85 | { | |
86 | m_widget = gtk_font_selection_dialog_new(wxGTK_CONV(message)); | |
87 | if (gtk_parent) | |
88 | gtk_window_set_transient_for(GTK_WINDOW(m_widget), gtk_parent); | |
89 | } | |
90 | g_object_ref(m_widget); | |
0b862e20 | 91 | |
dddda0eb | 92 | g_signal_connect(m_widget, "response", G_CALLBACK(response), this); |
30764ab5 VZ |
93 | |
94 | wxFont font = m_fontData.GetInitialFont(); | |
a1b806b9 | 95 | if( font.IsOk() ) |
30764ab5 | 96 | { |
74b0216f | 97 | const wxNativeFontInfo *info = font.GetNativeFontInfo(); |
30764ab5 | 98 | |
7826e2dd VZ |
99 | if ( info ) |
100 | { | |
dddda0eb PC |
101 | #if GTK_CHECK_VERSION(3,2,0) |
102 | if (gtk_check_version(3,2,0) == NULL) | |
103 | gtk_font_chooser_set_font_desc(GTK_FONT_CHOOSER(m_widget), info->description); | |
104 | else | |
105 | #endif | |
106 | { | |
107 | const wxString& fontname = info->ToString(); | |
108 | GtkFontSelectionDialog* sel = GTK_FONT_SELECTION_DIALOG(m_widget); | |
109 | gtk_font_selection_dialog_set_font_name(sel, wxGTK_CONV(fontname)); | |
110 | } | |
7826e2dd VZ |
111 | } |
112 | else | |
113 | { | |
114 | // this is not supposed to happen! | |
9a83f860 | 115 | wxFAIL_MSG(wxT("font is ok but no native font info?")); |
7826e2dd | 116 | } |
30764ab5 | 117 | } |
dbc65e27 | 118 | |
93763ad5 | 119 | return true; |
6dfaa4e5 RR |
120 | } |
121 | ||
122 | wxFontDialog::~wxFontDialog() | |
123 | { | |
124 | } | |
125 | ||
88a7a4e1 | 126 | #endif // wxUSE_FONTDLG && !__WXGPE__ |