2 /* ======================= Module HtmlRender ======================== */
8 #define SystemSevenOrLater 1
16 extern PyObject
*ResObj_New(Handle
);
17 extern int ResObj_Convert(PyObject
*, Handle
*);
18 extern PyObject
*OptResObj_New(Handle
);
19 extern int OptResObj_Convert(PyObject
*, Handle
*);
21 extern PyObject
*WinObj_New(WindowPtr
);
22 extern int WinObj_Convert(PyObject
*, WindowPtr
*);
23 extern PyTypeObject Window_Type
;
24 #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
26 extern PyObject
*DlgObj_New(DialogPtr
);
27 extern int DlgObj_Convert(PyObject
*, DialogPtr
*);
28 extern PyTypeObject Dialog_Type
;
29 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
31 extern PyObject
*MenuObj_New(MenuHandle
);
32 extern int MenuObj_Convert(PyObject
*, MenuHandle
*);
34 extern PyObject
*CtlObj_New(ControlHandle
);
35 extern int CtlObj_Convert(PyObject
*, ControlHandle
*);
37 extern PyObject
*GrafObj_New(GrafPtr
);
38 extern int GrafObj_Convert(PyObject
*, GrafPtr
*);
40 extern PyObject
*BMObj_New(BitMapPtr
);
41 extern int BMObj_Convert(PyObject
*, BitMapPtr
*);
43 extern PyObject
*WinObj_WhichWindow(WindowPtr
);
45 #include <HTMLRendering.h>
47 static PyObject
*Html_Error
;
49 /* --------------------- Object type HtmlObject --------------------- */
51 PyTypeObject HtmlObject_Type
;
53 #define HtmlObj_Check(x) ((x)->ob_type == &HtmlObject_Type)
55 typedef struct HtmlObjectObject
{
57 HRReference ob_itself
;
60 PyObject
*HtmlObj_New(itself
)
64 it
= PyObject_NEW(HtmlObjectObject
, &HtmlObject_Type
);
65 if (it
== NULL
) return NULL
;
66 it
->ob_itself
= itself
;
67 return (PyObject
*)it
;
69 HtmlObj_Convert(v
, p_itself
)
71 HRReference
*p_itself
;
73 if (!HtmlObj_Check(v
))
75 PyErr_SetString(PyExc_TypeError
, "HtmlObject required");
78 *p_itself
= ((HtmlObjectObject
*)v
)->ob_itself
;
82 static void HtmlObj_dealloc(self
)
83 HtmlObjectObject
*self
;
85 /* Cleanup of self->ob_itself goes here */
89 static PyObject
*HtmlObj_HRDisposeReference(_self
, _args
)
90 HtmlObjectObject
*_self
;
93 PyObject
*_res
= NULL
;
95 if (!PyArg_ParseTuple(_args
, ""))
97 _err
= HRDisposeReference(_self
->ob_itself
);
98 if (_err
!= noErr
) return PyMac_Error(_err
);
104 static PyObject
*HtmlObj_HRSetGrafPtr(_self
, _args
)
105 HtmlObjectObject
*_self
;
108 PyObject
*_res
= NULL
;
111 if (!PyArg_ParseTuple(_args
, "O&",
112 GrafObj_Convert
, &grafPtr
))
114 _err
= HRSetGrafPtr(_self
->ob_itself
,
116 if (_err
!= noErr
) return PyMac_Error(_err
);
122 static PyObject
*HtmlObj_HRActivate(_self
, _args
)
123 HtmlObjectObject
*_self
;
126 PyObject
*_res
= NULL
;
128 if (!PyArg_ParseTuple(_args
, ""))
130 _err
= HRActivate(_self
->ob_itself
);
131 if (_err
!= noErr
) return PyMac_Error(_err
);
137 static PyObject
*HtmlObj_HRDeactivate(_self
, _args
)
138 HtmlObjectObject
*_self
;
141 PyObject
*_res
= NULL
;
143 if (!PyArg_ParseTuple(_args
, ""))
145 _err
= HRDeactivate(_self
->ob_itself
);
146 if (_err
!= noErr
) return PyMac_Error(_err
);
152 static PyObject
*HtmlObj_HRDraw(_self
, _args
)
153 HtmlObjectObject
*_self
;
156 PyObject
*_res
= NULL
;
158 RgnHandle updateRgnH
;
159 if (!PyArg_ParseTuple(_args
, "O&",
160 ResObj_Convert
, &updateRgnH
))
162 _err
= HRDraw(_self
->ob_itself
,
164 if (_err
!= noErr
) return PyMac_Error(_err
);
170 static PyObject
*HtmlObj_HRSetRenderingRect(_self
, _args
)
171 HtmlObjectObject
*_self
;
174 PyObject
*_res
= NULL
;
177 if (!PyArg_ParseTuple(_args
, "O&",
178 PyMac_GetRect
, &renderingRect
))
180 _err
= HRSetRenderingRect(_self
->ob_itself
,
182 if (_err
!= noErr
) return PyMac_Error(_err
);
188 static PyObject
*HtmlObj_HRGetRenderedImageSize(_self
, _args
)
189 HtmlObjectObject
*_self
;
192 PyObject
*_res
= NULL
;
195 if (!PyArg_ParseTuple(_args
, ""))
197 _err
= HRGetRenderedImageSize(_self
->ob_itself
,
199 if (_err
!= noErr
) return PyMac_Error(_err
);
200 _res
= Py_BuildValue("O&",
201 PyMac_BuildPoint
, renderingSize
);
205 static PyObject
*HtmlObj_HRScrollToLocation(_self
, _args
)
206 HtmlObjectObject
*_self
;
209 PyObject
*_res
= NULL
;
212 if (!PyArg_ParseTuple(_args
, ""))
214 _err
= HRScrollToLocation(_self
->ob_itself
,
216 if (_err
!= noErr
) return PyMac_Error(_err
);
217 _res
= Py_BuildValue("O&",
218 PyMac_BuildPoint
, location
);
222 static PyObject
*HtmlObj_HRForceQuickdraw(_self
, _args
)
223 HtmlObjectObject
*_self
;
226 PyObject
*_res
= NULL
;
228 Boolean forceQuickdraw
;
229 if (!PyArg_ParseTuple(_args
, "b",
232 _err
= HRForceQuickdraw(_self
->ob_itself
,
234 if (_err
!= noErr
) return PyMac_Error(_err
);
240 static PyObject
*HtmlObj_HRSetScrollbarState(_self
, _args
)
241 HtmlObjectObject
*_self
;
244 PyObject
*_res
= NULL
;
246 HRScrollbarState hScrollbarState
;
247 HRScrollbarState vScrollbarState
;
248 if (!PyArg_ParseTuple(_args
, "hh",
252 _err
= HRSetScrollbarState(_self
->ob_itself
,
255 if (_err
!= noErr
) return PyMac_Error(_err
);
261 static PyObject
*HtmlObj_HRSetDrawBorder(_self
, _args
)
262 HtmlObjectObject
*_self
;
265 PyObject
*_res
= NULL
;
268 if (!PyArg_ParseTuple(_args
, "b",
271 _err
= HRSetDrawBorder(_self
->ob_itself
,
273 if (_err
!= noErr
) return PyMac_Error(_err
);
279 static PyObject
*HtmlObj_HRSetGrowboxCutout(_self
, _args
)
280 HtmlObjectObject
*_self
;
283 PyObject
*_res
= NULL
;
286 if (!PyArg_ParseTuple(_args
, "b",
289 _err
= HRSetGrowboxCutout(_self
->ob_itself
,
291 if (_err
!= noErr
) return PyMac_Error(_err
);
297 static PyObject
*HtmlObj_HRGoToFile(_self
, _args
)
298 HtmlObjectObject
*_self
;
301 PyObject
*_res
= NULL
;
304 Boolean addToHistory
;
305 Boolean forceRefresh
;
306 if (!PyArg_ParseTuple(_args
, "O&bb",
307 PyMac_GetFSSpec
, &fsspec
,
311 _err
= HRGoToFile(_self
->ob_itself
,
315 if (_err
!= noErr
) return PyMac_Error(_err
);
321 static PyObject
*HtmlObj_HRGoToURL(_self
, _args
)
322 HtmlObjectObject
*_self
;
325 PyObject
*_res
= NULL
;
328 Boolean addToHistory
;
329 Boolean forceRefresh
;
330 if (!PyArg_ParseTuple(_args
, "sbb",
335 _err
= HRGoToURL(_self
->ob_itself
,
339 if (_err
!= noErr
) return PyMac_Error(_err
);
345 static PyObject
*HtmlObj_HRGoToAnchor(_self
, _args
)
346 HtmlObjectObject
*_self
;
349 PyObject
*_res
= NULL
;
352 if (!PyArg_ParseTuple(_args
, "s",
355 _err
= HRGoToAnchor(_self
->ob_itself
,
357 if (_err
!= noErr
) return PyMac_Error(_err
);
363 static PyObject
*HtmlObj_HRGoToPtr(_self
, _args
)
364 HtmlObjectObject
*_self
;
367 PyObject
*_res
= NULL
;
371 int buffer__in_len__
;
372 Boolean addToHistory
;
373 Boolean forceRefresh
;
374 if (!PyArg_ParseTuple(_args
, "s#bb",
375 &buffer__in__
, &buffer__in_len__
,
379 buffer__len__
= buffer__in_len__
;
380 _err
= HRGoToPtr(_self
->ob_itself
,
381 buffer__in__
, buffer__len__
,
384 if (_err
!= noErr
) return PyMac_Error(_err
);
391 static PyObject
*HtmlObj_HRGetRootURL(_self
, _args
)
392 HtmlObjectObject
*_self
;
395 PyObject
*_res
= NULL
;
398 if (!PyArg_ParseTuple(_args
, "O&",
399 ResObj_Convert
, &rootURLH
))
401 _err
= HRGetRootURL(_self
->ob_itself
,
403 if (_err
!= noErr
) return PyMac_Error(_err
);
409 static PyObject
*HtmlObj_HRGetBaseURL(_self
, _args
)
410 HtmlObjectObject
*_self
;
413 PyObject
*_res
= NULL
;
416 if (!PyArg_ParseTuple(_args
, "O&",
417 ResObj_Convert
, &baseURLH
))
419 _err
= HRGetBaseURL(_self
->ob_itself
,
421 if (_err
!= noErr
) return PyMac_Error(_err
);
427 static PyObject
*HtmlObj_HRGetHTMLURL(_self
, _args
)
428 HtmlObjectObject
*_self
;
431 PyObject
*_res
= NULL
;
434 if (!PyArg_ParseTuple(_args
, "O&",
435 ResObj_Convert
, &HTMLURLH
))
437 _err
= HRGetHTMLURL(_self
->ob_itself
,
439 if (_err
!= noErr
) return PyMac_Error(_err
);
445 static PyObject
*HtmlObj_HRGetTitle(_self
, _args
)
446 HtmlObjectObject
*_self
;
449 PyObject
*_res
= NULL
;
452 if (!PyArg_ParseTuple(_args
, "s",
455 _err
= HRGetTitle(_self
->ob_itself
,
457 if (_err
!= noErr
) return PyMac_Error(_err
);
463 static PyObject
*HtmlObj_HRGetHTMLFile(_self
, _args
)
464 HtmlObjectObject
*_self
;
467 PyObject
*_res
= NULL
;
470 if (!PyArg_ParseTuple(_args
, ""))
472 _err
= HRGetHTMLFile(_self
->ob_itself
,
474 if (_err
!= noErr
) return PyMac_Error(_err
);
475 _res
= Py_BuildValue("O&",
476 PyMac_BuildFSSpec
, fsspec
);
480 static PyObject
*HtmlObj_HRUnregisterWasURLVisitedUPP(_self
, _args
)
481 HtmlObjectObject
*_self
;
484 PyObject
*_res
= NULL
;
485 if (!PyArg_ParseTuple(_args
, ""))
487 HRUnregisterWasURLVisitedUPP(_self
->ob_itself
);
493 static PyObject
*HtmlObj_HRUnregisterNewURLUPP(_self
, _args
)
494 HtmlObjectObject
*_self
;
497 PyObject
*_res
= NULL
;
498 if (!PyArg_ParseTuple(_args
, ""))
500 HRUnregisterNewURLUPP(_self
->ob_itself
);
506 static PyObject
*HtmlObj_HRUnregisterURLToFSSpecUPP(_self
, _args
)
507 HtmlObjectObject
*_self
;
510 PyObject
*_res
= NULL
;
511 if (!PyArg_ParseTuple(_args
, ""))
513 HRUnregisterURLToFSSpecUPP(_self
->ob_itself
);
519 static PyMethodDef HtmlObj_methods
[] = {
520 {"HRDisposeReference", (PyCFunction
)HtmlObj_HRDisposeReference
, 1,
522 {"HRSetGrafPtr", (PyCFunction
)HtmlObj_HRSetGrafPtr
, 1,
523 "(GrafPtr grafPtr) -> None"},
524 {"HRActivate", (PyCFunction
)HtmlObj_HRActivate
, 1,
526 {"HRDeactivate", (PyCFunction
)HtmlObj_HRDeactivate
, 1,
528 {"HRDraw", (PyCFunction
)HtmlObj_HRDraw
, 1,
529 "(RgnHandle updateRgnH) -> None"},
530 {"HRSetRenderingRect", (PyCFunction
)HtmlObj_HRSetRenderingRect
, 1,
531 "(Rect renderingRect) -> None"},
532 {"HRGetRenderedImageSize", (PyCFunction
)HtmlObj_HRGetRenderedImageSize
, 1,
533 "() -> (Point renderingSize)"},
534 {"HRScrollToLocation", (PyCFunction
)HtmlObj_HRScrollToLocation
, 1,
535 "() -> (Point location)"},
536 {"HRForceQuickdraw", (PyCFunction
)HtmlObj_HRForceQuickdraw
, 1,
537 "(Boolean forceQuickdraw) -> None"},
538 {"HRSetScrollbarState", (PyCFunction
)HtmlObj_HRSetScrollbarState
, 1,
539 "(HRScrollbarState hScrollbarState, HRScrollbarState vScrollbarState) -> None"},
540 {"HRSetDrawBorder", (PyCFunction
)HtmlObj_HRSetDrawBorder
, 1,
541 "(Boolean drawBorder) -> None"},
542 {"HRSetGrowboxCutout", (PyCFunction
)HtmlObj_HRSetGrowboxCutout
, 1,
543 "(Boolean allowCutout) -> None"},
544 {"HRGoToFile", (PyCFunction
)HtmlObj_HRGoToFile
, 1,
545 "(FSSpec fsspec, Boolean addToHistory, Boolean forceRefresh) -> None"},
546 {"HRGoToURL", (PyCFunction
)HtmlObj_HRGoToURL
, 1,
547 "(char * url, Boolean addToHistory, Boolean forceRefresh) -> None"},
548 {"HRGoToAnchor", (PyCFunction
)HtmlObj_HRGoToAnchor
, 1,
549 "(char * anchorName) -> None"},
550 {"HRGoToPtr", (PyCFunction
)HtmlObj_HRGoToPtr
, 1,
551 "(Buffer buffer, Boolean addToHistory, Boolean forceRefresh) -> None"},
552 {"HRGetRootURL", (PyCFunction
)HtmlObj_HRGetRootURL
, 1,
553 "(Handle rootURLH) -> None"},
554 {"HRGetBaseURL", (PyCFunction
)HtmlObj_HRGetBaseURL
, 1,
555 "(Handle baseURLH) -> None"},
556 {"HRGetHTMLURL", (PyCFunction
)HtmlObj_HRGetHTMLURL
, 1,
557 "(Handle HTMLURLH) -> None"},
558 {"HRGetTitle", (PyCFunction
)HtmlObj_HRGetTitle
, 1,
559 "(StringPtr title) -> None"},
560 {"HRGetHTMLFile", (PyCFunction
)HtmlObj_HRGetHTMLFile
, 1,
561 "() -> (FSSpec fsspec)"},
562 {"HRUnregisterWasURLVisitedUPP", (PyCFunction
)HtmlObj_HRUnregisterWasURLVisitedUPP
, 1,
564 {"HRUnregisterNewURLUPP", (PyCFunction
)HtmlObj_HRUnregisterNewURLUPP
, 1,
566 {"HRUnregisterURLToFSSpecUPP", (PyCFunction
)HtmlObj_HRUnregisterURLToFSSpecUPP
, 1,
571 PyMethodChain HtmlObj_chain
= { HtmlObj_methods
, NULL
};
573 static PyObject
*HtmlObj_getattr(self
, name
)
574 HtmlObjectObject
*self
;
577 return Py_FindMethodInChain(&HtmlObj_chain
, (PyObject
*)self
, name
);
580 #define HtmlObj_setattr NULL
582 #define HtmlObj_compare NULL
584 #define HtmlObj_repr NULL
586 #define HtmlObj_hash NULL
588 PyTypeObject HtmlObject_Type
= {
589 PyObject_HEAD_INIT(&PyType_Type
)
591 "HtmlRender.HtmlObject", /*tp_name*/
592 sizeof(HtmlObjectObject
), /*tp_basicsize*/
595 (destructor
) HtmlObj_dealloc
, /*tp_dealloc*/
597 (getattrfunc
) HtmlObj_getattr
, /*tp_getattr*/
598 (setattrfunc
) HtmlObj_setattr
, /*tp_setattr*/
599 (cmpfunc
) HtmlObj_compare
, /*tp_compare*/
600 (reprfunc
) HtmlObj_repr
, /*tp_repr*/
601 (PyNumberMethods
*)0, /* tp_as_number */
602 (PySequenceMethods
*)0, /* tp_as_sequence */
603 (PyMappingMethods
*)0, /* tp_as_mapping */
604 (hashfunc
) HtmlObj_hash
, /*tp_hash*/
607 /* ------------------- End object type HtmlObject ------------------- */
610 static PyObject
*Html_HRGetHTMLRenderingLibVersion(_self
, _args
)
614 PyObject
*_res
= NULL
;
616 NumVersion returnVers
;
617 if (!PyArg_ParseTuple(_args
, ""))
619 _err
= HRGetHTMLRenderingLibVersion(&returnVers
);
620 if (_err
!= noErr
) return PyMac_Error(_err
);
621 _res
= Py_BuildValue("O&",
622 PyMac_BuildNumVersion
, returnVers
);
626 static PyObject
*Html_HRNewReference(_self
, _args
)
630 PyObject
*_res
= NULL
;
635 if (!PyArg_ParseTuple(_args
, "O&O&",
636 PyMac_GetOSType
, &rendererType
,
637 GrafObj_Convert
, &grafPtr
))
639 _err
= HRNewReference(&hrRef
,
642 if (_err
!= noErr
) return PyMac_Error(_err
);
643 _res
= Py_BuildValue("O&",
648 static PyObject
*Html_HRFreeMemory(_self
, _args
)
652 PyObject
*_res
= NULL
;
655 if (!PyArg_ParseTuple(_args
, "l",
658 _rv
= HRFreeMemory(inBytesNeeded
);
659 _res
= Py_BuildValue("l",
664 static PyObject
*Html_HRScreenConfigurationChanged(_self
, _args
)
668 PyObject
*_res
= NULL
;
669 if (!PyArg_ParseTuple(_args
, ""))
671 HRScreenConfigurationChanged();
677 static PyObject
*Html_HRIsHREvent(_self
, _args
)
681 PyObject
*_res
= NULL
;
683 EventRecord eventRecord
;
684 if (!PyArg_ParseTuple(_args
, "O&",
685 PyMac_GetEventRecord
, &eventRecord
))
687 _rv
= HRIsHREvent(&eventRecord
);
688 _res
= Py_BuildValue("b",
693 static PyObject
*Html_HRUtilCreateFullURL(_self
, _args
)
697 PyObject
*_res
= NULL
;
702 if (!PyArg_ParseTuple(_args
, "ssO&",
705 ResObj_Convert
, &fullURLH
))
707 _err
= HRUtilCreateFullURL(rootURL
,
710 if (_err
!= noErr
) return PyMac_Error(_err
);
716 static PyObject
*Html_HRUtilGetFSSpecFromURL(_self
, _args
)
720 PyObject
*_res
= NULL
;
725 if (!PyArg_ParseTuple(_args
, "ss",
729 _err
= HRUtilGetFSSpecFromURL(rootURL
,
732 if (_err
!= noErr
) return PyMac_Error(_err
);
733 _res
= Py_BuildValue("O&",
734 PyMac_BuildFSSpec
, destSpec
);
738 static PyObject
*Html_HRUtilGetURLFromFSSpec(_self
, _args
)
742 PyObject
*_res
= NULL
;
746 if (!PyArg_ParseTuple(_args
, "O&O&",
747 PyMac_GetFSSpec
, &fsspec
,
748 ResObj_Convert
, &urlHandle
))
750 _err
= HRUtilGetURLFromFSSpec(&fsspec
,
752 if (_err
!= noErr
) return PyMac_Error(_err
);
758 static PyObject
*Html_HRHTMLRenderingLibAvailable(_self
, _args
)
762 PyObject
*_res
= NULL
;
764 if (!PyArg_ParseTuple(_args
, ""))
766 _rv
= HRHTMLRenderingLibAvailable();
767 _res
= Py_BuildValue("i",
772 static PyMethodDef Html_methods
[] = {
773 {"HRGetHTMLRenderingLibVersion", (PyCFunction
)Html_HRGetHTMLRenderingLibVersion
, 1,
774 "() -> (NumVersion returnVers)"},
775 {"HRNewReference", (PyCFunction
)Html_HRNewReference
, 1,
776 "(OSType rendererType, GrafPtr grafPtr) -> (HRReference hrRef)"},
777 {"HRFreeMemory", (PyCFunction
)Html_HRFreeMemory
, 1,
778 "(Size inBytesNeeded) -> (SInt32 _rv)"},
779 {"HRScreenConfigurationChanged", (PyCFunction
)Html_HRScreenConfigurationChanged
, 1,
781 {"HRIsHREvent", (PyCFunction
)Html_HRIsHREvent
, 1,
782 "(EventRecord eventRecord) -> (Boolean _rv)"},
783 {"HRUtilCreateFullURL", (PyCFunction
)Html_HRUtilCreateFullURL
, 1,
784 "(char * rootURL, char * linkURL, Handle fullURLH) -> None"},
785 {"HRUtilGetFSSpecFromURL", (PyCFunction
)Html_HRUtilGetFSSpecFromURL
, 1,
786 "(char * rootURL, char * linkURL) -> (FSSpec destSpec)"},
787 {"HRUtilGetURLFromFSSpec", (PyCFunction
)Html_HRUtilGetURLFromFSSpec
, 1,
788 "(FSSpec fsspec, Handle urlHandle) -> None"},
789 {"HRHTMLRenderingLibAvailable", (PyCFunction
)Html_HRHTMLRenderingLibAvailable
, 1,
797 void initHtmlRender()
805 m
= Py_InitModule("HtmlRender", Html_methods
);
806 d
= PyModule_GetDict(m
);
807 Html_Error
= PyMac_GetOSErrException();
808 if (Html_Error
== NULL
||
809 PyDict_SetItemString(d
, "Error", Html_Error
) != 0)
810 Py_FatalError("can't initialize HtmlRender.Error");
811 HtmlObject_Type
.ob_type
= &PyType_Type
;
812 Py_INCREF(&HtmlObject_Type
);
813 if (PyDict_SetItemString(d
, "HtmlObjectType", (PyObject
*)&HtmlObject_Type
) != 0)
814 Py_FatalError("can't initialize HtmlObjectType");
817 /* ===================== End module HtmlRender ====================== */