paint-selector.cpp revision e3b6cd4b0523f08a6414dc0800a15a3b1710ce8a
3935N/A#define __SP_PAINT_SELECTOR_C__
3935N/A
3935N/A/** \file
3935N/A * SPPaintSelector: Generic paint selector widget.
3935N/A */
3935N/A
3935N/A/*
3935N/A * Copyright (C) Lauris Kaplinski 2002
3935N/A * bulia byak <buliabyak@users.sf.net>
3935N/A * John Cliff <simarilius@yahoo.com>
3935N/A*/
3935N/A
3935N/A#define noSP_PS_VERBOSE
3935N/A
3935N/A#ifdef HAVE_CONFIG_H
3935N/A# include "config.h"
3935N/A#endif
3935N/A
3935N/A#include <cstring>
3935N/A#include <string>
3935N/A
3935N/A#include <gtk/gtkhbox.h>
3935N/A#include <gtk/gtkradiobutton.h>
3935N/A#include <gtk/gtkframe.h>
3935N/A#include <gtk/gtklabel.h>
3935N/A#include <gtk/gtkoptionmenu.h>
3935N/A#include <gtk/gtktooltips.h>
3935N/A#include <gtk/gtkmenuitem.h>
3935N/A#include <gtk/gtkseparatormenuitem.h>
3935N/A
3935N/A#include "../sp-pattern.h"
3935N/A#include <glibmm/i18n.h>
3935N/A#include "../widgets/icon.h"
3935N/A#include "../inkscape-stock.h"
3935N/A#include "widgets/widget-sizes.h"
3935N/A#include "xml/repr.h"
3935N/A
3935N/A#include "sp-color-notebook.h"
3935N/A#include "sp-linear-gradient-fns.h"
3935N/A#include "sp-radial-gradient-fns.h"
3935N/A/* fixme: Move it from dialogs to here */
3935N/A#include "gradient-selector.h"
3935N/A#include <inkscape.h>
3935N/A#include <document-private.h>
3935N/A#include <desktop-style.h>
3935N/A#include <style.h>
3935N/A#include "svg/svg-color.h"
3935N/A#include "svg/css-ostringstream.h"
3935N/A#include "path-prefix.h"
3935N/A#include "io/sys.h"
3935N/A#include "helper/stock-items.h"
3935N/A
3935N/A#include "paint-selector.h"
3935N/A
3935N/A#ifdef SP_PS_VERBOSE
3935N/A#include "svg/svg-icc-color.h"
3935N/A#endif // SP_PS_VERBOSE
3935N/A
3935N/Aenum {
3935N/A MODE_CHANGED,
3935N/A GRABBED,
3935N/A DRAGGED,
3935N/A RELEASED,
3935N/A CHANGED,
3935N/A FILLRULE_CHANGED,
5294N/A LAST_SIGNAL
5294N/A};
5294N/A
5294N/Astatic void sp_paint_selector_class_init(SPPaintSelectorClass *klass);
3935N/Astatic void sp_paint_selector_init(SPPaintSelector *slider);
3935N/Astatic void sp_paint_selector_destroy(GtkObject *object);
3935N/A
3935N/Astatic GtkWidget *sp_paint_selector_style_button_add(SPPaintSelector *psel, gchar const *px, SPPaintSelectorMode mode, GtkTooltips *tt, gchar const *tip);
3935N/Astatic void sp_paint_selector_style_button_toggled(GtkToggleButton *tb, SPPaintSelector *psel);
3935N/Astatic void sp_paint_selector_fillrule_toggled(GtkToggleButton *tb, SPPaintSelector *psel);
3935N/A
3935N/Astatic void sp_paint_selector_set_mode_empty(SPPaintSelector *psel);
3935N/Astatic void sp_paint_selector_set_mode_multiple(SPPaintSelector *psel);
3935N/Astatic void sp_paint_selector_set_mode_none(SPPaintSelector *psel);
3935N/Astatic void sp_paint_selector_set_mode_color(SPPaintSelector *psel, SPPaintSelectorMode mode);
3935N/Astatic void sp_paint_selector_set_mode_gradient(SPPaintSelector *psel, SPPaintSelectorMode mode);
3935N/Astatic void sp_paint_selector_set_mode_pattern(SPPaintSelector *psel, SPPaintSelectorMode mode);
3935N/Astatic void sp_paint_selector_set_mode_unset(SPPaintSelector *psel);
3935N/A
3935N/A
3935N/Astatic void sp_paint_selector_set_style_buttons(SPPaintSelector *psel, GtkWidget *active);
3935N/A
3935N/Astatic GtkVBoxClass *parent_class;
3935N/Astatic guint psel_signals[LAST_SIGNAL] = {0};
3935N/A
3935N/AGType sp_paint_selector_get_type(void)
3935N/A{
3935N/A static GtkType type = 0;
3935N/A if (!type) {
3935N/A GTypeInfo info = {
3935N/A sizeof(SPPaintSelectorClass),
3935N/A 0, // base_init
3935N/A 0, // base_finalize
3935N/A (GClassInitFunc)sp_paint_selector_class_init,
3935N/A 0, // class_finalize
3935N/A 0, // class_data
3935N/A sizeof(SPPaintSelector),
3935N/A 0, // n_preallocs
3935N/A (GInstanceInitFunc)sp_paint_selector_init,
3935N/A 0 // value_table
3935N/A };
3935N/A type = g_type_register_static(GTK_TYPE_VBOX, "SPPaintSelector", &info, static_cast<GTypeFlags>(0));
3935N/A }
3935N/A return type;
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_class_init(SPPaintSelectorClass *klass)
3935N/A{
3935N/A GtkObjectClass *object_class;
3935N/A GtkWidgetClass *widget_class;
3935N/A
3935N/A object_class = (GtkObjectClass *) klass;
3935N/A widget_class = (GtkWidgetClass *) klass;
3935N/A
3935N/A parent_class = (GtkVBoxClass*)gtk_type_class(GTK_TYPE_VBOX);
3935N/A
3935N/A psel_signals[MODE_CHANGED] = gtk_signal_new("mode_changed",
3935N/A (GtkSignalRunType)(GTK_RUN_FIRST | GTK_RUN_NO_RECURSE),
3935N/A GTK_CLASS_TYPE(object_class),
3935N/A GTK_SIGNAL_OFFSET(SPPaintSelectorClass, mode_changed),
3935N/A gtk_marshal_NONE__UINT,
3935N/A GTK_TYPE_NONE, 1, GTK_TYPE_UINT);
3935N/A psel_signals[GRABBED] = gtk_signal_new("grabbed",
3935N/A (GtkSignalRunType)(GTK_RUN_FIRST | GTK_RUN_NO_RECURSE),
3935N/A GTK_CLASS_TYPE(object_class),
3935N/A GTK_SIGNAL_OFFSET(SPPaintSelectorClass, grabbed),
3935N/A gtk_marshal_NONE__NONE,
3935N/A GTK_TYPE_NONE, 0);
3935N/A psel_signals[DRAGGED] = gtk_signal_new("dragged",
3935N/A (GtkSignalRunType)(GTK_RUN_FIRST | GTK_RUN_NO_RECURSE),
3935N/A GTK_CLASS_TYPE(object_class),
3935N/A GTK_SIGNAL_OFFSET(SPPaintSelectorClass, dragged),
3935N/A gtk_marshal_NONE__NONE,
3935N/A GTK_TYPE_NONE, 0);
3935N/A psel_signals[RELEASED] = gtk_signal_new("released",
3935N/A (GtkSignalRunType)(GTK_RUN_FIRST | GTK_RUN_NO_RECURSE),
3935N/A GTK_CLASS_TYPE(object_class),
3935N/A GTK_SIGNAL_OFFSET(SPPaintSelectorClass, released),
3935N/A gtk_marshal_NONE__NONE,
3935N/A GTK_TYPE_NONE, 0);
3935N/A psel_signals[CHANGED] = gtk_signal_new("changed",
3935N/A (GtkSignalRunType)(GTK_RUN_FIRST | GTK_RUN_NO_RECURSE),
3935N/A GTK_CLASS_TYPE(object_class),
3935N/A GTK_SIGNAL_OFFSET(SPPaintSelectorClass, changed),
3935N/A gtk_marshal_NONE__NONE,
3935N/A GTK_TYPE_NONE, 0);
3935N/A psel_signals[FILLRULE_CHANGED] = gtk_signal_new("fillrule_changed",
3935N/A (GtkSignalRunType)(GTK_RUN_FIRST | GTK_RUN_NO_RECURSE),
3935N/A GTK_CLASS_TYPE(object_class),
3935N/A GTK_SIGNAL_OFFSET(SPPaintSelectorClass, fillrule_changed),
3935N/A gtk_marshal_NONE__UINT,
3935N/A GTK_TYPE_NONE, 1, GTK_TYPE_UINT);
3935N/A
3935N/A object_class->destroy = sp_paint_selector_destroy;
3935N/A}
3935N/A
3935N/A#define XPAD 4
3935N/A#define YPAD 1
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_init(SPPaintSelector *psel)
3935N/A{
3935N/A GtkTooltips *tt = gtk_tooltips_new();
3935N/A
3935N/A psel->mode = (SPPaintSelectorMode)-1; // huh? do you mean 0xff? -- I think this means "not in the enum"
3935N/A
3935N/A /* Paint style button box */
3935N/A psel->style = gtk_hbox_new(FALSE, 0);
3935N/A gtk_widget_show(psel->style);
3935N/A gtk_container_set_border_width(GTK_CONTAINER(psel->style), 4);
3935N/A gtk_box_pack_start(GTK_BOX(psel), psel->style, FALSE, FALSE, 0);
3935N/A
3935N/A /* Buttons */
3935N/A psel->none = sp_paint_selector_style_button_add(psel, INKSCAPE_STOCK_FILL_NONE,
3935N/A SP_PAINT_SELECTOR_MODE_NONE, tt, _("No paint"));
5294N/A psel->solid = sp_paint_selector_style_button_add(psel, INKSCAPE_STOCK_FILL_SOLID,
5294N/A SP_PAINT_SELECTOR_MODE_COLOR_RGB, tt, _("Flat color"));
3935N/A psel->gradient = sp_paint_selector_style_button_add(psel, INKSCAPE_STOCK_FILL_GRADIENT,
3935N/A SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR, tt, _("Linear gradient"));
3935N/A psel->radial = sp_paint_selector_style_button_add(psel, INKSCAPE_STOCK_FILL_RADIAL,
3935N/A SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL, tt, _("Radial gradient"));
5294N/A psel->pattern = sp_paint_selector_style_button_add(psel, INKSCAPE_STOCK_FILL_PATTERN,
5294N/A SP_PAINT_SELECTOR_MODE_PATTERN, tt, _("Pattern"));
3935N/A psel->unset = sp_paint_selector_style_button_add(psel, INKSCAPE_STOCK_FILL_UNSET,
3935N/A SP_PAINT_SELECTOR_MODE_UNSET, tt, _("Unset paint (make it undefined so it can be inherited)"));
3935N/A
3935N/A /* Fillrule */
3935N/A {
3935N/A psel->fillrulebox = gtk_hbox_new(FALSE, 0);
3935N/A gtk_box_pack_end(GTK_BOX(psel->style), psel->fillrulebox, FALSE, FALSE, 0);
3935N/A
3935N/A GtkWidget *w;
3935N/A psel->evenodd = gtk_radio_button_new(NULL);
3935N/A gtk_button_set_relief(GTK_BUTTON(psel->evenodd), GTK_RELIEF_NONE);
3935N/A gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(psel->evenodd), FALSE);
3935N/A // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/painting.html#FillRuleProperty
3935N/A gtk_tooltips_set_tip(tt, psel->evenodd, _("Any path self-intersections or subpaths create holes in the fill (fill-rule: evenodd)"), NULL);
3935N/A gtk_object_set_data(GTK_OBJECT(psel->evenodd), "mode", GUINT_TO_POINTER(SP_PAINT_SELECTOR_FILLRULE_EVENODD));
3935N/A w = sp_icon_new(Inkscape::ICON_SIZE_DECORATION, "fillrule_evenodd");
3935N/A gtk_container_add(GTK_CONTAINER(psel->evenodd), w);
3935N/A gtk_box_pack_start(GTK_BOX(psel->fillrulebox), psel->evenodd, FALSE, FALSE, 0);
3935N/A gtk_signal_connect(GTK_OBJECT(psel->evenodd), "toggled", GTK_SIGNAL_FUNC(sp_paint_selector_fillrule_toggled), psel);
3935N/A
3935N/A psel->nonzero = gtk_radio_button_new(gtk_radio_button_group(GTK_RADIO_BUTTON(psel->evenodd)));
3935N/A gtk_button_set_relief(GTK_BUTTON(psel->nonzero), GTK_RELIEF_NONE);
3935N/A gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(psel->nonzero), FALSE);
3935N/A // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/painting.html#FillRuleProperty
3935N/A gtk_tooltips_set_tip(tt, psel->nonzero, _("Fill is solid unless a subpath is counterdirectional (fill-rule: nonzero)"), NULL);
3935N/A gtk_object_set_data(GTK_OBJECT(psel->nonzero), "mode", GUINT_TO_POINTER(SP_PAINT_SELECTOR_FILLRULE_NONZERO));
3935N/A w = sp_icon_new(Inkscape::ICON_SIZE_DECORATION, "fillrule_nonzero");
3935N/A gtk_container_add(GTK_CONTAINER(psel->nonzero), w);
3935N/A gtk_box_pack_start(GTK_BOX(psel->fillrulebox), psel->nonzero, FALSE, FALSE, 0);
3935N/A gtk_signal_connect(GTK_OBJECT(psel->nonzero), "toggled", GTK_SIGNAL_FUNC(sp_paint_selector_fillrule_toggled), psel);
3935N/A }
3935N/A
3935N/A /* Frame */
3935N/A psel->frame = gtk_frame_new("");
3935N/A gtk_widget_show(psel->frame);
3935N/A gtk_container_set_border_width(GTK_CONTAINER(psel->frame), 0);
3935N/A gtk_box_pack_start(GTK_BOX(psel), psel->frame, TRUE, TRUE, 0);
3935N/A
3935N/A /* Last used color */
3935N/A psel->color.set( 0.0, 0.0, 0.0 );
3935N/A psel->alpha = 1.0;
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_destroy(GtkObject *object)
3935N/A{
3935N/A SPPaintSelector *psel = SP_PAINT_SELECTOR(object);
3935N/A
3935N/A // clean up our long-living pattern menu
3935N/A g_object_set_data(G_OBJECT(psel),"patternmenu",NULL);
3935N/A
3935N/A if (((GtkObjectClass *) parent_class)->destroy)
3935N/A (* ((GtkObjectClass *) parent_class)->destroy)(object);
3935N/A}
3935N/A
3935N/Astatic GtkWidget *
3935N/Asp_paint_selector_style_button_add(SPPaintSelector *psel,
3935N/A gchar const *pixmap, SPPaintSelectorMode mode,
3935N/A GtkTooltips *tt, gchar const *tip)
3935N/A{
3935N/A GtkWidget *b, *w;
3935N/A
3935N/A b = gtk_toggle_button_new();
3935N/A gtk_tooltips_set_tip(tt, b, tip, NULL);
3935N/A gtk_widget_show(b);
3935N/A
3935N/A gtk_container_set_border_width(GTK_CONTAINER(b), 0);
3935N/A
3935N/A gtk_button_set_relief(GTK_BUTTON(b), GTK_RELIEF_NONE);
3935N/A
3935N/A gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(b), FALSE);
3935N/A gtk_object_set_data(GTK_OBJECT(b), "mode", GUINT_TO_POINTER(mode));
3935N/A
3935N/A w = sp_icon_new(Inkscape::ICON_SIZE_BUTTON, pixmap);
3935N/A gtk_widget_show(w);
3935N/A gtk_container_add(GTK_CONTAINER(b), w);
3935N/A
3935N/A gtk_box_pack_start(GTK_BOX(psel->style), b, FALSE, FALSE, 0);
3935N/A gtk_signal_connect(GTK_OBJECT(b), "toggled", GTK_SIGNAL_FUNC(sp_paint_selector_style_button_toggled), psel);
3935N/A
3935N/A return b;
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_style_button_toggled(GtkToggleButton *tb, SPPaintSelector *psel)
3935N/A{
3935N/A if (!psel->update && gtk_toggle_button_get_active(tb)) {
3935N/A sp_paint_selector_set_mode(psel, (SPPaintSelectorMode)GPOINTER_TO_UINT(gtk_object_get_data(GTK_OBJECT(tb), "mode")));
3935N/A }
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_fillrule_toggled(GtkToggleButton *tb, SPPaintSelector *psel)
3935N/A{
3935N/A if (!psel->update && gtk_toggle_button_get_active(tb)) {
3935N/A SPPaintSelectorFillRule fr = (SPPaintSelectorFillRule)GPOINTER_TO_UINT(gtk_object_get_data(GTK_OBJECT(tb), "mode"));
3935N/A gtk_signal_emit(GTK_OBJECT(psel), psel_signals[FILLRULE_CHANGED], fr);
3935N/A }
3935N/A}
3935N/A
3935N/Avoid
3935N/Asp_paint_selector_show_fillrule(SPPaintSelector *psel, bool is_fill)
3935N/A{
3935N/A if (psel->fillrulebox) {
3935N/A if (is_fill) {
3935N/A gtk_widget_show_all(psel->fillrulebox);
3935N/A } else {
3935N/A gtk_widget_destroy(psel->fillrulebox);
3935N/A psel->fillrulebox = NULL;
3935N/A }
3935N/A }
3935N/A}
3935N/A
3935N/A
3935N/AGtkWidget *
3935N/Asp_paint_selector_new(bool is_fill)
3935N/A{
3935N/A SPPaintSelector *psel;
3935N/A
3935N/A psel = (SPPaintSelector*)gtk_type_new(SP_TYPE_PAINT_SELECTOR);
3935N/A
3935N/A sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_MULTIPLE);
3935N/A
3935N/A // This silliness is here because I don't know how to pass a parameter to the
5294N/A // GtkObject "constructor" (sp_paint_selector_init). Remove it when paint_selector
3935N/A // becomes a normal class.
3935N/A sp_paint_selector_show_fillrule(psel, is_fill);
3935N/A
3935N/A return GTK_WIDGET(psel);
3935N/A}
3935N/A
3935N/Avoid
3935N/Asp_paint_selector_set_mode(SPPaintSelector *psel, SPPaintSelectorMode mode)
3935N/A{
3935N/A if (psel->mode != mode) {
3935N/A psel->update = TRUE;
3935N/A#ifdef SP_PS_VERBOSE
3935N/A g_print("Mode change %d -> %d\n", psel->mode, mode);
5294N/A#endif
3935N/A switch (mode) {
3935N/A case SP_PAINT_SELECTOR_MODE_EMPTY:
3935N/A sp_paint_selector_set_mode_empty(psel);
3935N/A break;
3935N/A case SP_PAINT_SELECTOR_MODE_MULTIPLE:
5294N/A sp_paint_selector_set_mode_multiple(psel);
3935N/A break;
3935N/A case SP_PAINT_SELECTOR_MODE_NONE:
3935N/A sp_paint_selector_set_mode_none(psel);
3935N/A break;
3935N/A case SP_PAINT_SELECTOR_MODE_COLOR_RGB:
3935N/A case SP_PAINT_SELECTOR_MODE_COLOR_CMYK:
3935N/A sp_paint_selector_set_mode_color(psel, mode);
5294N/A break;
3935N/A case SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR:
3935N/A case SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL:
5294N/A sp_paint_selector_set_mode_gradient(psel, mode);
3935N/A break;
3935N/A case SP_PAINT_SELECTOR_MODE_PATTERN:
3935N/A sp_paint_selector_set_mode_pattern(psel, mode);
3935N/A break;
3935N/A case SP_PAINT_SELECTOR_MODE_UNSET:
3935N/A sp_paint_selector_set_mode_unset(psel);
3935N/A break;
3935N/A default:
3935N/A g_warning("file %s: line %d: Unknown paint mode %d", __FILE__, __LINE__, mode);
3935N/A break;
3935N/A }
3935N/A psel->mode = mode;
3935N/A gtk_signal_emit(GTK_OBJECT(psel), psel_signals[MODE_CHANGED], psel->mode);
3935N/A psel->update = FALSE;
3935N/A }
3935N/A}
3935N/A
3935N/Avoid
3935N/Asp_paint_selector_set_fillrule(SPPaintSelector *psel, SPPaintSelectorFillRule fillrule)
3935N/A{
3935N/A if (psel->fillrulebox) {
3935N/A gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->evenodd), (fillrule == SP_PAINT_SELECTOR_FILLRULE_EVENODD));
3935N/A gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->nonzero), (fillrule == SP_PAINT_SELECTOR_FILLRULE_NONZERO));
3935N/A }
3935N/A}
3935N/A
3935N/Avoid
3935N/Asp_paint_selector_set_color_alpha(SPPaintSelector *psel, SPColor const *color, float alpha)
3935N/A{
3935N/A g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) );
3935N/A SPColorSelector *csel;
3935N/A guint32 rgba;
3935N/A
3935N/A/*
3935N/A if ( sp_color_get_colorspace_type(color) == SP_COLORSPACE_TYPE_CMYK )
3935N/A {
3935N/A#ifdef SP_PS_VERBOSE
3935N/A g_print("PaintSelector set CMYKA\n");
3935N/A#endif
3935N/A sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_COLOR_CMYK);
3935N/A }
3935N/A else
3935N/A*/
3935N/A {
3935N/A#ifdef SP_PS_VERBOSE
3935N/A g_print("PaintSelector set RGBA\n");
3935N/A#endif
3935N/A sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_COLOR_RGB);
3935N/A }
3935N/A
3935N/A csel = (SPColorSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "color-selector");
3935N/A rgba = color->toRGBA32( alpha );
3935N/A csel->base->setColorAlpha( *color, alpha );
3935N/A}
3935N/A
3935N/Avoid
3935N/Asp_paint_selector_set_gradient_linear(SPPaintSelector *psel, SPGradient *vector)
3935N/A{
3935N/A SPGradientSelector *gsel;
3935N/A#ifdef SP_PS_VERBOSE
3935N/A g_print("PaintSelector set GRADIENT LINEAR\n");
3935N/A#endif
3935N/A sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR);
3935N/A
3935N/A gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector");
3935N/A
3935N/A sp_gradient_selector_set_mode(gsel, SP_GRADIENT_SELECTOR_MODE_LINEAR);
3935N/A sp_gradient_selector_set_vector(gsel, (vector) ? SP_OBJECT_DOCUMENT(vector) : NULL, vector);
3935N/A}
3935N/A
3935N/Avoid
3935N/Asp_paint_selector_set_gradient_radial(SPPaintSelector *psel, SPGradient *vector)
3935N/A{
3935N/A SPGradientSelector *gsel;
3935N/A#ifdef SP_PS_VERBOSE
3935N/A g_print("PaintSelector set GRADIENT RADIAL\n");
3935N/A#endif
3935N/A sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL);
3935N/A
3935N/A gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector");
3935N/A
3935N/A sp_gradient_selector_set_mode(gsel, SP_GRADIENT_SELECTOR_MODE_RADIAL);
3935N/A sp_gradient_selector_set_vector(gsel, (vector) ? SP_OBJECT_DOCUMENT(vector) : NULL, vector);
3935N/A}
3935N/A
3935N/Avoid
3935N/Asp_paint_selector_set_gradient_properties(SPPaintSelector *psel, SPGradientUnits units, SPGradientSpread spread)
3935N/A{
3935N/A SPGradientSelector *gsel;
3935N/A g_return_if_fail(SP_IS_PAINT_SELECTOR(psel));
3935N/A g_return_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) ||
3935N/A (psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL));
3935N/A gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector");
3935N/A sp_gradient_selector_set_units(gsel, units);
3935N/A sp_gradient_selector_set_spread(gsel, spread);
3935N/A}
3935N/A
3935N/Avoid
3935N/Asp_paint_selector_get_gradient_properties(SPPaintSelector *psel, SPGradientUnits *units, SPGradientSpread *spread)
3935N/A{
5294N/A SPGradientSelector *gsel;
5294N/A g_return_if_fail(SP_IS_PAINT_SELECTOR(psel));
5294N/A g_return_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) ||
3935N/A (psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL));
3935N/A gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector");
3935N/A if (units) *units = sp_gradient_selector_get_units(gsel);
3935N/A if (spread) *spread = sp_gradient_selector_get_spread(gsel);
3935N/A}
3935N/A
3935N/A/**
3935N/A * \post (alpha == NULL) || (*alpha in [0.0, 1.0]).
5294N/A */
5294N/Avoid
5294N/Asp_paint_selector_get_color_alpha(SPPaintSelector *psel, SPColor *color, gfloat *alpha)
5294N/A{
3935N/A SPColorSelector *csel;
3935N/A
3935N/A csel = (SPColorSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "color-selector");
3935N/A
3935N/A csel->base->getColorAlpha( *color, alpha );
3935N/A
3935N/A g_assert( !alpha
3935N/A || ( ( 0.0 <= *alpha )
3935N/A && ( *alpha <= 1.0 ) ) );
3935N/A}
3935N/A
3935N/ASPGradient *
3935N/Asp_paint_selector_get_gradient_vector(SPPaintSelector *psel)
3935N/A{
3935N/A SPGradientSelector *gsel;
3935N/A
3935N/A g_return_val_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) ||
3935N/A (psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL), NULL);
3935N/A
3935N/A gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector");
3935N/A
3935N/A return sp_gradient_selector_get_vector(gsel);
3935N/A}
3935N/A
3935N/Avoid
3935N/Asp_gradient_selector_attrs_to_gradient(SPGradient *gr, SPPaintSelector *psel)
3935N/A{
3935N/A SPGradientUnits units;
3935N/A SPGradientSpread spread;
3935N/A sp_paint_selector_get_gradient_properties(psel, &units, &spread);
3935N/A sp_gradient_set_units(gr, units);
3935N/A sp_gradient_set_spread(gr, spread);
3935N/A SP_OBJECT(gr)->updateRepr();
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_clear_frame(SPPaintSelector *psel)
3935N/A{
3935N/A g_return_if_fail( psel != NULL);
3935N/A
3935N/A if (psel->selector) {
3935N/A
3935N/A /* before we destroy the frame contents, we must detach
3935N/A * the patternmenu so that Gtk doesn't gtk_widget_destroy
3935N/A * all the children of the menu. (We also have a g_object_ref
3935N/A * count set on it too so that the gtk_container_remove doesn't
3935N/A * end up destroying it.
3935N/A */
3935N/A GtkWidget *patterns = (GtkWidget *)g_object_get_data(G_OBJECT(psel), "patternmenu");
3935N/A if (patterns != NULL) {
3935N/A GtkWidget * parent = gtk_widget_get_parent( GTK_WIDGET(patterns));
3935N/A if ( parent != NULL ) {
3935N/A g_assert( GTK_IS_CONTAINER(parent) );
3935N/A gtk_container_remove( GTK_CONTAINER(parent), patterns );
3935N/A }
3935N/A }
3935N/A
3935N/A gtk_widget_destroy(psel->selector);
3935N/A psel->selector = NULL;
3935N/A }
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_set_mode_empty(SPPaintSelector *psel)
3935N/A{
3935N/A sp_paint_selector_set_style_buttons(psel, NULL);
3935N/A gtk_widget_set_sensitive(psel->style, FALSE);
3935N/A
3935N/A sp_paint_selector_clear_frame(psel);
3935N/A
3935N/A gtk_frame_set_label(GTK_FRAME(psel->frame), _("No objects"));
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_set_mode_multiple(SPPaintSelector *psel)
3935N/A{
3935N/A sp_paint_selector_set_style_buttons(psel, NULL);
3935N/A gtk_widget_set_sensitive(psel->style, TRUE);
3935N/A
3935N/A sp_paint_selector_clear_frame(psel);
3935N/A
3935N/A gtk_frame_set_label(GTK_FRAME(psel->frame), _("Multiple styles"));
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_set_mode_unset(SPPaintSelector *psel)
3935N/A{
3935N/A sp_paint_selector_set_style_buttons(psel, psel->unset);
3935N/A gtk_widget_set_sensitive(psel->style, TRUE);
3935N/A
3935N/A sp_paint_selector_clear_frame(psel);
3935N/A
3935N/A gtk_frame_set_label(GTK_FRAME(psel->frame), _("Paint is undefined"));
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_set_mode_none(SPPaintSelector *psel)
3935N/A{
3935N/A sp_paint_selector_set_style_buttons(psel, psel->none);
3935N/A gtk_widget_set_sensitive(psel->style, TRUE);
3935N/A
3935N/A sp_paint_selector_clear_frame(psel);
3935N/A
3935N/A gtk_frame_set_label(GTK_FRAME(psel->frame), _("No paint"));
3935N/A}
3935N/A
3935N/A/* Color paint */
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_color_grabbed(SPColorSelector *csel, SPPaintSelector *psel)
3935N/A{
3935N/A (void)csel;
3935N/A gtk_signal_emit(GTK_OBJECT(psel), psel_signals[GRABBED]);
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_color_dragged(SPColorSelector *csel, SPPaintSelector *psel)
3935N/A{
3935N/A (void)csel;
3935N/A gtk_signal_emit(GTK_OBJECT(psel), psel_signals[DRAGGED]);
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_color_released(SPColorSelector *csel, SPPaintSelector *psel)
3935N/A{
3935N/A (void)csel;
3935N/A gtk_signal_emit(GTK_OBJECT(psel), psel_signals[RELEASED]);
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_color_changed(SPColorSelector *csel, SPPaintSelector *psel)
3935N/A{
3935N/A csel->base->getColorAlpha( psel->color, &psel->alpha );
3935N/A
3935N/A gtk_signal_emit(GTK_OBJECT(psel), psel_signals[CHANGED]);
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_set_mode_color(SPPaintSelector *psel, SPPaintSelectorMode mode)
3935N/A{
3935N/A (void)mode;
3935N/A GtkWidget *csel;
3935N/A
3935N/A sp_paint_selector_set_style_buttons(psel, psel->solid);
3935N/A gtk_widget_set_sensitive(psel->style, TRUE);
3935N/A
3935N/A if ((psel->mode == SP_PAINT_SELECTOR_MODE_COLOR_RGB) || (psel->mode == SP_PAINT_SELECTOR_MODE_COLOR_CMYK)) {
3935N/A /* Already have color selector */
3935N/A csel = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(psel->selector), "color-selector");
3935N/A } else {
3935N/A
3935N/A sp_paint_selector_clear_frame(psel);
3935N/A /* Create new color selector */
3935N/A /* Create vbox */
3935N/A GtkWidget *vb = gtk_vbox_new(FALSE, 4);
3935N/A gtk_widget_show(vb);
3935N/A
3935N/A /* Color selector */
3935N/A csel = sp_color_selector_new( SP_TYPE_COLOR_NOTEBOOK );
3935N/A gtk_widget_show(csel);
3935N/A gtk_object_set_data(GTK_OBJECT(vb), "color-selector", csel);
3935N/A gtk_box_pack_start(GTK_BOX(vb), csel, TRUE, TRUE, 0);
3935N/A gtk_signal_connect(GTK_OBJECT(csel), "grabbed", GTK_SIGNAL_FUNC(sp_paint_selector_color_grabbed), psel);
3935N/A gtk_signal_connect(GTK_OBJECT(csel), "dragged", GTK_SIGNAL_FUNC(sp_paint_selector_color_dragged), psel);
3935N/A gtk_signal_connect(GTK_OBJECT(csel), "released", GTK_SIGNAL_FUNC(sp_paint_selector_color_released), psel);
3935N/A gtk_signal_connect(GTK_OBJECT(csel), "changed", GTK_SIGNAL_FUNC(sp_paint_selector_color_changed), psel);
3935N/A /* Pack everything to frame */
3935N/A gtk_container_add(GTK_CONTAINER(psel->frame), vb);
3935N/A psel->selector = vb;
3935N/A
3935N/A /* Set color */
3935N/A SP_COLOR_SELECTOR( csel )->base->setColorAlpha( psel->color, psel->alpha );
3935N/A
3935N/A }
3935N/A
3935N/A gtk_frame_set_label(GTK_FRAME(psel->frame), _("Flat color"));
3935N/A#ifdef SP_PS_VERBOSE
3935N/A g_print("Color req\n");
3935N/A#endif
3935N/A}
3935N/A
3935N/A/* Gradient */
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_gradient_grabbed(SPColorSelector *csel, SPPaintSelector *psel)
3935N/A{
3935N/A (void)csel;
3935N/A gtk_signal_emit(GTK_OBJECT(psel), psel_signals[GRABBED]);
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_gradient_dragged(SPColorSelector *csel, SPPaintSelector *psel)
3935N/A{
3935N/A (void)csel;
3935N/A gtk_signal_emit(GTK_OBJECT(psel), psel_signals[DRAGGED]);
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_gradient_released(SPColorSelector *csel, SPPaintSelector *psel)
3935N/A{
3935N/A (void)csel;
3935N/A gtk_signal_emit(GTK_OBJECT(psel), psel_signals[RELEASED]);
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_gradient_changed(SPColorSelector *csel, SPPaintSelector *psel)
3935N/A{
3935N/A (void)csel;
3935N/A gtk_signal_emit(GTK_OBJECT(psel), psel_signals[CHANGED]);
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_set_mode_gradient(SPPaintSelector *psel, SPPaintSelectorMode mode)
3935N/A{
3935N/A GtkWidget *gsel;
3935N/A
3935N/A /* fixme: We do not need function-wide gsel at all */
3935N/A
3935N/A if (mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) {
3935N/A sp_paint_selector_set_style_buttons(psel, psel->gradient);
3935N/A } else {
3935N/A sp_paint_selector_set_style_buttons(psel, psel->radial);
3935N/A }
3935N/A gtk_widget_set_sensitive(psel->style, TRUE);
3935N/A
3935N/A if ((psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) || (psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL)) {
3935N/A /* Already have gradient selector */
3935N/A gsel = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector");
3935N/A } else {
3935N/A sp_paint_selector_clear_frame(psel);
3935N/A /* Create new gradient selector */
3935N/A gsel = sp_gradient_selector_new();
3935N/A gtk_widget_show(gsel);
3935N/A gtk_signal_connect(GTK_OBJECT(gsel), "grabbed", GTK_SIGNAL_FUNC(sp_paint_selector_gradient_grabbed), psel);
3935N/A gtk_signal_connect(GTK_OBJECT(gsel), "dragged", GTK_SIGNAL_FUNC(sp_paint_selector_gradient_dragged), psel);
3935N/A gtk_signal_connect(GTK_OBJECT(gsel), "released", GTK_SIGNAL_FUNC(sp_paint_selector_gradient_released), psel);
3935N/A gtk_signal_connect(GTK_OBJECT(gsel), "changed", GTK_SIGNAL_FUNC(sp_paint_selector_gradient_changed), psel);
3935N/A /* Pack everything to frame */
3935N/A gtk_container_add(GTK_CONTAINER(psel->frame), gsel);
3935N/A psel->selector = gsel;
3935N/A gtk_object_set_data(GTK_OBJECT(psel->selector), "gradient-selector", gsel);
3935N/A }
3935N/A
3935N/A /* Actually we have to set option menu history here */
3935N/A if (mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) {
3935N/A sp_gradient_selector_set_mode(SP_GRADIENT_SELECTOR(gsel), SP_GRADIENT_SELECTOR_MODE_LINEAR);
3935N/A gtk_frame_set_label(GTK_FRAME(psel->frame), _("Linear gradient"));
3935N/A } else {
3935N/A sp_gradient_selector_set_mode(SP_GRADIENT_SELECTOR(gsel), SP_GRADIENT_SELECTOR_MODE_RADIAL);
3935N/A gtk_frame_set_label(GTK_FRAME(psel->frame), _("Radial gradient"));
3935N/A }
3935N/A#ifdef SP_PS_VERBOSE
3935N/A g_print("Gradient req\n");
3935N/A#endif
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_set_style_buttons(SPPaintSelector *psel, GtkWidget *active)
3935N/A{
3935N/A gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->none), (active == psel->none));
3935N/A gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->solid), (active == psel->solid));
3935N/A gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->gradient), (active == psel->gradient));
3935N/A gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->radial), (active == psel->radial));
3935N/A gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->pattern), (active == psel->pattern));
3935N/A gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->unset), (active == psel->unset));
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_psel_pattern_destroy(GtkWidget *widget, SPPaintSelector *psel)
3935N/A{
3935N/A (void)psel;
3935N/A // drop our reference to the pattern menu widget
3935N/A g_object_unref( G_OBJECT(widget) );
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_psel_pattern_change(GtkWidget *widget, SPPaintSelector *psel)
3935N/A{
3935N/A (void)widget;
3935N/A gtk_signal_emit(GTK_OBJECT(psel), psel_signals[CHANGED]);
3935N/A}
3935N/A
3935N/A
3935N/A
3935N/A/**
3935N/A * Returns a list of patterns in the defs of the given source document as a GSList object
3935N/A * Returns NULL if there are no patterns in the document.
3935N/A */
3935N/AGSList *
3935N/Aink_pattern_list_get (SPDocument *source)
3935N/A{
3935N/A if (source == NULL)
3935N/A return NULL;
3935N/A
3935N/A GSList *pl = NULL;
3935N/A GSList const *patterns = sp_document_get_resource_list(source, "pattern");
3935N/A for (GSList *l = (GSList *) patterns; l != NULL; l = l->next) {
3935N/A if (SP_PATTERN(l->data) == pattern_getroot(SP_PATTERN(l->data))) { // only if this is a root pattern
3935N/A pl = g_slist_prepend(pl, l->data);
3935N/A }
3935N/A }
3935N/A
3935N/A pl = g_slist_reverse(pl);
3935N/A return pl;
3935N/A}
3935N/A
3935N/A/**
3935N/A * Adds menu items for pattern list - derived from marker code, left hb etc in to make addition of previews easier at some point.
3935N/A */
3935N/Astatic void
3935N/Asp_pattern_menu_build (GtkWidget *m, GSList *pattern_list, SPDocument */*source*/)
3935N/A{
3935N/A
3935N/A for (; pattern_list != NULL; pattern_list = pattern_list->next) {
3935N/A Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) pattern_list->data);
3935N/A GtkWidget *i = gtk_menu_item_new();
3935N/A gtk_widget_show(i);
3935N/A
3935N/A if (repr->attribute("inkscape:stockid"))
3935N/A g_object_set_data (G_OBJECT(i), "stockid", (void *) "true");
3935N/A else
3935N/A g_object_set_data (G_OBJECT(i), "stockid", (void *) "false");
3935N/A
3935N/A gchar const *patid = repr->attribute("id");
3935N/A g_object_set_data (G_OBJECT(i), "pattern", (void *) patid);
3935N/A
3935N/A GtkWidget *hb = gtk_hbox_new(FALSE, 4);
3935N/A gtk_widget_show(hb);
3935N/A
3935N/A // create label
3935N/A GtkWidget *l;
3935N/A if (repr->attribute("inkscape:stockid"))
3935N/A l = gtk_label_new(repr->attribute("inkscape:stockid"));
3935N/A else
3935N/A l = gtk_label_new(repr->attribute("id"));
3935N/A gtk_widget_show(l);
3935N/A gtk_misc_set_alignment(GTK_MISC(l), 0.0, 0.5);
3935N/A
3935N/A gtk_box_pack_start(GTK_BOX(hb), l, TRUE, TRUE, 0);
3935N/A
3935N/A gtk_widget_show(hb);
3935N/A gtk_container_add(GTK_CONTAINER(i), hb);
3935N/A
3935N/A gtk_menu_append(GTK_MENU(m), i);
3935N/A }
3935N/A }
3935N/A
3935N/A/**
3935N/A * sp_pattern_list_from_doc()
3935N/A *
3935N/A * \brief Pick up all patterns from source, except those that are in
3935N/A * current_doc (if non-NULL), and add items to the pattern menu
3935N/A *
3935N/A */
3935N/Astatic void
3935N/Asp_pattern_list_from_doc (GtkWidget *m, SPDocument *current_doc, SPDocument *source, SPDocument *pattern_doc)
5294N/A{
5294N/A (void)current_doc;
3935N/A (void)pattern_doc;
3935N/A GSList *pl = ink_pattern_list_get(source);
3935N/A GSList *clean_pl = NULL;
3935N/A
5294N/A for (; pl != NULL; pl = pl->next) {
3935N/A if (!SP_IS_PATTERN(pl->data))
3935N/A continue;
5294N/A
3935N/A // Add to the list of patterns we really do wish to show
3935N/A clean_pl = g_slist_prepend (clean_pl, pl->data);
3935N/A }
3935N/A
3935N/A sp_pattern_menu_build (m, clean_pl, source);
3935N/A
3935N/A g_slist_free (pl);
3935N/A g_slist_free (clean_pl);
3935N/A}
3935N/A
3935N/A
3935N/A
3935N/A
3935N/Astatic void
3935N/Aink_pattern_menu_populate_menu(GtkWidget *m, SPDocument *doc)
3935N/A{
3935N/A static SPDocument *patterns_doc = NULL;
3935N/A
3935N/A // find and load patterns.svg
3935N/A if (patterns_doc == NULL) {
3935N/A char *patterns_source = g_build_filename(INKSCAPE_PATTERNSDIR, "patterns.svg", NULL);
3935N/A if (Inkscape::IO::file_test(patterns_source, G_FILE_TEST_IS_REGULAR)) {
3935N/A patterns_doc = sp_document_new(patterns_source, FALSE);
3935N/A }
3935N/A g_free(patterns_source);
3935N/A }
3935N/A
3935N/A // suck in from current doc
3935N/A sp_pattern_list_from_doc ( m, NULL, doc, patterns_doc );
3935N/A
3935N/A // add separator
3935N/A {
3935N/A GtkWidget *i = gtk_separator_menu_item_new();
3935N/A gchar const *patid = "";
3935N/A g_object_set_data (G_OBJECT(i), "pattern", (void *) patid);
3935N/A gtk_widget_show(i);
3935N/A gtk_menu_append(GTK_MENU(m), i);
3935N/A }
3935N/A
3935N/A // suck in from patterns.svg
5294N/A if (patterns_doc) {
3935N/A sp_document_ensure_up_to_date(doc);
3935N/A sp_pattern_list_from_doc ( m, doc, patterns_doc, NULL );
3935N/A }
3935N/A
3935N/A}
3935N/A
3935N/A
3935N/Astatic GtkWidget*
3935N/Aink_pattern_menu(GtkWidget *mnu)
3935N/A{
3935N/A /* Create new menu widget */
3935N/A GtkWidget *m = gtk_menu_new();
5294N/A gtk_widget_show(m);
3935N/A SPDocument *doc = SP_ACTIVE_DOCUMENT;
3935N/A
3935N/A if (!doc) {
3935N/A GtkWidget *i;
3935N/A i = gtk_menu_item_new_with_label(_("No document selected"));
3935N/A gtk_widget_show(i);
3935N/A gtk_menu_append(GTK_MENU(m), i);
3935N/A gtk_widget_set_sensitive(mnu, FALSE);
3935N/A } else {
3935N/A
3935N/A ink_pattern_menu_populate_menu(m, doc);
3935N/A gtk_widget_set_sensitive(mnu, TRUE);
3935N/A
3935N/A }
3935N/A gtk_option_menu_set_menu(GTK_OPTION_MENU(mnu), m);
3935N/A
3935N/A /* Set history */
3935N/A gtk_option_menu_set_history(GTK_OPTION_MENU(mnu), 0);
3935N/A return mnu;
5294N/A}
3935N/A
3935N/A
3935N/A/*update pattern list*/
3935N/Avoid
3935N/Asp_update_pattern_list( SPPaintSelector *psel, SPPattern *pattern)
3935N/A{
3935N/A if (psel->update) return;
5294N/A GtkWidget *mnu = (GtkWidget *)g_object_get_data(G_OBJECT(psel), "patternmenu");
3935N/A g_assert( mnu != NULL );
3935N/A
3935N/A /* Clear existing menu if any */
3935N/A gtk_option_menu_remove_menu(GTK_OPTION_MENU(mnu));
3935N/A
3935N/A ink_pattern_menu(mnu);
3935N/A
3935N/A /* Set history */
3935N/A
3935N/A if (pattern && !gtk_object_get_data(GTK_OBJECT(mnu), "update")) {
3935N/A
3935N/A gtk_object_set_data(GTK_OBJECT(mnu), "update", GINT_TO_POINTER(TRUE));
3935N/A
3935N/A gchar *patname = (gchar *) SP_OBJECT_REPR(pattern)->attribute("id");
3935N/A
3935N/A GtkMenu *m = GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(mnu)));
3935N/A
3935N/A GList *kids = GTK_MENU_SHELL(m)->children;
3935N/A
3935N/A int patpos = 0;
3935N/A int i = 0;
3935N/A
3935N/A for (; kids != NULL; kids = kids->next) {
3935N/A
3935N/A gchar *men_pat = (gchar *) g_object_get_data(G_OBJECT(kids->data), "pattern");
3935N/A if ( strcmp(men_pat, patname) == 0 ) {
3935N/A patpos = i;
3935N/A }
3935N/A i++;
3935N/A }
3935N/A
3935N/A
3935N/A gtk_option_menu_set_history(GTK_OPTION_MENU(mnu), patpos);
3935N/A gtk_object_set_data(GTK_OBJECT(mnu), "update", GINT_TO_POINTER(FALSE));
3935N/A }
3935N/A //gtk_option_menu_set_history(GTK_OPTION_MENU(mnu), 0);
3935N/A}
3935N/A
3935N/Astatic void
3935N/Asp_paint_selector_set_mode_pattern(SPPaintSelector *psel, SPPaintSelectorMode mode)
3935N/A{
3935N/A if (mode == SP_PAINT_SELECTOR_MODE_PATTERN)
3935N/A sp_paint_selector_set_style_buttons(psel, psel->pattern);
3935N/A
3935N/A gtk_widget_set_sensitive(psel->style, TRUE);
3935N/A
3935N/A GtkWidget *tbl = NULL;
3935N/A
3935N/A if (psel->mode == SP_PAINT_SELECTOR_MODE_PATTERN){
3935N/A /* Already have pattern menu */
3935N/A tbl = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(psel->selector), "pattern-selector");
3935N/A } else {
3935N/A sp_paint_selector_clear_frame(psel);
3935N/A
3935N/A /* Create vbox */
3935N/A tbl = gtk_vbox_new(FALSE, 4);
3935N/A gtk_widget_show(tbl);
3935N/A
3935N/A {
3935N/A GtkWidget *hb = gtk_hbox_new(FALSE, 1);
3935N/A
3935N/A GtkWidget *mnu = gtk_option_menu_new();
3935N/A ink_pattern_menu(mnu);
3935N/A gtk_signal_connect(GTK_OBJECT(mnu), "changed", GTK_SIGNAL_FUNC(sp_psel_pattern_change), psel);
3935N/A gtk_signal_connect(GTK_OBJECT(mnu), "destroy", GTK_SIGNAL_FUNC(sp_psel_pattern_destroy), psel);
3935N/A gtk_object_set_data(GTK_OBJECT(psel), "patternmenu", mnu);
3935N/A g_object_ref( G_OBJECT(mnu));
3935N/A
3935N/A gtk_container_add(GTK_CONTAINER(hb), mnu);
3935N/A gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, AUX_BETWEEN_BUTTON_GROUPS);
3935N/A }
3935N/A
3935N/A {
3935N/A GtkWidget *hb = gtk_hbox_new(FALSE, 0);
3935N/A GtkWidget *l = gtk_label_new(NULL);
3935N/A 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."));
3935N/A gtk_label_set_line_wrap(GTK_LABEL(l), true);
3935N/A gtk_widget_set_size_request(l, 180, -1);
3935N/A gtk_box_pack_start(GTK_BOX(hb), l, TRUE, TRUE, AUX_BETWEEN_BUTTON_GROUPS);
3935N/A gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, AUX_BETWEEN_BUTTON_GROUPS);
3935N/A }
3935N/A
3935N/A gtk_widget_show_all(tbl);
3935N/A
3935N/A gtk_container_add(GTK_CONTAINER(psel->frame), tbl);
3935N/A psel->selector = tbl;
3935N/A gtk_object_set_data(GTK_OBJECT(psel->selector), "pattern-selector", tbl);
3935N/A
3935N/A gtk_frame_set_label(GTK_FRAME(psel->frame), _("Pattern fill"));
3935N/A }
3935N/A#ifdef SP_PS_VERBOSE
3935N/A g_print("Pattern req\n");
3935N/A#endif
3935N/A}
3935N/A
3935N/ASPPattern *
3935N/Asp_paint_selector_get_pattern(SPPaintSelector *psel)
3935N/A{
3935N/A SPPattern *pat;
3935N/A g_return_val_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_PATTERN) , NULL);
3935N/A
3935N/A GtkWidget *patmnu = (GtkWidget *) g_object_get_data(G_OBJECT(psel), "patternmenu");
3935N/A /* no pattern menu if we were just selected */
3935N/A if ( patmnu == NULL ) return NULL;
3935N/A
3935N/A GtkMenu *m = GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(patmnu)));
3935N/A
3935N/A /* Get Pattern */
3935N/A if (!g_object_get_data(G_OBJECT(gtk_menu_get_active(m)), "pattern"))
3935N/A {
3935N/A return NULL;
3935N/A }
3935N/A gchar *patid = (gchar *) g_object_get_data(G_OBJECT(gtk_menu_get_active(m)),
3935N/A "pattern");
3935N/A //gchar *pattern = "";
3935N/A if (strcmp(patid, "none")){
3935N/A
3935N/A gchar *stockid = (gchar *) g_object_get_data(G_OBJECT(gtk_menu_get_active(m)),
3935N/A "stockid");
3935N/A gchar *paturn = patid;
3935N/A if (!strcmp(stockid,"true")) paturn = g_strconcat("urn:inkscape:pattern:",patid,NULL);
3935N/A SPObject *pat_obj = get_stock_item(paturn);
3935N/A if (pat_obj) {
3935N/A pat = SP_PATTERN(pat_obj);
3935N/A }
3935N/A } else {
3935N/A pat = pattern_getroot(SP_PATTERN(g_object_get_data(G_OBJECT(gtk_menu_get_active(m)), "pattern")));
3935N/A }
3935N/A
3935N/A if SP_IS_PATTERN(pat) return pat;
3935N/A return NULL;
3935N/A}
3935N/A
3935N/Avoid
3935N/Asp_paint_selector_set_flat_color(SPPaintSelector *psel, SPDesktop *desktop, gchar const *color_property, gchar const *opacity_property)
3935N/A{
3935N/A SPCSSAttr *css = sp_repr_css_attr_new();
3935N/A
3935N/A SPColor color;
3935N/A gfloat alpha;
3935N/A sp_paint_selector_get_color_alpha(psel, &color, &alpha);
3935N/A
5294N/A std::string colorStr = color.toString();
5294N/A
5294N/A#ifdef SP_PS_VERBOSE
3935N/A guint32 rgba = color.toRGBA32( alpha );
3935N/A g_message("sp_paint_selector_set_flat_color() to '%s' from 0x%08x::%s",
3935N/A colorStr.c_str(),
3935N/A rgba,
3935N/A (color.icc?color.icc->colorProfile.c_str():"<null>") );
3935N/A#endif // SP_PS_VERBOSE
3935N/A
3935N/A sp_repr_css_set_property(css, color_property, colorStr.c_str());
3935N/A Inkscape::CSSOStringStream osalpha;
3935N/A osalpha << alpha;
3935N/A sp_repr_css_set_property(css, opacity_property, osalpha.str().c_str());
3935N/A
3935N/A sp_desktop_set_style(desktop, css);
3935N/A
3935N/A sp_repr_css_attr_unref(css);
3935N/A}
3935N/A
3935N/ASPPaintSelectorMode
3935N/Asp_style_determine_paint_selector_mode(SPStyle *style, bool isfill)
3935N/A{
3935N/A SPPaintSelectorMode mode = SP_PAINT_SELECTOR_MODE_UNSET;
3935N/A SPIPaint& target = isfill ? style->fill : style->stroke;
3935N/A
3935N/A if ( !target.set ) {
3935N/A mode = SP_PAINT_SELECTOR_MODE_UNSET;
3935N/A } else if ( target.isPaintserver() ) {
3935N/A SPPaintServer *server = isfill? SP_STYLE_FILL_SERVER(style) : SP_STYLE_STROKE_SERVER(style);
3935N/A
3935N/A if (SP_IS_LINEARGRADIENT(server)) {
3935N/A mode = SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR;
3935N/A } else if (SP_IS_RADIALGRADIENT(server)) {
3935N/A mode = SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL;
3935N/A } else if (SP_IS_PATTERN(server)) {
3935N/A mode = SP_PAINT_SELECTOR_MODE_PATTERN;
3935N/A } else {
3935N/A g_warning( "file %s: line %d: Unknown paintserver", __FILE__, __LINE__ );
3935N/A mode = SP_PAINT_SELECTOR_MODE_NONE;
3935N/A }
3935N/A } else if ( target.isColor() ) {
3935N/A mode = SP_PAINT_SELECTOR_MODE_COLOR_RGB; // so far only rgb can be read from svg
3935N/A } else if ( target.isNone() ) {
3935N/A mode = SP_PAINT_SELECTOR_MODE_NONE;
3935N/A } else {
3935N/A g_warning( "file %s: line %d: Unknown paint type", __FILE__, __LINE__ );
3935N/A mode = SP_PAINT_SELECTOR_MODE_NONE;
3935N/A }
3935N/A
3935N/A return mode;
3935N/A}
3935N/A
3935N/A/*
3935N/A Local Variables:
3935N/A mode:c++
3935N/A c-file-style:"stroustrup"
3935N/A c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
3935N/A indent-tabs-mode:nil
3935N/A fill-column:99
3935N/A End:
3935N/A*/
3935N/A// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
3935N/A