I need informations about the PropDescription flags



Hi everybody !

My current work is to program objects for Dia.

Many of my objects properties are not saved in the dia defaults file as I would like. Thus, when I modify the object and restart the program, it always makes memory errors because of not allocated variables and so NULL pointer. I do not want to check every where if my structures are different from what they should be !

I think I can change the status of some properties to avoid this problem, and I am sure I have to change the PropDescription.

For the ones who does not understand very well what I speak about, the properties of a programmed object must be declared to Dia like that :
(this extract comes from the Standard - Box object, which the source code can be red at : http://cvs.gnome.org/viewcvs/dia/objects/standard/box.c?rev=1.48&view=markup)

static PropDescription box_props[] = {
  ELEMENT_COMMON_PROPERTIES,
  PROP_STD_LINE_WIDTH,
  PROP_STD_LINE_COLOUR,
  PROP_STD_FILL_COLOUR,
  PROP_STD_SHOW_BACKGROUND,
  PROP_STD_LINE_STYLE,
  { "corner_radius", PROP_TYPE_LENGTH, PROP_FLAG_VISIBLE, N_("Corner radius"), NULL, &corner_radius_data },
  { "aspect", PROP_TYPE_ENUM, PROP_FLAG_VISIBLE, N_("Aspect ratio"), NULL, prop_aspect_data },
  PROP_DESC_END
};

(...)

static PropOffset box_offsets[] = {
  ELEMENT_COMMON_PROPERTIES_OFFSETS,
  { "line_width", PROP_TYPE_REAL, offsetof(Box, border_width) },
  { "line_colour", PROP_TYPE_COLOUR, offsetof(Box, border_color) },
  { "fill_colour", PROP_TYPE_COLOUR, offsetof(Box, inner_color) },
  { "show_background", PROP_TYPE_BOOL, offsetof(Box, show_background) },
  { "aspect", PROP_TYPE_ENUM, offsetof(Box, aspect) },
  { "line_style", PROP_TYPE_LINESTYLE, offsetof(Box, line_style), offsetof(Box, dashlength) },
  { "corner_radius", PROP_TYPE_LENGTH, offsetof(Box, corner_radius) },
  { NULL, 0, 0 }
};


Two structures are used there : PropDescription and PropOffset. Here is the definition of the PropDescription structure :

struct _PropDescription {
  const gchar *name;
  PropertyType type;
  guint flags;
  const gchar *description;
  const gchar *tooltip;

  /* Holds some extra data whose meaning is dependent on the property type.
   * For example, int or float may use bounds for a spin button, and enums
   * may use a list of string names for enumeration values. */
  gpointer extra_data;

  /* if the property widget can send events when it's somehow interacted with,
     control will be passed to object_type-supplied event_handler, and
     event->dialog->obj_copy will be current with the dialog's values.
     When control comes back, event->dialog->obj_copy's properties will be
     brought back into the dialog. */
  PropEventHandler event_handler;

  GQuark quark; /* quark for property name -- helps speed up lookups. */
  GQuark type_quark;

  /* only used by dynamically constructed property descriptors (eg. groups) */
  PropEventHandlerChain chain_handler;

  const PropertyOps *ops;      
};


The way properties are saved and loaded from Dia Defaults file depends on the PropDescription.flags, which can be :

#define PROP_FLAG_VISIBLE   0x0001
#define PROP_FLAG_DONT_SAVE 0x0002
#define PROP_FLAG_DONT_MERGE 0x0004 /* in case group properties are edited */
#define PROP_FLAG_NO_DEFAULTS 0x0008 /* don't edit this in defaults dlg. */
#define PROP_FLAG_LOAD_ONLY 0x0010 /* for loading old formats */
#define PROP_FLAG_STANDARD 0x0020 /* One of the default toolbox props */
#define PROP_FLAG_MULTIVALUE 0x0040 /* Multiple values for prop in group */
#define PROP_FLAG_WIDGET_ONLY 0x0080 /* only cosmetic property, no data */
#define PROP_FLAG_OPTIONAL 0x0100 /* don't complain if it does not exist */


Could you explain me with more details how which flag change the way my properties are saved and loaded from the default dia file ?

For example, I do not really understand the differences between PROP_FLAG_DONT_SAVE and PROP_FLAG_LOAD_ONLY, between PROP_FLAG_DONT_MERGE and PROP_FLAG_MULTIVALUE ...

I think it is certainly very logic to the ones who created Dia, but for me all the flags are not very meanfull and this despite the little comments. Could you even give an example for each one ? And to help could you tell me which flags I should use to always give to my properties the values I defined in the _create function ?

Thank you !


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