X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a83f860948059b0273b5cc6d9e43fadad3ebfca..4e15d1caa03346c126015019c1fdf093033ef40b:/src/gtk/colordlg.cpp diff --git a/src/gtk/colordlg.cpp b/src/gtk/colordlg.cpp index 7ffd6045f2..87b61d2d44 100644 --- a/src/gtk/colordlg.cpp +++ b/src/gtk/colordlg.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: gtk/colordlg.cpp +// Name: src/gtk/colordlg.cpp // Purpose: Native wxColourDialog for GTK+ // Author: Vaclav Slavik // Modified by: @@ -19,17 +19,26 @@ #if wxUSE_COLOURDLG #include "wx/colordlg.h" +#include "wx/testing.h" #ifndef WX_PRECOMP #include "wx/intl.h" #endif +#include #include "wx/gtk/private.h" +#include "wx/gtk/private/gtk2-compat.h" #if wxUSE_LIBHILDON #include #endif // wxUSE_LIBHILDON +#if wxUSE_LIBHILDON2 +extern "C" { + #include +} +#endif // wxUSE_LIBHILDON2 + IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog) wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data) @@ -42,13 +51,15 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data) if (data) m_data = *data; - m_parent = GetParentForModalDialog(parent); + m_parent = GetParentForModalDialog(parent, 0); GtkWindow * const parentGTK = m_parent ? GTK_WINDOW(m_parent->m_widget) : NULL; #if wxUSE_LIBHILDON m_widget = hildon_color_selector_new(parentGTK); -#else // !wxUSE_LIBHILDON +#elif wxUSE_LIBHILDON2 // !wxUSE_LIBHILDON + m_widget = hildon_color_chooser_dialog_new(); +#else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 wxString title(_("Choose colour")); m_widget = gtk_color_selection_dialog_new(wxGTK_CONV(title)); #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON @@ -60,15 +71,20 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data) gtk_window_set_transient_for(GTK_WINDOW(m_widget), parentGTK); } - GtkColorSelection *sel = - GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget)->colorsel); +#if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 + GtkColorSelection* sel = GTK_COLOR_SELECTION( + gtk_color_selection_dialog_get_color_selection( + GTK_COLOR_SELECTION_DIALOG(m_widget))); gtk_color_selection_set_has_palette(sel, true); +#endif // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 return true; } int wxColourDialog::ShowModal() { + WX_TESTING_SHOW_MODAL_HOOK(); + ColourDataToDialog(); gint result = gtk_dialog_run(GTK_DIALOG(m_widget)); @@ -93,28 +109,49 @@ int wxColourDialog::ShowModal() void wxColourDialog::ColourDataToDialog() { +#if wxUSE_LIBHILDON || wxUSE_LIBHILDON2 const GdkColor * const - col = m_data.GetColour().Ok() ? m_data.GetColour().GetColor() + col = m_data.GetColour().IsOk() ? m_data.GetColour().GetColor() : NULL; - +#endif #if wxUSE_LIBHILDON HildonColorSelector * const sel = HILDON_COLOR_SELECTOR(m_widget); hildon_color_selector_set_color(sel, const_cast(col)); -#else // !wxUSE_LIBHILDON - GtkColorSelection *sel = - GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget)->colorsel); +#elif wxUSE_LIBHILDON2 + GdkColor clr; + if (col) + clr = *col; + else { + clr.pixel = 0; + clr.red = 32768; + clr.green = 32768; + clr.blue = 32768; + } + + hildon_color_chooser_dialog_set_color((HildonColorChooserDialog *)m_widget, &clr); +#else // !wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 + GtkColorSelection* sel = GTK_COLOR_SELECTION( + gtk_color_selection_dialog_get_color_selection( + GTK_COLOR_SELECTION_DIALOG(m_widget))); - if ( col ) - gtk_color_selection_set_current_color(sel, col); + const wxColour& color = m_data.GetColour(); + if (color.IsOk()) + { +#ifdef __WXGTK3__ + gtk_color_selection_set_current_rgba(sel, color); +#else + gtk_color_selection_set_current_color(sel, color.GetColor()); +#endif + } // setup the palette: - GdkColor colors[16]; + GdkColor colors[wxColourData::NUM_CUSTOM]; gint n_colors = 0; - for (unsigned i = 0; i < 16; i++) + for (unsigned i = 0; i < WXSIZEOF(colors); i++) { wxColour c = m_data.GetCustomColour(i); - if (c.Ok()) + if (c.IsOk()) { colors[n_colors] = *c.GetColor(); n_colors++; @@ -125,7 +162,7 @@ void wxColourDialog::ColourDataToDialog() GtkSettings *settings = gtk_widget_get_settings(GTK_WIDGET(sel)); g_object_set(settings, "gtk-color-palette", pal.c_str(), NULL); -#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON +#endif // wxUSE_LIBHILDON / wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 } void wxColourDialog::DialogToColourData() @@ -135,12 +172,36 @@ void wxColourDialog::DialogToColourData() const GdkColor * const clr = hildon_color_selector_get_color(sel); if ( clr ) m_data.SetColour(*clr); -#else // !wxUSE_LIBHILDON - GtkColorSelection *sel = - GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget)->colorsel); +#elif wxUSE_LIBHILDON2 // !wxUSE_LIBHILDON + const GdkColor * const + col = m_data.GetColour().IsOk() ? m_data.GetColour().GetColor() : NULL; + + GdkColor clr; + if (col) + clr = *col; + else { + clr.pixel = 0; + clr.red = 32768; + clr.green = 32768; + clr.blue = 32768; + } + GdkColor new_color = clr; + hildon_color_chooser_dialog_get_color((HildonColorChooserDialog *)m_widget, &new_color); + + m_data.SetColour(new_color); +#else // !wxUSE_LIBHILDON2 + + GtkColorSelection* sel = GTK_COLOR_SELECTION( + gtk_color_selection_dialog_get_color_selection( + GTK_COLOR_SELECTION_DIALOG(m_widget))); +#ifdef __WXGTK3__ + GdkRGBA clr; + gtk_color_selection_get_current_rgba(sel, &clr); +#else GdkColor clr; gtk_color_selection_get_current_color(sel, &clr); +#endif m_data.SetColour(clr); // Extract custom palette: @@ -153,7 +214,7 @@ void wxColourDialog::DialogToColourData() gint n_colors; if (gtk_color_selection_palette_from_string(pal, &colors, &n_colors)) { - for (int i = 0; i < wxMin(n_colors, 16); i++) + for (int i = 0; i < n_colors && i < wxColourData::NUM_CUSTOM; i++) { m_data.SetCustomColour(i, wxColour(colors[i])); } @@ -161,7 +222,7 @@ void wxColourDialog::DialogToColourData() } g_free(pal); -#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON +#endif // wxUSE_LIBHILDON / wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 } #endif // wxUSE_COLOURDLG