Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 848250c

Browse files
committed
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).
1 parent d3dbb38 commit 848250c

3 files changed

Lines changed: 166 additions & 41 deletions

File tree

Mac/Modules/ctl/Ctlmodule.c

Lines changed: 80 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
8188
static 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-
349338
static 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-
602577
static 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+
862869
static 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

13361378
void 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);

Mac/Modules/ctl/ctlscan.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def makeblacklistnames(self):
4141
'DisposeControl', # Generated manually
4242
'KillControls', # Implied by close of dialog
4343
'SetCtlAction',
44+
'TrackControl', # Generated manually
4445
'kControlBevelButtonCenterPopupGlyphTag', # Constant with funny definition
4546
'kControlProgressBarIndeterminateTag', # ditto
4647
# The following are unavailable for static 68k (appearance manager)
@@ -76,11 +77,11 @@ def makerepairinstructions(self):
7677
("long", "*", "OutMode")],
7778
[("VarVarOutBuffer", "*", "InOutMode")]),
7879

79-
# For TrackControl
80-
([("ProcPtr", "actionProc", "InMode")],
81-
[("FakeType('(ControlActionUPP)0')", "*", "*")]),
82-
([("ControlActionUPP", "actionProc", "InMode")],
83-
[("FakeType('(ControlActionUPP)0')", "*", "*")]),
80+
## # For TrackControl
81+
## ([("ProcPtr", "actionProc", "InMode")],
82+
## [("FakeType('(ControlActionUPP)0')", "*", "*")]),
83+
## ([("ControlActionUPP", "actionProc", "InMode")],
84+
## [("FakeType('(ControlActionUPP)0')", "*", "*")]),
8485

8586
([("ControlHandle", "*", "OutMode")],
8687
[("ExistingControlHandle", "*", "*")]),

Mac/Modules/ctl/ctlsupport.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@
7777
&itself->just, QdRGB_Convert, &itself->foreColor,
7878
QdRGB_Convert, &itself->backColor);
7979
}
80+
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 */
8087
"""
8188

8289
finalstuff = finalstuff + """
@@ -95,6 +102,47 @@
95102
Py_INCREF(it);
96103
return it;
97104
}
105+
106+
static int
107+
settrackfunc(obj)
108+
PyObject *obj;
109+
{
110+
if (tracker) {
111+
PyErr_SetString(Ctl_Error, "Tracker function in use");
112+
return 0;
113+
}
114+
tracker = obj;
115+
Py_INCREF(tracker);
116+
}
117+
118+
static void
119+
clrtrackfunc()
120+
{
121+
Py_XDECREF(tracker);
122+
tracker = 0;
123+
}
124+
125+
static pascal void
126+
mytracker(ctl, part)
127+
ControlHandle ctl;
128+
short part;
129+
{
130+
PyObject *args, *rv=0;
131+
132+
args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
133+
if (args && tracker) {
134+
rv = PyEval_CallObject(tracker, args);
135+
Py_DECREF(args);
136+
}
137+
if (rv)
138+
Py_DECREF(rv);
139+
else
140+
fprintf(stderr, "TrackControl: exception in tracker function\\n");
141+
}
142+
"""
143+
144+
initstuff = initstuff + """
145+
mytracker_upp = NewControlActionProc(mytracker);
98146
"""
99147

100148
class MyObjectDefinition(GlobalObjectDefinition):
@@ -125,6 +173,38 @@ def outputCleanupStructMembers(self):
125173
for f in functions: module.add(f)
126174
for f in methods: object.add(f)
127175

176+
# Manual generator for TrackControl, due to callback ideosyncracies
177+
trackcontrol_body = """
178+
ControlPartCode _rv;
179+
Point startPoint;
180+
ControlActionUPP upp = 0;
181+
PyObject *callback = 0;
182+
183+
if (!PyArg_ParseTuple(_args, "O&|O",
184+
PyMac_GetPoint, &startPoint, &callback))
185+
return NULL;
186+
if (callback && callback != Py_None) {
187+
if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
188+
upp = (ControlActionUPP)-1;
189+
else {
190+
settrackfunc(callback);
191+
upp = mytracker_upp;
192+
}
193+
}
194+
_rv = TrackControl(_self->ob_itself,
195+
startPoint,
196+
upp);
197+
clrtrackfunc();
198+
_res = Py_BuildValue("h",
199+
_rv);
200+
return _res;
201+
"""
202+
203+
f = ManualGenerator("TrackControl", trackcontrol_body);
204+
#f.docstring = "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"
205+
object.add(f)
206+
207+
128208
# generate output (open the output file as late as possible)
129209
SetOutputFileName(OUTPUTFILE)
130210
module.generate()

0 commit comments

Comments
 (0)