blob: 32788bcdb7719298f1d597624587f8e37f035d7c [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
Jack Jansene0581891999-02-07 14:02:03 +000047#define as_Control(h) ((ControlHandle)h)
Jack Jansena1a0fef1999-12-23 14:32:06 +000048#define as_Resource(ctl) ((Handle)ctl)
Jack Jansen1a7d5b12000-03-21 16:25:23 +000049#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
Jack Jansene0581891999-02-07 14:02:03 +000050
Guido van Rossum17448e21995-01-30 11:53:55 +000051#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
52
53extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
Jack Jansen21f96871998-02-20 16:02:09 +000054extern PyObject *QdRGB_New(RGBColorPtr);
55extern QdRGB_Convert(PyObject *, RGBColorPtr);
Guido van Rossum17448e21995-01-30 11:53:55 +000056
57#ifdef THINK_C
58#define ControlActionUPP ProcPtr
59#endif
60
Jack Jansen21f96871998-02-20 16:02:09 +000061/*
62** Parse/generate ControlFontStyleRec records
63*/
64#if 0 /* Not needed */
65PyObject *ControlFontStyle_New(itself)
66 ControlFontStyleRec *itself;
67{
68
69 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
70 itself->size, itself->style, itself->mode, itself->just,
71 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
72}
73#endif
74
75ControlFontStyle_Convert(v, itself)
76 PyObject *v;
77 ControlFontStyleRec *itself;
78{
79 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000080 &itself->font, &itself->size, &itself->style, &itself->mode,
81 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000082 QdRGB_Convert, &itself->backColor);
83}
84
Jack Jansen24c35311999-12-09 22:49:51 +000085/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000086static PyObject *tracker;
87static ControlActionUPP mytracker_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +000088static ControlUserPaneDrawUPP mydrawproc_upp;
89static ControlUserPaneIdleUPP myidleproc_upp;
Jack Jansen848250c1998-05-28 14:20:09 +000090
91extern int settrackfunc(PyObject *); /* forward */
92extern void clrtrackfunc(void); /* forward */
93
Guido van Rossum17448e21995-01-30 11:53:55 +000094static PyObject *Ctl_Error;
95
96/* ---------------------- Object type Control ----------------------- */
97
98PyTypeObject Control_Type;
99
100#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
101
102typedef struct ControlObject {
103 PyObject_HEAD
104 ControlHandle ob_itself;
Jack Jansenabc411b2000-03-20 16:09:09 +0000105 PyObject *ob_callbackdict;
Guido van Rossum17448e21995-01-30 11:53:55 +0000106} ControlObject;
107
108PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000109 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000110{
111 ControlObject *it;
112 if (itself == NULL) return PyMac_Error(resNotFound);
113 it = PyObject_NEW(ControlObject, &Control_Type);
114 if (it == NULL) return NULL;
115 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000116 SetControlReference(itself, (long)it);
Jack Jansenabc411b2000-03-20 16:09:09 +0000117 it->ob_callbackdict = NULL;
Guido van Rossum17448e21995-01-30 11:53:55 +0000118 return (PyObject *)it;
119}
120CtlObj_Convert(v, p_itself)
121 PyObject *v;
122 ControlHandle *p_itself;
123{
124 if (!CtlObj_Check(v))
125 {
126 PyErr_SetString(PyExc_TypeError, "Control required");
127 return 0;
128 }
129 *p_itself = ((ControlObject *)v)->ob_itself;
130 return 1;
131}
132
133static void CtlObj_dealloc(self)
134 ControlObject *self;
135{
Jack Jansenabc411b2000-03-20 16:09:09 +0000136 Py_XDECREF(self->ob_callbackdict);
Jack Jansen24c35311999-12-09 22:49:51 +0000137 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000138 PyMem_DEL(self);
139}
140
Jack Jansen21f96871998-02-20 16:02:09 +0000141static PyObject *CtlObj_HiliteControl(_self, _args)
142 ControlObject *_self;
143 PyObject *_args;
144{
145 PyObject *_res = NULL;
146 ControlPartCode hiliteState;
147 if (!PyArg_ParseTuple(_args, "h",
148 &hiliteState))
149 return NULL;
150 HiliteControl(_self->ob_itself,
151 hiliteState);
152 Py_INCREF(Py_None);
153 _res = Py_None;
154 return _res;
155}
156
Jack Jansen7d0bc831995-06-09 20:56:31 +0000157static PyObject *CtlObj_ShowControl(_self, _args)
158 ControlObject *_self;
159 PyObject *_args;
160{
161 PyObject *_res = NULL;
162 if (!PyArg_ParseTuple(_args, ""))
163 return NULL;
164 ShowControl(_self->ob_itself);
165 Py_INCREF(Py_None);
166 _res = Py_None;
167 return _res;
168}
169
170static PyObject *CtlObj_HideControl(_self, _args)
171 ControlObject *_self;
172 PyObject *_args;
173{
174 PyObject *_res = NULL;
175 if (!PyArg_ParseTuple(_args, ""))
176 return NULL;
177 HideControl(_self->ob_itself);
178 Py_INCREF(Py_None);
179 _res = Py_None;
180 return _res;
181}
182
Jack Jansen21f96871998-02-20 16:02:09 +0000183static PyObject *CtlObj_IsControlActive(_self, _args)
184 ControlObject *_self;
185 PyObject *_args;
186{
187 PyObject *_res = NULL;
188 Boolean _rv;
189 if (!PyArg_ParseTuple(_args, ""))
190 return NULL;
191 _rv = IsControlActive(_self->ob_itself);
192 _res = Py_BuildValue("b",
193 _rv);
194 return _res;
195}
196
197static PyObject *CtlObj_IsControlVisible(_self, _args)
198 ControlObject *_self;
199 PyObject *_args;
200{
201 PyObject *_res = NULL;
202 Boolean _rv;
203 if (!PyArg_ParseTuple(_args, ""))
204 return NULL;
205 _rv = IsControlVisible(_self->ob_itself);
206 _res = Py_BuildValue("b",
207 _rv);
208 return _res;
209}
210
211static PyObject *CtlObj_ActivateControl(_self, _args)
212 ControlObject *_self;
213 PyObject *_args;
214{
215 PyObject *_res = NULL;
216 OSErr _err;
217 if (!PyArg_ParseTuple(_args, ""))
218 return NULL;
219 _err = ActivateControl(_self->ob_itself);
220 if (_err != noErr) return PyMac_Error(_err);
221 Py_INCREF(Py_None);
222 _res = Py_None;
223 return _res;
224}
225
226static PyObject *CtlObj_DeactivateControl(_self, _args)
227 ControlObject *_self;
228 PyObject *_args;
229{
230 PyObject *_res = NULL;
231 OSErr _err;
232 if (!PyArg_ParseTuple(_args, ""))
233 return NULL;
234 _err = DeactivateControl(_self->ob_itself);
235 if (_err != noErr) return PyMac_Error(_err);
236 Py_INCREF(Py_None);
237 _res = Py_None;
238 return _res;
239}
240
241static PyObject *CtlObj_SetControlVisibility(_self, _args)
242 ControlObject *_self;
243 PyObject *_args;
244{
245 PyObject *_res = NULL;
246 OSErr _err;
247 Boolean inIsVisible;
248 Boolean inDoDraw;
249 if (!PyArg_ParseTuple(_args, "bb",
250 &inIsVisible,
251 &inDoDraw))
252 return NULL;
253 _err = SetControlVisibility(_self->ob_itself,
254 inIsVisible,
255 inDoDraw);
256 if (_err != noErr) return PyMac_Error(_err);
257 Py_INCREF(Py_None);
258 _res = Py_None;
259 return _res;
260}
261
Jack Jansen7d0bc831995-06-09 20:56:31 +0000262static PyObject *CtlObj_Draw1Control(_self, _args)
263 ControlObject *_self;
264 PyObject *_args;
265{
266 PyObject *_res = NULL;
267 if (!PyArg_ParseTuple(_args, ""))
268 return NULL;
269 Draw1Control(_self->ob_itself);
270 Py_INCREF(Py_None);
271 _res = Py_None;
272 return _res;
273}
274
Jack Jansen21f96871998-02-20 16:02:09 +0000275static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000276 ControlObject *_self;
277 PyObject *_args;
278{
279 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000280 OSErr _err;
281 Rect outRect;
282 SInt16 outBaseLineOffset;
283 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000284 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000285 _err = GetBestControlRect(_self->ob_itself,
286 &outRect,
287 &outBaseLineOffset);
288 if (_err != noErr) return PyMac_Error(_err);
289 _res = Py_BuildValue("O&h",
290 PyMac_BuildRect, &outRect,
291 outBaseLineOffset);
292 return _res;
293}
294
295static PyObject *CtlObj_SetControlFontStyle(_self, _args)
296 ControlObject *_self;
297 PyObject *_args;
298{
299 PyObject *_res = NULL;
300 OSErr _err;
301 ControlFontStyleRec inStyle;
302 if (!PyArg_ParseTuple(_args, "O&",
303 ControlFontStyle_Convert, &inStyle))
304 return NULL;
305 _err = SetControlFontStyle(_self->ob_itself,
306 &inStyle);
307 if (_err != noErr) return PyMac_Error(_err);
308 Py_INCREF(Py_None);
309 _res = Py_None;
310 return _res;
311}
312
313static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
314 ControlObject *_self;
315 PyObject *_args;
316{
317 PyObject *_res = NULL;
318 if (!PyArg_ParseTuple(_args, ""))
319 return NULL;
320 DrawControlInCurrentPort(_self->ob_itself);
321 Py_INCREF(Py_None);
322 _res = Py_None;
323 return _res;
324}
325
326static PyObject *CtlObj_SetUpControlBackground(_self, _args)
327 ControlObject *_self;
328 PyObject *_args;
329{
330 PyObject *_res = NULL;
331 OSErr _err;
332 SInt16 inDepth;
333 Boolean inIsColorDevice;
334 if (!PyArg_ParseTuple(_args, "hb",
335 &inDepth,
336 &inIsColorDevice))
337 return NULL;
338 _err = SetUpControlBackground(_self->ob_itself,
339 inDepth,
340 inIsColorDevice);
341 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000342 Py_INCREF(Py_None);
343 _res = Py_None;
344 return _res;
345}
346
Jack Jansena05ac601999-12-12 21:41:51 +0000347static PyObject *CtlObj_SetUpControlTextColor(_self, _args)
348 ControlObject *_self;
349 PyObject *_args;
350{
351 PyObject *_res = NULL;
352 OSErr _err;
353 SInt16 inDepth;
354 Boolean inIsColorDevice;
355 if (!PyArg_ParseTuple(_args, "hb",
356 &inDepth,
357 &inIsColorDevice))
358 return NULL;
359 _err = SetUpControlTextColor(_self->ob_itself,
360 inDepth,
361 inIsColorDevice);
362 if (_err != noErr) return PyMac_Error(_err);
363 Py_INCREF(Py_None);
364 _res = Py_None;
365 return _res;
366}
367
Jack Jansen7d0bc831995-06-09 20:56:31 +0000368static PyObject *CtlObj_DragControl(_self, _args)
369 ControlObject *_self;
370 PyObject *_args;
371{
372 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000373 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000374 Rect limitRect;
375 Rect slopRect;
376 DragConstraint axis;
377 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000378 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000379 PyMac_GetRect, &limitRect,
380 PyMac_GetRect, &slopRect,
381 &axis))
382 return NULL;
383 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000384 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000385 &limitRect,
386 &slopRect,
387 axis);
388 Py_INCREF(Py_None);
389 _res = Py_None;
390 return _res;
391}
392
393static PyObject *CtlObj_TestControl(_self, _args)
394 ControlObject *_self;
395 PyObject *_args;
396{
397 PyObject *_res = NULL;
398 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000399 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000400 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000401 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000402 return NULL;
403 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000404 testPoint);
405 _res = Py_BuildValue("h",
406 _rv);
407 return _res;
408}
409
410static PyObject *CtlObj_HandleControlKey(_self, _args)
411 ControlObject *_self;
412 PyObject *_args;
413{
414 PyObject *_res = NULL;
415 SInt16 _rv;
416 SInt16 inKeyCode;
417 SInt16 inCharCode;
418 SInt16 inModifiers;
419 if (!PyArg_ParseTuple(_args, "hhh",
420 &inKeyCode,
421 &inCharCode,
422 &inModifiers))
423 return NULL;
424 _rv = HandleControlKey(_self->ob_itself,
425 inKeyCode,
426 inCharCode,
427 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000428 _res = Py_BuildValue("h",
429 _rv);
430 return _res;
431}
432
433static PyObject *CtlObj_MoveControl(_self, _args)
434 ControlObject *_self;
435 PyObject *_args;
436{
437 PyObject *_res = NULL;
438 SInt16 h;
439 SInt16 v;
440 if (!PyArg_ParseTuple(_args, "hh",
441 &h,
442 &v))
443 return NULL;
444 MoveControl(_self->ob_itself,
445 h,
446 v);
447 Py_INCREF(Py_None);
448 _res = Py_None;
449 return _res;
450}
451
452static PyObject *CtlObj_SizeControl(_self, _args)
453 ControlObject *_self;
454 PyObject *_args;
455{
456 PyObject *_res = NULL;
457 SInt16 w;
458 SInt16 h;
459 if (!PyArg_ParseTuple(_args, "hh",
460 &w,
461 &h))
462 return NULL;
463 SizeControl(_self->ob_itself,
464 w,
465 h);
466 Py_INCREF(Py_None);
467 _res = Py_None;
468 return _res;
469}
470
Jack Jansenae8a68f1995-06-06 12:55:40 +0000471static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000472 ControlObject *_self;
473 PyObject *_args;
474{
475 PyObject *_res = NULL;
476 Str255 title;
477 if (!PyArg_ParseTuple(_args, "O&",
478 PyMac_GetStr255, title))
479 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000480 SetControlTitle(_self->ob_itself,
481 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000482 Py_INCREF(Py_None);
483 _res = Py_None;
484 return _res;
485}
486
Jack Jansenae8a68f1995-06-06 12:55:40 +0000487static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000488 ControlObject *_self;
489 PyObject *_args;
490{
491 PyObject *_res = NULL;
492 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000493 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000494 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000495 GetControlTitle(_self->ob_itself,
496 title);
Jack Jansen41009001999-03-07 20:05:20 +0000497 _res = Py_BuildValue("O&",
498 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000499 return _res;
500}
501
Jack Jansenae8a68f1995-06-06 12:55:40 +0000502static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000503 ControlObject *_self;
504 PyObject *_args;
505{
506 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000507 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000508 if (!PyArg_ParseTuple(_args, ""))
509 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000510 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000511 _res = Py_BuildValue("h",
512 _rv);
513 return _res;
514}
515
Jack Jansen7d0bc831995-06-09 20:56:31 +0000516static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000517 ControlObject *_self;
518 PyObject *_args;
519{
520 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000521 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000522 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000523 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000524 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000525 SetControlValue(_self->ob_itself,
526 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000527 Py_INCREF(Py_None);
528 _res = Py_None;
529 return _res;
530}
531
Jack Jansenae8a68f1995-06-06 12:55:40 +0000532static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000533 ControlObject *_self;
534 PyObject *_args;
535{
536 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000537 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000538 if (!PyArg_ParseTuple(_args, ""))
539 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000540 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000541 _res = Py_BuildValue("h",
542 _rv);
543 return _res;
544}
545
Jack Jansen7d0bc831995-06-09 20:56:31 +0000546static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000547 ControlObject *_self;
548 PyObject *_args;
549{
550 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000551 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000552 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000553 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000554 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000555 SetControlMinimum(_self->ob_itself,
556 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000557 Py_INCREF(Py_None);
558 _res = Py_None;
559 return _res;
560}
561
Jack Jansenae8a68f1995-06-06 12:55:40 +0000562static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000563 ControlObject *_self;
564 PyObject *_args;
565{
566 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000567 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000568 if (!PyArg_ParseTuple(_args, ""))
569 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000570 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000571 _res = Py_BuildValue("h",
572 _rv);
573 return _res;
574}
575
Jack Jansen7d0bc831995-06-09 20:56:31 +0000576static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000577 ControlObject *_self;
578 PyObject *_args;
579{
580 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000581 SInt16 newMaximum;
582 if (!PyArg_ParseTuple(_args, "h",
583 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000584 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000585 SetControlMaximum(_self->ob_itself,
586 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000587 Py_INCREF(Py_None);
588 _res = Py_None;
589 return _res;
590}
591
Jack Jansena05ac601999-12-12 21:41:51 +0000592static PyObject *CtlObj_GetControlViewSize(_self, _args)
593 ControlObject *_self;
594 PyObject *_args;
595{
596 PyObject *_res = NULL;
597 SInt32 _rv;
598 if (!PyArg_ParseTuple(_args, ""))
599 return NULL;
600 _rv = GetControlViewSize(_self->ob_itself);
601 _res = Py_BuildValue("l",
602 _rv);
603 return _res;
604}
605
606static PyObject *CtlObj_SetControlViewSize(_self, _args)
607 ControlObject *_self;
608 PyObject *_args;
609{
610 PyObject *_res = NULL;
611 SInt32 newViewSize;
612 if (!PyArg_ParseTuple(_args, "l",
613 &newViewSize))
614 return NULL;
615 SetControlViewSize(_self->ob_itself,
616 newViewSize);
617 Py_INCREF(Py_None);
618 _res = Py_None;
619 return _res;
620}
621
622static PyObject *CtlObj_GetControl32BitValue(_self, _args)
623 ControlObject *_self;
624 PyObject *_args;
625{
626 PyObject *_res = NULL;
627 SInt32 _rv;
628 if (!PyArg_ParseTuple(_args, ""))
629 return NULL;
630 _rv = GetControl32BitValue(_self->ob_itself);
631 _res = Py_BuildValue("l",
632 _rv);
633 return _res;
634}
635
636static PyObject *CtlObj_SetControl32BitValue(_self, _args)
637 ControlObject *_self;
638 PyObject *_args;
639{
640 PyObject *_res = NULL;
641 SInt32 newValue;
642 if (!PyArg_ParseTuple(_args, "l",
643 &newValue))
644 return NULL;
645 SetControl32BitValue(_self->ob_itself,
646 newValue);
647 Py_INCREF(Py_None);
648 _res = Py_None;
649 return _res;
650}
651
652static PyObject *CtlObj_GetControl32BitMaximum(_self, _args)
653 ControlObject *_self;
654 PyObject *_args;
655{
656 PyObject *_res = NULL;
657 SInt32 _rv;
658 if (!PyArg_ParseTuple(_args, ""))
659 return NULL;
660 _rv = GetControl32BitMaximum(_self->ob_itself);
661 _res = Py_BuildValue("l",
662 _rv);
663 return _res;
664}
665
666static PyObject *CtlObj_SetControl32BitMaximum(_self, _args)
667 ControlObject *_self;
668 PyObject *_args;
669{
670 PyObject *_res = NULL;
671 SInt32 newMaximum;
672 if (!PyArg_ParseTuple(_args, "l",
673 &newMaximum))
674 return NULL;
675 SetControl32BitMaximum(_self->ob_itself,
676 newMaximum);
677 Py_INCREF(Py_None);
678 _res = Py_None;
679 return _res;
680}
681
682static PyObject *CtlObj_GetControl32BitMinimum(_self, _args)
683 ControlObject *_self;
684 PyObject *_args;
685{
686 PyObject *_res = NULL;
687 SInt32 _rv;
688 if (!PyArg_ParseTuple(_args, ""))
689 return NULL;
690 _rv = GetControl32BitMinimum(_self->ob_itself);
691 _res = Py_BuildValue("l",
692 _rv);
693 return _res;
694}
695
696static PyObject *CtlObj_SetControl32BitMinimum(_self, _args)
697 ControlObject *_self;
698 PyObject *_args;
699{
700 PyObject *_res = NULL;
701 SInt32 newMinimum;
702 if (!PyArg_ParseTuple(_args, "l",
703 &newMinimum))
704 return NULL;
705 SetControl32BitMinimum(_self->ob_itself,
706 newMinimum);
707 Py_INCREF(Py_None);
708 _res = Py_None;
709 return _res;
710}
711
712static PyObject *CtlObj_IsValidControlHandle(_self, _args)
713 ControlObject *_self;
714 PyObject *_args;
715{
716 PyObject *_res = NULL;
717 Boolean _rv;
718 if (!PyArg_ParseTuple(_args, ""))
719 return NULL;
720 _rv = IsValidControlHandle(_self->ob_itself);
721 _res = Py_BuildValue("b",
722 _rv);
723 return _res;
724}
725
726static PyObject *CtlObj_RemoveControlProperty(_self, _args)
727 ControlObject *_self;
728 PyObject *_args;
729{
730 PyObject *_res = NULL;
Jack Jansenabc411b2000-03-20 16:09:09 +0000731 OSStatus _rv;
Jack Jansena05ac601999-12-12 21:41:51 +0000732 OSType propertyCreator;
733 OSType propertyTag;
734 if (!PyArg_ParseTuple(_args, "O&O&",
735 PyMac_GetOSType, &propertyCreator,
736 PyMac_GetOSType, &propertyTag))
737 return NULL;
Jack Jansenabc411b2000-03-20 16:09:09 +0000738 _rv = RemoveControlProperty(_self->ob_itself,
739 propertyCreator,
740 propertyTag);
741 _res = Py_BuildValue("l",
742 _rv);
Jack Jansena05ac601999-12-12 21:41:51 +0000743 return _res;
744}
745
746static PyObject *CtlObj_GetControlRegion(_self, _args)
747 ControlObject *_self;
748 PyObject *_args;
749{
750 PyObject *_res = NULL;
Jack Jansenabc411b2000-03-20 16:09:09 +0000751 OSStatus _rv;
Jack Jansena05ac601999-12-12 21:41:51 +0000752 ControlPartCode inPart;
753 RgnHandle outRegion;
754 if (!PyArg_ParseTuple(_args, "hO&",
755 &inPart,
756 ResObj_Convert, &outRegion))
757 return NULL;
Jack Jansenabc411b2000-03-20 16:09:09 +0000758 _rv = GetControlRegion(_self->ob_itself,
759 inPart,
760 outRegion);
761 _res = Py_BuildValue("l",
762 _rv);
Jack Jansena05ac601999-12-12 21:41:51 +0000763 return _res;
764}
765
Jack Jansen7d0bc831995-06-09 20:56:31 +0000766static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000767 ControlObject *_self;
768 PyObject *_args;
769{
770 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000771 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000772 if (!PyArg_ParseTuple(_args, ""))
773 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000774 _rv = GetControlVariant(_self->ob_itself);
775 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000776 _rv);
777 return _res;
778}
779
Jack Jansen7d0bc831995-06-09 20:56:31 +0000780static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000781 ControlObject *_self;
782 PyObject *_args;
783{
784 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000785 SInt32 data;
786 if (!PyArg_ParseTuple(_args, "l",
787 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000788 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000789 SetControlReference(_self->ob_itself,
790 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000791 Py_INCREF(Py_None);
792 _res = Py_None;
793 return _res;
794}
795
Jack Jansen7d0bc831995-06-09 20:56:31 +0000796static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000797 ControlObject *_self;
798 PyObject *_args;
799{
800 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000801 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000802 if (!PyArg_ParseTuple(_args, ""))
803 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000804 _rv = GetControlReference(_self->ob_itself);
805 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000806 _rv);
807 return _res;
808}
809
Jack Jansenc7fefed1997-08-15 14:32:18 +0000810static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
811 ControlObject *_self;
812 PyObject *_args;
813{
814 PyObject *_res = NULL;
815 Boolean _rv;
816 AuxCtlHandle acHndl;
817 if (!PyArg_ParseTuple(_args, ""))
818 return NULL;
819 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
820 &acHndl);
821 _res = Py_BuildValue("bO&",
822 _rv,
823 ResObj_New, acHndl);
824 return _res;
825}
826
827static PyObject *CtlObj_SetControlColor(_self, _args)
828 ControlObject *_self;
829 PyObject *_args;
830{
831 PyObject *_res = NULL;
832 CCTabHandle newColorTable;
833 if (!PyArg_ParseTuple(_args, "O&",
834 ResObj_Convert, &newColorTable))
835 return NULL;
836 SetControlColor(_self->ob_itself,
837 newColorTable);
838 Py_INCREF(Py_None);
839 _res = Py_None;
840 return _res;
841}
842
Jack Jansen21f96871998-02-20 16:02:09 +0000843static PyObject *CtlObj_SendControlMessage(_self, _args)
844 ControlObject *_self;
845 PyObject *_args;
846{
847 PyObject *_res = NULL;
848 SInt32 _rv;
849 SInt16 inMessage;
850 SInt32 inParam;
851 if (!PyArg_ParseTuple(_args, "hl",
852 &inMessage,
853 &inParam))
854 return NULL;
855 _rv = SendControlMessage(_self->ob_itself,
856 inMessage,
857 inParam);
858 _res = Py_BuildValue("l",
859 _rv);
860 return _res;
861}
862
863static PyObject *CtlObj_EmbedControl(_self, _args)
864 ControlObject *_self;
865 PyObject *_args;
866{
867 PyObject *_res = NULL;
868 OSErr _err;
869 ControlHandle inContainer;
870 if (!PyArg_ParseTuple(_args, "O&",
871 CtlObj_Convert, &inContainer))
872 return NULL;
873 _err = EmbedControl(_self->ob_itself,
874 inContainer);
875 if (_err != noErr) return PyMac_Error(_err);
876 Py_INCREF(Py_None);
877 _res = Py_None;
878 return _res;
879}
880
881static PyObject *CtlObj_AutoEmbedControl(_self, _args)
882 ControlObject *_self;
883 PyObject *_args;
884{
885 PyObject *_res = NULL;
886 OSErr _err;
887 WindowPtr inWindow;
888 if (!PyArg_ParseTuple(_args, "O&",
889 WinObj_Convert, &inWindow))
890 return NULL;
891 _err = AutoEmbedControl(_self->ob_itself,
892 inWindow);
893 if (_err != noErr) return PyMac_Error(_err);
894 Py_INCREF(Py_None);
895 _res = Py_None;
896 return _res;
897}
898
899static PyObject *CtlObj_GetSuperControl(_self, _args)
900 ControlObject *_self;
901 PyObject *_args;
902{
903 PyObject *_res = NULL;
904 OSErr _err;
905 ControlHandle outParent;
906 if (!PyArg_ParseTuple(_args, ""))
907 return NULL;
908 _err = GetSuperControl(_self->ob_itself,
909 &outParent);
910 if (_err != noErr) return PyMac_Error(_err);
911 _res = Py_BuildValue("O&",
912 CtlObj_WhichControl, outParent);
913 return _res;
914}
915
916static PyObject *CtlObj_CountSubControls(_self, _args)
917 ControlObject *_self;
918 PyObject *_args;
919{
920 PyObject *_res = NULL;
921 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000922 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +0000923 if (!PyArg_ParseTuple(_args, ""))
924 return NULL;
925 _err = CountSubControls(_self->ob_itself,
926 &outNumChildren);
927 if (_err != noErr) return PyMac_Error(_err);
928 _res = Py_BuildValue("h",
929 outNumChildren);
930 return _res;
931}
932
933static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
934 ControlObject *_self;
935 PyObject *_args;
936{
937 PyObject *_res = NULL;
938 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000939 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +0000940 ControlHandle outSubControl;
941 if (!PyArg_ParseTuple(_args, "h",
942 &inIndex))
943 return NULL;
944 _err = GetIndexedSubControl(_self->ob_itself,
945 inIndex,
946 &outSubControl);
947 if (_err != noErr) return PyMac_Error(_err);
948 _res = Py_BuildValue("O&",
949 CtlObj_WhichControl, outSubControl);
950 return _res;
951}
952
953static PyObject *CtlObj_SetControlSupervisor(_self, _args)
954 ControlObject *_self;
955 PyObject *_args;
956{
957 PyObject *_res = NULL;
958 OSErr _err;
959 ControlHandle inBoss;
960 if (!PyArg_ParseTuple(_args, "O&",
961 CtlObj_Convert, &inBoss))
962 return NULL;
963 _err = SetControlSupervisor(_self->ob_itself,
964 inBoss);
965 if (_err != noErr) return PyMac_Error(_err);
966 Py_INCREF(Py_None);
967 _res = Py_None;
968 return _res;
969}
970
971static PyObject *CtlObj_GetControlFeatures(_self, _args)
972 ControlObject *_self;
973 PyObject *_args;
974{
975 PyObject *_res = NULL;
976 OSErr _err;
977 UInt32 outFeatures;
978 if (!PyArg_ParseTuple(_args, ""))
979 return NULL;
980 _err = GetControlFeatures(_self->ob_itself,
981 &outFeatures);
982 if (_err != noErr) return PyMac_Error(_err);
983 _res = Py_BuildValue("l",
984 outFeatures);
985 return _res;
986}
987
988static PyObject *CtlObj_GetControlDataSize(_self, _args)
989 ControlObject *_self;
990 PyObject *_args;
991{
992 PyObject *_res = NULL;
993 OSErr _err;
994 ControlPartCode inPart;
995 ResType inTagName;
996 Size outMaxSize;
997 if (!PyArg_ParseTuple(_args, "hO&",
998 &inPart,
999 PyMac_GetOSType, &inTagName))
1000 return NULL;
1001 _err = GetControlDataSize(_self->ob_itself,
1002 inPart,
1003 inTagName,
1004 &outMaxSize);
1005 if (_err != noErr) return PyMac_Error(_err);
1006 _res = Py_BuildValue("l",
1007 outMaxSize);
1008 return _res;
1009}
1010
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001011static PyObject *CtlObj_as_Resource(_self, _args)
1012 ControlObject *_self;
1013 PyObject *_args;
1014{
1015 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001016 Handle _rv;
1017 if (!PyArg_ParseTuple(_args, ""))
1018 return NULL;
1019 _rv = as_Resource(_self->ob_itself);
1020 _res = Py_BuildValue("O&",
1021 ResObj_New, _rv);
1022 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001023}
1024
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001025static PyObject *CtlObj_GetControlRect(_self, _args)
1026 ControlObject *_self;
1027 PyObject *_args;
1028{
1029 PyObject *_res = NULL;
1030 Rect rect;
1031 if (!PyArg_ParseTuple(_args, ""))
1032 return NULL;
1033 GetControlRect(_self->ob_itself,
1034 &rect);
1035 _res = Py_BuildValue("O&",
1036 PyMac_BuildRect, &rect);
1037 return _res;
1038}
1039
Jack Jansencfb60ee1996-10-01 10:46:46 +00001040static PyObject *CtlObj_DisposeControl(_self, _args)
1041 ControlObject *_self;
1042 PyObject *_args;
1043{
1044 PyObject *_res = NULL;
1045
1046 if (!PyArg_ParseTuple(_args, ""))
1047 return NULL;
1048 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001049 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001050 DisposeControl(_self->ob_itself);
1051 _self->ob_itself = NULL;
1052 }
1053 Py_INCREF(Py_None);
1054 _res = Py_None;
1055 return _res;
1056
1057}
1058
Jack Jansen848250c1998-05-28 14:20:09 +00001059static PyObject *CtlObj_TrackControl(_self, _args)
1060 ControlObject *_self;
1061 PyObject *_args;
1062{
1063 PyObject *_res = NULL;
1064
1065 ControlPartCode _rv;
1066 Point startPoint;
1067 ControlActionUPP upp = 0;
1068 PyObject *callback = 0;
1069
1070 if (!PyArg_ParseTuple(_args, "O&|O",
1071 PyMac_GetPoint, &startPoint, &callback))
1072 return NULL;
1073 if (callback && callback != Py_None) {
1074 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1075 upp = (ControlActionUPP)-1;
1076 else {
1077 settrackfunc(callback);
1078 upp = mytracker_upp;
1079 }
1080 }
1081 _rv = TrackControl(_self->ob_itself,
1082 startPoint,
1083 upp);
1084 clrtrackfunc();
1085 _res = Py_BuildValue("h",
1086 _rv);
1087 return _res;
1088
1089}
1090
Jack Jansen24c35311999-12-09 22:49:51 +00001091static PyObject *CtlObj_HandleControlClick(_self, _args)
1092 ControlObject *_self;
1093 PyObject *_args;
1094{
1095 PyObject *_res = NULL;
1096
1097 ControlPartCode _rv;
1098 Point startPoint;
1099 SInt16 modifiers;
1100 ControlActionUPP upp = 0;
1101 PyObject *callback = 0;
1102
1103 if (!PyArg_ParseTuple(_args, "O&h|O",
1104 PyMac_GetPoint, &startPoint,
1105 &modifiers,
1106 &callback))
1107 return NULL;
1108 if (callback && callback != Py_None) {
1109 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1110 upp = (ControlActionUPP)-1;
1111 else {
1112 settrackfunc(callback);
1113 upp = mytracker_upp;
1114 }
1115 }
1116 _rv = HandleControlClick(_self->ob_itself,
1117 startPoint,
1118 modifiers,
1119 upp);
1120 clrtrackfunc();
1121 _res = Py_BuildValue("h",
1122 _rv);
1123 return _res;
1124
1125}
1126
1127static PyObject *CtlObj_SetControlData(_self, _args)
1128 ControlObject *_self;
1129 PyObject *_args;
1130{
1131 PyObject *_res = NULL;
1132
1133 OSErr _err;
1134 ControlPartCode inPart;
1135 ResType inTagName;
1136 Size bufferSize;
1137 Ptr buffer;
1138
1139 if (!PyArg_ParseTuple(_args, "hO&s#",
1140 &inPart,
1141 PyMac_GetOSType, &inTagName,
1142 &buffer, &bufferSize))
1143 return NULL;
1144
1145 _err = SetControlData(_self->ob_itself,
1146 inPart,
1147 inTagName,
1148 bufferSize,
1149 buffer);
1150
1151 if (_err != noErr)
1152 return PyMac_Error(_err);
1153 _res = Py_None;
1154 return _res;
1155
1156}
1157
1158static PyObject *CtlObj_GetControlData(_self, _args)
1159 ControlObject *_self;
1160 PyObject *_args;
1161{
1162 PyObject *_res = NULL;
1163
1164 OSErr _err;
1165 ControlPartCode inPart;
1166 ResType inTagName;
1167 Size bufferSize;
1168 Ptr buffer;
1169 Size outSize;
1170
1171 if (!PyArg_ParseTuple(_args, "hO&",
1172 &inPart,
1173 PyMac_GetOSType, &inTagName))
1174 return NULL;
1175
1176 /* allocate a buffer for the data */
1177 _err = GetControlDataSize(_self->ob_itself,
1178 inPart,
1179 inTagName,
1180 &bufferSize);
1181 if (_err != noErr)
1182 return PyMac_Error(_err);
1183 buffer = PyMem_NEW(char, bufferSize);
1184 if (buffer == NULL)
1185 return PyErr_NoMemory();
1186
1187 _err = GetControlData(_self->ob_itself,
1188 inPart,
1189 inTagName,
1190 bufferSize,
1191 buffer,
1192 &outSize);
1193
1194 if (_err != noErr) {
1195 PyMem_DEL(buffer);
1196 return PyMac_Error(_err);
1197 }
1198 _res = Py_BuildValue("s#", buffer, outSize);
1199 PyMem_DEL(buffer);
1200 return _res;
1201
1202}
1203
Jack Jansen1f9249c1999-12-19 00:05:50 +00001204static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1205 ControlObject *_self;
1206 PyObject *_args;
1207{
1208 PyObject *_res = NULL;
1209
1210 OSErr _err;
1211 ControlPartCode inPart;
1212 ResType inTagName;
1213 Handle buffer;
1214
1215 if (!PyArg_ParseTuple(_args, "hO&O&",
1216 &inPart,
1217 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001218 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001219 return NULL;
1220
1221 _err = SetControlData(_self->ob_itself,
1222 inPart,
1223 inTagName,
1224 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001225 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001226
1227 if (_err != noErr)
1228 return PyMac_Error(_err);
1229 _res = Py_None;
1230 return _res;
1231
1232}
1233
1234static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1235 ControlObject *_self;
1236 PyObject *_args;
1237{
1238 PyObject *_res = NULL;
1239
1240 OSErr _err;
1241 ControlPartCode inPart;
1242 ResType inTagName;
1243 Size bufferSize;
1244 Handle hdl;
1245
1246 if (!PyArg_ParseTuple(_args, "hO&",
1247 &inPart,
1248 PyMac_GetOSType, &inTagName))
1249 return NULL;
1250
1251 /* Check it is handle-sized */
1252 _err = GetControlDataSize(_self->ob_itself,
1253 inPart,
1254 inTagName,
1255 &bufferSize);
1256 if (_err != noErr)
1257 return PyMac_Error(_err);
1258 if (bufferSize != sizeof(Handle)) {
1259 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1260 return NULL;
1261 }
1262
1263 _err = GetControlData(_self->ob_itself,
1264 inPart,
1265 inTagName,
1266 sizeof(Handle),
1267 (Ptr)&hdl,
1268 &bufferSize);
1269
1270 if (_err != noErr) {
1271 return PyMac_Error(_err);
1272 }
1273 return Py_BuildValue("O&", OptResObj_New, hdl);
1274
1275}
1276
Jack Jansenabc411b2000-03-20 16:09:09 +00001277static PyObject *CtlObj_SetControlDataCallback(_self, _args)
1278 ControlObject *_self;
1279 PyObject *_args;
1280{
1281 PyObject *_res = NULL;
1282
1283 OSErr _err;
1284 ControlPartCode inPart;
1285 ResType inTagName;
1286 PyObject *callback;
1287 UniversalProcPtr *c_callback;
1288
1289 if (!PyArg_ParseTuple(_args, "hO&O",
1290 &inPart,
1291 PyMac_GetOSType, &inTagName,
1292 &callback))
1293 return NULL;
1294
1295 if ( setcallback(_self, inTagName, callback, &c_callback) < 0 )
1296 return NULL;
1297 _err = SetControlData(_self->ob_itself,
1298 inPart,
1299 inTagName,
1300 sizeof(c_callback),
1301 (Ptr)&c_callback);
1302
1303 if (_err != noErr)
1304 return PyMac_Error(_err);
1305 _res = Py_None;
1306 return _res;
1307
1308}
1309
Jack Jansen4c704131998-06-19 13:35:14 +00001310static PyObject *CtlObj_GetPopupData(_self, _args)
1311 ControlObject *_self;
1312 PyObject *_args;
1313{
1314 PyObject *_res = NULL;
1315
1316 PopupPrivateDataHandle hdl;
1317
1318 if ( (*_self->ob_itself)->contrlData == NULL ) {
1319 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1320 return 0;
1321 }
1322 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1323 HLock((Handle)hdl);
1324 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1325 HUnlock((Handle)hdl);
1326 return _res;
1327
1328}
1329
1330static PyObject *CtlObj_SetPopupData(_self, _args)
1331 ControlObject *_self;
1332 PyObject *_args;
1333{
1334 PyObject *_res = NULL;
1335
1336 PopupPrivateDataHandle hdl;
1337 MenuHandle mHandle;
1338 short mID;
1339
1340 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1341 return 0;
1342 if ( (*_self->ob_itself)->contrlData == NULL ) {
1343 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1344 return 0;
1345 }
1346 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1347 (*hdl)->mHandle = mHandle;
1348 (*hdl)->mID = mID;
1349 Py_INCREF(Py_None);
1350 return Py_None;
1351
1352}
1353
Guido van Rossum17448e21995-01-30 11:53:55 +00001354static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001355 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1356 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001357 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1358 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001359 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1360 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001361 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1362 "() -> (Boolean _rv)"},
1363 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1364 "() -> (Boolean _rv)"},
1365 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1366 "() -> None"},
1367 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1368 "() -> None"},
1369 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1370 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001371 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1372 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001373 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1374 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1375 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1376 "(ControlFontStyleRec inStyle) -> None"},
1377 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1378 "() -> None"},
1379 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1380 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001381 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1382 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001383 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001384 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001385 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001386 "(Point testPoint) -> (ControlPartCode _rv)"},
1387 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
1388 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001389 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001390 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001391 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001392 "(SInt16 w, SInt16 h) -> None"},
1393 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1394 "(Str255 title) -> None"},
1395 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001396 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001397 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001398 "() -> (SInt16 _rv)"},
1399 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1400 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001401 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001402 "() -> (SInt16 _rv)"},
1403 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1404 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001405 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001406 "() -> (SInt16 _rv)"},
1407 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1408 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001409 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
1410 "() -> (SInt32 _rv)"},
1411 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
1412 "(SInt32 newViewSize) -> None"},
1413 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
1414 "() -> (SInt32 _rv)"},
1415 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
1416 "(SInt32 newValue) -> None"},
1417 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
1418 "() -> (SInt32 _rv)"},
1419 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
1420 "(SInt32 newMaximum) -> None"},
1421 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
1422 "() -> (SInt32 _rv)"},
1423 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
1424 "(SInt32 newMinimum) -> None"},
1425 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
1426 "() -> (Boolean _rv)"},
1427 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansenabc411b2000-03-20 16:09:09 +00001428 "(OSType propertyCreator, OSType propertyTag) -> (OSStatus _rv)"},
Jack Jansena05ac601999-12-12 21:41:51 +00001429 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansenabc411b2000-03-20 16:09:09 +00001430 "(ControlPartCode inPart, RgnHandle outRegion) -> (OSStatus _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001431 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001432 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001433 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1434 "(SInt32 data) -> None"},
1435 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1436 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +00001437 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1438 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
1439 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1440 "(CCTabHandle newColorTable) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001441 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
1442 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
1443 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
1444 "(ControlHandle inContainer) -> None"},
1445 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
1446 "(WindowPtr inWindow) -> None"},
1447 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
1448 "() -> (ControlHandle outParent)"},
1449 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001450 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001451 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001452 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001453 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
1454 "(ControlHandle inBoss) -> None"},
1455 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
1456 "() -> (UInt32 outFeatures)"},
1457 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
1458 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001459 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00001460 "() -> (Handle _rv)"},
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001461 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
1462 "() -> (Rect rect)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00001463 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1464 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001465 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001466 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
1467 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
1468 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
1469 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
1470 "(stuff) -> None"},
1471 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
1472 "(part, type) -> String"},
Jack Jansen1f9249c1999-12-19 00:05:50 +00001473 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
1474 "(ResObj) -> None"},
1475 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
1476 "(part, type) -> ResObj"},
Jack Jansenabc411b2000-03-20 16:09:09 +00001477 {"SetControlDataCallback", (PyCFunction)CtlObj_SetControlDataCallback, 1,
1478 "(callbackfunc) -> None"},
Jack Jansen4c704131998-06-19 13:35:14 +00001479 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1480 NULL},
1481 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1482 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001483 {NULL, NULL, 0}
1484};
1485
1486PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1487
1488static PyObject *CtlObj_getattr(self, name)
1489 ControlObject *self;
1490 char *name;
1491{
1492 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1493}
1494
1495#define CtlObj_setattr NULL
1496
Jack Jansen8387af61999-03-13 23:07:32 +00001497static int CtlObj_compare(self, other)
1498 ControlObject *self, *other;
1499{
1500 unsigned long v, w;
1501
1502 if (!CtlObj_Check((PyObject *)other))
1503 {
1504 v=(unsigned long)self;
1505 w=(unsigned long)other;
1506 }
1507 else
1508 {
1509 v=(unsigned long)self->ob_itself;
1510 w=(unsigned long)other->ob_itself;
1511 }
1512 if( v < w ) return -1;
1513 if( v > w ) return 1;
1514 return 0;
1515}
1516
1517#define CtlObj_repr NULL
1518
1519static long CtlObj_hash(self)
1520 ControlObject *self;
1521{
1522 return (long)self->ob_itself;
1523}
1524
Guido van Rossum17448e21995-01-30 11:53:55 +00001525PyTypeObject Control_Type = {
1526 PyObject_HEAD_INIT(&PyType_Type)
1527 0, /*ob_size*/
1528 "Control", /*tp_name*/
1529 sizeof(ControlObject), /*tp_basicsize*/
1530 0, /*tp_itemsize*/
1531 /* methods */
1532 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1533 0, /*tp_print*/
1534 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1535 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00001536 (cmpfunc) CtlObj_compare, /*tp_compare*/
1537 (reprfunc) CtlObj_repr, /*tp_repr*/
1538 (PyNumberMethods *)0, /* tp_as_number */
1539 (PySequenceMethods *)0, /* tp_as_sequence */
1540 (PyMappingMethods *)0, /* tp_as_mapping */
1541 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00001542};
1543
1544/* -------------------- End object type Control --------------------- */
1545
1546
1547static PyObject *Ctl_NewControl(_self, _args)
1548 PyObject *_self;
1549 PyObject *_args;
1550{
1551 PyObject *_res = NULL;
1552 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001553 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001554 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001555 Str255 controlTitle;
1556 Boolean initiallyVisible;
1557 SInt16 initialValue;
1558 SInt16 minimumValue;
1559 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001560 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001561 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001562 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001563 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001564 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001565 PyMac_GetStr255, controlTitle,
1566 &initiallyVisible,
1567 &initialValue,
1568 &minimumValue,
1569 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001570 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001571 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001572 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001573 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001574 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001575 controlTitle,
1576 initiallyVisible,
1577 initialValue,
1578 minimumValue,
1579 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001580 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001581 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001582 _res = Py_BuildValue("O&",
1583 CtlObj_New, _rv);
1584 return _res;
1585}
1586
1587static PyObject *Ctl_GetNewControl(_self, _args)
1588 PyObject *_self;
1589 PyObject *_args;
1590{
1591 PyObject *_res = NULL;
1592 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001593 SInt16 resourceID;
1594 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001595 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001596 &resourceID,
1597 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001598 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001599 _rv = GetNewControl(resourceID,
1600 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001601 _res = Py_BuildValue("O&",
1602 CtlObj_New, _rv);
1603 return _res;
1604}
1605
Guido van Rossum17448e21995-01-30 11:53:55 +00001606static PyObject *Ctl_DrawControls(_self, _args)
1607 PyObject *_self;
1608 PyObject *_args;
1609{
1610 PyObject *_res = NULL;
1611 WindowPtr theWindow;
1612 if (!PyArg_ParseTuple(_args, "O&",
1613 WinObj_Convert, &theWindow))
1614 return NULL;
1615 DrawControls(theWindow);
1616 Py_INCREF(Py_None);
1617 _res = Py_None;
1618 return _res;
1619}
1620
Guido van Rossum17448e21995-01-30 11:53:55 +00001621static PyObject *Ctl_UpdateControls(_self, _args)
1622 PyObject *_self;
1623 PyObject *_args;
1624{
1625 PyObject *_res = NULL;
1626 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001627 RgnHandle updateRegion;
1628 if (!PyArg_ParseTuple(_args, "O&O&",
1629 WinObj_Convert, &theWindow,
1630 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001631 return NULL;
1632 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001633 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001634 Py_INCREF(Py_None);
1635 _res = Py_None;
1636 return _res;
1637}
1638
1639static PyObject *Ctl_FindControl(_self, _args)
1640 PyObject *_self;
1641 PyObject *_args;
1642{
1643 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001644 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001645 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001646 WindowPtr theWindow;
1647 ControlHandle theControl;
1648 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001649 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001650 WinObj_Convert, &theWindow))
1651 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001652 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001653 theWindow,
1654 &theControl);
1655 _res = Py_BuildValue("hO&",
1656 _rv,
1657 CtlObj_WhichControl, theControl);
1658 return _res;
1659}
1660
Jack Jansen21f96871998-02-20 16:02:09 +00001661static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1662 PyObject *_self;
1663 PyObject *_args;
1664{
1665 PyObject *_res = NULL;
1666 ControlHandle _rv;
1667 Point inWhere;
1668 WindowPtr inWindow;
1669 SInt16 outPart;
1670 if (!PyArg_ParseTuple(_args, "O&O&",
1671 PyMac_GetPoint, &inWhere,
1672 WinObj_Convert, &inWindow))
1673 return NULL;
1674 _rv = FindControlUnderMouse(inWhere,
1675 inWindow,
1676 &outPart);
1677 _res = Py_BuildValue("O&h",
1678 CtlObj_New, _rv,
1679 outPart);
1680 return _res;
1681}
1682
1683static PyObject *Ctl_IdleControls(_self, _args)
1684 PyObject *_self;
1685 PyObject *_args;
1686{
1687 PyObject *_res = NULL;
1688 WindowPtr inWindow;
1689 if (!PyArg_ParseTuple(_args, "O&",
1690 WinObj_Convert, &inWindow))
1691 return NULL;
1692 IdleControls(inWindow);
1693 Py_INCREF(Py_None);
1694 _res = Py_None;
1695 return _res;
1696}
1697
1698static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1699 PyObject *_self;
1700 PyObject *_args;
1701{
1702 PyObject *_res = NULL;
1703 OSErr _err;
1704 WindowPtr inWindow;
1705 FSSpec inDumpFile;
1706 if (!PyArg_ParseTuple(_args, "O&O&",
1707 WinObj_Convert, &inWindow,
1708 PyMac_GetFSSpec, &inDumpFile))
1709 return NULL;
1710 _err = DumpControlHierarchy(inWindow,
1711 &inDumpFile);
1712 if (_err != noErr) return PyMac_Error(_err);
1713 Py_INCREF(Py_None);
1714 _res = Py_None;
1715 return _res;
1716}
1717
1718static PyObject *Ctl_CreateRootControl(_self, _args)
1719 PyObject *_self;
1720 PyObject *_args;
1721{
1722 PyObject *_res = NULL;
1723 OSErr _err;
1724 WindowPtr inWindow;
1725 ControlHandle outControl;
1726 if (!PyArg_ParseTuple(_args, "O&",
1727 WinObj_Convert, &inWindow))
1728 return NULL;
1729 _err = CreateRootControl(inWindow,
1730 &outControl);
1731 if (_err != noErr) return PyMac_Error(_err);
1732 _res = Py_BuildValue("O&",
1733 CtlObj_WhichControl, outControl);
1734 return _res;
1735}
1736
1737static PyObject *Ctl_GetRootControl(_self, _args)
1738 PyObject *_self;
1739 PyObject *_args;
1740{
1741 PyObject *_res = NULL;
1742 OSErr _err;
1743 WindowPtr inWindow;
1744 ControlHandle outControl;
1745 if (!PyArg_ParseTuple(_args, "O&",
1746 WinObj_Convert, &inWindow))
1747 return NULL;
1748 _err = GetRootControl(inWindow,
1749 &outControl);
1750 if (_err != noErr) return PyMac_Error(_err);
1751 _res = Py_BuildValue("O&",
1752 CtlObj_WhichControl, outControl);
1753 return _res;
1754}
1755
1756static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1757 PyObject *_self;
1758 PyObject *_args;
1759{
1760 PyObject *_res = NULL;
1761 OSErr _err;
1762 WindowPtr inWindow;
1763 ControlHandle outControl;
1764 if (!PyArg_ParseTuple(_args, "O&",
1765 WinObj_Convert, &inWindow))
1766 return NULL;
1767 _err = GetKeyboardFocus(inWindow,
1768 &outControl);
1769 if (_err != noErr) return PyMac_Error(_err);
1770 _res = Py_BuildValue("O&",
1771 CtlObj_WhichControl, outControl);
1772 return _res;
1773}
1774
1775static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1776 PyObject *_self;
1777 PyObject *_args;
1778{
1779 PyObject *_res = NULL;
1780 OSErr _err;
1781 WindowPtr inWindow;
1782 ControlHandle inControl;
1783 ControlFocusPart inPart;
1784 if (!PyArg_ParseTuple(_args, "O&O&h",
1785 WinObj_Convert, &inWindow,
1786 CtlObj_Convert, &inControl,
1787 &inPart))
1788 return NULL;
1789 _err = SetKeyboardFocus(inWindow,
1790 inControl,
1791 inPart);
1792 if (_err != noErr) return PyMac_Error(_err);
1793 Py_INCREF(Py_None);
1794 _res = Py_None;
1795 return _res;
1796}
1797
1798static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1799 PyObject *_self;
1800 PyObject *_args;
1801{
1802 PyObject *_res = NULL;
1803 OSErr _err;
1804 WindowPtr inWindow;
1805 if (!PyArg_ParseTuple(_args, "O&",
1806 WinObj_Convert, &inWindow))
1807 return NULL;
1808 _err = AdvanceKeyboardFocus(inWindow);
1809 if (_err != noErr) return PyMac_Error(_err);
1810 Py_INCREF(Py_None);
1811 _res = Py_None;
1812 return _res;
1813}
1814
1815static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1816 PyObject *_self;
1817 PyObject *_args;
1818{
1819 PyObject *_res = NULL;
1820 OSErr _err;
1821 WindowPtr inWindow;
1822 if (!PyArg_ParseTuple(_args, "O&",
1823 WinObj_Convert, &inWindow))
1824 return NULL;
1825 _err = ReverseKeyboardFocus(inWindow);
1826 if (_err != noErr) return PyMac_Error(_err);
1827 Py_INCREF(Py_None);
1828 _res = Py_None;
1829 return _res;
1830}
1831
1832static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
1833 PyObject *_self;
1834 PyObject *_args;
1835{
1836 PyObject *_res = NULL;
1837 OSErr _err;
1838 WindowPtr inWindow;
1839 if (!PyArg_ParseTuple(_args, "O&",
1840 WinObj_Convert, &inWindow))
1841 return NULL;
1842 _err = ClearKeyboardFocus(inWindow);
1843 if (_err != noErr) return PyMac_Error(_err);
1844 Py_INCREF(Py_None);
1845 _res = Py_None;
1846 return _res;
1847}
1848
Jack Jansene0581891999-02-07 14:02:03 +00001849static PyObject *Ctl_as_Control(_self, _args)
1850 PyObject *_self;
1851 PyObject *_args;
1852{
1853 PyObject *_res = NULL;
1854 ControlHandle _rv;
1855 Handle h;
1856 if (!PyArg_ParseTuple(_args, "O&",
1857 ResObj_Convert, &h))
1858 return NULL;
1859 _rv = as_Control(h);
1860 _res = Py_BuildValue("O&",
1861 CtlObj_New, _rv);
1862 return _res;
1863}
1864
Guido van Rossum17448e21995-01-30 11:53:55 +00001865static PyMethodDef Ctl_methods[] = {
1866 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001867 "(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 +00001868 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001869 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001870 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1871 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001872 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001873 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001874 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001875 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1876 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1877 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1878 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1879 "(WindowPtr inWindow) -> None"},
1880 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1881 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1882 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1883 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1884 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1885 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1886 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1887 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1888 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1889 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1890 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1891 "(WindowPtr inWindow) -> None"},
1892 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1893 "(WindowPtr inWindow) -> None"},
1894 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1895 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00001896 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
1897 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001898 {NULL, NULL, 0}
1899};
1900
1901
1902
Jack Jansen8387af61999-03-13 23:07:32 +00001903PyObject *CtlObj_NewUnmanaged(itself)
1904 ControlHandle itself;
1905{
1906 ControlObject *it;
1907 if (itself == NULL) return PyMac_Error(resNotFound);
1908 it = PyObject_NEW(ControlObject, &Control_Type);
1909 if (it == NULL) return NULL;
1910 it->ob_itself = itself;
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001911 it->ob_callbackdict = NULL;
Jack Jansen8387af61999-03-13 23:07:32 +00001912 return (PyObject *)it;
1913}
1914
Guido van Rossum17448e21995-01-30 11:53:55 +00001915PyObject *
1916CtlObj_WhichControl(ControlHandle c)
1917{
1918 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00001919
Guido van Rossum17448e21995-01-30 11:53:55 +00001920 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00001921 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00001922 else {
1923 it = (PyObject *) GetControlReference(c);
1924 /*
1925 ** If the refcon is zero or doesn't point back to the Python object
1926 ** the control is not ours. Return a temporary object.
1927 */
1928 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1929 return CtlObj_NewUnmanaged(c);
1930 }
Guido van Rossum17448e21995-01-30 11:53:55 +00001931 Py_INCREF(it);
1932 return it;
1933}
1934
Jack Jansen848250c1998-05-28 14:20:09 +00001935static int
1936settrackfunc(obj)
1937 PyObject *obj;
1938{
1939 if (tracker) {
1940 PyErr_SetString(Ctl_Error, "Tracker function in use");
1941 return 0;
1942 }
1943 tracker = obj;
1944 Py_INCREF(tracker);
1945}
1946
1947static void
1948clrtrackfunc()
1949{
1950 Py_XDECREF(tracker);
1951 tracker = 0;
1952}
1953
1954static pascal void
1955mytracker(ctl, part)
1956 ControlHandle ctl;
1957 short part;
1958{
1959 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00001960
Jack Jansen848250c1998-05-28 14:20:09 +00001961 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
1962 if (args && tracker) {
1963 rv = PyEval_CallObject(tracker, args);
1964 Py_DECREF(args);
1965 }
1966 if (rv)
1967 Py_DECREF(rv);
1968 else
Jack Jansen24c35311999-12-09 22:49:51 +00001969 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00001970}
1971
Jack Jansenabc411b2000-03-20 16:09:09 +00001972static int
1973setcallback(self, which, callback, uppp)
1974 ControlObject *self;
1975 OSType which;
1976 PyObject *callback;
1977 UniversalProcPtr *uppp;
1978{
1979 char keybuf[9];
1980
1981 if ( which == kControlUserPaneDrawProcTag )
1982 *uppp = mydrawproc_upp;
1983 else if ( which == kControlUserPaneIdleProcTag )
1984 *uppp = myidleproc_upp;
1985 else
1986 return -1;
1987 /* Only now do we test for clearing of the callback: */
1988 if ( callback == Py_None )
1989 *uppp = NULL;
1990 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
1991 if ( self->ob_callbackdict == NULL )
1992 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
1993 return -1;
1994 /* And store the Python callback */
1995 sprintf(keybuf, "%x", which);
1996 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
1997 return -1;
1998 return 0;
1999}
2000
2001static PyObject *
2002callcallback(self, which, arglist)
2003 ControlObject *self;
2004 OSType which;
2005 PyObject *arglist;
2006{
2007 char keybuf[9];
2008 PyObject *func, *rv;
2009
2010 sprintf(keybuf, "%x", which);
2011 if ( self->ob_callbackdict == NULL ||
2012 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
2013 PySys_WriteStderr("Control callback without callback object\n");
2014 return NULL;
2015 }
2016 rv = PyEval_CallObject(func, arglist);
2017 if ( rv == NULL )
2018 PySys_WriteStderr("Exception in control callback handler\n");
2019 return rv;
2020}
2021
2022static pascal void
2023mydrawproc(ControlHandle control, SInt16 part)
2024{
2025 ControlObject *ctl_obj;
2026 PyObject *arglist, *rv;
2027
2028 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2029 arglist = Py_BuildValue("Oh", ctl_obj, part);
2030 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2031 Py_XDECREF(arglist);
2032 Py_XDECREF(rv);
2033}
2034
2035static pascal void
2036myidleproc(ControlHandle control)
2037{
2038 ControlObject *ctl_obj;
2039 PyObject *arglist, *rv;
2040
2041 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2042 arglist = Py_BuildValue("O", ctl_obj);
2043 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2044 Py_XDECREF(arglist);
2045 Py_XDECREF(rv);
2046}
2047
2048
Guido van Rossum17448e21995-01-30 11:53:55 +00002049
2050void initCtl()
2051{
2052 PyObject *m;
2053 PyObject *d;
2054
2055
2056
Jack Jansen848250c1998-05-28 14:20:09 +00002057 mytracker_upp = NewControlActionProc(mytracker);
Jack Jansenabc411b2000-03-20 16:09:09 +00002058 mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc);
2059 myidleproc_upp = NewControlUserPaneDrawProc(myidleproc);
Jack Jansen848250c1998-05-28 14:20:09 +00002060
Guido van Rossum17448e21995-01-30 11:53:55 +00002061
2062 m = Py_InitModule("Ctl", Ctl_methods);
2063 d = PyModule_GetDict(m);
2064 Ctl_Error = PyMac_GetOSErrException();
2065 if (Ctl_Error == NULL ||
2066 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
2067 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00002068 Control_Type.ob_type = &PyType_Type;
2069 Py_INCREF(&Control_Type);
2070 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2071 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00002072}
2073
2074/* ========================= End module Ctl ========================= */
2075