ProgrammedObject

Webs: Faemalia -:- Greatprawn -:- Playground -:- Technical -:- Tweak
Technical Web Sections: Register -:- Users -:- Changes -:- Index -:- Search -:- Statistics

This is a run-down on the AHOOC (Ad-Hoc Object-Oriented C) style of programming that Dia uses.

The parent object is almost always the first part of a structure. Thus, if we want to 'inherit' from the Element class (used for node-like objects with a roughly rectangular shape), we would define our structure like this:

typedef struct _MyObject {
  Element element;
...
} MyObject;

This allows any MyObject to be cast to Element, and since Element inherits from Object, a MyObject can also be cast to Object.

The Object will probably soon become a subclass of GObject, which will allow the use of a number of GLib functions.

You will also need to define a class object for your new object. It defines some operations that are 'external' to the object instance, such as creating and loading, as well as functions handling the defaults dialogs.

The defaults dialogs functions are usually set to NULL, meaning the dialogs are created based on the properties. This is highly, highly recommended, as it is not only easier, but also less errorprone and works better with group settings. If you think you have a good reason to not use the properties-based dialogs, please mail the Dia mailing list. Most likely we can improve the properties system to accomodate your needs, or show you a different way to do it that works better.

static ObjectTypeOps myobject_type_ops =
{
  (CreateFunc) myobject_create,
  (LoadFunc)   myobject_load,
  (SaveFunc)   myobject_save,
  (GetDefaultsFunc)   NULL,
  (ApplyDefaultsFunc) NULL
};

The type structure contains the name of this object (which is useful mostly when importers want to create one of these), a version number (used for backwards incompatible changes, which rarely happen), a pixmap for the icon, and the vtable.

ObjectType myobject_type =
{
  "MySheet - MyObject",   /* name */
  0,                      /* version */
  (char **) myobject_xpm, /* pixmap */

  &myobject_type_ops      /* ops */
};

An pointer to this type instance must be passed to object_register_type for the object to be loaded into dia. This usually happens in the PluginInit? function.

Next, we must define the vtable structure for the object (the ObjectOps), as well as the StdProps. Now we have all the structure set up, and just need to define the functions mentioned in the vtables.

-- LarsClausen - 05 Sep 2002


Edit -:- Attach -:- Ref-By -:- Printable -:- More