2 /* =========================== Module Ctl =========================== */
9 #include "pymactoolbox.h"
11 #ifdef WITHOUT_FRAMEWORKS
13 #include <ControlDefinitions.h>
15 #include <Carbon/Carbon.h>
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
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)
33 #define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
37 ** Parse/generate ControlFontStyleRec records
39 #if 0 /* Not needed */
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
);
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
63 PyControlID_New(ControlID
*itself
)
66 return Py_BuildValue("O&l", PyMac_BuildOSType
, itself
->signature
, itself
->id
);
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
{
98 ControlHandle ob_itself
;
99 PyObject
*ob_callbackdict
;
102 PyObject
*CtlObj_New(ControlHandle itself
)
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");
120 *p_itself
= ((ControlObject
*)v
)->ob_itself
;
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 */
131 static PyObject
*CtlObj_HiliteControl(ControlObject
*_self
, PyObject
*_args
)
133 PyObject
*_res
= NULL
;
134 ControlPartCode hiliteState
;
135 if (!PyArg_ParseTuple(_args
, "h",
138 HiliteControl(_self
->ob_itself
,
145 static PyObject
*CtlObj_ShowControl(ControlObject
*_self
, PyObject
*_args
)
147 PyObject
*_res
= NULL
;
148 if (!PyArg_ParseTuple(_args
, ""))
150 ShowControl(_self
->ob_itself
);
156 static PyObject
*CtlObj_HideControl(ControlObject
*_self
, PyObject
*_args
)
158 PyObject
*_res
= NULL
;
159 if (!PyArg_ParseTuple(_args
, ""))
161 HideControl(_self
->ob_itself
);
167 static PyObject
*CtlObj_IsControlActive(ControlObject
*_self
, PyObject
*_args
)
169 PyObject
*_res
= NULL
;
171 if (!PyArg_ParseTuple(_args
, ""))
173 _rv
= IsControlActive(_self
->ob_itself
);
174 _res
= Py_BuildValue("b",
179 static PyObject
*CtlObj_IsControlVisible(ControlObject
*_self
, PyObject
*_args
)
181 PyObject
*_res
= NULL
;
183 if (!PyArg_ParseTuple(_args
, ""))
185 _rv
= IsControlVisible(_self
->ob_itself
);
186 _res
= Py_BuildValue("b",
191 static PyObject
*CtlObj_ActivateControl(ControlObject
*_self
, PyObject
*_args
)
193 PyObject
*_res
= NULL
;
195 if (!PyArg_ParseTuple(_args
, ""))
197 _err
= ActivateControl(_self
->ob_itself
);
198 if (_err
!= noErr
) return PyMac_Error(_err
);
204 static PyObject
*CtlObj_DeactivateControl(ControlObject
*_self
, PyObject
*_args
)
206 PyObject
*_res
= NULL
;
208 if (!PyArg_ParseTuple(_args
, ""))
210 _err
= DeactivateControl(_self
->ob_itself
);
211 if (_err
!= noErr
) return PyMac_Error(_err
);
217 static PyObject
*CtlObj_SetControlVisibility(ControlObject
*_self
, PyObject
*_args
)
219 PyObject
*_res
= NULL
;
223 if (!PyArg_ParseTuple(_args
, "bb",
227 _err
= SetControlVisibility(_self
->ob_itself
,
230 if (_err
!= noErr
) return PyMac_Error(_err
);
236 static PyObject
*CtlObj_Draw1Control(ControlObject
*_self
, PyObject
*_args
)
238 PyObject
*_res
= NULL
;
239 if (!PyArg_ParseTuple(_args
, ""))
241 Draw1Control(_self
->ob_itself
);
247 static PyObject
*CtlObj_GetBestControlRect(ControlObject
*_self
, PyObject
*_args
)
249 PyObject
*_res
= NULL
;
252 SInt16 outBaseLineOffset
;
253 if (!PyArg_ParseTuple(_args
, ""))
255 _err
= GetBestControlRect(_self
->ob_itself
,
258 if (_err
!= noErr
) return PyMac_Error(_err
);
259 _res
= Py_BuildValue("O&h",
260 PyMac_BuildRect
, &outRect
,
265 static PyObject
*CtlObj_SetControlFontStyle(ControlObject
*_self
, PyObject
*_args
)
267 PyObject
*_res
= NULL
;
269 ControlFontStyleRec inStyle
;
270 if (!PyArg_ParseTuple(_args
, "O&",
271 ControlFontStyle_Convert
, &inStyle
))
273 _err
= SetControlFontStyle(_self
->ob_itself
,
275 if (_err
!= noErr
) return PyMac_Error(_err
);
281 static PyObject
*CtlObj_DrawControlInCurrentPort(ControlObject
*_self
, PyObject
*_args
)
283 PyObject
*_res
= NULL
;
284 if (!PyArg_ParseTuple(_args
, ""))
286 DrawControlInCurrentPort(_self
->ob_itself
);
292 static PyObject
*CtlObj_SetUpControlBackground(ControlObject
*_self
, PyObject
*_args
)
294 PyObject
*_res
= NULL
;
297 Boolean inIsColorDevice
;
298 if (!PyArg_ParseTuple(_args
, "hb",
302 _err
= SetUpControlBackground(_self
->ob_itself
,
305 if (_err
!= noErr
) return PyMac_Error(_err
);
311 static PyObject
*CtlObj_SetUpControlTextColor(ControlObject
*_self
, PyObject
*_args
)
313 PyObject
*_res
= NULL
;
316 Boolean inIsColorDevice
;
317 if (!PyArg_ParseTuple(_args
, "hb",
321 _err
= SetUpControlTextColor(_self
->ob_itself
,
324 if (_err
!= noErr
) return PyMac_Error(_err
);
330 static PyObject
*CtlObj_DragControl(ControlObject
*_self
, PyObject
*_args
)
332 PyObject
*_res
= NULL
;
337 if (!PyArg_ParseTuple(_args
, "O&O&O&H",
338 PyMac_GetPoint
, &startPoint
,
339 PyMac_GetRect
, &limitRect
,
340 PyMac_GetRect
, &slopRect
,
343 DragControl(_self
->ob_itself
,
353 static PyObject
*CtlObj_TestControl(ControlObject
*_self
, PyObject
*_args
)
355 PyObject
*_res
= NULL
;
358 if (!PyArg_ParseTuple(_args
, "O&",
359 PyMac_GetPoint
, &testPoint
))
361 _rv
= TestControl(_self
->ob_itself
,
363 _res
= Py_BuildValue("h",
368 #if TARGET_API_MAC_CARBON
370 static PyObject
*CtlObj_HandleControlContextualMenuClick(ControlObject
*_self
, PyObject
*_args
)
372 PyObject
*_res
= NULL
;
375 Boolean menuDisplayed
;
376 if (!PyArg_ParseTuple(_args
, "O&",
377 PyMac_GetPoint
, &inWhere
))
379 _err
= HandleControlContextualMenuClick(_self
->ob_itself
,
382 if (_err
!= noErr
) return PyMac_Error(_err
);
383 _res
= Py_BuildValue("b",
389 #if TARGET_API_MAC_CARBON
391 static PyObject
*CtlObj_GetControlClickActivation(ControlObject
*_self
, PyObject
*_args
)
393 PyObject
*_res
= NULL
;
396 EventModifiers inModifiers
;
397 ClickActivationResult outResult
;
398 if (!PyArg_ParseTuple(_args
, "O&H",
399 PyMac_GetPoint
, &inWhere
,
402 _err
= GetControlClickActivation(_self
->ob_itself
,
406 if (_err
!= noErr
) return PyMac_Error(_err
);
407 _res
= Py_BuildValue("l",
413 static PyObject
*CtlObj_HandleControlKey(ControlObject
*_self
, PyObject
*_args
)
415 PyObject
*_res
= NULL
;
419 EventModifiers inModifiers
;
420 if (!PyArg_ParseTuple(_args
, "hhH",
425 _rv
= HandleControlKey(_self
->ob_itself
,
429 _res
= Py_BuildValue("h",
434 #if TARGET_API_MAC_CARBON
436 static PyObject
*CtlObj_HandleControlSetCursor(ControlObject
*_self
, PyObject
*_args
)
438 PyObject
*_res
= NULL
;
441 EventModifiers modifiers
;
442 Boolean cursorWasSet
;
443 if (!PyArg_ParseTuple(_args
, "O&H",
444 PyMac_GetPoint
, &localPoint
,
447 _err
= HandleControlSetCursor(_self
->ob_itself
,
451 if (_err
!= noErr
) return PyMac_Error(_err
);
452 _res
= Py_BuildValue("b",
458 static PyObject
*CtlObj_MoveControl(ControlObject
*_self
, PyObject
*_args
)
460 PyObject
*_res
= NULL
;
463 if (!PyArg_ParseTuple(_args
, "hh",
467 MoveControl(_self
->ob_itself
,
475 static PyObject
*CtlObj_SizeControl(ControlObject
*_self
, PyObject
*_args
)
477 PyObject
*_res
= NULL
;
480 if (!PyArg_ParseTuple(_args
, "hh",
484 SizeControl(_self
->ob_itself
,
492 static PyObject
*CtlObj_SetControlTitle(ControlObject
*_self
, PyObject
*_args
)
494 PyObject
*_res
= NULL
;
496 if (!PyArg_ParseTuple(_args
, "O&",
497 PyMac_GetStr255
, title
))
499 SetControlTitle(_self
->ob_itself
,
506 static PyObject
*CtlObj_GetControlTitle(ControlObject
*_self
, PyObject
*_args
)
508 PyObject
*_res
= NULL
;
510 if (!PyArg_ParseTuple(_args
, ""))
512 GetControlTitle(_self
->ob_itself
,
514 _res
= Py_BuildValue("O&",
515 PyMac_BuildStr255
, title
);
519 static PyObject
*CtlObj_GetControlValue(ControlObject
*_self
, PyObject
*_args
)
521 PyObject
*_res
= NULL
;
523 if (!PyArg_ParseTuple(_args
, ""))
525 _rv
= GetControlValue(_self
->ob_itself
);
526 _res
= Py_BuildValue("h",
531 static PyObject
*CtlObj_SetControlValue(ControlObject
*_self
, PyObject
*_args
)
533 PyObject
*_res
= NULL
;
535 if (!PyArg_ParseTuple(_args
, "h",
538 SetControlValue(_self
->ob_itself
,
545 static PyObject
*CtlObj_GetControlMinimum(ControlObject
*_self
, PyObject
*_args
)
547 PyObject
*_res
= NULL
;
549 if (!PyArg_ParseTuple(_args
, ""))
551 _rv
= GetControlMinimum(_self
->ob_itself
);
552 _res
= Py_BuildValue("h",
557 static PyObject
*CtlObj_SetControlMinimum(ControlObject
*_self
, PyObject
*_args
)
559 PyObject
*_res
= NULL
;
561 if (!PyArg_ParseTuple(_args
, "h",
564 SetControlMinimum(_self
->ob_itself
,
571 static PyObject
*CtlObj_GetControlMaximum(ControlObject
*_self
, PyObject
*_args
)
573 PyObject
*_res
= NULL
;
575 if (!PyArg_ParseTuple(_args
, ""))
577 _rv
= GetControlMaximum(_self
->ob_itself
);
578 _res
= Py_BuildValue("h",
583 static PyObject
*CtlObj_SetControlMaximum(ControlObject
*_self
, PyObject
*_args
)
585 PyObject
*_res
= NULL
;
587 if (!PyArg_ParseTuple(_args
, "h",
590 SetControlMaximum(_self
->ob_itself
,
597 static PyObject
*CtlObj_GetControlViewSize(ControlObject
*_self
, PyObject
*_args
)
599 PyObject
*_res
= NULL
;
601 if (!PyArg_ParseTuple(_args
, ""))
603 _rv
= GetControlViewSize(_self
->ob_itself
);
604 _res
= Py_BuildValue("l",
609 static PyObject
*CtlObj_SetControlViewSize(ControlObject
*_self
, PyObject
*_args
)
611 PyObject
*_res
= NULL
;
613 if (!PyArg_ParseTuple(_args
, "l",
616 SetControlViewSize(_self
->ob_itself
,
623 static PyObject
*CtlObj_GetControl32BitValue(ControlObject
*_self
, PyObject
*_args
)
625 PyObject
*_res
= NULL
;
627 if (!PyArg_ParseTuple(_args
, ""))
629 _rv
= GetControl32BitValue(_self
->ob_itself
);
630 _res
= Py_BuildValue("l",
635 static PyObject
*CtlObj_SetControl32BitValue(ControlObject
*_self
, PyObject
*_args
)
637 PyObject
*_res
= NULL
;
639 if (!PyArg_ParseTuple(_args
, "l",
642 SetControl32BitValue(_self
->ob_itself
,
649 static PyObject
*CtlObj_GetControl32BitMaximum(ControlObject
*_self
, PyObject
*_args
)
651 PyObject
*_res
= NULL
;
653 if (!PyArg_ParseTuple(_args
, ""))
655 _rv
= GetControl32BitMaximum(_self
->ob_itself
);
656 _res
= Py_BuildValue("l",
661 static PyObject
*CtlObj_SetControl32BitMaximum(ControlObject
*_self
, PyObject
*_args
)
663 PyObject
*_res
= NULL
;
665 if (!PyArg_ParseTuple(_args
, "l",
668 SetControl32BitMaximum(_self
->ob_itself
,
675 static PyObject
*CtlObj_GetControl32BitMinimum(ControlObject
*_self
, PyObject
*_args
)
677 PyObject
*_res
= NULL
;
679 if (!PyArg_ParseTuple(_args
, ""))
681 _rv
= GetControl32BitMinimum(_self
->ob_itself
);
682 _res
= Py_BuildValue("l",
687 static PyObject
*CtlObj_SetControl32BitMinimum(ControlObject
*_self
, PyObject
*_args
)
689 PyObject
*_res
= NULL
;
691 if (!PyArg_ParseTuple(_args
, "l",
694 SetControl32BitMinimum(_self
->ob_itself
,
701 static PyObject
*CtlObj_IsValidControlHandle(ControlObject
*_self
, PyObject
*_args
)
703 PyObject
*_res
= NULL
;
705 if (!PyArg_ParseTuple(_args
, ""))
707 _rv
= IsValidControlHandle(_self
->ob_itself
);
708 _res
= Py_BuildValue("b",
713 #if TARGET_API_MAC_CARBON
715 static PyObject
*CtlObj_SetControlID(ControlObject
*_self
, PyObject
*_args
)
717 PyObject
*_res
= NULL
;
720 if (!PyArg_ParseTuple(_args
, "O&",
721 PyControlID_Convert
, &inID
))
723 _err
= SetControlID(_self
->ob_itself
,
725 if (_err
!= noErr
) return PyMac_Error(_err
);
732 #if TARGET_API_MAC_CARBON
734 static PyObject
*CtlObj_GetControlID(ControlObject
*_self
, PyObject
*_args
)
736 PyObject
*_res
= NULL
;
739 if (!PyArg_ParseTuple(_args
, ""))
741 _err
= GetControlID(_self
->ob_itself
,
743 if (_err
!= noErr
) return PyMac_Error(_err
);
744 _res
= Py_BuildValue("O&",
745 PyControlID_New
, &outID
);
750 static PyObject
*CtlObj_RemoveControlProperty(ControlObject
*_self
, PyObject
*_args
)
752 PyObject
*_res
= NULL
;
754 OSType propertyCreator
;
756 if (!PyArg_ParseTuple(_args
, "O&O&",
757 PyMac_GetOSType
, &propertyCreator
,
758 PyMac_GetOSType
, &propertyTag
))
760 _err
= RemoveControlProperty(_self
->ob_itself
,
763 if (_err
!= noErr
) return PyMac_Error(_err
);
769 #if TARGET_API_MAC_CARBON
771 static PyObject
*CtlObj_GetControlPropertyAttributes(ControlObject
*_self
, PyObject
*_args
)
773 PyObject
*_res
= NULL
;
775 OSType propertyCreator
;
778 if (!PyArg_ParseTuple(_args
, "O&O&",
779 PyMac_GetOSType
, &propertyCreator
,
780 PyMac_GetOSType
, &propertyTag
))
782 _err
= GetControlPropertyAttributes(_self
->ob_itself
,
786 if (_err
!= noErr
) return PyMac_Error(_err
);
787 _res
= Py_BuildValue("l",
793 #if TARGET_API_MAC_CARBON
795 static PyObject
*CtlObj_ChangeControlPropertyAttributes(ControlObject
*_self
, PyObject
*_args
)
797 PyObject
*_res
= NULL
;
799 OSType propertyCreator
;
801 UInt32 attributesToSet
;
802 UInt32 attributesToClear
;
803 if (!PyArg_ParseTuple(_args
, "O&O&ll",
804 PyMac_GetOSType
, &propertyCreator
,
805 PyMac_GetOSType
, &propertyTag
,
809 _err
= ChangeControlPropertyAttributes(_self
->ob_itself
,
814 if (_err
!= noErr
) return PyMac_Error(_err
);
821 static PyObject
*CtlObj_GetControlRegion(ControlObject
*_self
, PyObject
*_args
)
823 PyObject
*_res
= NULL
;
825 ControlPartCode inPart
;
827 if (!PyArg_ParseTuple(_args
, "hO&",
829 ResObj_Convert
, &outRegion
))
831 _err
= GetControlRegion(_self
->ob_itself
,
834 if (_err
!= noErr
) return PyMac_Error(_err
);
840 static PyObject
*CtlObj_GetControlVariant(ControlObject
*_self
, PyObject
*_args
)
842 PyObject
*_res
= NULL
;
844 if (!PyArg_ParseTuple(_args
, ""))
846 _rv
= GetControlVariant(_self
->ob_itself
);
847 _res
= Py_BuildValue("h",
852 static PyObject
*CtlObj_SetControlReference(ControlObject
*_self
, PyObject
*_args
)
854 PyObject
*_res
= NULL
;
856 if (!PyArg_ParseTuple(_args
, "l",
859 SetControlReference(_self
->ob_itself
,
866 static PyObject
*CtlObj_GetControlReference(ControlObject
*_self
, PyObject
*_args
)
868 PyObject
*_res
= NULL
;
870 if (!PyArg_ParseTuple(_args
, ""))
872 _rv
= GetControlReference(_self
->ob_itself
);
873 _res
= Py_BuildValue("l",
878 #if !TARGET_API_MAC_CARBON
880 static PyObject
*CtlObj_GetAuxiliaryControlRecord(ControlObject
*_self
, PyObject
*_args
)
882 PyObject
*_res
= NULL
;
885 if (!PyArg_ParseTuple(_args
, ""))
887 _rv
= GetAuxiliaryControlRecord(_self
->ob_itself
,
889 _res
= Py_BuildValue("bO&",
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
))
905 SetControlColor(_self
->ob_itself
,
913 static PyObject
*CtlObj_EmbedControl(ControlObject
*_self
, PyObject
*_args
)
915 PyObject
*_res
= NULL
;
917 ControlHandle inContainer
;
918 if (!PyArg_ParseTuple(_args
, "O&",
919 CtlObj_Convert
, &inContainer
))
921 _err
= EmbedControl(_self
->ob_itself
,
923 if (_err
!= noErr
) return PyMac_Error(_err
);
929 static PyObject
*CtlObj_AutoEmbedControl(ControlObject
*_self
, PyObject
*_args
)
931 PyObject
*_res
= NULL
;
934 if (!PyArg_ParseTuple(_args
, "O&",
935 WinObj_Convert
, &inWindow
))
937 _err
= AutoEmbedControl(_self
->ob_itself
,
939 if (_err
!= noErr
) return PyMac_Error(_err
);
945 static PyObject
*CtlObj_GetSuperControl(ControlObject
*_self
, PyObject
*_args
)
947 PyObject
*_res
= NULL
;
949 ControlHandle outParent
;
950 if (!PyArg_ParseTuple(_args
, ""))
952 _err
= GetSuperControl(_self
->ob_itself
,
954 if (_err
!= noErr
) return PyMac_Error(_err
);
955 _res
= Py_BuildValue("O&",
956 CtlObj_WhichControl
, outParent
);
960 static PyObject
*CtlObj_CountSubControls(ControlObject
*_self
, PyObject
*_args
)
962 PyObject
*_res
= NULL
;
964 UInt16 outNumChildren
;
965 if (!PyArg_ParseTuple(_args
, ""))
967 _err
= CountSubControls(_self
->ob_itself
,
969 if (_err
!= noErr
) return PyMac_Error(_err
);
970 _res
= Py_BuildValue("H",
975 static PyObject
*CtlObj_GetIndexedSubControl(ControlObject
*_self
, PyObject
*_args
)
977 PyObject
*_res
= NULL
;
980 ControlHandle outSubControl
;
981 if (!PyArg_ParseTuple(_args
, "H",
984 _err
= GetIndexedSubControl(_self
->ob_itself
,
987 if (_err
!= noErr
) return PyMac_Error(_err
);
988 _res
= Py_BuildValue("O&",
989 CtlObj_WhichControl
, outSubControl
);
993 static PyObject
*CtlObj_SetControlSupervisor(ControlObject
*_self
, PyObject
*_args
)
995 PyObject
*_res
= NULL
;
997 ControlHandle inBoss
;
998 if (!PyArg_ParseTuple(_args
, "O&",
999 CtlObj_Convert
, &inBoss
))
1001 _err
= SetControlSupervisor(_self
->ob_itself
,
1003 if (_err
!= noErr
) return PyMac_Error(_err
);
1009 static PyObject
*CtlObj_GetControlFeatures(ControlObject
*_self
, PyObject
*_args
)
1011 PyObject
*_res
= NULL
;
1014 if (!PyArg_ParseTuple(_args
, ""))
1016 _err
= GetControlFeatures(_self
->ob_itself
,
1018 if (_err
!= noErr
) return PyMac_Error(_err
);
1019 _res
= Py_BuildValue("l",
1024 static PyObject
*CtlObj_GetControlDataSize(ControlObject
*_self
, PyObject
*_args
)
1026 PyObject
*_res
= NULL
;
1028 ControlPartCode inPart
;
1031 if (!PyArg_ParseTuple(_args
, "hO&",
1033 PyMac_GetOSType
, &inTagName
))
1035 _err
= GetControlDataSize(_self
->ob_itself
,
1039 if (_err
!= noErr
) return PyMac_Error(_err
);
1040 _res
= Py_BuildValue("l",
1045 #if TARGET_API_MAC_CARBON
1047 static PyObject
*CtlObj_HandleControlDragTracking(ControlObject
*_self
, PyObject
*_args
)
1049 PyObject
*_res
= NULL
;
1051 DragTrackingMessage inMessage
;
1052 DragReference inDrag
;
1053 Boolean outLikesDrag
;
1054 if (!PyArg_ParseTuple(_args
, "hO&",
1056 DragObj_Convert
, &inDrag
))
1058 _err
= HandleControlDragTracking(_self
->ob_itself
,
1062 if (_err
!= noErr
) return PyMac_Error(_err
);
1063 _res
= Py_BuildValue("b",
1069 #if TARGET_API_MAC_CARBON
1071 static PyObject
*CtlObj_HandleControlDragReceive(ControlObject
*_self
, PyObject
*_args
)
1073 PyObject
*_res
= NULL
;
1075 DragReference inDrag
;
1076 if (!PyArg_ParseTuple(_args
, "O&",
1077 DragObj_Convert
, &inDrag
))
1079 _err
= HandleControlDragReceive(_self
->ob_itself
,
1081 if (_err
!= noErr
) return PyMac_Error(_err
);
1088 #if TARGET_API_MAC_CARBON
1090 static PyObject
*CtlObj_SetControlDragTrackingEnabled(ControlObject
*_self
, PyObject
*_args
)
1092 PyObject
*_res
= NULL
;
1095 if (!PyArg_ParseTuple(_args
, "b",
1098 _err
= SetControlDragTrackingEnabled(_self
->ob_itself
,
1100 if (_err
!= noErr
) return PyMac_Error(_err
);
1107 #if TARGET_API_MAC_CARBON
1109 static PyObject
*CtlObj_IsControlDragTrackingEnabled(ControlObject
*_self
, PyObject
*_args
)
1111 PyObject
*_res
= NULL
;
1114 if (!PyArg_ParseTuple(_args
, ""))
1116 _err
= IsControlDragTrackingEnabled(_self
->ob_itself
,
1118 if (_err
!= noErr
) return PyMac_Error(_err
);
1119 _res
= Py_BuildValue("b",
1125 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1127 static PyObject
*CtlObj_GetControlBounds(ControlObject
*_self
, PyObject
*_args
)
1129 PyObject
*_res
= NULL
;
1131 if (!PyArg_ParseTuple(_args
, ""))
1133 GetControlBounds(_self
->ob_itself
,
1135 _res
= Py_BuildValue("O&",
1136 PyMac_BuildRect
, &bounds
);
1141 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1143 static PyObject
*CtlObj_IsControlHilited(ControlObject
*_self
, PyObject
*_args
)
1145 PyObject
*_res
= NULL
;
1147 if (!PyArg_ParseTuple(_args
, ""))
1149 _rv
= IsControlHilited(_self
->ob_itself
);
1150 _res
= Py_BuildValue("b",
1156 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1158 static PyObject
*CtlObj_GetControlHilite(ControlObject
*_self
, PyObject
*_args
)
1160 PyObject
*_res
= NULL
;
1162 if (!PyArg_ParseTuple(_args
, ""))
1164 _rv
= GetControlHilite(_self
->ob_itself
);
1165 _res
= Py_BuildValue("H",
1171 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1173 static PyObject
*CtlObj_GetControlOwner(ControlObject
*_self
, PyObject
*_args
)
1175 PyObject
*_res
= NULL
;
1177 if (!PyArg_ParseTuple(_args
, ""))
1179 _rv
= GetControlOwner(_self
->ob_itself
);
1180 _res
= Py_BuildValue("O&",
1186 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1188 static PyObject
*CtlObj_GetControlDataHandle(ControlObject
*_self
, PyObject
*_args
)
1190 PyObject
*_res
= NULL
;
1192 if (!PyArg_ParseTuple(_args
, ""))
1194 _rv
= GetControlDataHandle(_self
->ob_itself
);
1195 _res
= Py_BuildValue("O&",
1201 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1203 static PyObject
*CtlObj_GetControlPopupMenuHandle(ControlObject
*_self
, PyObject
*_args
)
1205 PyObject
*_res
= NULL
;
1207 if (!PyArg_ParseTuple(_args
, ""))
1209 _rv
= GetControlPopupMenuHandle(_self
->ob_itself
);
1210 _res
= Py_BuildValue("O&",
1216 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1218 static PyObject
*CtlObj_GetControlPopupMenuID(ControlObject
*_self
, PyObject
*_args
)
1220 PyObject
*_res
= NULL
;
1222 if (!PyArg_ParseTuple(_args
, ""))
1224 _rv
= GetControlPopupMenuID(_self
->ob_itself
);
1225 _res
= Py_BuildValue("h",
1231 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1233 static PyObject
*CtlObj_SetControlDataHandle(ControlObject
*_self
, PyObject
*_args
)
1235 PyObject
*_res
= NULL
;
1237 if (!PyArg_ParseTuple(_args
, "O&",
1238 ResObj_Convert
, &dataHandle
))
1240 SetControlDataHandle(_self
->ob_itself
,
1248 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1250 static PyObject
*CtlObj_SetControlBounds(ControlObject
*_self
, PyObject
*_args
)
1252 PyObject
*_res
= NULL
;
1254 if (!PyArg_ParseTuple(_args
, "O&",
1255 PyMac_GetRect
, &bounds
))
1257 SetControlBounds(_self
->ob_itself
,
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
))
1274 SetControlPopupMenuHandle(_self
->ob_itself
,
1282 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1284 static PyObject
*CtlObj_SetControlPopupMenuID(ControlObject
*_self
, PyObject
*_args
)
1286 PyObject
*_res
= NULL
;
1288 if (!PyArg_ParseTuple(_args
, "h",
1291 SetControlPopupMenuID(_self
->ob_itself
,
1299 static PyObject
*CtlObj_GetBevelButtonMenuValue(ControlObject
*_self
, PyObject
*_args
)
1301 PyObject
*_res
= NULL
;
1304 if (!PyArg_ParseTuple(_args
, ""))
1306 _err
= GetBevelButtonMenuValue(_self
->ob_itself
,
1308 if (_err
!= noErr
) return PyMac_Error(_err
);
1309 _res
= Py_BuildValue("h",
1314 static PyObject
*CtlObj_SetBevelButtonMenuValue(ControlObject
*_self
, PyObject
*_args
)
1316 PyObject
*_res
= NULL
;
1319 if (!PyArg_ParseTuple(_args
, "h",
1322 _err
= SetBevelButtonMenuValue(_self
->ob_itself
,
1324 if (_err
!= noErr
) return PyMac_Error(_err
);
1330 static PyObject
*CtlObj_GetBevelButtonMenuHandle(ControlObject
*_self
, PyObject
*_args
)
1332 PyObject
*_res
= NULL
;
1334 MenuHandle outHandle
;
1335 if (!PyArg_ParseTuple(_args
, ""))
1337 _err
= GetBevelButtonMenuHandle(_self
->ob_itself
,
1339 if (_err
!= noErr
) return PyMac_Error(_err
);
1340 _res
= Py_BuildValue("O&",
1341 MenuObj_New
, outHandle
);
1345 static PyObject
*CtlObj_SetBevelButtonTransform(ControlObject
*_self
, PyObject
*_args
)
1347 PyObject
*_res
= NULL
;
1349 IconTransformType transform
;
1350 if (!PyArg_ParseTuple(_args
, "h",
1353 _err
= SetBevelButtonTransform(_self
->ob_itself
,
1355 if (_err
!= noErr
) return PyMac_Error(_err
);
1361 static PyObject
*CtlObj_SetDisclosureTriangleLastValue(ControlObject
*_self
, PyObject
*_args
)
1363 PyObject
*_res
= NULL
;
1366 if (!PyArg_ParseTuple(_args
, "h",
1369 _err
= SetDisclosureTriangleLastValue(_self
->ob_itself
,
1371 if (_err
!= noErr
) return PyMac_Error(_err
);
1377 static PyObject
*CtlObj_GetTabContentRect(ControlObject
*_self
, PyObject
*_args
)
1379 PyObject
*_res
= NULL
;
1381 Rect outContentRect
;
1382 if (!PyArg_ParseTuple(_args
, ""))
1384 _err
= GetTabContentRect(_self
->ob_itself
,
1386 if (_err
!= noErr
) return PyMac_Error(_err
);
1387 _res
= Py_BuildValue("O&",
1388 PyMac_BuildRect
, &outContentRect
);
1392 static PyObject
*CtlObj_SetTabEnabled(ControlObject
*_self
, PyObject
*_args
)
1394 PyObject
*_res
= NULL
;
1396 SInt16 inTabToHilite
;
1398 if (!PyArg_ParseTuple(_args
, "hb",
1402 _err
= SetTabEnabled(_self
->ob_itself
,
1405 if (_err
!= noErr
) return PyMac_Error(_err
);
1411 static PyObject
*CtlObj_SetImageWellTransform(ControlObject
*_self
, PyObject
*_args
)
1413 PyObject
*_res
= NULL
;
1415 IconTransformType inTransform
;
1416 if (!PyArg_ParseTuple(_args
, "h",
1419 _err
= SetImageWellTransform(_self
->ob_itself
,
1421 if (_err
!= noErr
) return PyMac_Error(_err
);
1427 static PyObject
*CtlObj_as_Resource(ControlObject
*_self
, PyObject
*_args
)
1429 PyObject
*_res
= NULL
;
1431 if (!PyArg_ParseTuple(_args
, ""))
1433 _rv
= as_Resource(_self
->ob_itself
);
1434 _res
= Py_BuildValue("O&",
1439 static PyObject
*CtlObj_GetControlRect(ControlObject
*_self
, PyObject
*_args
)
1441 PyObject
*_res
= NULL
;
1443 if (!PyArg_ParseTuple(_args
, ""))
1445 GetControlRect(_self
->ob_itself
,
1447 _res
= Py_BuildValue("O&",
1448 PyMac_BuildRect
, &rect
);
1452 static PyObject
*CtlObj_DisposeControl(ControlObject
*_self
, PyObject
*_args
)
1454 PyObject
*_res
= NULL
;
1456 if (!PyArg_ParseTuple(_args
, ""))
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
;
1469 static PyObject
*CtlObj_TrackControl(ControlObject
*_self
, PyObject
*_args
)
1471 PyObject
*_res
= NULL
;
1473 ControlPartCode _rv
;
1475 ControlActionUPP upp
= 0;
1476 PyObject
*callback
= 0;
1478 if (!PyArg_ParseTuple(_args
, "O&|O",
1479 PyMac_GetPoint
, &startPoint
, &callback
))
1481 if (callback
&& callback
!= Py_None
) {
1482 if (PyInt_Check(callback
) && PyInt_AS_LONG(callback
) == -1)
1483 upp
= (ControlActionUPP
)-1;
1485 settrackfunc(callback
);
1486 upp
= mytracker_upp
;
1489 _rv
= TrackControl(_self
->ob_itself
,
1493 _res
= Py_BuildValue("h",
1499 static PyObject
*CtlObj_HandleControlClick(ControlObject
*_self
, PyObject
*_args
)
1501 PyObject
*_res
= NULL
;
1503 ControlPartCode _rv
;
1506 ControlActionUPP upp
= 0;
1507 PyObject
*callback
= 0;
1509 if (!PyArg_ParseTuple(_args
, "O&h|O",
1510 PyMac_GetPoint
, &startPoint
,
1514 if (callback
&& callback
!= Py_None
) {
1515 if (PyInt_Check(callback
) && PyInt_AS_LONG(callback
) == -1)
1516 upp
= (ControlActionUPP
)-1;
1518 settrackfunc(callback
);
1519 upp
= mytracker_upp
;
1522 _rv
= HandleControlClick(_self
->ob_itself
,
1527 _res
= Py_BuildValue("h",
1533 static PyObject
*CtlObj_SetControlData(ControlObject
*_self
, PyObject
*_args
)
1535 PyObject
*_res
= NULL
;
1538 ControlPartCode inPart
;
1543 if (!PyArg_ParseTuple(_args
, "hO&s#",
1545 PyMac_GetOSType
, &inTagName
,
1546 &buffer
, &bufferSize
))
1549 _err
= SetControlData(_self
->ob_itself
,
1556 return PyMac_Error(_err
);
1562 static PyObject
*CtlObj_GetControlData(ControlObject
*_self
, PyObject
*_args
)
1564 PyObject
*_res
= NULL
;
1567 ControlPartCode inPart
;
1573 if (!PyArg_ParseTuple(_args
, "hO&",
1575 PyMac_GetOSType
, &inTagName
))
1578 /* allocate a buffer for the data */
1579 _err
= GetControlDataSize(_self
->ob_itself
,
1584 return PyMac_Error(_err
);
1585 buffer
= PyMem_NEW(char, bufferSize
);
1587 return PyErr_NoMemory();
1589 _err
= GetControlData(_self
->ob_itself
,
1596 if (_err
!= noErr
) {
1598 return PyMac_Error(_err
);
1600 _res
= Py_BuildValue("s#", buffer
, outSize
);
1606 static PyObject
*CtlObj_SetControlData_Handle(ControlObject
*_self
, PyObject
*_args
)
1608 PyObject
*_res
= NULL
;
1611 ControlPartCode inPart
;
1615 if (!PyArg_ParseTuple(_args
, "hO&O&",
1617 PyMac_GetOSType
, &inTagName
,
1618 OptResObj_Convert
, &buffer
))
1621 _err
= SetControlData(_self
->ob_itself
,
1628 return PyMac_Error(_err
);
1634 static PyObject
*CtlObj_GetControlData_Handle(ControlObject
*_self
, PyObject
*_args
)
1636 PyObject
*_res
= NULL
;
1639 ControlPartCode inPart
;
1644 if (!PyArg_ParseTuple(_args
, "hO&",
1646 PyMac_GetOSType
, &inTagName
))
1649 /* Check it is handle-sized */
1650 _err
= GetControlDataSize(_self
->ob_itself
,
1655 return PyMac_Error(_err
);
1656 if (bufferSize
!= sizeof(Handle
)) {
1657 PyErr_SetString(Ctl_Error
, "GetControlDataSize() != sizeof(Handle)");
1661 _err
= GetControlData(_self
->ob_itself
,
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
;
1680 ControlPartCode inPart
;
1683 UniversalProcPtr c_callback
;
1685 if (!PyArg_ParseTuple(_args
, "hO&O",
1687 PyMac_GetOSType
, &inTagName
,
1691 if ( setcallback((PyObject
*)_self
, inTagName
, callback
, &c_callback
) < 0 )
1693 _err
= SetControlData(_self
->ob_itself
,
1700 return PyMac_Error(_err
);
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");
1718 hdl
= (PopupPrivateDataHandle
)(*_self
->ob_itself
)->contrlData
;
1720 _res
= Py_BuildValue("O&i", MenuObj_New
, (*hdl
)->mHandle
, (int)(*hdl
)->mID
);
1721 HUnlock((Handle
)hdl
);
1727 #if !TARGET_API_MAC_CARBON
1729 static PyObject
*CtlObj_SetPopupData(ControlObject
*_self
, PyObject
*_args
)
1731 PyObject
*_res
= NULL
;
1733 PopupPrivateDataHandle hdl
;
1737 if (!PyArg_ParseTuple(_args
, "O&h", MenuObj_Convert
, &mHandle
, &mID
) )
1739 if ( (*_self
->ob_itself
)->contrlData
== NULL
) {
1740 PyErr_SetString(Ctl_Error
, "No contrlData handle in control");
1743 hdl
= (PopupPrivateDataHandle
)(*_self
->ob_itself
)->contrlData
;
1744 (*hdl
)->mHandle
= mHandle
;
1752 static PyMethodDef CtlObj_methods
[] = {
1753 {"HiliteControl", (PyCFunction
)CtlObj_HiliteControl
, 1,
1754 "(ControlPartCode hiliteState) -> None"},
1755 {"ShowControl", (PyCFunction
)CtlObj_ShowControl
, 1,
1757 {"HideControl", (PyCFunction
)CtlObj_HideControl
, 1,
1759 {"IsControlActive", (PyCFunction
)CtlObj_IsControlActive
, 1,
1760 "() -> (Boolean _rv)"},
1761 {"IsControlVisible", (PyCFunction
)CtlObj_IsControlVisible
, 1,
1762 "() -> (Boolean _rv)"},
1763 {"ActivateControl", (PyCFunction
)CtlObj_ActivateControl
, 1,
1765 {"DeactivateControl", (PyCFunction
)CtlObj_DeactivateControl
, 1,
1767 {"SetControlVisibility", (PyCFunction
)CtlObj_SetControlVisibility
, 1,
1768 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
1769 {"Draw1Control", (PyCFunction
)CtlObj_Draw1Control
, 1,
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,
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)"},
1791 #if TARGET_API_MAC_CARBON
1792 {"GetControlClickActivation", (PyCFunction
)CtlObj_GetControlClickActivation
, 1,
1793 "(Point inWhere, EventModifiers inModifiers) -> (ClickActivationResult outResult)"},
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)"},
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"},
1846 #if TARGET_API_MAC_CARBON
1847 {"GetControlID", (PyCFunction
)CtlObj_GetControlID
, 1,
1848 "() -> (ControlID outID)"},
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)"},
1858 #if TARGET_API_MAC_CARBON
1859 {"ChangeControlPropertyAttributes", (PyCFunction
)CtlObj_ChangeControlPropertyAttributes
, 1,
1860 "(OSType propertyCreator, OSType propertyTag, UInt32 attributesToSet, UInt32 attributesToClear) -> None"},
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)"},
1876 #if !TARGET_API_MAC_CARBON
1877 {"SetControlColor", (PyCFunction
)CtlObj_SetControlColor
, 1,
1878 "(CCTabHandle newColorTable) -> None"},
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)"},
1902 #if TARGET_API_MAC_CARBON
1903 {"HandleControlDragReceive", (PyCFunction
)CtlObj_HandleControlDragReceive
, 1,
1904 "(DragReference inDrag) -> None"},
1907 #if TARGET_API_MAC_CARBON
1908 {"SetControlDragTrackingEnabled", (PyCFunction
)CtlObj_SetControlDragTrackingEnabled
, 1,
1909 "(Boolean tracks) -> None"},
1912 #if TARGET_API_MAC_CARBON
1913 {"IsControlDragTrackingEnabled", (PyCFunction
)CtlObj_IsControlDragTrackingEnabled
, 1,
1914 "() -> (Boolean tracks)"},
1917 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1918 {"GetControlBounds", (PyCFunction
)CtlObj_GetControlBounds
, 1,
1919 "() -> (Rect bounds)"},
1922 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1923 {"IsControlHilited", (PyCFunction
)CtlObj_IsControlHilited
, 1,
1924 "() -> (Boolean _rv)"},
1927 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1928 {"GetControlHilite", (PyCFunction
)CtlObj_GetControlHilite
, 1,
1929 "() -> (UInt16 _rv)"},
1932 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1933 {"GetControlOwner", (PyCFunction
)CtlObj_GetControlOwner
, 1,
1934 "() -> (WindowPtr _rv)"},
1937 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1938 {"GetControlDataHandle", (PyCFunction
)CtlObj_GetControlDataHandle
, 1,
1939 "() -> (Handle _rv)"},
1942 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1943 {"GetControlPopupMenuHandle", (PyCFunction
)CtlObj_GetControlPopupMenuHandle
, 1,
1944 "() -> (MenuHandle _rv)"},
1947 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1948 {"GetControlPopupMenuID", (PyCFunction
)CtlObj_GetControlPopupMenuID
, 1,
1949 "() -> (short _rv)"},
1952 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1953 {"SetControlDataHandle", (PyCFunction
)CtlObj_SetControlDataHandle
, 1,
1954 "(Handle dataHandle) -> None"},
1957 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1958 {"SetControlBounds", (PyCFunction
)CtlObj_SetControlBounds
, 1,
1959 "(Rect bounds) -> None"},
1962 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1963 {"SetControlPopupMenuHandle", (PyCFunction
)CtlObj_SetControlPopupMenuHandle
, 1,
1964 "(MenuHandle popupMenu) -> None"},
1967 #if ACCESSOR_CALLS_ARE_FUNCTIONS
1968 {"SetControlPopupMenuID", (PyCFunction
)CtlObj_SetControlPopupMenuID
, 1,
1969 "(short menuID) -> None"},
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,
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,
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,
2013 #if !TARGET_API_MAC_CARBON
2014 {"SetPopupData", (PyCFunction
)CtlObj_SetPopupData
, 1,
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
)
2033 if (!CtlObj_Check((PyObject
*)other
))
2035 v
=(unsigned long)self
;
2036 w
=(unsigned long)other
;
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;
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
)
2058 "Control", /*tp_name*/
2059 sizeof(ControlObject
), /*tp_basicsize*/
2062 (destructor
) CtlObj_dealloc
, /*tp_dealloc*/
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
;
2081 WindowPtr owningWindow
;
2083 Str255 controlTitle
;
2084 Boolean initiallyVisible
;
2085 SInt16 initialValue
;
2086 SInt16 minimumValue
;
2087 SInt16 maximumValue
;
2089 SInt32 controlReference
;
2090 if (!PyArg_ParseTuple(_args
, "O&O&O&bhhhhl",
2091 WinObj_Convert
, &owningWindow
,
2092 PyMac_GetRect
, &boundsRect
,
2093 PyMac_GetStr255
, controlTitle
,
2101 _rv
= NewControl(owningWindow
,
2110 _res
= Py_BuildValue("O&",
2115 static PyObject
*Ctl_GetNewControl(PyObject
*_self
, PyObject
*_args
)
2117 PyObject
*_res
= NULL
;
2120 WindowPtr owningWindow
;
2121 if (!PyArg_ParseTuple(_args
, "hO&",
2123 WinObj_Convert
, &owningWindow
))
2125 _rv
= GetNewControl(resourceID
,
2127 _res
= Py_BuildValue("O&",
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
))
2139 DrawControls(theWindow
);
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
))
2154 UpdateControls(theWindow
,
2161 static PyObject
*Ctl_FindControl(PyObject
*_self
, PyObject
*_args
)
2163 PyObject
*_res
= NULL
;
2164 ControlPartCode _rv
;
2166 WindowPtr theWindow
;
2167 ControlHandle theControl
;
2168 if (!PyArg_ParseTuple(_args
, "O&O&",
2169 PyMac_GetPoint
, &testPoint
,
2170 WinObj_Convert
, &theWindow
))
2172 _rv
= FindControl(testPoint
,
2175 _res
= Py_BuildValue("hO&",
2177 CtlObj_WhichControl
, theControl
);
2181 static PyObject
*Ctl_FindControlUnderMouse(PyObject
*_self
, PyObject
*_args
)
2183 PyObject
*_res
= NULL
;
2188 if (!PyArg_ParseTuple(_args
, "O&O&",
2189 PyMac_GetPoint
, &inWhere
,
2190 WinObj_Convert
, &inWindow
))
2192 _rv
= FindControlUnderMouse(inWhere
,
2195 _res
= Py_BuildValue("O&h",
2201 static PyObject
*Ctl_IdleControls(PyObject
*_self
, PyObject
*_args
)
2203 PyObject
*_res
= NULL
;
2205 if (!PyArg_ParseTuple(_args
, "O&",
2206 WinObj_Convert
, &inWindow
))
2208 IdleControls(inWindow
);
2214 #if TARGET_API_MAC_CARBON
2216 static PyObject
*Ctl_GetControlByID(PyObject
*_self
, PyObject
*_args
)
2218 PyObject
*_res
= NULL
;
2222 ControlHandle outControl
;
2223 if (!PyArg_ParseTuple(_args
, "O&O&",
2224 WinObj_Convert
, &inWindow
,
2225 PyControlID_Convert
, &inID
))
2227 _err
= GetControlByID(inWindow
,
2230 if (_err
!= noErr
) return PyMac_Error(_err
);
2231 _res
= Py_BuildValue("O&",
2232 CtlObj_WhichControl
, outControl
);
2237 static PyObject
*Ctl_DumpControlHierarchy(PyObject
*_self
, PyObject
*_args
)
2239 PyObject
*_res
= NULL
;
2243 if (!PyArg_ParseTuple(_args
, "O&O&",
2244 WinObj_Convert
, &inWindow
,
2245 PyMac_GetFSSpec
, &inDumpFile
))
2247 _err
= DumpControlHierarchy(inWindow
,
2249 if (_err
!= noErr
) return PyMac_Error(_err
);
2255 static PyObject
*Ctl_CreateRootControl(PyObject
*_self
, PyObject
*_args
)
2257 PyObject
*_res
= NULL
;
2260 ControlHandle outControl
;
2261 if (!PyArg_ParseTuple(_args
, "O&",
2262 WinObj_Convert
, &inWindow
))
2264 _err
= CreateRootControl(inWindow
,
2266 if (_err
!= noErr
) return PyMac_Error(_err
);
2267 _res
= Py_BuildValue("O&",
2268 CtlObj_WhichControl
, outControl
);
2272 static PyObject
*Ctl_GetRootControl(PyObject
*_self
, PyObject
*_args
)
2274 PyObject
*_res
= NULL
;
2277 ControlHandle outControl
;
2278 if (!PyArg_ParseTuple(_args
, "O&",
2279 WinObj_Convert
, &inWindow
))
2281 _err
= GetRootControl(inWindow
,
2283 if (_err
!= noErr
) return PyMac_Error(_err
);
2284 _res
= Py_BuildValue("O&",
2285 CtlObj_WhichControl
, outControl
);
2289 static PyObject
*Ctl_GetKeyboardFocus(PyObject
*_self
, PyObject
*_args
)
2291 PyObject
*_res
= NULL
;
2294 ControlHandle outControl
;
2295 if (!PyArg_ParseTuple(_args
, "O&",
2296 WinObj_Convert
, &inWindow
))
2298 _err
= GetKeyboardFocus(inWindow
,
2300 if (_err
!= noErr
) return PyMac_Error(_err
);
2301 _res
= Py_BuildValue("O&",
2302 CtlObj_WhichControl
, outControl
);
2306 static PyObject
*Ctl_SetKeyboardFocus(PyObject
*_self
, PyObject
*_args
)
2308 PyObject
*_res
= NULL
;
2311 ControlHandle inControl
;
2312 ControlFocusPart inPart
;
2313 if (!PyArg_ParseTuple(_args
, "O&O&h",
2314 WinObj_Convert
, &inWindow
,
2315 CtlObj_Convert
, &inControl
,
2318 _err
= SetKeyboardFocus(inWindow
,
2321 if (_err
!= noErr
) return PyMac_Error(_err
);
2327 static PyObject
*Ctl_AdvanceKeyboardFocus(PyObject
*_self
, PyObject
*_args
)
2329 PyObject
*_res
= NULL
;
2332 if (!PyArg_ParseTuple(_args
, "O&",
2333 WinObj_Convert
, &inWindow
))
2335 _err
= AdvanceKeyboardFocus(inWindow
);
2336 if (_err
!= noErr
) return PyMac_Error(_err
);
2342 static PyObject
*Ctl_ReverseKeyboardFocus(PyObject
*_self
, PyObject
*_args
)
2344 PyObject
*_res
= NULL
;
2347 if (!PyArg_ParseTuple(_args
, "O&",
2348 WinObj_Convert
, &inWindow
))
2350 _err
= ReverseKeyboardFocus(inWindow
);
2351 if (_err
!= noErr
) return PyMac_Error(_err
);
2357 static PyObject
*Ctl_ClearKeyboardFocus(PyObject
*_self
, PyObject
*_args
)
2359 PyObject
*_res
= NULL
;
2362 if (!PyArg_ParseTuple(_args
, "O&",
2363 WinObj_Convert
, &inWindow
))
2365 _err
= ClearKeyboardFocus(inWindow
);
2366 if (_err
!= noErr
) return PyMac_Error(_err
);
2372 #if TARGET_API_MAC_CARBON
2374 static PyObject
*Ctl_SetAutomaticControlDragTrackingEnabledForWindow(PyObject
*_self
, PyObject
*_args
)
2376 PyObject
*_res
= NULL
;
2378 WindowPtr theWindow
;
2380 if (!PyArg_ParseTuple(_args
, "O&b",
2381 WinObj_Convert
, &theWindow
,
2384 _err
= SetAutomaticControlDragTrackingEnabledForWindow(theWindow
,
2386 if (_err
!= noErr
) return PyMac_Error(_err
);
2393 #if TARGET_API_MAC_CARBON
2395 static PyObject
*Ctl_IsAutomaticControlDragTrackingEnabledForWindow(PyObject
*_self
, PyObject
*_args
)
2397 PyObject
*_res
= NULL
;
2399 WindowPtr theWindow
;
2401 if (!PyArg_ParseTuple(_args
, "O&",
2402 WinObj_Convert
, &theWindow
))
2404 _err
= IsAutomaticControlDragTrackingEnabledForWindow(theWindow
,
2406 if (_err
!= noErr
) return PyMac_Error(_err
);
2407 _res
= Py_BuildValue("b",
2413 static PyObject
*Ctl_as_Control(PyObject
*_self
, PyObject
*_args
)
2415 PyObject
*_res
= NULL
;
2418 if (!PyArg_ParseTuple(_args
, "O&",
2419 ResObj_Convert
, &h
))
2421 _rv
= as_Control(h
);
2422 _res
= Py_BuildValue("O&",
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)"},
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"},
2469 #if TARGET_API_MAC_CARBON
2470 {"IsAutomaticControlDragTrackingEnabledForWindow", (PyCFunction
)Ctl_IsAutomaticControlDragTrackingEnabledForWindow
, 1,
2471 "(WindowPtr theWindow) -> (Boolean tracks)"},
2473 {"as_Control", (PyCFunction
)Ctl_as_Control
, 1,
2474 "(Handle h) -> (ControlHandle _rv)"},
2481 CtlObj_NewUnmanaged(ControlHandle itself
)
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
;
2493 CtlObj_WhichControl(ControlHandle c
)
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
);
2513 settrackfunc(PyObject
*obj
)
2516 PyErr_SetString(Ctl_Error
, "Tracker function in use");
2526 Py_XDECREF(tracker
);
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
);
2543 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
2547 setcallback(PyObject
*myself
, OSType which
, PyObject
*callback
, UniversalProcPtr
*uppp
)
2549 ControlObject
*self
= (ControlObject
*)myself
;
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
;
2562 /* Only now do we test for clearing of the callback: */
2563 if ( callback
== Py_None
)
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
)
2569 /* And store the Python callback */
2570 sprintf(keybuf
, "%x", which
);
2571 if (PyDict_SetItemString(self
->ob_callbackdict
, keybuf
, callback
) < 0)
2577 callcallback(ControlObject
*self
, OSType which
, PyObject
*arglist
)
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
);
2588 rv
= PyEval_CallObject(func
, arglist
);
2590 PySys_WriteStderr("Exception in control callback %x handler\n", which
);
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
);
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
);
2620 static pascal ControlPartCode
2621 myhittestproc(ControlHandle control
, Point where
)
2623 ControlObject
*ctl_obj
;
2624 PyObject
*arglist
, *rv
;
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 */
2633 PyArg_Parse(rv
, "h", &c_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
;
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
);
2651 PyArg_Parse(rv
, "h", &c_rv
);
2653 return (ControlPartCode
)c_rv
;
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)
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 ========================= */