Kaydet (Commit) a1a0fef2 authored tarafından Jack Jansen's avatar Jack Jansen

Unified handle-conversion scheme to

  handle = Ctl.as_Resource(ctl)
  ctl = Ctl.as_Control(handle)
and similarly for List, Menu, TE. The old handle.as_Control() methods are
still there for backward compatability.
üst 7b912120
...@@ -45,6 +45,7 @@ extern PyObject *WinObj_WhichWindow(WindowPtr); ...@@ -45,6 +45,7 @@ extern PyObject *WinObj_WhichWindow(WindowPtr);
#include <Controls.h> #include <Controls.h>
#define as_Control(h) ((ControlHandle)h) #define as_Control(h) ((ControlHandle)h)
#define as_Resource(ctl) ((Handle)ctl)
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
...@@ -1008,9 +1009,13 @@ static PyObject *CtlObj_as_Resource(_self, _args) ...@@ -1008,9 +1009,13 @@ static PyObject *CtlObj_as_Resource(_self, _args)
PyObject *_args; PyObject *_args;
{ {
PyObject *_res = NULL; PyObject *_res = NULL;
Handle _rv;
return ResObj_New((Handle)_self->ob_itself); if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = as_Resource(_self->ob_itself);
_res = Py_BuildValue("O&",
ResObj_New, _rv);
return _res;
} }
static PyObject *CtlObj_DisposeControl(_self, _args) static PyObject *CtlObj_DisposeControl(_self, _args)
...@@ -1400,7 +1405,7 @@ static PyMethodDef CtlObj_methods[] = { ...@@ -1400,7 +1405,7 @@ static PyMethodDef CtlObj_methods[] = {
{"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1, {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
"(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"}, "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
{"as_Resource", (PyCFunction)CtlObj_as_Resource, 1, {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
"Return this Control as a Resource"}, "() -> (Handle _rv)"},
{"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1, {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
"() -> None"}, "() -> None"},
{"TrackControl", (PyCFunction)CtlObj_TrackControl, 1, {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
......
...@@ -2,13 +2,7 @@ f = Function(ControlHandle, 'as_Control', ...@@ -2,13 +2,7 @@ f = Function(ControlHandle, 'as_Control',
(Handle, 'h', InMode)) (Handle, 'h', InMode))
functions.append(f) functions.append(f)
as_resource_body = """ f = Method(Handle, 'as_Resource', (ControlHandle, 'ctl', InMode))
return ResObj_New((Handle)_self->ob_itself);
"""
f = ManualGenerator("as_Resource", as_resource_body)
f.docstring = lambda : "Return this Control as a Resource"
methods.append(f) methods.append(f)
DisposeControl_body = """ DisposeControl_body = """
......
...@@ -45,6 +45,7 @@ includestuff = includestuff + """ ...@@ -45,6 +45,7 @@ includestuff = includestuff + """
#include <%s>""" % MACHEADERFILE + """ #include <%s>""" % MACHEADERFILE + """
#define as_Control(h) ((ControlHandle)h) #define as_Control(h) ((ControlHandle)h)
#define as_Resource(ctl) ((Handle)ctl)
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
......
...@@ -44,6 +44,9 @@ extern PyObject *WinObj_WhichWindow(WindowPtr); ...@@ -44,6 +44,9 @@ extern PyObject *WinObj_WhichWindow(WindowPtr);
#include <Lists.h> #include <Lists.h>
#define as_List(x) ((ListHandle)x)
#define as_Resource(lh) ((Handle)lh)
static PyObject *List_Error; static PyObject *List_Error;
/* ------------------------ Object type List ------------------------ */ /* ------------------------ Object type List ------------------------ */
...@@ -506,6 +509,20 @@ static PyObject *ListObj_LDraw(_self, _args) ...@@ -506,6 +509,20 @@ static PyObject *ListObj_LDraw(_self, _args)
return _res; return _res;
} }
static PyObject *ListObj_as_Resource(_self, _args)
ListObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
Handle _rv;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = as_Resource(_self->ob_itself);
_res = Py_BuildValue("O&",
ResObj_New, _rv);
return _res;
}
static PyMethodDef ListObj_methods[] = { static PyMethodDef ListObj_methods[] = {
{"LAddColumn", (PyCFunction)ListObj_LAddColumn, 1, {"LAddColumn", (PyCFunction)ListObj_LAddColumn, 1,
"(short count, short colNum) -> (short _rv)"}, "(short count, short colNum) -> (short _rv)"},
...@@ -551,6 +568,8 @@ static PyMethodDef ListObj_methods[] = { ...@@ -551,6 +568,8 @@ static PyMethodDef ListObj_methods[] = {
"(Boolean setIt, Point theCell) -> None"}, "(Boolean setIt, Point theCell) -> None"},
{"LDraw", (PyCFunction)ListObj_LDraw, 1, {"LDraw", (PyCFunction)ListObj_LDraw, 1,
"(Point theCell) -> None"}, "(Point theCell) -> None"},
{"as_Resource", (PyCFunction)ListObj_as_Resource, 1,
"() -> (Handle _rv)"},
{NULL, NULL, 0} {NULL, NULL, 0}
}; };
...@@ -662,9 +681,27 @@ static PyObject *List_LNew(_self, _args) ...@@ -662,9 +681,27 @@ static PyObject *List_LNew(_self, _args)
return _res; return _res;
} }
static PyObject *List_as_List(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
ListHandle _rv;
Handle h;
if (!PyArg_ParseTuple(_args, "O&",
ResObj_Convert, &h))
return NULL;
_rv = as_List(h);
_res = Py_BuildValue("O&",
ListObj_New, _rv);
return _res;
}
static PyMethodDef List_methods[] = { static PyMethodDef List_methods[] = {
{"LNew", (PyCFunction)List_LNew, 1, {"LNew", (PyCFunction)List_LNew, 1,
"(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle _rv)"}, "(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle _rv)"},
{"as_List", (PyCFunction)List_as_List, 1,
"(Handle h) -> (ListHandle _rv)"},
{NULL, NULL, 0} {NULL, NULL, 0}
}; };
......
...@@ -27,10 +27,13 @@ VarOutBufferShortsize = VarHeapOutputBufferType('char', 'short', 's') # (buf, &l ...@@ -27,10 +27,13 @@ VarOutBufferShortsize = VarHeapOutputBufferType('char', 'short', 's') # (buf, &l
InBufferShortsize = VarInputBufferType('char', 'short', 's') # (buf, len) InBufferShortsize = VarInputBufferType('char', 'short', 's') # (buf, len)
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj") RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
Handle = OpaqueByValueType("Handle", "ResObj")
includestuff = includestuff + """ includestuff = includestuff + """
#include <%s>""" % MACHEADERFILE + """ #include <%s>""" % MACHEADERFILE + """
#define as_List(x) ((ListHandle)x)
#define as_Resource(lh) ((Handle)lh)
""" """
class ListMethodGenerator(MethodGenerator): class ListMethodGenerator(MethodGenerator):
...@@ -93,7 +96,7 @@ class MyObjectDefinition(GlobalObjectDefinition): ...@@ -93,7 +96,7 @@ class MyObjectDefinition(GlobalObjectDefinition):
def outputSetattr(self): def outputSetattr(self):
Output(setattrCode) Output(setattrCode)
# From here on it's basically all boiler plate... # From here on it's basically all boiler plate...
# Create the generator groups and link them # Create the generator groups and link them
...@@ -110,6 +113,13 @@ functions = [] ...@@ -110,6 +113,13 @@ functions = []
methods = [] methods = []
execfile(INPUTFILE) execfile(INPUTFILE)
# Function to convert any handle to a list and vv.
f = Function(ListHandle, 'as_List', (Handle, 'h', InMode))
functions.append(f)
f = Method(Handle, 'as_Resource', (ListHandle, 'lh', InMode))
methods.append(f)
# add the populated lists to the generator groups # add the populated lists to the generator groups
# (in a different wordl the scan program would generate this) # (in a different wordl the scan program would generate this)
for f in functions: module.add(f) for f in functions: module.add(f)
......
...@@ -48,6 +48,7 @@ extern PyObject *WinObj_WhichWindow(WindowPtr); ...@@ -48,6 +48,7 @@ extern PyObject *WinObj_WhichWindow(WindowPtr);
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
#define as_Menu(h) ((MenuHandle)h) #define as_Menu(h) ((MenuHandle)h)
#define as_Resource(h) ((Handle)h)
static PyObject *Menu_Error; static PyObject *Menu_Error;
...@@ -1123,9 +1124,13 @@ static PyObject *MenuObj_as_Resource(_self, _args) ...@@ -1123,9 +1124,13 @@ static PyObject *MenuObj_as_Resource(_self, _args)
PyObject *_args; PyObject *_args;
{ {
PyObject *_res = NULL; PyObject *_res = NULL;
Handle _rv;
return ResObj_New((Handle)_self->ob_itself); if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = as_Resource(_self->ob_itself);
_res = Py_BuildValue("O&",
ResObj_New, _rv);
return _res;
} }
static PyObject *MenuObj_AppendMenu(_self, _args) static PyObject *MenuObj_AppendMenu(_self, _args)
...@@ -1291,7 +1296,7 @@ static PyMethodDef MenuObj_methods[] = { ...@@ -1291,7 +1296,7 @@ static PyMethodDef MenuObj_methods[] = {
{"IsMenuItemIconEnabled", (PyCFunction)MenuObj_IsMenuItemIconEnabled, 1, {"IsMenuItemIconEnabled", (PyCFunction)MenuObj_IsMenuItemIconEnabled, 1,
"(UInt16 item) -> (Boolean _rv)"}, "(UInt16 item) -> (Boolean _rv)"},
{"as_Resource", (PyCFunction)MenuObj_as_Resource, 1, {"as_Resource", (PyCFunction)MenuObj_as_Resource, 1,
"Return this Menu as a Resource"}, "() -> (Handle _rv)"},
{"AppendMenu", (PyCFunction)MenuObj_AppendMenu, 1, {"AppendMenu", (PyCFunction)MenuObj_AppendMenu, 1,
"(Str255 data) -> None"}, "(Str255 data) -> None"},
{"InsertMenu", (PyCFunction)MenuObj_InsertMenu, 1, {"InsertMenu", (PyCFunction)MenuObj_InsertMenu, 1,
......
...@@ -3,17 +3,10 @@ f = Function(void, 'OpenDeskAcc', ...@@ -3,17 +3,10 @@ f = Function(void, 'OpenDeskAcc',
) )
functions.append(f) functions.append(f)
f = Function(MenuHandle, 'as_Menu', f = Function(MenuHandle, 'as_Menu', (Handle, 'h', InMode))
(Handle, 'h', InMode))
functions.append(f) functions.append(f)
as_resource_body = """ f = Method(Handle, 'as_Resource', (MenuHandle, 'h', InMode))
return ResObj_New((Handle)_self->ob_itself);
"""
f = ManualGenerator("as_Resource", as_resource_body)
f.docstring = lambda : "Return this Menu as a Resource"
methods.append(f) methods.append(f)
# The following have "Mac" prepended to their names in the include file # The following have "Mac" prepended to their names in the include file
......
...@@ -24,6 +24,7 @@ from macsupport import * ...@@ -24,6 +24,7 @@ from macsupport import *
MenuHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) MenuHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
MenuRef = MenuHandle MenuRef = MenuHandle
Handle = OpaqueByValueType("Handle", "ResObj")
unsigned_char = Type('unsigned char', 'b') unsigned_char = Type('unsigned char', 'b')
...@@ -34,6 +35,7 @@ includestuff = includestuff + """ ...@@ -34,6 +35,7 @@ includestuff = includestuff + """
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
#define as_Menu(h) ((MenuHandle)h) #define as_Menu(h) ((MenuHandle)h)
#define as_Resource(h) ((Handle)h)
""" """
class MyObjectDefinition(GlobalObjectDefinition): class MyObjectDefinition(GlobalObjectDefinition):
......
...@@ -44,6 +44,9 @@ extern PyObject *WinObj_WhichWindow(WindowPtr); ...@@ -44,6 +44,9 @@ extern PyObject *WinObj_WhichWindow(WindowPtr);
#include <TextEdit.h> #include <TextEdit.h>
#define as_TE(h) ((TEHandle)h)
#define as_Handle(teh) ((Handle)teh)
/* Exported by Qdmodule.c: */ /* Exported by Qdmodule.c: */
extern PyObject *QdRGB_New(RGBColor *); extern PyObject *QdRGB_New(RGBColor *);
extern int QdRGB_Convert(PyObject *, RGBColor *); extern int QdRGB_Convert(PyObject *, RGBColor *);
...@@ -740,6 +743,20 @@ static PyObject *TEObj_TEGetHiliteRgn(_self, _args) ...@@ -740,6 +743,20 @@ static PyObject *TEObj_TEGetHiliteRgn(_self, _args)
return _res; return _res;
} }
static PyObject *TEObj_as_Handle(_self, _args)
TEObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
Handle _rv;
if (!PyArg_ParseTuple(_args, ""))
return NULL;
_rv = as_Handle(_self->ob_itself);
_res = Py_BuildValue("O&",
ResObj_New, _rv);
return _res;
}
static PyMethodDef TEObj_methods[] = { static PyMethodDef TEObj_methods[] = {
{"TESetText", (PyCFunction)TEObj_TESetText, 1, {"TESetText", (PyCFunction)TEObj_TESetText, 1,
"(Buffer text) -> None"}, "(Buffer text) -> None"},
...@@ -813,6 +830,8 @@ static PyMethodDef TEObj_methods[] = { ...@@ -813,6 +830,8 @@ static PyMethodDef TEObj_methods[] = {
"(short feature, short action) -> (short _rv)"}, "(short feature, short action) -> (short _rv)"},
{"TEGetHiliteRgn", (PyCFunction)TEObj_TEGetHiliteRgn, 1, {"TEGetHiliteRgn", (PyCFunction)TEObj_TEGetHiliteRgn, 1,
"(RgnHandle region) -> None"}, "(RgnHandle region) -> None"},
{"as_Handle", (PyCFunction)TEObj_as_Handle, 1,
"() -> (Handle _rv)"},
{NULL, NULL, 0} {NULL, NULL, 0}
}; };
...@@ -1029,6 +1048,22 @@ static PyObject *TE_TEToScrap(_self, _args) ...@@ -1029,6 +1048,22 @@ static PyObject *TE_TEToScrap(_self, _args)
return _res; return _res;
} }
static PyObject *TE_as_TE(_self, _args)
PyObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
TEHandle _rv;
Handle h;
if (!PyArg_ParseTuple(_args, "O&",
ResObj_Convert, &h))
return NULL;
_rv = as_TE(h);
_res = Py_BuildValue("O&",
TEObj_New, _rv);
return _res;
}
static PyMethodDef TE_methods[] = { static PyMethodDef TE_methods[] = {
{"TEScrapHandle", (PyCFunction)TE_TEScrapHandle, 1, {"TEScrapHandle", (PyCFunction)TE_TEScrapHandle, 1,
"() -> (Handle _rv)"}, "() -> (Handle _rv)"},
...@@ -1046,6 +1081,8 @@ static PyMethodDef TE_methods[] = { ...@@ -1046,6 +1081,8 @@ static PyMethodDef TE_methods[] = {
"() -> None"}, "() -> None"},
{"TEToScrap", (PyCFunction)TE_TEToScrap, 1, {"TEToScrap", (PyCFunction)TE_TEToScrap, 1,
"() -> None"}, "() -> None"},
{"as_TE", (PyCFunction)TE_as_TE, 1,
"(Handle h) -> (TEHandle _rv)"},
{NULL, NULL, 0} {NULL, NULL, 0}
}; };
......
...@@ -23,7 +23,7 @@ from macsupport import * ...@@ -23,7 +23,7 @@ from macsupport import *
# Create the type objects # Create the type objects
TEHandle = OpaqueByValueType("TEHandle", "TEObj") TEHandle = OpaqueByValueType("TEHandle", "TEObj")
CharsHandle = OpaqueByValueType("CharsHandle", "ResObj") CharsHandle = OpaqueByValueType("CharsHandle", "ResObj")
##Handle = OpaqueByValueType("Handle", "ResObj") Handle = OpaqueByValueType("Handle", "ResObj")
StScrpHandle = OpaqueByValueType("StScrpHandle", "ResObj") StScrpHandle = OpaqueByValueType("StScrpHandle", "ResObj")
TEStyleHandle = OpaqueByValueType("TEStyleHandle", "ResObj") TEStyleHandle = OpaqueByValueType("TEStyleHandle", "ResObj")
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj") RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
...@@ -34,6 +34,9 @@ TextStyle_ptr = TextStyle ...@@ -34,6 +34,9 @@ TextStyle_ptr = TextStyle
includestuff = includestuff + """ includestuff = includestuff + """
#include <%s>""" % MACHEADERFILE + """ #include <%s>""" % MACHEADERFILE + """
#define as_TE(h) ((TEHandle)h)
#define as_Resource(teh) ((Handle)teh)
/* Exported by Qdmodule.c: */ /* Exported by Qdmodule.c: */
extern PyObject *QdRGB_New(RGBColor *); extern PyObject *QdRGB_New(RGBColor *);
extern int QdRGB_Convert(PyObject *, RGBColor *); extern int QdRGB_Convert(PyObject *, RGBColor *);
...@@ -143,6 +146,12 @@ functions = [] ...@@ -143,6 +146,12 @@ functions = []
methods = [] methods = []
execfile(INPUTFILE) execfile(INPUTFILE)
# Converter from/to handle
f = Function(TEHandle, 'as_TE', (Handle, 'h', InMode))
functions.append(f)
f = Method(Handle, 'as_Resource', (TEHandle, 'teh', InMode))
methods.append(f)
# add the populated lists to the generator groups # add the populated lists to the generator groups
# (in a different wordl the scan program would generate this) # (in a different wordl the scan program would generate this)
for f in functions: module.add(f) for f in functions: module.add(f)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment