[dia] meta: show group's own meta info in property dialog



commit 8773b56148890babc49f1513ee276b01c3672410
Author: Hans Breuer <hans breuer org>
Date:   Sat Jul 20 20:09:27 2013 +0200

    meta: show group's own meta info in property dialog
    
    The meta info of groups is a bit special, it is mixed into
    the property dialog with 'by hand'. To really get/set the
    right meta info some flag needs to be set, too.

 lib/group.c       |   56 +++++++++++++++++++++++++++++++++++++++++++++++-----
 lib/propdialogs.c |    2 +-
 2 files changed, 51 insertions(+), 7 deletions(-)
---
diff --git a/lib/group.c b/lib/group.c
index 7bf9cf5..260dd04 100644
--- a/lib/group.c
+++ b/lib/group.c
@@ -618,6 +618,8 @@ group_prop_event_deliver(Group *group, Property *prop)
 }
 
 static PropDescription _group_props[] = {
+  { "meta", PROP_TYPE_DICT, PROP_FLAG_SELF_ONLY|PROP_FLAG_OPTIONAL,
+    "Object meta info", "Some key/value pairs"},
   { "matrix", PROP_TYPE_MATRIX, 
PROP_FLAG_SELF_ONLY|PROP_FLAG_DONT_MERGE|PROP_FLAG_VISIBLE|PROP_FLAG_OPTIONAL|PROP_FLAG_NO_DEFAULTS,
   N_("Transformation"), NULL, NULL },
 
@@ -639,19 +641,41 @@ group_describe_props(Group *group)
     group->pdesc = object_list_get_prop_descriptions(group->objects, PROP_UNION);
 
     if (group->pdesc != NULL) {
-      /* hijack event delivery */
+      /* Ensure we have no duplicates with own props */
+      int n_other = 0;
       for (i=0; group->pdesc[i].name != NULL; i++) {
+       int j;
+       gboolean is_own = FALSE;
+       for (j=0; j < G_N_ELEMENTS(_group_props); ++j) {
+         if (   group->pdesc[i].quark == _group_props[j].quark
+             && group->pdesc[i].type_quark == _group_props[j].type_quark)
+           is_own = TRUE;
+       }
+       if (!is_own) {
+         if (n_other != i)
+           memcpy ((gpointer)&group->pdesc[n_other], &group->pdesc[i], sizeof(PropDescription));
+         ++n_other;
+       }
+      }
+      /* Ensure NULL termination */
+      ((PropDescription *)&group->pdesc[n_other])->name = NULL;
+
+      /* hijack event delivery */
+      for (i=0; i < n_other; i++) {
+       /* Ensure we have no duplicates with our own properties */
         if (group->pdesc[i].event_handler) 
           prop_desc_insert_handler((PropDescription *)&group->pdesc[i],
                                    (PropEventHandler)group_prop_event_deliver);
       }
-      /* mix in our own single matrix property */
+      /* mix in our own properties */
       {
-        PropDescription *arr = g_new (PropDescription, i+2);
+       int n_own = G_N_ELEMENTS(_group_props) - 1;
+        PropDescription *arr = g_new (PropDescription, n_other+n_own+1);
        
-       arr[0] = _group_props[0];
-       memcpy (&arr[1], group->pdesc, (i+1) * sizeof(PropDescription));
-       for (i=1; arr[i].name != NULL; ++i) {
+       for (i = 0; i < n_own; ++i)
+         arr[i] = _group_props[i];
+       memcpy (&arr[n_own], group->pdesc, (n_other+1) * sizeof(PropDescription));
+       for (i=n_own; arr[i].name != NULL; ++i) {
          /* these are not meant to be saved/loaded with the group */
          arr[i].flags |= (PROP_FLAG_DONT_SAVE|PROP_FLAG_OPTIONAL);
        }
@@ -665,6 +689,7 @@ group_describe_props(Group *group)
 }
 
 static PropOffset _group_offsets[] = {
+  { "meta", PROP_TYPE_DICT, offsetof(DiaObject, meta) },
   { "matrix", PROP_TYPE_MATRIX, offsetof(Group, matrix) },
   { NULL }
 };
@@ -854,3 +879,22 @@ group_prop_change_free(GroupPropChange *change)
   }
   g_list_free(change->changes_per_object);
 }
+
+void
+group_transform (Group *group, const DiaMatrix *m)
+{
+  g_return_if_fail (m != NULL);
+
+  if (group->matrix) {
+    dia_matrix_multiply (group->matrix, group->matrix, m);
+  } else {
+    group->matrix = g_memdup (m, sizeof(*m));
+  }
+  /* don't keep the offset in the matrix*/
+  if (group->matrix->x0 != 0 || group->matrix->y0 != 0) {
+    Point delta = {group->matrix->x0, group->matrix->y0};
+    group->matrix->x0 = group->matrix->y0 = 0; /* offset used internally */
+    object_list_move_delta(group->objects, &delta);
+  }
+  group_update_data (group);
+}
diff --git a/lib/propdialogs.c b/lib/propdialogs.c
index ea8dcd8..cbd1890 100644
--- a/lib/propdialogs.c
+++ b/lib/propdialogs.c
@@ -323,7 +323,7 @@ _prop_list_extend_for_meta (GPtrArray *props)
     PROP_STD_NOTEBOOK_BEGIN,
     PROP_NOTEBOOK_PAGE("general_page",PROP_FLAG_DONT_MERGE,N_("General")),
     PROP_NOTEBOOK_PAGE("meta_page",0,N_("Meta")),
-    { "meta", PROP_TYPE_DICT, PROP_FLAG_VISIBLE, "", ""},
+    { "meta", PROP_TYPE_DICT, PROP_FLAG_VISIBLE|PROP_FLAG_SELF_ONLY, "", ""},
     PROP_STD_NOTEBOOK_END,
     {NULL}
   };


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