mirror of https://github.com/python/cpython
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).
This commit is contained in:
parent
d3dbb38e98
commit
848250c15b
|
@ -78,6 +78,13 @@ ControlFontStyle_Convert(v, itself)
|
||||||
QdRGB_Convert, &itself->backColor);
|
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;
|
static PyObject *Ctl_Error;
|
||||||
|
|
||||||
/* ---------------------- Object type Control ----------------------- */
|
/* ---------------------- Object type Control ----------------------- */
|
||||||
|
@ -328,24 +335,6 @@ static PyObject *CtlObj_SetUpControlBackground(_self, _args)
|
||||||
return _res;
|
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)
|
static PyObject *CtlObj_DragControl(_self, _args)
|
||||||
ControlObject *_self;
|
ControlObject *_self;
|
||||||
PyObject *_args;
|
PyObject *_args;
|
||||||
|
@ -585,20 +574,6 @@ static PyObject *CtlObj_GetControlVariant(_self, _args)
|
||||||
return _res;
|
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)
|
static PyObject *CtlObj_SetControlReference(_self, _args)
|
||||||
ControlObject *_self;
|
ControlObject *_self;
|
||||||
PyObject *_args;
|
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[] = {
|
static PyMethodDef CtlObj_methods[] = {
|
||||||
{"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
|
{"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
|
||||||
"(ControlPartCode hiliteState) -> None"},
|
"(ControlPartCode hiliteState) -> None"},
|
||||||
|
@ -886,8 +893,6 @@ static PyMethodDef CtlObj_methods[] = {
|
||||||
"() -> None"},
|
"() -> None"},
|
||||||
{"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
|
{"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
|
||||||
"(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
|
"(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
|
||||||
{"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
|
|
||||||
"(Point startPoint) -> (ControlPartCode _rv)"},
|
|
||||||
{"DragControl", (PyCFunction)CtlObj_DragControl, 1,
|
{"DragControl", (PyCFunction)CtlObj_DragControl, 1,
|
||||||
"(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
|
"(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
|
||||||
{"TestControl", (PyCFunction)CtlObj_TestControl, 1,
|
{"TestControl", (PyCFunction)CtlObj_TestControl, 1,
|
||||||
|
@ -916,8 +921,6 @@ static PyMethodDef CtlObj_methods[] = {
|
||||||
"(SInt16 newMaximum) -> None"},
|
"(SInt16 newMaximum) -> None"},
|
||||||
{"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
|
{"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
|
||||||
"() -> (ControlVariant _rv)"},
|
"() -> (ControlVariant _rv)"},
|
||||||
{"SetControlAction", (PyCFunction)CtlObj_SetControlAction, 1,
|
|
||||||
"() -> None"},
|
|
||||||
{"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
|
{"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
|
||||||
"(SInt32 data) -> None"},
|
"(SInt32 data) -> None"},
|
||||||
{"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
|
{"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
|
||||||
|
@ -948,6 +951,8 @@ static PyMethodDef CtlObj_methods[] = {
|
||||||
"Return this Control as a Resource"},
|
"Return this Control as a Resource"},
|
||||||
{"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
|
{"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
|
||||||
"() -> None"},
|
"() -> None"},
|
||||||
|
{"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
|
||||||
|
NULL},
|
||||||
{NULL, NULL, 0}
|
{NULL, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1332,6 +1337,43 @@ CtlObj_WhichControl(ControlHandle c)
|
||||||
return 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void initCtl()
|
void initCtl()
|
||||||
{
|
{
|
||||||
|
@ -1340,6 +1382,8 @@ void initCtl()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
mytracker_upp = NewControlActionProc(mytracker);
|
||||||
|
|
||||||
|
|
||||||
m = Py_InitModule("Ctl", Ctl_methods);
|
m = Py_InitModule("Ctl", Ctl_methods);
|
||||||
d = PyModule_GetDict(m);
|
d = PyModule_GetDict(m);
|
||||||
|
|
|
@ -41,6 +41,7 @@ class MyScanner(Scanner):
|
||||||
'DisposeControl', # Generated manually
|
'DisposeControl', # Generated manually
|
||||||
'KillControls', # Implied by close of dialog
|
'KillControls', # Implied by close of dialog
|
||||||
'SetCtlAction',
|
'SetCtlAction',
|
||||||
|
'TrackControl', # Generated manually
|
||||||
'kControlBevelButtonCenterPopupGlyphTag', # Constant with funny definition
|
'kControlBevelButtonCenterPopupGlyphTag', # Constant with funny definition
|
||||||
'kControlProgressBarIndeterminateTag', # ditto
|
'kControlProgressBarIndeterminateTag', # ditto
|
||||||
# The following are unavailable for static 68k (appearance manager)
|
# The following are unavailable for static 68k (appearance manager)
|
||||||
|
@ -76,11 +77,11 @@ class MyScanner(Scanner):
|
||||||
("long", "*", "OutMode")],
|
("long", "*", "OutMode")],
|
||||||
[("VarVarOutBuffer", "*", "InOutMode")]),
|
[("VarVarOutBuffer", "*", "InOutMode")]),
|
||||||
|
|
||||||
# For TrackControl
|
## # For TrackControl
|
||||||
([("ProcPtr", "actionProc", "InMode")],
|
## ([("ProcPtr", "actionProc", "InMode")],
|
||||||
[("FakeType('(ControlActionUPP)0')", "*", "*")]),
|
## [("FakeType('(ControlActionUPP)0')", "*", "*")]),
|
||||||
([("ControlActionUPP", "actionProc", "InMode")],
|
## ([("ControlActionUPP", "actionProc", "InMode")],
|
||||||
[("FakeType('(ControlActionUPP)0')", "*", "*")]),
|
## [("FakeType('(ControlActionUPP)0')", "*", "*")]),
|
||||||
|
|
||||||
([("ControlHandle", "*", "OutMode")],
|
([("ControlHandle", "*", "OutMode")],
|
||||||
[("ExistingControlHandle", "*", "*")]),
|
[("ExistingControlHandle", "*", "*")]),
|
||||||
|
|
|
@ -77,6 +77,13 @@ ControlFontStyle_Convert(v, itself)
|
||||||
&itself->just, QdRGB_Convert, &itself->foreColor,
|
&itself->just, QdRGB_Convert, &itself->foreColor,
|
||||||
QdRGB_Convert, &itself->backColor);
|
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 + """
|
finalstuff = finalstuff + """
|
||||||
|
@ -95,6 +102,47 @@ CtlObj_WhichControl(ControlHandle c)
|
||||||
Py_INCREF(it);
|
Py_INCREF(it);
|
||||||
return 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):
|
class MyObjectDefinition(GlobalObjectDefinition):
|
||||||
|
@ -125,6 +173,38 @@ execfile('ctledit.py')
|
||||||
for f in functions: module.add(f)
|
for f in functions: module.add(f)
|
||||||
for f in methods: object.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)
|
# generate output (open the output file as late as possible)
|
||||||
SetOutputFileName(OUTPUTFILE)
|
SetOutputFileName(OUTPUTFILE)
|
||||||
module.generate()
|
module.generate()
|
||||||
|
|
Loading…
Reference in New Issue