@@ -75,12 +75,12 @@ ControlFontStyle_Convert(v, itself)
7575 ControlFontStyleRec * itself ;
7676{
7777 return PyArg_ParseTuple (v , "hhhhhhO&O&" , & itself -> flags ,
78- & itself -> font , & itself -> size , & itself -> style , & itself -> mode ,
79- & itself -> just , QdRGB_Convert , & itself -> foreColor ,
78+ & itself -> font , & itself -> size , & itself -> style , & itself -> mode ,
79+ & itself -> just , QdRGB_Convert , & itself -> foreColor ,
8080 QdRGB_Convert , & itself -> backColor );
8181}
8282
83- /* TrackControl callback support */
83+ /* TrackControl and HandleControlClick callback support */
8484static PyObject * tracker ;
8585static ControlActionUPP mytracker_upp ;
8686
@@ -127,7 +127,7 @@ CtlObj_Convert(v, p_itself)
127127static void CtlObj_dealloc (self )
128128 ControlObject * self ;
129129{
130- if (self -> ob_itself ) SetControlReference (self -> ob_itself , (long )0 ); /* Make it forget about us */
130+ if (self -> ob_itself )SetControlReference (self -> ob_itself , (long )0 ); /* Make it forget about us */
131131 PyMem_DEL (self );
132132}
133133
@@ -717,7 +717,7 @@ static PyObject *CtlObj_CountSubControls(_self, _args)
717717{
718718 PyObject * _res = NULL ;
719719 OSErr _err ;
720- SInt16 outNumChildren ;
720+ UInt16 outNumChildren ;
721721 if (!PyArg_ParseTuple (_args , "" ))
722722 return NULL ;
723723 _err = CountSubControls (_self -> ob_itself ,
@@ -734,7 +734,7 @@ static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
734734{
735735 PyObject * _res = NULL ;
736736 OSErr _err ;
737- SInt16 inIndex ;
737+ UInt16 inIndex ;
738738 ControlHandle outSubControl ;
739739 if (!PyArg_ParseTuple (_args , "h" ,
740740 & inIndex ))
@@ -867,6 +867,119 @@ static PyObject *CtlObj_TrackControl(_self, _args)
867867
868868}
869869
870+ static PyObject * CtlObj_HandleControlClick (_self , _args )
871+ ControlObject * _self ;
872+ PyObject * _args ;
873+ {
874+ PyObject * _res = NULL ;
875+
876+ ControlPartCode _rv ;
877+ Point startPoint ;
878+ SInt16 modifiers ;
879+ ControlActionUPP upp = 0 ;
880+ PyObject * callback = 0 ;
881+
882+ if (!PyArg_ParseTuple (_args , "O&h|O" ,
883+ PyMac_GetPoint , & startPoint ,
884+ & modifiers ,
885+ & callback ))
886+ return NULL ;
887+ if (callback && callback != Py_None ) {
888+ if (PyInt_Check (callback ) && PyInt_AS_LONG (callback ) == -1 )
889+ upp = (ControlActionUPP )- 1 ;
890+ else {
891+ settrackfunc (callback );
892+ upp = mytracker_upp ;
893+ }
894+ }
895+ _rv = HandleControlClick (_self -> ob_itself ,
896+ startPoint ,
897+ modifiers ,
898+ upp );
899+ clrtrackfunc ();
900+ _res = Py_BuildValue ("h" ,
901+ _rv );
902+ return _res ;
903+
904+ }
905+
906+ static PyObject * CtlObj_SetControlData (_self , _args )
907+ ControlObject * _self ;
908+ PyObject * _args ;
909+ {
910+ PyObject * _res = NULL ;
911+
912+ OSErr _err ;
913+ ControlPartCode inPart ;
914+ ResType inTagName ;
915+ Size bufferSize ;
916+ Ptr buffer ;
917+
918+ if (!PyArg_ParseTuple (_args , "hO&s#" ,
919+ & inPart ,
920+ PyMac_GetOSType , & inTagName ,
921+ & buffer , & bufferSize ))
922+ return NULL ;
923+
924+ _err = SetControlData (_self -> ob_itself ,
925+ inPart ,
926+ inTagName ,
927+ bufferSize ,
928+ buffer );
929+
930+ if (_err != noErr )
931+ return PyMac_Error (_err );
932+ _res = Py_None ;
933+ return _res ;
934+
935+ }
936+
937+ static PyObject * CtlObj_GetControlData (_self , _args )
938+ ControlObject * _self ;
939+ PyObject * _args ;
940+ {
941+ PyObject * _res = NULL ;
942+
943+ OSErr _err ;
944+ ControlPartCode inPart ;
945+ ResType inTagName ;
946+ Size bufferSize ;
947+ Ptr buffer ;
948+ Size outSize ;
949+
950+ if (!PyArg_ParseTuple (_args , "hO&" ,
951+ & inPart ,
952+ PyMac_GetOSType , & inTagName ))
953+ return NULL ;
954+
955+ /* allocate a buffer for the data */
956+ _err = GetControlDataSize (_self -> ob_itself ,
957+ inPart ,
958+ inTagName ,
959+ & bufferSize );
960+ if (_err != noErr )
961+ return PyMac_Error (_err );
962+ buffer = PyMem_NEW (char , bufferSize );
963+ if (buffer == NULL )
964+ return PyErr_NoMemory ();
965+
966+ _err = GetControlData (_self -> ob_itself ,
967+ inPart ,
968+ inTagName ,
969+ bufferSize ,
970+ buffer ,
971+ & outSize );
972+
973+ if (_err != noErr ) {
974+ PyMem_DEL (buffer );
975+ return PyMac_Error (_err );
976+ }
977+ _res = Py_BuildValue ("s#" , buffer , outSize );
978+ PyMem_DEL (buffer );
979+ return _res ;
980+
981+ }
982+
870983static PyObject * CtlObj_GetPopupData (_self , _args )
871984 ControlObject * _self ;
872985 PyObject * _args ;
@@ -983,9 +1096,9 @@ static PyMethodDef CtlObj_methods[] = {
9831096 {"GetSuperControl" , (PyCFunction )CtlObj_GetSuperControl , 1 ,
9841097 "() -> (ControlHandle outParent)" },
9851098 {"CountSubControls" , (PyCFunction )CtlObj_CountSubControls , 1 ,
986- "() -> (SInt16 outNumChildren)" },
1099+ "() -> (UInt16 outNumChildren)" },
9871100 {"GetIndexedSubControl" , (PyCFunction )CtlObj_GetIndexedSubControl , 1 ,
988- "(SInt16 inIndex) -> (ControlHandle outSubControl)" },
1101+ "(UInt16 inIndex) -> (ControlHandle outSubControl)" },
9891102 {"SetControlSupervisor" , (PyCFunction )CtlObj_SetControlSupervisor , 1 ,
9901103 "(ControlHandle inBoss) -> None" },
9911104 {"GetControlFeatures" , (PyCFunction )CtlObj_GetControlFeatures , 1 ,
@@ -997,7 +1110,13 @@ static PyMethodDef CtlObj_methods[] = {
9971110 {"DisposeControl" , (PyCFunction )CtlObj_DisposeControl , 1 ,
9981111 "() -> None" },
9991112 {"TrackControl" , (PyCFunction )CtlObj_TrackControl , 1 ,
1000- NULL },
1113+ "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)" },
1114+ {"HandleControlClick" , (PyCFunction )CtlObj_HandleControlClick , 1 ,
1115+ "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)" },
1116+ {"SetControlData" , (PyCFunction )CtlObj_SetControlData , 1 ,
1117+ "(stuff) -> None" },
1118+ {"GetControlData" , (PyCFunction )CtlObj_GetControlData , 1 ,
1119+ "(part, type) -> String" },
10011120 {"GetPopupData" , (PyCFunction )CtlObj_GetPopupData , 1 ,
10021121 NULL },
10031122 {"SetPopupData" , (PyCFunction )CtlObj_SetPopupData , 1 ,
@@ -1437,7 +1556,7 @@ PyObject *
14371556CtlObj_WhichControl (ControlHandle c )
14381557{
14391558 PyObject * it ;
1440-
1559+
14411560 if (c == NULL )
14421561 it = Py_None ;
14431562 else {
@@ -1478,7 +1597,7 @@ mytracker(ctl, part)
14781597 short part ;
14791598{
14801599 PyObject * args , * rv = 0 ;
1481-
1600+
14821601 args = Py_BuildValue ("(O&i)" , CtlObj_WhichControl , ctl , (int )part );
14831602 if (args && tracker ) {
14841603 rv = PyEval_CallObject (tracker , args );
@@ -1487,7 +1606,7 @@ mytracker(ctl, part)
14871606 if (rv )
14881607 Py_DECREF (rv );
14891608 else
1490- PySys_WriteStderr ("TrackControl: exception in tracker function\n" );
1609+ PySys_WriteStderr ("TrackControl or HandleControlClick : exception in tracker function\n" );
14911610}
14921611
14931612
0 commit comments