diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2000-05-14 22:05:36 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2000-05-14 22:05:36 (GMT) |
commit | ebd0106c77802586adca7cec286b7437a66deb3c (patch) | |
tree | 2cff25e3f17617ecbd2a85da63825536aa32a148 | |
parent | 8711a2e1501dcaac7ddee56a21b5b1cd60e2803e (diff) | |
download | cpython-ebd0106c77802586adca7cec286b7437a66deb3c.zip cpython-ebd0106c77802586adca7cec286b7437a66deb3c.tar.gz cpython-ebd0106c77802586adca7cec286b7437a66deb3c.tar.bz2 |
Interface to macOS 9 HTMLRenderingLib. Not yet functional.
-rw-r--r-- | Mac/Build/HtmlRender.prj | bin | 0 -> 42130 bytes | |||
-rw-r--r-- | Mac/Build/HtmlRender.prj.exp | 1 | ||||
-rw-r--r-- | Mac/Modules/htmlrender/HtmlRendermodule.c | 802 | ||||
-rw-r--r-- | Mac/Modules/htmlrender/htmlscan.py | 61 | ||||
-rw-r--r-- | Mac/Modules/htmlrender/htmlsupport.py | 210 |
5 files changed, 1074 insertions, 0 deletions
diff --git a/Mac/Build/HtmlRender.prj b/Mac/Build/HtmlRender.prj Binary files differnew file mode 100644 index 0000000..eb57b12 --- /dev/null +++ b/Mac/Build/HtmlRender.prj diff --git a/Mac/Build/HtmlRender.prj.exp b/Mac/Build/HtmlRender.prj.exp new file mode 100644 index 0000000..949339f --- /dev/null +++ b/Mac/Build/HtmlRender.prj.exp @@ -0,0 +1 @@ +initHtmlRender diff --git a/Mac/Modules/htmlrender/HtmlRendermodule.c b/Mac/Modules/htmlrender/HtmlRendermodule.c new file mode 100644 index 0000000..e521c11 --- /dev/null +++ b/Mac/Modules/htmlrender/HtmlRendermodule.c @@ -0,0 +1,802 @@ + +/* ======================= Module HtmlRender ======================== */ + +#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 *OptResObj_New(Handle); +extern int OptResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); +extern PyTypeObject Window_Type; +#define WinObj_Check(x) ((x)->ob_type == &Window_Type) + +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 *GrafObj_New(GrafPtr); +extern int GrafObj_Convert(PyObject *, GrafPtr *); + +extern PyObject *BMObj_New(BitMapPtr); +extern int BMObj_Convert(PyObject *, BitMapPtr *); + +extern PyObject *WinObj_WhichWindow(WindowPtr); + +#include <HTMLRendering.h> + +static PyObject *Html_Error; + +/* --------------------- Object type HtmlObject --------------------- */ + +PyTypeObject HtmlObject_Type; + +#define HtmlObj_Check(x) ((x)->ob_type == &HtmlObject_Type) + +typedef struct HtmlObjectObject { + PyObject_HEAD + HRReference ob_itself; +} HtmlObjectObject; + +PyObject *HtmlObj_New(itself) + HRReference itself; +{ + HtmlObjectObject *it; + it = PyObject_NEW(HtmlObjectObject, &HtmlObject_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + return (PyObject *)it; +} +HtmlObj_Convert(v, p_itself) + PyObject *v; + HRReference *p_itself; +{ + if (!HtmlObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "HtmlObject required"); + return 0; + } + *p_itself = ((HtmlObjectObject *)v)->ob_itself; + return 1; +} + +static void HtmlObj_dealloc(self) + HtmlObjectObject *self; +{ + /* Cleanup of self->ob_itself goes here */ + PyMem_DEL(self); +} + +static PyObject *HtmlObj_HRDisposeReference(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = HRDisposeReference(_self->ob_itself); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRSetGrafPtr(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + GrafPtr grafPtr; + if (!PyArg_ParseTuple(_args, "O&", + GrafObj_Convert, &grafPtr)) + return NULL; + _err = HRSetGrafPtr(_self->ob_itself, + grafPtr); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRActivate(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = HRActivate(_self->ob_itself); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRDeactivate(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = HRDeactivate(_self->ob_itself); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRDraw(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + RgnHandle updateRgnH; + if (!PyArg_ParseTuple(_args, "O&", + ResObj_Convert, &updateRgnH)) + return NULL; + _err = HRDraw(_self->ob_itself, + updateRgnH); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRSetRenderingRect(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + Rect renderingRect; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetRect, &renderingRect)) + return NULL; + _err = HRSetRenderingRect(_self->ob_itself, + &renderingRect); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRGetRenderedImageSize(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + Point renderingSize; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = HRGetRenderedImageSize(_self->ob_itself, + &renderingSize); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + PyMac_BuildPoint, renderingSize); + return _res; +} + +static PyObject *HtmlObj_HRScrollToLocation(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + Point location; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = HRScrollToLocation(_self->ob_itself, + &location); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + PyMac_BuildPoint, location); + return _res; +} + +static PyObject *HtmlObj_HRForceQuickdraw(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + Boolean forceQuickdraw; + if (!PyArg_ParseTuple(_args, "b", + &forceQuickdraw)) + return NULL; + _err = HRForceQuickdraw(_self->ob_itself, + forceQuickdraw); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRSetScrollbarState(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + HRScrollbarState hScrollbarState; + HRScrollbarState vScrollbarState; + if (!PyArg_ParseTuple(_args, "hh", + &hScrollbarState, + &vScrollbarState)) + return NULL; + _err = HRSetScrollbarState(_self->ob_itself, + hScrollbarState, + vScrollbarState); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRSetDrawBorder(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + Boolean drawBorder; + if (!PyArg_ParseTuple(_args, "b", + &drawBorder)) + return NULL; + _err = HRSetDrawBorder(_self->ob_itself, + drawBorder); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRSetGrowboxCutout(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + Boolean allowCutout; + if (!PyArg_ParseTuple(_args, "b", + &allowCutout)) + return NULL; + _err = HRSetGrowboxCutout(_self->ob_itself, + allowCutout); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRGoToFile(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + FSSpec fsspec; + Boolean addToHistory; + Boolean forceRefresh; + if (!PyArg_ParseTuple(_args, "O&bb", + PyMac_GetFSSpec, &fsspec, + &addToHistory, + &forceRefresh)) + return NULL; + _err = HRGoToFile(_self->ob_itself, + &fsspec, + addToHistory, + forceRefresh); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRGoToURL(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + char * url; + Boolean addToHistory; + Boolean forceRefresh; + if (!PyArg_ParseTuple(_args, "sbb", + &url, + &addToHistory, + &forceRefresh)) + return NULL; + _err = HRGoToURL(_self->ob_itself, + url, + addToHistory, + forceRefresh); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRGoToAnchor(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + char * anchorName; + if (!PyArg_ParseTuple(_args, "s", + &anchorName)) + return NULL; + _err = HRGoToAnchor(_self->ob_itself, + anchorName); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRGoToPtr(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + char *buffer__in__; + long buffer__len__; + int buffer__in_len__; + Boolean addToHistory; + Boolean forceRefresh; + if (!PyArg_ParseTuple(_args, "s#bb", + &buffer__in__, &buffer__in_len__, + &addToHistory, + &forceRefresh)) + return NULL; + buffer__len__ = buffer__in_len__; + _err = HRGoToPtr(_self->ob_itself, + buffer__in__, buffer__len__, + addToHistory, + forceRefresh); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + buffer__error__: ; + return _res; +} + +static PyObject *HtmlObj_HRGetRootURL(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + Handle rootURLH; + if (!PyArg_ParseTuple(_args, "O&", + ResObj_Convert, &rootURLH)) + return NULL; + _err = HRGetRootURL(_self->ob_itself, + rootURLH); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRGetBaseURL(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + Handle baseURLH; + if (!PyArg_ParseTuple(_args, "O&", + ResObj_Convert, &baseURLH)) + return NULL; + _err = HRGetBaseURL(_self->ob_itself, + baseURLH); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRGetHTMLURL(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + Handle HTMLURLH; + if (!PyArg_ParseTuple(_args, "O&", + ResObj_Convert, &HTMLURLH)) + return NULL; + _err = HRGetHTMLURL(_self->ob_itself, + HTMLURLH); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRGetTitle(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + StringPtr title; + if (!PyArg_ParseTuple(_args, "s", + &title)) + return NULL; + _err = HRGetTitle(_self->ob_itself, + title); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRGetHTMLFile(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + FSSpec fsspec; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = HRGetHTMLFile(_self->ob_itself, + &fsspec); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + PyMac_BuildFSSpec, fsspec); + return _res; +} + +static PyObject *HtmlObj_HRUnregisterWasURLVisitedUPP(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + HRUnregisterWasURLVisitedUPP(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRUnregisterNewURLUPP(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + HRUnregisterNewURLUPP(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *HtmlObj_HRUnregisterURLToFSSpecUPP(_self, _args) + HtmlObjectObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + HRUnregisterURLToFSSpecUPP(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef HtmlObj_methods[] = { + {"HRDisposeReference", (PyCFunction)HtmlObj_HRDisposeReference, 1, + "() -> None"}, + {"HRSetGrafPtr", (PyCFunction)HtmlObj_HRSetGrafPtr, 1, + "(GrafPtr grafPtr) -> None"}, + {"HRActivate", (PyCFunction)HtmlObj_HRActivate, 1, + "() -> None"}, + {"HRDeactivate", (PyCFunction)HtmlObj_HRDeactivate, 1, + "() -> None"}, + {"HRDraw", (PyCFunction)HtmlObj_HRDraw, 1, + "(RgnHandle updateRgnH) -> None"}, + {"HRSetRenderingRect", (PyCFunction)HtmlObj_HRSetRenderingRect, 1, + "(Rect renderingRect) -> None"}, + {"HRGetRenderedImageSize", (PyCFunction)HtmlObj_HRGetRenderedImageSize, 1, + "() -> (Point renderingSize)"}, + {"HRScrollToLocation", (PyCFunction)HtmlObj_HRScrollToLocation, 1, + "() -> (Point location)"}, + {"HRForceQuickdraw", (PyCFunction)HtmlObj_HRForceQuickdraw, 1, + "(Boolean forceQuickdraw) -> None"}, + {"HRSetScrollbarState", (PyCFunction)HtmlObj_HRSetScrollbarState, 1, + "(HRScrollbarState hScrollbarState, HRScrollbarState vScrollbarState) -> None"}, + {"HRSetDrawBorder", (PyCFunction)HtmlObj_HRSetDrawBorder, 1, + "(Boolean drawBorder) -> None"}, + {"HRSetGrowboxCutout", (PyCFunction)HtmlObj_HRSetGrowboxCutout, 1, + "(Boolean allowCutout) -> None"}, + {"HRGoToFile", (PyCFunction)HtmlObj_HRGoToFile, 1, + "(FSSpec fsspec, Boolean addToHistory, Boolean forceRefresh) -> None"}, + {"HRGoToURL", (PyCFunction)HtmlObj_HRGoToURL, 1, + "(char * url, Boolean addToHistory, Boolean forceRefresh) -> None"}, + {"HRGoToAnchor", (PyCFunction)HtmlObj_HRGoToAnchor, 1, + "(char * anchorName) -> None"}, + {"HRGoToPtr", (PyCFunction)HtmlObj_HRGoToPtr, 1, + "(Buffer buffer, Boolean addToHistory, Boolean forceRefresh) -> None"}, + {"HRGetRootURL", (PyCFunction)HtmlObj_HRGetRootURL, 1, + "(Handle rootURLH) -> None"}, + {"HRGetBaseURL", (PyCFunction)HtmlObj_HRGetBaseURL, 1, + "(Handle baseURLH) -> None"}, + {"HRGetHTMLURL", (PyCFunction)HtmlObj_HRGetHTMLURL, 1, + "(Handle HTMLURLH) -> None"}, + {"HRGetTitle", (PyCFunction)HtmlObj_HRGetTitle, 1, + "(StringPtr title) -> None"}, + {"HRGetHTMLFile", (PyCFunction)HtmlObj_HRGetHTMLFile, 1, + "() -> (FSSpec fsspec)"}, + {"HRUnregisterWasURLVisitedUPP", (PyCFunction)HtmlObj_HRUnregisterWasURLVisitedUPP, 1, + "() -> None"}, + {"HRUnregisterNewURLUPP", (PyCFunction)HtmlObj_HRUnregisterNewURLUPP, 1, + "() -> None"}, + {"HRUnregisterURLToFSSpecUPP", (PyCFunction)HtmlObj_HRUnregisterURLToFSSpecUPP, 1, + "() -> None"}, + {NULL, NULL, 0} +}; + +PyMethodChain HtmlObj_chain = { HtmlObj_methods, NULL }; + +static PyObject *HtmlObj_getattr(self, name) + HtmlObjectObject *self; + char *name; +{ + return Py_FindMethodInChain(&HtmlObj_chain, (PyObject *)self, name); +} + +#define HtmlObj_setattr NULL + +#define HtmlObj_compare NULL + +#define HtmlObj_repr NULL + +#define HtmlObj_hash NULL + +PyTypeObject HtmlObject_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "HtmlObject", /*tp_name*/ + sizeof(HtmlObjectObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) HtmlObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) HtmlObj_getattr, /*tp_getattr*/ + (setattrfunc) HtmlObj_setattr, /*tp_setattr*/ + (cmpfunc) HtmlObj_compare, /*tp_compare*/ + (reprfunc) HtmlObj_repr, /*tp_repr*/ + (PyNumberMethods *)0, /* tp_as_number */ + (PySequenceMethods *)0, /* tp_as_sequence */ + (PyMappingMethods *)0, /* tp_as_mapping */ + (hashfunc) HtmlObj_hash, /*tp_hash*/ +}; + +/* ------------------- End object type HtmlObject ------------------- */ + + +static PyObject *Html_HRGetHTMLRenderingLibVersion(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + NumVersion returnVers; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = HRGetHTMLRenderingLibVersion(&returnVers); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + PyMac_BuildNumVersion, returnVers); + return _res; +} + +static PyObject *Html_HRNewReference(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + HRReference hrRef; + OSType rendererType; + GrafPtr grafPtr; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &rendererType, + GrafObj_Convert, &grafPtr)) + return NULL; + _err = HRNewReference(&hrRef, + rendererType, + grafPtr); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + HtmlObj_New, hrRef); + return _res; +} + +static PyObject *Html_HRFreeMemory(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + SInt32 _rv; + Size inBytesNeeded; + if (!PyArg_ParseTuple(_args, "l", + &inBytesNeeded)) + return NULL; + _rv = HRFreeMemory(inBytesNeeded); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *Html_HRScreenConfigurationChanged(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + HRScreenConfigurationChanged(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Html_HRIsHREvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + EventRecord eventRecord; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetEventRecord, &eventRecord)) + return NULL; + _rv = HRIsHREvent(&eventRecord); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Html_HRUtilCreateFullURL(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + char * rootURL; + char * linkURL; + Handle fullURLH; + if (!PyArg_ParseTuple(_args, "ssO&", + &rootURL, + &linkURL, + ResObj_Convert, &fullURLH)) + return NULL; + _err = HRUtilCreateFullURL(rootURL, + linkURL, + fullURLH); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Html_HRUtilGetFSSpecFromURL(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + char * rootURL; + char * linkURL; + FSSpec destSpec; + if (!PyArg_ParseTuple(_args, "ss", + &rootURL, + &linkURL)) + return NULL; + _err = HRUtilGetFSSpecFromURL(rootURL, + linkURL, + &destSpec); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + PyMac_BuildFSSpec, destSpec); + return _res; +} + +static PyObject *Html_HRUtilGetURLFromFSSpec(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSStatus _err; + FSSpec fsspec; + Handle urlHandle; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetFSSpec, &fsspec, + ResObj_Convert, &urlHandle)) + return NULL; + _err = HRUtilGetURLFromFSSpec(&fsspec, + urlHandle); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef Html_methods[] = { + {"HRGetHTMLRenderingLibVersion", (PyCFunction)Html_HRGetHTMLRenderingLibVersion, 1, + "() -> (NumVersion returnVers)"}, + {"HRNewReference", (PyCFunction)Html_HRNewReference, 1, + "(OSType rendererType, GrafPtr grafPtr) -> (HRReference hrRef)"}, + {"HRFreeMemory", (PyCFunction)Html_HRFreeMemory, 1, + "(Size inBytesNeeded) -> (SInt32 _rv)"}, + {"HRScreenConfigurationChanged", (PyCFunction)Html_HRScreenConfigurationChanged, 1, + "() -> None"}, + {"HRIsHREvent", (PyCFunction)Html_HRIsHREvent, 1, + "(EventRecord eventRecord) -> (Boolean _rv)"}, + {"HRUtilCreateFullURL", (PyCFunction)Html_HRUtilCreateFullURL, 1, + "(char * rootURL, char * linkURL, Handle fullURLH) -> None"}, + {"HRUtilGetFSSpecFromURL", (PyCFunction)Html_HRUtilGetFSSpecFromURL, 1, + "(char * rootURL, char * linkURL) -> (FSSpec destSpec)"}, + {"HRUtilGetURLFromFSSpec", (PyCFunction)Html_HRUtilGetURLFromFSSpec, 1, + "(FSSpec fsspec, Handle urlHandle) -> None"}, + {NULL, NULL, 0} +}; + + + + +void initHtmlRender() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("HtmlRender", Html_methods); + d = PyModule_GetDict(m); + Html_Error = PyMac_GetOSErrException(); + if (Html_Error == NULL || + PyDict_SetItemString(d, "Error", Html_Error) != 0) + Py_FatalError("can't initialize HtmlRender.Error"); + HtmlObject_Type.ob_type = &PyType_Type; + Py_INCREF(&HtmlObject_Type); + if (PyDict_SetItemString(d, "HtmlObjectType", (PyObject *)&HtmlObject_Type) != 0) + Py_FatalError("can't initialize HtmlObjectType"); +} + +/* ===================== End module HtmlRender ====================== */ + diff --git a/Mac/Modules/htmlrender/htmlscan.py b/Mac/Modules/htmlrender/htmlscan.py new file mode 100644 index 0000000..ae31c37 --- /dev/null +++ b/Mac/Modules/htmlrender/htmlscan.py @@ -0,0 +1,61 @@ +# Scan an Apple header file, generating a Python file of generator calls. + +import sys +import os +BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen') +sys.path.append(BGENDIR) + +from scantools import Scanner +from bgenlocations import TOOLBOXDIR + +LONG = "HtmlRendering" +SHORT = "html" +OBJECT = "HRReference" + +def main(): +## input = LONG + ".h" + input = "Macintosh HD:SWdev:Jack:Universal:Interfaces:CIncludes:HTMLRendering.h" + output = SHORT + "gen.py" + defsoutput = TOOLBOXDIR + LONG + ".py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now importing the generated code... ===" + exec "import " + SHORT + "support" + print "=== Done. It's up to you to compile it now! ===" + +class MyScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "Function" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t == OBJECT and m == "InMode": + classname = "Method" + listname = "methods" + return classname, listname + + def makeblacklistnames(self): + return [ + ] + + def makeblacklisttypes(self): + return [ + "HRNewURLUPP", + "HRURLToFSSpecUPP", + "HRWasURLVisitedUPP", + ] + + def makerepairinstructions(self): + return [ + ([('char', '*', 'OutMode'), ('UInt32', '*', 'InMode')], + [('InBuffer', '*', 'InMode')]), + ] + + def writeinitialdefs(self): + self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") + + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/htmlrender/htmlsupport.py b/Mac/Modules/htmlrender/htmlsupport.py new file mode 100644 index 0000000..d4547ca --- /dev/null +++ b/Mac/Modules/htmlrender/htmlsupport.py @@ -0,0 +1,210 @@ +# This script generates the Dialogs interface for Python. +# It uses the "bgen" package to generate C code. +# It execs the file dlggen.py which contain the function definitions +# (dlggen.py was generated by dlgscan.py, scanning the <Dialogs.h> header file). + +from macsupport import * + +# Create the type objects + +HRReference = OpaqueByValueType("HRReference", "HtmlObj") + +HRScrollbarState = Type("HRScrollbarState", "h") +URLSourceType = Type("URLSourceType", "h") +GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj") +RgnHandle = OpaqueByValueType("RgnHandle", "ResObj") +char_ptr = Type("char *", "s") +StringPtr = Type("StringPtr", "s") + +### An OptHandle is either a handle or None (in case NULL is passed in). +### This is needed for GetDialogItem(). +##OptHandle = OpaqueByValueType("Handle", "OptResObj") +## +##ModalFilterProcPtr = InputOnlyType("PyObject*", "O") +##ModalFilterProcPtr.passInput = lambda name: "NewModalFilterProc(Dlg_PassFilterProc(%s))" % name +##ModalFilterUPP = ModalFilterProcPtr +## +## +##DITLMethod = Type("DITLMethod", "h") +##DialogItemIndex = Type("DialogItemIndex", "h") +##DialogItemType = Type("DialogItemType", "h") +##DialogItemIndexZeroBased = Type("DialogItemIndexZeroBased", "h") +##AlertType = Type("AlertType", "h") +##StringPtr = Str255 +##EventMask = Type("EventMask", "h") +## +includestuff = includestuff + """ +#include <HTMLRendering.h> +""" +## +###ifndef HAVE_UNIVERSAL_HEADERS +###define NewModalFilterProc(x) (x) +###endif +## +###define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ +## +##/* XXX Shouldn't this be a stack? */ +##static PyObject *Dlg_FilterProc_callback = NULL; +## +##static PyObject *DlgObj_New(DialogPtr); /* Forward */ +## +##static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog, +## EventRecord *event, +## short *itemHit) +##{ +## Boolean rv; +## PyObject *args, *res; +## PyObject *callback = Dlg_FilterProc_callback; +## if (callback == NULL) +## return 0; /* Default behavior */ +## Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */ +## args = Py_BuildValue("O&O&", WinObj_WhichWindow, dialog, PyMac_BuildEventRecord, event); +## if (args == NULL) +## res = NULL; +## else { +## res = PyEval_CallObject(callback, args); +## Py_DECREF(args); +## } +## if (res == NULL) { +## PySys_WriteStderr("Exception in Dialog Filter\\n"); +## PyErr_Print(); +## *itemHit = -1; /* Fake return item */ +## return 1; /* We handled it */ +## } +## else { +## Dlg_FilterProc_callback = callback; +## if (PyInt_Check(res)) { +## *itemHit = PyInt_AsLong(res); +## rv = 1; +## } +## else +## rv = PyObject_IsTrue(res); +## } +## Py_DECREF(res); +## return rv; +##} +## +##static ModalFilterProcPtr +##Dlg_PassFilterProc(PyObject *callback) +##{ +## PyObject *tmp = Dlg_FilterProc_callback; +## Dlg_FilterProc_callback = NULL; +## if (callback == Py_None) { +## Py_XDECREF(tmp); +## return NULL; +## } +## Py_INCREF(callback); +## Dlg_FilterProc_callback = callback; +## Py_XDECREF(tmp); +## return &Dlg_UnivFilterProc; +##} +## +##static PyObject *Dlg_UserItemProc_callback = NULL; +## +##static pascal void Dlg_UnivUserItemProc(DialogPtr dialog, +## short item) +##{ +## PyObject *args, *res; +## +## if (Dlg_UserItemProc_callback == NULL) +## return; /* Default behavior */ +## Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */ +## args = Py_BuildValue("O&h", WinObj_WhichWindow, dialog, item); +## if (args == NULL) +## res = NULL; +## else { +## res = PyEval_CallObject(Dlg_UserItemProc_callback, args); +## Py_DECREF(args); +## } +## if (res == NULL) { +## PySys_WriteStderr("Exception in Dialog UserItem proc\\n"); +## PyErr_Print(); +## } +## Py_XDECREF(res); +## return; +##} +## +##extern PyMethodChain WinObj_chain; +##""" +## + +# Define a class which specializes our object definition +class MyObjectDefinition(GlobalObjectDefinition): + pass +## def __init__(self, name, prefix = None, itselftype = None): +## GlobalObjectDefinition.__init__(self, name, prefix, itselftype) +## self.basechain = "&WinObj_chain" +## def outputInitStructMembers(self): +## GlobalObjectDefinition.outputInitStructMembers(self) +## Output("SetWRefCon(itself, (long)it);") +## def outputCheckNewArg(self): +## Output("if (itself == NULL) return Py_None;") +## def outputCheckConvertArg(self): +## Output("if (v == Py_None) { *p_itself = NULL; return 1; }") +## Output("if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);") +## Output(" return 1; }") +## def outputFreeIt(self, itselfname): +## Output("DisposeDialog(%s);", itselfname) + +# Create the generator groups and link them +module = MacModule('HtmlRender', 'Html', includestuff, finalstuff, initstuff) +object = MyObjectDefinition('HtmlObject', 'HtmlObj', 'HRReference') +module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +methods = [] +execfile("htmlgen.py") + +# add the populated lists to the generator groups +for f in functions: module.add(f) +for f in methods: object.add(f) + +### Some methods that are currently macro's in C, but will be real routines +### in MacOS 8. +## +##f = Method(ExistingDialogPtr, 'GetDialogWindow', (DialogRef, 'dialog', InMode)) +##object.add(f) +##f = Method(SInt16, 'GetDialogDefaultItem', (DialogRef, 'dialog', InMode)) +##object.add(f) +##f = Method(SInt16, 'GetDialogCancelItem', (DialogRef, 'dialog', InMode)) +##object.add(f) +##f = Method(SInt16, 'GetDialogKeyboardFocusItem', (DialogRef, 'dialog', InMode)) +##object.add(f) +##f = Method(void, 'SetGrafPortOfDialog', (DialogRef, 'dialog', InMode)) +##object.add(f) +## +##setuseritembody = """ +## PyObject *new = NULL; +## +## +## if (!PyArg_ParseTuple(_args, "|O", &new)) +## return NULL; +## +## if (Dlg_UserItemProc_callback && new && new != Py_None) { +## PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed"); +## return NULL; +## } +## +## if (new == Py_None) { +## new = NULL; +## _res = Py_None; +## Py_INCREF(Py_None); +## } else { +## Py_INCREF(new); +## _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc)); +## } +## +## Dlg_UserItemProc_callback = new; +## return _res; +##""" +##f = ManualGenerator("SetUserItemHandler", setuseritembody) +##module.add(f) + +# generate output +SetOutputFileName('HtmlRendermodule.c') +module.generate() |