blob: 1b27b71a77c08206d9f4ff95286983b9814e9afb [file] [log] [blame]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001/* Stdwin module */
2
3/* Stdwin itself is a module, not a separate object type.
4 Object types defined here:
5 wp: a window
6 dp: a drawing structure (only one can exist at a time)
7 mp: a menu
8 tp: a textedit block
9*/
10
11/* Rules for translating C stdwin function calls into Python stwin:
12 - All names drop their initial letter 'w'
13 - Functions with a window as first parameter are methods of window objects
14 - There is no equivalent for wclose(); just delete the window object
15 (all references to it!) (XXX maybe this is a bad idea)
16 - w.begindrawing() returns a drawing object
17 - There is no equivalent for wenddrawing(win); just delete the drawing
18 object (all references to it!) (XXX maybe this is a bad idea)
19 - Functions that may only be used inside wbegindrawing / wendddrawing
20 are methods of the drawing object; this includes the text measurement
21 functions (which however have doubles as module functions).
22 - Methods of the drawing object drop an initial 'draw' from their name
23 if they have it, e.g., wdrawline() --> d.line()
24 - The obvious type conversions: int --> intobject; string --> stringobject
25 - A text parameter followed by a length parameter is only a text (string)
26 parameter in Python
27 - A point or other pair of horizontal and vertical coordinates is always
28 a pair of integers in Python
29 - Two points forming a rectangle or endpoints of a line segment are a
30 pair of points in Python
31 - The arguments to d.elarc() are three points.
32 - The functions wgetclip() and wsetclip() are translated into
33 stdwin.getcutbuffer() and stdwin.setcutbuffer(); 'clip' is really
34 a bad word for what these functions do (clipping has a different
35 meaning in the drawing world), while cutbuffer is standard X jargon.
Guido van Rossum01769f01990-10-30 13:39:00 +000036 XXX This must change again in the light of changes to stdwin!
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000037 - For textedit, similar rules hold, but they are less strict.
38 XXX more?
39*/
40
Guido van Rossum3f5da241990-12-20 15:06:42 +000041#include "allobjects.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000042
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000043#include "modsupport.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000044
Guido van Rossum3f5da241990-12-20 15:06:42 +000045#include "stdwin.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000046
47/* Window and menu object types declared here because of forward references */
48
49typedef struct {
50 OB_HEAD
51 object *w_title;
52 WINDOW *w_win;
53 object *w_attr; /* Attributes dictionary */
54} windowobject;
55
56extern typeobject Windowtype; /* Really static, forward */
57
58#define is_windowobject(wp) ((wp)->ob_type == &Windowtype)
59
60typedef struct {
61 OB_HEAD
62 MENU *m_menu;
63 int m_id;
64 object *m_attr; /* Attributes dictionary */
65} menuobject;
66
67extern typeobject Menutype; /* Really static, forward */
68
69#define is_menuobject(mp) ((mp)->ob_type == &Menutype)
70
71
72/* Strongly stdwin-specific argument handlers */
73
74static int
75getmousedetail(v, ep)
76 object *v;
77 EVENT *ep;
78{
79 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 4)
80 return err_badarg();
81 return getintintarg(gettupleitem(v, 0),
82 &ep->u.where.h, &ep->u.where.v) &&
83 getintarg(gettupleitem(v, 1), &ep->u.where.clicks) &&
84 getintarg(gettupleitem(v, 2), &ep->u.where.button) &&
85 getintarg(gettupleitem(v, 3), &ep->u.where.mask);
86}
87
88static int
89getmenudetail(v, ep)
90 object *v;
91 EVENT *ep;
92{
93 object *mp;
94 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2)
95 return err_badarg();
96 mp = gettupleitem(v, 0);
97 if (mp == NULL || !is_menuobject(mp))
98 return err_badarg();
99 ep->u.m.id = ((menuobject *)mp) -> m_id;
100 return getintarg(gettupleitem(v, 1), &ep->u.m.item);
101}
102
103static int
104geteventarg(v, ep)
105 object *v;
106 EVENT *ep;
107{
108 object *wp, *detail;
109 int a[4];
110 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 3)
111 return err_badarg();
112 if (!getintarg(gettupleitem(v, 0), &ep->type))
113 return 0;
114 wp = gettupleitem(v, 1);
115 if (wp == None)
116 ep->window = NULL;
117 else if (wp == NULL || !is_windowobject(wp))
118 return err_badarg();
119 else
120 ep->window = ((windowobject *)wp) -> w_win;
121 detail = gettupleitem(v, 2);
122 switch (ep->type) {
123 case WE_CHAR:
124 if (!is_stringobject(detail) || getstringsize(detail) != 1)
125 return err_badarg();
126 ep->u.character = getstringvalue(detail)[0];
127 return 1;
128 case WE_COMMAND:
129 return getintarg(detail, &ep->u.command);
130 case WE_DRAW:
131 if (!getrectarg(detail, a))
132 return 0;
133 ep->u.area.left = a[0];
134 ep->u.area.top = a[1];
135 ep->u.area.right = a[2];
136 ep->u.area.bottom = a[3];
137 return 1;
138 case WE_MOUSE_DOWN:
139 case WE_MOUSE_UP:
140 case WE_MOUSE_MOVE:
141 return getmousedetail(detail, ep);
142 case WE_MENU:
143 return getmenudetail(detail, ep);
144 default:
145 return 1;
146 }
147}
148
149
150/* Return construction tools */
151
152static object *
153makepoint(a, b)
154 int a, b;
155{
156 object *v;
157 object *w;
158 if ((v = newtupleobject(2)) == NULL)
159 return NULL;
160 if ((w = newintobject((long)a)) == NULL ||
161 settupleitem(v, 0, w) != 0 ||
162 (w = newintobject((long)b)) == NULL ||
163 settupleitem(v, 1, w) != 0) {
164 DECREF(v);
165 return NULL;
166 }
167 return v;
168}
169
170static object *
171makerect(a, b, c, d)
172 int a, b, c, d;
173{
174 object *v;
175 object *w;
176 if ((v = newtupleobject(2)) == NULL)
177 return NULL;
178 if ((w = makepoint(a, b)) == NULL ||
179 settupleitem(v, 0, w) != 0 ||
180 (w = makepoint(c, d)) == NULL ||
181 settupleitem(v, 1, w) != 0) {
182 DECREF(v);
183 return NULL;
184 }
185 return v;
186}
187
188static object *
189makemouse(hor, ver, clicks, button, mask)
190 int hor, ver, clicks, button, mask;
191{
192 object *v;
193 object *w;
194 if ((v = newtupleobject(4)) == NULL)
195 return NULL;
196 if ((w = makepoint(hor, ver)) == NULL ||
197 settupleitem(v, 0, w) != 0 ||
198 (w = newintobject((long)clicks)) == NULL ||
199 settupleitem(v, 1, w) != 0 ||
200 (w = newintobject((long)button)) == NULL ||
201 settupleitem(v, 2, w) != 0 ||
202 (w = newintobject((long)mask)) == NULL ||
203 settupleitem(v, 3, w) != 0) {
204 DECREF(v);
205 return NULL;
206 }
207 return v;
208}
209
210static object *
211makemenu(mp, item)
212 object *mp;
213 int item;
214{
215 object *v;
216 object *w;
217 if ((v = newtupleobject(2)) == NULL)
218 return NULL;
219 INCREF(mp);
220 if (settupleitem(v, 0, mp) != 0 ||
221 (w = newintobject((long)item)) == NULL ||
222 settupleitem(v, 1, w) != 0) {
223 DECREF(v);
224 return NULL;
225 }
226 return v;
227}
228
229
230/* Drawing objects */
231
232typedef struct {
233 OB_HEAD
234 windowobject *d_ref;
235} drawingobject;
236
237static drawingobject *Drawing; /* Set to current drawing object, or NULL */
238
239/* Drawing methods */
240
241static void
242drawing_dealloc(dp)
243 drawingobject *dp;
244{
245 wenddrawing(dp->d_ref->w_win);
246 Drawing = NULL;
247 DECREF(dp->d_ref);
248 free((char *)dp);
249}
250
251static object *
252drawing_generic(dp, args, func)
253 drawingobject *dp;
254 object *args;
255 void (*func) FPROTO((int, int, int, int));
256{
257 int a[4];
258 if (!getrectarg(args, a))
259 return NULL;
260 (*func)(a[0], a[1], a[2], a[3]);
261 INCREF(None);
262 return None;
263}
264
265static object *
266drawing_line(dp, args)
267 drawingobject *dp;
268 object *args;
269{
270 drawing_generic(dp, args, wdrawline);
271}
272
273static object *
274drawing_xorline(dp, args)
275 drawingobject *dp;
276 object *args;
277{
278 drawing_generic(dp, args, wxorline);
279}
280
281static object *
282drawing_circle(dp, args)
283 drawingobject *dp;
284 object *args;
285{
286 int a[3];
287 if (!getpointintarg(args, a))
288 return NULL;
289 wdrawcircle(a[0], a[1], a[2]);
290 INCREF(None);
291 return None;
292}
293
294static object *
295drawing_elarc(dp, args)
296 drawingobject *dp;
297 object *args;
298{
299 int a[6];
300 if (!get3pointarg(args, a))
301 return NULL;
302 wdrawelarc(a[0], a[1], a[2], a[3], a[4], a[5]);
303 INCREF(None);
304 return None;
305}
306
307static object *
308drawing_box(dp, args)
309 drawingobject *dp;
310 object *args;
311{
312 drawing_generic(dp, args, wdrawbox);
313}
314
315static object *
316drawing_erase(dp, args)
317 drawingobject *dp;
318 object *args;
319{
320 drawing_generic(dp, args, werase);
321}
322
323static object *
324drawing_paint(dp, args)
325 drawingobject *dp;
326 object *args;
327{
328 drawing_generic(dp, args, wpaint);
329}
330
331static object *
332drawing_invert(dp, args)
333 drawingobject *dp;
334 object *args;
335{
336 drawing_generic(dp, args, winvert);
337}
338
339static object *
340drawing_cliprect(dp, args)
341 drawingobject *dp;
342 object *args;
343{
344 drawing_generic(dp, args, wcliprect);
345}
346
347static object *
348drawing_noclip(dp, args)
349 drawingobject *dp;
350 object *args;
351{
352 if (!getnoarg(args))
353 return NULL;
354 wnoclip();
355 INCREF(None);
356 return None;
357}
358
359static object *
360drawing_shade(dp, args)
361 drawingobject *dp;
362 object *args;
363{
364 int a[5];
365 if (!getrectintarg(args, a))
366 return NULL;
367 wshade(a[0], a[1], a[2], a[3], a[4]);
368 INCREF(None);
369 return None;
370}
371
372static object *
373drawing_text(dp, args)
374 drawingobject *dp;
375 object *args;
376{
377 int a[2];
378 object *s;
379 if (!getpointstrarg(args, a, &s))
380 return NULL;
381 wdrawtext(a[0], a[1], getstringvalue(s), (int)getstringsize(s));
382 INCREF(None);
383 return None;
384}
385
386/* The following four are also used as stdwin functions */
387
388static object *
389drawing_lineheight(dp, args)
390 drawingobject *dp;
391 object *args;
392{
393 if (!getnoarg(args))
394 return NULL;
395 return newintobject((long)wlineheight());
396}
397
398static object *
399drawing_baseline(dp, args)
400 drawingobject *dp;
401 object *args;
402{
403 if (!getnoarg(args))
404 return NULL;
405 return newintobject((long)wbaseline());
406}
407
408static object *
409drawing_textwidth(dp, args)
410 drawingobject *dp;
411 object *args;
412{
413 object *s;
414 if (!getstrarg(args, &s))
415 return NULL;
416 return newintobject(
417 (long)wtextwidth(getstringvalue(s), (int)getstringsize(s)));
418}
419
420static object *
421drawing_textbreak(dp, args)
422 drawingobject *dp;
423 object *args;
424{
425 object *s;
426 int a;
427 if (!getstrintarg(args, &s, &a))
428 return NULL;
429 return newintobject(
430 (long)wtextbreak(getstringvalue(s), (int)getstringsize(s), a));
431}
432
433static struct methodlist drawing_methods[] = {
434 {"box", drawing_box},
435 {"circle", drawing_circle},
436 {"cliprect", drawing_cliprect},
437 {"elarc", drawing_elarc},
438 {"erase", drawing_erase},
439 {"invert", drawing_invert},
440 {"line", drawing_line},
441 {"noclip", drawing_noclip},
442 {"paint", drawing_paint},
443 {"shade", drawing_shade},
444 {"text", drawing_text},
445 {"xorline", drawing_xorline},
446
447 /* Text measuring methods: */
448 {"baseline", drawing_baseline},
449 {"lineheight", drawing_lineheight},
450 {"textbreak", drawing_textbreak},
451 {"textwidth", drawing_textwidth},
452 {NULL, NULL} /* sentinel */
453};
454
455static object *
456drawing_getattr(wp, name)
457 drawingobject *wp;
458 char *name;
459{
460 return findmethod(drawing_methods, (object *)wp, name);
461}
462
463static typeobject Drawingtype = {
464 OB_HEAD_INIT(&Typetype)
465 0, /*ob_size*/
466 "drawing", /*tp_name*/
467 sizeof(drawingobject), /*tp_size*/
468 0, /*tp_itemsize*/
469 /* methods */
470 drawing_dealloc, /*tp_dealloc*/
471 0, /*tp_print*/
472 drawing_getattr, /*tp_getattr*/
473 0, /*tp_setattr*/
474 0, /*tp_compare*/
475 0, /*tp_repr*/
476};
477
478
479/* Text(edit) objects */
480
481typedef struct {
482 OB_HEAD
483 TEXTEDIT *t_text;
484 windowobject *t_ref;
485 object *t_attr; /* Attributes dictionary */
486} textobject;
487
488extern typeobject Texttype; /* Really static, forward */
489
490static textobject *
491newtextobject(wp, left, top, right, bottom)
492 windowobject *wp;
493 int left, top, right, bottom;
494{
495 textobject *tp;
496 tp = NEWOBJ(textobject, &Texttype);
497 if (tp == NULL)
498 return NULL;
499 tp->t_attr = NULL;
500 INCREF(wp);
501 tp->t_ref = wp;
502 tp->t_text = tecreate(wp->w_win, left, top, right, bottom);
503 if (tp->t_text == NULL) {
504 DECREF(tp);
505 return (textobject *) err_nomem();
506 }
507 return tp;
508}
509
510/* Text(edit) methods */
511
512static void
513text_dealloc(tp)
514 textobject *tp;
515{
516 if (tp->t_text != NULL)
517 tefree(tp->t_text);
518 if (tp->t_attr != NULL)
519 DECREF(tp->t_attr);
520 DECREF(tp->t_ref);
521 DEL(tp);
522}
523
524static object *
525text_arrow(self, args)
526 textobject *self;
527 object *args;
528{
529 int code;
530 if (!getintarg(args, &code))
531 return NULL;
532 tearrow(self->t_text, code);
533 INCREF(None);
534 return None;
535}
536
537static object *
538text_draw(self, args)
539 textobject *self;
540 object *args;
541{
542 register TEXTEDIT *tp = self->t_text;
543 int a[4];
544 int left, top, right, bottom;
545 if (!getrectarg(args, a))
546 return NULL;
547 if (Drawing != NULL) {
548 err_setstr(RuntimeError, "not drawing");
549 return NULL;
550 }
551 /* Clip to text area and ignore if area is empty */
552 left = tegetleft(tp);
553 top = tegettop(tp);
554 right = tegetright(tp);
555 bottom = tegetbottom(tp);
556 if (a[0] < left) a[0] = left;
557 if (a[1] < top) a[1] = top;
558 if (a[2] > right) a[2] = right;
559 if (a[3] > bottom) a[3] = bottom;
560 if (a[0] < a[2] && a[1] < a[3]) {
561 /* Hide/show focus around draw call; these are undocumented,
562 but required here to get the highlighting correct.
563 The call to werase is also required for this reason.
564 Finally, this forces us to require (above) that we are NOT
565 already drawing. */
566 tehidefocus(tp);
567 wbegindrawing(self->t_ref->w_win);
568 werase(a[0], a[1], a[2], a[3]);
569 tedrawnew(tp, a[0], a[1], a[2], a[3]);
570 wenddrawing(self->t_ref->w_win);
571 teshowfocus(tp);
572 }
573 INCREF(None);
574 return None;
575}
576
577static object *
578text_event(self, args)
579 textobject *self;
580 object *args;
581{
582 register TEXTEDIT *tp = self->t_text;
583 EVENT e;
584 if (!geteventarg(args, &e))
585 return NULL;
586 if (e.type == WE_MOUSE_DOWN) {
Guido van Rossum33f17701991-02-13 23:19:39 +0000587 /* Cheat at the margins */
588 int width, height;
589 wgetdocsize(e.window, &width, &height);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000590 if (e.u.where.h < 0 && tegetleft(tp) == 0)
591 e.u.where.h = 0;
Guido van Rossum33f17701991-02-13 23:19:39 +0000592 else if (e.u.where.h > width && tegetright(tp) == width)
593 e.u.where.h = width;
594 if (e.u.where.v < 0 && tegettop(tp) == 0)
595 e.u.where.v = 0;
596 else if (e.u.where.v > height && tegetright(tp) == height)
597 e.u.where.v = height;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000598 }
599 return newintobject((long) teevent(tp, &e));
600}
601
602static object *
603text_getfocus(self, args)
604 textobject *self;
605 object *args;
606{
607 if (!getnoarg(args))
608 return NULL;
609 return makepoint(tegetfoc1(self->t_text), tegetfoc2(self->t_text));
610}
611
612static object *
613text_getfocustext(self, args)
614 textobject *self;
615 object *args;
616{
617 int f1, f2;
618 char *text;
619 if (!getnoarg(args))
620 return NULL;
621 f1 = tegetfoc1(self->t_text);
622 f2 = tegetfoc2(self->t_text);
623 text = tegettext(self->t_text);
624 return newsizedstringobject(text + f1, f2-f1);
625}
626
627static object *
628text_getrect(self, args)
629 textobject *self;
630 object *args;
631{
632 if (!getnoarg(args))
633 return NULL;
634 return makerect(tegetleft(self->t_text),
635 tegettop(self->t_text),
636 tegetright(self->t_text),
637 tegetbottom(self->t_text));
638}
639
640static object *
641text_gettext(self, args)
642 textobject *self;
643 object *args;
644{
645 if (!getnoarg(args))
646 return NULL;
647 return newsizedstringobject(tegettext(self->t_text),
648 tegetlen(self->t_text));
649}
650
651static object *
652text_move(self, args)
653 textobject *self;
654 object *args;
655{
656 int a[4];
657 if (!getrectarg(args, a))
658 return NULL;
659 temovenew(self->t_text, a[0], a[1], a[2], a[3]);
660 INCREF(None);
661 return None;
662}
663
664static object *
665text_setfocus(self, args)
666 textobject *self;
667 object *args;
668{
669 int a[2];
670 if (!getpointarg(args, a))
671 return NULL;
672 tesetfocus(self->t_text, a[0], a[1]);
673 INCREF(None);
674 return None;
675}
676
677static object *
678text_replace(self, args)
679 textobject *self;
680 object *args;
681{
682 object *text;
683 if (!getstrarg(args, &text))
684 return NULL;
685 tereplace(self->t_text, getstringvalue(text));
686 INCREF(None);
687 return None;
688}
689
690static struct methodlist text_methods[] = {
691 "arrow", text_arrow,
692 "draw", text_draw,
693 "event", text_event,
694 "getfocus", text_getfocus,
695 "getfocustext", text_getfocustext,
696 "getrect", text_getrect,
697 "gettext", text_gettext,
698 "move", text_move,
699 "replace", text_replace,
700 "setfocus", text_setfocus,
701 {NULL, NULL} /* sentinel */
702};
703
704static object *
705text_getattr(tp, name)
706 textobject *tp;
707 char *name;
708{
709 if (tp->t_attr != NULL) {
710 object *v = dictlookup(tp->t_attr, name);
711 if (v != NULL) {
712 INCREF(v);
713 return v;
714 }
715 }
716 return findmethod(text_methods, (object *)tp, name);
717}
718
719static int
720text_setattr(tp, name, v)
721 textobject *tp;
722 char *name;
723 object *v;
724{
725 if (tp->t_attr == NULL) {
726 tp->t_attr = newdictobject();
727 if (tp->t_attr == NULL)
728 return -1;
729 }
730 if (v == NULL)
731 return dictremove(tp->t_attr, name);
732 else
733 return dictinsert(tp->t_attr, name, v);
734}
735
736static typeobject Texttype = {
737 OB_HEAD_INIT(&Typetype)
738 0, /*ob_size*/
739 "textedit", /*tp_name*/
740 sizeof(textobject), /*tp_size*/
741 0, /*tp_itemsize*/
742 /* methods */
743 text_dealloc, /*tp_dealloc*/
744 0, /*tp_print*/
745 text_getattr, /*tp_getattr*/
746 text_setattr, /*tp_setattr*/
747 0, /*tp_compare*/
748 0, /*tp_repr*/
749};
750
751
752/* Menu objects */
753
Guido van Rossum2d14e211991-02-19 12:26:49 +0000754#define IDOFFSET 10 /* Menu IDs we use start here */
755#define MAXNMENU 20 /* Max #menus we allow */
756static menuobject *menulist[MAXNMENU];
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000757
758static menuobject *
759newmenuobject(title)
760 object *title;
761{
762 int id;
763 MENU *menu;
764 menuobject *mp;
Guido van Rossum2d14e211991-02-19 12:26:49 +0000765 for (id = 0; id < MAXNMENU; id++) {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000766 if (menulist[id] == NULL)
767 break;
768 }
769 if (id >= MAXNMENU)
770 return (menuobject *) err_nomem();
Guido van Rossum2d14e211991-02-19 12:26:49 +0000771 menu = wmenucreate(id + IDOFFSET, getstringvalue(title));
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000772 if (menu == NULL)
773 return (menuobject *) err_nomem();
774 mp = NEWOBJ(menuobject, &Menutype);
775 if (mp != NULL) {
776 mp->m_menu = menu;
Guido van Rossum2d14e211991-02-19 12:26:49 +0000777 mp->m_id = id + IDOFFSET;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000778 mp->m_attr = NULL;
779 menulist[id] = mp;
780 }
781 else
782 wmenudelete(menu);
783 return mp;
784}
785
786/* Menu methods */
787
788static void
789menu_dealloc(mp)
790 menuobject *mp;
791{
792
Guido van Rossum2d14e211991-02-19 12:26:49 +0000793 int id = mp->m_id - IDOFFSET;
794 if (id >= 0 && id < MAXNMENU && menulist[id] == mp) {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000795 menulist[id] = NULL;
796 }
797 wmenudelete(mp->m_menu);
798 if (mp->m_attr != NULL)
799 DECREF(mp->m_attr);
800 DEL(mp);
801}
802
803static object *
804menu_additem(self, args)
805 menuobject *self;
806 object *args;
807{
808 object *text;
809 int shortcut;
810 if (is_tupleobject(args)) {
811 object *v;
812 if (!getstrstrarg(args, &text, &v))
813 return NULL;
814 if (getstringsize(v) != 1) {
815 err_badarg();
816 return NULL;
817 }
818 shortcut = *getstringvalue(v) & 0xff;
819 }
820 else {
821 if (!getstrarg(args, &text))
822 return NULL;
823 shortcut = -1;
824 }
825 wmenuadditem(self->m_menu, getstringvalue(text), shortcut);
826 INCREF(None);
827 return None;
828}
829
830static object *
831menu_setitem(self, args)
832 menuobject *self;
833 object *args;
834{
835 int index;
836 object *text;
837 if (!getintstrarg(args, &index, &text))
838 return NULL;
839 wmenusetitem(self->m_menu, index, getstringvalue(text));
840 INCREF(None);
841 return None;
842}
843
844static object *
845menu_enable(self, args)
846 menuobject *self;
847 object *args;
848{
849 int index;
850 int flag;
851 if (!getintintarg(args, &index, &flag))
852 return NULL;
853 wmenuenable(self->m_menu, index, flag);
854 INCREF(None);
855 return None;
856}
857
858static object *
859menu_check(self, args)
860 menuobject *self;
861 object *args;
862{
863 int index;
864 int flag;
865 if (!getintintarg(args, &index, &flag))
866 return NULL;
867 wmenucheck(self->m_menu, index, flag);
868 INCREF(None);
869 return None;
870}
871
872static struct methodlist menu_methods[] = {
873 "additem", menu_additem,
874 "setitem", menu_setitem,
875 "enable", menu_enable,
876 "check", menu_check,
877 {NULL, NULL} /* sentinel */
878};
879
880static object *
881menu_getattr(mp, name)
882 menuobject *mp;
883 char *name;
884{
885 if (mp->m_attr != NULL) {
886 object *v = dictlookup(mp->m_attr, name);
887 if (v != NULL) {
888 INCREF(v);
889 return v;
890 }
891 }
892 return findmethod(menu_methods, (object *)mp, name);
893}
894
895static int
896menu_setattr(mp, name, v)
897 menuobject *mp;
898 char *name;
899 object *v;
900{
901 if (mp->m_attr == NULL) {
902 mp->m_attr = newdictobject();
903 if (mp->m_attr == NULL)
904 return -1;
905 }
906 if (v == NULL)
907 return dictremove(mp->m_attr, name);
908 else
909 return dictinsert(mp->m_attr, name, v);
910}
911
912static typeobject Menutype = {
913 OB_HEAD_INIT(&Typetype)
914 0, /*ob_size*/
915 "menu", /*tp_name*/
916 sizeof(menuobject), /*tp_size*/
917 0, /*tp_itemsize*/
918 /* methods */
919 menu_dealloc, /*tp_dealloc*/
920 0, /*tp_print*/
921 menu_getattr, /*tp_getattr*/
922 menu_setattr, /*tp_setattr*/
923 0, /*tp_compare*/
924 0, /*tp_repr*/
925};
926
927
928/* Windows */
929
930#define MAXNWIN 50
931static windowobject *windowlist[MAXNWIN];
932
933/* Window methods */
934
935static void
936window_dealloc(wp)
937 windowobject *wp;
938{
939 if (wp->w_win != NULL) {
940 int tag = wgettag(wp->w_win);
941 if (tag >= 0 && tag < MAXNWIN)
942 windowlist[tag] = NULL;
943 else
944 fprintf(stderr, "XXX help! tag %d in window_dealloc\n",
945 tag);
946 wclose(wp->w_win);
947 }
948 DECREF(wp->w_title);
949 if (wp->w_attr != NULL)
950 DECREF(wp->w_attr);
951 free((char *)wp);
952}
953
954static void
955window_print(wp, fp, flags)
956 windowobject *wp;
957 FILE *fp;
958 int flags;
959{
960 fprintf(fp, "<window titled '%s'>", getstringvalue(wp->w_title));
961}
962
963static object *
964window_begindrawing(wp, args)
965 windowobject *wp;
966 object *args;
967{
968 drawingobject *dp;
969 if (!getnoarg(args))
970 return NULL;
971 if (Drawing != NULL) {
972 err_setstr(RuntimeError, "already drawing");
973 return NULL;
974 }
975 dp = NEWOBJ(drawingobject, &Drawingtype);
976 if (dp == NULL)
977 return NULL;
978 Drawing = dp;
979 INCREF(wp);
980 dp->d_ref = wp;
981 wbegindrawing(wp->w_win);
982 return (object *)dp;
983}
984
985static object *
986window_change(wp, args)
987 windowobject *wp;
988 object *args;
989{
990 int a[4];
991 if (!getrectarg(args, a))
992 return NULL;
993 wchange(wp->w_win, a[0], a[1], a[2], a[3]);
994 INCREF(None);
995 return None;
996}
997
998static object *
999window_gettitle(wp, args)
1000 windowobject *wp;
1001 object *args;
1002{
1003 if (!getnoarg(args))
1004 return NULL;
1005 INCREF(wp->w_title);
1006 return wp->w_title;
1007}
1008
1009static object *
1010window_getwinsize(wp, args)
1011 windowobject *wp;
1012 object *args;
1013{
1014 int width, height;
1015 if (!getnoarg(args))
1016 return NULL;
1017 wgetwinsize(wp->w_win, &width, &height);
1018 return makepoint(width, height);
1019}
1020
1021static object *
1022window_getdocsize(wp, args)
1023 windowobject *wp;
1024 object *args;
1025{
1026 int width, height;
1027 if (!getnoarg(args))
1028 return NULL;
1029 wgetdocsize(wp->w_win, &width, &height);
1030 return makepoint(width, height);
1031}
1032
1033static object *
1034window_getorigin(wp, args)
1035 windowobject *wp;
1036 object *args;
1037{
1038 int width, height;
1039 if (!getnoarg(args))
1040 return NULL;
1041 wgetorigin(wp->w_win, &width, &height);
1042 return makepoint(width, height);
1043}
1044
1045static object *
1046window_scroll(wp, args)
1047 windowobject *wp;
1048 object *args;
1049{
1050 int a[6];
1051 if (!getrectpointarg(args, a))
1052 return NULL;
1053 wscroll(wp->w_win, a[0], a[1], a[2], a[3], a[4], a[5]);
1054 INCREF(None);
1055 return None;
1056}
1057
1058static object *
1059window_setdocsize(wp, args)
1060 windowobject *wp;
1061 object *args;
1062{
1063 int a[2];
1064 if (!getpointarg(args, a))
1065 return NULL;
1066 wsetdocsize(wp->w_win, a[0], a[1]);
1067 INCREF(None);
1068 return None;
1069}
1070
1071static object *
1072window_setorigin(wp, args)
1073 windowobject *wp;
1074 object *args;
1075{
1076 int a[2];
1077 if (!getpointarg(args, a))
1078 return NULL;
1079 wsetorigin(wp->w_win, a[0], a[1]);
1080 INCREF(None);
1081 return None;
1082}
1083
1084static object *
1085window_settitle(wp, args)
1086 windowobject *wp;
1087 object *args;
1088{
1089 object *title;
1090 if (!getstrarg(args, &title))
1091 return NULL;
1092 DECREF(wp->w_title);
1093 INCREF(title);
1094 wp->w_title = title;
1095 wsettitle(wp->w_win, getstringvalue(title));
1096 INCREF(None);
1097 return None;
1098}
1099
1100static object *
1101window_show(wp, args)
1102 windowobject *wp;
1103 object *args;
1104{
1105 int a[4];
1106 if (!getrectarg(args, a))
1107 return NULL;
1108 wshow(wp->w_win, a[0], a[1], a[2], a[3]);
1109 INCREF(None);
1110 return None;
1111}
1112
1113static object *
1114window_settimer(wp, args)
1115 windowobject *wp;
1116 object *args;
1117{
1118 int a;
1119 if (!getintarg(args, &a))
1120 return NULL;
1121 wsettimer(wp->w_win, a);
1122 INCREF(None);
1123 return None;
1124}
1125
1126static object *
1127window_menucreate(self, args)
1128 windowobject *self;
1129 object *args;
1130{
1131 menuobject *mp;
1132 object *title;
1133 if (!getstrarg(args, &title))
1134 return NULL;
1135 wmenusetdeflocal(1);
1136 mp = newmenuobject(title);
1137 if (mp == NULL)
1138 return NULL;
1139 wmenuattach(self->w_win, mp->m_menu);
1140 return (object *)mp;
1141}
1142
1143static object *
1144window_textcreate(self, args)
1145 windowobject *self;
1146 object *args;
1147{
1148 textobject *tp;
1149 int a[4];
1150 if (!getrectarg(args, a))
1151 return NULL;
1152 return (object *)
1153 newtextobject(self, a[0], a[1], a[2], a[3]);
1154}
1155
Guido van Rossum5b10f451990-10-30 16:01:48 +00001156static object *
1157window_setselection(self, args)
1158 windowobject *self;
1159 object *args;
1160{
1161 int sel;
1162 object *str;
1163 int ok;
1164 if (!getintstrarg(args, &sel, &str))
1165 return NULL;
1166 ok = wsetselection(self->w_win, sel,
1167 getstringvalue(str), (int)getstringsize(str));
1168 return newintobject(ok);
1169}
1170
1171static object *
1172window_setwincursor(self, args)
1173 windowobject *self;
1174 object *args;
1175{
1176 object *str;
1177 CURSOR *c;
1178 if (!getstrarg(args, &str))
1179 return NULL;
1180 c = wfetchcursor(getstringvalue(str));
1181 if (c == NULL) {
1182 err_setstr(RuntimeError, "no such cursor");
1183 return NULL;
1184 }
1185 wsetwincursor(self->w_win, c);
1186 INCREF(None);
1187 return None;
1188}
1189
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001190static struct methodlist window_methods[] = {
1191 {"begindrawing",window_begindrawing},
1192 {"change", window_change},
1193 {"getdocsize", window_getdocsize},
1194 {"getorigin", window_getorigin},
1195 {"gettitle", window_gettitle},
1196 {"getwinsize", window_getwinsize},
1197 {"menucreate", window_menucreate},
1198 {"scroll", window_scroll},
Guido van Rossum5b10f451990-10-30 16:01:48 +00001199 {"setwincursor",window_setwincursor},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001200 {"setdocsize", window_setdocsize},
1201 {"setorigin", window_setorigin},
Guido van Rossum5b10f451990-10-30 16:01:48 +00001202 {"setselection",window_setselection},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001203 {"settimer", window_settimer},
1204 {"settitle", window_settitle},
1205 {"show", window_show},
1206 {"textcreate", window_textcreate},
1207 {NULL, NULL} /* sentinel */
1208};
1209
1210static object *
1211window_getattr(wp, name)
1212 windowobject *wp;
1213 char *name;
1214{
1215 if (wp->w_attr != NULL) {
1216 object *v = dictlookup(wp->w_attr, name);
1217 if (v != NULL) {
1218 INCREF(v);
1219 return v;
1220 }
1221 }
1222 return findmethod(window_methods, (object *)wp, name);
1223}
1224
1225static int
1226window_setattr(wp, name, v)
1227 windowobject *wp;
1228 char *name;
1229 object *v;
1230{
1231 if (wp->w_attr == NULL) {
1232 wp->w_attr = newdictobject();
1233 if (wp->w_attr == NULL)
1234 return -1;
1235 }
1236 if (v == NULL)
1237 return dictremove(wp->w_attr, name);
1238 else
1239 return dictinsert(wp->w_attr, name, v);
1240}
1241
1242static typeobject Windowtype = {
1243 OB_HEAD_INIT(&Typetype)
1244 0, /*ob_size*/
1245 "window", /*tp_name*/
1246 sizeof(windowobject), /*tp_size*/
1247 0, /*tp_itemsize*/
1248 /* methods */
1249 window_dealloc, /*tp_dealloc*/
1250 window_print, /*tp_print*/
1251 window_getattr, /*tp_getattr*/
1252 window_setattr, /*tp_setattr*/
1253 0, /*tp_compare*/
1254 0, /*tp_repr*/
1255};
1256
1257/* Stdwin methods */
1258
1259static object *
1260stdwin_open(sw, args)
1261 object *sw;
1262 object *args;
1263{
1264 int tag;
1265 object *title;
1266 windowobject *wp;
1267 if (!getstrarg(args, &title))
1268 return NULL;
1269 for (tag = 0; tag < MAXNWIN; tag++) {
1270 if (windowlist[tag] == NULL)
1271 break;
1272 }
1273 if (tag >= MAXNWIN)
1274 return err_nomem();
1275 wp = NEWOBJ(windowobject, &Windowtype);
1276 if (wp == NULL)
1277 return NULL;
1278 INCREF(title);
1279 wp->w_title = title;
1280 wp->w_win = wopen(getstringvalue(title), (void (*)()) NULL);
1281 wp->w_attr = NULL;
1282 if (wp->w_win == NULL) {
1283 DECREF(wp);
1284 return NULL;
1285 }
1286 windowlist[tag] = wp;
1287 wsettag(wp->w_win, tag);
1288 return (object *)wp;
1289}
1290
1291static object *
Guido van Rossume8e7cf41991-01-16 14:06:18 +00001292stdwin_get_poll_event(poll, args)
1293 int poll;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001294 object *args;
1295{
1296 EVENT e;
1297 object *v, *w;
1298 if (!getnoarg(args))
1299 return NULL;
1300 if (Drawing != NULL) {
1301 err_setstr(RuntimeError, "cannot getevent() while drawing");
1302 return NULL;
1303 }
Guido van Rossume8e7cf41991-01-16 14:06:18 +00001304/* again: */
1305 if (poll) {
1306 if (!wpollevent(&e)) {
1307 INCREF(None);
1308 return None;
1309 }
1310 }
1311 else
1312 wgetevent(&e);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001313 if (e.type == WE_COMMAND && e.u.command == WC_CANCEL) {
1314 /* Turn keyboard interrupts into exceptions */
1315 err_set(KeyboardInterrupt);
1316 return NULL;
1317 }
Guido van Rossume8e7cf41991-01-16 14:06:18 +00001318/*
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001319 if (e.window == NULL && (e.type == WE_COMMAND || e.type == WE_CHAR))
1320 goto again;
Guido van Rossume8e7cf41991-01-16 14:06:18 +00001321*/
Guido van Rossum124967c1990-11-06 15:17:35 +00001322 if (e.type == WE_COMMAND && e.u.command == WC_CLOSE) {
1323 /* Turn WC_CLOSE commands into WE_CLOSE events */
1324 e.type = WE_CLOSE;
1325 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001326 v = newtupleobject(3);
1327 if (v == NULL)
1328 return NULL;
1329 if ((w = newintobject((long)e.type)) == NULL) {
1330 DECREF(v);
1331 return NULL;
1332 }
1333 settupleitem(v, 0, w);
1334 if (e.window == NULL)
1335 w = None;
1336 else {
1337 int tag = wgettag(e.window);
1338 if (tag < 0 || tag >= MAXNWIN || windowlist[tag] == NULL)
1339 w = None;
1340 else
1341 w = (object *)windowlist[tag];
Guido van Rossume8e7cf41991-01-16 14:06:18 +00001342#ifdef sgi
1343 /* XXX Trap for unexplained weird bug */
1344 if ((long)w == (long)0x80000001) {
1345 err_setstr(SystemError,
1346 "bad pointer in stdwin.getevent()");
1347 return NULL;
1348 }
1349#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001350 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001351 INCREF(w);
1352 settupleitem(v, 1, w);
1353 switch (e.type) {
1354 case WE_CHAR:
1355 {
1356 char c[1];
1357 c[0] = e.u.character;
1358 w = newsizedstringobject(c, 1);
1359 }
1360 break;
1361 case WE_COMMAND:
1362 w = newintobject((long)e.u.command);
1363 break;
1364 case WE_DRAW:
1365 w = makerect(e.u.area.left, e.u.area.top,
1366 e.u.area.right, e.u.area.bottom);
1367 break;
1368 case WE_MOUSE_DOWN:
1369 case WE_MOUSE_MOVE:
1370 case WE_MOUSE_UP:
1371 w = makemouse(e.u.where.h, e.u.where.v,
1372 e.u.where.clicks,
1373 e.u.where.button,
1374 e.u.where.mask);
1375 break;
1376 case WE_MENU:
Guido van Rossum2d14e211991-02-19 12:26:49 +00001377 if (e.u.m.id >= IDOFFSET && e.u.m.id < IDOFFSET+MAXNMENU &&
1378 menulist[e.u.m.id - IDOFFSET] != NULL)
1379 w = (object *)menulist[e.u.m.id - IDOFFSET];
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001380 else
1381 w = None;
1382 w = makemenu(w, e.u.m.item);
1383 break;
Guido van Rossum5b10f451990-10-30 16:01:48 +00001384 case WE_LOST_SEL:
1385 w = newintobject((long)e.u.sel);
1386 break;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001387 default:
1388 w = None;
1389 INCREF(w);
1390 break;
1391 }
1392 if (w == NULL) {
1393 DECREF(v);
1394 return NULL;
1395 }
1396 settupleitem(v, 2, w);
1397 return v;
1398}
1399
1400static object *
Guido van Rossume8e7cf41991-01-16 14:06:18 +00001401stdwin_getevent(sw, args)
1402 object *sw;
1403 object *args;
1404{
1405 return stdwin_get_poll_event(0, args);
1406}
1407
1408static object *
1409stdwin_pollevent(sw, args)
1410 object *sw;
1411 object *args;
1412{
1413 return stdwin_get_poll_event(1, args);
1414}
1415
1416static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001417stdwin_setdefwinpos(sw, args)
1418 object *sw;
1419 object *args;
1420{
1421 int a[2];
1422 if (!getpointarg(args, a))
1423 return NULL;
1424 wsetdefwinpos(a[0], a[1]);
1425 INCREF(None);
1426 return None;
1427}
1428
1429static object *
1430stdwin_setdefwinsize(sw, args)
1431 object *sw;
1432 object *args;
1433{
1434 int a[2];
1435 if (!getpointarg(args, a))
1436 return NULL;
1437 wsetdefwinsize(a[0], a[1]);
1438 INCREF(None);
1439 return None;
1440}
1441
1442static object *
Guido van Rossum33f17701991-02-13 23:19:39 +00001443stdwin_getdefwinpos(wp, args)
1444 windowobject *wp;
1445 object *args;
1446{
1447 int h, v;
1448 if (!getnoarg(args))
1449 return NULL;
1450 wgetdefwinpos(&h, &v);
1451 return makepoint(h, v);
1452}
1453
1454static object *
1455stdwin_getdefwinsize(wp, args)
1456 windowobject *wp;
1457 object *args;
1458{
1459 int width, height;
1460 if (!getnoarg(args))
1461 return NULL;
1462 wgetdefwinsize(&width, &height);
1463 return makepoint(width, height);
1464}
1465
1466static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001467stdwin_menucreate(self, args)
1468 object *self;
1469 object *args;
1470{
1471 object *title;
1472 if (!getstrarg(args, &title))
1473 return NULL;
1474 wmenusetdeflocal(0);
1475 return (object *)newmenuobject(title);
1476}
1477
1478static object *
1479stdwin_askfile(self, args)
1480 object *self;
1481 object *args;
1482{
1483 object *prompt, *dflt;
1484 int new, ret;
1485 char buf[256];
1486 if (!getstrstrintarg(args, &prompt, &dflt, &new))
1487 return NULL;
1488 strncpy(buf, getstringvalue(dflt), sizeof buf);
1489 buf[sizeof buf - 1] = '\0';
1490 ret = waskfile(getstringvalue(prompt), buf, sizeof buf, new);
1491 if (!ret) {
1492 err_set(KeyboardInterrupt);
1493 return NULL;
1494 }
1495 return newstringobject(buf);
1496}
1497
1498static object *
1499stdwin_askync(self, args)
1500 object *self;
1501 object *args;
1502{
1503 object *prompt;
1504 int new, ret;
1505 if (!getstrintarg(args, &prompt, &new))
1506 return NULL;
1507 ret = waskync(getstringvalue(prompt), new);
1508 if (ret < 0) {
1509 err_set(KeyboardInterrupt);
1510 return NULL;
1511 }
1512 return newintobject((long)ret);
1513}
1514
1515static object *
1516stdwin_askstr(self, args)
1517 object *self;
1518 object *args;
1519{
1520 object *prompt, *dflt;
1521 int ret;
1522 char buf[256];
1523 if (!getstrstrarg(args, &prompt, &dflt))
1524 return NULL;
1525 strncpy(buf, getstringvalue(dflt), sizeof buf);
1526 buf[sizeof buf - 1] = '\0';
1527 ret = waskstr(getstringvalue(prompt), buf, sizeof buf);
1528 if (!ret) {
1529 err_set(KeyboardInterrupt);
1530 return NULL;
1531 }
1532 return newstringobject(buf);
1533}
1534
1535static object *
1536stdwin_message(self, args)
1537 object *self;
1538 object *args;
1539{
1540 object *msg;
1541 if (!getstrarg(args, &msg))
1542 return NULL;
1543 wmessage(getstringvalue(msg));
1544 INCREF(None);
1545 return None;
1546}
1547
1548static object *
1549stdwin_fleep(self, args)
1550 object *self;
1551 object *args;
1552{
1553 if (!getnoarg(args))
1554 return NULL;
1555 wfleep();
1556 INCREF(None);
1557 return None;
1558}
1559
1560static object *
1561stdwin_setcutbuffer(self, args)
1562 object *self;
1563 object *args;
1564{
Guido van Rossum5b10f451990-10-30 16:01:48 +00001565 int i;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001566 object *str;
Guido van Rossum124967c1990-11-06 15:17:35 +00001567 if (!getintstrarg(args, &i, &str))
1568 return NULL;
Guido van Rossum5b10f451990-10-30 16:01:48 +00001569 wsetcutbuffer(i, getstringvalue(str), getstringsize(str));
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001570 INCREF(None);
1571 return None;
1572}
1573
1574static object *
1575stdwin_getcutbuffer(self, args)
1576 object *self;
1577 object *args;
1578{
Guido van Rossum5b10f451990-10-30 16:01:48 +00001579 int i;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001580 char *str;
Guido van Rossum01769f01990-10-30 13:39:00 +00001581 int len;
Guido van Rossum124967c1990-11-06 15:17:35 +00001582 if (!getintarg(args, &i))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001583 return NULL;
Guido van Rossum5b10f451990-10-30 16:01:48 +00001584 str = wgetcutbuffer(i, &len);
Guido van Rossum01769f01990-10-30 13:39:00 +00001585 if (str == NULL) {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001586 str = "";
Guido van Rossum01769f01990-10-30 13:39:00 +00001587 len = 0;
1588 }
1589 return newsizedstringobject(str, len);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001590}
1591
Guido van Rossum5b10f451990-10-30 16:01:48 +00001592static object *
1593stdwin_rotatecutbuffers(self, args)
1594 object *self;
1595 object *args;
1596{
1597 int i;
1598 if (!getintarg(args, &i))
1599 return NULL;
1600 wrotatecutbuffers(i);
1601 INCREF(None);
1602 return None;
1603}
1604
1605static object *
1606stdwin_getselection(self, args)
1607 object *self;
1608 object *args;
1609{
1610 int sel;
1611 char *data;
1612 int len;
1613 if (!getintarg(args, &sel))
1614 return NULL;
1615 data = wgetselection(sel, &len);
1616 if (data == NULL) {
1617 data = "";
1618 len = 0;
1619 }
1620 return newsizedstringobject(data, len);
1621}
1622
1623static object *
1624stdwin_resetselection(self, args)
1625 object *self;
1626 object *args;
1627{
1628 int sel;
1629 if (!getintarg(args, &sel))
1630 return NULL;
1631 wresetselection(sel);
1632 INCREF(None);
1633 return None;
1634}
1635
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001636static struct methodlist stdwin_methods[] = {
1637 {"askfile", stdwin_askfile},
1638 {"askstr", stdwin_askstr},
1639 {"askync", stdwin_askync},
1640 {"fleep", stdwin_fleep},
Guido van Rossum5b10f451990-10-30 16:01:48 +00001641 {"getselection", stdwin_getselection},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001642 {"getcutbuffer", stdwin_getcutbuffer},
Guido van Rossum33f17701991-02-13 23:19:39 +00001643 {"getdefwinpos", stdwin_getdefwinpos},
1644 {"getdefwinsize", stdwin_getdefwinsize},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001645 {"getevent", stdwin_getevent},
1646 {"menucreate", stdwin_menucreate},
1647 {"message", stdwin_message},
1648 {"open", stdwin_open},
Guido van Rossume8e7cf41991-01-16 14:06:18 +00001649 {"pollevent", stdwin_pollevent},
Guido van Rossum5b10f451990-10-30 16:01:48 +00001650 {"resetselection", stdwin_resetselection},
1651 {"rotatecutbuffers", stdwin_rotatecutbuffers},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001652 {"setcutbuffer", stdwin_setcutbuffer},
1653 {"setdefwinpos", stdwin_setdefwinpos},
1654 {"setdefwinsize", stdwin_setdefwinsize},
1655
1656 /* Text measuring methods borrow code from drawing objects: */
1657 {"baseline", drawing_baseline},
1658 {"lineheight", drawing_lineheight},
1659 {"textbreak", drawing_textbreak},
1660 {"textwidth", drawing_textwidth},
1661 {NULL, NULL} /* sentinel */
1662};
1663
1664void
1665initstdwin()
1666{
Guido van Rossum2d14e211991-02-19 12:26:49 +00001667 static int inited;
1668 if (!inited) {
1669 winit();
1670 inited = 1;
1671 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001672 initmodule("stdwin", stdwin_methods);
1673}