summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/ctl/ctlsupport.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1998-05-28 14:20:09 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1998-05-28 14:20:09 (GMT)
commit848250c15b7436a0e8b869730e3a2fdd070fc030 (patch)
treebdfc914151baa9bf091ac6dee1c06adea140de75 /Mac/Modules/ctl/ctlsupport.py
parentd3dbb38e98ed82234c9d14e963ee2e5bebaf99eb (diff)
downloadcpython-848250c15b7436a0e8b869730e3a2fdd070fc030.zip
cpython-848250c15b7436a0e8b869730e3a2fdd070fc030.tar.gz
cpython-848250c15b7436a0e8b869730e3a2fdd070fc030.tar.bz2
Allow an (optional) tracking function (or -1) to be specified to
TrackControl. TrackControl is now manually generated (too much work to explain this to bgen).
Diffstat (limited to 'Mac/Modules/ctl/ctlsupport.py')
-rw-r--r--Mac/Modules/ctl/ctlsupport.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/Mac/Modules/ctl/ctlsupport.py b/Mac/Modules/ctl/ctlsupport.py
index cee9a4c..75e7aa7 100644
--- a/Mac/Modules/ctl/ctlsupport.py
+++ b/Mac/Modules/ctl/ctlsupport.py
@@ -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()