improve treatment of multi-line replies, ignore empty lines
[python/dscho.git] / Modules / flmodule.c
blobf1dc634442ba20db69c70140a6a8202b63274919
1 /**********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* FL module -- interface to Mark Overmars' FORMS Library. */
27 /* 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. */
31 /* 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).
41 #include "forms.h"
43 #include "allobjects.h"
44 #include "import.h"
45 #include "modsupport.h"
46 #include "structmember.h"
47 #include "ceval.h"
49 /* Generic Forms Objects */
51 typedef 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;
59 staticforward typeobject GenericObjecttype;
61 #define is_genericobject(g) ((g)->ob_type == &GenericObjecttype)
63 /* List of all objects (XXX this should be a hash table on address...) */
65 static object *allgenerics = NULL;
66 static int nfreeslots = 0;
68 /* Add an object to the list of known objects */
70 static void
71 knowgeneric(g)
72 genericobject *g;
74 int i, n;
75 /* Create the list if it doesn't already exist */
76 if (allgenerics == NULL) {
77 allgenerics = newlistobject(0);
78 if (allgenerics == NULL) {
79 err_clear();
80 return; /* Too bad, live without allgenerics... */
83 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;
95 /* Strange... no free slots found... */
96 nfreeslots = 0;
98 /* No free entries, append new item to the end */
99 addlistitem(allgenerics, (object *)g);
102 /* Find an object in the list of known objects */
104 static genericobject *
105 findgeneric(generic)
106 FL_OBJECT *generic;
108 int i, n;
109 genericobject *g;
111 if (allgenerics == NULL)
112 return NULL; /* No objects known yet */
113 n = getlistsize(allgenerics);
114 for (i = 0; i < n; i++) {
115 g = (genericobject *)getlistitem(allgenerics, i);
116 if (g != NULL && g->ob_generic == generic)
117 return g;
119 return NULL; /* Unknown object */
122 /* Remove an object from the list of known objects */
124 static void
125 forgetgeneric(g)
126 genericobject *g;
128 int i, n;
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;
146 /* Called when a form is about to be freed --
147 remove all the objects that we know about from it. */
149 static void
150 releaseobjects(form)
151 FL_FORM *form;
153 int i, n;
154 genericobject *g;
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);
163 /* 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++;
177 /* Methods of generic objects */
179 static object *
180 generic_set_call_back(g, args)
181 genericobject *g;
182 object *args;
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;
190 else {
191 if (!is_tupleobject(args) || gettuplesize(args) != 2) {
192 err_badarg();
193 return NULL;
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);
202 INCREF(None);
203 return None;
206 static object *
207 generic_call(g, args, func)
208 genericobject *g;
209 object *args;
210 void (*func)(FL_OBJECT *);
212 if (!getnoarg(args))
213 return NULL;
214 (*func)(g->ob_generic);
215 INCREF(None);
216 return None;
219 static object *
220 generic_delete_object(g, args)
221 genericobject *g;
222 object *args;
224 object *res;
225 res = generic_call(g, args, fl_delete_object);
226 if (res != NULL)
227 forgetgeneric(g);
228 return res;
231 static object *
232 generic_show_object(g, args)
233 genericobject *g;
234 object *args;
236 return generic_call(g, args, fl_show_object);
239 static object *
240 generic_hide_object(g, args)
241 genericobject *g;
242 object *args;
244 return generic_call(g, args, fl_hide_object);
247 static object *
248 generic_redraw_object(g, args)
249 genericobject *g;
250 object *args;
252 return generic_call(g, args, fl_redraw_object);
255 static object *
256 generic_freeze_object(g, args)
257 genericobject *g;
258 object *args;
260 return generic_call(g, args, fl_freeze_object);
263 static object *
264 generic_unfreeze_object(g, args)
265 genericobject *g;
266 object *args;
268 return generic_call(g, args, fl_unfreeze_object);
271 static object *
272 generic_activate_object(g, args)
273 genericobject *g;
274 object *args;
276 return generic_call(g, args, fl_activate_object);
279 static object *
280 generic_deactivate_object(g, args)
281 genericobject *g;
282 object *args;
284 return generic_call(g, args, fl_deactivate_object);
287 static object *
288 generic_set_object_shortcut(g, args)
289 genericobject *g;
290 object *args;
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;
300 static struct methodlist generic_methods[] = {
301 {"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},
311 {NULL, NULL} /* sentinel */
314 static void
315 generic_dealloc(g)
316 genericobject *g;
318 fl_free_object(g->ob_generic);
319 XDECREF(g->ob_callback);
320 XDECREF(g->ob_callback_arg);
321 DEL(g);
324 #define OFF(x) offsetof(FL_OBJECT, x)
326 static 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},
344 /* {"frozen", T_INT, OFF(frozen), RO}, */
345 {"active", T_INT, OFF(active)},
346 {"input", T_INT, OFF(input)},
347 {"visible", T_INT, OFF(visible), RO},
348 {"radio", T_INT, OFF(radio)},
349 {"automatic", T_INT, OFF(automatic)},
350 {NULL} /* Sentinel */
353 #undef OFF
355 static object *
356 generic_getattr(g, name)
357 genericobject *g;
358 char *name;
360 object *meth;
362 /* XXX Ought to special-case name "__methods__" */
363 if (g-> ob_methods) {
364 meth = findmethod(g->ob_methods, (object *)g, name);
365 if (meth != NULL) return meth;
366 err_clear();
369 meth = findmethod(generic_methods, (object *)g, name);
370 if (meth != NULL)
371 return meth;
372 err_clear();
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);
379 return getmember((char *)g->ob_generic, generic_memberlist, name);
382 static int
383 generic_setattr(g, name, v)
384 genericobject *g;
385 char *name;
386 object *v;
388 int ret;
390 if (v == NULL) {
391 err_setstr(TypeError, "can't delete forms object attributes");
392 return -1;
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");
400 return -1;
402 fl_set_object_label(g->ob_generic, getstringvalue(v));
403 return 0;
406 ret = setmember((char *)g->ob_generic, generic_memberlist, name, v);
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);
414 return ret;
417 static object *
418 generic_repr(g)
419 genericobject *g;
421 char buf[100];
422 sprintf(buf, "<FORMS_object at %lx, objclass=%d>",
423 (long)g, g->ob_generic->objclass);
424 return newstringobject(buf);
427 static typeobject GenericObjecttype = {
428 OB_HEAD_INIT(&Typetype)
429 0, /*ob_size*/
430 "FORMS_object", /*tp_name*/
431 sizeof(genericobject), /*tp_size*/
432 0, /*tp_itemsize*/
433 /* methods */
434 (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*/
442 static object *
443 newgenericobject(generic, methods)
444 FL_OBJECT *generic;
445 struct methodlist *methods;
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;
459 /**********************************************************************/
460 /* Some common calling sequences */
462 /* void func (object, float) */
463 static object *
464 call_forms_INf (func, obj, args)
465 void (*func)(FL_OBJECT *, float);
466 FL_OBJECT *obj;
467 object *args;
469 float parameter;
471 if (!getargs(args, "f", &parameter)) return NULL;
473 (*func) (obj, parameter);
475 INCREF(None);
476 return None;
479 /* void func (object, float) */
480 static object *
481 call_forms_INfINf (func, obj, args)
482 void (*func)(FL_OBJECT *, float, float);
483 FL_OBJECT *obj;
484 object *args;
486 float par1, par2;
488 if (!getargs(args, "(ff)", &par1, &par2)) return NULL;
490 (*func) (obj, par1, par2);
492 INCREF(None);
493 return None;
496 /* void func (object, int) */
497 static object *
498 call_forms_INi (func, obj, args)
499 void (*func)(FL_OBJECT *, int);
500 FL_OBJECT *obj;
501 object *args;
503 int parameter;
505 if (!getintarg(args, &parameter)) return NULL;
507 (*func) (obj, parameter);
509 INCREF(None);
510 return None;
513 /* void func (object, char) */
514 static object *
515 call_forms_INc (func, obj, args)
516 void (*func)(FL_OBJECT *, int);
517 FL_OBJECT *obj;
518 object *args;
520 char *a;
522 if (!getstrarg(args, &a)) return NULL;
524 (*func) (obj, a[0]);
526 INCREF(None);
527 return None;
530 /* void func (object, string) */
531 static object *
532 call_forms_INstr (func, obj, args)
533 void (*func)(FL_OBJECT *, char *);
534 FL_OBJECT *obj;
535 object *args;
537 char *a;
539 if (!getstrarg(args, &a)) return NULL;
541 (*func) (obj, a);
543 INCREF(None);
544 return None;
548 /* void func (object, int, string) */
549 static object *
550 call_forms_INiINstr (func, obj, args)
551 void (*func)(FL_OBJECT *, int, char *);
552 FL_OBJECT *obj;
553 object *args;
555 char *b;
556 int a;
558 if (!getargs(args, "(is)", &a, &b)) return NULL;
560 (*func) (obj, a, b);
562 INCREF(None);
563 return None;
566 #ifdef UNUSED
567 /* void func (object, int, int) */
568 static object *
569 call_forms_INiINi (func, obj, args)
570 void (*func)(FL_OBJECT *, int, int);
571 FL_OBJECT *obj;
572 object *args;
574 int par1, par2;
576 if (!getargs(args, "(ii)", &par1, &par2)) return NULL;
578 (*func) (obj, par1, par2);
580 INCREF(None);
581 return None;
583 #endif
585 /* int func (object) */
586 static object *
587 call_forms_Ri (func, obj, args)
588 int (*func)(FL_OBJECT *);
589 FL_OBJECT *obj;
590 object *args;
592 int retval;
594 if (!getnoarg(args)) return NULL;
596 retval = (*func) (obj);
598 return newintobject ((long) retval);
601 /* char * func (object) */
602 static object *
603 call_forms_Rstr (func, obj, args)
604 char * (*func)(FL_OBJECT *);
605 FL_OBJECT *obj;
606 object *args;
608 char *str;
610 if (!getnoarg(args)) return NULL;
612 str = (*func) (obj);
614 if (str == NULL) {
615 INCREF(None);
616 return None;
618 return newstringobject (str);
621 /* int func (object) */
622 static object *
623 call_forms_Rf (func, obj, args)
624 float (*func)(FL_OBJECT *);
625 FL_OBJECT *obj;
626 object *args;
628 float retval;
630 if (!getnoarg(args)) return NULL;
632 retval = (*func) (obj);
634 return newfloatobject (retval);
637 static object *
638 call_forms_OUTfOUTf (func, obj, args)
639 void (*func)(FL_OBJECT *, float *, float *);
640 FL_OBJECT *obj;
641 object *args;
643 float f1, f2;
645 if (!getnoarg(args)) return NULL;
647 (*func) (obj, &f1, &f2);
649 return mkvalue("(ff)", f1, f2);
652 #ifdef UNUSED
653 static object *
654 call_forms_OUTf (func, obj, args)
655 void (*func)(FL_OBJECT *, float *);
656 FL_OBJECT *obj;
657 object *args;
659 float f;
661 if (!getnoarg(args)) return NULL;
663 (*func) (obj, &f);
665 return newfloatobject (f);
667 #endif
669 /**********************************************************************/
670 /* Class : browser */
672 static object *
673 set_browser_topline(g, args)
674 genericobject *g;
675 object *args;
677 return call_forms_INi (fl_set_browser_topline, g-> ob_generic, args);
680 static object *
681 clear_browser(g, args)
682 genericobject *g;
683 object *args;
685 return generic_call (g, args, fl_clear_browser);
688 static object *
689 add_browser_line (g, args)
690 genericobject *g;
691 object *args;
693 return call_forms_INstr (fl_add_browser_line, g-> ob_generic, args);
696 static object *
697 addto_browser (g, args)
698 genericobject *g;
699 object *args;
701 return call_forms_INstr (fl_addto_browser, g-> ob_generic, args);
704 static object *
705 insert_browser_line (g, args)
706 genericobject *g;
707 object *args;
709 return call_forms_INiINstr (fl_insert_browser_line,
710 g-> ob_generic, args);
713 static object *
714 delete_browser_line (g, args)
715 genericobject *g;
716 object *args;
718 return call_forms_INi (fl_delete_browser_line, g-> ob_generic, args);
721 static object *
722 replace_browser_line (g, args)
723 genericobject *g;
724 object *args;
726 return call_forms_INiINstr (fl_replace_browser_line,
727 g-> ob_generic, args);
730 static object *
731 get_browser_line(g, args)
732 genericobject *g;
733 object *args;
735 int i;
736 char *str;
738 if (!getintarg(args, &i))
739 return NULL;
741 str = fl_get_browser_line (g->ob_generic, i);
743 if (str == NULL) {
744 INCREF(None);
745 return None;
747 return newstringobject (str);
750 static object *
751 load_browser (g, args)
752 genericobject *g;
753 object *args;
755 /* XXX strictly speaking this is wrong since fl_load_browser
756 XXX returns int, not void */
757 return call_forms_INstr (fl_load_browser, g-> ob_generic, args);
760 static object *
761 get_browser_maxline(g, args)
762 genericobject *g;
763 object *args;
765 return call_forms_Ri (fl_get_browser_maxline, g-> ob_generic, args);
768 static object *
769 select_browser_line (g, args)
770 genericobject *g;
771 object *args;
773 return call_forms_INi (fl_select_browser_line, g-> ob_generic, args);
776 static object *
777 deselect_browser_line (g, args)
778 genericobject *g;
779 object *args;
781 return call_forms_INi (fl_deselect_browser_line, g-> ob_generic, args);
784 static object *
785 deselect_browser (g, args)
786 genericobject *g;
787 object *args;
789 return generic_call (g, args, fl_deselect_browser);
792 static object *
793 isselected_browser_line (g, args)
794 genericobject *g;
795 object *args;
797 int i, j;
799 if (!getintarg(args, &i))
800 return NULL;
802 j = fl_isselected_browser_line (g->ob_generic, i);
804 return newintobject (j);
807 static object *
808 get_browser (g, args)
809 genericobject *g;
810 object *args;
812 return call_forms_Ri (fl_get_browser, g-> ob_generic, args);
815 static object *
816 set_browser_fontsize (g, args)
817 genericobject *g;
818 object *args;
820 return call_forms_INf (fl_set_browser_fontsize, g-> ob_generic, args);
823 static object *
824 set_browser_fontstyle (g, args)
825 genericobject *g;
826 object *args;
828 return call_forms_INi (fl_set_browser_fontstyle, g-> ob_generic, args);
831 static object *
832 set_browser_specialkey (g, args)
833 genericobject *g;
834 object *args;
836 return call_forms_INc(fl_set_browser_specialkey, g-> ob_generic, args);
839 static struct methodlist browser_methods[] = {
840 {"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},
858 {NULL, NULL} /* sentinel */
861 /* Class: button */
863 static object *
864 set_button(g, args)
865 genericobject *g;
866 object *args;
868 return call_forms_INi (fl_set_button, g-> ob_generic, args);
871 static object *
872 get_button(g, args)
873 genericobject *g;
874 object *args;
876 return call_forms_Ri (fl_get_button, g-> ob_generic, args);
879 static object *
880 get_button_numb(g, args)
881 genericobject *g;
882 object *args;
884 return call_forms_Ri (fl_get_button_numb, g-> ob_generic, args);
887 static object *
888 set_button_shortcut(g, args)
889 genericobject *g;
890 object *args;
892 return call_forms_INstr (fl_set_button_shortcut, g-> ob_generic, args);
895 static struct methodlist button_methods[] = {
896 {"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},
900 {NULL, NULL} /* sentinel */
903 /* Class: choice */
905 static object *
906 set_choice(g, args)
907 genericobject *g;
908 object *args;
910 return call_forms_INi (fl_set_choice, g-> ob_generic, args);
913 static object *
914 get_choice(g, args)
915 genericobject *g;
916 object *args;
918 return call_forms_Ri (fl_get_choice, g-> ob_generic, args);
921 static object *
922 clear_choice (g, args)
923 genericobject *g;
924 object *args;
926 return generic_call (g, args, fl_clear_choice);
929 static object *
930 addto_choice (g, args)
931 genericobject *g;
932 object *args;
934 return call_forms_INstr (fl_addto_choice, g-> ob_generic, args);
937 static object *
938 replace_choice (g, args)
939 genericobject *g;
940 object *args;
942 return call_forms_INiINstr (fl_replace_choice, g-> ob_generic, args);
945 static object *
946 delete_choice (g, args)
947 genericobject *g;
948 object *args;
950 return call_forms_INi (fl_delete_choice, g-> ob_generic, args);
953 static object *
954 get_choice_text (g, args)
955 genericobject *g;
956 object *args;
958 return call_forms_Rstr (fl_get_choice_text, g-> ob_generic, args);
961 static object *
962 set_choice_fontsize (g, args)
963 genericobject *g;
964 object *args;
966 return call_forms_INf (fl_set_choice_fontsize, g-> ob_generic, args);
969 static object *
970 set_choice_fontstyle (g, args)
971 genericobject *g;
972 object *args;
974 return call_forms_INi (fl_set_choice_fontstyle, g-> ob_generic, args);
977 static struct methodlist choice_methods[] = {
978 {"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},
987 {NULL, NULL} /* sentinel */
990 /* Class : Clock */
992 static object *
993 get_clock(g, args)
994 genericobject *g;
995 object *args;
997 int i0, i1, i2;
999 if (!getnoarg(args))
1000 return NULL;
1002 fl_get_clock (g->ob_generic, &i0, &i1, &i2);
1004 return mkvalue("(iii)", i0, i1, i2);
1007 static struct methodlist clock_methods[] = {
1008 {"get_clock", (method)get_clock},
1009 {NULL, NULL} /* sentinel */
1012 /* CLass : Counters */
1014 static object *
1015 get_counter_value(g, args)
1016 genericobject *g;
1017 object *args;
1019 return call_forms_Rf (fl_get_counter_value, g-> ob_generic, args);
1022 static object *
1023 set_counter_value (g, args)
1024 genericobject *g;
1025 object *args;
1027 return call_forms_INf (fl_set_counter_value, g-> ob_generic, args);
1030 static object *
1031 set_counter_precision (g, args)
1032 genericobject *g;
1033 object *args;
1035 return call_forms_INi (fl_set_counter_precision, g-> ob_generic, args);
1038 static object *
1039 set_counter_bounds (g, args)
1040 genericobject *g;
1041 object *args;
1043 return call_forms_INfINf (fl_set_counter_bounds, g-> ob_generic, args);
1046 static object *
1047 set_counter_step (g, args)
1048 genericobject *g;
1049 object *args;
1051 return call_forms_INfINf (fl_set_counter_step, g-> ob_generic, args);
1054 static object *
1055 set_counter_return (g, args)
1056 genericobject *g;
1057 object *args;
1059 return call_forms_INi (fl_set_counter_return, g-> ob_generic, args);
1062 static struct methodlist counter_methods[] = {
1063 {"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},
1069 {NULL, NULL} /* sentinel */
1073 /* Class: Dials */
1075 static object *
1076 get_dial_value(g, args)
1077 genericobject *g;
1078 object *args;
1080 return call_forms_Rf (fl_get_dial_value, g-> ob_generic, args);
1083 static object *
1084 set_dial_value (g, args)
1085 genericobject *g;
1086 object *args;
1088 return call_forms_INf (fl_set_dial_value, g-> ob_generic, args);
1091 static object *
1092 set_dial_bounds (g, args)
1093 genericobject *g;
1094 object *args;
1096 return call_forms_INfINf (fl_set_dial_bounds, g-> ob_generic, args);
1099 static object *
1100 get_dial_bounds (g, args)
1101 genericobject *g;
1102 object *args;
1104 return call_forms_OUTfOUTf (fl_get_dial_bounds, g-> ob_generic, args);
1107 static object *
1108 set_dial_step (g, args)
1109 genericobject *g;
1110 object *args;
1112 return call_forms_INf (fl_set_dial_step, g-> ob_generic, args);
1115 static struct methodlist dial_methods[] = {
1116 {"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},
1121 {NULL, NULL} /* sentinel */
1124 /* Class : Input */
1126 static object *
1127 set_input (g, args)
1128 genericobject *g;
1129 object *args;
1131 return call_forms_INstr (fl_set_input, g-> ob_generic, args);
1134 static object *
1135 get_input (g, args)
1136 genericobject *g;
1137 object *args;
1139 return call_forms_Rstr (fl_get_input, g-> ob_generic, args);
1142 static object *
1143 set_input_color (g, args)
1144 genericobject *g;
1145 object *args;
1147 return call_forms_INfINf (fl_set_input_color, g-> ob_generic, args);
1150 static object *
1151 set_input_return (g, args)
1152 genericobject *g;
1153 object *args;
1155 return call_forms_INi (fl_set_input_return, g-> ob_generic, args);
1158 static struct methodlist input_methods[] = {
1159 {"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},
1163 {NULL, NULL} /* sentinel */
1167 /* Class : Menu */
1169 static object *
1170 set_menu (g, args)
1171 genericobject *g;
1172 object *args;
1174 return call_forms_INstr (fl_set_menu, g-> ob_generic, args);
1177 static object *
1178 get_menu (g, args)
1179 genericobject *g;
1180 object *args;
1182 /* 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);
1187 static object *
1188 get_menu_text (g, args)
1189 genericobject *g;
1190 object *args;
1192 return call_forms_Rstr (fl_get_menu_text, g-> ob_generic, args);
1195 static object *
1196 addto_menu (g, args)
1197 genericobject *g;
1198 object *args;
1200 return call_forms_INstr (fl_addto_menu, g-> ob_generic, args);
1203 static struct methodlist menu_methods[] = {
1204 {"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},
1208 {NULL, NULL} /* sentinel */
1212 /* Class: Sliders */
1214 static object *
1215 get_slider_value(g, args)
1216 genericobject *g;
1217 object *args;
1219 return call_forms_Rf (fl_get_slider_value, g-> ob_generic, args);
1222 static object *
1223 set_slider_value (g, args)
1224 genericobject *g;
1225 object *args;
1227 return call_forms_INf (fl_set_slider_value, g-> ob_generic, args);
1230 static object *
1231 set_slider_bounds (g, args)
1232 genericobject *g;
1233 object *args;
1235 return call_forms_INfINf (fl_set_slider_bounds, g-> ob_generic, args);
1238 static object *
1239 get_slider_bounds (g, args)
1240 genericobject *g;
1241 object *args;
1243 return call_forms_OUTfOUTf(fl_get_slider_bounds, g-> ob_generic, args);
1246 static object *
1247 set_slider_return (g, args)
1248 genericobject *g;
1249 object *args;
1251 return call_forms_INf (fl_set_slider_return, g-> ob_generic, args);
1254 static object *
1255 set_slider_size (g, args)
1256 genericobject *g;
1257 object *args;
1259 return call_forms_INf (fl_set_slider_size, g-> ob_generic, args);
1262 static object *
1263 set_slider_precision (g, args)
1264 genericobject *g;
1265 object *args;
1267 return call_forms_INi (fl_set_slider_precision, g-> ob_generic, args);
1270 static object *
1271 set_slider_step (g, args)
1272 genericobject *g;
1273 object *args;
1275 return call_forms_INf (fl_set_slider_step, g-> ob_generic, args);
1279 static struct methodlist slider_methods[] = {
1280 {"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},
1288 {NULL, NULL} /* sentinel */
1291 static object *
1292 set_positioner_xvalue (g, args)
1293 genericobject *g;
1294 object *args;
1296 return call_forms_INf (fl_set_positioner_xvalue, g-> ob_generic, args);
1299 static object *
1300 set_positioner_xbounds (g, args)
1301 genericobject *g;
1302 object *args;
1304 return call_forms_INfINf (fl_set_positioner_xbounds,
1305 g-> ob_generic, args);
1308 static object *
1309 set_positioner_yvalue (g, args)
1310 genericobject *g;
1311 object *args;
1313 return call_forms_INf (fl_set_positioner_yvalue, g-> ob_generic, args);
1316 static object *
1317 set_positioner_ybounds (g, args)
1318 genericobject *g;
1319 object *args;
1321 return call_forms_INfINf (fl_set_positioner_ybounds,
1322 g-> ob_generic, args);
1325 static object *
1326 get_positioner_xvalue (g, args)
1327 genericobject *g;
1328 object *args;
1330 return call_forms_Rf (fl_get_positioner_xvalue, g-> ob_generic, args);
1333 static object *
1334 get_positioner_xbounds (g, args)
1335 genericobject *g;
1336 object *args;
1338 return call_forms_OUTfOUTf (fl_get_positioner_xbounds,
1339 g-> ob_generic, args);
1342 static object *
1343 get_positioner_yvalue (g, args)
1344 genericobject *g;
1345 object *args;
1347 return call_forms_Rf (fl_get_positioner_yvalue, g-> ob_generic, args);
1350 static object *
1351 get_positioner_ybounds (g, args)
1352 genericobject *g;
1353 object *args;
1355 return call_forms_OUTfOUTf (fl_get_positioner_ybounds,
1356 g-> ob_generic, args);
1359 static struct methodlist positioner_methods[] = {
1360 {"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},
1368 {NULL, NULL} /* sentinel */
1371 /* Class timer */
1373 static object *
1374 set_timer (g, args)
1375 genericobject *g;
1376 object *args;
1378 return call_forms_INf (fl_set_timer, g-> ob_generic, args);
1381 static object *
1382 get_timer (g, args)
1383 genericobject *g;
1384 object *args;
1386 return call_forms_Rf (fl_get_timer, g-> ob_generic, args);
1389 static struct methodlist timer_methods[] = {
1390 {"set_timer", (method)set_timer},
1391 {"get_timer", (method)get_timer},
1392 {NULL, NULL} /* sentinel */
1395 /* Form objects */
1397 typedef struct {
1398 OB_HEAD
1399 FL_FORM *ob_form;
1400 } formobject;
1402 staticforward typeobject Formtype;
1404 #define is_formobject(v) ((v)->ob_type == &Formtype)
1406 static object *
1407 form_show_form(f, args)
1408 formobject *f;
1409 object *args;
1411 int place, border;
1412 char *name;
1413 if (!getargs(args, "(iis)", &place, &border, &name))
1414 return NULL;
1415 fl_show_form(f->ob_form, place, border, name);
1416 INCREF(None);
1417 return None;
1420 static object *
1421 form_call(func, f, args)
1422 FL_FORM *f;
1423 object *args;
1424 void (*func)(FL_FORM *);
1426 if (!getnoarg(args)) return NULL;
1428 (*func)(f);
1430 INCREF(None);
1431 return None;
1434 static object *
1435 form_call_INiINi(func, f, args)
1436 FL_FORM *f;
1437 object *args;
1438 void (*func)(FL_FORM *, int, int);
1440 int a, b;
1442 if (!getargs(args, "(ii)", &a, &b)) return NULL;
1444 (*func)(f, a, b);
1446 INCREF(None);
1447 return None;
1450 static object *
1451 form_call_INfINf(func, f, args)
1452 FL_FORM *f;
1453 object *args;
1454 void (*func)(FL_FORM *, float, float);
1456 float a, b;
1458 if (!getargs(args, "(ff)", &a, &b)) return NULL;
1460 (*func)(f, a, b);
1462 INCREF(None);
1463 return None;
1466 static object *
1467 form_hide_form(f, args)
1468 formobject *f;
1469 object *args;
1471 return form_call(fl_hide_form, f-> ob_form, args);
1474 static object *
1475 form_redraw_form(f, args)
1476 formobject *f;
1477 object *args;
1479 return form_call(fl_redraw_form, f-> ob_form, args);
1482 static object *
1483 form_add_object(f, args)
1484 formobject *f;
1485 object *args;
1487 genericobject *g;
1488 if (args == NULL || !is_genericobject(args)) {
1489 err_badarg();
1490 return NULL;
1492 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;
1498 fl_add_object(f->ob_form, g->ob_generic);
1499 knowgeneric(g);
1501 INCREF(None);
1502 return None;
1505 static object *
1506 form_set_form_position(f, args)
1507 formobject *f;
1508 object *args;
1510 return form_call_INiINi(fl_set_form_position, f-> ob_form, args);
1513 static object *
1514 form_set_form_size(f, args)
1515 formobject *f;
1516 object *args;
1518 return form_call_INiINi(fl_set_form_size, f-> ob_form, args);
1521 static object *
1522 form_scale_form(f, args)
1523 formobject *f;
1524 object *args;
1526 return form_call_INfINf(fl_scale_form, f-> ob_form, args);
1529 static object *
1530 generic_add_object(f, args, func, internal_methods)
1531 formobject *f;
1532 object *args;
1533 FL_OBJECT *(*func)(int, float, float, float, float, char*);
1534 struct methodlist *internal_methods;
1536 int type;
1537 float x, y, w, h;
1538 char *name;
1539 FL_OBJECT *obj;
1541 if (!getargs(args,"(iffffs)", &type,&x,&y,&w,&h,&name))
1542 return NULL;
1544 fl_addto_form (f-> ob_form);
1546 obj = (*func) (type, x, y, w, h, name);
1548 fl_end_form();
1550 if (obj == NULL) {
1551 err_nomem();
1552 return NULL;
1555 return newgenericobject (obj, internal_methods);
1558 static object *
1559 form_add_button(f, args)
1560 formobject *f;
1561 object *args;
1563 return generic_add_object(f, args, fl_add_button, button_methods);
1566 static object *
1567 form_add_lightbutton(f, args)
1568 formobject *f;
1569 object *args;
1571 return generic_add_object(f, args, fl_add_lightbutton, button_methods);
1574 static object *
1575 form_add_roundbutton(f, args)
1576 formobject *f;
1577 object *args;
1579 return generic_add_object(f, args, fl_add_roundbutton, button_methods);
1582 static object *
1583 form_add_menu (f, args)
1584 formobject *f;
1585 object *args;
1587 return generic_add_object(f, args, fl_add_menu, menu_methods);
1590 static object *
1591 form_add_slider(f, args)
1592 formobject *f;
1593 object *args;
1595 return generic_add_object(f, args, fl_add_slider, slider_methods);
1598 static object *
1599 form_add_valslider(f, args)
1600 formobject *f;
1601 object *args;
1603 return generic_add_object(f, args, fl_add_valslider, slider_methods);
1606 static object *
1607 form_add_dial(f, args)
1608 formobject *f;
1609 object *args;
1611 return generic_add_object(f, args, fl_add_dial, dial_methods);
1614 static object *
1615 form_add_counter(f, args)
1616 formobject *f;
1617 object *args;
1619 return generic_add_object(f, args, fl_add_counter, counter_methods);
1622 static object *
1623 form_add_clock(f, args)
1624 formobject *f;
1625 object *args;
1627 return generic_add_object(f, args, fl_add_clock, clock_methods);
1630 static object *
1631 form_add_box(f, args)
1632 formobject *f;
1633 object *args;
1635 return generic_add_object(f, args, fl_add_box,
1636 (struct methodlist *)NULL);
1639 static object *
1640 form_add_choice(f, args)
1641 formobject *f;
1642 object *args;
1644 return generic_add_object(f, args, fl_add_choice, choice_methods);
1647 static object *
1648 form_add_browser(f, args)
1649 formobject *f;
1650 object *args;
1652 return generic_add_object(f, args, fl_add_browser, browser_methods);
1655 static object *
1656 form_add_positioner(f, args)
1657 formobject *f;
1658 object *args;
1660 return generic_add_object(f, args, fl_add_positioner, positioner_methods);
1663 static object *
1664 form_add_input(f, args)
1665 formobject *f;
1666 object *args;
1668 return generic_add_object(f, args, fl_add_input, input_methods);
1671 static object *
1672 form_add_text(f, args)
1673 formobject *f;
1674 object *args;
1676 return generic_add_object(f, args, fl_add_text,
1677 (struct methodlist *)NULL);
1680 static object *
1681 form_add_timer(f, args)
1682 formobject *f;
1683 object *args;
1685 return generic_add_object(f, args, fl_add_timer, timer_methods);
1688 static object *
1689 form_freeze_form(f, args)
1690 formobject *f;
1691 object *args;
1693 return form_call(fl_freeze_form, f-> ob_form, args);
1696 static object *
1697 form_unfreeze_form(f, args)
1698 formobject *f;
1699 object *args;
1701 return form_call(fl_unfreeze_form, f-> ob_form, args);
1704 static object *
1705 form_activate_form(f, args)
1706 formobject *f;
1707 object *args;
1709 return form_call(fl_activate_form, f-> ob_form, args);
1712 static object *
1713 form_deactivate_form(f, args)
1714 formobject *f;
1715 object *args;
1717 return form_call(fl_deactivate_form, f-> ob_form, args);
1720 static object *
1721 form_bgn_group(f, args)
1722 formobject *f;
1723 object *args;
1725 FL_OBJECT *obj;
1727 fl_addto_form(f-> ob_form);
1728 obj = fl_bgn_group();
1729 fl_end_form();
1731 if (obj == NULL) {
1732 err_nomem();
1733 return NULL;
1736 return newgenericobject (obj, (struct methodlist *) NULL);
1739 static object *
1740 form_end_group(f, args)
1741 formobject *f;
1742 object *args;
1744 fl_addto_form(f-> ob_form);
1745 fl_end_group();
1746 fl_end_form();
1747 INCREF(None);
1748 return None;
1751 static object *
1752 forms_find_first_or_last(func, f, args)
1753 FL_OBJECT *(*func)(FL_FORM *, int, float, float);
1754 formobject *f;
1755 object *args;
1757 int type;
1758 float mx, my;
1759 FL_OBJECT *generic;
1760 genericobject *g;
1762 if (!getargs(args, "(iff)", &type, &mx, &my)) return NULL;
1764 generic = (*func) (f-> ob_form, type, mx, my);
1766 if (generic == NULL)
1768 INCREF(None);
1769 return None;
1772 g = findgeneric(generic);
1773 if (g == NULL) {
1774 err_setstr(RuntimeError,
1775 "forms_find_{first|last} returns unknown object");
1776 return NULL;
1778 INCREF(g);
1779 return (object *) g;
1782 static object *
1783 form_find_first(f, args)
1784 formobject *f;
1785 object *args;
1787 return forms_find_first_or_last(fl_find_first, f, args);
1790 static object *
1791 form_find_last(f, args)
1792 formobject *f;
1793 object *args;
1795 return forms_find_first_or_last(fl_find_last, f, args);
1798 static object *
1799 form_set_object_focus(f, args)
1800 formobject *f;
1801 object *args;
1803 genericobject *g;
1804 if (args == NULL || !is_genericobject(args)) {
1805 err_badarg();
1806 return NULL;
1808 g = (genericobject *)args;
1809 fl_set_object_focus(f->ob_form, g->ob_generic);
1810 INCREF(None);
1811 return None;
1814 static struct methodlist form_methods[] = {
1815 /* adm */
1816 {"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},
1832 /* basic objects */
1833 {"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},
1850 {NULL, NULL} /* sentinel */
1853 static void
1854 form_dealloc(f)
1855 formobject *f;
1857 releaseobjects(f->ob_form);
1858 if (f->ob_form->visible)
1859 fl_hide_form(f->ob_form);
1860 fl_free_form(f->ob_form);
1861 DEL(f);
1864 #define OFF(x) offsetof(FL_FORM, x)
1866 static struct memberlist form_memberlist[] = {
1867 {"window", T_LONG, OFF(window), RO},
1868 {"w", T_FLOAT, OFF(w)},
1869 {"h", T_FLOAT, OFF(h)},
1870 {"x", T_FLOAT, OFF(x), RO},
1871 {"y", T_FLOAT, OFF(y), RO},
1872 {"deactivated", T_INT, OFF(deactivated)},
1873 {"visible", T_INT, OFF(visible), RO},
1874 {"frozen", T_INT, OFF(frozen), RO},
1875 {"doublebuf", T_INT, OFF(doublebuf)},
1876 {NULL} /* Sentinel */
1879 #undef OFF
1881 static object *
1882 form_getattr(f, name)
1883 formobject *f;
1884 char *name;
1886 object *meth;
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);
1895 static int
1896 form_setattr(f, name, v)
1897 formobject *f;
1898 char *name;
1899 object *v;
1901 int ret;
1903 if (v == NULL) {
1904 err_setstr(TypeError, "can't delete form attributes");
1905 return 0;
1908 return setmember((char *)f->ob_form, form_memberlist, name, v);
1911 static object *
1912 form_repr(f)
1913 formobject *f;
1915 char buf[100];
1916 sprintf(buf, "<FORMS_form at %lx, window=%ld>",
1917 (long)f, f->ob_form->window);
1918 return newstringobject(buf);
1921 static typeobject Formtype = {
1922 OB_HEAD_INIT(&Typetype)
1923 0, /*ob_size*/
1924 "FORMS_form", /*tp_name*/
1925 sizeof(formobject), /*tp_size*/
1926 0, /*tp_itemsize*/
1927 /* methods */
1928 (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*/
1936 static object *
1937 newformobject(form)
1938 FL_FORM *form;
1940 formobject *f;
1941 f = NEWOBJ(formobject, &Formtype);
1942 if (f == NULL)
1943 return NULL;
1944 f->ob_form = form;
1945 return (object *)f;
1949 /* The "fl" module */
1951 static object *
1952 forms_make_form(dummy, args)
1953 object *dummy;
1954 object *args;
1956 int type;
1957 float w, h;
1958 FL_FORM *form;
1959 if (!getargs(args, "(iff)", &type, &w, &h))
1960 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;
1967 fl_end_form();
1968 return newformobject(form);
1971 static object *
1972 forms_activate_all_forms(f, args)
1973 object *f;
1974 object *args;
1976 fl_activate_all_forms();
1977 INCREF(None);
1978 return None;
1981 static object *
1982 forms_deactivate_all_forms(f, args)
1983 object *f;
1984 object *args;
1986 fl_deactivate_all_forms();
1987 INCREF(None);
1988 return None;
1991 static object *my_event_callback = NULL;
1993 static object *
1994 forms_set_event_call_back(dummy, args)
1995 object *dummy;
1996 object *args;
1998 if (args == None)
1999 args = NULL;
2000 my_event_callback = args;
2001 XINCREF(args);
2002 INCREF(None);
2003 return None;
2006 static object *
2007 forms_do_or_check_forms(dummy, args, func)
2008 object *dummy;
2009 object *args;
2010 FL_OBJECT *(*func)();
2012 FL_OBJECT *generic;
2013 genericobject *g;
2014 object *arg, *res;
2016 if (!getnoarg(args))
2017 return NULL;
2019 for (;;) {
2020 BGN_SAVE
2021 generic = (*func)();
2022 END_SAVE
2023 if (generic == NULL) {
2024 INCREF(None);
2025 return None;
2027 if (generic == FL_EVENT) {
2028 int dev;
2029 short val;
2030 if (my_event_callback == NULL)
2031 return newintobject(-1L);
2032 dev = fl_qread(&val);
2033 arg = mkvalue("(ih)", dev, val);
2034 if (arg == NULL)
2035 return NULL;
2036 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;
2043 g = findgeneric(generic);
2044 if (g == NULL) {
2045 /* Object not known to us (some dialogs cause this) */
2046 continue; /* Ignore it */
2048 if (g->ob_callback == NULL) {
2049 INCREF(g);
2050 return ((object *) g);
2052 arg = mkvalue("(OO)", (object *)g, g->ob_callback_arg);
2053 if (arg == NULL)
2054 return NULL;
2055 res = call_object(g->ob_callback, arg);
2056 XDECREF(res);
2057 DECREF(arg);
2058 if (res == NULL)
2059 return NULL; /* Callback raised exception */
2063 static object *
2064 forms_do_forms(dummy, args)
2065 object *dummy;
2066 object *args;
2068 return forms_do_or_check_forms(dummy, args, fl_do_forms);
2071 static object *
2072 forms_check_forms(dummy, args)
2073 object *dummy;
2074 object *args;
2076 return forms_do_or_check_forms(dummy, args, fl_check_forms);
2079 static object *
2080 forms_do_only_forms(dummy, args)
2081 object *dummy;
2082 object *args;
2084 return forms_do_or_check_forms(dummy, args, fl_do_only_forms);
2087 static object *
2088 forms_check_only_forms(dummy, args)
2089 object *dummy;
2090 object *args;
2092 return forms_do_or_check_forms(dummy, args, fl_check_only_forms);
2095 #ifdef UNUSED
2096 static object *
2097 fl_call(func, args)
2098 object *args;
2099 void (*func)();
2101 if (!getnoarg(args))
2102 return NULL;
2103 (*func)();
2104 INCREF(None);
2105 return None;
2107 #endif
2109 static object *
2110 forms_set_graphics_mode(dummy, args)
2111 object *dummy;
2112 object *args;
2114 int rgbmode, doublebuf;
2116 if (!getargs(args, "(ii)", &rgbmode, &doublebuf))
2117 return NULL;
2118 fl_set_graphics_mode(rgbmode,doublebuf);
2119 INCREF(None);
2120 return None;
2123 static object *
2124 forms_get_rgbmode(dummy, args)
2125 object *dummy;
2126 object *args;
2128 extern int fl_rgbmode;
2130 if (args != NULL) {
2131 err_badarg();
2132 return NULL;
2134 return newintobject((long)fl_rgbmode);
2137 static object *
2138 forms_show_errors(dummy, args)
2139 object *dummy;
2140 object *args;
2142 int show;
2143 if (!getargs(args, "i", &show))
2144 return NULL;
2145 fl_show_errors(show);
2146 INCREF(None);
2147 return None;
2150 static object *
2151 forms_set_font_name(dummy, args)
2152 object *dummy;
2153 object *args;
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;
2165 static object *
2166 forms_qdevice(self, args)
2167 object *self;
2168 object *args;
2170 short arg1;
2171 if (!getargs(args, "h", &arg1))
2172 return NULL;
2173 fl_qdevice(arg1);
2174 INCREF(None);
2175 return None;
2178 static object *
2179 forms_unqdevice(self, args)
2180 object *self;
2181 object *args;
2183 short arg1;
2184 if (!getargs(args, "h", &arg1))
2185 return NULL;
2186 fl_unqdevice(arg1);
2187 INCREF(None);
2188 return None;
2191 static object *
2192 forms_isqueued(self, args)
2193 object *self;
2194 object *args;
2196 long retval;
2197 short arg1;
2198 if (!getargs(args, "h", &arg1))
2199 return NULL;
2200 retval = fl_isqueued(arg1);
2202 return newintobject(retval);
2205 static object *
2206 forms_qtest(self, args)
2207 object *self;
2208 object *args;
2210 long retval;
2211 retval = fl_qtest();
2212 return newintobject(retval);
2216 static object *
2217 forms_qread(self, args)
2218 object *self;
2219 object *args;
2221 int dev;
2222 short val;
2223 BGN_SAVE
2224 dev = fl_qread(&val);
2225 END_SAVE
2226 return mkvalue("(ih)", dev, val);
2229 static object *
2230 forms_qreset(self, args)
2231 object *self;
2232 object *args;
2234 if (!getnoarg(args)) return NULL;
2236 fl_qreset();
2237 INCREF(None);
2238 return None;
2241 static object *
2242 forms_qenter(self, args)
2243 object *self;
2244 object *args;
2246 short arg1, arg2;
2247 if (!getargs(args, "(hh)", &arg1, &arg2))
2248 return NULL;
2249 fl_qenter(arg1, arg2);
2250 INCREF(None);
2251 return None;
2254 static object *
2255 forms_color(self, args)
2256 object *self;
2257 object *args;
2259 int arg;
2261 if (!getintarg(args, &arg)) return NULL;
2263 fl_color((short) arg);
2265 INCREF(None);
2266 return None;
2269 static object *
2270 forms_mapcolor(self, args)
2271 object *self;
2272 object *args;
2274 int arg0, arg1, arg2, arg3;
2276 if (!getargs(args, "(iiii)", &arg0, &arg1, &arg2, &arg3))
2277 return NULL;
2279 fl_mapcolor(arg0, (short) arg1, (short) arg2, (short) arg3);
2281 INCREF(None);
2282 return None;
2285 static object *
2286 forms_getmcolor(self, args)
2287 object *self;
2288 object *args;
2290 int arg;
2291 short r, g, b;
2293 if (!getintarg(args, &arg)) return NULL;
2295 fl_getmcolor(arg, &r, &g, &b);
2297 return mkvalue("(hhh)", r, g, b);
2300 static object *
2301 forms_get_mouse(self, args)
2302 object *self;
2303 object *args;
2305 float x, y;
2307 if (!getnoarg(args)) return NULL;
2309 fl_get_mouse(&x, &y);
2311 return mkvalue("(ff)", x, y);
2314 static object *
2315 forms_tie(self, args)
2316 object *self;
2317 object *args;
2319 short arg1, arg2, arg3;
2320 if (!getargs(args, "(hhh)", &arg1, &arg2, &arg3))
2321 return NULL;
2322 fl_tie(arg1, arg2, arg3);
2323 INCREF(None);
2324 return None;
2327 static object *
2328 forms_show_message(f, args)
2329 object *f;
2330 object *args;
2332 char *a, *b, *c;
2334 if (!getargs(args, "(sss)", &a, &b, &c)) return NULL;
2336 BGN_SAVE
2337 fl_show_message(a, b, c);
2338 END_SAVE
2340 INCREF(None);
2341 return None;
2344 static object *
2345 forms_show_choice(f, args)
2346 object *f;
2347 object *args;
2349 char *m1, *m2, *m3, *b1, *b2, *b3;
2350 int nb;
2351 char *format;
2352 long rv;
2354 if (args == NULL || !is_tupleobject(args)) {
2355 err_badarg();
2356 return NULL;
2358 nb = gettuplesize(args) - 3;
2359 if (nb <= 0) {
2360 err_setstr(TypeError, "need at least one button label");
2361 return NULL;
2363 if (is_intobject(gettupleitem(args, 3))) {
2364 err_setstr(TypeError,
2365 "'number-of-buttons' argument not needed");
2366 return NULL;
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;
2377 if (!getargs(args, format, &m1, &m2, &m3, &b1, &b2, &b3))
2378 return NULL;
2380 BGN_SAVE
2381 rv = fl_show_choice(m1, m2, m3, nb, b1, b2, b3);
2382 END_SAVE
2383 return newintobject(rv);
2386 static object *
2387 forms_show_question(f, args)
2388 object *f;
2389 object *args;
2391 int ret;
2392 char *a, *b, *c;
2394 if (!getargs(args, "(sss)", &a, &b, &c)) return NULL;
2396 BGN_SAVE
2397 ret = fl_show_question(a, b, c);
2398 END_SAVE
2400 return newintobject((long) ret);
2403 static object *
2404 forms_show_input(f, args)
2405 object *f;
2406 object *args;
2408 char *str;
2409 char *a, *b;
2411 if (!getargs(args, "(ss)", &a, &b)) return NULL;
2413 BGN_SAVE
2414 str = fl_show_input(a, b);
2415 END_SAVE
2417 if (str == NULL) {
2418 INCREF(None);
2419 return None;
2421 return newstringobject(str);
2424 static object *
2425 forms_file_selector(f, args)
2426 object *f;
2427 object *args;
2429 char *str;
2430 char *a, *b, *c, *d;
2432 if (!getargs(args, "(ssss)", &a, &b, &c, &d)) return NULL;
2434 BGN_SAVE
2435 str = fl_show_file_selector(a, b, c, d);
2436 END_SAVE
2438 if (str == NULL) {
2439 INCREF(None);
2440 return None;
2442 return newstringobject(str);
2446 static object *
2447 forms_file_selector_func(args, func)
2448 object *args;
2449 char *(*func)();
2451 char *str;
2453 str = (*func) ();
2455 if (str == NULL) {
2456 INCREF(None);
2457 return None;
2459 return newstringobject(str);
2462 static object *
2463 forms_get_directory(f, args)
2464 object *f;
2465 object *args;
2467 return forms_file_selector_func(args, fl_get_directory);
2470 static object *
2471 forms_get_pattern(f, args)
2472 object *f;
2473 object *args;
2475 return forms_file_selector_func(args, fl_get_pattern);
2478 static object *
2479 forms_get_filename(f, args)
2480 object *f;
2481 object *args;
2483 return forms_file_selector_func(args, fl_get_filename);
2486 static struct methodlist forms_methods[] = {
2487 /* adm */
2488 {"make_form", forms_make_form},
2489 {"activate_all_forms", forms_activate_all_forms},
2490 {"deactivate_all_forms",forms_deactivate_all_forms},
2491 /* gl support wrappers */
2492 {"qdevice", forms_qdevice},
2493 {"unqdevice", forms_unqdevice},
2494 {"isqueued", forms_isqueued},
2495 {"qtest", forms_qtest},
2496 {"qread", forms_qread},
2497 /* {"blkqread", forms_blkqread}, */
2498 {"qreset", forms_qreset},
2499 {"qenter", forms_qenter},
2500 {"get_mouse", forms_get_mouse},
2501 {"tie", forms_tie},
2502 /* {"new_events", forms_new_events}, */
2503 {"color", forms_color},
2504 {"mapcolor", forms_mapcolor},
2505 {"getmcolor", forms_getmcolor},
2506 /* interaction */
2507 {"do_forms", forms_do_forms},
2508 {"do_only_forms", forms_do_only_forms},
2509 {"check_forms", forms_check_forms},
2510 {"check_only_forms", forms_check_only_forms},
2511 {"set_event_call_back", forms_set_event_call_back},
2512 /* goodies */
2513 {"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},
2522 {"set_graphics_mode", forms_set_graphics_mode},
2523 {"get_rgbmode", forms_get_rgbmode},
2524 {"show_errors", forms_show_errors},
2525 {"set_font_name", forms_set_font_name},
2526 {NULL, NULL} /* sentinel */
2529 void
2530 initfl()
2532 initmodule("fl", forms_methods);
2533 foreground();
2534 fl_init();