blob: a6f6fba9bdd418dbe3e218ea449369cbf513aa2b [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
Guido van Rossum0b0db8e1993-01-21 16:07:51 +00002Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
3Amsterdam, The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00004
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
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
Guido van Rossumbf80e541993-02-08 15:49:17 +000033 bp: a bitmap
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000034*/
35
36/* Rules for translating C stdwin function calls into Python stwin:
37 - All names drop their initial letter 'w'
38 - Functions with a window as first parameter are methods of window objects
39 - There is no equivalent for wclose(); just delete the window object
40 (all references to it!) (XXX maybe this is a bad idea)
41 - w.begindrawing() returns a drawing object
42 - There is no equivalent for wenddrawing(win); just delete the drawing
43 object (all references to it!) (XXX maybe this is a bad idea)
44 - Functions that may only be used inside wbegindrawing / wendddrawing
45 are methods of the drawing object; this includes the text measurement
46 functions (which however have doubles as module functions).
47 - Methods of the drawing object drop an initial 'draw' from their name
48 if they have it, e.g., wdrawline() --> d.line()
49 - The obvious type conversions: int --> intobject; string --> stringobject
50 - A text parameter followed by a length parameter is only a text (string)
51 parameter in Python
52 - A point or other pair of horizontal and vertical coordinates is always
53 a pair of integers in Python
54 - Two points forming a rectangle or endpoints of a line segment are a
55 pair of points in Python
56 - The arguments to d.elarc() are three points.
57 - The functions wgetclip() and wsetclip() are translated into
58 stdwin.getcutbuffer() and stdwin.setcutbuffer(); 'clip' is really
59 a bad word for what these functions do (clipping has a different
60 meaning in the drawing world), while cutbuffer is standard X jargon.
Guido van Rossum01769f01990-10-30 13:39:00 +000061 XXX This must change again in the light of changes to stdwin!
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000062 - For textedit, similar rules hold, but they are less strict.
63 XXX more?
64*/
65
Guido van Rossum3f5da241990-12-20 15:06:42 +000066#include "allobjects.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000067#include "modsupport.h"
Guido van Rossumff4949e1992-08-05 19:58:53 +000068#include "ceval.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000069
Guido van Rossum0b0db8e1993-01-21 16:07:51 +000070#ifdef macintosh
Guido van Rossume9066061993-07-29 13:14:32 +000071#include ":::stdwin:H:stdwin.h"
Guido van Rossum0b0db8e1993-01-21 16:07:51 +000072#else /* !macintosh */
Guido van Rossum3f5da241990-12-20 15:06:42 +000073#include "stdwin.h"
Guido van Rossume9066061993-07-29 13:14:32 +000074#define HAVE_BITMAPS
Guido van Rossum0b0db8e1993-01-21 16:07:51 +000075#endif /* !macintosh */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000076
Guido van Rossumff4949e1992-08-05 19:58:53 +000077#ifdef USE_THREAD
78
79#include "thread.h"
80
81static type_lock StdwinLock; /* Lock held when interpreter not locked */
82
83#define BGN_STDWIN BGN_SAVE acquire_lock(StdwinLock, 1);
84#define RET_STDWIN release_lock(StdwinLock); RET_SAVE
85#define END_STDWIN release_lock(StdwinLock); END_SAVE
86
87#else
88
89#define BGN_STDWIN BGN_SAVE
90#define RET_STDWIN RET_SAVE
91#define END_STDWIN END_SAVE
92
93#endif
94
Guido van Rossum234f9421993-06-17 12:35:49 +000095#define getpointarg(v, a) getargs(v, "(ii)", a, (a)+1)
96#define get3pointarg(v, a) getargs(v, "((ii)(ii)(ii))", \
97 a, a+1, a+2, a+3, a+4, a+5)
98#define getrectarg(v, a) getargs(v, "((ii)(ii))", a, a+1, a+2, a+3)
99#define getrectintarg(v, a) getargs(v, "(((ii)(ii))i)", a, a+1, a+2, a+3, a+4)
100#define getpointintarg(v, a) getargs(v, "((ii)i)", a, a+1, a+2)
101#define getrectpointarg(v, a) getargs(v, "(((ii)(ii))(ii))", \
102 a, a+1, a+2, a+3, a+4, a+5)
103
Guido van Rossumbbf94341991-12-16 15:44:53 +0000104static object *StdwinError; /* Exception stdwin.error */
Guido van Rossum87e7ea71991-12-10 14:00:03 +0000105
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000106/* Window and menu object types declared here because of forward references */
107
108typedef struct {
109 OB_HEAD
110 object *w_title;
111 WINDOW *w_win;
112 object *w_attr; /* Attributes dictionary */
113} windowobject;
114
115extern typeobject Windowtype; /* Really static, forward */
116
117#define is_windowobject(wp) ((wp)->ob_type == &Windowtype)
118
119typedef struct {
120 OB_HEAD
121 MENU *m_menu;
122 int m_id;
123 object *m_attr; /* Attributes dictionary */
124} menuobject;
125
126extern typeobject Menutype; /* Really static, forward */
127
128#define is_menuobject(mp) ((mp)->ob_type == &Menutype)
129
Guido van Rossumbf80e541993-02-08 15:49:17 +0000130typedef struct {
131 OB_HEAD
132 BITMAP *b_bitmap;
133 object *b_attr; /* Attributes dictionary */
134} bitmapobject;
135
136extern typeobject Bitmaptype; /* Really static, forward */
137
138#define is_bitmapobject(mp) ((mp)->ob_type == &Bitmaptype)
139
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000140
141/* Strongly stdwin-specific argument handlers */
142
143static int
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000144getmenudetail(v, ep)
145 object *v;
146 EVENT *ep;
147{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000148 menuobject *mp;
149 if (!getargs(v, "(Oi)", &mp, &ep->u.m.item))
150 return 0;
151 if (!is_menuobject(mp))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000152 return err_badarg();
Guido van Rossumfc58e581992-01-27 16:45:55 +0000153 ep->u.m.id = mp->m_id;
154 return 1;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000155}
156
157static int
158geteventarg(v, ep)
159 object *v;
160 EVENT *ep;
161{
162 object *wp, *detail;
163 int a[4];
Guido van Rossumfc58e581992-01-27 16:45:55 +0000164 if (!getargs(v, "(iOO)", &ep->type, &wp, &detail))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000165 return 0;
Guido van Rossumfc58e581992-01-27 16:45:55 +0000166 if (is_windowobject(wp))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000167 ep->window = ((windowobject *)wp) -> w_win;
Guido van Rossumfc58e581992-01-27 16:45:55 +0000168 else if (wp == None)
169 ep->window = NULL;
170 else
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000171 return err_badarg();
Guido van Rossumfc58e581992-01-27 16:45:55 +0000172 switch (ep->type) {
173 case WE_CHAR: {
174 char c;
175 if (!getargs(detail, "c", &c))
176 return 0;
177 ep->u.character = c;
178 return 1;
179 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000180 case WE_COMMAND:
181 return getintarg(detail, &ep->u.command);
182 case WE_DRAW:
183 if (!getrectarg(detail, a))
184 return 0;
185 ep->u.area.left = a[0];
186 ep->u.area.top = a[1];
187 ep->u.area.right = a[2];
188 ep->u.area.bottom = a[3];
189 return 1;
190 case WE_MOUSE_DOWN:
191 case WE_MOUSE_UP:
192 case WE_MOUSE_MOVE:
Guido van Rossumfc58e581992-01-27 16:45:55 +0000193 return getargs(detail, "((ii)iii)",
194 &ep->u.where.h, &ep->u.where.v,
195 &ep->u.where.clicks,
196 &ep->u.where.button,
197 &ep->u.where.mask);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000198 case WE_MENU:
199 return getmenudetail(detail, ep);
Guido van Rossum3ee199e1992-06-30 12:48:26 +0000200 case WE_KEY:
201 return getargs(detail, "(ii)",
202 &ep->u.key.code, &ep->u.key.mask);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000203 default:
204 return 1;
205 }
206}
207
208
209/* Return construction tools */
210
211static object *
212makepoint(a, b)
213 int a, b;
214{
Guido van Rossum2ee12f41992-04-13 15:54:35 +0000215 return mkvalue("(ii)", a, b);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000216}
217
218static object *
219makerect(a, b, c, d)
220 int a, b, c, d;
221{
Guido van Rossum2ee12f41992-04-13 15:54:35 +0000222 return mkvalue("((ii)(ii))", a, b, c, d);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000223}
224
225
226/* Drawing objects */
227
228typedef struct {
229 OB_HEAD
230 windowobject *d_ref;
231} drawingobject;
232
233static drawingobject *Drawing; /* Set to current drawing object, or NULL */
234
235/* Drawing methods */
236
Guido van Rossum3c284741991-11-27 14:54:54 +0000237static object *
238drawing_close(dp)
239 drawingobject *dp;
240{
241 if (dp->d_ref != NULL) {
242 wenddrawing(dp->d_ref->w_win);
243 Drawing = NULL;
244 DECREF(dp->d_ref);
245 dp->d_ref = NULL;
246 }
247 INCREF(None);
248 return None;
249}
Guido van Rossum77b46041992-01-14 18:41:24 +0000250
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000251static void
252drawing_dealloc(dp)
253 drawingobject *dp;
254{
Guido van Rossum3c284741991-11-27 14:54:54 +0000255 if (dp->d_ref != NULL) {
256 wenddrawing(dp->d_ref->w_win);
257 Drawing = NULL;
258 DECREF(dp->d_ref);
259 dp->d_ref = NULL;
260 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000261 free((char *)dp);
262}
263
264static object *
265drawing_generic(dp, args, func)
266 drawingobject *dp;
267 object *args;
268 void (*func) FPROTO((int, int, int, int));
269{
270 int a[4];
271 if (!getrectarg(args, a))
272 return NULL;
273 (*func)(a[0], a[1], a[2], a[3]);
274 INCREF(None);
275 return None;
276}
277
278static object *
279drawing_line(dp, args)
280 drawingobject *dp;
281 object *args;
282{
Guido van Rossumbf109731991-03-06 13:14:12 +0000283 return drawing_generic(dp, args, wdrawline);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000284}
285
286static object *
287drawing_xorline(dp, args)
288 drawingobject *dp;
289 object *args;
290{
Guido van Rossumbf109731991-03-06 13:14:12 +0000291 return drawing_generic(dp, args, wxorline);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000292}
293
294static object *
295drawing_circle(dp, args)
296 drawingobject *dp;
297 object *args;
298{
299 int a[3];
300 if (!getpointintarg(args, a))
301 return NULL;
302 wdrawcircle(a[0], a[1], a[2]);
303 INCREF(None);
304 return None;
305}
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000306
Guido van Rossum27201061991-04-16 08:43:03 +0000307static object *
308drawing_fillcircle(dp, args)
309 drawingobject *dp;
310 object *args;
311{
312 int a[3];
313 if (!getpointintarg(args, a))
314 return NULL;
315 wfillcircle(a[0], a[1], a[2]);
316 INCREF(None);
317 return None;
318}
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000319
320static object *
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000321drawing_xorcircle(dp, args)
322 drawingobject *dp;
323 object *args;
324{
325 int a[3];
326 if (!getpointintarg(args, a))
327 return NULL;
328 wxorcircle(a[0], a[1], a[2]);
329 INCREF(None);
330 return None;
331}
332
333static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000334drawing_elarc(dp, args)
335 drawingobject *dp;
336 object *args;
337{
338 int a[6];
339 if (!get3pointarg(args, a))
340 return NULL;
341 wdrawelarc(a[0], a[1], a[2], a[3], a[4], a[5]);
342 INCREF(None);
343 return None;
344}
345
346static object *
Guido van Rossum27201061991-04-16 08:43:03 +0000347drawing_fillelarc(dp, args)
348 drawingobject *dp;
349 object *args;
350{
351 int a[6];
352 if (!get3pointarg(args, a))
353 return NULL;
354 wfillelarc(a[0], a[1], a[2], a[3], a[4], a[5]);
355 INCREF(None);
356 return None;
357}
358
359static object *
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000360drawing_xorelarc(dp, args)
361 drawingobject *dp;
362 object *args;
363{
364 int a[6];
365 if (!get3pointarg(args, a))
366 return NULL;
367 wxorelarc(a[0], a[1], a[2], a[3], a[4], a[5]);
368 INCREF(None);
369 return None;
370}
371
372static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000373drawing_box(dp, args)
374 drawingobject *dp;
375 object *args;
376{
Guido van Rossumbf109731991-03-06 13:14:12 +0000377 return drawing_generic(dp, args, wdrawbox);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000378}
379
380static object *
381drawing_erase(dp, args)
382 drawingobject *dp;
383 object *args;
384{
Guido van Rossumbf109731991-03-06 13:14:12 +0000385 return drawing_generic(dp, args, werase);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000386}
387
388static object *
389drawing_paint(dp, args)
390 drawingobject *dp;
391 object *args;
392{
Guido van Rossumbf109731991-03-06 13:14:12 +0000393 return drawing_generic(dp, args, wpaint);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000394}
395
396static object *
397drawing_invert(dp, args)
398 drawingobject *dp;
399 object *args;
400{
Guido van Rossumbf109731991-03-06 13:14:12 +0000401 return drawing_generic(dp, args, winvert);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000402}
403
Guido van Rossum27201061991-04-16 08:43:03 +0000404static POINT *
405getpointsarray(v, psize)
406 object *v;
407 int *psize;
408{
409 int n = -1;
410 object * (*getitem) PROTO((object *, int));
411 int i;
412 POINT *points;
413
414 if (v == NULL)
415 ;
416 else if (is_listobject(v)) {
417 n = getlistsize(v);
418 getitem = getlistitem;
419 }
420 else if (is_tupleobject(v)) {
421 n = gettuplesize(v);
422 getitem = gettupleitem;
423 }
424
425 if (n <= 0) {
426 (void) err_badarg();
427 return NULL;
428 }
429
430 points = NEW(POINT, n);
431 if (points == NULL) {
432 (void) err_nomem();
433 return NULL;
434 }
435
436 for (i = 0; i < n; i++) {
437 object *w = (*getitem)(v, i);
438 int a[2];
439 if (!getpointarg(w, a)) {
440 DEL(points);
441 return NULL;
442 }
443 points[i].h = a[0];
444 points[i].v = a[1];
445 }
446
447 *psize = n;
448 return points;
449}
450
451static object *
452drawing_poly(dp, args)
453 drawingobject *dp;
454 object *args;
455{
456 int n;
457 POINT *points = getpointsarray(args, &n);
458 if (points == NULL)
459 return NULL;
460 wdrawpoly(n, points);
461 DEL(points);
462 INCREF(None);
463 return None;
464}
465
466static object *
467drawing_fillpoly(dp, args)
468 drawingobject *dp;
469 object *args;
470{
471 int n;
472 POINT *points = getpointsarray(args, &n);
473 if (points == NULL)
474 return NULL;
475 wfillpoly(n, points);
476 DEL(points);
477 INCREF(None);
478 return None;
479}
480
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000481static object *
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000482drawing_xorpoly(dp, args)
483 drawingobject *dp;
484 object *args;
485{
486 int n;
487 POINT *points = getpointsarray(args, &n);
488 if (points == NULL)
489 return NULL;
490 wxorpoly(n, points);
491 DEL(points);
492 INCREF(None);
493 return None;
494}
495
496static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000497drawing_cliprect(dp, args)
498 drawingobject *dp;
499 object *args;
500{
Guido van Rossumbf109731991-03-06 13:14:12 +0000501 return drawing_generic(dp, args, wcliprect);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000502}
503
504static object *
505drawing_noclip(dp, args)
506 drawingobject *dp;
507 object *args;
508{
509 if (!getnoarg(args))
510 return NULL;
511 wnoclip();
512 INCREF(None);
513 return None;
514}
515
516static object *
517drawing_shade(dp, args)
518 drawingobject *dp;
519 object *args;
520{
521 int a[5];
522 if (!getrectintarg(args, a))
523 return NULL;
524 wshade(a[0], a[1], a[2], a[3], a[4]);
525 INCREF(None);
526 return None;
527}
528
529static object *
530drawing_text(dp, args)
531 drawingobject *dp;
532 object *args;
533{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000534 int h, v, size;
535 char *text;
536 if (!getargs(args, "((ii)s#)", &h, &v, &text, &size))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000537 return NULL;
Guido van Rossumfc58e581992-01-27 16:45:55 +0000538 wdrawtext(h, v, text, size);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000539 INCREF(None);
540 return None;
541}
542
543/* The following four are also used as stdwin functions */
544
545static object *
546drawing_lineheight(dp, args)
547 drawingobject *dp;
548 object *args;
549{
550 if (!getnoarg(args))
551 return NULL;
552 return newintobject((long)wlineheight());
553}
554
555static object *
556drawing_baseline(dp, args)
557 drawingobject *dp;
558 object *args;
559{
560 if (!getnoarg(args))
561 return NULL;
562 return newintobject((long)wbaseline());
563}
564
565static object *
566drawing_textwidth(dp, args)
567 drawingobject *dp;
568 object *args;
569{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000570 char *text;
571 int size;
572 if (!getargs(args, "s#", &text, &size))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000573 return NULL;
Guido van Rossumfc58e581992-01-27 16:45:55 +0000574 return newintobject((long)wtextwidth(text, size));
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000575}
576
577static object *
578drawing_textbreak(dp, args)
579 drawingobject *dp;
580 object *args;
581{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000582 char *text;
583 int size, width;
584 if (!getargs(args, "(s#i)", &text, &size, &width))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000585 return NULL;
Guido van Rossumfc58e581992-01-27 16:45:55 +0000586 return newintobject((long)wtextbreak(text, size, width));
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000587}
588
Guido van Rossum0c2290b1991-04-03 19:12:14 +0000589static object *
590drawing_setfont(self, args)
591 drawingobject *self;
592 object *args;
593{
Guido van Rossumfc58e581992-01-27 16:45:55 +0000594 char *font;
595 char style = '\0';
596 int size = 0;
597 if (args == NULL || !is_tupleobject(args)) {
Guido van Rossum3c8ba7a1992-02-05 11:15:00 +0000598 if (!getargs(args, "z", &font))
Guido van Rossum50429a11991-04-04 15:24:07 +0000599 return NULL;
600 }
601 else {
Guido van Rossumfc58e581992-01-27 16:45:55 +0000602 int n = gettuplesize(args);
603 if (n == 2) {
604 if (!getargs(args, "(zi)", &font, &size))
605 return NULL;
606 }
607 else if (!getargs(args, "(zic)", &font, &size, &style)) {
608 err_clear();
609 if (!getargs(args, "(zci)", &font, &style, &size))
610 return NULL;
Guido van Rossum50429a11991-04-04 15:24:07 +0000611 }
612 }
Guido van Rossum0b0db8e1993-01-21 16:07:51 +0000613 if (font != NULL) {
614 if (!wsetfont(font)) {
615 err_setstr(StdwinError, "font not found");
616 return NULL;
617 }
618 }
Guido van Rossum50429a11991-04-04 15:24:07 +0000619 if (size != 0)
620 wsetsize(size);
Guido van Rossumfc58e581992-01-27 16:45:55 +0000621 switch (style) {
622 case 'b':
623 wsetbold();
624 break;
625 case 'i':
626 wsetitalic();
627 break;
628 case 'o':
629 wsetbolditalic();
630 break;
631 case 'u':
632 wsetunderline();
633 break;
634 case 'p':
635 wsetplain();
636 break;
637 }
Guido van Rossum0c2290b1991-04-03 19:12:14 +0000638 INCREF(None);
639 return None;
640}
641
642static object *
643drawing_getbgcolor(self, args)
644 object *self;
645 object *args;
646{
647 if (!getnoarg(args))
648 return NULL;
649 return newintobject((long)wgetbgcolor());
650}
651
652static object *
653drawing_getfgcolor(self, args)
654 object *self;
655 object *args;
656{
657 if (!getnoarg(args))
658 return NULL;
659 return newintobject((long)wgetfgcolor());
660}
661
662static object *
663drawing_setbgcolor(self, args)
664 object *self;
665 object *args;
666{
667 long color;
668 if (!getlongarg(args, &color))
669 return NULL;
670 wsetbgcolor((COLOR)color);
671 INCREF(None);
672 return None;
673}
674
675static object *
676drawing_setfgcolor(self, args)
677 object *self;
678 object *args;
679{
680 long color;
681 if (!getlongarg(args, &color))
682 return NULL;
683 wsetfgcolor((COLOR)color);
684 INCREF(None);
685 return None;
686}
687
Guido van Rossume9066061993-07-29 13:14:32 +0000688#ifdef HAVE_BITMAPS
689
Guido van Rossumbf80e541993-02-08 15:49:17 +0000690static object *
691drawing_bitmap(self, args)
692 object *self;
693 object *args;
694{
695 int h, v;
696 object *bp;
697 object *mask = NULL;
698 if (!getargs(args, "((ii)O)", &h, &v, &bp)) {
699 err_clear();
700 if (!getargs(args, "((ii)OO)", &h, &v, &bp, &mask))
701 return NULL;
702 if (mask == None)
703 mask = NULL;
704 else if (!is_bitmapobject(mask)) {
705 err_badarg();
706 return NULL;
707 }
708 }
709 if (!is_bitmapobject(bp)) {
710 err_badarg();
711 return NULL;
712 }
713 if (((bitmapobject *)bp)->b_bitmap == NULL ||
714 mask != NULL && ((bitmapobject *)mask)->b_bitmap == NULL) {
715 err_setstr(StdwinError, "bitmap object already close");
716 return NULL;
717 }
718 if (mask == NULL)
719 wdrawbitmap(h, v, ((bitmapobject *)bp)->b_bitmap, ALLBITS);
720 else
721 wdrawbitmap(h, v,
722 ((bitmapobject *)bp)->b_bitmap,
723 ((bitmapobject *)bp)->b_bitmap);
724 INCREF(None);
725 return None;
726}
727
Guido van Rossume9066061993-07-29 13:14:32 +0000728#endif /* HAVE_BITMAPS */
729
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000730static struct methodlist drawing_methods[] = {
Guido van Rossume9066061993-07-29 13:14:32 +0000731#ifdef HAVE_BITMAPS
Guido van Rossumbf80e541993-02-08 15:49:17 +0000732 {"bitmap", drawing_bitmap},
Guido van Rossume9066061993-07-29 13:14:32 +0000733#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000734 {"box", drawing_box},
735 {"circle", drawing_circle},
736 {"cliprect", drawing_cliprect},
Guido van Rossum3c284741991-11-27 14:54:54 +0000737 {"close", drawing_close},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000738 {"elarc", drawing_elarc},
Guido van Rossum3c284741991-11-27 14:54:54 +0000739 {"enddrawing", drawing_close},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000740 {"erase", drawing_erase},
Guido van Rossum27201061991-04-16 08:43:03 +0000741 {"fillcircle", drawing_fillcircle},
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000742 {"fillelarc", drawing_fillelarc},
Guido van Rossum27201061991-04-16 08:43:03 +0000743 {"fillpoly", drawing_fillpoly},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000744 {"invert", drawing_invert},
745 {"line", drawing_line},
746 {"noclip", drawing_noclip},
747 {"paint", drawing_paint},
Guido van Rossum27201061991-04-16 08:43:03 +0000748 {"poly", drawing_poly},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000749 {"shade", drawing_shade},
750 {"text", drawing_text},
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000751 {"xorcircle", drawing_xorcircle},
752 {"xorelarc", drawing_xorelarc},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000753 {"xorline", drawing_xorline},
Guido van Rossuma2a181a1991-05-14 12:09:25 +0000754 {"xorpoly", drawing_xorpoly},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000755
756 /* Text measuring methods: */
757 {"baseline", drawing_baseline},
758 {"lineheight", drawing_lineheight},
759 {"textbreak", drawing_textbreak},
760 {"textwidth", drawing_textwidth},
Guido van Rossum0c2290b1991-04-03 19:12:14 +0000761
762 /* Font setting methods: */
763 {"setfont", drawing_setfont},
764
765 /* Color methods: */
766 {"getbgcolor", drawing_getbgcolor},
767 {"getfgcolor", drawing_getfgcolor},
768 {"setbgcolor", drawing_setbgcolor},
769 {"setfgcolor", drawing_setfgcolor},
770
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000771 {NULL, NULL} /* sentinel */
772};
773
774static object *
Guido van Rossum77b46041992-01-14 18:41:24 +0000775drawing_getattr(dp, name)
776 drawingobject *dp;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000777 char *name;
778{
Guido van Rossum77b46041992-01-14 18:41:24 +0000779 if (dp->d_ref == NULL) {
780 err_setstr(StdwinError, "drawing object already closed");
781 return NULL;
782 }
783 return findmethod(drawing_methods, (object *)dp, name);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000784}
785
Guido van Rossum541c8c01991-05-05 20:13:41 +0000786typeobject Drawingtype = {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000787 OB_HEAD_INIT(&Typetype)
788 0, /*ob_size*/
789 "drawing", /*tp_name*/
790 sizeof(drawingobject), /*tp_size*/
791 0, /*tp_itemsize*/
792 /* methods */
793 drawing_dealloc, /*tp_dealloc*/
794 0, /*tp_print*/
795 drawing_getattr, /*tp_getattr*/
796 0, /*tp_setattr*/
797 0, /*tp_compare*/
798 0, /*tp_repr*/
799};
800
801
802/* Text(edit) objects */
803
804typedef struct {
805 OB_HEAD
806 TEXTEDIT *t_text;
807 windowobject *t_ref;
808 object *t_attr; /* Attributes dictionary */
809} textobject;
810
811extern typeobject Texttype; /* Really static, forward */
812
813static textobject *
814newtextobject(wp, left, top, right, bottom)
815 windowobject *wp;
816 int left, top, right, bottom;
817{
818 textobject *tp;
819 tp = NEWOBJ(textobject, &Texttype);
820 if (tp == NULL)
821 return NULL;
822 tp->t_attr = NULL;
823 INCREF(wp);
824 tp->t_ref = wp;
825 tp->t_text = tecreate(wp->w_win, left, top, right, bottom);
826 if (tp->t_text == NULL) {
827 DECREF(tp);
828 return (textobject *) err_nomem();
829 }
830 return tp;
831}
832
833/* Text(edit) methods */
834
835static void
836text_dealloc(tp)
837 textobject *tp;
838{
839 if (tp->t_text != NULL)
840 tefree(tp->t_text);
Guido van Rossum3c284741991-11-27 14:54:54 +0000841 XDECREF(tp->t_attr);
842 XDECREF(tp->t_ref);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000843 DEL(tp);
844}
845
846static object *
Guido van Rossum3c284741991-11-27 14:54:54 +0000847text_close(tp, args)
848 textobject *tp;
849 object *args;
850{
851 if (tp->t_text != NULL) {
852 tefree(tp->t_text);
853 tp->t_text = NULL;
854 }
855 if (tp->t_attr != NULL) {
856 DECREF(tp->t_attr);
857 tp->t_attr = NULL;
858 }
859 if (tp->t_ref != NULL) {
860 DECREF(tp->t_ref);
861 tp->t_ref = NULL;
862 }
863 INCREF(None);
864 return None;
865}
866
867static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000868text_arrow(self, args)
869 textobject *self;
870 object *args;
871{
872 int code;
873 if (!getintarg(args, &code))
874 return NULL;
875 tearrow(self->t_text, code);
876 INCREF(None);
877 return None;
878}
879
880static object *
881text_draw(self, args)
882 textobject *self;
883 object *args;
884{
885 register TEXTEDIT *tp = self->t_text;
886 int a[4];
887 int left, top, right, bottom;
888 if (!getrectarg(args, a))
889 return NULL;
890 if (Drawing != NULL) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +0000891 err_setstr(StdwinError, "already drawing");
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000892 return NULL;
893 }
894 /* Clip to text area and ignore if area is empty */
895 left = tegetleft(tp);
896 top = tegettop(tp);
897 right = tegetright(tp);
898 bottom = tegetbottom(tp);
899 if (a[0] < left) a[0] = left;
900 if (a[1] < top) a[1] = top;
901 if (a[2] > right) a[2] = right;
902 if (a[3] > bottom) a[3] = bottom;
903 if (a[0] < a[2] && a[1] < a[3]) {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000904 wbegindrawing(self->t_ref->w_win);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000905 tedrawnew(tp, a[0], a[1], a[2], a[3]);
906 wenddrawing(self->t_ref->w_win);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000907 }
908 INCREF(None);
909 return None;
910}
911
912static object *
913text_event(self, args)
914 textobject *self;
915 object *args;
916{
917 register TEXTEDIT *tp = self->t_text;
918 EVENT e;
919 if (!geteventarg(args, &e))
920 return NULL;
921 if (e.type == WE_MOUSE_DOWN) {
Guido van Rossum33f17701991-02-13 23:19:39 +0000922 /* Cheat at the margins */
923 int width, height;
924 wgetdocsize(e.window, &width, &height);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000925 if (e.u.where.h < 0 && tegetleft(tp) == 0)
926 e.u.where.h = 0;
Guido van Rossum33f17701991-02-13 23:19:39 +0000927 else if (e.u.where.h > width && tegetright(tp) == width)
928 e.u.where.h = width;
929 if (e.u.where.v < 0 && tegettop(tp) == 0)
930 e.u.where.v = 0;
931 else if (e.u.where.v > height && tegetright(tp) == height)
932 e.u.where.v = height;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000933 }
934 return newintobject((long) teevent(tp, &e));
935}
936
937static object *
938text_getfocus(self, args)
939 textobject *self;
940 object *args;
941{
942 if (!getnoarg(args))
943 return NULL;
944 return makepoint(tegetfoc1(self->t_text), tegetfoc2(self->t_text));
945}
946
947static object *
948text_getfocustext(self, args)
949 textobject *self;
950 object *args;
951{
952 int f1, f2;
953 char *text;
954 if (!getnoarg(args))
955 return NULL;
956 f1 = tegetfoc1(self->t_text);
957 f2 = tegetfoc2(self->t_text);
958 text = tegettext(self->t_text);
959 return newsizedstringobject(text + f1, f2-f1);
960}
961
962static object *
963text_getrect(self, args)
964 textobject *self;
965 object *args;
966{
967 if (!getnoarg(args))
968 return NULL;
969 return makerect(tegetleft(self->t_text),
970 tegettop(self->t_text),
971 tegetright(self->t_text),
972 tegetbottom(self->t_text));
973}
974
975static object *
976text_gettext(self, args)
977 textobject *self;
978 object *args;
979{
980 if (!getnoarg(args))
981 return NULL;
982 return newsizedstringobject(tegettext(self->t_text),
983 tegetlen(self->t_text));
984}
985
986static object *
987text_move(self, args)
988 textobject *self;
989 object *args;
990{
991 int a[4];
992 if (!getrectarg(args, a))
993 return NULL;
994 temovenew(self->t_text, a[0], a[1], a[2], a[3]);
995 INCREF(None);
996 return None;
997}
998
999static object *
Guido van Rossum4b9cf8e1991-05-28 21:57:04 +00001000text_replace(self, args)
1001 textobject *self;
1002 object *args;
1003{
Guido van Rossumfc58e581992-01-27 16:45:55 +00001004 char *text;
Guido van Rossum4b9cf8e1991-05-28 21:57:04 +00001005 if (!getstrarg(args, &text))
1006 return NULL;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001007 tereplace(self->t_text, text);
Guido van Rossum4b9cf8e1991-05-28 21:57:04 +00001008 INCREF(None);
1009 return None;
1010}
1011
1012static object *
1013text_setactive(self, args)
1014 textobject *self;
1015 object *args;
1016{
1017 int flag;
1018 if (!getintarg(args, &flag))
1019 return NULL;
1020 tesetactive(self->t_text, flag);
1021 INCREF(None);
1022 return None;
1023}
1024
1025static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001026text_setfocus(self, args)
1027 textobject *self;
1028 object *args;
1029{
1030 int a[2];
1031 if (!getpointarg(args, a))
1032 return NULL;
1033 tesetfocus(self->t_text, a[0], a[1]);
1034 INCREF(None);
1035 return None;
1036}
1037
1038static object *
Guido van Rossum541c8c01991-05-05 20:13:41 +00001039text_settext(self, args)
1040 textobject *self;
1041 object *args;
1042{
Guido van Rossumfc58e581992-01-27 16:45:55 +00001043 char *text;
Guido van Rossum541c8c01991-05-05 20:13:41 +00001044 char *buf;
1045 int size;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001046 if (!getargs(args, "s#", &text, &size))
Guido van Rossum541c8c01991-05-05 20:13:41 +00001047 return NULL;
Guido van Rossum541c8c01991-05-05 20:13:41 +00001048 if ((buf = NEW(char, size)) == NULL) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +00001049 return err_nomem();
Guido van Rossum541c8c01991-05-05 20:13:41 +00001050 }
Guido van Rossumfc58e581992-01-27 16:45:55 +00001051 memcpy(buf, text, size);
Guido van Rossum541c8c01991-05-05 20:13:41 +00001052 tesetbuf(self->t_text, buf, size); /* Becomes owner of buffer */
1053 INCREF(None);
1054 return None;
1055}
1056
1057static object *
Guido van Rossum4b9cf8e1991-05-28 21:57:04 +00001058text_setview(self, args)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001059 textobject *self;
1060 object *args;
1061{
Guido van Rossum4b9cf8e1991-05-28 21:57:04 +00001062 int a[4];
1063 if (args == None)
1064 tenoview(self->t_text);
1065 else {
1066 if (!getrectarg(args, a))
1067 return NULL;
1068 tesetview(self->t_text, a[0], a[1], a[2], a[3]);
1069 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001070 INCREF(None);
1071 return None;
1072}
1073
1074static struct methodlist text_methods[] = {
Guido van Rossum3c284741991-11-27 14:54:54 +00001075 {"arrow", text_arrow},
1076 {"close", text_close},
1077 {"draw", text_draw},
1078 {"event", text_event},
1079 {"getfocus", text_getfocus},
Guido van Rossum77b46041992-01-14 18:41:24 +00001080 {"getfocustext",text_getfocustext},
Guido van Rossum3c284741991-11-27 14:54:54 +00001081 {"getrect", text_getrect},
1082 {"gettext", text_gettext},
Guido van Rossum77b46041992-01-14 18:41:24 +00001083 {"move", text_move},
Guido van Rossum3c284741991-11-27 14:54:54 +00001084 {"replace", text_replace},
1085 {"setactive", text_setactive},
1086 {"setfocus", text_setfocus},
1087 {"settext", text_settext},
1088 {"setview", text_setview},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001089 {NULL, NULL} /* sentinel */
1090};
1091
1092static object *
1093text_getattr(tp, name)
1094 textobject *tp;
1095 char *name;
1096{
Guido van Rossum85f50761991-10-20 20:22:50 +00001097 object *v = NULL;
Guido van Rossum77b46041992-01-14 18:41:24 +00001098 if (tp->t_ref == NULL) {
1099 err_setstr(StdwinError, "text object already closed");
1100 return NULL;
1101 }
Guido van Rossum85f50761991-10-20 20:22:50 +00001102 if (strcmp(name, "__dict__") == 0) {
1103 v = tp->t_attr;
1104 if (v == NULL)
1105 v = None;
1106 }
1107 else if (tp->t_attr != NULL) {
1108 v = dictlookup(tp->t_attr, name);
1109 }
1110 if (v != NULL) {
1111 INCREF(v);
1112 return v;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001113 }
1114 return findmethod(text_methods, (object *)tp, name);
1115}
1116
1117static int
1118text_setattr(tp, name, v)
1119 textobject *tp;
1120 char *name;
1121 object *v;
1122{
1123 if (tp->t_attr == NULL) {
1124 tp->t_attr = newdictobject();
1125 if (tp->t_attr == NULL)
1126 return -1;
1127 }
Guido van Rossum94472a01992-09-04 09:45:18 +00001128 if (v == NULL) {
1129 int rv = dictremove(tp->t_attr, name);
1130 if (rv < 0)
1131 err_setstr(AttributeError,
1132 "delete non-existing text object attribute");
1133 return rv;
1134 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001135 else
1136 return dictinsert(tp->t_attr, name, v);
1137}
1138
Guido van Rossum541c8c01991-05-05 20:13:41 +00001139typeobject Texttype = {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001140 OB_HEAD_INIT(&Typetype)
1141 0, /*ob_size*/
1142 "textedit", /*tp_name*/
1143 sizeof(textobject), /*tp_size*/
1144 0, /*tp_itemsize*/
1145 /* methods */
1146 text_dealloc, /*tp_dealloc*/
1147 0, /*tp_print*/
1148 text_getattr, /*tp_getattr*/
1149 text_setattr, /*tp_setattr*/
1150 0, /*tp_compare*/
1151 0, /*tp_repr*/
1152};
1153
1154
1155/* Menu objects */
1156
Guido van Rossum2d14e211991-02-19 12:26:49 +00001157#define IDOFFSET 10 /* Menu IDs we use start here */
Guido van Rossum27201061991-04-16 08:43:03 +00001158#define MAXNMENU 200 /* Max #menus we allow */
Guido van Rossum2d14e211991-02-19 12:26:49 +00001159static menuobject *menulist[MAXNMENU];
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001160
Guido van Rossumfc58e581992-01-27 16:45:55 +00001161static menuobject *newmenuobject PROTO((char *));
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001162static menuobject *
1163newmenuobject(title)
Guido van Rossumfc58e581992-01-27 16:45:55 +00001164 char *title;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001165{
1166 int id;
1167 MENU *menu;
1168 menuobject *mp;
Guido van Rossum2d14e211991-02-19 12:26:49 +00001169 for (id = 0; id < MAXNMENU; id++) {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001170 if (menulist[id] == NULL)
1171 break;
1172 }
Guido van Rossum27201061991-04-16 08:43:03 +00001173 if (id >= MAXNMENU) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +00001174 err_setstr(StdwinError, "creating too many menus");
Guido van Rossum27201061991-04-16 08:43:03 +00001175 return NULL;
1176 }
Guido van Rossumfc58e581992-01-27 16:45:55 +00001177 menu = wmenucreate(id + IDOFFSET, title);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001178 if (menu == NULL)
1179 return (menuobject *) err_nomem();
1180 mp = NEWOBJ(menuobject, &Menutype);
1181 if (mp != NULL) {
1182 mp->m_menu = menu;
Guido van Rossum2d14e211991-02-19 12:26:49 +00001183 mp->m_id = id + IDOFFSET;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001184 mp->m_attr = NULL;
1185 menulist[id] = mp;
1186 }
1187 else
1188 wmenudelete(menu);
1189 return mp;
1190}
1191
1192/* Menu methods */
1193
1194static void
1195menu_dealloc(mp)
1196 menuobject *mp;
1197{
1198
Guido van Rossum2d14e211991-02-19 12:26:49 +00001199 int id = mp->m_id - IDOFFSET;
1200 if (id >= 0 && id < MAXNMENU && menulist[id] == mp) {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001201 menulist[id] = NULL;
1202 }
Guido van Rossum77b46041992-01-14 18:41:24 +00001203 if (mp->m_menu != NULL)
1204 wmenudelete(mp->m_menu);
1205 XDECREF(mp->m_attr);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001206 DEL(mp);
1207}
1208
1209static object *
Guido van Rossum77b46041992-01-14 18:41:24 +00001210menu_close(mp, args)
1211 menuobject *mp;
1212 object *args;
1213{
1214 int id = mp->m_id - IDOFFSET;
1215 if (id >= 0 && id < MAXNMENU && menulist[id] == mp) {
1216 menulist[id] = NULL;
1217 }
1218 mp->m_id = -1;
1219 if (mp->m_menu != NULL)
1220 wmenudelete(mp->m_menu);
1221 mp->m_menu = NULL;
1222 XDECREF(mp->m_attr);
1223 mp->m_attr = NULL;
1224 INCREF(None);
1225 return None;
1226}
1227
1228static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001229menu_additem(self, args)
1230 menuobject *self;
1231 object *args;
1232{
Guido van Rossumfc58e581992-01-27 16:45:55 +00001233 char *text;
1234 int shortcut = -1;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001235 if (is_tupleobject(args)) {
Guido van Rossumfc58e581992-01-27 16:45:55 +00001236 char c;
1237 if (!getargs(args, "(sc)", &text, &c))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001238 return NULL;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001239 shortcut = c;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001240 }
Guido van Rossumfc58e581992-01-27 16:45:55 +00001241 else if (!getstrarg(args, &text))
1242 return NULL;
1243 wmenuadditem(self->m_menu, text, shortcut);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001244 INCREF(None);
1245 return None;
1246}
1247
1248static object *
1249menu_setitem(self, args)
1250 menuobject *self;
1251 object *args;
1252{
1253 int index;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001254 char *text;
Guido van Rossum234f9421993-06-17 12:35:49 +00001255 if (!getargs(args, "(is)", &index, &text))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001256 return NULL;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001257 wmenusetitem(self->m_menu, index, text);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001258 INCREF(None);
1259 return None;
1260}
1261
1262static object *
1263menu_enable(self, args)
1264 menuobject *self;
1265 object *args;
1266{
1267 int index;
1268 int flag;
Guido van Rossum234f9421993-06-17 12:35:49 +00001269 if (!getargs(args, "(ii)", &index, &flag))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001270 return NULL;
1271 wmenuenable(self->m_menu, index, flag);
1272 INCREF(None);
1273 return None;
1274}
1275
1276static object *
1277menu_check(self, args)
1278 menuobject *self;
1279 object *args;
1280{
1281 int index;
1282 int flag;
Guido van Rossum234f9421993-06-17 12:35:49 +00001283 if (!getargs(args, "(ii)", &index, &flag))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001284 return NULL;
1285 wmenucheck(self->m_menu, index, flag);
1286 INCREF(None);
1287 return None;
1288}
1289
1290static struct methodlist menu_methods[] = {
Guido van Rossum3c284741991-11-27 14:54:54 +00001291 {"additem", menu_additem},
1292 {"setitem", menu_setitem},
1293 {"enable", menu_enable},
1294 {"check", menu_check},
Guido van Rossum77b46041992-01-14 18:41:24 +00001295 {"close", menu_close},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001296 {NULL, NULL} /* sentinel */
1297};
1298
1299static object *
1300menu_getattr(mp, name)
1301 menuobject *mp;
1302 char *name;
1303{
Guido van Rossum85f50761991-10-20 20:22:50 +00001304 object *v = NULL;
Guido van Rossum77b46041992-01-14 18:41:24 +00001305 if (mp->m_menu == NULL) {
1306 err_setstr(StdwinError, "menu object already closed");
1307 return NULL;
1308 }
Guido van Rossum85f50761991-10-20 20:22:50 +00001309 if (strcmp(name, "__dict__") == 0) {
1310 v = mp->m_attr;
1311 if (v == NULL)
1312 v = None;
1313 }
1314 else if (mp->m_attr != NULL) {
1315 v = dictlookup(mp->m_attr, name);
1316 }
1317 if (v != NULL) {
1318 INCREF(v);
1319 return v;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001320 }
1321 return findmethod(menu_methods, (object *)mp, name);
1322}
1323
1324static int
1325menu_setattr(mp, name, v)
1326 menuobject *mp;
1327 char *name;
1328 object *v;
1329{
1330 if (mp->m_attr == NULL) {
1331 mp->m_attr = newdictobject();
1332 if (mp->m_attr == NULL)
1333 return -1;
1334 }
Guido van Rossum94472a01992-09-04 09:45:18 +00001335 if (v == NULL) {
1336 int rv = dictremove(mp->m_attr, name);
1337 if (rv < 0)
1338 err_setstr(AttributeError,
1339 "delete non-existing menu object attribute");
1340 return rv;
1341 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001342 else
1343 return dictinsert(mp->m_attr, name, v);
1344}
1345
Guido van Rossum541c8c01991-05-05 20:13:41 +00001346typeobject Menutype = {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001347 OB_HEAD_INIT(&Typetype)
1348 0, /*ob_size*/
1349 "menu", /*tp_name*/
1350 sizeof(menuobject), /*tp_size*/
1351 0, /*tp_itemsize*/
1352 /* methods */
1353 menu_dealloc, /*tp_dealloc*/
1354 0, /*tp_print*/
1355 menu_getattr, /*tp_getattr*/
1356 menu_setattr, /*tp_setattr*/
1357 0, /*tp_compare*/
1358 0, /*tp_repr*/
1359};
1360
1361
Guido van Rossume9066061993-07-29 13:14:32 +00001362#ifdef HAVE_BITMAPS
1363
Guido van Rossumbf80e541993-02-08 15:49:17 +00001364/* Bitmaps objects */
1365
1366static bitmapobject *newbitmapobject PROTO((int, int));
1367static bitmapobject *
1368newbitmapobject(width, height)
1369 int width, height;
1370{
1371 BITMAP *bitmap;
1372 bitmapobject *bp;
1373 bitmap = wnewbitmap(width, height);
1374 if (bitmap == NULL)
1375 return (bitmapobject *) err_nomem();
1376 bp = NEWOBJ(bitmapobject, &Bitmaptype);
1377 if (bp != NULL) {
1378 bp->b_bitmap = bitmap;
1379 bp->b_attr = NULL;
1380 }
1381 else
1382 wfreebitmap(bitmap);
1383 return bp;
1384}
1385
1386/* Bitmap methods */
1387
1388static void
1389bitmap_dealloc(bp)
1390 bitmapobject *bp;
1391{
1392 if (bp->b_bitmap != NULL)
1393 wfreebitmap(bp->b_bitmap);
1394 XDECREF(bp->b_attr);
1395 DEL(bp);
1396}
1397
1398static object *
1399bitmap_close(bp, args)
1400 bitmapobject *bp;
1401 object *args;
1402{
1403 if (bp->b_bitmap != NULL)
1404 wfreebitmap(bp->b_bitmap);
1405 bp->b_bitmap = NULL;
1406 XDECREF(bp->b_attr);
1407 bp->b_attr = NULL;
1408 INCREF(None);
1409 return None;
1410}
1411
1412static object *
1413bitmap_setbit(self, args)
1414 bitmapobject *self;
1415 object *args;
1416{
1417 int a[3];
1418 if (!getpointintarg(args, a))
1419 return NULL;
1420 wsetbit(self->b_bitmap, a[0], a[1], a[2]);
1421 INCREF(None);
1422 return None;
1423}
1424
1425static object *
1426bitmap_getbit(self, args)
1427 bitmapobject *self;
1428 object *args;
1429{
1430 int a[2];
1431 if (!getpointarg(args, a))
1432 return NULL;
1433 return newintobject((long) wgetbit(self->b_bitmap, a[0], a[1]));
1434}
1435
1436static object *
1437bitmap_getsize(self, args)
1438 bitmapobject *self;
1439 object *args;
1440{
1441 int width, height;
1442 if (!getnoarg(args))
1443 return NULL;
1444 wgetbitmapsize(self->b_bitmap, &width, &height);
1445 return mkvalue("(ii)", width, height);
1446}
1447
1448static struct methodlist bitmap_methods[] = {
1449 {"close", bitmap_close},
1450 {"getsize", bitmap_getsize},
1451 {"getbit", bitmap_getbit},
1452 {"setbit", bitmap_setbit},
1453 {NULL, NULL} /* sentinel */
1454};
1455
1456static object *
1457bitmap_getattr(bp, name)
1458 bitmapobject *bp;
1459 char *name;
1460{
1461 object *v = NULL;
1462 if (bp->b_bitmap == NULL) {
1463 err_setstr(StdwinError, "bitmap object already closed");
1464 return NULL;
1465 }
1466 if (strcmp(name, "__dict__") == 0) {
1467 v = bp->b_attr;
1468 if (v == NULL)
1469 v = None;
1470 }
1471 else if (bp->b_attr != NULL) {
1472 v = dictlookup(bp->b_attr, name);
1473 }
1474 if (v != NULL) {
1475 INCREF(v);
1476 return v;
1477 }
1478 return findmethod(bitmap_methods, (object *)bp, name);
1479}
1480
1481static int
1482bitmap_setattr(bp, name, v)
1483 bitmapobject *bp;
1484 char *name;
1485 object *v;
1486{
1487 if (bp->b_attr == NULL) {
1488 bp->b_attr = newdictobject();
1489 if (bp->b_attr == NULL)
1490 return -1;
1491 }
1492 if (v == NULL) {
1493 int rv = dictremove(bp->b_attr, name);
1494 if (rv < 0)
1495 err_setstr(AttributeError,
1496 "delete non-existing bitmap object attribute");
1497 return rv;
1498 }
1499 else
1500 return dictinsert(bp->b_attr, name, v);
1501}
1502
1503typeobject Bitmaptype = {
1504 OB_HEAD_INIT(&Typetype)
1505 0, /*ob_size*/
1506 "bitmap", /*tp_name*/
1507 sizeof(bitmapobject), /*tp_size*/
1508 0, /*tp_itemsize*/
1509 /* methods */
1510 bitmap_dealloc, /*tp_dealloc*/
1511 0, /*tp_print*/
1512 bitmap_getattr, /*tp_getattr*/
1513 bitmap_setattr, /*tp_setattr*/
1514 0, /*tp_compare*/
1515 0, /*tp_repr*/
1516};
1517
Guido van Rossume9066061993-07-29 13:14:32 +00001518#endif /* HAVE_BITMAPS */
1519
Guido van Rossumbf80e541993-02-08 15:49:17 +00001520
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001521/* Windows */
1522
1523#define MAXNWIN 50
1524static windowobject *windowlist[MAXNWIN];
1525
1526/* Window methods */
1527
1528static void
1529window_dealloc(wp)
1530 windowobject *wp;
1531{
1532 if (wp->w_win != NULL) {
1533 int tag = wgettag(wp->w_win);
1534 if (tag >= 0 && tag < MAXNWIN)
1535 windowlist[tag] = NULL;
1536 else
1537 fprintf(stderr, "XXX help! tag %d in window_dealloc\n",
1538 tag);
1539 wclose(wp->w_win);
1540 }
1541 DECREF(wp->w_title);
1542 if (wp->w_attr != NULL)
1543 DECREF(wp->w_attr);
1544 free((char *)wp);
1545}
1546
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001547static object *
Guido van Rossum3c284741991-11-27 14:54:54 +00001548window_close(wp, args)
1549 windowobject *wp;
1550 object *args;
1551{
1552 if (wp->w_win != NULL) {
1553 int tag = wgettag(wp->w_win);
1554 if (tag >= 0 && tag < MAXNWIN)
1555 windowlist[tag] = NULL;
1556 wclose(wp->w_win);
1557 wp->w_win = NULL;
1558 }
1559 INCREF(None);
1560 return None;
1561}
1562
1563static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001564window_begindrawing(wp, args)
1565 windowobject *wp;
1566 object *args;
1567{
1568 drawingobject *dp;
1569 if (!getnoarg(args))
1570 return NULL;
1571 if (Drawing != NULL) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +00001572 err_setstr(StdwinError, "already drawing");
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001573 return NULL;
1574 }
1575 dp = NEWOBJ(drawingobject, &Drawingtype);
1576 if (dp == NULL)
1577 return NULL;
1578 Drawing = dp;
1579 INCREF(wp);
1580 dp->d_ref = wp;
1581 wbegindrawing(wp->w_win);
1582 return (object *)dp;
1583}
1584
1585static object *
1586window_change(wp, args)
1587 windowobject *wp;
1588 object *args;
1589{
1590 int a[4];
1591 if (!getrectarg(args, a))
1592 return NULL;
1593 wchange(wp->w_win, a[0], a[1], a[2], a[3]);
1594 INCREF(None);
1595 return None;
1596}
1597
1598static object *
1599window_gettitle(wp, args)
1600 windowobject *wp;
1601 object *args;
1602{
1603 if (!getnoarg(args))
1604 return NULL;
1605 INCREF(wp->w_title);
1606 return wp->w_title;
1607}
1608
1609static object *
Guido van Rossum541c8c01991-05-05 20:13:41 +00001610window_getwinpos(wp, args)
1611 windowobject *wp;
1612 object *args;
1613{
1614 int h, v;
1615 if (!getnoarg(args))
1616 return NULL;
1617 wgetwinpos(wp->w_win, &h, &v);
1618 return makepoint(h, v);
1619}
1620
1621static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001622window_getwinsize(wp, args)
1623 windowobject *wp;
1624 object *args;
1625{
1626 int width, height;
1627 if (!getnoarg(args))
1628 return NULL;
1629 wgetwinsize(wp->w_win, &width, &height);
1630 return makepoint(width, height);
1631}
1632
1633static object *
Guido van Rossumbf80e541993-02-08 15:49:17 +00001634window_setwinpos(wp, args)
1635 windowobject *wp;
1636 object *args;
1637{
1638 int a[2];
1639 if (!getpointarg(args, a))
1640 return NULL;
1641 wsetwinpos(wp->w_win, a[0], a[1]);
1642 INCREF(None);
1643 return None;
1644}
1645
1646static object *
1647window_setwinsize(wp, args)
1648 windowobject *wp;
1649 object *args;
1650{
1651 int a[2];
1652 if (!getpointarg(args, a))
1653 return NULL;
1654 wsetwinsize(wp->w_win, a[0], a[1]);
1655 INCREF(None);
1656 return None;
1657}
1658
1659static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001660window_getdocsize(wp, args)
1661 windowobject *wp;
1662 object *args;
1663{
1664 int width, height;
1665 if (!getnoarg(args))
1666 return NULL;
1667 wgetdocsize(wp->w_win, &width, &height);
1668 return makepoint(width, height);
1669}
1670
1671static object *
1672window_getorigin(wp, args)
1673 windowobject *wp;
1674 object *args;
1675{
1676 int width, height;
1677 if (!getnoarg(args))
1678 return NULL;
1679 wgetorigin(wp->w_win, &width, &height);
1680 return makepoint(width, height);
1681}
1682
1683static object *
1684window_scroll(wp, args)
1685 windowobject *wp;
1686 object *args;
1687{
1688 int a[6];
1689 if (!getrectpointarg(args, a))
1690 return NULL;
1691 wscroll(wp->w_win, a[0], a[1], a[2], a[3], a[4], a[5]);
1692 INCREF(None);
1693 return None;
1694}
1695
1696static object *
1697window_setdocsize(wp, args)
1698 windowobject *wp;
1699 object *args;
1700{
1701 int a[2];
1702 if (!getpointarg(args, a))
1703 return NULL;
1704 wsetdocsize(wp->w_win, a[0], a[1]);
1705 INCREF(None);
1706 return None;
1707}
1708
1709static object *
1710window_setorigin(wp, args)
1711 windowobject *wp;
1712 object *args;
1713{
1714 int a[2];
1715 if (!getpointarg(args, a))
1716 return NULL;
1717 wsetorigin(wp->w_win, a[0], a[1]);
1718 INCREF(None);
1719 return None;
1720}
1721
1722static object *
1723window_settitle(wp, args)
1724 windowobject *wp;
1725 object *args;
1726{
1727 object *title;
Guido van Rossum234f9421993-06-17 12:35:49 +00001728 if (!getargs(args, "S", &title))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001729 return NULL;
1730 DECREF(wp->w_title);
1731 INCREF(title);
1732 wp->w_title = title;
1733 wsettitle(wp->w_win, getstringvalue(title));
1734 INCREF(None);
1735 return None;
1736}
1737
1738static object *
1739window_show(wp, args)
1740 windowobject *wp;
1741 object *args;
1742{
1743 int a[4];
1744 if (!getrectarg(args, a))
1745 return NULL;
1746 wshow(wp->w_win, a[0], a[1], a[2], a[3]);
1747 INCREF(None);
1748 return None;
1749}
1750
1751static object *
1752window_settimer(wp, args)
1753 windowobject *wp;
1754 object *args;
1755{
1756 int a;
1757 if (!getintarg(args, &a))
1758 return NULL;
1759 wsettimer(wp->w_win, a);
1760 INCREF(None);
1761 return None;
1762}
1763
1764static object *
1765window_menucreate(self, args)
1766 windowobject *self;
1767 object *args;
1768{
1769 menuobject *mp;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001770 char *title;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001771 if (!getstrarg(args, &title))
1772 return NULL;
1773 wmenusetdeflocal(1);
1774 mp = newmenuobject(title);
1775 if (mp == NULL)
1776 return NULL;
1777 wmenuattach(self->w_win, mp->m_menu);
1778 return (object *)mp;
1779}
1780
1781static object *
1782window_textcreate(self, args)
1783 windowobject *self;
1784 object *args;
1785{
1786 textobject *tp;
1787 int a[4];
1788 if (!getrectarg(args, a))
1789 return NULL;
1790 return (object *)
1791 newtextobject(self, a[0], a[1], a[2], a[3]);
1792}
1793
Guido van Rossum5b10f451990-10-30 16:01:48 +00001794static object *
1795window_setselection(self, args)
1796 windowobject *self;
1797 object *args;
1798{
Guido van Rossumfc58e581992-01-27 16:45:55 +00001799 int sel, size, ok;
1800 char *text;
1801 if (!getargs(args, "(is#)", &sel, &text, &size))
Guido van Rossum5b10f451990-10-30 16:01:48 +00001802 return NULL;
Guido van Rossumfc58e581992-01-27 16:45:55 +00001803 ok = wsetselection(self->w_win, sel, text, size);
Guido van Rossum5b10f451990-10-30 16:01:48 +00001804 return newintobject(ok);
1805}
1806
1807static object *
1808window_setwincursor(self, args)
1809 windowobject *self;
1810 object *args;
1811{
Guido van Rossumfc58e581992-01-27 16:45:55 +00001812 char *name;
Guido van Rossum5b10f451990-10-30 16:01:48 +00001813 CURSOR *c;
Guido van Rossum3c8ba7a1992-02-05 11:15:00 +00001814 if (!getargs(args, "z", &name))
Guido van Rossum5b10f451990-10-30 16:01:48 +00001815 return NULL;
Guido van Rossum3c8ba7a1992-02-05 11:15:00 +00001816 if (name == NULL)
1817 c = NULL;
1818 else {
1819 c = wfetchcursor(name);
1820 if (c == NULL) {
1821 err_setstr(StdwinError, "no such cursor");
1822 return NULL;
1823 }
Guido van Rossum5b10f451990-10-30 16:01:48 +00001824 }
1825 wsetwincursor(self->w_win, c);
1826 INCREF(None);
1827 return None;
1828}
1829
Guido van Rossumfc58e581992-01-27 16:45:55 +00001830static object *
1831window_setactive(self, args)
1832 windowobject *self;
1833 object *args;
1834{
1835 if (!getnoarg(args))
1836 return NULL;
1837 wsetactive(self->w_win);
1838 INCREF(None);
1839 return None;
1840}
1841
Guido van Rossum8dcbbac1991-07-27 21:42:24 +00001842#ifdef CWI_HACKS
1843static object *
1844window_getxwindowid(self, args)
1845 windowobject *self;
1846 object *args;
1847{
1848 long wid = wgetxwindowid(self->w_win);
1849 return newintobject(wid);
1850}
1851#endif
1852
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001853static struct methodlist window_methods[] = {
1854 {"begindrawing",window_begindrawing},
1855 {"change", window_change},
Guido van Rossum3c284741991-11-27 14:54:54 +00001856 {"close", window_close},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001857 {"getdocsize", window_getdocsize},
1858 {"getorigin", window_getorigin},
1859 {"gettitle", window_gettitle},
Guido van Rossum541c8c01991-05-05 20:13:41 +00001860 {"getwinpos", window_getwinpos},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001861 {"getwinsize", window_getwinsize},
1862 {"menucreate", window_menucreate},
1863 {"scroll", window_scroll},
Guido van Rossumb7e51601992-01-26 18:13:18 +00001864 {"setactive", window_setactive},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001865 {"setdocsize", window_setdocsize},
1866 {"setorigin", window_setorigin},
Guido van Rossum5b10f451990-10-30 16:01:48 +00001867 {"setselection",window_setselection},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001868 {"settimer", window_settimer},
1869 {"settitle", window_settitle},
Guido van Rossum27201061991-04-16 08:43:03 +00001870 {"setwincursor",window_setwincursor},
Guido van Rossumbf80e541993-02-08 15:49:17 +00001871 {"setwinpos", window_setwinpos},
1872 {"setwinsize", window_setwinsize},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001873 {"show", window_show},
1874 {"textcreate", window_textcreate},
Guido van Rossum8dcbbac1991-07-27 21:42:24 +00001875#ifdef CWI_HACKS
1876 {"getxwindowid",window_getxwindowid},
1877#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001878 {NULL, NULL} /* sentinel */
1879};
1880
1881static object *
1882window_getattr(wp, name)
1883 windowobject *wp;
1884 char *name;
1885{
Guido van Rossum85f50761991-10-20 20:22:50 +00001886 object *v = NULL;
Guido van Rossum77b46041992-01-14 18:41:24 +00001887 if (wp->w_win == NULL) {
1888 err_setstr(StdwinError, "window already closed");
1889 return NULL;
1890 }
Guido van Rossum85f50761991-10-20 20:22:50 +00001891 if (strcmp(name, "__dict__") == 0) {
1892 v = wp->w_attr;
1893 if (v == NULL)
1894 v = None;
1895 }
1896 else if (wp->w_attr != NULL) {
1897 v = dictlookup(wp->w_attr, name);
1898 }
1899 if (v != NULL) {
1900 INCREF(v);
1901 return v;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001902 }
1903 return findmethod(window_methods, (object *)wp, name);
1904}
1905
1906static int
1907window_setattr(wp, name, v)
1908 windowobject *wp;
1909 char *name;
1910 object *v;
1911{
1912 if (wp->w_attr == NULL) {
1913 wp->w_attr = newdictobject();
1914 if (wp->w_attr == NULL)
1915 return -1;
1916 }
Guido van Rossum94472a01992-09-04 09:45:18 +00001917 if (v == NULL) {
1918 int rv = dictremove(wp->w_attr, name);
1919 if (rv < 0)
1920 err_setstr(AttributeError,
1921 "delete non-existing menu object attribute");
1922 return rv;
1923 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001924 else
1925 return dictinsert(wp->w_attr, name, v);
1926}
1927
Guido van Rossum541c8c01991-05-05 20:13:41 +00001928typeobject Windowtype = {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001929 OB_HEAD_INIT(&Typetype)
1930 0, /*ob_size*/
1931 "window", /*tp_name*/
1932 sizeof(windowobject), /*tp_size*/
1933 0, /*tp_itemsize*/
1934 /* methods */
1935 window_dealloc, /*tp_dealloc*/
Guido van Rossum7066dd71992-09-17 17:54:56 +00001936 0, /*tp_print*/
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001937 window_getattr, /*tp_getattr*/
1938 window_setattr, /*tp_setattr*/
1939 0, /*tp_compare*/
1940 0, /*tp_repr*/
1941};
1942
1943/* Stdwin methods */
1944
1945static object *
1946stdwin_open(sw, args)
1947 object *sw;
1948 object *args;
1949{
1950 int tag;
1951 object *title;
1952 windowobject *wp;
Guido van Rossum234f9421993-06-17 12:35:49 +00001953 if (!getargs(args, "S", &title))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001954 return NULL;
1955 for (tag = 0; tag < MAXNWIN; tag++) {
1956 if (windowlist[tag] == NULL)
1957 break;
1958 }
Guido van Rossum27201061991-04-16 08:43:03 +00001959 if (tag >= MAXNWIN) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +00001960 err_setstr(StdwinError, "creating too many windows");
Guido van Rossum27201061991-04-16 08:43:03 +00001961 return NULL;
1962 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001963 wp = NEWOBJ(windowobject, &Windowtype);
1964 if (wp == NULL)
1965 return NULL;
1966 INCREF(title);
1967 wp->w_title = title;
1968 wp->w_win = wopen(getstringvalue(title), (void (*)()) NULL);
1969 wp->w_attr = NULL;
1970 if (wp->w_win == NULL) {
1971 DECREF(wp);
1972 return NULL;
1973 }
1974 windowlist[tag] = wp;
1975 wsettag(wp->w_win, tag);
1976 return (object *)wp;
1977}
1978
1979static object *
Guido van Rossum246b9d81991-06-03 10:55:14 +00001980window2object(win)
1981 WINDOW *win;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001982{
Guido van Rossum246b9d81991-06-03 10:55:14 +00001983 object *w;
1984 if (win == NULL)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001985 w = None;
1986 else {
Guido van Rossum246b9d81991-06-03 10:55:14 +00001987 int tag = wgettag(win);
1988 if (tag < 0 || tag >= MAXNWIN || windowlist[tag] == NULL ||
1989 windowlist[tag]->w_win != win)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001990 w = None;
1991 else
1992 w = (object *)windowlist[tag];
1993 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001994 INCREF(w);
Guido van Rossum246b9d81991-06-03 10:55:14 +00001995 return w;
1996}
1997
1998static object *
1999stdwin_get_poll_event(poll, args)
2000 int poll;
2001 object *args;
2002{
2003 EVENT e;
Guido van Rossum2ee12f41992-04-13 15:54:35 +00002004 object *u, *v, *w;
Guido van Rossum246b9d81991-06-03 10:55:14 +00002005 if (!getnoarg(args))
2006 return NULL;
2007 if (Drawing != NULL) {
Guido van Rossum87e7ea71991-12-10 14:00:03 +00002008 err_setstr(StdwinError, "cannot getevent() while drawing");
Guido van Rossum246b9d81991-06-03 10:55:14 +00002009 return NULL;
2010 }
2011 again:
Guido van Rossumff4949e1992-08-05 19:58:53 +00002012 BGN_STDWIN
Guido van Rossum246b9d81991-06-03 10:55:14 +00002013 if (poll) {
2014 if (!wpollevent(&e)) {
Guido van Rossumff4949e1992-08-05 19:58:53 +00002015 RET_STDWIN
Guido van Rossum246b9d81991-06-03 10:55:14 +00002016 INCREF(None);
2017 return None;
2018 }
2019 }
2020 else
2021 wgetevent(&e);
Guido van Rossumff4949e1992-08-05 19:58:53 +00002022 END_STDWIN
Guido van Rossum246b9d81991-06-03 10:55:14 +00002023 if (e.type == WE_COMMAND && e.u.command == WC_CANCEL) {
2024 /* Turn keyboard interrupts into exceptions */
2025 err_set(KeyboardInterrupt);
2026 return NULL;
2027 }
2028 if (e.type == WE_COMMAND && e.u.command == WC_CLOSE) {
2029 /* Turn WC_CLOSE commands into WE_CLOSE events */
2030 e.type = WE_CLOSE;
2031 }
Guido van Rossum2ee12f41992-04-13 15:54:35 +00002032 v = window2object(e.window);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002033 switch (e.type) {
2034 case WE_CHAR:
2035 {
2036 char c[1];
2037 c[0] = e.u.character;
2038 w = newsizedstringobject(c, 1);
2039 }
2040 break;
2041 case WE_COMMAND:
2042 w = newintobject((long)e.u.command);
2043 break;
2044 case WE_DRAW:
2045 w = makerect(e.u.area.left, e.u.area.top,
2046 e.u.area.right, e.u.area.bottom);
2047 break;
2048 case WE_MOUSE_DOWN:
2049 case WE_MOUSE_MOVE:
2050 case WE_MOUSE_UP:
Guido van Rossum2ee12f41992-04-13 15:54:35 +00002051 w = mkvalue("((ii)iii)",
2052 e.u.where.h, e.u.where.v,
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002053 e.u.where.clicks,
2054 e.u.where.button,
2055 e.u.where.mask);
2056 break;
2057 case WE_MENU:
Guido van Rossum2d14e211991-02-19 12:26:49 +00002058 if (e.u.m.id >= IDOFFSET && e.u.m.id < IDOFFSET+MAXNMENU &&
2059 menulist[e.u.m.id - IDOFFSET] != NULL)
Guido van Rossum2ee12f41992-04-13 15:54:35 +00002060 w = mkvalue("(Oi)",
2061 menulist[e.u.m.id - IDOFFSET], e.u.m.item);
Guido van Rossum246b9d81991-06-03 10:55:14 +00002062 else {
2063 /* Ghost menu event.
2064 Can occur only on the Mac if another part
2065 of the aplication has installed a menu;
2066 like the THINK C console library. */
2067 DECREF(v);
2068 goto again;
2069 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002070 break;
Guido van Rossum3ee199e1992-06-30 12:48:26 +00002071 case WE_KEY:
2072 w = mkvalue("(ii)", e.u.key.code, e.u.key.mask);
2073 break;
Guido van Rossum5b10f451990-10-30 16:01:48 +00002074 case WE_LOST_SEL:
2075 w = newintobject((long)e.u.sel);
2076 break;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002077 default:
2078 w = None;
2079 INCREF(w);
2080 break;
2081 }
2082 if (w == NULL) {
2083 DECREF(v);
2084 return NULL;
2085 }
Guido van Rossum2ee12f41992-04-13 15:54:35 +00002086 u = mkvalue("(iOO)", e.type, v, w);
2087 XDECREF(v);
2088 XDECREF(w);
2089 return u;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002090}
2091
2092static object *
Guido van Rossume8e7cf41991-01-16 14:06:18 +00002093stdwin_getevent(sw, args)
2094 object *sw;
2095 object *args;
2096{
2097 return stdwin_get_poll_event(0, args);
2098}
2099
2100static object *
2101stdwin_pollevent(sw, args)
2102 object *sw;
2103 object *args;
2104{
2105 return stdwin_get_poll_event(1, args);
2106}
2107
2108static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002109stdwin_setdefwinpos(sw, args)
2110 object *sw;
2111 object *args;
2112{
2113 int a[2];
2114 if (!getpointarg(args, a))
2115 return NULL;
2116 wsetdefwinpos(a[0], a[1]);
2117 INCREF(None);
2118 return None;
2119}
2120
2121static object *
2122stdwin_setdefwinsize(sw, args)
2123 object *sw;
2124 object *args;
2125{
2126 int a[2];
2127 if (!getpointarg(args, a))
2128 return NULL;
2129 wsetdefwinsize(a[0], a[1]);
2130 INCREF(None);
2131 return None;
2132}
2133
2134static object *
Guido van Rossum0c2290b1991-04-03 19:12:14 +00002135stdwin_setdefscrollbars(sw, args)
2136 object *sw;
2137 object *args;
2138{
2139 int a[2];
2140 if (!getpointarg(args, a))
2141 return NULL;
2142 wsetdefscrollbars(a[0], a[1]);
2143 INCREF(None);
2144 return None;
2145}
2146
2147static object *
Guido van Rossum541c8c01991-05-05 20:13:41 +00002148stdwin_getdefwinpos(self, args)
2149 object *self;
Guido van Rossum33f17701991-02-13 23:19:39 +00002150 object *args;
2151{
2152 int h, v;
2153 if (!getnoarg(args))
2154 return NULL;
2155 wgetdefwinpos(&h, &v);
2156 return makepoint(h, v);
2157}
2158
2159static object *
Guido van Rossum541c8c01991-05-05 20:13:41 +00002160stdwin_getdefwinsize(self, args)
2161 object *self;
Guido van Rossum33f17701991-02-13 23:19:39 +00002162 object *args;
2163{
2164 int width, height;
2165 if (!getnoarg(args))
2166 return NULL;
2167 wgetdefwinsize(&width, &height);
2168 return makepoint(width, height);
2169}
2170
2171static object *
Guido van Rossum541c8c01991-05-05 20:13:41 +00002172stdwin_getdefscrollbars(self, args)
2173 object *self;
Guido van Rossum0c2290b1991-04-03 19:12:14 +00002174 object *args;
2175{
2176 int h, v;
2177 if (!getnoarg(args))
2178 return NULL;
2179 wgetdefscrollbars(&h, &v);
2180 return makepoint(h, v);
2181}
2182
2183static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002184stdwin_menucreate(self, args)
2185 object *self;
2186 object *args;
2187{
Guido van Rossumfc58e581992-01-27 16:45:55 +00002188 char *title;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002189 if (!getstrarg(args, &title))
2190 return NULL;
2191 wmenusetdeflocal(0);
2192 return (object *)newmenuobject(title);
2193}
2194
2195static object *
2196stdwin_askfile(self, args)
2197 object *self;
2198 object *args;
2199{
Guido van Rossumfc58e581992-01-27 16:45:55 +00002200 char *prompt, *dflt;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002201 int new, ret;
2202 char buf[256];
Guido van Rossum234f9421993-06-17 12:35:49 +00002203 if (!getargs(args, "(ssi)", &prompt, &dflt, &new))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002204 return NULL;
Guido van Rossumfc58e581992-01-27 16:45:55 +00002205 strncpy(buf, dflt, sizeof buf);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002206 buf[sizeof buf - 1] = '\0';
Guido van Rossumff4949e1992-08-05 19:58:53 +00002207 BGN_STDWIN
Guido van Rossumfc58e581992-01-27 16:45:55 +00002208 ret = waskfile(prompt, buf, sizeof buf, new);
Guido van Rossumff4949e1992-08-05 19:58:53 +00002209 END_STDWIN
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002210 if (!ret) {
2211 err_set(KeyboardInterrupt);
2212 return NULL;
2213 }
2214 return newstringobject(buf);
2215}
2216
2217static object *
2218stdwin_askync(self, args)
2219 object *self;
2220 object *args;
2221{
Guido van Rossumfc58e581992-01-27 16:45:55 +00002222 char *prompt;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002223 int new, ret;
Guido van Rossum234f9421993-06-17 12:35:49 +00002224 if (!getargs(args, "(si)", &prompt, &new))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002225 return NULL;
Guido van Rossumff4949e1992-08-05 19:58:53 +00002226 BGN_STDWIN
Guido van Rossumfc58e581992-01-27 16:45:55 +00002227 ret = waskync(prompt, new);
Guido van Rossumff4949e1992-08-05 19:58:53 +00002228 END_STDWIN
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002229 if (ret < 0) {
2230 err_set(KeyboardInterrupt);
2231 return NULL;
2232 }
2233 return newintobject((long)ret);
2234}
2235
2236static object *
2237stdwin_askstr(self, args)
2238 object *self;
2239 object *args;
2240{
Guido van Rossumfc58e581992-01-27 16:45:55 +00002241 char *prompt, *dflt;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002242 int ret;
2243 char buf[256];
Guido van Rossum234f9421993-06-17 12:35:49 +00002244 if (!getargs(args, "(ss)", &prompt, &dflt))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002245 return NULL;
Guido van Rossumfc58e581992-01-27 16:45:55 +00002246 strncpy(buf, dflt, sizeof buf);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002247 buf[sizeof buf - 1] = '\0';
Guido van Rossumff4949e1992-08-05 19:58:53 +00002248 BGN_STDWIN
Guido van Rossumfc58e581992-01-27 16:45:55 +00002249 ret = waskstr(prompt, buf, sizeof buf);
Guido van Rossumff4949e1992-08-05 19:58:53 +00002250 END_STDWIN
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002251 if (!ret) {
2252 err_set(KeyboardInterrupt);
2253 return NULL;
2254 }
2255 return newstringobject(buf);
2256}
2257
2258static object *
2259stdwin_message(self, args)
2260 object *self;
2261 object *args;
2262{
Guido van Rossumfc58e581992-01-27 16:45:55 +00002263 char *msg;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002264 if (!getstrarg(args, &msg))
2265 return NULL;
Guido van Rossumff4949e1992-08-05 19:58:53 +00002266 BGN_STDWIN
Guido van Rossumfc58e581992-01-27 16:45:55 +00002267 wmessage(msg);
Guido van Rossumff4949e1992-08-05 19:58:53 +00002268 END_STDWIN
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002269 INCREF(None);
2270 return None;
2271}
2272
2273static object *
2274stdwin_fleep(self, args)
2275 object *self;
2276 object *args;
2277{
2278 if (!getnoarg(args))
2279 return NULL;
2280 wfleep();
2281 INCREF(None);
2282 return None;
2283}
2284
2285static object *
2286stdwin_setcutbuffer(self, args)
2287 object *self;
2288 object *args;
2289{
Guido van Rossumfc58e581992-01-27 16:45:55 +00002290 int i, size;
2291 char *str;
2292 if (!getargs(args, "(is#)", &i, &str, &size))
Guido van Rossum124967c1990-11-06 15:17:35 +00002293 return NULL;
Guido van Rossumfc58e581992-01-27 16:45:55 +00002294 wsetcutbuffer(i, str, size);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002295 INCREF(None);
2296 return None;
2297}
2298
2299static object *
Guido van Rossum246b9d81991-06-03 10:55:14 +00002300stdwin_getactive(self, args)
2301 object *self;
2302 object *args;
2303{
2304 return window2object(wgetactive());
2305}
2306
2307static object *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002308stdwin_getcutbuffer(self, args)
2309 object *self;
2310 object *args;
2311{
Guido van Rossum5b10f451990-10-30 16:01:48 +00002312 int i;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002313 char *str;
Guido van Rossum01769f01990-10-30 13:39:00 +00002314 int len;
Guido van Rossum124967c1990-11-06 15:17:35 +00002315 if (!getintarg(args, &i))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002316 return NULL;
Guido van Rossum5b10f451990-10-30 16:01:48 +00002317 str = wgetcutbuffer(i, &len);
Guido van Rossum01769f01990-10-30 13:39:00 +00002318 if (str == NULL) {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002319 str = "";
Guido van Rossum01769f01990-10-30 13:39:00 +00002320 len = 0;
2321 }
2322 return newsizedstringobject(str, len);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002323}
2324
Guido van Rossum5b10f451990-10-30 16:01:48 +00002325static object *
2326stdwin_rotatecutbuffers(self, args)
2327 object *self;
2328 object *args;
2329{
2330 int i;
2331 if (!getintarg(args, &i))
2332 return NULL;
2333 wrotatecutbuffers(i);
2334 INCREF(None);
2335 return None;
2336}
2337
2338static object *
2339stdwin_getselection(self, args)
2340 object *self;
2341 object *args;
2342{
2343 int sel;
2344 char *data;
2345 int len;
2346 if (!getintarg(args, &sel))
2347 return NULL;
2348 data = wgetselection(sel, &len);
2349 if (data == NULL) {
2350 data = "";
2351 len = 0;
2352 }
2353 return newsizedstringobject(data, len);
2354}
2355
2356static object *
2357stdwin_resetselection(self, args)
2358 object *self;
2359 object *args;
2360{
2361 int sel;
2362 if (!getintarg(args, &sel))
2363 return NULL;
2364 wresetselection(sel);
2365 INCREF(None);
2366 return None;
2367}
2368
Guido van Rossum0c2290b1991-04-03 19:12:14 +00002369static object *
2370stdwin_fetchcolor(self, args)
2371 object *self;
2372 object *args;
2373{
Guido van Rossumfc58e581992-01-27 16:45:55 +00002374 char *colorname;
Guido van Rossum34679b71993-01-26 13:33:44 +00002375 COLOR color;
Guido van Rossum0c2290b1991-04-03 19:12:14 +00002376 if (!getstrarg(args, &colorname))
2377 return NULL;
Guido van Rossum34679b71993-01-26 13:33:44 +00002378 color = wfetchcolor(colorname);
2379#ifdef BADCOLOR
2380 if (color == BADCOLOR) {
2381 err_setstr(StdwinError, "color name not found");
2382 return NULL;
2383 }
2384#endif
2385 return newintobject((long)color);
Guido van Rossum0c2290b1991-04-03 19:12:14 +00002386}
2387
Guido van Rossum541c8c01991-05-05 20:13:41 +00002388static object *
2389stdwin_getscrsize(self, args)
2390 object *self;
2391 object *args;
2392{
2393 int width, height;
2394 if (!getnoarg(args))
2395 return NULL;
2396 wgetscrsize(&width, &height);
2397 return makepoint(width, height);
2398}
2399
2400static object *
2401stdwin_getscrmm(self, args)
2402 object *self;
2403 object *args;
2404{
2405 int width, height;
2406 if (!getnoarg(args))
2407 return NULL;
2408 wgetscrmm(&width, &height);
2409 return makepoint(width, height);
2410}
2411
Guido van Rossumed233a51992-06-23 09:07:03 +00002412#ifdef unix
2413static object *
2414stdwin_connectionnumber(self, args)
2415 object *self;
2416 object *args;
2417{
2418 if (!getnoarg(args))
2419 return NULL;
2420 return newintobject((long) wconnectionnumber());
2421}
2422#endif
2423
Guido van Rossumbf80e541993-02-08 15:49:17 +00002424static object *
2425stdwin_listfontnames(self, args)
2426 object *self;
2427 object *args;
2428{
2429 char *pattern;
2430 char **fontnames;
2431 int count;
2432 object *list;
2433 if (!getargs(args, "z", &pattern))
2434 return NULL;
2435 fontnames = wlistfontnames(pattern, &count);
2436 list = newlistobject(count);
2437 if (list != NULL) {
2438 int i;
2439 for (i = 0; i < count; i++) {
2440 object *v = newstringobject(fontnames[i]);
2441 if (v == NULL) {
2442 DECREF(list);
2443 list = NULL;
2444 break;
2445 }
2446 setlistitem(list, i, v);
2447 }
2448 }
2449 return list;
2450}
2451
Guido van Rossume9066061993-07-29 13:14:32 +00002452#ifdef HAVE_BITMAPS
Guido van Rossumbf80e541993-02-08 15:49:17 +00002453static object *
2454stdwin_newbitmap(self, args)
2455 object *self;
2456 object *args;
2457{
2458 int width, height;
2459 bitmapobject *bp;
2460 if (!getargs(args, "(ii)", &width, &height))
2461 return NULL;
2462 return (object *)newbitmapobject(width, height);
2463}
Guido van Rossume9066061993-07-29 13:14:32 +00002464#endif
Guido van Rossumbf80e541993-02-08 15:49:17 +00002465
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002466static struct methodlist stdwin_methods[] = {
2467 {"askfile", stdwin_askfile},
2468 {"askstr", stdwin_askstr},
2469 {"askync", stdwin_askync},
Guido van Rossum27201061991-04-16 08:43:03 +00002470 {"fetchcolor", stdwin_fetchcolor},
Guido van Rossumed233a51992-06-23 09:07:03 +00002471#ifdef unix
2472 {"fileno", stdwin_connectionnumber},
2473 {"connectionnumber", stdwin_connectionnumber},
2474#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002475 {"fleep", stdwin_fleep},
Guido van Rossum246b9d81991-06-03 10:55:14 +00002476 {"getactive", stdwin_getactive},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002477 {"getcutbuffer", stdwin_getcutbuffer},
Guido van Rossum0c2290b1991-04-03 19:12:14 +00002478 {"getdefscrollbars", stdwin_getdefscrollbars},
Guido van Rossum33f17701991-02-13 23:19:39 +00002479 {"getdefwinpos", stdwin_getdefwinpos},
2480 {"getdefwinsize", stdwin_getdefwinsize},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002481 {"getevent", stdwin_getevent},
Guido van Rossum541c8c01991-05-05 20:13:41 +00002482 {"getscrmm", stdwin_getscrmm},
2483 {"getscrsize", stdwin_getscrsize},
Guido van Rossum27201061991-04-16 08:43:03 +00002484 {"getselection", stdwin_getselection},
Guido van Rossumbf80e541993-02-08 15:49:17 +00002485 {"listfontnames", stdwin_listfontnames},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002486 {"menucreate", stdwin_menucreate},
2487 {"message", stdwin_message},
Guido van Rossume9066061993-07-29 13:14:32 +00002488#ifdef HAVE_BITMAPS
Guido van Rossumbf80e541993-02-08 15:49:17 +00002489 {"newbitmap", stdwin_newbitmap},
Guido van Rossume9066061993-07-29 13:14:32 +00002490#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002491 {"open", stdwin_open},
Guido van Rossume8e7cf41991-01-16 14:06:18 +00002492 {"pollevent", stdwin_pollevent},
Guido van Rossum5b10f451990-10-30 16:01:48 +00002493 {"resetselection", stdwin_resetselection},
2494 {"rotatecutbuffers", stdwin_rotatecutbuffers},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002495 {"setcutbuffer", stdwin_setcutbuffer},
Guido van Rossum0c2290b1991-04-03 19:12:14 +00002496 {"setdefscrollbars", stdwin_setdefscrollbars},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002497 {"setdefwinpos", stdwin_setdefwinpos},
2498 {"setdefwinsize", stdwin_setdefwinsize},
2499
2500 /* Text measuring methods borrow code from drawing objects: */
2501 {"baseline", drawing_baseline},
2502 {"lineheight", drawing_lineheight},
2503 {"textbreak", drawing_textbreak},
2504 {"textwidth", drawing_textwidth},
Guido van Rossum0c2290b1991-04-03 19:12:14 +00002505
2506 /* Same for font setting methods: */
2507 {"setfont", drawing_setfont},
2508
2509 /* Same for color setting/getting methods: */
2510 {"getbgcolor", drawing_getbgcolor},
2511 {"getfgcolor", drawing_getfgcolor},
2512 {"setbgcolor", drawing_setbgcolor},
2513 {"setfgcolor", drawing_setfgcolor},
2514
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002515 {NULL, NULL} /* sentinel */
2516};
2517
2518void
2519initstdwin()
2520{
Guido van Rossumbbf94341991-12-16 15:44:53 +00002521 object *m, *d;
2522 static int inited = 0;
2523
Guido van Rossum2d14e211991-02-19 12:26:49 +00002524 if (!inited) {
2525 winit();
2526 inited = 1;
2527 }
Guido van Rossumbbf94341991-12-16 15:44:53 +00002528 m = initmodule("stdwin", stdwin_methods);
2529 d = getmoduledict(m);
2530
2531 /* Initialize stdwin.error exception */
2532 StdwinError = newstringobject("stdwin.error");
2533 if (StdwinError == NULL || dictinsert(d, "error", StdwinError) != 0)
2534 fatal("can't define stdwin.error");
Guido van Rossumff4949e1992-08-05 19:58:53 +00002535#ifdef USE_THREAD
2536 StdwinLock = allocate_lock();
2537 if (StdwinLock == NULL)
2538 fatal("can't allocate stdwin lock");
2539#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002540}