source: trunk/third/libglade2/doc/libglade-docs.xml @ 20816

Revision 20816, 20.9 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r20815, which included commits to RCS files with non-trunk default branches.
Line 
1<?xml version="1.0" standalone="no"?>
2<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
4
5<book id="libglade" xmlns:xi="http://www.w3.org/2003/XInclude">
6  <bookinfo>
7    <title>Libglade Reference Manual</title>
8    <releaseinfo>for libglade <xi:include href="version.xml"/></releaseinfo>
9    <authorgroup>
10      <author>
11        <firstname>James</firstname>
12        <surname>Henstridge</surname>
13        <affiliation>
14          <address>
15            <email>james@daa.com.au</email>
16          </address>
17        </affiliation>
18      </author>
19    </authorgroup>
20
21    <copyright>
22      <year>1999-2002</year>
23      <holder>James Henstridge</holder>
24    </copyright>
25
26    <legalnotice>
27      <para>Permission is granted to copy, distribute and/or modify
28      this document under the terms of the <citetitle>GNU Free
29      Documentation License</citetitle>, Version 1.1 or any later
30      version published by the Free Software Foundation with no
31      Invariant Sections, no Front-Cover Texts, and no Back-Cover
32      Texts. You may obtain a copy of the <citetitle>GNU Free
33      Documentation License</citetitle> from the Free Software
34      Foundation by visiting <ulink type="http"
35      url="http://www.fsf.org">their Web site</ulink> or by writing
36      to: Free Software Foundation, Inc., 59 Temple Place - Suite 330,
37      Boston, MA 02111-1307, USA.</para>
38
39      <para>Many of the names used by companies to distinguish their
40      products and services are claimed as trademarks. Where those
41      names appear in any GNOME documentation, and those trademarks
42      are made aware to the members of the GNOME Documentation
43      Project, the names have been printed in caps or initial
44      caps.</para>
45    </legalnotice>
46
47    <abstract>
48      <para>This manual documents the interfaces of the libglade
49      library and has some short notes to help get you up to speed
50      with using the library.</para>
51    </abstract>
52  </bookinfo>
53
54  <chapter id="libglade-notes">
55    <title>Libglade Programming Notes</title>
56
57    <para>Libglade is an alternative to using Glade's code generation.
58    Instead of generating code from the XML interface description,
59    libglade loads and parses the description at runtime.  It also
60    provides functions that can be used to connect signal handlers to
61    parts of the interface.</para>
62
63    <para>In this way, it allows you to separate your program code
64    from the interface code.  In fact, if you use the
65    glade_xml_signal_autoconnect() function, the GUI code could be as
66    simple as the <filename>test-libglade.c</filename> example that
67    comes with libglade.  Of course, you would also add your own
68    signal handlers to the code.  Note that the signals are connected
69    the same way as if you had hand coded the interface.  There is no
70    extra overhead to user interfaces constructed by libglade (after
71    the initial generating of course, and this is not much of an
72    overhead) when compared to a hand crafted interface.</para>
73
74    <sect1 id="libglade-basics">
75      <title>Libglade Programming Basics</title>
76
77      <para>Your basic libglade program will look something like this:</para>
78<programlisting><![CDATA[
79#include <gtk/gtk.h>
80#include <glade/glade.h>
81
82void some_signal_handler_func(GtkWidget *widget, gpointer user_data) {
83  /* do something useful here */
84}
85
86int main(int argc, char *argv[]) {
87    GladeXML *xml;
88
89    gtk_init(&argc, &argv);
90
91    /* load the interface */
92    xml = glade_xml_new("filename.glade", NULL, NULL);
93
94    /* connect the signals in the interface */
95    glade_xml_signal_autoconnect(xml);
96
97    /* start the event loop */
98    gtk_main();
99
100    return 0;
101}
102]]></programlisting>
103
104      <para>This will create the interface from the file
105      <filename>filename.glade</filename>, then connect all the
106      signals in the interface.  The automatic signal connection is
107      done by looking up function names in the global symbol table
108      using gmodule.  This means that the interface file can use
109      standard GTK functions such as
110      <function>gtk_widget_show</function>, or
111      <function>gtk_main_quit</function>, or others in the interface
112      and not have to write any code to connect the signals.</para>
113
114      <para>The <function>some_signal_handler_func</function> function
115      is not referenced anywhere in the program explicitely, but if
116      any signals are defined in the interface description that use
117      "some_signal_handler_func" as the handler name, then this
118      function will automatically be connected.  Note that the
119      function can not be static, since we require it to apear in the
120      symbol table.  Here is an example of the XML that would cause
121      <function>some_signal_handler_func</function> to be
122      connected:</para>
123
124<programlisting><![CDATA[
125<widget class="GtkWindow" id="MainWindow">
126  <property name="visible">yes</property>
127  <signal name="destroy" handler="some_signal_handler_func" />
128  ...
129</widget>
130]]></programlisting>
131
132      <note>
133        <para>If you wish to autoconnect handlers defined in the main
134        executable (not a shared library), you will need to pass a
135        linker flag to export the executable's symbols for dynamic
136        linking.  This flag is platform specific, but libtool can take
137        care of this for you.  Just add
138        <parameter>-export-dynamic</parameter> argument to your link
139        flags, and libtool will convert it to the correct
140        format.</para>
141
142        <para>Many people did not see this problem on GNU/Linux with
143        GTK+ 1.2, because the <command>gtk-config</command> script
144        adds the correct flag on that platform.  Such programs would
145        sometimes break when run on alternative platforms.</para>
146      </note>
147
148      <para>To compile the program, we would use the following:</para>
149<programlisting>
150cc -o testprogram testprogram.c `pkg-config --cflags --libs libglade-2.0`
151</programlisting>
152
153      <para>The <command>pkg-config</command> program is used to
154      deduce the compiler and link flags necessary to compile various
155      modules.  If you are using automake or autoconf, you probably
156      want to use the PKG_CHECK_MODULES macro.  This can be used to
157      check for the presence of a collection of a number of packages,
158      and set some shell variables:</para>
159
160<programlisting>
161PKG_CHECK_MODULES(MYPROG, libglade-2.0 libgnomeui-2.0 >= 1.110.0)
162AC_SUBST(MYPROG_CFLAGS)
163AC_SUBST(MYPROG_LIBS)
164</programlisting>
165
166    </sect1>
167
168    <sect1 id="libglade-modules">
169      <title>Libglade Modules</title>
170     
171      <para>Libglade can be extended to support widget libraries built
172      on top of GTK+.  These modules are loaded dynamically at
173      runtime.  These modules are loaded when
174      <sgmltag>&lt;requires&gt;</sgmltag> elements are found in the
175      glade file.</para>
176
177      <para>Currently there are libglade module support for
178      libbonoboui libgnomecanvas and libgnomeui.  Note that libglade
179      can also handle widgets that implement the properties interfaces
180      with no extra code.</para>
181
182      <para>While no additional libglade initialisation is required to
183      use a module, however, the underlying library might need
184      initialisation.  For instance, to use libgnomeui widgets from
185      libglade, you <emphasis>must</emphasis> call
186      <function>gnome_program_init</function> beforehand.</para>
187
188    </sect1>
189
190    <sect1 id="libglade-i18n">
191      <title>Internationalisation with Libglade</title>
192
193      <para>Glade files mark properties for translation with the
194      <parameter>translatable</parameter> property of the
195      <sgmltag>&lt;property&gt;</sgmltag> element:</para>
196
197<programlisting><![CDATA[
198<widget class="GtkLabel" id="label1">
199  <property name="label" translatable="yes">Foo</property>
200  ...
201</widget>
202]]></programlisting>
203
204      <para>Libglade will translate marked properties using the
205      translation domain specified in the
206      <function>glade_xml_new()</function> (or the default domain if
207      <constant>NULL</constant>).</para>
208
209      <para>Libglade also supports disambiguating properties by
210      prefixing them with a |-separated context string, e.g.
211      "Menu/Printer|Open" vs. "Menu/File|Open". You must tell Libglade that
212      the property has a prefix by setting the <parameter>context</parameter>
213      attribute of the <sgmltag>&lt;property&gt;</sgmltag> element to "yes".
214      To learn more about this technique, read the chapter "How to use
215      gettext in GUI programs" in the gettext manual, and see the GLib
216      API documentation for g_strip_context().
217      </para>
218
219      <para>To add the strings found in a glade file to your
220      translation catalog template through the use of
221      <command>intltool</command>. (XXXX - does this actually work
222      yet?).</para>
223
224    </sect1>
225
226    <sect1 id="libglade-extending">
227      <title>Extending Libglade</title>
228
229      <para>In some cases, libglade may not provide support for the
230      widgets you want to use, or you may want to insert a bit of hand
231      coded interface into the larger libglade generated
232      interface.  Libglade provides support for doing this.</para>
233
234      <para>If you are only need a few custom widgets (eg. a word
235      processor may have a custom widget for the document editing
236      area), the simplest choice is probably Glade's custom widget.
237      It allows you to specify a custom function that will be used to
238      create the widget.  The signature of the function is as
239      follows:</para>
240<programlisting>
241GtkWidget *custom_func(gchar *widget_name, gchar *string1, gchar *string2,
242                       gint int1, gint int2);
243</programlisting>
244
245      <para>When calling this function, widget_name is the name of the
246      widget given in the XML file, and
247      <parameter>string1</parameter>, <parameter>string2</parameter>,
248      <parameter>int1</parameter> and <parameter>int2</parameter> are
249      arbitrary constants whose values also come from the XML file.
250      Libglade supports the custom widget using gmodule.  For most
251      cases, this is sufficient.</para>
252
253
254      <para>If you wish to get libglade to recognise a new widget type
255      directly, your best option is to ensure that it implements
256      properties for all settings required to construct the widget,
257      and packing properties if the widget happens to be a container.
258      If the widget satisifies this requirement, libglade will support
259      the widget with no extra code (provided the widget's
260      <function>get_type()</function> function has been called to
261      register it with GLib).</para>
262
263      <para>If a widget has more complex requirements, a libglade
264      module must be written (or if the library containing the widget
265      already depends on libglade, it may build the module in).  In
266      the module, a widget construction routine and a build children
267      routine must be registered.  If the widget can be manipulated
268      via properties for construction or adding children, <link
269      linkend="glade-standard-build-widget"><function>glade_standard_build_widget</function></link>
270      or <link
271      linkend="glade-standard-build-children"><function>glade_standard_build_children</function></link>
272      can be used here.</para>
273
274      <para>If the widget mostly supports properties, custom handlers
275      for particular properties can be registered with <link
276      linkend="glade-register-custom-prop"><function>glade_register_custom_prop</function></link>.</para>
277
278      <para>If the widget implements no properties (and you have no
279      way to convince the author to do so), you will most likely need
280      to implement custom handlers for construction and adding
281      children.</para>
282
283      <para>For a more extensive example of registering new widget
284      types and build functions, see
285      <filename>glade/glade-gtk.c</filename> in the libglade package.
286      For more information on the exact API's used to register new
287      widget types with libglade, see the <link
288      linkend="libglade-Libglade-Build">Libglade Build</link> section
289      of this manual.</para>
290
291    </sect1>
292
293    <sect1 id="libglade-embedding">
294      <title>Embedding Libglade Interfaces</title>
295
296      <para>Sometimes you will only want to use libglade for a small
297      part of your program.  If it is just for some dialogs, this is
298      easy -- you just generate the dialogs from the interface files
299      when needed (note that libglade caches the XML parse tree
300      between calls to <function>glade_xml_new</function>, so you will
301      not suffer the performance hit of parsing a particular XML file
302      more than once).</para>
303
304      <para>On the other hand, you may want to use libglade to
305      generate just part of the UI, such as the menubar or a notebook
306      or something.  Libglade allows you to build only part of the
307      interface if you want to.  The second argument to
308      <function>glade_xml_new</function> specifies the name of the
309      base widget to build the interface from.  This way we can limit
310      the widgets that are constructed by libglade.</para>
311
312      <para>For the menubar example, we would create a dummy window in
313      Glade, and insert a menubar widget into the window.  We would
314      then name the menubar in glade ("menubar" would be a good choice
315      for the widget name ), and customise it as much as we want.  Now
316      in the program, we can use the following code:</para>
317
318<programlisting>
319GladeXML *xml;
320GtkWidget *menubar;
321
322xml = glade_xml_new("some-interface-file", "menubar", NULL);
323
324glade_xml_signal_autoconnect(xml);
325
326menubar = glade_xml_get_widget(xml, "menubar");
327/* do whatever we want to with the menubar */
328</programlisting>
329
330      <para>From here, we can do what ever we want with the menubar
331      widget.  The dummy window we created in Glade is never created,
332      so does not affect the program.  You can also use similar code
333      to only build a single dialog from a glade file that contains
334      many dialogs.</para>
335
336      <para>One thing to note -- if you don't want a widget to be
337      displayed as soon as it is constructed with
338      <function>glade_xml_new</function>, you should set the
339      <parameter>visible</parameter> property on that widget to "no"
340      in Glade.  This is the correct solution to the problem (putting
341      a hack into libglade so that it never shows the toplevel windows
342      is not The Right Thing).</para>
343
344    </sect1>
345  </chapter>
346
347  <chapter id="libglade-dtd">
348    <title>Glade 2.0 File Format</title>
349
350    <para>Libglade 2.0 introduces a new file format for storing the
351    user interface.  Unlike the previous format, this one does not
352    introduce a new element for each new property.  This was done so
353    that the format could be described with a fairly small DTD:</para>
354
355    <programlisting><xi:include href="../glade-2.0.dtd" parse="text"/></programlisting>
356
357    <para>The <sgmltag>&lt;widget&gt;</sgmltag> elements contain
358    <sgmltag>&lt;property&gt;</sgmltag> elements which define widget
359    properties.  In general these map to
360    <classname>GObject</classname> properties.</para>
361
362    <para>The <sgmltag>&lt;signal&gt;</sgmltag> and
363    <sgmltag>&lt;accelerator&gt;</sgmltag> elements are used to define
364    signals and accelerators on the widget.</para>
365
366    <para>The <sgmltag>&lt;widget&gt;</sgmltag> element may also
367    contain an <sgmltag>&lt;accessibility&gt;</sgmltag> element, which
368    contains accessibility related properties.  These set various ATK
369    options (such as ATK properties, relations and actions).</para>
370
371    <para>For each child of the widget, there is an
372    <sgmltag>&lt;child&gt;</sgmltag> element.  The
373    <parameter>internal-child</parameter> attribute is used to mark
374    "internal children of the parent.  These children are widgets that
375    are created when the parent is constructed, such as the
376    <classname>GtkVBox</classname> and
377    <classname>GtkHButtonBox</classname> in a
378    <classname>GtkDialog</classname>.</para>
379
380    <para>The <sgmltag>&lt;child&gt;</sgmltag> element contains either
381    a <sgmltag>&lt;widget&gt;</sgmltag> element representing the child
382    widget, or a <sgmltag>&lt;placeholder&gt;</sgmltag> element, which
383    is ignored when building the interface.  It may also contain a
384    <sgmltag>&lt;packing&gt;</sgmltag> element, which contains
385    <sgmltag>&lt;property&gt;</sgmltag> elements defining packing
386    properties.  These map to GtkContainer child packing
387    properties.</para>
388
389    <sect1 id="property-representations">
390
391      <title>Property Representations</title>
392
393      <para>Properties are represented as straight content data in the
394      glade file.  All programs working with glade files must
395      represent the various types in the same way.</para>
396
397    </sect1>
398
399    <sect1 id="libglade-dtd-exceptions">
400
401      <title>Exceptions</title>
402
403      <para>As some widgets do not implement properties for all
404      required properties.  This section documents some of the
405      exceptions built into libglade's logic.</para>
406
407      <para>The following properties have custom handlers in libglade.
408      Most of these will probably become real properties in GTK+
409      2.2.</para>
410
411      <itemizedlist>
412        <listitem>
413          <para><parameter>GtkWidget::visible</parameter> is handled
414          specially so that it gets applied after children have been
415          added.  This works around some sizing bugs in certain
416          widgets (and is the same behaviour libglade-0.x had).</para>
417        </listitem>
418        <listitem>
419          <para><parameter>GtkWidget::tooltip</parameter> implements
420          tooltips for the widget.  The property value is the tooltip
421          to set on the widget.</para>
422        </listitem>
423        <listitem>
424          <para><parameter>GtkOptionMenu::history</parameter> sets
425          which menu item index in the list should be selected
426          initially with
427          <function>gtk_option_menu_set_history()</function>.</para>
428        </listitem>
429        <listitem>
430          <para><parameter>GtkTextView::text</parameter> offers an
431          easy way to set the contents of a text view's buffer.</para>
432        </listitem>
433        <listitem>
434          <para><parameter>GtkCallendar::display_options</parameter>
435          sets display options of a calendar with
436          <function>gtk_calendar_display_options()</function>.</para>
437        </listitem>
438        <listitem>
439          <para><parameter>GtkRadioMenuItem::group</parameter> sets
440          the group for the radio item.  The property value is the
441          name of another widget in the group.  This property won't
442          handle forward references like the
443          <parameter>GtkRadioButton::group</parameter>
444          property.</para>
445        </listitem>
446        <listitem>
447          <para><parameter>GtkToolbar::tooltips</parameter> sets
448          whether the toolbar shows tooltips with
449          <function>gtk_toolbar_set_tooltips()</function>.</para>
450        </listitem>
451        <listitem>
452          <para><parameter>GtkStatusbar::has_resize_grip</parameter>
453          sets whether the status bar has a resize grip in the bottom
454          corner with
455          <function>gtk_statusbar_set_has_resize_grip()</function>.</para>
456        </listitem>
457        <listitem>
458          <para><parameter>GtkRuler::metric</parameter> sets the
459          bounds and metric type for the ruler with
460          <function>gtk_ruler_set_metric()</function>.</para>
461        </listitem>
462        <listitem>
463          <para><parameter>GtkMenuItem::label</parameter>,
464          <parameter>GtkMenuItem::use_underline</parameter> and
465          <parameter>GtkMenuItem::use_stock</parameter> are used to
466          create a label inside a menu item, and set whether it has a
467          mnemonic (underlined letter), and whether it should be a
468          stock item (standardised, translated label and an icon, if
469          it is a GtkImageMenuItem).  These properties act similarly
470          to the identically named <classname>GtkButton</classname>
471          properties.</para>
472        </listitem>
473      </itemizedlist>
474
475      <para>There are custom handlers for a number of deprecated
476      widgets, and deprecated settings for some widgets.  These most
477      likely won't be converted to real properties in the
478      future.  These include:</para>
479
480      <simplelist>
481        <member><parameter>GtkPixmap::build_insensitive</parameter></member>
482        <member><parameter>GtkPixmap::filename</parameter></member>
483        <member><parameter>GtkProgress::format</parameter></member>
484        <member><parameter>GtkCalendar::display_options</parameter></member>
485        <member><parameter>GtkCList::column_widths</parameter></member>
486        <member><parameter>GtkCList::selection_mode</parameter></member>
487        <member><parameter>GtkCList::shadow_type</parameter></member>
488        <member><parameter>GtkCList::show_titles</parameter></member>
489        <member><parameter>GtkTree::selection_mode</parameter></member>
490        <member><parameter>GtkTree::view_mode</parameter></member>
491        <member><parameter>GtkTree::view_line</parameter></member>
492        <member><parameter>GtkList::selection_mode</parameter></member>
493        <member><parameter>GtkCheckMenuItem::always_show_toggle</parameter></member>
494        <member><parameter>GtkText::text</parameter></member>
495      </simplelist>
496
497      <para><emphasis>XXXX - To be done</emphasis></para>
498
499    </sect1>
500
501  </chapter>
502
503  <part id="libglade-lib">
504    <title>Libglade Library Reference</title>
505
506    <partintro>
507      <para>This section contains the API reference for libglade.  All
508      the public interfaces are documented here.</para>
509    </partintro>
510
511    <xi:include href="xml/glade-init.xml"/>
512    <xi:include href="xml/glade-xml.xml"/>
513    <xi:include href="xml/glade-parser.xml"/>
514    <xi:include href="xml/glade-build.xml"/>
515  </part>
516
517</book>
Note: See TracBrowser for help on using the repository browser.