summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/ctl
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-01-30 11:53:55 (GMT)
committerGuido van Rossum <guido@python.org>1995-01-30 11:53:55 (GMT)
commit17448e24081eb713ac00d7bcb681f4f0d8abfcbf (patch)
tree4f9d6768ef326173e1141b1a92af63247a42b13a /Mac/Modules/ctl
parent80ffd6683ca7b06ed743c629459b06b07defbfb3 (diff)
downloadcpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.zip
cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.tar.gz
cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.tar.bz2
Committed a more or less working version.
Diffstat (limited to 'Mac/Modules/ctl')
-rw-r--r--Mac/Modules/ctl/Ctlmodule.c691
-rw-r--r--Mac/Modules/ctl/ctlgen.py172
-rw-r--r--Mac/Modules/ctl/ctlscan.py60
-rw-r--r--Mac/Modules/ctl/ctlsupport.py86
4 files changed, 1009 insertions, 0 deletions
diff --git a/Mac/Modules/ctl/Ctlmodule.c b/Mac/Modules/ctl/Ctlmodule.c
new file mode 100644
index 0000000..fb1459a
--- /dev/null
+++ b/Mac/Modules/ctl/Ctlmodule.c
@@ -0,0 +1,691 @@
+
+/* =========================== Module Ctl =========================== */
+
+#include "Python.h"
+
+
+
+#define SystemSevenOrLater 1
+
+#include "macglue.h"
+#include <Memory.h>
+#include <Dialogs.h>
+#include <Menus.h>
+#include <Controls.h>
+
+extern PyObject *ResObj_New(Handle);
+extern int ResObj_Convert(PyObject *, Handle *);
+
+extern PyObject *WinObj_New(WindowPtr);
+extern int WinObj_Convert(PyObject *, WindowPtr *);
+
+extern PyObject *DlgObj_New(DialogPtr);
+extern int DlgObj_Convert(PyObject *, DialogPtr *);
+extern PyTypeObject Dialog_Type;
+#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
+
+extern PyObject *MenuObj_New(MenuHandle);
+extern int MenuObj_Convert(PyObject *, MenuHandle *);
+
+extern PyObject *CtlObj_New(ControlHandle);
+extern int CtlObj_Convert(PyObject *, ControlHandle *);
+
+extern PyObject *WinObj_WhichWindow(WindowPtr);
+
+#include <Controls.h>
+
+#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
+
+extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
+
+#ifdef THINK_C
+#define ControlActionUPP ProcPtr
+#endif
+
+static PyObject *Ctl_Error;
+
+/* ---------------------- Object type Control ----------------------- */
+
+PyTypeObject Control_Type;
+
+#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
+
+typedef struct ControlObject {
+ PyObject_HEAD
+ ControlHandle ob_itself;
+} ControlObject;
+
+PyObject *CtlObj_New(itself)
+ const ControlHandle itself;
+{
+ ControlObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(ControlObject, &Control_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ SetCRefCon(itself, (long)it);
+ return (PyObject *)it;
+}
+CtlObj_Convert(v, p_itself)
+ PyObject *v;
+ ControlHandle *p_itself;
+{
+ if (!CtlObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "Control required");
+ return 0;
+ }
+ *p_itself = ((ControlObject *)v)->ob_itself;
+ return 1;
+}
+
+static void CtlObj_dealloc(self)
+ ControlObject *self;
+{
+ /* Cleanup of self->ob_itself goes here */
+ PyMem_DEL(self);
+}
+
+static PyObject *CtlObj_SetCTitle(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ Str255 title;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetStr255, title))
+ return NULL;
+ SetCTitle(_self->ob_itself,
+ title);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetCTitle(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ Str255 title;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetStr255, title))
+ return NULL;
+ GetCTitle(_self->ob_itself,
+ title);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_DisposeControl(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ DisposeControl(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_HideControl(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ HideControl(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_ShowControl(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ ShowControl(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_Draw1Control(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ Draw1Control(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_HiliteControl(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short hiliteState;
+ if (!PyArg_ParseTuple(_args, "h",
+ &hiliteState))
+ return NULL;
+ HiliteControl(_self->ob_itself,
+ hiliteState);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_MoveControl(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short h;
+ short v;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &h,
+ &v))
+ return NULL;
+ MoveControl(_self->ob_itself,
+ h,
+ v);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_SizeControl(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short w;
+ short h;
+ if (!PyArg_ParseTuple(_args, "hh",
+ &w,
+ &h))
+ return NULL;
+ SizeControl(_self->ob_itself,
+ w,
+ h);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_SetCtlValue(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short theValue;
+ if (!PyArg_ParseTuple(_args, "h",
+ &theValue))
+ return NULL;
+ SetCtlValue(_self->ob_itself,
+ theValue);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetCtlValue(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetCtlValue(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_SetCtlMin(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short minValue;
+ if (!PyArg_ParseTuple(_args, "h",
+ &minValue))
+ return NULL;
+ SetCtlMin(_self->ob_itself,
+ minValue);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetCtlMin(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetCtlMin(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_SetCtlMax(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short maxValue;
+ if (!PyArg_ParseTuple(_args, "h",
+ &maxValue))
+ return NULL;
+ SetCtlMax(_self->ob_itself,
+ maxValue);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetCtlMax(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetCtlMax(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_SetCRefCon(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ long data;
+ if (!PyArg_ParseTuple(_args, "l",
+ &data))
+ return NULL;
+ SetCRefCon(_self->ob_itself,
+ data);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_GetCRefCon(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ long _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetCRefCon(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_DragControl(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ Point startPt;
+ Rect limitRect;
+ Rect slopRect;
+ short axis;
+ if (!PyArg_ParseTuple(_args, "O&O&O&h",
+ PyMac_GetPoint, &startPt,
+ PyMac_GetRect, &limitRect,
+ PyMac_GetRect, &slopRect,
+ &axis))
+ return NULL;
+ DragControl(_self->ob_itself,
+ startPt,
+ &limitRect,
+ &slopRect,
+ axis);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CtlObj_TestControl(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short _rv;
+ Point thePt;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetPoint, &thePt))
+ return NULL;
+ _rv = TestControl(_self->ob_itself,
+ thePt);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_TrackControl(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short _rv;
+ Point thePoint;
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetPoint, &thePoint))
+ return NULL;
+ _rv = TrackControl(_self->ob_itself,
+ thePoint,
+ (ControlActionUPP)0);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyObject *CtlObj_GetCVariant(_self, _args)
+ ControlObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = GetCVariant(_self->ob_itself);
+ _res = Py_BuildValue("h",
+ _rv);
+ return _res;
+}
+
+static PyMethodDef CtlObj_methods[] = {
+ {"SetCTitle", (PyCFunction)CtlObj_SetCTitle, 1,
+ "(Str255 title) -> None"},
+ {"GetCTitle", (PyCFunction)CtlObj_GetCTitle, 1,
+ "(Str255 title) -> None"},
+ {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
+ "() -> None"},
+ {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
+ "() -> None"},
+ {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
+ "() -> None"},
+ {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
+ "() -> None"},
+ {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
+ "(short hiliteState) -> None"},
+ {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
+ "(short h, short v) -> None"},
+ {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
+ "(short w, short h) -> None"},
+ {"SetCtlValue", (PyCFunction)CtlObj_SetCtlValue, 1,
+ "(short theValue) -> None"},
+ {"GetCtlValue", (PyCFunction)CtlObj_GetCtlValue, 1,
+ "() -> (short _rv)"},
+ {"SetCtlMin", (PyCFunction)CtlObj_SetCtlMin, 1,
+ "(short minValue) -> None"},
+ {"GetCtlMin", (PyCFunction)CtlObj_GetCtlMin, 1,
+ "() -> (short _rv)"},
+ {"SetCtlMax", (PyCFunction)CtlObj_SetCtlMax, 1,
+ "(short maxValue) -> None"},
+ {"GetCtlMax", (PyCFunction)CtlObj_GetCtlMax, 1,
+ "() -> (short _rv)"},
+ {"SetCRefCon", (PyCFunction)CtlObj_SetCRefCon, 1,
+ "(long data) -> None"},
+ {"GetCRefCon", (PyCFunction)CtlObj_GetCRefCon, 1,
+ "() -> (long _rv)"},
+ {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
+ "(Point startPt, Rect limitRect, Rect slopRect, short axis) -> None"},
+ {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
+ "(Point thePt) -> (short _rv)"},
+ {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
+ "(Point thePoint) -> (short _rv)"},
+ {"GetCVariant", (PyCFunction)CtlObj_GetCVariant, 1,
+ "() -> (short _rv)"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
+
+static PyObject *CtlObj_getattr(self, name)
+ ControlObject *self;
+ char *name;
+{
+ return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
+}
+
+#define CtlObj_setattr NULL
+
+PyTypeObject Control_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "Control", /*tp_name*/
+ sizeof(ControlObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) CtlObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) CtlObj_getattr, /*tp_getattr*/
+ (setattrfunc) CtlObj_setattr, /*tp_setattr*/
+};
+
+/* -------------------- End object type Control --------------------- */
+
+
+static PyObject *Ctl_NewControl(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ ControlHandle _rv;
+ WindowPtr theWindow;
+ Rect boundsRect;
+ Str255 title;
+ Boolean visible;
+ short value;
+ short min;
+ short max;
+ short procID;
+ long refCon;
+ if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
+ WinObj_Convert, &theWindow,
+ PyMac_GetRect, &boundsRect,
+ PyMac_GetStr255, title,
+ &visible,
+ &value,
+ &min,
+ &max,
+ &procID,
+ &refCon))
+ return NULL;
+ _rv = NewControl(theWindow,
+ &boundsRect,
+ title,
+ visible,
+ value,
+ min,
+ max,
+ procID,
+ refCon);
+ _res = Py_BuildValue("O&",
+ CtlObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Ctl_GetNewControl(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ ControlHandle _rv;
+ short controlID;
+ WindowPtr owner;
+ if (!PyArg_ParseTuple(_args, "hO&",
+ &controlID,
+ WinObj_Convert, &owner))
+ return NULL;
+ _rv = GetNewControl(controlID,
+ owner);
+ _res = Py_BuildValue("O&",
+ CtlObj_New, _rv);
+ return _res;
+}
+
+static PyObject *Ctl_KillControls(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ WindowPtr theWindow;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &theWindow))
+ return NULL;
+ KillControls(theWindow);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Ctl_DrawControls(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ WindowPtr theWindow;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &theWindow))
+ return NULL;
+ DrawControls(theWindow);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Ctl_UpdtControl(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ WindowPtr theWindow;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &theWindow))
+ return NULL;
+ UpdtControl(theWindow,
+ theWindow->visRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Ctl_UpdateControls(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ WindowPtr theWindow;
+ if (!PyArg_ParseTuple(_args, "O&",
+ WinObj_Convert, &theWindow))
+ return NULL;
+ UpdateControls(theWindow,
+ theWindow->visRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Ctl_FindControl(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ short _rv;
+ Point thePoint;
+ WindowPtr theWindow;
+ ControlHandle theControl;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ PyMac_GetPoint, &thePoint,
+ WinObj_Convert, &theWindow))
+ return NULL;
+ _rv = FindControl(thePoint,
+ theWindow,
+ &theControl);
+ _res = Py_BuildValue("hO&",
+ _rv,
+ CtlObj_WhichControl, theControl);
+ return _res;
+}
+
+static PyMethodDef Ctl_methods[] = {
+ {"NewControl", (PyCFunction)Ctl_NewControl, 1,
+ "(WindowPtr theWindow, Rect boundsRect, Str255 title, Boolean visible, short value, short min, short max, short procID, long refCon) -> (ControlHandle _rv)"},
+ {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
+ "(short controlID, WindowPtr owner) -> (ControlHandle _rv)"},
+ {"KillControls", (PyCFunction)Ctl_KillControls, 1,
+ "(WindowPtr theWindow) -> None"},
+ {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
+ "(WindowPtr theWindow) -> None"},
+ {"UpdtControl", (PyCFunction)Ctl_UpdtControl, 1,
+ "(WindowPtr theWindow) -> None"},
+ {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
+ "(WindowPtr theWindow) -> None"},
+ {"FindControl", (PyCFunction)Ctl_FindControl, 1,
+ "(Point thePoint, WindowPtr theWindow) -> (short _rv, ControlHandle theControl)"},
+ {NULL, NULL, 0}
+};
+
+
+
+PyObject *
+CtlObj_WhichControl(ControlHandle c)
+{
+ PyObject *it;
+
+ /* XXX What if we find a control belonging to some other package? */
+ if (c == NULL)
+ it = NULL;
+ else
+ it = (PyObject *) GetCRefCon(c);
+ if (it == NULL || ((ControlObject *)it)->ob_itself != c)
+ it = Py_None;
+ Py_INCREF(it);
+ return it;
+}
+
+
+void initCtl()
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+
+ m = Py_InitModule("Ctl", Ctl_methods);
+ d = PyModule_GetDict(m);
+ Ctl_Error = PyMac_GetOSErrException();
+ if (Ctl_Error == NULL ||
+ PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
+ Py_FatalError("can't initialize Ctl.Error");
+}
+
+/* ========================= End module Ctl ========================= */
+
diff --git a/Mac/Modules/ctl/ctlgen.py b/Mac/Modules/ctl/ctlgen.py
new file mode 100644
index 0000000..fcbf0f4
--- /dev/null
+++ b/Mac/Modules/ctl/ctlgen.py
@@ -0,0 +1,172 @@
+# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Controls.h'
+
+f = Function(ControlHandle, 'NewControl',
+ (WindowPtr, 'theWindow', InMode),
+ (Rect_ptr, 'boundsRect', InMode),
+ (ConstStr255Param, 'title', InMode),
+ (Boolean, 'visible', InMode),
+ (short, 'value', InMode),
+ (short, 'min', InMode),
+ (short, 'max', InMode),
+ (short, 'procID', InMode),
+ (long, 'refCon', InMode),
+)
+functions.append(f)
+
+f = Method(void, 'SetCTitle',
+ (ControlHandle, 'theControl', InMode),
+ (ConstStr255Param, 'title', InMode),
+)
+methods.append(f)
+
+f = Method(void, 'GetCTitle',
+ (ControlHandle, 'theControl', InMode),
+ (Str255, 'title', InMode),
+)
+methods.append(f)
+
+f = Function(ControlHandle, 'GetNewControl',
+ (short, 'controlID', InMode),
+ (WindowPtr, 'owner', InMode),
+)
+functions.append(f)
+
+f = Method(void, 'DisposeControl',
+ (ControlHandle, 'theControl', InMode),
+)
+methods.append(f)
+
+f = Function(void, 'KillControls',
+ (WindowPtr, 'theWindow', InMode),
+)
+functions.append(f)
+
+f = Method(void, 'HideControl',
+ (ControlHandle, 'theControl', InMode),
+)
+methods.append(f)
+
+f = Method(void, 'ShowControl',
+ (ControlHandle, 'theControl', InMode),
+)
+methods.append(f)
+
+f = Function(void, 'DrawControls',
+ (WindowPtr, 'theWindow', InMode),
+)
+functions.append(f)
+
+f = Method(void, 'Draw1Control',
+ (ControlHandle, 'theControl', InMode),
+)
+methods.append(f)
+
+f = Method(void, 'HiliteControl',
+ (ControlHandle, 'theControl', InMode),
+ (short, 'hiliteState', InMode),
+)
+methods.append(f)
+
+f = Function(void, 'UpdtControl',
+ (WindowPtr, 'theWindow', InMode),
+ (RgnHandle, 'updateRgn', InMode),
+)
+functions.append(f)
+
+f = Function(void, 'UpdateControls',
+ (WindowPtr, 'theWindow', InMode),
+ (RgnHandle, 'updateRgn', InMode),
+)
+functions.append(f)
+
+f = Method(void, 'MoveControl',
+ (ControlHandle, 'theControl', InMode),
+ (short, 'h', InMode),
+ (short, 'v', InMode),
+)
+methods.append(f)
+
+f = Method(void, 'SizeControl',
+ (ControlHandle, 'theControl', InMode),
+ (short, 'w', InMode),
+ (short, 'h', InMode),
+)
+methods.append(f)
+
+f = Method(void, 'SetCtlValue',
+ (ControlHandle, 'theControl', InMode),
+ (short, 'theValue', InMode),
+)
+methods.append(f)
+
+f = Method(short, 'GetCtlValue',
+ (ControlHandle, 'theControl', InMode),
+)
+methods.append(f)
+
+f = Method(void, 'SetCtlMin',
+ (ControlHandle, 'theControl', InMode),
+ (short, 'minValue', InMode),
+)
+methods.append(f)
+
+f = Method(short, 'GetCtlMin',
+ (ControlHandle, 'theControl', InMode),
+)
+methods.append(f)
+
+f = Method(void, 'SetCtlMax',
+ (ControlHandle, 'theControl', InMode),
+ (short, 'maxValue', InMode),
+)
+methods.append(f)
+
+f = Method(short, 'GetCtlMax',
+ (ControlHandle, 'theControl', InMode),
+)
+methods.append(f)
+
+f = Method(void, 'SetCRefCon',
+ (ControlHandle, 'theControl', InMode),
+ (long, 'data', InMode),
+)
+methods.append(f)
+
+f = Method(long, 'GetCRefCon',
+ (ControlHandle, 'theControl', InMode),
+)
+methods.append(f)
+
+f = Method(void, 'DragControl',
+ (ControlHandle, 'theControl', InMode),
+ (Point, 'startPt', InMode),
+ (Rect_ptr, 'limitRect', InMode),
+ (Rect_ptr, 'slopRect', InMode),
+ (short, 'axis', InMode),
+)
+methods.append(f)
+
+f = Method(short, 'TestControl',
+ (ControlHandle, 'theControl', InMode),
+ (Point, 'thePt', InMode),
+)
+methods.append(f)
+
+f = Method(short, 'TrackControl',
+ (ControlHandle, 'theControl', InMode),
+ (Point, 'thePoint', InMode),
+ (FakeType('(ControlActionUPP)0'), 'actionProc', InMode),
+)
+methods.append(f)
+
+f = Function(short, 'FindControl',
+ (Point, 'thePoint', InMode),
+ (WindowPtr, 'theWindow', InMode),
+ (ExistingControlHandle, 'theControl', OutMode),
+)
+functions.append(f)
+
+f = Method(short, 'GetCVariant',
+ (ControlHandle, 'theControl', InMode),
+)
+methods.append(f)
diff --git a/Mac/Modules/ctl/ctlscan.py b/Mac/Modules/ctl/ctlscan.py
new file mode 100644
index 0000000..f104e8d
--- /dev/null
+++ b/Mac/Modules/ctl/ctlscan.py
@@ -0,0 +1,60 @@
+# Scan <Controls.h>, generating ctlgen.py.
+
+from scantools import Scanner
+
+def main():
+ input = "Controls.h"
+ output = "ctlgen.py"
+ defsoutput = "Controls.py"
+ scanner = MyScanner(input, output, defsoutput)
+ scanner.scan()
+ scanner.close()
+ print "=== Done scanning and generating, now doing 'import ctlsupport' ==="
+ import ctlsupport
+ print "=== Done. It's up to you to compile Ctlmodule.c ==="
+
+class MyScanner(Scanner):
+
+ def destination(self, type, name, arglist):
+ classname = "Function"
+ listname = "functions"
+ if arglist:
+ t, n, m = arglist[0]
+ if t == "ControlHandle" and m == "InMode":
+ classname = "Method"
+ listname = "methods"
+ return classname, listname
+
+ def makeblacklistnames(self):
+ return [
+ 'DisposeControl' # Implied by deletion of control object
+ 'KillControls', # Implied by close of dialog
+ 'SetCtlAction',
+ ]
+
+ def makeblacklisttypes(self):
+ return [
+ 'ProcPtr',
+ 'CCTabHandle',
+ 'AuxCtlHandle',
+ ]
+
+ def makerepairinstructions(self):
+ return [
+ ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
+ [("InBuffer", "*", "*")]),
+
+ ([("void", "*", "OutMode"), ("long", "*", "InMode"),
+ ("long", "*", "OutMode")],
+ [("VarVarOutBuffer", "*", "InOutMode")]),
+
+ # For TrackControl
+ ([("ProcPtr", "actionProc", "InMode")],
+ [("FakeType('(ControlActionUPP)0')", "*", "*")]),
+
+ ([("ControlHandle", "*", "OutMode")],
+ [("ExistingControlHandle", "*", "*")]),
+ ]
+
+if __name__ == "__main__":
+ main()
diff --git a/Mac/Modules/ctl/ctlsupport.py b/Mac/Modules/ctl/ctlsupport.py
new file mode 100644
index 0000000..97b1f33
--- /dev/null
+++ b/Mac/Modules/ctl/ctlsupport.py
@@ -0,0 +1,86 @@
+# This script generates a Python interface for an Apple Macintosh Manager.
+# It uses the "bgen" package to generate C code.
+# The function specifications are generated by scanning the mamager's header file,
+# using the "scantools" package (customized for this particular manager).
+
+import string
+
+# Declarations that change for each manager
+MACHEADERFILE = 'Controls.h' # The Apple header file
+MODNAME = 'Ctl' # The name of the module
+OBJECTNAME = 'Control' # The basic name of the objects used here
+
+# The following is *usually* unchanged but may still require tuning
+MODPREFIX = MODNAME # The prefix for module-wide routines
+OBJECTTYPE = OBJECTNAME + 'Handle' # The C type used to represent them
+OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
+INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
+OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
+
+from macsupport import *
+
+# Create the type objects
+
+ControlHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
+ExistingControlHandle = OpaqueByValueType(OBJECTTYPE, "CtlObj_WhichControl", "BUG")
+
+RgnHandle = FakeType("theWindow->visRgn") # XXX
+
+includestuff = includestuff + """
+#include <%s>""" % MACHEADERFILE + """
+
+#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
+
+extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
+
+#ifdef THINK_C
+#define ControlActionUPP ProcPtr
+#endif
+"""
+
+finalstuff = finalstuff + """
+PyObject *
+CtlObj_WhichControl(ControlHandle c)
+{
+ PyObject *it;
+
+ /* XXX What if we find a control belonging to some other package? */
+ if (c == NULL)
+ it = NULL;
+ else
+ it = (PyObject *) GetCRefCon(c);
+ if (it == NULL || ((ControlObject *)it)->ob_itself != c)
+ it = Py_None;
+ Py_INCREF(it);
+ return it;
+}
+"""
+
+class MyObjectDefinition(GlobalObjectDefinition):
+ def outputCheckNewArg(self):
+ Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+ def outputInitStructMembers(self):
+ GlobalObjectDefinition.outputInitStructMembers(self)
+ Output("SetCRefCon(itself, (long)it);")
+
+# Create the generator groups and link them
+module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
+object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
+module.addobject(object)
+
+# Create the generator classes used to populate the lists
+Function = OSErrFunctionGenerator
+Method = OSErrMethodGenerator
+
+# Create and populate the lists
+functions = []
+methods = []
+execfile(INPUTFILE)
+
+# add the populated lists to the generator groups
+for f in functions: module.add(f)
+for f in methods: object.add(f)
+
+# generate output (open the output file as late as possible)
+SetOutputFileName(OUTPUTFILE)
+module.generate()