2 /* =========================== Module TE ============================ */
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
);
47 /* Exported by Qdmodule.c: */
48 extern PyObject
*QdRGB_New(RGBColor
*);
49 extern int QdRGB_Convert(PyObject
*, RGBColor
*);
52 ** Parse/generate TextStyle records
54 PyObject
*TextStyle_New(itself
)
58 return Py_BuildValue("lllO&", (long)itself
->tsFont
, (long)itself
->tsFace
, (long)itself
->tsSize
, QdRGB_New
,
62 TextStyle_Convert(v
, p_itself
)
64 TextStylePtr p_itself
;
66 long font
, face
, size
;
68 if( !PyArg_ParseTuple(v
, "lllO&", &font
, &face
, &size
, QdRGB_Convert
, &p_itself
->tsColor
) )
70 p_itself
->tsFont
= (short)font
;
71 p_itself
->tsFace
= (Style
)face
;
72 p_itself
->tsSize
= (short)size
;
76 static PyObject
*TE_Error
;
78 /* ------------------------- Object type TE ------------------------- */
82 #define TEObj_Check(x) ((x)->ob_type == &TE_Type)
84 typedef struct TEObject
{
89 PyObject
*TEObj_New(itself
)
94 PyErr_SetString(TE_Error
,"Cannot create null TE");
97 it
= PyObject_NEW(TEObject
, &TE_Type
);
98 if (it
== NULL
) return NULL
;
99 it
->ob_itself
= itself
;
100 return (PyObject
*)it
;
102 TEObj_Convert(v
, p_itself
)
108 PyErr_SetString(PyExc_TypeError
, "TE required");
111 *p_itself
= ((TEObject
*)v
)->ob_itself
;
115 static void TEObj_dealloc(self
)
118 TEDispose(self
->ob_itself
);
122 static PyObject
*TEObj_TESetText(_self
, _args
)
126 PyObject
*_res
= NULL
;
130 if (!PyArg_ParseTuple(_args
, "s#",
131 &text__in__
, &text__in_len__
))
133 text__len__
= text__in_len__
;
134 TESetText(text__in__
, text__len__
,
142 static PyObject
*TEObj_TEGetText(_self
, _args
)
146 PyObject
*_res
= NULL
;
148 if (!PyArg_ParseTuple(_args
, ""))
150 _rv
= TEGetText(_self
->ob_itself
);
151 _res
= Py_BuildValue("O&",
156 static PyObject
*TEObj_TEIdle(_self
, _args
)
160 PyObject
*_res
= NULL
;
161 if (!PyArg_ParseTuple(_args
, ""))
163 TEIdle(_self
->ob_itself
);
169 static PyObject
*TEObj_TESetSelect(_self
, _args
)
173 PyObject
*_res
= NULL
;
176 if (!PyArg_ParseTuple(_args
, "ll",
180 TESetSelect(selStart
,
188 static PyObject
*TEObj_TEActivate(_self
, _args
)
192 PyObject
*_res
= NULL
;
193 if (!PyArg_ParseTuple(_args
, ""))
195 TEActivate(_self
->ob_itself
);
201 static PyObject
*TEObj_TEDeactivate(_self
, _args
)
205 PyObject
*_res
= NULL
;
206 if (!PyArg_ParseTuple(_args
, ""))
208 TEDeactivate(_self
->ob_itself
);
214 static PyObject
*TEObj_TEKey(_self
, _args
)
218 PyObject
*_res
= NULL
;
220 if (!PyArg_ParseTuple(_args
, "h",
230 static PyObject
*TEObj_TECut(_self
, _args
)
234 PyObject
*_res
= NULL
;
235 if (!PyArg_ParseTuple(_args
, ""))
237 TECut(_self
->ob_itself
);
243 static PyObject
*TEObj_TECopy(_self
, _args
)
247 PyObject
*_res
= NULL
;
248 if (!PyArg_ParseTuple(_args
, ""))
250 TECopy(_self
->ob_itself
);
256 static PyObject
*TEObj_TEPaste(_self
, _args
)
260 PyObject
*_res
= NULL
;
261 if (!PyArg_ParseTuple(_args
, ""))
263 TEPaste(_self
->ob_itself
);
269 static PyObject
*TEObj_TEDelete(_self
, _args
)
273 PyObject
*_res
= NULL
;
274 if (!PyArg_ParseTuple(_args
, ""))
276 TEDelete(_self
->ob_itself
);
282 static PyObject
*TEObj_TEInsert(_self
, _args
)
286 PyObject
*_res
= NULL
;
290 if (!PyArg_ParseTuple(_args
, "s#",
291 &text__in__
, &text__in_len__
))
293 text__len__
= text__in_len__
;
294 TEInsert(text__in__
, text__len__
,
302 static PyObject
*TEObj_TESetAlignment(_self
, _args
)
306 PyObject
*_res
= NULL
;
308 if (!PyArg_ParseTuple(_args
, "h",
318 static PyObject
*TEObj_TEUpdate(_self
, _args
)
322 PyObject
*_res
= NULL
;
324 if (!PyArg_ParseTuple(_args
, "O&",
325 PyMac_GetRect
, &rUpdate
))
334 static PyObject
*TEObj_TEScroll(_self
, _args
)
338 PyObject
*_res
= NULL
;
341 if (!PyArg_ParseTuple(_args
, "hh",
353 static PyObject
*TEObj_TESelView(_self
, _args
)
357 PyObject
*_res
= NULL
;
358 if (!PyArg_ParseTuple(_args
, ""))
360 TESelView(_self
->ob_itself
);
366 static PyObject
*TEObj_TEPinScroll(_self
, _args
)
370 PyObject
*_res
= NULL
;
373 if (!PyArg_ParseTuple(_args
, "hh",
385 static PyObject
*TEObj_TEAutoView(_self
, _args
)
389 PyObject
*_res
= NULL
;
391 if (!PyArg_ParseTuple(_args
, "b",
401 static PyObject
*TEObj_TECalText(_self
, _args
)
405 PyObject
*_res
= NULL
;
406 if (!PyArg_ParseTuple(_args
, ""))
408 TECalText(_self
->ob_itself
);
414 static PyObject
*TEObj_TEGetOffset(_self
, _args
)
418 PyObject
*_res
= NULL
;
421 if (!PyArg_ParseTuple(_args
, "O&",
422 PyMac_GetPoint
, &pt
))
424 _rv
= TEGetOffset(pt
,
426 _res
= Py_BuildValue("h",
431 static PyObject
*TEObj_TEGetPoint(_self
, _args
)
435 PyObject
*_res
= NULL
;
438 if (!PyArg_ParseTuple(_args
, "h",
441 _rv
= TEGetPoint(offset
,
443 _res
= Py_BuildValue("O&",
444 PyMac_BuildPoint
, _rv
);
448 static PyObject
*TEObj_TEClick(_self
, _args
)
452 PyObject
*_res
= NULL
;
455 if (!PyArg_ParseTuple(_args
, "O&b",
467 static PyObject
*TEObj_TESetStyleHandle(_self
, _args
)
471 PyObject
*_res
= NULL
;
472 TEStyleHandle theHandle
;
473 if (!PyArg_ParseTuple(_args
, "O&",
474 ResObj_Convert
, &theHandle
))
476 TESetStyleHandle(theHandle
,
483 static PyObject
*TEObj_TEGetStyleHandle(_self
, _args
)
487 PyObject
*_res
= NULL
;
489 if (!PyArg_ParseTuple(_args
, ""))
491 _rv
= TEGetStyleHandle(_self
->ob_itself
);
492 _res
= Py_BuildValue("O&",
497 static PyObject
*TEObj_TEGetStyle(_self
, _args
)
501 PyObject
*_res
= NULL
;
506 if (!PyArg_ParseTuple(_args
, "h",
514 _res
= Py_BuildValue("O&hh",
515 TextStyle_New
, &theStyle
,
521 static PyObject
*TEObj_TEStylePaste(_self
, _args
)
525 PyObject
*_res
= NULL
;
526 if (!PyArg_ParseTuple(_args
, ""))
528 TEStylePaste(_self
->ob_itself
);
534 static PyObject
*TEObj_TESetStyle(_self
, _args
)
538 PyObject
*_res
= NULL
;
542 if (!PyArg_ParseTuple(_args
, "hO&b",
544 TextStyle_Convert
, &newStyle
,
556 static PyObject
*TEObj_TEReplaceStyle(_self
, _args
)
560 PyObject
*_res
= NULL
;
565 if (!PyArg_ParseTuple(_args
, "hO&O&b",
567 TextStyle_Convert
, &oldStyle
,
568 TextStyle_Convert
, &newStyle
,
581 static PyObject
*TEObj_TEGetStyleScrapHandle(_self
, _args
)
585 PyObject
*_res
= NULL
;
587 if (!PyArg_ParseTuple(_args
, ""))
589 _rv
= TEGetStyleScrapHandle(_self
->ob_itself
);
590 _res
= Py_BuildValue("O&",
595 static PyObject
*TEObj_TEStyleInsert(_self
, _args
)
599 PyObject
*_res
= NULL
;
604 if (!PyArg_ParseTuple(_args
, "s#O&",
605 &text__in__
, &text__in_len__
,
606 ResObj_Convert
, &hST
))
608 text__len__
= text__in_len__
;
609 TEStyleInsert(text__in__
, text__len__
,
618 static PyObject
*TEObj_TEGetHeight(_self
, _args
)
622 PyObject
*_res
= NULL
;
626 if (!PyArg_ParseTuple(_args
, "ll",
630 _rv
= TEGetHeight(endLine
,
633 _res
= Py_BuildValue("l",
638 static PyObject
*TEObj_TEContinuousStyle(_self
, _args
)
642 PyObject
*_res
= NULL
;
646 if (!PyArg_ParseTuple(_args
, "hO&",
648 TextStyle_Convert
, &aStyle
))
650 _rv
= TEContinuousStyle(&mode
,
653 _res
= Py_BuildValue("bhO&",
656 TextStyle_New
, &aStyle
);
660 static PyObject
*TEObj_TEUseStyleScrap(_self
, _args
)
664 PyObject
*_res
= NULL
;
667 StScrpHandle newStyles
;
669 if (!PyArg_ParseTuple(_args
, "llO&b",
672 ResObj_Convert
, &newStyles
,
675 TEUseStyleScrap(rangeStart
,
685 static PyObject
*TEObj_TENumStyles(_self
, _args
)
689 PyObject
*_res
= NULL
;
693 if (!PyArg_ParseTuple(_args
, "ll",
697 _rv
= TENumStyles(rangeStart
,
700 _res
= Py_BuildValue("l",
705 static PyObject
*TEObj_TEFeatureFlag(_self
, _args
)
709 PyObject
*_res
= NULL
;
713 if (!PyArg_ParseTuple(_args
, "hh",
717 _rv
= TEFeatureFlag(feature
,
720 _res
= Py_BuildValue("h",
725 static PyMethodDef TEObj_methods
[] = {
726 {"TESetText", (PyCFunction
)TEObj_TESetText
, 1,
727 "(Buffer text) -> None"},
728 {"TEGetText", (PyCFunction
)TEObj_TEGetText
, 1,
729 "() -> (CharsHandle _rv)"},
730 {"TEIdle", (PyCFunction
)TEObj_TEIdle
, 1,
732 {"TESetSelect", (PyCFunction
)TEObj_TESetSelect
, 1,
733 "(long selStart, long selEnd) -> None"},
734 {"TEActivate", (PyCFunction
)TEObj_TEActivate
, 1,
736 {"TEDeactivate", (PyCFunction
)TEObj_TEDeactivate
, 1,
738 {"TEKey", (PyCFunction
)TEObj_TEKey
, 1,
739 "(CharParameter key) -> None"},
740 {"TECut", (PyCFunction
)TEObj_TECut
, 1,
742 {"TECopy", (PyCFunction
)TEObj_TECopy
, 1,
744 {"TEPaste", (PyCFunction
)TEObj_TEPaste
, 1,
746 {"TEDelete", (PyCFunction
)TEObj_TEDelete
, 1,
748 {"TEInsert", (PyCFunction
)TEObj_TEInsert
, 1,
749 "(Buffer text) -> None"},
750 {"TESetAlignment", (PyCFunction
)TEObj_TESetAlignment
, 1,
751 "(short just) -> None"},
752 {"TEUpdate", (PyCFunction
)TEObj_TEUpdate
, 1,
753 "(Rect rUpdate) -> None"},
754 {"TEScroll", (PyCFunction
)TEObj_TEScroll
, 1,
755 "(short dh, short dv) -> None"},
756 {"TESelView", (PyCFunction
)TEObj_TESelView
, 1,
758 {"TEPinScroll", (PyCFunction
)TEObj_TEPinScroll
, 1,
759 "(short dh, short dv) -> None"},
760 {"TEAutoView", (PyCFunction
)TEObj_TEAutoView
, 1,
761 "(Boolean fAuto) -> None"},
762 {"TECalText", (PyCFunction
)TEObj_TECalText
, 1,
764 {"TEGetOffset", (PyCFunction
)TEObj_TEGetOffset
, 1,
765 "(Point pt) -> (short _rv)"},
766 {"TEGetPoint", (PyCFunction
)TEObj_TEGetPoint
, 1,
767 "(short offset) -> (Point _rv)"},
768 {"TEClick", (PyCFunction
)TEObj_TEClick
, 1,
769 "(Point pt, Boolean fExtend) -> None"},
770 {"TESetStyleHandle", (PyCFunction
)TEObj_TESetStyleHandle
, 1,
771 "(TEStyleHandle theHandle) -> None"},
772 {"TEGetStyleHandle", (PyCFunction
)TEObj_TEGetStyleHandle
, 1,
773 "() -> (TEStyleHandle _rv)"},
774 {"TEGetStyle", (PyCFunction
)TEObj_TEGetStyle
, 1,
775 "(short offset) -> (TextStyle theStyle, short lineHeight, short fontAscent)"},
776 {"TEStylePaste", (PyCFunction
)TEObj_TEStylePaste
, 1,
778 {"TESetStyle", (PyCFunction
)TEObj_TESetStyle
, 1,
779 "(short mode, TextStyle newStyle, Boolean fRedraw) -> None"},
780 {"TEReplaceStyle", (PyCFunction
)TEObj_TEReplaceStyle
, 1,
781 "(short mode, TextStyle oldStyle, TextStyle newStyle, Boolean fRedraw) -> None"},
782 {"TEGetStyleScrapHandle", (PyCFunction
)TEObj_TEGetStyleScrapHandle
, 1,
783 "() -> (StScrpHandle _rv)"},
784 {"TEStyleInsert", (PyCFunction
)TEObj_TEStyleInsert
, 1,
785 "(Buffer text, StScrpHandle hST) -> None"},
786 {"TEGetHeight", (PyCFunction
)TEObj_TEGetHeight
, 1,
787 "(long endLine, long startLine) -> (long _rv)"},
788 {"TEContinuousStyle", (PyCFunction
)TEObj_TEContinuousStyle
, 1,
789 "(short mode, TextStyle aStyle) -> (Boolean _rv, short mode, TextStyle aStyle)"},
790 {"TEUseStyleScrap", (PyCFunction
)TEObj_TEUseStyleScrap
, 1,
791 "(long rangeStart, long rangeEnd, StScrpHandle newStyles, Boolean fRedraw) -> None"},
792 {"TENumStyles", (PyCFunction
)TEObj_TENumStyles
, 1,
793 "(long rangeStart, long rangeEnd) -> (long _rv)"},
794 {"TEFeatureFlag", (PyCFunction
)TEObj_TEFeatureFlag
, 1,
795 "(short feature, short action) -> (short _rv)"},
799 PyMethodChain TEObj_chain
= { TEObj_methods
, NULL
};
801 static PyObject
*TEObj_getattr(self
, name
)
806 if( strcmp(name
, "destRect") == 0 )
807 return Py_BuildValue("O&", PyMac_BuildRect
,
808 &(*self
->ob_itself
)->destRect
);
809 if( strcmp(name
, "viewRect") == 0 )
810 return Py_BuildValue("O&", PyMac_BuildRect
,
811 &(*self
->ob_itself
)->viewRect
);
812 if( strcmp(name
, "selRect") == 0 )
813 return Py_BuildValue("O&", PyMac_BuildRect
,
814 &(*self
->ob_itself
)->selRect
);
815 if( strcmp(name
, "lineHeight") == 0 )
816 return Py_BuildValue("h", (*self
->ob_itself
)->lineHeight
);
817 if( strcmp(name
, "fontAscent") == 0 )
818 return Py_BuildValue("h", (*self
->ob_itself
)->fontAscent
);
819 if( strcmp(name
, "selPoint") == 0 )
820 return Py_BuildValue("O&", PyMac_BuildPoint
,
821 &(*self
->ob_itself
)->selPoint
);
822 if( strcmp(name
, "selStart") == 0 )
823 return Py_BuildValue("h", (*self
->ob_itself
)->selStart
);
824 if( strcmp(name
, "selEnd") == 0 )
825 return Py_BuildValue("h", (*self
->ob_itself
)->selEnd
);
826 if( strcmp(name
, "active") == 0 )
827 return Py_BuildValue("h", (*self
->ob_itself
)->active
);
828 if( strcmp(name
, "just") == 0 )
829 return Py_BuildValue("h", (*self
->ob_itself
)->just
);
830 if( strcmp(name
, "teLength") == 0 )
831 return Py_BuildValue("h", (*self
->ob_itself
)->teLength
);
832 if( strcmp(name
, "txFont") == 0 )
833 return Py_BuildValue("h", (*self
->ob_itself
)->txFont
);
834 if( strcmp(name
, "txFace") == 0 )
835 return Py_BuildValue("h", (*self
->ob_itself
)->txFace
);
836 if( strcmp(name
, "txMode") == 0 )
837 return Py_BuildValue("h", (*self
->ob_itself
)->txMode
);
838 if( strcmp(name
, "txSize") == 0 )
839 return Py_BuildValue("h", (*self
->ob_itself
)->txSize
);
840 if( strcmp(name
, "nLines") == 0 )
841 return Py_BuildValue("h", (*self
->ob_itself
)->nLines
);
843 return Py_FindMethodInChain(&TEObj_chain
, (PyObject
*)self
, name
);
846 #define TEObj_setattr NULL
848 PyTypeObject TE_Type
= {
849 PyObject_HEAD_INIT(&PyType_Type
)
852 sizeof(TEObject
), /*tp_basicsize*/
855 (destructor
) TEObj_dealloc
, /*tp_dealloc*/
857 (getattrfunc
) TEObj_getattr
, /*tp_getattr*/
858 (setattrfunc
) TEObj_setattr
, /*tp_setattr*/
861 /* ----------------------- End object type TE ----------------------- */
864 static PyObject
*TE_TEScrapHandle(_self
, _args
)
868 PyObject
*_res
= NULL
;
870 if (!PyArg_ParseTuple(_args
, ""))
872 _rv
= TEScrapHandle();
873 _res
= Py_BuildValue("O&",
878 static PyObject
*TE_TEGetScrapLength(_self
, _args
)
882 PyObject
*_res
= NULL
;
884 if (!PyArg_ParseTuple(_args
, ""))
886 _rv
= TEGetScrapLength();
887 _res
= Py_BuildValue("l",
892 static PyObject
*TE_TENew(_self
, _args
)
896 PyObject
*_res
= NULL
;
900 if (!PyArg_ParseTuple(_args
, "O&O&",
901 PyMac_GetRect
, &destRect
,
902 PyMac_GetRect
, &viewRect
))
904 _rv
= TENew(&destRect
,
906 _res
= Py_BuildValue("O&",
911 static PyObject
*TE_TETextBox(_self
, _args
)
915 PyObject
*_res
= NULL
;
921 if (!PyArg_ParseTuple(_args
, "s#O&h",
922 &text__in__
, &text__in_len__
,
926 text__len__
= text__in_len__
;
927 TETextBox(text__in__
, text__len__
,
936 static PyObject
*TE_TEStyleNew(_self
, _args
)
940 PyObject
*_res
= NULL
;
944 if (!PyArg_ParseTuple(_args
, "O&O&",
945 PyMac_GetRect
, &destRect
,
946 PyMac_GetRect
, &viewRect
))
948 _rv
= TEStyleNew(&destRect
,
950 _res
= Py_BuildValue("O&",
955 static PyObject
*TE_TESetScrapLength(_self
, _args
)
959 PyObject
*_res
= NULL
;
961 if (!PyArg_ParseTuple(_args
, "l",
964 TESetScrapLength(length
);
970 static PyObject
*TE_TEFromScrap(_self
, _args
)
974 PyObject
*_res
= NULL
;
976 if (!PyArg_ParseTuple(_args
, ""))
978 _err
= TEFromScrap();
979 if (_err
!= noErr
) return PyMac_Error(_err
);
985 static PyObject
*TE_TEToScrap(_self
, _args
)
989 PyObject
*_res
= NULL
;
991 if (!PyArg_ParseTuple(_args
, ""))
994 if (_err
!= noErr
) return PyMac_Error(_err
);
1000 static PyMethodDef TE_methods
[] = {
1001 {"TEScrapHandle", (PyCFunction
)TE_TEScrapHandle
, 1,
1002 "() -> (Handle _rv)"},
1003 {"TEGetScrapLength", (PyCFunction
)TE_TEGetScrapLength
, 1,
1004 "() -> (long _rv)"},
1005 {"TENew", (PyCFunction
)TE_TENew
, 1,
1006 "(Rect destRect, Rect viewRect) -> (TEHandle _rv)"},
1007 {"TETextBox", (PyCFunction
)TE_TETextBox
, 1,
1008 "(Buffer text, Rect box, short just) -> None"},
1009 {"TEStyleNew", (PyCFunction
)TE_TEStyleNew
, 1,
1010 "(Rect destRect, Rect viewRect) -> (TEHandle _rv)"},
1011 {"TESetScrapLength", (PyCFunction
)TE_TESetScrapLength
, 1,
1012 "(long length) -> None"},
1013 {"TEFromScrap", (PyCFunction
)TE_TEFromScrap
, 1,
1015 {"TEToScrap", (PyCFunction
)TE_TEToScrap
, 1,
1031 m
= Py_InitModule("TE", TE_methods
);
1032 d
= PyModule_GetDict(m
);
1033 TE_Error
= PyMac_GetOSErrException();
1034 if (TE_Error
== NULL
||
1035 PyDict_SetItemString(d
, "Error", TE_Error
) != 0)
1036 Py_FatalError("can't initialize TE.Error");
1037 TE_Type
.ob_type
= &PyType_Type
;
1038 Py_INCREF(&TE_Type
);
1039 if (PyDict_SetItemString(d
, "TEType", (PyObject
*)&TE_Type
) != 0)
1040 Py_FatalError("can't initialize TEType");
1043 /* ========================= End module TE ========================== */