1<refentry id="widgetclasses" revision="8 Feb 2006">
2  <refmeta>
3    <refentrytitle>Widget Adaptor Definitions</refentrytitle>
4    <refmiscinfo>Glade UI</refmiscinfo>
5  </refmeta>
6  <refnamediv>
7    <refname>Widget Classes</refname>
8    <refpurpose>
9Adding support for custom widgets
10    </refpurpose>
11  </refnamediv>
12
13  <refsect1>
14    <title>Forward</title>
15
16    <para>
17Widget support in Glade is provided by the #GladeWidgetAdaptor object, each
18`glade-widget-class' definition in the catalog will result in the creation
19of an adaptor, which inherits the funcionality of the adaptor created for its
20parent, or the closest adaptor available in the ancestry. Adaptor methods can
21be overridden by functions in the plugin by specifying them in the catalog.
22There is also a wealth of options you can use in the `glade-widget-class' without
23writing code.
24    </para>
25    <para>
26A typical basic example of a widget class definition is as follows:
27      <programlisting>
28<![CDATA[<glade-widget-class name="FooFrobnicator" generic-name="frobnicator" title="Frobnicator"/>]]></programlisting>
29    </para>
30    <para>
31Here is the complete example of the form of the `glade-widget-class' definition:
32      <programlisting>
33<![CDATA[<glade-widget-class name="FooFrobnicator" generic-name="frobnicator" title="Frobnicator"/>
34  <post-create-function>foo_frobnicator_plugin_post_create</post-create-function>
35
36  ... widget class support functions go here
37
38  <properties>
39    <property id="frobnicated" default="False"/>
40
41    ... property definitions go here
42  </properties>
43
44  <signals>
45    <signal id="frobnicate" since="1.0"/>
46
47    ... signal definitions go here
48  </signals>
49
50  <packing-properties>
51    ... child packing property definitions go here
52  </packing-properties>
53
54  <actions>
55    <action id="launch_editor" name="Edit Frob" stock="gtk-edit"/>
56
57    ... context menu action definitions go here
58  </actions>
59
60  <packing-actions>
61    ... context menu action definitions for child objects go here
62  </packing-actions>
63
64  <packing-defaults>
65    <parent-class name="GtkVBox">
66      <child-property id="expand" default="false"/>
67    </parent-class>
68
69    ... packing default definitions go here
70  </packing-defaults>
71</glade-widget-class>]]></programlisting>
72    </para>
73
74  </refsect1>
75
76  <refsect1>
77    <title>Widget Class Properties</title>
78    <para>
79The following are all properies of the `glade-widget-class' tag
80    </para>
81    <variablelist>
82      <varlistentry>
83        <term>name</term>
84        <listitem>
85          <para>
86The class name of the widget; unless the 'get-type-function' property is present,
87this will essentially be used to instantiate the actual class by deriving
88'gtk_label_get_type' from 'GtkLabel' and searching for 'gtk_label_get_type' in the
89support library.
90          </para>
91        </listitem>
92      </varlistentry>
93
94     <varlistentry>
95        <term>since</term>
96        <listitem>
97          <para>
98A 'major.minor' formed version describing the version of the owning catalog in which this
99object class was introduced; example: <literal>since="1.0"</literal>.
100          </para>
101        </listitem>
102      </varlistentry>
103
104      <varlistentry>
105        <term>deprecated</term>
106        <listitem>
107          <para>
108A boolean property depicting that this widget is currently deprecated.
109          </para>
110        </listitem>
111      </varlistentry>
112
113      <varlistentry>
114        <term>builder-unsupported</term>
115        <listitem>
116          <para>
117A boolean property depicting that this widget is not supported by #GtkBuilder.
118          </para>
119        </listitem>
120      </varlistentry>
121
122      <varlistentry>
123        <term>get-type-function</term>
124        <listitem>
125          <para>
126Used to explicitly specify the name of the function used to get the type of the widget.
127It is optional, but if it is not present, the 'name' property will be used to guess the
128name of the function, a process that could lead to unexpected results.
129          </para>
130        </listitem>
131      </varlistentry>
132
133      <varlistentry>
134        <term>generic-name</term>
135        <listitem>
136          <para>
137Used to generate a default name for instances of the
138widget in the UI editor. It is also used in conjunction with the 'icon-prefix'
139to form an icon name for the widget.
140          </para>
141        </listitem>
142      </varlistentry>
143
144      <varlistentry>
145        <term>icon-name</term>
146        <listitem>
147          <para>
148Used to explicitly set an icon name for this widget.
149These icon names are looked up in the current icon theme to retrieve an icon for
150the widget.
151          </para>
152        </listitem>
153      </varlistentry>
154
155      <varlistentry>
156        <term>title</term>
157        <listitem>
158          <para>
159Used to display the name of the class in the palette and widget
160tree and will be translated before use in the interface.
161          </para>
162        </listitem>
163      </varlistentry>
164
165      <varlistentry>
166        <term>parent</term>
167        <listitem>
168          <para>
169Use this to specify the name of the parent your widget derives from, you
170can use this option instead of loading a real widget type (this allows you
171to fake derive and still add properties and run your catalog independantly
172of any plugins or libraries).
173          </para>
174        </listitem>
175      </varlistentry>
176
177      <varlistentry>
178        <term>toplevel</term>
179        <listitem>
180          <para>
181Used to know whether this widget class is toplevel or not
182in Glade context. This property will be inherited from the adaptors parent.
183          </para>
184        </listitem>
185      </varlistentry>
186
187      <varlistentry>
188        <term>fixed</term>
189        <listitem>
190          <para>
191Used to mark a #GladeWidgetClass for free form placement capacities
192to be handled with a #GladeFixed. This property will be inherited from the adaptors parent.
193          </para>
194        </listitem>
195      </varlistentry>
196
197      <varlistentry>
198        <term>use-placeholders</term>
199        <listitem>
200          <para>
201Used to inform the core about adaptors that implement
202#GtkContainer editing, and whether or not they use #GladePlaceholder. This property will
203be inherited from the adaptors parent.
204          </para>
205        </listitem>
206      </varlistentry>
207
208      <varlistentry>
209        <term>default-width</term>
210        <listitem>
211          <para>
212The default width to load a #GtkWindow derived widget in the #GladeDesignView.
213This property will be inherited from the adaptors parent.
214          </para>
215        </listitem>
216      </varlistentry>
217
218      <varlistentry>
219        <term>default-height</term>
220        <listitem>
221          <para>
222The default height to load a #GtkWindow derived widget in the #GladeDesignView.
223This property will be inherited from the adaptors parent.
224          </para>
225        </listitem>
226      </varlistentry>
227
228    </variablelist>
229  </refsect1>
230
231  <refsect1>
232    <title>Adapter Methods</title>
233    <para>
234The following are all child tags of the `glade-widget-class' tag
235    </para>
236    <variablelist>
237      <varlistentry>
238        <term>constructor-function</term>
239        <listitem>
240          <para>
241Used to override the actual #GObject constructor of the said #GladeWidgetAdaptor
242          </para>
243        </listitem>
244      </varlistentry>
245
246      <varlistentry>
247        <term>post-create-function</term>
248        <listitem>
249          <para>
250A #GladePostCreateFunc support function that gets called whenever a widget of the said class is instantiated.
251          </para>
252        </listitem>
253      </varlistentry>
254
255      <varlistentry>
256        <term>deep-post-create-function</term>
257        <listitem>
258          <para>
259Same as `post-create-function' except in that you must always chain up
260to the super class definition as a rule.
261          </para>
262        </listitem>
263      </varlistentry>
264
265      <varlistentry>
266        <term>get-property-function</term>
267        <listitem>
268          <para>
269A #GladeGetPropertyFunc to get values of properties on an instance in the
270runtime.
271          </para>
272        </listitem>
273      </varlistentry>
274
275      <varlistentry>
276        <term>set-property-function</term>
277        <listitem>
278          <para>
279A #GladeSetPropertyFunc to set values of properties on an instance in the
280runtime.
281          </para>
282        </listitem>
283      </varlistentry>
284
285      <varlistentry>
286        <term>verify-function</term>
287        <listitem>
288          <para>
289A #GladeVerifyPropertyFunc to set values of properties on an instance in the
290runtime.
291          </para>
292        </listitem>
293      </varlistentry>
294
295      <varlistentry>
296        <term>add-child-function</term>
297        <listitem>
298          <para>
299A #GladeAddChildFunc to add children to instances in the runtime.
300          </para>
301        </listitem>
302      </varlistentry>
303
304      <varlistentry>
305        <term>remove-child-function</term>
306        <listitem>
307          <para>
308A #GladeRemoveChildFunc to remove children from instances in the runtime.
309          </para>
310        </listitem>
311      </varlistentry>
312
313      <varlistentry>
314        <term>replace-child-function</term>
315        <listitem>
316          <para>
317A #GladeReplaceChildFunc to replace children inside instances in the runtime.
318          </para>
319        </listitem>
320      </varlistentry>
321
322      <varlistentry>
323        <term>get-children-function</term>
324        <listitem>
325          <para>
326A #GladeGetChildrenFunc to get a list of children inside instances in the runtime.
327          </para>
328        </listitem>
329      </varlistentry>
330
331      <varlistentry>
332        <term>child-get-property-function</term>
333        <listitem>
334          <para>
335A #GladeChildGetPropertyFunc to get packing properties from instances in the runtime.
336          </para>
337        </listitem>
338      </varlistentry>
339
340      <varlistentry>
341        <term>child-set-property-function</term>
342        <listitem>
343          <para>
344A #GladeChildSetPropertyFunc to set packing properties on instances in the runtime.
345          </para>
346        </listitem>
347      </varlistentry>
348
349      <varlistentry>
350        <term>child-verify-function</term>
351        <listitem>
352          <para>
353A #GladeChildVerifyPropertyFunc to verify packing properties on instances in the runtime.
354          </para>
355        </listitem>
356      </varlistentry>
357
358      <varlistentry>
359        <term>get-internal-child-function</term>
360        <listitem>
361          <para>
362A #GladeGetInternalFunc to retrieve an internal child of a composite object in the runtime.
363          </para>
364        </listitem>
365      </varlistentry>
366
367      <varlistentry>
368        <term>action-activate-function</term>
369        <listitem>
370          <para>
371A #GladeActionActivateFunc to run a routine for a plugin defined #GladeWidgetAction.
372          </para>
373        </listitem>
374      </varlistentry>
375
376      <varlistentry>
377        <term>child-action-activate-function</term>
378        <listitem>
379          <para>
380A #GladeChildActionActivateFunc to run a routine for a plugin defined packing #GladeWidgetAction.
381          </para>
382        </listitem>
383      </varlistentry>
384
385      <varlistentry>
386        <term>read-widget-function</term>
387        <listitem>
388          <para>
389A #GladeReadWidgetFunc to load a widget from the xml.
390          </para>
391        </listitem>
392      </varlistentry>
393
394      <varlistentry>
395        <term>write-widget-function</term>
396        <listitem>
397          <para>
398A #GladeWriteWidgetFunc to write a widget from the xml.
399          </para>
400        </listitem>
401      </varlistentry>
402
403      <varlistentry>
404        <term>read-child-function</term>
405        <listitem>
406          <para>
407A #GladeReadWidgetFunc to read a child to the xml.
408          </para>
409        </listitem>
410      </varlistentry>
411
412      <varlistentry>
413        <term>write-child-function</term>
414        <listitem>
415          <para>
416A #GladeWriteWidgetFunc to write a child to the xml.
417          </para>
418        </listitem>
419      </varlistentry>
420
421      <varlistentry>
422        <term>create-editor-property-function</term>
423        <listitem>
424          <para>
425A #GladeCreateEPropFunc to create widgets to be used in Glade's property editor.
426          </para>
427        </listitem>
428      </varlistentry>
429
430      <varlistentry>
431        <term>string-from-value-function</term>
432        <listitem>
433          <para>
434A #GladeStringFromValueFunc to create a string from a #GValue, these strings must
435be unique and comparable for undo/redo to work properly.
436          </para>
437        </listitem>
438      </varlistentry>
439
440    </variablelist>
441  </refsect1>
442
443  <refsect1>
444    <title>Action Definitions</title>
445    <para>
446Actions are added under the `actions' and `packing-actions' tags, actions can also
447be nested so as to allow grouping in context menus, example:
448      <programlisting>
449<![CDATA[...
450
451<action id="manage_frobs" name="Manage Frobs">
452  <action id="add_frob" name="Add" stock="gtk-add"/>
453  <action id="remove_frob" name="Remove" stock="gtk-remove"/>
454</action>
455
456...]]></programlisting>
457    </para>
458    <para>
459Here are the meanings of the `action' tag's properties:
460    </para>
461    <variablelist>
462      <varlistentry>
463        <term>id</term>
464        <listitem>
465          <para>
466The string identifier for this action, the action_path argument to your #GladeActionActivateFunc
467will be a combination if this id and any parents, for the above example:
468<literal>"manage_frobs/add_frob"</literal>.
469          </para>
470        </listitem>
471      </varlistentry>
472
473      <varlistentry>
474        <term>name</term>
475        <listitem>
476          <para>
477A string to be displayed in the UI for this action.
478          </para>
479        </listitem>
480      </varlistentry>
481
482      <varlistentry>
483        <term>stock</term>
484        <listitem>
485          <para>
486An optional Gtk stock icon to represent this action.
487          </para>
488        </listitem>
489      </varlistentry>
490
491      <varlistentry>
492        <term>important</term>
493        <listitem>
494          <para>
495A boolean option to add emphasis to this action; currently actions marked as `important'
496are added to the toolbar.
497          </para>
498        </listitem>
499      </varlistentry>
500
501    </variablelist>
502  </refsect1>
503
504  <refsect1>
505    <title>Packing Defaults</title>
506    <para>
507Default values can be specified for packing properties on your widget when added
508to a said type of parent, as the example shows above; use the `parent-class' to
509specify what parent (or derivative of that parent) you are targetting and fill
510in any `child-property' tags you need for that parent using `id' property to
511specify the property name and the `default' property for the value.
512    </para>
513  </refsect1>
514
515  <refsect1>
516    <title>Signals</title>
517    <para>
518The signal elements are currently only needed for versioning support, use
519the `signal' child tag as described above and set signal `id' to be supported
520since version `since'. Signals are initialized to be supported since the
521introducing #GladeWidgetAdaptor was supported.
522    </para>
523  </refsect1>
524
525  <refsect1>
526    <title>Icons</title>
527    <para>
528The Glade palette and other components use icons to represent the various widget classes.
529It is a good idea to provide icons for your widget classes, as this
530enhances the user interface.
531    </para>
532
533    <para>
534Glade uses the GTK+ GtkIconTheme facility to provide icons for widget classes. Any icon
535available in the current icon theme can be used as an icon for a widget class.
536    </para>
537
538    <para>
539By default, an icon name of the format "widget-CATALOG_NAME-GENERIC_NAME"
540is assigned to every widget class. CATALOG_NAME is the value of catalog name attribute,
541and GENERIC_NAME is the value of an widget class's generic name attribute.
542    </para>
543
544    <para>
545To explicity set an icon name for a widget class, the "icon-name" attribute of the
546"glade-widget-class" element can be specified. This will override the default icon
547name assigned to the widget class.
548    </para>
549
550    <para>
551Icon files can be installed under any system icon theme folder.
552    </para>
553  </refsect1>
554
555</refentry>
556