Code

Initial F&S dialog setting of swatch colors.
authorJon A. Cruz <jon@joncruz.org>
Tue, 9 Mar 2010 10:12:09 +0000 (02:12 -0800)
committerJon A. Cruz <jon@joncruz.org>
Tue, 9 Mar 2010 10:12:09 +0000 (02:12 -0800)
20 files changed:
src/desktop-style.cpp
src/extension/internal/odf.cpp
src/gradient-chemistry.cpp
src/gradient-drag.cpp
src/helper/stock-items.cpp
src/sp-gradient-fns.h
src/sp-gradient-reference.cpp
src/sp-gradient.cpp
src/sp-gradient.h
src/sp-paint-server.cpp
src/ui/widget/selected-style.cpp
src/widgets/fill-style.cpp
src/widgets/gradient-selector.cpp
src/widgets/gradient-selector.h
src/widgets/gradient-toolbar.cpp
src/widgets/gradient-vector.cpp
src/widgets/gradient-vector.h
src/widgets/paint-selector.cpp
src/widgets/paint-selector.h
src/widgets/stroke-style.cpp

index 2afcd610958061c993ea5ee53304a946cadd41ba..f3b1b833d8e8c778beac196502c8c3bcbc3a8bd1 100644 (file)
@@ -475,8 +475,8 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill
                 if (!SP_IS_LINEARGRADIENT(server))
                    return QUERY_STYLE_MULTIPLE_DIFFERENT;  // different kind of server
 
-                SPGradient *vector = sp_gradient_get_vector ( SP_GRADIENT (server), FALSE );
-                SPGradient *vector_res = sp_gradient_get_vector ( SP_GRADIENT (server_res), FALSE );
+                SPGradient *vector = SP_GRADIENT(server)->getVector();
+                SPGradient *vector_res = SP_GRADIENT(server_res)->getVector();
                 if (vector_res != vector)
                    return QUERY_STYLE_MULTIPLE_DIFFERENT;  // different gradient vectors
 
@@ -485,8 +485,8 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill
                 if (!SP_IS_RADIALGRADIENT(server))
                    return QUERY_STYLE_MULTIPLE_DIFFERENT;  // different kind of server
 
-                SPGradient *vector = sp_gradient_get_vector ( SP_GRADIENT (server), FALSE );
-                SPGradient *vector_res = sp_gradient_get_vector ( SP_GRADIENT (server_res), FALSE );
+                SPGradient *vector = SP_GRADIENT(server)->getVector();
+                SPGradient *vector_res = SP_GRADIENT(server_res)->getVector();
                 if (vector_res != vector)
                    return QUERY_STYLE_MULTIPLE_DIFFERENT;  // different gradient vectors
 
index 76b901023640bb504ca3dd551611db2aff07726c..5331c072cb82c075f866d06f4d844b19f5324730 100644 (file)
@@ -1659,7 +1659,7 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item,
 
     GradientInfo gi;
 
-    SPGradient *grvec = sp_gradient_get_vector(gradient, FALSE);
+    SPGradient *grvec = gradient->getVector(FALSE);
     for (SPStop *stop = grvec->getFirstStop() ;
          stop ; stop = stop->getNextStop())
         {
index 7382aa49bcdeb56641a37e2b9f7bcdfa92396b78..b2e68c345b613a4140c35c33c90713b2269deeff 100644 (file)
@@ -264,7 +264,7 @@ sp_gradient_fork_vector_if_necessary (SPGradient *gr)
 SPGradient *
 sp_gradient_get_forked_vector_if_necessary(SPGradient *gradient, bool force_vector)
 {
-    SPGradient *vector = sp_gradient_get_vector (gradient, force_vector);
+    SPGradient *vector = gradient->getVector(force_vector);
     vector = sp_gradient_fork_vector_if_necessary (vector);
     if ( gradient != vector && gradient->ref->getObject() != vector ) {
         sp_gradient_repr_set_link(SP_OBJECT_REPR(gradient), vector);
@@ -336,7 +336,7 @@ sp_gradient_convert_to_userspace(SPGradient *gr, SPItem *item, gchar const *prop
     g_return_val_if_fail(SP_IS_GRADIENT(gr), NULL);
 
     // First, fork it if it is shared
-    gr = sp_gradient_fork_private_if_necessary(gr, sp_gradient_get_vector(gr, FALSE),
+    gr = sp_gradient_fork_private_if_necessary(gr, gr->getVector(),
                                                SP_IS_RADIALGRADIENT(gr) ? SP_GRADIENT_TYPE_RADIAL : SP_GRADIENT_TYPE_LINEAR, SP_OBJECT(item));
 
     if (gr->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
@@ -555,7 +555,7 @@ sp_item_gradient_edit_stop (SPItem *item, guint point_type, guint point_i, bool
     if (!gradient || !SP_IS_GRADIENT(gradient))
         return;
 
-    SPGradient *vector = sp_gradient_get_vector (gradient, false);
+    SPGradient *vector = gradient->getVector();
     switch (point_type) {
         case POINT_LG_BEGIN:
         case POINT_RG_CENTER:
@@ -596,7 +596,7 @@ sp_item_gradient_stop_query_style (SPItem *item, guint point_type, guint point_i
     if (!gradient || !SP_IS_GRADIENT(gradient))
         return 0;
 
-    SPGradient *vector = sp_gradient_get_vector (gradient, false);
+    SPGradient *vector = gradient->getVector();
 
     if (!vector) // orphan!
         return 0; // what else to do?
@@ -649,7 +649,7 @@ sp_item_gradient_stop_set_style (SPItem *item, guint point_type, guint point_i,
     if (!gradient || !SP_IS_GRADIENT(gradient))
         return;
 
-    SPGradient *vector = sp_gradient_get_vector (gradient, false);
+    SPGradient *vector = gradient->getVector();
 
     if (!vector) // orphan!
         return;
@@ -705,7 +705,7 @@ sp_item_gradient_reverse_vector (SPItem *item, bool fill_or_stroke)
     if (!gradient || !SP_IS_GRADIENT(gradient))
         return;
 
-    SPGradient *vector = sp_gradient_get_vector (gradient, false);
+    SPGradient *vector = gradient->getVector();
     if (!vector) // orphan!
         return;
 
@@ -958,8 +958,9 @@ sp_item_gradient_get_vector (SPItem *item, bool fill_or_stroke)
 {
     SPGradient *gradient = sp_item_gradient (item, fill_or_stroke);
 
-    if (gradient)
-        return sp_gradient_get_vector (gradient, false);
+    if (gradient) {
+        return gradient->getVector();
+    }
     return NULL;
 }
 
@@ -1087,7 +1088,7 @@ sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType type, bool is_
             // current is private and it's either used once, or all its uses are by children of item;
             // so just change its href to vector
 
-            if ( current != gr && sp_gradient_get_vector(current, false) != gr ) {
+            if ( current != gr && current->getVector() != gr ) {
                 /* href is not the vector */
                 sp_gradient_repr_set_link(SP_OBJECT_REPR(current), gr);
             }
@@ -1123,25 +1124,20 @@ sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType type, bool is_
     }
 }
 
-static void
-sp_gradient_repr_set_link(Inkscape::XML::Node *repr, SPGradient *link)
+static void sp_gradient_repr_set_link(Inkscape::XML::Node *repr, SPGradient *link)
 {
     g_return_if_fail(repr != NULL);
-    g_return_if_fail(link != NULL);
-    g_return_if_fail(SP_IS_GRADIENT(link));
+    if (link) {
+        g_return_if_fail(SP_IS_GRADIENT(link));
+    }
 
-    gchar *ref;
     if (link) {
-        gchar const *id = link->getId();
-        size_t const len = strlen(id);
-        ref = (gchar*) alloca(len + 2);
-        *ref = '#';
-        memcpy(ref + 1, id, len + 1);
+        Glib::ustring ref("#");
+        ref += link->getId();
+        repr->setAttribute("xlink:href", ref.c_str());
     } else {
-        ref = NULL;
+        repr->setAttribute("xlink:href", 0);
     }
-
-    repr->setAttribute("xlink:href", ref);
 }
 
 /*
@@ -1225,7 +1221,7 @@ sp_gradient_vector_for_object(SPDocument *const doc, SPDesktop *const desktop,
         if (paint.isPaintserver()) {
             SPObject *server = is_fill? SP_OBJECT_STYLE_FILL_SERVER(o) : SP_OBJECT_STYLE_STROKE_SERVER(o);
             if (SP_IS_GRADIENT (server)) {
-                return sp_gradient_get_vector(SP_GRADIENT (server), TRUE);
+                return SP_GRADIENT(server)->getVector(true);
             } else {
                 rgba = sp_desktop_get_color(desktop, is_fill);
             }
index 13b422119f0efc6b61c57a20c3ac00e94ee44d5e..9796fc5da70c974025e418397affd83f709bf676 100644 (file)
@@ -905,7 +905,7 @@ gr_knot_clicked_handler(SPKnot */*knot*/, guint state, gpointer data)
     if ( (state & GDK_CONTROL_MASK) && (state & GDK_MOD1_MASK ) ) {
     // delete this knot from vector
         SPGradient *gradient = sp_item_gradient (draggable->item, draggable->fill_or_stroke);
-        gradient = sp_gradient_get_vector (gradient, false);
+        gradient = gradient->getVector();
         if (gradient->vector.stops.size() > 2) { // 2 is the minimum
             SPStop *stop = NULL;
             switch (draggable->point_type) {  // if we delete first or last stop, move the next/previous to the edge
index 575197fee3109deef8efe245edd39aef92dc4786..1c184da725c75c4dc9eb0700c380f255aa8b3e64 100644 (file)
@@ -23,7 +23,7 @@
 
 
 #include <xml/repr.h>
-#include "sp-gradient-fns.h"
+#include "sp-gradient.h"
 #include "document-private.h"
 #include "sp-pattern.h"
 #include "marker.h"
index 25729f5d7b94c97c5f358c110db76e19a260ae8a..dafa1646f4eeaad8e2d05d539cd4468dec41f2ad 100644 (file)
 
 class SPGradient;
 
-namespace Inkscape {
-namespace XML {
-class Node;
-}
-}
-
-#define SP_TYPE_GRADIENT (sp_gradient_get_type())
-#define SP_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_GRADIENT, SPGradient))
-#define SP_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_GRADIENT, SPGradientClass))
-#define SP_IS_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_GRADIENT))
-#define SP_IS_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_GRADIENT))
-
 #define SP_GRADIENT_STATE_IS_SET(g) (SP_GRADIENT(g)->state != SP_GRADIENT_STATE_UNKNOWN)
 #define SP_GRADIENT_IS_VECTOR(g) (SP_GRADIENT(g)->state == SP_GRADIENT_STATE_VECTOR)
 #define SP_GRADIENT_IS_PRIVATE(g) (SP_GRADIENT(g)->state == SP_GRADIENT_STATE_PRIVATE)
@@ -32,8 +20,6 @@ class Node;
 #define SP_GRADIENT_SPREAD(g) (SP_GRADIENT(g)->spread)
 #define SP_GRADIENT_UNITS(g) (SP_GRADIENT(g)->units)
 
-GType sp_gradient_get_type();
-
 /** Forces vector to be built, if not present (i.e. changed) */
 void sp_gradient_ensure_vector(SPGradient *gradient);
 
@@ -43,7 +29,6 @@ void sp_gradient_ensure_colors(SPGradient *gradient);
 void sp_gradient_set_units(SPGradient *gr, SPGradientUnits units);
 void sp_gradient_set_spread(SPGradient *gr, SPGradientSpread spread);
 
-SPGradient *sp_gradient_get_vector (SPGradient *gradient, bool force_private);
 SPGradientSpread sp_gradient_get_spread (SPGradient *gradient);
 
 /* Gradient repr methods */
index 618e1085a295bffd73d565472e2609ea95fbf225..39ef9915a91b725ae180d7e865c454900dccfe39 100644 (file)
@@ -1,5 +1,5 @@
 #include "sp-gradient-reference.h"
-#include "sp-gradient-fns.h"
+#include "sp-gradient.h"
 
 bool
 SPGradientReference::_acceptObject(SPObject *obj) const
index 4e8e8e3738c59dfebcc0db49c60a86889169df74..3d4d6967297de350fc3f5cb3d2925a182f5d522b 100644 (file)
@@ -815,8 +815,7 @@ chase_hrefs(SPGradient *const src, bool (*match)(SPGradient const *))
 /**
  * True if gradient has stops.
  */
-static bool
-has_stops(SPGradient const *gr)
+static bool has_stopsFN(SPGradient const *gr)
 {
     return SP_GRADIENT_HAS_STOPS(gr);
 }
@@ -840,23 +839,14 @@ has_units_set(SPGradient const *gr)
 }
 
 
-/**
- * Returns private vector of given gradient (the gradient at the end of the href chain which has
- * stops), optionally normalizing it.
- *
- * \pre SP_IS_GRADIENT(gradient).
- * \pre There exists a gradient in the chain that has stops.
- */
-SPGradient *
-sp_gradient_get_vector(SPGradient *gradient, bool force_vector)
+SPGradient *SPGradient::getVector(bool force_vector)
 {
-    g_return_val_if_fail(gradient != NULL, NULL);
-    g_return_val_if_fail(SP_IS_GRADIENT(gradient), NULL);
+    SPGradient * src = chase_hrefs(this, has_stopsFN);
 
-    SPGradient *const src = chase_hrefs(gradient, has_stops);
-    return ( force_vector
-             ? sp_gradient_ensure_vector_normalized(src)
-             : src );
+    if (force_vector) {
+        src = sp_gradient_ensure_vector_normalized(src);
+    }
+    return src;
 }
 
 /**
index 0451092345c54cf75ebed78cb4293ea3870f0537..e7488673dddb9a40fd7de11ca4e9e19ca732dbf5 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef __SP_GRADIENT_H__
-#define __SP_GRADIENT_H__
+#ifndef SEEN_SP_GRADIENT_H
+#define SEEN_SP_GRADIENT_H
 
 /** \file
  * SVG <stop> <linearGradient> and <radialGradient> implementation
@@ -7,7 +7,9 @@
  * Authors:
  *   Lauris Kaplinski <lauris@kaplinski.com>
  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *   Jon A. Cruz <jon@joncruz.org>
  *
+ * Copyrigt  (C) 2010 Jon A. Cruz
  * Copyright (C) 2007 Johan Engelen
  * Copyright (C) 1999-2002 Lauris Kaplinski
  * Copyright (C) 2000-2001 Ximian, Inc.
 
 struct SPGradientReference;
 
+
+#define SP_TYPE_GRADIENT (sp_gradient_get_type())
+#define SP_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_GRADIENT, SPGradient))
+#define SP_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_GRADIENT, SPGradientClass))
+#define SP_IS_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_GRADIENT))
+#define SP_IS_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_GRADIENT))
+
+GType sp_gradient_get_type();
+
 typedef enum {
     SP_GRADIENT_TYPE_UNKNOWN,
     SP_GRADIENT_TYPE_LINEAR,
@@ -93,6 +104,15 @@ struct SPGradient : public SPPaintServer {
 
     SPStop* getFirstStop();
     int getStopCount() const;
+
+/**
+ * Returns private vector of given gradient (the gradient at the end of the href chain which has
+ * stops), optionally normalizing it.
+ *
+ * \pre SP_IS_GRADIENT(gradient).
+ * \pre There exists a gradient in the chain that has stops.
+ */
+    SPGradient *getVector(bool force_private = false);
 };
 
 /**
@@ -105,7 +125,7 @@ struct SPGradientClass {
 
 #include "sp-gradient-fns.h"
 
-#endif /* !__SP_GRADIENT_H__ */
+#endif // SEEN_SP_GRADIENT_H
 
 /*
   Local Variables:
index 805aafaeaf98b4f815b0504ec52d41044442ea0c..258323a93d36399baffacada5af08aae80125106 100644 (file)
@@ -157,8 +157,17 @@ static void sp_painter_stale_fill(SPPainter */*painter*/, NRPixBlock *pb)
 
 bool SPPaintServer::isSwatch() const
 {
-    // Temporary for now. Later expand to more
-    return isSolid();
+    bool swatch = false;
+    if (SP_IS_GRADIENT(this)) {
+        SPGradient *grad = SP_GRADIENT(this);
+        if ( SP_GRADIENT_HAS_STOPS(grad) ) {
+            gchar const * attr = repr->attribute("osb:paint");
+            if (attr && !strcmp(attr, "solid")) {
+                swatch = true;
+            }
+        }
+    }
+    return swatch;
 }
 
 bool SPPaintServer::isSolid() const
index e7b0188d81ae138fa505cf25e976125cd1e3cc8b..a8f9f9c60d9ae9e1419d5384471321181721d2cf 100644 (file)
@@ -103,7 +103,7 @@ static guint nui_drop_target_entries = ENTRIES_SIZE(ui_drop_target_entries);
 static Dialog::FillAndStroke *get_fill_and_stroke_panel(SPDesktop *desktop);
 
 SelectedStyle::SelectedStyle(bool /*layout*/)
-    : 
+    :
       current_stroke_width(0),
 
       _desktop (NULL),
@@ -955,13 +955,13 @@ SelectedStyle::update()
                     _paintserver_id[i] += ")";
 
                     if (SP_IS_LINEARGRADIENT (server)) {
-                        SPGradient *vector = sp_gradient_get_vector(SP_GRADIENT(server), false);
+                        SPGradient *vector = SP_GRADIENT(server)->getVector();
                         sp_gradient_image_set_gradient ((SPGradientImage *) _gradient_preview_l[i], vector);
                         place->add(_gradient_box_l[i]);
                         _tooltips.set_tip(*place, __lgradient[i]);
                         _mode[i] = SS_LGRADIENT;
                     } else if (SP_IS_RADIALGRADIENT (server)) {
-                        SPGradient *vector = sp_gradient_get_vector(SP_GRADIENT(server), false);
+                        SPGradient *vector = SP_GRADIENT(server)->getVector();
                         sp_gradient_image_set_gradient ((SPGradientImage *) _gradient_preview_r[i], vector);
                         place->add(_gradient_box_r[i]);
                         _tooltips.set_tip(*place, __rgradient[i]);
@@ -1165,7 +1165,7 @@ RotateableSwatch::RotateableSwatch(SelectedStyle *parent, guint mode) :
     undokey("ssrot1"),
     cr(0),
     cr_set(false)
-    
+
 {
 }
 
@@ -1426,14 +1426,14 @@ RotateableStrokeWidth::do_release(double by, guint modifier) {
 
 Dialog::FillAndStroke *get_fill_and_stroke_panel(SPDesktop *desktop)
 {
-    if (Dialog::PanelDialogBase *panel_dialog = 
+    if (Dialog::PanelDialogBase *panel_dialog =
         dynamic_cast<Dialog::PanelDialogBase *>(desktop->_dlg_mgr->getDialog("FillAndStroke"))) {
         try {
-            Dialog::FillAndStroke &fill_and_stroke = 
+            Dialog::FillAndStroke &fill_and_stroke =
                 dynamic_cast<Dialog::FillAndStroke &>(panel_dialog->getPanel());
             return &fill_and_stroke;
         } catch (std::exception e) { }
-    }        
+    }
 
     return 0;
 }
index 0b08f36b57f8bb7b95baea562d006b41dfe2f6ac..87cd238a7fc45d20112102bcdf80ebc9522f5650 100644 (file)
@@ -210,10 +210,11 @@ sp_fill_style_widget_update (SPWidget *spw)
 
                 SPPaintServer *server = SP_STYLE_FILL_SERVER (query);
 
-                if (server && server->isSwatch()) {
-                    sp_paint_selector_set_swatch( psel, server );
+                if (server && SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()) {
+                    SPGradient *vector = SP_GRADIENT(server)->getVector();
+                    sp_paint_selector_set_swatch( psel, vector );
                 } else if (SP_IS_LINEARGRADIENT (server)) {
-                    SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE);
+                    SPGradient *vector = SP_GRADIENT(server)->getVector();
                     sp_paint_selector_set_gradient_linear (psel, vector);
 
                     SPLinearGradient *lg = SP_LINEARGRADIENT (server);
@@ -221,7 +222,7 @@ sp_fill_style_widget_update (SPWidget *spw)
                                                        SP_GRADIENT_UNITS (lg),
                                                        SP_GRADIENT_SPREAD (lg));
                 } else if (SP_IS_RADIALGRADIENT (server)) {
-                    SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE);
+                    SPGradient *vector = SP_GRADIENT(server)->getVector();
                     sp_paint_selector_set_gradient_radial (psel, vector);
 
                     SPRadialGradient *rg = SP_RADIALGRADIENT (server);
@@ -411,8 +412,9 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel,
 
         case SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR:
         case SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL:
+        case SP_PAINT_SELECTOR_MODE_SWATCH:
             if (items) {
-                SPGradientType const gradient_type = ( psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR
+                SPGradientType const gradient_type = ( psel->mode != SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL
                                                        ? SP_GRADIENT_TYPE_LINEAR
                                                        : SP_GRADIENT_TYPE_RADIAL );
 
@@ -518,10 +520,6 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel,
 
             break;
 
-        case SP_PAINT_SELECTOR_MODE_SWATCH:
-            // TODO
-            break;
-
         case SP_PAINT_SELECTOR_MODE_UNSET:
             if (items) {
                     SPCSSAttr *css = sp_repr_css_attr_new ();
index ada9b2f097a335d3a24f96e7e42cabac54236fc0..bc2413730e66d8fbe11f082d4ec2bb1b905f528b 100644 (file)
@@ -120,7 +120,7 @@ sp_gradient_selector_class_init (SPGradientSelectorClass *klass)
 static void
 sp_gradient_selector_init (SPGradientSelector *sel)
 {
-    GtkWidget *hb, *l, *m, *mi;
+    GtkWidget *hb, *m, *mi;
 
     sel->mode = SPGradientSelector::MODE_LINEAR;
 
@@ -182,9 +182,9 @@ sp_gradient_selector_init (SPGradientSelector *sel)
 
     gtk_option_menu_set_menu (GTK_OPTION_MENU (sel->spread), m);
 
-    l = gtk_label_new (_("Repeat:"));
-    gtk_widget_show (l);
-    gtk_box_pack_end (GTK_BOX (hb), l, FALSE, FALSE, 4);
+    sel->spreadLbl = gtk_label_new (_("Repeat:"));
+    gtk_widget_show(sel->spreadLbl);
+    gtk_box_pack_end(GTK_BOX(hb), sel->spreadLbl, FALSE, FALSE, 4);
 }
 
 static void
@@ -210,7 +210,28 @@ sp_gradient_selector_new (void)
 
 void SPGradientSelector::setMode(SelectorMode mode)
 {
-    this->mode = mode;
+    if (mode != this->mode) {
+        this->mode = mode;
+        if (mode == MODE_SWATCH) {
+            if (spread) {
+                GtkWidget *parent = gtk_widget_get_parent(spread);
+                if (parent) {
+                    gtk_container_remove(GTK_CONTAINER(parent), spread);
+                    spread = 0;
+                }
+            }
+            if (spreadLbl) {
+                GtkWidget *parent = gtk_widget_get_parent(spreadLbl);
+                if (parent) {
+                    gtk_container_remove(GTK_CONTAINER(parent), spreadLbl);
+                    spreadLbl = 0;
+                }
+            }
+
+            SPGradientVectorSelector* vs = SP_GRADIENT_VECTOR_SELECTOR(vectors);
+            vs->setSwatched();
+        }
+    }
 }
 
 void SPGradientSelector::setUnits(SPGradientUnits units)
@@ -227,7 +248,6 @@ void SPGradientSelector::setSpread(SPGradientSpread spread)
 
 SPGradientUnits SPGradientSelector::getUnits()
 {
-    //return (SPGradientUnits) sel->gradientUnits;
     return gradientUnits;
 }
 
index 85674b4a9d7c77f7672f18f899c9d260da7c10f8..25f561a6e9875a0c38a1c237128e69fe8b5e888d 100644 (file)
@@ -36,7 +36,8 @@ struct SPGradientSelector {
 
     enum SelectorMode {
         MODE_LINEAR,
-        MODE_RADIAL
+        MODE_RADIAL,
+        MODE_SWATCH
     };
 
     SelectorMode mode;
@@ -56,6 +57,7 @@ struct SPGradientSelector {
 
     /* Spread selector */
     GtkWidget *spread;
+    GtkWidget *spreadLbl;
 
     void setMode(SelectorMode mode);
     void setUnits(SPGradientUnits units);
index 784e3f20fa92dfdef224128e2e78a46ca43f2135..077e038e70ca8270686d3c391549f37772b358cf 100644 (file)
@@ -315,7 +315,7 @@ void gr_read_selection( Inkscape::Selection *selection,
         if (style && (style->fill.isPaintserver())) {
             SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (item);
             if (SP_IS_GRADIENT(server)) {
-                SPGradient *gradient = sp_gradient_get_vector (SP_GRADIENT (server), false);
+                SPGradient *gradient = SP_GRADIENT(server)->getVector();
                 SPGradientSpread spread = sp_gradient_get_spread (SP_GRADIENT (server));
 
                 if (gradient && gradient->isSolid()) {
@@ -341,7 +341,7 @@ void gr_read_selection( Inkscape::Selection *selection,
         if (style && (style->stroke.isPaintserver())) {
             SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (item);
             if (SP_IS_GRADIENT(server)) {
-                SPGradient *gradient = sp_gradient_get_vector (SP_GRADIENT (server), false);
+                SPGradient *gradient = SP_GRADIENT(server)->getVector();
                 SPGradientSpread spread = sp_gradient_get_spread (SP_GRADIENT (server));
 
                 if (gradient && gradient->isSolid()) {
index 751898f4f0dd2091e364d4d184c5b613d99b1ce2..147077f44a0285ee0aa179a9911a9a75c53e3811 100644 (file)
@@ -116,6 +116,8 @@ static void sp_gradient_vector_selector_init(SPGradientVectorSelector *gvs)
 {
     gvs->idlabel = TRUE;
 
+    gvs->swatched = false;
+
     gvs->doc = NULL;
     gvs->gr = NULL;
 
@@ -250,7 +252,7 @@ static void sp_gvs_rebuild_gui_full(SPGradientVectorSelector *gvs)
         const GSList *gradients = sp_document_get_resource_list(SP_OBJECT_DOCUMENT(gvs->gr), "gradient");
         for (const GSList *curr = gradients; curr; curr = curr->next) {
             SPGradient* grad = SP_GRADIENT(curr->data);
-            if (SP_GRADIENT_HAS_STOPS(grad) && !grad->isSwatch()) {
+            if (SP_GRADIENT_HAS_STOPS(grad) && (grad->isSwatch() == gvs->swatched)) {
                 gl = g_slist_prepend(gl, curr->data);
             }
         }
@@ -402,6 +404,12 @@ static void sp_gvs_defs_modified(SPObject */*defs*/, guint /*flags*/, SPGradient
     sp_gvs_rebuild_gui_full(gvs);
 }
 
+void SPGradientVectorSelector::setSwatched()
+{
+    swatched = true;
+    sp_gvs_rebuild_gui_full(this);
+}
+
 /*##################################################################
   ###                 Vector Editing Widget
   ##################################################################*/
index ea1f5159fee1390b4c224c87bafe2e24218a1d9d..ceca9158cbfa372dcc1c9320412750354b6bba83 100644 (file)
@@ -6,7 +6,9 @@
  *
  * Author:
  *   Lauris Kaplinski <lauris@kaplinski.com>
+ *   Jon A. Cruz <jon@joncruz.org>
  *
+ * Copyright (C) 2010 Jon A. Cruz
  * Copyright (C) 2001-2002 Lauris Kaplinski
  * Copyright (C) 2001 Ximian, Inc.
  *
@@ -31,6 +33,8 @@ struct SPGradientVectorSelector {
 
     guint idlabel : 1;
 
+    bool swatched;
+
     SPDocument *doc;
     SPGradient *gr;
 
@@ -40,6 +44,9 @@ struct SPGradientVectorSelector {
     sigc::connection gradient_release_connection;
     sigc::connection defs_release_connection;
     sigc::connection defs_modified_connection;
+
+
+    void setSwatched();
 };
 
 struct SPGradientVectorSelectorClass {
index 59312b0d2871bc2c597f1b17618339df1b0c028b..5898563a543b9048e3ca4bfd8416ca93f68e3d57 100644 (file)
@@ -92,6 +92,40 @@ static void sp_paint_selector_set_style_buttons(SPPaintSelector *psel, GtkWidget
 static GtkVBoxClass *parent_class;
 static guint psel_signals[LAST_SIGNAL] = {0};
 
+#ifdef SP_PS_VERBOSE
+static gchar const* modeStrings[] = {
+    "MODE_EMPTY",
+    "MODE_MULTIPLE",
+    "MODE_NONE",
+    "MODE_COLOR_RGB",
+    "MODE_COLOR_CMYK",
+    "MODE_GRADIENT_LINEAR",
+    "MODE_GRADIENT_RADIAL",
+    "MODE_PATTERN",
+    "MODE_SWATCH",
+    "MODE_UNSET",
+    ".",
+    ".",
+    ".",
+};
+#endif
+
+static bool isPaintModeGradient( SPPaintSelectorMode mode )
+{
+    bool isGrad = (mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) ||
+        (mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL) ||
+        (mode == SP_PAINT_SELECTOR_MODE_SWATCH);
+
+    return isGrad;
+}
+
+static SPGradientSelector *getGradientFromData(SPPaintSelector *psel)
+{
+    gchar const* key = (psel->mode == SP_PAINT_SELECTOR_MODE_SWATCH) ? "swatch-selector" : "gradient-selector";
+    SPGradientSelector *grad = reinterpret_cast<SPGradientSelector*>(gtk_object_get_data(GTK_OBJECT(psel->selector), key));
+    return grad;
+}
+
 GType sp_paint_selector_get_type(void)
 {
     static GtkType type = 0;
@@ -330,7 +364,7 @@ sp_paint_selector_set_mode(SPPaintSelector *psel, SPPaintSelectorMode mode)
     if (psel->mode != mode) {
         psel->update = TRUE;
 #ifdef SP_PS_VERBOSE
-        g_print("Mode change %d -> %d\n", psel->mode, mode);
+        g_print("Mode change %d -> %d   %s -> %s\n", psel->mode, mode, modeStrings[psel->mode], modeStrings[mode]);
 #endif
         switch (mode) {
             case SP_PAINT_SELECTOR_MODE_EMPTY:
@@ -407,24 +441,27 @@ sp_paint_selector_set_color_alpha(SPPaintSelector *psel, SPColor const *color, f
     csel->base->setColorAlpha( *color, alpha );
 }
 
-void sp_paint_selector_set_swatch(SPPaintSelector *psel, SPPaintServer */*server*/ )
+void sp_paint_selector_set_swatch(SPPaintSelector *psel, SPGradient *vector )
 {
 #ifdef SP_PS_VERBOSE
     g_print("PaintSelector set SWATCH\n");
 #endif
     sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_SWATCH);
+
+    SPGradientSelector *gsel = static_cast<SPGradientSelector*>(gtk_object_get_data(GTK_OBJECT(psel->selector), "swatch-selector"));
+
+    gsel->setVector((vector) ? SP_OBJECT_DOCUMENT(vector) : 0, vector);
 }
 
 void
 sp_paint_selector_set_gradient_linear(SPPaintSelector *psel, SPGradient *vector)
 {
-    SPGradientSelector *gsel;
 #ifdef SP_PS_VERBOSE
     g_print("PaintSelector set GRADIENT LINEAR\n");
 #endif
     sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR);
 
-    gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector");
+    SPGradientSelector *gsel = getGradientFromData(psel);
 
     gsel->setMode(SPGradientSelector::MODE_LINEAR);
     gsel->setVector((vector) ? SP_OBJECT_DOCUMENT(vector) : 0, vector);
@@ -433,39 +470,34 @@ sp_paint_selector_set_gradient_linear(SPPaintSelector *psel, SPGradient *vector)
 void
 sp_paint_selector_set_gradient_radial(SPPaintSelector *psel, SPGradient *vector)
 {
-    SPGradientSelector *gsel;
 #ifdef SP_PS_VERBOSE
     g_print("PaintSelector set GRADIENT RADIAL\n");
 #endif
     sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL);
 
-    gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector");
+    SPGradientSelector *gsel = getGradientFromData(psel);
 
     gsel->setMode(SPGradientSelector::MODE_RADIAL);
 
     gsel->setVector((vector) ? SP_OBJECT_DOCUMENT(vector) : 0, vector);
 }
 
-void
-sp_paint_selector_set_gradient_properties(SPPaintSelector *psel, SPGradientUnits units, SPGradientSpread spread)
+void sp_paint_selector_set_gradient_properties(SPPaintSelector *psel, SPGradientUnits units, SPGradientSpread spread)
 {
-    SPGradientSelector *gsel;
     g_return_if_fail(SP_IS_PAINT_SELECTOR(psel));
-    g_return_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) ||
-                     (psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL));
-    gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector");
+    g_return_if_fail(isPaintModeGradient(psel->mode));
+
+    SPGradientSelector *gsel = getGradientFromData(psel);
     gsel->setUnits(units);
     gsel->setSpread(spread);
 }
 
-void
-sp_paint_selector_get_gradient_properties(SPPaintSelector *psel, SPGradientUnits *units, SPGradientSpread *spread)
+void sp_paint_selector_get_gradient_properties(SPPaintSelector *psel, SPGradientUnits *units, SPGradientSpread *spread)
 {
-    SPGradientSelector *gsel;
     g_return_if_fail(SP_IS_PAINT_SELECTOR(psel));
-    g_return_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) ||
-                     (psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL));
-    gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector");
+    g_return_if_fail(isPaintModeGradient(psel->mode));
+
+    SPGradientSelector *gsel = getGradientFromData(psel);
     if (units) {
         *units = gsel->getUnits();
     }
@@ -491,24 +523,23 @@ sp_paint_selector_get_color_alpha(SPPaintSelector *psel, SPColor *color, gfloat
                    && ( *alpha <= 1.0 ) ) );
 }
 
-SPGradient *
-sp_paint_selector_get_gradient_vector(SPPaintSelector *psel)
+SPGradient *sp_paint_selector_get_gradient_vector(SPPaintSelector *psel)
 {
-    SPGradientSelector *gsel;
-
-    g_return_val_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) ||
-                         (psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL), NULL);
+    SPGradient* vect = 0;
 
-    gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector");
+    if (isPaintModeGradient(psel->mode)) {
+        SPGradientSelector *gsel = getGradientFromData(psel);
+        vect = gsel->getVector();
+    }
 
-    return gsel->getVector();
+    return vect;
 }
 
 void
 sp_gradient_selector_attrs_to_gradient(SPGradient *gr, SPPaintSelector *psel)
 {
-    SPGradientUnits units;
-    SPGradientSpread spread;
+    SPGradientUnits units = SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX;
+    SPGradientSpread spread = SP_GRADIENT_SPREAD_PAD;
     sp_paint_selector_get_gradient_properties(psel, &units, &spread);
     sp_gradient_set_units(gr, units);
     sp_gradient_set_spread(gr, spread);
@@ -1066,38 +1097,30 @@ sp_paint_selector_get_pattern(SPPaintSelector *psel)
 static void sp_paint_selector_set_mode_swatch(SPPaintSelector *psel, SPPaintSelectorMode mode)
 {
     if (mode == SP_PAINT_SELECTOR_MODE_SWATCH) {
-        sp_paint_selector_set_style_buttons(psel, psel->swatch); // TODO swatch
+        sp_paint_selector_set_style_buttons(psel, psel->swatch);
     }
 
     gtk_widget_set_sensitive(psel->style, TRUE);
 
-    GtkWidget *tbl = NULL;
+    GtkWidget *tbl = 0;
 
     if (psel->mode == SP_PAINT_SELECTOR_MODE_SWATCH){
         /* Already have pattern menu */
-        tbl = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(psel->selector), "swatch-selector");
+        tbl = static_cast<GtkWidget*>(gtk_object_get_data(GTK_OBJECT(psel->selector), "swatch-selector"));
     } else {
         sp_paint_selector_clear_frame(psel);
-
-        /* Create vbox */
-        tbl = gtk_vbox_new(FALSE, 4);
-        gtk_widget_show(tbl);
-
-        {
-            GtkWidget *hb = gtk_hbox_new(FALSE, 0);
-            GtkWidget *l = gtk_label_new(NULL);
-            gtk_label_set_markup(GTK_LABEL(l), _("Represents a swatch fill."));
-            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;
-        gtk_object_set_data(GTK_OBJECT(psel->selector), "swatch-selector", tbl);
+        /* Create new gradient selector */
+        GtkWidget *gsel = sp_gradient_selector_new();
+        SP_GRADIENT_SELECTOR(gsel)->setMode(SPGradientSelector::MODE_SWATCH);
+        gtk_widget_show(gsel);
+        gtk_signal_connect(GTK_OBJECT(gsel), "grabbed", GTK_SIGNAL_FUNC(sp_paint_selector_gradient_grabbed), psel);
+        gtk_signal_connect(GTK_OBJECT(gsel), "dragged", GTK_SIGNAL_FUNC(sp_paint_selector_gradient_dragged), psel);
+        gtk_signal_connect(GTK_OBJECT(gsel), "released", GTK_SIGNAL_FUNC(sp_paint_selector_gradient_released), psel);
+        gtk_signal_connect(GTK_OBJECT(gsel), "changed", GTK_SIGNAL_FUNC(sp_paint_selector_gradient_changed), psel);
+        // Pack everything to frame
+        gtk_container_add(GTK_CONTAINER(psel->frame), gsel);
+        psel->selector = gsel;
+        gtk_object_set_data(GTK_OBJECT(psel->selector), "swatch-selector", gsel);
 
         gtk_frame_set_label(GTK_FRAME(psel->frame), _("Swatch fill"));
     }
@@ -1145,7 +1168,13 @@ SPPaintSelectorMode sp_style_determine_paint_selector_mode(SPStyle *style, bool
     } else if ( target.isPaintserver() ) {
         SPPaintServer *server = isfill? SP_STYLE_FILL_SERVER(style) : SP_STYLE_STROKE_SERVER(style);
 
-        if (server && server->isSwatch()) {
+
+#ifdef SP_PS_VERBOSE
+        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 = SP_PAINT_SELECTOR_MODE_SWATCH;
         } else if (SP_IS_LINEARGRADIENT(server)) {
             mode = SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR;
index 82dee4d16ff45b07e7b4df6a3fb2fac5fdd23262..2d7ac301180822755523bee838b6c308ebf1373b 100644 (file)
@@ -101,7 +101,7 @@ void sp_paint_selector_set_gradient_linear (SPPaintSelector *psel, SPGradient *v
 
 void sp_paint_selector_set_gradient_radial (SPPaintSelector *psel, SPGradient *vector);
 
-void sp_paint_selector_set_swatch(SPPaintSelector *psel, SPPaintServer *server );
+void sp_paint_selector_set_swatch(SPPaintSelector *psel, SPGradient *vector );
 
 void sp_paint_selector_set_gradient_properties (SPPaintSelector *psel, SPGradientUnits units, SPGradientSpread spread);
 void sp_paint_selector_get_gradient_properties (SPPaintSelector *psel, SPGradientUnits *units, SPGradientSpread *spread);
index 51e70807c3055070ece8d12ad02894277f49e475..a981934dd8c81a80012949c1505f4db58ad08c43 100644 (file)
@@ -205,9 +205,10 @@ sp_stroke_style_paint_update (SPWidget *spw)
                 SPPaintServer *server = SP_STYLE_STROKE_SERVER (query);
 
                 if (server && server->isSwatch()) {
-                    sp_paint_selector_set_swatch( psel, server );
+                    SPGradient *vector = SP_GRADIENT(server)->getVector();
+                    sp_paint_selector_set_swatch( psel, vector );
                 } else if (SP_IS_LINEARGRADIENT (server)) {
-                    SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE);
+                    SPGradient *vector = SP_GRADIENT(server)->getVector();
                     sp_paint_selector_set_gradient_linear (psel, vector);
 
                     SPLinearGradient *lg = SP_LINEARGRADIENT (server);
@@ -215,7 +216,7 @@ sp_stroke_style_paint_update (SPWidget *spw)
                                                        SP_GRADIENT_UNITS (lg),
                                                        SP_GRADIENT_SPREAD (lg));
                 } else if (SP_IS_RADIALGRADIENT (server)) {
-                    SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE);
+                    SPGradient *vector = SP_GRADIENT(server)->getVector();
                     sp_paint_selector_set_gradient_radial (psel, vector);
 
                     SPRadialGradient *rg = SP_RADIALGRADIENT (server);