$Id: glademm-guide.html,v 1.10 1999/08/12 09:06:39 christof Exp $

Glade-- V0.5 User's Guide

This document attempts to give you a basic understanding on how to use glade-- and to indicate where it's strengths and weeknesses are.

Glade-- is a backend to glade. Glade is a GUI builder for the Gimp Toolkit (gtk). Glade is entirely written in C. It operates on an XML file and can output C sourcecode. Glade-- is written in C++ and makes use of recent C++ features such as the STL.

As a side note I recommend using CVS. It makes source code management really easy and if you by chance delete a file or overwrite it you can easily get it back. And, opposed to SCCS, it doesn't bloat your working directory with it's files. You might even get your old files back if your design decisions misleaded you. Besides that you can light-heartedly delete unecessary files, you can get them back.

Table of contents

Abstract
Table of contents
Create your glade file
Create your initial program files (glade--)
You changed the glade file
    The widget map
    User types
    Using glade-- generated widgets within another context (components, user defined widgets)
Strengths of glade--
Weaknesses of glade--
Future development
How to get it

Create your glade file

Design your GUI up to your favor. I recommend tables, they look great.
For numeric input I use spinbuttons, it doesn't cost you more and the user might use the extra functionality.

For textual input you might prefer option menus or combo boxes.
You should also take a look at the fancy SearchCombo widget of the gtk--addons I put to cvs.gnome.org.
Beware, stock glade does not support it (but gtk--addons come with a patch at hand).

! You will not see the C++ code options in glade unless you select C++ as your language. (Project options)

I recommend putting all your widgets on the heap (use_heap=true, -p option for glade--). Though current glade doesn't default to this behaviour. You might take a text editor and replace each '<widget>' by
'<widget><cxx_use_heap>True</cxx_use_heap>'. Loading and saving this file in glade will reindent it.

Then think about partitioning complex windows into substructures. Toplevel windows always come in an own file (and an own class). Signal callback functions are part of the topmost widget's class.
Feel free to break this via the 'separate class' or 'separate_file' switch. I recommend up to ten to twenty callbacks in one class. But on the other hand you lose the ability to easily access widgets outside your class.

Then think whether you need to access a widget in your program. If you need to access it inside your scope (class) declare it as protected.
If you need to access it outside your scope, mark it as public. Then include the appropriate header file, glade-- has generated a GMM_* macro for easy access:
   GMM_WINDOW1->show();
 

Create your initial program files (glade--)

Look into glade's project options (the sheet) and adjust the pathnames.
I recommend to put the glade file near to your program and let glade create fresh files in a subdirectory (source directory option in glade). Then copy the files you need into your current directory.

Simply invoke glade-- by pressing the gear's button in glade or by hand:
    glade-- <project file>

Some options are only available from the command line:
'-s' gives you some programming examples for signals and widget modification
'-p' puts widgets into the heap. [This is important for large projects. The total size of a structure with virtual functions can not exceed 32k on x86 computers. Since gtk-- is full of virtual function calls putting all widgets into one memory chunk is not advisable.]
'-A' disables autoconf/automake. For small projects these are overkill. Also, gnome automake support is not yet available.

Glade-- will generate the following files:

You changed the glade file

Since you should not edit the *_glade.cc and *_glade.hh files glade will overwrite them. Similar for the glademm_support.?? files. But what about the rest? Glade-- creates new files: Never rename a widget which form a class! (Unless you want to do a lot of search/replace work)
I usually use a whenever I did huge changes. Did I mention that CVS is a good idea? Use it! Accidental overwrites will not cause you any harm.

The widget map

Glade-- creates a map of public widgets. Access them via the GMM_FOO1 macros. But never access them before they are created or after they have been destroyed.
 

User types

glade supports custom widgets. Glade-- takes the creation function as include file name (.hh added) and class type.
If neccessary you can include and wrap any other class inside the expected header file.

Using glade-- generated widgets within another context (components, user defined widgets)

If you want to use components I propose the following route:

Strengths of glade--

Weaknesses of glade--

Future development

How to get it

http://home.wtal.de/petig/Gtk/ for released versions
anoncvs.gnome.org for development versions (recommended)