X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce00f59b5b169752d2f05ce3bb1a88ddc1b38b4c..4e15d1caa03346c126015019c1fdf093033ef40b:/src/gtk/colordlg.cpp diff --git a/src/gtk/colordlg.cpp b/src/gtk/colordlg.cpp index eb8bdae88e..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,12 +19,15 @@ #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 @@ -69,8 +72,9 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data) } #if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 - GtkColorSelection *sel = - GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget)->colorsel); + 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 @@ -79,6 +83,8 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data) int wxColourDialog::ShowModal() { + WX_TESTING_SHOW_MODAL_HOOK(); + ColourDataToDialog(); gint result = gtk_dialog_run(GTK_DIALOG(m_widget)); @@ -103,10 +109,11 @@ 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)); @@ -123,20 +130,28 @@ void wxColourDialog::ColourDataToDialog() 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(m_widget)->colorsel); + 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++; @@ -159,7 +174,7 @@ void wxColourDialog::DialogToColourData() m_data.SetColour(*clr); #elif wxUSE_LIBHILDON2 // !wxUSE_LIBHILDON const GdkColor * const - col = m_data.GetColour().Ok() ? m_data.GetColour().GetColor() : NULL; + col = m_data.GetColour().IsOk() ? m_data.GetColour().GetColor() : NULL; GdkColor clr; if (col) @@ -176,11 +191,17 @@ void wxColourDialog::DialogToColourData() m_data.SetColour(new_color); #else // !wxUSE_LIBHILDON2 - GtkColorSelection *sel = - GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget)->colorsel); + 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: @@ -193,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])); }