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