]> git.draconx.ca Git - gob-dx.git/blobdiff - doc/gob2.1.in
Release 2.0.16
[gob-dx.git] / doc / gob2.1.in
index f36c7259a8118c044cce4eaa68c5965c44a65908..904691ebb0f61659edb7a9fa25dc2dd5da277a8d 100644 (file)
@@ -1,6 +1,6 @@
 .\"
 .\" gob manual page
-.\" (C) 1999,2000,2001,2002 George Lebl <jirka@5z.com>
+.\" (C) 1999,2000,2001,2002,2005 George Lebl <jirka@5z.com>
 .\" 
 .\" This manual page is covered by the terms of the GNU General
 .\" Public License.  
@@ -51,6 +51,11 @@ correctly even on non-GNU compilers.  This option is for purists only.
 (using GNU extensions some warnings are eliminated, some ugly hacks and there
 is better argument type safety, so it\'s good to use them)
 .TP
+.B --no-touch
+Don\'t touch output files unless they really
+changed (implies --no-touch-headers).  Be careful with automake, see section
+PREVENTING SPURIOUS BUILDS.
+.TP
 .B --no-touch-headers
 Don\'t touch the generated header file unless it really changed, this avoids
 spurious rebuilds, but can confuse some make systems (automake in particular),
@@ -59,11 +64,11 @@ unchanged however.
 .TP
 .B --always-private-header
 Always create a \fB<basename>-private.h\fR file, even if it would be empty.
-This is the default.
 .TP
 .B --ondemand-private-header
 Create the private header only if it would have something in it, that is,
 if there are some private data members or protected methods.
+This is the default.
 .TP
 .B --no-private-header
 Never create a private header file.  If we use any private data members,
@@ -91,15 +96,22 @@ and SELF_CLASS macros.
 Do not remove the initial underscore from method names.
 .TP
 .B --always-private-struct
-Always include the private pointer in the public header file.  This is useful for
-files which are part of a library and you want to reserve the right to add some
-private data members without breaking binary compatibility.
+Always include the private pointer in the public header file.  This is useful
+for files which are part of a library and you want to reserve the right to add
+some private data members without breaking binary compatibility.
+.TP
+.B -o --output-dir
+The directory into which output should be placed.
+.TP
+.B --file-sep[=c]
+Replace default \`-\' file name separator.  If no separator character
+is given then none is used.  Only one character can be used.
 
 .SH TYPENAMES
 .PP
 Because we need to parse out different parts of the typename, sometimes you
 need to specify the typename with some special syntax.  Types are specified in
-capitalized form and words are separated by \':\'.  The first word of the type
+capitalized form and words are separated by \`:\'.  The first word of the type
 (which can be empty) is the "namespace".  This fact is for example used for the
 type checking macro and the type macro.  For "Gtk:New:Button", the macros will
 be GTK_IS_NEW_BUTTON and GTK_TYPE_NEW_BUTTON.  This colon separated format of
@@ -109,7 +121,8 @@ types.
 .SH OUTPUT FILES
 .PP
 The filenames are created from the typename.  The words are
-separated by \'-\' and all in lower case.  For example for an object named
+separated by \`-\' (this can be changed with
+\fB--file-sep\fR option) and all in lower case.  For example for an object named
 "Gtk:New:Button", the files are \fBgtk-new-button.c\fR and
 \fBgtk-new-button.h\fR.
 If you are using C++ mode, the output .c file will in fact be a .cc file.
@@ -137,36 +150,44 @@ the extern "C" and the protecting define.  To do this you can put them
 into the \'headertop\' (or \'ht\') section.  You may wish to include code or
 comments in all the files, which you can do by putting them into the \'all\'
 (or \'a\') section.  Similarly, code you wish to appear at the top of all
-files go in the \'alltop\' (or \'at\') section.  For example:
+files go in the \'alltop\' (or \'at\') section.  Finally,
+\'afterdecls\' includes code between the declarations and the method
+implementations, but note that \'afterdecls\' requires version 2.0.16.
+For example:
 .nf
 
   %alltop{
-  /* this will be on top of all output files */
+        /* this will be on top of all output files */
   %}
 
   %headertop{
-  /* this will be on top of the public header */
+        /* this will be on top of the public header */
   %}
 
   %privateheader{
-  /* this will go into the private header file */
+        /* this will go into the private header file */
   %}
 
   %h{
-  /* will be included in the header */
-  void somefunc(int i);
+        /* will be included in the header */
+        void somefunc(int i);
   %}
 
   %a{
-  /* will be included in all files */
+        /* will be included in all files */
+  %}
+
+  %afterdecls{
+        /* between the declarations and the method implementations */
+        /* Requires gob version 2.0.16 */
   %}
 
   %{
-  /* will be included in the C file */
-  void somefunc(int i)
-  {
-        /* some code */
-  }
+        /* will be included in the C file */
+        void somefunc(int i)
+        {
+              /* some code */
+        }
   %}
 
 .fi
@@ -203,6 +224,9 @@ For example:
   }
 
 .fi
+.PP
+To make an abstract class (to pass G_TYPE_FLAG_ABSTRACT) add \'(abstract)\'
+before the curly braces above.  This works since version 2.0.13.
 
 .SH DATA MEMBERS
 .PP
@@ -266,11 +290,12 @@ member foo:
   classwide int foo;
 
 .fi
-To access the member you do the standard voodoo of getting the class from the
-object and casting it to your class pointer.  Thus the following would work:
+To access the member you can use the SELF_GET_CLASS macro (or
+YOUR_OBJECT_NAME_GET_CLASS) to get at the class.
+Thus the following would work:
 .nf
 
-  SELF_CLASS(GTK_OBJECT(object)->klass)->foo = 20;
+  SELF_GET_CLASS(object)->foo = 20;
 
 .fi
 .PP
@@ -436,7 +461,8 @@ There is a STRING type which has only the extra \'default_value\' attribute.
 .PP
 The OBJECT type is one of the types that doesn\'t have a \'default_value\' and it
 only has an \'object_type\' attribute (in addition to nick and blurb of course)
-that is the exact object type that this property accepts.
+that is the exact object type that this property accepts.  The object_type
+should be as a type, that is for example \'Gtk:Button\'.
 .PP
 There is a BOXED type which is a pointer which has a boxed type defined
 (such that GObject knows how to copy and destroy this pointer).  Here
@@ -519,6 +545,21 @@ To get bettery type safety on some of the property types, you can specify
 the \'type\' attribute which will add casts where appropriate in code dealing
 with this property.  This is especially useful for POINTER and OBJECT types.
 But even for others.
+.PP
+You can also override properties from parent objects (that is override their
+implementation, not their attributes).  Do this by adding the
+special \'override\' attribute.  For example if the parent object
+had a \'height\' property then you could override it by
+.nf
+
+  private int height;
+  property INT height
+         (override)
+        set { self->_priv->height = g_value_get_int (VAL); }
+        get { g_value_set_int (VAL, self->_priv->height); };
+
+.fi
+Overriding is supported since gob 2.0.10.
 
 .SH METHODS
 .PP
@@ -572,15 +613,43 @@ to be more then 0 and less then 11, and a pointer to a GtkWidget object
 instance and it is checked for being null and the type will also be
 checked.
 .PP
+.B "Function attributes:"
+.PP
+For method that aren't virtual, signal or override methods, and aren't
+init or class_init, GLib function attribute macros G_GNUC_PRINTF,
+G_GNUC_SCANF, and G_GNUC_FORMAT can optionally be included after the
+argument list.  Simply include an \'attr\' keyword and the C code to include
+in the file.  You have to include braces and anything inside the braces
+will be printed into the header file after the function declaration and
+before the trailing semicolon.  The braces themselves are not printed.
+For example:
+.nf
+
+  public void
+  print (self, const char *format (check null), ...)
+    attr {G_GNUC_PRINTF(2, 3)}
+
+.fi
+.PP
+This will produce a prototype which will generate a warning at compile
+time if the contents of the format argument (argument number 2) aren't
+consistent with the types and number of the subsequent variadic
+arguments (the first of which is argument number 3).  Only one \'attr\'
+keyword per method is allowed.
+If you have more than one attribute to include, you should
+put them all within the braces.
+Note that function attributes were aded in version 2.0.16.
+.PP
 .B "Error return:"
 .PP
 Methods which have a return value, there also has to be something
-returned if there is an error, such as if a precondition is not met.  The
-default is 0, casted to the type of the method.  If you need to return
-something else then you can specify an "onerror" keyword after the
-prototype and after that a number, a token (an identifier) or a bit of C
-code enclosed in braces {}.  The braces will not be printed into the
-output, they just delimit the string.  For example:
+returned if there is an error, such as if a precondition is not met.
+The default is 0, casted to the type of the method.  If you need to
+return something else then you can specify an \'onerror\' keyword after
+the prototype and any optional function attribute macros, and after
+that a number, a token (an identifier) or a bit of C code enclosed in
+braces {}.  The braces will not be printed into the output, they just
+delimit the string.  For example:
 .nf
 
   public void * get_something (self, int i (check >= 0)) onerror NULL {
@@ -635,6 +704,31 @@ initialization is taken care of for you by gob itself.  The init function
 should on the other hand be used whenever you need to construct or initialize
 anything in the object to put it into a sane state.
 .PP
+.B "Constructor, dispose, finalize methods:"
+.PP
+Since 2.0.16, you can also easily add code to the object's constructor,
+dispose, and finalize methods.  See GObject documentation on how these are
+run.  The code you add will be run before calling the parents function
+for dispose and finalize, and after the parent function for constructor.
+The syntax is just like init and class_init.
+For example:
+.nf
+
+  constructor (self) {
+       /* constructor method */
+  }
+
+  dispose (self) {
+       /* dispose method */
+  }
+
+  finalize (self) {
+       /* finalize method */
+  }
+
+.fi
+You can also just override those methods as usual, but the above is much easier and nearly as flexible.
+.PP
 .B "Virtual methods:"
 .PP
 Virtual methods are basically pointers in the class structure,
@@ -725,6 +819,11 @@ would do:
 
 .fi
 .PP
+To use BOXED in the signal arguments you need to tell gob which type of boxed
+argument you want to use.  For this you can just add BOXED_GTK_TYPE_STRING
+instead of BOXED.  For example BOXED_GTK_TYPE_TREE_ITER for GtkTreeIter.
+This works since version 2.0.13.
+.PP
 .B "Override methods:"
 .PP
 If you need to override some method (a signal or a virtual method
@@ -1003,6 +1102,66 @@ for the correct prototypes if you can\'t figure them out from the idl itself.
 Also note that the first argument is not "self", but the servant and you must
 use bonobo_object_from_servant function to get the actual object pointer.
 
+.SH DIRECT LIBGLADE SUPPORT
+.PP
+Gob can simplify writing a libglade class.  Just create a new object that
+derives from a GtkContainer widget.  Then use a "GladeXML" class flag
+with the glade file name, root widget and optional domain  as arguments
+between double quotes.  For example:
+.nf
+
+class My:Glade from Gtk:Window (GladeXML "gob-libglade.glade" "root")
+{
+  ....
+}
+
+.fi
+Note however that then "gob-libglade.glade" would have to be in the current
+directory.  You could specify a path, but that may not work for all
+installations.  You can replace the glade filename with a token to be used
+in the generated .c file and you can then have a macro with the filename,
+as follows:
+.nf
+
+class My:Glade from Gtk:Window (GladeXML GLADE_FILE "root")
+{
+  ....
+}
+
+.fi
+And somewhere in your header files you would have
+.nf
+
+#define GLADE_FILE "/path/to/file.glade"
+
+.fi
+
+You can declare widgets as data members by adding a 'GladeXML' to
+the definition.
+.nf
+
+private Gtk:Button * button1 GladeXML;
+
+.fi
+This will automatically set the "button1" from the GladeXML file.
+
+All signals created with glade are automatically connected if you defined
+those class methods in your class.  For example suppose in glade that
+we set the "connect" signal on button1 to go to on_button1_clicked, then
+in our gob file we can just write:
+.nf
+
+public void
+on_button1_clicked(self, GtkButton * button)
+{
+}
+
+.fi
+
+See the examples directory for a full example.  Note that this feature
+requires version at least 2.0.12.
+
+
 .SH IDENTIFIER CONFLICTS
 .PP
 Gob will need to define some local variables and functions in the generated
@@ -1109,7 +1268,7 @@ check for GOB2 in your configure.in file.  You can use the supplied m4 macro
 which will also check the version of gob.  Basically you include this:
 .nf
 
-  GOB2_CHECK(2.0.0)
+  GOB2_CHECK([2.0.0])
 
 .fi
 This will replace @GOB2@ in your makefiles with the full path of gob2.  Thus
@@ -1126,6 +1285,25 @@ include the generated .c and .h files into BUILT_SOURCES variable.  You
 have to include both the .gob and the .c and .h files in the SOURCES for your
 program.
 
+.SH PREVENTING SPURIOUS BUILDS
+.PP
+When nothing has changed you might not really want to rebuild everything and
+gob provides options --no-touch (since 2.0.13) and --no-touch-headers to avoid
+this.  When working with build systems such as automake you have to be more
+careful as just using those options can cause automake to get confused and you
+will need to use something like the following:
+.nf
+
+  foo_SOURCES = foo.gob foo.gob.stamp foo.c foo.h foo-private.h
+  BUILT_SOURCES = foo.gob.stamp
+  MAINTAINERCLEANFILES = foo.gob.stamp
+
+  %.gob.stamp: %.gob
+          @GOB2@ --no-touch $<
+          @touch $@
+
+.fi 
+
 .SH DEBUGGING
 .PP
 GOB does several things to make debugging the code easier.  First it adds