From: Abhishek Sharma public Date: Sat, 24 Jul 2010 15:28:27 +0000 (+0530) Subject: Yet mor in c++ification X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5bf9e75a4b436336bc542149de4df7d777ff5a50;p=inkscape.git Yet mor in c++ification --- diff --git a/src/filter-chemistry.cpp b/src/filter-chemistry.cpp index 1f4e91c3b..9e0ee8383 100644 --- a/src/filter-chemistry.cpp +++ b/src/filter-chemistry.cpp @@ -101,7 +101,8 @@ SPFilter *new_filter(SPDocument *document) repr = xml_doc->createElement("svg:filter"); // Append the new filter node to defs - SP_OBJECT_REPR(defs)->appendChild(repr); + //SP_OBJECT_REPR(defs)->appendChild(repr); + defs->appendChild(repr); Inkscape::GC::release(repr); // get corresponding object @@ -169,7 +170,8 @@ filter_add_primitive(SPFilter *filter, const Inkscape::Filters::FilterPrimitiveT //set primitive as child of filter node // XML tree being used directly while/where it shouldn't be... - filter->getRepr()->appendChild(repr); + //filter->getRepr()->appendChild(repr); + filter->appendChild(repr); Inkscape::GC::release(repr); // get corresponding object @@ -218,7 +220,8 @@ new_filter_gaussian_blur (SPDocument *document, gdouble radius, double expansion Inkscape::GC::release(b_repr); // Append the new filter node to defs - SP_OBJECT_REPR(defs)->appendChild(repr); + //SP_OBJECT_REPR(defs)->appendChild(repr); + defs->appendChild(repr); Inkscape::GC::release(repr); // get corresponding object @@ -254,7 +257,8 @@ new_filter_blend_gaussian_blur (SPDocument *document, const char *blendmode, gdo repr->setAttribute("inkscape:collect", "always"); // Append the new filter node to defs - SP_OBJECT_REPR(defs)->appendChild(repr); + //SP_OBJECT_REPR(defs)->appendChild(repr); + defs->appendChild(repr); Inkscape::GC::release(repr); // get corresponding object @@ -361,7 +365,8 @@ modify_filter_gaussian_blur_from_item(SPDocument *document, SPItem *item, Inkscape::XML::Node *repr; repr = SP_OBJECT_REPR(item->style->getFilter())->duplicate(xml_doc); SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document); - SP_OBJECT_REPR(defs)->appendChild(repr); + //SP_OBJECT_REPR(defs)->appendChild(repr); + defs->appendChild(repr); filter = SP_FILTER( document->getObjectByRepr(repr) ); Inkscape::GC::release(repr); diff --git a/src/flood-context.cpp b/src/flood-context.cpp index 5181809dc..b9aaf902e 100644 --- a/src/flood-context.cpp +++ b/src/flood-context.cpp @@ -418,7 +418,7 @@ static void do_trace(bitmap_coords_info bci, guchar *trace_px, SPDesktop *deskto gray_map->destroy(gray_map); //XML Tree being used here directly while it shouldn't be...." - Inkscape::XML::Node *layer_repr = SP_GROUP(desktop->currentLayer())->getRepr(); + //Inkscape::XML::Node *layer_repr = SP_GROUP(desktop->currentLayer())->getRepr(); Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc()); long totalNodeCount = 0L; @@ -482,7 +482,8 @@ static void do_trace(bitmap_coords_info bci, guchar *trace_px, SPDesktop *deskto g_free(str); } - layer_repr->addChild(pathRepr, NULL); + //layer_repr->addChild(pathRepr, NULL); + desktop->currentLayer()->addChild(pathRepr,NULL); SPObject *reprobj = document->getObjectByRepr(pathRepr); if (reprobj) { @@ -1137,9 +1138,10 @@ static gint sp_flood_context_item_handler(SPEventContext *event_context, SPItem SPItem *item = sp_event_context_find_item (desktop, button_w, TRUE, TRUE); - Inkscape::XML::Node *pathRepr = SP_OBJECT_REPR(item); + //Inkscape::XML::Node *pathRepr = SP_OBJECT_REPR(item); /* Set style */ - sp_desktop_apply_style_tool (desktop, pathRepr, "/tools/paintbucket", false); + //sp_desktop_apply_style_tool (desktop, pathRepr, "/tools/paintbucket", false); + desktop->applyCurrentOrToolStyle(item, "/tools/paintbucket", false); SPDocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET, _("Set style on object")); ret = TRUE; } diff --git a/src/satisfied-guide-cns.cpp b/src/satisfied-guide-cns.cpp index dcf635989..f7f2bd7da 100644 --- a/src/satisfied-guide-cns.cpp +++ b/src/satisfied-guide-cns.cpp @@ -13,7 +13,7 @@ void satisfied_guide_cns(SPDesktop const &desktop, for (GSList const *l = nv.guides; l != NULL; l = l->next) { SPGuide &g = *SP_GUIDE(l->data); for (unsigned int i = 0; i < snappoints.size(); ++i) { - if (approx_equal( sp_guide_distance_from_pt(&g, snappoints[i].getPoint()), 0) ) { + if (approx_equal( g.getDistanceFrom(snappoints[i].getPoint()), 0) ) { cns.push_back(SPGuideConstraint(&g, i)); } } diff --git a/src/sp-defs.cpp b/src/sp-defs.cpp index 76cb2e1d9..b523322e1 100644 --- a/src/sp-defs.cpp +++ b/src/sp-defs.cpp @@ -20,7 +20,7 @@ #include "xml/repr.h" #include "document.h" -static void sp_defs_class_init(SPDefsClass *dc); +/*static void sp_defs_class_init(SPDefsClass *dc); static void sp_defs_init(SPDefs *defs); static void sp_defs_release(SPObject *object); @@ -28,9 +28,10 @@ static void sp_defs_update(SPObject *object, SPCtx *ctx, guint flags); static void sp_defs_modified(SPObject *object, guint flags); static Inkscape::XML::Node *sp_defs_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); -static SPObjectClass *parent_class; +static SPObjectClass *parent_class;*/ +SPObjectClass * SPDefsClass::static_parent_class = 0; -GType sp_defs_get_type(void) +GType SPDefs::sp_defs_get_type(void) { static GType defs_type = 0; @@ -39,7 +40,7 @@ GType sp_defs_get_type(void) sizeof(SPDefsClass), NULL, /* base_init */ NULL, /* base_finalize */ - (GClassInitFunc) sp_defs_class_init, + (GClassInitFunc) SPDefsClass::sp_defs_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof(SPDefs), @@ -53,30 +54,30 @@ GType sp_defs_get_type(void) return defs_type; } -static void sp_defs_class_init(SPDefsClass *dc) +void SPDefsClass::sp_defs_class_init(SPDefsClass *dc) { - parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT); + static_parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT); SPObjectClass *sp_object_class = (SPObjectClass *) dc; - sp_object_class->release = sp_defs_release; - sp_object_class->update = sp_defs_update; - sp_object_class->modified = sp_defs_modified; - sp_object_class->write = sp_defs_write; + sp_object_class->release = SPDefs::sp_defs_release; + sp_object_class->update = SPDefs::sp_defs_update; + sp_object_class->modified = SPDefs::sp_defs_modified; + sp_object_class->write = SPDefs::sp_defs_write; } -static void sp_defs_init(SPDefs */*defs*/) +void SPDefs::sp_defs_init(SPDefs */*defs*/) { } -static void sp_defs_release(SPObject *object) +void SPDefs::sp_defs_release(SPObject *object) { - if (((SPObjectClass *) (parent_class))->release) { - ((SPObjectClass *) (parent_class))->release(object); + if (((SPObjectClass *) (SPDefsClass::static_parent_class))->release) { + ((SPObjectClass *) (SPDefsClass::static_parent_class))->release(object); } } -static void sp_defs_update(SPObject *object, SPCtx *ctx, guint flags) +void SPDefs::sp_defs_update(SPObject *object, SPCtx *ctx, guint flags) { if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -95,7 +96,7 @@ static void sp_defs_update(SPObject *object, SPCtx *ctx, guint flags) } } -static void sp_defs_modified(SPObject *object, guint flags) +void SPDefs::sp_defs_modified(SPObject *object, guint flags) { if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -121,7 +122,7 @@ static void sp_defs_modified(SPObject *object, guint flags) } } -static Inkscape::XML::Node *sp_defs_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +Inkscape::XML::Node * SPDefs::sp_defs_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if (flags & SP_OBJECT_WRITE_BUILD) { @@ -147,8 +148,8 @@ static Inkscape::XML::Node *sp_defs_write(SPObject *object, Inkscape::XML::Docum } } - if (((SPObjectClass *) (parent_class))->write) { - (* ((SPObjectClass *) (parent_class))->write)(object, xml_doc, repr, flags); + if (((SPObjectClass *) (SPDefsClass::static_parent_class))->write) { + (* ((SPObjectClass *) (SPDefsClass::static_parent_class))->write)(object, xml_doc, repr, flags); } return repr; diff --git a/src/sp-defs.h b/src/sp-defs.h index 4b6f7a5b7..c88aef81e 100644 --- a/src/sp-defs.h +++ b/src/sp-defs.h @@ -14,20 +14,38 @@ #include "sp-object.h" -#define SP_TYPE_DEFS (sp_defs_get_type()) +#define SP_TYPE_DEFS (SPDefs::sp_defs_get_type()) #define SP_DEFS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_DEFS, SPDefs)) #define SP_DEFS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_DEFS, SPDefsClass)) #define SP_IS_DEFS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_DEFS)) #define SP_IS_DEFS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_DEFS)) -struct SPDefs : public SPObject { +class SPDefs : public SPObject { + public: + static GType sp_defs_get_type(void); + + private: + static void sp_defs_init(SPDefs *defs); + static void sp_defs_release(SPObject *object); + static void sp_defs_update(SPObject *object, SPCtx *ctx, guint flags); + static void sp_defs_modified(SPObject *object, guint flags); + static Inkscape::XML::Node *sp_defs_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); + + friend class SPDefsClass; }; -struct SPDefsClass { - SPObjectClass parent_class; +class SPDefsClass { + public: + SPObjectClass parent_class; + + private: + static void sp_defs_class_init(SPDefsClass *dc); + static SPObjectClass *static_parent_class; + + friend class SPDefs; }; -GType sp_defs_get_type(void); +//GType sp_defs_get_type(void); #endif /* !SEEN_SP_DEFS_H */ diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index e43c3056d..21b350486 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -242,7 +242,7 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) } SPGuide * -sp_guide_create(SPDesktop *desktop, Geom::Point const &pt1, Geom::Point const &pt2) { +SPGuide::createSPGuide(SPDesktop *desktop, Geom::Point const &pt1, Geom::Point const &pt2) { SPDocument *doc=sp_desktop_document(desktop); Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); @@ -253,7 +253,8 @@ sp_guide_create(SPDesktop *desktop, Geom::Point const &pt1, Geom::Point const &p sp_repr_set_point(repr, "position", pt1); sp_repr_set_point(repr, "orientation", n); - SP_OBJECT_REPR(desktop->namedview)->appendChild(repr); + //SP_OBJECT_REPR(desktop->namedview)->appendChild(repr); + desktop->namedview->appendChild(repr); Inkscape::GC::release(repr); SPGuide *guide= SP_GUIDE(doc->getObjectByRepr(repr)); @@ -263,7 +264,7 @@ sp_guide_create(SPDesktop *desktop, Geom::Point const &pt1, Geom::Point const &p void sp_guide_pt_pairs_to_guides(SPDesktop *dt, std::list > &pts) { for (std::list >::iterator i = pts.begin(); i != pts.end(); ++i) { - sp_guide_create(dt, (*i).first, (*i).second); + SPGuide::createSPGuide(dt, (*i).first, (*i).second); } } @@ -287,27 +288,27 @@ sp_guide_create_guides_around_page(SPDesktop *dt) { SPDocumentUndo::done (doc, SP_VERB_NONE, _("Guides Around Page")); } -void sp_guide_show(SPGuide *guide, SPCanvasGroup *group, GCallback handler) +void SPGuide::showSPGuide(SPCanvasGroup *group, GCallback handler) { - SPCanvasItem *item = sp_guideline_new(group, guide->point_on_line, guide->normal_to_line); - sp_guideline_set_color(SP_GUIDELINE(item), guide->color); + SPCanvasItem *item = sp_guideline_new(group, this->point_on_line, this->normal_to_line); + sp_guideline_set_color(SP_GUIDELINE(item), this->color); - g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), guide); + g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), this); - guide->views = g_slist_prepend(guide->views, item); + this->views = g_slist_prepend(this->views, item); } -void sp_guide_hide(SPGuide *guide, SPCanvas *canvas) +void SPGuide::hideSPGuide(SPCanvas *canvas) { - g_assert(guide != NULL); - g_assert(SP_IS_GUIDE(guide)); + //g_assert(guide != NULL); + //g_assert(SP_IS_GUIDE(guide)); g_assert(canvas != NULL); g_assert(SP_IS_CANVAS(canvas)); - for (GSList *l = guide->views; l != NULL; l = l->next) { + for (GSList *l = this->views; l != NULL; l = l->next) { if (canvas == SP_CANVAS_ITEM(l->data)->canvas) { sp_guideline_delete(SP_GUIDELINE(l->data)); - guide->views = g_slist_remove(guide->views, l->data); + this->views = g_slist_remove(this->views, l->data); return; } } @@ -315,14 +316,14 @@ void sp_guide_hide(SPGuide *guide, SPCanvas *canvas) g_assert_not_reached(); } -void sp_guide_sensitize(SPGuide *guide, SPCanvas *canvas, gboolean sensitive) +void SPGuide::sensitize(SPCanvas *canvas, gboolean sensitive) { - g_assert(guide != NULL); - g_assert(SP_IS_GUIDE(guide)); + //g_assert(guide != NULL); + //g_assert(SP_IS_GUIDE(guide)); g_assert(canvas != NULL); g_assert(SP_IS_CANVAS(canvas)); - for (GSList *l = guide->views; l != NULL; l = l->next) { + for (GSList *l = this->views; l != NULL; l = l->next) { if (canvas == SP_CANVAS_ITEM(l->data)->canvas) { sp_guideline_set_sensitive(SP_GUIDELINE(l->data), sensitive); return; @@ -332,14 +333,14 @@ void sp_guide_sensitize(SPGuide *guide, SPCanvas *canvas, gboolean sensitive) g_assert_not_reached(); } -Geom::Point sp_guide_position_from_pt(SPGuide const *guide, Geom::Point const &pt) +Geom::Point SPGuide::getPositionFrom(Geom::Point const &pt) const { - return -(pt - guide->point_on_line); + return -(pt - this->point_on_line); } -double sp_guide_distance_from_pt(SPGuide const *guide, Geom::Point const &pt) +double SPGuide::getDistanceFrom(Geom::Point const &pt) const { - return Geom::dot(pt - guide->point_on_line, guide->normal_to_line); + return Geom::dot(pt - this->point_on_line, this->normal_to_line); } /** diff --git a/src/sp-guide.h b/src/sp-guide.h index 6bf541cd1..b5914e890 100644 --- a/src/sp-guide.h +++ b/src/sp-guide.h @@ -25,7 +25,8 @@ #define SP_IS_GUIDE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_GUIDE)) /* Represents the constraint on p that dot(g.direction, p) == g.position. */ -struct SPGuide : public SPObject { +class SPGuide : public SPObject { + public: Geom::Point normal_to_line; Geom::Point point_on_line; @@ -37,24 +38,31 @@ struct SPGuide : public SPObject { inline bool is_horizontal() const { return (normal_to_line[Geom::X] == 0.); }; inline bool is_vertical() const { return (normal_to_line[Geom::Y] == 0.); }; inline double angle() const { return std::atan2( - normal_to_line[Geom::X], normal_to_line[Geom::Y] ); }; + static SPGuide *createSPGuide(SPDesktop *desktop, Geom::Point const &pt1, Geom::Point const &pt2); + void showSPGuide(SPCanvasGroup *group, GCallback handler); + void hideSPGuide(SPCanvas *canvas); + void sensitize(SPCanvas *canvas, gboolean sensitive); + Geom::Point getPositionFrom(Geom::Point const &pt) const; + double getDistanceFrom(Geom::Point const &pt) const; }; -struct SPGuideClass { +class SPGuideClass { + public: SPObjectClass parent_class; }; GType sp_guide_get_type(); -SPGuide *sp_guide_create(SPDesktop *desktop, Geom::Point const &pt1, Geom::Point const &pt2); +//SPGuide *sp_guide_create(SPDesktop *desktop, Geom::Point const &pt1, Geom::Point const &pt2); void sp_guide_pt_pairs_to_guides(SPDesktop *dt, std::list > &pts); void sp_guide_create_guides_around_page(SPDesktop *dt); -void sp_guide_show(SPGuide *guide, SPCanvasGroup *group, GCallback handler); -void sp_guide_hide(SPGuide *guide, SPCanvas *canvas); -void sp_guide_sensitize(SPGuide *guide, SPCanvas *canvas, gboolean sensitive); +//void sp_guide_show(SPGuide *guide, SPCanvasGroup *group, GCallback handler); +//void sp_guide_hide(SPGuide *guide, SPCanvas *canvas); +//void sp_guide_sensitize(SPGuide *guide, SPCanvas *canvas, gboolean sensitive); -Geom::Point sp_guide_position_from_pt(SPGuide const *guide, Geom::Point const &pt); -double sp_guide_distance_from_pt(SPGuide const *guide, Geom::Point const &pt); +//Geom::Point sp_guide_position_from_pt(SPGuide const *guide, Geom::Point const &pt); +//double sp_guide_distance_from_pt(SPGuide const *guide, Geom::Point const &pt); void sp_guide_moveto(SPGuide const &guide, Geom::Point const point_on_line, bool const commit); void sp_guide_set_normal(SPGuide const &guide, Geom::Point const normal_to_line, bool const commit); void sp_guide_remove(SPGuide *guide); diff --git a/src/sp-item-rm-unsatisfied-cns.cpp b/src/sp-item-rm-unsatisfied-cns.cpp index e92a573f1..a7f29fb80 100644 --- a/src/sp-item-rm-unsatisfied-cns.cpp +++ b/src/sp-item-rm-unsatisfied-cns.cpp @@ -21,7 +21,7 @@ void sp_item_rm_unsatisfied_cns(SPItem &item) SPGuideConstraint const &cn = item.constraints[i]; int const snappoint_ix = cn.snappoint_ix; g_assert( snappoint_ix < int(snappoints.size()) ); - if (!approx_equal( sp_guide_distance_from_pt(cn.g, snappoints[snappoint_ix].getPoint()), 0) ) { + if (!approx_equal( cn.g->getDistanceFrom(snappoints[snappoint_ix].getPoint()), 0) ) { remove_last(cn.g->attached_items, SPGuideAttachment(&item, cn.snappoint_ix)); g_assert( i < item.constraints.size() ); vector::iterator const ei(&item.constraints[i]); diff --git a/src/sp-line.cpp b/src/sp-line.cpp index b29e51b5a..b71616c5b 100644 --- a/src/sp-line.cpp +++ b/src/sp-line.cpp @@ -207,7 +207,7 @@ SPLine::sp_line_convert_to_guides(SPItem *item) points[0] = Geom::Point(line->x1.computed, line->y1.computed)*i2d; points[1] = Geom::Point(line->x2.computed, line->y2.computed)*i2d; - sp_guide_create(inkscape_active_desktop(), points[0], points[1]); + SPGuide::createSPGuide(inkscape_active_desktop(), points[0], points[1]); } Geom::Matrix diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 7c974802e..c4ce6355b 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -642,10 +642,9 @@ static void sp_namedview_child_added(SPObject *object, Inkscape::XML::Node *chil g_object_set(G_OBJECT(g), "color", nv->guidecolor, "hicolor", nv->guidehicolor, NULL); if (nv->editable) { for (GSList *l = nv->views; l != NULL; l = l->next) { - sp_guide_show(g, static_cast(l->data)->guides, (GCallback) sp_dt_guide_event); + g->SPGuide::showSPGuide(static_cast(l->data)->guides, (GCallback) sp_dt_guide_event); if (static_cast(l->data)->guides_active) - sp_guide_sensitize(g, - sp_desktop_canvas(static_cast (l->data)), + g->sensitize(sp_desktop_canvas(static_cast (l->data)), TRUE); sp_namedview_show_single_guide(SP_GUIDE(g), nv->showguides); } @@ -703,9 +702,9 @@ static Inkscape::XML::Node *sp_namedview_write(SPObject *object, Inkscape::XML:: void SPNamedView::show(SPDesktop *desktop) { for (GSList *l = guides; l != NULL; l = l->next) { - sp_guide_show(SP_GUIDE(l->data), desktop->guides, (GCallback) sp_dt_guide_event); + SP_GUIDE(l->data)->showSPGuide( desktop->guides, (GCallback) sp_dt_guide_event); if (desktop->guides_active) { - sp_guide_sensitize(SP_GUIDE(l->data), sp_desktop_canvas(desktop), TRUE); + SP_GUIDE(l->data)->sensitize(sp_desktop_canvas(desktop), TRUE); } sp_namedview_show_single_guide(SP_GUIDE(l->data), showguides); } @@ -841,7 +840,7 @@ void SPNamedView::hide(SPDesktop const *desktop) g_assert(g_slist_find(views, desktop)); for (GSList *l = guides; l != NULL; l = l->next) { - sp_guide_hide(SP_GUIDE(l->data), sp_desktop_canvas(desktop)); + SP_GUIDE(l->data)->hideSPGuide(sp_desktop_canvas(desktop)); } views = g_slist_remove(views, desktop); @@ -855,7 +854,7 @@ void SPNamedView::activateGuides(gpointer desktop, gboolean active) SPDesktop *dt = static_cast(desktop); for (GSList *l = guides; l != NULL; l = l->next) { - sp_guide_sensitize(SP_GUIDE(l->data), sp_desktop_canvas(dt), active); + SP_GUIDE(l->data)->sensitize( sp_desktop_canvas(dt), active); } } diff --git a/src/sp-object-group.cpp b/src/sp-object-group.cpp index 02ae5d29a..d0e5c01a7 100644 --- a/src/sp-object-group.cpp +++ b/src/sp-object-group.cpp @@ -16,18 +16,20 @@ #include "xml/repr.h" #include "document.h" -static void sp_objectgroup_class_init (SPObjectGroupClass *klass); +/*static void sp_objectgroup_class_init (SPObjectGroupClass *klass); static void sp_objectgroup_init (SPObjectGroup *objectgroup); static void sp_objectgroup_child_added (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * ref); static void sp_objectgroup_remove_child (SPObject * object, Inkscape::XML::Node * child); static void sp_objectgroup_order_changed (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * old_ref, Inkscape::XML::Node * new_ref); -static Inkscape::XML::Node *sp_objectgroup_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); +static Inkscape::XML::Node *sp_objectgroup_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);*/ -static SPObjectClass *parent_class; +//static SPObjectClass *parent_class; + +SPObjectClass * SPObjectGroupClass::static_parent_class = 0; GType -sp_objectgroup_get_type (void) +SPObjectGroup::sp_objectgroup_get_type (void) { static GType objectgroup_type = 0; if (!objectgroup_type) { @@ -35,7 +37,7 @@ sp_objectgroup_get_type (void) sizeof (SPObjectGroupClass), NULL, /* base_init */ NULL, /* base_finalize */ - (GClassInitFunc) sp_objectgroup_class_init, + (GClassInitFunc) SPObjectGroupClass::sp_objectgroup_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (SPObjectGroup), @@ -48,8 +50,8 @@ sp_objectgroup_get_type (void) return objectgroup_type; } -static void -sp_objectgroup_class_init (SPObjectGroupClass *klass) +void +SPObjectGroupClass::sp_objectgroup_class_init (SPObjectGroupClass *klass) { GObjectClass * object_class; SPObjectClass * sp_object_class; @@ -57,48 +59,48 @@ sp_objectgroup_class_init (SPObjectGroupClass *klass) object_class = (GObjectClass *) klass; sp_object_class = (SPObjectClass *) klass; - parent_class = (SPObjectClass *)g_type_class_ref (SP_TYPE_OBJECT); + static_parent_class = (SPObjectClass *)g_type_class_ref (SP_TYPE_OBJECT); - sp_object_class->child_added = sp_objectgroup_child_added; - sp_object_class->remove_child = sp_objectgroup_remove_child; - sp_object_class->order_changed = sp_objectgroup_order_changed; - sp_object_class->write = sp_objectgroup_write; + sp_object_class->child_added = SPObjectGroup::sp_objectgroup_child_added; + sp_object_class->remove_child = SPObjectGroup::sp_objectgroup_remove_child; + sp_object_class->order_changed = SPObjectGroup::sp_objectgroup_order_changed; + sp_object_class->write = SPObjectGroup::sp_objectgroup_write; } -static void -sp_objectgroup_init (SPObjectGroup */*objectgroup*/) +void +SPObjectGroup::sp_objectgroup_init (SPObjectGroup */*objectgroup*/) { } -static void -sp_objectgroup_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) +void +SPObjectGroup::sp_objectgroup_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { - if (((SPObjectClass *) (parent_class))->child_added) - (* ((SPObjectClass *) (parent_class))->child_added) (object, child, ref); + if (((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->child_added) + (* ((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->child_added) (object, child, ref); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } -static void -sp_objectgroup_remove_child (SPObject *object, Inkscape::XML::Node *child) +void +SPObjectGroup::sp_objectgroup_remove_child (SPObject *object, Inkscape::XML::Node *child) { - if (((SPObjectClass *) (parent_class))->remove_child) - (* ((SPObjectClass *) (parent_class))->remove_child) (object, child); + if (((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->remove_child) + (* ((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->remove_child) (object, child); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } -static void -sp_objectgroup_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref) +void +SPObjectGroup::sp_objectgroup_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref) { - if (((SPObjectClass *) (parent_class))->order_changed) - (* ((SPObjectClass *) (parent_class))->order_changed) (object, child, old_ref, new_ref); + if (((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->order_changed) + (* ((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->order_changed) (object, child, old_ref, new_ref); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } -static Inkscape::XML::Node * -sp_objectgroup_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +Inkscape::XML::Node * +SPObjectGroup::sp_objectgroup_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPObjectGroup *group; SPObject *child; @@ -127,8 +129,8 @@ sp_objectgroup_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inksca } } - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags); + if (((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->write) + ((SPObjectClass *) (SPObjectGroupClass::static_parent_class))->write (object, xml_doc, repr, flags); return repr; } diff --git a/src/sp-object-group.h b/src/sp-object-group.h index 5d67df6fe..7d35cfc17 100644 --- a/src/sp-object-group.h +++ b/src/sp-object-group.h @@ -15,19 +15,38 @@ #include "sp-object.h" -#define SP_TYPE_OBJECTGROUP (sp_objectgroup_get_type ()) +#define SP_TYPE_OBJECTGROUP (SPObjectGroup::sp_objectgroup_get_type ()) #define SP_OBJECTGROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_OBJECTGROUP, SPObjectGroup)) #define SP_OBJECTGROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_OBJECTGROUP, SPObjectGroupClass)) #define SP_IS_OBJECTGROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_OBJECTGROUP)) #define SP_IS_OBJECTGROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_OBJECTGROUP)) -struct SPObjectGroup : public SPObject { +class SPObjectGroup : public SPObject { + public: + static GType sp_objectgroup_get_type (void); + + private: + static void sp_objectgroup_init (SPObjectGroup *objectgroup); + + static void sp_objectgroup_child_added (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * ref); + static void sp_objectgroup_remove_child (SPObject * object, Inkscape::XML::Node * child); + static void sp_objectgroup_order_changed (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * old_ref, Inkscape::XML::Node * new_ref); + static Inkscape::XML::Node *sp_objectgroup_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); + + friend class SPObjectGroupClass; }; -struct SPObjectGroupClass { - SPObjectClass parent_class; +class SPObjectGroupClass { + public: + SPObjectClass parent_class; + + private: + static void sp_objectgroup_class_init (SPObjectGroupClass *klass); + static SPObjectClass *static_parent_class; + + friend class SPObjectGroup; }; -GType sp_objectgroup_get_type (void); +//GType sp_objectgroup_get_type (void); #endif diff --git a/src/sp-object.cpp b/src/sp-object.cpp index f23f374d4..80f39db4a 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -937,6 +937,13 @@ void SPObject::appendChild(Inkscape::XML::Node *child) { repr->appendChild(child); } +void SPObject::addChild(Inkscape::XML::Node *child, Inkscape::XML::Node * prev) +{ + g_assert(this->repr); + + repr->addChild(child,prev); +} + void SPObject::releaseReferences() { g_assert(this->document); g_assert(this->repr); diff --git a/src/sp-object.h b/src/sp-object.h index 61c69c3aa..4856bdd06 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -532,6 +532,7 @@ public: unsigned getPosition(); gchar const * getAttribute(gchar const *name,SPException *ex=0) const; void appendChild(Inkscape::XML::Node *child); + void addChild(Inkscape::XML::Node *child,Inkscape::XML::Node *prev=0); void setKeyValue(unsigned int key, gchar const *value); void setAttribute(gchar const *key, gchar const *value, SPException *ex=0); void readAttr(gchar const *key);