]> granicus.if.org Git - python/commitdiff
Allow an (optional) tracking function (or -1) to be specified to
authorJack Jansen <jack.jansen@cwi.nl>
Thu, 28 May 1998 14:20:09 +0000 (14:20 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Thu, 28 May 1998 14:20:09 +0000 (14:20 +0000)
TrackControl. TrackControl is now manually generated (too much work to
explain this to bgen).

Mac/Modules/ctl/Ctlmodule.c
Mac/Modules/ctl/ctlscan.py
Mac/Modules/ctl/ctlsupport.py

index e043b61d73d85e7b143a5358a4366cb04c274ba6..bfa88a11b56f82bc1c4d210c5ed3440f86191d61 100644 (file)
@@ -78,6 +78,13 @@ ControlFontStyle_Convert(v, itself)
                QdRGB_Convert, &itself->backColor);
 }
 
+/* TrackControl callback support */
+static PyObject *tracker;
+static ControlActionUPP mytracker_upp;
+
+extern int settrackfunc(PyObject *);   /* forward */
+extern void clrtrackfunc(void);        /* forward */
+
 static PyObject *Ctl_Error;
 
 /* ---------------------- Object type Control ----------------------- */
@@ -328,24 +335,6 @@ static PyObject *CtlObj_SetUpControlBackground(_self, _args)
        return _res;
 }
 
-static PyObject *CtlObj_TrackControl(_self, _args)
-       ControlObject *_self;
-       PyObject *_args;
-{
-       PyObject *_res = NULL;
-       ControlPartCode _rv;
-       Point startPoint;
-       if (!PyArg_ParseTuple(_args, "O&",
-                             PyMac_GetPoint, &startPoint))
-               return NULL;
-       _rv = TrackControl(_self->ob_itself,
-                          startPoint,
-                          (ControlActionUPP)0);
-       _res = Py_BuildValue("h",
-                            _rv);
-       return _res;
-}
-
 static PyObject *CtlObj_DragControl(_self, _args)
        ControlObject *_self;
        PyObject *_args;
@@ -585,20 +574,6 @@ static PyObject *CtlObj_GetControlVariant(_self, _args)
        return _res;
 }
 
-static PyObject *CtlObj_SetControlAction(_self, _args)
-       ControlObject *_self;
-       PyObject *_args;
-{
-       PyObject *_res = NULL;
-       if (!PyArg_ParseTuple(_args, ""))
-               return NULL;
-       SetControlAction(_self->ob_itself,
-                        (ControlActionUPP)0);
-       Py_INCREF(Py_None);
-       _res = Py_None;
-       return _res;
-}
-
 static PyObject *CtlObj_SetControlReference(_self, _args)
        ControlObject *_self;
        PyObject *_args;
@@ -859,6 +834,38 @@ static PyObject *CtlObj_DisposeControl(_self, _args)
 
 }
 
+static PyObject *CtlObj_TrackControl(_self, _args)
+       ControlObject *_self;
+       PyObject *_args;
+{
+       PyObject *_res = NULL;
+
+       ControlPartCode _rv;
+       Point startPoint;
+       ControlActionUPP upp = 0;
+       PyObject *callback = 0;
+
+       if (!PyArg_ParseTuple(_args, "O&|O",
+                             PyMac_GetPoint, &startPoint, &callback))
+               return NULL;
+       if (callback && callback != Py_None) {
+               if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
+                       upp = (ControlActionUPP)-1;
+               else {
+                       settrackfunc(callback);
+                       upp = mytracker_upp;
+               }
+       }
+       _rv = TrackControl(_self->ob_itself,
+                          startPoint,
+                          upp);
+       clrtrackfunc();
+       _res = Py_BuildValue("h",
+                            _rv);
+       return _res;
+
+}
+
 static PyMethodDef CtlObj_methods[] = {
        {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
         "(ControlPartCode hiliteState) -> None"},
@@ -886,8 +893,6 @@ static PyMethodDef CtlObj_methods[] = {
         "() -> None"},
        {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
         "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
-       {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
-        "(Point startPoint) -> (ControlPartCode _rv)"},
        {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
         "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
        {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
@@ -916,8 +921,6 @@ static PyMethodDef CtlObj_methods[] = {
         "(SInt16 newMaximum) -> None"},
        {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
         "() -> (ControlVariant _rv)"},
-       {"SetControlAction", (PyCFunction)CtlObj_SetControlAction, 1,
-        "() -> None"},
        {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
         "(SInt32 data) -> None"},
        {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
@@ -948,6 +951,8 @@ static PyMethodDef CtlObj_methods[] = {
         "Return this Control as a Resource"},
        {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
         "() -> None"},
+       {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
+        NULL},
        {NULL, NULL, 0}
 };
 
@@ -1332,6 +1337,43 @@ CtlObj_WhichControl(ControlHandle c)
        return it;
 }
 
+static int
+settrackfunc(obj)
+       PyObject *obj;
+{
+       if (tracker) {
+               PyErr_SetString(Ctl_Error, "Tracker function in use");
+               return 0;
+       }
+       tracker = obj;
+       Py_INCREF(tracker);
+}
+
+static void
+clrtrackfunc()
+{
+       Py_XDECREF(tracker);
+       tracker = 0;
+}
+
+static pascal void
+mytracker(ctl, part)
+       ControlHandle ctl;
+       short part;
+{
+       PyObject *args, *rv=0;
+       
+       args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
+       if (args && tracker) {
+               rv = PyEval_CallObject(tracker, args);
+               Py_DECREF(args);
+       }
+       if (rv)
+               Py_DECREF(rv);
+       else
+               fprintf(stderr, "TrackControl: exception in tracker function\n");
+}
+
 
 void initCtl()
 {
@@ -1340,6 +1382,8 @@ void initCtl()
 
 
 
+       mytracker_upp = NewControlActionProc(mytracker);
+
 
        m = Py_InitModule("Ctl", Ctl_methods);
        d = PyModule_GetDict(m);
index e124c5a11cece577ca233f9e9d64c31fdc5e41f8..66b4f569d9849efc42019417b7e31b0efe82491d 100644 (file)
@@ -41,6 +41,7 @@ class MyScanner(Scanner):
                        'DisposeControl', # Generated manually
                        'KillControls', # Implied by close of dialog
                        'SetCtlAction',
+                       'TrackControl', # Generated manually
                        'kControlBevelButtonCenterPopupGlyphTag', # Constant with funny definition
                        'kControlProgressBarIndeterminateTag', # ditto
                        # The following are unavailable for static 68k (appearance manager)
@@ -76,11 +77,11 @@ class MyScanner(Scanner):
                                                    ("long", "*", "OutMode")],
                         [("VarVarOutBuffer", "*", "InOutMode")]),
                        
-                       # For TrackControl
-                       ([("ProcPtr", "actionProc", "InMode")],
-                        [("FakeType('(ControlActionUPP)0')", "*", "*")]),
-                       ([("ControlActionUPP", "actionProc", "InMode")],
-                        [("FakeType('(ControlActionUPP)0')", "*", "*")]),
+##                     # For TrackControl
+##                     ([("ProcPtr", "actionProc", "InMode")],
+##                      [("FakeType('(ControlActionUPP)0')", "*", "*")]),
+##                     ([("ControlActionUPP", "actionProc", "InMode")],
+##                      [("FakeType('(ControlActionUPP)0')", "*", "*")]),
                        
                        ([("ControlHandle", "*", "OutMode")],
                         [("ExistingControlHandle", "*", "*")]),
index cee9a4c39e9ad13e4d0ad8b81431d667a087e0d3..75e7aa7b035dcfb299b2e2740b7343e94bd930ab 100644 (file)
@@ -77,6 +77,13 @@ ControlFontStyle_Convert(v, itself)
                &itself->just, QdRGB_Convert, &itself->foreColor, 
                QdRGB_Convert, &itself->backColor);
 }
+
+/* TrackControl callback support */
+static PyObject *tracker;
+static ControlActionUPP mytracker_upp;
+
+extern int settrackfunc(PyObject *);   /* forward */
+extern void clrtrackfunc(void);        /* forward */
 """
 
 finalstuff = finalstuff + """
@@ -95,6 +102,47 @@ CtlObj_WhichControl(ControlHandle c)
        Py_INCREF(it);
        return it;
 }
+
+static int
+settrackfunc(obj)
+       PyObject *obj;
+{
+       if (tracker) {
+               PyErr_SetString(Ctl_Error, "Tracker function in use");
+               return 0;
+       }
+       tracker = obj;
+       Py_INCREF(tracker);
+}
+
+static void
+clrtrackfunc()
+{
+       Py_XDECREF(tracker);
+       tracker = 0;
+}
+
+static pascal void
+mytracker(ctl, part)
+       ControlHandle ctl;
+       short part;
+{
+       PyObject *args, *rv=0;
+       
+       args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
+       if (args && tracker) {
+               rv = PyEval_CallObject(tracker, args);
+               Py_DECREF(args);
+       }
+       if (rv)
+               Py_DECREF(rv);
+       else
+               fprintf(stderr, "TrackControl: exception in tracker function\\n");
+}
+"""
+
+initstuff = initstuff + """
+mytracker_upp = NewControlActionProc(mytracker);
 """
 
 class MyObjectDefinition(GlobalObjectDefinition):
@@ -125,6 +173,38 @@ execfile('ctledit.py')
 for f in functions: module.add(f)
 for f in methods: object.add(f)
 
+# Manual generator for TrackControl, due to callback ideosyncracies
+trackcontrol_body = """
+ControlPartCode _rv;
+Point startPoint;
+ControlActionUPP upp = 0;
+PyObject *callback = 0;
+
+if (!PyArg_ParseTuple(_args, "O&|O",
+                      PyMac_GetPoint, &startPoint, &callback))
+       return NULL;
+if (callback && callback != Py_None) {
+       if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
+               upp = (ControlActionUPP)-1;
+       else {
+               settrackfunc(callback);
+               upp = mytracker_upp;
+       }
+}
+_rv = TrackControl(_self->ob_itself,
+                   startPoint,
+                   upp);
+clrtrackfunc();
+_res = Py_BuildValue("h",
+                     _rv);
+return _res;
+"""
+
+f = ManualGenerator("TrackControl", trackcontrol_body);
+#f.docstring = "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"
+object.add(f)
+
+
 # generate output (open the output file as late as possible)
 SetOutputFileName(OUTPUTFILE)
 module.generate()