summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/box3d.cpp79
-rw-r--r--src/box3d.h23
-rw-r--r--src/marker.cpp344
-rw-r--r--src/marker.h23
-rw-r--r--src/sp-anchor.cpp129
-rw-r--r--src/sp-anchor.h24
-rw-r--r--src/sp-item-group.cpp202
-rw-r--r--src/sp-item-group.h28
-rw-r--r--src/sp-root.cpp459
-rw-r--r--src/sp-root.h24
-rw-r--r--src/sp-switch.cpp59
-rw-r--r--src/sp-switch.h33
-rw-r--r--src/sp-symbol.cpp264
-rw-r--r--src/sp-symbol.h23
-rw-r--r--src/ui/dialog/object-attributes.cpp12
15 files changed, 764 insertions, 962 deletions
diff --git a/src/box3d.cpp b/src/box3d.cpp
index c3f6a1dbb..3c11d24d7 100644
--- a/src/box3d.cpp
+++ b/src/box3d.cpp
@@ -53,48 +53,25 @@ namespace {
bool box3DRegistered = SPFactory::instance().registerObject("inkscape:box3d", createBox3D);
}
-G_DEFINE_TYPE(SPBox3D, box3d, G_TYPE_OBJECT);
-
-static void box3d_class_init(SPBox3DClass *klass)
-{
-}
-
-CBox3D::CBox3D(SPBox3D* box) : CGroup(box) {
- this->spbox3d = box;
-}
-
-CBox3D::~CBox3D() {
-}
-
SPBox3D::SPBox3D() : SPGroup() {
- SPBox3D* box = this;
-
- box->cbox3d = new CBox3D(box);
- box->typeHierarchy.insert(typeid(SPBox3D));
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
- delete box->cgroup;
- box->cgroup = box->cbox3d;
- box->clpeitem = box->cbox3d;
- box->citem = box->cbox3d;
- box->cobject = box->cbox3d;
+ this->my_counter = 0;
+ this->swapped = Box3D::NONE;
- box->my_counter = 0;
- box->swapped = Box3D::NONE;
-
- box->persp_href = NULL;
- box->persp_ref = new Persp3DReference(box);
+ this->persp_href = NULL;
+ this->persp_ref = new Persp3DReference(this);
}
-static void
-box3d_init(SPBox3D *box)
-{
- new (box) SPBox3D();
+SPBox3D::~SPBox3D() {
}
-void CBox3D::build(SPDocument *document, Inkscape::XML::Node *repr) {
- SPBox3D* object = this->spbox3d;
+void SPBox3D::build(SPDocument *document, Inkscape::XML::Node *repr) {
+ SPBox3D* object = this;
- CGroup::build(document, repr);
+ SPGroup::build(document, repr);
SPBox3D *box = SP_BOX3D (object);
box->my_counter = counter++;
@@ -116,8 +93,8 @@ void CBox3D::build(SPDocument *document, Inkscape::XML::Node *repr) {
}
}
-void CBox3D::release() {
- SPBox3D* object = this->spbox3d;
+void SPBox3D::release() {
+ SPBox3D* object = this;
SPBox3D *box = object;
if (box->persp_href) {
@@ -151,11 +128,11 @@ void CBox3D::release() {
*/
}
- CGroup::release();
+ SPGroup::release();
}
-void CBox3D::set(unsigned int key, const gchar* value) {
- SPBox3D* object = this->spbox3d;
+void SPBox3D::set(unsigned int key, const gchar* value) {
+ SPBox3D* object = this;
SPBox3D *box = object;
switch (key) {
@@ -201,7 +178,7 @@ void CBox3D::set(unsigned int key, const gchar* value) {
}
break;
default:
- CGroup::set(key, value);
+ SPGroup::set(key, value);
break;
}
}
@@ -222,7 +199,7 @@ box3d_ref_changed(SPObject *old_ref, SPObject *ref, SPBox3D *box)
}
}
-void CBox3D::update(SPCtx *ctx, guint flags) {
+void SPBox3D::update(SPCtx *ctx, guint flags) {
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
/* FIXME?: Perhaps the display updates of box sides should be instantiated from here, but this
@@ -232,11 +209,11 @@ void CBox3D::update(SPCtx *ctx, guint flags) {
}
// Invoke parent method
- CGroup::update(ctx, flags);
+ SPGroup::update(ctx, flags);
}
-Inkscape::XML::Node* CBox3D::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPBox3D* object = this->spbox3d;
+Inkscape::XML::Node* SPBox3D::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
+ SPBox3D* object = this;
SPBox3D *box = object;
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
@@ -277,13 +254,13 @@ Inkscape::XML::Node* CBox3D::write(Inkscape::XML::Document *xml_doc, Inkscape::X
box->save_corner7 = box->orig_corner7;
}
- CGroup::write(xml_doc, repr, flags);
+ SPGroup::write(xml_doc, repr, flags);
return repr;
}
-gchar* CBox3D::description() {
- SPBox3D* item = this->spbox3d;
+gchar* SPBox3D::description() {
+ SPBox3D* item = this;
g_return_val_if_fail(SP_IS_BOX3D(item), NULL);
return g_strdup(_("<b>3D Box</b>"));
@@ -300,8 +277,8 @@ void box3d_position_set(SPBox3D *box)
}
}
-Geom::Affine CBox3D::set_transform(Geom::Affine const &xform) {
- SPBox3D* item = this->spbox3d;
+Geom::Affine SPBox3D::set_transform(Geom::Affine const &xform) {
+ SPBox3D* item = this;
SPBox3D *box = item;
// We don't apply the transform to the box directly but instead to its perspective (which is
@@ -1361,8 +1338,8 @@ box3d_push_back_corner_pair(SPBox3D *box, std::list<std::pair<Geom::Point, Geom:
box3d_get_corner_screen(box, c2, false)));
}
-void CBox3D::convert_to_guides() {
- SPBox3D* item = this->spbox3d;
+void SPBox3D::convert_to_guides() {
+ SPBox3D* item = this;
SPBox3D *box = item;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
diff --git a/src/box3d.h b/src/box3d.h
index b3f4f7d87..6763bb271 100644
--- a/src/box3d.h
+++ b/src/box3d.h
@@ -22,16 +22,15 @@
#define SP_TYPE_BOX3D (box3d_get_type ())
#define SP_BOX3D(obj) ((SPBox3D*)obj)
-#define SP_IS_BOX3D(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPBox3D)))
+#define SP_IS_BOX3D(obj) (dynamic_cast<const SPBox3D*>((SPObject*)obj))
struct Persp3D;
class Persp3DReference;
-class CBox3D;
class SPBox3D : public SPGroup {
public:
SPBox3D();
- CBox3D* cbox3d;
+ virtual ~SPBox3D();
gint z_orders[6]; // z_orders[i] holds the ID of the face at position #i in the group (from top to bottom)
@@ -52,18 +51,6 @@ public:
* Create a SPBox3D and append it to the parent.
*/
static SPBox3D * createBox3D(SPItem * parent);
-};
-
-class SPBox3DClass {
-public:
- SPGroupClass parent_class;
-};
-
-
-class CBox3D : public CGroup {
-public:
- CBox3D(SPBox3D* box3d);
- virtual ~CBox3D();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual void release();
@@ -74,14 +61,8 @@ public:
virtual gchar *description();
virtual Geom::Affine set_transform(Geom::Affine const &transform);
virtual void convert_to_guides();
-
-protected:
- SPBox3D* spbox3d;
};
-
-GType box3d_get_type (void);
-
void box3d_position_set (SPBox3D *box);
Proj::Pt3 box3d_get_proj_corner (SPBox3D const *box, guint id);
Geom::Point box3d_get_corner_screen (SPBox3D const *box, guint id, bool item_coords = true);
diff --git a/src/marker.cpp b/src/marker.cpp
index 7b824c196..1717c388e 100644
--- a/src/marker.cpp
+++ b/src/marker.cpp
@@ -52,57 +52,31 @@ namespace {
bool markerRegistered = SPFactory::instance().registerObject("svg:marker", createMarker);
}
-G_DEFINE_TYPE(SPMarker, sp_marker, G_TYPE_OBJECT);
-
-/**
- * Initializes a SPMarkerClass object. Establishes the function pointers to the class'
- * member routines in the class vtable, and sets pointers to parent classes.
- */
-static void sp_marker_class_init(SPMarkerClass *klass)
-{
-}
-
-CMarker::CMarker(SPMarker* marker) : CGroup(marker) {
- this->spmarker = marker;
-}
-
-CMarker::~CMarker() {
-}
-
SPMarker::SPMarker() : SPGroup() {
- SPMarker* marker = this;
-
- marker->cmarker = new CMarker(marker);
- marker->typeHierarchy.insert(typeid(SPMarker));
-
- delete marker->cgroup;
- marker->cgroup = marker->cmarker;
- marker->clpeitem = marker->cmarker;
- marker->citem = marker->cmarker;
- marker->cobject = marker->cmarker;
-
- marker->aspect_clip = 0;
- marker->aspect_align = 0;
- marker->aspect_set = 0;
- marker->markerUnits = 0;
- marker->orient_auto = 0;
- marker->markerUnits_set = 0;
- marker->orient_set = 0;
- marker->orient = 0;
-
- marker->viewBox = Geom::OptRect();
- marker->c2p.setIdentity();
- marker->views = NULL;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
+
+ this->aspect_clip = 0;
+ this->aspect_align = 0;
+ this->aspect_set = 0;
+ this->markerUnits = 0;
+ this->orient_auto = 0;
+ this->markerUnits_set = 0;
+ this->orient_set = 0;
+ this->orient = 0;
+
+ this->viewBox = Geom::OptRect();
+ this->c2p.setIdentity();
+ this->views = NULL;
}
/**
* Initializes an SPMarker object. This notes the marker's viewBox is
* not set and initializes the marker's c2p identity matrix.
*/
-static void
-sp_marker_init (SPMarker *marker)
-{
- new (marker) SPMarker();
+
+SPMarker::~SPMarker() {
}
/**
@@ -115,38 +89,32 @@ sp_marker_init (SPMarker *marker)
*
* \see SPObject::build()
*/
-void CMarker::build(SPDocument *document, Inkscape::XML::Node *repr) {
- SPMarker* object = this->spmarker;
-
- object->readAttr( "markerUnits" );
- object->readAttr( "refX" );
- object->readAttr( "refY" );
- object->readAttr( "markerWidth" );
- object->readAttr( "markerHeight" );
- object->readAttr( "orient" );
- object->readAttr( "viewBox" );
- object->readAttr( "preserveAspectRatio" );
-
- CGroup::build(document, repr);
+void SPMarker::build(SPDocument *document, Inkscape::XML::Node *repr) {
+ this->readAttr( "markerUnits" );
+ this->readAttr( "refX" );
+ this->readAttr( "refY" );
+ this->readAttr( "markerWidth" );
+ this->readAttr( "markerHeight" );
+ this->readAttr( "orient" );
+ this->readAttr( "viewBox" );
+ this->readAttr( "preserveAspectRatio" );
+
+ SPGroup::build(document, repr);
}
-void CMarker::release() {
- SPMarker* object = this->spmarker;
-
- SPMarker *marker = reinterpret_cast<SPMarker *>(object);
-
- while (marker->views) {
+void SPMarker::release() {
+ while (this->views) {
// Destroy all DrawingItems etc.
// Parent class ::hide method
//reinterpret_cast<SPItemClass *>(parent_class)->hide(marker, marker->views->key);
// CPPIFY: correct one?
- CGroup::hide(marker->views->key);
+ SPGroup::hide(this->views->key);
- sp_marker_view_remove (marker, marker->views, TRUE);
+ sp_marker_view_remove (this, this->views, TRUE);
}
- CGroup::release();
+ SPGroup::release();
}
/**
@@ -162,99 +130,143 @@ void CMarker::release() {
* \see SPObject::release()
*/
-void CMarker::set(unsigned int key, const gchar* value) {
- SPMarker* object = this->spmarker;
-
- SPMarker *marker = SP_MARKER(object);
-
+void SPMarker::set(unsigned int key, const gchar* value) {
switch (key) {
case SP_ATTR_MARKERUNITS:
- marker->markerUnits_set = FALSE;
- marker->markerUnits = SP_MARKER_UNITS_STROKEWIDTH;
+ this->markerUnits_set = FALSE;
+ this->markerUnits = SP_MARKER_UNITS_STROKEWIDTH;
+
if (value) {
if (!strcmp (value, "strokeWidth")) {
- marker->markerUnits_set = TRUE;
+ this->markerUnits_set = TRUE;
} else if (!strcmp (value, "userSpaceOnUse")) {
- marker->markerUnits = SP_MARKER_UNITS_USERSPACEONUSE;
- marker->markerUnits_set = TRUE;
+ this->markerUnits = SP_MARKER_UNITS_USERSPACEONUSE;
+ this->markerUnits_set = TRUE;
}
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
break;
+
case SP_ATTR_REFX:
- marker->refX.readOrUnset(value);
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->refX.readOrUnset(value);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_REFY:
- marker->refY.readOrUnset(value);
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->refY.readOrUnset(value);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_MARKERWIDTH:
- marker->markerWidth.readOrUnset(value, SVGLength::NONE, 3.0, 3.0);
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->markerWidth.readOrUnset(value, SVGLength::NONE, 3.0, 3.0);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_MARKERHEIGHT:
- marker->markerHeight.readOrUnset(value, SVGLength::NONE, 3.0, 3.0);
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ this->markerHeight.readOrUnset(value, SVGLength::NONE, 3.0, 3.0);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_ORIENT:
- marker->orient_set = FALSE;
- marker->orient_auto = FALSE;
- marker->orient = 0.0;
+ this->orient_set = FALSE;
+ this->orient_auto = FALSE;
+ this->orient = 0.0;
+
if (value) {
if (!strcmp (value, "auto")) {
- marker->orient_auto = TRUE;
- marker->orient_set = TRUE;
- } else if (sp_svg_number_read_f (value, &marker->orient)) {
- marker->orient_set = TRUE;
+ this->orient_auto = TRUE;
+ this->orient_set = TRUE;
+ } else if (sp_svg_number_read_f (value, &this->orient)) {
+ this->orient_set = TRUE;
}
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_VIEWBOX:
- marker->viewBox = Geom::OptRect();
+ this->viewBox = Geom::OptRect();
+
if (value) {
double x, y, width, height;
char *eptr;
+
/* fixme: We have to take original item affine into account */
/* fixme: Think (Lauris) */
eptr = (gchar *) value;
x = g_ascii_strtod (eptr, &eptr);
- while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
+
+ while (*eptr && ((*eptr == ',') || (*eptr == ' '))) {
+ eptr++;
+ }
+
y = g_ascii_strtod (eptr, &eptr);
- while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
+
+ while (*eptr && ((*eptr == ',') || (*eptr == ' '))) {
+ eptr++;
+ }
+
width = g_ascii_strtod (eptr, &eptr);
- while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
+
+ while (*eptr && ((*eptr == ',') || (*eptr == ' '))) {
+ eptr++;
+ }
+
height = g_ascii_strtod (eptr, &eptr);
- while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
+
+ while (*eptr && ((*eptr == ',') || (*eptr == ' '))) {
+ eptr++;
+ }
+
if ((width > 0) && (height > 0)) {
/* Set viewbox */
- marker->viewBox = Geom::Rect( Geom::Point(x,y),
- Geom::Point(x + width, y + height) );
+ this->viewBox = Geom::Rect(Geom::Point(x, y), Geom::Point(x + width, y + height));
}
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
break;
+
case SP_ATTR_PRESERVEASPECTRATIO:
/* Do setup before, so we can use break to escape */
- marker->aspect_set = FALSE;
- marker->aspect_align = SP_ASPECT_NONE;
- marker->aspect_clip = SP_ASPECT_MEET;
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+ this->aspect_set = FALSE;
+ this->aspect_align = SP_ASPECT_NONE;
+ this->aspect_clip = SP_ASPECT_MEET;
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+
if (value) {
int len;
gchar c[256];
const gchar *p, *e;
unsigned int align, clip;
p = value;
- while (*p && *p == 32) p += 1;
- if (!*p) break;
+
+ while (*p && *p == 32) {
+ p += 1;
+ }
+
+ if (!*p) {
+ break;
+ }
+
e = p;
- while (*e && *e != 32) e += 1;
+
+ while (*e && *e != 32) {
+ e += 1;
+ }
+
len = e - p;
- if (len > 8) break;
+
+ if (len > 8) {
+ break;
+ }
+
memcpy (c, value, len);
+
c[len] = 0;
+
/* Now the actual part */
if (!strcmp (c, "none")) {
align = SP_ASPECT_NONE;
@@ -279,8 +291,13 @@ void CMarker::set(unsigned int key, const gchar* value) {
} else {
break;
}
+
clip = SP_ASPECT_MEET;
- while (*e && *e == 32) e += 1;
+
+ while (*e && *e == 32) {
+ e += 1;
+ }
+
if (*e) {
if (!strcmp (e, "meet")) {
clip = SP_ASPECT_MEET;
@@ -290,21 +307,20 @@ void CMarker::set(unsigned int key, const gchar* value) {
break;
}
}
- marker->aspect_set = TRUE;
- marker->aspect_align = align;
- marker->aspect_clip = clip;
+
+ this->aspect_set = TRUE;
+ this->aspect_align = align;
+ this->aspect_clip = clip;
}
break;
+
default:
- CGroup::set(key, value);
+ SPGroup::set(key, value);
break;
}
}
-void CMarker::update(SPCtx *ctx, guint flags) {
- SPMarker* object = this->spmarker;
-
- SPMarker *marker = SP_MARKER(object);
+void SPMarker::update(SPCtx *ctx, guint flags) {
SPItemCtx rctx;
// fixme: We have to set up clip here too
@@ -317,15 +333,15 @@ void CMarker::update(SPCtx *ctx, guint flags) {
rctx.i2vp = Geom::identity();
// Set up viewport
- rctx.viewport = Geom::Rect::from_xywh(0, 0, marker->markerWidth.computed, marker->markerHeight.computed);
+ rctx.viewport = Geom::Rect::from_xywh(0, 0, this->markerWidth.computed, this->markerHeight.computed);
// Start with identity transform
- marker->c2p.setIdentity();
+ this->c2p.setIdentity();
// Viewbox is always present, either implicitly or explicitly
Geom::Rect vb;
- if (marker->viewBox) {
- vb = *marker->viewBox;
+ if (this->viewBox) {
+ vb = *this->viewBox;
} else {
vb = rctx.viewport;
}
@@ -337,7 +353,8 @@ void CMarker::update(SPCtx *ctx, guint flags) {
// double y = 0;
double width = 0;
double height = 0;
- if (marker->aspect_align == SP_ASPECT_NONE) {
+
+ if (this->aspect_align == SP_ASPECT_NONE) {
// x = 0.0;
// y = 0.0;
width = rctx.viewport.width();
@@ -347,7 +364,7 @@ void CMarker::update(SPCtx *ctx, guint flags) {
// Things are getting interesting
scalex = rctx.viewport.width() / (vb.width());
scaley = rctx.viewport.height() / (vb.height());
- scale = (marker->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley);
+ scale = (this->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley);
width = (vb.width()) * scale;
height = (vb.height()) * scale;
@@ -395,48 +412,43 @@ void CMarker::update(SPCtx *ctx, guint flags) {
break;
}*/
}
+
// TODO fixme: all that work is done to figure out x and y, which are just ignored. Check why.
// viewbox transformation and reference translation
- marker->c2p = Geom::Translate(-marker->refX.computed, -marker->refY.computed) *
+ this->c2p = Geom::Translate(-this->refX.computed, -this->refY.computed) *
Geom::Scale(width / vb.width(), height / vb.height());
- rctx.i2doc = marker->c2p * rctx.i2doc;
+ rctx.i2doc = this->c2p * rctx.i2doc;
// If viewBox is set reinitialize child viewport
// Otherwise it already correct
- if (marker->viewBox) {
- rctx.viewport = *marker->viewBox;
+ if (this->viewBox) {
+ rctx.viewport = *this->viewBox;
rctx.i2vp = Geom::identity();
}
// And invoke parent method
- CGroup::update((SPCtx *) &rctx, flags);
+ SPGroup::update((SPCtx *) &rctx, flags);
// As last step set additional transform of drawing group
- for (SPMarkerView *v = marker->views; v != NULL; v = v->next) {
+ for (SPMarkerView *v = this->views; v != NULL; v = v->next) {
for (unsigned i = 0 ; i < v->items.size() ; i++) {
if (v->items[i]) {
Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->items[i]);
- g->setChildTransform(marker->c2p);
+ g->setChildTransform(this->c2p);
}
}
}
}
-Inkscape::XML::Node* CMarker::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPMarker* object = this->spmarker;
-
- SPMarker *marker;
-
- marker = SP_MARKER (object);
-
+Inkscape::XML::Node* SPMarker::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
repr = xml_doc->createElement("svg:marker");
}
- if (marker->markerUnits_set) {
- if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
+ if (this->markerUnits_set) {
+ if (this->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
repr->setAttribute("markerUnits", "strokeWidth");
} else {
repr->setAttribute("markerUnits", "userSpaceOnUse");
@@ -444,49 +456,55 @@ Inkscape::XML::Node* CMarker::write(Inkscape::XML::Document *xml_doc, Inkscape::
} else {
repr->setAttribute("markerUnits", NULL);
}
- if (marker->refX._set) {
- sp_repr_set_svg_double(repr, "refX", marker->refX.computed);
+
+ if (this->refX._set) {
+ sp_repr_set_svg_double(repr, "refX", this->refX.computed);
} else {
repr->setAttribute("refX", NULL);
}
- if (marker->refY._set) {
- sp_repr_set_svg_double (repr, "refY", marker->refY.computed);
+
+ if (this->refY._set) {
+ sp_repr_set_svg_double (repr, "refY", this->refY.computed);
} else {
repr->setAttribute("refY", NULL);
}
- if (marker->markerWidth._set) {
- sp_repr_set_svg_double (repr, "markerWidth", marker->markerWidth.computed);
+
+ if (this->markerWidth._set) {
+ sp_repr_set_svg_double (repr, "markerWidth", this->markerWidth.computed);
} else {
repr->setAttribute("markerWidth", NULL);
}
- if (marker->markerHeight._set) {
- sp_repr_set_svg_double (repr, "markerHeight", marker->markerHeight.computed);
+
+ if (this->markerHeight._set) {
+ sp_repr_set_svg_double (repr, "markerHeight", this->markerHeight.computed);
} else {
repr->setAttribute("markerHeight", NULL);
}
- if (marker->orient_set) {
- if (marker->orient_auto) {
+
+ if (this->orient_set) {
+ if (this->orient_auto) {
repr->setAttribute("orient", "auto");
} else {
- sp_repr_set_css_double(repr, "orient", marker->orient);
+ sp_repr_set_css_double(repr, "orient", this->orient);
}
} else {
repr->setAttribute("orient", NULL);
}
+
/* fixme: */
//XML Tree being used directly here while it shouldn't be....
- repr->setAttribute("viewBox", object->getRepr()->attribute("viewBox"));
+ repr->setAttribute("viewBox", this->getRepr()->attribute("viewBox"));
//XML Tree being used directly here while it shouldn't be....
- repr->setAttribute("preserveAspectRatio", object->getRepr()->attribute("preserveAspectRatio"));
+ repr->setAttribute("preserveAspectRatio", this->getRepr()->attribute("preserveAspectRatio"));
- CGroup::write(xml_doc, repr, flags);
+ SPGroup::write(xml_doc, repr, flags);
return repr;
}
-Inkscape::DrawingItem* CMarker::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) {
+Inkscape::DrawingItem* SPMarker::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) {
// CPPIFY: correct?
- return CGroup::show(drawing, key, flags);
+ return SPGroup::show(drawing, key, flags);
}
/**
@@ -499,9 +517,9 @@ sp_marker_private_show (SPItem */*item*/, Inkscape::Drawing &/*drawing*/, unsign
return NULL;
}
-void CMarker::hide(unsigned int key) {
+void SPMarker::hide(unsigned int key) {
// CPPIFY: correct?
- CGroup::hide(key);
+ SPGroup::hide(key);
}
/**
@@ -513,7 +531,7 @@ sp_marker_private_hide (SPItem */*item*/, unsigned int /*key*/)
/* Break propagation */
}
-Geom::OptRect CMarker::bbox(Geom::Affine const &transform, SPItem::BBoxType type) {
+Geom::OptRect SPMarker::bbox(Geom::Affine const &transform, SPItem::BBoxType type) {
return Geom::OptRect();
}
@@ -527,7 +545,7 @@ sp_marker_bbox(SPItem const *, Geom::Affine const &, SPItem::BBoxType)
return Geom::OptRect();
}
-void CMarker::print(SPPrintContext* ctx) {
+void SPMarker::print(SPPrintContext* ctx) {
}
@@ -565,7 +583,7 @@ sp_marker_show_dimension (SPMarker *marker, unsigned int key, unsigned int size)
if (view && (view->items.size() != size)) {
/* Free old view and allocate new */
/* Parent class ::hide method */
- marker->cmarker->hide(key);
+ marker->hide(key);
sp_marker_view_remove (marker, view, TRUE);
view = NULL;
@@ -605,7 +623,7 @@ sp_marker_show_instance ( SPMarker *marker, Inkscape::DrawingItem *parent,
}
if (!v->items[pos]) {
/* Parent class ::show method */
- v->items[pos] = marker->cmarker->show(parent->drawing(), key, SP_ITEM_REFERENCE_FLAGS);
+ v->items[pos] = marker->show(parent->drawing(), key, SP_ITEM_REFERENCE_FLAGS);
if (v->items[pos]) {
/* fixme: Position (Lauris) */
@@ -651,7 +669,7 @@ sp_marker_hide (SPMarker *marker, unsigned int key)
next = v->next;
if (v->key == key) {
/* Parent class ::hide method */
- marker->cmarker->hide(key);
+ marker->hide(key);
sp_marker_view_remove (marker, v, TRUE);
return;
diff --git a/src/marker.h b/src/marker.h
index bd6d518d0..0300d7199 100644
--- a/src/marker.h
+++ b/src/marker.h
@@ -20,10 +20,9 @@
#define SP_TYPE_MARKER (sp_marker_get_type ())
#define SP_MARKER(obj) ((SPMarker*)obj)
-#define SP_IS_MARKER(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPMarker)))
+#define SP_IS_MARKER(obj) (dynamic_cast<const SPMarker*>((SPObject*)obj))
struct SPMarkerView;
-class CMarker;
#include <2geom/rect.h>
#include <2geom/affine.h>
@@ -36,7 +35,7 @@ class CMarker;
class SPMarker : public SPGroup {
public:
SPMarker();
- CMarker* cmarker;
+ virtual ~SPMarker();
/* units */
unsigned int markerUnits_set : 1;
@@ -68,17 +67,6 @@ public:
/* Private views */
SPMarkerView *views;
-};
-
-struct SPMarkerClass {
- SPGroupClass parent_class;
-};
-
-
-class CMarker : public CGroup {
-public:
- CMarker(SPMarker* marker);
- virtual ~CMarker();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual void release();
@@ -91,15 +79,8 @@ public:
virtual Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType type);
virtual void print(SPPrintContext *ctx);
-
-protected:
- SPMarker* spmarker;
};
-
-
-GType sp_marker_get_type (void);
-
class SPMarkerReference : public Inkscape::URIReference {
SPMarkerReference(SPObject *obj) : URIReference(obj) {}
SPMarker *getObject() const {
diff --git a/src/sp-anchor.cpp b/src/sp-anchor.cpp
index df2669ebf..babec4537 100644
--- a/src/sp-anchor.cpp
+++ b/src/sp-anchor.cpp
@@ -35,75 +35,47 @@ namespace {
bool anchorRegistered = SPFactory::instance().registerObject("svg:a", createAnchor);
}
-G_DEFINE_TYPE(SPAnchor, sp_anchor, G_TYPE_OBJECT);
-
-static void sp_anchor_class_init(SPAnchorClass *ac)
-{
-}
-
-CAnchor::CAnchor(SPAnchor* anchor) : CGroup(anchor) {
- this->spanchor = anchor;
-}
-
-CAnchor::~CAnchor() {
-}
-
SPAnchor::SPAnchor() : SPGroup() {
- SPAnchor* anchor = this;
-
- anchor->canchor = new CAnchor(anchor);
- anchor->typeHierarchy.insert(typeid(SPAnchor));
-
- delete anchor->cgroup;
- anchor->cgroup = anchor->canchor;
- anchor->clpeitem = anchor->canchor;
- anchor->citem = anchor->canchor;
- anchor->cobject = anchor->canchor;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
- anchor->href = NULL;
+ this->href = NULL;
}
-static void sp_anchor_init(SPAnchor *anchor)
-{
- new (anchor) SPAnchor();
+SPAnchor::~SPAnchor() {
}
-void CAnchor::build(SPDocument *document, Inkscape::XML::Node *repr) {
- SPAnchor* object = this->spanchor;
-
- CGroup::build(document, repr);
-
- object->readAttr( "xlink:type" );
- object->readAttr( "xlink:role" );
- object->readAttr( "xlink:arcrole" );
- object->readAttr( "xlink:title" );
- object->readAttr( "xlink:show" );
- object->readAttr( "xlink:actuate" );
- object->readAttr( "xlink:href" );
- object->readAttr( "target" );
+void SPAnchor::build(SPDocument *document, Inkscape::XML::Node *repr) {
+ SPGroup::build(document, repr);
+
+ this->readAttr( "xlink:type" );
+ this->readAttr( "xlink:role" );
+ this->readAttr( "xlink:arcrole" );
+ this->readAttr( "xlink:title" );
+ this->readAttr( "xlink:show" );
+ this->readAttr( "xlink:actuate" );
+ this->readAttr( "xlink:href" );
+ this->readAttr( "target" );
}
-void CAnchor::release() {
- SPAnchor *anchor = this->spanchor;
-
- if (anchor->href) {
- g_free(anchor->href);
- anchor->href = NULL;
+void SPAnchor::release() {
+ if (this->href) {
+ g_free(this->href);
+ this->href = NULL;
}
- CGroup::release();
+ SPGroup::release();
}
-void CAnchor::set(unsigned int key, const gchar* value) {
- SPAnchor *anchor = this->spanchor;
- SPAnchor* object = anchor;
-
+void SPAnchor::set(unsigned int key, const gchar* value) {
switch (key) {
case SP_ATTR_XLINK_HREF:
- g_free(anchor->href);
- anchor->href = g_strdup(value);
- object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ g_free(this->href);
+ this->href = g_strdup(value);
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
+
case SP_ATTR_XLINK_TYPE:
case SP_ATTR_XLINK_ROLE:
case SP_ATTR_XLINK_ARCROLE:
@@ -111,10 +83,11 @@ void CAnchor::set(unsigned int key, const gchar* value) {
case SP_ATTR_XLINK_SHOW:
case SP_ATTR_XLINK_ACTUATE:
case SP_ATTR_TARGET:
- object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
+
default:
- CGroup::set(key, value);
+ SPGroup::set(key, value);
break;
}
}
@@ -122,38 +95,33 @@ void CAnchor::set(unsigned int key, const gchar* value) {
#define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key));
-Inkscape::XML::Node* CAnchor::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPAnchor *anchor = this->spanchor;
- SPAnchor* object = anchor;
-
+Inkscape::XML::Node* SPAnchor::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
repr = xml_doc->createElement("svg:a");
}
- repr->setAttribute("xlink:href", anchor->href);
+ repr->setAttribute("xlink:href", this->href);
- if (repr != object->getRepr()) {
+ if (repr != this->getRepr()) {
// XML Tree being directly used while it shouldn't be in the
// below COPY_ATTR lines
- COPY_ATTR(repr, object->getRepr(), "xlink:type");
- COPY_ATTR(repr, object->getRepr(), "xlink:role");
- COPY_ATTR(repr, object->getRepr(), "xlink:arcrole");
- COPY_ATTR(repr, object->getRepr(), "xlink:title");
- COPY_ATTR(repr, object->getRepr(), "xlink:show");
- COPY_ATTR(repr, object->getRepr(), "xlink:actuate");
- COPY_ATTR(repr, object->getRepr(), "target");
+ COPY_ATTR(repr, this->getRepr(), "xlink:type");
+ COPY_ATTR(repr, this->getRepr(), "xlink:role");
+ COPY_ATTR(repr, this->getRepr(), "xlink:arcrole");
+ COPY_ATTR(repr, this->getRepr(), "xlink:title");
+ COPY_ATTR(repr, this->getRepr(), "xlink:show");
+ COPY_ATTR(repr, this->getRepr(), "xlink:actuate");
+ COPY_ATTR(repr, this->getRepr(), "target");
}
- CGroup::write(xml_doc, repr, flags);
+ SPGroup::write(xml_doc, repr, flags);
return repr;
}
-gchar* CAnchor::description() {
- SPAnchor *anchor = this->spanchor;
-
- if (anchor->href) {
- char *quoted_href = xml_quote_strdup(anchor->href);
+gchar* SPAnchor::description() {
+ if (this->href) {
+ char *quoted_href = xml_quote_strdup(this->href);
char *ret = g_strdup_printf(_("<b>Link</b> to %s"), quoted_href);
g_free(quoted_href);
return ret;
@@ -163,22 +131,23 @@ gchar* CAnchor::description() {
}
/* fixme: We should forward event to appropriate container/view */
-gint CAnchor::event(SPEvent* event) {
- SPAnchor *anchor = this->spanchor;
-
+gint SPAnchor::event(SPEvent* event) {
switch (event->type) {
case SP_EVENT_ACTIVATE:
- if (anchor->href) {
- g_print("Activated xlink:href=\"%s\"\n", anchor->href);
+ if (this->href) {
+ g_print("Activated xlink:href=\"%s\"\n", this->href);
return TRUE;
}
break;
+
case SP_EVENT_MOUSEOVER:
(static_cast<Inkscape::UI::View::View*>(event->data))->mouseover();
break;
+
case SP_EVENT_MOUSEOUT:
(static_cast<Inkscape::UI::View::View*>(event->data))->mouseout();
break;
+
default:
break;
}
diff --git a/src/sp-anchor.h b/src/sp-anchor.h
index 7fa1dcfc1..b3d95d9c4 100644
--- a/src/sp-anchor.h
+++ b/src/sp-anchor.h
@@ -15,29 +15,15 @@
#include "sp-item-group.h"
-#define SP_TYPE_ANCHOR (sp_anchor_get_type ())
#define SP_ANCHOR(obj) ((SPAnchor*)obj)
-#define SP_IS_ANCHOR(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPAnchor)))
-
-class CAnchor;
+#define SP_IS_ANCHOR(obj) (dynamic_cast<const SPAnchor*>((SPObject*)obj))
class SPAnchor : public SPGroup {
public:
SPAnchor();
- CAnchor* canchor;
+ virtual ~SPAnchor();
gchar *href;
-};
-
-struct SPAnchorClass {
- SPGroupClass parent_class;
-};
-
-
-class CAnchor : public CGroup {
-public:
- CAnchor(SPAnchor* anchor);
- virtual ~CAnchor();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual void release();
@@ -46,12 +32,6 @@ public:
virtual gchar* description();
virtual gint event(SPEvent *event);
-
-protected:
- SPAnchor* spanchor;
};
-
-GType sp_anchor_get_type (void);
-
#endif
diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp
index 10e84f2da..5956b16a9 100644
--- a/src/sp-item-group.cpp
+++ b/src/sp-item-group.cpp
@@ -67,71 +67,38 @@ namespace {
bool groupRegistered = SPFactory::instance().registerObject("svg:g", createGroup);
}
-G_DEFINE_TYPE(SPGroup, sp_group, G_TYPE_OBJECT);
+SPGroup::SPGroup() : SPLPEItem(), CLPEItem(this) {
+ delete this->clpeitem;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
-static void
-sp_group_class_init (SPGroupClass *klass)
-{
- GObjectClass * object_class;
- object_class = (GObjectClass *) klass;
- object_class->dispose = sp_group_dispose;
-}
-
-CGroup::CGroup(SPGroup *group) : CLPEItem(group) {
- this->spgroup = group;
+ this->_layer_mode = SPGroup::GROUP;
+ new (&this->_display_modes) std::map<unsigned int, SPGroup::LayerMode>();
}
-CGroup::~CGroup() {
+SPGroup::~SPGroup() {
+ this->_display_modes.~map();
}
-SPGroup::SPGroup() : SPLPEItem() {
- SPGroup* group = this;
-
- group->cgroup = new CGroup(group);
- group->typeHierarchy.insert(typeid(SPGroup));
-
- delete group->clpeitem;
- group->clpeitem = group->cgroup;
- group->citem = group->cgroup;
- group->cobject = group->cgroup;
-
- group->_layer_mode = SPGroup::GROUP;
- new (&group->_display_modes) std::map<unsigned int, SPGroup::LayerMode>();
-}
-
-static void
-sp_group_init (SPGroup *group)
-{
- new (group) SPGroup();
-}
-
-void CGroup::build(SPDocument *document, Inkscape::XML::Node *repr) {
- SPGroup* object = this->spgroup;
-
- object->readAttr( "inkscape:groupmode" );
+void SPGroup::build(SPDocument *document, Inkscape::XML::Node *repr) {
+ this->readAttr( "inkscape:groupmode" );
CLPEItem::build(document, repr);
}
-void CGroup::release() {
- SPGroup* object = this->spgroup;
-
- if ( SP_GROUP(object)->_layer_mode == SPGroup::LAYER ) {
- object->document->removeResource("layer", object);
+void SPGroup::release() {
+ if (this->_layer_mode == SPGroup::LAYER) {
+ this->document->removeResource("layer", this);
}
- CLPEItem::release();
-}
-static void
-sp_group_dispose(GObject *object)
-{
- SP_GROUP(object)->_display_modes.~map();
+ CLPEItem::release();
}
-void CGroup::child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) {
+void SPGroup::child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) {
CLPEItem::child_added(child, ref);
- SPObject *last_child = spgroup->lastChild();
+ SPObject *last_child = this->lastChild();
if (last_child && last_child->getRepr() == child) {
// optimization for the common special case where the child is being added at the end
@@ -141,7 +108,7 @@ void CGroup::child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) {
SPItemView *v;
Inkscape::DrawingItem *ac;
- for (v = spgroup->display; v != NULL; v = v->next) {
+ for (v = this->display; v != NULL; v = v->next) {
ac = SP_ITEM (ochild)->invoke_show (v->arenaitem->drawing(), v->key, v->flags);
if (ac) {
@@ -150,7 +117,7 @@ void CGroup::child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) {
}
}
} else { // general case
- SPObject *ochild = spgroup->get_child_by_repr(child);
+ SPObject *ochild = this->get_child_by_repr(child);
if ( ochild && SP_IS_ITEM(ochild) ) {
/* TODO: this should be moved into SPItem somehow */
SPItemView *v;
@@ -158,7 +125,7 @@ void CGroup::child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) {
unsigned position = SP_ITEM(ochild)->pos_in_parent();
- for (v = spgroup->display; v != NULL; v = v->next) {
+ for (v = this->display; v != NULL; v = v->next) {
ac = SP_ITEM (ochild)->invoke_show (v->arenaitem->drawing(), v->key, v->flags);
if (ac) {
@@ -169,22 +136,22 @@ void CGroup::child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) {
}
}
- spgroup->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
/* fixme: hide (Lauris) */
-void CGroup::remove_child(Inkscape::XML::Node *child) {
+void SPGroup::remove_child(Inkscape::XML::Node *child) {
CLPEItem::remove_child(child);
- spgroup->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
-void CGroup::order_changed (Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref)
+void SPGroup::order_changed (Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref)
{
CLPEItem::order_changed(child, old_ref, new_ref);
- SPObject *ochild = spgroup->get_child_by_repr(child);
+ SPObject *ochild = this->get_child_by_repr(child);
if ( ochild && SP_IS_ITEM(ochild) ) {
/* TODO: this should be moved into SPItem somehow */
SPItemView *v;
@@ -194,10 +161,10 @@ void CGroup::order_changed (Inkscape::XML::Node *child, Inkscape::XML::Node *old
}
}
- spgroup->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
-void CGroup::update(SPCtx *ctx, unsigned int flags) {
+void SPGroup::update(SPCtx *ctx, unsigned int flags) {
CLPEItem::update(ctx, flags);
SPItemCtx *ictx, cctx;
@@ -212,17 +179,17 @@ void CGroup::update(SPCtx *ctx, unsigned int flags) {
flags &= SP_OBJECT_MODIFIED_CASCADE;
if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
- SPObject *object = spgroup;
- for (SPItemView *v = spgroup->display; v != NULL; v = v->next) {
+ for (SPItemView *v = this->display; v != NULL; v = v->next) {
Inkscape::DrawingGroup *group = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem);
- group->setStyle(object->style);
+ group->setStyle(this->style);
}
}
- GSList *l = g_slist_reverse(spgroup->childList(true, SPObject::ActionUpdate));
+ GSList *l = g_slist_reverse(this->childList(true, SPObject::ActionUpdate));
while (l) {
SPObject *child = SP_OBJECT (l->data);
l = g_slist_remove (l, child);
+
if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
if (SP_IS_ITEM (child)) {
SPItem const &chi = *SP_ITEM(child);
@@ -233,43 +200,50 @@ void CGroup::update(SPCtx *ctx, unsigned int flags) {
child->updateDisplay(ctx, flags);
}
}
+
sp_object_unref(child);
}
}
-void CGroup::modified(guint flags) {
+void SPGroup::modified(guint flags) {
CLPEItem::modified(flags);
SPObject *child;
- if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
+ if (flags & SP_OBJECT_MODIFIED_FLAG) {
+ flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
+ }
+
flags &= SP_OBJECT_MODIFIED_CASCADE;
if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
- SPObject *object = spgroup;
- for (SPItemView *v = spgroup->display; v != NULL; v = v->next) {
+ for (SPItemView *v = this->display; v != NULL; v = v->next) {
Inkscape::DrawingGroup *group = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem);
- group->setStyle(object->style);
+ group->setStyle(this->style);
}
}
- GSList *l = g_slist_reverse(spgroup->childList(true));
+ GSList *l = g_slist_reverse(this->childList(true));
+
while (l) {
child = SP_OBJECT (l->data);
l = g_slist_remove (l, child);
+
if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
child->emitModified(flags);
}
+
sp_object_unref(child);
}
}
-Inkscape::XML::Node* CGroup::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPGroup* object = this->spgroup;
+Inkscape::XML::Node* SPGroup::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
+ SPGroup* object = this;
SPGroup *group = SP_GROUP(object);
if (flags & SP_OBJECT_WRITE_BUILD) {
GSList *l;
+
if (!repr) {
if (SP_IS_SWITCH(object)) {
repr = xml_doc->createElement("svg:switch");
@@ -277,15 +251,19 @@ Inkscape::XML::Node* CGroup::write(Inkscape::XML::Document *xml_doc, Inkscape::X
repr = xml_doc->createElement("svg:g");
}
}
+
l = NULL;
+
for (SPObject *child = object->firstChild(); child; child = child->getNext() ) {
if ( !SP_IS_TITLE(child) && !SP_IS_DESC(child) ) {
Inkscape::XML::Node *crepr = child->updateRepr(xml_doc, NULL, flags);
+
if (crepr) {
l = g_slist_prepend (l, crepr);
}
}
}
+
while (l) {
repr->addChild((Inkscape::XML::Node *) l->data, NULL);
Inkscape::GC::release((Inkscape::XML::Node *) l->data);
@@ -310,6 +288,7 @@ Inkscape::XML::Node* CGroup::write(Inkscape::XML::Document *xml_doc, Inkscape::X
} else {
value = NULL;
}
+
repr->setAttribute("inkscape:groupmode", value);
}
@@ -318,83 +297,91 @@ Inkscape::XML::Node* CGroup::write(Inkscape::XML::Document *xml_doc, Inkscape::X
return repr;
}
-Geom::OptRect CGroup::bbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype)
+Geom::OptRect SPGroup::bbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype)
{
Geom::OptRect bbox;
- GSList *l = this->spgroup->childList(false, SPObject::ActionBBox);
+ GSList *l = this->childList(false, SPObject::ActionBBox);
+
while (l) {
SPObject *o = SP_OBJECT (l->data);
+
if (SP_IS_ITEM(o) && !SP_ITEM(o)->isHidden()) {
SPItem *child = SP_ITEM(o);
Geom::Affine const ct(child->transform * transform);
bbox |= child->bounds(bboxtype, ct);
}
+
l = g_slist_remove (l, o);
}
+
return bbox;
}
-void CGroup::print(SPPrintContext *ctx) {
- GSList *l = g_slist_reverse(spgroup->childList(false));
+void SPGroup::print(SPPrintContext *ctx) {
+ GSList *l = g_slist_reverse(this->childList(false));
+
while (l) {
SPObject *o = SP_OBJECT (l->data);
+
if (SP_IS_ITEM(o)) {
SP_ITEM(o)->invoke_print (ctx);
}
+
l = g_slist_remove (l, o);
}
}
-gchar *CGroup::description() {
- gint len = this->spgroup->getItemCount();
+gchar *SPGroup::description() {
+ gint len = this->getItemCount();
return g_strdup_printf(
ngettext("<b>Group</b> of <b>%d</b> object",
"<b>Group</b> of <b>%d</b> objects",
len), len);
}
-void CGroup::set(unsigned int key, gchar const* value) {
- SPGroup *group = this->spgroup;
-
+void SPGroup::set(unsigned int key, gchar const* value) {
switch (key) {
case SP_ATTR_INKSCAPE_GROUPMODE:
if ( value && !strcmp(value, "layer") ) {
- group->setLayerMode(SPGroup::LAYER);
+ this->setLayerMode(SPGroup::LAYER);
} else if ( value && !strcmp(value, "maskhelper") ) {
- group->setLayerMode(SPGroup::MASK_HELPER);
+ this->setLayerMode(SPGroup::MASK_HELPER);
} else {
- group->setLayerMode(SPGroup::GROUP);
+ this->setLayerMode(SPGroup::GROUP);
}
break;
- default: {
+
+ default:
CLPEItem::set(key, value);
- }
+ break;
}
}
-Inkscape::DrawingItem *CGroup::show (Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) {
+Inkscape::DrawingItem *SPGroup::show (Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) {
Inkscape::DrawingGroup *ai;
- SPObject *object = spgroup;
ai = new Inkscape::DrawingGroup(drawing);
- ai->setPickChildren(spgroup->effectiveLayerMode(key) == SPGroup::LAYER);
- ai->setStyle(object->style);
+ ai->setPickChildren(this->effectiveLayerMode(key) == SPGroup::LAYER);
+ ai->setStyle(this->style);
- this->spgroup->_showChildren(drawing, ai, key, flags);
+ this->_showChildren(drawing, ai, key, flags);
return ai;
}
-void CGroup::hide (unsigned int key) {
+void SPGroup::hide (unsigned int key) {
SPItem * child;
- GSList *l = g_slist_reverse(spgroup->childList(false, SPObject::ActionShow));
+ GSList *l = g_slist_reverse(this->childList(false, SPObject::ActionShow));
+
while (l) {
SPObject *o = SP_OBJECT (l->data);
+
if (SP_IS_ITEM (o)) {
child = SP_ITEM (o);
child->invoke_hide (key);
}
+
l = g_slist_remove (l, o);
}
@@ -402,10 +389,8 @@ void CGroup::hide (unsigned int key) {
}
-void CGroup::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) {
- SPGroup* item = this->spgroup;
-
- for ( SPObject const *o = item->firstChild(); o; o = o->getNext() )
+void SPGroup::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) {
+ for ( SPObject const *o = this->firstChild(); o; o = o->getNext() )
{
if (SP_IS_ITEM(o)) {
SP_ITEM(o)->getSnappoints(p, snapprefs);
@@ -688,33 +673,32 @@ void SPGroup::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *
}
}
-void CGroup::update_patheffect(bool write) {
- SPGroup* lpeitem = this->spgroup;
-
+void SPGroup::update_patheffect(bool write) {
#ifdef GROUP_VERBOSE
g_message("sp_group_update_patheffect: %p\n", lpeitem);
#endif
- g_return_if_fail (lpeitem != NULL);
- g_return_if_fail (SP_IS_GROUP (lpeitem));
- GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
+ GSList const *item_list = sp_item_group_item_list(this);
+
for ( GSList const *iter = item_list; iter; iter = iter->next ) {
SPObject *subitem = static_cast<SPObject *>(iter->data);
+
if (SP_IS_LPE_ITEM(subitem)) {
((SPLPEItem*)subitem)->clpeitem->update_patheffect(write);
}
}
- if (sp_lpe_item_has_path_effect(lpeitem) && sp_lpe_item_path_effects_enabled(lpeitem)) {
- for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); it++)
+ if (sp_lpe_item_has_path_effect(this) && sp_lpe_item_path_effects_enabled(this)) {
+ for (PathEffectList::iterator it = this->path_effect_list->begin(); it != this->path_effect_list->end(); it++)
{
LivePathEffectObject *lpeobj = (*it)->lpeobject;
+
if (lpeobj && lpeobj->get_lpe()) {
- lpeobj->get_lpe()->doBeforeEffect(lpeitem);
+ lpeobj->get_lpe()->doBeforeEffect(this);
}
}
- sp_group_perform_patheffect(SP_GROUP(lpeitem), SP_GROUP(lpeitem), write);
+ sp_group_perform_patheffect(this, this, write);
}
}
@@ -722,17 +706,21 @@ static void
sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write)
{
GSList const *item_list = sp_item_group_item_list(SP_GROUP(group));
+
for ( GSList const *iter = item_list; iter; iter = iter->next ) {
SPObject *subitem = static_cast<SPObject *>(iter->data);
+
if (SP_IS_GROUP(subitem)) {
sp_group_perform_patheffect(SP_GROUP(subitem), topgroup, write);
} else if (SP_IS_SHAPE(subitem)) {
SPCurve * c = NULL;
+
if (SP_IS_PATH(subitem)) {
c = SP_PATH(subitem)->get_original_curve();
} else {
c = SP_SHAPE(subitem)->getCurve();
}
+
// only run LPEs when the shape has a curve defined
if (c) {
sp_lpe_item_perform_path_effect(SP_LPE_ITEM(topgroup), c);
diff --git a/src/sp-item-group.h b/src/sp-item-group.h
index dbe745239..1408eefe7 100644
--- a/src/sp-item-group.h
+++ b/src/sp-item-group.h
@@ -16,14 +16,11 @@
#include <map>
#include "sp-lpe-item.h"
-#define SP_TYPE_GROUP (sp_group_get_type ())
#define SP_GROUP(obj) ((SPGroup*)obj)
-#define SP_IS_GROUP(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPGroup)))
+#define SP_IS_GROUP(obj) (dynamic_cast<const SPGroup*>((SPObject*)obj))
#define SP_IS_LAYER(obj) (SP_IS_GROUP(obj) && SP_GROUP(obj)->layerMode() == SPGroup::LAYER)
-class CGroup;
-
namespace Inkscape {
class Drawing;
@@ -31,10 +28,10 @@ class DrawingItem;
} // namespace Inkscape
-class SPGroup : public SPLPEItem {
+class SPGroup : public SPLPEItem, public CLPEItem {
public:
SPGroup();
- CGroup *cgroup;
+ virtual ~SPGroup();
enum LayerMode { GROUP, LAYER, MASK_HELPER };
@@ -61,21 +58,8 @@ public:
private:
void _updateLayerMode(unsigned int display_key=0);
-};
-
-struct SPGroupClass {
- SPLPEItemClass parent_class;
-};
-
-/*
- * Virtual methods of SPGroup
- */
-class CGroup : public CLPEItem {
public:
- CGroup(SPGroup *group);
- virtual ~CGroup();
-
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual void release();
@@ -98,14 +82,8 @@ public:
virtual void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
virtual void update_patheffect(bool write);
-
-protected:
- SPGroup *spgroup;
};
-
-GType sp_group_get_type (void);
-
void sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done = true);
diff --git a/src/sp-root.cpp b/src/sp-root.cpp
index 8dcae05be..77ae15f85 100644
--- a/src/sp-root.cpp
+++ b/src/sp-root.cpp
@@ -41,206 +41,214 @@ namespace {
bool rootRegistered = SPFactory::instance().registerObject("svg:svg", createRoot);
}
-G_DEFINE_TYPE(SPRoot, sp_root, G_TYPE_OBJECT);
-
-/**
- * Initializes an SPRootClass object by setting its class and parent class objects, and registering
- * function pointers (i.e.\ gobject-style virtual functions) for various operations.
- */
-static void sp_root_class_init(SPRootClass *klass)
-{
-}
-
-CRoot::CRoot(SPRoot* root) : CGroup(root) {
- this->sproot = root;
-}
-
-CRoot::~CRoot() {
-}
-
SPRoot::SPRoot() : SPGroup() {
- SPRoot* root = this;
-
- root->croot = new CRoot(root);
- root->typeHierarchy.insert(typeid(SPRoot));
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
- delete root->cgroup;
- root->cgroup = root->croot;
- root->clpeitem = root->croot;
- root->citem = root->croot;
- root->cobject = root->croot;
-
- root->aspect_set = 0;
- root->aspect_align = 0;
- root->onload = NULL;
- root->aspect_clip = 0;
+ this->aspect_set = 0;
+ this->aspect_align = 0;
+ this->onload = NULL;
+ this->aspect_clip = 0;
static Inkscape::Version const zero_version(0, 0);
- sp_version_from_string(SVG_VERSION, &root->original.svg);
- root->version.svg = zero_version;
- root->original.svg = zero_version;
- root->version.inkscape = zero_version;
- root->original.inkscape = zero_version;
+ sp_version_from_string(SVG_VERSION, &this->original.svg);
+ this->version.svg = zero_version;
+ this->original.svg = zero_version;
+ this->version.inkscape = zero_version;
+ this->original.inkscape = zero_version;
- root->x.unset();
- root->y.unset();
- root->width.unset(SVGLength::PERCENT, 1.0, 1.0);
- root->height.unset(SVGLength::PERCENT, 1.0, 1.0);
+ this->x.unset();
+ this->y.unset();
+ this->width.unset(SVGLength::PERCENT, 1.0, 1.0);
+ this->height.unset(SVGLength::PERCENT, 1.0, 1.0);
- root->viewBox_set = FALSE;
+ this->viewBox_set = FALSE;
- root->c2p.setIdentity();
+ this->c2p.setIdentity();
- root->defs = NULL;
+ this->defs = NULL;
}
-/**
- * Initializes an SPRoot object by setting its default parameter values.
- */
-static void sp_root_init(SPRoot *root)
-{
- new (root) SPRoot();
+SPRoot::~SPRoot() {
}
-void CRoot::build(SPDocument *document, Inkscape::XML::Node *repr) {
- SPRoot* object = this->sproot;
-
- SPGroup *group = (SPGroup *) object;
- SPRoot *root = (SPRoot *) object;
-
+void SPRoot::build(SPDocument *document, Inkscape::XML::Node *repr) {
//XML Tree being used directly here while it shouldn't be.
- if ( !object->getRepr()->attribute("version") ) {
+ if ( !this->getRepr()->attribute("version") ) {
repr->setAttribute("version", SVG_VERSION);
}
- object->readAttr( "version" );
- object->readAttr( "inkscape:version" );
+ this->readAttr( "version" );
+ this->readAttr( "inkscape:version" );
/* It is important to parse these here, so objects will have viewport build-time */
- object->readAttr( "x" );
- object->readAttr( "y" );
- object->readAttr( "width" );
- object->readAttr( "height" );
- object->readAttr( "viewBox" );
- object->readAttr( "preserveAspectRatio" );
- object->readAttr( "onload" );
+ this->readAttr( "x" );
+ this->readAttr( "y" );
+ this->readAttr( "width" );
+ this->readAttr( "height" );
+ this->readAttr( "viewBox" );
+ this->readAttr( "preserveAspectRatio" );
+ this->readAttr( "onload" );
- CGroup::build(document, repr);
+ SPGroup::build(document, repr);
// Search for first <defs> node
- for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) {
+ for (SPObject *o = this->firstChild() ; o ; o = o->getNext() ) {
if (SP_IS_DEFS(o)) {
- root->defs = SP_DEFS(o);
+ this->defs = SP_DEFS(o);
break;
}
}
// clear transform, if any was read in - SVG does not allow transform= on <svg>
- SP_ITEM(object)->transform = Geom::identity();
+ SP_ITEM(this)->transform = Geom::identity();
}
-void CRoot::release() {
- SPRoot* object = this->sproot;
-
- SPRoot *root = (SPRoot *) object;
- root->defs = NULL;
+void SPRoot::release() {
+ this->defs = NULL;
- CGroup::release();
+ SPGroup::release();
}
-void CRoot::set(unsigned int key, const gchar* value) {
- SPRoot* object = this->sproot;
- SPRoot *root = object;
-
+void SPRoot::set(unsigned int key, const gchar* value) {
switch (key) {
case SP_ATTR_VERSION:
- if (!sp_version_from_string(value, &root->version.svg)) {
- root->version.svg = root->original.svg;
+ if (!sp_version_from_string(value, &this->version.svg)) {
+ this->version.svg = this->original.svg;
}
break;
+
case SP_ATTR_INKSCAPE_VERSION:
- if (!sp_version_from_string(value, &root->version.inkscape)) {
- root->version.inkscape = root->original.inkscape;
+ if (!sp_version_from_string(value, &this->version.inkscape)) {
+ this->version.inkscape = this->original.inkscape;
}
break;
+
case SP_ATTR_X:
- if (!root->x.readAbsolute(value)) {
+ if (!this->x.readAbsolute(value)) {
/* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
- root->x.unset();
+ this->x.unset();
}
+
/* fixme: I am almost sure these do not require viewport flag (Lauris) */
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
break;
+
case SP_ATTR_Y:
- if (!root->y.readAbsolute(value)) {
+ if (!this->y.readAbsolute(value)) {
/* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
- root->y.unset();
+ this->y.unset();
}
+
/* fixme: I am almost sure these do not require viewport flag (Lauris) */
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
break;
+
case SP_ATTR_WIDTH:
- if (!root->width.readAbsolute(value) || !(root->width.computed > 0.0)) {
+ if (!this->width.readAbsolute(value) || !(this->width.computed > 0.0)) {
/* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
- root->width.unset(SVGLength::PERCENT, 1.0, 1.0);
+ this->width.unset(SVGLength::PERCENT, 1.0, 1.0);
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
break;
+
case SP_ATTR_HEIGHT:
- if (!root->height.readAbsolute(value) || !(root->height.computed > 0.0)) {
+ if (!this->height.readAbsolute(value) || !(this->height.computed > 0.0)) {
/* fixme: em, ex, % are probably valid, but require special treatment (Lauris) */
- root->height.unset(SVGLength::PERCENT, 1.0, 1.0);
+ this->height.unset(SVGLength::PERCENT, 1.0, 1.0);
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
break;
+
case SP_ATTR_VIEWBOX:
if (value) {
double x, y, width, height;
char *eptr;
+
/* fixme: We have to take original item affine into account */
/* fixme: Think (Lauris) */
eptr = (gchar *) value;
x = g_ascii_strtod(eptr, &eptr);
- while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
+
+ while (*eptr && ((*eptr == ',') || (*eptr == ' '))) {
+ eptr++;
+ }
+
y = g_ascii_strtod(eptr, &eptr);
- while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
+
+ while (*eptr && ((*eptr == ',') || (*eptr == ' '))) {
+ eptr++;
+ }
+
width = g_ascii_strtod(eptr, &eptr);
- while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
+
+ while (*eptr && ((*eptr == ',') || (*eptr == ' '))) {
+ eptr++;
+ }
+
height = g_ascii_strtod(eptr, &eptr);
- while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
+
+ while (*eptr && ((*eptr == ',') || (*eptr == ' '))) {
+ eptr++;
+ }
+
if ((width > 0) && (height > 0)) {
/* Set viewbox */
- root->viewBox = Geom::Rect::from_xywh(x, y, width, height);
- root->viewBox_set = TRUE;
+ this->viewBox = Geom::Rect::from_xywh(x, y, width, height);
+ this->viewBox_set = TRUE;
} else {
- root->viewBox_set = FALSE;
+ this->viewBox_set = FALSE;
}
} else {
- root->viewBox_set = FALSE;
+ this->viewBox_set = FALSE;
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
break;
+
case SP_ATTR_PRESERVEASPECTRATIO:
/* Do setup before, so we can use break to escape */
- root->aspect_set = FALSE;
- root->aspect_align = SP_ASPECT_XMID_YMID;
- root->aspect_clip = SP_ASPECT_MEET;
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+ this->aspect_set = FALSE;
+ this->aspect_align = SP_ASPECT_XMID_YMID;
+ this->aspect_clip = SP_ASPECT_MEET;
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+
if (value) {
int len;
gchar c[256];
gchar const *p, *e;
unsigned int align, clip;
p = value;
- while (*p && *p == 32) p += 1;
- if (!*p) break;
+
+ while (*p && *p == 32) {
+ p += 1;
+ }
+
+ if (!*p) {
+ break;
+ }
+
e = p;
- while (*e && *e != 32) e += 1;
+
+ while (*e && *e != 32) {
+ e += 1;
+ }
+
len = e - p;
- if (len > 8) break;
+
+ if (len > 8) {
+ break;
+ }
+
memcpy(c, value, len);
+
c[len] = 0;
+
/* Now the actual part */
if (!strcmp(c, "none")) {
align = SP_ASPECT_NONE;
@@ -265,8 +273,13 @@ void CRoot::set(unsigned int key, const gchar* value) {
} else {
break;
}
+
clip = SP_ASPECT_MEET;
- while (*e && *e == 32) e += 1;
+
+ while (*e && *e == 32) {
+ e += 1;
+ }
+
if (*e) {
if (!strcmp(e, "meet")) {
clip = SP_ASPECT_MEET;
@@ -276,95 +289,91 @@ void CRoot::set(unsigned int key, const gchar* value) {
break;
}
}
- root->aspect_set = TRUE;
- root->aspect_align = align;
- root->aspect_clip = clip;
+
+ this->aspect_set = TRUE;
+ this->aspect_align = align;
+ this->aspect_clip = clip;
}
break;
+
case SP_ATTR_ONLOAD:
- root->onload = (char *) value;
+ this->onload = (char *) value;
break;
+
default:
/* Pass the set event to the parent */
- CGroup::set(key, value);
+ SPGroup::set(key, value);
break;
}
}
-void CRoot::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) {
- SPRoot* object = this->sproot;
-
- SPRoot *root = (SPRoot *) object;
- SPGroup *group = (SPGroup *) object;
+void SPRoot::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) {
+ SPGroup::child_added(child, ref);
- CGroup::child_added(child, ref);
-
- SPObject *co = object->document->getObjectByRepr(child);
+ SPObject *co = this->document->getObjectByRepr(child);
g_assert (co != NULL || !strcmp("comment", child->name())); // comment repr node has no object
if (co && SP_IS_DEFS(co)) {
// We search for first <defs> node - it is not beautiful, but works
- for (SPObject *c = group->firstChild() ; c ; c = c->getNext() ) {
+ for (SPObject *c = this->firstChild() ; c ; c = c->getNext() ) {
if (SP_IS_DEFS(c)) {
- root->defs = SP_DEFS(c);
+ this->defs = SP_DEFS(c);
break;
}
}
}
}
-void CRoot::remove_child(Inkscape::XML::Node* child) {
- SPRoot* object = this->sproot;
-
- SPRoot *root = (SPRoot *) object;
-
- if ( root->defs && (root->defs->getRepr() == child) ) {
+void SPRoot::remove_child(Inkscape::XML::Node* child) {
+ if ( this->defs && (this->defs->getRepr() == child) ) {
SPObject *iter = 0;
+
// We search for first remaining <defs> node - it is not beautiful, but works
- for ( iter = object->firstChild() ; iter ; iter = iter->getNext() ) {
- if ( SP_IS_DEFS(iter) && (SPDefs *)iter != root->defs ) {
- root->defs = (SPDefs *)iter;
+ for ( iter = this->firstChild() ; iter ; iter = iter->getNext() ) {
+ if ( SP_IS_DEFS(iter) && (SPDefs *)iter != this->defs ) {
+ this->defs = (SPDefs *)iter;
break;
}
}
+
if (!iter) {
/* we should probably create a new <defs> here? */
- root->defs = NULL;
+ this->defs = NULL;
}
}
- CGroup::remove_child(child);
+ SPGroup::remove_child(child);
}
-void CRoot::update(SPCtx *ctx, guint flags) {
- SPRoot* object = this->sproot;
-
- SPRoot *root = SP_ROOT(object);
+void SPRoot::update(SPCtx *ctx, guint flags) {
SPItemCtx *ictx = (SPItemCtx *) ctx;
/* fixme: This will be invoked too often (Lauris) */
/* fixme: We should calculate only if parent viewport has changed (Lauris) */
/* If position is specified as percentage, calculate actual values */
- if (root->x.unit == SVGLength::PERCENT) {
- root->x.computed = root->x.value * ictx->viewport.width();
+ if (this->x.unit == SVGLength::PERCENT) {
+ this->x.computed = this->x.value * ictx->viewport.width();
}
- if (root->y.unit == SVGLength::PERCENT) {
- root->y.computed = root->y.value * ictx->viewport.height();
+
+ if (this->y.unit == SVGLength::PERCENT) {
+ this->y.computed = this->y.value * ictx->viewport.height();
}
- if (root->width.unit == SVGLength::PERCENT) {
- root->width.computed = root->width.value * ictx->viewport.width();
+
+ if (this->width.unit == SVGLength::PERCENT) {
+ this->width.computed = this->width.value * ictx->viewport.width();
}
- if (root->height.unit == SVGLength::PERCENT) {
- root->height.computed = root->height.value * ictx->viewport.height();
+
+ if (this->height.unit == SVGLength::PERCENT) {
+ this->height.computed = this->height.value * ictx->viewport.height();
}
/* Create copy of item context */
SPItemCtx rctx = *ictx;
/* Calculate child to parent transformation */
- root->c2p.setIdentity();
+ this->c2p.setIdentity();
- if (object->parent) {
+ if (this->parent) {
/*
* fixme: I am not sure whether setting x and y does or does not
* fixme: translate the content of inner SVG.
@@ -372,66 +381,75 @@ void CRoot::update(SPCtx *ctx, guint flags) {
* fixme: height seems natural, as this makes the inner svg element
* fixme: self-contained. The spec is vague here.
*/
- root->c2p = Geom::Affine(Geom::Translate(root->x.computed,
- root->y.computed));
+ this->c2p = Geom::Affine(Geom::Translate(this->x.computed, this->y.computed));
}
- if (root->viewBox_set) {
+ if (this->viewBox_set) {
double x, y, width, height;
/* Determine actual viewbox in viewport coordinates */
- if (root->aspect_align == SP_ASPECT_NONE) {
+ if (this->aspect_align == SP_ASPECT_NONE) {
x = 0.0;
y = 0.0;
- width = root->width.computed;
- height = root->height.computed;
+ width = this->width.computed;
+ height = this->height.computed;
} else {
double scalex, scaley, scale;
/* Things are getting interesting */
- scalex = root->width.computed / root->viewBox.width();
- scaley = root->height.computed / root->viewBox.height();
- scale = (root->aspect_clip == SP_ASPECT_MEET) ? MIN(scalex, scaley) : MAX(scalex, scaley);
- width = root->viewBox.width() * scale;
- height = root->viewBox.height() * scale;
+ scalex = this->width.computed / this->viewBox.width();
+ scaley = this->height.computed / this->viewBox.height();
+ scale = (this->aspect_clip == SP_ASPECT_MEET) ? MIN(scalex, scaley) : MAX(scalex, scaley);
+ width = this->viewBox.width() * scale;
+ height = this->viewBox.height() * scale;
+
/* Now place viewbox to requested position */
/* todo: Use an array lookup to find the 0.0/0.5/1.0 coefficients,
as is done for dialogs/align.cpp. */
- switch (root->aspect_align) {
+ switch (this->aspect_align) {
case SP_ASPECT_XMIN_YMIN:
x = 0.0;
y = 0.0;
break;
+
case SP_ASPECT_XMID_YMIN:
- x = 0.5 * (root->width.computed - width);
+ x = 0.5 * (this->width.computed - width);
y = 0.0;
break;
+
case SP_ASPECT_XMAX_YMIN:
- x = 1.0 * (root->width.computed - width);
+ x = 1.0 * (this->width.computed - width);
y = 0.0;
break;
+
case SP_ASPECT_XMIN_YMID:
x = 0.0;
- y = 0.5 * (root->height.computed - height);
+ y = 0.5 * (this->height.computed - height);
break;
+
case SP_ASPECT_XMID_YMID:
- x = 0.5 * (root->width.computed - width);
- y = 0.5 * (root->height.computed - height);
+ x = 0.5 * (this->width.computed - width);
+ y = 0.5 * (this->height.computed - height);
break;
+
case SP_ASPECT_XMAX_YMID:
- x = 1.0 * (root->width.computed - width);
- y = 0.5 * (root->height.computed - height);
+ x = 1.0 * (this->width.computed - width);
+ y = 0.5 * (this->height.computed - height);
break;
+
case SP_ASPECT_XMIN_YMAX:
x = 0.0;
- y = 1.0 * (root->height.computed - height);
+ y = 1.0 * (this->height.computed - height);
break;
+
case SP_ASPECT_XMID_YMAX:
- x = 0.5 * (root->width.computed - width);
- y = 1.0 * (root->height.computed - height);
+ x = 0.5 * (this->width.computed - width);
+ y = 1.0 * (this->height.computed - height);
break;
+
case SP_ASPECT_XMAX_YMAX:
- x = 1.0 * (root->width.computed - width);
- y = 1.0 * (root->height.computed - height);
+ x = 1.0 * (this->width.computed - width);
+ y = 1.0 * (this->height.computed - height);
break;
+
default:
x = 0.0;
y = 0.0;
@@ -440,60 +458,53 @@ void CRoot::update(SPCtx *ctx, guint flags) {
}
/* Compose additional transformation from scale and position */
- Geom::Scale const viewBox_length( root->viewBox.dimensions() );
+ Geom::Scale const viewBox_length( this->viewBox.dimensions() );
Geom::Scale const new_length(width, height);
/* Append viewbox transformation */
/* TODO: The below looks suspicious to me (pjrm): I wonder whether the RHS
expression should have c2p at the beginning rather than at the end. Test it. */
- root->c2p = Geom::Translate(-root->viewBox.min()) * ( new_length * viewBox_length.inverse() ) * Geom::Translate(x, y) * root->c2p;
+ this->c2p = Geom::Translate(-this->viewBox.min()) * ( new_length * viewBox_length.inverse() ) * Geom::Translate(x, y) * this->c2p;
}
- rctx.i2doc = root->c2p * rctx.i2doc;
+ rctx.i2doc = this->c2p * rctx.i2doc;
/* Initialize child viewport */
- if (root->viewBox_set) {
- rctx.viewport = root->viewBox;
+ if (this->viewBox_set) {
+ rctx.viewport = this->viewBox;
} else {
/* fixme: I wonder whether this logic is correct (Lauris) */
Geom::Point minp(0,0);
- if (object->parent) {
- minp = Geom::Point(root->x.computed, root->y.computed);
+ if (this->parent) {
+ minp = Geom::Point(this->x.computed, this->y.computed);
}
- rctx.viewport = Geom::Rect::from_xywh(minp[Geom::X], minp[Geom::Y], root->width.computed, root->height.computed);
+
+ rctx.viewport = Geom::Rect::from_xywh(minp[Geom::X], minp[Geom::Y], this->width.computed, this->height.computed);
}
rctx.i2vp = Geom::identity();
/* And invoke parent method */
- CGroup::update((SPCtx *) &rctx, flags);
+ SPGroup::update((SPCtx *) &rctx, flags);
/* As last step set additional transform of drawing group */
- for (SPItemView *v = root->display; v != NULL; v = v->next) {
+ for (SPItemView *v = this->display; v != NULL; v = v->next) {
Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem);
- g->setChildTransform(root->c2p);
+ g->setChildTransform(this->c2p);
}
}
-void CRoot::modified(unsigned int flags) {
- SPRoot* object = this->sproot;
-
- SPRoot *root = SP_ROOT(object);
-
- CGroup::modified(flags);
+void SPRoot::modified(unsigned int flags) {
+ SPGroup::modified(flags);
/* fixme: (Lauris) */
- if (!object->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
- root->document->emitResizedSignal(root->width.computed, root->height.computed);
+ if (!this->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
+ this->document->emitResizedSignal(this->width.computed, this->height.computed);
}
}
-Inkscape::XML::Node* CRoot::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPRoot* object = this->sproot;
-
- SPRoot *root = SP_ROOT(object);
-
+Inkscape::XML::Node* SPRoot::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
repr = xml_doc->createElement("svg:svg");
}
@@ -503,59 +514,55 @@ Inkscape::XML::Node* CRoot::write(Inkscape::XML::Document *xml_doc, Inkscape::XM
}
if ( !repr->attribute("version") ) {
- gchar* myversion = sp_version_to_string(root->version.svg);
+ gchar* myversion = sp_version_to_string(this->version.svg);
repr->setAttribute("version", myversion);
g_free(myversion);
}
- if (fabs(root->x.computed) > 1e-9)
- sp_repr_set_svg_double(repr, "x", root->x.computed);
- if (fabs(root->y.computed) > 1e-9)
- sp_repr_set_svg_double(repr, "y", root->y.computed);
+ if (fabs(this->x.computed) > 1e-9) {
+ sp_repr_set_svg_double(repr, "x", this->x.computed);
+ }
+
+ if (fabs(this->y.computed) > 1e-9) {
+ sp_repr_set_svg_double(repr, "y", this->y.computed);
+ }
/* Unlike all other SPObject, here we want to preserve absolute units too (and only here,
* according to the recommendation in http://www.w3.org/TR/SVG11/coords.html#Units).
*/
- repr->setAttribute("width", sp_svg_length_write_with_units(root->width).c_str());
- repr->setAttribute("height", sp_svg_length_write_with_units(root->height).c_str());
+ repr->setAttribute("width", sp_svg_length_write_with_units(this->width).c_str());
+ repr->setAttribute("height", sp_svg_length_write_with_units(this->height).c_str());
- if (root->viewBox_set) {
+ if (this->viewBox_set) {
Inkscape::SVGOStringStream os;
- os << root->viewBox.left() << " " << root->viewBox.top() << " "
- << root->viewBox.width() << " " << root->viewBox.height();
+ os << this->viewBox.left() << " " << this->viewBox.top() << " "
+ << this->viewBox.width() << " " << this->viewBox.height();
+
repr->setAttribute("viewBox", os.str().c_str());
}
- CGroup::write(xml_doc, repr, flags);
+ SPGroup::write(xml_doc, repr, flags);
return repr;
}
-Inkscape::DrawingItem* CRoot::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) {
- SPRoot* item = this->sproot;
-
- SPRoot *root = SP_ROOT(item);
-
+Inkscape::DrawingItem* SPRoot::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) {
Inkscape::DrawingItem *ai = 0;
- ai = CGroup::show(drawing, key, flags);
+ ai = SPGroup::show(drawing, key, flags);
if (ai) {
Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(ai);
- g->setChildTransform(root->c2p);
+ g->setChildTransform(this->c2p);
}
return ai;
}
-void CRoot::print(SPPrintContext* ctx) {
- SPRoot* item = this->sproot;
-
- SPRoot *root = SP_ROOT(item);
-
- sp_print_bind(ctx, root->c2p, 1.0);
+void SPRoot::print(SPPrintContext* ctx) {
+ sp_print_bind(ctx, this->c2p, 1.0);
- CGroup::print(ctx);
+ SPGroup::print(ctx);
sp_print_release(ctx);
}
diff --git a/src/sp-root.h b/src/sp-root.h
index 1a55f19b0..d9c96da50 100644
--- a/src/sp-root.h
+++ b/src/sp-root.h
@@ -19,18 +19,16 @@
#include "enums.h"
#include "sp-item-group.h"
-#define SP_TYPE_ROOT (sp_root_get_type())
#define SP_ROOT(obj) ((SPRoot*)obj)
-#define SP_IS_ROOT(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPRoot)))
+#define SP_IS_ROOT(obj) (dynamic_cast<const SPRoot*>((SPObject*)obj))
class SPDefs;
-class CRoot;
/** \<svg\> element */
class SPRoot : public SPGroup {
public:
SPRoot();
- CRoot* croot;
+ virtual ~SPRoot();
struct {
Inkscape::Version svg;
@@ -63,17 +61,6 @@ public:
* this \<svg\> element: see writers of this member in sp-root.cpp.
*/
SPDefs *defs;
-};
-
-struct SPRootClass {
- SPGroupClass parent_class;
-};
-
-
-class CRoot : public CGroup {
-public:
- CRoot(SPRoot* root);
- virtual ~CRoot();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual void release();
@@ -87,15 +74,8 @@ public:
virtual Inkscape::DrawingItem* show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags);
virtual void print(SPPrintContext *ctx);
-
-protected:
- SPRoot* sproot;
};
-
-GType sp_root_get_type();
-
-
#endif /* !SP_ROOT_H_SEEN */
/*
diff --git a/src/sp-switch.cpp b/src/sp-switch.cpp
index 7dd5bf669..d36406cef 100644
--- a/src/sp-switch.cpp
+++ b/src/sp-switch.cpp
@@ -35,47 +35,26 @@ namespace {
bool switchRegistered = SPFactory::instance().registerObject("svg:switch", createSwitch);
}
-G_DEFINE_TYPE(SPSwitch, sp_switch, G_TYPE_OBJECT);
-
-static void
-sp_switch_class_init (SPSwitchClass *)
-{
-}
-
-CSwitch::CSwitch(SPSwitch* sw) : CGroup(sw) {
- this->spswitch = sw;
-}
-
-CSwitch::~CSwitch() {
-}
-
SPSwitch::SPSwitch() : SPGroup() {
- SPSwitch* sw = this;
-
- sw->cswitch = new CSwitch(sw);
- sw->typeHierarchy.insert(typeid(SPSwitch));
-
- delete sw->cgroup;
- sw->cgroup = sw->cswitch;
- sw->clpeitem = sw->cswitch;
- sw->citem = sw->cswitch;
- sw->cobject = sw->cswitch;
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
- sw->_cached_item = 0;
+ this->_cached_item = 0;
}
-static void sp_switch_init (SPSwitch *sw)
-{
- new (sw) SPSwitch();
+SPSwitch::~SPSwitch() {
}
SPObject *SPSwitch::_evaluateFirst() {
SPObject *first = 0;
+
for (SPObject *child = this->firstChild() ; child && !first ; child = child->getNext() ) {
if (SP_IS_ITEM(child) && sp_item_evaluate(SP_ITEM(child))) {
- first = child;
- }
+ first = child;
+ }
}
+
return first;
}
@@ -94,25 +73,25 @@ GSList *SPSwitch::_childList(bool add_ref, SPObject::Action action) {
return g_slist_prepend (NULL, child);
}
-gchar *CSwitch::description() {
- gint len = this->spgroup->getItemCount();
+gchar *SPSwitch::description() {
+ gint len = this->getItemCount();
return g_strdup_printf(
ngettext("<b>Conditional group</b> of <b>%d</b> object",
"<b>Conditional group</b> of <b>%d</b> objects",
len), len);
}
-void CSwitch::child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) {
- this->spswitch->_reevaluate(true);
+void SPSwitch::child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) {
+ this->_reevaluate(true);
}
-void CSwitch::remove_child(Inkscape::XML::Node *) {
- this->spswitch->_reevaluate();
+void SPSwitch::remove_child(Inkscape::XML::Node *) {
+ this->_reevaluate();
}
-void CSwitch::order_changed (Inkscape::XML::Node *, Inkscape::XML::Node *, Inkscape::XML::Node *)
+void SPSwitch::order_changed (Inkscape::XML::Node *, Inkscape::XML::Node *, Inkscape::XML::Node *)
{
- this->spswitch->_reevaluate();
+ this->_reevaluate();
}
void SPSwitch::_reevaluate(bool /*add_to_drawing*/) {
@@ -159,16 +138,20 @@ void SPSwitch::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem
SPObject *evaluated_child = this->_evaluateFirst();
GSList *l = this->_childList(false, SPObject::ActionShow);
+
while (l) {
SPObject *o = SP_OBJECT (l->data);
+
if (SP_IS_ITEM (o)) {
SPItem * child = SP_ITEM(o);
child->setEvaluated(o == evaluated_child);
Inkscape::DrawingItem *ac = child->invoke_show (drawing, key, flags);
+
if (ac) {
ai->appendChild(ac);
}
}
+
l = g_slist_remove (l, o);
}
}
diff --git a/src/sp-switch.h b/src/sp-switch.h
index f60834a95..24a2dbae6 100644
--- a/src/sp-switch.h
+++ b/src/sp-switch.h
@@ -17,21 +17,13 @@
#include <stddef.h>
#include <sigc++/connection.h>
-G_BEGIN_DECLS
-
-#define SP_TYPE_SWITCH (sp_switch_get_type())
#define SP_SWITCH(obj) ((SPSwitch*)obj)
-#define SP_IS_SWITCH(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPSwitch)))
-
-GType sp_switch_get_type() G_GNUC_CONST;
-class CSwitch;
+#define SP_IS_SWITCH(obj) (dynamic_cast<const SPSwitch*>((SPObject*)obj))
class SPSwitch : public SPGroup {
public:
SPSwitch();
- CSwitch* cswitch;
-
- static GType getType();
+ virtual ~SPSwitch();
void resetChildEvaluated() { _reevaluate(); }
@@ -45,32 +37,11 @@ public:
SPObject *_cached_item;
sigc::connection _release_connection;
-};
-
-struct SPSwitchClass : public SPGroupClass {
-};
-
-
-/*
- * Virtual methods of SPSwitch
- */
-class CSwitch : public CGroup {
-public:
- CSwitch(SPSwitch *sw);
- virtual ~CSwitch();
-
- friend class SPSwitch;
virtual void child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref);
virtual void remove_child(Inkscape::XML::Node *child);
virtual void order_changed(Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref);
virtual gchar *description();
-
-protected:
- SPSwitch* spswitch;
};
-
-G_END_DECLS
-
#endif
diff --git a/src/sp-symbol.cpp b/src/sp-symbol.cpp
index 4e5b53e48..9429046be 100644
--- a/src/sp-symbol.cpp
+++ b/src/sp-symbol.cpp
@@ -36,110 +36,119 @@ namespace {
bool symbolRegistered = SPFactory::instance().registerObject("svg:symbol", createSymbol);
}
-G_DEFINE_TYPE(SPSymbol, sp_symbol, G_TYPE_OBJECT);
-
-static void sp_symbol_class_init(SPSymbolClass *klass)
-{
-}
-
-CSymbol::CSymbol(SPSymbol* symbol) : CGroup(symbol) {
- this->spsymbol = symbol;
-}
-
-CSymbol::~CSymbol() {
-}
-
SPSymbol::SPSymbol() : SPGroup() {
- SPSymbol* symbol = this;
-
- symbol->csymbol = new CSymbol(symbol);
- symbol->typeHierarchy.insert(typeid(SPSymbol));
+ this->clpeitem = this;
+ this->citem = this;
+ this->cobject = this;
- delete symbol->cgroup;
- symbol->cgroup = symbol->csymbol;
- symbol->clpeitem = symbol->csymbol;
- symbol->citem = symbol->csymbol;
- symbol->cobject = symbol->csymbol;
+ this->aspect_align = 0;
+ this->aspect_clip = 0;
+ this->aspect_set = 0;
- symbol->aspect_align = 0;
- symbol->aspect_clip = 0;
- symbol->aspect_set = 0;
-
- symbol->viewBox_set = FALSE;
- symbol->c2p = Geom::identity();
+ this->viewBox_set = FALSE;
+ this->c2p = Geom::identity();
}
-static void sp_symbol_init(SPSymbol *symbol)
-{
- new (symbol) SPSymbol();
+SPSymbol::~SPSymbol() {
}
-void CSymbol::build(SPDocument *document, Inkscape::XML::Node *repr) {
- SPSymbol* object = this->spsymbol;
-
- object->readAttr( "viewBox" );
- object->readAttr( "preserveAspectRatio" );
+void SPSymbol::build(SPDocument *document, Inkscape::XML::Node *repr) {
+ this->readAttr( "viewBox" );
+ this->readAttr( "preserveAspectRatio" );
- CGroup::build(document, repr);
+ SPGroup::build(document, repr);
}
-void CSymbol::release() {
- CGroup::release();
+void SPSymbol::release() {
+ SPGroup::release();
}
-void CSymbol::set(unsigned int key, const gchar* value) {
- SPSymbol* object = this->spsymbol;
-
- SPSymbol *symbol = SP_SYMBOL(object);
-
+void SPSymbol::set(unsigned int key, const gchar* value) {
switch (key) {
case SP_ATTR_VIEWBOX:
if (value) {
double x, y, width, height;
char *eptr;
+
/* fixme: We have to take original item affine into account */
/* fixme: Think (Lauris) */
eptr = (gchar *) value;
x = g_ascii_strtod (eptr, &eptr);
- while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
+
+ while (*eptr && ((*eptr == ',') || (*eptr == ' '))) {
+ eptr++;
+ }
+
y = g_ascii_strtod (eptr, &eptr);
- while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
+
+ while (*eptr && ((*eptr == ',') || (*eptr == ' '))) {
+ eptr++;
+ }
+
width = g_ascii_strtod (eptr, &eptr);
- while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
+
+ while (*eptr && ((*eptr == ',') || (*eptr == ' '))) {
+ eptr++;
+ }
+
height = g_ascii_strtod (eptr, &eptr);
- while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++;
+
+ while (*eptr && ((*eptr == ',') || (*eptr == ' '))) {
+ eptr++;
+ }
+
if ((width > 0) && (height > 0)) {
/* Set viewbox */
- symbol->viewBox = Geom::Rect::from_xywh(x, y, width, height);
- symbol->viewBox_set = TRUE;
+ this->viewBox = Geom::Rect::from_xywh(x, y, width, height);
+ this->viewBox_set = TRUE;
} else {
- symbol->viewBox_set = FALSE;
+ this->viewBox_set = FALSE;
}
} else {
- symbol->viewBox_set = FALSE;
+ this->viewBox_set = FALSE;
}
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
break;
+
case SP_ATTR_PRESERVEASPECTRATIO:
/* Do setup before, so we can use break to escape */
- symbol->aspect_set = FALSE;
- symbol->aspect_align = SP_ASPECT_NONE;
- symbol->aspect_clip = SP_ASPECT_MEET;
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+ this->aspect_set = FALSE;
+ this->aspect_align = SP_ASPECT_NONE;
+ this->aspect_clip = SP_ASPECT_MEET;
+ this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG);
+
if (value) {
int len;
gchar c[256];
const gchar *p, *e;
unsigned int align, clip;
p = value;
- while (*p && *p == 32) p += 1;
- if (!*p) break;
+
+ while (*p && *p == 32) {
+ p += 1;
+ }
+
+ if (!*p) {
+ break;
+ }
+
e = p;
- while (*e && *e != 32) e += 1;
+
+ while (*e && *e != 32) {
+ e += 1;
+ }
+
len = e - p;
- if (len > 8) break;
+
+ if (len > 8) {
+ break;
+ }
+
memcpy (c, value, len);
+
c[len] = 0;
+
/* Now the actual part */
if (!strcmp (c, "none")) {
align = SP_ASPECT_NONE;
@@ -164,8 +173,13 @@ void CSymbol::set(unsigned int key, const gchar* value) {
} else {
break;
}
+
clip = SP_ASPECT_MEET;
- while (*e && *e == 32) e += 1;
+
+ while (*e && *e == 32) {
+ e += 1;
+ }
+
if (*e) {
if (!strcmp (e, "meet")) {
clip = SP_ASPECT_MEET;
@@ -175,30 +189,29 @@ void CSymbol::set(unsigned int key, const gchar* value) {
break;
}
}
- symbol->aspect_set = TRUE;
- symbol->aspect_align = align;
- symbol->aspect_clip = clip;
+
+ this->aspect_set = TRUE;
+ this->aspect_align = align;
+ this->aspect_clip = clip;
}
break;
+
default:
- CGroup::set(key, value);
+ SPGroup::set(key, value);
break;
}
}
-void CSymbol::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) {
- CGroup::child_added(child, ref);
+void SPSymbol::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) {
+ SPGroup::child_added(child, ref);
}
-void CSymbol::update(SPCtx *ctx, guint flags) {
- SPSymbol* object = this->spsymbol;
- SPSymbol *symbol = object;
-
+void SPSymbol::update(SPCtx *ctx, guint flags) {
SPItemCtx *ictx = (SPItemCtx *) ctx;
SPItemCtx rctx;
- if (object->cloned) {
+ if (this->cloned) {
/* Cloned <symbol> is actually renderable */
/* fixme: We have to set up clip here too */
@@ -208,12 +221,13 @@ void CSymbol::update(SPCtx *ctx, guint flags) {
/* Calculate child to parent transformation */
/* Apply parent <use> translation (set up as vewport) */
- symbol->c2p = Geom::Translate(rctx.viewport.min());
+ this->c2p = Geom::Translate(rctx.viewport.min());
- if (symbol->viewBox_set) {
+ if (this->viewBox_set) {
double x, y, width, height;
+
/* Determine actual viewbox in viewport coordinates */
- if (symbol->aspect_align == SP_ASPECT_NONE) {
+ if (this->aspect_align == SP_ASPECT_NONE) {
x = 0.0;
y = 0.0;
width = rctx.viewport.width();
@@ -221,13 +235,14 @@ void CSymbol::update(SPCtx *ctx, guint flags) {
} else {
double scalex, scaley, scale;
/* Things are getting interesting */
- scalex = rctx.viewport.width() / symbol->viewBox.width();
- scaley = rctx.viewport.height() / symbol->viewBox.height();
- scale = (symbol->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley);
- width = symbol->viewBox.width() * scale;
- height = symbol->viewBox.height() * scale;
+ scalex = rctx.viewport.width() / this->viewBox.width();
+ scaley = rctx.viewport.height() / this->viewBox.height();
+ scale = (this->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley);
+ width = this->viewBox.width() * scale;
+ height = this->viewBox.height() * scale;
+
/* Now place viewbox to requested position */
- switch (symbol->aspect_align) {
+ switch (this->aspect_align) {
case SP_ASPECT_XMIN_YMIN:
x = 0.0;
y = 0.0;
@@ -270,118 +285,107 @@ void CSymbol::update(SPCtx *ctx, guint flags) {
break;
}
}
+
/* Compose additional transformation from scale and position */
Geom::Affine q;
- q[0] = width / symbol->viewBox.width();
+ q[0] = width / this->viewBox.width();
q[1] = 0.0;
q[2] = 0.0;
- q[3] = height / symbol->viewBox.height();
- q[4] = -symbol->viewBox.left() * q[0] + x;
- q[5] = -symbol->viewBox.top() * q[3] + y;
+ q[3] = height / this->viewBox.height();
+ q[4] = -this->viewBox.left() * q[0] + x;
+ q[5] = -this->viewBox.top() * q[3] + y;
+
/* Append viewbox transformation */
- symbol->c2p = q * symbol->c2p;
+ this->c2p = q * this->c2p;
}
- rctx.i2doc = symbol->c2p * (Geom::Affine)rctx.i2doc;
+ rctx.i2doc = this->c2p * (Geom::Affine)rctx.i2doc;
/* If viewBox is set initialize child viewport */
/* Otherwise <use> has set it up already */
- if (symbol->viewBox_set) {
- rctx.viewport = symbol->viewBox;
+ if (this->viewBox_set) {
+ rctx.viewport = this->viewBox;
rctx.i2vp = Geom::identity();
}
// And invoke parent method
- CGroup::update((SPCtx *) &rctx, flags);
+ SPGroup::update((SPCtx *) &rctx, flags);
// As last step set additional transform of drawing group
- for (SPItemView *v = symbol->display; v != NULL; v = v->next) {
+ for (SPItemView *v = this->display; v != NULL; v = v->next) {
Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(v->arenaitem);
- g->setChildTransform(symbol->c2p);
+ g->setChildTransform(this->c2p);
}
} else {
// No-op
- CGroup::update(ctx, flags);
+ SPGroup::update(ctx, flags);
}
}
-void CSymbol::modified(unsigned int flags) {
- CGroup::modified(flags);
+void SPSymbol::modified(unsigned int flags) {
+ SPGroup::modified(flags);
}
-Inkscape::XML::Node* CSymbol::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
- SPSymbol* object = this->spsymbol;
-
+Inkscape::XML::Node* SPSymbol::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
repr = xml_doc->createElement("svg:symbol");
}
//XML Tree being used directly here while it shouldn't be.
- repr->setAttribute("viewBox", object->getRepr()->attribute("viewBox"));
+ repr->setAttribute("viewBox", this->getRepr()->attribute("viewBox"));
//XML Tree being used directly here while it shouldn't be.
- repr->setAttribute("preserveAspectRatio", object->getRepr()->attribute("preserveAspectRatio"));
+ repr->setAttribute("preserveAspectRatio", this->getRepr()->attribute("preserveAspectRatio"));
- CGroup::write(xml_doc, repr, flags);
+ SPGroup::write(xml_doc, repr, flags);
return repr;
}
-Inkscape::DrawingItem* CSymbol::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) {
- SPSymbol* item = this->spsymbol;
-
- SPSymbol *symbol = SP_SYMBOL(item);
+Inkscape::DrawingItem* SPSymbol::show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) {
Inkscape::DrawingItem *ai = 0;
- if (symbol->cloned) {
+ if (this->cloned) {
// Cloned <symbol> is actually renderable
- ai = CGroup::show(drawing, key, flags);
+ ai = SPGroup::show(drawing, key, flags);
Inkscape::DrawingGroup *g = dynamic_cast<Inkscape::DrawingGroup *>(ai);
+
if (g) {
- g->setChildTransform(symbol->c2p);
+ g->setChildTransform(this->c2p);
}
}
return ai;
}
-void CSymbol::hide(unsigned int key) {
- SPSymbol* item = this->spsymbol;
-
- SPSymbol *symbol = SP_SYMBOL(item);
-
- if (symbol->cloned) {
+void SPSymbol::hide(unsigned int key) {
+ if (this->cloned) {
/* Cloned <symbol> is actually renderable */
- CGroup::hide(key);
+ SPGroup::hide(key);
}
}
-Geom::OptRect CSymbol::bbox(Geom::Affine const &transform, SPItem::BBoxType type) {
- SPSymbol* item = this->spsymbol;
-
- SPSymbol const *symbol = SP_SYMBOL(item);
+Geom::OptRect SPSymbol::bbox(Geom::Affine const &transform, SPItem::BBoxType type) {
Geom::OptRect bbox;
- if (symbol->cloned) {
+ if (this->cloned) {
// Cloned <symbol> is actually renderable
- Geom::Affine const a( symbol->c2p * transform );
- bbox = CGroup::bbox(a, type);
+ Geom::Affine const a( this->c2p * transform );
+ bbox = SPGroup::bbox(a, type);
}
+
return bbox;
}
-void CSymbol::print(SPPrintContext* ctx) {
- SPSymbol* item = this->spsymbol;
-
- SPSymbol *symbol = SP_SYMBOL(item);
- if (symbol->cloned) {
+void SPSymbol::print(SPPrintContext* ctx) {
+ if (this->cloned) {
// Cloned <symbol> is actually renderable
- sp_print_bind(ctx, symbol->c2p, 1.0);
+ sp_print_bind(ctx, this->c2p, 1.0);
- CGroup::print(ctx);
+ SPGroup::print(ctx);
sp_print_release (ctx);
}
diff --git a/src/sp-symbol.h b/src/sp-symbol.h
index a1fc0c3c0..e0e98c62e 100644
--- a/src/sp-symbol.h
+++ b/src/sp-symbol.h
@@ -19,9 +19,7 @@
#define SP_TYPE_SYMBOL (sp_symbol_get_type ())
#define SP_SYMBOL(obj) ((SPSymbol*)obj)
-#define SP_IS_SYMBOL(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPSymbol)))
-
-class CSymbol;
+#define SP_IS_SYMBOL(obj) (dynamic_cast<const SPSymbol*>((SPObject*)obj))
#include <2geom/affine.h>
#include "svg/svg-length.h"
@@ -31,7 +29,7 @@ class CSymbol;
class SPSymbol : public SPGroup {
public:
SPSymbol();
- CSymbol* csymbol;
+ virtual ~SPSymbol();
/* viewBox; */
unsigned int viewBox_set : 1;
@@ -44,17 +42,6 @@ public:
/* Child to parent additional transform */
Geom::Affine c2p;
-};
-
-struct SPSymbolClass {
- SPGroupClass parent_class;
-};
-
-
-class CSymbol : public CGroup {
-public:
- CSymbol(SPSymbol* symbol);
- virtual ~CSymbol();
virtual void build(SPDocument *document, Inkscape::XML::Node *repr);
virtual void release();
@@ -69,12 +56,6 @@ public:
virtual void print(SPPrintContext *ctx);
virtual Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType type);
virtual void hide (unsigned int key);
-
-protected:
- SPSymbol* spsymbol;
};
-
-GType sp_symbol_get_type (void);
-
#endif
diff --git a/src/ui/dialog/object-attributes.cpp b/src/ui/dialog/object-attributes.cpp
index 027c9ae56..9a7b91c57 100644
--- a/src/ui/dialog/object-attributes.cpp
+++ b/src/ui/dialog/object-attributes.cpp
@@ -124,16 +124,20 @@ void ObjectAttributes::widget_setup (void)
}
blocked = true;
+
+ // CPPIFY
SPObject *obj = SP_OBJECT(item); //to get the selected item
- GObjectClass *klass = G_OBJECT_GET_CLASS(obj); //to deduce the object's type
- GType type = G_TYPE_FROM_CLASS(klass);
+// GObjectClass *klass = G_OBJECT_GET_CLASS(obj); //to deduce the object's type
+// GType type = G_TYPE_FROM_CLASS(klass);
const SPAttrDesc *desc;
- if (type == SP_TYPE_ANCHOR)
+// if (type == SP_TYPE_ANCHOR)
+ if (SP_IS_ANCHOR(item))
{
desc = anchor_desc;
}
- else if (type == SP_TYPE_IMAGE)
+// else if (type == SP_TYPE_IMAGE)
+ else if (SP_IS_IMAGE(item))
{
Inkscape::XML::Node *ir = obj->getRepr();
const gchar *href = ir->attribute("xlink:href");