blob: cafe0d6645f94c5556e896f9c25503d27d5255d1 [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 */
96
Guido van Rossum17448e21995-01-30 11:53:55 +000097static PyObject *Ctl_Error;
98
99/* ---------------------- Object type Control ----------------------- */
100
101PyTypeObject Control_Type;
102
103#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
104
105typedef struct ControlObject {
106 PyObject_HEAD
107 ControlHandle ob_itself;
Jack Jansenabc411b2000-03-20 16:09:09 +0000108 PyObject *ob_callbackdict;
Guido van Rossum17448e21995-01-30 11:53:55 +0000109} ControlObject;
110
111PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000112 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000113{
114 ControlObject *it;
115 if (itself == NULL) return PyMac_Error(resNotFound);
116 it = PyObject_NEW(ControlObject, &Control_Type);
117 if (it == NULL) return NULL;
118 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000119 SetControlReference(itself, (long)it);
Jack Jansenabc411b2000-03-20 16:09:09 +0000120 it->ob_callbackdict = NULL;
Guido van Rossum17448e21995-01-30 11:53:55 +0000121 return (PyObject *)it;
122}
123CtlObj_Convert(v, p_itself)
124 PyObject *v;
125 ControlHandle *p_itself;
126{
127 if (!CtlObj_Check(v))
128 {
129 PyErr_SetString(PyExc_TypeError, "Control required");
130 return 0;
131 }
132 *p_itself = ((ControlObject *)v)->ob_itself;
133 return 1;
134}
135
136static void CtlObj_dealloc(self)
137 ControlObject *self;
138{
Jack Jansenabc411b2000-03-20 16:09:09 +0000139 Py_XDECREF(self->ob_callbackdict);
Jack Jansen24c35311999-12-09 22:49:51 +0000140 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000141 PyMem_DEL(self);
142}
143
Jack Jansen21f96871998-02-20 16:02:09 +0000144static PyObject *CtlObj_HiliteControl(_self, _args)
145 ControlObject *_self;
146 PyObject *_args;
147{
148 PyObject *_res = NULL;
149 ControlPartCode hiliteState;
150 if (!PyArg_ParseTuple(_args, "h",
151 &hiliteState))
152 return NULL;
153 HiliteControl(_self->ob_itself,
154 hiliteState);
155 Py_INCREF(Py_None);
156 _res = Py_None;
157 return _res;
158}
159
Jack Jansen7d0bc831995-06-09 20:56:31 +0000160static PyObject *CtlObj_ShowControl(_self, _args)
161 ControlObject *_self;
162 PyObject *_args;
163{
164 PyObject *_res = NULL;
165 if (!PyArg_ParseTuple(_args, ""))
166 return NULL;
167 ShowControl(_self->ob_itself);
168 Py_INCREF(Py_None);
169 _res = Py_None;
170 return _res;
171}
172
173static PyObject *CtlObj_HideControl(_self, _args)
174 ControlObject *_self;
175 PyObject *_args;
176{
177 PyObject *_res = NULL;
178 if (!PyArg_ParseTuple(_args, ""))
179 return NULL;
180 HideControl(_self->ob_itself);
181 Py_INCREF(Py_None);
182 _res = Py_None;
183 return _res;
184}
185
Jack Jansen21f96871998-02-20 16:02:09 +0000186static PyObject *CtlObj_IsControlActive(_self, _args)
187 ControlObject *_self;
188 PyObject *_args;
189{
190 PyObject *_res = NULL;
191 Boolean _rv;
192 if (!PyArg_ParseTuple(_args, ""))
193 return NULL;
194 _rv = IsControlActive(_self->ob_itself);
195 _res = Py_BuildValue("b",
196 _rv);
197 return _res;
198}
199
200static PyObject *CtlObj_IsControlVisible(_self, _args)
201 ControlObject *_self;
202 PyObject *_args;
203{
204 PyObject *_res = NULL;
205 Boolean _rv;
206 if (!PyArg_ParseTuple(_args, ""))
207 return NULL;
208 _rv = IsControlVisible(_self->ob_itself);
209 _res = Py_BuildValue("b",
210 _rv);
211 return _res;
212}
213
214static PyObject *CtlObj_ActivateControl(_self, _args)
215 ControlObject *_self;
216 PyObject *_args;
217{
218 PyObject *_res = NULL;
219 OSErr _err;
220 if (!PyArg_ParseTuple(_args, ""))
221 return NULL;
222 _err = ActivateControl(_self->ob_itself);
223 if (_err != noErr) return PyMac_Error(_err);
224 Py_INCREF(Py_None);
225 _res = Py_None;
226 return _res;
227}
228
229static PyObject *CtlObj_DeactivateControl(_self, _args)
230 ControlObject *_self;
231 PyObject *_args;
232{
233 PyObject *_res = NULL;
234 OSErr _err;
235 if (!PyArg_ParseTuple(_args, ""))
236 return NULL;
237 _err = DeactivateControl(_self->ob_itself);
238 if (_err != noErr) return PyMac_Error(_err);
239 Py_INCREF(Py_None);
240 _res = Py_None;
241 return _res;
242}
243
244static PyObject *CtlObj_SetControlVisibility(_self, _args)
245 ControlObject *_self;
246 PyObject *_args;
247{
248 PyObject *_res = NULL;
249 OSErr _err;
250 Boolean inIsVisible;
251 Boolean inDoDraw;
252 if (!PyArg_ParseTuple(_args, "bb",
253 &inIsVisible,
254 &inDoDraw))
255 return NULL;
256 _err = SetControlVisibility(_self->ob_itself,
257 inIsVisible,
258 inDoDraw);
259 if (_err != noErr) return PyMac_Error(_err);
260 Py_INCREF(Py_None);
261 _res = Py_None;
262 return _res;
263}
264
Jack Jansen7d0bc831995-06-09 20:56:31 +0000265static PyObject *CtlObj_Draw1Control(_self, _args)
266 ControlObject *_self;
267 PyObject *_args;
268{
269 PyObject *_res = NULL;
270 if (!PyArg_ParseTuple(_args, ""))
271 return NULL;
272 Draw1Control(_self->ob_itself);
273 Py_INCREF(Py_None);
274 _res = Py_None;
275 return _res;
276}
277
Jack Jansen21f96871998-02-20 16:02:09 +0000278static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000279 ControlObject *_self;
280 PyObject *_args;
281{
282 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000283 OSErr _err;
284 Rect outRect;
285 SInt16 outBaseLineOffset;
286 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000287 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000288 _err = GetBestControlRect(_self->ob_itself,
289 &outRect,
290 &outBaseLineOffset);
291 if (_err != noErr) return PyMac_Error(_err);
292 _res = Py_BuildValue("O&h",
293 PyMac_BuildRect, &outRect,
294 outBaseLineOffset);
295 return _res;
296}
297
298static PyObject *CtlObj_SetControlFontStyle(_self, _args)
299 ControlObject *_self;
300 PyObject *_args;
301{
302 PyObject *_res = NULL;
303 OSErr _err;
304 ControlFontStyleRec inStyle;
305 if (!PyArg_ParseTuple(_args, "O&",
306 ControlFontStyle_Convert, &inStyle))
307 return NULL;
308 _err = SetControlFontStyle(_self->ob_itself,
309 &inStyle);
310 if (_err != noErr) return PyMac_Error(_err);
311 Py_INCREF(Py_None);
312 _res = Py_None;
313 return _res;
314}
315
316static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
317 ControlObject *_self;
318 PyObject *_args;
319{
320 PyObject *_res = NULL;
321 if (!PyArg_ParseTuple(_args, ""))
322 return NULL;
323 DrawControlInCurrentPort(_self->ob_itself);
324 Py_INCREF(Py_None);
325 _res = Py_None;
326 return _res;
327}
328
329static PyObject *CtlObj_SetUpControlBackground(_self, _args)
330 ControlObject *_self;
331 PyObject *_args;
332{
333 PyObject *_res = NULL;
334 OSErr _err;
335 SInt16 inDepth;
336 Boolean inIsColorDevice;
337 if (!PyArg_ParseTuple(_args, "hb",
338 &inDepth,
339 &inIsColorDevice))
340 return NULL;
341 _err = SetUpControlBackground(_self->ob_itself,
342 inDepth,
343 inIsColorDevice);
344 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000345 Py_INCREF(Py_None);
346 _res = Py_None;
347 return _res;
348}
349
Jack Jansena05ac601999-12-12 21:41:51 +0000350static PyObject *CtlObj_SetUpControlTextColor(_self, _args)
351 ControlObject *_self;
352 PyObject *_args;
353{
354 PyObject *_res = NULL;
355 OSErr _err;
356 SInt16 inDepth;
357 Boolean inIsColorDevice;
358 if (!PyArg_ParseTuple(_args, "hb",
359 &inDepth,
360 &inIsColorDevice))
361 return NULL;
362 _err = SetUpControlTextColor(_self->ob_itself,
363 inDepth,
364 inIsColorDevice);
365 if (_err != noErr) return PyMac_Error(_err);
366 Py_INCREF(Py_None);
367 _res = Py_None;
368 return _res;
369}
370
Jack Jansen7d0bc831995-06-09 20:56:31 +0000371static PyObject *CtlObj_DragControl(_self, _args)
372 ControlObject *_self;
373 PyObject *_args;
374{
375 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000376 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000377 Rect limitRect;
378 Rect slopRect;
379 DragConstraint axis;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000380 if (!PyArg_ParseTuple(_args, "O&O&O&H",
Jack Jansen754d4a41995-11-14 10:41:55 +0000381 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000382 PyMac_GetRect, &limitRect,
383 PyMac_GetRect, &slopRect,
384 &axis))
385 return NULL;
386 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000387 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000388 &limitRect,
389 &slopRect,
390 axis);
391 Py_INCREF(Py_None);
392 _res = Py_None;
393 return _res;
394}
395
396static PyObject *CtlObj_TestControl(_self, _args)
397 ControlObject *_self;
398 PyObject *_args;
399{
400 PyObject *_res = NULL;
401 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000402 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000403 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000404 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000405 return NULL;
406 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000407 testPoint);
408 _res = Py_BuildValue("h",
409 _rv);
410 return _res;
411}
412
413static PyObject *CtlObj_HandleControlKey(_self, _args)
414 ControlObject *_self;
415 PyObject *_args;
416{
417 PyObject *_res = NULL;
418 SInt16 _rv;
419 SInt16 inKeyCode;
420 SInt16 inCharCode;
421 SInt16 inModifiers;
422 if (!PyArg_ParseTuple(_args, "hhh",
423 &inKeyCode,
424 &inCharCode,
425 &inModifiers))
426 return NULL;
427 _rv = HandleControlKey(_self->ob_itself,
428 inKeyCode,
429 inCharCode,
430 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000431 _res = Py_BuildValue("h",
432 _rv);
433 return _res;
434}
435
436static PyObject *CtlObj_MoveControl(_self, _args)
437 ControlObject *_self;
438 PyObject *_args;
439{
440 PyObject *_res = NULL;
441 SInt16 h;
442 SInt16 v;
443 if (!PyArg_ParseTuple(_args, "hh",
444 &h,
445 &v))
446 return NULL;
447 MoveControl(_self->ob_itself,
448 h,
449 v);
450 Py_INCREF(Py_None);
451 _res = Py_None;
452 return _res;
453}
454
455static PyObject *CtlObj_SizeControl(_self, _args)
456 ControlObject *_self;
457 PyObject *_args;
458{
459 PyObject *_res = NULL;
460 SInt16 w;
461 SInt16 h;
462 if (!PyArg_ParseTuple(_args, "hh",
463 &w,
464 &h))
465 return NULL;
466 SizeControl(_self->ob_itself,
467 w,
468 h);
469 Py_INCREF(Py_None);
470 _res = Py_None;
471 return _res;
472}
473
Jack Jansenae8a68f1995-06-06 12:55:40 +0000474static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000475 ControlObject *_self;
476 PyObject *_args;
477{
478 PyObject *_res = NULL;
479 Str255 title;
480 if (!PyArg_ParseTuple(_args, "O&",
481 PyMac_GetStr255, title))
482 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000483 SetControlTitle(_self->ob_itself,
484 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000485 Py_INCREF(Py_None);
486 _res = Py_None;
487 return _res;
488}
489
Jack Jansenae8a68f1995-06-06 12:55:40 +0000490static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000491 ControlObject *_self;
492 PyObject *_args;
493{
494 PyObject *_res = NULL;
495 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000496 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000497 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000498 GetControlTitle(_self->ob_itself,
499 title);
Jack Jansen41009001999-03-07 20:05:20 +0000500 _res = Py_BuildValue("O&",
501 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000502 return _res;
503}
504
Jack Jansenae8a68f1995-06-06 12:55:40 +0000505static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000506 ControlObject *_self;
507 PyObject *_args;
508{
509 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000510 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000511 if (!PyArg_ParseTuple(_args, ""))
512 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000513 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000514 _res = Py_BuildValue("h",
515 _rv);
516 return _res;
517}
518
Jack Jansen7d0bc831995-06-09 20:56:31 +0000519static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000520 ControlObject *_self;
521 PyObject *_args;
522{
523 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000524 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000525 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000526 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000527 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000528 SetControlValue(_self->ob_itself,
529 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000530 Py_INCREF(Py_None);
531 _res = Py_None;
532 return _res;
533}
534
Jack Jansenae8a68f1995-06-06 12:55:40 +0000535static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000536 ControlObject *_self;
537 PyObject *_args;
538{
539 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000540 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000541 if (!PyArg_ParseTuple(_args, ""))
542 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000543 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000544 _res = Py_BuildValue("h",
545 _rv);
546 return _res;
547}
548
Jack Jansen7d0bc831995-06-09 20:56:31 +0000549static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000550 ControlObject *_self;
551 PyObject *_args;
552{
553 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000554 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000555 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000556 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000557 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000558 SetControlMinimum(_self->ob_itself,
559 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000560 Py_INCREF(Py_None);
561 _res = Py_None;
562 return _res;
563}
564
Jack Jansenae8a68f1995-06-06 12:55:40 +0000565static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000566 ControlObject *_self;
567 PyObject *_args;
568{
569 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000570 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000571 if (!PyArg_ParseTuple(_args, ""))
572 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000573 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000574 _res = Py_BuildValue("h",
575 _rv);
576 return _res;
577}
578
Jack Jansen7d0bc831995-06-09 20:56:31 +0000579static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000580 ControlObject *_self;
581 PyObject *_args;
582{
583 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000584 SInt16 newMaximum;
585 if (!PyArg_ParseTuple(_args, "h",
586 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000587 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000588 SetControlMaximum(_self->ob_itself,
589 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000590 Py_INCREF(Py_None);
591 _res = Py_None;
592 return _res;
593}
594
Jack Jansena05ac601999-12-12 21:41:51 +0000595static PyObject *CtlObj_GetControlViewSize(_self, _args)
596 ControlObject *_self;
597 PyObject *_args;
598{
599 PyObject *_res = NULL;
600 SInt32 _rv;
601 if (!PyArg_ParseTuple(_args, ""))
602 return NULL;
603 _rv = GetControlViewSize(_self->ob_itself);
604 _res = Py_BuildValue("l",
605 _rv);
606 return _res;
607}
608
609static PyObject *CtlObj_SetControlViewSize(_self, _args)
610 ControlObject *_self;
611 PyObject *_args;
612{
613 PyObject *_res = NULL;
614 SInt32 newViewSize;
615 if (!PyArg_ParseTuple(_args, "l",
616 &newViewSize))
617 return NULL;
618 SetControlViewSize(_self->ob_itself,
619 newViewSize);
620 Py_INCREF(Py_None);
621 _res = Py_None;
622 return _res;
623}
624
625static PyObject *CtlObj_GetControl32BitValue(_self, _args)
626 ControlObject *_self;
627 PyObject *_args;
628{
629 PyObject *_res = NULL;
630 SInt32 _rv;
631 if (!PyArg_ParseTuple(_args, ""))
632 return NULL;
633 _rv = GetControl32BitValue(_self->ob_itself);
634 _res = Py_BuildValue("l",
635 _rv);
636 return _res;
637}
638
639static PyObject *CtlObj_SetControl32BitValue(_self, _args)
640 ControlObject *_self;
641 PyObject *_args;
642{
643 PyObject *_res = NULL;
644 SInt32 newValue;
645 if (!PyArg_ParseTuple(_args, "l",
646 &newValue))
647 return NULL;
648 SetControl32BitValue(_self->ob_itself,
649 newValue);
650 Py_INCREF(Py_None);
651 _res = Py_None;
652 return _res;
653}
654
655static PyObject *CtlObj_GetControl32BitMaximum(_self, _args)
656 ControlObject *_self;
657 PyObject *_args;
658{
659 PyObject *_res = NULL;
660 SInt32 _rv;
661 if (!PyArg_ParseTuple(_args, ""))
662 return NULL;
663 _rv = GetControl32BitMaximum(_self->ob_itself);
664 _res = Py_BuildValue("l",
665 _rv);
666 return _res;
667}
668
669static PyObject *CtlObj_SetControl32BitMaximum(_self, _args)
670 ControlObject *_self;
671 PyObject *_args;
672{
673 PyObject *_res = NULL;
674 SInt32 newMaximum;
675 if (!PyArg_ParseTuple(_args, "l",
676 &newMaximum))
677 return NULL;
678 SetControl32BitMaximum(_self->ob_itself,
679 newMaximum);
680 Py_INCREF(Py_None);
681 _res = Py_None;
682 return _res;
683}
684
685static PyObject *CtlObj_GetControl32BitMinimum(_self, _args)
686 ControlObject *_self;
687 PyObject *_args;
688{
689 PyObject *_res = NULL;
690 SInt32 _rv;
691 if (!PyArg_ParseTuple(_args, ""))
692 return NULL;
693 _rv = GetControl32BitMinimum(_self->ob_itself);
694 _res = Py_BuildValue("l",
695 _rv);
696 return _res;
697}
698
699static PyObject *CtlObj_SetControl32BitMinimum(_self, _args)
700 ControlObject *_self;
701 PyObject *_args;
702{
703 PyObject *_res = NULL;
704 SInt32 newMinimum;
705 if (!PyArg_ParseTuple(_args, "l",
706 &newMinimum))
707 return NULL;
708 SetControl32BitMinimum(_self->ob_itself,
709 newMinimum);
710 Py_INCREF(Py_None);
711 _res = Py_None;
712 return _res;
713}
714
715static PyObject *CtlObj_IsValidControlHandle(_self, _args)
716 ControlObject *_self;
717 PyObject *_args;
718{
719 PyObject *_res = NULL;
720 Boolean _rv;
721 if (!PyArg_ParseTuple(_args, ""))
722 return NULL;
723 _rv = IsValidControlHandle(_self->ob_itself);
724 _res = Py_BuildValue("b",
725 _rv);
726 return _res;
727}
728
729static PyObject *CtlObj_RemoveControlProperty(_self, _args)
730 ControlObject *_self;
731 PyObject *_args;
732{
733 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000734 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000735 OSType propertyCreator;
736 OSType propertyTag;
737 if (!PyArg_ParseTuple(_args, "O&O&",
738 PyMac_GetOSType, &propertyCreator,
739 PyMac_GetOSType, &propertyTag))
740 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000741 _err = RemoveControlProperty(_self->ob_itself,
742 propertyCreator,
743 propertyTag);
744 if (_err != noErr) return PyMac_Error(_err);
745 Py_INCREF(Py_None);
746 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000747 return _res;
748}
749
750static PyObject *CtlObj_GetControlRegion(_self, _args)
751 ControlObject *_self;
752 PyObject *_args;
753{
754 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000755 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000756 ControlPartCode inPart;
757 RgnHandle outRegion;
758 if (!PyArg_ParseTuple(_args, "hO&",
759 &inPart,
760 ResObj_Convert, &outRegion))
761 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000762 _err = GetControlRegion(_self->ob_itself,
763 inPart,
764 outRegion);
765 if (_err != noErr) return PyMac_Error(_err);
766 Py_INCREF(Py_None);
767 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000768 return _res;
769}
770
Jack Jansen7d0bc831995-06-09 20:56:31 +0000771static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000772 ControlObject *_self;
773 PyObject *_args;
774{
775 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000776 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000777 if (!PyArg_ParseTuple(_args, ""))
778 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000779 _rv = GetControlVariant(_self->ob_itself);
780 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000781 _rv);
782 return _res;
783}
784
Jack Jansen7d0bc831995-06-09 20:56:31 +0000785static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000786 ControlObject *_self;
787 PyObject *_args;
788{
789 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000790 SInt32 data;
791 if (!PyArg_ParseTuple(_args, "l",
792 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000793 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000794 SetControlReference(_self->ob_itself,
795 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000796 Py_INCREF(Py_None);
797 _res = Py_None;
798 return _res;
799}
800
Jack Jansen7d0bc831995-06-09 20:56:31 +0000801static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000802 ControlObject *_self;
803 PyObject *_args;
804{
805 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000806 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000807 if (!PyArg_ParseTuple(_args, ""))
808 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000809 _rv = GetControlReference(_self->ob_itself);
810 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000811 _rv);
812 return _res;
813}
814
Jack Jansene79dc762000-06-02 21:35:07 +0000815#ifndef TARGET_API_MAC_CARBON
816
Jack Jansenc7fefed1997-08-15 14:32:18 +0000817static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
818 ControlObject *_self;
819 PyObject *_args;
820{
821 PyObject *_res = NULL;
822 Boolean _rv;
823 AuxCtlHandle acHndl;
824 if (!PyArg_ParseTuple(_args, ""))
825 return NULL;
826 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
827 &acHndl);
828 _res = Py_BuildValue("bO&",
829 _rv,
830 ResObj_New, acHndl);
831 return _res;
832}
Jack Jansene79dc762000-06-02 21:35:07 +0000833#endif
834
835#ifndef TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +0000836
837static PyObject *CtlObj_SetControlColor(_self, _args)
838 ControlObject *_self;
839 PyObject *_args;
840{
841 PyObject *_res = NULL;
842 CCTabHandle newColorTable;
843 if (!PyArg_ParseTuple(_args, "O&",
844 ResObj_Convert, &newColorTable))
845 return NULL;
846 SetControlColor(_self->ob_itself,
847 newColorTable);
848 Py_INCREF(Py_None);
849 _res = Py_None;
850 return _res;
851}
Jack Jansene79dc762000-06-02 21:35:07 +0000852#endif
853
854static PyObject *CtlObj_GetBevelButtonMenuValue(_self, _args)
855 ControlObject *_self;
856 PyObject *_args;
857{
858 PyObject *_res = NULL;
859 OSErr _err;
860 SInt16 outValue;
861 if (!PyArg_ParseTuple(_args, ""))
862 return NULL;
863 _err = GetBevelButtonMenuValue(_self->ob_itself,
864 &outValue);
865 if (_err != noErr) return PyMac_Error(_err);
866 _res = Py_BuildValue("h",
867 outValue);
868 return _res;
869}
870
871static PyObject *CtlObj_SetBevelButtonMenuValue(_self, _args)
872 ControlObject *_self;
873 PyObject *_args;
874{
875 PyObject *_res = NULL;
876 OSErr _err;
877 SInt16 inValue;
878 if (!PyArg_ParseTuple(_args, "h",
879 &inValue))
880 return NULL;
881 _err = SetBevelButtonMenuValue(_self->ob_itself,
882 inValue);
883 if (_err != noErr) return PyMac_Error(_err);
884 Py_INCREF(Py_None);
885 _res = Py_None;
886 return _res;
887}
888
889static PyObject *CtlObj_GetBevelButtonMenuHandle(_self, _args)
890 ControlObject *_self;
891 PyObject *_args;
892{
893 PyObject *_res = NULL;
894 OSErr _err;
895 MenuHandle outHandle;
896 if (!PyArg_ParseTuple(_args, ""))
897 return NULL;
898 _err = GetBevelButtonMenuHandle(_self->ob_itself,
899 &outHandle);
900 if (_err != noErr) return PyMac_Error(_err);
901 _res = Py_BuildValue("O&",
902 MenuObj_New, outHandle);
903 return _res;
904}
905
906static PyObject *CtlObj_SetBevelButtonTransform(_self, _args)
907 ControlObject *_self;
908 PyObject *_args;
909{
910 PyObject *_res = NULL;
911 OSErr _err;
912 IconTransformType transform;
913 if (!PyArg_ParseTuple(_args, "h",
914 &transform))
915 return NULL;
916 _err = SetBevelButtonTransform(_self->ob_itself,
917 transform);
918 if (_err != noErr) return PyMac_Error(_err);
919 Py_INCREF(Py_None);
920 _res = Py_None;
921 return _res;
922}
923
924static PyObject *CtlObj_SetImageWellTransform(_self, _args)
925 ControlObject *_self;
926 PyObject *_args;
927{
928 PyObject *_res = NULL;
929 OSErr _err;
930 IconTransformType inTransform;
931 if (!PyArg_ParseTuple(_args, "h",
932 &inTransform))
933 return NULL;
934 _err = SetImageWellTransform(_self->ob_itself,
935 inTransform);
936 if (_err != noErr) return PyMac_Error(_err);
937 Py_INCREF(Py_None);
938 _res = Py_None;
939 return _res;
940}
941
942static PyObject *CtlObj_GetTabContentRect(_self, _args)
943 ControlObject *_self;
944 PyObject *_args;
945{
946 PyObject *_res = NULL;
947 OSErr _err;
948 Rect outContentRect;
949 if (!PyArg_ParseTuple(_args, ""))
950 return NULL;
951 _err = GetTabContentRect(_self->ob_itself,
952 &outContentRect);
953 if (_err != noErr) return PyMac_Error(_err);
954 _res = Py_BuildValue("O&",
955 PyMac_BuildRect, &outContentRect);
956 return _res;
957}
958
959static PyObject *CtlObj_SetTabEnabled(_self, _args)
960 ControlObject *_self;
961 PyObject *_args;
962{
963 PyObject *_res = NULL;
964 OSErr _err;
965 SInt16 inTabToHilite;
966 Boolean inEnabled;
967 if (!PyArg_ParseTuple(_args, "hb",
968 &inTabToHilite,
969 &inEnabled))
970 return NULL;
971 _err = SetTabEnabled(_self->ob_itself,
972 inTabToHilite,
973 inEnabled);
974 if (_err != noErr) return PyMac_Error(_err);
975 Py_INCREF(Py_None);
976 _res = Py_None;
977 return _res;
978}
979
980static PyObject *CtlObj_SetDisclosureTriangleLastValue(_self, _args)
981 ControlObject *_self;
982 PyObject *_args;
983{
984 PyObject *_res = NULL;
985 OSErr _err;
986 SInt16 inValue;
987 if (!PyArg_ParseTuple(_args, "h",
988 &inValue))
989 return NULL;
990 _err = SetDisclosureTriangleLastValue(_self->ob_itself,
991 inValue);
992 if (_err != noErr) return PyMac_Error(_err);
993 Py_INCREF(Py_None);
994 _res = Py_None;
995 return _res;
996}
Jack Jansenc7fefed1997-08-15 14:32:18 +0000997
Jack Jansen21f96871998-02-20 16:02:09 +0000998static PyObject *CtlObj_SendControlMessage(_self, _args)
999 ControlObject *_self;
1000 PyObject *_args;
1001{
1002 PyObject *_res = NULL;
1003 SInt32 _rv;
1004 SInt16 inMessage;
1005 SInt32 inParam;
1006 if (!PyArg_ParseTuple(_args, "hl",
1007 &inMessage,
1008 &inParam))
1009 return NULL;
1010 _rv = SendControlMessage(_self->ob_itself,
1011 inMessage,
1012 inParam);
1013 _res = Py_BuildValue("l",
1014 _rv);
1015 return _res;
1016}
1017
1018static PyObject *CtlObj_EmbedControl(_self, _args)
1019 ControlObject *_self;
1020 PyObject *_args;
1021{
1022 PyObject *_res = NULL;
1023 OSErr _err;
1024 ControlHandle inContainer;
1025 if (!PyArg_ParseTuple(_args, "O&",
1026 CtlObj_Convert, &inContainer))
1027 return NULL;
1028 _err = EmbedControl(_self->ob_itself,
1029 inContainer);
1030 if (_err != noErr) return PyMac_Error(_err);
1031 Py_INCREF(Py_None);
1032 _res = Py_None;
1033 return _res;
1034}
1035
1036static PyObject *CtlObj_AutoEmbedControl(_self, _args)
1037 ControlObject *_self;
1038 PyObject *_args;
1039{
1040 PyObject *_res = NULL;
1041 OSErr _err;
1042 WindowPtr inWindow;
1043 if (!PyArg_ParseTuple(_args, "O&",
1044 WinObj_Convert, &inWindow))
1045 return NULL;
1046 _err = AutoEmbedControl(_self->ob_itself,
1047 inWindow);
1048 if (_err != noErr) return PyMac_Error(_err);
1049 Py_INCREF(Py_None);
1050 _res = Py_None;
1051 return _res;
1052}
1053
1054static PyObject *CtlObj_GetSuperControl(_self, _args)
1055 ControlObject *_self;
1056 PyObject *_args;
1057{
1058 PyObject *_res = NULL;
1059 OSErr _err;
1060 ControlHandle outParent;
1061 if (!PyArg_ParseTuple(_args, ""))
1062 return NULL;
1063 _err = GetSuperControl(_self->ob_itself,
1064 &outParent);
1065 if (_err != noErr) return PyMac_Error(_err);
1066 _res = Py_BuildValue("O&",
1067 CtlObj_WhichControl, outParent);
1068 return _res;
1069}
1070
1071static PyObject *CtlObj_CountSubControls(_self, _args)
1072 ControlObject *_self;
1073 PyObject *_args;
1074{
1075 PyObject *_res = NULL;
1076 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001077 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +00001078 if (!PyArg_ParseTuple(_args, ""))
1079 return NULL;
1080 _err = CountSubControls(_self->ob_itself,
1081 &outNumChildren);
1082 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +00001083 _res = Py_BuildValue("H",
Jack Jansen21f96871998-02-20 16:02:09 +00001084 outNumChildren);
1085 return _res;
1086}
1087
1088static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
1089 ControlObject *_self;
1090 PyObject *_args;
1091{
1092 PyObject *_res = NULL;
1093 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001094 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +00001095 ControlHandle outSubControl;
Jack Jansen0b13e7c2000-07-07 13:09:35 +00001096 if (!PyArg_ParseTuple(_args, "H",
Jack Jansen21f96871998-02-20 16:02:09 +00001097 &inIndex))
1098 return NULL;
1099 _err = GetIndexedSubControl(_self->ob_itself,
1100 inIndex,
1101 &outSubControl);
1102 if (_err != noErr) return PyMac_Error(_err);
1103 _res = Py_BuildValue("O&",
1104 CtlObj_WhichControl, outSubControl);
1105 return _res;
1106}
1107
1108static PyObject *CtlObj_SetControlSupervisor(_self, _args)
1109 ControlObject *_self;
1110 PyObject *_args;
1111{
1112 PyObject *_res = NULL;
1113 OSErr _err;
1114 ControlHandle inBoss;
1115 if (!PyArg_ParseTuple(_args, "O&",
1116 CtlObj_Convert, &inBoss))
1117 return NULL;
1118 _err = SetControlSupervisor(_self->ob_itself,
1119 inBoss);
1120 if (_err != noErr) return PyMac_Error(_err);
1121 Py_INCREF(Py_None);
1122 _res = Py_None;
1123 return _res;
1124}
1125
1126static PyObject *CtlObj_GetControlFeatures(_self, _args)
1127 ControlObject *_self;
1128 PyObject *_args;
1129{
1130 PyObject *_res = NULL;
1131 OSErr _err;
1132 UInt32 outFeatures;
1133 if (!PyArg_ParseTuple(_args, ""))
1134 return NULL;
1135 _err = GetControlFeatures(_self->ob_itself,
1136 &outFeatures);
1137 if (_err != noErr) return PyMac_Error(_err);
1138 _res = Py_BuildValue("l",
1139 outFeatures);
1140 return _res;
1141}
1142
1143static PyObject *CtlObj_GetControlDataSize(_self, _args)
1144 ControlObject *_self;
1145 PyObject *_args;
1146{
1147 PyObject *_res = NULL;
1148 OSErr _err;
1149 ControlPartCode inPart;
1150 ResType inTagName;
1151 Size outMaxSize;
1152 if (!PyArg_ParseTuple(_args, "hO&",
1153 &inPart,
1154 PyMac_GetOSType, &inTagName))
1155 return NULL;
1156 _err = GetControlDataSize(_self->ob_itself,
1157 inPart,
1158 inTagName,
1159 &outMaxSize);
1160 if (_err != noErr) return PyMac_Error(_err);
1161 _res = Py_BuildValue("l",
1162 outMaxSize);
1163 return _res;
1164}
1165
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001166static PyObject *CtlObj_as_Resource(_self, _args)
1167 ControlObject *_self;
1168 PyObject *_args;
1169{
1170 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001171 Handle _rv;
1172 if (!PyArg_ParseTuple(_args, ""))
1173 return NULL;
1174 _rv = as_Resource(_self->ob_itself);
1175 _res = Py_BuildValue("O&",
1176 ResObj_New, _rv);
1177 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001178}
1179
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001180static PyObject *CtlObj_GetControlRect(_self, _args)
1181 ControlObject *_self;
1182 PyObject *_args;
1183{
1184 PyObject *_res = NULL;
1185 Rect rect;
1186 if (!PyArg_ParseTuple(_args, ""))
1187 return NULL;
1188 GetControlRect(_self->ob_itself,
1189 &rect);
1190 _res = Py_BuildValue("O&",
1191 PyMac_BuildRect, &rect);
1192 return _res;
1193}
1194
Jack Jansencfb60ee1996-10-01 10:46:46 +00001195static PyObject *CtlObj_DisposeControl(_self, _args)
1196 ControlObject *_self;
1197 PyObject *_args;
1198{
1199 PyObject *_res = NULL;
1200
1201 if (!PyArg_ParseTuple(_args, ""))
1202 return NULL;
1203 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001204 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001205 DisposeControl(_self->ob_itself);
1206 _self->ob_itself = NULL;
1207 }
1208 Py_INCREF(Py_None);
1209 _res = Py_None;
1210 return _res;
1211
1212}
1213
Jack Jansen848250c1998-05-28 14:20:09 +00001214static PyObject *CtlObj_TrackControl(_self, _args)
1215 ControlObject *_self;
1216 PyObject *_args;
1217{
1218 PyObject *_res = NULL;
1219
1220 ControlPartCode _rv;
1221 Point startPoint;
1222 ControlActionUPP upp = 0;
1223 PyObject *callback = 0;
1224
1225 if (!PyArg_ParseTuple(_args, "O&|O",
1226 PyMac_GetPoint, &startPoint, &callback))
1227 return NULL;
1228 if (callback && callback != Py_None) {
1229 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1230 upp = (ControlActionUPP)-1;
1231 else {
1232 settrackfunc(callback);
1233 upp = mytracker_upp;
1234 }
1235 }
1236 _rv = TrackControl(_self->ob_itself,
1237 startPoint,
1238 upp);
1239 clrtrackfunc();
1240 _res = Py_BuildValue("h",
1241 _rv);
1242 return _res;
1243
1244}
1245
Jack Jansen24c35311999-12-09 22:49:51 +00001246static PyObject *CtlObj_HandleControlClick(_self, _args)
1247 ControlObject *_self;
1248 PyObject *_args;
1249{
1250 PyObject *_res = NULL;
1251
1252 ControlPartCode _rv;
1253 Point startPoint;
1254 SInt16 modifiers;
1255 ControlActionUPP upp = 0;
1256 PyObject *callback = 0;
1257
1258 if (!PyArg_ParseTuple(_args, "O&h|O",
1259 PyMac_GetPoint, &startPoint,
1260 &modifiers,
1261 &callback))
1262 return NULL;
1263 if (callback && callback != Py_None) {
1264 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1265 upp = (ControlActionUPP)-1;
1266 else {
1267 settrackfunc(callback);
1268 upp = mytracker_upp;
1269 }
1270 }
1271 _rv = HandleControlClick(_self->ob_itself,
1272 startPoint,
1273 modifiers,
1274 upp);
1275 clrtrackfunc();
1276 _res = Py_BuildValue("h",
1277 _rv);
1278 return _res;
1279
1280}
1281
1282static PyObject *CtlObj_SetControlData(_self, _args)
1283 ControlObject *_self;
1284 PyObject *_args;
1285{
1286 PyObject *_res = NULL;
1287
1288 OSErr _err;
1289 ControlPartCode inPart;
1290 ResType inTagName;
1291 Size bufferSize;
1292 Ptr buffer;
1293
1294 if (!PyArg_ParseTuple(_args, "hO&s#",
1295 &inPart,
1296 PyMac_GetOSType, &inTagName,
1297 &buffer, &bufferSize))
1298 return NULL;
1299
1300 _err = SetControlData(_self->ob_itself,
1301 inPart,
1302 inTagName,
1303 bufferSize,
1304 buffer);
1305
1306 if (_err != noErr)
1307 return PyMac_Error(_err);
1308 _res = Py_None;
1309 return _res;
1310
1311}
1312
1313static PyObject *CtlObj_GetControlData(_self, _args)
1314 ControlObject *_self;
1315 PyObject *_args;
1316{
1317 PyObject *_res = NULL;
1318
1319 OSErr _err;
1320 ControlPartCode inPart;
1321 ResType inTagName;
1322 Size bufferSize;
1323 Ptr buffer;
1324 Size outSize;
1325
1326 if (!PyArg_ParseTuple(_args, "hO&",
1327 &inPart,
1328 PyMac_GetOSType, &inTagName))
1329 return NULL;
1330
1331 /* allocate a buffer for the data */
1332 _err = GetControlDataSize(_self->ob_itself,
1333 inPart,
1334 inTagName,
1335 &bufferSize);
1336 if (_err != noErr)
1337 return PyMac_Error(_err);
1338 buffer = PyMem_NEW(char, bufferSize);
1339 if (buffer == NULL)
1340 return PyErr_NoMemory();
1341
1342 _err = GetControlData(_self->ob_itself,
1343 inPart,
1344 inTagName,
1345 bufferSize,
1346 buffer,
1347 &outSize);
1348
1349 if (_err != noErr) {
1350 PyMem_DEL(buffer);
1351 return PyMac_Error(_err);
1352 }
1353 _res = Py_BuildValue("s#", buffer, outSize);
1354 PyMem_DEL(buffer);
1355 return _res;
1356
1357}
1358
Jack Jansen1f9249c1999-12-19 00:05:50 +00001359static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1360 ControlObject *_self;
1361 PyObject *_args;
1362{
1363 PyObject *_res = NULL;
1364
1365 OSErr _err;
1366 ControlPartCode inPart;
1367 ResType inTagName;
1368 Handle buffer;
1369
1370 if (!PyArg_ParseTuple(_args, "hO&O&",
1371 &inPart,
1372 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001373 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001374 return NULL;
1375
1376 _err = SetControlData(_self->ob_itself,
1377 inPart,
1378 inTagName,
1379 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001380 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001381
1382 if (_err != noErr)
1383 return PyMac_Error(_err);
1384 _res = Py_None;
1385 return _res;
1386
1387}
1388
1389static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1390 ControlObject *_self;
1391 PyObject *_args;
1392{
1393 PyObject *_res = NULL;
1394
1395 OSErr _err;
1396 ControlPartCode inPart;
1397 ResType inTagName;
1398 Size bufferSize;
1399 Handle hdl;
1400
1401 if (!PyArg_ParseTuple(_args, "hO&",
1402 &inPart,
1403 PyMac_GetOSType, &inTagName))
1404 return NULL;
1405
1406 /* Check it is handle-sized */
1407 _err = GetControlDataSize(_self->ob_itself,
1408 inPart,
1409 inTagName,
1410 &bufferSize);
1411 if (_err != noErr)
1412 return PyMac_Error(_err);
1413 if (bufferSize != sizeof(Handle)) {
1414 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1415 return NULL;
1416 }
1417
1418 _err = GetControlData(_self->ob_itself,
1419 inPart,
1420 inTagName,
1421 sizeof(Handle),
1422 (Ptr)&hdl,
1423 &bufferSize);
1424
1425 if (_err != noErr) {
1426 return PyMac_Error(_err);
1427 }
1428 return Py_BuildValue("O&", OptResObj_New, hdl);
1429
1430}
1431
Jack Jansene79dc762000-06-02 21:35:07 +00001432#ifndef TARGET_API_MAC_CARBON_NOTYET
1433
Jack Jansenabc411b2000-03-20 16:09:09 +00001434static PyObject *CtlObj_SetControlDataCallback(_self, _args)
1435 ControlObject *_self;
1436 PyObject *_args;
1437{
1438 PyObject *_res = NULL;
1439
1440 OSErr _err;
1441 ControlPartCode inPart;
1442 ResType inTagName;
1443 PyObject *callback;
1444 UniversalProcPtr *c_callback;
1445
1446 if (!PyArg_ParseTuple(_args, "hO&O",
1447 &inPart,
1448 PyMac_GetOSType, &inTagName,
1449 &callback))
1450 return NULL;
1451
1452 if ( setcallback(_self, inTagName, callback, &c_callback) < 0 )
1453 return NULL;
1454 _err = SetControlData(_self->ob_itself,
1455 inPart,
1456 inTagName,
1457 sizeof(c_callback),
1458 (Ptr)&c_callback);
1459
1460 if (_err != noErr)
1461 return PyMac_Error(_err);
1462 _res = Py_None;
1463 return _res;
1464
1465}
Jack Jansene79dc762000-06-02 21:35:07 +00001466#endif
1467
1468#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00001469
Jack Jansen4c704131998-06-19 13:35:14 +00001470static PyObject *CtlObj_GetPopupData(_self, _args)
1471 ControlObject *_self;
1472 PyObject *_args;
1473{
1474 PyObject *_res = NULL;
1475
1476 PopupPrivateDataHandle hdl;
1477
1478 if ( (*_self->ob_itself)->contrlData == NULL ) {
1479 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1480 return 0;
1481 }
1482 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1483 HLock((Handle)hdl);
1484 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1485 HUnlock((Handle)hdl);
1486 return _res;
1487
1488}
Jack Jansene79dc762000-06-02 21:35:07 +00001489#endif
1490
1491#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001492
1493static PyObject *CtlObj_SetPopupData(_self, _args)
1494 ControlObject *_self;
1495 PyObject *_args;
1496{
1497 PyObject *_res = NULL;
1498
1499 PopupPrivateDataHandle hdl;
1500 MenuHandle mHandle;
1501 short mID;
1502
1503 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1504 return 0;
1505 if ( (*_self->ob_itself)->contrlData == NULL ) {
1506 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1507 return 0;
1508 }
1509 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1510 (*hdl)->mHandle = mHandle;
1511 (*hdl)->mID = mID;
1512 Py_INCREF(Py_None);
1513 return Py_None;
1514
1515}
Jack Jansene79dc762000-06-02 21:35:07 +00001516#endif
Jack Jansen4c704131998-06-19 13:35:14 +00001517
Guido van Rossum17448e21995-01-30 11:53:55 +00001518static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001519 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1520 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001521 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1522 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001523 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1524 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001525 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1526 "() -> (Boolean _rv)"},
1527 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1528 "() -> (Boolean _rv)"},
1529 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1530 "() -> None"},
1531 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1532 "() -> None"},
1533 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1534 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001535 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1536 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001537 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1538 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1539 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1540 "(ControlFontStyleRec inStyle) -> None"},
1541 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1542 "() -> None"},
1543 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1544 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001545 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1546 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001547 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001548 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001549 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001550 "(Point testPoint) -> (ControlPartCode _rv)"},
1551 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
1552 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001553 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001554 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001555 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001556 "(SInt16 w, SInt16 h) -> None"},
1557 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1558 "(Str255 title) -> None"},
1559 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001560 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001561 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001562 "() -> (SInt16 _rv)"},
1563 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1564 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001565 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001566 "() -> (SInt16 _rv)"},
1567 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1568 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001569 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001570 "() -> (SInt16 _rv)"},
1571 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1572 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001573 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
1574 "() -> (SInt32 _rv)"},
1575 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
1576 "(SInt32 newViewSize) -> None"},
1577 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
1578 "() -> (SInt32 _rv)"},
1579 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
1580 "(SInt32 newValue) -> None"},
1581 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
1582 "() -> (SInt32 _rv)"},
1583 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
1584 "(SInt32 newMaximum) -> None"},
1585 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
1586 "() -> (SInt32 _rv)"},
1587 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
1588 "(SInt32 newMinimum) -> None"},
1589 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
1590 "() -> (Boolean _rv)"},
1591 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00001592 "(OSType propertyCreator, OSType propertyTag) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001593 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00001594 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001595 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001596 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001597 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1598 "(SInt32 data) -> None"},
1599 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1600 "() -> (SInt32 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +00001601
1602#ifndef TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00001603 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1604 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
Jack Jansene79dc762000-06-02 21:35:07 +00001605#endif
1606
1607#ifndef TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00001608 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1609 "(CCTabHandle newColorTable) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00001610#endif
1611 {"GetBevelButtonMenuValue", (PyCFunction)CtlObj_GetBevelButtonMenuValue, 1,
1612 "() -> (SInt16 outValue)"},
1613 {"SetBevelButtonMenuValue", (PyCFunction)CtlObj_SetBevelButtonMenuValue, 1,
1614 "(SInt16 inValue) -> None"},
1615 {"GetBevelButtonMenuHandle", (PyCFunction)CtlObj_GetBevelButtonMenuHandle, 1,
1616 "() -> (MenuHandle outHandle)"},
1617 {"SetBevelButtonTransform", (PyCFunction)CtlObj_SetBevelButtonTransform, 1,
1618 "(IconTransformType transform) -> None"},
1619 {"SetImageWellTransform", (PyCFunction)CtlObj_SetImageWellTransform, 1,
1620 "(IconTransformType inTransform) -> None"},
1621 {"GetTabContentRect", (PyCFunction)CtlObj_GetTabContentRect, 1,
1622 "() -> (Rect outContentRect)"},
1623 {"SetTabEnabled", (PyCFunction)CtlObj_SetTabEnabled, 1,
1624 "(SInt16 inTabToHilite, Boolean inEnabled) -> None"},
1625 {"SetDisclosureTriangleLastValue", (PyCFunction)CtlObj_SetDisclosureTriangleLastValue, 1,
1626 "(SInt16 inValue) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001627 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
1628 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
1629 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
1630 "(ControlHandle inContainer) -> None"},
1631 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
1632 "(WindowPtr inWindow) -> None"},
1633 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
1634 "() -> (ControlHandle outParent)"},
1635 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001636 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001637 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001638 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001639 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
1640 "(ControlHandle inBoss) -> None"},
1641 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
1642 "() -> (UInt32 outFeatures)"},
1643 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
1644 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001645 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00001646 "() -> (Handle _rv)"},
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001647 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
1648 "() -> (Rect rect)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00001649 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1650 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001651 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001652 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
1653 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
1654 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
1655 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
1656 "(stuff) -> None"},
1657 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
1658 "(part, type) -> String"},
Jack Jansen1f9249c1999-12-19 00:05:50 +00001659 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
1660 "(ResObj) -> None"},
1661 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
1662 "(part, type) -> ResObj"},
Jack Jansene79dc762000-06-02 21:35:07 +00001663
1664#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00001665 {"SetControlDataCallback", (PyCFunction)CtlObj_SetControlDataCallback, 1,
1666 "(callbackfunc) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00001667#endif
1668
1669#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001670 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1671 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00001672#endif
1673
1674#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001675 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1676 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00001677#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00001678 {NULL, NULL, 0}
1679};
1680
1681PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1682
1683static PyObject *CtlObj_getattr(self, name)
1684 ControlObject *self;
1685 char *name;
1686{
1687 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1688}
1689
1690#define CtlObj_setattr NULL
1691
Jack Jansen8387af61999-03-13 23:07:32 +00001692static int CtlObj_compare(self, other)
1693 ControlObject *self, *other;
1694{
1695 unsigned long v, w;
1696
1697 if (!CtlObj_Check((PyObject *)other))
1698 {
1699 v=(unsigned long)self;
1700 w=(unsigned long)other;
1701 }
1702 else
1703 {
1704 v=(unsigned long)self->ob_itself;
1705 w=(unsigned long)other->ob_itself;
1706 }
1707 if( v < w ) return -1;
1708 if( v > w ) return 1;
1709 return 0;
1710}
1711
1712#define CtlObj_repr NULL
1713
1714static long CtlObj_hash(self)
1715 ControlObject *self;
1716{
1717 return (long)self->ob_itself;
1718}
1719
Guido van Rossum17448e21995-01-30 11:53:55 +00001720PyTypeObject Control_Type = {
1721 PyObject_HEAD_INIT(&PyType_Type)
1722 0, /*ob_size*/
1723 "Control", /*tp_name*/
1724 sizeof(ControlObject), /*tp_basicsize*/
1725 0, /*tp_itemsize*/
1726 /* methods */
1727 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1728 0, /*tp_print*/
1729 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1730 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00001731 (cmpfunc) CtlObj_compare, /*tp_compare*/
1732 (reprfunc) CtlObj_repr, /*tp_repr*/
1733 (PyNumberMethods *)0, /* tp_as_number */
1734 (PySequenceMethods *)0, /* tp_as_sequence */
1735 (PyMappingMethods *)0, /* tp_as_mapping */
1736 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00001737};
1738
1739/* -------------------- End object type Control --------------------- */
1740
1741
1742static PyObject *Ctl_NewControl(_self, _args)
1743 PyObject *_self;
1744 PyObject *_args;
1745{
1746 PyObject *_res = NULL;
1747 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001748 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001749 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001750 Str255 controlTitle;
1751 Boolean initiallyVisible;
1752 SInt16 initialValue;
1753 SInt16 minimumValue;
1754 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001755 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001756 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001757 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001758 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001759 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001760 PyMac_GetStr255, controlTitle,
1761 &initiallyVisible,
1762 &initialValue,
1763 &minimumValue,
1764 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001765 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001766 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001767 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001768 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001769 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001770 controlTitle,
1771 initiallyVisible,
1772 initialValue,
1773 minimumValue,
1774 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001775 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001776 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001777 _res = Py_BuildValue("O&",
1778 CtlObj_New, _rv);
1779 return _res;
1780}
1781
1782static PyObject *Ctl_GetNewControl(_self, _args)
1783 PyObject *_self;
1784 PyObject *_args;
1785{
1786 PyObject *_res = NULL;
1787 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001788 SInt16 resourceID;
1789 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001790 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001791 &resourceID,
1792 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001793 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001794 _rv = GetNewControl(resourceID,
1795 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001796 _res = Py_BuildValue("O&",
1797 CtlObj_New, _rv);
1798 return _res;
1799}
1800
Guido van Rossum17448e21995-01-30 11:53:55 +00001801static PyObject *Ctl_DrawControls(_self, _args)
1802 PyObject *_self;
1803 PyObject *_args;
1804{
1805 PyObject *_res = NULL;
1806 WindowPtr theWindow;
1807 if (!PyArg_ParseTuple(_args, "O&",
1808 WinObj_Convert, &theWindow))
1809 return NULL;
1810 DrawControls(theWindow);
1811 Py_INCREF(Py_None);
1812 _res = Py_None;
1813 return _res;
1814}
1815
Guido van Rossum17448e21995-01-30 11:53:55 +00001816static PyObject *Ctl_UpdateControls(_self, _args)
1817 PyObject *_self;
1818 PyObject *_args;
1819{
1820 PyObject *_res = NULL;
1821 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001822 RgnHandle updateRegion;
1823 if (!PyArg_ParseTuple(_args, "O&O&",
1824 WinObj_Convert, &theWindow,
1825 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001826 return NULL;
1827 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001828 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001829 Py_INCREF(Py_None);
1830 _res = Py_None;
1831 return _res;
1832}
1833
1834static PyObject *Ctl_FindControl(_self, _args)
1835 PyObject *_self;
1836 PyObject *_args;
1837{
1838 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001839 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001840 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001841 WindowPtr theWindow;
1842 ControlHandle theControl;
1843 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001844 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001845 WinObj_Convert, &theWindow))
1846 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001847 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001848 theWindow,
1849 &theControl);
1850 _res = Py_BuildValue("hO&",
1851 _rv,
1852 CtlObj_WhichControl, theControl);
1853 return _res;
1854}
1855
Jack Jansen21f96871998-02-20 16:02:09 +00001856static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1857 PyObject *_self;
1858 PyObject *_args;
1859{
1860 PyObject *_res = NULL;
1861 ControlHandle _rv;
1862 Point inWhere;
1863 WindowPtr inWindow;
1864 SInt16 outPart;
1865 if (!PyArg_ParseTuple(_args, "O&O&",
1866 PyMac_GetPoint, &inWhere,
1867 WinObj_Convert, &inWindow))
1868 return NULL;
1869 _rv = FindControlUnderMouse(inWhere,
1870 inWindow,
1871 &outPart);
1872 _res = Py_BuildValue("O&h",
1873 CtlObj_New, _rv,
1874 outPart);
1875 return _res;
1876}
1877
1878static PyObject *Ctl_IdleControls(_self, _args)
1879 PyObject *_self;
1880 PyObject *_args;
1881{
1882 PyObject *_res = NULL;
1883 WindowPtr inWindow;
1884 if (!PyArg_ParseTuple(_args, "O&",
1885 WinObj_Convert, &inWindow))
1886 return NULL;
1887 IdleControls(inWindow);
1888 Py_INCREF(Py_None);
1889 _res = Py_None;
1890 return _res;
1891}
1892
1893static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1894 PyObject *_self;
1895 PyObject *_args;
1896{
1897 PyObject *_res = NULL;
1898 OSErr _err;
1899 WindowPtr inWindow;
1900 FSSpec inDumpFile;
1901 if (!PyArg_ParseTuple(_args, "O&O&",
1902 WinObj_Convert, &inWindow,
1903 PyMac_GetFSSpec, &inDumpFile))
1904 return NULL;
1905 _err = DumpControlHierarchy(inWindow,
1906 &inDumpFile);
1907 if (_err != noErr) return PyMac_Error(_err);
1908 Py_INCREF(Py_None);
1909 _res = Py_None;
1910 return _res;
1911}
1912
1913static PyObject *Ctl_CreateRootControl(_self, _args)
1914 PyObject *_self;
1915 PyObject *_args;
1916{
1917 PyObject *_res = NULL;
1918 OSErr _err;
1919 WindowPtr inWindow;
1920 ControlHandle outControl;
1921 if (!PyArg_ParseTuple(_args, "O&",
1922 WinObj_Convert, &inWindow))
1923 return NULL;
1924 _err = CreateRootControl(inWindow,
1925 &outControl);
1926 if (_err != noErr) return PyMac_Error(_err);
1927 _res = Py_BuildValue("O&",
1928 CtlObj_WhichControl, outControl);
1929 return _res;
1930}
1931
1932static PyObject *Ctl_GetRootControl(_self, _args)
1933 PyObject *_self;
1934 PyObject *_args;
1935{
1936 PyObject *_res = NULL;
1937 OSErr _err;
1938 WindowPtr inWindow;
1939 ControlHandle outControl;
1940 if (!PyArg_ParseTuple(_args, "O&",
1941 WinObj_Convert, &inWindow))
1942 return NULL;
1943 _err = GetRootControl(inWindow,
1944 &outControl);
1945 if (_err != noErr) return PyMac_Error(_err);
1946 _res = Py_BuildValue("O&",
1947 CtlObj_WhichControl, outControl);
1948 return _res;
1949}
1950
1951static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1952 PyObject *_self;
1953 PyObject *_args;
1954{
1955 PyObject *_res = NULL;
1956 OSErr _err;
1957 WindowPtr inWindow;
1958 ControlHandle outControl;
1959 if (!PyArg_ParseTuple(_args, "O&",
1960 WinObj_Convert, &inWindow))
1961 return NULL;
1962 _err = GetKeyboardFocus(inWindow,
1963 &outControl);
1964 if (_err != noErr) return PyMac_Error(_err);
1965 _res = Py_BuildValue("O&",
1966 CtlObj_WhichControl, outControl);
1967 return _res;
1968}
1969
1970static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1971 PyObject *_self;
1972 PyObject *_args;
1973{
1974 PyObject *_res = NULL;
1975 OSErr _err;
1976 WindowPtr inWindow;
1977 ControlHandle inControl;
1978 ControlFocusPart inPart;
1979 if (!PyArg_ParseTuple(_args, "O&O&h",
1980 WinObj_Convert, &inWindow,
1981 CtlObj_Convert, &inControl,
1982 &inPart))
1983 return NULL;
1984 _err = SetKeyboardFocus(inWindow,
1985 inControl,
1986 inPart);
1987 if (_err != noErr) return PyMac_Error(_err);
1988 Py_INCREF(Py_None);
1989 _res = Py_None;
1990 return _res;
1991}
1992
1993static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1994 PyObject *_self;
1995 PyObject *_args;
1996{
1997 PyObject *_res = NULL;
1998 OSErr _err;
1999 WindowPtr inWindow;
2000 if (!PyArg_ParseTuple(_args, "O&",
2001 WinObj_Convert, &inWindow))
2002 return NULL;
2003 _err = AdvanceKeyboardFocus(inWindow);
2004 if (_err != noErr) return PyMac_Error(_err);
2005 Py_INCREF(Py_None);
2006 _res = Py_None;
2007 return _res;
2008}
2009
2010static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
2011 PyObject *_self;
2012 PyObject *_args;
2013{
2014 PyObject *_res = NULL;
2015 OSErr _err;
2016 WindowPtr inWindow;
2017 if (!PyArg_ParseTuple(_args, "O&",
2018 WinObj_Convert, &inWindow))
2019 return NULL;
2020 _err = ReverseKeyboardFocus(inWindow);
2021 if (_err != noErr) return PyMac_Error(_err);
2022 Py_INCREF(Py_None);
2023 _res = Py_None;
2024 return _res;
2025}
2026
2027static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
2028 PyObject *_self;
2029 PyObject *_args;
2030{
2031 PyObject *_res = NULL;
2032 OSErr _err;
2033 WindowPtr inWindow;
2034 if (!PyArg_ParseTuple(_args, "O&",
2035 WinObj_Convert, &inWindow))
2036 return NULL;
2037 _err = ClearKeyboardFocus(inWindow);
2038 if (_err != noErr) return PyMac_Error(_err);
2039 Py_INCREF(Py_None);
2040 _res = Py_None;
2041 return _res;
2042}
2043
Jack Jansene0581891999-02-07 14:02:03 +00002044static PyObject *Ctl_as_Control(_self, _args)
2045 PyObject *_self;
2046 PyObject *_args;
2047{
2048 PyObject *_res = NULL;
2049 ControlHandle _rv;
2050 Handle h;
2051 if (!PyArg_ParseTuple(_args, "O&",
2052 ResObj_Convert, &h))
2053 return NULL;
2054 _rv = as_Control(h);
2055 _res = Py_BuildValue("O&",
2056 CtlObj_New, _rv);
2057 return _res;
2058}
2059
Guido van Rossum17448e21995-01-30 11:53:55 +00002060static PyMethodDef Ctl_methods[] = {
2061 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002062 "(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 +00002063 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002064 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002065 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
2066 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002067 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00002068 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002069 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002070 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
2071 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
2072 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
2073 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
2074 "(WindowPtr inWindow) -> None"},
2075 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
2076 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
2077 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
2078 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2079 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
2080 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2081 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
2082 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2083 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
2084 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
2085 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
2086 "(WindowPtr inWindow) -> None"},
2087 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
2088 "(WindowPtr inWindow) -> None"},
2089 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
2090 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00002091 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
2092 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002093 {NULL, NULL, 0}
2094};
2095
2096
2097
Jack Jansen8387af61999-03-13 23:07:32 +00002098PyObject *CtlObj_NewUnmanaged(itself)
2099 ControlHandle itself;
2100{
2101 ControlObject *it;
2102 if (itself == NULL) return PyMac_Error(resNotFound);
2103 it = PyObject_NEW(ControlObject, &Control_Type);
2104 if (it == NULL) return NULL;
2105 it->ob_itself = itself;
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002106 it->ob_callbackdict = NULL;
Jack Jansen8387af61999-03-13 23:07:32 +00002107 return (PyObject *)it;
2108}
2109
Guido van Rossum17448e21995-01-30 11:53:55 +00002110PyObject *
2111CtlObj_WhichControl(ControlHandle c)
2112{
2113 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00002114
Guido van Rossum17448e21995-01-30 11:53:55 +00002115 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00002116 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00002117 else {
2118 it = (PyObject *) GetControlReference(c);
2119 /*
2120 ** If the refcon is zero or doesn't point back to the Python object
2121 ** the control is not ours. Return a temporary object.
2122 */
2123 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
2124 return CtlObj_NewUnmanaged(c);
2125 }
Guido van Rossum17448e21995-01-30 11:53:55 +00002126 Py_INCREF(it);
2127 return it;
2128}
2129
Jack Jansen848250c1998-05-28 14:20:09 +00002130static int
2131settrackfunc(obj)
2132 PyObject *obj;
2133{
2134 if (tracker) {
2135 PyErr_SetString(Ctl_Error, "Tracker function in use");
2136 return 0;
2137 }
2138 tracker = obj;
2139 Py_INCREF(tracker);
2140}
2141
2142static void
2143clrtrackfunc()
2144{
2145 Py_XDECREF(tracker);
2146 tracker = 0;
2147}
2148
2149static pascal void
Jack Jansene79dc762000-06-02 21:35:07 +00002150mytracker(ControlHandle ctl, short part)
Jack Jansen848250c1998-05-28 14:20:09 +00002151{
2152 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00002153
Jack Jansen848250c1998-05-28 14:20:09 +00002154 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
2155 if (args && tracker) {
2156 rv = PyEval_CallObject(tracker, args);
2157 Py_DECREF(args);
2158 }
2159 if (rv)
2160 Py_DECREF(rv);
2161 else
Jack Jansen24c35311999-12-09 22:49:51 +00002162 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00002163}
2164
Jack Jansene79dc762000-06-02 21:35:07 +00002165#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002166static int
2167setcallback(self, which, callback, uppp)
2168 ControlObject *self;
2169 OSType which;
2170 PyObject *callback;
2171 UniversalProcPtr *uppp;
2172{
2173 char keybuf[9];
2174
2175 if ( which == kControlUserPaneDrawProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002176 *uppp = (UniversalProcPtr)mydrawproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002177 else if ( which == kControlUserPaneIdleProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002178 *uppp = (UniversalProcPtr)myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002179 else if ( which == kControlUserPaneHitTestProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002180 *uppp = (UniversalProcPtr)myhittestproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002181 else if ( which == kControlUserPaneTrackingProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002182 *uppp = (UniversalProcPtr)mytrackingproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002183 else
2184 return -1;
2185 /* Only now do we test for clearing of the callback: */
2186 if ( callback == Py_None )
2187 *uppp = NULL;
2188 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
2189 if ( self->ob_callbackdict == NULL )
2190 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
2191 return -1;
2192 /* And store the Python callback */
2193 sprintf(keybuf, "%x", which);
2194 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
2195 return -1;
2196 return 0;
2197}
2198
2199static PyObject *
2200callcallback(self, which, arglist)
2201 ControlObject *self;
2202 OSType which;
2203 PyObject *arglist;
2204{
2205 char keybuf[9];
2206 PyObject *func, *rv;
2207
2208 sprintf(keybuf, "%x", which);
2209 if ( self->ob_callbackdict == NULL ||
2210 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
Jack Jansena27e9fb2000-03-21 23:03:02 +00002211 PySys_WriteStderr("Control callback %x without callback object\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002212 return NULL;
2213 }
2214 rv = PyEval_CallObject(func, arglist);
2215 if ( rv == NULL )
Jack Jansena27e9fb2000-03-21 23:03:02 +00002216 PySys_WriteStderr("Exception in control callback %x handler\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002217 return rv;
2218}
2219
2220static pascal void
2221mydrawproc(ControlHandle control, SInt16 part)
2222{
2223 ControlObject *ctl_obj;
2224 PyObject *arglist, *rv;
2225
2226 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2227 arglist = Py_BuildValue("Oh", ctl_obj, part);
2228 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2229 Py_XDECREF(arglist);
2230 Py_XDECREF(rv);
2231}
2232
2233static pascal void
2234myidleproc(ControlHandle control)
2235{
2236 ControlObject *ctl_obj;
2237 PyObject *arglist, *rv;
2238
2239 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2240 arglist = Py_BuildValue("O", ctl_obj);
2241 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2242 Py_XDECREF(arglist);
2243 Py_XDECREF(rv);
2244}
2245
Jack Jansena27e9fb2000-03-21 23:03:02 +00002246static pascal ControlPartCode
2247myhittestproc(ControlHandle control, Point where)
2248{
2249 ControlObject *ctl_obj;
2250 PyObject *arglist, *rv;
2251 short c_rv = -1;
2252
2253 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
Jack Jansendeb63732000-03-22 15:35:24 +00002254 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002255 rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
2256 Py_XDECREF(arglist);
2257 /* Ignore errors, nothing we can do about them */
2258 if ( rv )
2259 PyArg_Parse(rv, "h", &c_rv);
2260 Py_XDECREF(rv);
2261 return (ControlPartCode)c_rv;
2262}
2263
2264static pascal ControlPartCode
2265mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
2266{
2267 ControlObject *ctl_obj;
2268 PyObject *arglist, *rv;
2269 short c_rv = -1;
2270
2271 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2272 /* We cannot pass the actionProc without lots of work */
Jack Jansendeb63732000-03-22 15:35:24 +00002273 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002274 rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
2275 Py_XDECREF(arglist);
2276 if ( rv )
2277 PyArg_Parse(rv, "h", &c_rv);
2278 Py_XDECREF(rv);
2279 return (ControlPartCode)c_rv;
2280}
Jack Jansene79dc762000-06-02 21:35:07 +00002281#endif
Jack Jansenabc411b2000-03-20 16:09:09 +00002282
Guido van Rossum17448e21995-01-30 11:53:55 +00002283
2284void initCtl()
2285{
2286 PyObject *m;
2287 PyObject *d;
2288
2289
2290
Jack Jansen848250c1998-05-28 14:20:09 +00002291 mytracker_upp = NewControlActionProc(mytracker);
Jack Jansene79dc762000-06-02 21:35:07 +00002292#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002293 mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc);
Jack Jansen1b6e8212000-04-05 21:30:57 +00002294 myidleproc_upp = NewControlUserPaneIdleProc(myidleproc);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002295 myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc);
2296 mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc);
Jack Jansene79dc762000-06-02 21:35:07 +00002297#endif
Jack Jansen848250c1998-05-28 14:20:09 +00002298
Guido van Rossum17448e21995-01-30 11:53:55 +00002299
2300 m = Py_InitModule("Ctl", Ctl_methods);
2301 d = PyModule_GetDict(m);
2302 Ctl_Error = PyMac_GetOSErrException();
2303 if (Ctl_Error == NULL ||
2304 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
2305 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00002306 Control_Type.ob_type = &PyType_Type;
2307 Py_INCREF(&Control_Type);
2308 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2309 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00002310}
2311
2312/* ========================= End module Ctl ========================= */
2313