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