summaryrefslogtreecommitdiffstats
path: root/Mac
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
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')
-rw-r--r--Mac/Modules/ctl/Ctlmodule.c116
-rw-r--r--Mac/Modules/ctl/ctlscan.py11
-rw-r--r--Mac/Modules/ctl/ctlsupport.py80
3 files changed, 166 insertions, 41 deletions
diff --git a/Mac/Modules/ctl/Ctlmodule.c b/Mac/Modules/ctl/Ctlmodule.c
index e043b61..bfa88a1 100644
--- a/Mac/Modules/ctl/Ctlmodule.c
+++ b/Mac/Modules/ctl/Ctlmodule.c
@@ -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);
diff --git a/Mac/Modules/ctl/ctlscan.py b/Mac/Modules/ctl/ctlscan.py
index e124c5a..66b4f56 100644
--- a/Mac/Modules/ctl/ctlscan.py
+++ b/Mac/Modules/ctl/ctlscan.py
@@ -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", "*", "*")]),
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()