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"
28 #include "wx/gtk/private.h"
29 #include "wx/gtk/private/gtk2-compat.h"
32 #include <hildon-widgets/hildon-color-selector.h>
33 #endif // wxUSE_LIBHILDON
37 #include <hildon/hildon.h>
39 #endif // wxUSE_LIBHILDON2
41 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
43 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
48 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
53 m_parent
= GetParentForModalDialog(parent
, 0);
54 GtkWindow
* const parentGTK
= m_parent
? GTK_WINDOW(m_parent
->m_widget
)
58 m_widget
= hildon_color_selector_new(parentGTK
);
59 #elif wxUSE_LIBHILDON2 // !wxUSE_LIBHILDON
60 m_widget
= hildon_color_chooser_dialog_new();
61 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
62 wxString
title(_("Choose colour"));
63 m_widget
= gtk_color_selection_dialog_new(wxGTK_CONV(title
));
64 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
66 g_object_ref(m_widget
);
70 gtk_window_set_transient_for(GTK_WINDOW(m_widget
), parentGTK
);
73 #if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
74 GtkColorSelection
* sel
= GTK_COLOR_SELECTION(
75 gtk_color_selection_dialog_get_color_selection(
76 GTK_COLOR_SELECTION_DIALOG(m_widget
)));
77 gtk_color_selection_set_has_palette(sel
, true);
78 #endif // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
83 int wxColourDialog::ShowModal()
87 gint result
= gtk_dialog_run(GTK_DIALOG(m_widget
));
88 gtk_widget_hide(m_widget
);
93 wxFAIL_MSG(wxT("unexpected GtkColorSelectionDialog return code"));
96 case GTK_RESPONSE_CANCEL
:
97 case GTK_RESPONSE_DELETE_EVENT
:
98 case GTK_RESPONSE_CLOSE
:
101 case GTK_RESPONSE_OK
:
102 DialogToColourData();
107 void wxColourDialog::ColourDataToDialog()
109 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
110 const GdkColor
* const
111 col
= m_data
.GetColour().IsOk() ? m_data
.GetColour().GetColor()
115 HildonColorSelector
* const sel
= HILDON_COLOR_SELECTOR(m_widget
);
116 hildon_color_selector_set_color(sel
, const_cast<GdkColor
*>(col
));
117 #elif wxUSE_LIBHILDON2
128 hildon_color_chooser_dialog_set_color((HildonColorChooserDialog
*)m_widget
, &clr
);
129 #else // !wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
130 GtkColorSelection
* sel
= GTK_COLOR_SELECTION(
131 gtk_color_selection_dialog_get_color_selection(
132 GTK_COLOR_SELECTION_DIALOG(m_widget
)));
134 const wxColour
& color
= m_data
.GetColour();
138 gtk_color_selection_set_current_rgba(sel
, color
);
140 gtk_color_selection_set_current_color(sel
, color
.GetColor());
144 // setup the palette:
146 GdkColor colors
[wxColourData::NUM_CUSTOM
];
148 for (unsigned i
= 0; i
< WXSIZEOF(colors
); i
++)
150 wxColour c
= m_data
.GetCustomColour(i
);
153 colors
[n_colors
] = *c
.GetColor();
158 wxGtkString
pal(gtk_color_selection_palette_to_string(colors
, n_colors
));
160 GtkSettings
*settings
= gtk_widget_get_settings(GTK_WIDGET(sel
));
161 g_object_set(settings
, "gtk-color-palette", pal
.c_str(), NULL
);
162 #endif // wxUSE_LIBHILDON / wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
165 void wxColourDialog::DialogToColourData()
168 HildonColorSelector
* const sel
= HILDON_COLOR_SELECTOR(m_widget
);
169 const GdkColor
* const clr
= hildon_color_selector_get_color(sel
);
171 m_data
.SetColour(*clr
);
172 #elif wxUSE_LIBHILDON2 // !wxUSE_LIBHILDON
173 const GdkColor
* const
174 col
= m_data
.GetColour().IsOk() ? m_data
.GetColour().GetColor() : NULL
;
185 GdkColor new_color
= clr
;
186 hildon_color_chooser_dialog_get_color((HildonColorChooserDialog
*)m_widget
, &new_color
);
188 m_data
.SetColour(new_color
);
189 #else // !wxUSE_LIBHILDON2
191 GtkColorSelection
* sel
= GTK_COLOR_SELECTION(
192 gtk_color_selection_dialog_get_color_selection(
193 GTK_COLOR_SELECTION_DIALOG(m_widget
)));
197 gtk_color_selection_get_current_rgba(sel
, &clr
);
200 gtk_color_selection_get_current_color(sel
, &clr
);
202 m_data
.SetColour(clr
);
204 // Extract custom palette:
206 GtkSettings
*settings
= gtk_widget_get_settings(GTK_WIDGET(sel
));
208 g_object_get(settings
, "gtk-color-palette", &pal
, NULL
);
212 if (gtk_color_selection_palette_from_string(pal
, &colors
, &n_colors
))
214 for (int i
= 0; i
< n_colors
&& i
< wxColourData::NUM_CUSTOM
; i
++)
216 m_data
.SetCustomColour(i
, wxColour(colors
[i
]));
222 #endif // wxUSE_LIBHILDON / wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
225 #endif // wxUSE_COLOURDLG