From e58cac52b258e64c2cc88b0044bf9cfbaecedce2 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 9 Apr 2013 00:23:07 +0200 Subject: Started conversion of SPEventContext tree; added virtual pads to all classes. (bzr r11608.1.89) --- src/arc-context.cpp | 61 +++++++++++++++++++++++++------ src/arc-context.h | 20 +++++++++- src/box3d-context.cpp | 61 +++++++++++++++++++++++++------ src/box3d-context.h | 20 +++++++++- src/common-context.cpp | 38 ++++++++++++++++--- src/common-context.h | 19 +++++++++- src/connector-context.cpp | 49 ++++++++++++++++++++++--- src/connector-context.h | 21 ++++++++++- src/draw-context.cpp | 43 +++++++++++++++++++--- src/draw-context.h | 20 +++++++++- src/dyna-draw-context.cpp | 46 +++++++++++++++++++---- src/dyna-draw-context.h | 19 +++++++++- src/eraser-context.cpp | 47 +++++++++++++++++++----- src/eraser-context.h | 19 +++++++++- src/event-context.cpp | 42 ++++++++++++++++++++- src/event-context.h | 24 +++++++++++- src/flood-context.cpp | 49 ++++++++++++++++++++----- src/flood-context.h | 19 +++++++++- src/gradient-context.cpp | 34 ++++++++++++++--- src/gradient-context.h | 17 ++++++++- src/lpe-tool-context.cpp | 51 ++++++++++++++++++++++---- src/lpe-tool-context.h | 20 +++++++++- src/mesh-context.cpp | 35 +++++++++++++++--- src/mesh-context.h | 17 ++++++++- src/pen-context.cpp | 69 ++++++++++++++++++++++++++++------- src/pen-context.h | 21 ++++++++++- src/pencil-context.cpp | 39 ++++++++++++++++---- src/pencil-context.h | 18 ++++++++- src/rect-context.cpp | 68 +++++++++++++++++++++++++++------- src/rect-context.h | 22 ++++++++++- src/select-context.cpp | 50 +++++++++++++++++++++---- src/select-context.h | 20 +++++++++- src/spiral-context.cpp | 49 +++++++++++++++++++++---- src/spiral-context.h | 20 +++++++++- src/star-context.cpp | 93 ++++++++++++++++++++++++++++++++--------------- src/star-context.h | 20 +++++++++- src/text-context.cpp | 55 +++++++++++++++++++++++----- src/text-context.h | 19 +++++++++- src/ui/tool/node-tool.cpp | 60 ++++++++++++++++++++++++------ src/ui/tool/node-tool.h | 20 +++++++++- 40 files changed, 1226 insertions(+), 208 deletions(-) (limited to 'src') diff --git a/src/arc-context.cpp b/src/arc-context.cpp index b5bdf58ef..9ebce7fac 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -75,8 +75,16 @@ static void sp_arc_context_class_init(SPArcContextClass *klass) event_context_class->item_handler = sp_arc_context_item_handler; } +CArcContext::CArcContext(SPArcContext* arccontext) : CEventContext(arccontext) { + this->sparccontext = arccontext; +} + static void sp_arc_context_init(SPArcContext *arc_context) { + arc_context->carccontext = new CArcContext(arc_context); + delete arc_context->ceventcontext; + arc_context->ceventcontext = arc_context->carccontext; + SPEventContext *event_context = SP_EVENT_CONTEXT(arc_context); event_context->cursor_shape = cursor_ellipse_xpm; @@ -96,6 +104,12 @@ static void sp_arc_context_init(SPArcContext *arc_context) static void sp_arc_context_finish(SPEventContext *ec) { + ec->ceventcontext->finish(); +} + +void CArcContext::finish() { + SPEventContext* ec = this->speventcontext; + SPArcContext *ac = SP_ARC_CONTEXT(ec); SPDesktop *desktop = ec->desktop; @@ -103,9 +117,10 @@ static void sp_arc_context_finish(SPEventContext *ec) sp_arc_finish(ac); ac->sel_changed_connection.disconnect(); - if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->finish) { - (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->finish(ec); - } +// if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->finish) { +// (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->finish(ec); +// } + CEventContext::finish(); } static void sp_arc_context_dispose(GObject *object) @@ -147,12 +162,19 @@ static void sp_arc_context_selection_changed(Inkscape::Selection * selection, gp static void sp_arc_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CArcContext::setup() { + SPEventContext* ec = this->speventcontext; + SPArcContext *ac = SP_ARC_CONTEXT(ec); Inkscape::Selection *selection = sp_desktop_selection(ec->desktop); - if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->setup) { - (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->setup(ec); - } +// if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->setup) { +// (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->setup(ec); +// } + CEventContext::setup(); ec->shape_editor = new ShapeEditor(ec->desktop); @@ -180,6 +202,12 @@ static void sp_arc_context_setup(SPEventContext *ec) static gint sp_arc_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event) { + return event_context->ceventcontext->item_handler(item, event); +} + +gint CArcContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + SPDesktop *desktop = event_context->desktop; gint ret = FALSE; @@ -195,15 +223,23 @@ static gint sp_arc_context_item_handler(SPEventContext *event_context, SPItem *i break; } - if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->item_handler) { - ret = (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->item_handler(event_context, item, event); - } +// if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->item_handler) { +// ret = (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->item_handler(event_context, item, event); +// } + // CPPIFY: ret is overwritten... + ret = CEventContext::item_handler(item, event); return ret; } static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CArcContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + static bool dragging; SPDesktop *desktop = event_context->desktop; @@ -377,9 +413,10 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->root_handler) { - ret = (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->root_handler(event_context, event); - } +// if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->root_handler) { +// ret = (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->root_handler(event_context, event); +// } + ret = CEventContext::root_handler(event); } return ret; diff --git a/src/arc-context.h b/src/arc-context.h index 3e4f5412d..7ad84f8a4 100644 --- a/src/arc-context.h +++ b/src/arc-context.h @@ -27,7 +27,12 @@ #define SP_IS_ARC_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_ARC_CONTEXT)) #define SP_IS_ARC_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_ARC_CONTEXT)) -struct SPArcContext : public SPEventContext { +class CArcContext; + +class SPArcContext : public SPEventContext { +public: + CArcContext* carccontext; + SPItem *item; Geom::Point center; @@ -40,6 +45,19 @@ struct SPArcContextClass { SPEventContextClass parent_class; }; +class CArcContext : public CEventContext { +public: + CArcContext(SPArcContext* arccontext); + + virtual void setup(); + virtual void finish(); + virtual gint root_handler(GdkEvent* event); + virtual gint item_handler(SPItem* item, GdkEvent* event); + +private: + SPArcContext* sparccontext; +}; + /* Standard Gtk function */ GType sp_arc_context_get_type(void); diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index 1af5ed29f..7bf1d51b6 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -79,8 +79,16 @@ static void sp_box3d_context_class_init(Box3DContextClass *klass) event_context_class->item_handler = sp_box3d_context_item_handler; } +CBox3DContext::CBox3DContext(Box3DContext* box3dcontext) : CEventContext(box3dcontext) { + this->box3dcontext = box3dcontext; +} + static void sp_box3d_context_init(Box3DContext *box3d_context) { + box3d_context->cbox3dcontext = new CBox3DContext(box3d_context); + delete box3d_context->ceventcontext; + box3d_context->ceventcontext = box3d_context->cbox3dcontext; + SPEventContext *event_context = SP_EVENT_CONTEXT(box3d_context); event_context->cursor_shape = cursor_3dbox_xpm; @@ -104,6 +112,12 @@ static void sp_box3d_context_init(Box3DContext *box3d_context) static void sp_box3d_context_finish(SPEventContext *ec) { + ec->ceventcontext->finish(); +} + +void CBox3DContext::finish() { + SPEventContext* ec = this->box3dcontext; + Box3DContext *bc = SP_BOX3D_CONTEXT(ec); SPDesktop *desktop = ec->desktop; @@ -112,9 +126,10 @@ static void sp_box3d_context_finish(SPEventContext *ec) bc->sel_changed_connection.disconnect(); // sp_repr_remove_listener_by_data(cc->active_shape_repr, cc); - if (((SPEventContextClass *) sp_box3d_context_parent_class)->finish) { - ((SPEventContextClass *) sp_box3d_context_parent_class)->finish(ec); - } +// if (((SPEventContextClass *) sp_box3d_context_parent_class)->finish) { +// ((SPEventContextClass *) sp_box3d_context_parent_class)->finish(ec); +// } + CEventContext::finish(); } @@ -186,11 +201,18 @@ static void sp_box3d_context_ensure_persp_in_defs(SPDocument *document) { static void sp_box3d_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CBox3DContext::setup() { + SPEventContext* ec = this->speventcontext; + Box3DContext *bc = SP_BOX3D_CONTEXT(ec); - if (((SPEventContextClass *) sp_box3d_context_parent_class)->setup) { - ((SPEventContextClass *) sp_box3d_context_parent_class)->setup(ec); - } +// if (((SPEventContextClass *) sp_box3d_context_parent_class)->setup) { +// ((SPEventContextClass *) sp_box3d_context_parent_class)->setup(ec); +// } + CEventContext::setup(); ec->shape_editor = new ShapeEditor(ec->desktop); @@ -220,6 +242,12 @@ static void sp_box3d_context_setup(SPEventContext *ec) static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event) { + return event_context->ceventcontext->item_handler(item, event); +} + +gint CBox3DContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + SPDesktop *desktop = event_context->desktop; gint ret = FALSE; @@ -236,15 +264,23 @@ static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem break; } - if (((SPEventContextClass *) sp_box3d_context_parent_class)->item_handler) { - ret = ((SPEventContextClass *) sp_box3d_context_parent_class)->item_handler(event_context, item, event); - } +// if (((SPEventContextClass *) sp_box3d_context_parent_class)->item_handler) { +// ret = ((SPEventContextClass *) sp_box3d_context_parent_class)->item_handler(event_context, item, event); +// } + // CPPIFY: ret is always overwritten... + ret = CEventContext::item_handler(item, event); return ret; } static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CBox3DContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + static bool dragging; SPDesktop *desktop = event_context->desktop; @@ -549,9 +585,10 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven } if (!ret) { - if (((SPEventContextClass *) sp_box3d_context_parent_class)->root_handler) { - ret = ((SPEventContextClass *) sp_box3d_context_parent_class)->root_handler(event_context, event); - } +// if (((SPEventContextClass *) sp_box3d_context_parent_class)->root_handler) { +// ret = ((SPEventContextClass *) sp_box3d_context_parent_class)->root_handler(event_context, event); +// } + ret = CEventContext::root_handler(event); } return ret; diff --git a/src/box3d-context.h b/src/box3d-context.h index 70ff87ad1..62c3dcd2a 100644 --- a/src/box3d-context.h +++ b/src/box3d-context.h @@ -27,7 +27,12 @@ #define SP_IS_BOX3D_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_BOX3D_CONTEXT)) #define SP_IS_BOX3D_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_BOX3D_CONTEXT)) -struct Box3DContext : public SPEventContext { +class CBox3DContext; + +class Box3DContext : public SPEventContext { +public: + CBox3DContext* cbox3dcontext; + SPItem *item; Geom::Point center; @@ -61,6 +66,19 @@ struct Box3DContextClass { SPEventContextClass parent_class; }; +class CBox3DContext : public CEventContext { +public: + CBox3DContext(Box3DContext* box3dcontext); + + virtual void setup(); + virtual void finish(); + virtual gint root_handler(GdkEvent* event); + virtual gint item_handler(SPItem* item, GdkEvent* event); + +private: + Box3DContext* box3dcontext; +}; + /* Standard Gtk function */ GType sp_box3d_context_get_type (void); diff --git a/src/common-context.cpp b/src/common-context.cpp index ff99b5c0b..39a0d7cde 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -40,8 +40,16 @@ static void sp_common_context_class_init(SPCommonContextClass *klass) event_context_class->root_handler = sp_common_context_root_handler; } +CCommonContext::CCommonContext(SPCommonContext* commoncontext) : CEventContext(commoncontext) { + this->spcommoncontext = commoncontext; +} + static void sp_common_context_init(SPCommonContext *ctx) { + ctx->ccommoncontext = new CCommonContext(ctx); + delete ctx->ceventcontext; + ctx->ceventcontext = ctx->ccommoncontext; + // ctx->cursor_shape = cursor_eraser_xpm; // ctx->hot_x = 4; // ctx->hot_y = 4; @@ -123,13 +131,24 @@ static void sp_common_context_dispose(GObject *object) static void sp_common_context_setup(SPEventContext *ec) { - if ( SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup ) { - SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup(ec); - } + ec->ceventcontext->setup(); +} + +void CCommonContext::setup() { +// if ( SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup ) { +// SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup(ec); +// } + CEventContext::setup(); } static void sp_common_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *value) { + ec->ceventcontext->set(value); +} + +void CCommonContext::set(Inkscape::Preferences::Entry* value) { + SPEventContext* ec = this->speventcontext; + SPCommonContext *ctx = SP_COMMON_CONTEXT(ec); Glib::ustring path = value->getEntryName(); @@ -166,15 +185,22 @@ static void sp_common_context_set(SPEventContext *ec, Inkscape::Preferences::Ent static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CCommonContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + gint ret = FALSE; // TODO add common hanlding if ( !ret ) { - if ( SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->root_handler ) { - ret = SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->root_handler(event_context, event); - } +// if ( SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->root_handler ) { +// ret = SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->root_handler(event_context, event); +// } + ret = CEventContext::root_handler(event); } return ret; diff --git a/src/common-context.h b/src/common-context.h index 8903be391..b4113b9a9 100644 --- a/src/common-context.h +++ b/src/common-context.h @@ -31,7 +31,12 @@ #define SAMPLING_SIZE 8 /* fixme: ?? */ -struct SPCommonContext : public SPEventContext { +class CCommonContext; + +class SPCommonContext : public SPEventContext { +public: + CCommonContext* ccommoncontext; + /** accumulated shape which ultimately goes in svg:path */ SPCurve *accumulated; @@ -98,6 +103,18 @@ struct SPCommonContext : public SPEventContext { struct SPCommonContextClass : public SPEventContextClass{}; +class CCommonContext : public CEventContext { +public: + CCommonContext(SPCommonContext* commoncontext); + + virtual void setup(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + +private: + SPCommonContext* spcommoncontext; +}; + GType sp_common_context_get_type(void); #endif // COMMON_CONTEXT_H_SEEN diff --git a/src/connector-context.cpp b/src/connector-context.cpp index 9468894a0..aff1dcb4c 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -188,10 +188,17 @@ sp_connector_context_class_init(SPConnectorContextClass *klass) event_context_class->item_handler = sp_connector_context_item_handler; } +CConnectorContext::CConnectorContext(SPConnectorContext* connectorcontext) : CEventContext(connectorcontext) { + this->spconnectorcontext = connectorcontext; +} static void sp_connector_context_init(SPConnectorContext *cc) { + cc->cconnectorcontext = new CConnectorContext(cc); + delete cc->ceventcontext; + cc->ceventcontext = cc->cconnectorcontext; + SPEventContext *ec = SP_EVENT_CONTEXT(cc); ec->cursor_shape = cursor_connector_xpm; @@ -265,6 +272,12 @@ sp_connector_context_dispose(GObject *object) static void sp_connector_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CConnectorContext::setup() { + SPConnectorContext* ec = this->spconnectorcontext; + SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec); SPDesktop *dt = ec->desktop; @@ -312,6 +325,12 @@ sp_connector_context_setup(SPEventContext *ec) static void sp_connector_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) { + ec->ceventcontext->set(val); +} + +void CConnectorContext::set(Inkscape::Preferences::Entry* val) { + SPEventContext* ec = this->spconnectorcontext; + SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec); /* fixme: Proper error handling for non-numeric data. Use a locale-independent function like @@ -328,6 +347,12 @@ sp_connector_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) static void sp_connector_context_finish(SPEventContext *ec) { + ec->ceventcontext->finish(); +} + +void CConnectorContext::finish() { + SPEventContext* ec = this->speventcontext; + SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec); spcc_connector_finish(cc); @@ -348,7 +373,6 @@ sp_connector_context_finish(SPEventContext *ec) desktop->canvas->gen_all_enter_events = false; } - //----------------------------------------------------------------------------- @@ -448,6 +472,12 @@ cc_deselect_handle(SPKnot* knot) static gint sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event) { + return event_context->ceventcontext->item_handler(item, event); +} + +gint CConnectorContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + gint ret = FALSE; SPDesktop *desktop = event_context->desktop; @@ -509,6 +539,12 @@ sp_connector_context_item_handler(SPEventContext *event_context, SPItem *item, G gint sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *event) { + return ec->ceventcontext->root_handler(event); +} + +gint CConnectorContext::root_handler(GdkEvent* event) { + SPEventContext* ec = this->speventcontext; + SPConnectorContext *const cc = SP_CONNECTOR_CONTEXT(ec); gint ret = FALSE; @@ -534,11 +570,12 @@ sp_connector_context_root_handler(SPEventContext *ec, GdkEvent *event) } if (!ret) { - gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) - = (SP_EVENT_CONTEXT_CLASS(sp_connector_context_parent_class))->root_handler; - if (parent_root_handler) { - ret = parent_root_handler(ec, event); - } +// gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) +// = (SP_EVENT_CONTEXT_CLASS(sp_connector_context_parent_class))->root_handler; +// if (parent_root_handler) { +// ret = parent_root_handler(ec, event); +// } + ret = CEventContext::root_handler(event); } return ret; diff --git a/src/connector-context.h b/src/connector-context.h index 597feac38..74f84540f 100644 --- a/src/connector-context.h +++ b/src/connector-context.h @@ -45,7 +45,12 @@ enum { typedef std::map SPKnotList; -struct SPConnectorContext : public SPEventContext { +class CConnectorContext; + +class SPConnectorContext : public SPEventContext { +public: + CConnectorContext* cconnectorcontext; + Inkscape::Selection *selection; Geom::Point p[5]; @@ -96,6 +101,20 @@ struct SPConnectorContext : public SPEventContext { struct SPConnectorContextClass : public SPEventContextClass { }; +class CConnectorContext : public CEventContext { +public: + CConnectorContext(SPConnectorContext* connectorcontext); + + virtual void setup(); + virtual void finish(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + virtual gint item_handler(SPItem* item, GdkEvent* event); + +private: + SPConnectorContext* spconnectorcontext; +}; + GType sp_connector_context_get_type(); void cc_selection_set_avoid(bool const set_ignore); diff --git a/src/draw-context.cpp b/src/draw-context.cpp index e62435004..647a9c192 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -92,8 +92,16 @@ static void sp_draw_context_class_init(SPDrawContextClass *klass) ec_class->root_handler = sp_draw_context_root_handler; } +CDrawContext::CDrawContext(SPDrawContext* drawcontext) : CEventContext(drawcontext) { + this->spdrawcontext = drawcontext; +} + static void sp_draw_context_init(SPDrawContext *dc) { + dc->cdrawcontext = new CDrawContext(dc); + delete dc->ceventcontext; + dc->ceventcontext = dc->cdrawcontext; + dc->attach = FALSE; dc->red_color = 0xff00007f; @@ -148,12 +156,19 @@ static void sp_draw_context_dispose(GObject *object) static void sp_draw_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CDrawContext::setup() { + SPEventContext* ec = this->speventcontext; + SPDrawContext *dc = SP_DRAW_CONTEXT(ec); SPDesktop *dt = ec->desktop; - if ((SP_EVENT_CONTEXT_CLASS(sp_draw_context_parent_class))->setup) { - (SP_EVENT_CONTEXT_CLASS(sp_draw_context_parent_class))->setup(ec); - } +// if ((SP_EVENT_CONTEXT_CLASS(sp_draw_context_parent_class))->setup) { +// (SP_EVENT_CONTEXT_CLASS(sp_draw_context_parent_class))->setup(ec); +// } + CEventContext::setup(); dc->selection = sp_desktop_selection(dt); @@ -192,6 +207,12 @@ static void sp_draw_context_setup(SPEventContext *ec) static void sp_draw_context_finish(SPEventContext *ec) { + ec->ceventcontext->finish(); +} + +void CDrawContext::finish() { + SPEventContext* ec = this->speventcontext; + SPDrawContext *dc = SP_DRAW_CONTEXT(ec); dc->sel_changed_connection.disconnect(); @@ -212,8 +233,17 @@ static void sp_draw_context_set(SPEventContext */*ec*/, Inkscape::Preferences::E { } +void CDrawContext::set(Inkscape::Preferences::Entry* value) { +} + gint sp_draw_context_root_handler(SPEventContext *ec, GdkEvent *event) { + return ec->ceventcontext->root_handler(event); +} + +gint CDrawContext::root_handler(GdkEvent* event) { + SPEventContext* ec = this->speventcontext; + gint ret = FALSE; switch (event->type) { @@ -237,9 +267,10 @@ gint sp_draw_context_root_handler(SPEventContext *ec, GdkEvent *event) } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(sp_draw_context_parent_class))->root_handler) { - ret = (SP_EVENT_CONTEXT_CLASS(sp_draw_context_parent_class))->root_handler(ec, event); - } +// if ((SP_EVENT_CONTEXT_CLASS(sp_draw_context_parent_class))->root_handler) { +// ret = (SP_EVENT_CONTEXT_CLASS(sp_draw_context_parent_class))->root_handler(ec, event); +// } + ret = CEventContext::root_handler(event); } return ret; diff --git a/src/draw-context.h b/src/draw-context.h index 98309c0cb..4cb1d5cc2 100644 --- a/src/draw-context.h +++ b/src/draw-context.h @@ -35,7 +35,12 @@ namespace Inkscape class Selection; } -struct SPDrawContext : public SPEventContext{ +class CDrawContext; + +class SPDrawContext : public SPEventContext{ +public: + CDrawContext* cdrawcontext; + Inkscape::Selection *selection; SPCanvasItem *grab; @@ -83,6 +88,19 @@ struct SPDrawContext : public SPEventContext{ struct SPDrawContextClass : public SPEventContextClass{}; +class CDrawContext : public CEventContext { +public: + CDrawContext(SPDrawContext* drawcontext); + + virtual void setup(); + virtual void finish(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + +protected: + SPDrawContext* spdrawcontext; +}; + GType sp_draw_context_get_type(void) G_GNUC_CONST; /** diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp index 742d52f09..0cf3e60bc 100644 --- a/src/dyna-draw-context.cpp +++ b/src/dyna-draw-context.cpp @@ -114,9 +114,18 @@ sp_dyna_draw_context_class_init(SPDynaDrawContextClass *klass) event_context_class->root_handler = sp_dyna_draw_context_root_handler; } +CDynaDrawContext::CDynaDrawContext(SPDynaDrawContext* dynadrawcontext) : CCommonContext(dynadrawcontext) { + this->spdynadrawcontext = dynadrawcontext; +} + static void sp_dyna_draw_context_init(SPDynaDrawContext *ddc) { + ddc->cdynadrawcontext = new CDynaDrawContext(ddc); + delete ddc->ccommoncontext; + ddc->ccommoncontext = ddc->cdynadrawcontext; + ddc->ceventcontext = ddc->cdynadrawcontext; + ddc->cursor_shape = cursor_calligraphy_xpm; ddc->hot_x = 4; ddc->hot_y = 4; @@ -167,10 +176,17 @@ sp_dyna_draw_context_dispose(GObject *object) static void sp_dyna_draw_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CDynaDrawContext::setup() { + SPEventContext* ec = this->spdynadrawcontext; + SPDynaDrawContext *ddc = SP_DYNA_DRAW_CONTEXT(ec); - if ((SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->setup) - (SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->setup(ec); +// if ((SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->setup) +// (SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->setup(ec); + CCommonContext::setup(); ddc->accumulated = new SPCurve(); ddc->currentcurve = new SPCurve(); @@ -227,6 +243,12 @@ sp_dyna_draw_context_setup(SPEventContext *ec) static void sp_dyna_draw_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) { + ec->ceventcontext->set(val); +} + +void CDynaDrawContext::set(Inkscape::Preferences::Entry* val) { + SPEventContext* ec = this->speventcontext; + SPDynaDrawContext *ddc = SP_DYNA_DRAW_CONTEXT(ec); Glib::ustring path = val->getEntryName(); @@ -236,9 +258,10 @@ sp_dyna_draw_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) ddc->keep_selected = val->getBool(); } else { //pass on up to parent class to handle common attributes. - if ( SP_COMMON_CONTEXT_CLASS(sp_dyna_draw_context_parent_class)->set ) { - SP_COMMON_CONTEXT_CLASS(sp_dyna_draw_context_parent_class)->set(ec, val); - } +// if ( SP_COMMON_CONTEXT_CLASS(sp_dyna_draw_context_parent_class)->set ) { +// SP_COMMON_CONTEXT_CLASS(sp_dyna_draw_context_parent_class)->set(ec, val); +// } + CCommonContext::set(val); } //g_print("DDC: %g %g %g %g\n", ddc->mass, ddc->drag, ddc->angle, ddc->width); @@ -505,6 +528,12 @@ gint sp_dyna_draw_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CDynaDrawContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + SPDynaDrawContext *dc = SP_DYNA_DRAW_CONTEXT(event_context); SPDesktop *desktop = event_context->desktop; @@ -948,9 +977,10 @@ sp_dyna_draw_context_root_handler(SPEventContext *event_context, } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->root_handler) { - ret = (SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->root_handler(event_context, event); - } +// if ((SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->root_handler) { +// ret = (SP_EVENT_CONTEXT_CLASS(sp_dyna_draw_context_parent_class))->root_handler(event_context, event); +// } + ret = CCommonContext::root_handler(event); } return ret; diff --git a/src/dyna-draw-context.h b/src/dyna-draw-context.h index 8509e450b..2beea4ddf 100644 --- a/src/dyna-draw-context.h +++ b/src/dyna-draw-context.h @@ -35,7 +35,12 @@ #define DDC_MAX_TILT 1.0 #define DDC_DEFAULT_TILT 0.0 -struct SPDynaDrawContext : public SPCommonContext { +class CDynaDrawContext; + +class SPDynaDrawContext : public SPCommonContext { +public: + CDynaDrawContext* cdynadrawcontext; + /** newly created object remain selected */ bool keep_selected; @@ -56,6 +61,18 @@ struct SPDynaDrawContext : public SPCommonContext { struct SPDynaDrawContextClass : public SPEventContextClass{}; +class CDynaDrawContext : public CCommonContext { +public: + CDynaDrawContext(SPDynaDrawContext* dynadrawcontext); + + virtual void setup(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + +private: + SPDynaDrawContext* spdynadrawcontext; +}; + GType sp_dyna_draw_context_get_type(void); #endif // SP_DYNA_DRAW_CONTEXT_H_SEEN diff --git a/src/eraser-context.cpp b/src/eraser-context.cpp index cd0b1dc3b..59cce31bd 100644 --- a/src/eraser-context.cpp +++ b/src/eraser-context.cpp @@ -116,9 +116,18 @@ sp_eraser_context_class_init(SPEraserContextClass *klass) event_context_class->root_handler = sp_eraser_context_root_handler; } +CEraserContext::CEraserContext(SPEraserContext* erasercontext) : CCommonContext(erasercontext) { + this->sperasercontext = erasercontext; +} + static void sp_eraser_context_init(SPEraserContext *erc) { + erc->cerasercontext = new CEraserContext(erc); + delete erc->ccommoncontext; + erc->ccommoncontext = erc->cerasercontext; + erc->ceventcontext = erc->cerasercontext; + erc->cursor_shape = cursor_eraser_xpm; erc->hot_x = 4; erc->hot_y = 4; @@ -133,11 +142,18 @@ sp_eraser_context_dispose(GObject *object) static void sp_eraser_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CEraserContext::setup() { + SPEventContext* ec = this->sperasercontext; + SPEraserContext *erc = SP_ERASER_CONTEXT(ec); SPDesktop *desktop = ec->desktop; - if ((SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class))->setup) - (SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class))->setup(ec); +// if ((SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class))->setup) +// (SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class))->setup(ec); + CCommonContext::setup(); erc->accumulated = new SPCurve(); erc->currentcurve = new SPCurve(); @@ -192,10 +208,17 @@ static ProfileFloatElement f_profile[PROFILE_FLOAT_SIZE] = { static void sp_eraser_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) { + ec->ceventcontext->set(val); +} + +void CEraserContext::set(Inkscape::Preferences::Entry* val) { + SPEventContext* ec = this->sperasercontext; + //pass on up to parent class to handle common attributes. - if (SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class)->set ) { - SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class)->set(ec, val); - } +// if (SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class)->set ) { +// SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class)->set(ec, val); +// } + CCommonContext::set(val); } static double @@ -445,6 +468,12 @@ gint sp_eraser_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CEraserContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->sperasercontext; + SPEraserContext *dc = SP_ERASER_CONTEXT(event_context); SPDesktop *desktop = event_context->desktop; @@ -660,15 +689,15 @@ sp_eraser_context_root_handler(SPEventContext *event_context, } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class))->root_handler) { - ret = (SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class))->root_handler(event_context, event); - } +// if ((SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class))->root_handler) { +// ret = (SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class))->root_handler(event_context, event); +// } + ret = CCommonContext::root_handler(event); } return ret; } - static void clear_current(SPEraserContext *dc) { diff --git a/src/eraser-context.h b/src/eraser-context.h index bc4268aef..ae73dc0ad 100644 --- a/src/eraser-context.h +++ b/src/eraser-context.h @@ -37,11 +37,28 @@ G_BEGIN_DECLS #define ERC_MAX_TILT 1.0 #define ERC_DEFAULT_TILT 0.0 -struct SPEraserContext : public SPCommonContext { +class CEraserContext; + +class SPEraserContext : public SPCommonContext { +public: + CEraserContext* cerasercontext; }; struct SPEraserContextClass : public SPEventContextClass{}; +class CEraserContext : public CCommonContext { +public: + CEraserContext(SPEraserContext* erasercontext); + + virtual void setup(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + +private: + SPEraserContext* sperasercontext; +}; + + GType sp_eraser_context_get_type(void); G_END_DECLS diff --git a/src/event-context.cpp b/src/event-context.cpp index 6e5f0caad..47c8eff95 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -96,10 +96,31 @@ static void sp_event_context_class_init(SPEventContextClass *klass) { klass->item_handler = sp_event_context_private_item_handler; } +CEventContext::CEventContext(SPEventContext* eventcontext) { + this->speventcontext = eventcontext; +} + +CEventContext::~CEventContext() { +} + +void CEventContext::set(Inkscape::Preferences::Entry* val) { +} + +void CEventContext::activate() { +} + +void CEventContext::deactivate() { +} + +void CEventContext::finish() { +} + /** * Clears all SPEventContext object members. */ static void sp_event_context_init(SPEventContext *event_context) { + event_context->ceventcontext = new CEventContext(event_context); + event_context->desktop = NULL; event_context->cursor = NULL; event_context->_message_context = NULL; @@ -233,7 +254,12 @@ void sp_event_context_update_cursor(SPEventContext *ec) { * Redraws mouse cursor, at the moment. */ static void sp_event_context_private_setup(SPEventContext *ec) { - sp_event_context_update_cursor(ec); + //sp_event_context_update_cursor(ec); + ec->ceventcontext->setup(); +} + +void CEventContext::setup() { + sp_event_context_update_cursor(this->speventcontext); } /** @@ -356,6 +382,13 @@ static gdouble accelerate_scroll(GdkEvent *event, gdouble acceleration, */ static gint sp_event_context_private_root_handler( SPEventContext *event_context, GdkEvent *event) { + + return event_context->ceventcontext->root_handler(event); +} + +gint CEventContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + static Geom::Point button_w; static unsigned int panning = 0; static unsigned int panning_cursor = 0; @@ -811,6 +844,13 @@ static gint sp_event_context_private_root_handler( */ gint sp_event_context_private_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event) { + + return ec->ceventcontext->item_handler(item, event); +} + +gint CEventContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* ec = this->speventcontext; + int ret = FALSE; switch (event->type) { diff --git a/src/event-context.h b/src/event-context.h index e97a8ad8f..ac1086def 100644 --- a/src/event-context.h +++ b/src/event-context.h @@ -91,6 +91,8 @@ private: void sp_event_context_snap_delay_handler(SPEventContext *ec, gpointer const dse_item, gpointer const dse_item2, GdkEventMotion *event, DelayedSnapEvent::DelayedSnapEventOrigin origin); +class CEventContext; + /** * Base class for Event processors. * @@ -104,11 +106,14 @@ void sp_event_context_snap_delay_handler(SPEventContext *ec, gpointer const dse_ * plus few abstract base classes. Writing a new tool involves * subclassing SPEventContext. */ -struct SPEventContext : public GObject { +class SPEventContext : public GObject { +public: void enableSelectionCue (bool enable=true); void enableGrDrag (bool enable=true); bool deleteSelectedDrag(bool just_one); + CEventContext* ceventcontext; + /// Desktop eventcontext stack SPEventContext *next; unsigned key; @@ -159,6 +164,23 @@ struct SPEventContextClass : public GObjectClass { gint (* item_handler)(SPEventContext *ec, SPItem *item, GdkEvent *event); }; +class CEventContext { +public: + CEventContext(SPEventContext* eventcontext); + virtual ~CEventContext(); + + virtual void setup(); + virtual void finish(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual void activate(); + virtual void deactivate(); + virtual gint root_handler(GdkEvent* event); + virtual gint item_handler(SPItem* item, GdkEvent* event); + +protected: + SPEventContext* speventcontext; +}; + #define SP_EVENT_CONTEXT_DESKTOP(e) (SP_EVENT_CONTEXT(e)->desktop) #define SP_EVENT_CONTEXT_DOCUMENT(e) ((SP_EVENT_CONTEXT_DESKTOP(e))->doc()) diff --git a/src/flood-context.cpp b/src/flood-context.cpp index a62be624c..d8f9a2624 100644 --- a/src/flood-context.cpp +++ b/src/flood-context.cpp @@ -98,8 +98,16 @@ static void sp_flood_context_class_init(SPFloodContextClass *klass) event_context_class->item_handler = sp_flood_context_item_handler; } +CFloodContext::CFloodContext(SPFloodContext* floodcontext) : CEventContext(floodcontext) { + this->spfloodcontext = floodcontext; +} + static void sp_flood_context_init(SPFloodContext *flood_context) { + flood_context->cfloodcontext = new CFloodContext(flood_context); + delete flood_context->ceventcontext; + flood_context->ceventcontext = flood_context->cfloodcontext; + SPEventContext *event_context = SP_EVENT_CONTEXT(flood_context); event_context->cursor_shape = cursor_paintbucket_xpm; @@ -155,11 +163,18 @@ static void sp_flood_context_selection_changed(Inkscape::Selection *selection, g static void sp_flood_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CFloodContext::setup() { + SPEventContext* ec = this->speventcontext; + SPFloodContext *rc = SP_FLOOD_CONTEXT(ec); - if (((SPEventContextClass *) sp_flood_context_parent_class)->setup) { - ((SPEventContextClass *) sp_flood_context_parent_class)->setup(ec); - } +// if (((SPEventContextClass *) sp_flood_context_parent_class)->setup) { +// ((SPEventContextClass *) sp_flood_context_parent_class)->setup(ec); +// } + CEventContext::setup(); ec->shape_editor = new ShapeEditor(ec->desktop); @@ -181,6 +196,7 @@ static void sp_flood_context_setup(SPEventContext *ec) } } + // Changes from 0.48 -> 0.49 (Cairo) // 0.49: Ignores alpha in background // 0.48: RGBA, 0.49 ARGB @@ -1120,6 +1136,12 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even static gint sp_flood_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event) { + return event_context->ceventcontext->item_handler(item, event); +} + +gint CFloodContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + gint ret = FALSE; SPDesktop *desktop = event_context->desktop; @@ -1142,15 +1164,23 @@ static gint sp_flood_context_item_handler(SPEventContext *event_context, SPItem break; } - if (((SPEventContextClass *) sp_flood_context_parent_class)->item_handler) { - ret = ((SPEventContextClass *) sp_flood_context_parent_class)->item_handler(event_context, item, event); - } +// if (((SPEventContextClass *) sp_flood_context_parent_class)->item_handler) { +// ret = ((SPEventContextClass *) sp_flood_context_parent_class)->item_handler(event_context, item, event); +// } + // CPPIFY: ret is overwritten... + ret = CEventContext::item_handler(item, event); return ret; } static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CFloodContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + static bool dragging; gint ret = FALSE; @@ -1250,9 +1280,10 @@ static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEven } if (!ret) { - if (((SPEventContextClass *) sp_flood_context_parent_class)->root_handler) { - ret = ((SPEventContextClass *) sp_flood_context_parent_class)->root_handler(event_context, event); - } +// if (((SPEventContextClass *) sp_flood_context_parent_class)->root_handler) { +// ret = ((SPEventContextClass *) sp_flood_context_parent_class)->root_handler(event_context, event); +// } + ret = CEventContext::root_handler(event); } return ret; diff --git a/src/flood-context.h b/src/flood-context.h index 3e81cd01e..fa22027f4 100644 --- a/src/flood-context.h +++ b/src/flood-context.h @@ -29,7 +29,12 @@ #define FLOOD_COLOR_CHANNEL_B 4 #define FLOOD_COLOR_CHANNEL_A 8 -struct SPFloodContext : public SPEventContext { +class CFloodContext; + +class SPFloodContext : public SPEventContext { +public: + CFloodContext* cfloodcontext; + SPItem *item; sigc::connection sel_changed_connection; @@ -41,6 +46,18 @@ struct SPFloodContextClass { SPEventContextClass parent_class; }; +class CFloodContext : public CEventContext { +public: + CFloodContext(SPFloodContext* floodcontext); + + virtual void setup(); + virtual gint root_handler(GdkEvent* event); + virtual gint item_handler(SPItem* item, GdkEvent* event); + +private: + SPFloodContext* spfloodcontext; +}; + /* Standard Gtk function */ GType sp_flood_context_get_type (void); diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp index 8fd002d70..6ca427098 100644 --- a/src/gradient-context.cpp +++ b/src/gradient-context.cpp @@ -72,8 +72,16 @@ static void sp_gradient_context_class_init(SPGradientContextClass *klass) event_context_class->root_handler = sp_gradient_context_root_handler; } +CGradientContext::CGradientContext(SPGradientContext* gradientcontext) : CEventContext(gradientcontext) { + this->spgradientcontext = gradientcontext; +} + static void sp_gradient_context_init(SPGradientContext *gr_context) { + gr_context->cgradientcontext = new CGradientContext(gr_context); + delete gr_context->ceventcontext; + gr_context->ceventcontext = gr_context->cgradientcontext; + SPEventContext *event_context = SP_EVENT_CONTEXT(gr_context); gr_context->cursor_addnode = false; @@ -178,11 +186,18 @@ gradient_subselection_changed (gpointer, gpointer data) static void sp_gradient_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CGradientContext::setup() { + SPEventContext* ec = this->speventcontext; + SPGradientContext *rc = SP_GRADIENT_CONTEXT(ec); - if (((SPEventContextClass *) sp_gradient_context_parent_class)->setup) { - ((SPEventContextClass *) sp_gradient_context_parent_class)->setup(ec); - } +// if (((SPEventContextClass *) sp_gradient_context_parent_class)->setup) { +// ((SPEventContextClass *) sp_gradient_context_parent_class)->setup(ec); +// } + CEventContext::setup(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/gradient/selcue", true)) { @@ -487,6 +502,12 @@ sp_gradient_context_add_stop_near_point (SPGradientContext *rc, SPItem *item, G static gint sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CGradientContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + static bool dragging; SPDesktop *desktop = event_context->desktop; @@ -855,9 +876,10 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event) } if (!ret) { - if (((SPEventContextClass *) sp_gradient_context_parent_class)->root_handler) { - ret = ((SPEventContextClass *) sp_gradient_context_parent_class)->root_handler(event_context, event); - } +// if (((SPEventContextClass *) sp_gradient_context_parent_class)->root_handler) { +// ret = ((SPEventContextClass *) sp_gradient_context_parent_class)->root_handler(event_context, event); +// } + ret = CEventContext::root_handler(event); } return ret; diff --git a/src/gradient-context.h b/src/gradient-context.h index 464b95ad4..a0d6d5a07 100644 --- a/src/gradient-context.h +++ b/src/gradient-context.h @@ -25,7 +25,11 @@ #define SP_IS_GRADIENT_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_GRADIENT_CONTEXT)) #define SP_IS_GRADIENT_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_GRADIENT_CONTEXT)) -struct SPGradientContext : public SPEventContext { +class CGradientContext; + +class SPGradientContext : public SPEventContext { +public: + CGradientContext* cgradientcontext; Geom::Point origin; @@ -45,6 +49,17 @@ struct SPGradientContextClass { SPEventContextClass parent_class; }; +class CGradientContext : public CEventContext { +public: + CGradientContext(SPGradientContext* gradientcontext); + + virtual void setup(); + virtual gint root_handler(GdkEvent* event); + +private: + SPGradientContext* spgradientcontext; +}; + /* Standard Gtk function */ GType sp_gradient_context_get_type(); diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp index feabfa02d..ddea7a579 100644 --- a/src/lpe-tool-context.cpp +++ b/src/lpe-tool-context.cpp @@ -80,9 +80,19 @@ sp_lpetool_context_class_init(SPLPEToolContextClass *klass) event_context_class->item_handler = sp_lpetool_context_item_handler; } +CLPEToolContext::CLPEToolContext(SPLPEToolContext* lpetoolcontext) : CPenContext(lpetoolcontext) { + this->splpetoolcontext = lpetoolcontext; +} + static void sp_lpetool_context_init(SPLPEToolContext *lc) { + lc->clpetoolcontext = new CLPEToolContext(lc); + delete lc->cpencontext; + lc->cpencontext = lc->clpetoolcontext; + lc->cdrawcontext = lc->clpetoolcontext; + lc->ceventcontext = lc->clpetoolcontext; + lc->cursor_shape = cursor_crosshairs_xpm; lc->hot_x = 7; lc->hot_y = 7; @@ -121,10 +131,17 @@ sp_lpetool_context_dispose(GObject *object) static void sp_lpetool_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CLPEToolContext::setup() { + SPEventContext* ec = this->speventcontext; + SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(ec); - if (((SPEventContextClass *) sp_lpetool_context_parent_class)->setup) - ((SPEventContextClass *) sp_lpetool_context_parent_class)->setup(ec); +// if (((SPEventContextClass *) sp_lpetool_context_parent_class)->setup) +// ((SPEventContextClass *) sp_lpetool_context_parent_class)->setup(ec); + CPenContext::setup(); Inkscape::Selection *selection = sp_desktop_selection (ec->desktop); SPItem *item = selection->singleItem(); @@ -172,6 +189,12 @@ void sp_lpetool_context_selection_changed(Inkscape::Selection *selection, gpoint static void sp_lpetool_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) { + ec->ceventcontext->set(val); +} + +void CLPEToolContext::set(Inkscape::Preferences::Entry* val) { + SPEventContext* ec = this->speventcontext; + if (val->getEntryName() == "mode") { Inkscape::Preferences::get()->setString("/tools/geometric/mode", "drag"); SP_PEN_CONTEXT(ec)->mode = SP_PEN_CONTEXT_MODE_DRAG; @@ -188,6 +211,12 @@ sp_lpetool_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) static gint sp_lpetool_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event) { + return ec->ceventcontext->item_handler(item, event); +} + +gint CLPEToolContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* ec = this->spdrawcontext; + gint ret = FALSE; switch (event->type) { @@ -209,8 +238,9 @@ sp_lpetool_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *even } if (!ret) { - if (((SPEventContextClass *) sp_lpetool_context_parent_class)->item_handler) - ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->item_handler(ec, item, event); +// if (((SPEventContextClass *) sp_lpetool_context_parent_class)->item_handler) +// ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->item_handler(ec, item, event); + ret = CPenContext::item_handler(item, event); } return ret; @@ -219,6 +249,12 @@ sp_lpetool_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *even gint sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CLPEToolContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(event_context); SPDesktop *desktop = event_context->desktop; Inkscape::Selection *selection = sp_desktop_selection (desktop); @@ -295,9 +331,10 @@ sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event) } if (!ret) { - if (((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler) { - ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event); - } +// if (((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler) { +// ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event); +// } + ret = CPenContext::root_handler(event); } return ret; diff --git a/src/lpe-tool-context.h b/src/lpe-tool-context.h index fb3a5d4e2..0035fd424 100644 --- a/src/lpe-tool-context.h +++ b/src/lpe-tool-context.h @@ -45,7 +45,12 @@ class Selection; class ShapeEditor; -struct SPLPEToolContext : public SPPenContext { +class CLPEToolContext; + +class SPLPEToolContext : public SPPenContext { +public: + CLPEToolContext* clpetoolcontext; + ShapeEditor* shape_editor; SPCanvasItem *canvas_bbox; Inkscape::LivePathEffect::EffectType mode; @@ -60,6 +65,19 @@ struct SPLPEToolContext : public SPPenContext { struct SPLPEToolContextClass : public SPEventContextClass{}; +class CLPEToolContext : public CPenContext { +public: + CLPEToolContext(SPLPEToolContext* lpetoolcontext); + + virtual void setup(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + virtual gint item_handler(SPItem* item, GdkEvent* event); + +private: + SPLPEToolContext* splpetoolcontext; +}; + int lpetool_mode_to_index(Inkscape::LivePathEffect::EffectType const type); int lpetool_item_has_construction(SPLPEToolContext *lc, SPItem *item); bool lpetool_try_construction(SPLPEToolContext *lc, Inkscape::LivePathEffect::EffectType const type); diff --git a/src/mesh-context.cpp b/src/mesh-context.cpp index 36712d15d..78cc49396 100644 --- a/src/mesh-context.cpp +++ b/src/mesh-context.cpp @@ -74,8 +74,16 @@ static void sp_mesh_context_class_init(SPMeshContextClass *klass) event_context_class->root_handler = sp_mesh_context_root_handler; } +CMeshContext::CMeshContext(SPMeshContext* meshcontext) : CEventContext(meshcontext) { + this->spmeshcontext = meshcontext; +} + static void sp_mesh_context_init(SPMeshContext *gr_context) { + gr_context->cmeshcontext = new CMeshContext(gr_context); + delete gr_context->ceventcontext; + gr_context->ceventcontext = gr_context->cmeshcontext; + SPEventContext *event_context = SP_EVENT_CONTEXT(gr_context); gr_context->cursor_addnode = false; @@ -244,11 +252,18 @@ mesh_subselection_changed (gpointer, gpointer data) static void sp_mesh_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CMeshContext::setup() { + SPEventContext* ec = this->speventcontext; + SPMeshContext *rc = SP_MESH_CONTEXT(ec); - if (((SPEventContextClass *) sp_mesh_context_parent_class)->setup) { - ((SPEventContextClass *) sp_mesh_context_parent_class)->setup(ec); - } +// if (((SPEventContextClass *) sp_mesh_context_parent_class)->setup) { +// ((SPEventContextClass *) sp_mesh_context_parent_class)->setup(ec); +// } + CEventContext::setup(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/mesh/selcue", true)) { @@ -455,6 +470,12 @@ Handles all keyboard and mouse input for meshs. static gint sp_mesh_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CMeshContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + // static int count = 0; // std::cout << "sp_mesh_context_root_handler: " << count++ << std::endl; static bool dragging; @@ -924,15 +945,17 @@ sp_mesh_context_root_handler(SPEventContext *event_context, GdkEvent *event) } if (!ret) { - if (((SPEventContextClass *) sp_mesh_context_parent_class)->root_handler) { - ret = ((SPEventContextClass *) sp_mesh_context_parent_class)->root_handler(event_context, event); - } +// if (((SPEventContextClass *) sp_mesh_context_parent_class)->root_handler) { +// ret = ((SPEventContextClass *) sp_mesh_context_parent_class)->root_handler(event_context, event); +// } + ret = CEventContext::root_handler(event); } return ret; } + static void sp_mesh_drag(SPMeshContext &rc, Geom::Point const /*pt*/, guint /*state*/, guint32 /*etime*/) { diff --git a/src/mesh-context.h b/src/mesh-context.h index e5d06ec0a..d4ccc502e 100644 --- a/src/mesh-context.h +++ b/src/mesh-context.h @@ -27,7 +27,11 @@ #define SP_IS_MESH_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_MESH_CONTEXT)) #define SP_IS_MESH_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_MESH_CONTEXT)) -struct SPMeshContext : public SPEventContext { +class CMeshContext; + +class SPMeshContext : public SPEventContext { +public: + CMeshContext* cmeshcontext; Geom::Point origin; @@ -47,6 +51,17 @@ struct SPMeshContextClass { SPEventContextClass parent_class; }; +class CMeshContext : public CEventContext { +public: + CMeshContext(SPMeshContext* meshcontext); + + virtual void setup(); + virtual gint root_handler(GdkEvent* event); + +private: + SPMeshContext* spmeshcontext; +}; + // Standard Gtk function GType sp_mesh_context_get_type(); diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 6e3ed201e..2c045f8ad 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -102,11 +102,20 @@ static void sp_pen_context_class_init(SPPenContextClass *klass) event_context_class->item_handler = sp_pen_context_item_handler; } +CPenContext::CPenContext(SPPenContext* pencontext) : CDrawContext(pencontext) { + this->sppencontext = pencontext; +} + /** * Callback to initialize SPPenContext object. */ static void sp_pen_context_init(SPPenContext *pc) { + pc->cpencontext = new CPenContext(pc); + delete pc->cdrawcontext; + pc->cdrawcontext = pc->cpencontext; + pc->ceventcontext = pc->cpencontext; + SPEventContext *event_context = SP_EVENT_CONTEXT(pc); event_context->cursor_shape = cursor_pen_xpm; @@ -173,11 +182,18 @@ void sp_pen_context_set_polyline_mode(SPPenContext *const pc) { */ static void sp_pen_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CPenContext::setup() { + SPEventContext* ec = this->speventcontext; + SPPenContext *pc = SP_PEN_CONTEXT(ec); - if (((SPEventContextClass *) sp_pen_context_parent_class)->setup) { - ((SPEventContextClass *) sp_pen_context_parent_class)->setup(ec); - } +// if (((SPEventContextClass *) sp_pen_context_parent_class)->setup) { +// ((SPEventContextClass *) sp_pen_context_parent_class)->setup(ec); +// } + CDrawContext::setup(); ControlManager &mgr = ControlManager::getManager(); @@ -229,6 +245,12 @@ static void pen_cancel (SPPenContext *const pc) */ static void sp_pen_context_finish(SPEventContext *ec) { + ec->ceventcontext->finish(); +} + +void CPenContext::finish() { + SPEventContext* ec = this->speventcontext; + SPPenContext *pc = SP_PEN_CONTEXT(ec); sp_event_context_discard_delayed_snap_event(ec); @@ -237,9 +259,10 @@ static void sp_pen_context_finish(SPEventContext *ec) pen_cancel (pc); } - if (((SPEventContextClass *) sp_pen_context_parent_class)->finish) { - ((SPEventContextClass *) sp_pen_context_parent_class)->finish(ec); - } +// if (((SPEventContextClass *) sp_pen_context_parent_class)->finish) { +// ((SPEventContextClass *) sp_pen_context_parent_class)->finish(ec); +// } + CDrawContext::finish(); } /** @@ -247,6 +270,12 @@ static void sp_pen_context_finish(SPEventContext *ec) */ static void sp_pen_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) { + ec->ceventcontext->set(val); +} + +void CPenContext::set(Inkscape::Preferences::Entry* val) { + SPEventContext* ec = this->speventcontext; + SPPenContext *pc = SP_PEN_CONTEXT(ec); Glib::ustring name = val->getEntryName(); @@ -303,6 +332,12 @@ static void spdc_endpoint_snap_handle(SPPenContext const *const pc, Geom::Point static gint sp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event) { + return ec->ceventcontext->item_handler(item, event); +} + +gint CPenContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* ec = this->speventcontext; + SPPenContext *const pc = SP_PEN_CONTEXT(ec); gint ret = FALSE; @@ -319,8 +354,9 @@ static gint sp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEve } if (!ret) { - if (((SPEventContextClass *) sp_pen_context_parent_class)->item_handler) - ret = ((SPEventContextClass *) sp_pen_context_parent_class)->item_handler(ec, item, event); +// if (((SPEventContextClass *) sp_pen_context_parent_class)->item_handler) +// ret = ((SPEventContextClass *) sp_pen_context_parent_class)->item_handler(ec, item, event); + ret = CDrawContext::item_handler(item, event); } return ret; @@ -331,6 +367,12 @@ static gint sp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEve */ static gint sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event) { + return ec->ceventcontext->root_handler(event); +} + +gint CPenContext::root_handler(GdkEvent* event) { + SPEventContext* ec = this->speventcontext; + SPPenContext *const pc = SP_PEN_CONTEXT(ec); gint ret = FALSE; @@ -361,11 +403,12 @@ static gint sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event) } if (!ret) { - gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) - = ((SPEventContextClass *) sp_pen_context_parent_class)->root_handler; - if (parent_root_handler) { - ret = parent_root_handler(ec, event); - } +// gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) +// = ((SPEventContextClass *) sp_pen_context_parent_class)->root_handler; +// if (parent_root_handler) { +// ret = parent_root_handler(ec, event); +// } + ret = CDrawContext::root_handler(event); } return ret; diff --git a/src/pen-context.h b/src/pen-context.h index a68b76ff5..ae50cba53 100644 --- a/src/pen-context.h +++ b/src/pen-context.h @@ -28,10 +28,15 @@ enum { struct SPCtrlLine; +class CPenContext; + /** * SPPenContext: a context for pen tool events. */ -struct SPPenContext : public SPDrawContext { +class SPPenContext : public SPDrawContext { +public: + CPenContext* cpencontext; + Geom::Point p[5]; /** \invar npoints in {0, 2, 5}. */ @@ -61,6 +66,20 @@ struct SPPenContext : public SPDrawContext { /// The SPPenContext vtable (empty). struct SPPenContextClass : public SPEventContextClass { }; +class CPenContext : public CDrawContext { +public: + CPenContext(SPPenContext* pencontext); + + virtual void setup(); + virtual void finish(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + virtual gint item_handler(SPItem* item, GdkEvent* event); + +private: + SPPenContext* sppencontext; +}; + GType sp_pen_context_get_type(); inline bool sp_pen_context_has_waiting_LPE(SPPenContext *pc) { diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 090a43a25..eefa30ad6 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -88,12 +88,21 @@ sp_pencil_context_class_init(SPPencilContextClass *klass) event_context_class->root_handler = sp_pencil_context_root_handler; } +CPencilContext::CPencilContext(SPPencilContext* pencilcontext) : CDrawContext(pencilcontext) { + this->sppencilcontext = pencilcontext; +} + /** * Callback to initialize SPPencilContext object. */ static void sp_pencil_context_init(SPPencilContext *pc) { + pc->cpencilcontext = new CPencilContext(pc); + delete pc->cdrawcontext; + pc->cdrawcontext = pc->cpencilcontext; + pc->ceventcontext = pc->cpencilcontext; + SPEventContext *event_context = SP_EVENT_CONTEXT(pc); event_context->cursor_shape = cursor_pencil_xpm; @@ -115,14 +124,21 @@ sp_pencil_context_init(SPPencilContext *pc) static void sp_pencil_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CPencilContext::setup() { + SPEventContext* ec = this->speventcontext; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/freehand/pencil/selcue")) { ec->enableSelectionCue(); } - if (((SPEventContextClass *) sp_pencil_context_parent_class)->setup) { - ((SPEventContextClass *) sp_pencil_context_parent_class)->setup(ec); - } +// if (((SPEventContextClass *) sp_pencil_context_parent_class)->setup) { +// ((SPEventContextClass *) sp_pencil_context_parent_class)->setup(ec); +// } + CDrawContext::setup(); SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec); pc->is_drawing = false; @@ -160,6 +176,12 @@ spdc_endpoint_snap(SPPencilContext const *pc, Geom::Point &p, guint const state) gint sp_pencil_context_root_handler(SPEventContext *const ec, GdkEvent *event) { + return ec->ceventcontext->root_handler(event); +} + +gint CPencilContext::root_handler(GdkEvent* event) { + SPEventContext* ec = this->speventcontext; + SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec); gint ret = FALSE; @@ -190,11 +212,12 @@ sp_pencil_context_root_handler(SPEventContext *const ec, GdkEvent *event) } if (!ret) { - gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) - = ((SPEventContextClass *) sp_pencil_context_parent_class)->root_handler; - if (parent_root_handler) { - ret = parent_root_handler(ec, event); - } +// gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) +// = ((SPEventContextClass *) sp_pencil_context_parent_class)->root_handler; +// if (parent_root_handler) { +// ret = parent_root_handler(ec, event); +// } + ret = CDrawContext::root_handler(event); } return ret; diff --git a/src/pencil-context.h b/src/pencil-context.h index aa0f60eb2..e757552d4 100644 --- a/src/pencil-context.h +++ b/src/pencil-context.h @@ -21,10 +21,15 @@ enum PencilState { SP_PENCIL_CONTEXT_SKETCH }; +class CPencilContext; + /** * SPPencilContext: a context for pencil tool events */ -struct SPPencilContext : public SPDrawContext { +class SPPencilContext : public SPDrawContext { +public: + CPencilContext* cpencilcontext; + Geom::Point p[16]; gint npoints; PencilState state; @@ -41,6 +46,17 @@ struct SPPencilContext : public SPDrawContext { /// The SPPencilContext vtable (empty). struct SPPencilContextClass : public SPEventContextClass { }; +class CPencilContext : public CDrawContext { +public: + CPencilContext(SPPencilContext* pencilcontext); + + virtual void setup(); + virtual gint root_handler(GdkEvent* event); + +private: + SPPencilContext* sppencilcontext; +}; + GType sp_pencil_context_get_type(); diff --git a/src/rect-context.cpp b/src/rect-context.cpp index 40e1d5b2a..a53a9c7b4 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -78,10 +78,18 @@ static void sp_rect_context_class_init(SPRectContextClass *klass) event_context_class->item_handler = sp_rect_context_item_handler; } +CRectContext::CRectContext(SPRectContext* rectcontext) : CEventContext(rectcontext) { + this->sprectcontext = rectcontext; +} + static void sp_rect_context_init(SPRectContext *rect_context) { SPEventContext *event_context = SP_EVENT_CONTEXT(rect_context); + rect_context->crectcontext = new CRectContext(rect_context); + delete rect_context->ceventcontext; + rect_context->ceventcontext = rect_context->crectcontext; + event_context->cursor_shape = cursor_rect_xpm; event_context->hot_x = 4; event_context->hot_y = 4; @@ -102,6 +110,12 @@ static void sp_rect_context_init(SPRectContext *rect_context) static void sp_rect_context_finish(SPEventContext *ec) { + ec->ceventcontext->finish(); +} + +void CRectContext::finish() { + SPEventContext* ec = this->speventcontext; + SPRectContext *rc = SP_RECT_CONTEXT(ec); SPDesktop *desktop = ec->desktop; @@ -109,12 +123,12 @@ static void sp_rect_context_finish(SPEventContext *ec) sp_rect_finish(rc); rc->sel_changed_connection.disconnect(); - if (((SPEventContextClass *) sp_rect_context_parent_class)->finish) { - ((SPEventContextClass *) sp_rect_context_parent_class)->finish(ec); - } +// if (((SPEventContextClass *) sp_rect_context_parent_class)->finish) { +// ((SPEventContextClass *) sp_rect_context_parent_class)->finish(ec); +// } + CEventContext::finish(); } - static void sp_rect_context_dispose(GObject *object) { SPRectContext *rc = SP_RECT_CONTEXT(object); @@ -156,11 +170,18 @@ static void sp_rect_context_selection_changed(Inkscape::Selection *selection, gp static void sp_rect_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CRectContext::setup() { + SPRectContext* ec = this->sprectcontext; + SPRectContext *rc = SP_RECT_CONTEXT(ec); - if (((SPEventContextClass *) sp_rect_context_parent_class)->setup) { - ((SPEventContextClass *) sp_rect_context_parent_class)->setup(ec); - } +// if (((SPEventContextClass *) sp_rect_context_parent_class)->setup) { +// ((SPEventContextClass *) sp_rect_context_parent_class)->setup(ec); +// } + CEventContext::setup(); ec->shape_editor = new ShapeEditor(ec->desktop); @@ -191,6 +212,12 @@ static void sp_rect_context_setup(SPEventContext *ec) static void sp_rect_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) { + ec->ceventcontext->set(val); +} + +void CRectContext::set(Inkscape::Preferences::Entry* val) { + SPEventContext* ec = this->speventcontext; + SPRectContext *rc = SP_RECT_CONTEXT(ec); /* fixme: Proper error handling for non-numeric data. Use a locale-independent function like @@ -205,6 +232,12 @@ static void sp_rect_context_set(SPEventContext *ec, Inkscape::Preferences::Entry static gint sp_rect_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event) { + return event_context->ceventcontext->item_handler(item, event); +} + +gint CRectContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + SPDesktop *desktop = event_context->desktop; gint ret = FALSE; @@ -221,15 +254,23 @@ static gint sp_rect_context_item_handler(SPEventContext *event_context, SPItem * break; } - if (((SPEventContextClass *) sp_rect_context_parent_class)->item_handler) { - ret = ((SPEventContextClass *) sp_rect_context_parent_class)->item_handler(event_context, item, event); - } +// if (((SPEventContextClass *) sp_rect_context_parent_class)->item_handler) { +// ret = ((SPEventContextClass *) sp_rect_context_parent_class)->item_handler(event_context, item, event); +// } + // CPPIFY: ret is always overwritten... + ret = CEventContext::item_handler(item, event); return ret; } static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CRectContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + static bool dragging; SPDesktop *desktop = event_context->desktop; @@ -434,9 +475,10 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent } if (!ret) { - if (((SPEventContextClass *) sp_rect_context_parent_class)->root_handler) { - ret = ((SPEventContextClass *) sp_rect_context_parent_class)->root_handler(event_context, event); - } +// if (((SPEventContextClass *) sp_rect_context_parent_class)->root_handler) { +// ret = ((SPEventContextClass *) sp_rect_context_parent_class)->root_handler(event_context, event); +// } + ret = CEventContext::root_handler(event); } return ret; diff --git a/src/rect-context.h b/src/rect-context.h index 5b6c5373e..2001716ba 100644 --- a/src/rect-context.h +++ b/src/rect-context.h @@ -25,7 +25,12 @@ #define SP_IS_RECT_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_RECT_CONTEXT)) #define SP_IS_RECT_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_RECT_CONTEXT)) -struct SPRectContext : public SPEventContext { +class CRectContext; + +class SPRectContext : public SPEventContext { +public: + CRectContext* crectcontext; + SPItem *item; Geom::Point center; @@ -41,6 +46,21 @@ struct SPRectContextClass { SPEventContextClass parent_class; }; +class CRectContext : public CEventContext { +public: + CRectContext(SPRectContext* rectcontext); + + virtual void setup(); + virtual void finish(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + virtual gint item_handler(SPItem* item, GdkEvent* event); + +protected: + SPRectContext* sprectcontext; +}; + + /* Standard Gtk function */ GType sp_rect_context_get_type (void); diff --git a/src/select-context.cpp b/src/select-context.cpp index 2684cbc1e..294849e44 100644 --- a/src/select-context.cpp +++ b/src/select-context.cpp @@ -85,9 +85,17 @@ sp_select_context_class_init(SPSelectContextClass *klass) event_context_class->item_handler = sp_select_context_item_handler; } +CSelectContext::CSelectContext(SPSelectContext* selectcontext) : CEventContext(selectcontext) { + this->spselectcontext = selectcontext; +} + static void sp_select_context_init(SPSelectContext *sc) { + sc->cselectcontext = new CSelectContext(sc); + delete sc->ceventcontext; + sc->ceventcontext = sc->cselectcontext; + sc->dragging = FALSE; sc->moved = FALSE; sc->button_press_shift = false; @@ -161,11 +169,18 @@ sp_select_context_dispose(GObject *object) static void sp_select_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CSelectContext::setup() { + SPEventContext* ec = this->speventcontext; + SPSelectContext *select_context = SP_SELECT_CONTEXT(ec); - if ((SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->setup) { - (SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->setup(ec); - } +// if ((SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->setup) { +// (SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->setup(ec); +// } + CEventContext::setup(); SPDesktop *desktop = ec->desktop; @@ -190,6 +205,12 @@ sp_select_context_setup(SPEventContext *ec) static void sp_select_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) { + ec->ceventcontext->set(val); +} + +void CSelectContext::set(Inkscape::Preferences::Entry* val) { + SPEventContext* ec = this->speventcontext; + SPSelectContext *sc = SP_SELECT_CONTEXT(ec); Glib::ustring path = val->getEntryName(); @@ -292,6 +313,12 @@ sp_select_context_up_one_layer(SPDesktop *desktop) static gint sp_select_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event) { + return event_context->ceventcontext->item_handler(item, event); +} + +gint CSelectContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + gint ret = FALSE; SPDesktop *desktop = event_context->desktop; @@ -407,8 +434,9 @@ sp_select_context_item_handler(SPEventContext *event_context, SPItem *item, GdkE } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->item_handler) - ret = (SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->item_handler(event_context, item, event); +// if ((SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->item_handler) +// ret = (SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->item_handler(event_context, item, event); + ret = CEventContext::item_handler(item, event); } return ret; @@ -456,6 +484,12 @@ sp_select_context_cycle_through_items(SPSelectContext *sc, Inkscape::Selection * static gint sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CSelectContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + SPItem *item = NULL; SPItem *item_at_point = NULL, *group_at_point = NULL, *item_in_group = NULL; gint ret = FALSE; @@ -1125,14 +1159,14 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->root_handler) - ret = (SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->root_handler(event_context, event); +// if ((SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->root_handler) +// ret = (SP_EVENT_CONTEXT_CLASS(sp_select_context_parent_class))->root_handler(event_context, event); + ret = CEventContext::root_handler(event); } return ret; } - /* Local Variables: mode:c++ diff --git a/src/select-context.h b/src/select-context.h index a6877f802..8611177e7 100644 --- a/src/select-context.h +++ b/src/select-context.h @@ -29,7 +29,12 @@ namespace Inkscape { class SelectionDescriber; } -struct SPSelectContext : public SPEventContext { +class CSelectContext; + +class SPSelectContext : public SPEventContext { +public: + CSelectContext* cselectcontext; + guint dragging : 1; guint moved : 1; bool button_press_shift; @@ -52,6 +57,19 @@ struct SPSelectContextClass { SPEventContextClass parent_class; }; +class CSelectContext : public CEventContext { +public: + CSelectContext(SPSelectContext* selectcontext); + + virtual void setup(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + virtual gint item_handler(SPItem* item, GdkEvent* event); + +private: + SPSelectContext* spselectcontext; +}; + /* Standard Gtk function */ GType sp_select_context_get_type (void); diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index c54e7c487..fb5a85089 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -73,9 +73,17 @@ sp_spiral_context_class_init(SPSpiralContextClass *klass) event_context_class->root_handler = sp_spiral_context_root_handler; } +CSpiralContext::CSpiralContext(SPSpiralContext* spiralcontext) : CEventContext(spiralcontext) { + this->spspiralcontext = spiralcontext; +} + static void sp_spiral_context_init(SPSpiralContext *spiral_context) { + spiral_context->cspiralcontext = new CSpiralContext(spiral_context); + delete spiral_context->ceventcontext; + spiral_context->ceventcontext = spiral_context->cspiralcontext; + SPEventContext *event_context = SP_EVENT_CONTEXT(spiral_context); event_context->cursor_shape = cursor_spiral_xpm; @@ -98,6 +106,12 @@ sp_spiral_context_init(SPSpiralContext *spiral_context) static void sp_spiral_context_finish(SPEventContext *ec) { + ec->ceventcontext->finish(); +} + +void CSpiralContext::finish() { + SPEventContext* ec = this->speventcontext; + SPSpiralContext *sc = SP_SPIRAL_CONTEXT(ec); SPDesktop *desktop = ec->desktop; @@ -105,9 +119,10 @@ static void sp_spiral_context_finish(SPEventContext *ec) sp_spiral_finish(sc); sc->sel_changed_connection.disconnect(); - if ((SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->finish) { - (SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->finish(ec); - } +// if ((SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->finish) { +// (SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->finish(ec); +// } + CEventContext::finish(); } static void @@ -151,10 +166,17 @@ static void sp_spiral_context_selection_changed(Inkscape::Selection *selection, static void sp_spiral_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CSpiralContext::setup() { + SPEventContext* ec = this->speventcontext; + SPSpiralContext *sc = SP_SPIRAL_CONTEXT(ec); - if ((SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->setup) - (SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->setup(ec); +// if ((SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->setup) +// (SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->setup(ec); + CEventContext::setup(); sp_event_context_read(ec, "expansion"); sp_event_context_read(ec, "revolution"); @@ -185,6 +207,12 @@ sp_spiral_context_setup(SPEventContext *ec) static void sp_spiral_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) { + ec->ceventcontext->set(val); +} + +void CSpiralContext::set(Inkscape::Preferences::Entry* val) { + SPEventContext* ec = this->speventcontext; + SPSpiralContext *sc = SP_SPIRAL_CONTEXT(ec); Glib::ustring name = val->getEntryName(); @@ -200,6 +228,12 @@ sp_spiral_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) static gint sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CSpiralContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + static gboolean dragging; SPDesktop *desktop = event_context->desktop; @@ -374,8 +408,9 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->root_handler) - ret = (SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->root_handler(event_context, event); +// if ((SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->root_handler) +// ret = (SP_EVENT_CONTEXT_CLASS(sp_spiral_context_parent_class))->root_handler(event_context, event); + ret = CEventContext::root_handler(event); } return ret; diff --git a/src/spiral-context.h b/src/spiral-context.h index 7f696dfa2..3f1dc238d 100644 --- a/src/spiral-context.h +++ b/src/spiral-context.h @@ -27,7 +27,12 @@ #define SP_IS_SPIRAL_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_SPIRAL_CONTEXT)) #define SP_IS_SPIRAL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_SPIRAL_CONTEXT)) -struct SPSpiralContext : public SPEventContext { +class CSpiralContext; + +class SPSpiralContext : public SPEventContext { +public: + CSpiralContext* cspiralcontext; + SPItem * item; Geom::Point center; gdouble revo; @@ -43,6 +48,19 @@ struct SPSpiralContextClass { SPEventContextClass parent_class; }; +class CSpiralContext : public CEventContext { +public: + CSpiralContext(SPSpiralContext* spiralcontext); + + virtual void setup(); + virtual void finish(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + +private: + SPSpiralContext* spspiralcontext; +}; + /* Standard Gtk function */ GType sp_spiral_context_get_type (void); diff --git a/src/star-context.cpp b/src/star-context.cpp index 35ea79462..dec70eb4a 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -77,9 +77,17 @@ sp_star_context_class_init (SPStarContextClass * klass) event_context_class->root_handler = sp_star_context_root_handler; } +CStarContext::CStarContext(SPStarContext* starcontext) : CEventContext(starcontext) { + this->spstarcontext = starcontext; +} + static void sp_star_context_init (SPStarContext * star_context) { + star_context->cstarcontext = new CStarContext(star_context); + delete star_context->ceventcontext; + star_context->ceventcontext = star_context->cstarcontext; + SPEventContext *event_context = SP_EVENT_CONTEXT (star_context); event_context->cursor_shape = cursor_star_xpm; @@ -103,6 +111,12 @@ sp_star_context_init (SPStarContext * star_context) static void sp_star_context_finish(SPEventContext *ec) { + ec->ceventcontext->finish(); +} + +void CStarContext::finish() { + SPEventContext* ec = this->speventcontext; + SPStarContext *sc = SP_STAR_CONTEXT(ec); SPDesktop *desktop = ec->desktop; @@ -110,9 +124,10 @@ static void sp_star_context_finish(SPEventContext *ec) sp_star_finish(sc); sc->sel_changed_connection.disconnect(); - if ((SP_EVENT_CONTEXT_CLASS(sp_star_context_parent_class))->finish) { - (SP_EVENT_CONTEXT_CLASS(sp_star_context_parent_class))->finish(ec); - } +// if ((SP_EVENT_CONTEXT_CLASS(sp_star_context_parent_class))->finish) { +// (SP_EVENT_CONTEXT_CLASS(sp_star_context_parent_class))->finish(ec); +// } + CEventContext::finish(); } @@ -161,43 +176,56 @@ static void sp_star_context_selection_changed (Inkscape::Selection * selection, static void sp_star_context_setup (SPEventContext *ec) { - SPStarContext *sc = SP_STAR_CONTEXT (ec); + ec->ceventcontext->setup(); +} - if ((SP_EVENT_CONTEXT_CLASS(sp_star_context_parent_class))->setup) - (SP_EVENT_CONTEXT_CLASS(sp_star_context_parent_class))->setup (ec); +void CStarContext::setup() { + SPEventContext* ec = this->speventcontext; - sp_event_context_read (ec, "magnitude"); - sp_event_context_read (ec, "proportion"); - sp_event_context_read (ec, "isflatsided"); - sp_event_context_read (ec, "rounded"); - sp_event_context_read (ec, "randomized"); + SPStarContext *sc = SP_STAR_CONTEXT (ec); - ec->shape_editor = new ShapeEditor(ec->desktop); +// if ((SP_EVENT_CONTEXT_CLASS(sp_star_context_parent_class))->setup) +// (SP_EVENT_CONTEXT_CLASS(sp_star_context_parent_class))->setup (ec); + CEventContext::setup(); - SPItem *item = sp_desktop_selection(ec->desktop)->singleItem(); - if (item) { - ec->shape_editor->set_item(item, SH_KNOTHOLDER); - } + sp_event_context_read (ec, "magnitude"); + sp_event_context_read (ec, "proportion"); + sp_event_context_read (ec, "isflatsided"); + sp_event_context_read (ec, "rounded"); + sp_event_context_read (ec, "randomized"); - Inkscape::Selection *selection = sp_desktop_selection(ec->desktop); - sc->sel_changed_connection.disconnect(); - sc->sel_changed_connection = selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_star_context_selection_changed), (gpointer)sc)); + ec->shape_editor = new ShapeEditor(ec->desktop); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (prefs->getBool("/tools/shapes/selcue")) { - ec->enableSelectionCue(); - } + SPItem *item = sp_desktop_selection(ec->desktop)->singleItem(); + if (item) { + ec->shape_editor->set_item(item, SH_KNOTHOLDER); + } - if (prefs->getBool("/tools/shapes/gradientdrag")) { - ec->enableGrDrag(); - } + Inkscape::Selection *selection = sp_desktop_selection(ec->desktop); + sc->sel_changed_connection.disconnect(); + sc->sel_changed_connection = selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_star_context_selection_changed), (gpointer)sc)); + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/tools/shapes/selcue")) { + ec->enableSelectionCue(); + } - sc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); + if (prefs->getBool("/tools/shapes/gradientdrag")) { + ec->enableGrDrag(); + } + + sc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); } static void sp_star_context_set (SPEventContext *ec, Inkscape::Preferences::Entry *val) { + ec->ceventcontext->set(val); +} + +void CStarContext::set(Inkscape::Preferences::Entry* val) { + SPEventContext* ec = this->speventcontext; + SPStarContext *sc = SP_STAR_CONTEXT (ec); Glib::ustring path = val->getEntryName(); @@ -216,6 +244,12 @@ sp_star_context_set (SPEventContext *ec, Inkscape::Preferences::Entry *val) static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CStarContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + static gboolean dragging; SPDesktop *desktop = event_context->desktop; @@ -389,8 +423,9 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(sp_star_context_parent_class))->root_handler) - ret = (SP_EVENT_CONTEXT_CLASS(sp_star_context_parent_class))->root_handler (event_context, event); +// if ((SP_EVENT_CONTEXT_CLASS(sp_star_context_parent_class))->root_handler) +// ret = (SP_EVENT_CONTEXT_CLASS(sp_star_context_parent_class))->root_handler (event_context, event); + ret = CEventContext::root_handler(event); } return ret; diff --git a/src/star-context.h b/src/star-context.h index 4daafb3e4..83e6c0b26 100644 --- a/src/star-context.h +++ b/src/star-context.h @@ -25,7 +25,12 @@ #define SP_IS_STAR_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_STAR_CONTEXT)) #define SP_IS_STAR_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_STAR_CONTEXT)) -struct SPStarContext : public SPEventContext { +class CStarContext; + +class SPStarContext : public SPEventContext { +public: + CStarContext* cstarcontext; + SPItem *item; Geom::Point center; @@ -49,6 +54,19 @@ struct SPStarContextClass { SPEventContextClass parent_class; }; +class CStarContext : public CEventContext { +public: + CStarContext(SPStarContext* starcontext); + + virtual void setup(); + virtual void finish(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + +private: + SPStarContext* spstarcontext; +}; + GType sp_star_context_get_type (void); #endif diff --git a/src/text-context.cpp b/src/text-context.cpp index 1ee21e732..72fcd6319 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -94,8 +94,16 @@ static void sp_text_context_class_init(SPTextContextClass *klass) event_context_class->item_handler = sp_text_context_item_handler; } +CTextContext::CTextContext(SPTextContext* textcontext) : CEventContext(textcontext) { + this->sptextcontext = textcontext; +} + static void sp_text_context_init(SPTextContext *tc) { + tc->ctextcontext = new CTextContext(tc); + delete tc->ceventcontext; + tc->ceventcontext = tc->ctextcontext; + SPEventContext *event_context = SP_EVENT_CONTEXT(tc); event_context->cursor_shape = cursor_text_xpm; @@ -163,6 +171,12 @@ static void sp_text_context_dispose(GObject *obj) static void sp_text_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CTextContext::setup() { + SPEventContext* ec = this->speventcontext; + SPTextContext *tc = SP_TEXT_CONTEXT(ec); SPDesktop *desktop = ec->desktop; GtkSettings* settings = gtk_settings_get_default(); @@ -213,8 +227,9 @@ static void sp_text_context_setup(SPEventContext *ec) } } - if ((SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->setup) - (SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->setup(ec); +// if ((SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->setup) +// (SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->setup(ec); + CEventContext::setup(); ec->shape_editor = new ShapeEditor(ec->desktop); @@ -249,6 +264,12 @@ static void sp_text_context_setup(SPEventContext *ec) static void sp_text_context_finish(SPEventContext *ec) { + ec->ceventcontext->finish(); +} + +void CTextContext::finish() { + SPEventContext* ec = this->speventcontext; + SPTextContext *tc = SP_TEXT_CONTEXT(ec); if (ec->desktop) { @@ -297,9 +318,14 @@ static void sp_text_context_finish(SPEventContext *ec) tc->text_selection_quads.clear(); } - static gint sp_text_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event) { + return event_context->ceventcontext->item_handler(item, event); +} + +gint CTextContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + SPTextContext *tc = SP_TEXT_CONTEXT(event_context); SPDesktop *desktop = event_context->desktop; SPItem *item_ungrouped; @@ -432,8 +458,9 @@ static gint sp_text_context_item_handler(SPEventContext *event_context, SPItem * } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->item_handler) - ret = (SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->item_handler(event_context, item, event); +// if ((SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->item_handler) +// ret = (SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->item_handler(event_context, item, event); + ret = CEventContext::item_handler(item, event); } return ret; @@ -556,6 +583,12 @@ static void show_curr_uni_char(SPTextContext *const tc) static gint sp_text_context_root_handler(SPEventContext *const event_context, GdkEvent *const event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CTextContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + SPTextContext *const tc = SP_TEXT_CONTEXT(event_context); SPDesktop *desktop = event_context->desktop; @@ -1301,11 +1334,13 @@ static gint sp_text_context_root_handler(SPEventContext *const event_context, Gd } // if nobody consumed it so far - if ((SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->root_handler) { // and there's a handler in parent context, - return (SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->root_handler(event_context, event); // send event to parent - } else { - return FALSE; // return "I did nothing" value so that global shortcuts can be activated - } +// if ((SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->root_handler) { // and there's a handler in parent context, +// return (SP_EVENT_CONTEXT_CLASS(sp_text_context_parent_class))->root_handler(event_context, event); // send event to parent +// } else { +// return FALSE; // return "I did nothing" value so that global shortcuts can be activated +// } + return CEventContext::root_handler(event); + } /** diff --git a/src/text-context.h b/src/text-context.h index a33c69e0a..67686cc35 100644 --- a/src/text-context.h +++ b/src/text-context.h @@ -31,7 +31,11 @@ struct SPCtrlLine; -struct SPTextContext : public SPEventContext { +class CTextContext; + +class SPTextContext : public SPEventContext { +public: + CTextContext* ctextcontext; sigc::connection sel_changed_connection; sigc::connection sel_modified_connection; @@ -77,6 +81,19 @@ struct SPTextContextClass { SPEventContextClass parent_class; }; +class CTextContext : public CEventContext { +public: + CTextContext(SPTextContext* textcontext); + + virtual void setup(); + virtual void finish(); + virtual gint root_handler(GdkEvent* event); + virtual gint item_handler(SPItem* item, GdkEvent* event); + +private: + SPTextContext* sptextcontext; +}; + /* Standard Gtk function */ GType sp_text_context_get_type (void); diff --git a/src/ui/tool/node-tool.cpp b/src/ui/tool/node-tool.cpp index e743e0efc..9a51870af 100644 --- a/src/ui/tool/node-tool.cpp +++ b/src/ui/tool/node-tool.cpp @@ -104,7 +104,7 @@ using Inkscape::ControlManager; -namespace { +//namespace { SPCanvasGroup *create_control_group(SPDesktop *d); void ink_node_tool_dispose(GObject *object); @@ -122,7 +122,7 @@ void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint void handleControlUiStyleChange(InkNodeTool *nt); -} // anonymous namespace +//} // anonymous namespace G_DEFINE_TYPE(InkNodeTool, ink_node_tool, SP_TYPE_EVENT_CONTEXT); @@ -140,9 +140,17 @@ ink_node_tool_class_init(InkNodeToolClass *klass) event_context_class->item_handler = ink_node_tool_item_handler; } +CInkNodeTool::CInkNodeTool(InkNodeTool* inknodetool) : CEventContext(inknodetool) { + this->inknodetool = inknodetool; +} + static void ink_node_tool_init(InkNodeTool *nt) { + nt->cinknodetool = new CInkNodeTool(nt); + delete nt->ceventcontext; + nt->ceventcontext = nt->cinknodetool; + SPEventContext *event_context = SP_EVENT_CONTEXT(nt); event_context->cursor_shape = cursor_node_xpm; @@ -161,7 +169,7 @@ ink_node_tool_init(InkNodeTool *nt) new (&nt->_shape_editors) ShapeEditors(); } -namespace { +//namespace { SPCanvasGroup *create_control_group(SPDesktop *d) { @@ -216,10 +224,17 @@ void ink_node_tool_dispose(GObject *object) void ink_node_tool_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CInkNodeTool::setup() { + SPEventContext* ec = this->speventcontext; + InkNodeTool *nt = INK_NODE_TOOL(ec); - if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->setup) - SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->setup(ec); +// if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->setup) +// SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->setup(ec); + CEventContext::setup(); nt->_node_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); @@ -322,6 +337,12 @@ void ink_node_tool_setup(SPEventContext *ec) void ink_node_tool_set(SPEventContext *ec, Inkscape::Preferences::Entry *value) { + ec->ceventcontext->set(value); +} + +void CInkNodeTool::set(Inkscape::Preferences::Entry* value) { + SPEventContext* ec = this->speventcontext; + InkNodeTool *nt = INK_NODE_TOOL(ec); Glib::ustring entry_name = value->getEntryName(); @@ -355,8 +376,9 @@ void ink_node_tool_set(SPEventContext *ec, Inkscape::Preferences::Entry *value) nt->edit_masks = value->getBool(); ink_node_tool_selection_changed(nt, nt->desktop->selection); } else { - if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->set) - SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->set(ec, value); +// if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->set) +// SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->set(ec, value); + CEventContext::set(value); } } @@ -444,6 +466,12 @@ void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel) gint ink_node_tool_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CInkNodeTool::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + /* things to handle here: * 1. selection of items * 2. passing events to manipulators @@ -537,8 +565,9 @@ gint ink_node_tool_root_handler(SPEventContext *event_context, GdkEvent *event) default: break; } - if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->root_handler) - return SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->root_handler(event_context, event); +// if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->root_handler) +// return SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->root_handler(event_context, event); + CEventContext::root_handler(event); return FALSE; } @@ -603,8 +632,15 @@ void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event) gint ink_node_tool_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event) { - if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->item_handler) - return SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->item_handler(event_context, item, event); + return event_context->ceventcontext->item_handler(item, event); +} + +gint CInkNodeTool::item_handler(SPItem* item, GdkEvent* event) { + + +// if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->item_handler) +// return SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->item_handler(event_context, item, event); + CEventContext::item_handler(item, event); return FALSE; } @@ -679,7 +715,7 @@ void handleControlUiStyleChange(InkNodeTool *nt) nt->_multipath->updateHandles(); } -} // anonymous namespace +//} // anonymous namespace /* Local Variables: diff --git a/src/ui/tool/node-tool.h b/src/ui/tool/node-tool.h index 341faf329..7223b11b3 100644 --- a/src/ui/tool/node-tool.h +++ b/src/ui/tool/node-tool.h @@ -41,8 +41,13 @@ typedef std::auto_ptr SelectorPtr; typedef std::auto_ptr PathSharedDataPtr; typedef boost::ptr_map ShapeEditors; -struct InkNodeTool : public SPEventContext +class CInkNodeTool; + +class InkNodeTool : public SPEventContext { +public: + CInkNodeTool* cinknodetool; + sigc::connection _selection_changed_connection; sigc::connection _mouseover_changed_connection; sigc::connection _selection_modified_connection; @@ -74,6 +79,19 @@ struct InkNodeToolClass { SPEventContextClass parent_class; }; +class CInkNodeTool : public CEventContext { +public: + CInkNodeTool(InkNodeTool* inknodetool); + + virtual void setup(); + virtual void set(Inkscape::Preferences::Entry* val); + virtual gint root_handler(GdkEvent* event); + virtual gint item_handler(SPItem* item, GdkEvent* event); + +private: + InkNodeTool* inknodetool; +}; + GType ink_node_tool_get_type (void); #endif -- cgit v1.2.3