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

Skip to content

Commit 229c086

Browse files
committed
Changes by Corran Webster to support {Get,Set}ControlData and
HandleControlClick. Untested.
1 parent 4d56ecf commit 229c086

2 files changed

Lines changed: 132 additions & 12 deletions

File tree

Mac/Modules/ctl/ctlscan.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def makeblacklistnames(self):
4242
'KillControls', # Implied by close of dialog
4343
'SetCtlAction',
4444
'TrackControl', # Generated manually
45+
'HandleControlClick', # Generated manually
46+
'SetControlData', # Generated manually
47+
'GetControlData', # Generated manually
4548
'kControlBevelButtonCenterPopupGlyphTag', # Constant with funny definition
4649
'kControlProgressBarIndeterminateTag', # ditto
4750
# The following are unavailable for static 68k (appearance manager)
@@ -58,6 +61,10 @@ def makeblacklistnames(self):
5861
'SetDisclosureTriangleLastValue',
5962
# Unavailable in CW Pro 3 libraries
6063
'SetUpControlTextColor',
64+
# Generally Bad News
65+
'GetControlProperty',
66+
'SetControlProperty',
67+
'GetControlPropertySize',
6168
]
6269

6370
def makeblacklisttypes(self):
@@ -72,21 +79,21 @@ def makerepairinstructions(self):
7279
return [
7380
([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
7481
[("InBuffer", "*", "*")]),
75-
82+
7683
([("void", "*", "OutMode"), ("long", "*", "InMode"),
7784
("long", "*", "OutMode")],
7885
[("VarVarOutBuffer", "*", "InOutMode")]),
79-
86+
8087
## # For TrackControl
8188
## ([("ProcPtr", "actionProc", "InMode")],
8289
## [("FakeType('(ControlActionUPP)0')", "*", "*")]),
8390
## ([("ControlActionUPP", "actionProc", "InMode")],
8491
## [("FakeType('(ControlActionUPP)0')", "*", "*")]),
85-
92+
8693
# For GetControlTitle
8794
([('Str255', 'title', 'InMode')],
8895
[('Str255', 'title', 'OutMode')]),
89-
96+
9097
([("ControlHandle", "*", "OutMode")],
9198
[("ExistingControlHandle", "*", "*")]),
9299
([("ControlRef", "*", "OutMode")], # Ditto, for Universal Headers

Mac/Modules/ctl/ctlsupport.py

Lines changed: 121 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@
7575
ControlFontStyleRec *itself;
7676
{
7777
return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
78-
&itself->font, &itself->size, &itself->style, &itself->mode,
79-
&itself->just, QdRGB_Convert, &itself->foreColor,
78+
&itself->font, &itself->size, &itself->style, &itself->mode,
79+
&itself->just, QdRGB_Convert, &itself->foreColor,
8080
QdRGB_Convert, &itself->backColor);
8181
}
8282
83-
/* TrackControl callback support */
83+
/* TrackControl and HandleControlClick callback support */
8484
static PyObject *tracker;
8585
static ControlActionUPP mytracker_upp;
8686
@@ -104,7 +104,7 @@
104104
CtlObj_WhichControl(ControlHandle c)
105105
{
106106
PyObject *it;
107-
107+
108108
if (c == NULL)
109109
it = Py_None;
110110
else {
@@ -145,7 +145,7 @@
145145
short part;
146146
{
147147
PyObject *args, *rv=0;
148-
148+
149149
args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
150150
if (args && tracker) {
151151
rv = PyEval_CallObject(tracker, args);
@@ -154,7 +154,7 @@
154154
if (rv)
155155
Py_DECREF(rv);
156156
else
157-
PySys_WriteStderr("TrackControl: exception in tracker function\\n");
157+
PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\\n");
158158
}
159159
"""
160160

@@ -169,8 +169,8 @@ def outputInitStructMembers(self):
169169
GlobalObjectDefinition.outputInitStructMembers(self)
170170
Output("SetControlReference(itself, (long)it);")
171171
def outputCleanupStructMembers(self):
172-
Output("if (self->ob_itself) SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */")
173-
172+
Output("if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */")
173+
174174
# Create the generator groups and link them
175175
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
176176
object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
@@ -221,6 +221,119 @@ def outputCleanupStructMembers(self):
221221
#f.docstring = "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"
222222
object.add(f)
223223

224+
# CJW - added 5/12/99
225+
# Manual generator for HandleControlClick, as for TrackControl
226+
handlecontrolclick_body = """
227+
ControlPartCode _rv;
228+
Point startPoint;
229+
SInt16 modifiers;
230+
ControlActionUPP upp = 0;
231+
PyObject *callback = 0;
232+
233+
if (!PyArg_ParseTuple(_args, "O&h|O",
234+
PyMac_GetPoint, &startPoint,
235+
&modifiers,
236+
&callback))
237+
return NULL;
238+
if (callback && callback != Py_None) {
239+
if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
240+
upp = (ControlActionUPP)-1;
241+
else {
242+
settrackfunc(callback);
243+
upp = mytracker_upp;
244+
}
245+
}
246+
_rv = HandleControlClick(_self->ob_itself,
247+
startPoint,
248+
modifiers,
249+
upp);
250+
clrtrackfunc();
251+
_res = Py_BuildValue("h",
252+
_rv);
253+
return _res;
254+
"""
255+
256+
f = ManualGenerator("HandleControlClick", handlecontrolclick_body);
257+
#f.docstring = "(Point startPoint, Integer modifiers, [,trackercallback])
258+
-> (ControlPartCode _rv)"
259+
object.add(f)
260+
261+
# Manual Generator for SetControlData
262+
setcontroldata_body = """
263+
OSErr _err;
264+
ControlPartCode inPart;
265+
ResType inTagName;
266+
Size bufferSize;
267+
Ptr buffer;
268+
269+
if (!PyArg_ParseTuple(_args, "hO&s#",
270+
&inPart,
271+
PyMac_GetOSType, &inTagName,
272+
&buffer, &bufferSize))
273+
return NULL;
274+
275+
_err = SetControlData(_self->ob_itself,
276+
inPart,
277+
inTagName,
278+
bufferSize,
279+
buffer);
280+
281+
if (_err != noErr)
282+
return PyMac_Error(_err);
283+
_res = Py_None;
284+
return _res;
285+
"""
286+
287+
f = ManualGenerator("SetControlData", setcontroldata_body);
288+
#f.docstring = "(stuff) -> None"
289+
object.add(f)
290+
291+
# Manual Generator for GetControlData
292+
getcontroldata_body = """
293+
OSErr _err;
294+
ControlPartCode inPart;
295+
ResType inTagName;
296+
Size bufferSize;
297+
Ptr buffer;
298+
Size outSize;
299+
300+
if (!PyArg_ParseTuple(_args, "hO&",
301+
&inPart,
302+
PyMac_GetOSType, &inTagName))
303+
return NULL;
304+
305+
/* allocate a buffer for the data */
306+
_err = GetControlDataSize(_self->ob_itself,
307+
inPart,
308+
inTagName,
309+
&bufferSize);
310+
if (_err != noErr)
311+
return PyMac_Error(_err);
312+
buffer = PyMem_NEW(char, bufferSize);
313+
if (buffer == NULL)
314+
return PyErr_NoMemory();
315+
316+
_err = GetControlData(_self->ob_itself,
317+
inPart,
318+
inTagName,
319+
bufferSize,
320+
buffer,
321+
&outSize);
322+
323+
if (_err != noErr) {
324+
PyMem_DEL(buffer);
325+
return PyMac_Error(_err);
326+
}
327+
_res = Py_BuildValue("s#", buffer, outSize);
328+
PyMem_DEL(buffer);
329+
return _res;
330+
"""
331+
332+
f = ManualGenerator("GetControlData", getcontroldata_body);
333+
#f.docstring = "(part, type) -> String"
334+
object.add(f)
335+
# end CJW
336+
224337
# And manual generators to get/set popup menu information
225338
getpopupdata_body = """
226339
PopupPrivateDataHandle hdl;

0 commit comments

Comments
 (0)