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

Skip to content

Commit 4c70413

Browse files
committed
Added {Get,Set}PopupData calls to get at the data for popup menu controls.
1 parent cef4c84 commit 4c70413

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

Mac/Modules/ctl/Ctlmodule.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,50 @@ static PyObject *CtlObj_TrackControl(_self, _args)
866866

867867
}
868868

869+
static PyObject *CtlObj_GetPopupData(_self, _args)
870+
ControlObject *_self;
871+
PyObject *_args;
872+
{
873+
PyObject *_res = NULL;
874+
875+
PopupPrivateDataHandle hdl;
876+
877+
if ( (*_self->ob_itself)->contrlData == NULL ) {
878+
PyErr_SetString(Ctl_Error, "No contrlData handle in control");
879+
return 0;
880+
}
881+
hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
882+
HLock((Handle)hdl);
883+
_res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
884+
HUnlock((Handle)hdl);
885+
return _res;
886+
887+
}
888+
889+
static PyObject *CtlObj_SetPopupData(_self, _args)
890+
ControlObject *_self;
891+
PyObject *_args;
892+
{
893+
PyObject *_res = NULL;
894+
895+
PopupPrivateDataHandle hdl;
896+
MenuHandle mHandle;
897+
short mID;
898+
899+
if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
900+
return 0;
901+
if ( (*_self->ob_itself)->contrlData == NULL ) {
902+
PyErr_SetString(Ctl_Error, "No contrlData handle in control");
903+
return 0;
904+
}
905+
hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
906+
(*hdl)->mHandle = mHandle;
907+
(*hdl)->mID = mID;
908+
Py_INCREF(Py_None);
909+
return Py_None;
910+
911+
}
912+
869913
static PyMethodDef CtlObj_methods[] = {
870914
{"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
871915
"(ControlPartCode hiliteState) -> None"},
@@ -953,6 +997,10 @@ static PyMethodDef CtlObj_methods[] = {
953997
"() -> None"},
954998
{"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
955999
NULL},
1000+
{"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1001+
NULL},
1002+
{"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1003+
NULL},
9561004
{NULL, NULL, 0}
9571005
};
9581006

Mac/Modules/ctl/ctlsupport.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,43 @@ def outputCleanupStructMembers(self):
204204
#f.docstring = "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"
205205
object.add(f)
206206

207+
# And manual generators to get/set popup menu information
208+
getpopupdata_body = """
209+
PopupPrivateDataHandle hdl;
210+
211+
if ( (*_self->ob_itself)->contrlData == NULL ) {
212+
PyErr_SetString(Ctl_Error, "No contrlData handle in control");
213+
return 0;
214+
}
215+
hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
216+
HLock((Handle)hdl);
217+
_res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
218+
HUnlock((Handle)hdl);
219+
return _res;
220+
"""
221+
f = ManualGenerator("GetPopupData", getpopupdata_body)
222+
object.add(f)
223+
224+
setpopupdata_body = """
225+
PopupPrivateDataHandle hdl;
226+
MenuHandle mHandle;
227+
short mID;
228+
229+
if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
230+
return 0;
231+
if ( (*_self->ob_itself)->contrlData == NULL ) {
232+
PyErr_SetString(Ctl_Error, "No contrlData handle in control");
233+
return 0;
234+
}
235+
hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
236+
(*hdl)->mHandle = mHandle;
237+
(*hdl)->mID = mID;
238+
Py_INCREF(Py_None);
239+
return Py_None;
240+
"""
241+
f = ManualGenerator("SetPopupData", setpopupdata_body)
242+
object.add(f)
243+
207244

208245
# generate output (open the output file as late as possible)
209246
SetOutputFileName(OUTPUTFILE)

0 commit comments

Comments
 (0)