2 /* =========================== Module TE ============================ */
9 #include "pymactoolbox.h"
13 #define as_TE(h) ((TEHandle)h)
14 #define as_Resource(teh) ((Handle)teh)
17 ** Parse/generate TextStyle records
24 return Py_BuildValue("lllO&", (long)itself
->tsFont
, (long)itself
->tsFace
, (long)itself
->tsSize
, QdRGB_New
,
29 TextStyle_Convert(v
, p_itself
)
31 TextStylePtr p_itself
;
33 long font
, face
, size
;
35 if( !PyArg_ParseTuple(v
, "lllO&", &font
, &face
, &size
, QdRGB_Convert
, &p_itself
->tsColor
) )
37 p_itself
->tsFont
= (short)font
;
38 p_itself
->tsFace
= (Style
)face
;
39 p_itself
->tsSize
= (short)size
;
43 static PyObject
*TE_Error
;
45 /* ------------------------- Object type TE ------------------------- */
49 #define TEObj_Check(x) ((x)->ob_type == &TE_Type)
51 typedef struct TEObject
{
56 PyObject
*TEObj_New(itself
)
61 PyErr_SetString(TE_Error
,"Cannot create null TE");
64 it
= PyObject_NEW(TEObject
, &TE_Type
);
65 if (it
== NULL
) return NULL
;
66 it
->ob_itself
= itself
;
67 return (PyObject
*)it
;
69 TEObj_Convert(v
, p_itself
)
75 PyErr_SetString(PyExc_TypeError
, "TE required");
78 *p_itself
= ((TEObject
*)v
)->ob_itself
;
82 static void TEObj_dealloc(self
)
85 TEDispose(self
->ob_itself
);
89 static PyObject
*TEObj_TESetText(_self
, _args
)
93 PyObject
*_res
= NULL
;
97 if (!PyArg_ParseTuple(_args
, "s#",
98 &text__in__
, &text__in_len__
))
100 text__len__
= text__in_len__
;
101 TESetText(text__in__
, text__len__
,
109 static PyObject
*TEObj_TEGetText(_self
, _args
)
113 PyObject
*_res
= NULL
;
115 if (!PyArg_ParseTuple(_args
, ""))
117 _rv
= TEGetText(_self
->ob_itself
);
118 _res
= Py_BuildValue("O&",
123 static PyObject
*TEObj_TEIdle(_self
, _args
)
127 PyObject
*_res
= NULL
;
128 if (!PyArg_ParseTuple(_args
, ""))
130 TEIdle(_self
->ob_itself
);
136 static PyObject
*TEObj_TESetSelect(_self
, _args
)
140 PyObject
*_res
= NULL
;
143 if (!PyArg_ParseTuple(_args
, "ll",
147 TESetSelect(selStart
,
155 static PyObject
*TEObj_TEActivate(_self
, _args
)
159 PyObject
*_res
= NULL
;
160 if (!PyArg_ParseTuple(_args
, ""))
162 TEActivate(_self
->ob_itself
);
168 static PyObject
*TEObj_TEDeactivate(_self
, _args
)
172 PyObject
*_res
= NULL
;
173 if (!PyArg_ParseTuple(_args
, ""))
175 TEDeactivate(_self
->ob_itself
);
181 static PyObject
*TEObj_TEKey(_self
, _args
)
185 PyObject
*_res
= NULL
;
187 if (!PyArg_ParseTuple(_args
, "h",
197 static PyObject
*TEObj_TECut(_self
, _args
)
201 PyObject
*_res
= NULL
;
202 if (!PyArg_ParseTuple(_args
, ""))
204 TECut(_self
->ob_itself
);
210 static PyObject
*TEObj_TECopy(_self
, _args
)
214 PyObject
*_res
= NULL
;
215 if (!PyArg_ParseTuple(_args
, ""))
217 TECopy(_self
->ob_itself
);
223 static PyObject
*TEObj_TEPaste(_self
, _args
)
227 PyObject
*_res
= NULL
;
228 if (!PyArg_ParseTuple(_args
, ""))
230 TEPaste(_self
->ob_itself
);
236 static PyObject
*TEObj_TEDelete(_self
, _args
)
240 PyObject
*_res
= NULL
;
241 if (!PyArg_ParseTuple(_args
, ""))
243 TEDelete(_self
->ob_itself
);
249 static PyObject
*TEObj_TEInsert(_self
, _args
)
253 PyObject
*_res
= NULL
;
257 if (!PyArg_ParseTuple(_args
, "s#",
258 &text__in__
, &text__in_len__
))
260 text__len__
= text__in_len__
;
261 TEInsert(text__in__
, text__len__
,
269 static PyObject
*TEObj_TESetAlignment(_self
, _args
)
273 PyObject
*_res
= NULL
;
275 if (!PyArg_ParseTuple(_args
, "h",
285 static PyObject
*TEObj_TEUpdate(_self
, _args
)
289 PyObject
*_res
= NULL
;
291 if (!PyArg_ParseTuple(_args
, "O&",
292 PyMac_GetRect
, &rUpdate
))
301 static PyObject
*TEObj_TEScroll(_self
, _args
)
305 PyObject
*_res
= NULL
;
308 if (!PyArg_ParseTuple(_args
, "hh",
320 static PyObject
*TEObj_TESelView(_self
, _args
)
324 PyObject
*_res
= NULL
;
325 if (!PyArg_ParseTuple(_args
, ""))
327 TESelView(_self
->ob_itself
);
333 static PyObject
*TEObj_TEPinScroll(_self
, _args
)
337 PyObject
*_res
= NULL
;
340 if (!PyArg_ParseTuple(_args
, "hh",
352 static PyObject
*TEObj_TEAutoView(_self
, _args
)
356 PyObject
*_res
= NULL
;
358 if (!PyArg_ParseTuple(_args
, "b",
368 static PyObject
*TEObj_TECalText(_self
, _args
)
372 PyObject
*_res
= NULL
;
373 if (!PyArg_ParseTuple(_args
, ""))
375 TECalText(_self
->ob_itself
);
381 static PyObject
*TEObj_TEGetOffset(_self
, _args
)
385 PyObject
*_res
= NULL
;
388 if (!PyArg_ParseTuple(_args
, "O&",
389 PyMac_GetPoint
, &pt
))
391 _rv
= TEGetOffset(pt
,
393 _res
= Py_BuildValue("h",
398 static PyObject
*TEObj_TEGetPoint(_self
, _args
)
402 PyObject
*_res
= NULL
;
405 if (!PyArg_ParseTuple(_args
, "h",
408 _rv
= TEGetPoint(offset
,
410 _res
= Py_BuildValue("O&",
411 PyMac_BuildPoint
, _rv
);
415 static PyObject
*TEObj_TEClick(_self
, _args
)
419 PyObject
*_res
= NULL
;
422 if (!PyArg_ParseTuple(_args
, "O&b",
434 static PyObject
*TEObj_TESetStyleHandle(_self
, _args
)
438 PyObject
*_res
= NULL
;
439 TEStyleHandle theHandle
;
440 if (!PyArg_ParseTuple(_args
, "O&",
441 ResObj_Convert
, &theHandle
))
443 TESetStyleHandle(theHandle
,
450 static PyObject
*TEObj_TEGetStyleHandle(_self
, _args
)
454 PyObject
*_res
= NULL
;
456 if (!PyArg_ParseTuple(_args
, ""))
458 _rv
= TEGetStyleHandle(_self
->ob_itself
);
459 _res
= Py_BuildValue("O&",
464 static PyObject
*TEObj_TEGetStyle(_self
, _args
)
468 PyObject
*_res
= NULL
;
473 if (!PyArg_ParseTuple(_args
, "h",
481 _res
= Py_BuildValue("O&hh",
482 TextStyle_New
, &theStyle
,
488 static PyObject
*TEObj_TEStylePaste(_self
, _args
)
492 PyObject
*_res
= NULL
;
493 if (!PyArg_ParseTuple(_args
, ""))
495 TEStylePaste(_self
->ob_itself
);
501 static PyObject
*TEObj_TESetStyle(_self
, _args
)
505 PyObject
*_res
= NULL
;
509 if (!PyArg_ParseTuple(_args
, "hO&b",
511 TextStyle_Convert
, &newStyle
,
523 static PyObject
*TEObj_TEReplaceStyle(_self
, _args
)
527 PyObject
*_res
= NULL
;
532 if (!PyArg_ParseTuple(_args
, "hO&O&b",
534 TextStyle_Convert
, &oldStyle
,
535 TextStyle_Convert
, &newStyle
,
548 static PyObject
*TEObj_TEGetStyleScrapHandle(_self
, _args
)
552 PyObject
*_res
= NULL
;
554 if (!PyArg_ParseTuple(_args
, ""))
556 _rv
= TEGetStyleScrapHandle(_self
->ob_itself
);
557 _res
= Py_BuildValue("O&",
562 static PyObject
*TEObj_TEStyleInsert(_self
, _args
)
566 PyObject
*_res
= NULL
;
571 if (!PyArg_ParseTuple(_args
, "s#O&",
572 &text__in__
, &text__in_len__
,
573 ResObj_Convert
, &hST
))
575 text__len__
= text__in_len__
;
576 TEStyleInsert(text__in__
, text__len__
,
585 static PyObject
*TEObj_TEGetHeight(_self
, _args
)
589 PyObject
*_res
= NULL
;
593 if (!PyArg_ParseTuple(_args
, "ll",
597 _rv
= TEGetHeight(endLine
,
600 _res
= Py_BuildValue("l",
605 static PyObject
*TEObj_TEContinuousStyle(_self
, _args
)
609 PyObject
*_res
= NULL
;
613 if (!PyArg_ParseTuple(_args
, "hO&",
615 TextStyle_Convert
, &aStyle
))
617 _rv
= TEContinuousStyle(&mode
,
620 _res
= Py_BuildValue("bhO&",
623 TextStyle_New
, &aStyle
);
627 static PyObject
*TEObj_TEUseStyleScrap(_self
, _args
)
631 PyObject
*_res
= NULL
;
634 StScrpHandle newStyles
;
636 if (!PyArg_ParseTuple(_args
, "llO&b",
639 ResObj_Convert
, &newStyles
,
642 TEUseStyleScrap(rangeStart
,
652 static PyObject
*TEObj_TENumStyles(_self
, _args
)
656 PyObject
*_res
= NULL
;
660 if (!PyArg_ParseTuple(_args
, "ll",
664 _rv
= TENumStyles(rangeStart
,
667 _res
= Py_BuildValue("l",
672 static PyObject
*TEObj_TEFeatureFlag(_self
, _args
)
676 PyObject
*_res
= NULL
;
680 if (!PyArg_ParseTuple(_args
, "hh",
684 _rv
= TEFeatureFlag(feature
,
687 _res
= Py_BuildValue("h",
692 static PyObject
*TEObj_TEGetHiliteRgn(_self
, _args
)
696 PyObject
*_res
= NULL
;
699 if (!PyArg_ParseTuple(_args
, "O&",
700 ResObj_Convert
, ®ion
))
702 _err
= TEGetHiliteRgn(region
,
704 if (_err
!= noErr
) return PyMac_Error(_err
);
710 static PyObject
*TEObj_as_Resource(_self
, _args
)
714 PyObject
*_res
= NULL
;
716 if (!PyArg_ParseTuple(_args
, ""))
718 _rv
= as_Resource(_self
->ob_itself
);
719 _res
= Py_BuildValue("O&",
724 static PyMethodDef TEObj_methods
[] = {
725 {"TESetText", (PyCFunction
)TEObj_TESetText
, 1,
726 "(Buffer text) -> None"},
727 {"TEGetText", (PyCFunction
)TEObj_TEGetText
, 1,
728 "() -> (CharsHandle _rv)"},
729 {"TEIdle", (PyCFunction
)TEObj_TEIdle
, 1,
731 {"TESetSelect", (PyCFunction
)TEObj_TESetSelect
, 1,
732 "(long selStart, long selEnd) -> None"},
733 {"TEActivate", (PyCFunction
)TEObj_TEActivate
, 1,
735 {"TEDeactivate", (PyCFunction
)TEObj_TEDeactivate
, 1,
737 {"TEKey", (PyCFunction
)TEObj_TEKey
, 1,
738 "(CharParameter key) -> None"},
739 {"TECut", (PyCFunction
)TEObj_TECut
, 1,
741 {"TECopy", (PyCFunction
)TEObj_TECopy
, 1,
743 {"TEPaste", (PyCFunction
)TEObj_TEPaste
, 1,
745 {"TEDelete", (PyCFunction
)TEObj_TEDelete
, 1,
747 {"TEInsert", (PyCFunction
)TEObj_TEInsert
, 1,
748 "(Buffer text) -> None"},
749 {"TESetAlignment", (PyCFunction
)TEObj_TESetAlignment
, 1,
750 "(short just) -> None"},
751 {"TEUpdate", (PyCFunction
)TEObj_TEUpdate
, 1,
752 "(Rect rUpdate) -> None"},
753 {"TEScroll", (PyCFunction
)TEObj_TEScroll
, 1,
754 "(short dh, short dv) -> None"},
755 {"TESelView", (PyCFunction
)TEObj_TESelView
, 1,
757 {"TEPinScroll", (PyCFunction
)TEObj_TEPinScroll
, 1,
758 "(short dh, short dv) -> None"},
759 {"TEAutoView", (PyCFunction
)TEObj_TEAutoView
, 1,
760 "(Boolean fAuto) -> None"},
761 {"TECalText", (PyCFunction
)TEObj_TECalText
, 1,
763 {"TEGetOffset", (PyCFunction
)TEObj_TEGetOffset
, 1,
764 "(Point pt) -> (short _rv)"},
765 {"TEGetPoint", (PyCFunction
)TEObj_TEGetPoint
, 1,
766 "(short offset) -> (Point _rv)"},
767 {"TEClick", (PyCFunction
)TEObj_TEClick
, 1,
768 "(Point pt, Boolean fExtend) -> None"},
769 {"TESetStyleHandle", (PyCFunction
)TEObj_TESetStyleHandle
, 1,
770 "(TEStyleHandle theHandle) -> None"},
771 {"TEGetStyleHandle", (PyCFunction
)TEObj_TEGetStyleHandle
, 1,
772 "() -> (TEStyleHandle _rv)"},
773 {"TEGetStyle", (PyCFunction
)TEObj_TEGetStyle
, 1,
774 "(short offset) -> (TextStyle theStyle, short lineHeight, short fontAscent)"},
775 {"TEStylePaste", (PyCFunction
)TEObj_TEStylePaste
, 1,
777 {"TESetStyle", (PyCFunction
)TEObj_TESetStyle
, 1,
778 "(short mode, TextStyle newStyle, Boolean fRedraw) -> None"},
779 {"TEReplaceStyle", (PyCFunction
)TEObj_TEReplaceStyle
, 1,
780 "(short mode, TextStyle oldStyle, TextStyle newStyle, Boolean fRedraw) -> None"},
781 {"TEGetStyleScrapHandle", (PyCFunction
)TEObj_TEGetStyleScrapHandle
, 1,
782 "() -> (StScrpHandle _rv)"},
783 {"TEStyleInsert", (PyCFunction
)TEObj_TEStyleInsert
, 1,
784 "(Buffer text, StScrpHandle hST) -> None"},
785 {"TEGetHeight", (PyCFunction
)TEObj_TEGetHeight
, 1,
786 "(long endLine, long startLine) -> (long _rv)"},
787 {"TEContinuousStyle", (PyCFunction
)TEObj_TEContinuousStyle
, 1,
788 "(short mode, TextStyle aStyle) -> (Boolean _rv, short mode, TextStyle aStyle)"},
789 {"TEUseStyleScrap", (PyCFunction
)TEObj_TEUseStyleScrap
, 1,
790 "(long rangeStart, long rangeEnd, StScrpHandle newStyles, Boolean fRedraw) -> None"},
791 {"TENumStyles", (PyCFunction
)TEObj_TENumStyles
, 1,
792 "(long rangeStart, long rangeEnd) -> (long _rv)"},
793 {"TEFeatureFlag", (PyCFunction
)TEObj_TEFeatureFlag
, 1,
794 "(short feature, short action) -> (short _rv)"},
795 {"TEGetHiliteRgn", (PyCFunction
)TEObj_TEGetHiliteRgn
, 1,
796 "(RgnHandle region) -> None"},
797 {"as_Resource", (PyCFunction
)TEObj_as_Resource
, 1,
798 "() -> (Handle _rv)"},
802 PyMethodChain TEObj_chain
= { TEObj_methods
, NULL
};
804 static PyObject
*TEObj_getattr(self
, name
)
809 if( strcmp(name
, "destRect") == 0 )
810 return Py_BuildValue("O&", PyMac_BuildRect
,
811 &(*self
->ob_itself
)->destRect
);
812 if( strcmp(name
, "viewRect") == 0 )
813 return Py_BuildValue("O&", PyMac_BuildRect
,
814 &(*self
->ob_itself
)->viewRect
);
815 if( strcmp(name
, "selRect") == 0 )
816 return Py_BuildValue("O&", PyMac_BuildRect
,
817 &(*self
->ob_itself
)->selRect
);
818 if( strcmp(name
, "lineHeight") == 0 )
819 return Py_BuildValue("h", (*self
->ob_itself
)->lineHeight
);
820 if( strcmp(name
, "fontAscent") == 0 )
821 return Py_BuildValue("h", (*self
->ob_itself
)->fontAscent
);
822 if( strcmp(name
, "selPoint") == 0 )
823 return Py_BuildValue("O&", PyMac_BuildPoint
,
824 (*self
->ob_itself
)->selPoint
);
825 if( strcmp(name
, "selStart") == 0 )
826 return Py_BuildValue("h", (*self
->ob_itself
)->selStart
);
827 if( strcmp(name
, "selEnd") == 0 )
828 return Py_BuildValue("h", (*self
->ob_itself
)->selEnd
);
829 if( strcmp(name
, "active") == 0 )
830 return Py_BuildValue("h", (*self
->ob_itself
)->active
);
831 if( strcmp(name
, "just") == 0 )
832 return Py_BuildValue("h", (*self
->ob_itself
)->just
);
833 if( strcmp(name
, "teLength") == 0 )
834 return Py_BuildValue("h", (*self
->ob_itself
)->teLength
);
835 if( strcmp(name
, "txFont") == 0 )
836 return Py_BuildValue("h", (*self
->ob_itself
)->txFont
);
837 if( strcmp(name
, "txFace") == 0 )
838 return Py_BuildValue("h", (*self
->ob_itself
)->txFace
);
839 if( strcmp(name
, "txMode") == 0 )
840 return Py_BuildValue("h", (*self
->ob_itself
)->txMode
);
841 if( strcmp(name
, "txSize") == 0 )
842 return Py_BuildValue("h", (*self
->ob_itself
)->txSize
);
843 if( strcmp(name
, "nLines") == 0 )
844 return Py_BuildValue("h", (*self
->ob_itself
)->nLines
);
846 return Py_FindMethodInChain(&TEObj_chain
, (PyObject
*)self
, name
);
849 #define TEObj_setattr NULL
851 #define TEObj_compare NULL
853 #define TEObj_repr NULL
855 #define TEObj_hash NULL
857 PyTypeObject TE_Type
= {
858 PyObject_HEAD_INIT(&PyType_Type
)
861 sizeof(TEObject
), /*tp_basicsize*/
864 (destructor
) TEObj_dealloc
, /*tp_dealloc*/
866 (getattrfunc
) TEObj_getattr
, /*tp_getattr*/
867 (setattrfunc
) TEObj_setattr
, /*tp_setattr*/
868 (cmpfunc
) TEObj_compare
, /*tp_compare*/
869 (reprfunc
) TEObj_repr
, /*tp_repr*/
870 (PyNumberMethods
*)0, /* tp_as_number */
871 (PySequenceMethods
*)0, /* tp_as_sequence */
872 (PyMappingMethods
*)0, /* tp_as_mapping */
873 (hashfunc
) TEObj_hash
, /*tp_hash*/
876 /* ----------------------- End object type TE ----------------------- */
879 static PyObject
*TE_TEScrapHandle(_self
, _args
)
883 PyObject
*_res
= NULL
;
885 if (!PyArg_ParseTuple(_args
, ""))
887 _rv
= TEScrapHandle();
888 _res
= Py_BuildValue("O&",
893 static PyObject
*TE_TEGetScrapLength(_self
, _args
)
897 PyObject
*_res
= NULL
;
899 if (!PyArg_ParseTuple(_args
, ""))
901 _rv
= TEGetScrapLength();
902 _res
= Py_BuildValue("l",
907 static PyObject
*TE_TENew(_self
, _args
)
911 PyObject
*_res
= NULL
;
915 if (!PyArg_ParseTuple(_args
, "O&O&",
916 PyMac_GetRect
, &destRect
,
917 PyMac_GetRect
, &viewRect
))
919 _rv
= TENew(&destRect
,
921 _res
= Py_BuildValue("O&",
926 static PyObject
*TE_TETextBox(_self
, _args
)
930 PyObject
*_res
= NULL
;
936 if (!PyArg_ParseTuple(_args
, "s#O&h",
937 &text__in__
, &text__in_len__
,
941 text__len__
= text__in_len__
;
942 TETextBox(text__in__
, text__len__
,
951 static PyObject
*TE_TEStyleNew(_self
, _args
)
955 PyObject
*_res
= NULL
;
959 if (!PyArg_ParseTuple(_args
, "O&O&",
960 PyMac_GetRect
, &destRect
,
961 PyMac_GetRect
, &viewRect
))
963 _rv
= TEStyleNew(&destRect
,
965 _res
= Py_BuildValue("O&",
970 static PyObject
*TE_TESetScrapLength(_self
, _args
)
974 PyObject
*_res
= NULL
;
976 if (!PyArg_ParseTuple(_args
, "l",
979 TESetScrapLength(length
);
985 static PyObject
*TE_TEFromScrap(_self
, _args
)
989 PyObject
*_res
= NULL
;
991 if (!PyArg_ParseTuple(_args
, ""))
993 _err
= TEFromScrap();
994 if (_err
!= noErr
) return PyMac_Error(_err
);
1000 static PyObject
*TE_TEToScrap(_self
, _args
)
1004 PyObject
*_res
= NULL
;
1006 if (!PyArg_ParseTuple(_args
, ""))
1009 if (_err
!= noErr
) return PyMac_Error(_err
);
1015 static PyObject
*TE_as_TE(_self
, _args
)
1019 PyObject
*_res
= NULL
;
1022 if (!PyArg_ParseTuple(_args
, "O&",
1023 ResObj_Convert
, &h
))
1026 _res
= Py_BuildValue("O&",
1031 static PyMethodDef TE_methods
[] = {
1032 {"TEScrapHandle", (PyCFunction
)TE_TEScrapHandle
, 1,
1033 "() -> (Handle _rv)"},
1034 {"TEGetScrapLength", (PyCFunction
)TE_TEGetScrapLength
, 1,
1035 "() -> (long _rv)"},
1036 {"TENew", (PyCFunction
)TE_TENew
, 1,
1037 "(Rect destRect, Rect viewRect) -> (TEHandle _rv)"},
1038 {"TETextBox", (PyCFunction
)TE_TETextBox
, 1,
1039 "(Buffer text, Rect box, short just) -> None"},
1040 {"TEStyleNew", (PyCFunction
)TE_TEStyleNew
, 1,
1041 "(Rect destRect, Rect viewRect) -> (TEHandle _rv)"},
1042 {"TESetScrapLength", (PyCFunction
)TE_TESetScrapLength
, 1,
1043 "(long length) -> None"},
1044 {"TEFromScrap", (PyCFunction
)TE_TEFromScrap
, 1,
1046 {"TEToScrap", (PyCFunction
)TE_TEToScrap
, 1,
1048 {"as_TE", (PyCFunction
)TE_as_TE
, 1,
1049 "(Handle h) -> (TEHandle _rv)"},
1064 m
= Py_InitModule("TE", TE_methods
);
1065 d
= PyModule_GetDict(m
);
1066 TE_Error
= PyMac_GetOSErrException();
1067 if (TE_Error
== NULL
||
1068 PyDict_SetItemString(d
, "Error", TE_Error
) != 0)
1069 Py_FatalError("can't initialize TE.Error");
1070 TE_Type
.ob_type
= &PyType_Type
;
1071 Py_INCREF(&TE_Type
);
1072 if (PyDict_SetItemString(d
, "TEType", (PyObject
*)&TE_Type
) != 0)
1073 Py_FatalError("can't initialize TEType");
1076 /* ========================= End module TE ========================== */