Widget Adaptor Definitions

Widget Classes — Adding support for custom widgets

Forward

Widget support in Glade is provided by the #GladeWidgetAdaptor object, each `glade-widget-class' definition in the catalog will result in the creation of an adaptor, which inherits the functionality of the adaptor created for its parent, or the closest adaptor available in the ancestry. Adaptor methods can be overridden by functions in the plugin by specifying them in the catalog. There is also a wealth of options you can use in the `glade-widget-class' without writing code.

A typical basic example of a widget class definition is as follows:

<glade-widget-class name="FooFrobnicator" generic-name="frobnicator" title="Frobnicator"/>

Here is the complete example of the form of the `glade-widget-class' definition:

<glade-widget-class name="FooFrobnicator" generic-name="frobnicator" title="Frobnicator"/>
  <post-create-function>foo_frobnicator_plugin_post_create</post-create-function>

  ... widget class support functions go here

  <properties>
    <property id="frobnicated" default="False"/>

    ... property definitions go here
  </properties>

  <signals>
    <signal id="frobnicate" since="1.0"/>

    ... signal definitions go here
  </signals>

  <packing-properties>
    ... child packing property definitions go here
  </packing-properties>

  <actions>
    <action id="launch_editor" name="Edit Frob" stock="gtk-edit"/>

    ... context menu action definitions go here
  </actions>

  <packing-actions>
    ... context menu action definitions for child objects go here
  </packing-actions>

  <packing-defaults>
    <parent-class name="GtkVBox">
      <child-property id="expand" default="false"/>
    </parent-class>

    ... packing default definitions go here
  </packing-defaults>
</glade-widget-class>

Widget Class Properties

The following are all properties of the `glade-widget-class' tag

name

The class name of the widget; unless the 'get-type-function' property is present, this will essentially be used to instantiate the actual class by deriving 'gtk_label_get_type' from 'GtkLabel' and searching for 'gtk_label_get_type' in the support library.

since

A 'major.minor' formed version describing the version of the owning catalog in which this object class was introduced; example: since="1.0".

deprecated

A boolean property depicting that this widget is currently deprecated.

builder-unsupported

A boolean property depicting that this widget is not supported by #GtkBuilder.

get-type-function

Used to explicitly specify the name of the function used to get the type of the widget. It is optional, but if it is not present, the 'name' property will be used to guess the name of the function, a process that could lead to unexpected results.

generic-name

Used to generate a default name for instances of the widget in the UI editor. It is also used in conjunction with the 'icon-prefix' to form an icon name for the widget.

icon-name

Used to explicitly set an icon name for this widget. These icon names are looked up in the current icon theme to retrieve an icon for the widget.

title

Used to display the name of the class in the palette and widget tree and will be translated before use in the interface.

parent

Use this to specify the name of the parent your widget derives from, you can use this option instead of loading a real widget type (this allows you to fake derive and still add properties and run your catalog independently of any plugins or libraries).

toplevel

Used to know whether this widget class is toplevel or not in Glade context. This property will be inherited from the adaptors parent.

fixed

Used to mark a #GladeWidgetAdaptor for free form placement capacities to be handled with a #GladeFixed. This property will be inherited from the adaptors parent.

use-placeholders

Used to inform the core about adaptors that implement #GtkContainer editing, and whether or not they use #GladePlaceholder. This property will be inherited from the adaptors parent.

default-width

The default width to load a #GtkWindow derived widget in the #GladeDesignView. This property will be inherited from the adaptors parent.

default-height

The default height to load a #GtkWindow derived widget in the #GladeDesignView. This property will be inherited from the adaptors parent.

Adapter Methods

The following are all child tags of the `glade-widget-class' tag

constructor-function

Used to override the actual #GObject constructor of the said #GladeWidgetAdaptor

post-create-function

A #GladePostCreateFunc support function that gets called whenever a widget of the said class is instantiated.

deep-post-create-function

Same as `post-create-function' except in that you must always chain up to the super class definition as a rule.

get-property-function

A #GladeGetPropertyFunc to get values of properties on an instance in the runtime.

set-property-function

A #GladeSetPropertyFunc to set values of properties on an instance in the runtime.

verify-function

A #GladeVerifyPropertyFunc to set values of properties on an instance in the runtime.

add-child-function

A #GladeAddChildFunc to add children to instances in the runtime.

remove-child-function

A #GladeRemoveChildFunc to remove children from instances in the runtime.

replace-child-function

A #GladeReplaceChildFunc to replace children inside instances in the runtime.

get-children-function

A #GladeGetChildrenFunc to get a list of children inside instances in the runtime.

child-get-property-function

A #GladeChildGetPropertyFunc to get packing properties from instances in the runtime.

child-set-property-function

A #GladeChildSetPropertyFunc to set packing properties on instances in the runtime.

child-verify-function

A #GladeChildVerifyPropertyFunc to verify packing properties on instances in the runtime.

get-internal-child-function

A #GladeGetInternalFunc to retrieve an internal child of a composite object in the runtime.

action-activate-function

A #GladeActionActivateFunc to run a routine for a plugin defined #GladeWidgetAction.

child-action-activate-function

A #GladeChildActionActivateFunc to run a routine for a plugin defined packing #GladeWidgetAction.

read-widget-function

A #GladeReadWidgetFunc to load a widget from the xml.

write-widget-function

A #GladeWriteWidgetFunc to write a widget from the xml.

read-child-function

A #GladeReadWidgetFunc to read a child to the xml.

write-child-function

A #GladeWriteWidgetFunc to write a child to the xml.

create-editor-property-function

A #GladeCreateEPropFunc to create widgets to be used in Glade's property editor.

string-from-value-function

A #GladeStringFromValueFunc to create a string from a #GValue, these strings must be unique and comparable for undo/redo to work properly.

Action Definitions

Actions are added under the `actions' and `packing-actions' tags, actions can also be nested so as to allow grouping in context menus, example:

...

<action id="manage_frobs" name="Manage Frobs">
  <action id="add_frob" name="Add" stock="gtk-add"/>
  <action id="remove_frob" name="Remove" stock="gtk-remove"/>
</action>

...

Here are the meanings of the `action' tag's properties:

id

The string identifier for this action, the action_path argument to your #GladeActionActivateFunc will be a combination if this id and any parents, for the above example: "manage_frobs/add_frob".

name

A string to be displayed in the UI for this action.

stock

An optional Gtk stock icon to represent this action.

important

A boolean option to add emphasis to this action; currently actions marked as `important' are added to the toolbar.

Packing Defaults

Default values can be specified for packing properties on your widget when added to a said type of parent, as the example shows above; use the `parent-class' to specify what parent (or derivative of that parent) you are targeting and fill in any `child-property' tags you need for that parent using `id' property to specify the property name and the `default' property for the value.

Signals

The signal elements are currently only needed for versioning support, use the `signal' child tag as described above and set signal `id' to be supported since version `since'. Signals are initialized to be supported since the introducing #GladeWidgetAdaptor was supported.

Icons

The Glade palette and other components use icons to represent the various widget classes. It is a good idea to provide icons for your widget classes, as this enhances the user interface.

Glade uses the GTK+ GtkIconTheme facility to provide icons for widget classes. Any icon available in the current icon theme can be used as an icon for a widget class.

By default, an icon name of the format "widget-CATALOG_NAME-GENERIC_NAME" is assigned to every widget class. CATALOG_NAME is the value of catalog name attribute, and GENERIC_NAME is the value of an widget class's generic name attribute.

To explicitly set an icon name for a widget class, the "icon-name" attribute of the "glade-widget-class" element can be specified. This will override the default icon name assigned to the widget class.

Icon files can be installed under any system icon theme folder.