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 // 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
33 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
35 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
40 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
45 m_parent
= GetParentForModalDialog(parent
);
46 GtkWindow
* const parentGTK
= m_parent
? GTK_WINDOW(m_parent
->m_widget
)
50 m_widget
= hildon_color_selector_new(parentGTK
);
51 #else // !wxUSE_LIBHILDON
52 wxString
title(_("Choose colour"));
53 m_widget
= gtk_color_selection_dialog_new(wxGTK_CONV(title
));
54 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
56 g_object_ref(m_widget
);
60 gtk_window_set_transient_for(GTK_WINDOW(m_widget
), parentGTK
);
63 GtkColorSelection
*sel
=
64 GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget
)->colorsel
);
65 gtk_color_selection_set_has_palette(sel
, true);
70 int wxColourDialog::ShowModal()
74 gint result
= gtk_dialog_run(GTK_DIALOG(m_widget
));
75 gtk_widget_hide(m_widget
);
80 wxFAIL_MSG(wxT("unexpected GtkColorSelectionDialog return code"));
83 case GTK_RESPONSE_CANCEL
:
84 case GTK_RESPONSE_DELETE_EVENT
:
85 case GTK_RESPONSE_CLOSE
:
94 void wxColourDialog::ColourDataToDialog()
96 const GdkColor
* const
97 col
= m_data
.GetColour().Ok() ? m_data
.GetColour().GetColor()
101 HildonColorSelector
* const sel
= HILDON_COLOR_SELECTOR(m_widget
);
102 hildon_color_selector_set_color(sel
, const_cast<GdkColor
*>(col
));
103 #else // !wxUSE_LIBHILDON
104 GtkColorSelection
*sel
=
105 GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget
)->colorsel
);
108 gtk_color_selection_set_current_color(sel
, col
);
110 // setup the palette:
114 for (unsigned i
= 0; i
< 16; i
++)
116 wxColour c
= m_data
.GetCustomColour(i
);
119 colors
[n_colors
] = *c
.GetColor();
124 wxGtkString
pal(gtk_color_selection_palette_to_string(colors
, n_colors
));
126 GtkSettings
*settings
= gtk_widget_get_settings(GTK_WIDGET(sel
));
127 g_object_set(settings
, "gtk-color-palette", pal
.c_str(), NULL
);
128 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
131 void wxColourDialog::DialogToColourData()
134 HildonColorSelector
* const sel
= HILDON_COLOR_SELECTOR(m_widget
);
135 const GdkColor
* const clr
= hildon_color_selector_get_color(sel
);
137 m_data
.SetColour(*clr
);
138 #else // !wxUSE_LIBHILDON
139 GtkColorSelection
*sel
=
140 GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget
)->colorsel
);
143 gtk_color_selection_get_current_color(sel
, &clr
);
144 m_data
.SetColour(clr
);
146 // Extract custom palette:
148 GtkSettings
*settings
= gtk_widget_get_settings(GTK_WIDGET(sel
));
150 g_object_get(settings
, "gtk-color-palette", &pal
, NULL
);
154 if (gtk_color_selection_palette_from_string(pal
, &colors
, &n_colors
))
156 for (int i
= 0; i
< wxMin(n_colors
, 16); i
++)
158 m_data
.SetCustomColour(i
, wxColour(colors
[i
]));
164 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
167 #endif // wxUSE_COLOURDLG