Code

Fixed signed/unsigned problem with precision calc. Fixes bug #399604.
[inkscape.git] / src / sp-object-group.cpp
1 #define __SP_OBJECTGROUP_C__
3 /*
4  * Abstract base class for non-item groups
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *
9  * Copyright (C) 1999-2003 Authors
10  * Copyright (C) 2001-2002 Ximian, Inc.
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #include "sp-object-group.h"
16 #include "xml/repr.h"
17 #include "document.h"
19 static void sp_objectgroup_class_init (SPObjectGroupClass *klass);
20 static void sp_objectgroup_init (SPObjectGroup *objectgroup);
22 static void sp_objectgroup_child_added (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * ref);
23 static void sp_objectgroup_remove_child (SPObject * object, Inkscape::XML::Node * child);
24 static void sp_objectgroup_order_changed (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * old_ref, Inkscape::XML::Node * new_ref);
25 static Inkscape::XML::Node *sp_objectgroup_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
27 static SPObjectClass *parent_class;
29 GType
30 sp_objectgroup_get_type (void)
31 {
32         static GType objectgroup_type = 0;
33         if (!objectgroup_type) {
34                 GTypeInfo objectgroup_info = {
35                         sizeof (SPObjectGroupClass),
36                         NULL,   /* base_init */
37                         NULL,   /* base_finalize */
38                         (GClassInitFunc) sp_objectgroup_class_init,
39                         NULL,   /* class_finalize */
40                         NULL,   /* class_data */
41                         sizeof (SPObjectGroup),
42                         16,     /* n_preallocs */
43                         (GInstanceInitFunc) sp_objectgroup_init,
44                         NULL,   /* value_table */
45                 };
46                 objectgroup_type = g_type_register_static (SP_TYPE_OBJECT, "SPObjectGroup", &objectgroup_info, (GTypeFlags)0);
47         }
48         return objectgroup_type;
49 }
51 static void
52 sp_objectgroup_class_init (SPObjectGroupClass *klass)
53 {
54         GObjectClass * object_class;
55         SPObjectClass * sp_object_class;
57         object_class = (GObjectClass *) klass;
58         sp_object_class = (SPObjectClass *) klass;
60         parent_class = (SPObjectClass *)g_type_class_ref (SP_TYPE_OBJECT);
62         sp_object_class->child_added = sp_objectgroup_child_added;
63         sp_object_class->remove_child = sp_objectgroup_remove_child;
64         sp_object_class->order_changed = sp_objectgroup_order_changed;
65         sp_object_class->write = sp_objectgroup_write;
66 }
68 static void
69 sp_objectgroup_init (SPObjectGroup */*objectgroup*/)
70 {
71 }
73 static void
74 sp_objectgroup_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
75 {
76         if (((SPObjectClass *) (parent_class))->child_added)
77                 (* ((SPObjectClass *) (parent_class))->child_added) (object, child, ref);
79         object->requestModified(SP_OBJECT_MODIFIED_FLAG);
80 }
82 static void
83 sp_objectgroup_remove_child (SPObject *object, Inkscape::XML::Node *child)
84 {
85         if (((SPObjectClass *) (parent_class))->remove_child)
86                 (* ((SPObjectClass *) (parent_class))->remove_child) (object, child);
88         object->requestModified(SP_OBJECT_MODIFIED_FLAG);
89 }
91 static void
92 sp_objectgroup_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref)
93 {
94         if (((SPObjectClass *) (parent_class))->order_changed)
95                 (* ((SPObjectClass *) (parent_class))->order_changed) (object, child, old_ref, new_ref);
97         object->requestModified(SP_OBJECT_MODIFIED_FLAG);
98 }
100 static Inkscape::XML::Node *
101 sp_objectgroup_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
103         SPObjectGroup *group;
104         SPObject *child;
105         Inkscape::XML::Node *crepr;
107         group = SP_OBJECTGROUP (object);
109         if (flags & SP_OBJECT_WRITE_BUILD) {
110                 GSList *l;
111                 if (!repr) {
112                         repr = xml_doc->createElement("svg:g");
113                 }
114                 l = NULL;
115                 for ( child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
116                         crepr = child->updateRepr(xml_doc, NULL, flags);
117                         if (crepr) l = g_slist_prepend (l, crepr);
118                 }
119                 while (l) {
120                         repr->addChild((Inkscape::XML::Node *) l->data, NULL);
121                         Inkscape::GC::release((Inkscape::XML::Node *) l->data);
122                         l = g_slist_remove (l, l->data);
123                 }
124         } else {
125                 for ( child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
126                         child->updateRepr(flags);
127                 }
128         }
130         if (((SPObjectClass *) (parent_class))->write)
131                 ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags);
133         return repr;