1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/colordlg.h"
22 #include "wx/testing.h"
29 #include "wx/gtk/private.h"
30 #include "wx/gtk/private/gtk2-compat.h"
33 #include <hildon-widgets/hildon-color-selector.h>
34 #endif // wxUSE_LIBHILDON
38 #include <hildon/hildon.h>
40 #endif // wxUSE_LIBHILDON2
42 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
44 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
49 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
54 m_parent
= GetParentForModalDialog(parent
, 0);
55 GtkWindow
* const parentGTK
= m_parent
? GTK_WINDOW(m_parent
->m_widget
)
59 m_widget
= hildon_color_selector_new(parentGTK
);
60 #elif wxUSE_LIBHILDON2 // !wxUSE_LIBHILDON
61 m_widget
= hildon_color_chooser_dialog_new();
62 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
63 wxString
title(_("Choose colour"));
64 m_widget
= gtk_color_selection_dialog_new(wxGTK_CONV(title
));
65 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
67 g_object_ref(m_widget
);
71 gtk_window_set_transient_for(GTK_WINDOW(m_widget
), parentGTK
);
74 #if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
75 GtkColorSelection
* sel
= GTK_COLOR_SELECTION(
76 gtk_color_selection_dialog_get_color_selection(
77 GTK_COLOR_SELECTION_DIALOG(m_widget
)));
78 gtk_color_selection_set_has_palette(sel
, true);
79 #endif // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
84 int wxColourDialog::ShowModal()
86 WX_TESTING_SHOW_MODAL_HOOK();
90 gint result
= gtk_dialog_run(GTK_DIALOG(m_widget
));
91 gtk_widget_hide(m_widget
);
96 wxFAIL_MSG(wxT("unexpected GtkColorSelectionDialog return code"));
99 case GTK_RESPONSE_CANCEL
:
100 case GTK_RESPONSE_DELETE_EVENT
:
101 case GTK_RESPONSE_CLOSE
:
104 case GTK_RESPONSE_OK
:
105 DialogToColourData();
110 void wxColourDialog::ColourDataToDialog()
112 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
113 const GdkColor
* const
114 col
= m_data
.GetColour().IsOk() ? m_data
.GetColour().GetColor()
118 HildonColorSelector
* const sel
= HILDON_COLOR_SELECTOR(m_widget
);
119 hildon_color_selector_set_color(sel
, const_cast<GdkColor
*>(col
));
120 #elif wxUSE_LIBHILDON2
131 hildon_color_chooser_dialog_set_color((HildonColorChooserDialog
*)m_widget
, &clr
);
132 #else // !wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
133 GtkColorSelection
* sel
= GTK_COLOR_SELECTION(
134 gtk_color_selection_dialog_get_color_selection(
135 GTK_COLOR_SELECTION_DIALOG(m_widget
)));
137 const wxColour
& color
= m_data
.GetColour();
141 gtk_color_selection_set_current_rgba(sel
, color
);
143 gtk_color_selection_set_current_color(sel
, color
.GetColor());
147 // setup the palette:
149 GdkColor colors
[wxColourData::NUM_CUSTOM
];
151 for (unsigned i
= 0; i
< WXSIZEOF(colors
); i
++)
153 wxColour c
= m_data
.GetCustomColour(i
);
156 colors
[n_colors
] = *c
.GetColor();
161 wxGtkString
pal(gtk_color_selection_palette_to_string(colors
, n_colors
));
163 GtkSettings
*settings
= gtk_widget_get_settings(GTK_WIDGET(sel
));
164 g_object_set(settings
, "gtk-color-palette", pal
.c_str(), NULL
);
165 #endif // wxUSE_LIBHILDON / wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
168 void wxColourDialog::DialogToColourData()
171 HildonColorSelector
* const sel
= HILDON_COLOR_SELECTOR(m_widget
);
172 const GdkColor
* const clr
= hildon_color_selector_get_color(sel
);
174 m_data
.SetColour(*clr
);
175 #elif wxUSE_LIBHILDON2 // !wxUSE_LIBHILDON
176 const GdkColor
* const
177 col
= m_data
.GetColour().IsOk() ? m_data
.GetColour().GetColor() : NULL
;
188 GdkColor new_color
= clr
;
189 hildon_color_chooser_dialog_get_color((HildonColorChooserDialog
*)m_widget
, &new_color
);
191 m_data
.SetColour(new_color
);
192 #else // !wxUSE_LIBHILDON2
194 GtkColorSelection
* sel
= GTK_COLOR_SELECTION(
195 gtk_color_selection_dialog_get_color_selection(
196 GTK_COLOR_SELECTION_DIALOG(m_widget
)));
200 gtk_color_selection_get_current_rgba(sel
, &clr
);
203 gtk_color_selection_get_current_color(sel
, &clr
);
205 m_data
.SetColour(clr
);
207 // Extract custom palette:
209 GtkSettings
*settings
= gtk_widget_get_settings(GTK_WIDGET(sel
));
211 g_object_get(settings
, "gtk-color-palette", &pal
, NULL
);
215 if (gtk_color_selection_palette_from_string(pal
, &colors
, &n_colors
))
217 for (int i
= 0; i
< n_colors
&& i
< wxColourData::NUM_CUSTOM
; i
++)
219 m_data
.SetCustomColour(i
, wxColour(colors
[i
]));
225 #endif // wxUSE_LIBHILDON / wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
228 #endif // wxUSE_COLOURDLG