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"
27 #include "wx/gtk/private.h"
30 #include <hildon-widgets/hildon-color-selector.h>
31 #endif // wxUSE_LIBHILDON
35 #include <hildon/hildon.h>
37 #endif // wxUSE_LIBHILDON2
39 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
41 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
46 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
51 m_parent
= GetParentForModalDialog(parent
, 0);
52 GtkWindow
* const parentGTK
= m_parent
? GTK_WINDOW(m_parent
->m_widget
)
56 m_widget
= hildon_color_selector_new(parentGTK
);
57 #elif wxUSE_LIBHILDON2 // !wxUSE_LIBHILDON
58 m_widget
= hildon_color_chooser_dialog_new();
59 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
60 wxString
title(_("Choose colour"));
61 m_widget
= gtk_color_selection_dialog_new(wxGTK_CONV(title
));
62 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
64 g_object_ref(m_widget
);
68 gtk_window_set_transient_for(GTK_WINDOW(m_widget
), parentGTK
);
71 #if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
72 GtkColorSelection
* sel
= GTK_COLOR_SELECTION(
73 gtk_color_selection_dialog_get_color_selection(
74 GTK_COLOR_SELECTION_DIALOG(m_widget
)));
75 gtk_color_selection_set_has_palette(sel
, true);
76 #endif // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
81 int wxColourDialog::ShowModal()
85 gint result
= gtk_dialog_run(GTK_DIALOG(m_widget
));
86 gtk_widget_hide(m_widget
);
91 wxFAIL_MSG(wxT("unexpected GtkColorSelectionDialog return code"));
94 case GTK_RESPONSE_CANCEL
:
95 case GTK_RESPONSE_DELETE_EVENT
:
96 case GTK_RESPONSE_CLOSE
:
100 DialogToColourData();
105 void wxColourDialog::ColourDataToDialog()
107 const GdkColor
* const
108 col
= m_data
.GetColour().IsOk() ? m_data
.GetColour().GetColor()
112 HildonColorSelector
* const sel
= HILDON_COLOR_SELECTOR(m_widget
);
113 hildon_color_selector_set_color(sel
, const_cast<GdkColor
*>(col
));
114 #elif wxUSE_LIBHILDON2
125 hildon_color_chooser_dialog_set_color((HildonColorChooserDialog
*)m_widget
, &clr
);
126 #else // !wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
127 GtkColorSelection
* sel
= GTK_COLOR_SELECTION(
128 gtk_color_selection_dialog_get_color_selection(
129 GTK_COLOR_SELECTION_DIALOG(m_widget
)));
132 gtk_color_selection_set_current_color(sel
, col
);
134 // setup the palette:
138 for (unsigned i
= 0; i
< 16; i
++)
140 wxColour c
= m_data
.GetCustomColour(i
);
143 colors
[n_colors
] = *c
.GetColor();
148 wxGtkString
pal(gtk_color_selection_palette_to_string(colors
, n_colors
));
150 GtkSettings
*settings
= gtk_widget_get_settings(GTK_WIDGET(sel
));
151 g_object_set(settings
, "gtk-color-palette", pal
.c_str(), NULL
);
152 #endif // wxUSE_LIBHILDON / wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
155 void wxColourDialog::DialogToColourData()
158 HildonColorSelector
* const sel
= HILDON_COLOR_SELECTOR(m_widget
);
159 const GdkColor
* const clr
= hildon_color_selector_get_color(sel
);
161 m_data
.SetColour(*clr
);
162 #elif wxUSE_LIBHILDON2 // !wxUSE_LIBHILDON
163 const GdkColor
* const
164 col
= m_data
.GetColour().IsOk() ? m_data
.GetColour().GetColor() : NULL
;
175 GdkColor new_color
= clr
;
176 hildon_color_chooser_dialog_get_color((HildonColorChooserDialog
*)m_widget
, &new_color
);
178 m_data
.SetColour(new_color
);
179 #else // !wxUSE_LIBHILDON2
181 GtkColorSelection
* sel
= GTK_COLOR_SELECTION(
182 gtk_color_selection_dialog_get_color_selection(
183 GTK_COLOR_SELECTION_DIALOG(m_widget
)));
186 gtk_color_selection_get_current_color(sel
, &clr
);
187 m_data
.SetColour(clr
);
189 // Extract custom palette:
191 GtkSettings
*settings
= gtk_widget_get_settings(GTK_WIDGET(sel
));
193 g_object_get(settings
, "gtk-color-palette", &pal
, NULL
);
197 if (gtk_color_selection_palette_from_string(pal
, &colors
, &n_colors
))
199 for (int i
= 0; i
< wxMin(n_colors
, 16); i
++)
201 m_data
.SetCustomColour(i
, wxColour(colors
[i
]));
207 #endif // wxUSE_LIBHILDON / wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
210 #endif // wxUSE_COLOURDLG