blob: 083929deb4301ab64d320b9403a4c18ab5c11313 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Ctl =========================== */
3
4#include "Python.h"
5
6
7
Guido van Rossum17448e21995-01-30 11:53:55 +00008#include "macglue.h"
Jack Jansen9d8b96c2000-07-14 22:16:45 +00009#include "pymactoolbox.h"
Guido van Rossum17448e21995-01-30 11:53:55 +000010
11#include <Controls.h>
Jack Jansenf7d5aa62000-12-10 23:43:49 +000012#ifndef kControlCheckBoxUncheckedValue
13#include <ControlDefinitions.h>
14#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000015
Jack Jansen0e04eec2001-05-17 21:58:34 +000016#ifdef USE_TOOLBOX_OBJECT_GLUE
17extern PyObject *_CtlObj_New(ControlHandle);
18extern int _CtlObj_Convert(PyObject *, ControlHandle *);
19
20#define CtlObj_New _CtlObj_New
21#define CtlObj_Convert _CtlObj_Convert
22#endif
23
Jack Jansen9d8b96c2000-07-14 22:16:45 +000024staticforward PyObject *CtlObj_WhichControl(ControlHandle);
25
Jack Jansene0581891999-02-07 14:02:03 +000026#define as_Control(h) ((ControlHandle)h)
Jack Jansena1a0fef1999-12-23 14:32:06 +000027#define as_Resource(ctl) ((Handle)ctl)
Jack Jansen74a1e632000-07-14 22:37:27 +000028#if TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +000029#define GetControlRect(ctl, rectp) GetControlBounds(ctl, rectp)
30#else
Jack Jansen1a7d5b12000-03-21 16:25:23 +000031#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
Jack Jansene79dc762000-06-02 21:35:07 +000032#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000033
Jack Jansen21f96871998-02-20 16:02:09 +000034/*
35** Parse/generate ControlFontStyleRec records
36*/
37#if 0 /* Not needed */
Jack Jansen9d8b96c2000-07-14 22:16:45 +000038static PyObject *
39ControlFontStyle_New(itself)
Jack Jansen21f96871998-02-20 16:02:09 +000040 ControlFontStyleRec *itself;
41{
42
43 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
44 itself->size, itself->style, itself->mode, itself->just,
45 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
46}
47#endif
48
Jack Jansen9d8b96c2000-07-14 22:16:45 +000049static int
Jack Jansen21f96871998-02-20 16:02:09 +000050ControlFontStyle_Convert(v, itself)
51 PyObject *v;
52 ControlFontStyleRec *itself;
53{
54 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000055 &itself->font, &itself->size, &itself->style, &itself->mode,
56 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000057 QdRGB_Convert, &itself->backColor);
58}
59
Jack Jansenf7d5aa62000-12-10 23:43:49 +000060/*
61** Parse/generate ControlID records
62*/
63static PyObject *
64PyControlID_New(itself)
65 ControlID *itself;
66{
67
68 return Py_BuildValue("O&l", PyMac_BuildOSType, itself->signature, itself->id);
69}
70
71static int
72PyControlID_Convert(v, itself)
73 PyObject *v;
74 ControlID *itself;
75{
76 return PyArg_ParseTuple(v, "O&l", PyMac_GetOSType, &itself->signature, &itself->id);
77}
78
79
Jack Jansen24c35311999-12-09 22:49:51 +000080/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000081static PyObject *tracker;
82static ControlActionUPP mytracker_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +000083static ControlUserPaneDrawUPP mydrawproc_upp;
84static ControlUserPaneIdleUPP myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +000085static ControlUserPaneHitTestUPP myhittestproc_upp;
86static ControlUserPaneTrackingUPP mytrackingproc_upp;
Jack Jansen848250c1998-05-28 14:20:09 +000087
88extern int settrackfunc(PyObject *); /* forward */
89extern void clrtrackfunc(void); /* forward */
Jack Jansen85152b92000-07-11 21:12:55 +000090staticforward int setcallback(PyObject *, OSType, PyObject *, UniversalProcPtr *);
Jack Jansen848250c1998-05-28 14:20:09 +000091
Guido van Rossum17448e21995-01-30 11:53:55 +000092static PyObject *Ctl_Error;
93
94/* ---------------------- Object type Control ----------------------- */
95
96PyTypeObject Control_Type;
97
98#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
99
100typedef struct ControlObject {
101 PyObject_HEAD
102 ControlHandle ob_itself;
Jack Jansenabc411b2000-03-20 16:09:09 +0000103 PyObject *ob_callbackdict;
Guido van Rossum17448e21995-01-30 11:53:55 +0000104} ControlObject;
105
106PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000107 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000108{
109 ControlObject *it;
110 if (itself == NULL) return PyMac_Error(resNotFound);
111 it = PyObject_NEW(ControlObject, &Control_Type);
112 if (it == NULL) return NULL;
113 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000114 SetControlReference(itself, (long)it);
Jack Jansenabc411b2000-03-20 16:09:09 +0000115 it->ob_callbackdict = NULL;
Guido van Rossum17448e21995-01-30 11:53:55 +0000116 return (PyObject *)it;
117}
118CtlObj_Convert(v, p_itself)
119 PyObject *v;
120 ControlHandle *p_itself;
121{
122 if (!CtlObj_Check(v))
123 {
124 PyErr_SetString(PyExc_TypeError, "Control required");
125 return 0;
126 }
127 *p_itself = ((ControlObject *)v)->ob_itself;
128 return 1;
129}
130
131static void CtlObj_dealloc(self)
132 ControlObject *self;
133{
Jack Jansenabc411b2000-03-20 16:09:09 +0000134 Py_XDECREF(self->ob_callbackdict);
Jack Jansen24c35311999-12-09 22:49:51 +0000135 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000136 PyMem_DEL(self);
137}
138
Jack Jansen21f96871998-02-20 16:02:09 +0000139static PyObject *CtlObj_HiliteControl(_self, _args)
140 ControlObject *_self;
141 PyObject *_args;
142{
143 PyObject *_res = NULL;
144 ControlPartCode hiliteState;
145 if (!PyArg_ParseTuple(_args, "h",
146 &hiliteState))
147 return NULL;
148 HiliteControl(_self->ob_itself,
149 hiliteState);
150 Py_INCREF(Py_None);
151 _res = Py_None;
152 return _res;
153}
154
Jack Jansen7d0bc831995-06-09 20:56:31 +0000155static PyObject *CtlObj_ShowControl(_self, _args)
156 ControlObject *_self;
157 PyObject *_args;
158{
159 PyObject *_res = NULL;
160 if (!PyArg_ParseTuple(_args, ""))
161 return NULL;
162 ShowControl(_self->ob_itself);
163 Py_INCREF(Py_None);
164 _res = Py_None;
165 return _res;
166}
167
168static PyObject *CtlObj_HideControl(_self, _args)
169 ControlObject *_self;
170 PyObject *_args;
171{
172 PyObject *_res = NULL;
173 if (!PyArg_ParseTuple(_args, ""))
174 return NULL;
175 HideControl(_self->ob_itself);
176 Py_INCREF(Py_None);
177 _res = Py_None;
178 return _res;
179}
180
Jack Jansen21f96871998-02-20 16:02:09 +0000181static PyObject *CtlObj_IsControlActive(_self, _args)
182 ControlObject *_self;
183 PyObject *_args;
184{
185 PyObject *_res = NULL;
186 Boolean _rv;
187 if (!PyArg_ParseTuple(_args, ""))
188 return NULL;
189 _rv = IsControlActive(_self->ob_itself);
190 _res = Py_BuildValue("b",
191 _rv);
192 return _res;
193}
194
195static PyObject *CtlObj_IsControlVisible(_self, _args)
196 ControlObject *_self;
197 PyObject *_args;
198{
199 PyObject *_res = NULL;
200 Boolean _rv;
201 if (!PyArg_ParseTuple(_args, ""))
202 return NULL;
203 _rv = IsControlVisible(_self->ob_itself);
204 _res = Py_BuildValue("b",
205 _rv);
206 return _res;
207}
208
209static PyObject *CtlObj_ActivateControl(_self, _args)
210 ControlObject *_self;
211 PyObject *_args;
212{
213 PyObject *_res = NULL;
214 OSErr _err;
215 if (!PyArg_ParseTuple(_args, ""))
216 return NULL;
217 _err = ActivateControl(_self->ob_itself);
218 if (_err != noErr) return PyMac_Error(_err);
219 Py_INCREF(Py_None);
220 _res = Py_None;
221 return _res;
222}
223
224static PyObject *CtlObj_DeactivateControl(_self, _args)
225 ControlObject *_self;
226 PyObject *_args;
227{
228 PyObject *_res = NULL;
229 OSErr _err;
230 if (!PyArg_ParseTuple(_args, ""))
231 return NULL;
232 _err = DeactivateControl(_self->ob_itself);
233 if (_err != noErr) return PyMac_Error(_err);
234 Py_INCREF(Py_None);
235 _res = Py_None;
236 return _res;
237}
238
239static PyObject *CtlObj_SetControlVisibility(_self, _args)
240 ControlObject *_self;
241 PyObject *_args;
242{
243 PyObject *_res = NULL;
244 OSErr _err;
245 Boolean inIsVisible;
246 Boolean inDoDraw;
247 if (!PyArg_ParseTuple(_args, "bb",
248 &inIsVisible,
249 &inDoDraw))
250 return NULL;
251 _err = SetControlVisibility(_self->ob_itself,
252 inIsVisible,
253 inDoDraw);
254 if (_err != noErr) return PyMac_Error(_err);
255 Py_INCREF(Py_None);
256 _res = Py_None;
257 return _res;
258}
259
Jack Jansen7d0bc831995-06-09 20:56:31 +0000260static PyObject *CtlObj_Draw1Control(_self, _args)
261 ControlObject *_self;
262 PyObject *_args;
263{
264 PyObject *_res = NULL;
265 if (!PyArg_ParseTuple(_args, ""))
266 return NULL;
267 Draw1Control(_self->ob_itself);
268 Py_INCREF(Py_None);
269 _res = Py_None;
270 return _res;
271}
272
Jack Jansen21f96871998-02-20 16:02:09 +0000273static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000274 ControlObject *_self;
275 PyObject *_args;
276{
277 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000278 OSErr _err;
279 Rect outRect;
280 SInt16 outBaseLineOffset;
281 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000282 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000283 _err = GetBestControlRect(_self->ob_itself,
284 &outRect,
285 &outBaseLineOffset);
286 if (_err != noErr) return PyMac_Error(_err);
287 _res = Py_BuildValue("O&h",
288 PyMac_BuildRect, &outRect,
289 outBaseLineOffset);
290 return _res;
291}
292
293static PyObject *CtlObj_SetControlFontStyle(_self, _args)
294 ControlObject *_self;
295 PyObject *_args;
296{
297 PyObject *_res = NULL;
298 OSErr _err;
299 ControlFontStyleRec inStyle;
300 if (!PyArg_ParseTuple(_args, "O&",
301 ControlFontStyle_Convert, &inStyle))
302 return NULL;
303 _err = SetControlFontStyle(_self->ob_itself,
304 &inStyle);
305 if (_err != noErr) return PyMac_Error(_err);
306 Py_INCREF(Py_None);
307 _res = Py_None;
308 return _res;
309}
310
311static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
312 ControlObject *_self;
313 PyObject *_args;
314{
315 PyObject *_res = NULL;
316 if (!PyArg_ParseTuple(_args, ""))
317 return NULL;
318 DrawControlInCurrentPort(_self->ob_itself);
319 Py_INCREF(Py_None);
320 _res = Py_None;
321 return _res;
322}
323
324static PyObject *CtlObj_SetUpControlBackground(_self, _args)
325 ControlObject *_self;
326 PyObject *_args;
327{
328 PyObject *_res = NULL;
329 OSErr _err;
330 SInt16 inDepth;
331 Boolean inIsColorDevice;
332 if (!PyArg_ParseTuple(_args, "hb",
333 &inDepth,
334 &inIsColorDevice))
335 return NULL;
336 _err = SetUpControlBackground(_self->ob_itself,
337 inDepth,
338 inIsColorDevice);
339 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000340 Py_INCREF(Py_None);
341 _res = Py_None;
342 return _res;
343}
344
Jack Jansena05ac601999-12-12 21:41:51 +0000345static PyObject *CtlObj_SetUpControlTextColor(_self, _args)
346 ControlObject *_self;
347 PyObject *_args;
348{
349 PyObject *_res = NULL;
350 OSErr _err;
351 SInt16 inDepth;
352 Boolean inIsColorDevice;
353 if (!PyArg_ParseTuple(_args, "hb",
354 &inDepth,
355 &inIsColorDevice))
356 return NULL;
357 _err = SetUpControlTextColor(_self->ob_itself,
358 inDepth,
359 inIsColorDevice);
360 if (_err != noErr) return PyMac_Error(_err);
361 Py_INCREF(Py_None);
362 _res = Py_None;
363 return _res;
364}
365
Jack Jansen7d0bc831995-06-09 20:56:31 +0000366static PyObject *CtlObj_DragControl(_self, _args)
367 ControlObject *_self;
368 PyObject *_args;
369{
370 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000371 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000372 Rect limitRect;
373 Rect slopRect;
374 DragConstraint axis;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000375 if (!PyArg_ParseTuple(_args, "O&O&O&H",
Jack Jansen754d4a41995-11-14 10:41:55 +0000376 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000377 PyMac_GetRect, &limitRect,
378 PyMac_GetRect, &slopRect,
379 &axis))
380 return NULL;
381 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000382 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000383 &limitRect,
384 &slopRect,
385 axis);
386 Py_INCREF(Py_None);
387 _res = Py_None;
388 return _res;
389}
390
391static PyObject *CtlObj_TestControl(_self, _args)
392 ControlObject *_self;
393 PyObject *_args;
394{
395 PyObject *_res = NULL;
396 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000397 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000398 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000399 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000400 return NULL;
401 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000402 testPoint);
403 _res = Py_BuildValue("h",
404 _rv);
405 return _res;
406}
407
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000408#if TARGET_API_MAC_CARBON
409
410static PyObject *CtlObj_HandleControlContextualMenuClick(_self, _args)
411 ControlObject *_self;
412 PyObject *_args;
413{
414 PyObject *_res = NULL;
415 OSStatus _err;
416 Point inWhere;
417 Boolean menuDisplayed;
418 if (!PyArg_ParseTuple(_args, "O&",
419 PyMac_GetPoint, &inWhere))
420 return NULL;
421 _err = HandleControlContextualMenuClick(_self->ob_itself,
422 inWhere,
423 &menuDisplayed);
424 if (_err != noErr) return PyMac_Error(_err);
425 _res = Py_BuildValue("b",
426 menuDisplayed);
427 return _res;
428}
429#endif
430
431#if TARGET_API_MAC_CARBON
432
433static PyObject *CtlObj_GetControlClickActivation(_self, _args)
434 ControlObject *_self;
435 PyObject *_args;
436{
437 PyObject *_res = NULL;
438 OSStatus _err;
439 Point inWhere;
440 EventModifiers inModifiers;
441 ClickActivationResult outResult;
442 if (!PyArg_ParseTuple(_args, "O&H",
443 PyMac_GetPoint, &inWhere,
444 &inModifiers))
445 return NULL;
446 _err = GetControlClickActivation(_self->ob_itself,
447 inWhere,
448 inModifiers,
449 &outResult);
450 if (_err != noErr) return PyMac_Error(_err);
451 _res = Py_BuildValue("l",
452 outResult);
453 return _res;
454}
455#endif
456
Jack Jansen21f96871998-02-20 16:02:09 +0000457static PyObject *CtlObj_HandleControlKey(_self, _args)
458 ControlObject *_self;
459 PyObject *_args;
460{
461 PyObject *_res = NULL;
462 SInt16 _rv;
463 SInt16 inKeyCode;
464 SInt16 inCharCode;
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000465 EventModifiers inModifiers;
466 if (!PyArg_ParseTuple(_args, "hhH",
Jack Jansen21f96871998-02-20 16:02:09 +0000467 &inKeyCode,
468 &inCharCode,
469 &inModifiers))
470 return NULL;
471 _rv = HandleControlKey(_self->ob_itself,
472 inKeyCode,
473 inCharCode,
474 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000475 _res = Py_BuildValue("h",
476 _rv);
477 return _res;
478}
479
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000480#if TARGET_API_MAC_CARBON
481
482static PyObject *CtlObj_HandleControlSetCursor(_self, _args)
483 ControlObject *_self;
484 PyObject *_args;
485{
486 PyObject *_res = NULL;
487 OSStatus _err;
488 Point localPoint;
489 EventModifiers modifiers;
490 Boolean cursorWasSet;
491 if (!PyArg_ParseTuple(_args, "O&H",
492 PyMac_GetPoint, &localPoint,
493 &modifiers))
494 return NULL;
495 _err = HandleControlSetCursor(_self->ob_itself,
496 localPoint,
497 modifiers,
498 &cursorWasSet);
499 if (_err != noErr) return PyMac_Error(_err);
500 _res = Py_BuildValue("b",
501 cursorWasSet);
502 return _res;
503}
504#endif
505
Jack Jansen7d0bc831995-06-09 20:56:31 +0000506static PyObject *CtlObj_MoveControl(_self, _args)
507 ControlObject *_self;
508 PyObject *_args;
509{
510 PyObject *_res = NULL;
511 SInt16 h;
512 SInt16 v;
513 if (!PyArg_ParseTuple(_args, "hh",
514 &h,
515 &v))
516 return NULL;
517 MoveControl(_self->ob_itself,
518 h,
519 v);
520 Py_INCREF(Py_None);
521 _res = Py_None;
522 return _res;
523}
524
525static PyObject *CtlObj_SizeControl(_self, _args)
526 ControlObject *_self;
527 PyObject *_args;
528{
529 PyObject *_res = NULL;
530 SInt16 w;
531 SInt16 h;
532 if (!PyArg_ParseTuple(_args, "hh",
533 &w,
534 &h))
535 return NULL;
536 SizeControl(_self->ob_itself,
537 w,
538 h);
539 Py_INCREF(Py_None);
540 _res = Py_None;
541 return _res;
542}
543
Jack Jansenae8a68f1995-06-06 12:55:40 +0000544static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000545 ControlObject *_self;
546 PyObject *_args;
547{
548 PyObject *_res = NULL;
549 Str255 title;
550 if (!PyArg_ParseTuple(_args, "O&",
551 PyMac_GetStr255, title))
552 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000553 SetControlTitle(_self->ob_itself,
554 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000555 Py_INCREF(Py_None);
556 _res = Py_None;
557 return _res;
558}
559
Jack Jansenae8a68f1995-06-06 12:55:40 +0000560static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000561 ControlObject *_self;
562 PyObject *_args;
563{
564 PyObject *_res = NULL;
565 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000566 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000567 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000568 GetControlTitle(_self->ob_itself,
569 title);
Jack Jansen41009001999-03-07 20:05:20 +0000570 _res = Py_BuildValue("O&",
571 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000572 return _res;
573}
574
Jack Jansenae8a68f1995-06-06 12:55:40 +0000575static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000576 ControlObject *_self;
577 PyObject *_args;
578{
579 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000580 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000581 if (!PyArg_ParseTuple(_args, ""))
582 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000583 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000584 _res = Py_BuildValue("h",
585 _rv);
586 return _res;
587}
588
Jack Jansen7d0bc831995-06-09 20:56:31 +0000589static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000590 ControlObject *_self;
591 PyObject *_args;
592{
593 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000594 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000595 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000596 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000597 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000598 SetControlValue(_self->ob_itself,
599 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000600 Py_INCREF(Py_None);
601 _res = Py_None;
602 return _res;
603}
604
Jack Jansenae8a68f1995-06-06 12:55:40 +0000605static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000606 ControlObject *_self;
607 PyObject *_args;
608{
609 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000610 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000611 if (!PyArg_ParseTuple(_args, ""))
612 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000613 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000614 _res = Py_BuildValue("h",
615 _rv);
616 return _res;
617}
618
Jack Jansen7d0bc831995-06-09 20:56:31 +0000619static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000620 ControlObject *_self;
621 PyObject *_args;
622{
623 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000624 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000625 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000626 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000627 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000628 SetControlMinimum(_self->ob_itself,
629 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000630 Py_INCREF(Py_None);
631 _res = Py_None;
632 return _res;
633}
634
Jack Jansenae8a68f1995-06-06 12:55:40 +0000635static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000636 ControlObject *_self;
637 PyObject *_args;
638{
639 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000640 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000641 if (!PyArg_ParseTuple(_args, ""))
642 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000643 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000644 _res = Py_BuildValue("h",
645 _rv);
646 return _res;
647}
648
Jack Jansen7d0bc831995-06-09 20:56:31 +0000649static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000650 ControlObject *_self;
651 PyObject *_args;
652{
653 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000654 SInt16 newMaximum;
655 if (!PyArg_ParseTuple(_args, "h",
656 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000657 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000658 SetControlMaximum(_self->ob_itself,
659 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000660 Py_INCREF(Py_None);
661 _res = Py_None;
662 return _res;
663}
664
Jack Jansena05ac601999-12-12 21:41:51 +0000665static PyObject *CtlObj_GetControlViewSize(_self, _args)
666 ControlObject *_self;
667 PyObject *_args;
668{
669 PyObject *_res = NULL;
670 SInt32 _rv;
671 if (!PyArg_ParseTuple(_args, ""))
672 return NULL;
673 _rv = GetControlViewSize(_self->ob_itself);
674 _res = Py_BuildValue("l",
675 _rv);
676 return _res;
677}
678
679static PyObject *CtlObj_SetControlViewSize(_self, _args)
680 ControlObject *_self;
681 PyObject *_args;
682{
683 PyObject *_res = NULL;
684 SInt32 newViewSize;
685 if (!PyArg_ParseTuple(_args, "l",
686 &newViewSize))
687 return NULL;
688 SetControlViewSize(_self->ob_itself,
689 newViewSize);
690 Py_INCREF(Py_None);
691 _res = Py_None;
692 return _res;
693}
694
695static PyObject *CtlObj_GetControl32BitValue(_self, _args)
696 ControlObject *_self;
697 PyObject *_args;
698{
699 PyObject *_res = NULL;
700 SInt32 _rv;
701 if (!PyArg_ParseTuple(_args, ""))
702 return NULL;
703 _rv = GetControl32BitValue(_self->ob_itself);
704 _res = Py_BuildValue("l",
705 _rv);
706 return _res;
707}
708
709static PyObject *CtlObj_SetControl32BitValue(_self, _args)
710 ControlObject *_self;
711 PyObject *_args;
712{
713 PyObject *_res = NULL;
714 SInt32 newValue;
715 if (!PyArg_ParseTuple(_args, "l",
716 &newValue))
717 return NULL;
718 SetControl32BitValue(_self->ob_itself,
719 newValue);
720 Py_INCREF(Py_None);
721 _res = Py_None;
722 return _res;
723}
724
725static PyObject *CtlObj_GetControl32BitMaximum(_self, _args)
726 ControlObject *_self;
727 PyObject *_args;
728{
729 PyObject *_res = NULL;
730 SInt32 _rv;
731 if (!PyArg_ParseTuple(_args, ""))
732 return NULL;
733 _rv = GetControl32BitMaximum(_self->ob_itself);
734 _res = Py_BuildValue("l",
735 _rv);
736 return _res;
737}
738
739static PyObject *CtlObj_SetControl32BitMaximum(_self, _args)
740 ControlObject *_self;
741 PyObject *_args;
742{
743 PyObject *_res = NULL;
744 SInt32 newMaximum;
745 if (!PyArg_ParseTuple(_args, "l",
746 &newMaximum))
747 return NULL;
748 SetControl32BitMaximum(_self->ob_itself,
749 newMaximum);
750 Py_INCREF(Py_None);
751 _res = Py_None;
752 return _res;
753}
754
755static PyObject *CtlObj_GetControl32BitMinimum(_self, _args)
756 ControlObject *_self;
757 PyObject *_args;
758{
759 PyObject *_res = NULL;
760 SInt32 _rv;
761 if (!PyArg_ParseTuple(_args, ""))
762 return NULL;
763 _rv = GetControl32BitMinimum(_self->ob_itself);
764 _res = Py_BuildValue("l",
765 _rv);
766 return _res;
767}
768
769static PyObject *CtlObj_SetControl32BitMinimum(_self, _args)
770 ControlObject *_self;
771 PyObject *_args;
772{
773 PyObject *_res = NULL;
774 SInt32 newMinimum;
775 if (!PyArg_ParseTuple(_args, "l",
776 &newMinimum))
777 return NULL;
778 SetControl32BitMinimum(_self->ob_itself,
779 newMinimum);
780 Py_INCREF(Py_None);
781 _res = Py_None;
782 return _res;
783}
784
785static PyObject *CtlObj_IsValidControlHandle(_self, _args)
786 ControlObject *_self;
787 PyObject *_args;
788{
789 PyObject *_res = NULL;
790 Boolean _rv;
791 if (!PyArg_ParseTuple(_args, ""))
792 return NULL;
793 _rv = IsValidControlHandle(_self->ob_itself);
794 _res = Py_BuildValue("b",
795 _rv);
796 return _res;
797}
798
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000799#if TARGET_API_MAC_CARBON
800
801static PyObject *CtlObj_SetControlID(_self, _args)
802 ControlObject *_self;
803 PyObject *_args;
804{
805 PyObject *_res = NULL;
806 OSStatus _err;
807 ControlID inID;
808 if (!PyArg_ParseTuple(_args, "O&",
809 PyControlID_Convert, &inID))
810 return NULL;
811 _err = SetControlID(_self->ob_itself,
812 &inID);
813 if (_err != noErr) return PyMac_Error(_err);
814 Py_INCREF(Py_None);
815 _res = Py_None;
816 return _res;
817}
818#endif
819
820#if TARGET_API_MAC_CARBON
821
822static PyObject *CtlObj_GetControlID(_self, _args)
823 ControlObject *_self;
824 PyObject *_args;
825{
826 PyObject *_res = NULL;
827 OSStatus _err;
828 ControlID outID;
829 if (!PyArg_ParseTuple(_args, ""))
830 return NULL;
831 _err = GetControlID(_self->ob_itself,
832 &outID);
833 if (_err != noErr) return PyMac_Error(_err);
834 _res = Py_BuildValue("O&",
835 PyControlID_New, &outID);
836 return _res;
837}
838#endif
839
Jack Jansena05ac601999-12-12 21:41:51 +0000840static PyObject *CtlObj_RemoveControlProperty(_self, _args)
841 ControlObject *_self;
842 PyObject *_args;
843{
844 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000845 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000846 OSType propertyCreator;
847 OSType propertyTag;
848 if (!PyArg_ParseTuple(_args, "O&O&",
849 PyMac_GetOSType, &propertyCreator,
850 PyMac_GetOSType, &propertyTag))
851 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000852 _err = RemoveControlProperty(_self->ob_itself,
853 propertyCreator,
854 propertyTag);
855 if (_err != noErr) return PyMac_Error(_err);
856 Py_INCREF(Py_None);
857 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000858 return _res;
859}
860
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000861#if TARGET_API_MAC_CARBON
862
863static PyObject *CtlObj_GetControlPropertyAttributes(_self, _args)
864 ControlObject *_self;
865 PyObject *_args;
866{
867 PyObject *_res = NULL;
868 OSStatus _err;
869 OSType propertyCreator;
870 OSType propertyTag;
871 UInt32 attributes;
872 if (!PyArg_ParseTuple(_args, "O&O&",
873 PyMac_GetOSType, &propertyCreator,
874 PyMac_GetOSType, &propertyTag))
875 return NULL;
876 _err = GetControlPropertyAttributes(_self->ob_itself,
877 propertyCreator,
878 propertyTag,
879 &attributes);
880 if (_err != noErr) return PyMac_Error(_err);
881 _res = Py_BuildValue("l",
882 attributes);
883 return _res;
884}
885#endif
886
887#if TARGET_API_MAC_CARBON
888
889static PyObject *CtlObj_ChangeControlPropertyAttributes(_self, _args)
890 ControlObject *_self;
891 PyObject *_args;
892{
893 PyObject *_res = NULL;
894 OSStatus _err;
895 OSType propertyCreator;
896 OSType propertyTag;
897 UInt32 attributesToSet;
898 UInt32 attributesToClear;
899 if (!PyArg_ParseTuple(_args, "O&O&ll",
900 PyMac_GetOSType, &propertyCreator,
901 PyMac_GetOSType, &propertyTag,
902 &attributesToSet,
903 &attributesToClear))
904 return NULL;
905 _err = ChangeControlPropertyAttributes(_self->ob_itself,
906 propertyCreator,
907 propertyTag,
908 attributesToSet,
909 attributesToClear);
910 if (_err != noErr) return PyMac_Error(_err);
911 Py_INCREF(Py_None);
912 _res = Py_None;
913 return _res;
914}
915#endif
916
Jack Jansena05ac601999-12-12 21:41:51 +0000917static PyObject *CtlObj_GetControlRegion(_self, _args)
918 ControlObject *_self;
919 PyObject *_args;
920{
921 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000922 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000923 ControlPartCode inPart;
924 RgnHandle outRegion;
925 if (!PyArg_ParseTuple(_args, "hO&",
926 &inPart,
927 ResObj_Convert, &outRegion))
928 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000929 _err = GetControlRegion(_self->ob_itself,
930 inPart,
931 outRegion);
932 if (_err != noErr) return PyMac_Error(_err);
933 Py_INCREF(Py_None);
934 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000935 return _res;
936}
937
Jack Jansen7d0bc831995-06-09 20:56:31 +0000938static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000939 ControlObject *_self;
940 PyObject *_args;
941{
942 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000943 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000944 if (!PyArg_ParseTuple(_args, ""))
945 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000946 _rv = GetControlVariant(_self->ob_itself);
947 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000948 _rv);
949 return _res;
950}
951
Jack Jansen7d0bc831995-06-09 20:56:31 +0000952static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000953 ControlObject *_self;
954 PyObject *_args;
955{
956 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000957 SInt32 data;
958 if (!PyArg_ParseTuple(_args, "l",
959 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000960 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000961 SetControlReference(_self->ob_itself,
962 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000963 Py_INCREF(Py_None);
964 _res = Py_None;
965 return _res;
966}
967
Jack Jansen7d0bc831995-06-09 20:56:31 +0000968static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000969 ControlObject *_self;
970 PyObject *_args;
971{
972 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000973 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000974 if (!PyArg_ParseTuple(_args, ""))
975 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000976 _rv = GetControlReference(_self->ob_itself);
977 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000978 _rv);
979 return _res;
980}
981
Jack Jansen74a1e632000-07-14 22:37:27 +0000982#if !TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000983
Jack Jansenc7fefed1997-08-15 14:32:18 +0000984static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
985 ControlObject *_self;
986 PyObject *_args;
987{
988 PyObject *_res = NULL;
989 Boolean _rv;
990 AuxCtlHandle acHndl;
991 if (!PyArg_ParseTuple(_args, ""))
992 return NULL;
993 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
994 &acHndl);
995 _res = Py_BuildValue("bO&",
996 _rv,
997 ResObj_New, acHndl);
998 return _res;
999}
Jack Jansene79dc762000-06-02 21:35:07 +00001000#endif
1001
Jack Jansen74a1e632000-07-14 22:37:27 +00001002#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00001003
1004static PyObject *CtlObj_SetControlColor(_self, _args)
1005 ControlObject *_self;
1006 PyObject *_args;
1007{
1008 PyObject *_res = NULL;
1009 CCTabHandle newColorTable;
1010 if (!PyArg_ParseTuple(_args, "O&",
1011 ResObj_Convert, &newColorTable))
1012 return NULL;
1013 SetControlColor(_self->ob_itself,
1014 newColorTable);
1015 Py_INCREF(Py_None);
1016 _res = Py_None;
1017 return _res;
1018}
Jack Jansene79dc762000-06-02 21:35:07 +00001019#endif
1020
Jack Jansen21f96871998-02-20 16:02:09 +00001021static PyObject *CtlObj_SendControlMessage(_self, _args)
1022 ControlObject *_self;
1023 PyObject *_args;
1024{
1025 PyObject *_res = NULL;
1026 SInt32 _rv;
1027 SInt16 inMessage;
1028 SInt32 inParam;
1029 if (!PyArg_ParseTuple(_args, "hl",
1030 &inMessage,
1031 &inParam))
1032 return NULL;
1033 _rv = SendControlMessage(_self->ob_itself,
1034 inMessage,
1035 inParam);
1036 _res = Py_BuildValue("l",
1037 _rv);
1038 return _res;
1039}
1040
1041static PyObject *CtlObj_EmbedControl(_self, _args)
1042 ControlObject *_self;
1043 PyObject *_args;
1044{
1045 PyObject *_res = NULL;
1046 OSErr _err;
1047 ControlHandle inContainer;
1048 if (!PyArg_ParseTuple(_args, "O&",
1049 CtlObj_Convert, &inContainer))
1050 return NULL;
1051 _err = EmbedControl(_self->ob_itself,
1052 inContainer);
1053 if (_err != noErr) return PyMac_Error(_err);
1054 Py_INCREF(Py_None);
1055 _res = Py_None;
1056 return _res;
1057}
1058
1059static PyObject *CtlObj_AutoEmbedControl(_self, _args)
1060 ControlObject *_self;
1061 PyObject *_args;
1062{
1063 PyObject *_res = NULL;
1064 OSErr _err;
1065 WindowPtr inWindow;
1066 if (!PyArg_ParseTuple(_args, "O&",
1067 WinObj_Convert, &inWindow))
1068 return NULL;
1069 _err = AutoEmbedControl(_self->ob_itself,
1070 inWindow);
1071 if (_err != noErr) return PyMac_Error(_err);
1072 Py_INCREF(Py_None);
1073 _res = Py_None;
1074 return _res;
1075}
1076
1077static PyObject *CtlObj_GetSuperControl(_self, _args)
1078 ControlObject *_self;
1079 PyObject *_args;
1080{
1081 PyObject *_res = NULL;
1082 OSErr _err;
1083 ControlHandle outParent;
1084 if (!PyArg_ParseTuple(_args, ""))
1085 return NULL;
1086 _err = GetSuperControl(_self->ob_itself,
1087 &outParent);
1088 if (_err != noErr) return PyMac_Error(_err);
1089 _res = Py_BuildValue("O&",
1090 CtlObj_WhichControl, outParent);
1091 return _res;
1092}
1093
1094static PyObject *CtlObj_CountSubControls(_self, _args)
1095 ControlObject *_self;
1096 PyObject *_args;
1097{
1098 PyObject *_res = NULL;
1099 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001100 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +00001101 if (!PyArg_ParseTuple(_args, ""))
1102 return NULL;
1103 _err = CountSubControls(_self->ob_itself,
1104 &outNumChildren);
1105 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +00001106 _res = Py_BuildValue("H",
Jack Jansen21f96871998-02-20 16:02:09 +00001107 outNumChildren);
1108 return _res;
1109}
1110
1111static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
1112 ControlObject *_self;
1113 PyObject *_args;
1114{
1115 PyObject *_res = NULL;
1116 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001117 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +00001118 ControlHandle outSubControl;
Jack Jansen0b13e7c2000-07-07 13:09:35 +00001119 if (!PyArg_ParseTuple(_args, "H",
Jack Jansen21f96871998-02-20 16:02:09 +00001120 &inIndex))
1121 return NULL;
1122 _err = GetIndexedSubControl(_self->ob_itself,
1123 inIndex,
1124 &outSubControl);
1125 if (_err != noErr) return PyMac_Error(_err);
1126 _res = Py_BuildValue("O&",
1127 CtlObj_WhichControl, outSubControl);
1128 return _res;
1129}
1130
1131static PyObject *CtlObj_SetControlSupervisor(_self, _args)
1132 ControlObject *_self;
1133 PyObject *_args;
1134{
1135 PyObject *_res = NULL;
1136 OSErr _err;
1137 ControlHandle inBoss;
1138 if (!PyArg_ParseTuple(_args, "O&",
1139 CtlObj_Convert, &inBoss))
1140 return NULL;
1141 _err = SetControlSupervisor(_self->ob_itself,
1142 inBoss);
1143 if (_err != noErr) return PyMac_Error(_err);
1144 Py_INCREF(Py_None);
1145 _res = Py_None;
1146 return _res;
1147}
1148
1149static PyObject *CtlObj_GetControlFeatures(_self, _args)
1150 ControlObject *_self;
1151 PyObject *_args;
1152{
1153 PyObject *_res = NULL;
1154 OSErr _err;
1155 UInt32 outFeatures;
1156 if (!PyArg_ParseTuple(_args, ""))
1157 return NULL;
1158 _err = GetControlFeatures(_self->ob_itself,
1159 &outFeatures);
1160 if (_err != noErr) return PyMac_Error(_err);
1161 _res = Py_BuildValue("l",
1162 outFeatures);
1163 return _res;
1164}
1165
1166static PyObject *CtlObj_GetControlDataSize(_self, _args)
1167 ControlObject *_self;
1168 PyObject *_args;
1169{
1170 PyObject *_res = NULL;
1171 OSErr _err;
1172 ControlPartCode inPart;
1173 ResType inTagName;
1174 Size outMaxSize;
1175 if (!PyArg_ParseTuple(_args, "hO&",
1176 &inPart,
1177 PyMac_GetOSType, &inTagName))
1178 return NULL;
1179 _err = GetControlDataSize(_self->ob_itself,
1180 inPart,
1181 inTagName,
1182 &outMaxSize);
1183 if (_err != noErr) return PyMac_Error(_err);
1184 _res = Py_BuildValue("l",
1185 outMaxSize);
1186 return _res;
1187}
1188
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001189#if TARGET_API_MAC_CARBON
1190
Jack Jansen723ad8a2000-12-12 22:10:21 +00001191static PyObject *CtlObj_HandleControlDragTracking(_self, _args)
1192 ControlObject *_self;
1193 PyObject *_args;
1194{
1195 PyObject *_res = NULL;
1196 OSStatus _err;
1197 DragTrackingMessage inMessage;
1198 DragReference inDrag;
1199 Boolean outLikesDrag;
1200 if (!PyArg_ParseTuple(_args, "hO&",
1201 &inMessage,
1202 DragObj_Convert, &inDrag))
1203 return NULL;
1204 _err = HandleControlDragTracking(_self->ob_itself,
1205 inMessage,
1206 inDrag,
1207 &outLikesDrag);
1208 if (_err != noErr) return PyMac_Error(_err);
1209 _res = Py_BuildValue("b",
1210 outLikesDrag);
1211 return _res;
1212}
1213#endif
1214
1215#if TARGET_API_MAC_CARBON
1216
1217static PyObject *CtlObj_HandleControlDragReceive(_self, _args)
1218 ControlObject *_self;
1219 PyObject *_args;
1220{
1221 PyObject *_res = NULL;
1222 OSStatus _err;
1223 DragReference inDrag;
1224 if (!PyArg_ParseTuple(_args, "O&",
1225 DragObj_Convert, &inDrag))
1226 return NULL;
1227 _err = HandleControlDragReceive(_self->ob_itself,
1228 inDrag);
1229 if (_err != noErr) return PyMac_Error(_err);
1230 Py_INCREF(Py_None);
1231 _res = Py_None;
1232 return _res;
1233}
1234#endif
1235
1236#if TARGET_API_MAC_CARBON
1237
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001238static PyObject *CtlObj_SetControlDragTrackingEnabled(_self, _args)
1239 ControlObject *_self;
1240 PyObject *_args;
1241{
1242 PyObject *_res = NULL;
1243 OSStatus _err;
1244 Boolean tracks;
1245 if (!PyArg_ParseTuple(_args, "b",
1246 &tracks))
1247 return NULL;
1248 _err = SetControlDragTrackingEnabled(_self->ob_itself,
1249 tracks);
1250 if (_err != noErr) return PyMac_Error(_err);
1251 Py_INCREF(Py_None);
1252 _res = Py_None;
1253 return _res;
1254}
1255#endif
1256
1257#if TARGET_API_MAC_CARBON
1258
1259static PyObject *CtlObj_IsControlDragTrackingEnabled(_self, _args)
1260 ControlObject *_self;
1261 PyObject *_args;
1262{
1263 PyObject *_res = NULL;
1264 OSStatus _err;
1265 Boolean tracks;
1266 if (!PyArg_ParseTuple(_args, ""))
1267 return NULL;
1268 _err = IsControlDragTrackingEnabled(_self->ob_itself,
1269 &tracks);
1270 if (_err != noErr) return PyMac_Error(_err);
1271 _res = Py_BuildValue("b",
1272 tracks);
1273 return _res;
1274}
1275#endif
1276
1277#if ACCESSOR_CALLS_ARE_FUNCTIONS
1278
1279static PyObject *CtlObj_GetControlBounds(_self, _args)
1280 ControlObject *_self;
1281 PyObject *_args;
1282{
1283 PyObject *_res = NULL;
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001284 Rect bounds;
1285 if (!PyArg_ParseTuple(_args, ""))
1286 return NULL;
Jack Jansena9e3db32001-01-09 22:10:16 +00001287 GetControlBounds(_self->ob_itself,
1288 &bounds);
1289 _res = Py_BuildValue("O&",
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001290 PyMac_BuildRect, &bounds);
1291 return _res;
1292}
1293#endif
1294
1295#if ACCESSOR_CALLS_ARE_FUNCTIONS
1296
1297static PyObject *CtlObj_IsControlHilited(_self, _args)
1298 ControlObject *_self;
1299 PyObject *_args;
1300{
1301 PyObject *_res = NULL;
1302 Boolean _rv;
1303 if (!PyArg_ParseTuple(_args, ""))
1304 return NULL;
1305 _rv = IsControlHilited(_self->ob_itself);
1306 _res = Py_BuildValue("b",
1307 _rv);
1308 return _res;
1309}
1310#endif
1311
1312#if ACCESSOR_CALLS_ARE_FUNCTIONS
1313
1314static PyObject *CtlObj_GetControlHilite(_self, _args)
1315 ControlObject *_self;
1316 PyObject *_args;
1317{
1318 PyObject *_res = NULL;
1319 UInt16 _rv;
1320 if (!PyArg_ParseTuple(_args, ""))
1321 return NULL;
1322 _rv = GetControlHilite(_self->ob_itself);
1323 _res = Py_BuildValue("H",
1324 _rv);
1325 return _res;
1326}
1327#endif
1328
1329#if ACCESSOR_CALLS_ARE_FUNCTIONS
1330
1331static PyObject *CtlObj_GetControlOwner(_self, _args)
1332 ControlObject *_self;
1333 PyObject *_args;
1334{
1335 PyObject *_res = NULL;
1336 WindowPtr _rv;
1337 if (!PyArg_ParseTuple(_args, ""))
1338 return NULL;
1339 _rv = GetControlOwner(_self->ob_itself);
1340 _res = Py_BuildValue("O&",
1341 WinObj_New, _rv);
1342 return _res;
1343}
1344#endif
1345
1346#if ACCESSOR_CALLS_ARE_FUNCTIONS
1347
1348static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1349 ControlObject *_self;
1350 PyObject *_args;
1351{
1352 PyObject *_res = NULL;
1353 Handle _rv;
1354 if (!PyArg_ParseTuple(_args, ""))
1355 return NULL;
1356 _rv = GetControlDataHandle(_self->ob_itself);
1357 _res = Py_BuildValue("O&",
1358 ResObj_New, _rv);
1359 return _res;
1360}
1361#endif
1362
1363#if ACCESSOR_CALLS_ARE_FUNCTIONS
1364
1365static PyObject *CtlObj_GetControlPopupMenuHandle(_self, _args)
1366 ControlObject *_self;
1367 PyObject *_args;
1368{
1369 PyObject *_res = NULL;
1370 MenuHandle _rv;
1371 if (!PyArg_ParseTuple(_args, ""))
1372 return NULL;
1373 _rv = GetControlPopupMenuHandle(_self->ob_itself);
1374 _res = Py_BuildValue("O&",
1375 MenuObj_New, _rv);
1376 return _res;
1377}
1378#endif
1379
1380#if ACCESSOR_CALLS_ARE_FUNCTIONS
1381
1382static PyObject *CtlObj_GetControlPopupMenuID(_self, _args)
1383 ControlObject *_self;
1384 PyObject *_args;
1385{
1386 PyObject *_res = NULL;
1387 short _rv;
1388 if (!PyArg_ParseTuple(_args, ""))
1389 return NULL;
1390 _rv = GetControlPopupMenuID(_self->ob_itself);
1391 _res = Py_BuildValue("h",
1392 _rv);
1393 return _res;
1394}
1395#endif
1396
1397#if ACCESSOR_CALLS_ARE_FUNCTIONS
1398
1399static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1400 ControlObject *_self;
1401 PyObject *_args;
1402{
1403 PyObject *_res = NULL;
1404 Handle dataHandle;
1405 if (!PyArg_ParseTuple(_args, "O&",
1406 ResObj_Convert, &dataHandle))
1407 return NULL;
1408 SetControlDataHandle(_self->ob_itself,
1409 dataHandle);
1410 Py_INCREF(Py_None);
1411 _res = Py_None;
1412 return _res;
1413}
1414#endif
1415
1416#if ACCESSOR_CALLS_ARE_FUNCTIONS
1417
1418static PyObject *CtlObj_SetControlBounds(_self, _args)
1419 ControlObject *_self;
1420 PyObject *_args;
1421{
1422 PyObject *_res = NULL;
1423 Rect bounds;
1424 if (!PyArg_ParseTuple(_args, "O&",
1425 PyMac_GetRect, &bounds))
1426 return NULL;
1427 SetControlBounds(_self->ob_itself,
1428 &bounds);
1429 Py_INCREF(Py_None);
1430 _res = Py_None;
1431 return _res;
1432}
1433#endif
1434
1435#if ACCESSOR_CALLS_ARE_FUNCTIONS
1436
1437static PyObject *CtlObj_SetControlPopupMenuHandle(_self, _args)
1438 ControlObject *_self;
1439 PyObject *_args;
1440{
1441 PyObject *_res = NULL;
1442 MenuHandle popupMenu;
1443 if (!PyArg_ParseTuple(_args, "O&",
1444 MenuObj_Convert, &popupMenu))
1445 return NULL;
1446 SetControlPopupMenuHandle(_self->ob_itself,
1447 popupMenu);
1448 Py_INCREF(Py_None);
1449 _res = Py_None;
1450 return _res;
1451}
1452#endif
1453
1454#if ACCESSOR_CALLS_ARE_FUNCTIONS
1455
1456static PyObject *CtlObj_SetControlPopupMenuID(_self, _args)
1457 ControlObject *_self;
1458 PyObject *_args;
1459{
1460 PyObject *_res = NULL;
1461 short menuID;
1462 if (!PyArg_ParseTuple(_args, "h",
1463 &menuID))
1464 return NULL;
1465 SetControlPopupMenuID(_self->ob_itself,
1466 menuID);
1467 Py_INCREF(Py_None);
1468 _res = Py_None;
1469 return _res;
1470}
1471#endif
1472
1473static PyObject *CtlObj_GetBevelButtonMenuValue(_self, _args)
1474 ControlObject *_self;
1475 PyObject *_args;
1476{
1477 PyObject *_res = NULL;
1478 OSErr _err;
1479 SInt16 outValue;
1480 if (!PyArg_ParseTuple(_args, ""))
1481 return NULL;
1482 _err = GetBevelButtonMenuValue(_self->ob_itself,
1483 &outValue);
1484 if (_err != noErr) return PyMac_Error(_err);
1485 _res = Py_BuildValue("h",
1486 outValue);
1487 return _res;
1488}
1489
1490static PyObject *CtlObj_SetBevelButtonMenuValue(_self, _args)
1491 ControlObject *_self;
1492 PyObject *_args;
1493{
1494 PyObject *_res = NULL;
1495 OSErr _err;
1496 SInt16 inValue;
1497 if (!PyArg_ParseTuple(_args, "h",
1498 &inValue))
1499 return NULL;
1500 _err = SetBevelButtonMenuValue(_self->ob_itself,
1501 inValue);
1502 if (_err != noErr) return PyMac_Error(_err);
1503 Py_INCREF(Py_None);
1504 _res = Py_None;
1505 return _res;
1506}
1507
1508static PyObject *CtlObj_GetBevelButtonMenuHandle(_self, _args)
1509 ControlObject *_self;
1510 PyObject *_args;
1511{
1512 PyObject *_res = NULL;
1513 OSErr _err;
1514 MenuHandle outHandle;
1515 if (!PyArg_ParseTuple(_args, ""))
1516 return NULL;
1517 _err = GetBevelButtonMenuHandle(_self->ob_itself,
1518 &outHandle);
1519 if (_err != noErr) return PyMac_Error(_err);
1520 _res = Py_BuildValue("O&",
1521 MenuObj_New, outHandle);
1522 return _res;
1523}
1524
1525static PyObject *CtlObj_SetBevelButtonTransform(_self, _args)
1526 ControlObject *_self;
1527 PyObject *_args;
1528{
1529 PyObject *_res = NULL;
1530 OSErr _err;
1531 IconTransformType transform;
1532 if (!PyArg_ParseTuple(_args, "h",
1533 &transform))
1534 return NULL;
1535 _err = SetBevelButtonTransform(_self->ob_itself,
1536 transform);
1537 if (_err != noErr) return PyMac_Error(_err);
1538 Py_INCREF(Py_None);
1539 _res = Py_None;
1540 return _res;
1541}
1542
1543static PyObject *CtlObj_SetDisclosureTriangleLastValue(_self, _args)
1544 ControlObject *_self;
1545 PyObject *_args;
1546{
1547 PyObject *_res = NULL;
1548 OSErr _err;
1549 SInt16 inValue;
1550 if (!PyArg_ParseTuple(_args, "h",
1551 &inValue))
1552 return NULL;
1553 _err = SetDisclosureTriangleLastValue(_self->ob_itself,
1554 inValue);
1555 if (_err != noErr) return PyMac_Error(_err);
1556 Py_INCREF(Py_None);
1557 _res = Py_None;
1558 return _res;
1559}
1560
1561static PyObject *CtlObj_GetTabContentRect(_self, _args)
1562 ControlObject *_self;
1563 PyObject *_args;
1564{
1565 PyObject *_res = NULL;
1566 OSErr _err;
1567 Rect outContentRect;
1568 if (!PyArg_ParseTuple(_args, ""))
1569 return NULL;
1570 _err = GetTabContentRect(_self->ob_itself,
1571 &outContentRect);
1572 if (_err != noErr) return PyMac_Error(_err);
1573 _res = Py_BuildValue("O&",
1574 PyMac_BuildRect, &outContentRect);
1575 return _res;
1576}
1577
1578static PyObject *CtlObj_SetTabEnabled(_self, _args)
1579 ControlObject *_self;
1580 PyObject *_args;
1581{
1582 PyObject *_res = NULL;
1583 OSErr _err;
1584 SInt16 inTabToHilite;
1585 Boolean inEnabled;
1586 if (!PyArg_ParseTuple(_args, "hb",
1587 &inTabToHilite,
1588 &inEnabled))
1589 return NULL;
1590 _err = SetTabEnabled(_self->ob_itself,
1591 inTabToHilite,
1592 inEnabled);
1593 if (_err != noErr) return PyMac_Error(_err);
1594 Py_INCREF(Py_None);
1595 _res = Py_None;
1596 return _res;
1597}
1598
1599static PyObject *CtlObj_SetImageWellTransform(_self, _args)
1600 ControlObject *_self;
1601 PyObject *_args;
1602{
1603 PyObject *_res = NULL;
1604 OSErr _err;
1605 IconTransformType inTransform;
1606 if (!PyArg_ParseTuple(_args, "h",
1607 &inTransform))
1608 return NULL;
1609 _err = SetImageWellTransform(_self->ob_itself,
1610 inTransform);
1611 if (_err != noErr) return PyMac_Error(_err);
1612 Py_INCREF(Py_None);
1613 _res = Py_None;
1614 return _res;
1615}
1616
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001617static PyObject *CtlObj_as_Resource(_self, _args)
1618 ControlObject *_self;
1619 PyObject *_args;
1620{
1621 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001622 Handle _rv;
1623 if (!PyArg_ParseTuple(_args, ""))
1624 return NULL;
1625 _rv = as_Resource(_self->ob_itself);
1626 _res = Py_BuildValue("O&",
1627 ResObj_New, _rv);
1628 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001629}
1630
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001631static PyObject *CtlObj_GetControlRect(_self, _args)
1632 ControlObject *_self;
1633 PyObject *_args;
1634{
1635 PyObject *_res = NULL;
1636 Rect rect;
1637 if (!PyArg_ParseTuple(_args, ""))
1638 return NULL;
1639 GetControlRect(_self->ob_itself,
1640 &rect);
1641 _res = Py_BuildValue("O&",
1642 PyMac_BuildRect, &rect);
1643 return _res;
1644}
1645
Jack Jansencfb60ee1996-10-01 10:46:46 +00001646static PyObject *CtlObj_DisposeControl(_self, _args)
1647 ControlObject *_self;
1648 PyObject *_args;
1649{
1650 PyObject *_res = NULL;
1651
1652 if (!PyArg_ParseTuple(_args, ""))
1653 return NULL;
1654 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001655 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001656 DisposeControl(_self->ob_itself);
1657 _self->ob_itself = NULL;
1658 }
1659 Py_INCREF(Py_None);
1660 _res = Py_None;
1661 return _res;
1662
1663}
1664
Jack Jansen848250c1998-05-28 14:20:09 +00001665static PyObject *CtlObj_TrackControl(_self, _args)
1666 ControlObject *_self;
1667 PyObject *_args;
1668{
1669 PyObject *_res = NULL;
1670
1671 ControlPartCode _rv;
1672 Point startPoint;
1673 ControlActionUPP upp = 0;
1674 PyObject *callback = 0;
1675
1676 if (!PyArg_ParseTuple(_args, "O&|O",
1677 PyMac_GetPoint, &startPoint, &callback))
1678 return NULL;
1679 if (callback && callback != Py_None) {
1680 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1681 upp = (ControlActionUPP)-1;
1682 else {
1683 settrackfunc(callback);
1684 upp = mytracker_upp;
1685 }
1686 }
1687 _rv = TrackControl(_self->ob_itself,
1688 startPoint,
1689 upp);
1690 clrtrackfunc();
1691 _res = Py_BuildValue("h",
1692 _rv);
1693 return _res;
1694
1695}
1696
Jack Jansen24c35311999-12-09 22:49:51 +00001697static PyObject *CtlObj_HandleControlClick(_self, _args)
1698 ControlObject *_self;
1699 PyObject *_args;
1700{
1701 PyObject *_res = NULL;
1702
1703 ControlPartCode _rv;
1704 Point startPoint;
1705 SInt16 modifiers;
1706 ControlActionUPP upp = 0;
1707 PyObject *callback = 0;
1708
1709 if (!PyArg_ParseTuple(_args, "O&h|O",
1710 PyMac_GetPoint, &startPoint,
1711 &modifiers,
1712 &callback))
1713 return NULL;
1714 if (callback && callback != Py_None) {
1715 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1716 upp = (ControlActionUPP)-1;
1717 else {
1718 settrackfunc(callback);
1719 upp = mytracker_upp;
1720 }
1721 }
1722 _rv = HandleControlClick(_self->ob_itself,
1723 startPoint,
1724 modifiers,
1725 upp);
1726 clrtrackfunc();
1727 _res = Py_BuildValue("h",
1728 _rv);
1729 return _res;
1730
1731}
1732
1733static PyObject *CtlObj_SetControlData(_self, _args)
1734 ControlObject *_self;
1735 PyObject *_args;
1736{
1737 PyObject *_res = NULL;
1738
1739 OSErr _err;
1740 ControlPartCode inPart;
1741 ResType inTagName;
1742 Size bufferSize;
1743 Ptr buffer;
1744
1745 if (!PyArg_ParseTuple(_args, "hO&s#",
1746 &inPart,
1747 PyMac_GetOSType, &inTagName,
1748 &buffer, &bufferSize))
1749 return NULL;
1750
1751 _err = SetControlData(_self->ob_itself,
1752 inPart,
1753 inTagName,
1754 bufferSize,
1755 buffer);
1756
1757 if (_err != noErr)
1758 return PyMac_Error(_err);
1759 _res = Py_None;
1760 return _res;
1761
1762}
1763
1764static PyObject *CtlObj_GetControlData(_self, _args)
1765 ControlObject *_self;
1766 PyObject *_args;
1767{
1768 PyObject *_res = NULL;
1769
1770 OSErr _err;
1771 ControlPartCode inPart;
1772 ResType inTagName;
1773 Size bufferSize;
1774 Ptr buffer;
1775 Size outSize;
1776
1777 if (!PyArg_ParseTuple(_args, "hO&",
1778 &inPart,
1779 PyMac_GetOSType, &inTagName))
1780 return NULL;
1781
1782 /* allocate a buffer for the data */
1783 _err = GetControlDataSize(_self->ob_itself,
1784 inPart,
1785 inTagName,
1786 &bufferSize);
1787 if (_err != noErr)
1788 return PyMac_Error(_err);
1789 buffer = PyMem_NEW(char, bufferSize);
1790 if (buffer == NULL)
1791 return PyErr_NoMemory();
1792
1793 _err = GetControlData(_self->ob_itself,
1794 inPart,
1795 inTagName,
1796 bufferSize,
1797 buffer,
1798 &outSize);
1799
1800 if (_err != noErr) {
1801 PyMem_DEL(buffer);
1802 return PyMac_Error(_err);
1803 }
1804 _res = Py_BuildValue("s#", buffer, outSize);
1805 PyMem_DEL(buffer);
1806 return _res;
1807
1808}
1809
Jack Jansena9e3db32001-01-09 22:10:16 +00001810static PyObject *CtlObj_SetControlData_Handle(_self, _args)
Jack Jansen1f9249c1999-12-19 00:05:50 +00001811 ControlObject *_self;
1812 PyObject *_args;
1813{
1814 PyObject *_res = NULL;
1815
1816 OSErr _err;
1817 ControlPartCode inPart;
1818 ResType inTagName;
1819 Handle buffer;
1820
1821 if (!PyArg_ParseTuple(_args, "hO&O&",
1822 &inPart,
1823 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001824 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001825 return NULL;
1826
1827 _err = SetControlData(_self->ob_itself,
1828 inPart,
1829 inTagName,
1830 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001831 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001832
1833 if (_err != noErr)
1834 return PyMac_Error(_err);
1835 _res = Py_None;
1836 return _res;
1837
1838}
1839
Jack Jansena9e3db32001-01-09 22:10:16 +00001840static PyObject *CtlObj_GetControlData_Handle(_self, _args)
Jack Jansen1f9249c1999-12-19 00:05:50 +00001841 ControlObject *_self;
1842 PyObject *_args;
1843{
1844 PyObject *_res = NULL;
1845
1846 OSErr _err;
1847 ControlPartCode inPart;
1848 ResType inTagName;
1849 Size bufferSize;
1850 Handle hdl;
1851
1852 if (!PyArg_ParseTuple(_args, "hO&",
1853 &inPart,
1854 PyMac_GetOSType, &inTagName))
1855 return NULL;
1856
1857 /* Check it is handle-sized */
1858 _err = GetControlDataSize(_self->ob_itself,
1859 inPart,
1860 inTagName,
1861 &bufferSize);
1862 if (_err != noErr)
1863 return PyMac_Error(_err);
1864 if (bufferSize != sizeof(Handle)) {
1865 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1866 return NULL;
1867 }
1868
1869 _err = GetControlData(_self->ob_itself,
1870 inPart,
1871 inTagName,
1872 sizeof(Handle),
1873 (Ptr)&hdl,
1874 &bufferSize);
1875
1876 if (_err != noErr) {
1877 return PyMac_Error(_err);
1878 }
1879 return Py_BuildValue("O&", OptResObj_New, hdl);
1880
1881}
1882
Jack Jansena9e3db32001-01-09 22:10:16 +00001883static PyObject *CtlObj_SetControlData_Callback(_self, _args)
Jack Jansenabc411b2000-03-20 16:09:09 +00001884 ControlObject *_self;
1885 PyObject *_args;
1886{
1887 PyObject *_res = NULL;
1888
1889 OSErr _err;
1890 ControlPartCode inPart;
1891 ResType inTagName;
1892 PyObject *callback;
Jack Jansen85152b92000-07-11 21:12:55 +00001893 UniversalProcPtr c_callback;
Jack Jansenabc411b2000-03-20 16:09:09 +00001894
1895 if (!PyArg_ParseTuple(_args, "hO&O",
1896 &inPart,
1897 PyMac_GetOSType, &inTagName,
1898 &callback))
1899 return NULL;
1900
Jack Jansen85152b92000-07-11 21:12:55 +00001901 if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 )
Jack Jansenabc411b2000-03-20 16:09:09 +00001902 return NULL;
1903 _err = SetControlData(_self->ob_itself,
1904 inPart,
1905 inTagName,
1906 sizeof(c_callback),
1907 (Ptr)&c_callback);
1908
1909 if (_err != noErr)
1910 return PyMac_Error(_err);
1911 _res = Py_None;
1912 return _res;
1913
1914}
Jack Jansene79dc762000-06-02 21:35:07 +00001915
Jack Jansen736b51d2001-01-12 23:39:00 +00001916#if !TARGET_API_MAC_CARBON
Jack Jansenabc411b2000-03-20 16:09:09 +00001917
Jack Jansen4c704131998-06-19 13:35:14 +00001918static PyObject *CtlObj_GetPopupData(_self, _args)
1919 ControlObject *_self;
1920 PyObject *_args;
1921{
1922 PyObject *_res = NULL;
1923
1924 PopupPrivateDataHandle hdl;
1925
1926 if ( (*_self->ob_itself)->contrlData == NULL ) {
1927 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1928 return 0;
1929 }
1930 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1931 HLock((Handle)hdl);
1932 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1933 HUnlock((Handle)hdl);
1934 return _res;
1935
1936}
Jack Jansene79dc762000-06-02 21:35:07 +00001937#endif
1938
Jack Jansen736b51d2001-01-12 23:39:00 +00001939#if !TARGET_API_MAC_CARBON
Jack Jansen4c704131998-06-19 13:35:14 +00001940
1941static PyObject *CtlObj_SetPopupData(_self, _args)
1942 ControlObject *_self;
1943 PyObject *_args;
1944{
1945 PyObject *_res = NULL;
1946
1947 PopupPrivateDataHandle hdl;
1948 MenuHandle mHandle;
1949 short mID;
1950
1951 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1952 return 0;
1953 if ( (*_self->ob_itself)->contrlData == NULL ) {
1954 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1955 return 0;
1956 }
1957 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1958 (*hdl)->mHandle = mHandle;
1959 (*hdl)->mID = mID;
1960 Py_INCREF(Py_None);
1961 return Py_None;
1962
1963}
Jack Jansene79dc762000-06-02 21:35:07 +00001964#endif
Jack Jansen4c704131998-06-19 13:35:14 +00001965
Guido van Rossum17448e21995-01-30 11:53:55 +00001966static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001967 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1968 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001969 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1970 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001971 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1972 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001973 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1974 "() -> (Boolean _rv)"},
1975 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1976 "() -> (Boolean _rv)"},
1977 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1978 "() -> None"},
1979 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1980 "() -> None"},
1981 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1982 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001983 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1984 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001985 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1986 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1987 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1988 "(ControlFontStyleRec inStyle) -> None"},
1989 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1990 "() -> None"},
1991 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1992 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001993 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1994 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001995 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001996 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001997 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001998 "(Point testPoint) -> (ControlPartCode _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001999
2000#if TARGET_API_MAC_CARBON
2001 {"HandleControlContextualMenuClick", (PyCFunction)CtlObj_HandleControlContextualMenuClick, 1,
2002 "(Point inWhere) -> (Boolean menuDisplayed)"},
2003#endif
2004
2005#if TARGET_API_MAC_CARBON
2006 {"GetControlClickActivation", (PyCFunction)CtlObj_GetControlClickActivation, 1,
2007 "(Point inWhere, EventModifiers inModifiers) -> (ClickActivationResult outResult)"},
2008#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002009 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002010 "(SInt16 inKeyCode, SInt16 inCharCode, EventModifiers inModifiers) -> (SInt16 _rv)"},
2011
2012#if TARGET_API_MAC_CARBON
2013 {"HandleControlSetCursor", (PyCFunction)CtlObj_HandleControlSetCursor, 1,
2014 "(Point localPoint, EventModifiers modifiers) -> (Boolean cursorWasSet)"},
2015#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00002016 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002017 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002018 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002019 "(SInt16 w, SInt16 h) -> None"},
2020 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
2021 "(Str255 title) -> None"},
2022 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00002023 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00002024 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002025 "() -> (SInt16 _rv)"},
2026 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
2027 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00002028 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002029 "() -> (SInt16 _rv)"},
2030 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
2031 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00002032 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002033 "() -> (SInt16 _rv)"},
2034 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
2035 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00002036 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
2037 "() -> (SInt32 _rv)"},
2038 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
2039 "(SInt32 newViewSize) -> None"},
2040 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
2041 "() -> (SInt32 _rv)"},
2042 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
2043 "(SInt32 newValue) -> None"},
2044 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
2045 "() -> (SInt32 _rv)"},
2046 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
2047 "(SInt32 newMaximum) -> None"},
2048 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
2049 "() -> (SInt32 _rv)"},
2050 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
2051 "(SInt32 newMinimum) -> None"},
2052 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
2053 "() -> (Boolean _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002054
2055#if TARGET_API_MAC_CARBON
2056 {"SetControlID", (PyCFunction)CtlObj_SetControlID, 1,
2057 "(ControlID inID) -> None"},
2058#endif
2059
2060#if TARGET_API_MAC_CARBON
2061 {"GetControlID", (PyCFunction)CtlObj_GetControlID, 1,
2062 "() -> (ControlID outID)"},
2063#endif
Jack Jansena05ac601999-12-12 21:41:51 +00002064 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00002065 "(OSType propertyCreator, OSType propertyTag) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002066
2067#if TARGET_API_MAC_CARBON
2068 {"GetControlPropertyAttributes", (PyCFunction)CtlObj_GetControlPropertyAttributes, 1,
2069 "(OSType propertyCreator, OSType propertyTag) -> (UInt32 attributes)"},
2070#endif
2071
2072#if TARGET_API_MAC_CARBON
2073 {"ChangeControlPropertyAttributes", (PyCFunction)CtlObj_ChangeControlPropertyAttributes, 1,
2074 "(OSType propertyCreator, OSType propertyTag, UInt32 attributesToSet, UInt32 attributesToClear) -> None"},
2075#endif
Jack Jansena05ac601999-12-12 21:41:51 +00002076 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00002077 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00002078 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002079 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00002080 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
2081 "(SInt32 data) -> None"},
2082 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
2083 "() -> (SInt32 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +00002084
Jack Jansen74a1e632000-07-14 22:37:27 +00002085#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00002086 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
2087 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
Jack Jansene79dc762000-06-02 21:35:07 +00002088#endif
2089
Jack Jansen74a1e632000-07-14 22:37:27 +00002090#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00002091 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
2092 "(CCTabHandle newColorTable) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00002093#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002094 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
2095 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
2096 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
2097 "(ControlHandle inContainer) -> None"},
2098 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
2099 "(WindowPtr inWindow) -> None"},
2100 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
2101 "() -> (ControlHandle outParent)"},
2102 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002103 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00002104 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002105 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00002106 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
2107 "(ControlHandle inBoss) -> None"},
2108 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
2109 "() -> (UInt32 outFeatures)"},
2110 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
2111 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002112
2113#if TARGET_API_MAC_CARBON
Jack Jansen723ad8a2000-12-12 22:10:21 +00002114 {"HandleControlDragTracking", (PyCFunction)CtlObj_HandleControlDragTracking, 1,
2115 "(DragTrackingMessage inMessage, DragReference inDrag) -> (Boolean outLikesDrag)"},
2116#endif
2117
2118#if TARGET_API_MAC_CARBON
2119 {"HandleControlDragReceive", (PyCFunction)CtlObj_HandleControlDragReceive, 1,
2120 "(DragReference inDrag) -> None"},
2121#endif
2122
2123#if TARGET_API_MAC_CARBON
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002124 {"SetControlDragTrackingEnabled", (PyCFunction)CtlObj_SetControlDragTrackingEnabled, 1,
2125 "(Boolean tracks) -> None"},
2126#endif
2127
2128#if TARGET_API_MAC_CARBON
2129 {"IsControlDragTrackingEnabled", (PyCFunction)CtlObj_IsControlDragTrackingEnabled, 1,
2130 "() -> (Boolean tracks)"},
2131#endif
2132
2133#if ACCESSOR_CALLS_ARE_FUNCTIONS
2134 {"GetControlBounds", (PyCFunction)CtlObj_GetControlBounds, 1,
Jack Jansena9e3db32001-01-09 22:10:16 +00002135 "() -> (Rect bounds)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002136#endif
2137
2138#if ACCESSOR_CALLS_ARE_FUNCTIONS
2139 {"IsControlHilited", (PyCFunction)CtlObj_IsControlHilited, 1,
2140 "() -> (Boolean _rv)"},
2141#endif
2142
2143#if ACCESSOR_CALLS_ARE_FUNCTIONS
2144 {"GetControlHilite", (PyCFunction)CtlObj_GetControlHilite, 1,
2145 "() -> (UInt16 _rv)"},
2146#endif
2147
2148#if ACCESSOR_CALLS_ARE_FUNCTIONS
2149 {"GetControlOwner", (PyCFunction)CtlObj_GetControlOwner, 1,
2150 "() -> (WindowPtr _rv)"},
2151#endif
2152
2153#if ACCESSOR_CALLS_ARE_FUNCTIONS
2154 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
2155 "() -> (Handle _rv)"},
2156#endif
2157
2158#if ACCESSOR_CALLS_ARE_FUNCTIONS
2159 {"GetControlPopupMenuHandle", (PyCFunction)CtlObj_GetControlPopupMenuHandle, 1,
2160 "() -> (MenuHandle _rv)"},
2161#endif
2162
2163#if ACCESSOR_CALLS_ARE_FUNCTIONS
2164 {"GetControlPopupMenuID", (PyCFunction)CtlObj_GetControlPopupMenuID, 1,
2165 "() -> (short _rv)"},
2166#endif
2167
2168#if ACCESSOR_CALLS_ARE_FUNCTIONS
2169 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
2170 "(Handle dataHandle) -> None"},
2171#endif
2172
2173#if ACCESSOR_CALLS_ARE_FUNCTIONS
2174 {"SetControlBounds", (PyCFunction)CtlObj_SetControlBounds, 1,
2175 "(Rect bounds) -> None"},
2176#endif
2177
2178#if ACCESSOR_CALLS_ARE_FUNCTIONS
2179 {"SetControlPopupMenuHandle", (PyCFunction)CtlObj_SetControlPopupMenuHandle, 1,
2180 "(MenuHandle popupMenu) -> None"},
2181#endif
2182
2183#if ACCESSOR_CALLS_ARE_FUNCTIONS
2184 {"SetControlPopupMenuID", (PyCFunction)CtlObj_SetControlPopupMenuID, 1,
2185 "(short menuID) -> None"},
2186#endif
2187 {"GetBevelButtonMenuValue", (PyCFunction)CtlObj_GetBevelButtonMenuValue, 1,
2188 "() -> (SInt16 outValue)"},
2189 {"SetBevelButtonMenuValue", (PyCFunction)CtlObj_SetBevelButtonMenuValue, 1,
2190 "(SInt16 inValue) -> None"},
2191 {"GetBevelButtonMenuHandle", (PyCFunction)CtlObj_GetBevelButtonMenuHandle, 1,
2192 "() -> (MenuHandle outHandle)"},
2193 {"SetBevelButtonTransform", (PyCFunction)CtlObj_SetBevelButtonTransform, 1,
2194 "(IconTransformType transform) -> None"},
2195 {"SetDisclosureTriangleLastValue", (PyCFunction)CtlObj_SetDisclosureTriangleLastValue, 1,
2196 "(SInt16 inValue) -> None"},
2197 {"GetTabContentRect", (PyCFunction)CtlObj_GetTabContentRect, 1,
2198 "() -> (Rect outContentRect)"},
2199 {"SetTabEnabled", (PyCFunction)CtlObj_SetTabEnabled, 1,
2200 "(SInt16 inTabToHilite, Boolean inEnabled) -> None"},
2201 {"SetImageWellTransform", (PyCFunction)CtlObj_SetImageWellTransform, 1,
2202 "(IconTransformType inTransform) -> None"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00002203 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00002204 "() -> (Handle _rv)"},
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002205 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
2206 "() -> (Rect rect)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00002207 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
2208 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00002209 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002210 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
2211 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
2212 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
2213 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
2214 "(stuff) -> None"},
2215 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
2216 "(part, type) -> String"},
Jack Jansena9e3db32001-01-09 22:10:16 +00002217 {"SetControlData_Handle", (PyCFunction)CtlObj_SetControlData_Handle, 1,
Jack Jansen1f9249c1999-12-19 00:05:50 +00002218 "(ResObj) -> None"},
Jack Jansena9e3db32001-01-09 22:10:16 +00002219 {"GetControlData_Handle", (PyCFunction)CtlObj_GetControlData_Handle, 1,
Jack Jansen1f9249c1999-12-19 00:05:50 +00002220 "(part, type) -> ResObj"},
Jack Jansena9e3db32001-01-09 22:10:16 +00002221 {"SetControlData_Callback", (PyCFunction)CtlObj_SetControlData_Callback, 1,
Jack Jansenabc411b2000-03-20 16:09:09 +00002222 "(callbackfunc) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00002223
Jack Jansen736b51d2001-01-12 23:39:00 +00002224#if !TARGET_API_MAC_CARBON
Jack Jansen4c704131998-06-19 13:35:14 +00002225 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
2226 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00002227#endif
2228
Jack Jansen736b51d2001-01-12 23:39:00 +00002229#if !TARGET_API_MAC_CARBON
Jack Jansen4c704131998-06-19 13:35:14 +00002230 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
2231 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00002232#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00002233 {NULL, NULL, 0}
2234};
2235
2236PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
2237
2238static PyObject *CtlObj_getattr(self, name)
2239 ControlObject *self;
2240 char *name;
2241{
2242 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
2243}
2244
2245#define CtlObj_setattr NULL
2246
Jack Jansen8387af61999-03-13 23:07:32 +00002247static int CtlObj_compare(self, other)
2248 ControlObject *self, *other;
2249{
2250 unsigned long v, w;
2251
2252 if (!CtlObj_Check((PyObject *)other))
2253 {
2254 v=(unsigned long)self;
2255 w=(unsigned long)other;
2256 }
2257 else
2258 {
2259 v=(unsigned long)self->ob_itself;
2260 w=(unsigned long)other->ob_itself;
2261 }
2262 if( v < w ) return -1;
2263 if( v > w ) return 1;
2264 return 0;
2265}
2266
2267#define CtlObj_repr NULL
2268
2269static long CtlObj_hash(self)
2270 ControlObject *self;
2271{
2272 return (long)self->ob_itself;
2273}
2274
Guido van Rossum17448e21995-01-30 11:53:55 +00002275PyTypeObject Control_Type = {
2276 PyObject_HEAD_INIT(&PyType_Type)
2277 0, /*ob_size*/
2278 "Control", /*tp_name*/
2279 sizeof(ControlObject), /*tp_basicsize*/
2280 0, /*tp_itemsize*/
2281 /* methods */
2282 (destructor) CtlObj_dealloc, /*tp_dealloc*/
2283 0, /*tp_print*/
2284 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
2285 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00002286 (cmpfunc) CtlObj_compare, /*tp_compare*/
2287 (reprfunc) CtlObj_repr, /*tp_repr*/
2288 (PyNumberMethods *)0, /* tp_as_number */
2289 (PySequenceMethods *)0, /* tp_as_sequence */
2290 (PyMappingMethods *)0, /* tp_as_mapping */
2291 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00002292};
2293
2294/* -------------------- End object type Control --------------------- */
2295
2296
2297static PyObject *Ctl_NewControl(_self, _args)
2298 PyObject *_self;
2299 PyObject *_args;
2300{
2301 PyObject *_res = NULL;
2302 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002303 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00002304 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00002305 Str255 controlTitle;
2306 Boolean initiallyVisible;
2307 SInt16 initialValue;
2308 SInt16 minimumValue;
2309 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00002310 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00002311 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00002312 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00002313 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00002314 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00002315 PyMac_GetStr255, controlTitle,
2316 &initiallyVisible,
2317 &initialValue,
2318 &minimumValue,
2319 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00002320 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00002321 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00002322 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002323 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00002324 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00002325 controlTitle,
2326 initiallyVisible,
2327 initialValue,
2328 minimumValue,
2329 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00002330 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00002331 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00002332 _res = Py_BuildValue("O&",
2333 CtlObj_New, _rv);
2334 return _res;
2335}
2336
2337static PyObject *Ctl_GetNewControl(_self, _args)
2338 PyObject *_self;
2339 PyObject *_args;
2340{
2341 PyObject *_res = NULL;
2342 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002343 SInt16 resourceID;
2344 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00002345 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00002346 &resourceID,
2347 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00002348 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002349 _rv = GetNewControl(resourceID,
2350 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00002351 _res = Py_BuildValue("O&",
2352 CtlObj_New, _rv);
2353 return _res;
2354}
2355
Guido van Rossum17448e21995-01-30 11:53:55 +00002356static PyObject *Ctl_DrawControls(_self, _args)
2357 PyObject *_self;
2358 PyObject *_args;
2359{
2360 PyObject *_res = NULL;
2361 WindowPtr theWindow;
2362 if (!PyArg_ParseTuple(_args, "O&",
2363 WinObj_Convert, &theWindow))
2364 return NULL;
2365 DrawControls(theWindow);
2366 Py_INCREF(Py_None);
2367 _res = Py_None;
2368 return _res;
2369}
2370
Guido van Rossum17448e21995-01-30 11:53:55 +00002371static PyObject *Ctl_UpdateControls(_self, _args)
2372 PyObject *_self;
2373 PyObject *_args;
2374{
2375 PyObject *_res = NULL;
2376 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00002377 RgnHandle updateRegion;
2378 if (!PyArg_ParseTuple(_args, "O&O&",
2379 WinObj_Convert, &theWindow,
2380 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00002381 return NULL;
2382 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00002383 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00002384 Py_INCREF(Py_None);
2385 _res = Py_None;
2386 return _res;
2387}
2388
2389static PyObject *Ctl_FindControl(_self, _args)
2390 PyObject *_self;
2391 PyObject *_args;
2392{
2393 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00002394 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002395 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00002396 WindowPtr theWindow;
2397 ControlHandle theControl;
2398 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00002399 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00002400 WinObj_Convert, &theWindow))
2401 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002402 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00002403 theWindow,
2404 &theControl);
2405 _res = Py_BuildValue("hO&",
2406 _rv,
2407 CtlObj_WhichControl, theControl);
2408 return _res;
2409}
2410
Jack Jansen21f96871998-02-20 16:02:09 +00002411static PyObject *Ctl_FindControlUnderMouse(_self, _args)
2412 PyObject *_self;
2413 PyObject *_args;
2414{
2415 PyObject *_res = NULL;
2416 ControlHandle _rv;
2417 Point inWhere;
2418 WindowPtr inWindow;
2419 SInt16 outPart;
2420 if (!PyArg_ParseTuple(_args, "O&O&",
2421 PyMac_GetPoint, &inWhere,
2422 WinObj_Convert, &inWindow))
2423 return NULL;
2424 _rv = FindControlUnderMouse(inWhere,
2425 inWindow,
2426 &outPart);
2427 _res = Py_BuildValue("O&h",
2428 CtlObj_New, _rv,
2429 outPart);
2430 return _res;
2431}
2432
2433static PyObject *Ctl_IdleControls(_self, _args)
2434 PyObject *_self;
2435 PyObject *_args;
2436{
2437 PyObject *_res = NULL;
2438 WindowPtr inWindow;
2439 if (!PyArg_ParseTuple(_args, "O&",
2440 WinObj_Convert, &inWindow))
2441 return NULL;
2442 IdleControls(inWindow);
2443 Py_INCREF(Py_None);
2444 _res = Py_None;
2445 return _res;
2446}
2447
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002448#if TARGET_API_MAC_CARBON
2449
2450static PyObject *Ctl_GetControlByID(_self, _args)
2451 PyObject *_self;
2452 PyObject *_args;
2453{
2454 PyObject *_res = NULL;
2455 OSStatus _err;
2456 WindowPtr inWindow;
2457 ControlID inID;
2458 ControlHandle outControl;
2459 if (!PyArg_ParseTuple(_args, "O&O&",
2460 WinObj_Convert, &inWindow,
2461 PyControlID_Convert, &inID))
2462 return NULL;
2463 _err = GetControlByID(inWindow,
2464 &inID,
2465 &outControl);
2466 if (_err != noErr) return PyMac_Error(_err);
2467 _res = Py_BuildValue("O&",
2468 CtlObj_WhichControl, outControl);
2469 return _res;
2470}
2471#endif
2472
Jack Jansen21f96871998-02-20 16:02:09 +00002473static PyObject *Ctl_DumpControlHierarchy(_self, _args)
2474 PyObject *_self;
2475 PyObject *_args;
2476{
2477 PyObject *_res = NULL;
2478 OSErr _err;
2479 WindowPtr inWindow;
2480 FSSpec inDumpFile;
2481 if (!PyArg_ParseTuple(_args, "O&O&",
2482 WinObj_Convert, &inWindow,
2483 PyMac_GetFSSpec, &inDumpFile))
2484 return NULL;
2485 _err = DumpControlHierarchy(inWindow,
2486 &inDumpFile);
2487 if (_err != noErr) return PyMac_Error(_err);
2488 Py_INCREF(Py_None);
2489 _res = Py_None;
2490 return _res;
2491}
2492
2493static PyObject *Ctl_CreateRootControl(_self, _args)
2494 PyObject *_self;
2495 PyObject *_args;
2496{
2497 PyObject *_res = NULL;
2498 OSErr _err;
2499 WindowPtr inWindow;
2500 ControlHandle outControl;
2501 if (!PyArg_ParseTuple(_args, "O&",
2502 WinObj_Convert, &inWindow))
2503 return NULL;
2504 _err = CreateRootControl(inWindow,
2505 &outControl);
2506 if (_err != noErr) return PyMac_Error(_err);
2507 _res = Py_BuildValue("O&",
2508 CtlObj_WhichControl, outControl);
2509 return _res;
2510}
2511
2512static PyObject *Ctl_GetRootControl(_self, _args)
2513 PyObject *_self;
2514 PyObject *_args;
2515{
2516 PyObject *_res = NULL;
2517 OSErr _err;
2518 WindowPtr inWindow;
2519 ControlHandle outControl;
2520 if (!PyArg_ParseTuple(_args, "O&",
2521 WinObj_Convert, &inWindow))
2522 return NULL;
2523 _err = GetRootControl(inWindow,
2524 &outControl);
2525 if (_err != noErr) return PyMac_Error(_err);
2526 _res = Py_BuildValue("O&",
2527 CtlObj_WhichControl, outControl);
2528 return _res;
2529}
2530
2531static PyObject *Ctl_GetKeyboardFocus(_self, _args)
2532 PyObject *_self;
2533 PyObject *_args;
2534{
2535 PyObject *_res = NULL;
2536 OSErr _err;
2537 WindowPtr inWindow;
2538 ControlHandle outControl;
2539 if (!PyArg_ParseTuple(_args, "O&",
2540 WinObj_Convert, &inWindow))
2541 return NULL;
2542 _err = GetKeyboardFocus(inWindow,
2543 &outControl);
2544 if (_err != noErr) return PyMac_Error(_err);
2545 _res = Py_BuildValue("O&",
2546 CtlObj_WhichControl, outControl);
2547 return _res;
2548}
2549
2550static PyObject *Ctl_SetKeyboardFocus(_self, _args)
2551 PyObject *_self;
2552 PyObject *_args;
2553{
2554 PyObject *_res = NULL;
2555 OSErr _err;
2556 WindowPtr inWindow;
2557 ControlHandle inControl;
2558 ControlFocusPart inPart;
2559 if (!PyArg_ParseTuple(_args, "O&O&h",
2560 WinObj_Convert, &inWindow,
2561 CtlObj_Convert, &inControl,
2562 &inPart))
2563 return NULL;
2564 _err = SetKeyboardFocus(inWindow,
2565 inControl,
2566 inPart);
2567 if (_err != noErr) return PyMac_Error(_err);
2568 Py_INCREF(Py_None);
2569 _res = Py_None;
2570 return _res;
2571}
2572
2573static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
2574 PyObject *_self;
2575 PyObject *_args;
2576{
2577 PyObject *_res = NULL;
2578 OSErr _err;
2579 WindowPtr inWindow;
2580 if (!PyArg_ParseTuple(_args, "O&",
2581 WinObj_Convert, &inWindow))
2582 return NULL;
2583 _err = AdvanceKeyboardFocus(inWindow);
2584 if (_err != noErr) return PyMac_Error(_err);
2585 Py_INCREF(Py_None);
2586 _res = Py_None;
2587 return _res;
2588}
2589
2590static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
2591 PyObject *_self;
2592 PyObject *_args;
2593{
2594 PyObject *_res = NULL;
2595 OSErr _err;
2596 WindowPtr inWindow;
2597 if (!PyArg_ParseTuple(_args, "O&",
2598 WinObj_Convert, &inWindow))
2599 return NULL;
2600 _err = ReverseKeyboardFocus(inWindow);
2601 if (_err != noErr) return PyMac_Error(_err);
2602 Py_INCREF(Py_None);
2603 _res = Py_None;
2604 return _res;
2605}
2606
2607static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
2608 PyObject *_self;
2609 PyObject *_args;
2610{
2611 PyObject *_res = NULL;
2612 OSErr _err;
2613 WindowPtr inWindow;
2614 if (!PyArg_ParseTuple(_args, "O&",
2615 WinObj_Convert, &inWindow))
2616 return NULL;
2617 _err = ClearKeyboardFocus(inWindow);
2618 if (_err != noErr) return PyMac_Error(_err);
2619 Py_INCREF(Py_None);
2620 _res = Py_None;
2621 return _res;
2622}
2623
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002624#if TARGET_API_MAC_CARBON
2625
2626static PyObject *Ctl_SetAutomaticControlDragTrackingEnabledForWindow(_self, _args)
2627 PyObject *_self;
2628 PyObject *_args;
2629{
2630 PyObject *_res = NULL;
2631 OSStatus _err;
2632 WindowPtr theWindow;
2633 Boolean tracks;
2634 if (!PyArg_ParseTuple(_args, "O&b",
2635 WinObj_Convert, &theWindow,
2636 &tracks))
2637 return NULL;
2638 _err = SetAutomaticControlDragTrackingEnabledForWindow(theWindow,
2639 tracks);
2640 if (_err != noErr) return PyMac_Error(_err);
2641 Py_INCREF(Py_None);
2642 _res = Py_None;
2643 return _res;
2644}
2645#endif
2646
2647#if TARGET_API_MAC_CARBON
2648
2649static PyObject *Ctl_IsAutomaticControlDragTrackingEnabledForWindow(_self, _args)
2650 PyObject *_self;
2651 PyObject *_args;
2652{
2653 PyObject *_res = NULL;
2654 OSStatus _err;
2655 WindowPtr theWindow;
2656 Boolean tracks;
2657 if (!PyArg_ParseTuple(_args, "O&",
2658 WinObj_Convert, &theWindow))
2659 return NULL;
2660 _err = IsAutomaticControlDragTrackingEnabledForWindow(theWindow,
2661 &tracks);
2662 if (_err != noErr) return PyMac_Error(_err);
2663 _res = Py_BuildValue("b",
2664 tracks);
2665 return _res;
2666}
2667#endif
2668
Jack Jansene0581891999-02-07 14:02:03 +00002669static PyObject *Ctl_as_Control(_self, _args)
2670 PyObject *_self;
2671 PyObject *_args;
2672{
2673 PyObject *_res = NULL;
2674 ControlHandle _rv;
2675 Handle h;
2676 if (!PyArg_ParseTuple(_args, "O&",
2677 ResObj_Convert, &h))
2678 return NULL;
2679 _rv = as_Control(h);
2680 _res = Py_BuildValue("O&",
2681 CtlObj_New, _rv);
2682 return _res;
2683}
2684
Guido van Rossum17448e21995-01-30 11:53:55 +00002685static PyMethodDef Ctl_methods[] = {
2686 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002687 "(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 +00002688 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002689 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002690 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
2691 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002692 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00002693 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002694 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002695 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
2696 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
2697 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
2698 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
2699 "(WindowPtr inWindow) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002700
2701#if TARGET_API_MAC_CARBON
2702 {"GetControlByID", (PyCFunction)Ctl_GetControlByID, 1,
2703 "(WindowPtr inWindow, ControlID inID) -> (ControlHandle outControl)"},
2704#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002705 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
2706 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
2707 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
2708 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2709 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
2710 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2711 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
2712 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2713 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
2714 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
2715 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
2716 "(WindowPtr inWindow) -> None"},
2717 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
2718 "(WindowPtr inWindow) -> None"},
2719 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
2720 "(WindowPtr inWindow) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002721
2722#if TARGET_API_MAC_CARBON
2723 {"SetAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_SetAutomaticControlDragTrackingEnabledForWindow, 1,
2724 "(WindowPtr theWindow, Boolean tracks) -> None"},
2725#endif
2726
2727#if TARGET_API_MAC_CARBON
2728 {"IsAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_IsAutomaticControlDragTrackingEnabledForWindow, 1,
2729 "(WindowPtr theWindow) -> (Boolean tracks)"},
2730#endif
Jack Jansene0581891999-02-07 14:02:03 +00002731 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
2732 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002733 {NULL, NULL, 0}
2734};
2735
2736
2737
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002738static PyObject *
2739CtlObj_NewUnmanaged(itself)
Jack Jansen8387af61999-03-13 23:07:32 +00002740 ControlHandle itself;
2741{
2742 ControlObject *it;
2743 if (itself == NULL) return PyMac_Error(resNotFound);
2744 it = PyObject_NEW(ControlObject, &Control_Type);
2745 if (it == NULL) return NULL;
2746 it->ob_itself = itself;
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002747 it->ob_callbackdict = NULL;
Jack Jansen8387af61999-03-13 23:07:32 +00002748 return (PyObject *)it;
2749}
2750
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002751static PyObject *
Guido van Rossum17448e21995-01-30 11:53:55 +00002752CtlObj_WhichControl(ControlHandle c)
2753{
2754 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00002755
Guido van Rossum17448e21995-01-30 11:53:55 +00002756 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00002757 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00002758 else {
2759 it = (PyObject *) GetControlReference(c);
2760 /*
2761 ** If the refcon is zero or doesn't point back to the Python object
2762 ** the control is not ours. Return a temporary object.
2763 */
2764 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
2765 return CtlObj_NewUnmanaged(c);
2766 }
Guido van Rossum17448e21995-01-30 11:53:55 +00002767 Py_INCREF(it);
2768 return it;
2769}
2770
Jack Jansen848250c1998-05-28 14:20:09 +00002771static int
2772settrackfunc(obj)
2773 PyObject *obj;
2774{
2775 if (tracker) {
2776 PyErr_SetString(Ctl_Error, "Tracker function in use");
2777 return 0;
2778 }
2779 tracker = obj;
2780 Py_INCREF(tracker);
2781}
2782
2783static void
2784clrtrackfunc()
2785{
2786 Py_XDECREF(tracker);
2787 tracker = 0;
2788}
2789
2790static pascal void
Jack Jansene79dc762000-06-02 21:35:07 +00002791mytracker(ControlHandle ctl, short part)
Jack Jansen848250c1998-05-28 14:20:09 +00002792{
2793 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00002794
Jack Jansen848250c1998-05-28 14:20:09 +00002795 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
2796 if (args && tracker) {
2797 rv = PyEval_CallObject(tracker, args);
2798 Py_DECREF(args);
2799 }
2800 if (rv)
2801 Py_DECREF(rv);
2802 else
Jack Jansen24c35311999-12-09 22:49:51 +00002803 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00002804}
2805
Jack Jansenabc411b2000-03-20 16:09:09 +00002806static int
Jack Jansen85152b92000-07-11 21:12:55 +00002807setcallback(myself, which, callback, uppp)
2808 PyObject *myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002809 OSType which;
2810 PyObject *callback;
2811 UniversalProcPtr *uppp;
2812{
Jack Jansen85152b92000-07-11 21:12:55 +00002813 ControlObject *self = (ControlObject *)myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002814 char keybuf[9];
2815
2816 if ( which == kControlUserPaneDrawProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002817 *uppp = (UniversalProcPtr)mydrawproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002818 else if ( which == kControlUserPaneIdleProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002819 *uppp = (UniversalProcPtr)myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002820 else if ( which == kControlUserPaneHitTestProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002821 *uppp = (UniversalProcPtr)myhittestproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002822 else if ( which == kControlUserPaneTrackingProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002823 *uppp = (UniversalProcPtr)mytrackingproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002824 else
2825 return -1;
2826 /* Only now do we test for clearing of the callback: */
2827 if ( callback == Py_None )
2828 *uppp = NULL;
2829 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
2830 if ( self->ob_callbackdict == NULL )
2831 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
2832 return -1;
2833 /* And store the Python callback */
2834 sprintf(keybuf, "%x", which);
2835 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
2836 return -1;
2837 return 0;
2838}
2839
2840static PyObject *
2841callcallback(self, which, arglist)
2842 ControlObject *self;
2843 OSType which;
2844 PyObject *arglist;
2845{
2846 char keybuf[9];
2847 PyObject *func, *rv;
2848
2849 sprintf(keybuf, "%x", which);
2850 if ( self->ob_callbackdict == NULL ||
2851 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
Jack Jansena27e9fb2000-03-21 23:03:02 +00002852 PySys_WriteStderr("Control callback %x without callback object\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002853 return NULL;
2854 }
2855 rv = PyEval_CallObject(func, arglist);
2856 if ( rv == NULL )
Jack Jansena27e9fb2000-03-21 23:03:02 +00002857 PySys_WriteStderr("Exception in control callback %x handler\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002858 return rv;
2859}
2860
2861static pascal void
2862mydrawproc(ControlHandle control, SInt16 part)
2863{
2864 ControlObject *ctl_obj;
2865 PyObject *arglist, *rv;
2866
2867 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2868 arglist = Py_BuildValue("Oh", ctl_obj, part);
2869 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2870 Py_XDECREF(arglist);
2871 Py_XDECREF(rv);
2872}
2873
2874static pascal void
2875myidleproc(ControlHandle control)
2876{
2877 ControlObject *ctl_obj;
2878 PyObject *arglist, *rv;
2879
2880 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2881 arglist = Py_BuildValue("O", ctl_obj);
2882 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2883 Py_XDECREF(arglist);
2884 Py_XDECREF(rv);
2885}
2886
Jack Jansena27e9fb2000-03-21 23:03:02 +00002887static pascal ControlPartCode
2888myhittestproc(ControlHandle control, Point where)
2889{
2890 ControlObject *ctl_obj;
2891 PyObject *arglist, *rv;
2892 short c_rv = -1;
2893
2894 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
Jack Jansendeb63732000-03-22 15:35:24 +00002895 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002896 rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
2897 Py_XDECREF(arglist);
2898 /* Ignore errors, nothing we can do about them */
2899 if ( rv )
2900 PyArg_Parse(rv, "h", &c_rv);
2901 Py_XDECREF(rv);
2902 return (ControlPartCode)c_rv;
2903}
2904
2905static pascal ControlPartCode
2906mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
2907{
2908 ControlObject *ctl_obj;
2909 PyObject *arglist, *rv;
2910 short c_rv = -1;
2911
2912 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2913 /* We cannot pass the actionProc without lots of work */
Jack Jansendeb63732000-03-22 15:35:24 +00002914 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002915 rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
2916 Py_XDECREF(arglist);
2917 if ( rv )
2918 PyArg_Parse(rv, "h", &c_rv);
2919 Py_XDECREF(rv);
2920 return (ControlPartCode)c_rv;
2921}
Jack Jansenabc411b2000-03-20 16:09:09 +00002922
Guido van Rossum17448e21995-01-30 11:53:55 +00002923
2924void initCtl()
2925{
2926 PyObject *m;
2927 PyObject *d;
2928
2929
2930
Jack Jansen848250c1998-05-28 14:20:09 +00002931 mytracker_upp = NewControlActionProc(mytracker);
Jack Jansenabc411b2000-03-20 16:09:09 +00002932 mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc);
Jack Jansen1b6e8212000-04-05 21:30:57 +00002933 myidleproc_upp = NewControlUserPaneIdleProc(myidleproc);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002934 myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc);
2935 mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc);
Jack Jansen0e04eec2001-05-17 21:58:34 +00002936 PyMac_INIT_TOOLBOX_OBJECT_NEW(CtlObj_New);
2937 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CtlObj_Convert);
Jack Jansen848250c1998-05-28 14:20:09 +00002938
Guido van Rossum17448e21995-01-30 11:53:55 +00002939
2940 m = Py_InitModule("Ctl", Ctl_methods);
2941 d = PyModule_GetDict(m);
2942 Ctl_Error = PyMac_GetOSErrException();
2943 if (Ctl_Error == NULL ||
2944 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002945 return;
Jack Jansena755e681997-09-20 17:40:22 +00002946 Control_Type.ob_type = &PyType_Type;
2947 Py_INCREF(&Control_Type);
2948 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2949 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00002950}
2951
2952/* ========================= End module Ctl ========================= */
2953