]> git.draconx.ca Git - gob-dx.git/blob - doc/gob.1.in
Release 0.90.3
[gob-dx.git] / doc / gob.1.in
1 .\"
2 .\" gob manual page
3 .\" (C) 1999 George Lebl <jirka@5z.com>
4 .\" 
5 .\" This manual page is covered by the terms of the GNU General
6 .\" Public License.  
7 .\"
8 .TH GOB 1 "GOB @VERSION@" 
9 .SH NAME
10 GOB \- The GTK+ Object Builder
11 .SH SYNOPSIS
12 .PP
13 .B gob
14 .SH DESCRIPTION
15 .PP
16 GTK+ Object Builder is a simple preprocessor for easily creating
17 GTK+ objects.  It does not parse any C code and ignores any C errors.  It
18 is in spirit similar to things like lex or yacc.
19
20 .SH TYPENAMES
21 .PP
22 Because we need to parse out different parts of the typename, 
23 sometimes you need to specify the typename with some special syntax.
24 Types are specified in capitalized form and words are separated by ':'.
25 The first word of the type (which can be empty) is the "namespace".  This
26 fact is for example used for the type checking macro.  For "Gtk:New:Button",
27 the macro will be GTK_IS_NEW_BUTTON.  This format of typenames is used in
28 the class declaration header and for method argument types.
29
30 .SH OUTPUT FILE NAMES
31 .PP
32 The filenames are created from the typename.  The words are
33 separated by '-' and all in lower case.  For example for an object named
34 "Gtk:New:Button", the files are gtk-new-button.c and gtk-new-button.h.
35
36 .SH INCLUDING NORMAL C CODE IN THE OUTPUT FILES
37 .PP
38 To include some code directly in the output C file begin with
39 '%{' on an empty line and end the code with a '%{' on an empty line.  To
40 put the code in the output header file, start the code with a '%h{'.
41 For example:
42 .nf
43
44   %h{
45   void somefunc(int i);
46   %}
47   %{
48   void somefunc(int i)
49   {
50           /* some code */
51   }
52   %}
53
54 .fi
55
56 .SH MAKING A NEW CLASS
57 .PP
58 The class header:
59 .PP
60 There can be only one class per input file.  Defining a class
61 is sort of like in Java, you define the class and write inline code
62 directly into the class definition.  To define a class you need to specify
63 the new object name and the name of the object from which it is derived
64 from, such as this "class <new type> from <parent type> { <class code> }".
65 For example:
66 .nf
67
68   class Gtk:New:Button from Gtk:Button {
69           <class code>
70   }
71
72 .fi
73 .PP
74 Data members:
75 .PP
76 There are three types of data members.  Two of them are normal
77 data numbers, and one is a virtual one, usually linked to a normal public
78 data member.  The two normal data members are public or private. They are
79 basically just copied into the object directly.  There is only one
80 identifier allowed per typename unlike in normal C.  Example:
81 .nf
82
83   public int i;
84   private GtkWidget *h;
85
86 .fi
87 .PP
88 The private members are not currently protected from outside use,
89 they are just marked by a comment in the header file, this will most likely
90 be somehow solved in some future version.
91 .PP
92 The third type is an argument type.  It is a named datamember which
93 is one of the features of the GTK+ object system.  You need to define a get
94 and a set handler.  They are fragments of C code that will be used to 
95 get the value or set the value of the argument.  Inside them you can use the
96 define ARG to which you assign the data or get the data.  You can also use
97 the identifier "self" as pointer to the object instance.  The type is
98 defined as one of the gtk type enums, but without the GTK_TYPE_ prefix.
99 For example:
100 .nf
101
102   public int height;
103   argument INT height set { self->height = ARG; } get { ARG = self->height; };
104
105 .fi
106 .PP
107 If you don't define a set or a get handler it will be a readonly
108 or a writeonly argument.  If you want to add extra argument flags, add
109 them into parenthesis after the argument keyword, separated by '|' and
110 without the GTK_ARG_ prefix.  For example:
111 .nf
112
113   public int height;
114   argument (CONSTRUCT) INT height get { ARG = self->height; };
115
116 .fi
117 .PP
118 Methods:
119 .PP
120 There is a whole array of possible methods.  The two normal,
121 "familiar" method types are private and public.  Public are defined as
122 normal functions with a prototype in the header file.  Private methods
123 are defined as static functions with prototypes at the top of the .c
124 file.  Then there are signal, virtual and override methods.  You can also
125 define init and init_class methods with a special definition if you want
126 to add code to the constructors or you can just leave them out.
127 .PP
128 Argument lists:
129 .PP
130 For all but the init and init_class methods, you use the
131 following syntax for arguments.  The first argument can be just "self",
132 which gob will translate into a pointer to the object instance.  The rest
133 of the arguments are very similar to normal C arguments.  If the
134 typename is an object pointer you should use the syntax defined above
135 with the words separated by ':'
136 .nf
137 <type> <argument id>
138 or
139 <type> <argument id> (check <list of checks>)
140 .fi
141 .PP
142 The checks are glib type preconditions, and can be the following:
143 "null", which tests pointers for being NULL, "type" which checks GTK+
144 object pointers for being the right type, "<test> <number>" which tests
145 numeric arguments for being a certain value.  The test can be a <,>,<=,>=
146 != or ==.  Example:
147 .nf
148   
149   public int foo(self, int h (check > 0 < 11), Gtk:Widget *w (check null type))
150
151 .fi
152 .PP
153 This will be the prototype of a function which has a self pointer
154 as the first argument, an integer argument which will be checked and has
155 to be more then 0 and less then 11, and a pointer to a GtkWidget object
156 instance and it is checked for being null and the type will also be
157 checked.
158 .PP
159 Error return:
160 .PP
161 Methods which have a return value, there also has to be something
162 returned if there is an error, such as if a precondition is not met.  The
163 default is 0, casted to the type of the method.  If you need to return
164 something else then you can specify an "onerror" keyword after the
165 prototype and after that a number, a token (an identifier) or a bit of C
166 code enclosed in braces {}.  The braces will not be printed into the
167 output, they just delimit the string.  For example
168 .nf
169
170   public void * get_something(self, int i (check >= 0)) onerror NULL {
171           ...
172   }
173
174 .fi
175 .PP
176 Virtual methods:
177 .PP
178 Virtual methods are basically pointers in the class structure,
179 so that one can override the method in derived methods.  They can be empty
180 (if you put ';' instead of the C code).  A wrapper will also be defined
181 which makes calling the methods he same as public methods.  This type of
182 method is just a little bit "slower" then normal functions, but not as
183 slow as signals.  You define them by using "virtual" keyword before the
184 prototype. If you put the keyword "private" right after the "virtual"
185 keyword, the wrapper will not be a public method, but a private one.
186 .PP
187 Signals:
188 .PP
189 Signals are methods to which the user can bind other handlers
190 and override the default handler.  The default handler is basically the
191 method body.  This is the most versatile and flexible type of a method
192 and also the slowest.  You need to specify a whole bunch of things when
193 you define a signal.  One thing is when the default handler will be run,
194 first or last.  You specify that by "first" or "last" right after the
195 "signal" keyword.  Then you need to define the gtk enum types (again
196 without the GTK_TYPE_ prefix).  For that you define the return types
197 and the types of arguments after the "self" pointer (not including the
198 "self" pointer).  You put it in the following syntax "<return type> (<list
199 of arguments>)".  If the return type is void, the type should be "NONE",
200 the same should be for the argument list.  The rest of the prototype is
201 the same as for other method types.  The body can also be empty, and
202 also there is a public method wrapper which you can use for calling the
203 signal just like a public method.  Example:
204 .nf
205
206   signal first INT(POINTER,INT)
207   int do_something(self, Gtk:Widget *w (check null type), int length)
208   {
209           ...
210   }
211   
212 or
213
214   signal last NONE(NONE) void foo(self);
215
216 .fi
217 .PP
218 If you don't want the wrapper that emits the signal to be public, you can
219 include the keyword "private" after the "signal" keyword. This will make
220 the wrapper a normal private method.
221 .PP
222 If you don't define a "first" or a "last", the default will be taken as
223 "last".
224 .PP
225 Override methods:
226 .PP
227 If you need to override some method (a signal or a virtual method
228 of some class in the parent tree of the new object), you can define and
229 override method.  After the "override" keyword, you should put the
230 typename of the class you are overriding a method from.  Other then that
231 it is the same as for other methods.  The "self" pointer in this case
232 should be the type of the method you are overriding so that you don't
233 get warnings during compilation.  Example:
234 .nf
235
236   override (Gtk:Container) void
237   add (Gtk:Container *self (check null type), Gtk:Widget *wid (check null type))
238   {
239           ...
240   }
241 .fi
242 .PP
243 Calling methods:
244 .PP
245 Inside the code, defines are set for the methods, so that you don't
246 have to type the class name before each call.  Example:
247 .nf
248
249   private int
250   foo(self)
251   {
252           return self->len;
253   }
254   
255   private int
256   bar(self,int i)
257   {
258           return foo(self) + i;
259   }
260
261 .fi
262 .PP
263 Making new objects:
264 .PP
265 You should define a new method which should be a normal public method.  Inside
266 this method, you can use the GET_NEW macro that is defined for you and that
267 will fetch a new object, so a fairly standard new method would look like:
268 .nf
269
270   public GtkWidget *
271   new(void) {
272           GtkObject *ret;
273           ret = GTK_OBJECT (GET_NEW);
274           return ret;
275   }
276
277 .fi
278
279 .SH BUGS
280 .PP
281 The generated header file is included as the first file in the .c file, no
282 matter what. This means that you will have to put things that need to be
283 included before that, into an %h{ } section.
284 .PP
285 Also the lexer does not actually parse the C code, so I'm sure that some corner
286 cases or maybe even some not so corner cases of C syntax might confuse gob
287 completely.  If you find any, send me the source that makes it go gaga and I'll
288 try to make the lexer try to handle it properly, but no promises.
289 .PP
290 Gob uses a lot of #define's so sometimes it can confuse your code.  One way
291 to make sure you don't get confused is not to use method names for absolutely
292 anything else since gob will use defines of the type:
293 .nf
294
295   #define method_name class_name_method_name
296
297 .fi
298 For your class code.
299
300 .SH AUTHOR
301 .PP
302 George Lebl <jirka@5z.com>