UML class fix bigtime.
[dia.git] / lib / propoffsets.c
blob9fcaf2961b3dffae14df6844dc6f9bfcf355af03
1 /* Dia -- a diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * Property system for dia objects/shapes.
5 * Copyright (C) 2000 James Henstridge
6 * Copyright (C) 2001 Cyrille Chepelov
7 * Major restructuration done in August 2001 by C. Chepelov
9 * Propoffsets.c: routines which deal with (almost) actually setting/putting
10 * data in an object's members, and offset lists.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <glib.h>
28 #include "properties.h"
29 #include "propinternals.h"
31 void
32 do_set_props_from_offsets(void *base,
33 GPtrArray *props, const PropOffset *offsets)
35 /* Warning: the name quarks *must* all be valid */
36 guint i;
38 for (i = 0; i < props->len; i++) {
39 Property *prop = g_ptr_array_index(props,i);
40 const PropOffset *ofs;
41 for (ofs = offsets; ofs->name ; ofs++) {
42 if ((prop->name_quark == ofs->name_quark) &&
43 (prop->type_quark == ofs->type_quark)) {
44 /* beware of props not set, see PROP_FLAG_OPTIONAL */
45 if ((prop->experience & PXP_NOTSET) == 0)
46 prop->ops->set_from_offset(prop,base,ofs->offset,ofs->offset2);
47 break;
53 void
54 do_get_props_from_offsets(void *base,
55 GPtrArray *props, const PropOffset *offsets)
57 /* Warning: the name quarks *must* all be valid */
58 /* This is identical to do_set_props_from_offsets(). This sucks. */
59 guint i;
61 for (i = 0; i < props->len; i++) {
62 Property *prop = g_ptr_array_index(props,i);
63 const PropOffset *ofs;
64 for (ofs = offsets; ofs->name ; ofs++) {
65 if ((prop->name_quark == ofs->name_quark) &&
66 (prop->type_quark == ofs->type_quark)) {
67 prop->ops->get_from_offset(prop,base,ofs->offset,ofs->offset2);
68 break;
74 /* *************************************** */
76 void
77 prop_offset_list_calculate_quarks(PropOffset *olist)
79 guint i;
81 for (i = 0; olist[i].name != NULL; i++) {
82 if (olist[i].name_quark == 0)
83 olist[i].name_quark = g_quark_from_static_string(olist[i].name);
84 if (olist[i].type_quark == 0)
85 olist[i].type_quark = g_quark_from_static_string(olist[i].type);
86 if (!olist[i].ops)
87 olist[i].ops = prop_type_get_ops(olist[i].type);