/* Copyright (C) 1998-2002 The gtkmm Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see . */ #include #include namespace { static Gtk::ColorSelection::SlotChangePaletteHook* global_change_palette_hook = nullptr; static void global_change_palette_hook_callback(GdkScreen* screen, const GdkColor* colors, int n_colors) { g_return_if_fail(global_change_palette_hook != nullptr); try { (*global_change_palette_hook)( Glib::wrap(screen, true), Glib::ArrayHandler::array_to_vector(colors, n_colors, Glib::OWNERSHIP_NONE)); } catch(...) { Glib::exception_handlers_invoke(); } } static void old_change_palette_hook_callback(const Glib::RefPtr& screen, const std::vector& colors, GtkColorSelectionChangePaletteWithScreenFunc func) { g_return_if_fail(func != nullptr); (*func)(Glib::unwrap(screen), Glib::ArrayHandler::vector_to_array(colors).data(), colors.size()); } } // anonymous namespace namespace Gtk { Gdk::Color ColorSelection::get_current_color() const { Gdk::Color color; //GdkColor Just a simple struct. gtk_color_selection_get_current_color(const_cast(gobj()), color.gobj()); return color; } Gdk::Color ColorSelection::get_previous_color() const { Gdk::Color color; //GdkColor Just a simple struct. gtk_color_selection_get_previous_color(const_cast(gobj()), color.gobj()); return color; } Gdk::RGBA ColorSelection::get_current_rgba() const { Gdk::RGBA color; //GdkRGBA is just a simple struct. gtk_color_selection_get_current_rgba(const_cast(gobj()), color.gobj()); return color; } Gdk::RGBA ColorSelection::get_previous_rgba() const { Gdk::RGBA color; //GdkRGBA is just a simple struct. gtk_color_selection_get_previous_rgba(const_cast(gobj()), color.gobj()); return color; } // static std::vector ColorSelection::palette_from_string(const Glib::ustring& str) { GdkColor* colors = nullptr; int n_colors = 0; gtk_color_selection_palette_from_string(str.c_str(), &colors, &n_colors); return Glib::ArrayHandler::array_to_vector(colors, n_colors, Glib::OWNERSHIP_SHALLOW); } // static Glib::ustring ColorSelection::palette_to_string(const std::vector& colors) { if(char *const str = gtk_color_selection_palette_to_string(Glib::ArrayHandler::vector_to_array(colors).data (), colors.size())) return Glib::ustring(Glib::make_unique_ptr_gfree(str).get()); else return Glib::ustring(); } // static ColorSelection::SlotChangePaletteHook ColorSelection::set_change_palette_hook(const ColorSelection::SlotChangePaletteHook& slot) { GtkColorSelectionChangePaletteWithScreenFunc new_func = nullptr; SlotChangePaletteHook* new_slot = nullptr; SlotChangePaletteHook old_slot; if(slot) { new_func = &global_change_palette_hook_callback; new_slot = new SlotChangePaletteHook(slot); } const GtkColorSelectionChangePaletteWithScreenFunc old_func = gtk_color_selection_set_change_palette_with_screen_hook(new_func); if(old_func) { try { if(old_func != &global_change_palette_hook_callback) old_slot = sigc::bind<-1>(sigc::ptr_fun(&old_change_palette_hook_callback), old_func); else if(global_change_palette_hook) old_slot = *global_change_palette_hook; } catch(...) { gtk_color_selection_set_change_palette_with_screen_hook(old_func); delete new_slot; throw; } } delete global_change_palette_hook; global_change_palette_hook = new_slot; return old_slot; } } // namespace Gtk