Added Ctl.as_Control and Menu.as_Menu methods, which take a resource as
argument and return a Control or Menu object.
diff --git a/Mac/Modules/ctl/Ctlmodule.c b/Mac/Modules/ctl/Ctlmodule.c
index 6a74d23..07fff29 100644
--- a/Mac/Modules/ctl/Ctlmodule.c
+++ b/Mac/Modules/ctl/Ctlmodule.c
@@ -44,6 +44,8 @@
#include <Controls.h>
+#define as_Control(h) ((ControlHandle)h)
+
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
@@ -1333,6 +1335,22 @@
return _res;
}
+static PyObject *Ctl_as_Control(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ ControlHandle _rv;
+ Handle h;
+ if (!PyArg_ParseTuple(_args, "O&",
+ ResObj_Convert, &h))
+ return NULL;
+ _rv = as_Control(h);
+ _res = Py_BuildValue("O&",
+ CtlObj_New, _rv);
+ return _res;
+}
+
static PyMethodDef Ctl_methods[] = {
{"NewControl", (PyCFunction)Ctl_NewControl, 1,
"(WindowPtr owningWindow, Rect boundsRect, Str255 controlTitle, Boolean initiallyVisible, SInt16 initialValue, SInt16 minimumValue, SInt16 maximumValue, SInt16 procID, SInt32 controlReference) -> (ControlHandle _rv)"},
@@ -1364,6 +1382,8 @@
"(WindowPtr inWindow) -> None"},
{"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
"(WindowPtr inWindow) -> None"},
+ {"as_Control", (PyCFunction)Ctl_as_Control, 1,
+ "(Handle h) -> (ControlHandle _rv)"},
{NULL, NULL, 0}
};
diff --git a/Mac/Modules/ctl/ctledit.py b/Mac/Modules/ctl/ctledit.py
index a23eef8..97534e2 100644
--- a/Mac/Modules/ctl/ctledit.py
+++ b/Mac/Modules/ctl/ctledit.py
@@ -1,3 +1,7 @@
+f = Function(ControlHandle, 'as_Control',
+ (Handle, 'h', InMode))
+functions.append(f)
+
as_resource_body = """
return ResObj_New((Handle)_self->ob_itself);
"""
diff --git a/Mac/Modules/ctl/ctlsupport.py b/Mac/Modules/ctl/ctlsupport.py
index 84dd6ce..3ba6778 100644
--- a/Mac/Modules/ctl/ctlsupport.py
+++ b/Mac/Modules/ctl/ctlsupport.py
@@ -44,6 +44,8 @@
includestuff = includestuff + """
#include <%s>""" % MACHEADERFILE + """
+#define as_Control(h) ((ControlHandle)h)
+
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */