py-cvs-2001_07_13 (Rev 1.3) merge
[python/dscho.git] / Mac / Modules / ctl / Ctlmodule.c
blob536da3c3408907a1243a3487208778c313e2cdee
2 /* =========================== Module Ctl =========================== */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #ifdef WITHOUT_FRAMEWORKS
12 #include <Controls.h>
13 #include <ControlDefinitions.h>
14 #else
15 #include <Carbon/Carbon.h>
16 #endif
18 #ifdef USE_TOOLBOX_OBJECT_GLUE
19 extern PyObject *_CtlObj_New(ControlHandle);
20 extern int _CtlObj_Convert(PyObject *, ControlHandle *);
22 #define CtlObj_New _CtlObj_New
23 #define CtlObj_Convert _CtlObj_Convert
24 #endif
26 staticforward PyObject *CtlObj_WhichControl(ControlHandle);
28 #define as_Control(h) ((ControlHandle)h)
29 #define as_Resource(ctl) ((Handle)ctl)
30 #if TARGET_API_MAC_CARBON
31 #define GetControlRect(ctl, rectp) GetControlBounds(ctl, rectp)
32 #else
33 #define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
34 #endif
37 ** Parse/generate ControlFontStyleRec records
39 #if 0 /* Not needed */
40 static PyObject *
41 ControlFontStyle_New(ControlFontStyleRec *itself)
44 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
45 itself->size, itself->style, itself->mode, itself->just,
46 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
48 #endif
50 static int
51 ControlFontStyle_Convert(PyObject *v, ControlFontStyleRec *itself)
53 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
54 &itself->font, &itself->size, &itself->style, &itself->mode,
55 &itself->just, QdRGB_Convert, &itself->foreColor,
56 QdRGB_Convert, &itself->backColor);
60 ** Parse/generate ControlID records
62 static PyObject *
63 PyControlID_New(ControlID *itself)
66 return Py_BuildValue("O&l", PyMac_BuildOSType, itself->signature, itself->id);
69 static int
70 PyControlID_Convert(PyObject *v, ControlID *itself)
72 return PyArg_ParseTuple(v, "O&l", PyMac_GetOSType, &itself->signature, &itself->id);
76 /* TrackControl and HandleControlClick callback support */
77 static PyObject *tracker;
78 static ControlActionUPP mytracker_upp;
79 static ControlUserPaneDrawUPP mydrawproc_upp;
80 static ControlUserPaneIdleUPP myidleproc_upp;
81 static ControlUserPaneHitTestUPP myhittestproc_upp;
82 static ControlUserPaneTrackingUPP mytrackingproc_upp;
84 staticforward int settrackfunc(PyObject *); /* forward */
85 staticforward void clrtrackfunc(void); /* forward */
86 staticforward int setcallback(PyObject *, OSType, PyObject *, UniversalProcPtr *);
88 static PyObject *Ctl_Error;
90 /* ---------------------- Object type Control ----------------------- */
92 PyTypeObject Control_Type;
94 #define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
96 typedef struct ControlObject {
97 PyObject_HEAD
98 ControlHandle ob_itself;
99 PyObject *ob_callbackdict;
100 } ControlObject;
102 PyObject *CtlObj_New(ControlHandle itself)
104 ControlObject *it;
105 if (itself == NULL) return PyMac_Error(resNotFound);
106 it = PyObject_NEW(ControlObject, &Control_Type);
107 if (it == NULL) return NULL;
108 it->ob_itself = itself;
109 SetControlReference(itself, (long)it);
110 it->ob_callbackdict = NULL;
111 return (PyObject *)it;
113 CtlObj_Convert(PyObject *v, ControlHandle *p_itself)
115 if (!CtlObj_Check(v))
117 PyErr_SetString(PyExc_TypeError, "Control required");
118 return 0;
120 *p_itself = ((ControlObject *)v)->ob_itself;
121 return 1;
124 static void CtlObj_dealloc(ControlObject *self)
126 Py_XDECREF(self->ob_callbackdict);
127 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
128 PyMem_DEL(self);
131 static PyObject *CtlObj_HiliteControl(ControlObject *_self, PyObject *_args)
133 PyObject *_res = NULL;
134 ControlPartCode hiliteState;
135 if (!PyArg_ParseTuple(_args, "h",
136 &hiliteState))
137 return NULL;
138 HiliteControl(_self->ob_itself,
139 hiliteState);
140 Py_INCREF(Py_None);
141 _res = Py_None;
142 return _res;
145 static PyObject *CtlObj_ShowControl(ControlObject *_self, PyObject *_args)
147 PyObject *_res = NULL;
148 if (!PyArg_ParseTuple(_args, ""))
149 return NULL;
150 ShowControl(_self->ob_itself);
151 Py_INCREF(Py_None);
152 _res = Py_None;
153 return _res;
156 static PyObject *CtlObj_HideControl(ControlObject *_self, PyObject *_args)
158 PyObject *_res = NULL;
159 if (!PyArg_ParseTuple(_args, ""))
160 return NULL;
161 HideControl(_self->ob_itself);
162 Py_INCREF(Py_None);
163 _res = Py_None;
164 return _res;
167 static PyObject *CtlObj_IsControlActive(ControlObject *_self, PyObject *_args)
169 PyObject *_res = NULL;
170 Boolean _rv;
171 if (!PyArg_ParseTuple(_args, ""))
172 return NULL;
173 _rv = IsControlActive(_self->ob_itself);
174 _res = Py_BuildValue("b",
175 _rv);
176 return _res;
179 static PyObject *CtlObj_IsControlVisible(ControlObject *_self, PyObject *_args)
181 PyObject *_res = NULL;
182 Boolean _rv;
183 if (!PyArg_ParseTuple(_args, ""))
184 return NULL;
185 _rv = IsControlVisible(_self->ob_itself);
186 _res = Py_BuildValue("b",
187 _rv);
188 return _res;
191 static PyObject *CtlObj_ActivateControl(ControlObject *_self, PyObject *_args)
193 PyObject *_res = NULL;
194 OSErr _err;
195 if (!PyArg_ParseTuple(_args, ""))
196 return NULL;
197 _err = ActivateControl(_self->ob_itself);
198 if (_err != noErr) return PyMac_Error(_err);
199 Py_INCREF(Py_None);
200 _res = Py_None;
201 return _res;
204 static PyObject *CtlObj_DeactivateControl(ControlObject *_self, PyObject *_args)
206 PyObject *_res = NULL;
207 OSErr _err;
208 if (!PyArg_ParseTuple(_args, ""))
209 return NULL;
210 _err = DeactivateControl(_self->ob_itself);
211 if (_err != noErr) return PyMac_Error(_err);
212 Py_INCREF(Py_None);
213 _res = Py_None;
214 return _res;
217 static PyObject *CtlObj_SetControlVisibility(ControlObject *_self, PyObject *_args)
219 PyObject *_res = NULL;
220 OSErr _err;
221 Boolean inIsVisible;
222 Boolean inDoDraw;
223 if (!PyArg_ParseTuple(_args, "bb",
224 &inIsVisible,
225 &inDoDraw))
226 return NULL;
227 _err = SetControlVisibility(_self->ob_itself,
228 inIsVisible,
229 inDoDraw);
230 if (_err != noErr) return PyMac_Error(_err);
231 Py_INCREF(Py_None);
232 _res = Py_None;
233 return _res;
236 static PyObject *CtlObj_Draw1Control(ControlObject *_self, PyObject *_args)
238 PyObject *_res = NULL;
239 if (!PyArg_ParseTuple(_args, ""))
240 return NULL;
241 Draw1Control(_self->ob_itself);
242 Py_INCREF(Py_None);
243 _res = Py_None;
244 return _res;
247 static PyObject *CtlObj_GetBestControlRect(ControlObject *_self, PyObject *_args)
249 PyObject *_res = NULL;
250 OSErr _err;
251 Rect outRect;
252 SInt16 outBaseLineOffset;
253 if (!PyArg_ParseTuple(_args, ""))
254 return NULL;
255 _err = GetBestControlRect(_self->ob_itself,
256 &outRect,
257 &outBaseLineOffset);
258 if (_err != noErr) return PyMac_Error(_err);
259 _res = Py_BuildValue("O&h",
260 PyMac_BuildRect, &outRect,
261 outBaseLineOffset);
262 return _res;
265 static PyObject *CtlObj_SetControlFontStyle(ControlObject *_self, PyObject *_args)
267 PyObject *_res = NULL;
268 OSErr _err;
269 ControlFontStyleRec inStyle;
270 if (!PyArg_ParseTuple(_args, "O&",
271 ControlFontStyle_Convert, &inStyle))
272 return NULL;
273 _err = SetControlFontStyle(_self->ob_itself,
274 &inStyle);
275 if (_err != noErr) return PyMac_Error(_err);
276 Py_INCREF(Py_None);
277 _res = Py_None;
278 return _res;
281 static PyObject *CtlObj_DrawControlInCurrentPort(ControlObject *_self, PyObject *_args)
283 PyObject *_res = NULL;
284 if (!PyArg_ParseTuple(_args, ""))
285 return NULL;
286 DrawControlInCurrentPort(_self->ob_itself);
287 Py_INCREF(Py_None);
288 _res = Py_None;
289 return _res;
292 static PyObject *CtlObj_SetUpControlBackground(ControlObject *_self, PyObject *_args)
294 PyObject *_res = NULL;
295 OSErr _err;
296 SInt16 inDepth;
297 Boolean inIsColorDevice;
298 if (!PyArg_ParseTuple(_args, "hb",
299 &inDepth,
300 &inIsColorDevice))
301 return NULL;
302 _err = SetUpControlBackground(_self->ob_itself,
303 inDepth,
304 inIsColorDevice);
305 if (_err != noErr) return PyMac_Error(_err);
306 Py_INCREF(Py_None);
307 _res = Py_None;
308 return _res;
311 static PyObject *CtlObj_SetUpControlTextColor(ControlObject *_self, PyObject *_args)
313 PyObject *_res = NULL;
314 OSErr _err;
315 SInt16 inDepth;
316 Boolean inIsColorDevice;
317 if (!PyArg_ParseTuple(_args, "hb",
318 &inDepth,
319 &inIsColorDevice))
320 return NULL;
321 _err = SetUpControlTextColor(_self->ob_itself,
322 inDepth,
323 inIsColorDevice);
324 if (_err != noErr) return PyMac_Error(_err);
325 Py_INCREF(Py_None);
326 _res = Py_None;
327 return _res;
330 static PyObject *CtlObj_DragControl(ControlObject *_self, PyObject *_args)
332 PyObject *_res = NULL;
333 Point startPoint;
334 Rect limitRect;
335 Rect slopRect;
336 DragConstraint axis;
337 if (!PyArg_ParseTuple(_args, "O&O&O&H",
338 PyMac_GetPoint, &startPoint,
339 PyMac_GetRect, &limitRect,
340 PyMac_GetRect, &slopRect,
341 &axis))
342 return NULL;
343 DragControl(_self->ob_itself,
344 startPoint,
345 &limitRect,
346 &slopRect,
347 axis);
348 Py_INCREF(Py_None);
349 _res = Py_None;
350 return _res;
353 static PyObject *CtlObj_TestControl(ControlObject *_self, PyObject *_args)
355 PyObject *_res = NULL;
356 ControlPartCode _rv;
357 Point testPoint;
358 if (!PyArg_ParseTuple(_args, "O&",
359 PyMac_GetPoint, &testPoint))
360 return NULL;
361 _rv = TestControl(_self->ob_itself,
362 testPoint);
363 _res = Py_BuildValue("h",
364 _rv);
365 return _res;
368 #if TARGET_API_MAC_CARBON
370 static PyObject *CtlObj_HandleControlContextualMenuClick(ControlObject *_self, PyObject *_args)
372 PyObject *_res = NULL;
373 OSStatus _err;
374 Point inWhere;
375 Boolean menuDisplayed;
376 if (!PyArg_ParseTuple(_args, "O&",
377 PyMac_GetPoint, &inWhere))
378 return NULL;
379 _err = HandleControlContextualMenuClick(_self->ob_itself,
380 inWhere,
381 &menuDisplayed);
382 if (_err != noErr) return PyMac_Error(_err);
383 _res = Py_BuildValue("b",
384 menuDisplayed);
385 return _res;
387 #endif
389 #if TARGET_API_MAC_CARBON
391 static PyObject *CtlObj_GetControlClickActivation(ControlObject *_self, PyObject *_args)
393 PyObject *_res = NULL;
394 OSStatus _err;
395 Point inWhere;
396 EventModifiers inModifiers;
397 ClickActivationResult outResult;
398 if (!PyArg_ParseTuple(_args, "O&H",
399 PyMac_GetPoint, &inWhere,
400 &inModifiers))
401 return NULL;
402 _err = GetControlClickActivation(_self->ob_itself,
403 inWhere,
404 inModifiers,
405 &outResult);
406 if (_err != noErr) return PyMac_Error(_err);
407 _res = Py_BuildValue("l",
408 outResult);
409 return _res;
411 #endif
413 static PyObject *CtlObj_HandleControlKey(ControlObject *_self, PyObject *_args)
415 PyObject *_res = NULL;
416 SInt16 _rv;
417 SInt16 inKeyCode;
418 SInt16 inCharCode;
419 EventModifiers inModifiers;
420 if (!PyArg_ParseTuple(_args, "hhH",
421 &inKeyCode,
422 &inCharCode,
423 &inModifiers))
424 return NULL;
425 _rv = HandleControlKey(_self->ob_itself,
426 inKeyCode,
427 inCharCode,
428 inModifiers);
429 _res = Py_BuildValue("h",
430 _rv);
431 return _res;
434 #if TARGET_API_MAC_CARBON
436 static PyObject *CtlObj_HandleControlSetCursor(ControlObject *_self, PyObject *_args)
438 PyObject *_res = NULL;
439 OSStatus _err;
440 Point localPoint;
441 EventModifiers modifiers;
442 Boolean cursorWasSet;
443 if (!PyArg_ParseTuple(_args, "O&H",
444 PyMac_GetPoint, &localPoint,
445 &modifiers))
446 return NULL;
447 _err = HandleControlSetCursor(_self->ob_itself,
448 localPoint,
449 modifiers,
450 &cursorWasSet);
451 if (_err != noErr) return PyMac_Error(_err);
452 _res = Py_BuildValue("b",
453 cursorWasSet);
454 return _res;
456 #endif
458 static PyObject *CtlObj_MoveControl(ControlObject *_self, PyObject *_args)
460 PyObject *_res = NULL;
461 SInt16 h;
462 SInt16 v;
463 if (!PyArg_ParseTuple(_args, "hh",
465 &v))
466 return NULL;
467 MoveControl(_self->ob_itself,
470 Py_INCREF(Py_None);
471 _res = Py_None;
472 return _res;
475 static PyObject *CtlObj_SizeControl(ControlObject *_self, PyObject *_args)
477 PyObject *_res = NULL;
478 SInt16 w;
479 SInt16 h;
480 if (!PyArg_ParseTuple(_args, "hh",
482 &h))
483 return NULL;
484 SizeControl(_self->ob_itself,
487 Py_INCREF(Py_None);
488 _res = Py_None;
489 return _res;
492 static PyObject *CtlObj_SetControlTitle(ControlObject *_self, PyObject *_args)
494 PyObject *_res = NULL;
495 Str255 title;
496 if (!PyArg_ParseTuple(_args, "O&",
497 PyMac_GetStr255, title))
498 return NULL;
499 SetControlTitle(_self->ob_itself,
500 title);
501 Py_INCREF(Py_None);
502 _res = Py_None;
503 return _res;
506 static PyObject *CtlObj_GetControlTitle(ControlObject *_self, PyObject *_args)
508 PyObject *_res = NULL;
509 Str255 title;
510 if (!PyArg_ParseTuple(_args, ""))
511 return NULL;
512 GetControlTitle(_self->ob_itself,
513 title);
514 _res = Py_BuildValue("O&",
515 PyMac_BuildStr255, title);
516 return _res;
519 static PyObject *CtlObj_GetControlValue(ControlObject *_self, PyObject *_args)
521 PyObject *_res = NULL;
522 SInt16 _rv;
523 if (!PyArg_ParseTuple(_args, ""))
524 return NULL;
525 _rv = GetControlValue(_self->ob_itself);
526 _res = Py_BuildValue("h",
527 _rv);
528 return _res;
531 static PyObject *CtlObj_SetControlValue(ControlObject *_self, PyObject *_args)
533 PyObject *_res = NULL;
534 SInt16 newValue;
535 if (!PyArg_ParseTuple(_args, "h",
536 &newValue))
537 return NULL;
538 SetControlValue(_self->ob_itself,
539 newValue);
540 Py_INCREF(Py_None);
541 _res = Py_None;
542 return _res;
545 static PyObject *CtlObj_GetControlMinimum(ControlObject *_self, PyObject *_args)
547 PyObject *_res = NULL;
548 SInt16 _rv;
549 if (!PyArg_ParseTuple(_args, ""))
550 return NULL;
551 _rv = GetControlMinimum(_self->ob_itself);
552 _res = Py_BuildValue("h",
553 _rv);
554 return _res;
557 static PyObject *CtlObj_SetControlMinimum(ControlObject *_self, PyObject *_args)
559 PyObject *_res = NULL;
560 SInt16 newMinimum;
561 if (!PyArg_ParseTuple(_args, "h",
562 &newMinimum))
563 return NULL;
564 SetControlMinimum(_self->ob_itself,
565 newMinimum);
566 Py_INCREF(Py_None);
567 _res = Py_None;
568 return _res;
571 static PyObject *CtlObj_GetControlMaximum(ControlObject *_self, PyObject *_args)
573 PyObject *_res = NULL;
574 SInt16 _rv;
575 if (!PyArg_ParseTuple(_args, ""))
576 return NULL;
577 _rv = GetControlMaximum(_self->ob_itself);
578 _res = Py_BuildValue("h",
579 _rv);
580 return _res;
583 static PyObject *CtlObj_SetControlMaximum(ControlObject *_self, PyObject *_args)
585 PyObject *_res = NULL;
586 SInt16 newMaximum;
587 if (!PyArg_ParseTuple(_args, "h",
588 &newMaximum))
589 return NULL;
590 SetControlMaximum(_self->ob_itself,
591 newMaximum);
592 Py_INCREF(Py_None);
593 _res = Py_None;
594 return _res;
597 static PyObject *CtlObj_GetControlViewSize(ControlObject *_self, PyObject *_args)
599 PyObject *_res = NULL;
600 SInt32 _rv;
601 if (!PyArg_ParseTuple(_args, ""))
602 return NULL;
603 _rv = GetControlViewSize(_self->ob_itself);
604 _res = Py_BuildValue("l",
605 _rv);
606 return _res;
609 static PyObject *CtlObj_SetControlViewSize(ControlObject *_self, PyObject *_args)
611 PyObject *_res = NULL;
612 SInt32 newViewSize;
613 if (!PyArg_ParseTuple(_args, "l",
614 &newViewSize))
615 return NULL;
616 SetControlViewSize(_self->ob_itself,
617 newViewSize);
618 Py_INCREF(Py_None);
619 _res = Py_None;
620 return _res;
623 static PyObject *CtlObj_GetControl32BitValue(ControlObject *_self, PyObject *_args)
625 PyObject *_res = NULL;
626 SInt32 _rv;
627 if (!PyArg_ParseTuple(_args, ""))
628 return NULL;
629 _rv = GetControl32BitValue(_self->ob_itself);
630 _res = Py_BuildValue("l",
631 _rv);
632 return _res;
635 static PyObject *CtlObj_SetControl32BitValue(ControlObject *_self, PyObject *_args)
637 PyObject *_res = NULL;
638 SInt32 newValue;
639 if (!PyArg_ParseTuple(_args, "l",
640 &newValue))
641 return NULL;
642 SetControl32BitValue(_self->ob_itself,
643 newValue);
644 Py_INCREF(Py_None);
645 _res = Py_None;
646 return _res;
649 static PyObject *CtlObj_GetControl32BitMaximum(ControlObject *_self, PyObject *_args)
651 PyObject *_res = NULL;
652 SInt32 _rv;
653 if (!PyArg_ParseTuple(_args, ""))
654 return NULL;
655 _rv = GetControl32BitMaximum(_self->ob_itself);
656 _res = Py_BuildValue("l",
657 _rv);
658 return _res;
661 static PyObject *CtlObj_SetControl32BitMaximum(ControlObject *_self, PyObject *_args)
663 PyObject *_res = NULL;
664 SInt32 newMaximum;
665 if (!PyArg_ParseTuple(_args, "l",
666 &newMaximum))
667 return NULL;
668 SetControl32BitMaximum(_self->ob_itself,
669 newMaximum);
670 Py_INCREF(Py_None);
671 _res = Py_None;
672 return _res;
675 static PyObject *CtlObj_GetControl32BitMinimum(ControlObject *_self, PyObject *_args)
677 PyObject *_res = NULL;
678 SInt32 _rv;
679 if (!PyArg_ParseTuple(_args, ""))
680 return NULL;
681 _rv = GetControl32BitMinimum(_self->ob_itself);
682 _res = Py_BuildValue("l",
683 _rv);
684 return _res;
687 static PyObject *CtlObj_SetControl32BitMinimum(ControlObject *_self, PyObject *_args)
689 PyObject *_res = NULL;
690 SInt32 newMinimum;
691 if (!PyArg_ParseTuple(_args, "l",
692 &newMinimum))
693 return NULL;
694 SetControl32BitMinimum(_self->ob_itself,
695 newMinimum);
696 Py_INCREF(Py_None);
697 _res = Py_None;
698 return _res;
701 static PyObject *CtlObj_IsValidControlHandle(ControlObject *_self, PyObject *_args)
703 PyObject *_res = NULL;
704 Boolean _rv;
705 if (!PyArg_ParseTuple(_args, ""))
706 return NULL;
707 _rv = IsValidControlHandle(_self->ob_itself);
708 _res = Py_BuildValue("b",
709 _rv);
710 return _res;
713 #if TARGET_API_MAC_CARBON
715 static PyObject *CtlObj_SetControlID(ControlObject *_self, PyObject *_args)
717 PyObject *_res = NULL;
718 OSStatus _err;
719 ControlID inID;
720 if (!PyArg_ParseTuple(_args, "O&",
721 PyControlID_Convert, &inID))
722 return NULL;
723 _err = SetControlID(_self->ob_itself,
724 &inID);
725 if (_err != noErr) return PyMac_Error(_err);
726 Py_INCREF(Py_None);
727 _res = Py_None;
728 return _res;
730 #endif
732 #if TARGET_API_MAC_CARBON
734 static PyObject *CtlObj_GetControlID(ControlObject *_self, PyObject *_args)
736 PyObject *_res = NULL;
737 OSStatus _err;
738 ControlID outID;
739 if (!PyArg_ParseTuple(_args, ""))
740 return NULL;
741 _err = GetControlID(_self->ob_itself,
742 &outID);
743 if (_err != noErr) return PyMac_Error(_err);
744 _res = Py_BuildValue("O&",
745 PyControlID_New, &outID);
746 return _res;
748 #endif
750 static PyObject *CtlObj_RemoveControlProperty(ControlObject *_self, PyObject *_args)
752 PyObject *_res = NULL;
753 OSStatus _err;
754 OSType propertyCreator;
755 OSType propertyTag;
756 if (!PyArg_ParseTuple(_args, "O&O&",
757 PyMac_GetOSType, &propertyCreator,
758 PyMac_GetOSType, &propertyTag))
759 return NULL;
760 _err = RemoveControlProperty(_self->ob_itself,
761 propertyCreator,
762 propertyTag);
763 if (_err != noErr) return PyMac_Error(_err);
764 Py_INCREF(Py_None);
765 _res = Py_None;
766 return _res;
769 #if TARGET_API_MAC_CARBON
771 static PyObject *CtlObj_GetControlPropertyAttributes(ControlObject *_self, PyObject *_args)
773 PyObject *_res = NULL;
774 OSStatus _err;
775 OSType propertyCreator;
776 OSType propertyTag;
777 UInt32 attributes;
778 if (!PyArg_ParseTuple(_args, "O&O&",
779 PyMac_GetOSType, &propertyCreator,
780 PyMac_GetOSType, &propertyTag))
781 return NULL;
782 _err = GetControlPropertyAttributes(_self->ob_itself,
783 propertyCreator,
784 propertyTag,
785 &attributes);
786 if (_err != noErr) return PyMac_Error(_err);
787 _res = Py_BuildValue("l",
788 attributes);
789 return _res;
791 #endif
793 #if TARGET_API_MAC_CARBON
795 static PyObject *CtlObj_ChangeControlPropertyAttributes(ControlObject *_self, PyObject *_args)
797 PyObject *_res = NULL;
798 OSStatus _err;
799 OSType propertyCreator;
800 OSType propertyTag;
801 UInt32 attributesToSet;
802 UInt32 attributesToClear;
803 if (!PyArg_ParseTuple(_args, "O&O&ll",
804 PyMac_GetOSType, &propertyCreator,
805 PyMac_GetOSType, &propertyTag,
806 &attributesToSet,
807 &attributesToClear))
808 return NULL;
809 _err = ChangeControlPropertyAttributes(_self->ob_itself,
810 propertyCreator,
811 propertyTag,
812 attributesToSet,
813 attributesToClear);
814 if (_err != noErr) return PyMac_Error(_err);
815 Py_INCREF(Py_None);
816 _res = Py_None;
817 return _res;
819 #endif
821 static PyObject *CtlObj_GetControlRegion(ControlObject *_self, PyObject *_args)
823 PyObject *_res = NULL;
824 OSStatus _err;
825 ControlPartCode inPart;
826 RgnHandle outRegion;
827 if (!PyArg_ParseTuple(_args, "hO&",
828 &inPart,
829 ResObj_Convert, &outRegion))
830 return NULL;
831 _err = GetControlRegion(_self->ob_itself,
832 inPart,
833 outRegion);
834 if (_err != noErr) return PyMac_Error(_err);
835 Py_INCREF(Py_None);
836 _res = Py_None;
837 return _res;
840 static PyObject *CtlObj_GetControlVariant(ControlObject *_self, PyObject *_args)
842 PyObject *_res = NULL;
843 ControlVariant _rv;
844 if (!PyArg_ParseTuple(_args, ""))
845 return NULL;
846 _rv = GetControlVariant(_self->ob_itself);
847 _res = Py_BuildValue("h",
848 _rv);
849 return _res;
852 static PyObject *CtlObj_SetControlReference(ControlObject *_self, PyObject *_args)
854 PyObject *_res = NULL;
855 SInt32 data;
856 if (!PyArg_ParseTuple(_args, "l",
857 &data))
858 return NULL;
859 SetControlReference(_self->ob_itself,
860 data);
861 Py_INCREF(Py_None);
862 _res = Py_None;
863 return _res;
866 static PyObject *CtlObj_GetControlReference(ControlObject *_self, PyObject *_args)
868 PyObject *_res = NULL;
869 SInt32 _rv;
870 if (!PyArg_ParseTuple(_args, ""))
871 return NULL;
872 _rv = GetControlReference(_self->ob_itself);
873 _res = Py_BuildValue("l",
874 _rv);
875 return _res;
878 #if !TARGET_API_MAC_CARBON
880 static PyObject *CtlObj_GetAuxiliaryControlRecord(ControlObject *_self, PyObject *_args)
882 PyObject *_res = NULL;
883 Boolean _rv;
884 AuxCtlHandle acHndl;
885 if (!PyArg_ParseTuple(_args, ""))
886 return NULL;
887 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
888 &acHndl);
889 _res = Py_BuildValue("bO&",
890 _rv,
891 ResObj_New, acHndl);
892 return _res;
894 #endif
896 #if !TARGET_API_MAC_CARBON
898 static PyObject *CtlObj_SetControlColor(ControlObject *_self, PyObject *_args)
900 PyObject *_res = NULL;
901 CCTabHandle newColorTable;
902 if (!PyArg_ParseTuple(_args, "O&",
903 ResObj_Convert, &newColorTable))
904 return NULL;
905 SetControlColor(_self->ob_itself,
906 newColorTable);
907 Py_INCREF(Py_None);
908 _res = Py_None;
909 return _res;
911 #endif
913 static PyObject *CtlObj_EmbedControl(ControlObject *_self, PyObject *_args)
915 PyObject *_res = NULL;
916 OSErr _err;
917 ControlHandle inContainer;
918 if (!PyArg_ParseTuple(_args, "O&",
919 CtlObj_Convert, &inContainer))
920 return NULL;
921 _err = EmbedControl(_self->ob_itself,
922 inContainer);
923 if (_err != noErr) return PyMac_Error(_err);
924 Py_INCREF(Py_None);
925 _res = Py_None;
926 return _res;
929 static PyObject *CtlObj_AutoEmbedControl(ControlObject *_self, PyObject *_args)
931 PyObject *_res = NULL;
932 OSErr _err;
933 WindowPtr inWindow;
934 if (!PyArg_ParseTuple(_args, "O&",
935 WinObj_Convert, &inWindow))
936 return NULL;
937 _err = AutoEmbedControl(_self->ob_itself,
938 inWindow);
939 if (_err != noErr) return PyMac_Error(_err);
940 Py_INCREF(Py_None);
941 _res = Py_None;
942 return _res;
945 static PyObject *CtlObj_GetSuperControl(ControlObject *_self, PyObject *_args)
947 PyObject *_res = NULL;
948 OSErr _err;
949 ControlHandle outParent;
950 if (!PyArg_ParseTuple(_args, ""))
951 return NULL;
952 _err = GetSuperControl(_self->ob_itself,
953 &outParent);
954 if (_err != noErr) return PyMac_Error(_err);
955 _res = Py_BuildValue("O&",
956 CtlObj_WhichControl, outParent);
957 return _res;
960 static PyObject *CtlObj_CountSubControls(ControlObject *_self, PyObject *_args)
962 PyObject *_res = NULL;
963 OSErr _err;
964 UInt16 outNumChildren;
965 if (!PyArg_ParseTuple(_args, ""))
966 return NULL;
967 _err = CountSubControls(_self->ob_itself,
968 &outNumChildren);
969 if (_err != noErr) return PyMac_Error(_err);
970 _res = Py_BuildValue("H",
971 outNumChildren);
972 return _res;
975 static PyObject *CtlObj_GetIndexedSubControl(ControlObject *_self, PyObject *_args)
977 PyObject *_res = NULL;
978 OSErr _err;
979 UInt16 inIndex;
980 ControlHandle outSubControl;
981 if (!PyArg_ParseTuple(_args, "H",
982 &inIndex))
983 return NULL;
984 _err = GetIndexedSubControl(_self->ob_itself,
985 inIndex,
986 &outSubControl);
987 if (_err != noErr) return PyMac_Error(_err);
988 _res = Py_BuildValue("O&",
989 CtlObj_WhichControl, outSubControl);
990 return _res;
993 static PyObject *CtlObj_SetControlSupervisor(ControlObject *_self, PyObject *_args)
995 PyObject *_res = NULL;
996 OSErr _err;
997 ControlHandle inBoss;
998 if (!PyArg_ParseTuple(_args, "O&",
999 CtlObj_Convert, &inBoss))
1000 return NULL;
1001 _err = SetControlSupervisor(_self->ob_itself,
1002 inBoss);
1003 if (_err != noErr) return PyMac_Error(_err);
1004 Py_INCREF(Py_None);
1005 _res = Py_None;
1006 return _res;
1009 static PyObject *CtlObj_GetControlFeatures(ControlObject *_self, PyObject *_args)
1011 PyObject *_res = NULL;
1012 OSErr _err;
1013 UInt32 outFeatures;
1014 if (!PyArg_ParseTuple(_args, ""))
1015 return NULL;
1016 _err = GetControlFeatures(_self->ob_itself,
1017 &outFeatures);
1018 if (_err != noErr) return PyMac_Error(_err);
1019 _res = Py_BuildValue("l",
1020 outFeatures);
1021 return _res;
1024 static PyObject *CtlObj_GetControlDataSize(ControlObject *_self, PyObject *_args)
1026 PyObject *_res = NULL;
1027 OSErr _err;
1028 ControlPartCode inPart;
1029 ResType inTagName;
1030 Size outMaxSize;
1031 if (!PyArg_ParseTuple(_args, "hO&",
1032 &inPart,
1033 PyMac_GetOSType, &inTagName))
1034 return NULL;
1035 _err = GetControlDataSize(_self->ob_itself,
1036 inPart,
1037 inTagName,
1038 &outMaxSize);
1039 if (_err != noErr) return PyMac_Error(_err);
1040 _res = Py_BuildValue("l",
1041 outMaxSize);
1042 return _res;
1045 #if TARGET_API_MAC_CARBON
1047 static PyObject *CtlObj_HandleControlDragTracking(ControlObject *_self, PyObject *_args)
1049 PyObject *_res = NULL;
1050 OSStatus _err;
1051 DragTrackingMessage inMessage;
1052 DragReference inDrag;
1053 Boolean outLikesDrag;
1054 if (!PyArg_ParseTuple(_args, "hO&",
1055 &inMessage,
1056 DragObj_Convert, &inDrag))
1057 return NULL;
1058 _err = HandleControlDragTracking(_self->ob_itself,
1059 inMessage,
1060 inDrag,
1061 &outLikesDrag);
1062 if (_err != noErr) return PyMac_Error(_err);
1063 _res = Py_BuildValue("b",
1064 outLikesDrag);
1065 return _res;
1067 #endif
1069 #if TARGET_API_MAC_CARBON
1071 static PyObject *CtlObj_HandleControlDragReceive(ControlObject *_self, PyObject *_args)
1073 PyObject *_res = NULL;
1074 OSStatus _err;
1075 DragReference inDrag;
1076 if (!PyArg_ParseTuple(_args, "O&",
1077 DragObj_Convert, &inDrag))
1078 return NULL;
1079 _err = HandleControlDragReceive(_self->ob_itself,
1080 inDrag);
1081 if (_err != noErr) return PyMac_Error(_err);
1082 Py_INCREF(Py_None);
1083 _res = Py_None;
1084 return _res;
1086 #endif
1088 #if TARGET_API_MAC_CARBON
1090 static PyObject *CtlObj_SetControlDragTrackingEnabled(ControlObject *_self, PyObject *_args)
1092 PyObject *_res = NULL;
1093 OSStatus _err;
1094 Boolean tracks;
1095 if (!PyArg_ParseTuple(_args, "b",
1096 &tracks))
1097 return NULL;
1098 _err = SetControlDragTrackingEnabled(_self->ob_itself,
1099 tracks);
1100 if (_err != noErr) return PyMac_Error(_err);
1101 Py_INCREF(Py_None);
1102 _res = Py_None;
1103 return _res;
1105 #endif
1107 #if TARGET_API_MAC_CARBON
1109 static PyObject *CtlObj_IsControlDragTrackingEnabled(ControlObject *_self, PyObject *_args)
1111 PyObject *_res = NULL;
1112 OSStatus _err;
1113 Boolean tracks;
1114 if (!PyArg_ParseTuple(_args, ""))
1115 return NULL;
1116 _err = IsControlDragTrackingEnabled(_self->ob_itself,
1117 &tracks);
1118 if (_err != noErr) return PyMac_Error(_err);
1119 _res = Py_BuildValue("b",
1120 tracks);
1121 return _res;
1123 #endif
1125 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1127 static PyObject *CtlObj_GetControlBounds(ControlObject *_self, PyObject *_args)
1129 PyObject *_res = NULL;
1130 Rect bounds;
1131 if (!PyArg_ParseTuple(_args, ""))
1132 return NULL;
1133 GetControlBounds(_self->ob_itself,
1134 &bounds);
1135 _res = Py_BuildValue("O&",
1136 PyMac_BuildRect, &bounds);
1137 return _res;
1139 #endif
1141 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1143 static PyObject *CtlObj_IsControlHilited(ControlObject *_self, PyObject *_args)
1145 PyObject *_res = NULL;
1146 Boolean _rv;
1147 if (!PyArg_ParseTuple(_args, ""))
1148 return NULL;
1149 _rv = IsControlHilited(_self->ob_itself);
1150 _res = Py_BuildValue("b",
1151 _rv);
1152 return _res;
1154 #endif
1156 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1158 static PyObject *CtlObj_GetControlHilite(ControlObject *_self, PyObject *_args)
1160 PyObject *_res = NULL;
1161 UInt16 _rv;
1162 if (!PyArg_ParseTuple(_args, ""))
1163 return NULL;
1164 _rv = GetControlHilite(_self->ob_itself);
1165 _res = Py_BuildValue("H",
1166 _rv);
1167 return _res;
1169 #endif
1171 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1173 static PyObject *CtlObj_GetControlOwner(ControlObject *_self, PyObject *_args)
1175 PyObject *_res = NULL;
1176 WindowPtr _rv;
1177 if (!PyArg_ParseTuple(_args, ""))
1178 return NULL;
1179 _rv = GetControlOwner(_self->ob_itself);
1180 _res = Py_BuildValue("O&",
1181 WinObj_New, _rv);
1182 return _res;
1184 #endif
1186 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1188 static PyObject *CtlObj_GetControlDataHandle(ControlObject *_self, PyObject *_args)
1190 PyObject *_res = NULL;
1191 Handle _rv;
1192 if (!PyArg_ParseTuple(_args, ""))
1193 return NULL;
1194 _rv = GetControlDataHandle(_self->ob_itself);
1195 _res = Py_BuildValue("O&",
1196 ResObj_New, _rv);
1197 return _res;
1199 #endif
1201 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1203 static PyObject *CtlObj_GetControlPopupMenuHandle(ControlObject *_self, PyObject *_args)
1205 PyObject *_res = NULL;
1206 MenuHandle _rv;
1207 if (!PyArg_ParseTuple(_args, ""))
1208 return NULL;
1209 _rv = GetControlPopupMenuHandle(_self->ob_itself);
1210 _res = Py_BuildValue("O&",
1211 MenuObj_New, _rv);
1212 return _res;
1214 #endif
1216 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1218 static PyObject *CtlObj_GetControlPopupMenuID(ControlObject *_self, PyObject *_args)
1220 PyObject *_res = NULL;
1221 short _rv;
1222 if (!PyArg_ParseTuple(_args, ""))
1223 return NULL;
1224 _rv = GetControlPopupMenuID(_self->ob_itself);
1225 _res = Py_BuildValue("h",
1226 _rv);
1227 return _res;
1229 #endif
1231 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1233 static PyObject *CtlObj_SetControlDataHandle(ControlObject *_self, PyObject *_args)
1235 PyObject *_res = NULL;
1236 Handle dataHandle;
1237 if (!PyArg_ParseTuple(_args, "O&",
1238 ResObj_Convert, &dataHandle))
1239 return NULL;
1240 SetControlDataHandle(_self->ob_itself,
1241 dataHandle);
1242 Py_INCREF(Py_None);
1243 _res = Py_None;
1244 return _res;
1246 #endif
1248 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1250 static PyObject *CtlObj_SetControlBounds(ControlObject *_self, PyObject *_args)
1252 PyObject *_res = NULL;
1253 Rect bounds;
1254 if (!PyArg_ParseTuple(_args, "O&",
1255 PyMac_GetRect, &bounds))
1256 return NULL;
1257 SetControlBounds(_self->ob_itself,
1258 &bounds);
1259 Py_INCREF(Py_None);
1260 _res = Py_None;
1261 return _res;
1263 #endif
1265 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1267 static PyObject *CtlObj_SetControlPopupMenuHandle(ControlObject *_self, PyObject *_args)
1269 PyObject *_res = NULL;
1270 MenuHandle popupMenu;
1271 if (!PyArg_ParseTuple(_args, "O&",
1272 MenuObj_Convert, &popupMenu))
1273 return NULL;
1274 SetControlPopupMenuHandle(_self->ob_itself,
1275 popupMenu);
1276 Py_INCREF(Py_None);
1277 _res = Py_None;
1278 return _res;
1280 #endif
1282 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1284 static PyObject *CtlObj_SetControlPopupMenuID(ControlObject *_self, PyObject *_args)
1286 PyObject *_res = NULL;
1287 short menuID;
1288 if (!PyArg_ParseTuple(_args, "h",
1289 &menuID))
1290 return NULL;
1291 SetControlPopupMenuID(_self->ob_itself,
1292 menuID);
1293 Py_INCREF(Py_None);
1294 _res = Py_None;
1295 return _res;
1297 #endif
1299 static PyObject *CtlObj_GetBevelButtonMenuValue(ControlObject *_self, PyObject *_args)
1301 PyObject *_res = NULL;
1302 OSErr _err;
1303 SInt16 outValue;
1304 if (!PyArg_ParseTuple(_args, ""))
1305 return NULL;
1306 _err = GetBevelButtonMenuValue(_self->ob_itself,
1307 &outValue);
1308 if (_err != noErr) return PyMac_Error(_err);
1309 _res = Py_BuildValue("h",
1310 outValue);
1311 return _res;
1314 static PyObject *CtlObj_SetBevelButtonMenuValue(ControlObject *_self, PyObject *_args)
1316 PyObject *_res = NULL;
1317 OSErr _err;
1318 SInt16 inValue;
1319 if (!PyArg_ParseTuple(_args, "h",
1320 &inValue))
1321 return NULL;
1322 _err = SetBevelButtonMenuValue(_self->ob_itself,
1323 inValue);
1324 if (_err != noErr) return PyMac_Error(_err);
1325 Py_INCREF(Py_None);
1326 _res = Py_None;
1327 return _res;
1330 static PyObject *CtlObj_GetBevelButtonMenuHandle(ControlObject *_self, PyObject *_args)
1332 PyObject *_res = NULL;
1333 OSErr _err;
1334 MenuHandle outHandle;
1335 if (!PyArg_ParseTuple(_args, ""))
1336 return NULL;
1337 _err = GetBevelButtonMenuHandle(_self->ob_itself,
1338 &outHandle);
1339 if (_err != noErr) return PyMac_Error(_err);
1340 _res = Py_BuildValue("O&",
1341 MenuObj_New, outHandle);
1342 return _res;
1345 static PyObject *CtlObj_SetBevelButtonTransform(ControlObject *_self, PyObject *_args)
1347 PyObject *_res = NULL;
1348 OSErr _err;
1349 IconTransformType transform;
1350 if (!PyArg_ParseTuple(_args, "h",
1351 &transform))
1352 return NULL;
1353 _err = SetBevelButtonTransform(_self->ob_itself,
1354 transform);
1355 if (_err != noErr) return PyMac_Error(_err);
1356 Py_INCREF(Py_None);
1357 _res = Py_None;
1358 return _res;
1361 static PyObject *CtlObj_SetDisclosureTriangleLastValue(ControlObject *_self, PyObject *_args)
1363 PyObject *_res = NULL;
1364 OSErr _err;
1365 SInt16 inValue;
1366 if (!PyArg_ParseTuple(_args, "h",
1367 &inValue))
1368 return NULL;
1369 _err = SetDisclosureTriangleLastValue(_self->ob_itself,
1370 inValue);
1371 if (_err != noErr) return PyMac_Error(_err);
1372 Py_INCREF(Py_None);
1373 _res = Py_None;
1374 return _res;
1377 static PyObject *CtlObj_GetTabContentRect(ControlObject *_self, PyObject *_args)
1379 PyObject *_res = NULL;
1380 OSErr _err;
1381 Rect outContentRect;
1382 if (!PyArg_ParseTuple(_args, ""))
1383 return NULL;
1384 _err = GetTabContentRect(_self->ob_itself,
1385 &outContentRect);
1386 if (_err != noErr) return PyMac_Error(_err);
1387 _res = Py_BuildValue("O&",
1388 PyMac_BuildRect, &outContentRect);
1389 return _res;
1392 static PyObject *CtlObj_SetTabEnabled(ControlObject *_self, PyObject *_args)
1394 PyObject *_res = NULL;
1395 OSErr _err;
1396 SInt16 inTabToHilite;
1397 Boolean inEnabled;
1398 if (!PyArg_ParseTuple(_args, "hb",
1399 &inTabToHilite,
1400 &inEnabled))
1401 return NULL;
1402 _err = SetTabEnabled(_self->ob_itself,
1403 inTabToHilite,
1404 inEnabled);
1405 if (_err != noErr) return PyMac_Error(_err);
1406 Py_INCREF(Py_None);
1407 _res = Py_None;
1408 return _res;
1411 static PyObject *CtlObj_SetImageWellTransform(ControlObject *_self, PyObject *_args)
1413 PyObject *_res = NULL;
1414 OSErr _err;
1415 IconTransformType inTransform;
1416 if (!PyArg_ParseTuple(_args, "h",
1417 &inTransform))
1418 return NULL;
1419 _err = SetImageWellTransform(_self->ob_itself,
1420 inTransform);
1421 if (_err != noErr) return PyMac_Error(_err);
1422 Py_INCREF(Py_None);
1423 _res = Py_None;
1424 return _res;
1427 static PyObject *CtlObj_as_Resource(ControlObject *_self, PyObject *_args)
1429 PyObject *_res = NULL;
1430 Handle _rv;
1431 if (!PyArg_ParseTuple(_args, ""))
1432 return NULL;
1433 _rv = as_Resource(_self->ob_itself);
1434 _res = Py_BuildValue("O&",
1435 ResObj_New, _rv);
1436 return _res;
1439 static PyObject *CtlObj_GetControlRect(ControlObject *_self, PyObject *_args)
1441 PyObject *_res = NULL;
1442 Rect rect;
1443 if (!PyArg_ParseTuple(_args, ""))
1444 return NULL;
1445 GetControlRect(_self->ob_itself,
1446 &rect);
1447 _res = Py_BuildValue("O&",
1448 PyMac_BuildRect, &rect);
1449 return _res;
1452 static PyObject *CtlObj_DisposeControl(ControlObject *_self, PyObject *_args)
1454 PyObject *_res = NULL;
1456 if (!PyArg_ParseTuple(_args, ""))
1457 return NULL;
1458 if ( _self->ob_itself ) {
1459 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
1460 DisposeControl(_self->ob_itself);
1461 _self->ob_itself = NULL;
1463 Py_INCREF(Py_None);
1464 _res = Py_None;
1465 return _res;
1469 static PyObject *CtlObj_TrackControl(ControlObject *_self, PyObject *_args)
1471 PyObject *_res = NULL;
1473 ControlPartCode _rv;
1474 Point startPoint;
1475 ControlActionUPP upp = 0;
1476 PyObject *callback = 0;
1478 if (!PyArg_ParseTuple(_args, "O&|O",
1479 PyMac_GetPoint, &startPoint, &callback))
1480 return NULL;
1481 if (callback && callback != Py_None) {
1482 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1483 upp = (ControlActionUPP)-1;
1484 else {
1485 settrackfunc(callback);
1486 upp = mytracker_upp;
1489 _rv = TrackControl(_self->ob_itself,
1490 startPoint,
1491 upp);
1492 clrtrackfunc();
1493 _res = Py_BuildValue("h",
1494 _rv);
1495 return _res;
1499 static PyObject *CtlObj_HandleControlClick(ControlObject *_self, PyObject *_args)
1501 PyObject *_res = NULL;
1503 ControlPartCode _rv;
1504 Point startPoint;
1505 SInt16 modifiers;
1506 ControlActionUPP upp = 0;
1507 PyObject *callback = 0;
1509 if (!PyArg_ParseTuple(_args, "O&h|O",
1510 PyMac_GetPoint, &startPoint,
1511 &modifiers,
1512 &callback))
1513 return NULL;
1514 if (callback && callback != Py_None) {
1515 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1516 upp = (ControlActionUPP)-1;
1517 else {
1518 settrackfunc(callback);
1519 upp = mytracker_upp;
1522 _rv = HandleControlClick(_self->ob_itself,
1523 startPoint,
1524 modifiers,
1525 upp);
1526 clrtrackfunc();
1527 _res = Py_BuildValue("h",
1528 _rv);
1529 return _res;
1533 static PyObject *CtlObj_SetControlData(ControlObject *_self, PyObject *_args)
1535 PyObject *_res = NULL;
1537 OSErr _err;
1538 ControlPartCode inPart;
1539 ResType inTagName;
1540 Size bufferSize;
1541 Ptr buffer;
1543 if (!PyArg_ParseTuple(_args, "hO&s#",
1544 &inPart,
1545 PyMac_GetOSType, &inTagName,
1546 &buffer, &bufferSize))
1547 return NULL;
1549 _err = SetControlData(_self->ob_itself,
1550 inPart,
1551 inTagName,
1552 bufferSize,
1553 buffer);
1555 if (_err != noErr)
1556 return PyMac_Error(_err);
1557 _res = Py_None;
1558 return _res;
1562 static PyObject *CtlObj_GetControlData(ControlObject *_self, PyObject *_args)
1564 PyObject *_res = NULL;
1566 OSErr _err;
1567 ControlPartCode inPart;
1568 ResType inTagName;
1569 Size bufferSize;
1570 Ptr buffer;
1571 Size outSize;
1573 if (!PyArg_ParseTuple(_args, "hO&",
1574 &inPart,
1575 PyMac_GetOSType, &inTagName))
1576 return NULL;
1578 /* allocate a buffer for the data */
1579 _err = GetControlDataSize(_self->ob_itself,
1580 inPart,
1581 inTagName,
1582 &bufferSize);
1583 if (_err != noErr)
1584 return PyMac_Error(_err);
1585 buffer = PyMem_NEW(char, bufferSize);
1586 if (buffer == NULL)
1587 return PyErr_NoMemory();
1589 _err = GetControlData(_self->ob_itself,
1590 inPart,
1591 inTagName,
1592 bufferSize,
1593 buffer,
1594 &outSize);
1596 if (_err != noErr) {
1597 PyMem_DEL(buffer);
1598 return PyMac_Error(_err);
1600 _res = Py_BuildValue("s#", buffer, outSize);
1601 PyMem_DEL(buffer);
1602 return _res;
1606 static PyObject *CtlObj_SetControlData_Handle(ControlObject *_self, PyObject *_args)
1608 PyObject *_res = NULL;
1610 OSErr _err;
1611 ControlPartCode inPart;
1612 ResType inTagName;
1613 Handle buffer;
1615 if (!PyArg_ParseTuple(_args, "hO&O&",
1616 &inPart,
1617 PyMac_GetOSType, &inTagName,
1618 OptResObj_Convert, &buffer))
1619 return NULL;
1621 _err = SetControlData(_self->ob_itself,
1622 inPart,
1623 inTagName,
1624 sizeof(buffer),
1625 (Ptr)&buffer);
1627 if (_err != noErr)
1628 return PyMac_Error(_err);
1629 _res = Py_None;
1630 return _res;
1634 static PyObject *CtlObj_GetControlData_Handle(ControlObject *_self, PyObject *_args)
1636 PyObject *_res = NULL;
1638 OSErr _err;
1639 ControlPartCode inPart;
1640 ResType inTagName;
1641 Size bufferSize;
1642 Handle hdl;
1644 if (!PyArg_ParseTuple(_args, "hO&",
1645 &inPart,
1646 PyMac_GetOSType, &inTagName))
1647 return NULL;
1649 /* Check it is handle-sized */
1650 _err = GetControlDataSize(_self->ob_itself,
1651 inPart,
1652 inTagName,
1653 &bufferSize);
1654 if (_err != noErr)
1655 return PyMac_Error(_err);
1656 if (bufferSize != sizeof(Handle)) {
1657 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1658 return NULL;
1661 _err = GetControlData(_self->ob_itself,
1662 inPart,
1663 inTagName,
1664 sizeof(Handle),
1665 (Ptr)&hdl,
1666 &bufferSize);
1668 if (_err != noErr) {
1669 return PyMac_Error(_err);
1671 return Py_BuildValue("O&", OptResObj_New, hdl);
1675 static PyObject *CtlObj_SetControlData_Callback(ControlObject *_self, PyObject *_args)
1677 PyObject *_res = NULL;
1679 OSErr _err;
1680 ControlPartCode inPart;
1681 ResType inTagName;
1682 PyObject *callback;
1683 UniversalProcPtr c_callback;
1685 if (!PyArg_ParseTuple(_args, "hO&O",
1686 &inPart,
1687 PyMac_GetOSType, &inTagName,
1688 &callback))
1689 return NULL;
1691 if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 )
1692 return NULL;
1693 _err = SetControlData(_self->ob_itself,
1694 inPart,
1695 inTagName,
1696 sizeof(c_callback),
1697 (Ptr)&c_callback);
1699 if (_err != noErr)
1700 return PyMac_Error(_err);
1701 _res = Py_None;
1702 return _res;
1706 #if !TARGET_API_MAC_CARBON
1708 static PyObject *CtlObj_GetPopupData(ControlObject *_self, PyObject *_args)
1710 PyObject *_res = NULL;
1712 PopupPrivateDataHandle hdl;
1714 if ( (*_self->ob_itself)->contrlData == NULL ) {
1715 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1716 return 0;
1718 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1719 HLock((Handle)hdl);
1720 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1721 HUnlock((Handle)hdl);
1722 return _res;
1725 #endif
1727 #if !TARGET_API_MAC_CARBON
1729 static PyObject *CtlObj_SetPopupData(ControlObject *_self, PyObject *_args)
1731 PyObject *_res = NULL;
1733 PopupPrivateDataHandle hdl;
1734 MenuHandle mHandle;
1735 short mID;
1737 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1738 return 0;
1739 if ( (*_self->ob_itself)->contrlData == NULL ) {
1740 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1741 return 0;
1743 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1744 (*hdl)->mHandle = mHandle;
1745 (*hdl)->mID = mID;
1746 Py_INCREF(Py_None);
1747 return Py_None;
1750 #endif
1752 static PyMethodDef CtlObj_methods[] = {
1753 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1754 "(ControlPartCode hiliteState) -> None"},
1755 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1756 "() -> None"},
1757 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1758 "() -> None"},
1759 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1760 "() -> (Boolean _rv)"},
1761 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1762 "() -> (Boolean _rv)"},
1763 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1764 "() -> None"},
1765 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1766 "() -> None"},
1767 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1768 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
1769 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1770 "() -> None"},
1771 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1772 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1773 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1774 "(ControlFontStyleRec inStyle) -> None"},
1775 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1776 "() -> None"},
1777 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1778 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
1779 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1780 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
1781 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
1782 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
1783 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
1784 "(Point testPoint) -> (ControlPartCode _rv)"},
1786 #if TARGET_API_MAC_CARBON
1787 {"HandleControlContextualMenuClick", (PyCFunction)CtlObj_HandleControlContextualMenuClick, 1,
1788 "(Point inWhere) -> (Boolean menuDisplayed)"},
1789 #endif
1791 #if TARGET_API_MAC_CARBON
1792 {"GetControlClickActivation", (PyCFunction)CtlObj_GetControlClickActivation, 1,
1793 "(Point inWhere, EventModifiers inModifiers) -> (ClickActivationResult outResult)"},
1794 #endif
1795 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
1796 "(SInt16 inKeyCode, SInt16 inCharCode, EventModifiers inModifiers) -> (SInt16 _rv)"},
1798 #if TARGET_API_MAC_CARBON
1799 {"HandleControlSetCursor", (PyCFunction)CtlObj_HandleControlSetCursor, 1,
1800 "(Point localPoint, EventModifiers modifiers) -> (Boolean cursorWasSet)"},
1801 #endif
1802 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
1803 "(SInt16 h, SInt16 v) -> None"},
1804 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
1805 "(SInt16 w, SInt16 h) -> None"},
1806 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1807 "(Str255 title) -> None"},
1808 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
1809 "() -> (Str255 title)"},
1810 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
1811 "() -> (SInt16 _rv)"},
1812 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1813 "(SInt16 newValue) -> None"},
1814 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
1815 "() -> (SInt16 _rv)"},
1816 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1817 "(SInt16 newMinimum) -> None"},
1818 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
1819 "() -> (SInt16 _rv)"},
1820 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1821 "(SInt16 newMaximum) -> None"},
1822 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
1823 "() -> (SInt32 _rv)"},
1824 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
1825 "(SInt32 newViewSize) -> None"},
1826 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
1827 "() -> (SInt32 _rv)"},
1828 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
1829 "(SInt32 newValue) -> None"},
1830 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
1831 "() -> (SInt32 _rv)"},
1832 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
1833 "(SInt32 newMaximum) -> None"},
1834 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
1835 "() -> (SInt32 _rv)"},
1836 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
1837 "(SInt32 newMinimum) -> None"},
1838 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
1839 "() -> (Boolean _rv)"},
1841 #if TARGET_API_MAC_CARBON
1842 {"SetControlID", (PyCFunction)CtlObj_SetControlID, 1,
1843 "(ControlID inID) -> None"},
1844 #endif
1846 #if TARGET_API_MAC_CARBON
1847 {"GetControlID", (PyCFunction)CtlObj_GetControlID, 1,
1848 "() -> (ControlID outID)"},
1849 #endif
1850 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
1851 "(OSType propertyCreator, OSType propertyTag) -> None"},
1853 #if TARGET_API_MAC_CARBON
1854 {"GetControlPropertyAttributes", (PyCFunction)CtlObj_GetControlPropertyAttributes, 1,
1855 "(OSType propertyCreator, OSType propertyTag) -> (UInt32 attributes)"},
1856 #endif
1858 #if TARGET_API_MAC_CARBON
1859 {"ChangeControlPropertyAttributes", (PyCFunction)CtlObj_ChangeControlPropertyAttributes, 1,
1860 "(OSType propertyCreator, OSType propertyTag, UInt32 attributesToSet, UInt32 attributesToClear) -> None"},
1861 #endif
1862 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
1863 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
1864 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
1865 "() -> (ControlVariant _rv)"},
1866 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1867 "(SInt32 data) -> None"},
1868 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1869 "() -> (SInt32 _rv)"},
1871 #if !TARGET_API_MAC_CARBON
1872 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1873 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
1874 #endif
1876 #if !TARGET_API_MAC_CARBON
1877 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1878 "(CCTabHandle newColorTable) -> None"},
1879 #endif
1880 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
1881 "(ControlHandle inContainer) -> None"},
1882 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
1883 "(WindowPtr inWindow) -> None"},
1884 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
1885 "() -> (ControlHandle outParent)"},
1886 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
1887 "() -> (UInt16 outNumChildren)"},
1888 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
1889 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
1890 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
1891 "(ControlHandle inBoss) -> None"},
1892 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
1893 "() -> (UInt32 outFeatures)"},
1894 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
1895 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
1897 #if TARGET_API_MAC_CARBON
1898 {"HandleControlDragTracking", (PyCFunction)CtlObj_HandleControlDragTracking, 1,
1899 "(DragTrackingMessage inMessage, DragReference inDrag) -> (Boolean outLikesDrag)"},
1900 #endif
1902 #if TARGET_API_MAC_CARBON
1903 {"HandleControlDragReceive", (PyCFunction)CtlObj_HandleControlDragReceive, 1,
1904 "(DragReference inDrag) -> None"},
1905 #endif
1907 #if TARGET_API_MAC_CARBON
1908 {"SetControlDragTrackingEnabled", (PyCFunction)CtlObj_SetControlDragTrackingEnabled, 1,
1909 "(Boolean tracks) -> None"},
1910 #endif
1912 #if TARGET_API_MAC_CARBON
1913 {"IsControlDragTrackingEnabled", (PyCFunction)CtlObj_IsControlDragTrackingEnabled, 1,
1914 "() -> (Boolean tracks)"},
1915 #endif
1917 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1918 {"GetControlBounds", (PyCFunction)CtlObj_GetControlBounds, 1,
1919 "() -> (Rect bounds)"},
1920 #endif
1922 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1923 {"IsControlHilited", (PyCFunction)CtlObj_IsControlHilited, 1,
1924 "() -> (Boolean _rv)"},
1925 #endif
1927 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1928 {"GetControlHilite", (PyCFunction)CtlObj_GetControlHilite, 1,
1929 "() -> (UInt16 _rv)"},
1930 #endif
1932 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1933 {"GetControlOwner", (PyCFunction)CtlObj_GetControlOwner, 1,
1934 "() -> (WindowPtr _rv)"},
1935 #endif
1937 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1938 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
1939 "() -> (Handle _rv)"},
1940 #endif
1942 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1943 {"GetControlPopupMenuHandle", (PyCFunction)CtlObj_GetControlPopupMenuHandle, 1,
1944 "() -> (MenuHandle _rv)"},
1945 #endif
1947 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1948 {"GetControlPopupMenuID", (PyCFunction)CtlObj_GetControlPopupMenuID, 1,
1949 "() -> (short _rv)"},
1950 #endif
1952 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1953 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
1954 "(Handle dataHandle) -> None"},
1955 #endif
1957 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1958 {"SetControlBounds", (PyCFunction)CtlObj_SetControlBounds, 1,
1959 "(Rect bounds) -> None"},
1960 #endif
1962 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1963 {"SetControlPopupMenuHandle", (PyCFunction)CtlObj_SetControlPopupMenuHandle, 1,
1964 "(MenuHandle popupMenu) -> None"},
1965 #endif
1967 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1968 {"SetControlPopupMenuID", (PyCFunction)CtlObj_SetControlPopupMenuID, 1,
1969 "(short menuID) -> None"},
1970 #endif
1971 {"GetBevelButtonMenuValue", (PyCFunction)CtlObj_GetBevelButtonMenuValue, 1,
1972 "() -> (SInt16 outValue)"},
1973 {"SetBevelButtonMenuValue", (PyCFunction)CtlObj_SetBevelButtonMenuValue, 1,
1974 "(SInt16 inValue) -> None"},
1975 {"GetBevelButtonMenuHandle", (PyCFunction)CtlObj_GetBevelButtonMenuHandle, 1,
1976 "() -> (MenuHandle outHandle)"},
1977 {"SetBevelButtonTransform", (PyCFunction)CtlObj_SetBevelButtonTransform, 1,
1978 "(IconTransformType transform) -> None"},
1979 {"SetDisclosureTriangleLastValue", (PyCFunction)CtlObj_SetDisclosureTriangleLastValue, 1,
1980 "(SInt16 inValue) -> None"},
1981 {"GetTabContentRect", (PyCFunction)CtlObj_GetTabContentRect, 1,
1982 "() -> (Rect outContentRect)"},
1983 {"SetTabEnabled", (PyCFunction)CtlObj_SetTabEnabled, 1,
1984 "(SInt16 inTabToHilite, Boolean inEnabled) -> None"},
1985 {"SetImageWellTransform", (PyCFunction)CtlObj_SetImageWellTransform, 1,
1986 "(IconTransformType inTransform) -> None"},
1987 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
1988 "() -> (Handle _rv)"},
1989 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
1990 "() -> (Rect rect)"},
1991 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1992 "() -> None"},
1993 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
1994 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
1995 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
1996 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
1997 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
1998 "(stuff) -> None"},
1999 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
2000 "(part, type) -> String"},
2001 {"SetControlData_Handle", (PyCFunction)CtlObj_SetControlData_Handle, 1,
2002 "(ResObj) -> None"},
2003 {"GetControlData_Handle", (PyCFunction)CtlObj_GetControlData_Handle, 1,
2004 "(part, type) -> ResObj"},
2005 {"SetControlData_Callback", (PyCFunction)CtlObj_SetControlData_Callback, 1,
2006 "(callbackfunc) -> None"},
2008 #if !TARGET_API_MAC_CARBON
2009 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
2010 NULL},
2011 #endif
2013 #if !TARGET_API_MAC_CARBON
2014 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
2015 NULL},
2016 #endif
2017 {NULL, NULL, 0}
2020 PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
2022 static PyObject *CtlObj_getattr(ControlObject *self, char *name)
2024 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
2027 #define CtlObj_setattr NULL
2029 static int CtlObj_compare(ControlObject *self, ControlObject *other)
2031 unsigned long v, w;
2033 if (!CtlObj_Check((PyObject *)other))
2035 v=(unsigned long)self;
2036 w=(unsigned long)other;
2038 else
2040 v=(unsigned long)self->ob_itself;
2041 w=(unsigned long)other->ob_itself;
2043 if( v < w ) return -1;
2044 if( v > w ) return 1;
2045 return 0;
2048 #define CtlObj_repr NULL
2050 static long CtlObj_hash(ControlObject *self)
2052 return (long)self->ob_itself;
2055 PyTypeObject Control_Type = {
2056 PyObject_HEAD_INIT(&PyType_Type)
2057 0, /*ob_size*/
2058 "Control", /*tp_name*/
2059 sizeof(ControlObject), /*tp_basicsize*/
2060 0, /*tp_itemsize*/
2061 /* methods */
2062 (destructor) CtlObj_dealloc, /*tp_dealloc*/
2063 0, /*tp_print*/
2064 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
2065 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
2066 (cmpfunc) CtlObj_compare, /*tp_compare*/
2067 (reprfunc) CtlObj_repr, /*tp_repr*/
2068 (PyNumberMethods *)0, /* tp_as_number */
2069 (PySequenceMethods *)0, /* tp_as_sequence */
2070 (PyMappingMethods *)0, /* tp_as_mapping */
2071 (hashfunc) CtlObj_hash, /*tp_hash*/
2074 /* -------------------- End object type Control --------------------- */
2077 static PyObject *Ctl_NewControl(PyObject *_self, PyObject *_args)
2079 PyObject *_res = NULL;
2080 ControlHandle _rv;
2081 WindowPtr owningWindow;
2082 Rect boundsRect;
2083 Str255 controlTitle;
2084 Boolean initiallyVisible;
2085 SInt16 initialValue;
2086 SInt16 minimumValue;
2087 SInt16 maximumValue;
2088 SInt16 procID;
2089 SInt32 controlReference;
2090 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
2091 WinObj_Convert, &owningWindow,
2092 PyMac_GetRect, &boundsRect,
2093 PyMac_GetStr255, controlTitle,
2094 &initiallyVisible,
2095 &initialValue,
2096 &minimumValue,
2097 &maximumValue,
2098 &procID,
2099 &controlReference))
2100 return NULL;
2101 _rv = NewControl(owningWindow,
2102 &boundsRect,
2103 controlTitle,
2104 initiallyVisible,
2105 initialValue,
2106 minimumValue,
2107 maximumValue,
2108 procID,
2109 controlReference);
2110 _res = Py_BuildValue("O&",
2111 CtlObj_New, _rv);
2112 return _res;
2115 static PyObject *Ctl_GetNewControl(PyObject *_self, PyObject *_args)
2117 PyObject *_res = NULL;
2118 ControlHandle _rv;
2119 SInt16 resourceID;
2120 WindowPtr owningWindow;
2121 if (!PyArg_ParseTuple(_args, "hO&",
2122 &resourceID,
2123 WinObj_Convert, &owningWindow))
2124 return NULL;
2125 _rv = GetNewControl(resourceID,
2126 owningWindow);
2127 _res = Py_BuildValue("O&",
2128 CtlObj_New, _rv);
2129 return _res;
2132 static PyObject *Ctl_DrawControls(PyObject *_self, PyObject *_args)
2134 PyObject *_res = NULL;
2135 WindowPtr theWindow;
2136 if (!PyArg_ParseTuple(_args, "O&",
2137 WinObj_Convert, &theWindow))
2138 return NULL;
2139 DrawControls(theWindow);
2140 Py_INCREF(Py_None);
2141 _res = Py_None;
2142 return _res;
2145 static PyObject *Ctl_UpdateControls(PyObject *_self, PyObject *_args)
2147 PyObject *_res = NULL;
2148 WindowPtr theWindow;
2149 RgnHandle updateRegion;
2150 if (!PyArg_ParseTuple(_args, "O&O&",
2151 WinObj_Convert, &theWindow,
2152 ResObj_Convert, &updateRegion))
2153 return NULL;
2154 UpdateControls(theWindow,
2155 updateRegion);
2156 Py_INCREF(Py_None);
2157 _res = Py_None;
2158 return _res;
2161 static PyObject *Ctl_FindControl(PyObject *_self, PyObject *_args)
2163 PyObject *_res = NULL;
2164 ControlPartCode _rv;
2165 Point testPoint;
2166 WindowPtr theWindow;
2167 ControlHandle theControl;
2168 if (!PyArg_ParseTuple(_args, "O&O&",
2169 PyMac_GetPoint, &testPoint,
2170 WinObj_Convert, &theWindow))
2171 return NULL;
2172 _rv = FindControl(testPoint,
2173 theWindow,
2174 &theControl);
2175 _res = Py_BuildValue("hO&",
2176 _rv,
2177 CtlObj_WhichControl, theControl);
2178 return _res;
2181 static PyObject *Ctl_FindControlUnderMouse(PyObject *_self, PyObject *_args)
2183 PyObject *_res = NULL;
2184 ControlHandle _rv;
2185 Point inWhere;
2186 WindowPtr inWindow;
2187 SInt16 outPart;
2188 if (!PyArg_ParseTuple(_args, "O&O&",
2189 PyMac_GetPoint, &inWhere,
2190 WinObj_Convert, &inWindow))
2191 return NULL;
2192 _rv = FindControlUnderMouse(inWhere,
2193 inWindow,
2194 &outPart);
2195 _res = Py_BuildValue("O&h",
2196 CtlObj_New, _rv,
2197 outPart);
2198 return _res;
2201 static PyObject *Ctl_IdleControls(PyObject *_self, PyObject *_args)
2203 PyObject *_res = NULL;
2204 WindowPtr inWindow;
2205 if (!PyArg_ParseTuple(_args, "O&",
2206 WinObj_Convert, &inWindow))
2207 return NULL;
2208 IdleControls(inWindow);
2209 Py_INCREF(Py_None);
2210 _res = Py_None;
2211 return _res;
2214 #if TARGET_API_MAC_CARBON
2216 static PyObject *Ctl_GetControlByID(PyObject *_self, PyObject *_args)
2218 PyObject *_res = NULL;
2219 OSStatus _err;
2220 WindowPtr inWindow;
2221 ControlID inID;
2222 ControlHandle outControl;
2223 if (!PyArg_ParseTuple(_args, "O&O&",
2224 WinObj_Convert, &inWindow,
2225 PyControlID_Convert, &inID))
2226 return NULL;
2227 _err = GetControlByID(inWindow,
2228 &inID,
2229 &outControl);
2230 if (_err != noErr) return PyMac_Error(_err);
2231 _res = Py_BuildValue("O&",
2232 CtlObj_WhichControl, outControl);
2233 return _res;
2235 #endif
2237 static PyObject *Ctl_DumpControlHierarchy(PyObject *_self, PyObject *_args)
2239 PyObject *_res = NULL;
2240 OSErr _err;
2241 WindowPtr inWindow;
2242 FSSpec inDumpFile;
2243 if (!PyArg_ParseTuple(_args, "O&O&",
2244 WinObj_Convert, &inWindow,
2245 PyMac_GetFSSpec, &inDumpFile))
2246 return NULL;
2247 _err = DumpControlHierarchy(inWindow,
2248 &inDumpFile);
2249 if (_err != noErr) return PyMac_Error(_err);
2250 Py_INCREF(Py_None);
2251 _res = Py_None;
2252 return _res;
2255 static PyObject *Ctl_CreateRootControl(PyObject *_self, PyObject *_args)
2257 PyObject *_res = NULL;
2258 OSErr _err;
2259 WindowPtr inWindow;
2260 ControlHandle outControl;
2261 if (!PyArg_ParseTuple(_args, "O&",
2262 WinObj_Convert, &inWindow))
2263 return NULL;
2264 _err = CreateRootControl(inWindow,
2265 &outControl);
2266 if (_err != noErr) return PyMac_Error(_err);
2267 _res = Py_BuildValue("O&",
2268 CtlObj_WhichControl, outControl);
2269 return _res;
2272 static PyObject *Ctl_GetRootControl(PyObject *_self, PyObject *_args)
2274 PyObject *_res = NULL;
2275 OSErr _err;
2276 WindowPtr inWindow;
2277 ControlHandle outControl;
2278 if (!PyArg_ParseTuple(_args, "O&",
2279 WinObj_Convert, &inWindow))
2280 return NULL;
2281 _err = GetRootControl(inWindow,
2282 &outControl);
2283 if (_err != noErr) return PyMac_Error(_err);
2284 _res = Py_BuildValue("O&",
2285 CtlObj_WhichControl, outControl);
2286 return _res;
2289 static PyObject *Ctl_GetKeyboardFocus(PyObject *_self, PyObject *_args)
2291 PyObject *_res = NULL;
2292 OSErr _err;
2293 WindowPtr inWindow;
2294 ControlHandle outControl;
2295 if (!PyArg_ParseTuple(_args, "O&",
2296 WinObj_Convert, &inWindow))
2297 return NULL;
2298 _err = GetKeyboardFocus(inWindow,
2299 &outControl);
2300 if (_err != noErr) return PyMac_Error(_err);
2301 _res = Py_BuildValue("O&",
2302 CtlObj_WhichControl, outControl);
2303 return _res;
2306 static PyObject *Ctl_SetKeyboardFocus(PyObject *_self, PyObject *_args)
2308 PyObject *_res = NULL;
2309 OSErr _err;
2310 WindowPtr inWindow;
2311 ControlHandle inControl;
2312 ControlFocusPart inPart;
2313 if (!PyArg_ParseTuple(_args, "O&O&h",
2314 WinObj_Convert, &inWindow,
2315 CtlObj_Convert, &inControl,
2316 &inPart))
2317 return NULL;
2318 _err = SetKeyboardFocus(inWindow,
2319 inControl,
2320 inPart);
2321 if (_err != noErr) return PyMac_Error(_err);
2322 Py_INCREF(Py_None);
2323 _res = Py_None;
2324 return _res;
2327 static PyObject *Ctl_AdvanceKeyboardFocus(PyObject *_self, PyObject *_args)
2329 PyObject *_res = NULL;
2330 OSErr _err;
2331 WindowPtr inWindow;
2332 if (!PyArg_ParseTuple(_args, "O&",
2333 WinObj_Convert, &inWindow))
2334 return NULL;
2335 _err = AdvanceKeyboardFocus(inWindow);
2336 if (_err != noErr) return PyMac_Error(_err);
2337 Py_INCREF(Py_None);
2338 _res = Py_None;
2339 return _res;
2342 static PyObject *Ctl_ReverseKeyboardFocus(PyObject *_self, PyObject *_args)
2344 PyObject *_res = NULL;
2345 OSErr _err;
2346 WindowPtr inWindow;
2347 if (!PyArg_ParseTuple(_args, "O&",
2348 WinObj_Convert, &inWindow))
2349 return NULL;
2350 _err = ReverseKeyboardFocus(inWindow);
2351 if (_err != noErr) return PyMac_Error(_err);
2352 Py_INCREF(Py_None);
2353 _res = Py_None;
2354 return _res;
2357 static PyObject *Ctl_ClearKeyboardFocus(PyObject *_self, PyObject *_args)
2359 PyObject *_res = NULL;
2360 OSErr _err;
2361 WindowPtr inWindow;
2362 if (!PyArg_ParseTuple(_args, "O&",
2363 WinObj_Convert, &inWindow))
2364 return NULL;
2365 _err = ClearKeyboardFocus(inWindow);
2366 if (_err != noErr) return PyMac_Error(_err);
2367 Py_INCREF(Py_None);
2368 _res = Py_None;
2369 return _res;
2372 #if TARGET_API_MAC_CARBON
2374 static PyObject *Ctl_SetAutomaticControlDragTrackingEnabledForWindow(PyObject *_self, PyObject *_args)
2376 PyObject *_res = NULL;
2377 OSStatus _err;
2378 WindowPtr theWindow;
2379 Boolean tracks;
2380 if (!PyArg_ParseTuple(_args, "O&b",
2381 WinObj_Convert, &theWindow,
2382 &tracks))
2383 return NULL;
2384 _err = SetAutomaticControlDragTrackingEnabledForWindow(theWindow,
2385 tracks);
2386 if (_err != noErr) return PyMac_Error(_err);
2387 Py_INCREF(Py_None);
2388 _res = Py_None;
2389 return _res;
2391 #endif
2393 #if TARGET_API_MAC_CARBON
2395 static PyObject *Ctl_IsAutomaticControlDragTrackingEnabledForWindow(PyObject *_self, PyObject *_args)
2397 PyObject *_res = NULL;
2398 OSStatus _err;
2399 WindowPtr theWindow;
2400 Boolean tracks;
2401 if (!PyArg_ParseTuple(_args, "O&",
2402 WinObj_Convert, &theWindow))
2403 return NULL;
2404 _err = IsAutomaticControlDragTrackingEnabledForWindow(theWindow,
2405 &tracks);
2406 if (_err != noErr) return PyMac_Error(_err);
2407 _res = Py_BuildValue("b",
2408 tracks);
2409 return _res;
2411 #endif
2413 static PyObject *Ctl_as_Control(PyObject *_self, PyObject *_args)
2415 PyObject *_res = NULL;
2416 ControlHandle _rv;
2417 Handle h;
2418 if (!PyArg_ParseTuple(_args, "O&",
2419 ResObj_Convert, &h))
2420 return NULL;
2421 _rv = as_Control(h);
2422 _res = Py_BuildValue("O&",
2423 CtlObj_New, _rv);
2424 return _res;
2427 static PyMethodDef Ctl_methods[] = {
2428 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
2429 "(WindowPtr owningWindow, Rect boundsRect, Str255 controlTitle, Boolean initiallyVisible, SInt16 initialValue, SInt16 minimumValue, SInt16 maximumValue, SInt16 procID, SInt32 controlReference) -> (ControlHandle _rv)"},
2430 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
2431 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
2432 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
2433 "(WindowPtr theWindow) -> None"},
2434 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
2435 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
2436 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
2437 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
2438 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
2439 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
2440 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
2441 "(WindowPtr inWindow) -> None"},
2443 #if TARGET_API_MAC_CARBON
2444 {"GetControlByID", (PyCFunction)Ctl_GetControlByID, 1,
2445 "(WindowPtr inWindow, ControlID inID) -> (ControlHandle outControl)"},
2446 #endif
2447 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
2448 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
2449 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
2450 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2451 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
2452 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2453 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
2454 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2455 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
2456 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
2457 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
2458 "(WindowPtr inWindow) -> None"},
2459 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
2460 "(WindowPtr inWindow) -> None"},
2461 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
2462 "(WindowPtr inWindow) -> None"},
2464 #if TARGET_API_MAC_CARBON
2465 {"SetAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_SetAutomaticControlDragTrackingEnabledForWindow, 1,
2466 "(WindowPtr theWindow, Boolean tracks) -> None"},
2467 #endif
2469 #if TARGET_API_MAC_CARBON
2470 {"IsAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_IsAutomaticControlDragTrackingEnabledForWindow, 1,
2471 "(WindowPtr theWindow) -> (Boolean tracks)"},
2472 #endif
2473 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
2474 "(Handle h) -> (ControlHandle _rv)"},
2475 {NULL, NULL, 0}
2480 static PyObject *
2481 CtlObj_NewUnmanaged(ControlHandle itself)
2483 ControlObject *it;
2484 if (itself == NULL) return PyMac_Error(resNotFound);
2485 it = PyObject_NEW(ControlObject, &Control_Type);
2486 if (it == NULL) return NULL;
2487 it->ob_itself = itself;
2488 it->ob_callbackdict = NULL;
2489 return (PyObject *)it;
2492 static PyObject *
2493 CtlObj_WhichControl(ControlHandle c)
2495 PyObject *it;
2497 if (c == NULL)
2498 it = Py_None;
2499 else {
2500 it = (PyObject *) GetControlReference(c);
2502 ** If the refcon is zero or doesn't point back to the Python object
2503 ** the control is not ours. Return a temporary object.
2505 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
2506 return CtlObj_NewUnmanaged(c);
2508 Py_INCREF(it);
2509 return it;
2512 static int
2513 settrackfunc(PyObject *obj)
2515 if (tracker) {
2516 PyErr_SetString(Ctl_Error, "Tracker function in use");
2517 return 0;
2519 tracker = obj;
2520 Py_INCREF(tracker);
2523 static void
2524 clrtrackfunc(void)
2526 Py_XDECREF(tracker);
2527 tracker = 0;
2530 static pascal void
2531 mytracker(ControlHandle ctl, short part)
2533 PyObject *args, *rv=0;
2535 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
2536 if (args && tracker) {
2537 rv = PyEval_CallObject(tracker, args);
2538 Py_DECREF(args);
2540 if (rv)
2541 Py_DECREF(rv);
2542 else
2543 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
2546 static int
2547 setcallback(PyObject *myself, OSType which, PyObject *callback, UniversalProcPtr *uppp)
2549 ControlObject *self = (ControlObject *)myself;
2550 char keybuf[9];
2552 if ( which == kControlUserPaneDrawProcTag )
2553 *uppp = (UniversalProcPtr)mydrawproc_upp;
2554 else if ( which == kControlUserPaneIdleProcTag )
2555 *uppp = (UniversalProcPtr)myidleproc_upp;
2556 else if ( which == kControlUserPaneHitTestProcTag )
2557 *uppp = (UniversalProcPtr)myhittestproc_upp;
2558 else if ( which == kControlUserPaneTrackingProcTag )
2559 *uppp = (UniversalProcPtr)mytrackingproc_upp;
2560 else
2561 return -1;
2562 /* Only now do we test for clearing of the callback: */
2563 if ( callback == Py_None )
2564 *uppp = NULL;
2565 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
2566 if ( self->ob_callbackdict == NULL )
2567 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
2568 return -1;
2569 /* And store the Python callback */
2570 sprintf(keybuf, "%x", which);
2571 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
2572 return -1;
2573 return 0;
2576 static PyObject *
2577 callcallback(ControlObject *self, OSType which, PyObject *arglist)
2579 char keybuf[9];
2580 PyObject *func, *rv;
2582 sprintf(keybuf, "%x", which);
2583 if ( self->ob_callbackdict == NULL ||
2584 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
2585 PySys_WriteStderr("Control callback %x without callback object\n", which);
2586 return NULL;
2588 rv = PyEval_CallObject(func, arglist);
2589 if ( rv == NULL )
2590 PySys_WriteStderr("Exception in control callback %x handler\n", which);
2591 return rv;
2594 static pascal void
2595 mydrawproc(ControlHandle control, SInt16 part)
2597 ControlObject *ctl_obj;
2598 PyObject *arglist, *rv;
2600 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2601 arglist = Py_BuildValue("Oh", ctl_obj, part);
2602 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2603 Py_XDECREF(arglist);
2604 Py_XDECREF(rv);
2607 static pascal void
2608 myidleproc(ControlHandle control)
2610 ControlObject *ctl_obj;
2611 PyObject *arglist, *rv;
2613 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2614 arglist = Py_BuildValue("O", ctl_obj);
2615 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2616 Py_XDECREF(arglist);
2617 Py_XDECREF(rv);
2620 static pascal ControlPartCode
2621 myhittestproc(ControlHandle control, Point where)
2623 ControlObject *ctl_obj;
2624 PyObject *arglist, *rv;
2625 short c_rv = -1;
2627 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2628 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
2629 rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
2630 Py_XDECREF(arglist);
2631 /* Ignore errors, nothing we can do about them */
2632 if ( rv )
2633 PyArg_Parse(rv, "h", &c_rv);
2634 Py_XDECREF(rv);
2635 return (ControlPartCode)c_rv;
2638 static pascal ControlPartCode
2639 mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
2641 ControlObject *ctl_obj;
2642 PyObject *arglist, *rv;
2643 short c_rv = -1;
2645 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2646 /* We cannot pass the actionProc without lots of work */
2647 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
2648 rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
2649 Py_XDECREF(arglist);
2650 if ( rv )
2651 PyArg_Parse(rv, "h", &c_rv);
2652 Py_XDECREF(rv);
2653 return (ControlPartCode)c_rv;
2657 void initCtl(void)
2659 PyObject *m;
2660 PyObject *d;
2664 mytracker_upp = NewControlActionUPP(mytracker);
2665 mydrawproc_upp = NewControlUserPaneDrawUPP(mydrawproc);
2666 myidleproc_upp = NewControlUserPaneIdleUPP(myidleproc);
2667 myhittestproc_upp = NewControlUserPaneHitTestUPP(myhittestproc);
2668 mytrackingproc_upp = NewControlUserPaneTrackingUPP(mytrackingproc);
2669 PyMac_INIT_TOOLBOX_OBJECT_NEW(ControlHandle, CtlObj_New);
2670 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ControlHandle, CtlObj_Convert);
2673 m = Py_InitModule("Ctl", Ctl_methods);
2674 d = PyModule_GetDict(m);
2675 Ctl_Error = PyMac_GetOSErrException();
2676 if (Ctl_Error == NULL ||
2677 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
2678 return;
2679 Control_Type.ob_type = &PyType_Type;
2680 Py_INCREF(&Control_Type);
2681 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2682 Py_FatalError("can't initialize ControlType");
2685 /* ========================= End module Ctl ========================= */