diff options
-rw-r--r-- | Mac/Modules/ctl/Ctlmodule.c | 77 | ||||
-rw-r--r-- | Mac/Modules/ctl/ctlsupport.py | 72 |
2 files changed, 148 insertions, 1 deletions
diff --git a/Mac/Modules/ctl/Ctlmodule.c b/Mac/Modules/ctl/Ctlmodule.c index 071e140..d1deee8 100644 --- a/Mac/Modules/ctl/Ctlmodule.c +++ b/Mac/Modules/ctl/Ctlmodule.c @@ -1177,6 +1177,79 @@ static PyObject *CtlObj_GetControlData(_self, _args) } +static PyObject *CtlObj_SetControlDataHandle(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + + OSErr _err; + ControlPartCode inPart; + ResType inTagName; + Handle buffer; + + if (!PyArg_ParseTuple(_args, "hO&O&", + &inPart, + PyMac_GetOSType, &inTagName, + OptResObj_Convert, buffer)) + return NULL; + + _err = SetControlData(_self->ob_itself, + inPart, + inTagName, + sizeof(buffer), + (Ptr)buffer); + + if (_err != noErr) + return PyMac_Error(_err); + _res = Py_None; + return _res; + +} + +static PyObject *CtlObj_GetControlDataHandle(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + + OSErr _err; + ControlPartCode inPart; + ResType inTagName; + Size bufferSize; + Handle hdl; + + if (!PyArg_ParseTuple(_args, "hO&", + &inPart, + PyMac_GetOSType, &inTagName)) + return NULL; + + /* Check it is handle-sized */ + _err = GetControlDataSize(_self->ob_itself, + inPart, + inTagName, + &bufferSize); + if (_err != noErr) + return PyMac_Error(_err); + if (bufferSize != sizeof(Handle)) { + PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)"); + return NULL; + } + + _err = GetControlData(_self->ob_itself, + inPart, + inTagName, + sizeof(Handle), + (Ptr)&hdl, + &bufferSize); + + if (_err != noErr) { + return PyMac_Error(_err); + } + return Py_BuildValue("O&", OptResObj_New, hdl); + +} + static PyObject *CtlObj_GetPopupData(_self, _args) ControlObject *_self; PyObject *_args; @@ -1338,6 +1411,10 @@ static PyMethodDef CtlObj_methods[] = { "(stuff) -> None"}, {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1, "(part, type) -> String"}, + {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1, + "(ResObj) -> None"}, + {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1, + "(part, type) -> ResObj"}, {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1, NULL}, {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1, diff --git a/Mac/Modules/ctl/ctlsupport.py b/Mac/Modules/ctl/ctlsupport.py index 70ae285..4a4620f 100644 --- a/Mac/Modules/ctl/ctlsupport.py +++ b/Mac/Modules/ctl/ctlsupport.py @@ -331,7 +331,77 @@ return _res; f = ManualGenerator("GetControlData", getcontroldata_body); f.docstring = lambda: "(part, type) -> String" object.add(f) -# end CJW + +# Manual Generator for SetControlDataHandle +setcontroldatahandle_body = """ +OSErr _err; +ControlPartCode inPart; +ResType inTagName; +Handle buffer; + +if (!PyArg_ParseTuple(_args, "hO&O&", + &inPart, + PyMac_GetOSType, &inTagName, + OptResObj_Convert, buffer)) + return NULL; + +_err = SetControlData(_self->ob_itself, + inPart, + inTagName, + sizeof(buffer), + (Ptr)buffer); + +if (_err != noErr) + return PyMac_Error(_err); +_res = Py_None; +return _res; +""" + +f = ManualGenerator("SetControlDataHandle", setcontroldatahandle_body); +f.docstring = lambda: "(ResObj) -> None" +object.add(f) + +# Manual Generator for GetControlDataHandle +getcontroldatahandle_body = """ +OSErr _err; +ControlPartCode inPart; +ResType inTagName; +Size bufferSize; +Handle hdl; + +if (!PyArg_ParseTuple(_args, "hO&", + &inPart, + PyMac_GetOSType, &inTagName)) + return NULL; + +/* Check it is handle-sized */ +_err = GetControlDataSize(_self->ob_itself, + inPart, + inTagName, + &bufferSize); +if (_err != noErr) + return PyMac_Error(_err); +if (bufferSize != sizeof(Handle)) { + PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)"); + return NULL; +} + +_err = GetControlData(_self->ob_itself, + inPart, + inTagName, + sizeof(Handle), + (Ptr)&hdl, + &bufferSize); + +if (_err != noErr) { + return PyMac_Error(_err); +} +return Py_BuildValue("O&", OptResObj_New, hdl); +""" + +f = ManualGenerator("GetControlDataHandle", getcontroldatahandle_body); +f.docstring = lambda: "(part, type) -> ResObj" +object.add(f) # And manual generators to get/set popup menu information getpopupdata_body = """ |