[dia] cleanup: remove DiaObject::flags, add remove DiaObjectType::flags



commit 501abb261535f4697f7382f0d8e72887c34b0b43
Author: Hans Breuer <hans breuer org>
Date:   Mon Sep 15 19:44:00 2014 +0200

    cleanup: remove DiaObject::flags, add remove DiaObjectType::flags
    
    The only object flag is a type property (parenting is object type specific).
    There is no way to change it after construction and there must not be. This
    reduces the size of DiaObject to 96 (32 bit OS) and just needs one
    indirection per object_flags_set() call.
    Also remove unused DIA_OBJECT_GRABS_CHILD_INPUT - another leftover from
    the unfinished "new group" stuff.
    
    tests>test-sizeof
    
    DiaObject: 96
    Connection: 224
    Element: 392
    UMLClass: 952
    Handle: 32
    ConnectionPoint: 32

 lib/layer.c                    |    7 +------
 lib/object.c                   |    8 +++-----
 lib/object.h                   |    8 ++------
 lib/plug-ins.h                 |    2 +-
 objects/AADL/aadlbox.c         |    2 --
 objects/AADL/aadlbus.c         |   13 ++++++++-----
 objects/AADL/aadldata.c        |   13 ++++++++-----
 objects/AADL/aadldevice.c      |   13 ++++++++-----
 objects/AADL/aadlmemory.c      |   11 +++++++----
 objects/AADL/aadlpackage.c     |   11 +++++++----
 objects/AADL/aadlprocess.c     |   13 ++++++++-----
 objects/AADL/aadlprocessor.c   |   11 +++++++----
 objects/AADL/aadlsubprogram.c  |   13 ++++++++-----
 objects/AADL/aadlsystem.c      |   13 ++++++++-----
 objects/AADL/aadlthread.c      |    5 ++++-
 objects/AADL/aadlthreadgroup.c |   13 ++++++++-----
 objects/UML/component.c        |   10 +++++++---
 objects/UML/large_package.c    |   15 +++++++++------
 objects/custom/custom_object.c |    4 +---
 objects/network/radiocell.c    |    9 +++++++--
 20 files changed, 112 insertions(+), 82 deletions(-)
---
diff --git a/lib/layer.c b/lib/layer.c
index 45bf867..e1a9636 100644
--- a/lib/layer.c
+++ b/lib/layer.c
@@ -477,10 +477,6 @@ layer_find_closest_object_except(Layer *layer, Point *pos,
   ;
   }
 
-  /* If the object is within a closed group, find the group. */
-  closest = dia_object_get_parent_with_flags(closest,
-                                            DIA_OBJECT_GRABS_CHILD_INPUT);
-
   return closest;
 }
 
@@ -528,8 +524,7 @@ layer_find_closest_connectionpoint(Layer *layer,
   for (l = layer->objects; l!=NULL; l = g_list_next(l) ) {
     obj = (DiaObject *) l->data;
 
-    if (obj == notthis) continue;
-    if (obj != dia_object_get_parent_with_flags(obj, DIA_OBJECT_GRABS_CHILD_INPUT))
+    if (obj == notthis)
       continue;
     for (i=0;i<obj->num_connections;i++) {
       cp = obj->connections[i];
diff --git a/lib/object.c b/lib/object.c
index a4e8d68..e9107f9 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -115,7 +115,6 @@ object_copy(DiaObject *from, DiaObject *to)
 
   to->ops = from->ops;
 
-  to->flags = from->flags;
   to->parent = from->parent;
   to->children = g_list_copy(from->children);
 }
@@ -882,7 +881,7 @@ dia_object_get_parent_with_flags(DiaObject *obj, guint flags)
   }
   while (obj->parent != NULL) {
     obj = obj->parent;
-    if ((obj->flags & flags) == flags) {
+    if ((obj->type->flags & flags) == flags) {
       top = obj;
     }
   }
@@ -903,8 +902,7 @@ dia_object_is_selectable(DiaObject *obj)
   if (obj->parent_layer == NULL) {
     return FALSE;
   }
-  return obj->parent_layer == obj->parent_layer->parent_diagram->active_layer
-    && obj == dia_object_get_parent_with_flags(obj, DIA_OBJECT_GRABS_CHILD_INPUT);
+  return obj->parent_layer == obj->parent_layer->parent_diagram->active_layer;
 }
 
 
@@ -988,7 +986,7 @@ object_get_type(char *name)
 gboolean
 object_flags_set(DiaObject *obj, gint flags)
 {
-  return (obj->flags & flags) == flags;
+  return (obj->type->flags & flags) == flags;
 }
 
 /** Load an object from XML based on its properties.
diff --git a/lib/object.h b/lib/object.h
index 1671ad9..84bad53 100644
--- a/lib/object.h
+++ b/lib/object.h
@@ -42,11 +42,7 @@ typedef enum {
    *  it, a.k.a. be a parent.  A parent moves its children along and 
    *  constricts its children to live inside its borders.
    */
-  DIA_OBJECT_CAN_PARENT = 1,
-  /** Set this if the DiaObject grabs all input destined for its children.
-   * This is typically used for group-like objects.
-   */
-  DIA_OBJECT_GRABS_CHILD_INPUT = 2
+  DIA_OBJECT_CAN_PARENT = 1
 } DiaObjectFlags;
 
 /** This enumeration gives a bitset of modifier keys currently held down.
@@ -538,7 +534,6 @@ struct _DiaObject {
                           dia_object_get_parent_layer() */
   DiaObject *parent; /*!< Back-pointer to DiaObject which is parenting this object. Can be NULL */
   GList *children; /*!< In case this object is a parent of other object the children are listed here */
-  gint flags; /*!< Various flags that can be set for this object, see defines above */
 
   /** The area that contains all parts rendered interactively, so includes
    *  handles, bezier controllers etc.  Despite historical difference, this
@@ -594,6 +589,7 @@ struct _DiaObjectType {
   void *default_user_data; /*!< use this if no user data is specified in the .sheet file */
   const PropDescription *prop_descs; /*!< property descriptions */
   const PropOffset *prop_offsets; /*!< DiaObject struct offsets */
+  gint flags; /*!< Various flags that can be set for this object, see defines above */
 };
 
 /* base property stuff ... */
diff --git a/lib/plug-ins.h b/lib/plug-ins.h
index 7e92a09..24d63cb 100644
--- a/lib/plug-ins.h
+++ b/lib/plug-ins.h
@@ -52,7 +52,7 @@ G_BEGIN_DECLS
  *
  * \ingroup Plugins
  */
-#define DIA_PLUGIN_API_VERSION 20
+#define DIA_PLUGIN_API_VERSION 21
 
 typedef enum {
   DIA_PLUGIN_INIT_OK,
diff --git a/objects/AADL/aadlbox.c b/objects/AADL/aadlbox.c
index 921eb7b..5fce7da 100755
--- a/objects/AADL/aadlbox.c
+++ b/objects/AADL/aadlbox.c
@@ -875,8 +875,6 @@ DiaObject *aadlbox_create(Point *startpoint, void *user_data,
   elem = &aadlbox->element;
   obj = &elem->object;
 
-  obj->flags |= DIA_OBJECT_CAN_PARENT;
-
   elem->corner = *startpoint;
 
   aadlbox->specific = (Aadlbox_specific *) user_data;
diff --git a/objects/AADL/aadlbus.c b/objects/AADL/aadlbus.c
index c1d8802..df0e670 100755
--- a/objects/AADL/aadlbus.c
+++ b/objects/AADL/aadlbus.c
@@ -185,12 +185,15 @@ extern ObjectTypeOps aadlbus_type_ops;
 
 DiaObjectType aadlbus_type =
 {
-  "AADL - Bus",          /* name */
-  0,                  /* version */
-  aadlbus_xpm,         /* pixmap */
-  &aadlbus_type_ops,      /* ops */
+  "AADL - Bus",           /* name */
+  0,                   /* version */
+  aadlbus_xpm,          /* pixmap */
+  &aadlbus_type_ops,       /* ops */
   NULL,
-  &aadlbus_specific /* user data */
+  &aadlbus_specific, /* user data */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 static ObjectOps aadlbus_ops =
diff --git a/objects/AADL/aadldata.c b/objects/AADL/aadldata.c
index d304efa..b074494 100755
--- a/objects/AADL/aadldata.c
+++ b/objects/AADL/aadldata.c
@@ -137,12 +137,15 @@ ObjectTypeOps aadldata_type_ops;
 
 DiaObjectType aadldata_type =
 {
-  "AADL - Data",          /* name */
-  0,                   /* version */
-  aadldata_xpm,         /* pixmap */
-  &aadldata_type_ops,      /* ops */
+  "AADL - Data",           /* name */
+  0,                    /* version */
+  aadldata_xpm,          /* pixmap */
+  &aadldata_type_ops,       /* ops */
   NULL,
-  &aadldata_specific /* user data */
+  &aadldata_specific, /* user data */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 
diff --git a/objects/AADL/aadldevice.c b/objects/AADL/aadldevice.c
index f36ed9f..a84cd9b 100755
--- a/objects/AADL/aadldevice.c
+++ b/objects/AADL/aadldevice.c
@@ -117,12 +117,15 @@ ObjectTypeOps aadldevice_type_ops;
 
 DiaObjectType aadldevice_type =
 {
-  "AADL - Device",          /* name */
-  0,                     /* version */
-  aadldevice_xpm,         /* pixmap */
-  &aadldevice_type_ops,      /* ops */
+  "AADL - Device",           /* name */
+  0,                      /* version */
+  aadldevice_xpm,          /* pixmap */
+  &aadldevice_type_ops,       /* ops */
   NULL,
-  &aadldevice_specific /* user data */
+  &aadldevice_specific, /* user data */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 
diff --git a/objects/AADL/aadlmemory.c b/objects/AADL/aadlmemory.c
index 26c4a96..c7cde60 100755
--- a/objects/AADL/aadlmemory.c
+++ b/objects/AADL/aadlmemory.c
@@ -106,12 +106,15 @@ ObjectTypeOps aadlmemory_type_ops;
 
 DiaObjectType aadlmemory_type =
 {
-  "AADL - Memory",          /* name */
-  0,                     /* version */
-  aadlmemory_xpm,         /* pixmap */
+  "AADL - Memory",           /* name */
+  0,                      /* version */
+  aadlmemory_xpm,          /* pixmap */
   &aadlmemory_type_ops,      /* ops */
   NULL,
-  &aadlmemory_specific /* user data */
+  &aadlmemory_specific, /* user data */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 
diff --git a/objects/AADL/aadlpackage.c b/objects/AADL/aadlpackage.c
index a0b1974..cbdda12 100755
--- a/objects/AADL/aadlpackage.c
+++ b/objects/AADL/aadlpackage.c
@@ -84,13 +84,16 @@ ObjectTypeOps aadlpackage_type_ops;
 
 DiaObjectType aadlpackage_type =
 {
-  "AADL - Package",          /* name */
-  0,                      /* version */
-  aadlpackage_xpm,         /* pixmap */
+  "AADL - Package",           /* name */
+  0,                       /* version */
+  aadlpackage_xpm,          /* pixmap */
 
   &aadlpackage_type_ops,      /* ops */
   NULL,
-  &aadlpackage_specific /* user data */
+  &aadlpackage_specific, /* user data */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 
diff --git a/objects/AADL/aadlprocess.c b/objects/AADL/aadlprocess.c
index 65f2a67..9cced77 100755
--- a/objects/AADL/aadlprocess.c
+++ b/objects/AADL/aadlprocess.c
@@ -124,12 +124,15 @@ ObjectTypeOps aadlprocess_type_ops;
 
 DiaObjectType aadlprocess_type =
 {
-  "AADL - Process",          /* name */
-  0,                      /* version */
-  aadlprocess_xpm,         /* pixmap */
-  &aadlprocess_type_ops,      /* ops */
+  "AADL - Process",           /* name */
+  0,                       /* version */
+  aadlprocess_xpm,          /* pixmap */
+  &aadlprocess_type_ops,       /* ops */
   NULL,
-  &aadlprocess_specific /* user data */
+  &aadlprocess_specific, /* user data */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 
diff --git a/objects/AADL/aadlprocessor.c b/objects/AADL/aadlprocessor.c
index 9e56cab..231e79c 100755
--- a/objects/AADL/aadlprocessor.c
+++ b/objects/AADL/aadlprocessor.c
@@ -93,12 +93,15 @@ ObjectTypeOps aadlprocessor_type_ops;
 
 DiaObjectType aadlprocessor_type =
 {
-  "AADL - Processor",          /* name */
-  0,                        /* version */
-  aadlprocessor_xpm,         /* pixmap */
+  "AADL - Processor",           /* name */
+  0,                         /* version */
+  aadlprocessor_xpm,          /* pixmap */
   &aadlprocessor_type_ops,      /* ops */
   NULL,
-  &aadlprocessor_specific /* user data */
+  &aadlprocessor_specific, /* user data */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 
diff --git a/objects/AADL/aadlsubprogram.c b/objects/AADL/aadlsubprogram.c
index 80e4190..d2615fa 100755
--- a/objects/AADL/aadlsubprogram.c
+++ b/objects/AADL/aadlsubprogram.c
@@ -107,12 +107,15 @@ ObjectTypeOps aadlsubprogram_type_ops;
 
 DiaObjectType aadlsubprogram_type =
 {
-  "AADL - Subprogram",          /* name */
-  0,                         /* version */
-  aadlsubprogram_xpm,         /* pixmap */
-  &aadlsubprogram_type_ops,      /* ops */
+  "AADL - Subprogram",           /* name */
+  0,                          /* version */
+  aadlsubprogram_xpm,          /* pixmap */
+  &aadlsubprogram_type_ops,       /* ops */
   NULL,
-  &aadlsubprogram_specific /* user data */
+  &aadlsubprogram_specific, /* user data */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 
diff --git a/objects/AADL/aadlsystem.c b/objects/AADL/aadlsystem.c
index a7e8db0..2b34a92 100755
--- a/objects/AADL/aadlsystem.c
+++ b/objects/AADL/aadlsystem.c
@@ -116,13 +116,16 @@ ObjectTypeOps aadlsystem_type_ops;
 
 DiaObjectType aadlsystem_type =
 {
-  "AADL - System",          /* name */
-  0,                     /* version */
-  aadlsystem_xpm,         /* pixmap */
+  "AADL - System",           /* name */
+  0,                      /* version */
+  aadlsystem_xpm,          /* pixmap */
 
-  &aadlsystem_type_ops,      /* ops */
+  &aadlsystem_type_ops,       /* ops */
   NULL,
-  &aadlsystem_specific /* user data */
+  &aadlsystem_specific, /* user data */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 
diff --git a/objects/AADL/aadlthread.c b/objects/AADL/aadlthread.c
index ff7d411..3a60686 100755
--- a/objects/AADL/aadlthread.c
+++ b/objects/AADL/aadlthread.c
@@ -56,7 +56,10 @@ DiaObjectType aadlthread_type =
 
   &aadlthread_type_ops,      /* ops */
   NULL,
-  &aadlthread_specific /* user data */
+  &aadlthread_specific, /* user data */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 
diff --git a/objects/AADL/aadlthreadgroup.c b/objects/AADL/aadlthreadgroup.c
index 72ba861..a2b7ef2 100755
--- a/objects/AADL/aadlthreadgroup.c
+++ b/objects/AADL/aadlthreadgroup.c
@@ -54,12 +54,15 @@ ObjectTypeOps aadlthreadgroup_type_ops;
 
 DiaObjectType aadlthreadgroup_type =
 {
-  "AADL - Thread Group",         /* name */
-  0,                          /* version */
-  aadlthreadgroup_xpm,         /* pixmap */
-  &aadlthreadgroup_type_ops,      /* ops */
+  "AADL - Thread Group",          /* name */
+  0,                           /* version */
+  aadlthreadgroup_xpm,          /* pixmap */
+  &aadlthreadgroup_type_ops,       /* ops */
   NULL,
-  &aadlthreadgroup_specific /* user data */
+  &aadlthreadgroup_specific, /* user data */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 
diff --git a/objects/UML/component.c b/objects/UML/component.c
index 6562c38..fe5b943 100644
--- a/objects/UML/component.c
+++ b/objects/UML/component.c
@@ -94,7 +94,13 @@ DiaObjectType component_type =
   "UML - Component", /* name */
   0,              /* version */
   component_xpm,   /* pixmap */
-  &component_type_ops /* ops */
+  &component_type_ops, /* ops */
+
+  NULL, /* pixmap_file: fallback if pixmap is NULL */
+  NULL, /* default_user_data: use this if no user data is specified in the .sheet file */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 static ObjectOps component_ops = {
@@ -391,8 +397,6 @@ component_create(Point *startpoint,
 
   obj->ops = &component_ops;
 
-  obj->flags |= DIA_OBJECT_CAN_PARENT;
-
   elem->corner = *startpoint;
   cmp->line_color = attributes_get_foreground();
   cmp->fill_color = attributes_get_background();
diff --git a/objects/UML/large_package.c b/objects/UML/large_package.c
index b6e5b72..c7206b0 100644
--- a/objects/UML/large_package.c
+++ b/objects/UML/large_package.c
@@ -101,10 +101,15 @@ static ObjectTypeOps largepackage_type_ops =
 
 DiaObjectType largepackage_type =
 {
-  "UML - LargePackage", /* name */
-  0,                 /* version */
-  largepackage_xpm,   /* pixmap */
-  &largepackage_type_ops /* ops */
+  "UML - LargePackage",  /* name */
+  0,                  /* version */
+  largepackage_xpm,    /* pixmap */
+  &largepackage_type_ops, /* ops */
+  NULL, /* pixmap_file: fallback if pixmap is NULL */
+  NULL, /* default_user_data: use this if no user data is specified in the .sheet file */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 static ObjectOps largepackage_ops = {
@@ -351,8 +356,6 @@ largepackage_create(Point *startpoint,
 
   obj->ops = &largepackage_ops;
 
-  obj->flags |= DIA_OBJECT_CAN_PARENT;
-
   elem->corner = *startpoint;
 
   element_init(elem, 8, NUM_CONNECTIONS);
diff --git a/objects/custom/custom_object.c b/objects/custom/custom_object.c
index 934903e..1cb5057 100644
--- a/objects/custom/custom_object.c
+++ b/objects/custom/custom_object.c
@@ -1545,8 +1545,6 @@ custom_create(Point *startpoint,
 
   custom->info = info;
 
-  obj->flags |= info->object_flags;
-
   custom->old_subscale = 1.0;
   custom->subscale = 1.0;
   custom->current_subshape = NULL;
@@ -1648,7 +1646,6 @@ custom_copy(Custom *custom)
 
   element_copy(elem, newelem);
   newcustom->info = custom->info;
-  newobj->flags = custom->element.object.flags;
 
   newcustom->padding = custom->padding;
   newcustom->current_subshape = NULL; /* it's temporary state, don't copy from wrong object */
@@ -1798,6 +1795,7 @@ custom_object_new(ShapeInfo *info, DiaObjectType **otype)
   *obj = custom_type;
 
   obj->name = info->name;
+  obj->flags |= info->object_flags;
   obj->default_user_data = info;
 
   if (info->icon) {
diff --git a/objects/network/radiocell.c b/objects/network/radiocell.c
index 1aaad21..3933503 100644
--- a/objects/network/radiocell.c
+++ b/objects/network/radiocell.c
@@ -93,7 +93,13 @@ DiaObjectType radiocell_type =
   0,                           /* version */
   (const char **) radiocell_xpm, /* pixmap */
 
-  &radiocell_type_ops          /* ops */
+  &radiocell_type_ops,         /* ops */
+
+  NULL, /* pixmap_file: fallback if pixmap is NULL */
+  NULL, /* default_user_data: use this if no user data is specified in the .sheet file */
+  NULL, /* prop_descs: property descriptions */
+  NULL, /* prop_offsets: DiaObject struct offsets */
+  DIA_OBJECT_CAN_PARENT /* flags */
 };
 
 static ObjectOps radiocell_ops = {
@@ -319,7 +325,6 @@ radiocell_create(Point *startpoint,
   obj = &poly->object;
   obj->type = &radiocell_type;
   obj->ops = &radiocell_ops;
-  obj->flags |= DIA_OBJECT_CAN_PARENT;
 
   radiocell->radius = 4.;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]