@@ -78,6 +78,13 @@ ControlFontStyle_Convert(v, itself)
7878 QdRGB_Convert , & itself -> backColor );
7979}
8080
81+ /* TrackControl callback support */
82+ static PyObject * tracker ;
83+ static ControlActionUPP mytracker_upp ;
84+
85+ extern int settrackfunc (PyObject * ); /* forward */
86+ extern void clrtrackfunc (void ); /* forward */
87+
8188static PyObject * Ctl_Error ;
8289
8390/* ---------------------- Object type Control ----------------------- */
@@ -328,24 +335,6 @@ static PyObject *CtlObj_SetUpControlBackground(_self, _args)
328335 return _res ;
329336}
330337
331- static PyObject * CtlObj_TrackControl (_self , _args )
332- ControlObject * _self ;
333- PyObject * _args ;
334- {
335- PyObject * _res = NULL ;
336- ControlPartCode _rv ;
337- Point startPoint ;
338- if (!PyArg_ParseTuple (_args , "O&" ,
339- PyMac_GetPoint , & startPoint ))
340- return NULL ;
341- _rv = TrackControl (_self -> ob_itself ,
342- startPoint ,
343- (ControlActionUPP )0 );
344- _res = Py_BuildValue ("h" ,
345- _rv );
346- return _res ;
347- }
348-
349338static PyObject * CtlObj_DragControl (_self , _args )
350339 ControlObject * _self ;
351340 PyObject * _args ;
@@ -585,20 +574,6 @@ static PyObject *CtlObj_GetControlVariant(_self, _args)
585574 return _res ;
586575}
587576
588- static PyObject * CtlObj_SetControlAction (_self , _args )
589- ControlObject * _self ;
590- PyObject * _args ;
591- {
592- PyObject * _res = NULL ;
593- if (!PyArg_ParseTuple (_args , "" ))
594- return NULL ;
595- SetControlAction (_self -> ob_itself ,
596- (ControlActionUPP )0 );
597- Py_INCREF (Py_None );
598- _res = Py_None ;
599- return _res ;
600- }
601-
602577static PyObject * CtlObj_SetControlReference (_self , _args )
603578 ControlObject * _self ;
604579 PyObject * _args ;
@@ -859,6 +834,38 @@ static PyObject *CtlObj_DisposeControl(_self, _args)
859834
860835}
861836
837+ static PyObject * CtlObj_TrackControl (_self , _args )
838+ ControlObject * _self ;
839+ PyObject * _args ;
840+ {
841+ PyObject * _res = NULL ;
842+
843+ ControlPartCode _rv ;
844+ Point startPoint ;
845+ ControlActionUPP upp = 0 ;
846+ PyObject * callback = 0 ;
847+
848+ if (!PyArg_ParseTuple (_args , "O&|O" ,
849+ PyMac_GetPoint , & startPoint , & callback ))
850+ return NULL ;
851+ if (callback && callback != Py_None ) {
852+ if (PyInt_Check (callback ) && PyInt_AS_LONG (callback ) == -1 )
853+ upp = (ControlActionUPP )- 1 ;
854+ else {
855+ settrackfunc (callback );
856+ upp = mytracker_upp ;
857+ }
858+ }
859+ _rv = TrackControl (_self -> ob_itself ,
860+ startPoint ,
861+ upp );
862+ clrtrackfunc ();
863+ _res = Py_BuildValue ("h" ,
864+ _rv );
865+ return _res ;
866+
867+ }
868+
862869static PyMethodDef CtlObj_methods [] = {
863870 {"HiliteControl" , (PyCFunction )CtlObj_HiliteControl , 1 ,
864871 "(ControlPartCode hiliteState) -> None" },
@@ -886,8 +893,6 @@ static PyMethodDef CtlObj_methods[] = {
886893 "() -> None" },
887894 {"SetUpControlBackground" , (PyCFunction )CtlObj_SetUpControlBackground , 1 ,
888895 "(SInt16 inDepth, Boolean inIsColorDevice) -> None" },
889- {"TrackControl" , (PyCFunction )CtlObj_TrackControl , 1 ,
890- "(Point startPoint) -> (ControlPartCode _rv)" },
891896 {"DragControl" , (PyCFunction )CtlObj_DragControl , 1 ,
892897 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None" },
893898 {"TestControl" , (PyCFunction )CtlObj_TestControl , 1 ,
@@ -916,8 +921,6 @@ static PyMethodDef CtlObj_methods[] = {
916921 "(SInt16 newMaximum) -> None" },
917922 {"GetControlVariant" , (PyCFunction )CtlObj_GetControlVariant , 1 ,
918923 "() -> (ControlVariant _rv)" },
919- {"SetControlAction" , (PyCFunction )CtlObj_SetControlAction , 1 ,
920- "() -> None" },
921924 {"SetControlReference" , (PyCFunction )CtlObj_SetControlReference , 1 ,
922925 "(SInt32 data) -> None" },
923926 {"GetControlReference" , (PyCFunction )CtlObj_GetControlReference , 1 ,
@@ -948,6 +951,8 @@ static PyMethodDef CtlObj_methods[] = {
948951 "Return this Control as a Resource" },
949952 {"DisposeControl" , (PyCFunction )CtlObj_DisposeControl , 1 ,
950953 "() -> None" },
954+ {"TrackControl" , (PyCFunction )CtlObj_TrackControl , 1 ,
955+ NULL },
951956 {NULL , NULL , 0 }
952957};
953958
@@ -1332,6 +1337,43 @@ CtlObj_WhichControl(ControlHandle c)
13321337 return it ;
13331338}
13341339
1340+ static int
1341+ settrackfunc (obj )
1342+ PyObject * obj ;
1343+ {
1344+ if (tracker ) {
1345+ PyErr_SetString (Ctl_Error , "Tracker function in use" );
1346+ return 0 ;
1347+ }
1348+ tracker = obj ;
1349+ Py_INCREF (tracker );
1350+ }
1351+
1352+ static void
1353+ clrtrackfunc ()
1354+ {
1355+ Py_XDECREF (tracker );
1356+ tracker = 0 ;
1357+ }
1358+
1359+ static pascal void
1360+ mytracker (ctl , part )
1361+ ControlHandle ctl ;
1362+ short part ;
1363+ {
1364+ PyObject * args , * rv = 0 ;
1365+
1366+ args = Py_BuildValue ("(O&i)" , CtlObj_WhichControl , ctl , (int )part );
1367+ if (args && tracker ) {
1368+ rv = PyEval_CallObject (tracker , args );
1369+ Py_DECREF (args );
1370+ }
1371+ if (rv )
1372+ Py_DECREF (rv );
1373+ else
1374+ fprintf (stderr , "TrackControl: exception in tracker function\n" );
1375+ }
1376+
13351377
13361378void initCtl ()
13371379{
@@ -1340,6 +1382,8 @@ void initCtl()
13401382
13411383
13421384
1385+ mytracker_upp = NewControlActionProc (mytracker );
1386+
13431387
13441388 m = Py_InitModule ("Ctl" , Ctl_methods );
13451389 d = PyModule_GetDict (m );
0 commit comments