blob: 863276773b266feef0d9fd63e4681c647a6fcca0 [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 Jansene79dc762000-06-02 21:35:07 +000049#ifdef TARGET_API_MAC_CARBON
50#define GetControlRect(ctl, rectp) GetControlBounds(ctl, rectp)
51#else
Jack Jansen1a7d5b12000-03-21 16:25:23 +000052#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
Jack Jansene79dc762000-06-02 21:35:07 +000053#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000054#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
55
56extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
Jack Jansen21f96871998-02-20 16:02:09 +000057extern PyObject *QdRGB_New(RGBColorPtr);
58extern QdRGB_Convert(PyObject *, RGBColorPtr);
Guido van Rossum17448e21995-01-30 11:53:55 +000059
Jack Jansen21f96871998-02-20 16:02:09 +000060/*
61** Parse/generate ControlFontStyleRec records
62*/
63#if 0 /* Not needed */
64PyObject *ControlFontStyle_New(itself)
65 ControlFontStyleRec *itself;
66{
67
68 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
69 itself->size, itself->style, itself->mode, itself->just,
70 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
71}
72#endif
73
74ControlFontStyle_Convert(v, itself)
75 PyObject *v;
76 ControlFontStyleRec *itself;
77{
78 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000079 &itself->font, &itself->size, &itself->style, &itself->mode,
80 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000081 QdRGB_Convert, &itself->backColor);
82}
83
Jack Jansen24c35311999-12-09 22:49:51 +000084/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000085static PyObject *tracker;
86static ControlActionUPP mytracker_upp;
Jack Jansene79dc762000-06-02 21:35:07 +000087#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +000088static ControlUserPaneDrawUPP mydrawproc_upp;
89static ControlUserPaneIdleUPP myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +000090static ControlUserPaneHitTestUPP myhittestproc_upp;
91static ControlUserPaneTrackingUPP mytrackingproc_upp;
Jack Jansene79dc762000-06-02 21:35:07 +000092#endif
Jack Jansen848250c1998-05-28 14:20:09 +000093
94extern int settrackfunc(PyObject *); /* forward */
95extern void clrtrackfunc(void); /* forward */
Jack Jansen85152b92000-07-11 21:12:55 +000096#ifndef TARGET_API_MAC_CARBON_NOTYET
97staticforward int setcallback(PyObject *, OSType, PyObject *, UniversalProcPtr *);
98#endif
Jack Jansen848250c1998-05-28 14:20:09 +000099
Guido van Rossum17448e21995-01-30 11:53:55 +0000100static PyObject *Ctl_Error;
101
102/* ---------------------- Object type Control ----------------------- */
103
104PyTypeObject Control_Type;
105
106#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
107
108typedef struct ControlObject {
109 PyObject_HEAD
110 ControlHandle ob_itself;
Jack Jansenabc411b2000-03-20 16:09:09 +0000111 PyObject *ob_callbackdict;
Guido van Rossum17448e21995-01-30 11:53:55 +0000112} ControlObject;
113
114PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000115 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000116{
117 ControlObject *it;
118 if (itself == NULL) return PyMac_Error(resNotFound);
119 it = PyObject_NEW(ControlObject, &Control_Type);
120 if (it == NULL) return NULL;
121 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000122 SetControlReference(itself, (long)it);
Jack Jansenabc411b2000-03-20 16:09:09 +0000123 it->ob_callbackdict = NULL;
Guido van Rossum17448e21995-01-30 11:53:55 +0000124 return (PyObject *)it;
125}
126CtlObj_Convert(v, p_itself)
127 PyObject *v;
128 ControlHandle *p_itself;
129{
130 if (!CtlObj_Check(v))
131 {
132 PyErr_SetString(PyExc_TypeError, "Control required");
133 return 0;
134 }
135 *p_itself = ((ControlObject *)v)->ob_itself;
136 return 1;
137}
138
139static void CtlObj_dealloc(self)
140 ControlObject *self;
141{
Jack Jansenabc411b2000-03-20 16:09:09 +0000142 Py_XDECREF(self->ob_callbackdict);
Jack Jansen24c35311999-12-09 22:49:51 +0000143 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000144 PyMem_DEL(self);
145}
146
Jack Jansen21f96871998-02-20 16:02:09 +0000147static PyObject *CtlObj_HiliteControl(_self, _args)
148 ControlObject *_self;
149 PyObject *_args;
150{
151 PyObject *_res = NULL;
152 ControlPartCode hiliteState;
153 if (!PyArg_ParseTuple(_args, "h",
154 &hiliteState))
155 return NULL;
156 HiliteControl(_self->ob_itself,
157 hiliteState);
158 Py_INCREF(Py_None);
159 _res = Py_None;
160 return _res;
161}
162
Jack Jansen7d0bc831995-06-09 20:56:31 +0000163static PyObject *CtlObj_ShowControl(_self, _args)
164 ControlObject *_self;
165 PyObject *_args;
166{
167 PyObject *_res = NULL;
168 if (!PyArg_ParseTuple(_args, ""))
169 return NULL;
170 ShowControl(_self->ob_itself);
171 Py_INCREF(Py_None);
172 _res = Py_None;
173 return _res;
174}
175
176static PyObject *CtlObj_HideControl(_self, _args)
177 ControlObject *_self;
178 PyObject *_args;
179{
180 PyObject *_res = NULL;
181 if (!PyArg_ParseTuple(_args, ""))
182 return NULL;
183 HideControl(_self->ob_itself);
184 Py_INCREF(Py_None);
185 _res = Py_None;
186 return _res;
187}
188
Jack Jansen21f96871998-02-20 16:02:09 +0000189static PyObject *CtlObj_IsControlActive(_self, _args)
190 ControlObject *_self;
191 PyObject *_args;
192{
193 PyObject *_res = NULL;
194 Boolean _rv;
195 if (!PyArg_ParseTuple(_args, ""))
196 return NULL;
197 _rv = IsControlActive(_self->ob_itself);
198 _res = Py_BuildValue("b",
199 _rv);
200 return _res;
201}
202
203static PyObject *CtlObj_IsControlVisible(_self, _args)
204 ControlObject *_self;
205 PyObject *_args;
206{
207 PyObject *_res = NULL;
208 Boolean _rv;
209 if (!PyArg_ParseTuple(_args, ""))
210 return NULL;
211 _rv = IsControlVisible(_self->ob_itself);
212 _res = Py_BuildValue("b",
213 _rv);
214 return _res;
215}
216
217static PyObject *CtlObj_ActivateControl(_self, _args)
218 ControlObject *_self;
219 PyObject *_args;
220{
221 PyObject *_res = NULL;
222 OSErr _err;
223 if (!PyArg_ParseTuple(_args, ""))
224 return NULL;
225 _err = ActivateControl(_self->ob_itself);
226 if (_err != noErr) return PyMac_Error(_err);
227 Py_INCREF(Py_None);
228 _res = Py_None;
229 return _res;
230}
231
232static PyObject *CtlObj_DeactivateControl(_self, _args)
233 ControlObject *_self;
234 PyObject *_args;
235{
236 PyObject *_res = NULL;
237 OSErr _err;
238 if (!PyArg_ParseTuple(_args, ""))
239 return NULL;
240 _err = DeactivateControl(_self->ob_itself);
241 if (_err != noErr) return PyMac_Error(_err);
242 Py_INCREF(Py_None);
243 _res = Py_None;
244 return _res;
245}
246
247static PyObject *CtlObj_SetControlVisibility(_self, _args)
248 ControlObject *_self;
249 PyObject *_args;
250{
251 PyObject *_res = NULL;
252 OSErr _err;
253 Boolean inIsVisible;
254 Boolean inDoDraw;
255 if (!PyArg_ParseTuple(_args, "bb",
256 &inIsVisible,
257 &inDoDraw))
258 return NULL;
259 _err = SetControlVisibility(_self->ob_itself,
260 inIsVisible,
261 inDoDraw);
262 if (_err != noErr) return PyMac_Error(_err);
263 Py_INCREF(Py_None);
264 _res = Py_None;
265 return _res;
266}
267
Jack Jansen7d0bc831995-06-09 20:56:31 +0000268static PyObject *CtlObj_Draw1Control(_self, _args)
269 ControlObject *_self;
270 PyObject *_args;
271{
272 PyObject *_res = NULL;
273 if (!PyArg_ParseTuple(_args, ""))
274 return NULL;
275 Draw1Control(_self->ob_itself);
276 Py_INCREF(Py_None);
277 _res = Py_None;
278 return _res;
279}
280
Jack Jansen21f96871998-02-20 16:02:09 +0000281static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000282 ControlObject *_self;
283 PyObject *_args;
284{
285 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000286 OSErr _err;
287 Rect outRect;
288 SInt16 outBaseLineOffset;
289 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000290 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000291 _err = GetBestControlRect(_self->ob_itself,
292 &outRect,
293 &outBaseLineOffset);
294 if (_err != noErr) return PyMac_Error(_err);
295 _res = Py_BuildValue("O&h",
296 PyMac_BuildRect, &outRect,
297 outBaseLineOffset);
298 return _res;
299}
300
301static PyObject *CtlObj_SetControlFontStyle(_self, _args)
302 ControlObject *_self;
303 PyObject *_args;
304{
305 PyObject *_res = NULL;
306 OSErr _err;
307 ControlFontStyleRec inStyle;
308 if (!PyArg_ParseTuple(_args, "O&",
309 ControlFontStyle_Convert, &inStyle))
310 return NULL;
311 _err = SetControlFontStyle(_self->ob_itself,
312 &inStyle);
313 if (_err != noErr) return PyMac_Error(_err);
314 Py_INCREF(Py_None);
315 _res = Py_None;
316 return _res;
317}
318
319static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
320 ControlObject *_self;
321 PyObject *_args;
322{
323 PyObject *_res = NULL;
324 if (!PyArg_ParseTuple(_args, ""))
325 return NULL;
326 DrawControlInCurrentPort(_self->ob_itself);
327 Py_INCREF(Py_None);
328 _res = Py_None;
329 return _res;
330}
331
332static PyObject *CtlObj_SetUpControlBackground(_self, _args)
333 ControlObject *_self;
334 PyObject *_args;
335{
336 PyObject *_res = NULL;
337 OSErr _err;
338 SInt16 inDepth;
339 Boolean inIsColorDevice;
340 if (!PyArg_ParseTuple(_args, "hb",
341 &inDepth,
342 &inIsColorDevice))
343 return NULL;
344 _err = SetUpControlBackground(_self->ob_itself,
345 inDepth,
346 inIsColorDevice);
347 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000348 Py_INCREF(Py_None);
349 _res = Py_None;
350 return _res;
351}
352
Jack Jansena05ac601999-12-12 21:41:51 +0000353static PyObject *CtlObj_SetUpControlTextColor(_self, _args)
354 ControlObject *_self;
355 PyObject *_args;
356{
357 PyObject *_res = NULL;
358 OSErr _err;
359 SInt16 inDepth;
360 Boolean inIsColorDevice;
361 if (!PyArg_ParseTuple(_args, "hb",
362 &inDepth,
363 &inIsColorDevice))
364 return NULL;
365 _err = SetUpControlTextColor(_self->ob_itself,
366 inDepth,
367 inIsColorDevice);
368 if (_err != noErr) return PyMac_Error(_err);
369 Py_INCREF(Py_None);
370 _res = Py_None;
371 return _res;
372}
373
Jack Jansen7d0bc831995-06-09 20:56:31 +0000374static PyObject *CtlObj_DragControl(_self, _args)
375 ControlObject *_self;
376 PyObject *_args;
377{
378 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000379 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000380 Rect limitRect;
381 Rect slopRect;
382 DragConstraint axis;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000383 if (!PyArg_ParseTuple(_args, "O&O&O&H",
Jack Jansen754d4a41995-11-14 10:41:55 +0000384 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000385 PyMac_GetRect, &limitRect,
386 PyMac_GetRect, &slopRect,
387 &axis))
388 return NULL;
389 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000390 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000391 &limitRect,
392 &slopRect,
393 axis);
394 Py_INCREF(Py_None);
395 _res = Py_None;
396 return _res;
397}
398
399static PyObject *CtlObj_TestControl(_self, _args)
400 ControlObject *_self;
401 PyObject *_args;
402{
403 PyObject *_res = NULL;
404 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000405 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000406 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000407 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000408 return NULL;
409 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000410 testPoint);
411 _res = Py_BuildValue("h",
412 _rv);
413 return _res;
414}
415
416static PyObject *CtlObj_HandleControlKey(_self, _args)
417 ControlObject *_self;
418 PyObject *_args;
419{
420 PyObject *_res = NULL;
421 SInt16 _rv;
422 SInt16 inKeyCode;
423 SInt16 inCharCode;
424 SInt16 inModifiers;
425 if (!PyArg_ParseTuple(_args, "hhh",
426 &inKeyCode,
427 &inCharCode,
428 &inModifiers))
429 return NULL;
430 _rv = HandleControlKey(_self->ob_itself,
431 inKeyCode,
432 inCharCode,
433 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000434 _res = Py_BuildValue("h",
435 _rv);
436 return _res;
437}
438
439static PyObject *CtlObj_MoveControl(_self, _args)
440 ControlObject *_self;
441 PyObject *_args;
442{
443 PyObject *_res = NULL;
444 SInt16 h;
445 SInt16 v;
446 if (!PyArg_ParseTuple(_args, "hh",
447 &h,
448 &v))
449 return NULL;
450 MoveControl(_self->ob_itself,
451 h,
452 v);
453 Py_INCREF(Py_None);
454 _res = Py_None;
455 return _res;
456}
457
458static PyObject *CtlObj_SizeControl(_self, _args)
459 ControlObject *_self;
460 PyObject *_args;
461{
462 PyObject *_res = NULL;
463 SInt16 w;
464 SInt16 h;
465 if (!PyArg_ParseTuple(_args, "hh",
466 &w,
467 &h))
468 return NULL;
469 SizeControl(_self->ob_itself,
470 w,
471 h);
472 Py_INCREF(Py_None);
473 _res = Py_None;
474 return _res;
475}
476
Jack Jansenae8a68f1995-06-06 12:55:40 +0000477static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000478 ControlObject *_self;
479 PyObject *_args;
480{
481 PyObject *_res = NULL;
482 Str255 title;
483 if (!PyArg_ParseTuple(_args, "O&",
484 PyMac_GetStr255, title))
485 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000486 SetControlTitle(_self->ob_itself,
487 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000488 Py_INCREF(Py_None);
489 _res = Py_None;
490 return _res;
491}
492
Jack Jansenae8a68f1995-06-06 12:55:40 +0000493static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000494 ControlObject *_self;
495 PyObject *_args;
496{
497 PyObject *_res = NULL;
498 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000499 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000500 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000501 GetControlTitle(_self->ob_itself,
502 title);
Jack Jansen41009001999-03-07 20:05:20 +0000503 _res = Py_BuildValue("O&",
504 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000505 return _res;
506}
507
Jack Jansenae8a68f1995-06-06 12:55:40 +0000508static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000509 ControlObject *_self;
510 PyObject *_args;
511{
512 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000513 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000514 if (!PyArg_ParseTuple(_args, ""))
515 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000516 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000517 _res = Py_BuildValue("h",
518 _rv);
519 return _res;
520}
521
Jack Jansen7d0bc831995-06-09 20:56:31 +0000522static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000523 ControlObject *_self;
524 PyObject *_args;
525{
526 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000527 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000528 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000529 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000530 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000531 SetControlValue(_self->ob_itself,
532 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000533 Py_INCREF(Py_None);
534 _res = Py_None;
535 return _res;
536}
537
Jack Jansenae8a68f1995-06-06 12:55:40 +0000538static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000539 ControlObject *_self;
540 PyObject *_args;
541{
542 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000543 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000544 if (!PyArg_ParseTuple(_args, ""))
545 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000546 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000547 _res = Py_BuildValue("h",
548 _rv);
549 return _res;
550}
551
Jack Jansen7d0bc831995-06-09 20:56:31 +0000552static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000553 ControlObject *_self;
554 PyObject *_args;
555{
556 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000557 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000558 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000559 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000560 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000561 SetControlMinimum(_self->ob_itself,
562 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000563 Py_INCREF(Py_None);
564 _res = Py_None;
565 return _res;
566}
567
Jack Jansenae8a68f1995-06-06 12:55:40 +0000568static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000569 ControlObject *_self;
570 PyObject *_args;
571{
572 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000573 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000574 if (!PyArg_ParseTuple(_args, ""))
575 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000576 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000577 _res = Py_BuildValue("h",
578 _rv);
579 return _res;
580}
581
Jack Jansen7d0bc831995-06-09 20:56:31 +0000582static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000583 ControlObject *_self;
584 PyObject *_args;
585{
586 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000587 SInt16 newMaximum;
588 if (!PyArg_ParseTuple(_args, "h",
589 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000590 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000591 SetControlMaximum(_self->ob_itself,
592 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000593 Py_INCREF(Py_None);
594 _res = Py_None;
595 return _res;
596}
597
Jack Jansena05ac601999-12-12 21:41:51 +0000598static PyObject *CtlObj_GetControlViewSize(_self, _args)
599 ControlObject *_self;
600 PyObject *_args;
601{
602 PyObject *_res = NULL;
603 SInt32 _rv;
604 if (!PyArg_ParseTuple(_args, ""))
605 return NULL;
606 _rv = GetControlViewSize(_self->ob_itself);
607 _res = Py_BuildValue("l",
608 _rv);
609 return _res;
610}
611
612static PyObject *CtlObj_SetControlViewSize(_self, _args)
613 ControlObject *_self;
614 PyObject *_args;
615{
616 PyObject *_res = NULL;
617 SInt32 newViewSize;
618 if (!PyArg_ParseTuple(_args, "l",
619 &newViewSize))
620 return NULL;
621 SetControlViewSize(_self->ob_itself,
622 newViewSize);
623 Py_INCREF(Py_None);
624 _res = Py_None;
625 return _res;
626}
627
628static PyObject *CtlObj_GetControl32BitValue(_self, _args)
629 ControlObject *_self;
630 PyObject *_args;
631{
632 PyObject *_res = NULL;
633 SInt32 _rv;
634 if (!PyArg_ParseTuple(_args, ""))
635 return NULL;
636 _rv = GetControl32BitValue(_self->ob_itself);
637 _res = Py_BuildValue("l",
638 _rv);
639 return _res;
640}
641
642static PyObject *CtlObj_SetControl32BitValue(_self, _args)
643 ControlObject *_self;
644 PyObject *_args;
645{
646 PyObject *_res = NULL;
647 SInt32 newValue;
648 if (!PyArg_ParseTuple(_args, "l",
649 &newValue))
650 return NULL;
651 SetControl32BitValue(_self->ob_itself,
652 newValue);
653 Py_INCREF(Py_None);
654 _res = Py_None;
655 return _res;
656}
657
658static PyObject *CtlObj_GetControl32BitMaximum(_self, _args)
659 ControlObject *_self;
660 PyObject *_args;
661{
662 PyObject *_res = NULL;
663 SInt32 _rv;
664 if (!PyArg_ParseTuple(_args, ""))
665 return NULL;
666 _rv = GetControl32BitMaximum(_self->ob_itself);
667 _res = Py_BuildValue("l",
668 _rv);
669 return _res;
670}
671
672static PyObject *CtlObj_SetControl32BitMaximum(_self, _args)
673 ControlObject *_self;
674 PyObject *_args;
675{
676 PyObject *_res = NULL;
677 SInt32 newMaximum;
678 if (!PyArg_ParseTuple(_args, "l",
679 &newMaximum))
680 return NULL;
681 SetControl32BitMaximum(_self->ob_itself,
682 newMaximum);
683 Py_INCREF(Py_None);
684 _res = Py_None;
685 return _res;
686}
687
688static PyObject *CtlObj_GetControl32BitMinimum(_self, _args)
689 ControlObject *_self;
690 PyObject *_args;
691{
692 PyObject *_res = NULL;
693 SInt32 _rv;
694 if (!PyArg_ParseTuple(_args, ""))
695 return NULL;
696 _rv = GetControl32BitMinimum(_self->ob_itself);
697 _res = Py_BuildValue("l",
698 _rv);
699 return _res;
700}
701
702static PyObject *CtlObj_SetControl32BitMinimum(_self, _args)
703 ControlObject *_self;
704 PyObject *_args;
705{
706 PyObject *_res = NULL;
707 SInt32 newMinimum;
708 if (!PyArg_ParseTuple(_args, "l",
709 &newMinimum))
710 return NULL;
711 SetControl32BitMinimum(_self->ob_itself,
712 newMinimum);
713 Py_INCREF(Py_None);
714 _res = Py_None;
715 return _res;
716}
717
718static PyObject *CtlObj_IsValidControlHandle(_self, _args)
719 ControlObject *_self;
720 PyObject *_args;
721{
722 PyObject *_res = NULL;
723 Boolean _rv;
724 if (!PyArg_ParseTuple(_args, ""))
725 return NULL;
726 _rv = IsValidControlHandle(_self->ob_itself);
727 _res = Py_BuildValue("b",
728 _rv);
729 return _res;
730}
731
732static PyObject *CtlObj_RemoveControlProperty(_self, _args)
733 ControlObject *_self;
734 PyObject *_args;
735{
736 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000737 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000738 OSType propertyCreator;
739 OSType propertyTag;
740 if (!PyArg_ParseTuple(_args, "O&O&",
741 PyMac_GetOSType, &propertyCreator,
742 PyMac_GetOSType, &propertyTag))
743 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000744 _err = RemoveControlProperty(_self->ob_itself,
745 propertyCreator,
746 propertyTag);
747 if (_err != noErr) return PyMac_Error(_err);
748 Py_INCREF(Py_None);
749 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000750 return _res;
751}
752
753static PyObject *CtlObj_GetControlRegion(_self, _args)
754 ControlObject *_self;
755 PyObject *_args;
756{
757 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000758 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000759 ControlPartCode inPart;
760 RgnHandle outRegion;
761 if (!PyArg_ParseTuple(_args, "hO&",
762 &inPart,
763 ResObj_Convert, &outRegion))
764 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000765 _err = GetControlRegion(_self->ob_itself,
766 inPart,
767 outRegion);
768 if (_err != noErr) return PyMac_Error(_err);
769 Py_INCREF(Py_None);
770 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000771 return _res;
772}
773
Jack Jansen7d0bc831995-06-09 20:56:31 +0000774static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000775 ControlObject *_self;
776 PyObject *_args;
777{
778 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000779 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000780 if (!PyArg_ParseTuple(_args, ""))
781 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000782 _rv = GetControlVariant(_self->ob_itself);
783 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000784 _rv);
785 return _res;
786}
787
Jack Jansen7d0bc831995-06-09 20:56:31 +0000788static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000789 ControlObject *_self;
790 PyObject *_args;
791{
792 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000793 SInt32 data;
794 if (!PyArg_ParseTuple(_args, "l",
795 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000796 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000797 SetControlReference(_self->ob_itself,
798 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000799 Py_INCREF(Py_None);
800 _res = Py_None;
801 return _res;
802}
803
Jack Jansen7d0bc831995-06-09 20:56:31 +0000804static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000805 ControlObject *_self;
806 PyObject *_args;
807{
808 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000809 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000810 if (!PyArg_ParseTuple(_args, ""))
811 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000812 _rv = GetControlReference(_self->ob_itself);
813 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000814 _rv);
815 return _res;
816}
817
Jack Jansene79dc762000-06-02 21:35:07 +0000818#ifndef TARGET_API_MAC_CARBON
819
Jack Jansenc7fefed1997-08-15 14:32:18 +0000820static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
821 ControlObject *_self;
822 PyObject *_args;
823{
824 PyObject *_res = NULL;
825 Boolean _rv;
826 AuxCtlHandle acHndl;
827 if (!PyArg_ParseTuple(_args, ""))
828 return NULL;
829 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
830 &acHndl);
831 _res = Py_BuildValue("bO&",
832 _rv,
833 ResObj_New, acHndl);
834 return _res;
835}
Jack Jansene79dc762000-06-02 21:35:07 +0000836#endif
837
838#ifndef TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +0000839
840static PyObject *CtlObj_SetControlColor(_self, _args)
841 ControlObject *_self;
842 PyObject *_args;
843{
844 PyObject *_res = NULL;
845 CCTabHandle newColorTable;
846 if (!PyArg_ParseTuple(_args, "O&",
847 ResObj_Convert, &newColorTable))
848 return NULL;
849 SetControlColor(_self->ob_itself,
850 newColorTable);
851 Py_INCREF(Py_None);
852 _res = Py_None;
853 return _res;
854}
Jack Jansene79dc762000-06-02 21:35:07 +0000855#endif
856
857static PyObject *CtlObj_GetBevelButtonMenuValue(_self, _args)
858 ControlObject *_self;
859 PyObject *_args;
860{
861 PyObject *_res = NULL;
862 OSErr _err;
863 SInt16 outValue;
864 if (!PyArg_ParseTuple(_args, ""))
865 return NULL;
866 _err = GetBevelButtonMenuValue(_self->ob_itself,
867 &outValue);
868 if (_err != noErr) return PyMac_Error(_err);
869 _res = Py_BuildValue("h",
870 outValue);
871 return _res;
872}
873
874static PyObject *CtlObj_SetBevelButtonMenuValue(_self, _args)
875 ControlObject *_self;
876 PyObject *_args;
877{
878 PyObject *_res = NULL;
879 OSErr _err;
880 SInt16 inValue;
881 if (!PyArg_ParseTuple(_args, "h",
882 &inValue))
883 return NULL;
884 _err = SetBevelButtonMenuValue(_self->ob_itself,
885 inValue);
886 if (_err != noErr) return PyMac_Error(_err);
887 Py_INCREF(Py_None);
888 _res = Py_None;
889 return _res;
890}
891
892static PyObject *CtlObj_GetBevelButtonMenuHandle(_self, _args)
893 ControlObject *_self;
894 PyObject *_args;
895{
896 PyObject *_res = NULL;
897 OSErr _err;
898 MenuHandle outHandle;
899 if (!PyArg_ParseTuple(_args, ""))
900 return NULL;
901 _err = GetBevelButtonMenuHandle(_self->ob_itself,
902 &outHandle);
903 if (_err != noErr) return PyMac_Error(_err);
904 _res = Py_BuildValue("O&",
905 MenuObj_New, outHandle);
906 return _res;
907}
908
909static PyObject *CtlObj_SetBevelButtonTransform(_self, _args)
910 ControlObject *_self;
911 PyObject *_args;
912{
913 PyObject *_res = NULL;
914 OSErr _err;
915 IconTransformType transform;
916 if (!PyArg_ParseTuple(_args, "h",
917 &transform))
918 return NULL;
919 _err = SetBevelButtonTransform(_self->ob_itself,
920 transform);
921 if (_err != noErr) return PyMac_Error(_err);
922 Py_INCREF(Py_None);
923 _res = Py_None;
924 return _res;
925}
926
927static PyObject *CtlObj_SetImageWellTransform(_self, _args)
928 ControlObject *_self;
929 PyObject *_args;
930{
931 PyObject *_res = NULL;
932 OSErr _err;
933 IconTransformType inTransform;
934 if (!PyArg_ParseTuple(_args, "h",
935 &inTransform))
936 return NULL;
937 _err = SetImageWellTransform(_self->ob_itself,
938 inTransform);
939 if (_err != noErr) return PyMac_Error(_err);
940 Py_INCREF(Py_None);
941 _res = Py_None;
942 return _res;
943}
944
945static PyObject *CtlObj_GetTabContentRect(_self, _args)
946 ControlObject *_self;
947 PyObject *_args;
948{
949 PyObject *_res = NULL;
950 OSErr _err;
951 Rect outContentRect;
952 if (!PyArg_ParseTuple(_args, ""))
953 return NULL;
954 _err = GetTabContentRect(_self->ob_itself,
955 &outContentRect);
956 if (_err != noErr) return PyMac_Error(_err);
957 _res = Py_BuildValue("O&",
958 PyMac_BuildRect, &outContentRect);
959 return _res;
960}
961
962static PyObject *CtlObj_SetTabEnabled(_self, _args)
963 ControlObject *_self;
964 PyObject *_args;
965{
966 PyObject *_res = NULL;
967 OSErr _err;
968 SInt16 inTabToHilite;
969 Boolean inEnabled;
970 if (!PyArg_ParseTuple(_args, "hb",
971 &inTabToHilite,
972 &inEnabled))
973 return NULL;
974 _err = SetTabEnabled(_self->ob_itself,
975 inTabToHilite,
976 inEnabled);
977 if (_err != noErr) return PyMac_Error(_err);
978 Py_INCREF(Py_None);
979 _res = Py_None;
980 return _res;
981}
982
983static PyObject *CtlObj_SetDisclosureTriangleLastValue(_self, _args)
984 ControlObject *_self;
985 PyObject *_args;
986{
987 PyObject *_res = NULL;
988 OSErr _err;
989 SInt16 inValue;
990 if (!PyArg_ParseTuple(_args, "h",
991 &inValue))
992 return NULL;
993 _err = SetDisclosureTriangleLastValue(_self->ob_itself,
994 inValue);
995 if (_err != noErr) return PyMac_Error(_err);
996 Py_INCREF(Py_None);
997 _res = Py_None;
998 return _res;
999}
Jack Jansenc7fefed1997-08-15 14:32:18 +00001000
Jack Jansen21f96871998-02-20 16:02:09 +00001001static PyObject *CtlObj_SendControlMessage(_self, _args)
1002 ControlObject *_self;
1003 PyObject *_args;
1004{
1005 PyObject *_res = NULL;
1006 SInt32 _rv;
1007 SInt16 inMessage;
1008 SInt32 inParam;
1009 if (!PyArg_ParseTuple(_args, "hl",
1010 &inMessage,
1011 &inParam))
1012 return NULL;
1013 _rv = SendControlMessage(_self->ob_itself,
1014 inMessage,
1015 inParam);
1016 _res = Py_BuildValue("l",
1017 _rv);
1018 return _res;
1019}
1020
1021static PyObject *CtlObj_EmbedControl(_self, _args)
1022 ControlObject *_self;
1023 PyObject *_args;
1024{
1025 PyObject *_res = NULL;
1026 OSErr _err;
1027 ControlHandle inContainer;
1028 if (!PyArg_ParseTuple(_args, "O&",
1029 CtlObj_Convert, &inContainer))
1030 return NULL;
1031 _err = EmbedControl(_self->ob_itself,
1032 inContainer);
1033 if (_err != noErr) return PyMac_Error(_err);
1034 Py_INCREF(Py_None);
1035 _res = Py_None;
1036 return _res;
1037}
1038
1039static PyObject *CtlObj_AutoEmbedControl(_self, _args)
1040 ControlObject *_self;
1041 PyObject *_args;
1042{
1043 PyObject *_res = NULL;
1044 OSErr _err;
1045 WindowPtr inWindow;
1046 if (!PyArg_ParseTuple(_args, "O&",
1047 WinObj_Convert, &inWindow))
1048 return NULL;
1049 _err = AutoEmbedControl(_self->ob_itself,
1050 inWindow);
1051 if (_err != noErr) return PyMac_Error(_err);
1052 Py_INCREF(Py_None);
1053 _res = Py_None;
1054 return _res;
1055}
1056
1057static PyObject *CtlObj_GetSuperControl(_self, _args)
1058 ControlObject *_self;
1059 PyObject *_args;
1060{
1061 PyObject *_res = NULL;
1062 OSErr _err;
1063 ControlHandle outParent;
1064 if (!PyArg_ParseTuple(_args, ""))
1065 return NULL;
1066 _err = GetSuperControl(_self->ob_itself,
1067 &outParent);
1068 if (_err != noErr) return PyMac_Error(_err);
1069 _res = Py_BuildValue("O&",
1070 CtlObj_WhichControl, outParent);
1071 return _res;
1072}
1073
1074static PyObject *CtlObj_CountSubControls(_self, _args)
1075 ControlObject *_self;
1076 PyObject *_args;
1077{
1078 PyObject *_res = NULL;
1079 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001080 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +00001081 if (!PyArg_ParseTuple(_args, ""))
1082 return NULL;
1083 _err = CountSubControls(_self->ob_itself,
1084 &outNumChildren);
1085 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +00001086 _res = Py_BuildValue("H",
Jack Jansen21f96871998-02-20 16:02:09 +00001087 outNumChildren);
1088 return _res;
1089}
1090
1091static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
1092 ControlObject *_self;
1093 PyObject *_args;
1094{
1095 PyObject *_res = NULL;
1096 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001097 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +00001098 ControlHandle outSubControl;
Jack Jansen0b13e7c2000-07-07 13:09:35 +00001099 if (!PyArg_ParseTuple(_args, "H",
Jack Jansen21f96871998-02-20 16:02:09 +00001100 &inIndex))
1101 return NULL;
1102 _err = GetIndexedSubControl(_self->ob_itself,
1103 inIndex,
1104 &outSubControl);
1105 if (_err != noErr) return PyMac_Error(_err);
1106 _res = Py_BuildValue("O&",
1107 CtlObj_WhichControl, outSubControl);
1108 return _res;
1109}
1110
1111static PyObject *CtlObj_SetControlSupervisor(_self, _args)
1112 ControlObject *_self;
1113 PyObject *_args;
1114{
1115 PyObject *_res = NULL;
1116 OSErr _err;
1117 ControlHandle inBoss;
1118 if (!PyArg_ParseTuple(_args, "O&",
1119 CtlObj_Convert, &inBoss))
1120 return NULL;
1121 _err = SetControlSupervisor(_self->ob_itself,
1122 inBoss);
1123 if (_err != noErr) return PyMac_Error(_err);
1124 Py_INCREF(Py_None);
1125 _res = Py_None;
1126 return _res;
1127}
1128
1129static PyObject *CtlObj_GetControlFeatures(_self, _args)
1130 ControlObject *_self;
1131 PyObject *_args;
1132{
1133 PyObject *_res = NULL;
1134 OSErr _err;
1135 UInt32 outFeatures;
1136 if (!PyArg_ParseTuple(_args, ""))
1137 return NULL;
1138 _err = GetControlFeatures(_self->ob_itself,
1139 &outFeatures);
1140 if (_err != noErr) return PyMac_Error(_err);
1141 _res = Py_BuildValue("l",
1142 outFeatures);
1143 return _res;
1144}
1145
1146static PyObject *CtlObj_GetControlDataSize(_self, _args)
1147 ControlObject *_self;
1148 PyObject *_args;
1149{
1150 PyObject *_res = NULL;
1151 OSErr _err;
1152 ControlPartCode inPart;
1153 ResType inTagName;
1154 Size outMaxSize;
1155 if (!PyArg_ParseTuple(_args, "hO&",
1156 &inPart,
1157 PyMac_GetOSType, &inTagName))
1158 return NULL;
1159 _err = GetControlDataSize(_self->ob_itself,
1160 inPart,
1161 inTagName,
1162 &outMaxSize);
1163 if (_err != noErr) return PyMac_Error(_err);
1164 _res = Py_BuildValue("l",
1165 outMaxSize);
1166 return _res;
1167}
1168
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001169static PyObject *CtlObj_as_Resource(_self, _args)
1170 ControlObject *_self;
1171 PyObject *_args;
1172{
1173 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001174 Handle _rv;
1175 if (!PyArg_ParseTuple(_args, ""))
1176 return NULL;
1177 _rv = as_Resource(_self->ob_itself);
1178 _res = Py_BuildValue("O&",
1179 ResObj_New, _rv);
1180 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001181}
1182
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001183static PyObject *CtlObj_GetControlRect(_self, _args)
1184 ControlObject *_self;
1185 PyObject *_args;
1186{
1187 PyObject *_res = NULL;
1188 Rect rect;
1189 if (!PyArg_ParseTuple(_args, ""))
1190 return NULL;
1191 GetControlRect(_self->ob_itself,
1192 &rect);
1193 _res = Py_BuildValue("O&",
1194 PyMac_BuildRect, &rect);
1195 return _res;
1196}
1197
Jack Jansencfb60ee1996-10-01 10:46:46 +00001198static PyObject *CtlObj_DisposeControl(_self, _args)
1199 ControlObject *_self;
1200 PyObject *_args;
1201{
1202 PyObject *_res = NULL;
1203
1204 if (!PyArg_ParseTuple(_args, ""))
1205 return NULL;
1206 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001207 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001208 DisposeControl(_self->ob_itself);
1209 _self->ob_itself = NULL;
1210 }
1211 Py_INCREF(Py_None);
1212 _res = Py_None;
1213 return _res;
1214
1215}
1216
Jack Jansen848250c1998-05-28 14:20:09 +00001217static PyObject *CtlObj_TrackControl(_self, _args)
1218 ControlObject *_self;
1219 PyObject *_args;
1220{
1221 PyObject *_res = NULL;
1222
1223 ControlPartCode _rv;
1224 Point startPoint;
1225 ControlActionUPP upp = 0;
1226 PyObject *callback = 0;
1227
1228 if (!PyArg_ParseTuple(_args, "O&|O",
1229 PyMac_GetPoint, &startPoint, &callback))
1230 return NULL;
1231 if (callback && callback != Py_None) {
1232 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1233 upp = (ControlActionUPP)-1;
1234 else {
1235 settrackfunc(callback);
1236 upp = mytracker_upp;
1237 }
1238 }
1239 _rv = TrackControl(_self->ob_itself,
1240 startPoint,
1241 upp);
1242 clrtrackfunc();
1243 _res = Py_BuildValue("h",
1244 _rv);
1245 return _res;
1246
1247}
1248
Jack Jansen24c35311999-12-09 22:49:51 +00001249static PyObject *CtlObj_HandleControlClick(_self, _args)
1250 ControlObject *_self;
1251 PyObject *_args;
1252{
1253 PyObject *_res = NULL;
1254
1255 ControlPartCode _rv;
1256 Point startPoint;
1257 SInt16 modifiers;
1258 ControlActionUPP upp = 0;
1259 PyObject *callback = 0;
1260
1261 if (!PyArg_ParseTuple(_args, "O&h|O",
1262 PyMac_GetPoint, &startPoint,
1263 &modifiers,
1264 &callback))
1265 return NULL;
1266 if (callback && callback != Py_None) {
1267 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1268 upp = (ControlActionUPP)-1;
1269 else {
1270 settrackfunc(callback);
1271 upp = mytracker_upp;
1272 }
1273 }
1274 _rv = HandleControlClick(_self->ob_itself,
1275 startPoint,
1276 modifiers,
1277 upp);
1278 clrtrackfunc();
1279 _res = Py_BuildValue("h",
1280 _rv);
1281 return _res;
1282
1283}
1284
1285static PyObject *CtlObj_SetControlData(_self, _args)
1286 ControlObject *_self;
1287 PyObject *_args;
1288{
1289 PyObject *_res = NULL;
1290
1291 OSErr _err;
1292 ControlPartCode inPart;
1293 ResType inTagName;
1294 Size bufferSize;
1295 Ptr buffer;
1296
1297 if (!PyArg_ParseTuple(_args, "hO&s#",
1298 &inPart,
1299 PyMac_GetOSType, &inTagName,
1300 &buffer, &bufferSize))
1301 return NULL;
1302
1303 _err = SetControlData(_self->ob_itself,
1304 inPart,
1305 inTagName,
1306 bufferSize,
1307 buffer);
1308
1309 if (_err != noErr)
1310 return PyMac_Error(_err);
1311 _res = Py_None;
1312 return _res;
1313
1314}
1315
1316static PyObject *CtlObj_GetControlData(_self, _args)
1317 ControlObject *_self;
1318 PyObject *_args;
1319{
1320 PyObject *_res = NULL;
1321
1322 OSErr _err;
1323 ControlPartCode inPart;
1324 ResType inTagName;
1325 Size bufferSize;
1326 Ptr buffer;
1327 Size outSize;
1328
1329 if (!PyArg_ParseTuple(_args, "hO&",
1330 &inPart,
1331 PyMac_GetOSType, &inTagName))
1332 return NULL;
1333
1334 /* allocate a buffer for the data */
1335 _err = GetControlDataSize(_self->ob_itself,
1336 inPart,
1337 inTagName,
1338 &bufferSize);
1339 if (_err != noErr)
1340 return PyMac_Error(_err);
1341 buffer = PyMem_NEW(char, bufferSize);
1342 if (buffer == NULL)
1343 return PyErr_NoMemory();
1344
1345 _err = GetControlData(_self->ob_itself,
1346 inPart,
1347 inTagName,
1348 bufferSize,
1349 buffer,
1350 &outSize);
1351
1352 if (_err != noErr) {
1353 PyMem_DEL(buffer);
1354 return PyMac_Error(_err);
1355 }
1356 _res = Py_BuildValue("s#", buffer, outSize);
1357 PyMem_DEL(buffer);
1358 return _res;
1359
1360}
1361
Jack Jansen1f9249c1999-12-19 00:05:50 +00001362static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1363 ControlObject *_self;
1364 PyObject *_args;
1365{
1366 PyObject *_res = NULL;
1367
1368 OSErr _err;
1369 ControlPartCode inPart;
1370 ResType inTagName;
1371 Handle buffer;
1372
1373 if (!PyArg_ParseTuple(_args, "hO&O&",
1374 &inPart,
1375 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001376 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001377 return NULL;
1378
1379 _err = SetControlData(_self->ob_itself,
1380 inPart,
1381 inTagName,
1382 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001383 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001384
1385 if (_err != noErr)
1386 return PyMac_Error(_err);
1387 _res = Py_None;
1388 return _res;
1389
1390}
1391
1392static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1393 ControlObject *_self;
1394 PyObject *_args;
1395{
1396 PyObject *_res = NULL;
1397
1398 OSErr _err;
1399 ControlPartCode inPart;
1400 ResType inTagName;
1401 Size bufferSize;
1402 Handle hdl;
1403
1404 if (!PyArg_ParseTuple(_args, "hO&",
1405 &inPart,
1406 PyMac_GetOSType, &inTagName))
1407 return NULL;
1408
1409 /* Check it is handle-sized */
1410 _err = GetControlDataSize(_self->ob_itself,
1411 inPart,
1412 inTagName,
1413 &bufferSize);
1414 if (_err != noErr)
1415 return PyMac_Error(_err);
1416 if (bufferSize != sizeof(Handle)) {
1417 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1418 return NULL;
1419 }
1420
1421 _err = GetControlData(_self->ob_itself,
1422 inPart,
1423 inTagName,
1424 sizeof(Handle),
1425 (Ptr)&hdl,
1426 &bufferSize);
1427
1428 if (_err != noErr) {
1429 return PyMac_Error(_err);
1430 }
1431 return Py_BuildValue("O&", OptResObj_New, hdl);
1432
1433}
1434
Jack Jansene79dc762000-06-02 21:35:07 +00001435#ifndef TARGET_API_MAC_CARBON_NOTYET
1436
Jack Jansenabc411b2000-03-20 16:09:09 +00001437static PyObject *CtlObj_SetControlDataCallback(_self, _args)
1438 ControlObject *_self;
1439 PyObject *_args;
1440{
1441 PyObject *_res = NULL;
1442
1443 OSErr _err;
1444 ControlPartCode inPart;
1445 ResType inTagName;
1446 PyObject *callback;
Jack Jansen85152b92000-07-11 21:12:55 +00001447 UniversalProcPtr c_callback;
Jack Jansenabc411b2000-03-20 16:09:09 +00001448
1449 if (!PyArg_ParseTuple(_args, "hO&O",
1450 &inPart,
1451 PyMac_GetOSType, &inTagName,
1452 &callback))
1453 return NULL;
1454
Jack Jansen85152b92000-07-11 21:12:55 +00001455 if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 )
Jack Jansenabc411b2000-03-20 16:09:09 +00001456 return NULL;
1457 _err = SetControlData(_self->ob_itself,
1458 inPart,
1459 inTagName,
1460 sizeof(c_callback),
1461 (Ptr)&c_callback);
1462
1463 if (_err != noErr)
1464 return PyMac_Error(_err);
1465 _res = Py_None;
1466 return _res;
1467
1468}
Jack Jansene79dc762000-06-02 21:35:07 +00001469#endif
1470
1471#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00001472
Jack Jansen4c704131998-06-19 13:35:14 +00001473static PyObject *CtlObj_GetPopupData(_self, _args)
1474 ControlObject *_self;
1475 PyObject *_args;
1476{
1477 PyObject *_res = NULL;
1478
1479 PopupPrivateDataHandle hdl;
1480
1481 if ( (*_self->ob_itself)->contrlData == NULL ) {
1482 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1483 return 0;
1484 }
1485 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1486 HLock((Handle)hdl);
1487 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1488 HUnlock((Handle)hdl);
1489 return _res;
1490
1491}
Jack Jansene79dc762000-06-02 21:35:07 +00001492#endif
1493
1494#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001495
1496static PyObject *CtlObj_SetPopupData(_self, _args)
1497 ControlObject *_self;
1498 PyObject *_args;
1499{
1500 PyObject *_res = NULL;
1501
1502 PopupPrivateDataHandle hdl;
1503 MenuHandle mHandle;
1504 short mID;
1505
1506 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1507 return 0;
1508 if ( (*_self->ob_itself)->contrlData == NULL ) {
1509 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1510 return 0;
1511 }
1512 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1513 (*hdl)->mHandle = mHandle;
1514 (*hdl)->mID = mID;
1515 Py_INCREF(Py_None);
1516 return Py_None;
1517
1518}
Jack Jansene79dc762000-06-02 21:35:07 +00001519#endif
Jack Jansen4c704131998-06-19 13:35:14 +00001520
Guido van Rossum17448e21995-01-30 11:53:55 +00001521static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001522 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1523 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001524 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1525 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001526 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1527 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001528 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1529 "() -> (Boolean _rv)"},
1530 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1531 "() -> (Boolean _rv)"},
1532 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1533 "() -> None"},
1534 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1535 "() -> None"},
1536 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1537 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001538 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1539 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001540 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1541 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1542 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1543 "(ControlFontStyleRec inStyle) -> None"},
1544 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1545 "() -> None"},
1546 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1547 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001548 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1549 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001550 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001551 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001552 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001553 "(Point testPoint) -> (ControlPartCode _rv)"},
1554 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
1555 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001556 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001557 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001558 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001559 "(SInt16 w, SInt16 h) -> None"},
1560 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1561 "(Str255 title) -> None"},
1562 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001563 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001564 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001565 "() -> (SInt16 _rv)"},
1566 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1567 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001568 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001569 "() -> (SInt16 _rv)"},
1570 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1571 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001572 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001573 "() -> (SInt16 _rv)"},
1574 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1575 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001576 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
1577 "() -> (SInt32 _rv)"},
1578 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
1579 "(SInt32 newViewSize) -> None"},
1580 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
1581 "() -> (SInt32 _rv)"},
1582 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
1583 "(SInt32 newValue) -> None"},
1584 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
1585 "() -> (SInt32 _rv)"},
1586 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
1587 "(SInt32 newMaximum) -> None"},
1588 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
1589 "() -> (SInt32 _rv)"},
1590 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
1591 "(SInt32 newMinimum) -> None"},
1592 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
1593 "() -> (Boolean _rv)"},
1594 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00001595 "(OSType propertyCreator, OSType propertyTag) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001596 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00001597 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001598 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001599 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001600 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1601 "(SInt32 data) -> None"},
1602 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1603 "() -> (SInt32 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +00001604
1605#ifndef TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00001606 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1607 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
Jack Jansene79dc762000-06-02 21:35:07 +00001608#endif
1609
1610#ifndef TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00001611 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1612 "(CCTabHandle newColorTable) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00001613#endif
1614 {"GetBevelButtonMenuValue", (PyCFunction)CtlObj_GetBevelButtonMenuValue, 1,
1615 "() -> (SInt16 outValue)"},
1616 {"SetBevelButtonMenuValue", (PyCFunction)CtlObj_SetBevelButtonMenuValue, 1,
1617 "(SInt16 inValue) -> None"},
1618 {"GetBevelButtonMenuHandle", (PyCFunction)CtlObj_GetBevelButtonMenuHandle, 1,
1619 "() -> (MenuHandle outHandle)"},
1620 {"SetBevelButtonTransform", (PyCFunction)CtlObj_SetBevelButtonTransform, 1,
1621 "(IconTransformType transform) -> None"},
1622 {"SetImageWellTransform", (PyCFunction)CtlObj_SetImageWellTransform, 1,
1623 "(IconTransformType inTransform) -> None"},
1624 {"GetTabContentRect", (PyCFunction)CtlObj_GetTabContentRect, 1,
1625 "() -> (Rect outContentRect)"},
1626 {"SetTabEnabled", (PyCFunction)CtlObj_SetTabEnabled, 1,
1627 "(SInt16 inTabToHilite, Boolean inEnabled) -> None"},
1628 {"SetDisclosureTriangleLastValue", (PyCFunction)CtlObj_SetDisclosureTriangleLastValue, 1,
1629 "(SInt16 inValue) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001630 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
1631 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
1632 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
1633 "(ControlHandle inContainer) -> None"},
1634 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
1635 "(WindowPtr inWindow) -> None"},
1636 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
1637 "() -> (ControlHandle outParent)"},
1638 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001639 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001640 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001641 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001642 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
1643 "(ControlHandle inBoss) -> None"},
1644 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
1645 "() -> (UInt32 outFeatures)"},
1646 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
1647 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001648 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00001649 "() -> (Handle _rv)"},
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001650 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
1651 "() -> (Rect rect)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00001652 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1653 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001654 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001655 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
1656 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
1657 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
1658 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
1659 "(stuff) -> None"},
1660 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
1661 "(part, type) -> String"},
Jack Jansen1f9249c1999-12-19 00:05:50 +00001662 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
1663 "(ResObj) -> None"},
1664 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
1665 "(part, type) -> ResObj"},
Jack Jansene79dc762000-06-02 21:35:07 +00001666
1667#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00001668 {"SetControlDataCallback", (PyCFunction)CtlObj_SetControlDataCallback, 1,
1669 "(callbackfunc) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00001670#endif
1671
1672#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001673 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1674 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00001675#endif
1676
1677#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001678 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1679 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00001680#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00001681 {NULL, NULL, 0}
1682};
1683
1684PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1685
1686static PyObject *CtlObj_getattr(self, name)
1687 ControlObject *self;
1688 char *name;
1689{
1690 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1691}
1692
1693#define CtlObj_setattr NULL
1694
Jack Jansen8387af61999-03-13 23:07:32 +00001695static int CtlObj_compare(self, other)
1696 ControlObject *self, *other;
1697{
1698 unsigned long v, w;
1699
1700 if (!CtlObj_Check((PyObject *)other))
1701 {
1702 v=(unsigned long)self;
1703 w=(unsigned long)other;
1704 }
1705 else
1706 {
1707 v=(unsigned long)self->ob_itself;
1708 w=(unsigned long)other->ob_itself;
1709 }
1710 if( v < w ) return -1;
1711 if( v > w ) return 1;
1712 return 0;
1713}
1714
1715#define CtlObj_repr NULL
1716
1717static long CtlObj_hash(self)
1718 ControlObject *self;
1719{
1720 return (long)self->ob_itself;
1721}
1722
Guido van Rossum17448e21995-01-30 11:53:55 +00001723PyTypeObject Control_Type = {
1724 PyObject_HEAD_INIT(&PyType_Type)
1725 0, /*ob_size*/
1726 "Control", /*tp_name*/
1727 sizeof(ControlObject), /*tp_basicsize*/
1728 0, /*tp_itemsize*/
1729 /* methods */
1730 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1731 0, /*tp_print*/
1732 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1733 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00001734 (cmpfunc) CtlObj_compare, /*tp_compare*/
1735 (reprfunc) CtlObj_repr, /*tp_repr*/
1736 (PyNumberMethods *)0, /* tp_as_number */
1737 (PySequenceMethods *)0, /* tp_as_sequence */
1738 (PyMappingMethods *)0, /* tp_as_mapping */
1739 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00001740};
1741
1742/* -------------------- End object type Control --------------------- */
1743
1744
1745static PyObject *Ctl_NewControl(_self, _args)
1746 PyObject *_self;
1747 PyObject *_args;
1748{
1749 PyObject *_res = NULL;
1750 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001751 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001752 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001753 Str255 controlTitle;
1754 Boolean initiallyVisible;
1755 SInt16 initialValue;
1756 SInt16 minimumValue;
1757 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001758 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001759 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001760 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001761 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001762 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001763 PyMac_GetStr255, controlTitle,
1764 &initiallyVisible,
1765 &initialValue,
1766 &minimumValue,
1767 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001768 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001769 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001770 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001771 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001772 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001773 controlTitle,
1774 initiallyVisible,
1775 initialValue,
1776 minimumValue,
1777 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001778 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001779 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001780 _res = Py_BuildValue("O&",
1781 CtlObj_New, _rv);
1782 return _res;
1783}
1784
1785static PyObject *Ctl_GetNewControl(_self, _args)
1786 PyObject *_self;
1787 PyObject *_args;
1788{
1789 PyObject *_res = NULL;
1790 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001791 SInt16 resourceID;
1792 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001793 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001794 &resourceID,
1795 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001796 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001797 _rv = GetNewControl(resourceID,
1798 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001799 _res = Py_BuildValue("O&",
1800 CtlObj_New, _rv);
1801 return _res;
1802}
1803
Guido van Rossum17448e21995-01-30 11:53:55 +00001804static PyObject *Ctl_DrawControls(_self, _args)
1805 PyObject *_self;
1806 PyObject *_args;
1807{
1808 PyObject *_res = NULL;
1809 WindowPtr theWindow;
1810 if (!PyArg_ParseTuple(_args, "O&",
1811 WinObj_Convert, &theWindow))
1812 return NULL;
1813 DrawControls(theWindow);
1814 Py_INCREF(Py_None);
1815 _res = Py_None;
1816 return _res;
1817}
1818
Guido van Rossum17448e21995-01-30 11:53:55 +00001819static PyObject *Ctl_UpdateControls(_self, _args)
1820 PyObject *_self;
1821 PyObject *_args;
1822{
1823 PyObject *_res = NULL;
1824 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001825 RgnHandle updateRegion;
1826 if (!PyArg_ParseTuple(_args, "O&O&",
1827 WinObj_Convert, &theWindow,
1828 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001829 return NULL;
1830 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001831 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001832 Py_INCREF(Py_None);
1833 _res = Py_None;
1834 return _res;
1835}
1836
1837static PyObject *Ctl_FindControl(_self, _args)
1838 PyObject *_self;
1839 PyObject *_args;
1840{
1841 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001842 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001843 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001844 WindowPtr theWindow;
1845 ControlHandle theControl;
1846 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001847 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001848 WinObj_Convert, &theWindow))
1849 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001850 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001851 theWindow,
1852 &theControl);
1853 _res = Py_BuildValue("hO&",
1854 _rv,
1855 CtlObj_WhichControl, theControl);
1856 return _res;
1857}
1858
Jack Jansen21f96871998-02-20 16:02:09 +00001859static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1860 PyObject *_self;
1861 PyObject *_args;
1862{
1863 PyObject *_res = NULL;
1864 ControlHandle _rv;
1865 Point inWhere;
1866 WindowPtr inWindow;
1867 SInt16 outPart;
1868 if (!PyArg_ParseTuple(_args, "O&O&",
1869 PyMac_GetPoint, &inWhere,
1870 WinObj_Convert, &inWindow))
1871 return NULL;
1872 _rv = FindControlUnderMouse(inWhere,
1873 inWindow,
1874 &outPart);
1875 _res = Py_BuildValue("O&h",
1876 CtlObj_New, _rv,
1877 outPart);
1878 return _res;
1879}
1880
1881static PyObject *Ctl_IdleControls(_self, _args)
1882 PyObject *_self;
1883 PyObject *_args;
1884{
1885 PyObject *_res = NULL;
1886 WindowPtr inWindow;
1887 if (!PyArg_ParseTuple(_args, "O&",
1888 WinObj_Convert, &inWindow))
1889 return NULL;
1890 IdleControls(inWindow);
1891 Py_INCREF(Py_None);
1892 _res = Py_None;
1893 return _res;
1894}
1895
1896static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1897 PyObject *_self;
1898 PyObject *_args;
1899{
1900 PyObject *_res = NULL;
1901 OSErr _err;
1902 WindowPtr inWindow;
1903 FSSpec inDumpFile;
1904 if (!PyArg_ParseTuple(_args, "O&O&",
1905 WinObj_Convert, &inWindow,
1906 PyMac_GetFSSpec, &inDumpFile))
1907 return NULL;
1908 _err = DumpControlHierarchy(inWindow,
1909 &inDumpFile);
1910 if (_err != noErr) return PyMac_Error(_err);
1911 Py_INCREF(Py_None);
1912 _res = Py_None;
1913 return _res;
1914}
1915
1916static PyObject *Ctl_CreateRootControl(_self, _args)
1917 PyObject *_self;
1918 PyObject *_args;
1919{
1920 PyObject *_res = NULL;
1921 OSErr _err;
1922 WindowPtr inWindow;
1923 ControlHandle outControl;
1924 if (!PyArg_ParseTuple(_args, "O&",
1925 WinObj_Convert, &inWindow))
1926 return NULL;
1927 _err = CreateRootControl(inWindow,
1928 &outControl);
1929 if (_err != noErr) return PyMac_Error(_err);
1930 _res = Py_BuildValue("O&",
1931 CtlObj_WhichControl, outControl);
1932 return _res;
1933}
1934
1935static PyObject *Ctl_GetRootControl(_self, _args)
1936 PyObject *_self;
1937 PyObject *_args;
1938{
1939 PyObject *_res = NULL;
1940 OSErr _err;
1941 WindowPtr inWindow;
1942 ControlHandle outControl;
1943 if (!PyArg_ParseTuple(_args, "O&",
1944 WinObj_Convert, &inWindow))
1945 return NULL;
1946 _err = GetRootControl(inWindow,
1947 &outControl);
1948 if (_err != noErr) return PyMac_Error(_err);
1949 _res = Py_BuildValue("O&",
1950 CtlObj_WhichControl, outControl);
1951 return _res;
1952}
1953
1954static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1955 PyObject *_self;
1956 PyObject *_args;
1957{
1958 PyObject *_res = NULL;
1959 OSErr _err;
1960 WindowPtr inWindow;
1961 ControlHandle outControl;
1962 if (!PyArg_ParseTuple(_args, "O&",
1963 WinObj_Convert, &inWindow))
1964 return NULL;
1965 _err = GetKeyboardFocus(inWindow,
1966 &outControl);
1967 if (_err != noErr) return PyMac_Error(_err);
1968 _res = Py_BuildValue("O&",
1969 CtlObj_WhichControl, outControl);
1970 return _res;
1971}
1972
1973static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1974 PyObject *_self;
1975 PyObject *_args;
1976{
1977 PyObject *_res = NULL;
1978 OSErr _err;
1979 WindowPtr inWindow;
1980 ControlHandle inControl;
1981 ControlFocusPart inPart;
1982 if (!PyArg_ParseTuple(_args, "O&O&h",
1983 WinObj_Convert, &inWindow,
1984 CtlObj_Convert, &inControl,
1985 &inPart))
1986 return NULL;
1987 _err = SetKeyboardFocus(inWindow,
1988 inControl,
1989 inPart);
1990 if (_err != noErr) return PyMac_Error(_err);
1991 Py_INCREF(Py_None);
1992 _res = Py_None;
1993 return _res;
1994}
1995
1996static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1997 PyObject *_self;
1998 PyObject *_args;
1999{
2000 PyObject *_res = NULL;
2001 OSErr _err;
2002 WindowPtr inWindow;
2003 if (!PyArg_ParseTuple(_args, "O&",
2004 WinObj_Convert, &inWindow))
2005 return NULL;
2006 _err = AdvanceKeyboardFocus(inWindow);
2007 if (_err != noErr) return PyMac_Error(_err);
2008 Py_INCREF(Py_None);
2009 _res = Py_None;
2010 return _res;
2011}
2012
2013static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
2014 PyObject *_self;
2015 PyObject *_args;
2016{
2017 PyObject *_res = NULL;
2018 OSErr _err;
2019 WindowPtr inWindow;
2020 if (!PyArg_ParseTuple(_args, "O&",
2021 WinObj_Convert, &inWindow))
2022 return NULL;
2023 _err = ReverseKeyboardFocus(inWindow);
2024 if (_err != noErr) return PyMac_Error(_err);
2025 Py_INCREF(Py_None);
2026 _res = Py_None;
2027 return _res;
2028}
2029
2030static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
2031 PyObject *_self;
2032 PyObject *_args;
2033{
2034 PyObject *_res = NULL;
2035 OSErr _err;
2036 WindowPtr inWindow;
2037 if (!PyArg_ParseTuple(_args, "O&",
2038 WinObj_Convert, &inWindow))
2039 return NULL;
2040 _err = ClearKeyboardFocus(inWindow);
2041 if (_err != noErr) return PyMac_Error(_err);
2042 Py_INCREF(Py_None);
2043 _res = Py_None;
2044 return _res;
2045}
2046
Jack Jansene0581891999-02-07 14:02:03 +00002047static PyObject *Ctl_as_Control(_self, _args)
2048 PyObject *_self;
2049 PyObject *_args;
2050{
2051 PyObject *_res = NULL;
2052 ControlHandle _rv;
2053 Handle h;
2054 if (!PyArg_ParseTuple(_args, "O&",
2055 ResObj_Convert, &h))
2056 return NULL;
2057 _rv = as_Control(h);
2058 _res = Py_BuildValue("O&",
2059 CtlObj_New, _rv);
2060 return _res;
2061}
2062
Guido van Rossum17448e21995-01-30 11:53:55 +00002063static PyMethodDef Ctl_methods[] = {
2064 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002065 "(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 +00002066 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002067 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002068 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
2069 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002070 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00002071 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002072 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002073 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
2074 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
2075 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
2076 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
2077 "(WindowPtr inWindow) -> None"},
2078 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
2079 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
2080 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
2081 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2082 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
2083 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2084 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
2085 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2086 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
2087 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
2088 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
2089 "(WindowPtr inWindow) -> None"},
2090 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
2091 "(WindowPtr inWindow) -> None"},
2092 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
2093 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00002094 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
2095 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002096 {NULL, NULL, 0}
2097};
2098
2099
2100
Jack Jansen8387af61999-03-13 23:07:32 +00002101PyObject *CtlObj_NewUnmanaged(itself)
2102 ControlHandle itself;
2103{
2104 ControlObject *it;
2105 if (itself == NULL) return PyMac_Error(resNotFound);
2106 it = PyObject_NEW(ControlObject, &Control_Type);
2107 if (it == NULL) return NULL;
2108 it->ob_itself = itself;
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002109 it->ob_callbackdict = NULL;
Jack Jansen8387af61999-03-13 23:07:32 +00002110 return (PyObject *)it;
2111}
2112
Guido van Rossum17448e21995-01-30 11:53:55 +00002113PyObject *
2114CtlObj_WhichControl(ControlHandle c)
2115{
2116 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00002117
Guido van Rossum17448e21995-01-30 11:53:55 +00002118 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00002119 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00002120 else {
2121 it = (PyObject *) GetControlReference(c);
2122 /*
2123 ** If the refcon is zero or doesn't point back to the Python object
2124 ** the control is not ours. Return a temporary object.
2125 */
2126 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
2127 return CtlObj_NewUnmanaged(c);
2128 }
Guido van Rossum17448e21995-01-30 11:53:55 +00002129 Py_INCREF(it);
2130 return it;
2131}
2132
Jack Jansen848250c1998-05-28 14:20:09 +00002133static int
2134settrackfunc(obj)
2135 PyObject *obj;
2136{
2137 if (tracker) {
2138 PyErr_SetString(Ctl_Error, "Tracker function in use");
2139 return 0;
2140 }
2141 tracker = obj;
2142 Py_INCREF(tracker);
2143}
2144
2145static void
2146clrtrackfunc()
2147{
2148 Py_XDECREF(tracker);
2149 tracker = 0;
2150}
2151
2152static pascal void
Jack Jansene79dc762000-06-02 21:35:07 +00002153mytracker(ControlHandle ctl, short part)
Jack Jansen848250c1998-05-28 14:20:09 +00002154{
2155 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00002156
Jack Jansen848250c1998-05-28 14:20:09 +00002157 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
2158 if (args && tracker) {
2159 rv = PyEval_CallObject(tracker, args);
2160 Py_DECREF(args);
2161 }
2162 if (rv)
2163 Py_DECREF(rv);
2164 else
Jack Jansen24c35311999-12-09 22:49:51 +00002165 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00002166}
2167
Jack Jansene79dc762000-06-02 21:35:07 +00002168#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002169static int
Jack Jansen85152b92000-07-11 21:12:55 +00002170setcallback(myself, which, callback, uppp)
2171 PyObject *myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002172 OSType which;
2173 PyObject *callback;
2174 UniversalProcPtr *uppp;
2175{
Jack Jansen85152b92000-07-11 21:12:55 +00002176 ControlObject *self = (ControlObject *)myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002177 char keybuf[9];
2178
2179 if ( which == kControlUserPaneDrawProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002180 *uppp = (UniversalProcPtr)mydrawproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002181 else if ( which == kControlUserPaneIdleProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002182 *uppp = (UniversalProcPtr)myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002183 else if ( which == kControlUserPaneHitTestProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002184 *uppp = (UniversalProcPtr)myhittestproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002185 else if ( which == kControlUserPaneTrackingProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002186 *uppp = (UniversalProcPtr)mytrackingproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002187 else
2188 return -1;
2189 /* Only now do we test for clearing of the callback: */
2190 if ( callback == Py_None )
2191 *uppp = NULL;
2192 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
2193 if ( self->ob_callbackdict == NULL )
2194 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
2195 return -1;
2196 /* And store the Python callback */
2197 sprintf(keybuf, "%x", which);
2198 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
2199 return -1;
2200 return 0;
2201}
2202
2203static PyObject *
2204callcallback(self, which, arglist)
2205 ControlObject *self;
2206 OSType which;
2207 PyObject *arglist;
2208{
2209 char keybuf[9];
2210 PyObject *func, *rv;
2211
2212 sprintf(keybuf, "%x", which);
2213 if ( self->ob_callbackdict == NULL ||
2214 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
Jack Jansena27e9fb2000-03-21 23:03:02 +00002215 PySys_WriteStderr("Control callback %x without callback object\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002216 return NULL;
2217 }
2218 rv = PyEval_CallObject(func, arglist);
2219 if ( rv == NULL )
Jack Jansena27e9fb2000-03-21 23:03:02 +00002220 PySys_WriteStderr("Exception in control callback %x handler\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002221 return rv;
2222}
2223
2224static pascal void
2225mydrawproc(ControlHandle control, SInt16 part)
2226{
2227 ControlObject *ctl_obj;
2228 PyObject *arglist, *rv;
2229
2230 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2231 arglist = Py_BuildValue("Oh", ctl_obj, part);
2232 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2233 Py_XDECREF(arglist);
2234 Py_XDECREF(rv);
2235}
2236
2237static pascal void
2238myidleproc(ControlHandle control)
2239{
2240 ControlObject *ctl_obj;
2241 PyObject *arglist, *rv;
2242
2243 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2244 arglist = Py_BuildValue("O", ctl_obj);
2245 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2246 Py_XDECREF(arglist);
2247 Py_XDECREF(rv);
2248}
2249
Jack Jansena27e9fb2000-03-21 23:03:02 +00002250static pascal ControlPartCode
2251myhittestproc(ControlHandle control, Point where)
2252{
2253 ControlObject *ctl_obj;
2254 PyObject *arglist, *rv;
2255 short c_rv = -1;
2256
2257 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
Jack Jansendeb63732000-03-22 15:35:24 +00002258 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002259 rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
2260 Py_XDECREF(arglist);
2261 /* Ignore errors, nothing we can do about them */
2262 if ( rv )
2263 PyArg_Parse(rv, "h", &c_rv);
2264 Py_XDECREF(rv);
2265 return (ControlPartCode)c_rv;
2266}
2267
2268static pascal ControlPartCode
2269mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
2270{
2271 ControlObject *ctl_obj;
2272 PyObject *arglist, *rv;
2273 short c_rv = -1;
2274
2275 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2276 /* We cannot pass the actionProc without lots of work */
Jack Jansendeb63732000-03-22 15:35:24 +00002277 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002278 rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
2279 Py_XDECREF(arglist);
2280 if ( rv )
2281 PyArg_Parse(rv, "h", &c_rv);
2282 Py_XDECREF(rv);
2283 return (ControlPartCode)c_rv;
2284}
Jack Jansene79dc762000-06-02 21:35:07 +00002285#endif
Jack Jansenabc411b2000-03-20 16:09:09 +00002286
Guido van Rossum17448e21995-01-30 11:53:55 +00002287
2288void initCtl()
2289{
2290 PyObject *m;
2291 PyObject *d;
2292
2293
2294
Jack Jansen848250c1998-05-28 14:20:09 +00002295 mytracker_upp = NewControlActionProc(mytracker);
Jack Jansene79dc762000-06-02 21:35:07 +00002296#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002297 mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc);
Jack Jansen1b6e8212000-04-05 21:30:57 +00002298 myidleproc_upp = NewControlUserPaneIdleProc(myidleproc);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002299 myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc);
2300 mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc);
Jack Jansene79dc762000-06-02 21:35:07 +00002301#endif
Jack Jansen848250c1998-05-28 14:20:09 +00002302
Guido van Rossum17448e21995-01-30 11:53:55 +00002303
2304 m = Py_InitModule("Ctl", Ctl_methods);
2305 d = PyModule_GetDict(m);
2306 Ctl_Error = PyMac_GetOSErrException();
2307 if (Ctl_Error == NULL ||
2308 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
2309 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00002310 Control_Type.ob_type = &PyType_Type;
2311 Py_INCREF(&Control_Type);
2312 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2313 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00002314}
2315
2316/* ========================= End module Ctl ========================= */
2317