

Writing Source Code
===================

I think you need to make several passes through the widget tree, so for
external programs using Glade's output, you'll have to read in a component
at a time.

I'm thinking of C output here. For other languages this may be different.

There are 4 output files - two pairs of .c & .h files.
The first pair contains code to create the components, and declarations.
The second pair contains empty signal handler functions, and declarations.

Stages:

1. Write start of all 4 files -
      For main source file:
	#include <gtk/gtk.h>
	#include "<signal handler declarations>.h"

      For signal handler source file:
	#include <gtk/gtk.h>
	#include "<main source file>.h"


	(Any globals needed?)
	possibly some utility functions like create/load_pixmap()

	create all styles in an init() function?


2. Iterate over components:

2.1 Write function prototype to source file -
      Add to main source file:
	GtkWidget* create_<component name>() {

      Add to main header file:
	GtkWidget* create_<component name>();

2.2 Write variable declarations. For this we need to scan the component
    hierarchy to collect the types and names needed, e.g.
	GtkWidget *window1, *hbox1, *table1, *entry1, *label1, *label2; ...
	GtkTooltips *tooltips;

2.3 Create tooltips if needed by the component.
	tooltips = gtk_tooltips_new();

2.4 Walk the hierarchy, creating and adding widgets as we go. We also have to
    set up any signals and accelerators.

      Add to main source file:
	entry1 = gtk_entry_new();
	gtk_box_pack_start(GTK_BOX(hbox1), entry, TRUE, TRUE, 2);
	gtk_entry_set_editable(GTK_ENTRY(entry1), FALSE);
	gtk_entry_set_visible(GTK_ENTRY(entry1), FALSE);
	gtk_signal_connect(GTK_OBJECT(entry1), "key_press_event",
			   GTK_SIGNAL_FUNC(on_entry1_key_press_event), NULL);

      Add to handlers header file (Note: we have to figure out the prototype):
	gint on_entry1_key_press_event(GtkWidget *widget, GdkEventKey *event,
				       gpointer data);

      Add to handlers source file:
	gint on_entry1_key_press_event(GtkWidget *widget, GdkEventKey *event,
				       gpointer data) {

	  return FALSE;
	}

    Note: if we try to use Args wherever possible, then the output may be
    more portable to other languages?


2.5 Write function end. For C that's just '}'.



Damon, 4 June 1998



Dynamic Loading
===============

	- Aim is to allow users of Glade to specify extra libraries
	  containing more GTK widgets (which Glade has no knowledge of at all!)
	  so that Glade can use these widgets while creating the interface.

	- How portable is it??

	  On Linux need to link with -ldl (see ld.so info files).
	  Load library with:    handle = dlopen ("/lib/libm.so", RTLD_LAZY);
	  Look up symbol with:  cosine = dlsym(handle, "cos");
	  Call it with:         printf ("%f\\n", (*cosine)(2.0));

	  Does it need a completely different procedure on each Unix platform?
	  Maybe we could support just Linux and a few other popular platforms.
	  Maybe someone has written a portable library of functions for this?

	- How does Glade determine what widgets are available and what
	  functions?
	  Need a standard function included with the library to initialize
	  it and return info on the included widgets?

	  This would call gtk_<widget>_get_type() on all the widgets in the
	  library.

	  If GTK's get_arg/set_arg mechanism works OK, then all we need
	  returned is an array of widget type IDs?

	     void *handle;
	     gint* (*library_info_fn)();
	     gint* library_info;

	     handle = dlopen (library, RTLD_LAZY);
	     library_info_fn = dlsym(handle, "library_info");
             library_info = (*library_info_fn)();


	  We create new widgets with:     widget = gtk_type_new(type);
	  query the widgets properties:   gtk_object_query_args(type);
	  and show/apply properties with: gtk_object_getv/setv(widget, ...);

	  Is that all we need??

	  Some way of getting icons and tooltips for the palette would be nice
	  (though we could provide a number of custom icons and the class name
	   could be used for the tooltip).

	- The libraries could also contain customization functions which,
	  when called, pop up a dialog box or something to customize the
	  widget.

	- User could specify additional widget libraries in a Glade config
	  file. - Or even in a dialog in Glade itself.
	- Glade could even look for some standard libraries - GtkXmHTML,
	  Gnome's widget libraries. - May be a problem with versions?


In summary, people creating their own widgets to use with Glade (or any other
UI builder) should:

  1. compile them into a library.
  2. make sure the widgets are configurable with GTK's get_arg/set_arg
     mechanism (and also that creating the widget with gtk_type_new()
     results in a valid widget).
  3. include one extra function to initialize the widgets and return the
     types, something like this:

gint*
library_info()
{
  gint types[4];

  types[0] = gtk_myfirstwidget_get_type();
  types[1] = gtk_mysecondwidget_get_type();
  types[2] = gtk_mythirdwidget_get_type();
  types[3] = 0;

  return types;
}


Damon, 14th May 1998