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"
29 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
31 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
36 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
41 wxString
title(_("Choose colour"));
42 m_widget
= gtk_color_selection_dialog_new(wxGTK_CONV(title
));
44 m_parent
= GetParentForModalDialog(parent
);
47 GtkWindow
* gtk_parent
= GTK_WINDOW( gtk_widget_get_toplevel(m_parent
->m_widget
) );
48 gtk_window_set_transient_for(GTK_WINDOW(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
));
64 gtk_widget_hide(m_widget
);
69 wxFAIL_MSG(_T("unexpected GtkColorSelectionDialog return code"));
72 case GTK_RESPONSE_CANCEL
:
73 case GTK_RESPONSE_DELETE_EVENT
:
74 case GTK_RESPONSE_CLOSE
:
83 void wxColourDialog::ColourDataToDialog()
85 GtkColorSelection
*sel
=
86 GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget
)->colorsel
);
88 if (m_data
.GetColour().Ok())
90 gtk_color_selection_set_current_color(sel
,
91 m_data
.GetColour().GetColor());
98 for (unsigned i
= 0; i
< 16; i
++)
100 wxColour c
= m_data
.GetCustomColour(i
);
103 colors
[n_colors
] = *c
.GetColor();
108 wxGtkString
pal(gtk_color_selection_palette_to_string(colors
, n_colors
));
110 GtkSettings
*settings
= gtk_widget_get_settings(GTK_WIDGET(sel
));
111 g_object_set(settings
, "gtk-color-palette", pal
.c_str(), NULL
);
114 void wxColourDialog::DialogToColourData()
116 GtkColorSelection
*sel
=
117 GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget
)->colorsel
);
120 gtk_color_selection_get_current_color(sel
, &clr
);
121 m_data
.SetColour(wxColour(clr
));
123 // Extract custom palette:
125 GtkSettings
*settings
= gtk_widget_get_settings(GTK_WIDGET(sel
));
127 g_object_get(settings
, "gtk-color-palette", &pal
, NULL
);
131 if (gtk_color_selection_palette_from_string(pal
, &colors
, &n_colors
))
133 for (int i
= 0; i
< wxMin(n_colors
, 16); i
++)
135 m_data
.SetCustomColour(i
, wxColour(colors
[i
]));
143 #endif // wxUSE_COLOURDLG