Code

C++ify knotholders
authorcilix42 <cilix42@users.sourceforge.net>
Wed, 4 Jun 2008 12:19:54 +0000 (12:19 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Wed, 4 Jun 2008 12:19:54 +0000 (12:19 +0000)
32 files changed:
src/Makefile_insert
src/arc-context.cpp
src/arc-context.h
src/box3d-context.cpp
src/box3d-context.h
src/event-context.cpp
src/event-context.h
src/flood-context.h
src/gradient-context.h
src/knot-holder-entity.h
src/knot.cpp
src/knot.h
src/knotholder.cpp
src/knotholder.h
src/live_effects/effect.cpp
src/live_effects/effect.h
src/live_effects/parameter/point.cpp
src/live_effects/parameter/pointparam-knotholder.cpp
src/live_effects/parameter/pointparam-knotholder.h
src/node-context.h
src/object-edit.cpp
src/object-edit.h
src/rect-context.cpp
src/rect-context.h
src/shape-editor.cpp
src/shape-editor.h
src/spiral-context.cpp
src/spiral-context.h
src/star-context.cpp
src/star-context.h
src/text-context.cpp
src/vanishing-point.cpp

index a81b7a2f55f490ac8678e5dc1f93ccd6dd3c13e9..f49498092f3d7d58fe7b4454dfd62b8355facf3c 100644 (file)
@@ -95,7 +95,7 @@ libinkpre_a_SOURCES = \
        isnan.h isinf.h \
        isnormal.h \
        knot-enums.h    \
-       knot-holder-entity.h    \
+       knot-holder-entity.h knot-holder-entity.cpp     \
        knot.cpp knot.h \
        knotholder.cpp knotholder.h     \
        layer-fns.cpp layer-fns.h       \
index e3dc7161c290df51cb7a0b9f5827a81d8da92345..e1cbaf1ccb1aabd9419c62a554250c41ade09379 100644 (file)
@@ -123,7 +123,7 @@ static void sp_arc_context_dispose(GObject *object)
     ac->sel_changed_connection.~connection();
 
     if (ec->shape_knot_holder) {
-        sp_knot_holder_destroy(ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
         ec->shape_knot_holder = NULL;
     }
 
@@ -161,7 +161,7 @@ void sp_arc_context_selection_changed(Inkscape::Selection * selection, gpointer
     SPEventContext *ec = SP_EVENT_CONTEXT(ac);
 
     if (ec->shape_knot_holder) { // desktroy knotholder
-        sp_knot_holder_destroy(ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
         ec->shape_knot_holder = NULL;
     }
 
index 2ce008b4309d009acc4b2ab9932327142d54324f..6d16d4a91311f263860baa45d6acc7ffc3aed742 100644 (file)
@@ -19,7 +19,6 @@
 
 #include <libnr/nr-point.h>
 #include "event-context.h"
-struct SPKnotHolder;
 
 #define SP_TYPE_ARC_CONTEXT            (sp_arc_context_get_type())
 #define SP_ARC_CONTEXT(obj)            (GTK_CHECK_CAST((obj), SP_TYPE_ARC_CONTEXT, SPArcContext))
index c1af593d4f617b4ca437c85e23633a2d1bd26a44..e5acaba1f1b1d1bbb49b4a7b9ee60ce74c13ccdf 100644 (file)
@@ -141,7 +141,7 @@ static void sp_box3d_context_dispose(GObject *object)
     }
 
     if (ec->shape_knot_holder) {
-        sp_knot_holder_destroy(ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
         ec->shape_knot_holder = NULL;
     }
 
@@ -176,7 +176,7 @@ static void sp_box3d_context_selection_changed(Inkscape::Selection *selection, g
     SPEventContext *ec = SP_EVENT_CONTEXT(bc);
 
     if (ec->shape_knot_holder) { // destroy knotholder
-        sp_knot_holder_destroy(ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
         ec->shape_knot_holder = NULL;
     }
 
index 38058b1cb195eaf4a6e2a8ed7da0086eabdb9792..3432a1a5b899d0005d6238da8ddca23e13c09a39 100644 (file)
@@ -20,8 +20,6 @@
 #include "proj_pt.h"
 #include "vanishing-point.h"
 
-struct SPKnotHolder;
-
 #define SP_TYPE_BOX3D_CONTEXT            (sp_box3d_context_get_type ())
 #define SP_BOX3D_CONTEXT(obj)            (GTK_CHECK_CAST ((obj), SP_TYPE_BOX3D_CONTEXT, Box3DContext))
 #define SP_BOX3D_CONTEXT_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), SP_TYPE_BOX3D_CONTEXT, Box3DContextClass))
index f482c99fb0dc6d0880591e0c37e4d19f6ee9fde8..017c06c166a4f47fcdbaa65a64f3de359cd8de16 100644 (file)
@@ -1053,7 +1053,7 @@ ec_shape_event_attr_changed(Inkscape::XML::Node */*shape_repr*/, gchar const *na
     SPEventContext *ec = SP_EVENT_CONTEXT(data);
 
     if (ec->shape_knot_holder) {
-        sp_knot_holder_destroy(ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
     }
     ec->shape_knot_holder = NULL;
 
index 8b0b5d128b083045f40b5a8134fc7491ee0852ba..3a745a6a2c4cafb6d8c4f89268a9cc2003e89306 100644 (file)
@@ -24,8 +24,7 @@
 struct GrDrag;
 struct SPDesktop;
 struct SPItem;
-struct SPKnotHolder;
-
+class KnotHolder;
 namespace NR {
     class Point;
 }
@@ -72,7 +71,7 @@ struct SPEventContext : public GObject {
     GrDrag *_grdrag;
     GrDrag *get_drag () {return _grdrag;}
 
-    SPKnotHolder *shape_knot_holder;
+    KnotHolder *shape_knot_holder;
     Inkscape::XML::Node *shape_repr;
 
     bool space_panning;
index a0d9e7d44fbbc4d0c10776abc05ba90fbc2e80b2..af537dea059e42f3778706183d1e4fb2207db075 100644 (file)
@@ -17,8 +17,6 @@
 #include "helper/unit-menu.h"
 #include "helper/units.h"
 
-struct SPKnotHolder;
-
 #define SP_TYPE_FLOOD_CONTEXT            (sp_flood_context_get_type ())
 #define SP_FLOOD_CONTEXT(obj)            (GTK_CHECK_CAST ((obj), SP_TYPE_FLOOD_CONTEXT, SPFloodContext))
 #define SP_FLOOD_CONTEXT_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), SP_TYPE_FLOOD_CONTEXT, SPFloodContextClass))
index d0fe0d421ed3179a1939536b3f116cd99e3e6ebe..ac46826361b717ac3f0f075cdf6f8cfed52c2fe3 100644 (file)
@@ -17,7 +17,6 @@
 #include <sigc++/sigc++.h>
 #include "event-context.h"
 #include "libnr/nr-point.h"
-struct SPKnotHolder;
 
 #define SP_TYPE_GRADIENT_CONTEXT            (sp_gradient_context_get_type())
 #define SP_GRADIENT_CONTEXT(obj)            (GTK_CHECK_CAST((obj), SP_TYPE_GRADIENT_CONTEXT, SPGradientContext))
index bbc0c5634d4a32fb5096b45dddac93213d1d00ea..854182726a836bc586a3fe40f11499f42496dbea 100644 (file)
@@ -2,20 +2,23 @@
 #define SEEN_KNOT_HOLDER_ENTITY_H
 
 /** \file 
- * SPKnotHolderEntity definition. 
+ * KnotHolderEntity definition. 
  * 
  * Authors:
  *   Mitsuru Oka <oka326@parkcity.ne.jp>
+ *   Maximilian Albert <maximilian.albert@gmail.com>
  *
  * Copyright (C) 1999-2001 Lauris Kaplinski
  * Copyright (C) 2000-2001 Ximian, Inc.
  * Copyright (C) 2001 Mitsuru Oka
  * Copyright (C) 2004 Monash University
+ * Copyright (C) 2008 Maximilian Albert
  *
  * Released under GNU GPL
  */
 
 #include <glib/gtypes.h>
+#include "knot.h"
 
 struct SPItem;
 struct SPKnot;
@@ -23,9 +26,39 @@ namespace NR {
 class Point;
 }
 
-/// SPKnotHolderEntity definition. 
-struct SPKnotHolderEntity {
+class SPDesktop;
+class KnotHolder;
+
+typedef void (* SPKnotHolderSetFunc) (SPItem *item, NR::Point const &p, NR::Point const &origin, guint state);
+typedef NR::Point (* SPKnotHolderGetFunc) (SPItem *item);
+/* fixme: Think how to make callbacks most sensitive (Lauris) */
+typedef void (* SPKnotHolderReleasedFunc) (SPItem *item);
+
+class KnotHolderEntity {
+public:
+    KnotHolderEntity() {}
+    virtual ~KnotHolderEntity();
+    virtual void create(SPDesktop *desktop, SPItem *item, KnotHolder *parent, const gchar *tip = "", 
+                        SPKnotShapeType shape = SP_KNOT_SHAPE_DIAMOND,
+                        SPKnotModeType mode = SP_KNOT_MODE_XOR,
+                        guint32 color = 0xffffff00);
+
+    /* the get/set/click handlers are virtual functions; each handler class for a knot
+       should be derived from KnotHolderEntity and override these functions */
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+    virtual NR::Point knot_get_func();
+    virtual void knot_click_func(guint state);
+
+    void update_knot();
+
+//private:
     SPKnot *knot;
+    SPItem *item;
+
+    KnotHolder *parent_holder;
+
+    int my_counter;
+    static int counter;
 
     /** Connection to \a knot's "moved" signal. */
     guint   handler_id;
@@ -34,6 +67,10 @@ struct SPKnotHolderEntity {
     /** Connection to \a knot's "ungrabbed" signal. */
     guint   _ungrab_handler_id;
 
+    sigc::connection _moved_connection;
+    sigc::connection _click_connection;
+    sigc::connection _ungrabbed_connection;
+
     /**
      * Called solely from knot_moved_handler.
      *
@@ -51,6 +88,25 @@ struct SPKnotHolderEntity {
     void (* knot_click) (SPItem *item, guint state);
 };
 
+/* pattern manipulation */
+
+class PatternKnotHolderEntityXY : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
+
+class PatternKnotHolderEntityAngle : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
+
+class PatternKnotHolderEntityScale : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
 
 #endif /* !SEEN_KNOT_HOLDER_ENTITY_H */
 
index cbb923d41a877d9b0d140687e1196758c0c85769..4e4cf567806513622b584ccaa56bd144c9e9b286 100644 (file)
@@ -335,10 +335,12 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot
                         g_signal_emit(knot,
                                       knot_signals[UNGRABBED], 0,
                                       event->button.state);
+                        knot->_ungrabbed_signal.emit();
                     } else {
                         g_signal_emit(knot,
                                       knot_signals[CLICKED], 0,
                                       event->button.state);
+                        knot->_click_signal.emit(knot, event->button.state);
                     }
                     grabbed = FALSE;
                     moved = FALSE;
@@ -560,6 +562,7 @@ void sp_knot_set_position(SPKnot *knot, NR::Point *p, guint state)
                   knot_signals[MOVED], 0,
                   p,
                   state);
+    knot->_moved_signal.emit(knot, p, state);
 }
 
 /**
index bba49f3e7479c932d9ebbf1e1ec4ad69a5d2c749..07f5040fac30087c2a921605377332ebf0a7a1c3 100644 (file)
@@ -20,6 +20,7 @@
 #include "forward.h"
 #include <libnr/nr-point.h>
 #include "knot-enums.h"
+#include <sigc++/sigc++.h>
 
 class SPKnot;
 class SPKnotClass;
@@ -65,6 +66,16 @@ struct SPKnot : GObject {
 
     double pressure; /**< The tablet pen pressure when the knot is being dragged. */
 
+    // C++ signals
+    /**
+    sigc::signal<void, NR::Point const &, NR::Point const &, guint> _moved_signal;
+    sigc::signal<void, guint> _click_signal;
+    sigc::signal<NR::Point> _ungrabbed_signal;
+    **/
+    sigc::signal<void, SPKnot *, NR::Point const *, guint> _moved_signal;
+    sigc::signal<void, SPKnot *, guint> _click_signal;
+    sigc::signal<void> _ungrabbed_signal;
+
     //TODO: all the members above should eventualle become private, accessible via setters/getters
     inline void setSize (guint i) {size = i;}
     inline void setShape (guint i) {shape = (SPKnotShapeType) i;}
index 161e779d1baf97b7134dec2375baeae60c80667b..b589d18c5bf65baadda28edfe2c3f3ec1cbf718c 100644 (file)
@@ -6,20 +6,17 @@
  * Authors:
  *   Mitsuru Oka <oka326@parkcity.ne.jp>
  *   bulia byak <buliabyak@users.sf.net>
+ *   Maximilian Albert <maximilian.albert@gmail.com>
  *
- * Copyright (C) 2001-2005 authors
+ * Copyright (C) 2001-2008 authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
 
-#define noKNOT_HOLDER_DEBUG
-
-
 #include "document.h"
 #include "sp-shape.h"
 #include "knot.h"
 #include "knotholder.h"
-#include "knot-holder-entity.h"
 #include "rect-context.h"
 #include "sp-rect.h"
 #include "arc-context.h"
 #include "sp-spiral.h"
 #include "sp-offset.h"
 #include "box3d.h"
+#include "sp-pattern.h"
+#include "style.h"
+
+#include "xml/repr.h" // for debugging only
 
 #include <libnr/nr-matrix-div.h>
 #include <glibmm/i18n.h>
 
 class SPDesktop;
 
-static void knot_clicked_handler (SPKnot *knot, guint state, gpointer data);
-static void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gpointer data);
-static void knot_ungrabbed_handler (SPKnot *knot, unsigned int state, SPKnotHolder *kh);
-static void sp_knot_holder_class_init(SPKnotHolderClass *klass);
+//static void knot_clicked_handler (SPKnot *knot, guint state, gpointer data);
+//static void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gpointer data);
+//static void knot_ungrabbed_handler (SPKnot *knot, unsigned int state, KnotHolder *kh);
 
-void sp_knot_holder_dispose(GObject *object);
-
-#ifdef KNOT_HOLDER_DEBUG
-
-static void sp_knot_holder_debug(GtkObject *object, gpointer data)
-{
-    g_print("sp-knot-holder-debug: [type=%s] [data=%s]\n", gtk_type_name(GTK_OBJECT_TYPE(object)), (const gchar *) data);
-}
-#endif
-
-static GObjectClass *parent_class;
-
-/**
- * Registers SPKnotHolder class and returns its type number.
- */
-GType sp_knot_holder_get_type()
-{
-    static GType type = 0;
-    if (!type) {
-        GTypeInfo info = {
-            sizeof(SPKnotHolderClass),
-            NULL,      /* base_init */
-            NULL,      /* base_finalize */
-            (GClassInitFunc) sp_knot_holder_class_init,
-            NULL,      /* class_finalize */
-            NULL,      /* class_data */
-            sizeof (SPKnotHolder),
-            16,        /* n_preallocs */
-            NULL,
-            NULL
-        };
-        type = g_type_register_static (G_TYPE_OBJECT, "SPKnotHolder", &info, (GTypeFlags) 0);
-    }
-    return type;
-}
-
-/**
- * SPKnotHolder vtable initialization.
- */
-static void sp_knot_holder_class_init(SPKnotHolderClass *klass){
-    parent_class = (GObjectClass*) g_type_class_peek_parent(klass);
-    klass->dispose = sp_knot_holder_dispose;
-}
-
-SPKnotHolder *sp_knot_holder_new(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler)
+KnotHolder::KnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler)
 {
     Inkscape::XML::Node *repr = SP_OBJECT(item)->repr;
 
-    g_return_val_if_fail(desktop != NULL, NULL);
-    g_return_val_if_fail(item != NULL, NULL);
-    g_return_val_if_fail(SP_IS_ITEM(item), NULL);
-
-    SPKnotHolder *knot_holder = (SPKnotHolder*)g_object_new (SP_TYPE_KNOT_HOLDER, 0);
-    knot_holder->desktop = desktop;
-    knot_holder->item = item;
-    g_object_ref(G_OBJECT(item));
-    knot_holder->entity = NULL;
-
-    knot_holder->released = relhandler;
+    if (!desktop || !item || !SP_IS_ITEM(item)) {
+        g_print ("Error! Throw an exception, please!\n");
+    }
 
-    knot_holder->repr = repr;
-    knot_holder->local_change = FALSE;
+    this->desktop = desktop;
+    this->item = item;
+    g_object_ref(G_OBJECT(item)); // TODO: is this still needed after C++-ification?
 
-#ifdef KNOT_HOLDER_DEBUG
-    g_signal_connect(G_OBJECT(desktop), "destroy", sp_knot_holder_debug, (gpointer) "SPKnotHolder::item");
-#endif
+    this->released = relhandler;
 
-    return knot_holder;
+    this->repr = repr;
+    this->local_change = FALSE;
 }
 
-void sp_knot_holder_dispose(GObject *object) {
-    SPKnotHolder *kh = G_TYPE_CHECK_INSTANCE_CAST((object), SP_TYPE_KNOT_HOLDER, SPKnotHolder);
-
-    g_object_unref(G_OBJECT(kh->item));
-    while (kh->entity) {
-        SPKnotHolderEntity *e = (SPKnotHolderEntity *) kh->entity->data;
-        g_signal_handler_disconnect(e->knot, e->_click_handler_id);
-        g_signal_handler_disconnect(e->knot, e->_ungrab_handler_id);
-        /* unref should call destroy */
-        g_object_unref(e->knot);
-        g_free(e);
-        kh->entity = g_slist_remove(kh->entity, e);
+KnotHolder::~KnotHolder() {
+    g_object_unref(G_OBJECT(item));
+    for(std::list<KnotHolderEntity *>::iterator i = entity.begin(); i != entity.end(); ++i) {
+        delete *i;
     }
+    entity.clear(); // this shouldn't be necessary, though
 }
 
+/** TODO: is this still needed?
 void sp_knot_holder_destroy(SPKnotHolder *kh) {
     g_object_unref(kh);
     }
-
-void sp_knot_holder_add(
-    SPKnotHolder *knot_holder,
-    SPKnotHolderSetFunc knot_set,
-    SPKnotHolderGetFunc knot_get,
-    void (* knot_click) (SPItem *item, guint state),
-    const gchar *tip
-    )
-{
-    sp_knot_holder_add_full(knot_holder, knot_set, knot_get, knot_click, SP_KNOT_SHAPE_DIAMOND, SP_KNOT_MODE_XOR, tip);
-}
-
-void sp_knot_holder_add_full(
-    SPKnotHolder *knot_holder,
-    SPKnotHolderSetFunc knot_set,
-    SPKnotHolderGetFunc knot_get,
-    void (* knot_click) (SPItem *item, guint state),
-    SPKnotShapeType     shape,
-    SPKnotModeType      mode,
-    const gchar *tip
-    )
-{
-    g_return_if_fail(knot_holder != NULL);
-    g_return_if_fail(knot_set != NULL);
-    g_return_if_fail(knot_get != NULL);
-       
-    SPItem *item = SP_ITEM(knot_holder->item);
-
-    /* create new SPKnotHolderEntry */
-    SPKnotHolderEntity *e = g_new(SPKnotHolderEntity, 1);
-    e->knot = sp_knot_new(knot_holder->desktop, tip);
-    e->knot_set = knot_set;
-    e->knot_get = knot_get;
-    if (knot_click) {
-        e->knot_click = knot_click;
-    } else {
-        e->knot_click = NULL;
-    }
-
-    g_object_set(G_OBJECT (e->knot->item), "shape", shape, NULL);
-    g_object_set(G_OBJECT (e->knot->item), "mode", mode, NULL);
-
-    // TODO: add a color argument
-    //e->knot->fill [SP_KNOT_STATE_NORMAL] = 0x00ff0000;
-    //g_object_set (G_OBJECT (e->knot->item), "fill_color", 0x00ff0000, NULL);
-
-    knot_holder->entity = g_slist_append(knot_holder->entity, e);
-
-    /* Move to current point. */
-    NR::Point dp = e->knot_get(item) * sp_item_i2d_affine(item);
-    sp_knot_set_position(e->knot, &dp, SP_KNOT_STATE_NORMAL);
-
-    e->handler_id = g_signal_connect(e->knot, "moved", G_CALLBACK(knot_moved_handler), knot_holder);
-    e->_click_handler_id = g_signal_connect(e->knot, "clicked", G_CALLBACK(knot_clicked_handler), knot_holder);
-    e->_ungrab_handler_id = g_signal_connect(e->knot, "ungrabbed", G_CALLBACK(knot_ungrabbed_handler), knot_holder);
-
-#ifdef KNOT_HOLDER_DEBUG
-    g_signal_connect(ob, "destroy", sp_knot_holder_debug, "SPKnotHolder::knot");
-#endif
-    sp_knot_show(e->knot);
-}
+**/
 
 /**
  * \param p In desktop coordinates.
  */
 
-//static
-void knotholder_update_knots(SPKnotHolder *knot_holder, SPItem *item)
+void
+KnotHolder::update_knots()
 {
     NR::Matrix const i2d(sp_item_i2d_affine(item));
 
-    for (GSList *el = knot_holder->entity; el; el = el->next) {
-        SPKnotHolderEntity *e = (SPKnotHolderEntity *) el->data;
-        GObject *kob = e->knot;
-
-        NR::Point dp( e->knot_get(item) * i2d );
-        g_signal_handler_block(kob, e->handler_id);
-        sp_knot_set_position(e->knot, &dp, SP_KNOT_STATE_NORMAL);
-        g_signal_handler_unblock(kob, e->handler_id);
+    for(std::list<KnotHolderEntity *>::iterator i = entity.begin(); i != entity.end(); ++i) {
+        KnotHolderEntity *e = *i;
+        e->update_knot();
     }
 }
 
-static void knot_clicked_handler(SPKnot *knot, guint state, gpointer data)
+void
+KnotHolder::knot_clicked_handler(SPKnot *knot, guint state)
 {
-    SPKnotHolder *knot_holder = (SPKnotHolder *) data;
-    SPItem *item  = SP_ITEM (knot_holder->item);
+    KnotHolder *knot_holder = this;
 
-    g_object_ref(knot_holder);
-    for (GSList *el = knot_holder->entity; el; el = el->next) {
-        SPKnotHolderEntity *e = (SPKnotHolderEntity *) el->data;
+    for(std::list<KnotHolderEntity *>::iterator i = knot_holder->entity.begin(); i != knot_holder->entity.end(); ++i) {
+        KnotHolderEntity *e = *i;
         if (e->knot == knot) {
-            if (e->knot_click) {
-                e->knot_click(item, state);
-            }
+            // no need to test whether knot_click exists since it's virtual now
+            e->knot_click_func(state);
             break;
         }
     }
@@ -231,8 +106,7 @@ static void knot_clicked_handler(SPKnot *knot, guint state, gpointer data)
         sp_shape_set_shape(SP_SHAPE(item));
     }
 
-    knotholder_update_knots(knot_holder, item);
-    g_object_unref(knot_holder);
+    knot_holder->update_knots();
 
     unsigned int object_verb = SP_VERB_NONE;
 
@@ -254,22 +128,21 @@ static void knot_clicked_handler(SPKnot *knot, guint state, gpointer data)
     }
 
     // for drag, this is done by ungrabbed_handler, but for click we must do it here
-    sp_document_done(SP_OBJECT_DOCUMENT(knot_holder->item), object_verb, 
+    sp_document_done(SP_OBJECT_DOCUMENT(item), object_verb, 
                      _("Change handle"));
 }
 
-static void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gpointer data)
+void
+KnotHolder::knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state)
 {
-    SPKnotHolder *knot_holder = (SPKnotHolder *) data;
-    SPItem *item  = SP_ITEM (knot_holder->item);
     // this was a local change and the knotholder does not need to be recreated:
-    knot_holder->local_change = TRUE;
+    this->local_change = TRUE;
 
-    for (GSList *el = knot_holder->entity; el; el = el->next) {
-        SPKnotHolderEntity *e = (SPKnotHolderEntity *) el->data;
+    for(std::list<KnotHolderEntity *>::iterator i = this->entity.begin(); i != this->entity.end(); ++i) {
+        KnotHolderEntity *e = *i;
         if (e->knot == knot) {
             NR::Point const q = *p / sp_item_i2d_affine(item);
-            e->knot_set(item, q, e->knot->drag_origin / sp_item_i2d_affine(item), state);
+            e->knot_set_func(q, e->knot->drag_origin / sp_item_i2d_affine(item), state);
             break;
         }
     }
@@ -278,15 +151,16 @@ static void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gp
         sp_shape_set_shape(SP_SHAPE (item));
     }
 
-    knotholder_update_knots(knot_holder, item);
+    this->update_knots();
 }
 
-static void knot_ungrabbed_handler(SPKnot */*knot*/, unsigned int /*state*/, SPKnotHolder *kh)
+void
+KnotHolder::knot_ungrabbed_handler()
 {
-    if (kh->released) {
-        kh->released(kh->item);
+    if (this->released) {
+        this->released(this->item);
     } else {
-        SPObject *object = (SPObject *) kh->item;
+        SPObject *object = (SPObject *) this->item;
         object->updateRepr(object->repr, SP_OBJECT_WRITE_EXT);
 
         unsigned int object_verb = SP_VERB_NONE;
@@ -313,6 +187,31 @@ static void knot_ungrabbed_handler(SPKnot */*knot*/, unsigned int /*state*/, SPK
     }
 }
 
+void
+KnotHolder::add_pattern_knotholder()
+{
+    if ((SP_OBJECT(item)->style->fill.isPaintserver())
+        && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
+    {
+        PatternKnotHolderEntityXY *entity_xy = new PatternKnotHolderEntityXY();
+        PatternKnotHolderEntityAngle *entity_angle = new PatternKnotHolderEntityAngle();
+        PatternKnotHolderEntityScale *entity_scale = new PatternKnotHolderEntityScale();
+        entity_xy->create(desktop, item, this,
+                          // TRANSLATORS: This refers to the pattern that's inside the object
+                          _("<b>Move</b> the pattern fill inside the object"),
+                          SP_KNOT_SHAPE_CROSS);
+        entity_angle->create(desktop, item, this,
+                             _("<b>Scale</b> the pattern fill uniformly"),
+                             SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
+        entity_scale->create(desktop, item, this,
+                             _("<b>Rotate</b> the pattern fill; with <b>Ctrl</b> to snap angle"),
+                             SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR);
+        entity.push_back(entity_xy);
+        entity.push_back(entity_angle);
+        entity.push_back(entity_scale);
+    }
+}
+
 /*
   Local Variables:
   mode:c++
index fd09c7b23fb4ee2802fffd181087e0718a7405f9..316db208217e74317b56227b9c304966b860848c 100644 (file)
@@ -2,14 +2,16 @@
 #define __SP_KNOTHOLDER_H__
 
 /*
- * SPKnotHolder - Hold SPKnot list and manage signals
+ * KnotHolder - Hold SPKnot list and manage signals
  *
  * Author:
  *   Mitsuru Oka <oka326@parkcity.ne.jp>
+ *   Maximilian Albert <maximilian.albert@gmail.com>
  *
  * Copyright (C) 1999-2001 Lauris Kaplinski
  * Copyright (C) 2000-2001 Ximian, Inc.
  * Copyright (C) 2001 Mitsuru Oka
+ * Copyright (C) 2008 Maximilian Albert
  *
  * Released under GNU GPL
  *
@@ -19,6 +21,8 @@
 #include "knot-enums.h"
 #include "forward.h"
 #include "libnr/nr-forward.h"
+#include "knot-holder-entity.h"
+#include <list>
 
 namespace Inkscape {
 namespace XML {
@@ -32,10 +36,24 @@ typedef NR::Point (* SPKnotHolderGetFunc) (SPItem *item);
 /* fixme: Think how to make callbacks most sensitive (Lauris) */
 typedef void (* SPKnotHolderReleasedFunc) (SPItem *item);
 
-struct SPKnotHolder : GObject {
+class KnotHolder {
+public:
+    KnotHolder() {} // do nothing in the default constructor
+    KnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler);
+    virtual ~KnotHolder();
+
+    void update_knots();
+
+    void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state);
+    void knot_clicked_handler(SPKnot *knot, guint state);
+    void knot_ungrabbed_handler();
+
+    void add_pattern_knotholder();
+
+//private:
     SPDesktop *desktop;
-    SPItem *item;
-    GSList *entity;
+    SPItem *item; // TODO: Remove this and keep the actual item (e.g., SPRect etc.) in the item-specific knotholders
+    std::list<KnotHolderEntity *> entity;
 
     SPKnotHolderReleasedFunc released;
 
@@ -44,34 +62,11 @@ struct SPKnotHolder : GObject {
     gboolean local_change; ///< if true, no need to recreate knotholder if repr was changed.
 };
 
-struct SPKnotHolderClass : GObjectClass {
-};
-
-/* fixme: As a temporary solution, if released is NULL knotholder flushes undo itself (Lauris) */
-SPKnotHolder *sp_knot_holder_new(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler);
-
-void sp_knot_holder_destroy(SPKnotHolder *knots);
-
-void sp_knot_holder_add(SPKnotHolder *knot_holder,
-                        SPKnotHolderSetFunc knot_set,
-                        SPKnotHolderGetFunc knot_get,
-                        void (* knot_click) (SPItem *item, guint state),
-                        gchar const *tip);
-
-void sp_knot_holder_add_full(SPKnotHolder *knot_holder,
-                             SPKnotHolderSetFunc knot_set,
-                             SPKnotHolderGetFunc knot_get,
-                             void (* knot_click) (SPItem *item, guint state),
-                             SPKnotShapeType shape,
-                             SPKnotModeType mode,
-                             gchar const *tip);
-
-GType sp_knot_holder_get_type();
-
-// FIXME: This is an ugly hack! What is the right way to update the knots from VPDrag::updateBoxHandles() ?
-void knotholder_update_knots(SPKnotHolder *knot_holder, SPItem *item);
-
-#define SP_TYPE_KNOT_HOLDER      (sp_knot_holder_get_type())
+/**
+void knot_clicked_handler(SPKnot *knot, guint state, gpointer data);
+void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gpointer data);
+void knot_ungrabbed_handler(SPKnot *knot, unsigned int state, KnotHolder *kh);
+**/
 
 #endif /* !__SP_KNOTHOLDER_H__ */
 
index f968ec5c086e2436857300062319b754acb46f77..639ad93a48ee34ecf60eeb1e1d8028e14f2b7365 100644 (file)
@@ -319,10 +319,10 @@ Effect::registerKnotHolderHandle(SPKnotHolderSetFunc set_func, SPKnotHolderGetFu
 
 // TODO: allow for adding click_functions and description strings, too
 void
-Effect::addHandles(SPKnotHolder *knotholder) {
+Effect::addHandles(KnotHolder *knotholder) {
     std::vector<std::pair<SPKnotHolderSetFunc, SPKnotHolderGetFunc> >::iterator i;
     for (i = knotholder_func_vector.begin(); i != knotholder_func_vector.end(); ++i) {
-        sp_knot_holder_add(knotholder, i->first, i->second, NULL, (""));
+        //knotholder->add(i->first, i->second, NULL, (""));
     }
 }
 
index d5a49d71ed8235e4195d87b9eed11a8940b7dd7d..6d72a56151f5ec2e834e6ea29da5195507e31fcd 100644 (file)
@@ -100,7 +100,7 @@ public:
     virtual void transform_multiply(Geom::Matrix const& postmul, bool set);
 
     bool providesKnotholder() { return knotholder_func_vector.size() > 0; }
-    void addHandles(SPKnotHolder *knotholder);
+    void addHandles(KnotHolder *knotholder);
 
     Glib::ustring          getName();
     Inkscape::XML::Node *  getRepr();
index a54be8baa76aaf3a495eb2076d5996bb31e3bbf8..28d5dae704d9a85e7f75fa52752e1c114c1c282c 100644 (file)
@@ -136,7 +136,7 @@ PointParam::param_editOncanvas(SPItem * item, SPDesktop * dt)
         tools_switch_current(TOOLS_NODES);
     }
 
-    PointParamKnotHolder * kh =  pointparam_knot_holder_new( dt, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str(), item);
+    PointParamKnotHolder * kh =  new PointParamKnotHolder(dt, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str(), item);
     if (kh) {
         kh->add_knot(* dynamic_cast<Geom::Point *>( this ), NULL, knot_shape, knot_mode, knot_color, param_getTooltip()->c_str() );
 
index 55cb812093a6b9bdc2a4e90f60aa7f5594f663d4..8e929a59ef19cbc3fdb5aca5e989da785c5ae883 100644 (file)
@@ -33,86 +33,31 @@ namespace Inkscape {
 static void pointparam_knot_clicked_handler (SPKnot *knot, guint state, PointParamKnotHolder *kh);
 static void pointparam_knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, PointParamKnotHolder *kh);
 static void pointparam_knot_ungrabbed_handler (SPKnot *knot, unsigned int state, PointParamKnotHolder *kh);
-static void pointparam_knot_holder_class_init(PointParamKnotHolderClass *klass);
 
-void pointparam_knot_holder_dispose(GObject *object);
-
-static SPKnotHolderClass *parent_class;
-
-/**
- * Registers PointParamKnotHolder class and returns its type number.
- */
-GType pointparam_knot_holder_get_type()
+PointParamKnotHolder::PointParamKnotHolder(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item)
 {
-    static GType type = 0;
-    if (!type) {
-        GTypeInfo info = {
-            sizeof(PointParamKnotHolderClass),
-            NULL,      /* base_init */
-            NULL,      /* base_finalize */
-            (GClassInitFunc) pointparam_knot_holder_class_init,
-            NULL,      /* class_finalize */
-            NULL,      /* class_data */
-            sizeof (PointParamKnotHolder),
-            16,        /* n_preallocs */
-            NULL,
-            NULL
-        };
-        type = g_type_register_static (G_TYPE_OBJECT, "InkscapePointParamKnotHolder", &info, (GTypeFlags) 0);
+    if (!desktop || !item || !SP_IS_ITEM(item)) {
+        g_print ("Error! Throw an exception, please!\n");
     }
-    return type;
-}
-
-/**
- * PointParamKnotHolder vtable initialization.
- */
-static void pointparam_knot_holder_class_init(PointParamKnotHolderClass *klass)
-{
-    GObjectClass *gobject_class;
-    gobject_class = (GObjectClass *) klass;
 
-    parent_class = (SPKnotHolderClass*) g_type_class_peek_parent(klass);
-    gobject_class->dispose = pointparam_knot_holder_dispose;
-}
-
-PointParamKnotHolder *pointparam_knot_holder_new(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item)
-{
-    g_return_val_if_fail(desktop != NULL, NULL);
-    g_return_val_if_fail(item != NULL, NULL);
-    g_return_val_if_fail(SP_IS_ITEM(item), NULL);
-
-    PointParamKnotHolder *knot_holder = (PointParamKnotHolder*)g_object_new (INKSCAPE_TYPE_POINTPARAM_KNOT_HOLDER, 0);
-    knot_holder->desktop = desktop;
-    knot_holder->item = item;
-    knot_holder->lpeobject = LIVEPATHEFFECT(lpeobject);
+    this->desktop = desktop;
+    this->item = item;
+    this->lpeobject = LIVEPATHEFFECT(lpeobject);
     g_object_ref(G_OBJECT(item));
     g_object_ref(G_OBJECT(lpeobject));
-    knot_holder->entity = NULL;
 
-    knot_holder->released = NULL;
+    this->released = NULL;
 
-    knot_holder->repr = lpeobject->repr;
-    knot_holder->repr_key = key;
+    this->repr = lpeobject->repr;
+    this->repr_key = key;
 
-    knot_holder->local_change = FALSE;
-
-    return knot_holder;
+    this->local_change = FALSE;
 }
 
-void pointparam_knot_holder_dispose(GObject *object) {
-    PointParamKnotHolder *kh = G_TYPE_CHECK_INSTANCE_CAST((object), INKSCAPE_TYPE_POINTPARAM_KNOT_HOLDER, PointParamKnotHolder);
-
-    g_object_unref(G_OBJECT(kh->item));
-    g_object_unref(G_OBJECT(kh->lpeobject));
-    while (kh->entity) {
-        SPKnotHolderEntity *e = (SPKnotHolderEntity *) kh->entity->data;
-        g_signal_handler_disconnect(e->knot, e->_click_handler_id);
-        g_signal_handler_disconnect(e->knot, e->_ungrab_handler_id);
-        /* unref should call destroy */
-        g_object_unref(e->knot);
-        g_free(e);
-        kh->entity = g_slist_remove(kh->entity, e);
-    }
+PointParamKnotHolder::~PointParamKnotHolder()
+{
+    g_object_unref(G_OBJECT(this->item));
+    g_object_unref(G_OBJECT(this->lpeobject));
 }
 
 void
@@ -125,25 +70,13 @@ PointParamKnotHolder::add_knot (
     const gchar *tip )
 {
     /* create new SPKnotHolderEntry */
-    SPKnotHolderEntity *e = g_new(SPKnotHolderEntity, 1);
-    e->knot = sp_knot_new(desktop, tip);
-    e->knot_set = NULL;
-    e->knot_get = NULL;
-    if (knot_click) {
-        e->knot_click = knot_click;
-    } else {
-        e->knot_click = NULL;
-    }
-
-    g_object_set(G_OBJECT (e->knot->item), "shape", shape, NULL);
-    g_object_set(G_OBJECT (e->knot->item), "mode", mode, NULL);
-
-    e->knot->fill [SP_KNOT_STATE_NORMAL] = color;
-    g_object_set (G_OBJECT (e->knot->item), "fill_color", color, NULL);
+    // TODO: knot_click can't be set any more with the new KnotHolder design; make it a virtual function?
+    KnotHolderEntity *e = new KnotHolderEntity();
+    e->create(this->desktop, this->item, this, tip, shape, mode, color);
 
-    entity = g_slist_append(entity, e);
+    entity.push_back(e);
 
-    /* Move to current point. */
+    // Move to current point.
     NR::Point dp = p * sp_item_i2d_affine(item);
     sp_knot_set_position(e->knot, &dp, SP_KNOT_STATE_NORMAL);
 
index 156bcaf64f7163d076fb809bb068f75cd0ff3b0c..cb5be0d8d683048ad9270a1e742b9843b93b9b8a 100644 (file)
@@ -32,8 +32,11 @@ typedef void (* PointParamKnotHolderSetFunc) (SPItem *item, NR::Point const &p,
 typedef NR::Point (* PointParamKnotHolderGetFunc) (SPItem *item);
 typedef void (* PointParamKnotHolderClickedFunc) (SPItem *item, guint state);
 
-class PointParamKnotHolder : public SPKnotHolder {
+class PointParamKnotHolder : public KnotHolder {
 public:
+    PointParamKnotHolder(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item);
+    ~PointParamKnotHolder();
+
     LivePathEffectObject * lpeobject;
     Inkscape::XML::Node  * repr;
     const gchar          * repr_key;
@@ -46,17 +49,6 @@ public:
                     const gchar *tip );
 };
 
-struct PointParamKnotHolderClass : SPKnotHolderClass {
-};
-
-PointParamKnotHolder *pointparam_knot_holder_new(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item);
-
-GType pointparam_knot_holder_get_type();
-
-
-#define INKSCAPE_TYPE_POINTPARAM_KNOT_HOLDER      (Inkscape::pointparam_knot_holder_get_type())
-
-
 } // namespace Inkscape
 
 
index 3e42b74b931bff515fdb791cf4d04734ae91346a..4a52c28a0064bdbc5aab4ef7d75e47f8e47ea6a2 100644 (file)
@@ -16,7 +16,6 @@
 #include "forward.h"
 #include "display/display-forward.h"
 #include "nodepath.h"
-struct SPKnotHolder;
 namespace Inkscape { class Selection; }
 
 #define SP_TYPE_NODE_CONTEXT            (sp_node_context_get_type ())
index dedcfdabf20e2051576d6b433a4d5fc946217efd..d335ced533aeec1082cd905bbe5d5b468ecd834a 100644 (file)
@@ -6,6 +6,7 @@
  * Authors:
  *   Lauris Kaplinski <lauris@kaplinski.com>
  *   Mitsuru Oka
+ *   Maximilian Albert <maximilian.albert@gmail.com>
  *
  * Licensed under GNU GPL
  */
@@ -28,7 +29,7 @@
 #include "inkscape.h"
 #include "snap.h"
 #include "desktop-affine.h"
-#include <style.h>
+#include "style.h"
 #include "desktop.h"
 #include "desktop-handles.h"
 #include "sp-namedview.h"
@@ -42,6 +43,7 @@
 #include "object-edit.h"
 
 #include <libnr/nr-scale-ops.h>
+#include <libnr/nr-matrix-div.h>
 
 #include "xml/repr.h"
 
 
 #define sp_round(v,m) (((v) < 0.0) ? ((ceil((v) / (m) - 0.5)) * (m)) : ((floor((v) / (m) + 0.5)) * (m)))
 
-static SPKnotHolder *sp_rect_knot_holder(SPItem *item, SPDesktop *desktop);
-static SPKnotHolder *box3d_knot_holder(SPItem *item, SPDesktop *desktop);
-static SPKnotHolder *sp_arc_knot_holder(SPItem *item, SPDesktop *desktop);
-static SPKnotHolder *sp_star_knot_holder(SPItem *item, SPDesktop *desktop);
-static SPKnotHolder *sp_spiral_knot_holder(SPItem *item, SPDesktop *desktop);
-static SPKnotHolder *sp_offset_knot_holder(SPItem *item, SPDesktop *desktop);
-static SPKnotHolder *sp_misc_knot_holder(SPItem *item, SPDesktop *desktop);
-static SPKnotHolder *sp_flowtext_knot_holder(SPItem *item, SPDesktop *desktop);
-static void sp_pat_knot_holder(SPItem *item, SPKnotHolder *knot_holder);
-
-static SPKnotHolder *sp_lpe_knot_holder(SPItem *item, SPDesktop *desktop)
+static KnotHolder *sp_lpe_knot_holder(SPItem *item, SPDesktop *desktop)
 {
-    SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
+    KnotHolder *knot_holder = new KnotHolder(desktop, item, NULL);
 
     Inkscape::LivePathEffect::Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
     if (!effect) {
@@ -73,171 +65,70 @@ static SPKnotHolder *sp_lpe_knot_holder(SPItem *item, SPDesktop *desktop)
     return knot_holder;
 }
 
-SPKnotHolder *
+KnotHolder *
 sp_item_knot_holder(SPItem *item, SPDesktop *desktop)
 {
-    if ( SP_IS_LPE_ITEM(item) &&
-         sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)) &&
-         sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))->isVisible() &&
-         sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))->providesKnotholder() )
-    {
-        return sp_lpe_knot_holder(item, desktop);
+    KnotHolder *knotholder = NULL;
+
+    if (SP_IS_LPE_ITEM(item) &&
+        sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)) &&
+        sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))->isVisible() &&
+        sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))->providesKnotholder()) {
+        knotholder = sp_lpe_knot_holder(item, desktop);
     } else if (SP_IS_RECT(item)) {
-        return sp_rect_knot_holder(item, desktop);
+        knotholder = new RectKnotHolder(desktop, item, NULL);
     } else if (SP_IS_BOX3D(item)) {
-        return box3d_knot_holder(item, desktop);
+        knotholder = new Box3DKnotHolder(desktop, item, NULL);
     } else if (SP_IS_ARC(item)) {
-        return sp_arc_knot_holder(item, desktop);
+        knotholder = new ArcKnotHolder(desktop, item, NULL);
     } else if (SP_IS_STAR(item)) {
-        return sp_star_knot_holder(item, desktop);
+        knotholder = new StarKnotHolder(desktop, item, NULL);
     } else if (SP_IS_SPIRAL(item)) {
-        return sp_spiral_knot_holder(item, desktop);
+        knotholder = new SpiralKnotHolder(desktop, item, NULL);
     } else if (SP_IS_OFFSET(item)) {
-        return sp_offset_knot_holder(item, desktop);
+        knotholder = new OffsetKnotHolder(desktop, item, NULL);
     } else if (SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) {
-        return sp_flowtext_knot_holder(item, desktop);
-    } else {
-        return sp_misc_knot_holder(item, desktop);
-    }
-
-    return NULL;
-}
-
-
-/* Pattern manipulation */
-
-static gdouble sp_pattern_extract_theta(SPPattern *pat, gdouble scale)
-{
-    gdouble theta = asin(pat->patternTransform[1] / scale);
-    if (pat->patternTransform[0] < 0) theta = M_PI - theta ;
-    return theta;
-}
-
-static gdouble sp_pattern_extract_scale(SPPattern *pat)
-{
-    gdouble s = pat->patternTransform[1];
-    gdouble c = pat->patternTransform[0];
-    gdouble xscale = sqrt(c * c + s * s);
-    return xscale;
-}
-
-static NR::Point sp_pattern_extract_trans(SPPattern const *pat)
-{
-    return NR::Point(pat->patternTransform[4], pat->patternTransform[5]);
-}
-
-static void
-sp_pattern_xy_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
-{
-    SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
-
-    NR::Point p_snapped = p;
-
-    if ( state & GDK_CONTROL_MASK ) {
-        if (fabs((p - origin)[NR::X]) > fabs((p - origin)[NR::Y])) {
-            p_snapped[NR::Y] = origin[NR::Y];
-        } else {
-            p_snapped[NR::X] = origin[NR::X];
-        }
+        knotholder = new FlowtextKnotHolder(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL);
+    } else if ((SP_OBJECT(item)->style->fill.isPaintserver())
+               && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style))) {
+        knotholder->add_pattern_knotholder();
     }
 
-    if (state)  {
-        NR::Point const q = p_snapped - sp_pattern_extract_trans(pat);
-        sp_item_adjust_pattern(item, NR::Matrix(NR::translate(q)));
-    }
-
-    item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
-}
-
-
-static NR::Point sp_pattern_xy_get(SPItem *item)
-{
-    SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
-    return sp_pattern_extract_trans(pat);
-}
-
-static NR::Point sp_pattern_angle_get(SPItem *item)
-{
-    SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
-
-    gdouble x = (pattern_width(pat)*0.5);
-    gdouble y = 0;
-    NR::Point delta = NR::Point(x,y);
-    gdouble scale = sp_pattern_extract_scale(pat);
-    gdouble theta = sp_pattern_extract_theta(pat, scale);
-    delta = delta * NR::Matrix(NR::rotate(theta))*NR::Matrix(NR::scale(scale,scale));
-    delta = delta + sp_pattern_extract_trans(pat);
-    return delta;
-}
-
-static void
-sp_pattern_angle_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
-{
-    int const snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
-
-    SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
-
-    // get the angle from pattern 0,0 to the cursor pos
-    NR::Point delta = p - sp_pattern_extract_trans(pat);
-    gdouble theta = atan2(delta);
-
-    if ( state & GDK_CONTROL_MASK ) {
-        theta = sp_round(theta, M_PI/snaps);
-    }
-
-    // get the scale from the current transform so we can keep it.
-    gdouble scl = sp_pattern_extract_scale(pat);
-    NR::Matrix rot =  NR::Matrix(NR::rotate(theta)) * NR::Matrix(NR::scale(scl,scl));
-    NR::Point const t = sp_pattern_extract_trans(pat);
-    rot[4] = t[NR::X];
-    rot[5] = t[NR::Y];
-    sp_item_adjust_pattern(item, rot, true);
-    item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
-}
-
-static void
-sp_pattern_scale_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
-{
-    SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
-
-    // Get the scale from the position of the knotholder,
-    NR::Point d = p - sp_pattern_extract_trans(pat);
-    gdouble s = NR::L2(d);
-    gdouble pat_x = pattern_width(pat) * 0.5;
-    gdouble pat_y = pattern_height(pat) * 0.5;
-    gdouble pat_h = hypot(pat_x, pat_y);
-    gdouble scl = s / pat_h;
-
-    // get angle from current transform, (need get current scale first to calculate angle)
-    gdouble oldscale = sp_pattern_extract_scale(pat);
-    gdouble theta = sp_pattern_extract_theta(pat,oldscale);
-
-    NR::Matrix rot =  NR::Matrix(NR::rotate(theta)) * NR::Matrix(NR::scale(scl,scl));
-    NR::Point const t = sp_pattern_extract_trans(pat);
-    rot[4] = t[NR::X];
-    rot[5] = t[NR::Y];
-    sp_item_adjust_pattern(item, rot, true);
-    item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
-}
-
-
-static NR::Point sp_pattern_scale_get(SPItem *item)
-{
-    SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
-
-    gdouble x = pattern_width(pat)*0.5;
-    gdouble y = pattern_height(pat)*0.5;
-    NR::Point delta = NR::Point(x,y);
-    NR::Matrix a = pat->patternTransform;
-    a[4] = 0;
-    a[5] = 0;
-    delta = delta * a;
-    delta = delta + sp_pattern_extract_trans(pat);
-    return delta;
+    return knotholder;
 }
 
 /* SPRect */
 
+/* handle for horizontal rounding radius */
+class RectKnotHolderEntityRX : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+    virtual void knot_click_func(guint state);
+};
+
+/* handle for vertical rounding radius */
+class RectKnotHolderEntityRY : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+    virtual void knot_click_func(guint state);
+};
+
+/* handle for width/height adjustment */
+class RectKnotHolderEntityWH : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
+
+/* handle for x/y adjustment */
+class RectKnotHolderEntityXY : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
+
 static NR::Point snap_knot_position(SPItem *item, NR::Point const &p)
 {
     SPDesktop const *desktop = inkscape_active_desktop();
@@ -249,14 +140,16 @@ static NR::Point snap_knot_position(SPItem *item, NR::Point const &p)
     return s * i2d.inverse();
 }
 
-static NR::Point sp_rect_rx_get(SPItem *item)
+NR::Point
+RectKnotHolderEntityRX::knot_get_func()
 {
     SPRect *rect = SP_RECT(item);
 
     return NR::Point(rect->x.computed + rect->width.computed - rect->rx.computed, rect->y.computed);
 }
 
-static void sp_rect_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
+void
+RectKnotHolderEntityRX::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state)
 {
     SPRect *rect = SP_RECT(item);
 
@@ -274,18 +167,38 @@ static void sp_rect_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*
         rect->rx._set = true;
     }
 
+    update_knot();
+
     ((SPObject*)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
 }
 
+void
+RectKnotHolderEntityRX::knot_click_func(guint state)
+{
+    SPRect *rect = SP_RECT(item);
+
+    if (state & GDK_SHIFT_MASK) {
+        /* remove rounding from rectangle */
+        SP_OBJECT_REPR(rect)->setAttribute("rx", NULL);
+        SP_OBJECT_REPR(rect)->setAttribute("ry", NULL);
+    } else if (state & GDK_CONTROL_MASK) {
+        /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
+        SP_OBJECT_REPR(rect)->setAttribute("ry", SP_OBJECT_REPR(rect)->attribute("rx"));
+    }
+
+    update_knot();
+}
 
-static NR::Point sp_rect_ry_get(SPItem *item)
+NR::Point
+RectKnotHolderEntityRY::knot_get_func()
 {
     SPRect *rect = SP_RECT(item);
 
     return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->ry.computed);
 }
 
-static void sp_rect_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
+void
+RectKnotHolderEntityRY::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state)
 {
     SPRect *rect = SP_RECT(item);
 
@@ -311,42 +224,20 @@ static void sp_rect_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*
         rect->ry._set = true;
     }
 
-    ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
-}
-
-/**
- *  Remove rounding from a rectangle.
- */
-static void rect_remove_rounding(SPRect *rect)
-{
-    SP_OBJECT_REPR(rect)->setAttribute("rx", NULL);
-    SP_OBJECT_REPR(rect)->setAttribute("ry", NULL);
-}
+    update_knot();
 
-/**
- *  Called when the horizontal rounding radius knot is clicked.
- */
-static void sp_rect_rx_knot_click(SPItem *item, guint state)
-{
-    SPRect *rect = SP_RECT(item);
-
-    if (state & GDK_SHIFT_MASK) {
-        rect_remove_rounding(rect);
-    } else if (state & GDK_CONTROL_MASK) {
-        /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
-        SP_OBJECT_REPR(rect)->setAttribute("ry", SP_OBJECT_REPR(rect)->attribute("rx"));
-    }
+    ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
 }
 
-/**
- *  Called when the vertical rounding radius knot is clicked.
- */
-static void sp_rect_ry_knot_click(SPItem *item, guint state)
+void
+RectKnotHolderEntityRY::knot_click_func(guint state)
 {
     SPRect *rect = SP_RECT(item);
 
     if (state & GDK_SHIFT_MASK) {
-        rect_remove_rounding(rect);
+        /* remove rounding */
+        SP_OBJECT_REPR(rect)->setAttribute("rx", NULL);
+        SP_OBJECT_REPR(rect)->setAttribute("ry", NULL);
     } else if (state & GDK_CONTROL_MASK) {
         /* Ctrl-click sets the vertical rounding to be the same as the horizontal */
         SP_OBJECT_REPR(rect)->setAttribute("rx", SP_OBJECT_REPR(rect)->attribute("ry"));
@@ -368,7 +259,8 @@ static void sp_rect_clamp_radii(SPRect *rect)
     }
 }
 
-static NR::Point sp_rect_wh_get(SPItem *item)
+NR::Point
+RectKnotHolderEntityWH::knot_get_func()
 {
     SPRect *rect = SP_RECT(item);
 
@@ -429,21 +321,26 @@ static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point
     ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
 }
 
-static void sp_rect_wh_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
+void
+RectKnotHolderEntityWH::knot_set_func(NR::Point const &p, NR::Point const &origin, guint state)
 {
     SPRect *rect = SP_RECT(item);
 
     sp_rect_wh_set_internal(rect, p, origin, state);
+
+    update_knot();
 }
 
-static NR::Point sp_rect_xy_get(SPItem *item)
+NR::Point
+RectKnotHolderEntityXY::knot_get_func()
 {
     SPRect *rect = SP_RECT(item);
 
     return NR::Point(rect->x.computed, rect->y.computed);
 }
 
-static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
+void
+RectKnotHolderEntityXY::knot_set_func(NR::Point const &p, NR::Point const &origin, guint state)
 {
     SPRect *rect = SP_RECT(item);
 
@@ -510,52 +407,61 @@ static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &or
 
     sp_rect_clamp_radii(rect);
 
+    update_knot();
+
     ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
 }
 
-static SPKnotHolder *sp_rect_knot_holder(SPItem *item, SPDesktop *desktop)
-{
-    SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
-
-    sp_knot_holder_add_full(
-      knot_holder, sp_rect_rx_set, sp_rect_rx_get, sp_rect_rx_knot_click,
-      SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
-      _("Adjust the <b>horizontal rounding</b> radius; with <b>Ctrl</b> to make the vertical "
-        "radius the same"));
-
-    sp_knot_holder_add_full(
-      knot_holder, sp_rect_ry_set, sp_rect_ry_get, sp_rect_ry_knot_click,
-      SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
-      _("Adjust the <b>vertical rounding</b> radius; with <b>Ctrl</b> to make the horizontal "
-        "radius the same")
-      );
-
-    sp_knot_holder_add_full(
-      knot_holder, sp_rect_wh_set, sp_rect_wh_get, NULL,
-      SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
-      _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
-        "or stretch in one dimension only")
-      );
-
-    sp_knot_holder_add_full(
-      knot_holder, sp_rect_xy_set, sp_rect_xy_get, NULL,
-      SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
-      _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b> to lock ratio "
-        "or stretch in one dimension only")
-      );
-
-    sp_pat_knot_holder(item, knot_holder);
-    return knot_holder;
+RectKnotHolder::RectKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
+    KnotHolder(desktop, item, relhandler)
+{
+    RectKnotHolderEntityRX *entity_rx = new RectKnotHolderEntityRX();
+    RectKnotHolderEntityRY *entity_ry = new RectKnotHolderEntityRY();
+    RectKnotHolderEntityWH *entity_wh = new RectKnotHolderEntityWH();
+    RectKnotHolderEntityXY *entity_xy = new RectKnotHolderEntityXY();
+    entity_rx->create(desktop, item, this,
+                      _("Adjust the <b>horizontal rounding</b> radius; with <b>Ctrl</b> "
+                        "to make the vertical radius the same"),
+                       SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR);
+    entity_ry->create(desktop, item, this,
+                      _("Adjust the <b>vertical rounding</b> radius; with <b>Ctrl</b> "
+                        "to make the horizontal radius the same"),
+                      SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR);
+    entity_wh->create(desktop, item, this,
+                      _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b>"
+                        "to lock ratio or stretch in one dimension only"),
+                      SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
+    entity_xy->create(desktop, item, this,
+                      _("Adjust the <b>width and height</b> of the rectangle; with <b>Ctrl</b>"
+                        "to lock ratio or stretch in one dimension only"),
+                      SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
+    entity.push_back(entity_rx);
+    entity.push_back(entity_ry);
+    entity.push_back(entity_wh);
+    entity.push_back(entity_xy);
+
+    add_pattern_knotholder();
 }
 
 /* Box3D (= the new 3D box structure) */
 
-static NR::Point box3d_knot_get(SPItem *item, guint knot_id)
+class Box3DKnotHolderEntity : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func() = 0;
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state) = 0;
+
+    static NR::Point knot_get_func_generic(SPItem *item, unsigned int knot_id);
+    static void knot_set_func_generic(SPItem *item, unsigned int knot_id, NR::Point const &p, guint state);
+};
+
+NR::Point
+Box3DKnotHolderEntity::knot_get_func_generic(SPItem *item, unsigned int knot_id)
 {
     return box3d_get_corner_screen(SP_BOX3D(item), knot_id);
 }
 
-static void box3d_knot_set(SPItem *item, guint knot_id, NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
+void
+Box3DKnotHolderEntity::knot_set_func_generic(SPItem *item, unsigned int knot_id, NR::Point const &new_pos, guint state)
 {
     NR::Point const s = snap_knot_position(item, new_pos);
 
@@ -575,141 +481,260 @@ static void box3d_knot_set(SPItem *item, guint knot_id, NR::Point const &new_pos
     box3d_position_set(box);
 }
 
-static NR::Point box3d_knot_center_get (SPItem *item)
-{
-    return box3d_get_center_screen (SP_BOX3D(item));
-}
+class Box3DKnotHolderEntity0 : public Box3DKnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
 
-static void box3d_knot_center_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
-{
-    NR::Point const s = snap_knot_position(item, new_pos);
+class Box3DKnotHolderEntity1 : public Box3DKnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
 
-    SPBox3D *box = SP_BOX3D(item);
-    NR::Matrix const i2d (sp_item_i2d_affine (item));
+class Box3DKnotHolderEntity2 : public Box3DKnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
 
-    box3d_set_center (SP_BOX3D(item), s * i2d, origin * i2d, !(state & GDK_SHIFT_MASK) ? Box3D::XY : Box3D::Z,
-                      state & GDK_CONTROL_MASK);
+class Box3DKnotHolderEntity3 : public Box3DKnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
 
-    box3d_set_z_orders(box);
-    box3d_position_set(box);
+class Box3DKnotHolderEntity4 : public Box3DKnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
+
+class Box3DKnotHolderEntity5 : public Box3DKnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
+
+class Box3DKnotHolderEntity6 : public Box3DKnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
+
+class Box3DKnotHolderEntity7 : public Box3DKnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
+
+class Box3DKnotHolderEntityCenter : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
+
+NR::Point
+Box3DKnotHolderEntity0::knot_get_func()
+{
+    return knot_get_func_generic(item, 0);
 }
 
-static void box3d_knot0_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
+NR::Point
+Box3DKnotHolderEntity1::knot_get_func()
 {
-    box3d_knot_set(item, 0, new_pos, origin, state);
+    return knot_get_func_generic(item, 1);
 }
 
-static void box3d_knot1_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
+NR::Point
+Box3DKnotHolderEntity2::knot_get_func()
 {
-    box3d_knot_set(item, 1, new_pos, origin, state);
+    return knot_get_func_generic(item, 2);
 }
 
-static void box3d_knot2_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
+NR::Point
+Box3DKnotHolderEntity3::knot_get_func()
 {
-    box3d_knot_set(item, 2, new_pos, origin, state);
+    return knot_get_func_generic(item, 3);
 }
 
-static void box3d_knot3_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
+NR::Point
+Box3DKnotHolderEntity4::knot_get_func()
 {
-    box3d_knot_set(item, 3, new_pos, origin, state);
+    return knot_get_func_generic(item, 4);
 }
 
-static void box3d_knot4_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
+NR::Point
+Box3DKnotHolderEntity5::knot_get_func()
 {
-    box3d_knot_set(item, 4, new_pos, origin, state);
+    return knot_get_func_generic(item, 5);
 }
 
-static void box3d_knot5_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
+NR::Point
+Box3DKnotHolderEntity6::knot_get_func()
 {
-    box3d_knot_set(item, 5, new_pos, origin, state);
+    return knot_get_func_generic(item, 6);
 }
 
-static void box3d_knot6_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
+NR::Point
+Box3DKnotHolderEntity7::knot_get_func()
 {
-    box3d_knot_set(item, 6, new_pos, origin, state);
+    return knot_get_func_generic(item, 7);
 }
 
-static void box3d_knot7_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state)
+NR::Point
+Box3DKnotHolderEntityCenter::knot_get_func()
 {
-    box3d_knot_set(item, 7, new_pos, origin, state);
+    return box3d_get_center_screen(SP_BOX3D(item));
 }
 
-static NR::Point box3d_knot0_get(SPItem *item)
+void
+Box3DKnotHolderEntity0::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
 {
-    return box3d_knot_get(item, 0);
+    knot_set_func_generic(item, 0, new_pos, state);
 }
 
-static NR::Point box3d_knot1_get(SPItem *item)
+void
+Box3DKnotHolderEntity1::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
 {
-    return box3d_knot_get(item, 1);
+    knot_set_func_generic(item, 1, new_pos, state);
 }
 
-static NR::Point box3d_knot2_get(SPItem *item)
+void
+Box3DKnotHolderEntity2::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
 {
-    return box3d_knot_get(item, 2);
+    knot_set_func_generic(item, 2, new_pos, state);
 }
 
-static NR::Point box3d_knot3_get(SPItem *item)
+void
+Box3DKnotHolderEntity3::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
 {
-    return box3d_knot_get(item, 3);
+    knot_set_func_generic(item, 3, new_pos, state);
 }
 
-static NR::Point box3d_knot4_get(SPItem *item)
+void
+Box3DKnotHolderEntity4::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
 {
-    return box3d_knot_get(item, 4);
+    knot_set_func_generic(item, 4, new_pos, state);
 }
 
-static NR::Point box3d_knot5_get(SPItem *item)
+void
+Box3DKnotHolderEntity5::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
 {
-    return box3d_knot_get(item, 5);
+    knot_set_func_generic(item, 5, new_pos, state);
 }
 
-static NR::Point box3d_knot6_get(SPItem *item)
+void
+Box3DKnotHolderEntity6::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
 {
-    return box3d_knot_get(item, 6);
+    knot_set_func_generic(item, 6, new_pos, state);
 }
 
-static NR::Point box3d_knot7_get(SPItem *item)
+void
+Box3DKnotHolderEntity7::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state)
 {
-    return box3d_knot_get(item, 7);
+    knot_set_func_generic(item, 7, new_pos, state);
 }
 
-SPKnotHolder *
-box3d_knot_holder(SPItem *item, SPDesktop *desktop)
+void
+Box3DKnotHolderEntityCenter::knot_set_func(NR::Point const &new_pos, NR::Point const &origin, guint state)
 {
-    g_assert(item != NULL);
-    SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
-
-    sp_knot_holder_add(knot_holder, box3d_knot0_set, box3d_knot0_get, NULL,
-                       _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
-    sp_knot_holder_add(knot_holder, box3d_knot1_set, box3d_knot1_get, NULL,
-                       _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
-    sp_knot_holder_add(knot_holder, box3d_knot2_set, box3d_knot2_get, NULL,
-                       _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
-    sp_knot_holder_add(knot_holder, box3d_knot3_set, box3d_knot3_get, NULL,
-                       _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
-    sp_knot_holder_add(knot_holder, box3d_knot4_set, box3d_knot4_get, NULL,
-                       _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
-    sp_knot_holder_add(knot_holder, box3d_knot5_set, box3d_knot5_get, NULL,
-                       _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
-    sp_knot_holder_add(knot_holder, box3d_knot6_set, box3d_knot6_get, NULL,
-                       _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
-    sp_knot_holder_add(knot_holder, box3d_knot7_set, box3d_knot7_get, NULL,
-                       _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
-
-    // center dragging
-    sp_knot_holder_add_full(knot_holder, box3d_knot_center_set, box3d_knot_center_get, NULL,
-                            SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,_("Move the box in perspective"));
-
-    sp_pat_knot_holder(item, knot_holder);
+    NR::Point const s = snap_knot_position(item, new_pos);
 
-    return knot_holder;
-}
+    SPBox3D *box = SP_BOX3D(item);
+    NR::Matrix const i2d (sp_item_i2d_affine (item));
 
+    box3d_set_center (SP_BOX3D(item), s * i2d, origin * i2d, !(state & GDK_SHIFT_MASK) ? Box3D::XY : Box3D::Z,
+                      state & GDK_CONTROL_MASK);
 
+    box3d_set_z_orders(box);
+    box3d_position_set(box);
+}
+
+Box3DKnotHolder::Box3DKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
+    KnotHolder(desktop, item, relhandler)
+{
+    Box3DKnotHolderEntity0 *entity_corner0 = new Box3DKnotHolderEntity0();
+    Box3DKnotHolderEntity1 *entity_corner1 = new Box3DKnotHolderEntity1();
+    Box3DKnotHolderEntity2 *entity_corner2 = new Box3DKnotHolderEntity2();
+    Box3DKnotHolderEntity3 *entity_corner3 = new Box3DKnotHolderEntity3();
+    Box3DKnotHolderEntity4 *entity_corner4 = new Box3DKnotHolderEntity4();
+    Box3DKnotHolderEntity5 *entity_corner5 = new Box3DKnotHolderEntity5();
+    Box3DKnotHolderEntity6 *entity_corner6 = new Box3DKnotHolderEntity6();
+    Box3DKnotHolderEntity7 *entity_corner7 = new Box3DKnotHolderEntity7();
+    Box3DKnotHolderEntityCenter *entity_center = new Box3DKnotHolderEntityCenter();
+
+    entity_corner0->create(desktop, item, this,
+                           _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; "
+                             "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
+    entity_corner1->create(desktop, item, this,
+                           _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; "
+                             "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
+    entity_corner2->create(desktop, item, this,
+                           _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; "
+                             "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
+    entity_corner3->create(desktop, item, this,
+                           _("Resize box in X/Y direction; with <b>Shift</b> along the Z axis; "
+                             "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
+    entity_corner4->create(desktop, item, this,
+                     _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; "
+                       "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
+    entity_corner5->create(desktop, item, this,
+                     _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; "
+                       "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
+    entity_corner6->create(desktop, item, this,
+                     _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; "
+                       "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
+    entity_corner7->create(desktop, item, this,
+                     _("Resize box along the Z axis; with <b>Shift</b> in X/Y direction; "
+                       "with <b>Ctrl</b> to constrain to the directions of edges or diagonals"));
+    entity_center->create(desktop, item, this,
+                          _("Move the box in perspective"),
+                          SP_KNOT_SHAPE_CROSS);
+
+    entity.push_back(entity_corner0);
+    entity.push_back(entity_corner1);
+    entity.push_back(entity_corner2);
+    entity.push_back(entity_corner3);
+    entity.push_back(entity_corner4);
+    entity.push_back(entity_corner5);
+    entity.push_back(entity_corner6);
+    entity.push_back(entity_corner7);
+    entity.push_back(entity_center);
+
+    add_pattern_knotholder();
+}
 
 /* SPArc */
 
+class ArcKnotHolderEntityStart : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
+
+class ArcKnotHolderEntityEnd : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+    virtual void knot_click_func(guint state);
+};
+
+class ArcKnotHolderEntityRX : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+    virtual void knot_click_func(guint state);
+};
+
+class ArcKnotHolderEntityRY : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+    virtual void knot_click_func(guint state);
+};
+
 /*
  * return values:
  *   1  : inside
@@ -728,8 +753,8 @@ sp_genericellipse_side(SPGenericEllipse *ellipse, NR::Point const &p)
     return 0;
 }
 
-static void
-sp_arc_start_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
+void
+ArcKnotHolderEntityStart::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state)
 {
     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
 
@@ -750,7 +775,8 @@ sp_arc_start_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/,
     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
 }
 
-static NR::Point sp_arc_start_get(SPItem *item)
+NR::Point
+ArcKnotHolderEntityStart::knot_get_func()
 {
     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
     SPArc *arc = SP_ARC(item);
@@ -758,8 +784,8 @@ static NR::Point sp_arc_start_get(SPItem *item)
     return sp_arc_get_xy(arc, ge->start);
 }
 
-static void
-sp_arc_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
+void
+ArcKnotHolderEntityEnd::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state)
 {
     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
 
@@ -780,7 +806,8 @@ sp_arc_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, gu
     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
 }
 
-static NR::Point sp_arc_end_get(SPItem *item)
+NR::Point
+ArcKnotHolderEntityEnd::knot_get_func()
 {
     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
     SPArc *arc = SP_ARC(item);
@@ -788,8 +815,9 @@ static NR::Point sp_arc_end_get(SPItem *item)
     return sp_arc_get_xy(arc, ge->end);
 }
 
-static void
-sp_arc_startend_click(SPItem *item, guint state)
+
+void
+ArcKnotHolderEntityEnd::knot_click_func(guint state)
 {
     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
 
@@ -800,8 +828,8 @@ sp_arc_startend_click(SPItem *item, guint state)
 }
 
 
-static void
-sp_arc_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
+void
+ArcKnotHolderEntityRX::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state)
 {
     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
     SPArc *arc = SP_ARC(item);
@@ -817,15 +845,27 @@ sp_arc_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, gui
     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
 }
 
-static NR::Point sp_arc_rx_get(SPItem *item)
+NR::Point
+ArcKnotHolderEntityRX::knot_get_func()
 {
     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
 
     return (NR::Point(ge->cx.computed, ge->cy.computed) -  NR::Point(ge->rx.computed, 0));
 }
 
-static void
-sp_arc_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
+void
+ArcKnotHolderEntityRX::knot_click_func(guint state)
+{
+    SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
+
+    if (state & GDK_CONTROL_MASK) {
+        ge->ry.computed = ge->rx.computed;
+        ((SPObject *)ge)->updateRepr();
+    }
+}
+
+void
+ArcKnotHolderEntityRY::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state)
 {
     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
     SPArc *arc = SP_ARC(item);
@@ -841,26 +881,16 @@ sp_arc_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, gui
     ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
 }
 
-static NR::Point sp_arc_ry_get(SPItem *item)
+NR::Point
+ArcKnotHolderEntityRY::knot_get_func()
 {
     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
 
     return (NR::Point(ge->cx.computed, ge->cy.computed) -  NR::Point(0, ge->ry.computed));
 }
 
-static void
-sp_arc_rx_click(SPItem *item, guint state)
-{
-    SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
-
-    if (state & GDK_CONTROL_MASK) {
-        ge->ry.computed = ge->rx.computed;
-        ((SPObject *)ge)->updateRepr();
-    }
-}
-
-static void
-sp_arc_ry_click(SPItem *item, guint state)
+void
+ArcKnotHolderEntityRY::knot_click_func(guint state)
 {
     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
 
@@ -870,33 +900,53 @@ sp_arc_ry_click(SPItem *item, guint state)
     }
 }
 
-static SPKnotHolder *
-sp_arc_knot_holder(SPItem *item, SPDesktop *desktop)
-{
-    SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
-
-    sp_knot_holder_add_full(knot_holder, sp_arc_rx_set, sp_arc_rx_get, sp_arc_rx_click,
-                            SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
-                            _("Adjust ellipse <b>width</b>, with <b>Ctrl</b> to make circle"));
-    sp_knot_holder_add_full(knot_holder, sp_arc_ry_set, sp_arc_ry_get, sp_arc_ry_click,
-                            SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
-                            _("Adjust ellipse <b>height</b>, with <b>Ctrl</b> to make circle"));
-    sp_knot_holder_add_full(knot_holder, sp_arc_start_set, sp_arc_start_get, sp_arc_startend_click,
-                            SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
-                            _("Position the <b>start point</b> of the arc or segment; with <b>Ctrl</b> to snap angle; drag <b>inside</b> the ellipse for arc, <b>outside</b> for segment"));
-    sp_knot_holder_add_full(knot_holder, sp_arc_end_set, sp_arc_end_get, sp_arc_startend_click,
-                            SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
-                            _("Position the <b>end point</b> of the arc or segment; with <b>Ctrl</b> to snap angle; drag <b>inside</b> the ellipse for arc, <b>outside</b> for segment"));
-
-    sp_pat_knot_holder(item, knot_holder);
-
-    return knot_holder;
+ArcKnotHolder::ArcKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
+    KnotHolder(desktop, item, relhandler)
+{
+    ArcKnotHolderEntityRX *entity_rx = new ArcKnotHolderEntityRX();
+    ArcKnotHolderEntityRY *entity_ry = new ArcKnotHolderEntityRY();
+    ArcKnotHolderEntityStart *entity_start = new ArcKnotHolderEntityStart();
+    ArcKnotHolderEntityEnd *entity_end = new ArcKnotHolderEntityEnd();
+    entity_rx->create(desktop, item, this,
+                      _("Adjust ellipse <b>width</b>, with <b>Ctrl</b> to make circle"),
+                      SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
+    entity_ry->create(desktop, item, this,
+                      _("Adjust ellipse <b>height</b>, with <b>Ctrl</b> to make circle"),
+                      SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
+    entity_start->create(desktop, item, this,
+                         _("Position the <b>start point</b> of the arc or segment; with <b>Ctrl</b>"
+                           "to snap angle; drag <b>inside</b> the ellipse for arc, <b>outside</b> for segment"),
+                         SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR);
+    entity_end->create(desktop, item, this,
+                       _("Position the <b>end point</b> of the arc or segment; with <b>Ctrl</b> to snap angle; "
+                         "drag <b>inside</b> the ellipse for arc, <b>outside</b> for segment"),
+                       SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR);
+    entity.push_back(entity_rx);
+    entity.push_back(entity_ry);
+    entity.push_back(entity_start);
+    entity.push_back(entity_end);
+
+    add_pattern_knotholder();
 }
 
 /* SPStar */
 
-static void
-sp_star_knot1_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
+class StarKnotHolderEntity1 : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+    virtual void knot_click_func(guint state);
+};
+
+class StarKnotHolderEntity2 : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+    virtual void knot_click_func(guint state);
+};
+
+void
+StarKnotHolderEntity1::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state)
 {
     SPStar *star = SP_STAR(item);
 
@@ -921,8 +971,8 @@ sp_star_knot1_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/,
     ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
 }
 
-static void
-sp_star_knot2_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
+void
+StarKnotHolderEntity2::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state)
 {
     SPStar *star = SP_STAR(item);
 
@@ -950,7 +1000,8 @@ sp_star_knot2_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/,
     }
 }
 
-static NR::Point sp_star_knot1_get(SPItem *item)
+NR::Point
+StarKnotHolderEntity1::knot_get_func()
 {
     g_assert(item != NULL);
 
@@ -960,7 +1011,8 @@ static NR::Point sp_star_knot1_get(SPItem *item)
 
 }
 
-static NR::Point sp_star_knot2_get(SPItem *item)
+NR::Point
+StarKnotHolderEntity2::knot_get_func()
 {
     g_assert(item != NULL);
 
@@ -986,36 +1038,64 @@ sp_star_knot_click(SPItem *item, guint state)
     }
 }
 
-static SPKnotHolder *
-sp_star_knot_holder(SPItem *item, SPDesktop *desktop)
+void
+StarKnotHolderEntity1::knot_click_func(guint state)
 {
-    /* we don't need to get parent knot_holder */
-    SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
-    g_assert(item != NULL);
+    return sp_star_knot_click(item, state);
+}
 
+void
+StarKnotHolderEntity2::knot_click_func(guint state)
+{
+    return sp_star_knot_click(item, state);
+}
+
+StarKnotHolder::StarKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
+    KnotHolder(desktop, item, relhandler)
+{
     SPStar *star = SP_STAR(item);
 
-    sp_knot_holder_add(knot_holder, sp_star_knot1_set, sp_star_knot1_get, sp_star_knot_click,
-                       _("Adjust the <b>tip radius</b> of the star or polygon; with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
-    if (star->flatsided == false)
-        sp_knot_holder_add(knot_holder, sp_star_knot2_set, sp_star_knot2_get, sp_star_knot_click,
-                           _("Adjust the <b>base radius</b> of the star; with <b>Ctrl</b> to keep star rays radial (no skew); with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
+    StarKnotHolderEntity1 *entity1 = new StarKnotHolderEntity1();
+    entity1->create(desktop, item, this,
+                    _("Adjust the <b>tip radius</b> of the star or polygon; "
+                      "with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
+    entity.push_back(entity1);
 
-    sp_pat_knot_holder(item, knot_holder);
+    if (star->flatsided == false) {
+        StarKnotHolderEntity2 *entity2 = new StarKnotHolderEntity2();
+        entity2->create(desktop, item, this,
+                        _("Adjust the <b>base radius</b> of the star; with <b>Ctrl</b> to keep star rays "
+                          "radial (no skew); with <b>Shift</b> to round; with <b>Alt</b> to randomize"));
+        entity.push_back(entity2);
+    }
 
-    return knot_holder;
+    add_pattern_knotholder();
 }
 
 /* SPSpiral */
 
+class SpiralKnotHolderEntityInner : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+    virtual void knot_click_func(guint state);
+};
+
+class SpiralKnotHolderEntityOuter : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
+
+
 /*
  * set attributes via inner (t=t0) knot point:
  *   [default] increase/decrease inner point
  *   [shift]   increase/decrease inner and outer arg synchronizely
  *   [control] constrain inner arg to round per PI/4
  */
-static void
-sp_spiral_inner_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
+void
+SpiralKnotHolderEntityInner::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state)
 {
     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
 
@@ -1056,8 +1136,8 @@ sp_spiral_inner_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*
  *   [default] increase/decrease revolution factor
  *   [control] constrain inner arg to round per PI/4
  */
-static void
-sp_spiral_outer_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state)
+void
+SpiralKnotHolderEntityOuter::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state)
 {
     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
 
@@ -1129,22 +1209,24 @@ sp_spiral_outer_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*
     ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
 }
 
-static NR::Point sp_spiral_inner_get(SPItem *item)
+NR::Point
+SpiralKnotHolderEntityInner::knot_get_func()
 {
     SPSpiral *spiral = SP_SPIRAL(item);
 
     return sp_spiral_get_xy(spiral, spiral->t0);
 }
 
-static NR::Point sp_spiral_outer_get(SPItem *item)
+NR::Point
+SpiralKnotHolderEntityOuter::knot_get_func()
 {
     SPSpiral *spiral = SP_SPIRAL(item);
 
     return sp_spiral_get_xy(spiral, 1.0);
 }
 
-static void
-sp_spiral_inner_click(SPItem *item, guint state)
+void
+SpiralKnotHolderEntityInner::knot_click_func(guint state)
 {
     SPSpiral *spiral = SP_SPIRAL(item);
 
@@ -1157,25 +1239,33 @@ sp_spiral_inner_click(SPItem *item, guint state)
     }
 }
 
-static SPKnotHolder *
-sp_spiral_knot_holder(SPItem *item, SPDesktop *desktop)
+SpiralKnotHolder::SpiralKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
+    KnotHolder(desktop, item, relhandler)
 {
-    SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
+    SpiralKnotHolderEntityInner *entity_inner = new SpiralKnotHolderEntityInner();
+    SpiralKnotHolderEntityOuter *entity_outer = new SpiralKnotHolderEntityOuter();
+    entity_inner->create(desktop, item, this,
+                         _("Roll/unroll the spiral from <b>inside</b>; with <b>Ctrl</b> to snap angle; "
+                           "with <b>Alt</b> to converge/diverge"));
+    entity_outer->create(desktop, item, this,
+                         _("Roll/unroll the spiral from <b>outside</b>; with <b>Ctrl</b> to snap angle; "
+                           "with <b>Shift</b> to scale/rotate"));
+    entity.push_back(entity_inner);
+    entity.push_back(entity_outer);
 
-    sp_knot_holder_add(knot_holder, sp_spiral_inner_set, sp_spiral_inner_get, sp_spiral_inner_click,
-                       _("Roll/unroll the spiral from <b>inside</b>; with <b>Ctrl</b> to snap angle; with <b>Alt</b> to converge/diverge"));
-    sp_knot_holder_add(knot_holder, sp_spiral_outer_set, sp_spiral_outer_get, NULL,
-                       _("Roll/unroll the spiral from <b>outside</b>; with <b>Ctrl</b> to snap angle; with <b>Shift</b> to scale/rotate"));
-
-    sp_pat_knot_holder(item, knot_holder);
-
-    return knot_holder;
+    add_pattern_knotholder();
 }
 
 /* SPOffset */
 
-static void
-sp_offset_offset_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
+class OffsetKnotHolderEntity : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
+
+void
+OffsetKnotHolderEntity::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/)
 {
     SPOffset *offset = SP_OFFSET(item);
 
@@ -1187,7 +1277,8 @@ sp_offset_offset_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin
 }
 
 
-static NR::Point sp_offset_offset_get(SPItem *item)
+NR::Point
+OffsetKnotHolderEntity::knot_get_func()
 {
     SPOffset *offset = SP_OFFSET(item);
 
@@ -1196,77 +1287,50 @@ static NR::Point sp_offset_offset_get(SPItem *item)
     return np;
 }
 
-static SPKnotHolder *
-sp_offset_knot_holder(SPItem *item, SPDesktop *desktop)
+OffsetKnotHolder::OffsetKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
+    KnotHolder(desktop, item, relhandler)
 {
-    SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
-
-    sp_knot_holder_add(knot_holder, sp_offset_offset_set, sp_offset_offset_get, NULL,
-                       _("Adjust the <b>offset distance</b>"));
-
-    sp_pat_knot_holder(item, knot_holder);
+    OffsetKnotHolderEntity *entity_offset = new OffsetKnotHolderEntity();
+    entity_offset->create(desktop, item, this,
+                          _("Adjust the <b>offset distance</b>"));
+    entity.push_back(entity_offset);
 
-    return knot_holder;
+    add_pattern_knotholder();
 }
 
-static SPKnotHolder *
-sp_misc_knot_holder(SPItem *item, SPDesktop *desktop) // FIXME: eliminate, instead make a pattern-drag similar to gradient-drag
-{
-    if ((SP_OBJECT(item)->style->fill.isPaintserver())
-        && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
-    {
-        SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL);
-
-        sp_pat_knot_holder(item, knot_holder);
+class FlowtextKnotHolderEntity : public KnotHolderEntity {
+public:
+    virtual NR::Point knot_get_func();
+    virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state);
+};
 
-        return knot_holder;
-    }
-    return NULL;
-}
-
-static void
-sp_pat_knot_holder(SPItem *item, SPKnotHolder *knot_holder)
-{
-    if ((SP_OBJECT(item)->style->fill.isPaintserver())
-        && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)))
-    {
-        sp_knot_holder_add_full(knot_holder, sp_pattern_xy_set, sp_pattern_xy_get, NULL, SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,
-                                // TRANSLATORS: This refers to the pattern that's inside the object
-                                _("<b>Move</b> the pattern fill inside the object"));
-        sp_knot_holder_add_full(knot_holder, sp_pattern_scale_set, sp_pattern_scale_get, NULL, SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR,
-                                _("<b>Scale</b> the pattern fill uniformly"));
-        sp_knot_holder_add_full(knot_holder, sp_pattern_angle_set, sp_pattern_angle_get, NULL, SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR,
-                                _("<b>Rotate</b> the pattern fill; with <b>Ctrl</b> to snap angle"));
-    }
-}
-
-static NR::Point sp_flowtext_corner_get(SPItem *item)
+NR::Point
+FlowtextKnotHolderEntity::knot_get_func()
 {
     SPRect *rect = SP_RECT(item);
 
     return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
 }
 
-static void
-sp_flowtext_corner_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
+void
+FlowtextKnotHolderEntity::knot_set_func(NR::Point const &p, NR::Point const &origin, guint state)
 {
     SPRect *rect = SP_RECT(item);
 
     sp_rect_wh_set_internal(rect, p, origin, state);
 }
 
-static SPKnotHolder *
-sp_flowtext_knot_holder(SPItem *item, SPDesktop *desktop)
+FlowtextKnotHolder::FlowtextKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :
+    KnotHolder(desktop, item, relhandler)
 {
-    SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL);
-
-    sp_knot_holder_add(knot_holder, sp_flowtext_corner_set, sp_flowtext_corner_get, NULL,
-                       _("Drag to resize the <b>flowed text frame</b>"));
+    g_assert(item != NULL);
 
-    return knot_holder;
+    FlowtextKnotHolderEntity *entity_flowtext = new FlowtextKnotHolderEntity();
+    entity_flowtext->create(desktop, item, this,
+                            _("Drag to resize the <b>flowed text frame</b>"));
+    entity.push_back(entity_flowtext);
 }
 
-
 /*
   Local Variables:
   mode:c++
index 9fdc2365fa5629cef33fc0be4dbd24a6dc7ee655..9dda02e3498220f7c4ea030f8968420c4b6d878b 100644 (file)
 
 #include "knotholder.h"
 
-SPKnotHolder *sp_item_knot_holder (SPItem *item, SPDesktop *desktop);
+KnotHolder *sp_item_knot_holder (SPItem *item, SPDesktop *desktop);
+
+class RectKnotHolder : public KnotHolder {
+public:
+    RectKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler);
+    virtual ~RectKnotHolder() {};
+};
+
+class Box3DKnotHolder : public KnotHolder {
+public:
+    Box3DKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler);
+    virtual ~Box3DKnotHolder() {};
+};
+
+class ArcKnotHolder : public KnotHolder {
+public:
+    ArcKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler);
+    virtual ~ArcKnotHolder() {};
+};
+
+class StarKnotHolder : public KnotHolder {
+public:
+    StarKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler);
+    virtual ~StarKnotHolder() {};
+};
+
+class SpiralKnotHolder : public KnotHolder {
+public:
+    SpiralKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler);
+    virtual ~SpiralKnotHolder() {};
+};
+
+class OffsetKnotHolder : public KnotHolder {
+public:
+    OffsetKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler);
+    virtual ~OffsetKnotHolder() {};
+};
+
+class FlowtextKnotHolder : public KnotHolder {
+public:
+    FlowtextKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler);
+    virtual ~FlowtextKnotHolder() {};
+};
+
+class MiscKnotHolder : public KnotHolder {
+public:
+    MiscKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler);
+    virtual ~MiscKnotHolder() {};
+};
 
 #endif
 
index f53a399482ee40915684f56a1932f5e31759bae1..18904f9313d6a46268b66bf9bc23ae194de3b46d 100644 (file)
@@ -135,7 +135,7 @@ static void sp_rect_context_dispose(GObject *object)
     }
 
     if (ec->shape_knot_holder) {
-        sp_knot_holder_destroy(ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
         ec->shape_knot_holder = NULL;
     }
 
@@ -170,7 +170,7 @@ void sp_rect_context_selection_changed(Inkscape::Selection *selection, gpointer
     SPEventContext *ec = SP_EVENT_CONTEXT(rc);
 
     if (ec->shape_knot_holder) { // destroy knotholder
-        sp_knot_holder_destroy(ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
         ec->shape_knot_holder = NULL;
     }
 
index 782102b73980162a1b899cb2a2fadbf41684f4c4..ae2680f8f6fbceefdafb652356e8c77cb4a83c3d 100644 (file)
@@ -17,7 +17,6 @@
 #include <sigc++/sigc++.h>
 #include "event-context.h"
 #include "libnr/nr-point.h"
-struct SPKnotHolder;
 
 #define SP_TYPE_RECT_CONTEXT            (sp_rect_context_get_type ())
 #define SP_RECT_CONTEXT(obj)            (GTK_CHECK_CAST ((obj), SP_TYPE_RECT_CONTEXT, SPRectContext))
index 49d8a2a1442b51297739151851908313f072f7ab..3b892db038273d5cf503f249a42969608b3c25d0 100644 (file)
@@ -82,7 +82,7 @@ void ShapeEditor::unset_item() {
     }
 
     if (this->knotholder) {
-        sp_knot_holder_destroy(this->knotholder);
+        delete this->knotholder;
         this->knotholder = NULL;
     }
 }
@@ -257,7 +257,7 @@ void ShapeEditor::set_item_lpe_path_parameter(SPItem *item, SPObject *lpeobject,
 *  pass a new knotholder to ShapeEditor to manage (and delete)
 */
 void
-ShapeEditor::set_knotholder(SPKnotHolder * knot_holder)
+ShapeEditor::set_knotholder(KnotHolder * knot_holder)
 {
     unset_item();
 
index bc4d9eff3f7bef0efbcb537745a64b598d172ea8..b117c3ce9db64a8fd59437561f1af0bdf0ea1643 100644 (file)
@@ -24,7 +24,7 @@ class Path;
 #include "libnr/nr-point.h"
 #include "libnr/nr-maybe.h"
 
-class SPKnotHolder;
+class KnotHolder;
 class SPDesktop;
 class SPNodeContext;
 class ShapeEditorsCollective;
@@ -37,7 +37,7 @@ public:
 
     void set_item (SPItem *item);
     void set_item_lpe_path_parameter(SPItem *item, SPObject *lpeobject, const char * key);
-    void set_knotholder(SPKnotHolder * knot_holder);
+    void set_knotholder(KnotHolder * knot_holder);
     void reset_item ();
     void unset_item ();
 
@@ -121,7 +121,7 @@ private:
     SPDesktop *desktop;
 
     Inkscape::NodePath::Path *nodepath;
-    SPKnotHolder *knotholder;
+    KnotHolder *knotholder;
 
     ShapeEditorsCollective *container;
 
index e868593697e30ab300571ddb76e02deb07deb7d8..56c5b0ebd76bf89d1407b1e18b7d4a26ece8a483 100644 (file)
@@ -131,7 +131,7 @@ sp_spiral_context_dispose(GObject *object)
     if (sc->item) sp_spiral_finish(sc);
 
     if (ec->shape_knot_holder) {
-        sp_knot_holder_destroy(ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
         ec->shape_knot_holder = NULL;
     }
 
@@ -167,7 +167,7 @@ sp_spiral_context_selection_changed(Inkscape::Selection *selection, gpointer dat
     SPEventContext *ec = SP_EVENT_CONTEXT(sc);
 
     if (ec->shape_knot_holder) { // desktroy knotholder
-        sp_knot_holder_destroy(ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
         ec->shape_knot_holder = NULL;
     }
 
index 9ddff544122062f5b076b6db1d5ef4cb33d0f367..263e7b4127b6821a8644d7af5d97d869431c44f2 100644 (file)
@@ -17,7 +17,6 @@
 #include <sigc++/sigc++.h>
 #include "event-context.h"
 #include "libnr/nr-point.h"
-struct SPKnotHolder;
 
 #define SP_TYPE_SPIRAL_CONTEXT            (sp_spiral_context_get_type ())
 #define SP_SPIRAL_CONTEXT(obj)            (GTK_CHECK_CAST ((obj), SP_TYPE_SPIRAL_CONTEXT, SPSpiralContext))
index 1b3b1e7b05c25ec0b096409fb8f2a1839383eb58..c5fa5a0b975ce3907be51ad74e66e269de4da3e8 100644 (file)
@@ -132,7 +132,7 @@ sp_star_context_dispose (GObject *object)
     sc->sel_changed_connection.~connection();
 
     if (ec->shape_knot_holder) {
-        sp_knot_holder_destroy (ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
         ec->shape_knot_holder = NULL;
     }
 
@@ -174,7 +174,7 @@ sp_star_context_selection_changed (Inkscape::Selection * selection, gpointer dat
     SPEventContext *ec = SP_EVENT_CONTEXT (sc);
 
     if (ec->shape_knot_holder) { // desktroy knotholder
-        sp_knot_holder_destroy (ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
         ec->shape_knot_holder = NULL;
     }
 
index 6ad7025c0753d7e96d3f7661b73c76926fa270c1..37a7f587cdffa63fe8f9c4fa191c791bc40eabcc 100644 (file)
@@ -17,7 +17,6 @@
 #include <sigc++/sigc++.h>
 #include "event-context.h"
 #include "libnr/nr-point.h"
-struct SPKnotHolder;
 
 #define SP_TYPE_STAR_CONTEXT (sp_star_context_get_type ())
 #define SP_STAR_CONTEXT(obj) (GTK_CHECK_CAST ((obj), SP_TYPE_STAR_CONTEXT, SPStarContext))
index b79dce6c92dee88a5a18ed104d18105b694288fa..dc4de38e7dcd76a6c3801d50bef1a5528f1875ca 100644 (file)
@@ -185,7 +185,7 @@ sp_text_context_dispose(GObject *obj)
     Inkscape::Rubberband::get()->stop();
 
     if (ec->shape_knot_holder) {
-        sp_knot_holder_destroy(ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
         ec->shape_knot_holder = NULL;
     }
     if (ec->shape_repr) { // remove old listener
@@ -1377,7 +1377,7 @@ sp_text_context_selection_changed(Inkscape::Selection *selection, SPTextContext
     SPEventContext *ec = SP_EVENT_CONTEXT(tc);
 
     if (ec->shape_knot_holder) { // destroy knotholder
-        sp_knot_holder_destroy(ec->shape_knot_holder);
+        delete ec->shape_knot_holder;
         ec->shape_knot_holder = NULL;
     }
 
index c781f8e4dbc6f67627a3e74b138ea36d70c64c5a..9688b8501b4189a106d08ff3dcd616d6a3762ea9 100644 (file)
@@ -22,7 +22,7 @@
 #include "xml/repr.h"
 #include "perspective-line.h"
 
-#include "knotholder.h" // FIXME: can we avoid direct access to knotholder_update_knots?
+#include "knotholder.h" // FIXME: can we avoid direct access to KnotHolder::update_knots?
 
 namespace Box3D {
 
@@ -601,7 +601,7 @@ void
 VPDrag::updateBoxHandles ()
 {
     // FIXME: Is there a way to update the knots without accessing the
-    //        (previously) statically linked function knotholder_update_knots?
+    //        (previously) statically linked function KnotHolder::update_knots?
 
     GSList *sel = (GSList *) selection->itemList();
     if (!sel)
@@ -615,7 +615,7 @@ VPDrag::updateBoxHandles ()
     SPEventContext *ec = inkscape_active_event_context();
     g_assert (ec != NULL);
     if (ec->shape_knot_holder != NULL) {
-        knotholder_update_knots(ec->shape_knot_holder, (SPItem *) sel->data);
+        ec->shape_knot_holder->update_knots();
     }
 }