blob: 03e2db5add357326e030cfd58defccb99b6899be [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
2Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
3Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000025/* Stdwin module */
26
27/* Stdwin itself is a module, not a separate object type.
28 Object types defined here:
29 wp: a window
30 dp: a drawing structure (only one can exist at a time)
31 mp: a menu
32 tp: a textedit block
33*/
34
35/* Rules for translating C stdwin function calls into Python stwin:
36 - All names drop their initial letter 'w'
37 - Functions with a window as first parameter are methods of window objects
38 - There is no equivalent for wclose(); just delete the window object
39 (all references to it!) (XXX maybe this is a bad idea)
40 - w.begindrawing() returns a drawing object
41 - There is no equivalent for wenddrawing(win); just delete the drawing
42 object (all references to it!) (XXX maybe this is a bad idea)
43 - Functions that may only be used inside wbegindrawing / wendddrawing
44 are methods of the drawing object; this includes the text measurement
45 functions (which however have doubles as module functions).
46 - Methods of the drawing object drop an initial 'draw' from their name
47 if they have it, e.g., wdrawline() --> d.line()
48 - The obvious type conversions: int --> intobject; string --> stringobject
49 - A text parameter followed by a length parameter is only a text (string)
50 parameter in Python
51 - A point or other pair of horizontal and vertical coordinates is always
52 a pair of integers in Python
53 - Two points forming a rectangle or endpoints of a line segment are a
54 pair of points in Python
55 - The arguments to d.elarc() are three points.
56 - The functions wgetclip() and wsetclip() are translated into
57 stdwin.getcutbuffer() and stdwin.setcutbuffer(); 'clip' is really
58 a bad word for what these functions do (clipping has a different
59 meaning in the drawing world), while cutbuffer is standard X jargon.
Guido van Rossum01769f01990-10-30 13:39:00 +000060 XXX This must change again in the light of changes to stdwin!
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000061 - For textedit, similar rules hold, but they are less strict.
62 XXX more?
63*/
64
Guido van Rossum3f5da241990-12-20 15:06:42 +000065#include "allobjects.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000066
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000067#include "modsupport.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000068
Guido van Rossum3f5da241990-12-20 15:06:42 +000069#include "stdwin.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000070
Guido van Rossum87e7ea71991-12-10 14:00:03 +000071#define StdwinError RuntimeError /* XXX Change this later */
72
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000073/* Window and menu object types declared here because of forward references */
74
75typedef struct {
76 OB_HEAD
77 object *w_title;
78 WINDOW *w_win;
79 object *w_attr; /* Attributes dictionary */
80} windowobject;
81
82extern typeobject Windowtype; /* Really static, forward */
83
84#define is_windowobject(wp) ((wp)->ob_type == &Windowtype)
85
86typedef struct {
87 OB_HEAD
88 MENU *m_menu;
89 int m_id;
90 object *m_attr; /* Attributes dictionary */
91} menuobject;
92
93extern typeobject Menutype; /* Really static, forward */
94
95#define is_menuobject(mp) ((mp)->ob_type == &Menutype)
96
97
98/* Strongly stdwin-specific argument handlers */
99
100static int
101getmousedetail(v, ep)
102 object *v;
103 EVENT *ep;
104{
105 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 4)
106 return err_badarg();
107 return getintintarg(gettupleitem(v, 0),
108 &ep->u.where.h, &ep->u.where.v) &&
109 getintarg(gettupleitem(v, 1), &ep->u.where.clicks) &&
110 getintarg(gettupleitem(v, 2), &ep->u.where.button) &&
111 getintarg(gettupleitem(v, 3), &ep->u.where.mask);
112}
113
114static int
115getmenudetail(v, ep)
116 object *v;
117 EVENT *ep;
118{
119 object *mp;
120 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2)
121 return err_badarg();
122 mp = gettupleitem(v, 0);
123 if (mp == NULL || !is_menuobject(mp))
124 return err_badarg();
125 ep->u.m.id = ((menuobject *)mp) -> m_id;
126 return getintarg(gettupleitem(v, 1), &ep->u.m.item);
127}
128
129static int
130geteventarg(v, ep)
131 object *v;
132 EVENT *ep;
133{
134 object *wp, *detail;
135 int a[4];
136 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 3)
137 return err_badarg();
138 if (!getintarg(gettupleitem(v, 0), &ep->type))
139 return 0;
140 wp = gettupleitem(v, 1);
141 if (wp == None)
142 ep->window = NULL;
143 else if (wp == NULL || !is_windowobject(wp))
144 return err_badarg();
145 else
146 ep->window = ((windowobject *)wp) -> w_win;
147 detail = gettupleitem(v, 2);
148 switch (ep->type) {
149 case WE_CHAR:
150 if (!is_stringobject(detail) || getstringsize(detail) != 1)
151 return err_badarg();
152 ep->u.character = getstringvalue(detail)[0];
153 return 1;
154 case WE_COMMAND:
155 return getintarg(detail, &ep->u.command);
156 case WE_DRAW:
157 if (!getrectarg(detail, a))
158 return 0;
159 ep->u.area.left = a[0];
160 ep->u.area.top = a[1];
161 ep->u.area.right = a[2];
162 ep->u.area.bottom = a[3];
163 return 1;
164 case WE_MOUSE_DOWN:
165 case WE_MOUSE_UP:
166 case WE_MOUSE_MOVE:
167 return getmousedetail(detail, ep);
168 case WE_MENU:
169 return getmenudetail(detail, ep);
170 default:
171 return 1;
172 }
173}
174
175
176/* Return construction tools */
177
178static object *
179makepoint(a, b)
180 int a, b;
181{
182 object *v;
183 object *w;
184 if ((v = newtupleobject(2)) == NULL)
185 return NULL;
186 if ((w = newintobject((long)a)) == NULL ||
187 settupleitem(v, 0, w) != 0 ||
188 (w = newintobject((long)b)) == NULL ||
189 settupleitem(v, 1, w) != 0) {
190 DECREF(v);
191 return NULL;
192 }
193 return v;
194}
195
196static object *
197makerect(a, b, c, d)
198 int a, b, c, d;
199{
200 object *v;
201 object *w;
202 if ((v = newtupleobject(2)) == NULL)
203 return NULL;
204 if ((w = makepoint(a, b)) == NULL ||
205 settupleitem(v, 0, w) != 0 ||
206 (w = makepoint(c, d)) == NULL ||
207 settupleitem(v, 1, w) != 0) {
208 DECREF(v);
209 return NULL;
210 }
211 return v;
212}
213
214static object *
215makemouse(hor, ver, clicks, button, mask)
216 int hor, ver, clicks, button, mask;
217{
218 object *v;
219 object *w;
220 if ((v = newtupleobject(4)) == NULL)
221 return NULL;
222 if ((w = makepoint(hor, ver)) == NULL ||
223 settupleitem(v, 0, w) != 0 ||
224 (w = newintobject((long)clicks)) == NULL ||
225 settupleitem(v, 1, w) != 0 ||
226 (w = newintobject((long)button)) == NULL ||
227 settupleitem(v, 2, w) != 0 ||
228 (w = newintobject((long)mask)) == NULL ||
229 settupleitem(v, 3, w) != 0) {
230 DECREF(v);
231 return NULL;
232 }
233 return v;
234}
235
236static object *
237makemenu(mp, item)
238 object *mp;
239 int item;
240{
241 object *v;
242 object *w;
243 if ((v = newtupleobject(2)) == NULL)
244 return NULL;
245 INCREF(mp);
246 if (settupleitem(v, 0, mp) != 0 ||
247 (w = newintobject((long)item)) == NULL ||
248 settupleitem(v, 1, w) != 0) {
249 DECREF(v);
250 return NULL;
251 }
252 return v;
253}
254
255
256/* Drawing objects */
257
258typedef struct {
259 OB_HEAD
260 windowobject *d_ref;
261} drawingobject;
262
263static drawingobject *Drawing; /* Set to current drawing object, or NULL */
264
265/* Drawing methods */
266
Guido van Rossum3c284741991-11-27 14:54:54 +0000267static object *
268drawing_close(dp)
269 drawingobject *dp;
270{
271 if (dp->d_ref != NULL) {
272 wenddrawing(dp->d_ref->w_win);
273 Drawing = NULL;
274 DECREF(dp->d_ref);
275 dp->d_ref = NULL;
276 }
277 INCREF(None);
278 return None;
279}
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000280static void
281drawing_dealloc(dp)
282 drawingobject *dp;
283{
Guido van Rossum3c284741991-11-27 14:54:54 +0000284 if (dp->d_ref != NULL) {
285 wenddrawing(dp->d_ref->w_win);
286 Drawing = NULL;
287 DECREF(dp->d_ref);
288 dp->d_ref = NULL;
289 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000290 free((char *)dp);
291}
292
293static object *
294drawing_generic(dp, args, func)
295 drawingobject *dp;
296 object *args;
297 void (*func) FPROTO((int, int, int, int));
298{
299 int a[4];
300 if (!getrectarg(args, a))
301 return NULL;
302 (*func)(a[0], a[1], a[2], a[3]);
303 INCREF(None);
304 return None;
305}
306
307static object *
308drawing_line(dp, args)
309 drawingobject *dp;
310 object *args;
311{
Guido van Rossumbf109731991-03-06 13:14:12 +0000312 return drawing_generic(dp, args, wdrawline);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000313}
314
315static object *
316drawing_xorline(dp, args)
317 drawingobject *dp;
318 object *args;
319{
Guido van Rossumbf109731991-03-06 13:14:12 +0000320 return drawing_generic(dp, args, wxorline);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000321}
322
323static object *
324drawing_circle(dp, args)
325 drawingobject *dp;
326 object *args;
327{
328 int a[3];
329 if (!getpointintarg(args, a))
330 return NULL;
331 wdrawcircle(a[0], a[1], a[2]);
332 INCREF(None);
333 return None;
334}
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000335
Guido van Rossum27201061991-04-16 08:43:03 +0000336static object *
337drawing_fillcircle(dp, args)
338 drawingobject *dp;
339 object *args;
340{
341 int a[3];
342 if (!getpointintarg(args, a))
343 return NULL;
344 wfillcircle(a[0], a[1], a[2]);
345 INCREF(None);
346 return None;
347}
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000348
349static object *
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000350drawing_xorcircle(dp, args)
351 drawingobject *dp;
352 object *args;
353{
354 int a[3];
355 if (!getpointintarg(args, a))
356 return NULL;
357 wxorcircle(a[0], a[1], a[2]);
358 INCREF(None);
359 return None;
360}
361
362static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000363drawing_elarc(dp, args)
364 drawingobject *dp;
365 object *args;
366{
367 int a[6];
368 if (!get3pointarg(args, a))
369 return NULL;
370 wdrawelarc(a[0], a[1], a[2], a[3], a[4], a[5]);
371 INCREF(None);
372 return None;
373}
374
375static object *
Guido van Rossum27201061991-04-16 08:43:03 +0000376drawing_fillelarc(dp, args)
377 drawingobject *dp;
378 object *args;
379{
380 int a[6];
381 if (!get3pointarg(args, a))
382 return NULL;
383 wfillelarc(a[0], a[1], a[2], a[3], a[4], a[5]);
384 INCREF(None);
385 return None;
386}
387
388static object *
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000389drawing_xorelarc(dp, args)
390 drawingobject *dp;
391 object *args;
392{
393 int a[6];
394 if (!get3pointarg(args, a))
395 return NULL;
396 wxorelarc(a[0], a[1], a[2], a[3], a[4], a[5]);
397 INCREF(None);
398 return None;
399}
400
401static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000402drawing_box(dp, args)
403 drawingobject *dp;
404 object *args;
405{
Guido van Rossumbf109731991-03-06 13:14:12 +0000406 return drawing_generic(dp, args, wdrawbox);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000407}
408
409static object *
410drawing_erase(dp, args)
411 drawingobject *dp;
412 object *args;
413{
Guido van Rossumbf109731991-03-06 13:14:12 +0000414 return drawing_generic(dp, args, werase);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000415}
416
417static object *
418drawing_paint(dp, args)
419 drawingobject *dp;
420 object *args;
421{
Guido van Rossumbf109731991-03-06 13:14:12 +0000422 return drawing_generic(dp, args, wpaint);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000423}
424
425static object *
426drawing_invert(dp, args)
427 drawingobject *dp;
428 object *args;
429{
Guido van Rossumbf109731991-03-06 13:14:12 +0000430 return drawing_generic(dp, args, winvert);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000431}
432
Guido van Rossum27201061991-04-16 08:43:03 +0000433static POINT *
434getpointsarray(v, psize)
435 object *v;
436 int *psize;
437{
438 int n = -1;
439 object * (*getitem) PROTO((object *, int));
440 int i;
441 POINT *points;
442
443 if (v == NULL)
444 ;
445 else if (is_listobject(v)) {
446 n = getlistsize(v);
447 getitem = getlistitem;
448 }
449 else if (is_tupleobject(v)) {
450 n = gettuplesize(v);
451 getitem = gettupleitem;
452 }
453
454 if (n <= 0) {
455 (void) err_badarg();
456 return NULL;
457 }
458
459 points = NEW(POINT, n);
460 if (points == NULL) {
461 (void) err_nomem();
462 return NULL;
463 }
464
465 for (i = 0; i < n; i++) {
466 object *w = (*getitem)(v, i);
467 int a[2];
468 if (!getpointarg(w, a)) {
469 DEL(points);
470 return NULL;
471 }
472 points[i].h = a[0];
473 points[i].v = a[1];
474 }
475
476 *psize = n;
477 return points;
478}
479
480static object *
481drawing_poly(dp, args)
482 drawingobject *dp;
483 object *args;
484{
485 int n;
486 POINT *points = getpointsarray(args, &n);
487 if (points == NULL)
488 return NULL;
489 wdrawpoly(n, points);
490 DEL(points);
491 INCREF(None);
492 return None;
493}
494
495static object *
496drawing_fillpoly(dp, args)
497 drawingobject *dp;
498 object *args;
499{
500 int n;
501 POINT *points = getpointsarray(args, &n);
502 if (points == NULL)
503 return NULL;
504 wfillpoly(n, points);
505 DEL(points);
506 INCREF(None);
507 return None;
508}
509
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000510static object *
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000511drawing_xorpoly(dp, args)
512 drawingobject *dp;
513 object *args;
514{
515 int n;
516 POINT *points = getpointsarray(args, &n);
517 if (points == NULL)
518 return NULL;
519 wxorpoly(n, points);
520 DEL(points);
521 INCREF(None);
522 return None;
523}
524
525static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000526drawing_cliprect(dp, args)
527 drawingobject *dp;
528 object *args;
529{
Guido van Rossumbf109731991-03-06 13:14:12 +0000530 return drawing_generic(dp, args, wcliprect);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000531}
532
533static object *
534drawing_noclip(dp, args)
535 drawingobject *dp;
536 object *args;
537{
538 if (!getnoarg(args))
539 return NULL;
540 wnoclip();
541 INCREF(None);
542 return None;
543}
544
545static object *
546drawing_shade(dp, args)
547 drawingobject *dp;
548 object *args;
549{
550 int a[5];
551 if (!getrectintarg(args, a))
552 return NULL;
553 wshade(a[0], a[1], a[2], a[3], a[4]);
554 INCREF(None);
555 return None;
556}
557
558static object *
559drawing_text(dp, args)
560 drawingobject *dp;
561 object *args;
562{
563 int a[2];
564 object *s;
565 if (!getpointstrarg(args, a, &s))
566 return NULL;
567 wdrawtext(a[0], a[1], getstringvalue(s), (int)getstringsize(s));
568 INCREF(None);
569 return None;
570}
571
572/* The following four are also used as stdwin functions */
573
574static object *
575drawing_lineheight(dp, args)
576 drawingobject *dp;
577 object *args;
578{
579 if (!getnoarg(args))
580 return NULL;
581 return newintobject((long)wlineheight());
582}
583
584static object *
585drawing_baseline(dp, args)
586 drawingobject *dp;
587 object *args;
588{
589 if (!getnoarg(args))
590 return NULL;
591 return newintobject((long)wbaseline());
592}
593
594static object *
595drawing_textwidth(dp, args)
596 drawingobject *dp;
597 object *args;
598{
599 object *s;
600 if (!getstrarg(args, &s))
601 return NULL;
602 return newintobject(
603 (long)wtextwidth(getstringvalue(s), (int)getstringsize(s)));
604}
605
606static object *
607drawing_textbreak(dp, args)
608 drawingobject *dp;
609 object *args;
610{
611 object *s;
612 int a;
613 if (!getstrintarg(args, &s, &a))
614 return NULL;
615 return newintobject(
616 (long)wtextbreak(getstringvalue(s), (int)getstringsize(s), a));
617}
618
Guido van Rossum0c2290b1991-04-03 19:12:14 +0000619static object *
620drawing_setfont(self, args)
621 drawingobject *self;
622 object *args;
623{
Guido van Rossum50429a11991-04-04 15:24:07 +0000624 object *font, *style;
625 int size;
626 if (args == NULL) {
627 err_badarg();
Guido van Rossum0c2290b1991-04-03 19:12:14 +0000628 return NULL;
Guido van Rossum50429a11991-04-04 15:24:07 +0000629 }
630 if (is_stringobject(args)) {
631 font = args;
632 style = NULL;
633 size = 0;
634 }
635 else if (is_tupleobject(args)) {
636 int n = gettuplesize(args);
637 if (n == 2) {
638 if (!getstrintarg(args, &font, &size))
639 return NULL;
640 style = NULL;
641 }
642 else if (!getstrstrintarg(args, &font, &style, &size))
643 return NULL;
644 }
645 else {
646 err_badarg();
647 return NULL;
648 }
Guido van Rossum246b9d81991-06-03 10:55:14 +0000649 wsetfont(getstringvalue(font));
Guido van Rossum50429a11991-04-04 15:24:07 +0000650 if (style != NULL) {
651 switch (*getstringvalue(style)) {
652 case 'b':
653 wsetbold();
654 break;
655 case 'i':
656 wsetitalic();
657 break;
658 case 'o':
659 wsetbolditalic();
660 break;
661 case 'u':
662 wsetunderline();
663 break;
664 default:
665 wsetplain();
666 break;
667 }
668 }
669 if (size != 0)
670 wsetsize(size);
Guido van Rossum0c2290b1991-04-03 19:12:14 +0000671 INCREF(None);
672 return None;
673}
674
675static object *
676drawing_getbgcolor(self, args)
677 object *self;
678 object *args;
679{
680 if (!getnoarg(args))
681 return NULL;
682 return newintobject((long)wgetbgcolor());
683}
684
685static object *
686drawing_getfgcolor(self, args)
687 object *self;
688 object *args;
689{
690 if (!getnoarg(args))
691 return NULL;
692 return newintobject((long)wgetfgcolor());
693}
694
695static object *
696drawing_setbgcolor(self, args)
697 object *self;
698 object *args;
699{
700 long color;
701 if (!getlongarg(args, &color))
702 return NULL;
703 wsetbgcolor((COLOR)color);
704 INCREF(None);
705 return None;
706}
707
708static object *
709drawing_setfgcolor(self, args)
710 object *self;
711 object *args;
712{
713 long color;
714 if (!getlongarg(args, &color))
715 return NULL;
716 wsetfgcolor((COLOR)color);
717 INCREF(None);
718 return None;
719}
720
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000721static struct methodlist drawing_methods[] = {
722 {"box", drawing_box},
723 {"circle", drawing_circle},
724 {"cliprect", drawing_cliprect},
Guido van Rossum3c284741991-11-27 14:54:54 +0000725 {"close", drawing_close},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000726 {"elarc", drawing_elarc},
Guido van Rossum3c284741991-11-27 14:54:54 +0000727 {"enddrawing", drawing_close},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000728 {"erase", drawing_erase},
Guido van Rossum27201061991-04-16 08:43:03 +0000729 {"fillcircle", drawing_fillcircle},
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000730 {"fillelarc", drawing_fillelarc},
Guido van Rossum27201061991-04-16 08:43:03 +0000731 {"fillpoly", drawing_fillpoly},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000732 {"invert", drawing_invert},
733 {"line", drawing_line},
734 {"noclip", drawing_noclip},
735 {"paint", drawing_paint},
Guido van Rossum27201061991-04-16 08:43:03 +0000736 {"poly", drawing_poly},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000737 {"shade", drawing_shade},
738 {"text", drawing_text},
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000739 {"xorcircle", drawing_xorcircle},
740 {"xorelarc", drawing_xorelarc},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000741 {"xorline", drawing_xorline},
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000742 {"xorpoly", drawing_xorpoly},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000743
744 /* Text measuring methods: */
745 {"baseline", drawing_baseline},
746 {"lineheight", drawing_lineheight},
747 {"textbreak", drawing_textbreak},
748 {"textwidth", drawing_textwidth},
Guido van Rossum0c2290b1991-04-03 19:12:14 +0000749
750 /* Font setting methods: */
751 {"setfont", drawing_setfont},
752
753 /* Color methods: */
754 {"getbgcolor", drawing_getbgcolor},
755 {"getfgcolor", drawing_getfgcolor},
756 {"setbgcolor", drawing_setbgcolor},
757 {"setfgcolor", drawing_setfgcolor},
758
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000759 {NULL, NULL} /* sentinel */
760};
761
762static object *
763drawing_getattr(wp, name)
764 drawingobject *wp;
765 char *name;
766{
767 return findmethod(drawing_methods, (object *)wp, name);
768}
769
Guido van Rossum541c8c01991-05-05 20:13:41 +0000770typeobject Drawingtype = {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000771 OB_HEAD_INIT(&Typetype)
772 0, /*ob_size*/
773 "drawing", /*tp_name*/
774 sizeof(drawingobject), /*tp_size*/
775 0, /*tp_itemsize*/
776 /* methods */
777 drawing_dealloc, /*tp_dealloc*/
778 0, /*tp_print*/
779 drawing_getattr, /*tp_getattr*/
780 0, /*tp_setattr*/
781 0, /*tp_compare*/
782 0, /*tp_repr*/
783};
784
785
786/* Text(edit) objects */
787
788typedef struct {
789 OB_HEAD
790 TEXTEDIT *t_text;
791 windowobject *t_ref;
792 object *t_attr; /* Attributes dictionary */
793} textobject;
794
795extern typeobject Texttype; /* Really static, forward */
796
797static textobject *
798newtextobject(wp, left, top, right, bottom)
799 windowobject *wp;
800 int left, top, right, bottom;
801{
802 textobject *tp;
803 tp = NEWOBJ(textobject, &Texttype);
804 if (tp == NULL)
805 return NULL;
806 tp->t_attr = NULL;
807 INCREF(wp);
808 tp->t_ref = wp;
809 tp->t_text = tecreate(wp->w_win, left, top, right, bottom);
810 if (tp->t_text == NULL) {
811 DECREF(tp);
812 return (textobject *) err_nomem();
813 }
814 return tp;
815}
816
817/* Text(edit) methods */
818
819static void
820text_dealloc(tp)
821 textobject *tp;
822{
823 if (tp->t_text != NULL)
824 tefree(tp->t_text);
Guido van Rossum3c284741991-11-27 14:54:54 +0000825 XDECREF(tp->t_attr);
826 XDECREF(tp->t_ref);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000827 DEL(tp);
828}
829
830static object *
Guido van Rossum3c284741991-11-27 14:54:54 +0000831text_close(tp, args)
832 textobject *tp;
833 object *args;
834{
835 if (tp->t_text != NULL) {
836 tefree(tp->t_text);
837 tp->t_text = NULL;
838 }
839 if (tp->t_attr != NULL) {
840 DECREF(tp->t_attr);
841 tp->t_attr = NULL;
842 }
843 if (tp->t_ref != NULL) {
844 DECREF(tp->t_ref);
845 tp->t_ref = NULL;
846 }
847 INCREF(None);
848 return None;
849}
850
851static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000852text_arrow(self, args)
853 textobject *self;
854 object *args;
855{
856 int code;
857 if (!getintarg(args, &code))
858 return NULL;
859 tearrow(self->t_text, code);
860 INCREF(None);
861 return None;
862}
863
864static object *
865text_draw(self, args)
866 textobject *self;
867 object *args;
868{
869 register TEXTEDIT *tp = self->t_text;
870 int a[4];
871 int left, top, right, bottom;
872 if (!getrectarg(args, a))
873 return NULL;
874 if (Drawing != NULL) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +0000875 err_setstr(StdwinError, "already drawing");
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000876 return NULL;
877 }
878 /* Clip to text area and ignore if area is empty */
879 left = tegetleft(tp);
880 top = tegettop(tp);
881 right = tegetright(tp);
882 bottom = tegetbottom(tp);
883 if (a[0] < left) a[0] = left;
884 if (a[1] < top) a[1] = top;
885 if (a[2] > right) a[2] = right;
886 if (a[3] > bottom) a[3] = bottom;
887 if (a[0] < a[2] && a[1] < a[3]) {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000888 wbegindrawing(self->t_ref->w_win);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000889 tedrawnew(tp, a[0], a[1], a[2], a[3]);
890 wenddrawing(self->t_ref->w_win);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000891 }
892 INCREF(None);
893 return None;
894}
895
896static object *
897text_event(self, args)
898 textobject *self;
899 object *args;
900{
901 register TEXTEDIT *tp = self->t_text;
902 EVENT e;
903 if (!geteventarg(args, &e))
904 return NULL;
905 if (e.type == WE_MOUSE_DOWN) {
Guido van Rossum33f17701991-02-13 23:19:39 +0000906 /* Cheat at the margins */
907 int width, height;
908 wgetdocsize(e.window, &width, &height);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000909 if (e.u.where.h < 0 && tegetleft(tp) == 0)
910 e.u.where.h = 0;
Guido van Rossum33f17701991-02-13 23:19:39 +0000911 else if (e.u.where.h > width && tegetright(tp) == width)
912 e.u.where.h = width;
913 if (e.u.where.v < 0 && tegettop(tp) == 0)
914 e.u.where.v = 0;
915 else if (e.u.where.v > height && tegetright(tp) == height)
916 e.u.where.v = height;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000917 }
918 return newintobject((long) teevent(tp, &e));
919}
920
921static object *
922text_getfocus(self, args)
923 textobject *self;
924 object *args;
925{
926 if (!getnoarg(args))
927 return NULL;
928 return makepoint(tegetfoc1(self->t_text), tegetfoc2(self->t_text));
929}
930
931static object *
932text_getfocustext(self, args)
933 textobject *self;
934 object *args;
935{
936 int f1, f2;
937 char *text;
938 if (!getnoarg(args))
939 return NULL;
940 f1 = tegetfoc1(self->t_text);
941 f2 = tegetfoc2(self->t_text);
942 text = tegettext(self->t_text);
943 return newsizedstringobject(text + f1, f2-f1);
944}
945
946static object *
947text_getrect(self, args)
948 textobject *self;
949 object *args;
950{
951 if (!getnoarg(args))
952 return NULL;
953 return makerect(tegetleft(self->t_text),
954 tegettop(self->t_text),
955 tegetright(self->t_text),
956 tegetbottom(self->t_text));
957}
958
959static object *
960text_gettext(self, args)
961 textobject *self;
962 object *args;
963{
964 if (!getnoarg(args))
965 return NULL;
966 return newsizedstringobject(tegettext(self->t_text),
967 tegetlen(self->t_text));
968}
969
970static object *
971text_move(self, args)
972 textobject *self;
973 object *args;
974{
975 int a[4];
976 if (!getrectarg(args, a))
977 return NULL;
978 temovenew(self->t_text, a[0], a[1], a[2], a[3]);
979 INCREF(None);
980 return None;
981}
982
983static object *
Guido van Rossum4b9cf8e1991-05-28 21:57:04 +0000984text_replace(self, args)
985 textobject *self;
986 object *args;
987{
988 object *text;
989 if (!getstrarg(args, &text))
990 return NULL;
991 tereplace(self->t_text, getstringvalue(text));
992 INCREF(None);
993 return None;
994}
995
996static object *
997text_setactive(self, args)
998 textobject *self;
999 object *args;
1000{
1001 int flag;
1002 if (!getintarg(args, &flag))
1003 return NULL;
1004 tesetactive(self->t_text, flag);
1005 INCREF(None);
1006 return None;
1007}
1008
1009static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001010text_setfocus(self, args)
1011 textobject *self;
1012 object *args;
1013{
1014 int a[2];
1015 if (!getpointarg(args, a))
1016 return NULL;
1017 tesetfocus(self->t_text, a[0], a[1]);
1018 INCREF(None);
1019 return None;
1020}
1021
1022static object *
Guido van Rossum541c8c01991-05-05 20:13:41 +00001023text_settext(self, args)
1024 textobject *self;
1025 object *args;
1026{
1027 object *text;
1028 char *buf;
1029 int size;
1030 if (!getstrarg(args, &text))
1031 return NULL;
1032 size = getstringsize(text);
1033 if ((buf = NEW(char, size)) == NULL) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +00001034 return err_nomem();
Guido van Rossum541c8c01991-05-05 20:13:41 +00001035 }
1036 memcpy(buf, getstringvalue(text), size);
1037 tesetbuf(self->t_text, buf, size); /* Becomes owner of buffer */
1038 INCREF(None);
1039 return None;
1040}
1041
1042static object *
Guido van Rossum4b9cf8e1991-05-28 21:57:04 +00001043text_setview(self, args)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001044 textobject *self;
1045 object *args;
1046{
Guido van Rossum4b9cf8e1991-05-28 21:57:04 +00001047 int a[4];
1048 if (args == None)
1049 tenoview(self->t_text);
1050 else {
1051 if (!getrectarg(args, a))
1052 return NULL;
1053 tesetview(self->t_text, a[0], a[1], a[2], a[3]);
1054 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001055 INCREF(None);
1056 return None;
1057}
1058
1059static struct methodlist text_methods[] = {
Guido van Rossum3c284741991-11-27 14:54:54 +00001060 {"arrow", text_arrow},
1061 {"close", text_close},
1062 {"draw", text_draw},
1063 {"event", text_event},
1064 {"getfocus", text_getfocus},
1065 {"getfocustext", text_getfocustext},
1066 {"getrect", text_getrect},
1067 {"gettext", text_gettext},
1068 {"move", text_move},
1069 {"replace", text_replace},
1070 {"setactive", text_setactive},
1071 {"setfocus", text_setfocus},
1072 {"settext", text_settext},
1073 {"setview", text_setview},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001074 {NULL, NULL} /* sentinel */
1075};
1076
1077static object *
1078text_getattr(tp, name)
1079 textobject *tp;
1080 char *name;
1081{
Guido van Rossum85f50761991-10-20 20:22:50 +00001082 object *v = NULL;
1083 if (strcmp(name, "__dict__") == 0) {
1084 v = tp->t_attr;
1085 if (v == NULL)
1086 v = None;
1087 }
1088 else if (tp->t_attr != NULL) {
1089 v = dictlookup(tp->t_attr, name);
1090 }
1091 if (v != NULL) {
1092 INCREF(v);
1093 return v;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001094 }
1095 return findmethod(text_methods, (object *)tp, name);
1096}
1097
1098static int
1099text_setattr(tp, name, v)
1100 textobject *tp;
1101 char *name;
1102 object *v;
1103{
1104 if (tp->t_attr == NULL) {
1105 tp->t_attr = newdictobject();
1106 if (tp->t_attr == NULL)
1107 return -1;
1108 }
1109 if (v == NULL)
1110 return dictremove(tp->t_attr, name);
1111 else
1112 return dictinsert(tp->t_attr, name, v);
1113}
1114
Guido van Rossum541c8c01991-05-05 20:13:41 +00001115typeobject Texttype = {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001116 OB_HEAD_INIT(&Typetype)
1117 0, /*ob_size*/
1118 "textedit", /*tp_name*/
1119 sizeof(textobject), /*tp_size*/
1120 0, /*tp_itemsize*/
1121 /* methods */
1122 text_dealloc, /*tp_dealloc*/
1123 0, /*tp_print*/
1124 text_getattr, /*tp_getattr*/
1125 text_setattr, /*tp_setattr*/
1126 0, /*tp_compare*/
1127 0, /*tp_repr*/
1128};
1129
1130
1131/* Menu objects */
1132
Guido van Rossum2d14e211991-02-19 12:26:49 +00001133#define IDOFFSET 10 /* Menu IDs we use start here */
Guido van Rossum27201061991-04-16 08:43:03 +00001134#define MAXNMENU 200 /* Max #menus we allow */
Guido van Rossum2d14e211991-02-19 12:26:49 +00001135static menuobject *menulist[MAXNMENU];
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001136
1137static menuobject *
1138newmenuobject(title)
1139 object *title;
1140{
1141 int id;
1142 MENU *menu;
1143 menuobject *mp;
Guido van Rossum2d14e211991-02-19 12:26:49 +00001144 for (id = 0; id < MAXNMENU; id++) {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001145 if (menulist[id] == NULL)
1146 break;
1147 }
Guido van Rossum27201061991-04-16 08:43:03 +00001148 if (id >= MAXNMENU) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +00001149 err_setstr(StdwinError, "creating too many menus");
Guido van Rossum27201061991-04-16 08:43:03 +00001150 return NULL;
1151 }
Guido van Rossum2d14e211991-02-19 12:26:49 +00001152 menu = wmenucreate(id + IDOFFSET, getstringvalue(title));
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001153 if (menu == NULL)
1154 return (menuobject *) err_nomem();
1155 mp = NEWOBJ(menuobject, &Menutype);
1156 if (mp != NULL) {
1157 mp->m_menu = menu;
Guido van Rossum2d14e211991-02-19 12:26:49 +00001158 mp->m_id = id + IDOFFSET;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001159 mp->m_attr = NULL;
1160 menulist[id] = mp;
1161 }
1162 else
1163 wmenudelete(menu);
1164 return mp;
1165}
1166
1167/* Menu methods */
1168
1169static void
1170menu_dealloc(mp)
1171 menuobject *mp;
1172{
1173
Guido van Rossum2d14e211991-02-19 12:26:49 +00001174 int id = mp->m_id - IDOFFSET;
1175 if (id >= 0 && id < MAXNMENU && menulist[id] == mp) {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001176 menulist[id] = NULL;
1177 }
1178 wmenudelete(mp->m_menu);
1179 if (mp->m_attr != NULL)
1180 DECREF(mp->m_attr);
1181 DEL(mp);
1182}
1183
1184static object *
1185menu_additem(self, args)
1186 menuobject *self;
1187 object *args;
1188{
1189 object *text;
1190 int shortcut;
1191 if (is_tupleobject(args)) {
1192 object *v;
1193 if (!getstrstrarg(args, &text, &v))
1194 return NULL;
1195 if (getstringsize(v) != 1) {
1196 err_badarg();
1197 return NULL;
1198 }
1199 shortcut = *getstringvalue(v) & 0xff;
1200 }
1201 else {
1202 if (!getstrarg(args, &text))
1203 return NULL;
1204 shortcut = -1;
1205 }
1206 wmenuadditem(self->m_menu, getstringvalue(text), shortcut);
1207 INCREF(None);
1208 return None;
1209}
1210
1211static object *
1212menu_setitem(self, args)
1213 menuobject *self;
1214 object *args;
1215{
1216 int index;
1217 object *text;
1218 if (!getintstrarg(args, &index, &text))
1219 return NULL;
1220 wmenusetitem(self->m_menu, index, getstringvalue(text));
1221 INCREF(None);
1222 return None;
1223}
1224
1225static object *
1226menu_enable(self, args)
1227 menuobject *self;
1228 object *args;
1229{
1230 int index;
1231 int flag;
1232 if (!getintintarg(args, &index, &flag))
1233 return NULL;
1234 wmenuenable(self->m_menu, index, flag);
1235 INCREF(None);
1236 return None;
1237}
1238
1239static object *
1240menu_check(self, args)
1241 menuobject *self;
1242 object *args;
1243{
1244 int index;
1245 int flag;
1246 if (!getintintarg(args, &index, &flag))
1247 return NULL;
1248 wmenucheck(self->m_menu, index, flag);
1249 INCREF(None);
1250 return None;
1251}
1252
1253static struct methodlist menu_methods[] = {
Guido van Rossum3c284741991-11-27 14:54:54 +00001254 {"additem", menu_additem},
1255 {"setitem", menu_setitem},
1256 {"enable", menu_enable},
1257 {"check", menu_check},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001258 {NULL, NULL} /* sentinel */
1259};
1260
1261static object *
1262menu_getattr(mp, name)
1263 menuobject *mp;
1264 char *name;
1265{
Guido van Rossum85f50761991-10-20 20:22:50 +00001266 object *v = NULL;
1267 if (strcmp(name, "__dict__") == 0) {
1268 v = mp->m_attr;
1269 if (v == NULL)
1270 v = None;
1271 }
1272 else if (mp->m_attr != NULL) {
1273 v = dictlookup(mp->m_attr, name);
1274 }
1275 if (v != NULL) {
1276 INCREF(v);
1277 return v;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001278 }
1279 return findmethod(menu_methods, (object *)mp, name);
1280}
1281
1282static int
1283menu_setattr(mp, name, v)
1284 menuobject *mp;
1285 char *name;
1286 object *v;
1287{
1288 if (mp->m_attr == NULL) {
1289 mp->m_attr = newdictobject();
1290 if (mp->m_attr == NULL)
1291 return -1;
1292 }
1293 if (v == NULL)
1294 return dictremove(mp->m_attr, name);
1295 else
1296 return dictinsert(mp->m_attr, name, v);
1297}
1298
Guido van Rossum541c8c01991-05-05 20:13:41 +00001299typeobject Menutype = {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001300 OB_HEAD_INIT(&Typetype)
1301 0, /*ob_size*/
1302 "menu", /*tp_name*/
1303 sizeof(menuobject), /*tp_size*/
1304 0, /*tp_itemsize*/
1305 /* methods */
1306 menu_dealloc, /*tp_dealloc*/
1307 0, /*tp_print*/
1308 menu_getattr, /*tp_getattr*/
1309 menu_setattr, /*tp_setattr*/
1310 0, /*tp_compare*/
1311 0, /*tp_repr*/
1312};
1313
1314
1315/* Windows */
1316
1317#define MAXNWIN 50
1318static windowobject *windowlist[MAXNWIN];
1319
1320/* Window methods */
1321
1322static void
1323window_dealloc(wp)
1324 windowobject *wp;
1325{
1326 if (wp->w_win != NULL) {
1327 int tag = wgettag(wp->w_win);
1328 if (tag >= 0 && tag < MAXNWIN)
1329 windowlist[tag] = NULL;
1330 else
1331 fprintf(stderr, "XXX help! tag %d in window_dealloc\n",
1332 tag);
1333 wclose(wp->w_win);
1334 }
1335 DECREF(wp->w_title);
1336 if (wp->w_attr != NULL)
1337 DECREF(wp->w_attr);
1338 free((char *)wp);
1339}
1340
Guido van Rossumd783a461991-06-07 22:35:42 +00001341static int
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001342window_print(wp, fp, flags)
1343 windowobject *wp;
1344 FILE *fp;
1345 int flags;
1346{
Guido van Rossum3c284741991-11-27 14:54:54 +00001347 fprintf(fp, "<%s window titled '%s'>",
1348 wp->w_win == NULL ? "closed" : "open",
1349 getstringvalue(wp->w_title));
Guido van Rossumd783a461991-06-07 22:35:42 +00001350 return 0;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001351}
1352
1353static object *
Guido van Rossum3c284741991-11-27 14:54:54 +00001354window_close(wp, args)
1355 windowobject *wp;
1356 object *args;
1357{
1358 if (wp->w_win != NULL) {
1359 int tag = wgettag(wp->w_win);
1360 if (tag >= 0 && tag < MAXNWIN)
1361 windowlist[tag] = NULL;
1362 wclose(wp->w_win);
1363 wp->w_win = NULL;
1364 }
1365 INCREF(None);
1366 return None;
1367}
1368
1369static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001370window_begindrawing(wp, args)
1371 windowobject *wp;
1372 object *args;
1373{
1374 drawingobject *dp;
1375 if (!getnoarg(args))
1376 return NULL;
1377 if (Drawing != NULL) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +00001378 err_setstr(StdwinError, "already drawing");
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001379 return NULL;
1380 }
1381 dp = NEWOBJ(drawingobject, &Drawingtype);
1382 if (dp == NULL)
1383 return NULL;
1384 Drawing = dp;
1385 INCREF(wp);
1386 dp->d_ref = wp;
1387 wbegindrawing(wp->w_win);
1388 return (object *)dp;
1389}
1390
1391static object *
1392window_change(wp, args)
1393 windowobject *wp;
1394 object *args;
1395{
1396 int a[4];
1397 if (!getrectarg(args, a))
1398 return NULL;
1399 wchange(wp->w_win, a[0], a[1], a[2], a[3]);
1400 INCREF(None);
1401 return None;
1402}
1403
1404static object *
1405window_gettitle(wp, args)
1406 windowobject *wp;
1407 object *args;
1408{
1409 if (!getnoarg(args))
1410 return NULL;
1411 INCREF(wp->w_title);
1412 return wp->w_title;
1413}
1414
1415static object *
Guido van Rossum541c8c01991-05-05 20:13:41 +00001416window_getwinpos(wp, args)
1417 windowobject *wp;
1418 object *args;
1419{
1420 int h, v;
1421 if (!getnoarg(args))
1422 return NULL;
1423 wgetwinpos(wp->w_win, &h, &v);
1424 return makepoint(h, v);
1425}
1426
1427static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001428window_getwinsize(wp, args)
1429 windowobject *wp;
1430 object *args;
1431{
1432 int width, height;
1433 if (!getnoarg(args))
1434 return NULL;
1435 wgetwinsize(wp->w_win, &width, &height);
1436 return makepoint(width, height);
1437}
1438
1439static object *
1440window_getdocsize(wp, args)
1441 windowobject *wp;
1442 object *args;
1443{
1444 int width, height;
1445 if (!getnoarg(args))
1446 return NULL;
1447 wgetdocsize(wp->w_win, &width, &height);
1448 return makepoint(width, height);
1449}
1450
1451static object *
1452window_getorigin(wp, args)
1453 windowobject *wp;
1454 object *args;
1455{
1456 int width, height;
1457 if (!getnoarg(args))
1458 return NULL;
1459 wgetorigin(wp->w_win, &width, &height);
1460 return makepoint(width, height);
1461}
1462
1463static object *
1464window_scroll(wp, args)
1465 windowobject *wp;
1466 object *args;
1467{
1468 int a[6];
1469 if (!getrectpointarg(args, a))
1470 return NULL;
1471 wscroll(wp->w_win, a[0], a[1], a[2], a[3], a[4], a[5]);
1472 INCREF(None);
1473 return None;
1474}
1475
1476static object *
1477window_setdocsize(wp, args)
1478 windowobject *wp;
1479 object *args;
1480{
1481 int a[2];
1482 if (!getpointarg(args, a))
1483 return NULL;
1484 wsetdocsize(wp->w_win, a[0], a[1]);
1485 INCREF(None);
1486 return None;
1487}
1488
1489static object *
1490window_setorigin(wp, args)
1491 windowobject *wp;
1492 object *args;
1493{
1494 int a[2];
1495 if (!getpointarg(args, a))
1496 return NULL;
1497 wsetorigin(wp->w_win, a[0], a[1]);
1498 INCREF(None);
1499 return None;
1500}
1501
1502static object *
1503window_settitle(wp, args)
1504 windowobject *wp;
1505 object *args;
1506{
1507 object *title;
1508 if (!getstrarg(args, &title))
1509 return NULL;
1510 DECREF(wp->w_title);
1511 INCREF(title);
1512 wp->w_title = title;
1513 wsettitle(wp->w_win, getstringvalue(title));
1514 INCREF(None);
1515 return None;
1516}
1517
1518static object *
1519window_show(wp, args)
1520 windowobject *wp;
1521 object *args;
1522{
1523 int a[4];
1524 if (!getrectarg(args, a))
1525 return NULL;
1526 wshow(wp->w_win, a[0], a[1], a[2], a[3]);
1527 INCREF(None);
1528 return None;
1529}
1530
1531static object *
1532window_settimer(wp, args)
1533 windowobject *wp;
1534 object *args;
1535{
1536 int a;
1537 if (!getintarg(args, &a))
1538 return NULL;
1539 wsettimer(wp->w_win, a);
1540 INCREF(None);
1541 return None;
1542}
1543
1544static object *
1545window_menucreate(self, args)
1546 windowobject *self;
1547 object *args;
1548{
1549 menuobject *mp;
1550 object *title;
1551 if (!getstrarg(args, &title))
1552 return NULL;
1553 wmenusetdeflocal(1);
1554 mp = newmenuobject(title);
1555 if (mp == NULL)
1556 return NULL;
1557 wmenuattach(self->w_win, mp->m_menu);
1558 return (object *)mp;
1559}
1560
1561static object *
1562window_textcreate(self, args)
1563 windowobject *self;
1564 object *args;
1565{
1566 textobject *tp;
1567 int a[4];
1568 if (!getrectarg(args, a))
1569 return NULL;
1570 return (object *)
1571 newtextobject(self, a[0], a[1], a[2], a[3]);
1572}
1573
Guido van Rossum5b10f451990-10-30 16:01:48 +00001574static object *
1575window_setselection(self, args)
1576 windowobject *self;
1577 object *args;
1578{
1579 int sel;
1580 object *str;
1581 int ok;
1582 if (!getintstrarg(args, &sel, &str))
1583 return NULL;
1584 ok = wsetselection(self->w_win, sel,
1585 getstringvalue(str), (int)getstringsize(str));
1586 return newintobject(ok);
1587}
1588
1589static object *
1590window_setwincursor(self, args)
1591 windowobject *self;
1592 object *args;
1593{
1594 object *str;
1595 CURSOR *c;
1596 if (!getstrarg(args, &str))
1597 return NULL;
1598 c = wfetchcursor(getstringvalue(str));
1599 if (c == NULL) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +00001600 err_setstr(StdwinError, "no such cursor");
Guido van Rossum5b10f451990-10-30 16:01:48 +00001601 return NULL;
1602 }
1603 wsetwincursor(self->w_win, c);
1604 INCREF(None);
1605 return None;
1606}
1607
Guido van Rossum8dcbbac1991-07-27 21:42:24 +00001608#ifdef CWI_HACKS
1609static object *
1610window_getxwindowid(self, args)
1611 windowobject *self;
1612 object *args;
1613{
1614 long wid = wgetxwindowid(self->w_win);
1615 return newintobject(wid);
1616}
1617#endif
1618
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001619static struct methodlist window_methods[] = {
1620 {"begindrawing",window_begindrawing},
1621 {"change", window_change},
Guido van Rossum3c284741991-11-27 14:54:54 +00001622 {"close", window_close},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001623 {"getdocsize", window_getdocsize},
1624 {"getorigin", window_getorigin},
1625 {"gettitle", window_gettitle},
Guido van Rossum541c8c01991-05-05 20:13:41 +00001626 {"getwinpos", window_getwinpos},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001627 {"getwinsize", window_getwinsize},
1628 {"menucreate", window_menucreate},
1629 {"scroll", window_scroll},
1630 {"setdocsize", window_setdocsize},
1631 {"setorigin", window_setorigin},
Guido van Rossum5b10f451990-10-30 16:01:48 +00001632 {"setselection",window_setselection},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001633 {"settimer", window_settimer},
1634 {"settitle", window_settitle},
Guido van Rossum27201061991-04-16 08:43:03 +00001635 {"setwincursor",window_setwincursor},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001636 {"show", window_show},
1637 {"textcreate", window_textcreate},
Guido van Rossum8dcbbac1991-07-27 21:42:24 +00001638#ifdef CWI_HACKS
1639 {"getxwindowid",window_getxwindowid},
1640#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001641 {NULL, NULL} /* sentinel */
1642};
1643
1644static object *
1645window_getattr(wp, name)
1646 windowobject *wp;
1647 char *name;
1648{
Guido van Rossum85f50761991-10-20 20:22:50 +00001649 object *v = NULL;
1650 if (strcmp(name, "__dict__") == 0) {
1651 v = wp->w_attr;
1652 if (v == NULL)
1653 v = None;
1654 }
1655 else if (wp->w_attr != NULL) {
1656 v = dictlookup(wp->w_attr, name);
1657 }
1658 if (v != NULL) {
1659 INCREF(v);
1660 return v;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001661 }
1662 return findmethod(window_methods, (object *)wp, name);
1663}
1664
1665static int
1666window_setattr(wp, name, v)
1667 windowobject *wp;
1668 char *name;
1669 object *v;
1670{
1671 if (wp->w_attr == NULL) {
1672 wp->w_attr = newdictobject();
1673 if (wp->w_attr == NULL)
1674 return -1;
1675 }
1676 if (v == NULL)
1677 return dictremove(wp->w_attr, name);
1678 else
1679 return dictinsert(wp->w_attr, name, v);
1680}
1681
Guido van Rossum541c8c01991-05-05 20:13:41 +00001682typeobject Windowtype = {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001683 OB_HEAD_INIT(&Typetype)
1684 0, /*ob_size*/
1685 "window", /*tp_name*/
1686 sizeof(windowobject), /*tp_size*/
1687 0, /*tp_itemsize*/
1688 /* methods */
1689 window_dealloc, /*tp_dealloc*/
1690 window_print, /*tp_print*/
1691 window_getattr, /*tp_getattr*/
1692 window_setattr, /*tp_setattr*/
1693 0, /*tp_compare*/
1694 0, /*tp_repr*/
1695};
1696
1697/* Stdwin methods */
1698
1699static object *
1700stdwin_open(sw, args)
1701 object *sw;
1702 object *args;
1703{
1704 int tag;
1705 object *title;
1706 windowobject *wp;
1707 if (!getstrarg(args, &title))
1708 return NULL;
1709 for (tag = 0; tag < MAXNWIN; tag++) {
1710 if (windowlist[tag] == NULL)
1711 break;
1712 }
Guido van Rossum27201061991-04-16 08:43:03 +00001713 if (tag >= MAXNWIN) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +00001714 err_setstr(StdwinError, "creating too many windows");
Guido van Rossum27201061991-04-16 08:43:03 +00001715 return NULL;
1716 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001717 wp = NEWOBJ(windowobject, &Windowtype);
1718 if (wp == NULL)
1719 return NULL;
1720 INCREF(title);
1721 wp->w_title = title;
1722 wp->w_win = wopen(getstringvalue(title), (void (*)()) NULL);
1723 wp->w_attr = NULL;
1724 if (wp->w_win == NULL) {
1725 DECREF(wp);
1726 return NULL;
1727 }
1728 windowlist[tag] = wp;
1729 wsettag(wp->w_win, tag);
1730 return (object *)wp;
1731}
1732
1733static object *
Guido van Rossum246b9d81991-06-03 10:55:14 +00001734window2object(win)
1735 WINDOW *win;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001736{
Guido van Rossum246b9d81991-06-03 10:55:14 +00001737 object *w;
1738 if (win == NULL)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001739 w = None;
1740 else {
Guido van Rossum246b9d81991-06-03 10:55:14 +00001741 int tag = wgettag(win);
1742 if (tag < 0 || tag >= MAXNWIN || windowlist[tag] == NULL ||
1743 windowlist[tag]->w_win != win)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001744 w = None;
1745 else
1746 w = (object *)windowlist[tag];
Guido van Rossume8e7cf41991-01-16 14:06:18 +00001747#ifdef sgi
1748 /* XXX Trap for unexplained weird bug */
1749 if ((long)w == (long)0x80000001) {
1750 err_setstr(SystemError,
1751 "bad pointer in stdwin.getevent()");
1752 return NULL;
1753 }
1754#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001755 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001756 INCREF(w);
Guido van Rossum246b9d81991-06-03 10:55:14 +00001757 return w;
1758}
1759
1760static object *
1761stdwin_get_poll_event(poll, args)
1762 int poll;
1763 object *args;
1764{
1765 EVENT e;
1766 object *v, *w;
1767 if (!getnoarg(args))
1768 return NULL;
1769 if (Drawing != NULL) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +00001770 err_setstr(StdwinError, "cannot getevent() while drawing");
Guido van Rossum246b9d81991-06-03 10:55:14 +00001771 return NULL;
1772 }
1773 again:
1774 if (poll) {
1775 if (!wpollevent(&e)) {
1776 INCREF(None);
1777 return None;
1778 }
1779 }
1780 else
1781 wgetevent(&e);
1782 if (e.type == WE_COMMAND && e.u.command == WC_CANCEL) {
1783 /* Turn keyboard interrupts into exceptions */
1784 err_set(KeyboardInterrupt);
1785 return NULL;
1786 }
1787 if (e.type == WE_COMMAND && e.u.command == WC_CLOSE) {
1788 /* Turn WC_CLOSE commands into WE_CLOSE events */
1789 e.type = WE_CLOSE;
1790 }
1791 v = newtupleobject(3);
1792 if (v == NULL)
1793 return NULL;
1794 if ((w = newintobject((long)e.type)) == NULL) {
1795 DECREF(v);
1796 return NULL;
1797 }
1798 settupleitem(v, 0, w);
1799 settupleitem(v, 1, window2object(e.window));
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001800 switch (e.type) {
1801 case WE_CHAR:
1802 {
1803 char c[1];
1804 c[0] = e.u.character;
1805 w = newsizedstringobject(c, 1);
1806 }
1807 break;
1808 case WE_COMMAND:
1809 w = newintobject((long)e.u.command);
1810 break;
1811 case WE_DRAW:
1812 w = makerect(e.u.area.left, e.u.area.top,
1813 e.u.area.right, e.u.area.bottom);
1814 break;
1815 case WE_MOUSE_DOWN:
1816 case WE_MOUSE_MOVE:
1817 case WE_MOUSE_UP:
1818 w = makemouse(e.u.where.h, e.u.where.v,
1819 e.u.where.clicks,
1820 e.u.where.button,
1821 e.u.where.mask);
1822 break;
1823 case WE_MENU:
Guido van Rossum2d14e211991-02-19 12:26:49 +00001824 if (e.u.m.id >= IDOFFSET && e.u.m.id < IDOFFSET+MAXNMENU &&
1825 menulist[e.u.m.id - IDOFFSET] != NULL)
1826 w = (object *)menulist[e.u.m.id - IDOFFSET];
Guido van Rossum246b9d81991-06-03 10:55:14 +00001827 else {
1828 /* Ghost menu event.
1829 Can occur only on the Mac if another part
1830 of the aplication has installed a menu;
1831 like the THINK C console library. */
1832 DECREF(v);
1833 goto again;
1834 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001835 w = makemenu(w, e.u.m.item);
1836 break;
Guido van Rossum5b10f451990-10-30 16:01:48 +00001837 case WE_LOST_SEL:
1838 w = newintobject((long)e.u.sel);
1839 break;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001840 default:
1841 w = None;
1842 INCREF(w);
1843 break;
1844 }
1845 if (w == NULL) {
1846 DECREF(v);
1847 return NULL;
1848 }
1849 settupleitem(v, 2, w);
1850 return v;
1851}
1852
1853static object *
Guido van Rossume8e7cf41991-01-16 14:06:18 +00001854stdwin_getevent(sw, args)
1855 object *sw;
1856 object *args;
1857{
1858 return stdwin_get_poll_event(0, args);
1859}
1860
1861static object *
1862stdwin_pollevent(sw, args)
1863 object *sw;
1864 object *args;
1865{
1866 return stdwin_get_poll_event(1, args);
1867}
1868
1869static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001870stdwin_setdefwinpos(sw, args)
1871 object *sw;
1872 object *args;
1873{
1874 int a[2];
1875 if (!getpointarg(args, a))
1876 return NULL;
1877 wsetdefwinpos(a[0], a[1]);
1878 INCREF(None);
1879 return None;
1880}
1881
1882static object *
1883stdwin_setdefwinsize(sw, args)
1884 object *sw;
1885 object *args;
1886{
1887 int a[2];
1888 if (!getpointarg(args, a))
1889 return NULL;
1890 wsetdefwinsize(a[0], a[1]);
1891 INCREF(None);
1892 return None;
1893}
1894
1895static object *
Guido van Rossum0c2290b1991-04-03 19:12:14 +00001896stdwin_setdefscrollbars(sw, args)
1897 object *sw;
1898 object *args;
1899{
1900 int a[2];
1901 if (!getpointarg(args, a))
1902 return NULL;
1903 wsetdefscrollbars(a[0], a[1]);
1904 INCREF(None);
1905 return None;
1906}
1907
1908static object *
Guido van Rossum541c8c01991-05-05 20:13:41 +00001909stdwin_getdefwinpos(self, args)
1910 object *self;
Guido van Rossum33f17701991-02-13 23:19:39 +00001911 object *args;
1912{
1913 int h, v;
1914 if (!getnoarg(args))
1915 return NULL;
1916 wgetdefwinpos(&h, &v);
1917 return makepoint(h, v);
1918}
1919
1920static object *
Guido van Rossum541c8c01991-05-05 20:13:41 +00001921stdwin_getdefwinsize(self, args)
1922 object *self;
Guido van Rossum33f17701991-02-13 23:19:39 +00001923 object *args;
1924{
1925 int width, height;
1926 if (!getnoarg(args))
1927 return NULL;
1928 wgetdefwinsize(&width, &height);
1929 return makepoint(width, height);
1930}
1931
1932static object *
Guido van Rossum541c8c01991-05-05 20:13:41 +00001933stdwin_getdefscrollbars(self, args)
1934 object *self;
Guido van Rossum0c2290b1991-04-03 19:12:14 +00001935 object *args;
1936{
1937 int h, v;
1938 if (!getnoarg(args))
1939 return NULL;
1940 wgetdefscrollbars(&h, &v);
1941 return makepoint(h, v);
1942}
1943
1944static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001945stdwin_menucreate(self, args)
1946 object *self;
1947 object *args;
1948{
1949 object *title;
1950 if (!getstrarg(args, &title))
1951 return NULL;
1952 wmenusetdeflocal(0);
1953 return (object *)newmenuobject(title);
1954}
1955
1956static object *
1957stdwin_askfile(self, args)
1958 object *self;
1959 object *args;
1960{
1961 object *prompt, *dflt;
1962 int new, ret;
1963 char buf[256];
1964 if (!getstrstrintarg(args, &prompt, &dflt, &new))
1965 return NULL;
1966 strncpy(buf, getstringvalue(dflt), sizeof buf);
1967 buf[sizeof buf - 1] = '\0';
1968 ret = waskfile(getstringvalue(prompt), buf, sizeof buf, new);
1969 if (!ret) {
1970 err_set(KeyboardInterrupt);
1971 return NULL;
1972 }
1973 return newstringobject(buf);
1974}
1975
1976static object *
1977stdwin_askync(self, args)
1978 object *self;
1979 object *args;
1980{
1981 object *prompt;
1982 int new, ret;
1983 if (!getstrintarg(args, &prompt, &new))
1984 return NULL;
1985 ret = waskync(getstringvalue(prompt), new);
1986 if (ret < 0) {
1987 err_set(KeyboardInterrupt);
1988 return NULL;
1989 }
1990 return newintobject((long)ret);
1991}
1992
1993static object *
1994stdwin_askstr(self, args)
1995 object *self;
1996 object *args;
1997{
1998 object *prompt, *dflt;
1999 int ret;
2000 char buf[256];
2001 if (!getstrstrarg(args, &prompt, &dflt))
2002 return NULL;
2003 strncpy(buf, getstringvalue(dflt), sizeof buf);
2004 buf[sizeof buf - 1] = '\0';
2005 ret = waskstr(getstringvalue(prompt), buf, sizeof buf);
2006 if (!ret) {
2007 err_set(KeyboardInterrupt);
2008 return NULL;
2009 }
2010 return newstringobject(buf);
2011}
2012
2013static object *
2014stdwin_message(self, args)
2015 object *self;
2016 object *args;
2017{
2018 object *msg;
2019 if (!getstrarg(args, &msg))
2020 return NULL;
2021 wmessage(getstringvalue(msg));
2022 INCREF(None);
2023 return None;
2024}
2025
2026static object *
2027stdwin_fleep(self, args)
2028 object *self;
2029 object *args;
2030{
2031 if (!getnoarg(args))
2032 return NULL;
2033 wfleep();
2034 INCREF(None);
2035 return None;
2036}
2037
2038static object *
2039stdwin_setcutbuffer(self, args)
2040 object *self;
2041 object *args;
2042{
Guido van Rossum5b10f451990-10-30 16:01:48 +00002043 int i;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002044 object *str;
Guido van Rossum124967c1990-11-06 15:17:35 +00002045 if (!getintstrarg(args, &i, &str))
2046 return NULL;
Guido van Rossum5b10f451990-10-30 16:01:48 +00002047 wsetcutbuffer(i, getstringvalue(str), getstringsize(str));
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002048 INCREF(None);
2049 return None;
2050}
2051
2052static object *
Guido van Rossum246b9d81991-06-03 10:55:14 +00002053stdwin_getactive(self, args)
2054 object *self;
2055 object *args;
2056{
2057 return window2object(wgetactive());
2058}
2059
2060static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002061stdwin_getcutbuffer(self, args)
2062 object *self;
2063 object *args;
2064{
Guido van Rossum5b10f451990-10-30 16:01:48 +00002065 int i;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002066 char *str;
Guido van Rossum01769f01990-10-30 13:39:00 +00002067 int len;
Guido van Rossum124967c1990-11-06 15:17:35 +00002068 if (!getintarg(args, &i))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002069 return NULL;
Guido van Rossum5b10f451990-10-30 16:01:48 +00002070 str = wgetcutbuffer(i, &len);
Guido van Rossum01769f01990-10-30 13:39:00 +00002071 if (str == NULL) {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002072 str = "";
Guido van Rossum01769f01990-10-30 13:39:00 +00002073 len = 0;
2074 }
2075 return newsizedstringobject(str, len);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002076}
2077
Guido van Rossum5b10f451990-10-30 16:01:48 +00002078static object *
2079stdwin_rotatecutbuffers(self, args)
2080 object *self;
2081 object *args;
2082{
2083 int i;
2084 if (!getintarg(args, &i))
2085 return NULL;
2086 wrotatecutbuffers(i);
2087 INCREF(None);
2088 return None;
2089}
2090
2091static object *
2092stdwin_getselection(self, args)
2093 object *self;
2094 object *args;
2095{
2096 int sel;
2097 char *data;
2098 int len;
2099 if (!getintarg(args, &sel))
2100 return NULL;
2101 data = wgetselection(sel, &len);
2102 if (data == NULL) {
2103 data = "";
2104 len = 0;
2105 }
2106 return newsizedstringobject(data, len);
2107}
2108
2109static object *
2110stdwin_resetselection(self, args)
2111 object *self;
2112 object *args;
2113{
2114 int sel;
2115 if (!getintarg(args, &sel))
2116 return NULL;
2117 wresetselection(sel);
2118 INCREF(None);
2119 return None;
2120}
2121
Guido van Rossum0c2290b1991-04-03 19:12:14 +00002122static object *
2123stdwin_fetchcolor(self, args)
2124 object *self;
2125 object *args;
2126{
2127 object *colorname;
2128 if (!getstrarg(args, &colorname))
2129 return NULL;
2130 return newintobject((long)wfetchcolor(getstringvalue(colorname)));
2131}
2132
Guido van Rossum541c8c01991-05-05 20:13:41 +00002133static object *
2134stdwin_getscrsize(self, args)
2135 object *self;
2136 object *args;
2137{
2138 int width, height;
2139 if (!getnoarg(args))
2140 return NULL;
2141 wgetscrsize(&width, &height);
2142 return makepoint(width, height);
2143}
2144
2145static object *
2146stdwin_getscrmm(self, args)
2147 object *self;
2148 object *args;
2149{
2150 int width, height;
2151 if (!getnoarg(args))
2152 return NULL;
2153 wgetscrmm(&width, &height);
2154 return makepoint(width, height);
2155}
2156
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002157static struct methodlist stdwin_methods[] = {
2158 {"askfile", stdwin_askfile},
2159 {"askstr", stdwin_askstr},
2160 {"askync", stdwin_askync},
Guido van Rossum27201061991-04-16 08:43:03 +00002161 {"fetchcolor", stdwin_fetchcolor},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002162 {"fleep", stdwin_fleep},
Guido van Rossum246b9d81991-06-03 10:55:14 +00002163 {"getactive", stdwin_getactive},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002164 {"getcutbuffer", stdwin_getcutbuffer},
Guido van Rossum0c2290b1991-04-03 19:12:14 +00002165 {"getdefscrollbars", stdwin_getdefscrollbars},
Guido van Rossum33f17701991-02-13 23:19:39 +00002166 {"getdefwinpos", stdwin_getdefwinpos},
2167 {"getdefwinsize", stdwin_getdefwinsize},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002168 {"getevent", stdwin_getevent},
Guido van Rossum541c8c01991-05-05 20:13:41 +00002169 {"getscrmm", stdwin_getscrmm},
2170 {"getscrsize", stdwin_getscrsize},
Guido van Rossum27201061991-04-16 08:43:03 +00002171 {"getselection", stdwin_getselection},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002172 {"menucreate", stdwin_menucreate},
2173 {"message", stdwin_message},
2174 {"open", stdwin_open},
Guido van Rossume8e7cf41991-01-16 14:06:18 +00002175 {"pollevent", stdwin_pollevent},
Guido van Rossum5b10f451990-10-30 16:01:48 +00002176 {"resetselection", stdwin_resetselection},
2177 {"rotatecutbuffers", stdwin_rotatecutbuffers},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002178 {"setcutbuffer", stdwin_setcutbuffer},
Guido van Rossum0c2290b1991-04-03 19:12:14 +00002179 {"setdefscrollbars", stdwin_setdefscrollbars},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002180 {"setdefwinpos", stdwin_setdefwinpos},
2181 {"setdefwinsize", stdwin_setdefwinsize},
2182
2183 /* Text measuring methods borrow code from drawing objects: */
2184 {"baseline", drawing_baseline},
2185 {"lineheight", drawing_lineheight},
2186 {"textbreak", drawing_textbreak},
2187 {"textwidth", drawing_textwidth},
Guido van Rossum0c2290b1991-04-03 19:12:14 +00002188
2189 /* Same for font setting methods: */
2190 {"setfont", drawing_setfont},
2191
2192 /* Same for color setting/getting methods: */
2193 {"getbgcolor", drawing_getbgcolor},
2194 {"getfgcolor", drawing_getfgcolor},
2195 {"setbgcolor", drawing_setbgcolor},
2196 {"setfgcolor", drawing_setfgcolor},
2197
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002198 {NULL, NULL} /* sentinel */
2199};
2200
2201void
2202initstdwin()
2203{
Guido van Rossum2d14e211991-02-19 12:26:49 +00002204 static int inited;
2205 if (!inited) {
2206 winit();
2207 inited = 1;
2208 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002209 initmodule("stdwin", stdwin_methods);
2210}