1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/colordlg.cpp
3 // Purpose: Native wxColourDialog for GTK+
4 // Author: Vaclav Slavik
8 // Copyright: (c) Vaclav Slavik, 2004
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "colordlg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_COLOURDLG && defined(__WXGTK20__)
25 #include "wx/colordlg.h"
31 #include "wx/gtk/private.h"
33 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
35 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
40 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
45 wxString
title(_("Choose colour"));
46 m_widget
= gtk_color_selection_dialog_new(wxGTK_CONV(title
));
49 gtk_window_set_transient_for(GTK_WINDOW(m_widget
),
50 GTK_WINDOW(parent
->m_widget
));
52 GtkColorSelection
*sel
=
53 GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget
)->colorsel
);
54 gtk_color_selection_set_has_palette(sel
, true);
59 int wxColourDialog::ShowModal()
63 gint result
= gtk_dialog_run(GTK_DIALOG(m_widget
));
68 wxFAIL_MSG(_T("unexpected GtkColorSelectionDialog return code"));
71 case GTK_RESPONSE_CANCEL
:
72 case GTK_RESPONSE_DELETE_EVENT
:
73 case GTK_RESPONSE_CLOSE
:
82 void wxColourDialog::ColourDataToDialog()
84 GtkColorSelection
*sel
=
85 GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget
)->colorsel
);
87 if (m_data
.GetColour().Ok())
89 gtk_color_selection_set_current_color(sel
,
90 m_data
.GetColour().GetColor());
97 for (unsigned i
= 0; i
< 16; i
++)
99 wxColour c
= m_data
.GetCustomColour(i
);
102 colors
[n_colors
] = *c
.GetColor();
107 gchar
*pal
= gtk_color_selection_palette_to_string(colors
, n_colors
);
109 GtkSettings
*settings
= gtk_widget_get_settings(GTK_WIDGET(sel
));
110 g_object_set(settings
, "gtk-color-palette", pal
, NULL
);
115 void wxColourDialog::DialogToColourData()
117 GtkColorSelection
*sel
=
118 GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget
)->colorsel
);
121 gtk_color_selection_get_current_color(sel
, &clr
);
122 m_data
.SetColour(wxColour(clr
.red
>> 8, clr
.green
>> 8, clr
.blue
>> 8));
124 // Extract custom palette:
126 GtkSettings
*settings
= gtk_widget_get_settings(GTK_WIDGET(sel
));
128 g_object_get(settings
, "gtk-color-palette", &pal
, NULL
);
132 if (gtk_color_selection_palette_from_string(pal
, &colors
, &n_colors
))
134 for (int i
= 0; i
< wxMin(n_colors
, 16); i
++)
136 m_data
.SetCustomColour(i
, wxColour(colors
[i
].red
>> 8,
137 colors
[i
].green
>> 8,
138 colors
[i
].blue
>> 8));
146 #endif // wxUSE_COLOURDLG && defined(__WXGTK20__)