paint-selector.cpp revision 1f94403a1f6b0f5aa33d876ed8a3dfaeafea3eea
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering/**
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering * @file
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering * SPPaintSelector: Generic paint selector widget.
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering */
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering/*
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering * Authors:
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering * Lauris Kaplinski
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * bulia byak <buliabyak@users.sf.net>
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * John Cliff <simarilius@yahoo.com>
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering * Jon A. Cruz <jon@joncruz.org>
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering * Abhishek Sharma
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering *
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering * Copyright (C) Lauris Kaplinski 2002
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering * Copyright (C) 2010 Authors
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering*/
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering#define noSP_PS_VERBOSE
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering#ifdef HAVE_CONFIG_H
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering# include "config.h"
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering#endif
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek#include <cstring>
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#include <string>
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "widgets/swatch-selector.h"
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "sp-pattern.h"
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include <glibmm/i18n.h>
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "widgets/icon.h"
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "widgets/widget-sizes.h"
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "xml/repr.h"
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "sp-linear-gradient.h"
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering#include "sp-radial-gradient.h"
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering#include "sp-mesh.h"
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek#include "sp-stop.h"
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek/* fixme: Move it from dialogs to here */
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "gradient-selector.h"
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include <inkscape.h>
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include <document-private.h>
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#include <desktop-style.h>
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#include <style.h>
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#include "svg/svg-color.h"
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#include "svg/css-ostringstream.h"
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#include "path-prefix.h"
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "io/sys.h"
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "helper/stock-items.h"
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "ui/icon-names.h"
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "ui/widget/color-notebook.h"
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "paint-selector.h"
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#ifdef SP_PS_VERBOSE
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#include "svg/svg-icc-color.h"
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek#endif // SP_PS_VERBOSE
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
1930eed2a7855d2df06ccf51f9e394428bf547e2Jon Severinsson#include <gtk/gtk.h>
1930eed2a7855d2df06ccf51f9e394428bf547e2Jon Severinsson
1930eed2a7855d2df06ccf51f9e394428bf547e2Jon Severinssonusing Inkscape::Widgets::SwatchSelector;
1930eed2a7855d2df06ccf51f9e394428bf547e2Jon Severinssonusing Inkscape::UI::SelectedColor;
1930eed2a7855d2df06ccf51f9e394428bf547e2Jon Severinsson
1930eed2a7855d2df06ccf51f9e394428bf547e2Jon Severinssonenum {
1930eed2a7855d2df06ccf51f9e394428bf547e2Jon Severinsson MODE_CHANGED,
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering GRABBED,
76cc0bf682b944d4cb611f1b37c71fce140f8fe7Zbigniew Jędrzejewski-Szmek DRAGGED,
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering RELEASED,
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering CHANGED,
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering FILLRULE_CHANGED,
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering LAST_SIGNAL
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering};
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void sp_paint_selector_dispose(GObject *object);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poetteringstatic GtkWidget *sp_paint_selector_style_button_add(SPPaintSelector *psel, gchar const *px, SPPaintSelector::Mode mode, gchar const *tip);
1930eed2a7855d2df06ccf51f9e394428bf547e2Jon Severinssonstatic void sp_paint_selector_style_button_toggled(GtkToggleButton *tb, SPPaintSelector *psel);
1930eed2a7855d2df06ccf51f9e394428bf547e2Jon Severinssonstatic void sp_paint_selector_fillrule_toggled(GtkToggleButton *tb, SPPaintSelector *psel);
1930eed2a7855d2df06ccf51f9e394428bf547e2Jon Severinsson
1930eed2a7855d2df06ccf51f9e394428bf547e2Jon Severinssonstatic void sp_paint_selector_set_mode_empty(SPPaintSelector *psel);
1930eed2a7855d2df06ccf51f9e394428bf547e2Jon Severinssonstatic void sp_paint_selector_set_mode_multiple(SPPaintSelector *psel);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poetteringstatic void sp_paint_selector_set_mode_none(SPPaintSelector *psel);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void sp_paint_selector_set_mode_color(SPPaintSelector *psel, SPPaintSelector::Mode mode);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poetteringstatic void sp_paint_selector_set_mode_gradient(SPPaintSelector *psel, SPPaintSelector::Mode mode);
76cc0bf682b944d4cb611f1b37c71fce140f8fe7Zbigniew Jędrzejewski-Szmekstatic void sp_paint_selector_set_mode_pattern(SPPaintSelector *psel, SPPaintSelector::Mode mode);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void sp_paint_selector_set_mode_swatch(SPPaintSelector *psel, SPPaintSelector::Mode mode);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void sp_paint_selector_set_mode_unset(SPPaintSelector *psel);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poetteringstatic void sp_paint_selector_set_style_buttons(SPPaintSelector *psel, GtkWidget *active);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmekstatic guint psel_signals[LAST_SIGNAL] = {0};
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#ifdef SP_PS_VERBOSE
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic gchar const* modeStrings[] = {
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek "MODE_EMPTY",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek "MODE_MULTIPLE",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek "MODE_NONE",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek "MODE_SOLID_COLOR",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek "MODE_GRADIENT_LINEAR",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek "MODE_GRADIENT_RADIAL",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek "MODE_PATTERN",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek "MODE_SWATCH",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek "MODE_UNSET",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek ".",
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering ".",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek ".",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek};
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#endif
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic bool isPaintModeGradient(SPPaintSelector::Mode mode)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek bool isGrad = (mode == SPPaintSelector::MODE_GRADIENT_LINEAR) ||
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek (mode == SPPaintSelector::MODE_GRADIENT_RADIAL) ||
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#ifdef WITH_MESH
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek (mode == SPPaintSelector::MODE_GRADIENT_MESH) ||
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#endif
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek (mode == SPPaintSelector::MODE_SWATCH);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek return isGrad;
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek}
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic SPGradientSelector *getGradientFromData(SPPaintSelector const *psel)
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-Szmek{
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering SPGradientSelector *grad = 0;
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek if (psel->mode == SPPaintSelector::MODE_SWATCH) {
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering SwatchSelector *swatchsel = static_cast<SwatchSelector*>(g_object_get_data(G_OBJECT(psel->selector), "swatch-selector"));
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering if (swatchsel) {
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering grad = swatchsel->getGradientSelector();
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering }
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering } else {
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering grad = reinterpret_cast<SPGradientSelector*>(g_object_get_data(G_OBJECT(psel->selector), "gradient-selector"));
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering }
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering return grad;
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering}
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#if GTK_CHECK_VERSION(3,0,0)
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart PoetteringG_DEFINE_TYPE(SPPaintSelector, sp_paint_selector, GTK_TYPE_BOX);
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek#else
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-SzmekG_DEFINE_TYPE(SPPaintSelector, sp_paint_selector, GTK_TYPE_VBOX);
01c3322e017989d25f7b4b51268245d5315ae678Zbigniew Jędrzejewski-Szmek#endif
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poetteringstatic void
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poetteringsp_paint_selector_class_init(SPPaintSelectorClass *klass)
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering{
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering GObjectClass *object_class = G_OBJECT_CLASS(klass);
93b73b064c663d6248bebfbbbd82989b5ca10fc5Lennart Poettering
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering psel_signals[MODE_CHANGED] = g_signal_new("mode_changed",
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering G_TYPE_FROM_CLASS(object_class),
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering G_STRUCT_OFFSET(SPPaintSelectorClass, mode_changed),
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering NULL, NULL,
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering g_cclosure_marshal_VOID__UINT,
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering G_TYPE_NONE, 1, G_TYPE_UINT);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering psel_signals[GRABBED] = g_signal_new("grabbed",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek G_TYPE_FROM_CLASS(object_class),
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering G_STRUCT_OFFSET(SPPaintSelectorClass, grabbed),
93b73b064c663d6248bebfbbbd82989b5ca10fc5Lennart Poettering NULL, NULL,
93b73b064c663d6248bebfbbbd82989b5ca10fc5Lennart Poettering g_cclosure_marshal_VOID__VOID,
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek G_TYPE_NONE, 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel_signals[DRAGGED] = g_signal_new("dragged",
93b73b064c663d6248bebfbbbd82989b5ca10fc5Lennart Poettering G_TYPE_FROM_CLASS(object_class),
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-Szmek (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek G_STRUCT_OFFSET(SPPaintSelectorClass, dragged),
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-Szmek NULL, NULL,
01c3322e017989d25f7b4b51268245d5315ae678Zbigniew Jędrzejewski-Szmek g_cclosure_marshal_VOID__VOID,
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering G_TYPE_NONE, 0);
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-Szmek psel_signals[RELEASED] = g_signal_new("released",
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-Szmek G_TYPE_FROM_CLASS(object_class),
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering G_STRUCT_OFFSET(SPPaintSelectorClass, released),
93b73b064c663d6248bebfbbbd82989b5ca10fc5Lennart Poettering NULL, NULL,
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek g_cclosure_marshal_VOID__VOID,
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek G_TYPE_NONE, 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel_signals[CHANGED] = g_signal_new("changed",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek G_TYPE_FROM_CLASS(object_class),
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering G_STRUCT_OFFSET(SPPaintSelectorClass, changed),
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek NULL, NULL,
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek g_cclosure_marshal_VOID__VOID,
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek G_TYPE_NONE, 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel_signals[FILLRULE_CHANGED] = g_signal_new("fillrule_changed",
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek G_TYPE_FROM_CLASS(object_class),
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering G_STRUCT_OFFSET(SPPaintSelectorClass, fillrule_changed),
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek NULL, NULL,
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek g_cclosure_marshal_VOID__UINT,
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek G_TYPE_NONE, 1, G_TYPE_UINT);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek object_class->dispose = sp_paint_selector_dispose;
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek}
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#define XPAD 4
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#define YPAD 1
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmeksp_paint_selector_init(SPPaintSelector *psel)
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek{
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek#if GTK_CHECK_VERSION(3,0,0)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_orientable_set_orientation(GTK_ORIENTABLE(psel), GTK_ORIENTATION_VERTICAL);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#endif
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->mode = static_cast<SPPaintSelector::Mode>(-1); // huh? do you mean 0xff? -- I think this means "not in the enum"
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek /* Paint style button box */
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#if GTK_CHECK_VERSION(3,0,0)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->style = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_box_set_homogeneous(GTK_BOX(psel->style), FALSE);
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek#else
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->style = gtk_hbox_new(FALSE, 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#endif
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_widget_show(psel->style);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_container_set_border_width(GTK_CONTAINER(psel->style), 4);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_box_pack_start(GTK_BOX(psel), psel->style, FALSE, FALSE, 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek /* Buttons */
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->none = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON("paint-none"),
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek SPPaintSelector::MODE_NONE, _("No paint"));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->solid = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON("paint-solid"),
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek SPPaintSelector::MODE_SOLID_COLOR, _("Flat color"));
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek psel->gradient = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON("paint-gradient-linear"),
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek SPPaintSelector::MODE_GRADIENT_LINEAR, _("Linear gradient"));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->radial = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON("paint-gradient-radial"),
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek SPPaintSelector::MODE_GRADIENT_RADIAL, _("Radial gradient"));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#ifdef WITH_MESH
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->mesh = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON("paint-gradient-mesh"),
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek SPPaintSelector::MODE_GRADIENT_MESH, _("Mesh gradient"));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#endif
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->pattern = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON("paint-pattern"),
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek SPPaintSelector::MODE_PATTERN, _("Pattern"));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->swatch = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON("paint-swatch"),
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek SPPaintSelector::MODE_SWATCH, _("Swatch"));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->unset = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON("paint-unknown"),
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek SPPaintSelector::MODE_UNSET, _("Unset paint (make it undefined so it can be inherited)"));
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek /* Fillrule */
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek {
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#if GTK_CHECK_VERSION(3,0,0)
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-Szmek psel->fillrulebox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_box_set_homogeneous(GTK_BOX(psel->fillrulebox), FALSE);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering#else
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->fillrulebox = gtk_hbox_new(FALSE, 0);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering#endif
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_box_pack_end(GTK_BOX(psel->style), psel->fillrulebox, FALSE, FALSE, 0);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering GtkWidget *w;
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering psel->evenodd = gtk_radio_button_new(NULL);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_button_set_relief(GTK_BUTTON(psel->evenodd), GTK_RELIEF_NONE);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(psel->evenodd), FALSE);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/painting.html#FillRuleProperty
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_widget_set_tooltip_text(psel->evenodd, _("Any path self-intersections or subpaths create holes in the fill (fill-rule: evenodd)"));
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering g_object_set_data(G_OBJECT(psel->evenodd), "mode", GUINT_TO_POINTER(SPPaintSelector::FILLRULE_EVENODD));
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering w = sp_icon_new(Inkscape::ICON_SIZE_DECORATION, INKSCAPE_ICON("fill-rule-even-odd"));
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_container_add(GTK_CONTAINER(psel->evenodd), w);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_box_pack_start(GTK_BOX(psel->fillrulebox), psel->evenodd, FALSE, FALSE, 0);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering g_signal_connect(G_OBJECT(psel->evenodd), "toggled", G_CALLBACK(sp_paint_selector_fillrule_toggled), psel);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->nonzero = gtk_radio_button_new(gtk_radio_button_get_group(GTK_RADIO_BUTTON(psel->evenodd)));
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_button_set_relief(GTK_BUTTON(psel->nonzero), GTK_RELIEF_NONE);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(psel->nonzero), FALSE);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/painting.html#FillRuleProperty
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_widget_set_tooltip_text(psel->nonzero, _("Fill is solid unless a subpath is counterdirectional (fill-rule: nonzero)"));
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering g_object_set_data(G_OBJECT(psel->nonzero), "mode", GUINT_TO_POINTER(SPPaintSelector::FILLRULE_NONZERO));
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering w = sp_icon_new(Inkscape::ICON_SIZE_DECORATION, INKSCAPE_ICON("fill-rule-nonzero"));
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_container_add(GTK_CONTAINER(psel->nonzero), w);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_box_pack_start(GTK_BOX(psel->fillrulebox), psel->nonzero, FALSE, FALSE, 0);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering g_signal_connect(G_OBJECT(psel->nonzero), "toggled", G_CALLBACK(sp_paint_selector_fillrule_toggled), psel);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering }
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek /* Frame */
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering psel->label = gtk_label_new("");
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-Szmek#if GTK_CHECK_VERSION(3,0,0)
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-Szmek GtkWidget *lbbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-Szmek gtk_box_set_homogeneous(GTK_BOX(lbbox), FALSE);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering#else
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering GtkWidget *lbbox = gtk_hbox_new(FALSE, 4);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#endif
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_widget_show(psel->label);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_box_pack_start(GTK_BOX(lbbox), psel->label, false, false, 4);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering gtk_box_pack_start(GTK_BOX(psel), lbbox, false, false, 4);
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#if GTK_CHECK_VERSION(3,0,0)
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering psel->frame = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-Szmek gtk_box_set_homogeneous(GTK_BOX(psel->frame), FALSE);
5e592c66bdf76dfc8445b332f7a5088ca504ee90Zbigniew Jędrzejewski-Szmek#else
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->frame = gtk_vbox_new(FALSE, 4);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#endif
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_widget_show(psel->frame);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek //gtk_container_set_border_width(GTK_CONTAINER(psel->frame), 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_box_pack_start(GTK_BOX(psel), psel->frame, TRUE, TRUE, 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek /* Last used color */
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek psel->selected_color = new SelectedColor;
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->updating_color = false;
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->selected_color->signal_grabbed.connect(sigc::mem_fun(psel, &SPPaintSelector::onSelectedColorGrabbed));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->selected_color->signal_dragged.connect(sigc::mem_fun(psel, &SPPaintSelector::onSelectedColorDragged));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->selected_color->signal_released.connect(sigc::mem_fun(psel, &SPPaintSelector::onSelectedColorReleased));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->selected_color->signal_changed.connect(sigc::mem_fun(psel, &SPPaintSelector::onSelectedColorChanged));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek}
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void sp_paint_selector_dispose(GObject *object)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek SPPaintSelector *psel = SP_PAINT_SELECTOR(object);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek // clean up our long-living pattern menu
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek g_object_set_data(G_OBJECT(psel),"patternmenu",NULL);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek if (psel->selected_color) {
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek delete psel->selected_color;
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->selected_color = NULL;
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek }
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek if ((G_OBJECT_CLASS(sp_paint_selector_parent_class))->dispose)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek (G_OBJECT_CLASS(sp_paint_selector_parent_class))->dispose(object);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek}
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic GtkWidget *sp_paint_selector_style_button_add(SPPaintSelector *psel,
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gchar const *pixmap, SPPaintSelector::Mode mode,
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gchar const *tip)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek GtkWidget *b, *w;
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek b = gtk_toggle_button_new();
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_widget_set_tooltip_text(b, tip);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_widget_show(b);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_container_set_border_width(GTK_CONTAINER(b), 0);
e4e61fdbed832a2bd3f5dcd47623872d9081599cLennart Poettering
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek gtk_button_set_relief(GTK_BUTTON(b), GTK_RELIEF_NONE);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(b), FALSE);
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek g_object_set_data(G_OBJECT(b), "mode", GUINT_TO_POINTER(mode));
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek w = sp_icon_new(Inkscape::ICON_SIZE_BUTTON, pixmap);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_widget_show(w);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_container_add(GTK_CONTAINER(b), w);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_box_pack_start(GTK_BOX(psel->style), b, FALSE, FALSE, 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek g_signal_connect(G_OBJECT(b), "toggled", G_CALLBACK(sp_paint_selector_style_button_toggled), psel);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek return b;
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek}
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmeksp_paint_selector_style_button_toggled(GtkToggleButton *tb, SPPaintSelector *psel)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek if (!psel->update && gtk_toggle_button_get_active(tb)) {
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->setMode(static_cast<SPPaintSelector::Mode>(GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(tb), "mode"))));
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering }
3b1a55e110ab387a8d213581983e20c0a63d7894Zbigniew Jędrzejewski-Szmek}
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmekstatic void
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmeksp_paint_selector_fillrule_toggled(GtkToggleButton *tb, SPPaintSelector *psel)
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek{
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek if (!psel->update && gtk_toggle_button_get_active(tb)) {
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek SPPaintSelector::FillRule fr = static_cast<SPPaintSelector::FillRule>(GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(tb), "mode")));
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek g_signal_emit(G_OBJECT(psel), psel_signals[FILLRULE_CHANGED], 0, fr);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek }
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek}
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
1fa2f38f0f011010bf57522b42fcc168856a7003Zbigniew Jędrzejewski-Szmekstatic void
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmeksp_paint_selector_show_fillrule(SPPaintSelector *psel, bool is_fill)
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek{
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek if (psel->fillrulebox) {
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek if (is_fill) {
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek gtk_widget_show_all(psel->fillrulebox);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek } else {
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek gtk_widget_destroy(psel->fillrulebox);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek psel->fillrulebox = NULL;
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering }
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering }
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek}
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-SzmekSPPaintSelector *sp_paint_selector_new(FillOrStroke kind)
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek{
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek SPPaintSelector *psel = static_cast<SPPaintSelector*>(g_object_new(SP_TYPE_PAINT_SELECTOR, NULL));
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek psel->setMode(SPPaintSelector::MODE_MULTIPLE);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek // This silliness is here because I don't know how to pass a parameter to the
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering // GtkObject "constructor" (sp_paint_selector_init). Remove it when paint_selector
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering // becomes a normal class.
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek sp_paint_selector_show_fillrule(psel, kind == FILL);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek return psel;
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek}
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmekvoid SPPaintSelector::setMode(Mode mode)
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek{
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek if (this->mode != mode) {
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek update = TRUE;
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek#ifdef SP_PS_VERBOSE
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek g_print("Mode change %d -> %d %s -> %s\n", this->mode, mode, modeStrings[this->mode], modeStrings[mode]);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek#endif
1fa2f38f0f011010bf57522b42fcc168856a7003Zbigniew Jędrzejewski-Szmek switch (mode) {
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek case MODE_EMPTY:
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek sp_paint_selector_set_mode_empty(this);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek break;
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek case MODE_MULTIPLE:
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek sp_paint_selector_set_mode_multiple(this);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek break;
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek case MODE_NONE:
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek sp_paint_selector_set_mode_none(this);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek break;
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek case MODE_SOLID_COLOR:
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek sp_paint_selector_set_mode_color(this, mode);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek break;
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek case MODE_GRADIENT_LINEAR:
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmek case MODE_GRADIENT_RADIAL:
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek#ifdef WITH_MESH
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek case MODE_GRADIENT_MESH:
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek#endif
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek sp_paint_selector_set_mode_gradient(this, mode);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek break;
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek case MODE_PATTERN:
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek sp_paint_selector_set_mode_pattern(this, mode);
3b1a55e110ab387a8d213581983e20c0a63d7894Zbigniew Jędrzejewski-Szmek break;
3b1a55e110ab387a8d213581983e20c0a63d7894Zbigniew Jędrzejewski-Szmek case MODE_SWATCH:
3b1a55e110ab387a8d213581983e20c0a63d7894Zbigniew Jędrzejewski-Szmek sp_paint_selector_set_mode_swatch(this, mode);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek break;
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek case MODE_UNSET:
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek sp_paint_selector_set_mode_unset(this);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek break;
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering default:
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek g_warning("file %s: line %d: Unknown paint mode %d", __FILE__, __LINE__, mode);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek break;
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek }
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek this->mode = mode;
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek g_signal_emit(G_OBJECT(this), psel_signals[MODE_CHANGED], 0, this->mode);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek update = FALSE;
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek }
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek}
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmekvoid SPPaintSelector::setFillrule(FillRule fillrule)
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek{
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek if (fillrulebox) {
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek // TODO this flips widgets but does not use a member to store state. Revisit
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(evenodd), (fillrule == FILLRULE_EVENODD));
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(nonzero), (fillrule == FILLRULE_NONZERO));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek }
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek}
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmekvoid SPPaintSelector::setColorAlpha(SPColor const &color, float alpha)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek{
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) );
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek/*
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek guint32 rgba = 0;
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek if ( sp_color_get_colorspace_type(color) == SP_COLORSPACE_TYPE_CMYK )
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek {
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#ifdef SP_PS_VERBOSE
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek g_print("PaintSelector set CMYKA\n");
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#endif
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek sp_paint_selector_set_mode(psel, MODE_COLOR_CMYK);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek }
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek else
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek*/
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek {
e06851720573d3adb4be54a1decfe35bc750b8f4Zbigniew Jędrzejewski-Szmek#ifdef SP_PS_VERBOSE
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek g_print("PaintSelector set RGBA\n");
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#endif
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek setMode(MODE_SOLID_COLOR);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek }
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek updating_color = true;
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek selected_color->setColorAlpha(color, alpha);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek updating_color = false;
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek //rgba = color.toRGBA32( alpha );
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek}
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmekvoid SPPaintSelector::setSwatch(SPGradient *vector )
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#ifdef SP_PS_VERBOSE
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek g_print("PaintSelector set SWATCH\n");
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#endif
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek setMode(MODE_SWATCH);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek SwatchSelector *swatchsel = static_cast<SwatchSelector*>(g_object_get_data(G_OBJECT(selector), "swatch-selector"));
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek if (swatchsel) {
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek swatchsel->setVector( (vector) ? vector->document : 0, vector );
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek }
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek}
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmekvoid SPPaintSelector::setGradientLinear(SPGradient *vector)
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek{
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#ifdef SP_PS_VERBOSE
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek g_print("PaintSelector set GRADIENT LINEAR\n");
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#endif
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek setMode(MODE_GRADIENT_LINEAR);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek SPGradientSelector *gsel = getGradientFromData(this);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gsel->setMode(SPGradientSelector::MODE_LINEAR);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek gsel->setVector((vector) ? vector->document : 0, vector);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek}
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmekvoid SPPaintSelector::setGradientRadial(SPGradient *vector)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#ifdef SP_PS_VERBOSE
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek g_print("PaintSelector set GRADIENT RADIAL\n");
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#endif
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek setMode(MODE_GRADIENT_RADIAL);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek SPGradientSelector *gsel = getGradientFromData(this);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gsel->setMode(SPGradientSelector::MODE_RADIAL);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gsel->setVector((vector) ? vector->document : 0, vector);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek}
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#ifdef WITH_MESH
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekvoid SPPaintSelector::setGradientMesh(SPGradient *vector)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#ifdef SP_PS_VERBOSE
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek g_print("PaintSelector set GRADIENT MESH\n");
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek#endif
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering setMode(MODE_GRADIENT_RADIAL);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek SPGradientSelector *gsel = getGradientFromData(this);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek gsel->setMode(SPGradientSelector::MODE_MESH);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek gsel->setVector((vector) ? vector->document : 0, vector);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek}
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek#endif
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmekvoid SPPaintSelector::setGradientProperties( SPGradientUnits units, SPGradientSpread spread )
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek{
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek g_return_if_fail(isPaintModeGradient(mode));
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek SPGradientSelector *gsel = getGradientFromData(this);
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek gsel->setUnits(units);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gsel->setSpread(spread);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek}
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmekvoid SPPaintSelector::getGradientProperties( SPGradientUnits &units, SPGradientSpread &spread) const
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek{
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek g_return_if_fail(isPaintModeGradient(mode));
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek SPGradientSelector *gsel = getGradientFromData(this);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek units = gsel->getUnits();
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek spread = gsel->getSpread();
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek}
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek/**
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek * \post (alpha == NULL) || (*alpha in [0.0, 1.0]).
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek */
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmekvoid SPPaintSelector::getColorAlpha(SPColor &color, gfloat &alpha) const
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek{
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek selected_color->colorAlpha(color, alpha);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek g_assert( ( 0.0 <= alpha )
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek && ( alpha <= 1.0 ) );
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek}
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-SzmekSPGradient *SPPaintSelector::getGradientVector()
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek{
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek SPGradient* vect = 0;
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek if (isPaintModeGradient(mode)) {
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek SPGradientSelector *gsel = getGradientFromData(this);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek vect = gsel->getVector();
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek }
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek return vect;
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek}
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekvoid SPPaintSelector::pushAttrsToGradient( SPGradient *gr ) const
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek{
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek SPGradientUnits units = SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX;
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek SPGradientSpread spread = SP_GRADIENT_SPREAD_PAD;
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek getGradientProperties( units, spread );
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek gr->setUnits(units);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek gr->setSpread(spread);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek gr->updateRepr();
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek}
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
fa1c4b518ec7d8ec2d647213ee651cde4d6c9d7eZbigniew Jędrzejewski-Szmekstatic void
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmeksp_paint_selector_clear_frame(SPPaintSelector *psel)
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek{
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek g_return_if_fail( psel != NULL);
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek if (psel->selector) {
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek //This is a hack to work around GtkNotebook bug in ColorSelector. Is sends signal switch-page on destroy
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek //The widget is hidden firts so it can recognize that it should not process signals from notebook child
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek gtk_widget_set_visible(psel->selector, false);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_widget_destroy(psel->selector);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek psel->selector = NULL;
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek }
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek}
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmekstatic void
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmeksp_paint_selector_set_mode_empty(SPPaintSelector *psel)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek sp_paint_selector_set_style_buttons(psel, NULL);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_widget_set_sensitive(psel->style, FALSE);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek sp_paint_selector_clear_frame(psel);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>No objects</b>"));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek}
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmeksp_paint_selector_set_mode_multiple(SPPaintSelector *psel)
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek sp_paint_selector_set_style_buttons(psel, NULL);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_widget_set_sensitive(psel->style, TRUE);
a6dcc7e5924f9c27d3e9c6560a448b02ec28b65fZbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek sp_paint_selector_clear_frame(psel);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
a6dcc7e5924f9c27d3e9c6560a448b02ec28b65fZbigniew Jędrzejewski-Szmek gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>Multiple styles</b>"));
a6dcc7e5924f9c27d3e9c6560a448b02ec28b65fZbigniew Jędrzejewski-Szmek}
a6dcc7e5924f9c27d3e9c6560a448b02ec28b65fZbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmeksp_paint_selector_set_mode_unset(SPPaintSelector *psel)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek sp_paint_selector_set_style_buttons(psel, psel->unset);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_widget_set_sensitive(psel->style, TRUE);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek sp_paint_selector_clear_frame(psel);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>Paint is undefined</b>"));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek}
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmeksp_paint_selector_set_mode_none(SPPaintSelector *psel)
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek sp_paint_selector_set_style_buttons(psel, psel->none);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek gtk_widget_set_sensitive(psel->style, TRUE);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek sp_paint_selector_clear_frame(psel);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>No paint</b>"));
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
a6dcc7e5924f9c27d3e9c6560a448b02ec28b65fZbigniew Jędrzejewski-Szmek}
a6dcc7e5924f9c27d3e9c6560a448b02ec28b65fZbigniew Jędrzejewski-Szmek
a6dcc7e5924f9c27d3e9c6560a448b02ec28b65fZbigniew Jędrzejewski-Szmek/* Color paint */
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekvoid SPPaintSelector::onSelectedColorGrabbed() {
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek g_signal_emit(G_OBJECT(this), psel_signals[GRABBED], 0);
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek}
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmekvoid SPPaintSelector::onSelectedColorDragged() {
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek if (updating_color) {
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek return;
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek }
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering g_signal_emit(G_OBJECT(this), psel_signals[DRAGGED], 0);
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering}
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekvoid SPPaintSelector::onSelectedColorReleased() {
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek g_signal_emit(G_OBJECT(this), psel_signals[RELEASED], 0);
a6dcc7e5924f9c27d3e9c6560a448b02ec28b65fZbigniew Jędrzejewski-Szmek}
a6dcc7e5924f9c27d3e9c6560a448b02ec28b65fZbigniew Jędrzejewski-Szmek
a6dcc7e5924f9c27d3e9c6560a448b02ec28b65fZbigniew Jędrzejewski-Szmekvoid SPPaintSelector::onSelectedColorChanged() {
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek if (updating_color) {
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek return;
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek }
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek if (mode == MODE_SOLID_COLOR) {
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek g_signal_emit(G_OBJECT(this), psel_signals[CHANGED], 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek } else {
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek g_warning("SPPaintSelector::onSelectedColorChanged(): selected color changed while not in color selection mode");
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek }
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek}
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmekstatic void sp_paint_selector_set_mode_color(SPPaintSelector *psel, SPPaintSelector::Mode /*mode*/)
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek{
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek using Inkscape::UI::Widget::ColorNotebook;
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek if ((psel->mode == SPPaintSelector::MODE_SWATCH)
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek || (psel->mode == SPPaintSelector::MODE_GRADIENT_LINEAR)
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek || (psel->mode == SPPaintSelector::MODE_GRADIENT_RADIAL) ) {
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek SPGradientSelector *gsel = getGradientFromData(psel);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek if (gsel) {
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek SPGradient *gradient = gsel->getVector();
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek // Gradient can be null if object paint is changed externally (ie. with a color picker tool)
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek if (gradient)
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek {
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek SPColor color = gradient->getFirstStop()->specified_color;
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek float alpha = gradient->getFirstStop()->opacity;
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek psel->selected_color->setColorAlpha(color, alpha, false);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek }
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek }
e06851720573d3adb4be54a1decfe35bc750b8f4Zbigniew Jędrzejewski-Szmek }
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek sp_paint_selector_set_style_buttons(psel, psel->solid);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek gtk_widget_set_sensitive(psel->style, TRUE);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek if ((psel->mode == SPPaintSelector::MODE_SOLID_COLOR)) {
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek /* Already have color selector */
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek // Do nothing
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek } else {
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek sp_paint_selector_clear_frame(psel);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek /* Create new color selector */
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek /* Create vbox */
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#if GTK_CHECK_VERSION(3,0,0)
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek GtkWidget *vb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek gtk_box_set_homogeneous(GTK_BOX(vb), FALSE);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#else
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek GtkWidget *vb = gtk_vbox_new(FALSE, 4);
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek#endif
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek gtk_widget_show(vb);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek /* Color selector */
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek Gtk::Widget *color_selector = Gtk::manage(new ColorNotebook(*(psel->selected_color)));
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek color_selector->show();
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek gtk_box_pack_start(GTK_BOX(vb), color_selector->gobj(), TRUE, TRUE, 0);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek /* Pack everything to frame */
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek gtk_container_add(GTK_CONTAINER(psel->frame), vb);
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek psel->selector = vb;
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek }
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>Flat color</b>"));
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#ifdef SP_PS_VERBOSE
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek g_print("Color req\n");
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek#endif
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek}
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek/* Gradient */
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmekstatic void sp_paint_selector_gradient_grabbed(SPGradientSelector * /*csel*/, SPPaintSelector *psel)
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek{
4b5bc5396c090ee41c45cab9052372d296c4a2f4Zbigniew Jędrzejewski-Szmek g_signal_emit(G_OBJECT(psel), psel_signals[GRABBED], 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek}
5146f9f065dbc06b849f92fa00d8d57bd0096e12Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void sp_paint_selector_gradient_dragged(SPGradientSelector * /*csel*/, SPPaintSelector *psel)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek g_signal_emit(G_OBJECT(psel), psel_signals[DRAGGED], 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek}
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void sp_paint_selector_gradient_released(SPGradientSelector * /*csel*/, SPPaintSelector *psel)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek{
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek g_signal_emit(G_OBJECT(psel), psel_signals[RELEASED], 0);
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek}
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmekstatic void sp_paint_selector_gradient_changed(SPGradientSelector * /*csel*/, SPPaintSelector *psel)
d89c8fdf48c7bad5816b9f2e77e8361721f22517Zbigniew Jędrzejewski-Szmek{
355b59e252c9910e44a1ad95c045ba8db58a4f6aZbigniew Jędrzejewski-Szmek g_signal_emit(G_OBJECT(psel), psel_signals[CHANGED], 0);
}
static void sp_paint_selector_set_mode_gradient(SPPaintSelector *psel, SPPaintSelector::Mode mode)
{
GtkWidget *gsel;
/* fixme: We do not need function-wide gsel at all */
if (mode == SPPaintSelector::MODE_GRADIENT_LINEAR) {
sp_paint_selector_set_style_buttons(psel, psel->gradient);
} else if (mode == SPPaintSelector::MODE_GRADIENT_RADIAL) {
sp_paint_selector_set_style_buttons(psel, psel->radial);
}
#ifdef WITH_MESH
else {
sp_paint_selector_set_style_buttons(psel, psel->mesh);
}
#endif
gtk_widget_set_sensitive(psel->style, TRUE);
if ((psel->mode == SPPaintSelector::MODE_GRADIENT_LINEAR) || (psel->mode == SPPaintSelector::MODE_GRADIENT_RADIAL)) {
/* Already have gradient selector */
gsel = GTK_WIDGET(g_object_get_data(G_OBJECT(psel->selector), "gradient-selector"));
} else {
sp_paint_selector_clear_frame(psel);
/* Create new gradient selector */
gsel = sp_gradient_selector_new();
gtk_widget_show(gsel);
g_signal_connect(G_OBJECT(gsel), "grabbed", G_CALLBACK(sp_paint_selector_gradient_grabbed), psel);
g_signal_connect(G_OBJECT(gsel), "dragged", G_CALLBACK(sp_paint_selector_gradient_dragged), psel);
g_signal_connect(G_OBJECT(gsel), "released", G_CALLBACK(sp_paint_selector_gradient_released), psel);
g_signal_connect(G_OBJECT(gsel), "changed", G_CALLBACK(sp_paint_selector_gradient_changed), psel);
/* Pack everything to frame */
gtk_container_add(GTK_CONTAINER(psel->frame), gsel);
psel->selector = gsel;
g_object_set_data(G_OBJECT(psel->selector), "gradient-selector", gsel);
}
/* Actually we have to set option menu history here */
if (mode == SPPaintSelector::MODE_GRADIENT_LINEAR) {
SP_GRADIENT_SELECTOR(gsel)->setMode(SPGradientSelector::MODE_LINEAR);
//sp_gradient_selector_set_mode(SP_GRADIENT_SELECTOR(gsel), SP_GRADIENT_SELECTOR_MODE_LINEAR);
gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>Linear gradient</b>"));
} else if (mode == SPPaintSelector::MODE_GRADIENT_LINEAR) {
SP_GRADIENT_SELECTOR(gsel)->setMode(SPGradientSelector::MODE_RADIAL);
gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>Radial gradient</b>"));
}
#ifdef WITH_MESH
else {
SP_GRADIENT_SELECTOR(gsel)->setMode(SPGradientSelector::MODE_MESH);
gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>Mesh gradient</b>"));
}
#endif
#ifdef SP_PS_VERBOSE
g_print("Gradient req\n");
#endif
}
static void
sp_paint_selector_set_style_buttons(SPPaintSelector *psel, GtkWidget *active)
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->none), (active == psel->none));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->solid), (active == psel->solid));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->gradient), (active == psel->gradient));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->radial), (active == psel->radial));
#ifdef WITH_MESH
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->mesh), (active == psel->mesh));
#endif
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->pattern), (active == psel->pattern));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->swatch), (active == psel->swatch));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->unset), (active == psel->unset));
}
static void sp_psel_pattern_destroy(GtkWidget *widget, SPPaintSelector * /*psel*/)
{
// drop our reference to the pattern menu widget
g_object_unref( G_OBJECT(widget) );
}
static void sp_psel_pattern_change(GtkWidget * /*widget*/, SPPaintSelector *psel)
{
g_signal_emit(G_OBJECT(psel), psel_signals[CHANGED], 0);
}
/**
* Returns a list of patterns in the defs of the given source document as a GSList object
* Returns NULL if there are no patterns in the document.
*/
static GSList *
ink_pattern_list_get (SPDocument *source)
{
if (source == NULL)
return NULL;
GSList *pl = NULL;
GSList const *patterns = source->getResourceList("pattern");
for (GSList *l = const_cast<GSList *>(patterns); l != NULL; l = l->next) {
if (SP_PATTERN(l->data) == SP_PATTERN(l->data)->rootPattern()) { // only if this is a root pattern
pl = g_slist_prepend(pl, l->data);
}
}
pl = g_slist_reverse(pl);
return pl;
}
/**
* Adds menu items for pattern list - derived from marker code, left hb etc in to make addition of previews easier at some point.
*/
static void
sp_pattern_menu_build (GtkWidget *combo, GSList *pattern_list, SPDocument */*source*/)
{
GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo)));
GtkTreeIter iter;
for (; pattern_list != NULL; pattern_list = pattern_list->next) {
Inkscape::XML::Node *repr = reinterpret_cast<SPItem *>(pattern_list->data)->getRepr();
// label for combobox
gchar const *label;
if (repr->attribute("inkscape:stockid")) {
label = _(repr->attribute("inkscape:stockid"));
} else {
label = _(repr->attribute("id"));
}
gchar const *patid = repr->attribute("id");
gboolean stockid = false;
if (repr->attribute("inkscape:stockid")) {
stockid = true;
}
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
COMBO_COL_LABEL, label, COMBO_COL_STOCK, stockid, COMBO_COL_PATTERN, patid, COMBO_COL_SEP, FALSE, -1);
}
}
/**
* Pick up all patterns from source, except those that are in
* current_doc (if non-NULL), and add items to the pattern menu.
*/
static void sp_pattern_list_from_doc(GtkWidget *combo, SPDocument * /*current_doc*/, SPDocument *source, SPDocument * /*pattern_doc*/)
{
GSList *pl = ink_pattern_list_get(source);
GSList *clean_pl = NULL;
for (; pl != NULL; pl = pl->next) {
if (!SP_IS_PATTERN(pl->data)) {
continue;
}
// Add to the list of patterns we really do wish to show
clean_pl = g_slist_prepend (clean_pl, pl->data);
}
sp_pattern_menu_build (combo, clean_pl, source);
g_slist_free (pl);
g_slist_free (clean_pl);
}
static void
ink_pattern_menu_populate_menu(GtkWidget *combo, SPDocument *doc)
{
static SPDocument *patterns_doc = NULL;
// find and load patterns.svg
if (patterns_doc == NULL) {
char *patterns_source = g_build_filename(INKSCAPE_PATTERNSDIR, "patterns.svg", NULL);
if (Inkscape::IO::file_test(patterns_source, G_FILE_TEST_IS_REGULAR)) {
patterns_doc = SPDocument::createNewDoc(patterns_source, FALSE);
}
g_free(patterns_source);
}
// suck in from current doc
sp_pattern_list_from_doc ( combo, NULL, doc, patterns_doc );
// add separator
{
GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo)));
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set(store, &iter,
COMBO_COL_LABEL, "", COMBO_COL_STOCK, false, COMBO_COL_PATTERN, "", COMBO_COL_SEP, true, -1);
}
// suck in from patterns.svg
if (patterns_doc) {
doc->ensureUpToDate();
sp_pattern_list_from_doc ( combo, doc, patterns_doc, NULL );
}
}
static GtkWidget*
ink_pattern_menu(GtkWidget *combo)
{
SPDocument *doc = SP_ACTIVE_DOCUMENT;
GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo)));
GtkTreeIter iter;
if (!doc) {
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COMBO_COL_LABEL, _("No document selected"), COMBO_COL_STOCK, false, COMBO_COL_PATTERN, "", COMBO_COL_SEP, false, -1);
gtk_widget_set_sensitive(combo, FALSE);
} else {
ink_pattern_menu_populate_menu(combo, doc);
gtk_widget_set_sensitive(combo, TRUE);
}
// Select the first item that is not a seperator
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter)) {
gboolean sep = false;
gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, COMBO_COL_SEP, &sep, -1);
if (sep) {
gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
}
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter);
}
return combo;
}
/*update pattern list*/
void SPPaintSelector::updatePatternList( SPPattern *pattern )
{
if (update) {
return;
}
GtkWidget *combo = GTK_WIDGET(g_object_get_data(G_OBJECT(this), "patternmenu"));
g_assert( combo != NULL );
/* Clear existing menu if any */
GtkTreeModel *store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
gtk_list_store_clear(GTK_LIST_STORE(store));
ink_pattern_menu(combo);
/* Set history */
if (pattern && !g_object_get_data(G_OBJECT(combo), "update")) {
g_object_set_data(G_OBJECT(combo), "update", GINT_TO_POINTER(TRUE));
gchar const *patname = pattern->getRepr()->attribute("id");
// Find this pattern and set it active in the combo_box
GtkTreeIter iter ;
gchar *patid = NULL;
bool valid = gtk_tree_model_get_iter_first (store, &iter);
if (!valid) {
return;
}
gtk_tree_model_get (store, &iter, COMBO_COL_PATTERN, &patid, -1);
while (valid && strcmp(patid, patname) != 0) {
valid = gtk_tree_model_iter_next (store, &iter);
gtk_tree_model_get (store, &iter, COMBO_COL_PATTERN, &patid, -1);
}
if (valid) {
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter);
}
g_object_set_data(G_OBJECT(combo), "update", GINT_TO_POINTER(FALSE));
}
}
static void sp_paint_selector_set_mode_pattern(SPPaintSelector *psel, SPPaintSelector::Mode mode)
{
if (mode == SPPaintSelector::MODE_PATTERN) {
sp_paint_selector_set_style_buttons(psel, psel->pattern);
}
gtk_widget_set_sensitive(psel->style, TRUE);
GtkWidget *tbl = NULL;
if (psel->mode == SPPaintSelector::MODE_PATTERN) {
/* Already have pattern menu */
tbl = GTK_WIDGET(g_object_get_data(G_OBJECT(psel->selector), "pattern-selector"));
} else {
sp_paint_selector_clear_frame(psel);
/* Create vbox */
#if GTK_CHECK_VERSION(3,0,0)
tbl = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
gtk_box_set_homogeneous(GTK_BOX(tbl), FALSE);
#else
tbl = gtk_vbox_new(FALSE, 4);
#endif
gtk_widget_show(tbl);
{
#if GTK_CHECK_VERSION(3,0,0)
GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
gtk_box_set_homogeneous(GTK_BOX(hb), FALSE);
#else
GtkWidget *hb = gtk_hbox_new(FALSE, 1);
#endif
/**
* Create a combo_box and store with 4 columns,
* The label, a pointer to the pattern, is stockid or not, is a separator or not.
*/
GtkListStore *store = gtk_list_store_new (COMBO_N_COLS, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_BOOLEAN);
GtkWidget *combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(combo), SPPaintSelector::isSeparator, NULL, NULL);
GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
gtk_cell_renderer_set_padding (renderer, 2, 0);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, "text", COMBO_COL_LABEL, NULL);
ink_pattern_menu(combo);
g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(sp_psel_pattern_change), psel);
g_signal_connect(G_OBJECT(combo), "destroy", G_CALLBACK(sp_psel_pattern_destroy), psel);
g_object_set_data(G_OBJECT(psel), "patternmenu", combo);
g_object_ref( G_OBJECT(combo));
gtk_container_add(GTK_CONTAINER(hb), combo);
gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, AUX_BETWEEN_BUTTON_GROUPS);
g_object_unref( G_OBJECT(store));
}
{
#if GTK_CHECK_VERSION(3,0,0)
GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_set_homogeneous(GTK_BOX(hb), FALSE);
#else
GtkWidget *hb = gtk_hbox_new(FALSE, 0);
#endif
GtkWidget *l = gtk_label_new(NULL);
gtk_label_set_markup(GTK_LABEL(l), _("Use the <b>Node tool</b> to adjust position, scale, and rotation of the pattern on canvas. Use <b>Object &gt; Pattern &gt; Objects to Pattern</b> to create a new pattern from selection."));
gtk_label_set_line_wrap(GTK_LABEL(l), true);
gtk_widget_set_size_request(l, 180, -1);
gtk_box_pack_start(GTK_BOX(hb), l, TRUE, TRUE, AUX_BETWEEN_BUTTON_GROUPS);
gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, AUX_BETWEEN_BUTTON_GROUPS);
}
gtk_widget_show_all(tbl);
gtk_container_add(GTK_CONTAINER(psel->frame), tbl);
psel->selector = tbl;
g_object_set_data(G_OBJECT(psel->selector), "pattern-selector", tbl);
gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>Pattern fill</b>"));
}
#ifdef SP_PS_VERBOSE
g_print("Pattern req\n");
#endif
}
gboolean SPPaintSelector::isSeparator (GtkTreeModel *model, GtkTreeIter *iter, gpointer /*data*/) {
gboolean sep = FALSE;
gtk_tree_model_get(model, iter, COMBO_COL_SEP, &sep, -1);
return sep;
}
SPPattern *SPPaintSelector::getPattern()
{
SPPattern *pat = 0;
g_return_val_if_fail((mode == MODE_PATTERN) , NULL);
GtkWidget *combo = GTK_WIDGET(g_object_get_data(G_OBJECT(this), "patternmenu"));
/* no pattern menu if we were just selected */
if ( combo == NULL ) {
return NULL;
}
GtkTreeModel *store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
/* Get the selected pattern */
GtkTreeIter iter;
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX(combo), &iter) ||
!gtk_list_store_iter_is_valid(GTK_LIST_STORE(store), &iter)) {
return NULL;
}
gchar *patid = NULL;
gboolean stockid = FALSE;
gchar *label = NULL;
gtk_tree_model_get (store, &iter, COMBO_COL_LABEL, &label, COMBO_COL_STOCK, &stockid, COMBO_COL_PATTERN, &patid, -1);
if (patid == NULL) {
return NULL;
}
if (strcmp(patid, "none")){
gchar *paturn;
if (stockid) {
paturn = g_strconcat("urn:inkscape:pattern:",patid,NULL);
}
else {
paturn = g_strdup(patid);
}
SPObject *pat_obj = get_stock_item(paturn);
if (pat_obj) {
pat = SP_PATTERN(pat_obj);
}
g_free(paturn);
} else {
pat = SP_PATTERN(patid)->rootPattern();
}
if (pat && !SP_IS_PATTERN(pat)) {
pat = 0;
}
return pat;
}
static void sp_paint_selector_set_mode_swatch(SPPaintSelector *psel, SPPaintSelector::Mode mode)
{
if (mode == SPPaintSelector::MODE_SWATCH) {
sp_paint_selector_set_style_buttons(psel, psel->swatch);
}
gtk_widget_set_sensitive(psel->style, TRUE);
if (psel->mode == SPPaintSelector::MODE_SWATCH){
// swatchsel = static_cast<SwatchSelector*>(g_object_get_data(G_OBJECT(psel->selector), "swatch-selector"));
} else {
sp_paint_selector_clear_frame(psel);
// Create new gradient selector
SwatchSelector *swatchsel = new SwatchSelector();
swatchsel->show();
swatchsel->connectGrabbedHandler( G_CALLBACK(sp_paint_selector_gradient_grabbed), psel );
swatchsel->connectDraggedHandler( G_CALLBACK(sp_paint_selector_gradient_dragged), psel );
swatchsel->connectReleasedHandler( G_CALLBACK(sp_paint_selector_gradient_released), psel );
swatchsel->connectchangedHandler( G_CALLBACK(sp_paint_selector_gradient_changed), psel );
// Pack everything to frame
gtk_container_add(GTK_CONTAINER(psel->frame), GTK_WIDGET(swatchsel->gobj()));
psel->selector = GTK_WIDGET(swatchsel->gobj());
g_object_set_data(G_OBJECT(psel->selector), "swatch-selector", swatchsel);
gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>Swatch fill</b>"));
}
#ifdef SP_PS_VERBOSE
g_print("Swatch req\n");
#endif
}
// TODO this seems very bad to be taking in a desktop pointer to muck with. Logic probably belongs elsewhere
void SPPaintSelector::setFlatColor( SPDesktop *desktop, gchar const *color_property, gchar const *opacity_property )
{
SPCSSAttr *css = sp_repr_css_attr_new();
SPColor color;
gfloat alpha = 0;
getColorAlpha( color, alpha );
std::string colorStr = color.toString();
#ifdef SP_PS_VERBOSE
guint32 rgba = color.toRGBA32( alpha );
g_message("sp_paint_selector_set_flat_color() to '%s' from 0x%08x::%s",
colorStr.c_str(),
rgba,
(color.icc ? color.icc->colorProfile.c_str():"<null>") );
#endif // SP_PS_VERBOSE
sp_repr_css_set_property(css, color_property, colorStr.c_str());
Inkscape::CSSOStringStream osalpha;
osalpha << alpha;
sp_repr_css_set_property(css, opacity_property, osalpha.str().c_str());
sp_desktop_set_style(desktop, css);
sp_repr_css_attr_unref(css);
}
SPPaintSelector::Mode SPPaintSelector::getModeForStyle(SPStyle const & style, FillOrStroke kind)
{
Mode mode = MODE_UNSET;
SPIPaint const & target = (kind == FILL) ? style.fill : style.stroke;
if ( !target.set ) {
mode = MODE_UNSET;
} else if ( target.isPaintserver() ) {
SPPaintServer const *server = (kind == FILL) ? style.getFillPaintServer() : style.getStrokePaintServer();
#ifdef SP_PS_VERBOSE
g_message("SPPaintSelector::getModeForStyle(%p, %d)", &style, kind);
g_message("==== server:%p %s grad:%s swatch:%s", server, server->getId(), (SP_IS_GRADIENT(server)?"Y":"n"), (SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()?"Y":"n"));
#endif // SP_PS_VERBOSE
if (server && SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()) {
mode = MODE_SWATCH;
} else if (SP_IS_LINEARGRADIENT(server)) {
mode = MODE_GRADIENT_LINEAR;
} else if (SP_IS_RADIALGRADIENT(server)) {
mode = MODE_GRADIENT_RADIAL;
#ifdef WITH_MESH
} else if (SP_IS_MESH(server)) {
mode = MODE_GRADIENT_MESH;
#endif
} else if (SP_IS_PATTERN(server)) {
mode = MODE_PATTERN;
} else {
g_warning( "file %s: line %d: Unknown paintserver", __FILE__, __LINE__ );
mode = MODE_NONE;
}
} else if ( target.isColor() ) {
// TODO this is no longer a valid assertion:
mode = MODE_SOLID_COLOR; // so far only rgb can be read from svg
} else if ( target.isNone() ) {
mode = MODE_NONE;
} else {
g_warning( "file %s: line %d: Unknown paint type", __FILE__, __LINE__ );
mode = MODE_NONE;
}
return mode;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :