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