blob: f1dc634442ba20db69c70140a6a8202b63274919 [file] [log] [blame]
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001/**********************************************************
Guido van Rossum524b5881995-01-04 19:10:35 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
Guido van Rossumc7df79e1991-08-07 11:32:58 +00004
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
25/* FL module -- interface to Mark Overmars' FORMS Library. */
26
Guido van Rossumf1dc5661993-07-05 10:31:29 +000027/* This code works with FORMS version 2.2a.
28 FORMS can be ftp'ed from ftp.cs.ruu.nl (131.211.80.17), directory
29 /pub/SGI/FORMS. */
Guido van Rossumddc0d3e1991-12-10 13:56:42 +000030
Jack Jansen743db361992-08-13 14:13:11 +000031/* A half-hearted attempt has been made to allow programs using this
32 * module to exploit parallelism (through the threads module). No provisions
33 * have been made for multiple threads to use this module at the same time,
34 * though. So, a program with a forms thread and a non-forms thread will work
35 * fine but a program with two threads using forms will probably crash (unless
36 * the program takes precaution to ensure that only one thread can be in
37 * this module at any time). This will have to be fixed some time.
38 * (A fix will probably also have to synchronise with the gl module).
39 */
40
Guido van Rossumc7df79e1991-08-07 11:32:58 +000041#include "forms.h"
42
43#include "allobjects.h"
44#include "import.h"
45#include "modsupport.h"
46#include "structmember.h"
Guido van Rossumff4949e1992-08-05 19:58:53 +000047#include "ceval.h"
Guido van Rossumc7df79e1991-08-07 11:32:58 +000048
49/* Generic Forms Objects */
50
51typedef struct {
52 OB_HEAD
53 FL_OBJECT *ob_generic;
54 struct methodlist *ob_methods;
55 object *ob_callback;
56 object *ob_callback_arg;
57} genericobject;
58
Guido van Rossumb6775db1994-08-01 11:34:53 +000059staticforward typeobject GenericObjecttype;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000060
61#define is_genericobject(g) ((g)->ob_type == &GenericObjecttype)
62
63/* List of all objects (XXX this should be a hash table on address...) */
Guido van Rossumc7df79e1991-08-07 11:32:58 +000064
65static object *allgenerics = NULL;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000066static int nfreeslots = 0;
67
68/* Add an object to the list of known objects */
Guido van Rossumc7df79e1991-08-07 11:32:58 +000069
70static void
71knowgeneric(g)
72 genericobject *g;
73{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000074 int i, n;
75 /* Create the list if it doesn't already exist */
Guido van Rossumc7df79e1991-08-07 11:32:58 +000076 if (allgenerics == NULL) {
77 allgenerics = newlistobject(0);
78 if (allgenerics == NULL) {
79 err_clear();
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000080 return; /* Too bad, live without allgenerics... */
Guido van Rossumc7df79e1991-08-07 11:32:58 +000081 }
82 }
Guido van Rossum2df7bcc1991-10-20 20:18:26 +000083 if (nfreeslots > 0) {
84 /* Search the list for reusable slots (NULL items) */
85 /* XXX This can be made faster! */
86 n = getlistsize(allgenerics);
87 for (i = 0; i < n; i++) {
88 if (getlistitem(allgenerics, i) == NULL) {
89 INCREF(g);
90 setlistitem(allgenerics, i, (object *)g);
91 nfreeslots--;
92 return;
93 }
94 }
95 /* Strange... no free slots found... */
96 nfreeslots = 0;
97 }
98 /* No free entries, append new item to the end */
Guido van Rossumc7df79e1991-08-07 11:32:58 +000099 addlistitem(allgenerics, (object *)g);
100}
101
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000102/* Find an object in the list of known objects */
103
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000104static genericobject *
105findgeneric(generic)
106 FL_OBJECT *generic;
107{
108 int i, n;
109 genericobject *g;
110
111 if (allgenerics == NULL)
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000112 return NULL; /* No objects known yet */
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000113 n = getlistsize(allgenerics);
114 for (i = 0; i < n; i++) {
115 g = (genericobject *)getlistitem(allgenerics, i);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000116 if (g != NULL && g->ob_generic == generic)
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000117 return g;
118 }
119 return NULL; /* Unknown object */
120}
121
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000122/* Remove an object from the list of known objects */
123
124static void
125forgetgeneric(g)
126 genericobject *g;
127{
128 int i, n;
129
130 XDECREF(g->ob_callback);
131 g->ob_callback = NULL;
132 XDECREF(g->ob_callback_arg);
133 g->ob_callback_arg = NULL;
134 if (allgenerics == NULL)
135 return; /* No objects known yet */
136 n = getlistsize(allgenerics);
137 for (i = 0; i < n; i++) {
138 if (g == (genericobject *)getlistitem(allgenerics, i)) {
139 setlistitem(allgenerics, i, (object *)NULL);
140 nfreeslots++;
141 break;
142 }
143 }
144}
145
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000146/* Called when a form is about to be freed --
147 remove all the objects that we know about from it. */
148
149static void
150releaseobjects(form)
151 FL_FORM *form;
152{
153 int i, n;
154 genericobject *g;
155
156 if (allgenerics == NULL)
157 return; /* No objects known yet */
158 n = getlistsize(allgenerics);
159 for (i = 0; i < n; i++) {
160 g = (genericobject *)getlistitem(allgenerics, i);
161 if (g != NULL && g->ob_generic->form == form) {
162 fl_delete_object(g->ob_generic);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000163 /* The object is now unreachable for
164 do_forms and check_forms, so
165 delete it from the list of known objects */
166 XDECREF(g->ob_callback);
167 g->ob_callback = NULL;
168 XDECREF(g->ob_callback_arg);
169 g->ob_callback_arg = NULL;
170 setlistitem(allgenerics, i, (object *)NULL);
171 nfreeslots++;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000172 }
173 }
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000174}
175
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000176
177/* Methods of generic objects */
178
179static object *
180generic_set_call_back(g, args)
181 genericobject *g;
182 object *args;
183{
184 if (args == NULL) {
185 XDECREF(g->ob_callback);
186 XDECREF(g->ob_callback_arg);
187 g->ob_callback = NULL;
188 g->ob_callback_arg = NULL;
189 }
190 else {
191 if (!is_tupleobject(args) || gettuplesize(args) != 2) {
192 err_badarg();
193 return NULL;
194 }
195 XDECREF(g->ob_callback);
196 XDECREF(g->ob_callback_arg);
197 g->ob_callback = gettupleitem(args, 0);
198 INCREF(g->ob_callback);
199 g->ob_callback_arg = gettupleitem(args, 1);
200 INCREF(g->ob_callback_arg);
201 }
202 INCREF(None);
203 return None;
204}
205
206static object *
207generic_call(g, args, func)
208 genericobject *g;
209 object *args;
210 void (*func)(FL_OBJECT *);
211{
212 if (!getnoarg(args))
213 return NULL;
214 (*func)(g->ob_generic);
215 INCREF(None);
216 return None;
217}
218
219static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000220generic_delete_object(g, args)
221 genericobject *g;
222 object *args;
223{
224 object *res;
225 res = generic_call(g, args, fl_delete_object);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000226 if (res != NULL)
227 forgetgeneric(g);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000228 return res;
229}
230
231static object *
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000232generic_show_object(g, args)
233 genericobject *g;
234 object *args;
235{
236 return generic_call(g, args, fl_show_object);
237}
238
239static object *
240generic_hide_object(g, args)
241 genericobject *g;
242 object *args;
243{
244 return generic_call(g, args, fl_hide_object);
245}
246
247static object *
248generic_redraw_object(g, args)
249 genericobject *g;
250 object *args;
251{
252 return generic_call(g, args, fl_redraw_object);
253}
254
255static object *
256generic_freeze_object(g, args)
257 genericobject *g;
258 object *args;
259{
260 return generic_call(g, args, fl_freeze_object);
261}
262
263static object *
264generic_unfreeze_object(g, args)
265 genericobject *g;
266 object *args;
267{
268 return generic_call(g, args, fl_unfreeze_object);
269}
270
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000271static object *
272generic_activate_object(g, args)
273 genericobject *g;
274 object *args;
275{
276 return generic_call(g, args, fl_activate_object);
277}
278
279static object *
280generic_deactivate_object(g, args)
281 genericobject *g;
282 object *args;
283{
284 return generic_call(g, args, fl_deactivate_object);
285}
286
287static object *
288generic_set_object_shortcut(g, args)
289 genericobject *g;
290 object *args;
291{
292 char *str;
293 if (!getargs(args, "s", &str))
294 return NULL;
295 fl_set_object_shortcut(g->ob_generic, str);
296 INCREF(None);
297 return None;
298}
299
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000300static struct methodlist generic_methods[] = {
Guido van Rossumb6775db1994-08-01 11:34:53 +0000301 {"set_call_back", (method)generic_set_call_back},
302 {"delete_object", (method)generic_delete_object},
303 {"show_object", (method)generic_show_object},
304 {"hide_object", (method)generic_hide_object},
305 {"redraw_object", (method)generic_redraw_object},
306 {"freeze_object", (method)generic_freeze_object},
307 {"unfreeze_object", (method)generic_unfreeze_object},
308 {"activate_object", (method)generic_activate_object},
309 {"deactivate_object", (method)generic_deactivate_object},
310 {"set_object_shortcut", (method)generic_set_object_shortcut},
Guido van Rossum03747111991-08-08 12:10:01 +0000311 {NULL, NULL} /* sentinel */
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000312};
313
314static void
315generic_dealloc(g)
316 genericobject *g;
317{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000318 fl_free_object(g->ob_generic);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000319 XDECREF(g->ob_callback);
320 XDECREF(g->ob_callback_arg);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000321 DEL(g);
322}
323
324#define OFF(x) offsetof(FL_OBJECT, x)
325
326static struct memberlist generic_memberlist[] = {
327 {"objclass", T_INT, OFF(objclass), RO},
328 {"type", T_INT, OFF(type), RO},
329 {"boxtype", T_INT, OFF(boxtype)},
330 {"x", T_FLOAT, OFF(x)},
331 {"y", T_FLOAT, OFF(y)},
332 {"w", T_FLOAT, OFF(w)},
333 {"h", T_FLOAT, OFF(h)},
334 {"col1", T_INT, OFF(col1)},
335 {"col2", T_INT, OFF(col2)},
336 {"align", T_INT, OFF(align)},
337 {"lcol", T_INT, OFF(lcol)},
338 {"lsize", T_FLOAT, OFF(lsize)},
339 /* "label" is treated specially! */
340 {"lstyle", T_INT, OFF(lstyle)},
341 {"pushed", T_INT, OFF(pushed), RO},
342 {"focus", T_INT, OFF(focus), RO},
343 {"belowmouse", T_INT, OFF(belowmouse),RO},
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000344/* {"frozen", T_INT, OFF(frozen), RO}, */
Guido van Rossum7066dd71992-09-17 17:54:56 +0000345 {"active", T_INT, OFF(active)},
346 {"input", T_INT, OFF(input)},
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000347 {"visible", T_INT, OFF(visible), RO},
Guido van Rossum7066dd71992-09-17 17:54:56 +0000348 {"radio", T_INT, OFF(radio)},
349 {"automatic", T_INT, OFF(automatic)},
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000350 {NULL} /* Sentinel */
351};
352
Guido van Rossumd97f0481991-11-19 20:26:28 +0000353#undef OFF
354
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000355static object *
356generic_getattr(g, name)
357 genericobject *g;
358 char *name;
359{
360 object *meth;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000361
362 /* XXX Ought to special-case name "__methods__" */
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000363 if (g-> ob_methods) {
Guido van Rossum03747111991-08-08 12:10:01 +0000364 meth = findmethod(g->ob_methods, (object *)g, name);
365 if (meth != NULL) return meth;
366 err_clear();
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000367 }
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000368
369 meth = findmethod(generic_methods, (object *)g, name);
370 if (meth != NULL)
371 return meth;
372 err_clear();
373
374 /* "label" is an exception, getmember only works for char pointers,
375 not for char arrays */
376 if (strcmp(name, "label") == 0)
377 return newstringobject(g->ob_generic->label);
378
379 return getmember((char *)g->ob_generic, generic_memberlist, name);
380}
381
382static int
383generic_setattr(g, name, v)
384 genericobject *g;
385 char *name;
386 object *v;
387{
388 int ret;
389
390 if (v == NULL) {
391 err_setstr(TypeError, "can't delete forms object attributes");
Guido van Rossum3dd8c981992-06-03 17:07:49 +0000392 return -1;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000393 }
394
395 /* "label" is an exception: setmember doesn't set strings;
396 and FORMS wants you to call a function to set the label */
397 if (strcmp(name, "label") == 0) {
398 if (!is_stringobject(v)) {
399 err_setstr(TypeError, "label attr must be string");
Guido van Rossum3dd8c981992-06-03 17:07:49 +0000400 return -1;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000401 }
402 fl_set_object_label(g->ob_generic, getstringvalue(v));
403 return 0;
404 }
405
406 ret = setmember((char *)g->ob_generic, generic_memberlist, name, v);
407
408 /* Rather than calling all the various set_object_* functions,
409 we call fl_redraw_object here. This is sometimes redundant
410 but I doubt that's a big problem */
411 if (ret == 0)
412 fl_redraw_object(g->ob_generic);
413
414 return ret;
415}
416
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000417static object *
418generic_repr(g)
419 genericobject *g;
420{
421 char buf[100];
422 sprintf(buf, "<FORMS_object at %lx, objclass=%d>",
423 (long)g, g->ob_generic->objclass);
424 return newstringobject(buf);
425}
426
Guido van Rossumb6775db1994-08-01 11:34:53 +0000427static typeobject GenericObjecttype = {
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000428 OB_HEAD_INIT(&Typetype)
Guido van Rossumb6775db1994-08-01 11:34:53 +0000429 0, /*ob_size*/
430 "FORMS_object", /*tp_name*/
431 sizeof(genericobject), /*tp_size*/
432 0, /*tp_itemsize*/
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000433 /* methods */
Guido van Rossumb6775db1994-08-01 11:34:53 +0000434 (destructor)generic_dealloc, /*tp_dealloc*/
435 0, /*tp_print*/
436 (getattrfunc)generic_getattr, /*tp_getattr*/
437 (setattrfunc)generic_setattr, /*tp_setattr*/
438 0, /*tp_compare*/
439 (reprfunc)generic_repr, /*tp_repr*/
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000440};
441
442static object *
443newgenericobject(generic, methods)
444 FL_OBJECT *generic;
445 struct methodlist *methods;
446{
447 genericobject *g;
448 g = NEWOBJ(genericobject, &GenericObjecttype);
449 if (g == NULL)
450 return NULL;
451 g-> ob_generic = generic;
452 g->ob_methods = methods;
453 g->ob_callback = NULL;
454 g->ob_callback_arg = NULL;
455 knowgeneric(g);
456 return (object *)g;
457}
458
459/**********************************************************************/
460/* Some common calling sequences */
461
462/* void func (object, float) */
463static object *
464call_forms_INf (func, obj, args)
Guido van Rossumabe58351991-08-08 12:34:44 +0000465 void (*func)(FL_OBJECT *, float);
Guido van Rossum03747111991-08-08 12:10:01 +0000466 FL_OBJECT *obj;
467 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000468{
Guido van Rossum03747111991-08-08 12:10:01 +0000469 float parameter;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000470
Guido van Rossumfc58e581992-01-27 16:45:55 +0000471 if (!getargs(args, "f", &parameter)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000472
Guido van Rossum03747111991-08-08 12:10:01 +0000473 (*func) (obj, parameter);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000474
Guido van Rossum03747111991-08-08 12:10:01 +0000475 INCREF(None);
476 return None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000477}
478
479/* void func (object, float) */
480static object *
481call_forms_INfINf (func, obj, args)
Guido van Rossumabe58351991-08-08 12:34:44 +0000482 void (*func)(FL_OBJECT *, float, float);
Guido van Rossum03747111991-08-08 12:10:01 +0000483 FL_OBJECT *obj;
484 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000485{
Guido van Rossum03747111991-08-08 12:10:01 +0000486 float par1, par2;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000487
Guido van Rossumfc58e581992-01-27 16:45:55 +0000488 if (!getargs(args, "(ff)", &par1, &par2)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000489
Guido van Rossum03747111991-08-08 12:10:01 +0000490 (*func) (obj, par1, par2);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000491
Guido van Rossum03747111991-08-08 12:10:01 +0000492 INCREF(None);
493 return None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000494}
495
496/* void func (object, int) */
497static object *
498call_forms_INi (func, obj, args)
Guido van Rossumabe58351991-08-08 12:34:44 +0000499 void (*func)(FL_OBJECT *, int);
Guido van Rossum03747111991-08-08 12:10:01 +0000500 FL_OBJECT *obj;
501 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000502{
Guido van Rossum03747111991-08-08 12:10:01 +0000503 int parameter;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000504
Guido van Rossumfc58e581992-01-27 16:45:55 +0000505 if (!getintarg(args, &parameter)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000506
Guido van Rossum03747111991-08-08 12:10:01 +0000507 (*func) (obj, parameter);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000508
Guido van Rossum03747111991-08-08 12:10:01 +0000509 INCREF(None);
510 return None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000511}
512
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000513/* void func (object, char) */
514static object *
515call_forms_INc (func, obj, args)
516 void (*func)(FL_OBJECT *, int);
517 FL_OBJECT *obj;
518 object *args;
519{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000520 char *a;
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000521
Guido van Rossumfc58e581992-01-27 16:45:55 +0000522 if (!getstrarg(args, &a)) return NULL;
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000523
Guido van Rossumfc58e581992-01-27 16:45:55 +0000524 (*func) (obj, a[0]);
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000525
526 INCREF(None);
527 return None;
528}
529
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000530/* void func (object, string) */
531static object *
532call_forms_INstr (func, obj, args)
Guido van Rossumabe58351991-08-08 12:34:44 +0000533 void (*func)(FL_OBJECT *, char *);
Guido van Rossum03747111991-08-08 12:10:01 +0000534 FL_OBJECT *obj;
535 object *args;
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000536{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000537 char *a;
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000538
Guido van Rossumfc58e581992-01-27 16:45:55 +0000539 if (!getstrarg(args, &a)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000540
Guido van Rossumfc58e581992-01-27 16:45:55 +0000541 (*func) (obj, a);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000542
Guido van Rossum03747111991-08-08 12:10:01 +0000543 INCREF(None);
544 return None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000545}
546
547
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000548/* void func (object, int, string) */
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000549static object *
550call_forms_INiINstr (func, obj, args)
Guido van Rossumabe58351991-08-08 12:34:44 +0000551 void (*func)(FL_OBJECT *, int, char *);
Guido van Rossum03747111991-08-08 12:10:01 +0000552 FL_OBJECT *obj;
553 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000554{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000555 char *b;
556 int a;
Guido van Rossum03747111991-08-08 12:10:01 +0000557
Guido van Rossum234f9421993-06-17 12:35:49 +0000558 if (!getargs(args, "(is)", &a, &b)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +0000559
Guido van Rossumfc58e581992-01-27 16:45:55 +0000560 (*func) (obj, a, b);
Guido van Rossum03747111991-08-08 12:10:01 +0000561
562 INCREF(None);
563 return None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000564}
565
Guido van Rossum03747111991-08-08 12:10:01 +0000566#ifdef UNUSED
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000567/* void func (object, int, int) */
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000568static object *
569call_forms_INiINi (func, obj, args)
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000570 void (*func)(FL_OBJECT *, int, int);
Guido van Rossum03747111991-08-08 12:10:01 +0000571 FL_OBJECT *obj;
572 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000573{
Guido van Rossum03747111991-08-08 12:10:01 +0000574 int par1, par2;
575
Guido van Rossum234f9421993-06-17 12:35:49 +0000576 if (!getargs(args, "(ii)", &par1, &par2)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +0000577
578 (*func) (obj, par1, par2);
579
580 INCREF(None);
581 return None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000582}
Guido van Rossum03747111991-08-08 12:10:01 +0000583#endif
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000584
585/* int func (object) */
586static object *
587call_forms_Ri (func, obj, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000588 int (*func)(FL_OBJECT *);
589 FL_OBJECT *obj;
590 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000591{
Guido van Rossum03747111991-08-08 12:10:01 +0000592 int retval;
593
594 if (!getnoarg(args)) return NULL;
595
596 retval = (*func) (obj);
597
598 return newintobject ((long) retval);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000599}
600
601/* char * func (object) */
602static object *
603call_forms_Rstr (func, obj, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000604 char * (*func)(FL_OBJECT *);
605 FL_OBJECT *obj;
606 object *args;
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000607{
Guido van Rossum03747111991-08-08 12:10:01 +0000608 char *str;
609
Guido van Rossumfc58e581992-01-27 16:45:55 +0000610 if (!getnoarg(args)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +0000611
612 str = (*func) (obj);
613
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000614 if (str == NULL) {
615 INCREF(None);
616 return None;
617 }
Guido van Rossum03747111991-08-08 12:10:01 +0000618 return newstringobject (str);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000619}
620
621/* int func (object) */
622static object *
623call_forms_Rf (func, obj, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000624 float (*func)(FL_OBJECT *);
625 FL_OBJECT *obj;
626 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000627{
Guido van Rossum03747111991-08-08 12:10:01 +0000628 float retval;
629
630 if (!getnoarg(args)) return NULL;
631
632 retval = (*func) (obj);
633
634 return newfloatobject (retval);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000635}
636
637static object *
638call_forms_OUTfOUTf (func, obj, args)
Guido van Rossumabe58351991-08-08 12:34:44 +0000639 void (*func)(FL_OBJECT *, float *, float *);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000640 FL_OBJECT *obj;
641 object *args;
642{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000643 float f1, f2;
Guido van Rossum03747111991-08-08 12:10:01 +0000644
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000645 if (!getnoarg(args)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +0000646
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000647 (*func) (obj, &f1, &f2);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000648
Guido van Rossume5372401993-03-16 12:15:04 +0000649 return mkvalue("(ff)", f1, f2);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000650}
651
Guido van Rossum03747111991-08-08 12:10:01 +0000652#ifdef UNUSED
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000653static object *
654call_forms_OUTf (func, obj, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000655 void (*func)(FL_OBJECT *, float *);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000656 FL_OBJECT *obj;
657 object *args;
658{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000659 float f;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000660
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000661 if (!getnoarg(args)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000662
663 (*func) (obj, &f);
664
665 return newfloatobject (f);
666}
Guido van Rossum03747111991-08-08 12:10:01 +0000667#endif
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000668
669/**********************************************************************/
670/* Class : browser */
671
672static object *
673set_browser_topline(g, args)
674 genericobject *g;
675 object *args;
676{
Guido van Rossum03747111991-08-08 12:10:01 +0000677 return call_forms_INi (fl_set_browser_topline, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000678}
679
680static object *
681clear_browser(g, args)
682 genericobject *g;
683 object *args;
684{
Guido van Rossum03747111991-08-08 12:10:01 +0000685 return generic_call (g, args, fl_clear_browser);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000686}
687
688static object *
689add_browser_line (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000690 genericobject *g;
691 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000692{
Guido van Rossum03747111991-08-08 12:10:01 +0000693 return call_forms_INstr (fl_add_browser_line, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000694}
695
696static object *
697addto_browser (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000698 genericobject *g;
699 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000700{
Guido van Rossum03747111991-08-08 12:10:01 +0000701 return call_forms_INstr (fl_addto_browser, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000702}
703
704static object *
705insert_browser_line (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000706 genericobject *g;
707 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000708{
Guido van Rossum03747111991-08-08 12:10:01 +0000709 return call_forms_INiINstr (fl_insert_browser_line,
710 g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000711}
712
713static object *
714delete_browser_line (g, args)
715 genericobject *g;
716 object *args;
717{
Guido van Rossum03747111991-08-08 12:10:01 +0000718 return call_forms_INi (fl_delete_browser_line, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000719}
720
721static object *
722replace_browser_line (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000723 genericobject *g;
724 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000725{
Guido van Rossum03747111991-08-08 12:10:01 +0000726 return call_forms_INiINstr (fl_replace_browser_line,
727 g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000728}
729
730static object *
731get_browser_line(g, args)
732 genericobject *g;
733 object *args;
734{
735 int i;
736 char *str;
737
738 if (!getintarg(args, &i))
739 return NULL;
740
741 str = fl_get_browser_line (g->ob_generic, i);
742
Guido van Rossum2df7bcc1991-10-20 20:18:26 +0000743 if (str == NULL) {
744 INCREF(None);
745 return None;
746 }
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000747 return newstringobject (str);
748}
749
750static object *
751load_browser (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000752 genericobject *g;
753 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000754{
Guido van Rossumabe58351991-08-08 12:34:44 +0000755 /* XXX strictly speaking this is wrong since fl_load_browser
756 XXX returns int, not void */
Guido van Rossum03747111991-08-08 12:10:01 +0000757 return call_forms_INstr (fl_load_browser, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000758}
759
760static object *
761get_browser_maxline(g, args)
762 genericobject *g;
763 object *args;
764{
Guido van Rossum03747111991-08-08 12:10:01 +0000765 return call_forms_Ri (fl_get_browser_maxline, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000766}
767
768static object *
769select_browser_line (g, args)
770 genericobject *g;
771 object *args;
772{
Guido van Rossum03747111991-08-08 12:10:01 +0000773 return call_forms_INi (fl_select_browser_line, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000774}
775
776static object *
777deselect_browser_line (g, args)
778 genericobject *g;
779 object *args;
780{
Guido van Rossum03747111991-08-08 12:10:01 +0000781 return call_forms_INi (fl_deselect_browser_line, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000782}
783
784static object *
785deselect_browser (g, args)
786 genericobject *g;
787 object *args;
788{
Guido van Rossum03747111991-08-08 12:10:01 +0000789 return generic_call (g, args, fl_deselect_browser);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000790}
791
792static object *
793isselected_browser_line (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000794 genericobject *g;
795 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000796{
797 int i, j;
Guido van Rossum03747111991-08-08 12:10:01 +0000798
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000799 if (!getintarg(args, &i))
800 return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +0000801
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000802 j = fl_isselected_browser_line (g->ob_generic, i);
Guido van Rossum03747111991-08-08 12:10:01 +0000803
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000804 return newintobject (j);
805}
806
807static object *
808get_browser (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000809 genericobject *g;
810 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000811{
Guido van Rossum03747111991-08-08 12:10:01 +0000812 return call_forms_Ri (fl_get_browser, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000813}
814
815static object *
816set_browser_fontsize (g, args)
817 genericobject *g;
818 object *args;
819{
Guido van Rossum03747111991-08-08 12:10:01 +0000820 return call_forms_INf (fl_set_browser_fontsize, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000821}
822
823static object *
824set_browser_fontstyle (g, args)
825 genericobject *g;
826 object *args;
827{
Guido van Rossum03747111991-08-08 12:10:01 +0000828 return call_forms_INi (fl_set_browser_fontstyle, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000829}
830
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000831static object *
832set_browser_specialkey (g, args)
833 genericobject *g;
834 object *args;
835{
836 return call_forms_INc(fl_set_browser_specialkey, g-> ob_generic, args);
837}
838
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000839static struct methodlist browser_methods[] = {
Guido van Rossumb6775db1994-08-01 11:34:53 +0000840 {"set_browser_topline", (method)set_browser_topline},
841 {"clear_browser", (method)clear_browser},
842 {"add_browser_line", (method)add_browser_line},
843 {"addto_browser", (method)addto_browser},
844 {"insert_browser_line", (method)insert_browser_line},
845 {"delete_browser_line", (method)delete_browser_line},
846 {"replace_browser_line", (method)replace_browser_line},
847 {"get_browser_line", (method)get_browser_line},
848 {"load_browser", (method)load_browser},
849 {"get_browser_maxline", (method)get_browser_maxline},
850 {"select_browser_line", (method)select_browser_line},
851 {"deselect_browser_line", (method)deselect_browser_line},
852 {"deselect_browser", (method)deselect_browser},
853 {"isselected_browser_line", (method)isselected_browser_line},
854 {"get_browser", (method)get_browser},
855 {"set_browser_fontsize", (method)set_browser_fontsize},
856 {"set_browser_fontstyle", (method)set_browser_fontstyle},
857 {"set_browser_specialkey", (method)set_browser_specialkey},
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000858 {NULL, NULL} /* sentinel */
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000859};
860
861/* Class: button */
862
863static object *
864set_button(g, args)
865 genericobject *g;
866 object *args;
867{
Guido van Rossum03747111991-08-08 12:10:01 +0000868 return call_forms_INi (fl_set_button, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000869}
870
871static object *
872get_button(g, args)
873 genericobject *g;
874 object *args;
875{
Guido van Rossum03747111991-08-08 12:10:01 +0000876 return call_forms_Ri (fl_get_button, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000877}
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000878
879static object *
880get_button_numb(g, args)
881 genericobject *g;
882 object *args;
883{
884 return call_forms_Ri (fl_get_button_numb, g-> ob_generic, args);
885}
886
Guido van Rossumddc0d3e1991-12-10 13:56:42 +0000887static object *
888set_button_shortcut(g, args)
889 genericobject *g;
890 object *args;
891{
892 return call_forms_INstr (fl_set_button_shortcut, g-> ob_generic, args);
893}
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000894
895static struct methodlist button_methods[] = {
Guido van Rossumb6775db1994-08-01 11:34:53 +0000896 {"set_button", (method)set_button},
897 {"get_button", (method)get_button},
898 {"get_button_numb", (method)get_button_numb},
899 {"set_button_shortcut", (method)set_button_shortcut},
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000900 {NULL, NULL} /* sentinel */
901};
902
903/* Class: choice */
904
905static object *
906set_choice(g, args)
907 genericobject *g;
908 object *args;
909{
Guido van Rossum03747111991-08-08 12:10:01 +0000910 return call_forms_INi (fl_set_choice, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000911}
912
913static object *
914get_choice(g, args)
915 genericobject *g;
916 object *args;
917{
Guido van Rossum03747111991-08-08 12:10:01 +0000918 return call_forms_Ri (fl_get_choice, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000919}
920
921static object *
922clear_choice (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000923 genericobject *g;
924 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000925{
Guido van Rossum03747111991-08-08 12:10:01 +0000926 return generic_call (g, args, fl_clear_choice);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000927}
928
929static object *
930addto_choice (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000931 genericobject *g;
932 object *args;
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000933{
Guido van Rossum03747111991-08-08 12:10:01 +0000934 return call_forms_INstr (fl_addto_choice, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000935}
936
937static object *
938replace_choice (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000939 genericobject *g;
940 object *args;
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000941{
Guido van Rossum03747111991-08-08 12:10:01 +0000942 return call_forms_INiINstr (fl_replace_choice, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000943}
944
945static object *
946delete_choice (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000947 genericobject *g;
948 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000949{
Guido van Rossum03747111991-08-08 12:10:01 +0000950 return call_forms_INi (fl_delete_choice, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000951}
952
953static object *
954get_choice_text (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000955 genericobject *g;
956 object *args;
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +0000957{
Guido van Rossum03747111991-08-08 12:10:01 +0000958 return call_forms_Rstr (fl_get_choice_text, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000959}
960
961static object *
962set_choice_fontsize (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000963 genericobject *g;
964 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000965{
Guido van Rossum03747111991-08-08 12:10:01 +0000966 return call_forms_INf (fl_set_choice_fontsize, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000967}
968
969static object *
970set_choice_fontstyle (g, args)
Guido van Rossum03747111991-08-08 12:10:01 +0000971 genericobject *g;
972 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000973{
Guido van Rossum03747111991-08-08 12:10:01 +0000974 return call_forms_INi (fl_set_choice_fontstyle, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000975}
976
977static struct methodlist choice_methods[] = {
Guido van Rossumb6775db1994-08-01 11:34:53 +0000978 {"set_choice", (method)set_choice},
979 {"get_choice", (method)get_choice},
980 {"clear_choice", (method)clear_choice},
981 {"addto_choice", (method)addto_choice},
982 {"replace_choice", (method)replace_choice},
983 {"delete_choice", (method)delete_choice},
984 {"get_choice_text", (method)get_choice_text},
985 {"set_choice_fontsize", (method)set_choice_fontsize},
986 {"set_choice_fontstyle",(method)set_choice_fontstyle},
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000987 {NULL, NULL} /* sentinel */
988};
989
990/* Class : Clock */
991
992static object *
993get_clock(g, args)
994 genericobject *g;
995 object *args;
996{
997 int i0, i1, i2;
Guido van Rossumc7df79e1991-08-07 11:32:58 +0000998
999 if (!getnoarg(args))
1000 return NULL;
1001
1002 fl_get_clock (g->ob_generic, &i0, &i1, &i2);
1003
Guido van Rossume5372401993-03-16 12:15:04 +00001004 return mkvalue("(iii)", i0, i1, i2);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001005}
1006
1007static struct methodlist clock_methods[] = {
Guido van Rossumb6775db1994-08-01 11:34:53 +00001008 {"get_clock", (method)get_clock},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001009 {NULL, NULL} /* sentinel */
1010};
1011
1012/* CLass : Counters */
1013
1014static object *
1015get_counter_value(g, args)
1016 genericobject *g;
1017 object *args;
1018{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001019 return call_forms_Rf (fl_get_counter_value, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001020}
1021
1022static object *
1023set_counter_value (g, args)
1024 genericobject *g;
1025 object *args;
1026{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001027 return call_forms_INf (fl_set_counter_value, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001028}
1029
1030static object *
1031set_counter_precision (g, args)
1032 genericobject *g;
1033 object *args;
1034{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001035 return call_forms_INi (fl_set_counter_precision, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001036}
1037
1038static object *
1039set_counter_bounds (g, args)
1040 genericobject *g;
1041 object *args;
1042{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001043 return call_forms_INfINf (fl_set_counter_bounds, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001044}
1045
1046static object *
1047set_counter_step (g, args)
1048 genericobject *g;
1049 object *args;
1050{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001051 return call_forms_INfINf (fl_set_counter_step, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001052}
1053
1054static object *
1055set_counter_return (g, args)
1056 genericobject *g;
1057 object *args;
1058{
Guido van Rossum03747111991-08-08 12:10:01 +00001059 return call_forms_INi (fl_set_counter_return, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001060}
1061
1062static struct methodlist counter_methods[] = {
Guido van Rossumb6775db1994-08-01 11:34:53 +00001063 {"set_counter_value", (method)set_counter_value},
1064 {"get_counter_value", (method)get_counter_value},
1065 {"set_counter_bounds", (method)set_counter_bounds},
1066 {"set_counter_step", (method)set_counter_step},
1067 {"set_counter_precision", (method)set_counter_precision},
1068 {"set_counter_return", (method)set_counter_return},
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001069 {NULL, NULL} /* sentinel */
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001070};
1071
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001072
1073/* Class: Dials */
1074
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001075static object *
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001076get_dial_value(g, args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001077 genericobject *g;
1078 object *args;
1079{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001080 return call_forms_Rf (fl_get_dial_value, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001081}
1082
1083static object *
1084set_dial_value (g, args)
1085 genericobject *g;
1086 object *args;
1087{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001088 return call_forms_INf (fl_set_dial_value, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001089}
1090
1091static object *
1092set_dial_bounds (g, args)
1093 genericobject *g;
1094 object *args;
1095{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001096 return call_forms_INfINf (fl_set_dial_bounds, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001097}
1098
1099static object *
1100get_dial_bounds (g, args)
1101 genericobject *g;
1102 object *args;
1103{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001104 return call_forms_OUTfOUTf (fl_get_dial_bounds, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001105}
1106
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001107static object *
1108set_dial_step (g, args)
1109 genericobject *g;
1110 object *args;
1111{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001112 return call_forms_INf (fl_set_dial_step, g-> ob_generic, args);
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001113}
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001114
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001115static struct methodlist dial_methods[] = {
Guido van Rossumb6775db1994-08-01 11:34:53 +00001116 {"set_dial_value", (method)set_dial_value},
1117 {"get_dial_value", (method)get_dial_value},
1118 {"set_dial_bounds", (method)set_dial_bounds},
1119 {"get_dial_bounds", (method)get_dial_bounds},
1120 {"set_dial_step", (method)set_dial_step},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001121 {NULL, NULL} /* sentinel */
1122};
1123
1124/* Class : Input */
1125
1126static object *
1127set_input (g, args)
1128 genericobject *g;
1129 object *args;
1130{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001131 return call_forms_INstr (fl_set_input, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001132}
1133
1134static object *
1135get_input (g, args)
1136 genericobject *g;
1137 object *args;
1138{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001139 return call_forms_Rstr (fl_get_input, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001140}
1141
1142static object *
1143set_input_color (g, args)
1144 genericobject *g;
1145 object *args;
1146{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001147 return call_forms_INfINf (fl_set_input_color, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001148}
1149
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001150static object *
1151set_input_return (g, args)
1152 genericobject *g;
1153 object *args;
1154{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001155 return call_forms_INi (fl_set_input_return, g-> ob_generic, args);
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001156}
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001157
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001158static struct methodlist input_methods[] = {
Guido van Rossumb6775db1994-08-01 11:34:53 +00001159 {"set_input", (method)set_input},
1160 {"get_input", (method)get_input},
1161 {"set_input_color", (method)set_input_color},
1162 {"set_input_return", (method)set_input_return},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001163 {NULL, NULL} /* sentinel */
1164};
1165
1166
1167/* Class : Menu */
1168
1169static object *
1170set_menu (g, args)
1171 genericobject *g;
1172 object *args;
1173{
Guido van Rossumabe58351991-08-08 12:34:44 +00001174 return call_forms_INstr (fl_set_menu, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001175}
1176
1177static object *
1178get_menu (g, args)
1179 genericobject *g;
1180 object *args;
1181{
Guido van Rossumabe58351991-08-08 12:34:44 +00001182 /* XXX strictly speaking this is wrong since fl_get_menu
1183 XXX returns long, not int */
1184 return call_forms_Ri (fl_get_menu, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001185}
1186
1187static object *
Guido van Rossum8b17d6b1993-03-30 13:18:41 +00001188get_menu_text (g, args)
1189 genericobject *g;
1190 object *args;
1191{
1192 return call_forms_Rstr (fl_get_menu_text, g-> ob_generic, args);
1193}
1194
1195static object *
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001196addto_menu (g, args)
1197 genericobject *g;
1198 object *args;
1199{
Guido van Rossumabe58351991-08-08 12:34:44 +00001200 return call_forms_INstr (fl_addto_menu, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001201}
1202
1203static struct methodlist menu_methods[] = {
Guido van Rossumb6775db1994-08-01 11:34:53 +00001204 {"set_menu", (method)set_menu},
1205 {"get_menu", (method)get_menu},
1206 {"get_menu_text", (method)get_menu_text},
1207 {"addto_menu", (method)addto_menu},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001208 {NULL, NULL} /* sentinel */
1209};
1210
1211
1212/* Class: Sliders */
1213
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001214static object *
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001215get_slider_value(g, args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001216 genericobject *g;
1217 object *args;
1218{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001219 return call_forms_Rf (fl_get_slider_value, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001220}
1221
1222static object *
1223set_slider_value (g, args)
1224 genericobject *g;
1225 object *args;
1226{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001227 return call_forms_INf (fl_set_slider_value, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001228}
1229
1230static object *
1231set_slider_bounds (g, args)
1232 genericobject *g;
1233 object *args;
1234{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001235 return call_forms_INfINf (fl_set_slider_bounds, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001236}
1237
1238static object *
1239get_slider_bounds (g, args)
1240 genericobject *g;
1241 object *args;
1242{
1243 return call_forms_OUTfOUTf(fl_get_slider_bounds, g-> ob_generic, args);
1244}
1245
1246static object *
1247set_slider_return (g, args)
1248 genericobject *g;
1249 object *args;
1250{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001251 return call_forms_INf (fl_set_slider_return, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001252}
1253
1254static object *
1255set_slider_size (g, args)
1256 genericobject *g;
1257 object *args;
1258{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001259 return call_forms_INf (fl_set_slider_size, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001260}
1261
1262static object *
1263set_slider_precision (g, args)
1264 genericobject *g;
1265 object *args;
1266{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001267 return call_forms_INi (fl_set_slider_precision, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001268}
1269
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001270static object *
1271set_slider_step (g, args)
1272 genericobject *g;
1273 object *args;
1274{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001275 return call_forms_INf (fl_set_slider_step, g-> ob_generic, args);
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001276}
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00001277
1278
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001279static struct methodlist slider_methods[] = {
Guido van Rossumb6775db1994-08-01 11:34:53 +00001280 {"set_slider_value", (method)set_slider_value},
1281 {"get_slider_value", (method)get_slider_value},
1282 {"set_slider_bounds", (method)set_slider_bounds},
1283 {"get_slider_bounds", (method)get_slider_bounds},
1284 {"set_slider_return", (method)set_slider_return},
1285 {"set_slider_size", (method)set_slider_size},
1286 {"set_slider_precision",(method)set_slider_precision},
1287 {"set_slider_step", (method)set_slider_step},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001288 {NULL, NULL} /* sentinel */
1289};
1290
1291static object *
1292set_positioner_xvalue (g, args)
1293 genericobject *g;
1294 object *args;
1295{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001296 return call_forms_INf (fl_set_positioner_xvalue, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001297}
1298
1299static object *
1300set_positioner_xbounds (g, args)
1301 genericobject *g;
1302 object *args;
1303{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001304 return call_forms_INfINf (fl_set_positioner_xbounds,
1305 g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001306}
1307
1308static object *
1309set_positioner_yvalue (g, args)
1310 genericobject *g;
1311 object *args;
1312{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001313 return call_forms_INf (fl_set_positioner_yvalue, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001314}
1315
1316static object *
1317set_positioner_ybounds (g, args)
1318 genericobject *g;
1319 object *args;
1320{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001321 return call_forms_INfINf (fl_set_positioner_ybounds,
1322 g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001323}
1324
1325static object *
1326get_positioner_xvalue (g, args)
1327 genericobject *g;
1328 object *args;
1329{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001330 return call_forms_Rf (fl_get_positioner_xvalue, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001331}
1332
1333static object *
1334get_positioner_xbounds (g, args)
1335 genericobject *g;
1336 object *args;
1337{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001338 return call_forms_OUTfOUTf (fl_get_positioner_xbounds,
1339 g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001340}
1341
1342static object *
1343get_positioner_yvalue (g, args)
1344 genericobject *g;
1345 object *args;
1346{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001347 return call_forms_Rf (fl_get_positioner_yvalue, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001348}
1349
1350static object *
1351get_positioner_ybounds (g, args)
1352 genericobject *g;
1353 object *args;
1354{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001355 return call_forms_OUTfOUTf (fl_get_positioner_ybounds,
1356 g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001357}
1358
1359static struct methodlist positioner_methods[] = {
Guido van Rossumb6775db1994-08-01 11:34:53 +00001360 {"set_positioner_xvalue", (method)set_positioner_xvalue},
1361 {"set_positioner_yvalue", (method)set_positioner_yvalue},
1362 {"set_positioner_xbounds", (method)set_positioner_xbounds},
1363 {"set_positioner_ybounds", (method)set_positioner_ybounds},
1364 {"get_positioner_xvalue", (method)get_positioner_xvalue},
1365 {"get_positioner_yvalue", (method)get_positioner_yvalue},
1366 {"get_positioner_xbounds", (method)get_positioner_xbounds},
1367 {"get_positioner_ybounds", (method)get_positioner_ybounds},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001368 {NULL, NULL} /* sentinel */
1369};
1370
1371/* Class timer */
1372
1373static object *
1374set_timer (g, args)
1375 genericobject *g;
1376 object *args;
1377{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001378 return call_forms_INf (fl_set_timer, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001379}
1380
1381static object *
1382get_timer (g, args)
1383 genericobject *g;
1384 object *args;
1385{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001386 return call_forms_Rf (fl_get_timer, g-> ob_generic, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001387}
1388
1389static struct methodlist timer_methods[] = {
Guido van Rossumb6775db1994-08-01 11:34:53 +00001390 {"set_timer", (method)set_timer},
1391 {"get_timer", (method)get_timer},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001392 {NULL, NULL} /* sentinel */
1393};
1394
1395/* Form objects */
1396
1397typedef struct {
1398 OB_HEAD
1399 FL_FORM *ob_form;
1400} formobject;
1401
Guido van Rossumb6775db1994-08-01 11:34:53 +00001402staticforward typeobject Formtype;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001403
1404#define is_formobject(v) ((v)->ob_type == &Formtype)
1405
1406static object *
1407form_show_form(f, args)
1408 formobject *f;
1409 object *args;
1410{
1411 int place, border;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001412 char *name;
1413 if (!getargs(args, "(iis)", &place, &border, &name))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001414 return NULL;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001415 fl_show_form(f->ob_form, place, border, name);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001416 INCREF(None);
1417 return None;
1418}
1419
1420static object *
1421form_call(func, f, args)
1422 FL_FORM *f;
1423 object *args;
1424 void (*func)(FL_FORM *);
1425{
1426 if (!getnoarg(args)) return NULL;
1427
1428 (*func)(f);
1429
1430 INCREF(None);
1431 return None;
1432}
1433
1434static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001435form_call_INiINi(func, f, args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001436 FL_FORM *f;
1437 object *args;
1438 void (*func)(FL_FORM *, int, int);
1439{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001440 int a, b;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001441
Guido van Rossum234f9421993-06-17 12:35:49 +00001442 if (!getargs(args, "(ii)", &a, &b)) return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001443
1444 (*func)(f, a, b);
1445
1446 INCREF(None);
1447 return None;
1448}
1449
1450static object *
Guido van Rossumf1dc5661993-07-05 10:31:29 +00001451form_call_INfINf(func, f, args)
1452 FL_FORM *f;
1453 object *args;
1454 void (*func)(FL_FORM *, float, float);
1455{
1456 float a, b;
1457
1458 if (!getargs(args, "(ff)", &a, &b)) return NULL;
1459
1460 (*func)(f, a, b);
1461
1462 INCREF(None);
1463 return None;
1464}
1465
1466static object *
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001467form_hide_form(f, args)
1468 formobject *f;
1469 object *args;
1470{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001471 return form_call(fl_hide_form, f-> ob_form, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001472}
1473
1474static object *
1475form_redraw_form(f, args)
1476 formobject *f;
1477 object *args;
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001478{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001479 return form_call(fl_redraw_form, f-> ob_form, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001480}
1481
1482static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001483form_add_object(f, args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001484 formobject *f;
1485 object *args;
1486{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001487 genericobject *g;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001488 if (args == NULL || !is_genericobject(args)) {
1489 err_badarg();
1490 return NULL;
1491 }
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001492 g = (genericobject *)args;
1493 if (findgeneric(g->ob_generic) != NULL) {
1494 err_setstr(RuntimeError,
1495 "add_object of object already in a form");
1496 return NULL;
1497 }
1498 fl_add_object(f->ob_form, g->ob_generic);
1499 knowgeneric(g);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001500
1501 INCREF(None);
1502 return None;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001503}
1504
1505static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001506form_set_form_position(f, args)
1507 formobject *f;
1508 object *args;
1509{
1510 return form_call_INiINi(fl_set_form_position, f-> ob_form, args);
1511}
1512
1513static object *
Guido van Rossumf1dc5661993-07-05 10:31:29 +00001514form_set_form_size(f, args)
1515 formobject *f;
1516 object *args;
1517{
1518 return form_call_INiINi(fl_set_form_size, f-> ob_form, args);
1519}
1520
1521static object *
1522form_scale_form(f, args)
1523 formobject *f;
1524 object *args;
1525{
1526 return form_call_INfINf(fl_scale_form, f-> ob_form, args);
1527}
1528
1529static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001530generic_add_object(f, args, func, internal_methods)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001531 formobject *f;
1532 object *args;
1533 FL_OBJECT *(*func)(int, float, float, float, float, char*);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001534 struct methodlist *internal_methods;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001535{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001536 int type;
1537 float x, y, w, h;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001538 char *name;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001539 FL_OBJECT *obj;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001540
Guido van Rossumfc58e581992-01-27 16:45:55 +00001541 if (!getargs(args,"(iffffs)", &type,&x,&y,&w,&h,&name))
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001542 return NULL;
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001543
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001544 fl_addto_form (f-> ob_form);
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001545
Guido van Rossumfc58e581992-01-27 16:45:55 +00001546 obj = (*func) (type, x, y, w, h, name);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001547
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001548 fl_end_form();
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001549
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001550 if (obj == NULL) {
1551 err_nomem();
1552 return NULL;
1553 }
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001554
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001555 return newgenericobject (obj, internal_methods);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001556}
1557
1558static object *
1559form_add_button(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001560 formobject *f;
1561 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001562{
1563 return generic_add_object(f, args, fl_add_button, button_methods);
1564}
1565
1566static object *
1567form_add_lightbutton(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001568 formobject *f;
1569 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001570{
1571 return generic_add_object(f, args, fl_add_lightbutton, button_methods);
1572}
1573
1574static object *
1575form_add_roundbutton(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001576 formobject *f;
1577 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001578{
1579 return generic_add_object(f, args, fl_add_roundbutton, button_methods);
1580}
1581
1582static object *
1583form_add_menu (f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001584 formobject *f;
1585 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001586{
1587 return generic_add_object(f, args, fl_add_menu, menu_methods);
1588}
1589
1590static object *
1591form_add_slider(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001592 formobject *f;
1593 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001594{
1595 return generic_add_object(f, args, fl_add_slider, slider_methods);
1596}
1597
1598static object *
1599form_add_valslider(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001600 formobject *f;
1601 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001602{
1603 return generic_add_object(f, args, fl_add_valslider, slider_methods);
1604}
1605
1606static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001607form_add_dial(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001608 formobject *f;
1609 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001610{
1611 return generic_add_object(f, args, fl_add_dial, dial_methods);
1612}
1613
1614static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001615form_add_counter(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001616 formobject *f;
1617 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001618{
1619 return generic_add_object(f, args, fl_add_counter, counter_methods);
1620}
1621
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001622static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001623form_add_clock(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001624 formobject *f;
1625 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001626{
1627 return generic_add_object(f, args, fl_add_clock, clock_methods);
1628}
1629
1630static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001631form_add_box(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001632 formobject *f;
1633 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001634{
Guido van Rossum03747111991-08-08 12:10:01 +00001635 return generic_add_object(f, args, fl_add_box,
1636 (struct methodlist *)NULL);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001637}
1638
1639static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001640form_add_choice(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001641 formobject *f;
1642 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001643{
1644 return generic_add_object(f, args, fl_add_choice, choice_methods);
1645}
1646
1647static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001648form_add_browser(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001649 formobject *f;
1650 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001651{
1652 return generic_add_object(f, args, fl_add_browser, browser_methods);
1653}
1654
1655static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001656form_add_positioner(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001657 formobject *f;
1658 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001659{
1660 return generic_add_object(f, args, fl_add_positioner, positioner_methods);
1661}
1662
1663static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001664form_add_input(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001665 formobject *f;
1666 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001667{
1668 return generic_add_object(f, args, fl_add_input, input_methods);
1669}
1670
1671static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001672form_add_text(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001673 formobject *f;
1674 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001675{
Guido van Rossum03747111991-08-08 12:10:01 +00001676 return generic_add_object(f, args, fl_add_text,
1677 (struct methodlist *)NULL);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001678}
1679
1680static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001681form_add_timer(f, args)
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001682 formobject *f;
1683 object *args;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001684{
1685 return generic_add_object(f, args, fl_add_timer, timer_methods);
1686}
1687
1688static object *
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001689form_freeze_form(f, args)
1690 formobject *f;
1691 object *args;
1692{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001693 return form_call(fl_freeze_form, f-> ob_form, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001694}
1695
1696static object *
1697form_unfreeze_form(f, args)
1698 formobject *f;
1699 object *args;
1700{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001701 return form_call(fl_unfreeze_form, f-> ob_form, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001702}
1703
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001704static object *
1705form_activate_form(f, args)
1706 formobject *f;
1707 object *args;
1708{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001709 return form_call(fl_activate_form, f-> ob_form, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001710}
1711
1712static object *
1713form_deactivate_form(f, args)
1714 formobject *f;
1715 object *args;
1716{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001717 return form_call(fl_deactivate_form, f-> ob_form, args);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001718}
1719
Guido van Rossum75cc8981991-08-08 12:07:45 +00001720static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001721form_bgn_group(f, args)
Guido van Rossum03747111991-08-08 12:10:01 +00001722 formobject *f;
1723 object *args;
1724{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001725 FL_OBJECT *obj;
1726
1727 fl_addto_form(f-> ob_form);
1728 obj = fl_bgn_group();
1729 fl_end_form();
1730
1731 if (obj == NULL) {
1732 err_nomem();
1733 return NULL;
1734 }
1735
1736 return newgenericobject (obj, (struct methodlist *) NULL);
Guido van Rossum03747111991-08-08 12:10:01 +00001737}
1738
1739static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001740form_end_group(f, args)
Guido van Rossum03747111991-08-08 12:10:01 +00001741 formobject *f;
1742 object *args;
1743{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001744 fl_addto_form(f-> ob_form);
Guido van Rossum03747111991-08-08 12:10:01 +00001745 fl_end_group();
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001746 fl_end_form();
Guido van Rossum03747111991-08-08 12:10:01 +00001747 INCREF(None);
1748 return None;
1749}
1750
1751static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001752forms_find_first_or_last(func, f, args)
Guido van Rossum75cc8981991-08-08 12:07:45 +00001753 FL_OBJECT *(*func)(FL_FORM *, int, float, float);
Guido van Rossum03747111991-08-08 12:10:01 +00001754 formobject *f;
Guido van Rossum75cc8981991-08-08 12:07:45 +00001755 object *args;
1756{
1757 int type;
1758 float mx, my;
1759 FL_OBJECT *generic;
1760 genericobject *g;
1761
Guido van Rossumfc58e581992-01-27 16:45:55 +00001762 if (!getargs(args, "(iff)", &type, &mx, &my)) return NULL;
Guido van Rossum75cc8981991-08-08 12:07:45 +00001763
Guido van Rossum03747111991-08-08 12:10:01 +00001764 generic = (*func) (f-> ob_form, type, mx, my);
Guido van Rossum75cc8981991-08-08 12:07:45 +00001765
1766 if (generic == NULL)
1767 {
1768 INCREF(None);
1769 return None;
1770 }
1771
1772 g = findgeneric(generic);
1773 if (g == NULL) {
1774 err_setstr(RuntimeError,
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001775 "forms_find_{first|last} returns unknown object");
Guido van Rossum75cc8981991-08-08 12:07:45 +00001776 return NULL;
1777 }
1778 INCREF(g);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001779 return (object *) g;
Guido van Rossum75cc8981991-08-08 12:07:45 +00001780}
1781
1782static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001783form_find_first(f, args)
Guido van Rossum03747111991-08-08 12:10:01 +00001784 formobject *f;
Guido van Rossum75cc8981991-08-08 12:07:45 +00001785 object *args;
1786{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001787 return forms_find_first_or_last(fl_find_first, f, args);
Guido van Rossum75cc8981991-08-08 12:07:45 +00001788}
1789
1790static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001791form_find_last(f, args)
Guido van Rossum03747111991-08-08 12:10:01 +00001792 formobject *f;
Guido van Rossum75cc8981991-08-08 12:07:45 +00001793 object *args;
1794{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001795 return forms_find_first_or_last(fl_find_last, f, args);
Guido van Rossum75cc8981991-08-08 12:07:45 +00001796}
1797
Guido van Rossum7066dd71992-09-17 17:54:56 +00001798static object *
1799form_set_object_focus(f, args)
1800 formobject *f;
1801 object *args;
1802{
1803 genericobject *g;
1804 if (args == NULL || !is_genericobject(args)) {
1805 err_badarg();
1806 return NULL;
1807 }
1808 g = (genericobject *)args;
1809 fl_set_object_focus(f->ob_form, g->ob_generic);
1810 INCREF(None);
1811 return None;
1812}
1813
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001814static struct methodlist form_methods[] = {
1815/* adm */
Guido van Rossumb6775db1994-08-01 11:34:53 +00001816 {"show_form", (method)form_show_form},
1817 {"hide_form", (method)form_hide_form},
1818 {"redraw_form", (method)form_redraw_form},
1819 {"set_form_position", (method)form_set_form_position},
1820 {"set_form_size", (method)form_set_form_size},
1821 {"scale_form", (method)form_scale_form},
1822 {"freeze_form", (method)form_freeze_form},
1823 {"unfreeze_form", (method)form_unfreeze_form},
1824 {"activate_form", (method)form_activate_form},
1825 {"deactivate_form", (method)form_deactivate_form},
1826 {"bgn_group", (method)form_bgn_group},
1827 {"end_group", (method)form_end_group},
1828 {"find_first", (method)form_find_first},
1829 {"find_last", (method)form_find_last},
1830 {"set_object_focus", (method)form_set_object_focus},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001831
1832/* basic objects */
Guido van Rossumb6775db1994-08-01 11:34:53 +00001833 {"add_button", (method)form_add_button},
1834/* {"add_bitmap", (method)form_add_bitmap}, */
1835 {"add_lightbutton", (method)form_add_lightbutton},
1836 {"add_roundbutton", (method)form_add_roundbutton},
1837 {"add_menu", (method)form_add_menu},
1838 {"add_slider", (method)form_add_slider},
1839 {"add_positioner", (method)form_add_positioner},
1840 {"add_valslider", (method)form_add_valslider},
1841 {"add_dial", (method)form_add_dial},
1842 {"add_counter", (method)form_add_counter},
1843 {"add_box", (method)form_add_box},
1844 {"add_clock", (method)form_add_clock},
1845 {"add_choice", (method)form_add_choice},
1846 {"add_browser", (method)form_add_browser},
1847 {"add_input", (method)form_add_input},
1848 {"add_timer", (method)form_add_timer},
1849 {"add_text", (method)form_add_text},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001850 {NULL, NULL} /* sentinel */
1851};
1852
1853static void
1854form_dealloc(f)
1855 formobject *f;
1856{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001857 releaseobjects(f->ob_form);
Guido van Rossum336b5911992-04-08 11:16:25 +00001858 if (f->ob_form->visible)
1859 fl_hide_form(f->ob_form);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001860 fl_free_form(f->ob_form);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001861 DEL(f);
1862}
1863
Guido van Rossumd97f0481991-11-19 20:26:28 +00001864#define OFF(x) offsetof(FL_FORM, x)
1865
Guido van Rossum32db5e31991-11-12 15:43:18 +00001866static struct memberlist form_memberlist[] = {
1867 {"window", T_LONG, OFF(window), RO},
1868 {"w", T_FLOAT, OFF(w)},
1869 {"h", T_FLOAT, OFF(h)},
Guido van Rossum7066dd71992-09-17 17:54:56 +00001870 {"x", T_FLOAT, OFF(x), RO},
1871 {"y", T_FLOAT, OFF(y), RO},
Guido van Rossum32db5e31991-11-12 15:43:18 +00001872 {"deactivated", T_INT, OFF(deactivated)},
Guido van Rossum7066dd71992-09-17 17:54:56 +00001873 {"visible", T_INT, OFF(visible), RO},
1874 {"frozen", T_INT, OFF(frozen), RO},
Guido van Rossum32db5e31991-11-12 15:43:18 +00001875 {"doublebuf", T_INT, OFF(doublebuf)},
1876 {NULL} /* Sentinel */
1877};
1878
Guido van Rossumd97f0481991-11-19 20:26:28 +00001879#undef OFF
1880
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001881static object *
1882form_getattr(f, name)
1883 formobject *f;
1884 char *name;
1885{
Guido van Rossum32db5e31991-11-12 15:43:18 +00001886 object *meth;
1887
1888 meth = findmethod(form_methods, (object *)f, name);
1889 if (meth != NULL)
1890 return meth;
1891 err_clear();
1892 return getmember((char *)f->ob_form, form_memberlist, name);
1893}
1894
1895static int
1896form_setattr(f, name, v)
1897 formobject *f;
1898 char *name;
1899 object *v;
1900{
1901 int ret;
1902
1903 if (v == NULL) {
1904 err_setstr(TypeError, "can't delete form attributes");
Sjoerd Mullender93fcb9b1994-01-03 14:03:25 +00001905 return 0;
Guido van Rossum32db5e31991-11-12 15:43:18 +00001906 }
1907
1908 return setmember((char *)f->ob_form, form_memberlist, name, v);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001909}
1910
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00001911static object *
1912form_repr(f)
1913 formobject *f;
1914{
1915 char buf[100];
1916 sprintf(buf, "<FORMS_form at %lx, window=%ld>",
1917 (long)f, f->ob_form->window);
1918 return newstringobject(buf);
1919}
1920
Guido van Rossumb6775db1994-08-01 11:34:53 +00001921static typeobject Formtype = {
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001922 OB_HEAD_INIT(&Typetype)
Guido van Rossumb6775db1994-08-01 11:34:53 +00001923 0, /*ob_size*/
1924 "FORMS_form", /*tp_name*/
1925 sizeof(formobject), /*tp_size*/
1926 0, /*tp_itemsize*/
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001927 /* methods */
Guido van Rossumb6775db1994-08-01 11:34:53 +00001928 (destructor)form_dealloc, /*tp_dealloc*/
1929 0, /*tp_print*/
1930 (getattrfunc)form_getattr, /*tp_getattr*/
1931 (setattrfunc)form_setattr, /*tp_setattr*/
1932 0, /*tp_compare*/
1933 (reprfunc)form_repr, /*tp_repr*/
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001934};
1935
1936static object *
1937newformobject(form)
1938 FL_FORM *form;
1939{
1940 formobject *f;
1941 f = NEWOBJ(formobject, &Formtype);
1942 if (f == NULL)
1943 return NULL;
1944 f->ob_form = form;
1945 return (object *)f;
1946}
1947
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001948
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001949/* The "fl" module */
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00001950
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001951static object *
1952forms_make_form(dummy, args)
1953 object *dummy;
1954 object *args;
1955{
1956 int type;
1957 float w, h;
1958 FL_FORM *form;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001959 if (!getargs(args, "(iff)", &type, &w, &h))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001960 return NULL;
1961 form = fl_bgn_form(type, w, h);
1962 if (form == NULL) {
1963 /* XXX Actually, cannot happen! */
1964 err_nomem();
1965 return NULL;
1966 }
1967 fl_end_form();
1968 return newformobject(form);
1969}
1970
Guido van Rossum2bac4d31992-03-27 17:20:21 +00001971static object *
1972forms_activate_all_forms(f, args)
1973 object *f;
1974 object *args;
1975{
1976 fl_activate_all_forms();
1977 INCREF(None);
1978 return None;
1979}
1980
1981static object *
1982forms_deactivate_all_forms(f, args)
1983 object *f;
1984 object *args;
1985{
1986 fl_deactivate_all_forms();
1987 INCREF(None);
1988 return None;
1989}
1990
Guido van Rossumc7df79e1991-08-07 11:32:58 +00001991static object *my_event_callback = NULL;
1992
1993static object *
1994forms_set_event_call_back(dummy, args)
1995 object *dummy;
1996 object *args;
1997{
Guido van Rossumf6da4f61993-07-26 15:24:57 +00001998 if (args == None)
1999 args = NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002000 my_event_callback = args;
2001 XINCREF(args);
2002 INCREF(None);
2003 return None;
2004}
2005
2006static object *
2007forms_do_or_check_forms(dummy, args, func)
2008 object *dummy;
2009 object *args;
2010 FL_OBJECT *(*func)();
2011{
2012 FL_OBJECT *generic;
2013 genericobject *g;
2014 object *arg, *res;
2015
2016 if (!getnoarg(args))
2017 return NULL;
2018
2019 for (;;) {
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002020 BGN_SAVE
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002021 generic = (*func)();
Jack Jansen743db361992-08-13 14:13:11 +00002022 END_SAVE
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002023 if (generic == NULL) {
2024 INCREF(None);
2025 return None;
2026 }
2027 if (generic == FL_EVENT) {
2028 int dev;
2029 short val;
2030 if (my_event_callback == NULL)
Guido van Rossum7066dd71992-09-17 17:54:56 +00002031 return newintobject(-1L);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002032 dev = fl_qread(&val);
Guido van Rossume5372401993-03-16 12:15:04 +00002033 arg = mkvalue("(ih)", dev, val);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002034 if (arg == NULL)
2035 return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002036 res = call_object(my_event_callback, arg);
2037 XDECREF(res);
2038 DECREF(arg);
2039 if (res == NULL)
2040 return NULL; /* Callback raised exception */
2041 continue;
2042 }
2043 g = findgeneric(generic);
2044 if (g == NULL) {
Guido van Rossuma9e7dc11992-10-18 18:53:57 +00002045 /* Object not known to us (some dialogs cause this) */
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00002046 continue; /* Ignore it */
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002047 }
2048 if (g->ob_callback == NULL) {
2049 INCREF(g);
2050 return ((object *) g);
2051 }
Guido van Rossume5372401993-03-16 12:15:04 +00002052 arg = mkvalue("(OO)", (object *)g, g->ob_callback_arg);
2053 if (arg == NULL)
2054 return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002055 res = call_object(g->ob_callback, arg);
2056 XDECREF(res);
2057 DECREF(arg);
2058 if (res == NULL)
2059 return NULL; /* Callback raised exception */
2060 }
2061}
2062
2063static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002064forms_do_forms(dummy, args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002065 object *dummy;
2066 object *args;
2067{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002068 return forms_do_or_check_forms(dummy, args, fl_do_forms);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002069}
2070
2071static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002072forms_check_forms(dummy, args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002073 object *dummy;
2074 object *args;
2075{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002076 return forms_do_or_check_forms(dummy, args, fl_check_forms);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002077}
2078
Guido van Rossum7066dd71992-09-17 17:54:56 +00002079static object *
2080forms_do_only_forms(dummy, args)
2081 object *dummy;
2082 object *args;
2083{
2084 return forms_do_or_check_forms(dummy, args, fl_do_only_forms);
2085}
2086
2087static object *
2088forms_check_only_forms(dummy, args)
2089 object *dummy;
2090 object *args;
2091{
2092 return forms_do_or_check_forms(dummy, args, fl_check_only_forms);
2093}
2094
Guido van Rossum03747111991-08-08 12:10:01 +00002095#ifdef UNUSED
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002096static object *
2097fl_call(func, args)
2098 object *args;
2099 void (*func)();
2100{
2101 if (!getnoarg(args))
2102 return NULL;
2103 (*func)();
2104 INCREF(None);
2105 return None;
2106}
Guido van Rossum03747111991-08-08 12:10:01 +00002107#endif
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002108
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00002109static object *
2110forms_set_graphics_mode(dummy, args)
2111 object *dummy;
2112 object *args;
2113{
2114 int rgbmode, doublebuf;
2115
Guido van Rossum234f9421993-06-17 12:35:49 +00002116 if (!getargs(args, "(ii)", &rgbmode, &doublebuf))
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00002117 return NULL;
2118 fl_set_graphics_mode(rgbmode,doublebuf);
2119 INCREF(None);
2120 return None;
2121}
2122
2123static object *
2124forms_get_rgbmode(dummy, args)
2125 object *dummy;
2126 object *args;
2127{
Guido van Rossum7066dd71992-09-17 17:54:56 +00002128 extern int fl_rgbmode;
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00002129
2130 if (args != NULL) {
2131 err_badarg();
2132 return NULL;
2133 }
Guido van Rossum7066dd71992-09-17 17:54:56 +00002134 return newintobject((long)fl_rgbmode);
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00002135}
Guido van Rossum7066dd71992-09-17 17:54:56 +00002136
2137static object *
2138forms_show_errors(dummy, args)
2139 object *dummy;
2140 object *args;
2141{
2142 int show;
2143 if (!getargs(args, "i", &show))
2144 return NULL;
2145 fl_show_errors(show);
2146 INCREF(None);
2147 return None;
2148}
2149
2150static object *
2151forms_set_font_name(dummy, args)
2152 object *dummy;
2153 object *args;
2154{
2155 int numb;
2156 char *name;
2157 if (!getargs(args, "(is)", &numb, &name))
2158 return NULL;
2159 fl_set_font_name(numb, name);
2160 INCREF(None);
2161 return None;
2162}
2163
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00002164
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002165static object *
2166forms_qdevice(self, args)
2167 object *self;
2168 object *args;
2169{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002170 short arg1;
2171 if (!getargs(args, "h", &arg1))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002172 return NULL;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002173 fl_qdevice(arg1);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002174 INCREF(None);
2175 return None;
2176}
2177
2178static object *
2179forms_unqdevice(self, args)
2180 object *self;
2181 object *args;
2182{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002183 short arg1;
2184 if (!getargs(args, "h", &arg1))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002185 return NULL;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002186 fl_unqdevice(arg1);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002187 INCREF(None);
2188 return None;
2189}
2190
2191static object *
2192forms_isqueued(self, args)
2193 object *self;
2194 object *args;
2195{
Guido van Rossum03747111991-08-08 12:10:01 +00002196 long retval;
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002197 short arg1;
2198 if (!getargs(args, "h", &arg1))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002199 return NULL;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002200 retval = fl_isqueued(arg1);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002201
Guido van Rossum03747111991-08-08 12:10:01 +00002202 return newintobject(retval);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002203}
2204
2205static object *
2206forms_qtest(self, args)
2207 object *self;
2208 object *args;
2209{
2210 long retval;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002211 retval = fl_qtest();
Guido van Rossum03747111991-08-08 12:10:01 +00002212 return newintobject(retval);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002213}
2214
2215
2216static object *
2217forms_qread(self, args)
2218 object *self;
2219 object *args;
2220{
Guido van Rossume5372401993-03-16 12:15:04 +00002221 int dev;
2222 short val;
Jack Jansen743db361992-08-13 14:13:11 +00002223 BGN_SAVE
Guido van Rossume5372401993-03-16 12:15:04 +00002224 dev = fl_qread(&val);
Jack Jansen743db361992-08-13 14:13:11 +00002225 END_SAVE
Guido van Rossume5372401993-03-16 12:15:04 +00002226 return mkvalue("(ih)", dev, val);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002227}
2228
2229static object *
2230forms_qreset(self, args)
2231 object *self;
2232 object *args;
2233{
2234 if (!getnoarg(args)) return NULL;
2235
Guido van Rossum03747111991-08-08 12:10:01 +00002236 fl_qreset();
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002237 INCREF(None);
2238 return None;
2239}
2240
2241static object *
2242forms_qenter(self, args)
2243 object *self;
2244 object *args;
2245{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002246 short arg1, arg2;
2247 if (!getargs(args, "(hh)", &arg1, &arg2))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002248 return NULL;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002249 fl_qenter(arg1, arg2);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002250 INCREF(None);
2251 return None;
2252}
2253
2254static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002255forms_color(self, args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002256 object *self;
2257 object *args;
2258{
2259 int arg;
2260
2261 if (!getintarg(args, &arg)) return NULL;
2262
2263 fl_color((short) arg);
2264
2265 INCREF(None);
2266 return None;
2267}
2268
2269static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002270forms_mapcolor(self, args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002271 object *self;
2272 object *args;
2273{
2274 int arg0, arg1, arg2, arg3;
2275
Guido van Rossumfc58e581992-01-27 16:45:55 +00002276 if (!getargs(args, "(iiii)", &arg0, &arg1, &arg2, &arg3))
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002277 return NULL;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002278
2279 fl_mapcolor(arg0, (short) arg1, (short) arg2, (short) arg3);
2280
2281 INCREF(None);
2282 return None;
2283}
2284
2285static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002286forms_getmcolor(self, args)
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002287 object *self;
2288 object *args;
2289{
Guido van Rossum03747111991-08-08 12:10:01 +00002290 int arg;
2291 short r, g, b;
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002292
2293 if (!getintarg(args, &arg)) return NULL;
2294
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002295 fl_getmcolor(arg, &r, &g, &b);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002296
Guido van Rossume5372401993-03-16 12:15:04 +00002297 return mkvalue("(hhh)", r, g, b);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002298}
2299
2300static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002301forms_get_mouse(self, args)
Guido van Rossum75cc8981991-08-08 12:07:45 +00002302 object *self;
2303 object *args;
2304{
Guido van Rossume5372401993-03-16 12:15:04 +00002305 float x, y;
Guido van Rossum75cc8981991-08-08 12:07:45 +00002306
2307 if (!getnoarg(args)) return NULL;
2308
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002309 fl_get_mouse(&x, &y);
Guido van Rossum75cc8981991-08-08 12:07:45 +00002310
Guido van Rossume5372401993-03-16 12:15:04 +00002311 return mkvalue("(ff)", x, y);
Guido van Rossum75cc8981991-08-08 12:07:45 +00002312}
2313
2314static object *
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002315forms_tie(self, args)
2316 object *self;
2317 object *args;
2318{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002319 short arg1, arg2, arg3;
2320 if (!getargs(args, "(hhh)", &arg1, &arg2, &arg3))
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002321 return NULL;
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002322 fl_tie(arg1, arg2, arg3);
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002323 INCREF(None);
2324 return None;
2325}
2326
Guido van Rossum03747111991-08-08 12:10:01 +00002327static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002328forms_show_message(f, args)
Guido van Rossum2bac4d31992-03-27 17:20:21 +00002329 object *f;
2330 object *args;
Guido van Rossum03747111991-08-08 12:10:01 +00002331{
Guido van Rossumfc58e581992-01-27 16:45:55 +00002332 char *a, *b, *c;
Guido van Rossum03747111991-08-08 12:10:01 +00002333
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002334 if (!getargs(args, "(sss)", &a, &b, &c)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +00002335
Jack Jansen743db361992-08-13 14:13:11 +00002336 BGN_SAVE
Guido van Rossumfc58e581992-01-27 16:45:55 +00002337 fl_show_message(a, b, c);
Jack Jansen743db361992-08-13 14:13:11 +00002338 END_SAVE
Guido van Rossum03747111991-08-08 12:10:01 +00002339
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002340 INCREF(None);
Guido van Rossum03747111991-08-08 12:10:01 +00002341 return None;
2342}
2343
2344static object *
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00002345forms_show_choice(f, args)
Guido van Rossum2bac4d31992-03-27 17:20:21 +00002346 object *f;
2347 object *args;
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00002348{
2349 char *m1, *m2, *m3, *b1, *b2, *b3;
2350 int nb;
2351 char *format;
Guido van Rossum7066dd71992-09-17 17:54:56 +00002352 long rv;
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00002353
2354 if (args == NULL || !is_tupleobject(args)) {
2355 err_badarg();
2356 return NULL;
2357 }
2358 nb = gettuplesize(args) - 3;
2359 if (nb <= 0) {
2360 err_setstr(TypeError, "need at least one button label");
2361 return NULL;
2362 }
2363 if (is_intobject(gettupleitem(args, 3))) {
2364 err_setstr(TypeError,
2365 "'number-of-buttons' argument not needed");
2366 return NULL;
2367 }
2368 switch (nb) {
2369 case 1: format = "(ssss)"; break;
2370 case 2: format = "(sssss)"; break;
2371 case 3: format = "(ssssss)"; break;
2372 default:
2373 err_setstr(TypeError, "too many button labels");
2374 return NULL;
2375 }
2376
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002377 if (!getargs(args, format, &m1, &m2, &m3, &b1, &b2, &b3))
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00002378 return NULL;
2379
Jack Jansen743db361992-08-13 14:13:11 +00002380 BGN_SAVE
2381 rv = fl_show_choice(m1, m2, m3, nb, b1, b2, b3);
2382 END_SAVE
2383 return newintobject(rv);
Guido van Rossumb3a0e4c1992-03-23 18:20:54 +00002384}
2385
2386static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002387forms_show_question(f, args)
Guido van Rossum2bac4d31992-03-27 17:20:21 +00002388 object *f;
2389 object *args;
Guido van Rossum03747111991-08-08 12:10:01 +00002390{
Guido van Rossumfc58e581992-01-27 16:45:55 +00002391 int ret;
2392 char *a, *b, *c;
Guido van Rossum03747111991-08-08 12:10:01 +00002393
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002394 if (!getargs(args, "(sss)", &a, &b, &c)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +00002395
Jack Jansen743db361992-08-13 14:13:11 +00002396 BGN_SAVE
Guido van Rossumfc58e581992-01-27 16:45:55 +00002397 ret = fl_show_question(a, b, c);
Jack Jansen743db361992-08-13 14:13:11 +00002398 END_SAVE
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002399
2400 return newintobject((long) ret);
Guido van Rossum03747111991-08-08 12:10:01 +00002401}
2402
2403static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002404forms_show_input(f, args)
Guido van Rossum2bac4d31992-03-27 17:20:21 +00002405 object *f;
2406 object *args;
Guido van Rossum03747111991-08-08 12:10:01 +00002407{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002408 char *str;
Guido van Rossumfc58e581992-01-27 16:45:55 +00002409 char *a, *b;
Guido van Rossum03747111991-08-08 12:10:01 +00002410
Guido van Rossum234f9421993-06-17 12:35:49 +00002411 if (!getargs(args, "(ss)", &a, &b)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +00002412
Jack Jansen743db361992-08-13 14:13:11 +00002413 BGN_SAVE
Guido van Rossumfc58e581992-01-27 16:45:55 +00002414 str = fl_show_input(a, b);
Jack Jansen743db361992-08-13 14:13:11 +00002415 END_SAVE
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002416
2417 if (str == NULL) {
2418 INCREF(None);
2419 return None;
2420 }
2421 return newstringobject(str);
Guido van Rossum03747111991-08-08 12:10:01 +00002422}
2423
2424static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002425forms_file_selector(f, args)
Guido van Rossum2bac4d31992-03-27 17:20:21 +00002426 object *f;
2427 object *args;
Guido van Rossum03747111991-08-08 12:10:01 +00002428{
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002429 char *str;
Guido van Rossumfc58e581992-01-27 16:45:55 +00002430 char *a, *b, *c, *d;
Guido van Rossum03747111991-08-08 12:10:01 +00002431
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002432 if (!getargs(args, "(ssss)", &a, &b, &c, &d)) return NULL;
Guido van Rossum03747111991-08-08 12:10:01 +00002433
Jack Jansen743db361992-08-13 14:13:11 +00002434 BGN_SAVE
Guido van Rossumfc58e581992-01-27 16:45:55 +00002435 str = fl_show_file_selector(a, b, c, d);
Jack Jansen743db361992-08-13 14:13:11 +00002436 END_SAVE
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002437
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002438 if (str == NULL) {
2439 INCREF(None);
2440 return None;
2441 }
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002442 return newstringobject(str);
Guido van Rossum03747111991-08-08 12:10:01 +00002443}
2444
2445
2446static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002447forms_file_selector_func(args, func)
Guido van Rossum2bac4d31992-03-27 17:20:21 +00002448 object *args;
2449 char *(*func)();
Guido van Rossum03747111991-08-08 12:10:01 +00002450{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002451 char *str;
Guido van Rossum03747111991-08-08 12:10:01 +00002452
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002453 str = (*func) ();
2454
2455 if (str == NULL) {
2456 INCREF(None);
2457 return None;
2458 }
2459 return newstringobject(str);
Guido van Rossum03747111991-08-08 12:10:01 +00002460}
2461
2462static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002463forms_get_directory(f, args)
Guido van Rossum2bac4d31992-03-27 17:20:21 +00002464 object *f;
2465 object *args;
Guido van Rossum03747111991-08-08 12:10:01 +00002466{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002467 return forms_file_selector_func(args, fl_get_directory);
Guido van Rossum03747111991-08-08 12:10:01 +00002468}
2469
2470static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002471forms_get_pattern(f, args)
Guido van Rossum2bac4d31992-03-27 17:20:21 +00002472 object *f;
2473 object *args;
Guido van Rossum03747111991-08-08 12:10:01 +00002474{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002475 return forms_file_selector_func(args, fl_get_pattern);
Guido van Rossum03747111991-08-08 12:10:01 +00002476}
2477
2478static object *
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002479forms_get_filename(f, args)
Guido van Rossum2bac4d31992-03-27 17:20:21 +00002480 object *f;
2481 object *args;
Guido van Rossum03747111991-08-08 12:10:01 +00002482{
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002483 return forms_file_selector_func(args, fl_get_filename);
Guido van Rossum03747111991-08-08 12:10:01 +00002484}
2485
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002486static struct methodlist forms_methods[] = {
2487/* adm */
2488 {"make_form", forms_make_form},
Guido van Rossum2bac4d31992-03-27 17:20:21 +00002489 {"activate_all_forms", forms_activate_all_forms},
2490 {"deactivate_all_forms",forms_deactivate_all_forms},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002491/* gl support wrappers */
2492 {"qdevice", forms_qdevice},
2493 {"unqdevice", forms_unqdevice},
2494 {"isqueued", forms_isqueued},
2495 {"qtest", forms_qtest},
2496 {"qread", forms_qread},
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002497/* {"blkqread", forms_blkqread}, */
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002498 {"qreset", forms_qreset},
2499 {"qenter", forms_qenter},
Guido van Rossum03747111991-08-08 12:10:01 +00002500 {"get_mouse", forms_get_mouse},
2501 {"tie", forms_tie},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002502/* {"new_events", forms_new_events}, */
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002503 {"color", forms_color},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002504 {"mapcolor", forms_mapcolor},
2505 {"getmcolor", forms_getmcolor},
2506/* interaction */
2507 {"do_forms", forms_do_forms},
Guido van Rossuma9e7dc11992-10-18 18:53:57 +00002508 {"do_only_forms", forms_do_only_forms},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002509 {"check_forms", forms_check_forms},
Guido van Rossuma9e7dc11992-10-18 18:53:57 +00002510 {"check_only_forms", forms_check_only_forms},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002511 {"set_event_call_back", forms_set_event_call_back},
2512/* goodies */
Guido van Rossumaa7ca2d1992-09-03 20:37:02 +00002513 {"show_message", forms_show_message},
2514 {"show_question", forms_show_question},
2515 {"show_choice", forms_show_choice},
2516 {"show_input", forms_show_input},
2517 {"show_file_selector", forms_file_selector},
2518 {"file_selector", forms_file_selector}, /* BW compat */
2519 {"get_directory", forms_get_directory},
2520 {"get_pattern", forms_get_pattern},
2521 {"get_filename", forms_get_filename},
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00002522 {"set_graphics_mode", forms_set_graphics_mode},
2523 {"get_rgbmode", forms_get_rgbmode},
Guido van Rossum7066dd71992-09-17 17:54:56 +00002524 {"show_errors", forms_show_errors},
2525 {"set_font_name", forms_set_font_name},
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002526 {NULL, NULL} /* sentinel */
2527};
2528
2529void
2530initfl()
2531{
2532 initmodule("fl", forms_methods);
Guido van Rossum2df7bcc1991-10-20 20:18:26 +00002533 foreground();
Guido van Rossumddc0d3e1991-12-10 13:56:42 +00002534 fl_init();
Guido van Rossumc7df79e1991-08-07 11:32:58 +00002535}