• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* FL module -- interface to Mark Overmars' FORMS Library. */
2 
3 /* This code works with FORMS version 2.2 (if you defined
4    OBSOLETE_FORMS_CALLS), and 2.3.
5    FORMS can be ftp'ed from ftp.cs.ruu.nl (131.211.80.17), directory
6    /pub/SGI/FORMS. */
7 
8 /* A half-hearted attempt has been made to allow programs using this
9  * module to exploit parallelism (through the threads module). No provisions
10  * have been made for multiple threads to use this module at the same time,
11  * though. So, a program with a forms thread and a non-forms thread will work
12  * fine but a program with two threads using forms will probably crash (unless
13  * the program takes precaution to ensure that only one thread can be in
14  * this module at any time). This will have to be fixed some time.
15  * (A fix will probably also have to synchronize with the gl module).
16  */
17 
18 #include "Python.h"
19 #include "forms.h"
20 #include "structmember.h"
21 
22 /* Generic Forms Objects */
23 
24 typedef struct {
25     PyObject_HEAD
26     FL_OBJECT *ob_generic;
27     PyMethodDef *ob_methods;
28     PyObject *ob_callback;
29     PyObject *ob_callback_arg;
30 } genericobject;
31 
32 static PyTypeObject GenericObjecttype;
33 
34 #define is_genericobject(g) ((g)->ob_type == &GenericObjecttype)
35 
36 /* List of all objects (XXX this should be a hash table on address...) */
37 
38 static PyObject *allgenerics = NULL;
39 static int nfreeslots = 0;
40 
41 /* Add an object to the list of known objects */
42 
43 static void
knowgeneric(genericobject * g)44 knowgeneric(genericobject *g)
45 {
46     int i, n;
47     /* Create the list if it doesn't already exist */
48     if (allgenerics == NULL) {
49         allgenerics = PyList_New(0);
50         if (allgenerics == NULL) {
51             PyErr_Clear();
52             return; /* Too bad, live without allgenerics... */
53         }
54     }
55     if (nfreeslots > 0) {
56         /* Search the list for reusable slots (NULL items) */
57         /* XXX This can be made faster! */
58         n = PyList_Size(allgenerics);
59         for (i = 0; i < n; i++) {
60             if (PyList_GetItem(allgenerics, i) == NULL) {
61                 Py_INCREF(g);
62                 PyList_SetItem(allgenerics, i, (PyObject *)g);
63                 nfreeslots--;
64                 return;
65             }
66         }
67         /* Strange... no free slots found... */
68         nfreeslots = 0;
69     }
70     /* No free entries, append new item to the end */
71     PyList_Append(allgenerics, (PyObject *)g);
72 }
73 
74 /* Find an object in the list of known objects */
75 
76 static genericobject *
findgeneric(FL_OBJECT * generic)77 findgeneric(FL_OBJECT *generic)
78 {
79     int i, n;
80     genericobject *g;
81 
82     if (allgenerics == NULL)
83         return NULL; /* No objects known yet */
84     n = PyList_Size(allgenerics);
85     for (i = 0; i < n; i++) {
86         g = (genericobject *)PyList_GetItem(allgenerics, i);
87         if (g != NULL && g->ob_generic == generic)
88             return g;
89     }
90     return NULL; /* Unknown object */
91 }
92 
93 /* Remove an object from the list of known objects */
94 
95 static void
forgetgeneric(genericobject * g)96 forgetgeneric(genericobject *g)
97 {
98     int i, n;
99 
100     Py_CLEAR(g->ob_callback);
101     Py_CLEAR(g->ob_callback_arg);
102     if (allgenerics == NULL)
103         return; /* No objects known yet */
104     n = PyList_Size(allgenerics);
105     for (i = 0; i < n; i++) {
106         if (g == (genericobject *)PyList_GetItem(allgenerics, i)) {
107             PyList_SetItem(allgenerics, i, (PyObject *)NULL);
108             nfreeslots++;
109             break;
110         }
111     }
112 }
113 
114 /* Called when a form is about to be freed --
115    remove all the objects that we know about from it. */
116 
117 static void
releaseobjects(FL_FORM * form)118 releaseobjects(FL_FORM *form)
119 {
120     int i, n;
121     genericobject *g;
122 
123     if (allgenerics == NULL)
124         return; /* No objects known yet */
125     n = PyList_Size(allgenerics);
126     for (i = 0; i < n; i++) {
127         g = (genericobject *)PyList_GetItem(allgenerics, i);
128         if (g != NULL && g->ob_generic->form == form) {
129             fl_delete_object(g->ob_generic);
130             /* The object is now unreachable for
131                do_forms and check_forms, so
132                delete it from the list of known objects */
133             Py_CLEAR(g->ob_callback);
134             Py_CLEAR(g->ob_callback_arg);
135             PyList_SetItem(allgenerics, i, (PyObject *)NULL);
136             nfreeslots++;
137         }
138     }
139 }
140 
141 
142 /* Methods of generic objects */
143 
144 static PyObject *
generic_set_call_back(genericobject * g,PyObject * args)145 generic_set_call_back(genericobject *g, PyObject *args)
146 {
147     if (PyTuple_GET_SIZE(args) == 0) {
148         Py_XDECREF(g->ob_callback);
149         Py_XDECREF(g->ob_callback_arg);
150         g->ob_callback = NULL;
151         g->ob_callback_arg = NULL;
152     }
153     else {
154         PyObject *a, *b;
155         if (!PyArg_UnpackTuple(args, "set_call_back", 2, 2, &a, &b))
156             return NULL;
157         Py_XDECREF(g->ob_callback);
158         Py_XDECREF(g->ob_callback_arg);
159         g->ob_callback = a;
160         Py_INCREF(g->ob_callback);
161         g->ob_callback_arg = b;
162         Py_INCREF(g->ob_callback_arg);
163     }
164     Py_INCREF(Py_None);
165     return Py_None;
166 }
167 
168 static PyObject *
generic_call(genericobject * g,void (* func)(FL_OBJECT *))169 generic_call(genericobject *g, void (*func)(FL_OBJECT *))
170 {
171     (*func)(g->ob_generic);
172     Py_INCREF(Py_None);
173     return Py_None;
174 }
175 
176 static PyObject *
generic_delete_object(genericobject * g)177 generic_delete_object(genericobject *g)
178 {
179     PyObject *res;
180     res = generic_call(g, fl_delete_object);
181     if (res != NULL)
182         forgetgeneric(g);
183     return res;
184 }
185 
186 static PyObject *
generic_show_object(genericobject * g)187 generic_show_object(genericobject *g)
188 {
189     return generic_call(g, fl_show_object);
190 }
191 
192 static PyObject *
generic_hide_object(genericobject * g)193 generic_hide_object(genericobject *g)
194 {
195     return generic_call(g, fl_hide_object);
196 }
197 
198 static PyObject *
generic_redraw_object(genericobject * g)199 generic_redraw_object(genericobject *g)
200 {
201     return generic_call(g, fl_redraw_object);
202 }
203 
204 #ifdef OBSOLETE_FORMS_CALLS
205 
206  /* (un)freeze_object() are obsolete in FORMS 2.2 and unsupported
207     in 2.3.  Since there's no foolproof way to tell which version we're
208     using, we omit them unconditionally. */
209 
210 static PyObject *
generic_freeze_object(genericobject * g)211 generic_freeze_object(genericobject *g)
212 {
213     return generic_call(g, fl_freeze_object);
214 }
215 
216 static PyObject *
generic_unfreeze_object(genericobject * g)217 generic_unfreeze_object(genericobject *g)
218 {
219     return generic_call(g, fl_unfreeze_object);
220 }
221 
222 #endif /* OBSOLETE_FORMS_CALLS */
223 
224 static PyObject *
generic_activate_object(genericobject * g)225 generic_activate_object(genericobject *g)
226 {
227     return generic_call(g, fl_activate_object);
228 }
229 
230 static PyObject *
generic_deactivate_object(genericobject * g)231 generic_deactivate_object(genericobject *g)
232 {
233     return generic_call(g, fl_deactivate_object);
234 }
235 
236 static PyObject *
generic_set_object_shortcut(genericobject * g,PyObject * args)237 generic_set_object_shortcut(genericobject *g, PyObject *args)
238 {
239     char *str;
240     if (!PyArg_ParseTuple(args, "s:set_object_shortcut", &str))
241         return NULL;
242     fl_set_object_shortcut(g->ob_generic, str);
243     Py_INCREF(Py_None);
244     return Py_None;
245 }
246 
247 static PyMethodDef generic_methods[] = {
248     {"set_call_back",           (PyCFunction)generic_set_call_back, METH_VARARGS},
249     {"delete_object",           (PyCFunction)generic_delete_object, METH_NOARGS},
250     {"show_object",             (PyCFunction)generic_show_object, METH_NOARGS},
251     {"hide_object",             (PyCFunction)generic_hide_object, METH_NOARGS},
252     {"redraw_object",           (PyCFunction)generic_redraw_object, METH_NOARGS},
253 #ifdef OBSOLETE_FORMS_CALLS
254     {"freeze_object",           (PyCFunction)generic_freeze_object, METH_NOARGS},
255     {"unfreeze_object",         (PyCFunction)generic_unfreeze_object, METH_NOARGS},
256 #endif
257     {"activate_object",         (PyCFunction)generic_activate_object, METH_NOARGS},
258     {"deactivate_object",       (PyCFunction)generic_deactivate_object, METH_NOARGS},
259     {"set_object_shortcut",     (PyCFunction)generic_set_object_shortcut, METH_VARARGS},
260     {NULL,                      NULL}           /* sentinel */
261 };
262 
263 static void
generic_dealloc(genericobject * g)264 generic_dealloc(genericobject *g)
265 {
266     fl_free_object(g->ob_generic);
267     Py_XDECREF(g->ob_callback);
268     Py_XDECREF(g->ob_callback_arg);
269     PyObject_Del(g);
270 }
271 
272 #define OFF(x) offsetof(FL_OBJECT, x)
273 
274 static struct memberlist generic_memberlist[] = {
275     {"objclass",        T_INT,          OFF(objclass),  RO},
276     {"type",            T_INT,          OFF(type),      RO},
277     {"boxtype",         T_INT,          OFF(boxtype)},
278     {"x",               T_FLOAT,        OFF(x)},
279     {"y",               T_FLOAT,        OFF(y)},
280     {"w",               T_FLOAT,        OFF(w)},
281     {"h",               T_FLOAT,        OFF(h)},
282     {"col1",            T_INT,          OFF(col1)},
283     {"col2",            T_INT,          OFF(col2)},
284     {"align",           T_INT,          OFF(align)},
285     {"lcol",            T_INT,          OFF(lcol)},
286     {"lsize",           T_FLOAT,        OFF(lsize)},
287     /* "label" is treated specially! */
288     {"lstyle",          T_INT,          OFF(lstyle)},
289     {"pushed",          T_INT,          OFF(pushed),    RO},
290     {"focus",           T_INT,          OFF(focus),     RO},
291     {"belowmouse",      T_INT,          OFF(belowmouse),RO},
292 /*      {"frozen",      T_INT,          OFF(frozen),    RO},    */
293     {"active",          T_INT,          OFF(active)},
294     {"input",           T_INT,          OFF(input)},
295     {"visible",         T_INT,          OFF(visible),   RO},
296     {"radio",           T_INT,          OFF(radio)},
297     {"automatic",       T_INT,          OFF(automatic)},
298     {NULL}      /* Sentinel */
299 };
300 
301 #undef OFF
302 
303 static PyObject *
generic_getattr(genericobject * g,char * name)304 generic_getattr(genericobject *g, char *name)
305 {
306     PyObject *meth;
307 
308     /* XXX Ought to special-case name "__methods__" */
309     if (g-> ob_methods) {
310         meth = Py_FindMethod(g->ob_methods, (PyObject *)g, name);
311         if (meth != NULL) return meth;
312         PyErr_Clear();
313     }
314 
315     meth = Py_FindMethod(generic_methods, (PyObject *)g, name);
316     if (meth != NULL)
317         return meth;
318     PyErr_Clear();
319 
320     /* "label" is an exception, getmember only works for char pointers,
321        not for char arrays */
322     if (strcmp(name, "label") == 0)
323         return PyString_FromString(g->ob_generic->label);
324 
325     return PyMember_Get((char *)g->ob_generic, generic_memberlist, name);
326 }
327 
328 static int
generic_setattr(genericobject * g,char * name,PyObject * v)329 generic_setattr(genericobject *g, char *name, PyObject *v)
330 {
331     int ret;
332 
333     if (v == NULL) {
334         PyErr_SetString(PyExc_TypeError,
335                         "can't delete forms object attributes");
336         return -1;
337     }
338 
339     /* "label" is an exception: setmember doesn't set strings;
340        and FORMS wants you to call a function to set the label */
341     if (strcmp(name, "label") == 0) {
342         if (!PyString_Check(v)) {
343             PyErr_SetString(PyExc_TypeError,
344                             "label attr must be string");
345             return -1;
346         }
347         fl_set_object_label(g->ob_generic, PyString_AsString(v));
348         return 0;
349     }
350 
351     ret = PyMember_Set((char *)g->ob_generic, generic_memberlist, name, v);
352 
353     /* Rather than calling all the various set_object_* functions,
354        we call fl_redraw_object here.  This is sometimes redundant
355        but I doubt that's a big problem */
356     if (ret == 0)
357         fl_redraw_object(g->ob_generic);
358 
359     return ret;
360 }
361 
362 static PyObject *
generic_repr(genericobject * g)363 generic_repr(genericobject *g)
364 {
365     char buf[100];
366     PyOS_snprintf(buf, sizeof(buf), "<FORMS_object at %p, objclass=%d>",
367                   g, g->ob_generic->objclass);
368     return PyString_FromString(buf);
369 }
370 
371 static PyTypeObject GenericObjecttype = {
372     PyObject_HEAD_INIT(&PyType_Type)
373     0,                                  /*ob_size*/
374     "fl.FORMS_object",                  /*tp_name*/
375     sizeof(genericobject),              /*tp_size*/
376     0,                                  /*tp_itemsize*/
377     /* methods */
378     (destructor)generic_dealloc,        /*tp_dealloc*/
379     0,                                  /*tp_print*/
380     (getattrfunc)generic_getattr,       /*tp_getattr*/
381     (setattrfunc)generic_setattr,       /*tp_setattr*/
382     0,                                  /*tp_compare*/
383     (reprfunc)generic_repr,             /*tp_repr*/
384 };
385 
386 static PyObject *
newgenericobject(FL_OBJECT * generic,PyMethodDef * methods)387 newgenericobject(FL_OBJECT *generic, PyMethodDef *methods)
388 {
389     genericobject *g;
390     g = PyObject_New(genericobject, &GenericObjecttype);
391     if (g == NULL)
392         return NULL;
393     g-> ob_generic = generic;
394     g->ob_methods = methods;
395     g->ob_callback = NULL;
396     g->ob_callback_arg = NULL;
397     knowgeneric(g);
398     return (PyObject *)g;
399 }
400 
401 /**********************************************************************/
402 /* Some common calling sequences */
403 
404 /* void func (object, float) */
405 static PyObject *
call_forms_INf(void (* func)(FL_OBJECT *,float),FL_OBJECT * obj,PyObject * args)406 call_forms_INf (void (*func)(FL_OBJECT *, float), FL_OBJECT *obj, PyObject *args)
407 {
408     float parameter;
409 
410     if (!PyArg_Parse(args, "f", &parameter)) return NULL;
411 
412     (*func) (obj, parameter);
413 
414     Py_INCREF(Py_None);
415     return Py_None;
416 }
417 
418 /* void func (object, float) */
419 static PyObject *
call_forms_INfINf(void (* func)(FL_OBJECT *,float,float),FL_OBJECT * obj,PyObject * args)420 call_forms_INfINf (void (*func)(FL_OBJECT *, float, float), FL_OBJECT *obj, PyObject *args)
421 {
422     float par1, par2;
423 
424     if (!PyArg_Parse(args, "(ff)", &par1, &par2)) return NULL;
425 
426     (*func) (obj, par1, par2);
427 
428     Py_INCREF(Py_None);
429     return Py_None;
430 }
431 
432 /* void func (object, int) */
433 static PyObject *
call_forms_INi(void (* func)(FL_OBJECT *,int),FL_OBJECT * obj,PyObject * args)434 call_forms_INi (void (*func)(FL_OBJECT *, int), FL_OBJECT *obj, PyObject *args)
435 {
436     int parameter;
437 
438     if (!PyArg_Parse(args, "i", &parameter)) return NULL;
439 
440     (*func) (obj, parameter);
441 
442     Py_INCREF(Py_None);
443     return Py_None;
444 }
445 
446 /* void func (object, char) */
447 static PyObject *
call_forms_INc(void (* func)(FL_OBJECT *,int),FL_OBJECT * obj,PyObject * args)448 call_forms_INc (void (*func)(FL_OBJECT *, int), FL_OBJECT *obj, PyObject *args)
449 {
450     char *a;
451 
452     if (!PyArg_Parse(args, "s", &a)) return NULL;
453 
454     (*func) (obj, a[0]);
455 
456     Py_INCREF(Py_None);
457     return Py_None;
458 }
459 
460 /* void func (object, string) */
461 static PyObject *
call_forms_INstr(void (* func)(FL_OBJECT *,char *),FL_OBJECT * obj,PyObject * args)462 call_forms_INstr (void (*func)(FL_OBJECT *, char *), FL_OBJECT *obj, PyObject *args)
463 {
464     char *a;
465 
466     if (!PyArg_Parse(args, "s", &a)) return NULL;
467 
468     (*func) (obj, a);
469 
470     Py_INCREF(Py_None);
471     return Py_None;
472 }
473 
474 
475 /* void func (object, int, string) */
476 static PyObject *
call_forms_INiINstr(void (* func)(FL_OBJECT *,int,char *),FL_OBJECT * obj,PyObject * args)477 call_forms_INiINstr (void (*func)(FL_OBJECT *, int, char *), FL_OBJECT *obj, PyObject *args)
478 {
479     char *b;
480     int a;
481 
482     if (!PyArg_Parse(args, "(is)", &a, &b)) return NULL;
483 
484     (*func) (obj, a, b);
485 
486     Py_INCREF(Py_None);
487     return Py_None;
488 }
489 
490 #ifdef UNUSED
491 /* void func (object, int, int) */
492 static PyObject *
call_forms_INiINi(void (* func)(FL_OBJECT *,int,int),FL_OBJECT * obj,PyObject * args)493 call_forms_INiINi (void (*func)(FL_OBJECT *, int, int), FL_OBJECT *obj, PyObject *args)
494 {
495     int par1, par2;
496 
497     if (!PyArg_Parse(args, "(ii)", &par1, &par2)) return NULL;
498 
499     (*func) (obj, par1, par2);
500 
501     Py_INCREF(Py_None);
502     return Py_None;
503 }
504 #endif
505 
506 /* int func (object) */
507 static PyObject *
call_forms_Ri(int (* func)(FL_OBJECT *),FL_OBJECT * obj)508 call_forms_Ri (int (*func)(FL_OBJECT *), FL_OBJECT *obj)
509 {
510     int retval;
511 
512     retval = (*func) (obj);
513 
514     return PyInt_FromLong ((long) retval);
515 }
516 
517 /* char * func (object) */
518 static PyObject *
call_forms_Rstr(char * (* func)(FL_OBJECT *),FL_OBJECT * obj)519 call_forms_Rstr (char * (*func)(FL_OBJECT *), FL_OBJECT *obj)
520 {
521     char *str;
522 
523     str = (*func) (obj);
524 
525     if (str == NULL) {
526         Py_INCREF(Py_None);
527         return Py_None;
528     }
529     return PyString_FromString (str);
530 }
531 
532 /* int func (object) */
533 static PyObject *
call_forms_Rf(float (* func)(FL_OBJECT *),FL_OBJECT * obj)534 call_forms_Rf (float (*func)(FL_OBJECT *), FL_OBJECT *obj)
535 {
536     float retval;
537 
538     retval = (*func) (obj);
539 
540     return PyFloat_FromDouble (retval);
541 }
542 
543 static PyObject *
call_forms_OUTfOUTf(void (* func)(FL_OBJECT *,float *,float *),FL_OBJECT * obj)544 call_forms_OUTfOUTf (void (*func)(FL_OBJECT *, float *, float *), FL_OBJECT *obj)
545 {
546     float f1, f2;
547 
548     (*func) (obj, &f1, &f2);
549 
550     return Py_BuildValue("(ff)", f1, f2);
551 }
552 
553 #ifdef UNUSED
554 static PyObject *
call_forms_OUTf(void (* func)(FL_OBJECT *,float *),FL_OBJECT * obj)555 call_forms_OUTf (void (*func)(FL_OBJECT *, float *), FL_OBJECT *obj)
556 {
557     float f;
558 
559     (*func) (obj, &f);
560 
561     return PyFloat_FromDouble (f);
562 }
563 #endif
564 
565 /**********************************************************************/
566 /* Class : browser */
567 
568 static PyObject *
set_browser_topline(genericobject * g,PyObject * args)569 set_browser_topline(genericobject *g, PyObject *args)
570 {
571     return call_forms_INi (fl_set_browser_topline, g-> ob_generic, args);
572 }
573 
574 static PyObject *
clear_browser(genericobject * g)575 clear_browser(genericobject *g)
576 {
577     return generic_call (g, fl_clear_browser);
578 }
579 
580 static PyObject *
add_browser_line(genericobject * g,PyObject * args)581 add_browser_line (genericobject *g, PyObject *args)
582 {
583     return call_forms_INstr (fl_add_browser_line, g-> ob_generic, args);
584 }
585 
586 static PyObject *
addto_browser(genericobject * g,PyObject * args)587 addto_browser (genericobject *g, PyObject *args)
588 {
589     return call_forms_INstr (fl_addto_browser, g-> ob_generic, args);
590 }
591 
592 static PyObject *
insert_browser_line(genericobject * g,PyObject * args)593 insert_browser_line (genericobject *g, PyObject *args)
594 {
595     return call_forms_INiINstr (fl_insert_browser_line,
596                                 g-> ob_generic, args);
597 }
598 
599 static PyObject *
delete_browser_line(genericobject * g,PyObject * args)600 delete_browser_line (genericobject *g, PyObject *args)
601 {
602     return call_forms_INi (fl_delete_browser_line, g-> ob_generic, args);
603 }
604 
605 static PyObject *
replace_browser_line(genericobject * g,PyObject * args)606 replace_browser_line (genericobject *g, PyObject *args)
607 {
608     return call_forms_INiINstr (fl_replace_browser_line,
609                                 g-> ob_generic, args);
610 }
611 
612 static PyObject *
get_browser_line(genericobject * g,PyObject * args)613 get_browser_line(genericobject *g, PyObject *args)
614 {
615     int i;
616     char *str;
617 
618     if (!PyArg_Parse(args, "i", &i))
619         return NULL;
620 
621     str = fl_get_browser_line (g->ob_generic, i);
622 
623     if (str == NULL) {
624         Py_INCREF(Py_None);
625         return Py_None;
626     }
627     return PyString_FromString (str);
628 }
629 
630 static PyObject *
load_browser(genericobject * g,PyObject * args)631 load_browser (genericobject *g, PyObject *args)
632 {
633     /* XXX strictly speaking this is wrong since fl_load_browser
634        XXX returns int, not void */
635     return call_forms_INstr (fl_load_browser, g-> ob_generic, args);
636 }
637 
638 static PyObject *
get_browser_maxline(genericobject * g)639 get_browser_maxline(genericobject *g)
640 {
641     return call_forms_Ri (fl_get_browser_maxline, g-> ob_generic);
642 }
643 
644 static PyObject *
select_browser_line(genericobject * g,PyObject * args)645 select_browser_line (genericobject *g, PyObject *args)
646 {
647     return call_forms_INi (fl_select_browser_line, g-> ob_generic, args);
648 }
649 
650 static PyObject *
deselect_browser_line(genericobject * g,PyObject * args)651 deselect_browser_line (genericobject *g, PyObject *args)
652 {
653     return call_forms_INi (fl_deselect_browser_line, g-> ob_generic, args);
654 }
655 
656 static PyObject *
deselect_browser(genericobject * g)657 deselect_browser (genericobject *g)
658 {
659     return generic_call (g, fl_deselect_browser);
660 }
661 
662 static PyObject *
isselected_browser_line(genericobject * g,PyObject * args)663 isselected_browser_line (genericobject *g, PyObject *args)
664 {
665     int i, j;
666 
667     if (!PyArg_Parse(args, "i", &i))
668         return NULL;
669 
670     j = fl_isselected_browser_line (g->ob_generic, i);
671 
672     return PyInt_FromLong (j);
673 }
674 
675 static PyObject *
get_browser(genericobject * g)676 get_browser (genericobject *g)
677 {
678     return call_forms_Ri (fl_get_browser, g-> ob_generic);
679 }
680 
681 static PyObject *
set_browser_fontsize(genericobject * g,PyObject * args)682 set_browser_fontsize (genericobject *g, PyObject *args)
683 {
684     return call_forms_INf (fl_set_browser_fontsize, g-> ob_generic, args);
685 }
686 
687 static PyObject *
set_browser_fontstyle(genericobject * g,PyObject * args)688 set_browser_fontstyle (genericobject *g, PyObject *args)
689 {
690     return call_forms_INi (fl_set_browser_fontstyle, g-> ob_generic, args);
691 }
692 
693 static PyObject *
set_browser_specialkey(genericobject * g,PyObject * args)694 set_browser_specialkey (genericobject *g, PyObject *args)
695 {
696     return call_forms_INc(fl_set_browser_specialkey, g-> ob_generic, args);
697 }
698 
699 static PyMethodDef browser_methods[] = {
700     {"set_browser_topline",             (PyCFunction)set_browser_topline,
701      METH_OLDARGS},
702     {"clear_browser",                   (PyCFunction)clear_browser,
703      METH_NOARGS},
704     {"add_browser_line",                (PyCFunction)add_browser_line,
705      METH_OLDARGS},
706     {"addto_browser",                   (PyCFunction)addto_browser,
707      METH_OLDARGS},
708     {"insert_browser_line",             (PyCFunction)insert_browser_line,
709      METH_OLDARGS},
710     {"delete_browser_line",             (PyCFunction)delete_browser_line,
711      METH_OLDARGS},
712     {"replace_browser_line",            (PyCFunction)replace_browser_line,
713      METH_OLDARGS},
714     {"get_browser_line",                (PyCFunction)get_browser_line,
715      METH_OLDARGS},
716     {"load_browser",                    (PyCFunction)load_browser,
717      METH_OLDARGS},
718     {"get_browser_maxline",             (PyCFunction)get_browser_maxline,
719      METH_NOARGS,}
720     {"select_browser_line",             (PyCFunction)select_browser_line,
721      METH_OLDARGS},
722     {"deselect_browser_line",           (PyCFunction)deselect_browser_line,
723      METH_OLDARGS},
724     {"deselect_browser",                (PyCFunction)deselect_browser,
725      METH_NOARGS,}
726     {"isselected_browser_line",         (PyCFunction)isselected_browser_line,
727      METH_OLDARGS},
728     {"get_browser",                     (PyCFunction)get_browser,
729      METH_NOARGS,}
730     {"set_browser_fontsize",            (PyCFunction)set_browser_fontsize,
731      METH_OLDARGS},
732     {"set_browser_fontstyle",           (PyCFunction)set_browser_fontstyle,
733      METH_OLDARGS},
734     {"set_browser_specialkey",          (PyCFunction)set_browser_specialkey,
735      METH_OLDARGS},
736     {NULL,                              NULL}           /* sentinel */
737 };
738 
739 /* Class: button */
740 
741 static PyObject *
set_button(genericobject * g,PyObject * args)742 set_button(genericobject *g, PyObject *args)
743 {
744     return call_forms_INi (fl_set_button, g-> ob_generic, args);
745 }
746 
747 static PyObject *
get_button(genericobject * g)748 get_button(genericobject *g)
749 {
750     return call_forms_Ri (fl_get_button, g-> ob_generic);
751 }
752 
753 static PyObject *
get_button_numb(genericobject * g)754 get_button_numb(genericobject *g)
755 {
756     return call_forms_Ri (fl_get_button_numb, g-> ob_generic);
757 }
758 
759 static PyObject *
set_button_shortcut(genericobject * g,PyObject * args)760 set_button_shortcut(genericobject *g, PyObject *args)
761 {
762     return call_forms_INstr (fl_set_button_shortcut, g-> ob_generic, args);
763 }
764 
765 static PyMethodDef button_methods[] = {
766     {"set_button",              (PyCFunction)set_button, METH_OLDARGS},
767     {"get_button",              (PyCFunction)get_button, METH_NOARGS},
768     {"get_button_numb",         (PyCFunction)get_button_numb, METH_NOARGS},
769     {"set_button_shortcut",     (PyCFunction)set_button_shortcut, METH_OLDARGS},
770     {NULL,                      NULL}           /* sentinel */
771 };
772 
773 /* Class: choice */
774 
775 static PyObject *
set_choice(genericobject * g,PyObject * args)776 set_choice(genericobject *g, PyObject *args)
777 {
778     return call_forms_INi (fl_set_choice, g-> ob_generic, args);
779 }
780 
781 static PyObject *
get_choice(genericobject * g)782 get_choice(genericobject *g)
783 {
784     return call_forms_Ri (fl_get_choice, g-> ob_generic);
785 }
786 
787 static PyObject *
clear_choice(genericobject * g)788 clear_choice (genericobject *g)
789 {
790     return generic_call (g, fl_clear_choice);
791 }
792 
793 static PyObject *
addto_choice(genericobject * g,PyObject * args)794 addto_choice (genericobject *g, PyObject *args)
795 {
796     return call_forms_INstr (fl_addto_choice, g-> ob_generic, args);
797 }
798 
799 static PyObject *
replace_choice(genericobject * g,PyObject * args)800 replace_choice (genericobject *g, PyObject *args)
801 {
802     return call_forms_INiINstr (fl_replace_choice, g-> ob_generic, args);
803 }
804 
805 static PyObject *
delete_choice(genericobject * g,PyObject * args)806 delete_choice (genericobject *g, PyObject *args)
807 {
808     return call_forms_INi (fl_delete_choice, g-> ob_generic, args);
809 }
810 
811 static PyObject *
get_choice_text(genericobject * g)812 get_choice_text (genericobject *g)
813 {
814     return call_forms_Rstr (fl_get_choice_text, g-> ob_generic);
815 }
816 
817 static PyObject *
set_choice_fontsize(genericobject * g,PyObject * args)818 set_choice_fontsize (genericobject *g, PyObject *args)
819 {
820     return call_forms_INf (fl_set_choice_fontsize, g-> ob_generic, args);
821 }
822 
823 static PyObject *
set_choice_fontstyle(genericobject * g,PyObject * args)824 set_choice_fontstyle (genericobject *g, PyObject *args)
825 {
826     return call_forms_INi (fl_set_choice_fontstyle, g-> ob_generic, args);
827 }
828 
829 static PyMethodDef choice_methods[] = {
830     {"set_choice",              (PyCFunction)set_choice,      METH_OLDARGS},
831     {"get_choice",              (PyCFunction)get_choice,      METH_NOARGS},
832     {"clear_choice",            (PyCFunction)clear_choice,    METH_NOARGS},
833     {"addto_choice",            (PyCFunction)addto_choice,    METH_OLDARGS},
834     {"replace_choice",          (PyCFunction)replace_choice,  METH_OLDARGS},
835     {"delete_choice",           (PyCFunction)delete_choice,   METH_OLDARGS},
836     {"get_choice_text",         (PyCFunction)get_choice_text, METH_NOARGS},
837     {"set_choice_fontsize", (PyCFunction)set_choice_fontsize, METH_OLDARGS},
838     {"set_choice_fontstyle",(PyCFunction)set_choice_fontstyle, METH_OLDARGS},
839     {NULL,                      NULL}           /* sentinel */
840 };
841 
842 /* Class : Clock */
843 
844 static PyObject *
get_clock(genericobject * g)845 get_clock(genericobject *g)
846 {
847     int i0, i1, i2;
848 
849     fl_get_clock (g->ob_generic, &i0, &i1, &i2);
850 
851     return Py_BuildValue("(iii)", i0, i1, i2);
852 }
853 
854 static PyMethodDef clock_methods[] = {
855     {"get_clock",               (PyCFunction)get_clock, METH_NOARGS},
856     {NULL,                      NULL}           /* sentinel */
857 };
858 
859 /* CLass : Counters */
860 
861 static PyObject *
get_counter_value(genericobject * g)862 get_counter_value(genericobject *g)
863 {
864     return call_forms_Rf (fl_get_counter_value, g-> ob_generic);
865 }
866 
867 static PyObject *
set_counter_value(genericobject * g,PyObject * args)868 set_counter_value (genericobject *g, PyObject *args)
869 {
870     return call_forms_INf (fl_set_counter_value, g-> ob_generic, args);
871 }
872 
873 static PyObject *
set_counter_precision(genericobject * g,PyObject * args)874 set_counter_precision (genericobject *g, PyObject *args)
875 {
876     return call_forms_INi (fl_set_counter_precision, g-> ob_generic, args);
877 }
878 
879 static PyObject *
set_counter_bounds(genericobject * g,PyObject * args)880 set_counter_bounds (genericobject *g, PyObject *args)
881 {
882     return call_forms_INfINf (fl_set_counter_bounds, g-> ob_generic, args);
883 }
884 
885 static PyObject *
set_counter_step(genericobject * g,PyObject * args)886 set_counter_step (genericobject *g, PyObject *args)
887 {
888     return call_forms_INfINf (fl_set_counter_step, g-> ob_generic, args);
889 }
890 
891 static PyObject *
set_counter_return(genericobject * g,PyObject * args)892 set_counter_return (genericobject *g, PyObject *args)
893 {
894     return call_forms_INi (fl_set_counter_return, g-> ob_generic, args);
895 }
896 
897 static PyMethodDef counter_methods[] = {
898     {"set_counter_value",               (PyCFunction)set_counter_value,
899      METH_OLDARGS},
900     {"get_counter_value",               (PyCFunction)get_counter_value,
901      METH_NOARGS},
902     {"set_counter_bounds",              (PyCFunction)set_counter_bounds,
903      METH_OLDARGS},
904     {"set_counter_step",                (PyCFunction)set_counter_step,
905      METH_OLDARGS},
906     {"set_counter_precision",           (PyCFunction)set_counter_precision,
907      METH_OLDARGS},
908     {"set_counter_return",              (PyCFunction)set_counter_return,
909      METH_OLDARGS},
910     {NULL,                              NULL}           /* sentinel */
911 };
912 
913 
914 /* Class: Dials */
915 
916 static PyObject *
get_dial_value(genericobject * g)917 get_dial_value(genericobject *g)
918 {
919     return call_forms_Rf (fl_get_dial_value, g-> ob_generic);
920 }
921 
922 static PyObject *
set_dial_value(genericobject * g,PyObject * args)923 set_dial_value (genericobject *g, PyObject *args)
924 {
925     return call_forms_INf (fl_set_dial_value, g-> ob_generic, args);
926 }
927 
928 static PyObject *
set_dial_bounds(genericobject * g,PyObject * args)929 set_dial_bounds (genericobject *g, PyObject *args)
930 {
931     return call_forms_INfINf (fl_set_dial_bounds, g-> ob_generic, args);
932 }
933 
934 static PyObject *
get_dial_bounds(genericobject * g)935 get_dial_bounds (genericobject *g)
936 {
937     return call_forms_OUTfOUTf (fl_get_dial_bounds, g-> ob_generic);
938 }
939 
940 static PyObject *
set_dial_step(genericobject * g,PyObject * args)941 set_dial_step (genericobject *g, PyObject *args)
942 {
943     return call_forms_INf (fl_set_dial_step, g-> ob_generic, args);
944 }
945 
946 static PyMethodDef dial_methods[] = {
947     {"set_dial_value",          (PyCFunction)set_dial_value,  METH_OLDARGS},
948     {"get_dial_value",          (PyCFunction)get_dial_value,  METH_NOARGS},
949     {"set_dial_bounds",         (PyCFunction)set_dial_bounds, METH_OLDARGS},
950     {"get_dial_bounds",         (PyCFunction)get_dial_bounds, METH_NOARGS},
951     {"set_dial_step",           (PyCFunction)set_dial_step,   METH_OLDARGS},
952     {NULL,                      NULL}           /* sentinel */
953 };
954 
955 /* Class : Input */
956 
957 static PyObject *
set_input(genericobject * g,PyObject * args)958 set_input (genericobject *g, PyObject *args)
959 {
960     return call_forms_INstr (fl_set_input, g-> ob_generic, args);
961 }
962 
963 static PyObject *
get_input(genericobject * g)964 get_input (genericobject *g)
965 {
966     return call_forms_Rstr (fl_get_input, g-> ob_generic);
967 }
968 
969 static PyObject *
set_input_color(genericobject * g,PyObject * args)970 set_input_color (genericobject *g, PyObject *args)
971 {
972     return call_forms_INfINf (fl_set_input_color, g-> ob_generic, args);
973 }
974 
975 static PyObject *
set_input_return(genericobject * g,PyObject * args)976 set_input_return (genericobject *g, PyObject *args)
977 {
978     return call_forms_INi (fl_set_input_return, g-> ob_generic, args);
979 }
980 
981 static PyMethodDef input_methods[] = {
982     {"set_input",               (PyCFunction)set_input,        METH_OLDARGS},
983     {"get_input",               (PyCFunction)get_input,        METH_NOARGS},
984     {"set_input_color",         (PyCFunction)set_input_color,  METH_OLDARGS},
985     {"set_input_return",        (PyCFunction)set_input_return, METH_OLDARGS},
986     {NULL,                      NULL}           /* sentinel */
987 };
988 
989 
990 /* Class : Menu */
991 
992 static PyObject *
set_menu(genericobject * g,PyObject * args)993 set_menu (genericobject *g, PyObject *args)
994 {
995     return call_forms_INstr (fl_set_menu, g-> ob_generic, args);
996 }
997 
998 static PyObject *
get_menu(genericobject * g)999 get_menu (genericobject *g)
1000 {
1001     /* XXX strictly speaking this is wrong since fl_get_menu
1002        XXX returns long, not int */
1003     return call_forms_Ri (fl_get_menu, g-> ob_generic);
1004 }
1005 
1006 static PyObject *
get_menu_text(genericobject * g)1007 get_menu_text (genericobject *g)
1008 {
1009     return call_forms_Rstr (fl_get_menu_text, g-> ob_generic);
1010 }
1011 
1012 static PyObject *
addto_menu(genericobject * g,PyObject * args)1013 addto_menu (genericobject *g, PyObject *args)
1014 {
1015     return call_forms_INstr (fl_addto_menu, g-> ob_generic, args);
1016 }
1017 
1018 static PyMethodDef menu_methods[] = {
1019     {"set_menu",                (PyCFunction)set_menu,      METH_OLDARGS},
1020     {"get_menu",                (PyCFunction)get_menu,      METH_NOARGS},
1021     {"get_menu_text",           (PyCFunction)get_menu_text, METH_NOARGS},
1022     {"addto_menu",              (PyCFunction)addto_menu,    METH_OLDARGS},
1023     {NULL,                      NULL}           /* sentinel */
1024 };
1025 
1026 
1027 /* Class: Sliders */
1028 
1029 static PyObject *
get_slider_value(genericobject * g)1030 get_slider_value(genericobject *g)
1031 {
1032     return call_forms_Rf (fl_get_slider_value, g-> ob_generic);
1033 }
1034 
1035 static PyObject *
set_slider_value(genericobject * g,PyObject * args)1036 set_slider_value (genericobject *g, PyObject *args)
1037 {
1038     return call_forms_INf (fl_set_slider_value, g-> ob_generic, args);
1039 }
1040 
1041 static PyObject *
set_slider_bounds(genericobject * g,PyObject * args)1042 set_slider_bounds (genericobject *g, PyObject *args)
1043 {
1044     return call_forms_INfINf (fl_set_slider_bounds, g-> ob_generic, args);
1045 }
1046 
1047 static PyObject *
get_slider_bounds(genericobject * g)1048 get_slider_bounds (genericobject *g)
1049 {
1050     return call_forms_OUTfOUTf(fl_get_slider_bounds, g-> ob_generic);
1051 }
1052 
1053 static PyObject *
set_slider_return(genericobject * g,PyObject * args)1054 set_slider_return (genericobject *g, PyObject *args)
1055 {
1056     return call_forms_INf (fl_set_slider_return, g-> ob_generic, args);
1057 }
1058 
1059 static PyObject *
set_slider_size(genericobject * g,PyObject * args)1060 set_slider_size (genericobject *g, PyObject *args)
1061 {
1062     return call_forms_INf (fl_set_slider_size, g-> ob_generic, args);
1063 }
1064 
1065 static PyObject *
set_slider_precision(genericobject * g,PyObject * args)1066 set_slider_precision (genericobject *g, PyObject *args)
1067 {
1068     return call_forms_INi (fl_set_slider_precision, g-> ob_generic, args);
1069 }
1070 
1071 static PyObject *
set_slider_step(genericobject * g,PyObject * args)1072 set_slider_step (genericobject *g, PyObject *args)
1073 {
1074     return call_forms_INf (fl_set_slider_step, g-> ob_generic, args);
1075 }
1076 
1077 
1078 static PyMethodDef slider_methods[] = {
1079     {"set_slider_value",        (PyCFunction)set_slider_value,  METH_OLDARGS},
1080     {"get_slider_value",        (PyCFunction)get_slider_value,  METH_NOARGS},
1081     {"set_slider_bounds",       (PyCFunction)set_slider_bounds, METH_OLDARGS},
1082     {"get_slider_bounds",       (PyCFunction)get_slider_bounds, METH_NOARGS},
1083     {"set_slider_return",       (PyCFunction)set_slider_return, METH_OLDARGS},
1084     {"set_slider_size",         (PyCFunction)set_slider_size,   METH_OLDARGS},
1085     {"set_slider_precision",(PyCFunction)set_slider_precision, METH_OLDARGS},
1086     {"set_slider_step",         (PyCFunction)set_slider_step,   METH_OLDARGS},
1087     {NULL,                      NULL}           /* sentinel */
1088 };
1089 
1090 static PyObject *
set_positioner_xvalue(genericobject * g,PyObject * args)1091 set_positioner_xvalue (genericobject *g, PyObject *args)
1092 {
1093     return call_forms_INf (fl_set_positioner_xvalue, g-> ob_generic, args);
1094 }
1095 
1096 static PyObject *
set_positioner_xbounds(genericobject * g,PyObject * args)1097 set_positioner_xbounds (genericobject *g, PyObject *args)
1098 {
1099     return call_forms_INfINf (fl_set_positioner_xbounds,
1100                               g-> ob_generic, args);
1101 }
1102 
1103 static PyObject *
set_positioner_yvalue(genericobject * g,PyObject * args)1104 set_positioner_yvalue (genericobject *g, PyObject *args)
1105 {
1106     return call_forms_INf (fl_set_positioner_yvalue, g-> ob_generic, args);
1107 }
1108 
1109 static PyObject *
set_positioner_ybounds(genericobject * g,PyObject * args)1110 set_positioner_ybounds (genericobject *g, PyObject *args)
1111 {
1112     return call_forms_INfINf (fl_set_positioner_ybounds,
1113                               g-> ob_generic, args);
1114 }
1115 
1116 static PyObject *
get_positioner_xvalue(genericobject * g)1117 get_positioner_xvalue (genericobject *g)
1118 {
1119     return call_forms_Rf (fl_get_positioner_xvalue, g-> ob_generic);
1120 }
1121 
1122 static PyObject *
get_positioner_xbounds(genericobject * g)1123 get_positioner_xbounds (genericobject *g)
1124 {
1125     return call_forms_OUTfOUTf (fl_get_positioner_xbounds, g-> ob_generic);
1126 }
1127 
1128 static PyObject *
get_positioner_yvalue(genericobject * g)1129 get_positioner_yvalue (genericobject *g)
1130 {
1131     return call_forms_Rf (fl_get_positioner_yvalue, g-> ob_generic);
1132 }
1133 
1134 static PyObject *
get_positioner_ybounds(genericobject * g)1135 get_positioner_ybounds (genericobject *g)
1136 {
1137     return call_forms_OUTfOUTf (fl_get_positioner_ybounds, g-> ob_generic);
1138 }
1139 
1140 static PyMethodDef positioner_methods[] = {
1141     {"set_positioner_xvalue",           (PyCFunction)set_positioner_xvalue,
1142      METH_OLDARGS},
1143     {"set_positioner_yvalue",           (PyCFunction)set_positioner_yvalue,
1144      METH_OLDARGS},
1145     {"set_positioner_xbounds",          (PyCFunction)set_positioner_xbounds,
1146      METH_OLDARGS},
1147     {"set_positioner_ybounds",          (PyCFunction)set_positioner_ybounds,
1148      METH_OLDARGS},
1149     {"get_positioner_xvalue",           (PyCFunction)get_positioner_xvalue,
1150      METH_NOARGS},
1151     {"get_positioner_yvalue",           (PyCFunction)get_positioner_yvalue,
1152      METH_NOARGS},
1153     {"get_positioner_xbounds",          (PyCFunction)get_positioner_xbounds,
1154      METH_NOARGS},
1155     {"get_positioner_ybounds",          (PyCFunction)get_positioner_ybounds,
1156      METH_NOARGS},
1157     {NULL,                      NULL}           /* sentinel */
1158 };
1159 
1160 /* Class timer */
1161 
1162 static PyObject *
set_timer(genericobject * g,PyObject * args)1163 set_timer (genericobject *g, PyObject *args)
1164 {
1165     return call_forms_INf (fl_set_timer, g-> ob_generic, args);
1166 }
1167 
1168 static PyObject *
get_timer(genericobject * g)1169 get_timer (genericobject *g)
1170 {
1171     return call_forms_Rf (fl_get_timer, g-> ob_generic);
1172 }
1173 
1174 static PyMethodDef timer_methods[] = {
1175     {"set_timer",               (PyCFunction)set_timer, METH_OLDARGS},
1176     {"get_timer",               (PyCFunction)get_timer, METH_NOARGS},
1177     {NULL,                      NULL}           /* sentinel */
1178 };
1179 
1180 /* Form objects */
1181 
1182 typedef struct {
1183     PyObject_HEAD
1184     FL_FORM *ob_form;
1185 } formobject;
1186 
1187 static PyTypeObject Formtype;
1188 
1189 #define is_formobject(v) ((v)->ob_type == &Formtype)
1190 
1191 static PyObject *
form_show_form(formobject * f,PyObject * args)1192 form_show_form(formobject *f, PyObject *args)
1193 {
1194     int place, border;
1195     char *name;
1196     if (!PyArg_Parse(args, "(iis)", &place, &border, &name))
1197         return NULL;
1198     fl_show_form(f->ob_form, place, border, name);
1199     Py_INCREF(Py_None);
1200     return Py_None;
1201 }
1202 
1203 static PyObject *
form_call(void (* func)(FL_FORM *),FL_FORM * f)1204 form_call(void (*func)(FL_FORM *), FL_FORM *f)
1205 {
1206     (*func)(f);
1207 
1208     Py_INCREF(Py_None);
1209     return Py_None;
1210 }
1211 
1212 static PyObject *
form_call_INiINi(void (* func)(FL_FORM *,int,int),FL_FORM * f,PyObject * args)1213 form_call_INiINi(void (*func)(FL_FORM *, int, int), FL_FORM *f, PyObject *args)
1214 {
1215     int a, b;
1216 
1217     if (!PyArg_Parse(args, "(ii)", &a, &b)) return NULL;
1218 
1219     (*func)(f, a, b);
1220 
1221     Py_INCREF(Py_None);
1222     return Py_None;
1223 }
1224 
1225 static PyObject *
form_call_INfINf(void (* func)(FL_FORM *,float,float),FL_FORM * f,PyObject * args)1226 form_call_INfINf(void (*func)(FL_FORM *, float, float), FL_FORM *f, PyObject *args)
1227 {
1228     float a, b;
1229 
1230     if (!PyArg_Parse(args, "(ff)", &a, &b)) return NULL;
1231 
1232     (*func)(f, a, b);
1233 
1234     Py_INCREF(Py_None);
1235     return Py_None;
1236 }
1237 
1238 static PyObject *
form_hide_form(formobject * f)1239 form_hide_form(formobject *f)
1240 {
1241     return form_call(fl_hide_form, f-> ob_form);
1242 }
1243 
1244 static PyObject *
form_redraw_form(formobject * f)1245 form_redraw_form(formobject *f)
1246 {
1247     return form_call(fl_redraw_form, f-> ob_form);
1248 }
1249 
1250 static PyObject *
form_set_form_position(formobject * f,PyObject * args)1251 form_set_form_position(formobject *f, PyObject *args)
1252 {
1253     return form_call_INiINi(fl_set_form_position, f-> ob_form, args);
1254 }
1255 
1256 static PyObject *
form_set_form_size(formobject * f,PyObject * args)1257 form_set_form_size(formobject *f, PyObject *args)
1258 {
1259     return form_call_INiINi(fl_set_form_size, f-> ob_form, args);
1260 }
1261 
1262 static PyObject *
form_scale_form(formobject * f,PyObject * args)1263 form_scale_form(formobject *f, PyObject *args)
1264 {
1265     return form_call_INfINf(fl_scale_form, f-> ob_form, args);
1266 }
1267 
1268 static PyObject *
generic_add_object(formobject * f,PyObject * args,FL_OBJECT * (* func)(int,float,float,float,float,char *),PyMethodDef * internal_methods)1269 generic_add_object(formobject *f, PyObject *args, FL_OBJECT *(*func)(int, float, float, float, float, char*), PyMethodDef *internal_methods)
1270 {
1271     int type;
1272     float x, y, w, h;
1273     char *name;
1274     FL_OBJECT *obj;
1275 
1276     if (!PyArg_Parse(args,"(iffffs)", &type,&x,&y,&w,&h,&name))
1277         return NULL;
1278 
1279     fl_addto_form (f-> ob_form);
1280 
1281     obj = (*func) (type, x, y, w, h, name);
1282 
1283     fl_end_form();
1284 
1285     if (obj == NULL) {
1286         PyErr_NoMemory();
1287         return NULL;
1288     }
1289 
1290     return newgenericobject (obj, internal_methods);
1291 }
1292 
1293 static PyObject *
form_add_button(formobject * f,PyObject * args)1294 form_add_button(formobject *f, PyObject *args)
1295 {
1296     return generic_add_object(f, args, fl_add_button, button_methods);
1297 }
1298 
1299 static PyObject *
form_add_lightbutton(formobject * f,PyObject * args)1300 form_add_lightbutton(formobject *f, PyObject *args)
1301 {
1302     return generic_add_object(f, args, fl_add_lightbutton, button_methods);
1303 }
1304 
1305 static PyObject *
form_add_roundbutton(formobject * f,PyObject * args)1306 form_add_roundbutton(formobject *f, PyObject *args)
1307 {
1308     return generic_add_object(f, args, fl_add_roundbutton, button_methods);
1309 }
1310 
1311 static PyObject *
form_add_menu(formobject * f,PyObject * args)1312 form_add_menu (formobject *f, PyObject *args)
1313 {
1314     return generic_add_object(f, args, fl_add_menu, menu_methods);
1315 }
1316 
1317 static PyObject *
form_add_slider(formobject * f,PyObject * args)1318 form_add_slider(formobject *f, PyObject *args)
1319 {
1320     return generic_add_object(f, args, fl_add_slider, slider_methods);
1321 }
1322 
1323 static PyObject *
form_add_valslider(formobject * f,PyObject * args)1324 form_add_valslider(formobject *f, PyObject *args)
1325 {
1326     return generic_add_object(f, args, fl_add_valslider, slider_methods);
1327 }
1328 
1329 static PyObject *
form_add_dial(formobject * f,PyObject * args)1330 form_add_dial(formobject *f, PyObject *args)
1331 {
1332     return generic_add_object(f, args, fl_add_dial, dial_methods);
1333 }
1334 
1335 static PyObject *
form_add_counter(formobject * f,PyObject * args)1336 form_add_counter(formobject *f, PyObject *args)
1337 {
1338     return generic_add_object(f, args, fl_add_counter, counter_methods);
1339 }
1340 
1341 static PyObject *
form_add_clock(formobject * f,PyObject * args)1342 form_add_clock(formobject *f, PyObject *args)
1343 {
1344     return generic_add_object(f, args, fl_add_clock, clock_methods);
1345 }
1346 
1347 static PyObject *
form_add_box(formobject * f,PyObject * args)1348 form_add_box(formobject *f, PyObject *args)
1349 {
1350     return generic_add_object(f, args, fl_add_box,
1351                               (PyMethodDef *)NULL);
1352 }
1353 
1354 static PyObject *
form_add_choice(formobject * f,PyObject * args)1355 form_add_choice(formobject *f, PyObject *args)
1356 {
1357     return generic_add_object(f, args, fl_add_choice, choice_methods);
1358 }
1359 
1360 static PyObject *
form_add_browser(formobject * f,PyObject * args)1361 form_add_browser(formobject *f, PyObject *args)
1362 {
1363     return generic_add_object(f, args, fl_add_browser, browser_methods);
1364 }
1365 
1366 static PyObject *
form_add_positioner(formobject * f,PyObject * args)1367 form_add_positioner(formobject *f, PyObject *args)
1368 {
1369     return generic_add_object(f, args, fl_add_positioner,
1370                               positioner_methods);
1371 }
1372 
1373 static PyObject *
form_add_input(formobject * f,PyObject * args)1374 form_add_input(formobject *f, PyObject *args)
1375 {
1376     return generic_add_object(f, args, fl_add_input, input_methods);
1377 }
1378 
1379 static PyObject *
form_add_text(formobject * f,PyObject * args)1380 form_add_text(formobject *f, PyObject *args)
1381 {
1382     return generic_add_object(f, args, fl_add_text,
1383                               (PyMethodDef *)NULL);
1384 }
1385 
1386 static PyObject *
form_add_timer(formobject * f,PyObject * args)1387 form_add_timer(formobject *f, PyObject *args)
1388 {
1389     return generic_add_object(f, args, fl_add_timer, timer_methods);
1390 }
1391 
1392 static PyObject *
form_freeze_form(formobject * f)1393 form_freeze_form(formobject *f)
1394 {
1395     return form_call(fl_freeze_form, f-> ob_form);
1396 }
1397 
1398 static PyObject *
form_unfreeze_form(formobject * f)1399 form_unfreeze_form(formobject *f)
1400 {
1401     return form_call(fl_unfreeze_form, f-> ob_form);
1402 }
1403 
1404 static PyObject *
form_activate_form(formobject * f)1405 form_activate_form(formobject *f)
1406 {
1407     return form_call(fl_activate_form, f-> ob_form);
1408 }
1409 
1410 static PyObject *
form_deactivate_form(formobject * f)1411 form_deactivate_form(formobject *f)
1412 {
1413     return form_call(fl_deactivate_form, f-> ob_form);
1414 }
1415 
1416 static PyObject *
form_bgn_group(formobject * f,PyObject * args)1417 form_bgn_group(formobject *f, PyObject *args)
1418 {
1419     FL_OBJECT *obj;
1420 
1421     fl_addto_form(f-> ob_form);
1422     obj = fl_bgn_group();
1423     fl_end_form();
1424 
1425     if (obj == NULL) {
1426         PyErr_NoMemory();
1427         return NULL;
1428     }
1429 
1430     return newgenericobject (obj, (PyMethodDef *) NULL);
1431 }
1432 
1433 static PyObject *
form_end_group(formobject * f,PyObject * args)1434 form_end_group(formobject *f, PyObject *args)
1435 {
1436     fl_addto_form(f-> ob_form);
1437     fl_end_group();
1438     fl_end_form();
1439     Py_INCREF(Py_None);
1440     return Py_None;
1441 }
1442 
1443 static PyObject *
forms_find_first_or_last(FL_OBJECT * (* func)(FL_FORM *,int,float,float),formobject * f,PyObject * args)1444 forms_find_first_or_last(FL_OBJECT *(*func)(FL_FORM *, int, float, float), formobject *f, PyObject *args)
1445 {
1446     int type;
1447     float mx, my;
1448     FL_OBJECT *generic;
1449     genericobject *g;
1450 
1451     if (!PyArg_Parse(args, "(iff)", &type, &mx, &my)) return NULL;
1452 
1453     generic = (*func) (f-> ob_form, type, mx, my);
1454 
1455     if (generic == NULL)
1456     {
1457         Py_INCREF(Py_None);
1458         return Py_None;
1459     }
1460 
1461     g = findgeneric(generic);
1462     if (g == NULL) {
1463         PyErr_SetString(PyExc_RuntimeError,
1464                    "forms_find_{first|last} returns unknown object");
1465         return NULL;
1466     }
1467     Py_INCREF(g);
1468     return (PyObject *) g;
1469 }
1470 
1471 static PyObject *
form_find_first(formobject * f,PyObject * args)1472 form_find_first(formobject *f, PyObject *args)
1473 {
1474     return forms_find_first_or_last(fl_find_first, f, args);
1475 }
1476 
1477 static PyObject *
form_find_last(formobject * f,PyObject * args)1478 form_find_last(formobject *f, PyObject *args)
1479 {
1480     return forms_find_first_or_last(fl_find_last, f, args);
1481 }
1482 
1483 static PyObject *
form_set_object_focus(formobject * f,PyObject * args)1484 form_set_object_focus(formobject *f, PyObject *args)
1485 {
1486     genericobject *g;
1487     if (args == NULL || !is_genericobject(args)) {
1488         PyErr_BadArgument();
1489         return NULL;
1490     }
1491     g = (genericobject *)args;
1492     fl_set_object_focus(f->ob_form, g->ob_generic);
1493     Py_INCREF(Py_None);
1494     return Py_None;
1495 }
1496 
1497 static PyMethodDef form_methods[] = {
1498 /* adm */
1499     {"show_form",               (PyCFunction)form_show_form,     METH_OLDARGS},
1500     {"hide_form",               (PyCFunction)form_hide_form,     METH_NOARGS},
1501     {"redraw_form",             (PyCFunction)form_redraw_form,   METH_NOARGS},
1502     {"set_form_position",       (PyCFunction)form_set_form_position, METH_OLDARGS},
1503     {"set_form_size",           (PyCFunction)form_set_form_size, METH_OLDARGS},
1504     {"scale_form",              (PyCFunction)form_scale_form,    METH_OLDARGS},
1505     {"freeze_form",             (PyCFunction)form_freeze_form,   METH_NOARGS},
1506     {"unfreeze_form",           (PyCFunction)form_unfreeze_form, METH_NOARGS},
1507     {"activate_form",           (PyCFunction)form_activate_form, METH_NOARGS},
1508     {"deactivate_form",         (PyCFunction)form_deactivate_form, METH_NOARGS},
1509     {"bgn_group",               (PyCFunction)form_bgn_group,  METH_OLDARGS},
1510     {"end_group",               (PyCFunction)form_end_group,  METH_OLDARGS},
1511     {"find_first",              (PyCFunction)form_find_first, METH_OLDARGS},
1512     {"find_last",               (PyCFunction)form_find_last,  METH_OLDARGS},
1513     {"set_object_focus",        (PyCFunction)form_set_object_focus, METH_OLDARGS},
1514 
1515 /* basic objects */
1516     {"add_button",              (PyCFunction)form_add_button, METH_OLDARGS},
1517 /*      {"add_bitmap",          (method)form_add_bitmap, METH_OLDARGS}, */
1518     {"add_lightbutton",         (PyCFunction)form_add_lightbutton, METH_OLDARGS},
1519     {"add_roundbutton",         (PyCFunction)form_add_roundbutton, METH_OLDARGS},
1520     {"add_menu",                (PyCFunction)form_add_menu,      METH_OLDARGS},
1521     {"add_slider",              (PyCFunction)form_add_slider,    METH_OLDARGS},
1522     {"add_positioner",          (PyCFunction)form_add_positioner, METH_OLDARGS},
1523     {"add_valslider",           (PyCFunction)form_add_valslider, METH_OLDARGS},
1524     {"add_dial",                (PyCFunction)form_add_dial,      METH_OLDARGS},
1525     {"add_counter",             (PyCFunction)form_add_counter,   METH_OLDARGS},
1526     {"add_box",                 (PyCFunction)form_add_box,       METH_OLDARGS},
1527     {"add_clock",               (PyCFunction)form_add_clock,     METH_OLDARGS},
1528     {"add_choice",              (PyCFunction)form_add_choice,    METH_OLDARGS},
1529     {"add_browser",             (PyCFunction)form_add_browser,   METH_OLDARGS},
1530     {"add_input",               (PyCFunction)form_add_input,     METH_OLDARGS},
1531     {"add_timer",               (PyCFunction)form_add_timer,     METH_OLDARGS},
1532     {"add_text",                (PyCFunction)form_add_text,      METH_OLDARGS},
1533     {NULL,                      NULL}           /* sentinel */
1534 };
1535 
1536 static void
form_dealloc(formobject * f)1537 form_dealloc(formobject *f)
1538 {
1539     releaseobjects(f->ob_form);
1540     if (f->ob_form->visible)
1541         fl_hide_form(f->ob_form);
1542     fl_free_form(f->ob_form);
1543     PyObject_Del(f);
1544 }
1545 
1546 #define OFF(x) offsetof(FL_FORM, x)
1547 
1548 static struct memberlist form_memberlist[] = {
1549     {"window",          T_LONG,         OFF(window),    RO},
1550     {"w",               T_FLOAT,        OFF(w)},
1551     {"h",               T_FLOAT,        OFF(h)},
1552     {"x",               T_FLOAT,        OFF(x),         RO},
1553     {"y",               T_FLOAT,        OFF(y),         RO},
1554     {"deactivated",     T_INT,          OFF(deactivated)},
1555     {"visible",         T_INT,          OFF(visible),   RO},
1556     {"frozen",          T_INT,          OFF(frozen),    RO},
1557     {"doublebuf",       T_INT,          OFF(doublebuf)},
1558     {NULL}      /* Sentinel */
1559 };
1560 
1561 #undef OFF
1562 
1563 static PyObject *
form_getattr(formobject * f,char * name)1564 form_getattr(formobject *f, char *name)
1565 {
1566     PyObject *meth;
1567 
1568     meth = Py_FindMethod(form_methods, (PyObject *)f, name);
1569     if (meth != NULL)
1570         return meth;
1571     PyErr_Clear();
1572     return PyMember_Get((char *)f->ob_form, form_memberlist, name);
1573 }
1574 
1575 static int
form_setattr(formobject * f,char * name,PyObject * v)1576 form_setattr(formobject *f, char *name, PyObject *v)
1577 {
1578     if (v == NULL) {
1579         PyErr_SetString(PyExc_TypeError,
1580                         "can't delete form attributes");
1581         return -1;
1582     }
1583 
1584     return PyMember_Set((char *)f->ob_form, form_memberlist, name, v);
1585 }
1586 
1587 static PyObject *
form_repr(formobject * f)1588 form_repr(formobject *f)
1589 {
1590     char buf[100];
1591     PyOS_snprintf(buf, sizeof(buf), "<FORMS_form at %p, window=%ld>",
1592                   f, f->ob_form->window);
1593     return PyString_FromString(buf);
1594 }
1595 
1596 static PyTypeObject Formtype = {
1597     PyObject_HEAD_INIT(&PyType_Type)
1598     0,                                  /*ob_size*/
1599     "fl.FORMS_form",                    /*tp_name*/
1600     sizeof(formobject),                 /*tp_size*/
1601     0,                                  /*tp_itemsize*/
1602     /* methods */
1603     (destructor)form_dealloc,           /*tp_dealloc*/
1604     0,                                  /*tp_print*/
1605     (getattrfunc)form_getattr,          /*tp_getattr*/
1606     (setattrfunc)form_setattr,          /*tp_setattr*/
1607     0,                                  /*tp_compare*/
1608     (reprfunc)form_repr,                /*tp_repr*/
1609 };
1610 
1611 static PyObject *
newformobject(FL_FORM * form)1612 newformobject(FL_FORM *form)
1613 {
1614     formobject *f;
1615     f = PyObject_New(formobject, &Formtype);
1616     if (f == NULL)
1617         return NULL;
1618     f->ob_form = form;
1619     return (PyObject *)f;
1620 }
1621 
1622 
1623 /* The "fl" module */
1624 
1625 static PyObject *
forms_make_form(PyObject * dummy,PyObject * args)1626 forms_make_form(PyObject *dummy, PyObject *args)
1627 {
1628     int type;
1629     float w, h;
1630     FL_FORM *form;
1631     if (!PyArg_Parse(args, "(iff)", &type, &w, &h))
1632         return NULL;
1633     form = fl_bgn_form(type, w, h);
1634     if (form == NULL) {
1635         /* XXX Actually, cannot happen! */
1636         PyErr_NoMemory();
1637         return NULL;
1638     }
1639     fl_end_form();
1640     return newformobject(form);
1641 }
1642 
1643 static PyObject *
forms_activate_all_forms(PyObject * f,PyObject * args)1644 forms_activate_all_forms(PyObject *f, PyObject *args)
1645 {
1646     fl_activate_all_forms();
1647     Py_INCREF(Py_None);
1648     return Py_None;
1649 }
1650 
1651 static PyObject *
forms_deactivate_all_forms(PyObject * f,PyObject * args)1652 forms_deactivate_all_forms(PyObject *f, PyObject *args)
1653 {
1654     fl_deactivate_all_forms();
1655     Py_INCREF(Py_None);
1656     return Py_None;
1657 }
1658 
1659 static PyObject *my_event_callback = NULL;
1660 
1661 static PyObject *
forms_set_event_call_back(PyObject * dummy,PyObject * args)1662 forms_set_event_call_back(PyObject *dummy, PyObject *args)
1663 {
1664     if (args == Py_None)
1665         args = NULL;
1666     my_event_callback = args;
1667     Py_XINCREF(args);
1668     Py_INCREF(Py_None);
1669     return Py_None;
1670 }
1671 
1672 static PyObject *
forms_do_or_check_forms(PyObject * dummy,FL_OBJECT * (* func)(void))1673 forms_do_or_check_forms(PyObject *dummy, FL_OBJECT *(*func)(void))
1674 {
1675     FL_OBJECT *generic;
1676     genericobject *g;
1677     PyObject *arg, *res;
1678 
1679     for (;;) {
1680         Py_BEGIN_ALLOW_THREADS
1681         generic = (*func)();
1682         Py_END_ALLOW_THREADS
1683         if (generic == NULL) {
1684             Py_INCREF(Py_None);
1685             return Py_None;
1686         }
1687         if (generic == FL_EVENT) {
1688             int dev;
1689             short val;
1690             if (my_event_callback == NULL)
1691                 return PyInt_FromLong(-1L);
1692             dev = fl_qread(&val);
1693             arg = Py_BuildValue("(ih)", dev, val);
1694             if (arg == NULL)
1695                 return NULL;
1696             res = PyEval_CallObject(my_event_callback, arg);
1697             Py_XDECREF(res);
1698             Py_DECREF(arg);
1699             if (res == NULL)
1700                 return NULL; /* Callback raised exception */
1701             continue;
1702         }
1703         g = findgeneric(generic);
1704         if (g == NULL) {
1705             /* Object not known to us (some dialogs cause this) */
1706             continue; /* Ignore it */
1707         }
1708         if (g->ob_callback == NULL) {
1709             Py_INCREF(g);
1710             return ((PyObject *) g);
1711         }
1712         arg = PyTuple_Pack(2, (PyObject *)g, g->ob_callback_arg);
1713         if (arg == NULL)
1714             return NULL;
1715         res = PyEval_CallObject(g->ob_callback, arg);
1716         Py_XDECREF(res);
1717         Py_DECREF(arg);
1718         if (res == NULL)
1719             return NULL; /* Callback raised exception */
1720     }
1721 }
1722 
1723 static PyObject *
forms_do_forms(PyObject * dummy)1724 forms_do_forms(PyObject *dummy)
1725 {
1726     return forms_do_or_check_forms(dummy, fl_do_forms);
1727 }
1728 
1729 static PyObject *
forms_check_forms(PyObject * dummy)1730 forms_check_forms(PyObject *dummy)
1731 {
1732     return forms_do_or_check_forms(dummy, fl_check_forms);
1733 }
1734 
1735 static PyObject *
forms_do_only_forms(PyObject * dummy)1736 forms_do_only_forms(PyObject *dummy)
1737 {
1738     return forms_do_or_check_forms(dummy, fl_do_only_forms);
1739 }
1740 
1741 static PyObject *
forms_check_only_forms(PyObject * dummy)1742 forms_check_only_forms(PyObject *dummy)
1743 {
1744     return forms_do_or_check_forms(dummy, fl_check_only_forms);
1745 }
1746 
1747 #ifdef UNUSED
1748 static PyObject *
fl_call(void (* func)(void))1749 fl_call(void (*func)(void))
1750 {
1751     (*func)();
1752     Py_INCREF(Py_None);
1753     return Py_None;
1754 }
1755 #endif
1756 
1757 static PyObject *
forms_set_graphics_mode(PyObject * dummy,PyObject * args)1758 forms_set_graphics_mode(PyObject *dummy, PyObject *args)
1759 {
1760     int rgbmode, doublebuf;
1761 
1762     if (!PyArg_Parse(args, "(ii)", &rgbmode, &doublebuf))
1763         return NULL;
1764     fl_set_graphics_mode(rgbmode,doublebuf);
1765     Py_INCREF(Py_None);
1766     return Py_None;
1767 }
1768 
1769 static PyObject *
forms_get_rgbmode(PyObject * dummy,PyObject * args)1770 forms_get_rgbmode(PyObject *dummy, PyObject *args)
1771 {
1772     extern int fl_rgbmode;
1773 
1774     if (args != NULL) {
1775         PyErr_BadArgument();
1776         return NULL;
1777     }
1778     return PyInt_FromLong((long)fl_rgbmode);
1779 }
1780 
1781 static PyObject *
forms_show_errors(PyObject * dummy,PyObject * args)1782 forms_show_errors(PyObject *dummy, PyObject *args)
1783 {
1784     int show;
1785     if (!PyArg_Parse(args, "i", &show))
1786         return NULL;
1787     fl_show_errors(show);
1788     Py_INCREF(Py_None);
1789     return Py_None;
1790 }
1791 
1792 static PyObject *
forms_set_font_name(PyObject * dummy,PyObject * args)1793 forms_set_font_name(PyObject *dummy, PyObject *args)
1794 {
1795     int numb;
1796     char *name;
1797     if (!PyArg_Parse(args, "(is)", &numb, &name))
1798         return NULL;
1799     fl_set_font_name(numb, name);
1800     Py_INCREF(Py_None);
1801     return Py_None;
1802 }
1803 
1804 
1805 static PyObject *
forms_qdevice(PyObject * self,PyObject * args)1806 forms_qdevice(PyObject *self, PyObject *args)
1807 {
1808     short arg1;
1809     if (!PyArg_Parse(args, "h", &arg1))
1810         return NULL;
1811     fl_qdevice(arg1);
1812     Py_INCREF(Py_None);
1813     return Py_None;
1814 }
1815 
1816 static PyObject *
forms_unqdevice(PyObject * self,PyObject * args)1817 forms_unqdevice(PyObject *self, PyObject *args)
1818 {
1819     short arg1;
1820     if (!PyArg_Parse(args, "h", &arg1))
1821         return NULL;
1822     fl_unqdevice(arg1);
1823     Py_INCREF(Py_None);
1824     return Py_None;
1825 }
1826 
1827 static PyObject *
forms_isqueued(PyObject * self,PyObject * args)1828 forms_isqueued(PyObject *self, PyObject *args)
1829 {
1830     long retval;
1831     short arg1;
1832     if (!PyArg_Parse(args, "h", &arg1))
1833         return NULL;
1834     retval = fl_isqueued(arg1);
1835 
1836     return PyInt_FromLong(retval);
1837 }
1838 
1839 static PyObject *
forms_qtest(PyObject * self,PyObject * args)1840 forms_qtest(PyObject *self, PyObject *args)
1841 {
1842     long retval;
1843     retval = fl_qtest();
1844     return PyInt_FromLong(retval);
1845 }
1846 
1847 
1848 static PyObject *
forms_qread(PyObject * self,PyObject * args)1849 forms_qread(PyObject *self, PyObject *args)
1850 {
1851     int dev;
1852     short val;
1853     Py_BEGIN_ALLOW_THREADS
1854     dev = fl_qread(&val);
1855     Py_END_ALLOW_THREADS
1856     return Py_BuildValue("(ih)", dev, val);
1857 }
1858 
1859 static PyObject *
forms_qreset(PyObject * self)1860 forms_qreset(PyObject *self)
1861 {
1862     fl_qreset();
1863     Py_INCREF(Py_None);
1864     return Py_None;
1865 }
1866 
1867 static PyObject *
forms_qenter(PyObject * self,PyObject * args)1868 forms_qenter(PyObject *self, PyObject *args)
1869 {
1870     short arg1, arg2;
1871     if (!PyArg_Parse(args, "(hh)", &arg1, &arg2))
1872         return NULL;
1873     fl_qenter(arg1, arg2);
1874     Py_INCREF(Py_None);
1875     return Py_None;
1876 }
1877 
1878 static PyObject *
forms_color(PyObject * self,PyObject * args)1879 forms_color(PyObject *self, PyObject *args)
1880 {
1881     int arg;
1882 
1883     if (!PyArg_Parse(args, "i", &arg)) return NULL;
1884 
1885     fl_color((short) arg);
1886 
1887     Py_INCREF(Py_None);
1888     return Py_None;
1889 }
1890 
1891 static PyObject *
forms_mapcolor(PyObject * self,PyObject * args)1892 forms_mapcolor(PyObject *self, PyObject *args)
1893 {
1894     int arg0, arg1, arg2, arg3;
1895 
1896     if (!PyArg_Parse(args, "(iiii)", &arg0, &arg1, &arg2, &arg3))
1897         return NULL;
1898 
1899     fl_mapcolor(arg0, (short) arg1, (short) arg2, (short) arg3);
1900 
1901     Py_INCREF(Py_None);
1902     return Py_None;
1903 }
1904 
1905 static PyObject *
forms_getmcolor(PyObject * self,PyObject * args)1906 forms_getmcolor(PyObject *self, PyObject *args)
1907 {
1908     int arg;
1909     short r, g, b;
1910 
1911     if (!PyArg_Parse(args, "i", &arg)) return NULL;
1912 
1913     fl_getmcolor(arg, &r, &g, &b);
1914 
1915     return Py_BuildValue("(hhh)", r, g, b);
1916 }
1917 
1918 static PyObject *
forms_get_mouse(PyObject * self)1919 forms_get_mouse(PyObject *self)
1920 {
1921     float x, y;
1922 
1923     fl_get_mouse(&x, &y);
1924 
1925     return Py_BuildValue("(ff)", x, y);
1926 }
1927 
1928 static PyObject *
forms_tie(PyObject * self,PyObject * args)1929 forms_tie(PyObject *self, PyObject *args)
1930 {
1931     short arg1, arg2, arg3;
1932     if (!PyArg_Parse(args, "(hhh)", &arg1, &arg2, &arg3))
1933         return NULL;
1934     fl_tie(arg1, arg2, arg3);
1935     Py_INCREF(Py_None);
1936     return Py_None;
1937 }
1938 
1939 static PyObject *
forms_show_message(PyObject * f,PyObject * args)1940 forms_show_message(PyObject *f, PyObject *args)
1941 {
1942     char *a, *b, *c;
1943 
1944     if (!PyArg_Parse(args, "(sss)", &a, &b, &c)) return NULL;
1945 
1946     Py_BEGIN_ALLOW_THREADS
1947     fl_show_message(a, b, c);
1948     Py_END_ALLOW_THREADS
1949 
1950     Py_INCREF(Py_None);
1951     return Py_None;
1952 }
1953 
1954 static PyObject *
forms_show_choice(PyObject * f,PyObject * args)1955 forms_show_choice(PyObject *f, PyObject *args)
1956 {
1957     char *m1, *m2, *m3, *b1, *b2, *b3;
1958     int nb;
1959     char *format;
1960     long rv;
1961 
1962     if (args == NULL || !PyTuple_Check(args)) {
1963         PyErr_BadArgument();
1964         return NULL;
1965     }
1966     nb = PyTuple_Size(args) - 3;
1967     if (nb <= 0) {
1968         PyErr_SetString(PyExc_TypeError,
1969                         "need at least one button label");
1970         return NULL;
1971     }
1972     if (PyInt_Check(PyTuple_GetItem(args, 3))) {
1973         PyErr_SetString(PyExc_TypeError,
1974                    "'number-of-buttons' argument not needed");
1975         return NULL;
1976     }
1977     switch (nb) {
1978     case 1: format = "(ssss)"; break;
1979     case 2: format = "(sssss)"; break;
1980     case 3: format = "(ssssss)"; break;
1981     default:
1982         PyErr_SetString(PyExc_TypeError, "too many button labels");
1983         return NULL;
1984     }
1985 
1986     if (!PyArg_Parse(args, format, &m1, &m2, &m3, &b1, &b2, &b3))
1987         return NULL;
1988 
1989     Py_BEGIN_ALLOW_THREADS
1990     rv = fl_show_choice(m1, m2, m3, nb, b1, b2, b3);
1991     Py_END_ALLOW_THREADS
1992     return PyInt_FromLong(rv);
1993 }
1994 
1995 static PyObject *
forms_show_question(PyObject * f,PyObject * args)1996 forms_show_question(PyObject *f, PyObject *args)
1997 {
1998     int ret;
1999     char *a, *b, *c;
2000 
2001     if (!PyArg_Parse(args, "(sss)", &a, &b, &c)) return NULL;
2002 
2003     Py_BEGIN_ALLOW_THREADS
2004     ret = fl_show_question(a, b, c);
2005     Py_END_ALLOW_THREADS
2006 
2007     return PyInt_FromLong((long) ret);
2008 }
2009 
2010 static PyObject *
forms_show_input(PyObject * f,PyObject * args)2011 forms_show_input(PyObject *f, PyObject *args)
2012 {
2013     char *str;
2014     char *a, *b;
2015 
2016     if (!PyArg_Parse(args, "(ss)", &a, &b)) return NULL;
2017 
2018     Py_BEGIN_ALLOW_THREADS
2019     str = fl_show_input(a, b);
2020     Py_END_ALLOW_THREADS
2021 
2022     if (str == NULL) {
2023         Py_INCREF(Py_None);
2024         return Py_None;
2025     }
2026     return PyString_FromString(str);
2027 }
2028 
2029 static PyObject *
forms_file_selector(PyObject * f,PyObject * args)2030 forms_file_selector(PyObject *f, PyObject *args)
2031 {
2032     char *str;
2033     char *a, *b, *c, *d;
2034 
2035     if (!PyArg_Parse(args, "(ssss)", &a, &b, &c, &d)) return NULL;
2036 
2037     Py_BEGIN_ALLOW_THREADS
2038     str = fl_show_file_selector(a, b, c, d);
2039     Py_END_ALLOW_THREADS
2040 
2041     if (str == NULL) {
2042         Py_INCREF(Py_None);
2043         return Py_None;
2044     }
2045     return PyString_FromString(str);
2046 }
2047 
2048 
2049 static PyObject *
forms_file_selector_func(PyObject * args,char * (* func)(void))2050 forms_file_selector_func(PyObject *args, char *(*func)(void))
2051 {
2052     char *str;
2053 
2054     str = (*func) ();
2055 
2056     if (str == NULL) {
2057         Py_INCREF(Py_None);
2058         return Py_None;
2059     }
2060     return PyString_FromString(str);
2061 }
2062 
2063 static PyObject *
forms_get_directory(PyObject * f,PyObject * args)2064 forms_get_directory(PyObject *f, PyObject *args)
2065 {
2066     return forms_file_selector_func(args, fl_get_directory);
2067 }
2068 
2069 static PyObject *
forms_get_pattern(PyObject * f,PyObject * args)2070 forms_get_pattern(PyObject *f, PyObject *args)
2071 {
2072     return forms_file_selector_func(args, fl_get_pattern);
2073 }
2074 
2075 static PyObject *
forms_get_filename(PyObject * f,PyObject * args)2076 forms_get_filename(PyObject *f, PyObject *args)
2077 {
2078     return forms_file_selector_func(args, fl_get_filename);
2079 }
2080 
2081 static PyMethodDef forms_methods[] = {
2082 /* adm */
2083     {"make_form",               forms_make_form, METH_OLDARGS},
2084     {"activate_all_forms",      forms_activate_all_forms, METH_OLDARGS},
2085     {"deactivate_all_forms",forms_deactivate_all_forms, METH_OLDARGS},
2086 /* gl support wrappers */
2087     {"qdevice",                 forms_qdevice, METH_OLDARGS},
2088     {"unqdevice",               forms_unqdevice, METH_OLDARGS},
2089     {"isqueued",                forms_isqueued, METH_OLDARGS},
2090     {"qtest",                   forms_qtest, METH_OLDARGS},
2091     {"qread",                   forms_qread, METH_OLDARGS},
2092 /*      {"blkqread",            forms_blkqread, METH_OLDARGS}, */
2093     {"qreset",                  forms_qreset, METH_NOARGS},
2094     {"qenter",                  forms_qenter, METH_OLDARGS},
2095     {"get_mouse",               forms_get_mouse, METH_NOARGS},
2096     {"tie",                     forms_tie, METH_OLDARGS},
2097 /*      {"new_events",          forms_new_events, METH_OLDARGS}, */
2098     {"color",                   forms_color, METH_OLDARGS},
2099     {"mapcolor",                forms_mapcolor, METH_OLDARGS},
2100     {"getmcolor",               forms_getmcolor, METH_OLDARGS},
2101 /* interaction */
2102     {"do_forms",                forms_do_forms, METH_NOARGS},
2103     {"do_only_forms",           forms_do_only_forms, METH_NOARGS},
2104     {"check_forms",             forms_check_forms, METH_NOARGS},
2105     {"check_only_forms",        forms_check_only_forms, METH_NOARGS},
2106     {"set_event_call_back",     forms_set_event_call_back, METH_OLDARGS},
2107 /* goodies */
2108     {"show_message",            forms_show_message, METH_OLDARGS},
2109     {"show_question",           forms_show_question, METH_OLDARGS},
2110     {"show_choice",             forms_show_choice, METH_OLDARGS},
2111     {"show_input",              forms_show_input, METH_OLDARGS},
2112     {"show_file_selector",      forms_file_selector, METH_OLDARGS},
2113     {"file_selector",           forms_file_selector, METH_OLDARGS}, /* BW compat */
2114     {"get_directory",           forms_get_directory, METH_OLDARGS},
2115     {"get_pattern",             forms_get_pattern, METH_OLDARGS},
2116     {"get_filename",            forms_get_filename, METH_OLDARGS},
2117     {"set_graphics_mode",       forms_set_graphics_mode, METH_OLDARGS},
2118     {"get_rgbmode",             forms_get_rgbmode, METH_OLDARGS},
2119     {"show_errors",             forms_show_errors, METH_OLDARGS},
2120     {"set_font_name",           forms_set_font_name, METH_OLDARGS},
2121     {NULL,                      NULL}           /* sentinel */
2122 };
2123 
2124 PyMODINIT_FUNC
initfl(void)2125 initfl(void)
2126 {
2127     if (PyErr_WarnPy3k("the fl module has been removed in "
2128                        "Python 3.0", 2) < 0)
2129         return;
2130 
2131     Py_InitModule("fl", forms_methods);
2132     if (m == NULL)
2133         return;
2134     foreground();
2135     fl_init();
2136 }
2137 
2138 
2139 
2140