blob: e043b61d73d85e7b143a5358a4366cb04c274ba6 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Ctl =========================== */
3
4#include "Python.h"
5
6
7
8#define SystemSevenOrLater 1
9
10#include "macglue.h"
11#include <Memory.h>
12#include <Dialogs.h>
13#include <Menus.h>
14#include <Controls.h>
15
16extern PyObject *ResObj_New(Handle);
17extern int ResObj_Convert(PyObject *, Handle *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000018extern PyObject *OptResObj_New(Handle);
19extern int OptResObj_Convert(PyObject *, Handle *);
Guido van Rossum17448e21995-01-30 11:53:55 +000020
21extern PyObject *WinObj_New(WindowPtr);
22extern int WinObj_Convert(PyObject *, WindowPtr *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000023extern PyTypeObject Window_Type;
24#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
Guido van Rossum17448e21995-01-30 11:53:55 +000025
26extern PyObject *DlgObj_New(DialogPtr);
27extern int DlgObj_Convert(PyObject *, DialogPtr *);
28extern PyTypeObject Dialog_Type;
29#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
30
31extern PyObject *MenuObj_New(MenuHandle);
32extern int MenuObj_Convert(PyObject *, MenuHandle *);
33
34extern PyObject *CtlObj_New(ControlHandle);
35extern int CtlObj_Convert(PyObject *, ControlHandle *);
36
Jack Jansen425e9eb1995-12-12 15:02:03 +000037extern PyObject *GrafObj_New(GrafPtr);
38extern int GrafObj_Convert(PyObject *, GrafPtr *);
39
40extern PyObject *BMObj_New(BitMapPtr);
41extern int BMObj_Convert(PyObject *, BitMapPtr *);
42
Guido van Rossum17448e21995-01-30 11:53:55 +000043extern PyObject *WinObj_WhichWindow(WindowPtr);
44
45#include <Controls.h>
46
47#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
48
49extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
Jack Jansen21f96871998-02-20 16:02:09 +000050extern PyObject *QdRGB_New(RGBColorPtr);
51extern QdRGB_Convert(PyObject *, RGBColorPtr);
Guido van Rossum17448e21995-01-30 11:53:55 +000052
53#ifdef THINK_C
54#define ControlActionUPP ProcPtr
55#endif
56
Jack Jansen21f96871998-02-20 16:02:09 +000057/*
58** Parse/generate ControlFontStyleRec records
59*/
60#if 0 /* Not needed */
61PyObject *ControlFontStyle_New(itself)
62 ControlFontStyleRec *itself;
63{
64
65 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
66 itself->size, itself->style, itself->mode, itself->just,
67 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
68}
69#endif
70
71ControlFontStyle_Convert(v, itself)
72 PyObject *v;
73 ControlFontStyleRec *itself;
74{
75 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
76 &itself->font, &itself->size, &itself->style, &itself->mode,
77 &itself->just, QdRGB_Convert, &itself->foreColor,
78 QdRGB_Convert, &itself->backColor);
79}
80
Guido van Rossum17448e21995-01-30 11:53:55 +000081static PyObject *Ctl_Error;
82
83/* ---------------------- Object type Control ----------------------- */
84
85PyTypeObject Control_Type;
86
87#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
88
89typedef struct ControlObject {
90 PyObject_HEAD
91 ControlHandle ob_itself;
92} ControlObject;
93
94PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +000095 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +000096{
97 ControlObject *it;
98 if (itself == NULL) return PyMac_Error(resNotFound);
99 it = PyObject_NEW(ControlObject, &Control_Type);
100 if (it == NULL) return NULL;
101 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000102 SetControlReference(itself, (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +0000103 return (PyObject *)it;
104}
105CtlObj_Convert(v, p_itself)
106 PyObject *v;
107 ControlHandle *p_itself;
108{
109 if (!CtlObj_Check(v))
110 {
111 PyErr_SetString(PyExc_TypeError, "Control required");
112 return 0;
113 }
114 *p_itself = ((ControlObject *)v)->ob_itself;
115 return 1;
116}
117
118static void CtlObj_dealloc(self)
119 ControlObject *self;
120{
Jack Jansen85ae4a81997-04-08 15:26:03 +0000121 if (self->ob_itself) SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000122 PyMem_DEL(self);
123}
124
Jack Jansen21f96871998-02-20 16:02:09 +0000125static PyObject *CtlObj_HiliteControl(_self, _args)
126 ControlObject *_self;
127 PyObject *_args;
128{
129 PyObject *_res = NULL;
130 ControlPartCode hiliteState;
131 if (!PyArg_ParseTuple(_args, "h",
132 &hiliteState))
133 return NULL;
134 HiliteControl(_self->ob_itself,
135 hiliteState);
136 Py_INCREF(Py_None);
137 _res = Py_None;
138 return _res;
139}
140
Jack Jansen7d0bc831995-06-09 20:56:31 +0000141static PyObject *CtlObj_ShowControl(_self, _args)
142 ControlObject *_self;
143 PyObject *_args;
144{
145 PyObject *_res = NULL;
146 if (!PyArg_ParseTuple(_args, ""))
147 return NULL;
148 ShowControl(_self->ob_itself);
149 Py_INCREF(Py_None);
150 _res = Py_None;
151 return _res;
152}
153
154static PyObject *CtlObj_HideControl(_self, _args)
155 ControlObject *_self;
156 PyObject *_args;
157{
158 PyObject *_res = NULL;
159 if (!PyArg_ParseTuple(_args, ""))
160 return NULL;
161 HideControl(_self->ob_itself);
162 Py_INCREF(Py_None);
163 _res = Py_None;
164 return _res;
165}
166
Jack Jansen21f96871998-02-20 16:02:09 +0000167static PyObject *CtlObj_IsControlActive(_self, _args)
168 ControlObject *_self;
169 PyObject *_args;
170{
171 PyObject *_res = NULL;
172 Boolean _rv;
173 if (!PyArg_ParseTuple(_args, ""))
174 return NULL;
175 _rv = IsControlActive(_self->ob_itself);
176 _res = Py_BuildValue("b",
177 _rv);
178 return _res;
179}
180
181static PyObject *CtlObj_IsControlVisible(_self, _args)
182 ControlObject *_self;
183 PyObject *_args;
184{
185 PyObject *_res = NULL;
186 Boolean _rv;
187 if (!PyArg_ParseTuple(_args, ""))
188 return NULL;
189 _rv = IsControlVisible(_self->ob_itself);
190 _res = Py_BuildValue("b",
191 _rv);
192 return _res;
193}
194
195static PyObject *CtlObj_ActivateControl(_self, _args)
196 ControlObject *_self;
197 PyObject *_args;
198{
199 PyObject *_res = NULL;
200 OSErr _err;
201 if (!PyArg_ParseTuple(_args, ""))
202 return NULL;
203 _err = ActivateControl(_self->ob_itself);
204 if (_err != noErr) return PyMac_Error(_err);
205 Py_INCREF(Py_None);
206 _res = Py_None;
207 return _res;
208}
209
210static PyObject *CtlObj_DeactivateControl(_self, _args)
211 ControlObject *_self;
212 PyObject *_args;
213{
214 PyObject *_res = NULL;
215 OSErr _err;
216 if (!PyArg_ParseTuple(_args, ""))
217 return NULL;
218 _err = DeactivateControl(_self->ob_itself);
219 if (_err != noErr) return PyMac_Error(_err);
220 Py_INCREF(Py_None);
221 _res = Py_None;
222 return _res;
223}
224
225static PyObject *CtlObj_SetControlVisibility(_self, _args)
226 ControlObject *_self;
227 PyObject *_args;
228{
229 PyObject *_res = NULL;
230 OSErr _err;
231 Boolean inIsVisible;
232 Boolean inDoDraw;
233 if (!PyArg_ParseTuple(_args, "bb",
234 &inIsVisible,
235 &inDoDraw))
236 return NULL;
237 _err = SetControlVisibility(_self->ob_itself,
238 inIsVisible,
239 inDoDraw);
240 if (_err != noErr) return PyMac_Error(_err);
241 Py_INCREF(Py_None);
242 _res = Py_None;
243 return _res;
244}
245
Jack Jansen7d0bc831995-06-09 20:56:31 +0000246static PyObject *CtlObj_Draw1Control(_self, _args)
247 ControlObject *_self;
248 PyObject *_args;
249{
250 PyObject *_res = NULL;
251 if (!PyArg_ParseTuple(_args, ""))
252 return NULL;
253 Draw1Control(_self->ob_itself);
254 Py_INCREF(Py_None);
255 _res = Py_None;
256 return _res;
257}
258
Jack Jansen21f96871998-02-20 16:02:09 +0000259static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000260 ControlObject *_self;
261 PyObject *_args;
262{
263 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000264 OSErr _err;
265 Rect outRect;
266 SInt16 outBaseLineOffset;
267 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000268 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000269 _err = GetBestControlRect(_self->ob_itself,
270 &outRect,
271 &outBaseLineOffset);
272 if (_err != noErr) return PyMac_Error(_err);
273 _res = Py_BuildValue("O&h",
274 PyMac_BuildRect, &outRect,
275 outBaseLineOffset);
276 return _res;
277}
278
279static PyObject *CtlObj_SetControlFontStyle(_self, _args)
280 ControlObject *_self;
281 PyObject *_args;
282{
283 PyObject *_res = NULL;
284 OSErr _err;
285 ControlFontStyleRec inStyle;
286 if (!PyArg_ParseTuple(_args, "O&",
287 ControlFontStyle_Convert, &inStyle))
288 return NULL;
289 _err = SetControlFontStyle(_self->ob_itself,
290 &inStyle);
291 if (_err != noErr) return PyMac_Error(_err);
292 Py_INCREF(Py_None);
293 _res = Py_None;
294 return _res;
295}
296
297static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
298 ControlObject *_self;
299 PyObject *_args;
300{
301 PyObject *_res = NULL;
302 if (!PyArg_ParseTuple(_args, ""))
303 return NULL;
304 DrawControlInCurrentPort(_self->ob_itself);
305 Py_INCREF(Py_None);
306 _res = Py_None;
307 return _res;
308}
309
310static PyObject *CtlObj_SetUpControlBackground(_self, _args)
311 ControlObject *_self;
312 PyObject *_args;
313{
314 PyObject *_res = NULL;
315 OSErr _err;
316 SInt16 inDepth;
317 Boolean inIsColorDevice;
318 if (!PyArg_ParseTuple(_args, "hb",
319 &inDepth,
320 &inIsColorDevice))
321 return NULL;
322 _err = SetUpControlBackground(_self->ob_itself,
323 inDepth,
324 inIsColorDevice);
325 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000326 Py_INCREF(Py_None);
327 _res = Py_None;
328 return _res;
329}
330
331static PyObject *CtlObj_TrackControl(_self, _args)
332 ControlObject *_self;
333 PyObject *_args;
334{
335 PyObject *_res = NULL;
336 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000337 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000338 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000339 PyMac_GetPoint, &startPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000340 return NULL;
341 _rv = TrackControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000342 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000343 (ControlActionUPP)0);
344 _res = Py_BuildValue("h",
345 _rv);
346 return _res;
347}
348
349static PyObject *CtlObj_DragControl(_self, _args)
350 ControlObject *_self;
351 PyObject *_args;
352{
353 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000354 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000355 Rect limitRect;
356 Rect slopRect;
357 DragConstraint axis;
358 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000359 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000360 PyMac_GetRect, &limitRect,
361 PyMac_GetRect, &slopRect,
362 &axis))
363 return NULL;
364 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000365 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000366 &limitRect,
367 &slopRect,
368 axis);
369 Py_INCREF(Py_None);
370 _res = Py_None;
371 return _res;
372}
373
374static PyObject *CtlObj_TestControl(_self, _args)
375 ControlObject *_self;
376 PyObject *_args;
377{
378 PyObject *_res = NULL;
379 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000380 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000381 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000382 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000383 return NULL;
384 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000385 testPoint);
386 _res = Py_BuildValue("h",
387 _rv);
388 return _res;
389}
390
391static PyObject *CtlObj_HandleControlKey(_self, _args)
392 ControlObject *_self;
393 PyObject *_args;
394{
395 PyObject *_res = NULL;
396 SInt16 _rv;
397 SInt16 inKeyCode;
398 SInt16 inCharCode;
399 SInt16 inModifiers;
400 if (!PyArg_ParseTuple(_args, "hhh",
401 &inKeyCode,
402 &inCharCode,
403 &inModifiers))
404 return NULL;
405 _rv = HandleControlKey(_self->ob_itself,
406 inKeyCode,
407 inCharCode,
408 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000409 _res = Py_BuildValue("h",
410 _rv);
411 return _res;
412}
413
414static PyObject *CtlObj_MoveControl(_self, _args)
415 ControlObject *_self;
416 PyObject *_args;
417{
418 PyObject *_res = NULL;
419 SInt16 h;
420 SInt16 v;
421 if (!PyArg_ParseTuple(_args, "hh",
422 &h,
423 &v))
424 return NULL;
425 MoveControl(_self->ob_itself,
426 h,
427 v);
428 Py_INCREF(Py_None);
429 _res = Py_None;
430 return _res;
431}
432
433static PyObject *CtlObj_SizeControl(_self, _args)
434 ControlObject *_self;
435 PyObject *_args;
436{
437 PyObject *_res = NULL;
438 SInt16 w;
439 SInt16 h;
440 if (!PyArg_ParseTuple(_args, "hh",
441 &w,
442 &h))
443 return NULL;
444 SizeControl(_self->ob_itself,
445 w,
446 h);
447 Py_INCREF(Py_None);
448 _res = Py_None;
449 return _res;
450}
451
Jack Jansenae8a68f1995-06-06 12:55:40 +0000452static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000453 ControlObject *_self;
454 PyObject *_args;
455{
456 PyObject *_res = NULL;
457 Str255 title;
458 if (!PyArg_ParseTuple(_args, "O&",
459 PyMac_GetStr255, title))
460 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000461 SetControlTitle(_self->ob_itself,
462 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000463 Py_INCREF(Py_None);
464 _res = Py_None;
465 return _res;
466}
467
Jack Jansenae8a68f1995-06-06 12:55:40 +0000468static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000469 ControlObject *_self;
470 PyObject *_args;
471{
472 PyObject *_res = NULL;
473 Str255 title;
474 if (!PyArg_ParseTuple(_args, "O&",
475 PyMac_GetStr255, title))
476 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000477 GetControlTitle(_self->ob_itself,
478 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000479 Py_INCREF(Py_None);
480 _res = Py_None;
481 return _res;
482}
483
Jack Jansenae8a68f1995-06-06 12:55:40 +0000484static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000485 ControlObject *_self;
486 PyObject *_args;
487{
488 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000489 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000490 if (!PyArg_ParseTuple(_args, ""))
491 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000492 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000493 _res = Py_BuildValue("h",
494 _rv);
495 return _res;
496}
497
Jack Jansen7d0bc831995-06-09 20:56:31 +0000498static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000499 ControlObject *_self;
500 PyObject *_args;
501{
502 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000503 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000504 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000505 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000506 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000507 SetControlValue(_self->ob_itself,
508 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000509 Py_INCREF(Py_None);
510 _res = Py_None;
511 return _res;
512}
513
Jack Jansenae8a68f1995-06-06 12:55:40 +0000514static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000515 ControlObject *_self;
516 PyObject *_args;
517{
518 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000519 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000520 if (!PyArg_ParseTuple(_args, ""))
521 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000522 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000523 _res = Py_BuildValue("h",
524 _rv);
525 return _res;
526}
527
Jack Jansen7d0bc831995-06-09 20:56:31 +0000528static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000529 ControlObject *_self;
530 PyObject *_args;
531{
532 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000533 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000534 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000535 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000536 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000537 SetControlMinimum(_self->ob_itself,
538 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000539 Py_INCREF(Py_None);
540 _res = Py_None;
541 return _res;
542}
543
Jack Jansenae8a68f1995-06-06 12:55:40 +0000544static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000545 ControlObject *_self;
546 PyObject *_args;
547{
548 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000549 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000550 if (!PyArg_ParseTuple(_args, ""))
551 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000552 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000553 _res = Py_BuildValue("h",
554 _rv);
555 return _res;
556}
557
Jack Jansen7d0bc831995-06-09 20:56:31 +0000558static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000559 ControlObject *_self;
560 PyObject *_args;
561{
562 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000563 SInt16 newMaximum;
564 if (!PyArg_ParseTuple(_args, "h",
565 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000566 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000567 SetControlMaximum(_self->ob_itself,
568 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000569 Py_INCREF(Py_None);
570 _res = Py_None;
571 return _res;
572}
573
Jack Jansen7d0bc831995-06-09 20:56:31 +0000574static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000575 ControlObject *_self;
576 PyObject *_args;
577{
578 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000579 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000580 if (!PyArg_ParseTuple(_args, ""))
581 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000582 _rv = GetControlVariant(_self->ob_itself);
583 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000584 _rv);
585 return _res;
586}
587
Jack Jansenae8a68f1995-06-06 12:55:40 +0000588static PyObject *CtlObj_SetControlAction(_self, _args)
589 ControlObject *_self;
590 PyObject *_args;
591{
592 PyObject *_res = NULL;
593 if (!PyArg_ParseTuple(_args, ""))
594 return NULL;
595 SetControlAction(_self->ob_itself,
596 (ControlActionUPP)0);
597 Py_INCREF(Py_None);
598 _res = Py_None;
599 return _res;
600}
601
Jack Jansen7d0bc831995-06-09 20:56:31 +0000602static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000603 ControlObject *_self;
604 PyObject *_args;
605{
606 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000607 SInt32 data;
608 if (!PyArg_ParseTuple(_args, "l",
609 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000610 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000611 SetControlReference(_self->ob_itself,
612 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000613 Py_INCREF(Py_None);
614 _res = Py_None;
615 return _res;
616}
617
Jack Jansen7d0bc831995-06-09 20:56:31 +0000618static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000619 ControlObject *_self;
620 PyObject *_args;
621{
622 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000623 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000624 if (!PyArg_ParseTuple(_args, ""))
625 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000626 _rv = GetControlReference(_self->ob_itself);
627 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000628 _rv);
629 return _res;
630}
631
Jack Jansenc7fefed1997-08-15 14:32:18 +0000632static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
633 ControlObject *_self;
634 PyObject *_args;
635{
636 PyObject *_res = NULL;
637 Boolean _rv;
638 AuxCtlHandle acHndl;
639 if (!PyArg_ParseTuple(_args, ""))
640 return NULL;
641 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
642 &acHndl);
643 _res = Py_BuildValue("bO&",
644 _rv,
645 ResObj_New, acHndl);
646 return _res;
647}
648
649static PyObject *CtlObj_SetControlColor(_self, _args)
650 ControlObject *_self;
651 PyObject *_args;
652{
653 PyObject *_res = NULL;
654 CCTabHandle newColorTable;
655 if (!PyArg_ParseTuple(_args, "O&",
656 ResObj_Convert, &newColorTable))
657 return NULL;
658 SetControlColor(_self->ob_itself,
659 newColorTable);
660 Py_INCREF(Py_None);
661 _res = Py_None;
662 return _res;
663}
664
Jack Jansen21f96871998-02-20 16:02:09 +0000665static PyObject *CtlObj_SendControlMessage(_self, _args)
666 ControlObject *_self;
667 PyObject *_args;
668{
669 PyObject *_res = NULL;
670 SInt32 _rv;
671 SInt16 inMessage;
672 SInt32 inParam;
673 if (!PyArg_ParseTuple(_args, "hl",
674 &inMessage,
675 &inParam))
676 return NULL;
677 _rv = SendControlMessage(_self->ob_itself,
678 inMessage,
679 inParam);
680 _res = Py_BuildValue("l",
681 _rv);
682 return _res;
683}
684
685static PyObject *CtlObj_EmbedControl(_self, _args)
686 ControlObject *_self;
687 PyObject *_args;
688{
689 PyObject *_res = NULL;
690 OSErr _err;
691 ControlHandle inContainer;
692 if (!PyArg_ParseTuple(_args, "O&",
693 CtlObj_Convert, &inContainer))
694 return NULL;
695 _err = EmbedControl(_self->ob_itself,
696 inContainer);
697 if (_err != noErr) return PyMac_Error(_err);
698 Py_INCREF(Py_None);
699 _res = Py_None;
700 return _res;
701}
702
703static PyObject *CtlObj_AutoEmbedControl(_self, _args)
704 ControlObject *_self;
705 PyObject *_args;
706{
707 PyObject *_res = NULL;
708 OSErr _err;
709 WindowPtr inWindow;
710 if (!PyArg_ParseTuple(_args, "O&",
711 WinObj_Convert, &inWindow))
712 return NULL;
713 _err = AutoEmbedControl(_self->ob_itself,
714 inWindow);
715 if (_err != noErr) return PyMac_Error(_err);
716 Py_INCREF(Py_None);
717 _res = Py_None;
718 return _res;
719}
720
721static PyObject *CtlObj_GetSuperControl(_self, _args)
722 ControlObject *_self;
723 PyObject *_args;
724{
725 PyObject *_res = NULL;
726 OSErr _err;
727 ControlHandle outParent;
728 if (!PyArg_ParseTuple(_args, ""))
729 return NULL;
730 _err = GetSuperControl(_self->ob_itself,
731 &outParent);
732 if (_err != noErr) return PyMac_Error(_err);
733 _res = Py_BuildValue("O&",
734 CtlObj_WhichControl, outParent);
735 return _res;
736}
737
738static PyObject *CtlObj_CountSubControls(_self, _args)
739 ControlObject *_self;
740 PyObject *_args;
741{
742 PyObject *_res = NULL;
743 OSErr _err;
744 SInt16 outNumChildren;
745 if (!PyArg_ParseTuple(_args, ""))
746 return NULL;
747 _err = CountSubControls(_self->ob_itself,
748 &outNumChildren);
749 if (_err != noErr) return PyMac_Error(_err);
750 _res = Py_BuildValue("h",
751 outNumChildren);
752 return _res;
753}
754
755static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
756 ControlObject *_self;
757 PyObject *_args;
758{
759 PyObject *_res = NULL;
760 OSErr _err;
761 SInt16 inIndex;
762 ControlHandle outSubControl;
763 if (!PyArg_ParseTuple(_args, "h",
764 &inIndex))
765 return NULL;
766 _err = GetIndexedSubControl(_self->ob_itself,
767 inIndex,
768 &outSubControl);
769 if (_err != noErr) return PyMac_Error(_err);
770 _res = Py_BuildValue("O&",
771 CtlObj_WhichControl, outSubControl);
772 return _res;
773}
774
775static PyObject *CtlObj_SetControlSupervisor(_self, _args)
776 ControlObject *_self;
777 PyObject *_args;
778{
779 PyObject *_res = NULL;
780 OSErr _err;
781 ControlHandle inBoss;
782 if (!PyArg_ParseTuple(_args, "O&",
783 CtlObj_Convert, &inBoss))
784 return NULL;
785 _err = SetControlSupervisor(_self->ob_itself,
786 inBoss);
787 if (_err != noErr) return PyMac_Error(_err);
788 Py_INCREF(Py_None);
789 _res = Py_None;
790 return _res;
791}
792
793static PyObject *CtlObj_GetControlFeatures(_self, _args)
794 ControlObject *_self;
795 PyObject *_args;
796{
797 PyObject *_res = NULL;
798 OSErr _err;
799 UInt32 outFeatures;
800 if (!PyArg_ParseTuple(_args, ""))
801 return NULL;
802 _err = GetControlFeatures(_self->ob_itself,
803 &outFeatures);
804 if (_err != noErr) return PyMac_Error(_err);
805 _res = Py_BuildValue("l",
806 outFeatures);
807 return _res;
808}
809
810static PyObject *CtlObj_GetControlDataSize(_self, _args)
811 ControlObject *_self;
812 PyObject *_args;
813{
814 PyObject *_res = NULL;
815 OSErr _err;
816 ControlPartCode inPart;
817 ResType inTagName;
818 Size outMaxSize;
819 if (!PyArg_ParseTuple(_args, "hO&",
820 &inPart,
821 PyMac_GetOSType, &inTagName))
822 return NULL;
823 _err = GetControlDataSize(_self->ob_itself,
824 inPart,
825 inTagName,
826 &outMaxSize);
827 if (_err != noErr) return PyMac_Error(_err);
828 _res = Py_BuildValue("l",
829 outMaxSize);
830 return _res;
831}
832
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000833static PyObject *CtlObj_as_Resource(_self, _args)
834 ControlObject *_self;
835 PyObject *_args;
836{
837 PyObject *_res = NULL;
838
839 return ResObj_New((Handle)_self->ob_itself);
840
841}
842
Jack Jansencfb60ee1996-10-01 10:46:46 +0000843static PyObject *CtlObj_DisposeControl(_self, _args)
844 ControlObject *_self;
845 PyObject *_args;
846{
847 PyObject *_res = NULL;
848
849 if (!PyArg_ParseTuple(_args, ""))
850 return NULL;
851 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +0000852 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +0000853 DisposeControl(_self->ob_itself);
854 _self->ob_itself = NULL;
855 }
856 Py_INCREF(Py_None);
857 _res = Py_None;
858 return _res;
859
860}
861
Guido van Rossum17448e21995-01-30 11:53:55 +0000862static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +0000863 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
864 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000865 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
866 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000867 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
868 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000869 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
870 "() -> (Boolean _rv)"},
871 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
872 "() -> (Boolean _rv)"},
873 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
874 "() -> None"},
875 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
876 "() -> None"},
877 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
878 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000879 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
880 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000881 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
882 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
883 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
884 "(ControlFontStyleRec inStyle) -> None"},
885 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
886 "() -> None"},
887 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
888 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000889 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000890 "(Point startPoint) -> (ControlPartCode _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000891 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000892 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000893 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000894 "(Point testPoint) -> (ControlPartCode _rv)"},
895 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
896 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000897 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000898 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000899 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000900 "(SInt16 w, SInt16 h) -> None"},
901 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
902 "(Str255 title) -> None"},
903 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
904 "(Str255 title) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000905 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000906 "() -> (SInt16 _rv)"},
907 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
908 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000909 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000910 "() -> (SInt16 _rv)"},
911 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
912 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000913 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000914 "() -> (SInt16 _rv)"},
915 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
916 "(SInt16 newMaximum) -> None"},
917 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000918 "() -> (ControlVariant _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000919 {"SetControlAction", (PyCFunction)CtlObj_SetControlAction, 1,
920 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000921 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
922 "(SInt32 data) -> None"},
923 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
924 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +0000925 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
926 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
927 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
928 "(CCTabHandle newColorTable) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +0000929 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
930 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
931 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
932 "(ControlHandle inContainer) -> None"},
933 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
934 "(WindowPtr inWindow) -> None"},
935 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
936 "() -> (ControlHandle outParent)"},
937 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
938 "() -> (SInt16 outNumChildren)"},
939 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
940 "(SInt16 inIndex) -> (ControlHandle outSubControl)"},
941 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
942 "(ControlHandle inBoss) -> None"},
943 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
944 "() -> (UInt32 outFeatures)"},
945 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
946 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000947 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
948 "Return this Control as a Resource"},
Jack Jansencfb60ee1996-10-01 10:46:46 +0000949 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
950 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000951 {NULL, NULL, 0}
952};
953
954PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
955
956static PyObject *CtlObj_getattr(self, name)
957 ControlObject *self;
958 char *name;
959{
960 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
961}
962
963#define CtlObj_setattr NULL
964
965PyTypeObject Control_Type = {
966 PyObject_HEAD_INIT(&PyType_Type)
967 0, /*ob_size*/
968 "Control", /*tp_name*/
969 sizeof(ControlObject), /*tp_basicsize*/
970 0, /*tp_itemsize*/
971 /* methods */
972 (destructor) CtlObj_dealloc, /*tp_dealloc*/
973 0, /*tp_print*/
974 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
975 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
976};
977
978/* -------------------- End object type Control --------------------- */
979
980
981static PyObject *Ctl_NewControl(_self, _args)
982 PyObject *_self;
983 PyObject *_args;
984{
985 PyObject *_res = NULL;
986 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000987 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +0000988 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +0000989 Str255 controlTitle;
990 Boolean initiallyVisible;
991 SInt16 initialValue;
992 SInt16 minimumValue;
993 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000994 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +0000995 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +0000996 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +0000997 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +0000998 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +0000999 PyMac_GetStr255, controlTitle,
1000 &initiallyVisible,
1001 &initialValue,
1002 &minimumValue,
1003 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001004 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001005 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001006 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001007 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001008 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001009 controlTitle,
1010 initiallyVisible,
1011 initialValue,
1012 minimumValue,
1013 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001014 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001015 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001016 _res = Py_BuildValue("O&",
1017 CtlObj_New, _rv);
1018 return _res;
1019}
1020
1021static PyObject *Ctl_GetNewControl(_self, _args)
1022 PyObject *_self;
1023 PyObject *_args;
1024{
1025 PyObject *_res = NULL;
1026 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001027 SInt16 resourceID;
1028 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001029 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001030 &resourceID,
1031 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001032 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001033 _rv = GetNewControl(resourceID,
1034 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001035 _res = Py_BuildValue("O&",
1036 CtlObj_New, _rv);
1037 return _res;
1038}
1039
Guido van Rossum17448e21995-01-30 11:53:55 +00001040static PyObject *Ctl_DrawControls(_self, _args)
1041 PyObject *_self;
1042 PyObject *_args;
1043{
1044 PyObject *_res = NULL;
1045 WindowPtr theWindow;
1046 if (!PyArg_ParseTuple(_args, "O&",
1047 WinObj_Convert, &theWindow))
1048 return NULL;
1049 DrawControls(theWindow);
1050 Py_INCREF(Py_None);
1051 _res = Py_None;
1052 return _res;
1053}
1054
Guido van Rossum17448e21995-01-30 11:53:55 +00001055static PyObject *Ctl_UpdateControls(_self, _args)
1056 PyObject *_self;
1057 PyObject *_args;
1058{
1059 PyObject *_res = NULL;
1060 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001061 RgnHandle updateRegion;
1062 if (!PyArg_ParseTuple(_args, "O&O&",
1063 WinObj_Convert, &theWindow,
1064 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001065 return NULL;
1066 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001067 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001068 Py_INCREF(Py_None);
1069 _res = Py_None;
1070 return _res;
1071}
1072
1073static PyObject *Ctl_FindControl(_self, _args)
1074 PyObject *_self;
1075 PyObject *_args;
1076{
1077 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001078 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001079 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001080 WindowPtr theWindow;
1081 ControlHandle theControl;
1082 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001083 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001084 WinObj_Convert, &theWindow))
1085 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001086 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001087 theWindow,
1088 &theControl);
1089 _res = Py_BuildValue("hO&",
1090 _rv,
1091 CtlObj_WhichControl, theControl);
1092 return _res;
1093}
1094
Jack Jansen21f96871998-02-20 16:02:09 +00001095static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1096 PyObject *_self;
1097 PyObject *_args;
1098{
1099 PyObject *_res = NULL;
1100 ControlHandle _rv;
1101 Point inWhere;
1102 WindowPtr inWindow;
1103 SInt16 outPart;
1104 if (!PyArg_ParseTuple(_args, "O&O&",
1105 PyMac_GetPoint, &inWhere,
1106 WinObj_Convert, &inWindow))
1107 return NULL;
1108 _rv = FindControlUnderMouse(inWhere,
1109 inWindow,
1110 &outPart);
1111 _res = Py_BuildValue("O&h",
1112 CtlObj_New, _rv,
1113 outPart);
1114 return _res;
1115}
1116
1117static PyObject *Ctl_IdleControls(_self, _args)
1118 PyObject *_self;
1119 PyObject *_args;
1120{
1121 PyObject *_res = NULL;
1122 WindowPtr inWindow;
1123 if (!PyArg_ParseTuple(_args, "O&",
1124 WinObj_Convert, &inWindow))
1125 return NULL;
1126 IdleControls(inWindow);
1127 Py_INCREF(Py_None);
1128 _res = Py_None;
1129 return _res;
1130}
1131
1132static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1133 PyObject *_self;
1134 PyObject *_args;
1135{
1136 PyObject *_res = NULL;
1137 OSErr _err;
1138 WindowPtr inWindow;
1139 FSSpec inDumpFile;
1140 if (!PyArg_ParseTuple(_args, "O&O&",
1141 WinObj_Convert, &inWindow,
1142 PyMac_GetFSSpec, &inDumpFile))
1143 return NULL;
1144 _err = DumpControlHierarchy(inWindow,
1145 &inDumpFile);
1146 if (_err != noErr) return PyMac_Error(_err);
1147 Py_INCREF(Py_None);
1148 _res = Py_None;
1149 return _res;
1150}
1151
1152static PyObject *Ctl_CreateRootControl(_self, _args)
1153 PyObject *_self;
1154 PyObject *_args;
1155{
1156 PyObject *_res = NULL;
1157 OSErr _err;
1158 WindowPtr inWindow;
1159 ControlHandle outControl;
1160 if (!PyArg_ParseTuple(_args, "O&",
1161 WinObj_Convert, &inWindow))
1162 return NULL;
1163 _err = CreateRootControl(inWindow,
1164 &outControl);
1165 if (_err != noErr) return PyMac_Error(_err);
1166 _res = Py_BuildValue("O&",
1167 CtlObj_WhichControl, outControl);
1168 return _res;
1169}
1170
1171static PyObject *Ctl_GetRootControl(_self, _args)
1172 PyObject *_self;
1173 PyObject *_args;
1174{
1175 PyObject *_res = NULL;
1176 OSErr _err;
1177 WindowPtr inWindow;
1178 ControlHandle outControl;
1179 if (!PyArg_ParseTuple(_args, "O&",
1180 WinObj_Convert, &inWindow))
1181 return NULL;
1182 _err = GetRootControl(inWindow,
1183 &outControl);
1184 if (_err != noErr) return PyMac_Error(_err);
1185 _res = Py_BuildValue("O&",
1186 CtlObj_WhichControl, outControl);
1187 return _res;
1188}
1189
1190static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1191 PyObject *_self;
1192 PyObject *_args;
1193{
1194 PyObject *_res = NULL;
1195 OSErr _err;
1196 WindowPtr inWindow;
1197 ControlHandle outControl;
1198 if (!PyArg_ParseTuple(_args, "O&",
1199 WinObj_Convert, &inWindow))
1200 return NULL;
1201 _err = GetKeyboardFocus(inWindow,
1202 &outControl);
1203 if (_err != noErr) return PyMac_Error(_err);
1204 _res = Py_BuildValue("O&",
1205 CtlObj_WhichControl, outControl);
1206 return _res;
1207}
1208
1209static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1210 PyObject *_self;
1211 PyObject *_args;
1212{
1213 PyObject *_res = NULL;
1214 OSErr _err;
1215 WindowPtr inWindow;
1216 ControlHandle inControl;
1217 ControlFocusPart inPart;
1218 if (!PyArg_ParseTuple(_args, "O&O&h",
1219 WinObj_Convert, &inWindow,
1220 CtlObj_Convert, &inControl,
1221 &inPart))
1222 return NULL;
1223 _err = SetKeyboardFocus(inWindow,
1224 inControl,
1225 inPart);
1226 if (_err != noErr) return PyMac_Error(_err);
1227 Py_INCREF(Py_None);
1228 _res = Py_None;
1229 return _res;
1230}
1231
1232static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1233 PyObject *_self;
1234 PyObject *_args;
1235{
1236 PyObject *_res = NULL;
1237 OSErr _err;
1238 WindowPtr inWindow;
1239 if (!PyArg_ParseTuple(_args, "O&",
1240 WinObj_Convert, &inWindow))
1241 return NULL;
1242 _err = AdvanceKeyboardFocus(inWindow);
1243 if (_err != noErr) return PyMac_Error(_err);
1244 Py_INCREF(Py_None);
1245 _res = Py_None;
1246 return _res;
1247}
1248
1249static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1250 PyObject *_self;
1251 PyObject *_args;
1252{
1253 PyObject *_res = NULL;
1254 OSErr _err;
1255 WindowPtr inWindow;
1256 if (!PyArg_ParseTuple(_args, "O&",
1257 WinObj_Convert, &inWindow))
1258 return NULL;
1259 _err = ReverseKeyboardFocus(inWindow);
1260 if (_err != noErr) return PyMac_Error(_err);
1261 Py_INCREF(Py_None);
1262 _res = Py_None;
1263 return _res;
1264}
1265
1266static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
1267 PyObject *_self;
1268 PyObject *_args;
1269{
1270 PyObject *_res = NULL;
1271 OSErr _err;
1272 WindowPtr inWindow;
1273 if (!PyArg_ParseTuple(_args, "O&",
1274 WinObj_Convert, &inWindow))
1275 return NULL;
1276 _err = ClearKeyboardFocus(inWindow);
1277 if (_err != noErr) return PyMac_Error(_err);
1278 Py_INCREF(Py_None);
1279 _res = Py_None;
1280 return _res;
1281}
1282
Guido van Rossum17448e21995-01-30 11:53:55 +00001283static PyMethodDef Ctl_methods[] = {
1284 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001285 "(WindowPtr owningWindow, Rect boundsRect, Str255 controlTitle, Boolean initiallyVisible, SInt16 initialValue, SInt16 minimumValue, SInt16 maximumValue, SInt16 procID, SInt32 controlReference) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001286 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001287 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001288 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1289 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001290 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001291 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001292 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001293 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1294 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1295 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1296 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1297 "(WindowPtr inWindow) -> None"},
1298 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1299 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1300 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1301 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1302 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1303 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1304 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1305 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1306 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1307 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1308 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1309 "(WindowPtr inWindow) -> None"},
1310 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1311 "(WindowPtr inWindow) -> None"},
1312 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1313 "(WindowPtr inWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001314 {NULL, NULL, 0}
1315};
1316
1317
1318
1319PyObject *
1320CtlObj_WhichControl(ControlHandle c)
1321{
1322 PyObject *it;
1323
1324 /* XXX What if we find a control belonging to some other package? */
1325 if (c == NULL)
1326 it = NULL;
1327 else
Jack Jansen85ae4a81997-04-08 15:26:03 +00001328 it = (PyObject *) GetControlReference(c);
Guido van Rossum17448e21995-01-30 11:53:55 +00001329 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1330 it = Py_None;
1331 Py_INCREF(it);
1332 return it;
1333}
1334
1335
1336void initCtl()
1337{
1338 PyObject *m;
1339 PyObject *d;
1340
1341
1342
1343
1344 m = Py_InitModule("Ctl", Ctl_methods);
1345 d = PyModule_GetDict(m);
1346 Ctl_Error = PyMac_GetOSErrException();
1347 if (Ctl_Error == NULL ||
1348 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
1349 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001350 Control_Type.ob_type = &PyType_Type;
1351 Py_INCREF(&Control_Type);
1352 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
1353 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00001354}
1355
1356/* ========================= End module Ctl ========================= */
1357