X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b25630fb6c870cc2bd2b465b45e1788a04391e24..726cc8697cd44a41b43257f05ca8cdd42b71a711:/src/gtk/colordlg.cpp diff --git a/src/gtk/colordlg.cpp b/src/gtk/colordlg.cpp index 9e676a6fa8..ca9e536a65 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: @@ -9,10 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "colordlg.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -20,7 +16,7 @@ #pragma hdrstop #endif -#if wxUSE_COLOURDLG && defined(__WXGTK20__) +#if wxUSE_COLOURDLG #include "wx/colordlg.h" @@ -30,6 +26,16 @@ #include "wx/gtk/private.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,55 +48,89 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data) if (data) m_data = *data; + 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); +#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)); - - if (parent) - gtk_window_set_transient_for(GTK_WINDOW(m_widget), - GTK_WINDOW(parent->m_widget)); - - GtkColorSelection *sel = - GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget)->colorsel); +#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON + + g_object_ref(m_widget); + + if ( parentGTK ) + { + gtk_window_set_transient_for(GTK_WINDOW(m_widget), parentGTK); + } + +#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() { ColourDataToDialog(); - + gint result = gtk_dialog_run(GTK_DIALOG(m_widget)); gtk_widget_hide(m_widget); - + switch (result) { default: - wxFAIL_MSG(_T("unexpected GtkColorSelectionDialog return code")); + wxFAIL_MSG(wxT("unexpected GtkColorSelectionDialog return code")); // fall through case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_DELETE_EVENT: case GTK_RESPONSE_CLOSE: return wxID_CANCEL; - + case GTK_RESPONSE_OK: DialogToColourData(); return wxID_OK; - }; + } } void wxColourDialog::ColourDataToDialog() { - GtkColorSelection *sel = - GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget)->colorsel); - - if (m_data.GetColour().Ok()) - { - gtk_color_selection_set_current_color(sel, - m_data.GetColour().GetColor()); + const GdkColor * const + col = m_data.GetColour().Ok() ? m_data.GetColour().GetColor() + : NULL; + +#if wxUSE_LIBHILDON + HildonColorSelector * const sel = HILDON_COLOR_SELECTOR(m_widget); + hildon_color_selector_set_color(sel, const_cast(col)); +#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); + // setup the palette: GdkColor colors[16]; @@ -105,23 +145,47 @@ void wxColourDialog::ColourDataToDialog() } } - gchar *pal = gtk_color_selection_palette_to_string(colors, n_colors); + wxGtkString pal(gtk_color_selection_palette_to_string(colors, n_colors)); GtkSettings *settings = gtk_widget_get_settings(GTK_WIDGET(sel)); - g_object_set(settings, "gtk-color-palette", pal, NULL); - - g_free(pal); + g_object_set(settings, "gtk-color-palette", pal.c_str(), NULL); +#endif // wxUSE_LIBHILDON / wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 } void wxColourDialog::DialogToColourData() { - GtkColorSelection *sel = - GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(m_widget)->colorsel); +#if wxUSE_LIBHILDON + HildonColorSelector * const sel = HILDON_COLOR_SELECTOR(m_widget); + const GdkColor * const clr = hildon_color_selector_get_color(sel); + if ( clr ) + m_data.SetColour(*clr); +#elif wxUSE_LIBHILDON2 // !wxUSE_LIBHILDON + const GdkColor * const + col = m_data.GetColour().Ok() ? 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))); GdkColor clr; gtk_color_selection_get_current_color(sel, &clr); - m_data.SetColour(wxColour(clr.red >> 8, clr.green >> 8, clr.blue >> 8)); - + m_data.SetColour(clr); + // Extract custom palette: GtkSettings *settings = gtk_widget_get_settings(GTK_WIDGET(sel)); @@ -134,15 +198,14 @@ void wxColourDialog::DialogToColourData() { for (int i = 0; i < wxMin(n_colors, 16); i++) { - m_data.SetCustomColour(i, wxColour(colors[i].red >> 8, - colors[i].green >> 8, - colors[i].blue >> 8)); + m_data.SetCustomColour(i, wxColour(colors[i])); } g_free(colors); } - + g_free(pal); +#endif // wxUSE_LIBHILDON / wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 } -#endif // wxUSE_COLOURDLG && defined(__WXGTK20__) +#endif // wxUSE_COLOURDLG