Update for release.
[python/dscho.git] / Mac / Modules / te / _TEmodule.c
blob2da251350766fed3a6e8a11cd6319cdf06287068
2 /* =========================== Module _TE =========================== */
4 #include "Python.h"
8 #ifdef _WIN32
9 #include "pywintoolbox.h"
10 #else
11 #include "macglue.h"
12 #include "pymactoolbox.h"
13 #endif
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
19 return NULL; \
20 }} while(0)
23 #ifdef WITHOUT_FRAMEWORKS
24 #include <TextEdit.h>
25 #else
26 #include <Carbon/Carbon.h>
27 #endif
29 #ifdef USE_TOOLBOX_OBJECT_GLUE
30 extern PyObject *_TEObj_New(TEHandle);
31 extern int _TEObj_Convert(PyObject *, TEHandle *);
33 #define TEObj_New _TEObj_New
34 #define TEObj_Convert _TEObj_Convert
35 #endif
37 #define as_TE(h) ((TEHandle)h)
38 #define as_Resource(teh) ((Handle)teh)
41 ** Parse/generate TextStyle records
43 static PyObject *
44 TextStyle_New(TextStylePtr itself)
47 return Py_BuildValue("lllO&", (long)itself->tsFont, (long)itself->tsFace, (long)itself->tsSize, QdRGB_New,
48 &itself->tsColor);
51 static int
52 TextStyle_Convert(PyObject *v, TextStylePtr p_itself)
54 long font, face, size;
56 if( !PyArg_ParseTuple(v, "lllO&", &font, &face, &size, QdRGB_Convert, &p_itself->tsColor) )
57 return 0;
58 p_itself->tsFont = (short)font;
59 p_itself->tsFace = (Style)face;
60 p_itself->tsSize = (short)size;
61 return 1;
64 static PyObject *TE_Error;
66 /* ------------------------- Object type TE ------------------------- */
68 PyTypeObject TE_Type;
70 #define TEObj_Check(x) ((x)->ob_type == &TE_Type || PyObject_TypeCheck((x), &TE_Type))
72 typedef struct TEObject {
73 PyObject_HEAD
74 TEHandle ob_itself;
75 } TEObject;
77 PyObject *TEObj_New(TEHandle itself)
79 TEObject *it;
80 if (itself == NULL) {
81 PyErr_SetString(TE_Error,"Cannot create null TE");
82 return NULL;
84 it = PyObject_NEW(TEObject, &TE_Type);
85 if (it == NULL) return NULL;
86 it->ob_itself = itself;
87 return (PyObject *)it;
89 int TEObj_Convert(PyObject *v, TEHandle *p_itself)
91 if (!TEObj_Check(v))
93 PyErr_SetString(PyExc_TypeError, "TE required");
94 return 0;
96 *p_itself = ((TEObject *)v)->ob_itself;
97 return 1;
100 static void TEObj_dealloc(TEObject *self)
102 TEDispose(self->ob_itself);
103 self->ob_type->tp_free((PyObject *)self);
106 static PyObject *TEObj_TESetText(TEObject *_self, PyObject *_args)
108 PyObject *_res = NULL;
109 char *text__in__;
110 long text__len__;
111 int text__in_len__;
112 #ifndef TESetText
113 PyMac_PRECHECK(TESetText);
114 #endif
115 if (!PyArg_ParseTuple(_args, "s#",
116 &text__in__, &text__in_len__))
117 return NULL;
118 text__len__ = text__in_len__;
119 TESetText(text__in__, text__len__,
120 _self->ob_itself);
121 Py_INCREF(Py_None);
122 _res = Py_None;
123 return _res;
126 static PyObject *TEObj_TEGetText(TEObject *_self, PyObject *_args)
128 PyObject *_res = NULL;
129 CharsHandle _rv;
130 #ifndef TEGetText
131 PyMac_PRECHECK(TEGetText);
132 #endif
133 if (!PyArg_ParseTuple(_args, ""))
134 return NULL;
135 _rv = TEGetText(_self->ob_itself);
136 _res = Py_BuildValue("O&",
137 ResObj_New, _rv);
138 return _res;
141 static PyObject *TEObj_TEIdle(TEObject *_self, PyObject *_args)
143 PyObject *_res = NULL;
144 #ifndef TEIdle
145 PyMac_PRECHECK(TEIdle);
146 #endif
147 if (!PyArg_ParseTuple(_args, ""))
148 return NULL;
149 TEIdle(_self->ob_itself);
150 Py_INCREF(Py_None);
151 _res = Py_None;
152 return _res;
155 static PyObject *TEObj_TESetSelect(TEObject *_self, PyObject *_args)
157 PyObject *_res = NULL;
158 long selStart;
159 long selEnd;
160 #ifndef TESetSelect
161 PyMac_PRECHECK(TESetSelect);
162 #endif
163 if (!PyArg_ParseTuple(_args, "ll",
164 &selStart,
165 &selEnd))
166 return NULL;
167 TESetSelect(selStart,
168 selEnd,
169 _self->ob_itself);
170 Py_INCREF(Py_None);
171 _res = Py_None;
172 return _res;
175 static PyObject *TEObj_TEActivate(TEObject *_self, PyObject *_args)
177 PyObject *_res = NULL;
178 #ifndef TEActivate
179 PyMac_PRECHECK(TEActivate);
180 #endif
181 if (!PyArg_ParseTuple(_args, ""))
182 return NULL;
183 TEActivate(_self->ob_itself);
184 Py_INCREF(Py_None);
185 _res = Py_None;
186 return _res;
189 static PyObject *TEObj_TEDeactivate(TEObject *_self, PyObject *_args)
191 PyObject *_res = NULL;
192 #ifndef TEDeactivate
193 PyMac_PRECHECK(TEDeactivate);
194 #endif
195 if (!PyArg_ParseTuple(_args, ""))
196 return NULL;
197 TEDeactivate(_self->ob_itself);
198 Py_INCREF(Py_None);
199 _res = Py_None;
200 return _res;
203 static PyObject *TEObj_TEKey(TEObject *_self, PyObject *_args)
205 PyObject *_res = NULL;
206 CharParameter key;
207 #ifndef TEKey
208 PyMac_PRECHECK(TEKey);
209 #endif
210 if (!PyArg_ParseTuple(_args, "h",
211 &key))
212 return NULL;
213 TEKey(key,
214 _self->ob_itself);
215 Py_INCREF(Py_None);
216 _res = Py_None;
217 return _res;
220 static PyObject *TEObj_TECut(TEObject *_self, PyObject *_args)
222 PyObject *_res = NULL;
223 #ifndef TECut
224 PyMac_PRECHECK(TECut);
225 #endif
226 if (!PyArg_ParseTuple(_args, ""))
227 return NULL;
228 TECut(_self->ob_itself);
229 Py_INCREF(Py_None);
230 _res = Py_None;
231 return _res;
234 static PyObject *TEObj_TECopy(TEObject *_self, PyObject *_args)
236 PyObject *_res = NULL;
237 #ifndef TECopy
238 PyMac_PRECHECK(TECopy);
239 #endif
240 if (!PyArg_ParseTuple(_args, ""))
241 return NULL;
242 TECopy(_self->ob_itself);
243 Py_INCREF(Py_None);
244 _res = Py_None;
245 return _res;
248 static PyObject *TEObj_TEPaste(TEObject *_self, PyObject *_args)
250 PyObject *_res = NULL;
251 #ifndef TEPaste
252 PyMac_PRECHECK(TEPaste);
253 #endif
254 if (!PyArg_ParseTuple(_args, ""))
255 return NULL;
256 TEPaste(_self->ob_itself);
257 Py_INCREF(Py_None);
258 _res = Py_None;
259 return _res;
262 static PyObject *TEObj_TEDelete(TEObject *_self, PyObject *_args)
264 PyObject *_res = NULL;
265 #ifndef TEDelete
266 PyMac_PRECHECK(TEDelete);
267 #endif
268 if (!PyArg_ParseTuple(_args, ""))
269 return NULL;
270 TEDelete(_self->ob_itself);
271 Py_INCREF(Py_None);
272 _res = Py_None;
273 return _res;
276 static PyObject *TEObj_TEInsert(TEObject *_self, PyObject *_args)
278 PyObject *_res = NULL;
279 char *text__in__;
280 long text__len__;
281 int text__in_len__;
282 #ifndef TEInsert
283 PyMac_PRECHECK(TEInsert);
284 #endif
285 if (!PyArg_ParseTuple(_args, "s#",
286 &text__in__, &text__in_len__))
287 return NULL;
288 text__len__ = text__in_len__;
289 TEInsert(text__in__, text__len__,
290 _self->ob_itself);
291 Py_INCREF(Py_None);
292 _res = Py_None;
293 return _res;
296 static PyObject *TEObj_TESetAlignment(TEObject *_self, PyObject *_args)
298 PyObject *_res = NULL;
299 short just;
300 #ifndef TESetAlignment
301 PyMac_PRECHECK(TESetAlignment);
302 #endif
303 if (!PyArg_ParseTuple(_args, "h",
304 &just))
305 return NULL;
306 TESetAlignment(just,
307 _self->ob_itself);
308 Py_INCREF(Py_None);
309 _res = Py_None;
310 return _res;
313 static PyObject *TEObj_TEUpdate(TEObject *_self, PyObject *_args)
315 PyObject *_res = NULL;
316 Rect rUpdate;
317 #ifndef TEUpdate
318 PyMac_PRECHECK(TEUpdate);
319 #endif
320 if (!PyArg_ParseTuple(_args, "O&",
321 PyMac_GetRect, &rUpdate))
322 return NULL;
323 TEUpdate(&rUpdate,
324 _self->ob_itself);
325 Py_INCREF(Py_None);
326 _res = Py_None;
327 return _res;
330 static PyObject *TEObj_TEScroll(TEObject *_self, PyObject *_args)
332 PyObject *_res = NULL;
333 short dh;
334 short dv;
335 #ifndef TEScroll
336 PyMac_PRECHECK(TEScroll);
337 #endif
338 if (!PyArg_ParseTuple(_args, "hh",
339 &dh,
340 &dv))
341 return NULL;
342 TEScroll(dh,
344 _self->ob_itself);
345 Py_INCREF(Py_None);
346 _res = Py_None;
347 return _res;
350 static PyObject *TEObj_TESelView(TEObject *_self, PyObject *_args)
352 PyObject *_res = NULL;
353 #ifndef TESelView
354 PyMac_PRECHECK(TESelView);
355 #endif
356 if (!PyArg_ParseTuple(_args, ""))
357 return NULL;
358 TESelView(_self->ob_itself);
359 Py_INCREF(Py_None);
360 _res = Py_None;
361 return _res;
364 static PyObject *TEObj_TEPinScroll(TEObject *_self, PyObject *_args)
366 PyObject *_res = NULL;
367 short dh;
368 short dv;
369 #ifndef TEPinScroll
370 PyMac_PRECHECK(TEPinScroll);
371 #endif
372 if (!PyArg_ParseTuple(_args, "hh",
373 &dh,
374 &dv))
375 return NULL;
376 TEPinScroll(dh,
378 _self->ob_itself);
379 Py_INCREF(Py_None);
380 _res = Py_None;
381 return _res;
384 static PyObject *TEObj_TEAutoView(TEObject *_self, PyObject *_args)
386 PyObject *_res = NULL;
387 Boolean fAuto;
388 #ifndef TEAutoView
389 PyMac_PRECHECK(TEAutoView);
390 #endif
391 if (!PyArg_ParseTuple(_args, "b",
392 &fAuto))
393 return NULL;
394 TEAutoView(fAuto,
395 _self->ob_itself);
396 Py_INCREF(Py_None);
397 _res = Py_None;
398 return _res;
401 static PyObject *TEObj_TECalText(TEObject *_self, PyObject *_args)
403 PyObject *_res = NULL;
404 #ifndef TECalText
405 PyMac_PRECHECK(TECalText);
406 #endif
407 if (!PyArg_ParseTuple(_args, ""))
408 return NULL;
409 TECalText(_self->ob_itself);
410 Py_INCREF(Py_None);
411 _res = Py_None;
412 return _res;
415 static PyObject *TEObj_TEGetOffset(TEObject *_self, PyObject *_args)
417 PyObject *_res = NULL;
418 short _rv;
419 Point pt;
420 #ifndef TEGetOffset
421 PyMac_PRECHECK(TEGetOffset);
422 #endif
423 if (!PyArg_ParseTuple(_args, "O&",
424 PyMac_GetPoint, &pt))
425 return NULL;
426 _rv = TEGetOffset(pt,
427 _self->ob_itself);
428 _res = Py_BuildValue("h",
429 _rv);
430 return _res;
433 static PyObject *TEObj_TEGetPoint(TEObject *_self, PyObject *_args)
435 PyObject *_res = NULL;
436 Point _rv;
437 short offset;
438 #ifndef TEGetPoint
439 PyMac_PRECHECK(TEGetPoint);
440 #endif
441 if (!PyArg_ParseTuple(_args, "h",
442 &offset))
443 return NULL;
444 _rv = TEGetPoint(offset,
445 _self->ob_itself);
446 _res = Py_BuildValue("O&",
447 PyMac_BuildPoint, _rv);
448 return _res;
451 static PyObject *TEObj_TEClick(TEObject *_self, PyObject *_args)
453 PyObject *_res = NULL;
454 Point pt;
455 Boolean fExtend;
456 #ifndef TEClick
457 PyMac_PRECHECK(TEClick);
458 #endif
459 if (!PyArg_ParseTuple(_args, "O&b",
460 PyMac_GetPoint, &pt,
461 &fExtend))
462 return NULL;
463 TEClick(pt,
464 fExtend,
465 _self->ob_itself);
466 Py_INCREF(Py_None);
467 _res = Py_None;
468 return _res;
471 static PyObject *TEObj_TESetStyleHandle(TEObject *_self, PyObject *_args)
473 PyObject *_res = NULL;
474 TEStyleHandle theHandle;
475 #ifndef TESetStyleHandle
476 PyMac_PRECHECK(TESetStyleHandle);
477 #endif
478 if (!PyArg_ParseTuple(_args, "O&",
479 ResObj_Convert, &theHandle))
480 return NULL;
481 TESetStyleHandle(theHandle,
482 _self->ob_itself);
483 Py_INCREF(Py_None);
484 _res = Py_None;
485 return _res;
488 static PyObject *TEObj_TEGetStyleHandle(TEObject *_self, PyObject *_args)
490 PyObject *_res = NULL;
491 TEStyleHandle _rv;
492 #ifndef TEGetStyleHandle
493 PyMac_PRECHECK(TEGetStyleHandle);
494 #endif
495 if (!PyArg_ParseTuple(_args, ""))
496 return NULL;
497 _rv = TEGetStyleHandle(_self->ob_itself);
498 _res = Py_BuildValue("O&",
499 ResObj_New, _rv);
500 return _res;
503 static PyObject *TEObj_TEGetStyle(TEObject *_self, PyObject *_args)
505 PyObject *_res = NULL;
506 short offset;
507 TextStyle theStyle;
508 short lineHeight;
509 short fontAscent;
510 #ifndef TEGetStyle
511 PyMac_PRECHECK(TEGetStyle);
512 #endif
513 if (!PyArg_ParseTuple(_args, "h",
514 &offset))
515 return NULL;
516 TEGetStyle(offset,
517 &theStyle,
518 &lineHeight,
519 &fontAscent,
520 _self->ob_itself);
521 _res = Py_BuildValue("O&hh",
522 TextStyle_New, &theStyle,
523 lineHeight,
524 fontAscent);
525 return _res;
528 static PyObject *TEObj_TEStylePaste(TEObject *_self, PyObject *_args)
530 PyObject *_res = NULL;
531 #ifndef TEStylePaste
532 PyMac_PRECHECK(TEStylePaste);
533 #endif
534 if (!PyArg_ParseTuple(_args, ""))
535 return NULL;
536 TEStylePaste(_self->ob_itself);
537 Py_INCREF(Py_None);
538 _res = Py_None;
539 return _res;
542 static PyObject *TEObj_TESetStyle(TEObject *_self, PyObject *_args)
544 PyObject *_res = NULL;
545 short mode;
546 TextStyle newStyle;
547 Boolean fRedraw;
548 #ifndef TESetStyle
549 PyMac_PRECHECK(TESetStyle);
550 #endif
551 if (!PyArg_ParseTuple(_args, "hO&b",
552 &mode,
553 TextStyle_Convert, &newStyle,
554 &fRedraw))
555 return NULL;
556 TESetStyle(mode,
557 &newStyle,
558 fRedraw,
559 _self->ob_itself);
560 Py_INCREF(Py_None);
561 _res = Py_None;
562 return _res;
565 static PyObject *TEObj_TEReplaceStyle(TEObject *_self, PyObject *_args)
567 PyObject *_res = NULL;
568 short mode;
569 TextStyle oldStyle;
570 TextStyle newStyle;
571 Boolean fRedraw;
572 #ifndef TEReplaceStyle
573 PyMac_PRECHECK(TEReplaceStyle);
574 #endif
575 if (!PyArg_ParseTuple(_args, "hO&O&b",
576 &mode,
577 TextStyle_Convert, &oldStyle,
578 TextStyle_Convert, &newStyle,
579 &fRedraw))
580 return NULL;
581 TEReplaceStyle(mode,
582 &oldStyle,
583 &newStyle,
584 fRedraw,
585 _self->ob_itself);
586 Py_INCREF(Py_None);
587 _res = Py_None;
588 return _res;
591 static PyObject *TEObj_TEGetStyleScrapHandle(TEObject *_self, PyObject *_args)
593 PyObject *_res = NULL;
594 StScrpHandle _rv;
595 #ifndef TEGetStyleScrapHandle
596 PyMac_PRECHECK(TEGetStyleScrapHandle);
597 #endif
598 if (!PyArg_ParseTuple(_args, ""))
599 return NULL;
600 _rv = TEGetStyleScrapHandle(_self->ob_itself);
601 _res = Py_BuildValue("O&",
602 ResObj_New, _rv);
603 return _res;
606 static PyObject *TEObj_TEStyleInsert(TEObject *_self, PyObject *_args)
608 PyObject *_res = NULL;
609 char *text__in__;
610 long text__len__;
611 int text__in_len__;
612 StScrpHandle hST;
613 #ifndef TEStyleInsert
614 PyMac_PRECHECK(TEStyleInsert);
615 #endif
616 if (!PyArg_ParseTuple(_args, "s#O&",
617 &text__in__, &text__in_len__,
618 ResObj_Convert, &hST))
619 return NULL;
620 text__len__ = text__in_len__;
621 TEStyleInsert(text__in__, text__len__,
622 hST,
623 _self->ob_itself);
624 Py_INCREF(Py_None);
625 _res = Py_None;
626 return _res;
629 static PyObject *TEObj_TEGetHeight(TEObject *_self, PyObject *_args)
631 PyObject *_res = NULL;
632 long _rv;
633 long endLine;
634 long startLine;
635 #ifndef TEGetHeight
636 PyMac_PRECHECK(TEGetHeight);
637 #endif
638 if (!PyArg_ParseTuple(_args, "ll",
639 &endLine,
640 &startLine))
641 return NULL;
642 _rv = TEGetHeight(endLine,
643 startLine,
644 _self->ob_itself);
645 _res = Py_BuildValue("l",
646 _rv);
647 return _res;
650 static PyObject *TEObj_TEContinuousStyle(TEObject *_self, PyObject *_args)
652 PyObject *_res = NULL;
653 Boolean _rv;
654 short mode;
655 TextStyle aStyle;
656 #ifndef TEContinuousStyle
657 PyMac_PRECHECK(TEContinuousStyle);
658 #endif
659 if (!PyArg_ParseTuple(_args, "hO&",
660 &mode,
661 TextStyle_Convert, &aStyle))
662 return NULL;
663 _rv = TEContinuousStyle(&mode,
664 &aStyle,
665 _self->ob_itself);
666 _res = Py_BuildValue("bhO&",
667 _rv,
668 mode,
669 TextStyle_New, &aStyle);
670 return _res;
673 static PyObject *TEObj_TEUseStyleScrap(TEObject *_self, PyObject *_args)
675 PyObject *_res = NULL;
676 long rangeStart;
677 long rangeEnd;
678 StScrpHandle newStyles;
679 Boolean fRedraw;
680 #ifndef TEUseStyleScrap
681 PyMac_PRECHECK(TEUseStyleScrap);
682 #endif
683 if (!PyArg_ParseTuple(_args, "llO&b",
684 &rangeStart,
685 &rangeEnd,
686 ResObj_Convert, &newStyles,
687 &fRedraw))
688 return NULL;
689 TEUseStyleScrap(rangeStart,
690 rangeEnd,
691 newStyles,
692 fRedraw,
693 _self->ob_itself);
694 Py_INCREF(Py_None);
695 _res = Py_None;
696 return _res;
699 static PyObject *TEObj_TENumStyles(TEObject *_self, PyObject *_args)
701 PyObject *_res = NULL;
702 long _rv;
703 long rangeStart;
704 long rangeEnd;
705 #ifndef TENumStyles
706 PyMac_PRECHECK(TENumStyles);
707 #endif
708 if (!PyArg_ParseTuple(_args, "ll",
709 &rangeStart,
710 &rangeEnd))
711 return NULL;
712 _rv = TENumStyles(rangeStart,
713 rangeEnd,
714 _self->ob_itself);
715 _res = Py_BuildValue("l",
716 _rv);
717 return _res;
720 static PyObject *TEObj_TEFeatureFlag(TEObject *_self, PyObject *_args)
722 PyObject *_res = NULL;
723 short _rv;
724 short feature;
725 short action;
726 #ifndef TEFeatureFlag
727 PyMac_PRECHECK(TEFeatureFlag);
728 #endif
729 if (!PyArg_ParseTuple(_args, "hh",
730 &feature,
731 &action))
732 return NULL;
733 _rv = TEFeatureFlag(feature,
734 action,
735 _self->ob_itself);
736 _res = Py_BuildValue("h",
737 _rv);
738 return _res;
741 static PyObject *TEObj_TEGetHiliteRgn(TEObject *_self, PyObject *_args)
743 PyObject *_res = NULL;
744 OSErr _err;
745 RgnHandle region;
746 #ifndef TEGetHiliteRgn
747 PyMac_PRECHECK(TEGetHiliteRgn);
748 #endif
749 if (!PyArg_ParseTuple(_args, "O&",
750 ResObj_Convert, &region))
751 return NULL;
752 _err = TEGetHiliteRgn(region,
753 _self->ob_itself);
754 if (_err != noErr) return PyMac_Error(_err);
755 Py_INCREF(Py_None);
756 _res = Py_None;
757 return _res;
760 static PyObject *TEObj_as_Resource(TEObject *_self, PyObject *_args)
762 PyObject *_res = NULL;
763 Handle _rv;
764 #ifndef as_Resource
765 PyMac_PRECHECK(as_Resource);
766 #endif
767 if (!PyArg_ParseTuple(_args, ""))
768 return NULL;
769 _rv = as_Resource(_self->ob_itself);
770 _res = Py_BuildValue("O&",
771 ResObj_New, _rv);
772 return _res;
775 static PyMethodDef TEObj_methods[] = {
776 {"TESetText", (PyCFunction)TEObj_TESetText, 1,
777 PyDoc_STR("(Buffer text) -> None")},
778 {"TEGetText", (PyCFunction)TEObj_TEGetText, 1,
779 PyDoc_STR("() -> (CharsHandle _rv)")},
780 {"TEIdle", (PyCFunction)TEObj_TEIdle, 1,
781 PyDoc_STR("() -> None")},
782 {"TESetSelect", (PyCFunction)TEObj_TESetSelect, 1,
783 PyDoc_STR("(long selStart, long selEnd) -> None")},
784 {"TEActivate", (PyCFunction)TEObj_TEActivate, 1,
785 PyDoc_STR("() -> None")},
786 {"TEDeactivate", (PyCFunction)TEObj_TEDeactivate, 1,
787 PyDoc_STR("() -> None")},
788 {"TEKey", (PyCFunction)TEObj_TEKey, 1,
789 PyDoc_STR("(CharParameter key) -> None")},
790 {"TECut", (PyCFunction)TEObj_TECut, 1,
791 PyDoc_STR("() -> None")},
792 {"TECopy", (PyCFunction)TEObj_TECopy, 1,
793 PyDoc_STR("() -> None")},
794 {"TEPaste", (PyCFunction)TEObj_TEPaste, 1,
795 PyDoc_STR("() -> None")},
796 {"TEDelete", (PyCFunction)TEObj_TEDelete, 1,
797 PyDoc_STR("() -> None")},
798 {"TEInsert", (PyCFunction)TEObj_TEInsert, 1,
799 PyDoc_STR("(Buffer text) -> None")},
800 {"TESetAlignment", (PyCFunction)TEObj_TESetAlignment, 1,
801 PyDoc_STR("(short just) -> None")},
802 {"TEUpdate", (PyCFunction)TEObj_TEUpdate, 1,
803 PyDoc_STR("(Rect rUpdate) -> None")},
804 {"TEScroll", (PyCFunction)TEObj_TEScroll, 1,
805 PyDoc_STR("(short dh, short dv) -> None")},
806 {"TESelView", (PyCFunction)TEObj_TESelView, 1,
807 PyDoc_STR("() -> None")},
808 {"TEPinScroll", (PyCFunction)TEObj_TEPinScroll, 1,
809 PyDoc_STR("(short dh, short dv) -> None")},
810 {"TEAutoView", (PyCFunction)TEObj_TEAutoView, 1,
811 PyDoc_STR("(Boolean fAuto) -> None")},
812 {"TECalText", (PyCFunction)TEObj_TECalText, 1,
813 PyDoc_STR("() -> None")},
814 {"TEGetOffset", (PyCFunction)TEObj_TEGetOffset, 1,
815 PyDoc_STR("(Point pt) -> (short _rv)")},
816 {"TEGetPoint", (PyCFunction)TEObj_TEGetPoint, 1,
817 PyDoc_STR("(short offset) -> (Point _rv)")},
818 {"TEClick", (PyCFunction)TEObj_TEClick, 1,
819 PyDoc_STR("(Point pt, Boolean fExtend) -> None")},
820 {"TESetStyleHandle", (PyCFunction)TEObj_TESetStyleHandle, 1,
821 PyDoc_STR("(TEStyleHandle theHandle) -> None")},
822 {"TEGetStyleHandle", (PyCFunction)TEObj_TEGetStyleHandle, 1,
823 PyDoc_STR("() -> (TEStyleHandle _rv)")},
824 {"TEGetStyle", (PyCFunction)TEObj_TEGetStyle, 1,
825 PyDoc_STR("(short offset) -> (TextStyle theStyle, short lineHeight, short fontAscent)")},
826 {"TEStylePaste", (PyCFunction)TEObj_TEStylePaste, 1,
827 PyDoc_STR("() -> None")},
828 {"TESetStyle", (PyCFunction)TEObj_TESetStyle, 1,
829 PyDoc_STR("(short mode, TextStyle newStyle, Boolean fRedraw) -> None")},
830 {"TEReplaceStyle", (PyCFunction)TEObj_TEReplaceStyle, 1,
831 PyDoc_STR("(short mode, TextStyle oldStyle, TextStyle newStyle, Boolean fRedraw) -> None")},
832 {"TEGetStyleScrapHandle", (PyCFunction)TEObj_TEGetStyleScrapHandle, 1,
833 PyDoc_STR("() -> (StScrpHandle _rv)")},
834 {"TEStyleInsert", (PyCFunction)TEObj_TEStyleInsert, 1,
835 PyDoc_STR("(Buffer text, StScrpHandle hST) -> None")},
836 {"TEGetHeight", (PyCFunction)TEObj_TEGetHeight, 1,
837 PyDoc_STR("(long endLine, long startLine) -> (long _rv)")},
838 {"TEContinuousStyle", (PyCFunction)TEObj_TEContinuousStyle, 1,
839 PyDoc_STR("(short mode, TextStyle aStyle) -> (Boolean _rv, short mode, TextStyle aStyle)")},
840 {"TEUseStyleScrap", (PyCFunction)TEObj_TEUseStyleScrap, 1,
841 PyDoc_STR("(long rangeStart, long rangeEnd, StScrpHandle newStyles, Boolean fRedraw) -> None")},
842 {"TENumStyles", (PyCFunction)TEObj_TENumStyles, 1,
843 PyDoc_STR("(long rangeStart, long rangeEnd) -> (long _rv)")},
844 {"TEFeatureFlag", (PyCFunction)TEObj_TEFeatureFlag, 1,
845 PyDoc_STR("(short feature, short action) -> (short _rv)")},
846 {"TEGetHiliteRgn", (PyCFunction)TEObj_TEGetHiliteRgn, 1,
847 PyDoc_STR("(RgnHandle region) -> None")},
848 {"as_Resource", (PyCFunction)TEObj_as_Resource, 1,
849 PyDoc_STR("() -> (Handle _rv)")},
850 {NULL, NULL, 0}
853 static PyObject *TEObj_get_destRect(TEObject *self, void *closure)
855 return Py_BuildValue("O&", PyMac_BuildRect, &(*self->ob_itself)->destRect);
858 #define TEObj_set_destRect NULL
860 static PyObject *TEObj_get_viewRect(TEObject *self, void *closure)
862 return Py_BuildValue("O&", PyMac_BuildRect, &(*self->ob_itself)->viewRect);
865 #define TEObj_set_viewRect NULL
867 static PyObject *TEObj_get_selRect(TEObject *self, void *closure)
869 return Py_BuildValue("O&", PyMac_BuildRect, &(*self->ob_itself)->selRect);
872 #define TEObj_set_selRect NULL
874 static PyObject *TEObj_get_lineHeight(TEObject *self, void *closure)
876 return Py_BuildValue("h", (*self->ob_itself)->lineHeight);
879 #define TEObj_set_lineHeight NULL
881 static PyObject *TEObj_get_fontAscent(TEObject *self, void *closure)
883 return Py_BuildValue("h", (*self->ob_itself)->fontAscent);
886 #define TEObj_set_fontAscent NULL
888 static PyObject *TEObj_get_selPoint(TEObject *self, void *closure)
890 return Py_BuildValue("O&", PyMac_BuildPoint, (*self->ob_itself)->selPoint);
893 #define TEObj_set_selPoint NULL
895 static PyObject *TEObj_get_selStart(TEObject *self, void *closure)
897 return Py_BuildValue("h", (*self->ob_itself)->selStart);
900 #define TEObj_set_selStart NULL
902 static PyObject *TEObj_get_selEnd(TEObject *self, void *closure)
904 return Py_BuildValue("h", (*self->ob_itself)->selEnd);
907 #define TEObj_set_selEnd NULL
909 static PyObject *TEObj_get_active(TEObject *self, void *closure)
911 return Py_BuildValue("h", (*self->ob_itself)->active);
914 #define TEObj_set_active NULL
916 static PyObject *TEObj_get_just(TEObject *self, void *closure)
918 return Py_BuildValue("h", (*self->ob_itself)->just);
921 #define TEObj_set_just NULL
923 static PyObject *TEObj_get_teLength(TEObject *self, void *closure)
925 return Py_BuildValue("h", (*self->ob_itself)->teLength);
928 #define TEObj_set_teLength NULL
930 static PyObject *TEObj_get_txFont(TEObject *self, void *closure)
932 return Py_BuildValue("h", (*self->ob_itself)->txFont);
935 #define TEObj_set_txFont NULL
937 static PyObject *TEObj_get_txFace(TEObject *self, void *closure)
939 return Py_BuildValue("h", (*self->ob_itself)->txFace);
942 #define TEObj_set_txFace NULL
944 static PyObject *TEObj_get_txMode(TEObject *self, void *closure)
946 return Py_BuildValue("h", (*self->ob_itself)->txMode);
949 #define TEObj_set_txMode NULL
951 static PyObject *TEObj_get_txSize(TEObject *self, void *closure)
953 return Py_BuildValue("h", (*self->ob_itself)->txSize);
956 #define TEObj_set_txSize NULL
958 static PyObject *TEObj_get_nLines(TEObject *self, void *closure)
960 return Py_BuildValue("h", (*self->ob_itself)->nLines);
963 #define TEObj_set_nLines NULL
965 static PyGetSetDef TEObj_getsetlist[] = {
966 {"destRect", (getter)TEObj_get_destRect, (setter)TEObj_set_destRect, "Destination rectangle"},
967 {"viewRect", (getter)TEObj_get_viewRect, (setter)TEObj_set_viewRect, "Viewing rectangle"},
968 {"selRect", (getter)TEObj_get_selRect, (setter)TEObj_set_selRect, "Selection rectangle"},
969 {"lineHeight", (getter)TEObj_get_lineHeight, (setter)TEObj_set_lineHeight, "Height of a line"},
970 {"fontAscent", (getter)TEObj_get_fontAscent, (setter)TEObj_set_fontAscent, "Ascent of a line"},
971 {"selPoint", (getter)TEObj_get_selPoint, (setter)TEObj_set_selPoint, "Selection Point"},
972 {"selStart", (getter)TEObj_get_selStart, (setter)TEObj_set_selStart, "Start of selection"},
973 {"selEnd", (getter)TEObj_get_selEnd, (setter)TEObj_set_selEnd, "End of selection"},
974 {"active", (getter)TEObj_get_active, (setter)TEObj_set_active, "TBD"},
975 {"just", (getter)TEObj_get_just, (setter)TEObj_set_just, "Justification"},
976 {"teLength", (getter)TEObj_get_teLength, (setter)TEObj_set_teLength, "TBD"},
977 {"txFont", (getter)TEObj_get_txFont, (setter)TEObj_set_txFont, "Current font"},
978 {"txFace", (getter)TEObj_get_txFace, (setter)TEObj_set_txFace, "Current font variant"},
979 {"txMode", (getter)TEObj_get_txMode, (setter)TEObj_set_txMode, "Current text-drawing mode"},
980 {"txSize", (getter)TEObj_get_txSize, (setter)TEObj_set_txSize, "Current font size"},
981 {"nLines", (getter)TEObj_get_nLines, (setter)TEObj_set_nLines, "TBD"},
982 {NULL, NULL, NULL, NULL},
986 #define TEObj_compare NULL
988 #define TEObj_repr NULL
990 #define TEObj_hash NULL
991 #define TEObj_tp_init 0
993 #define TEObj_tp_alloc PyType_GenericAlloc
995 static PyObject *TEObj_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
997 PyObject *self;
998 TEHandle itself;
999 char *kw[] = {"itself", 0};
1001 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, TEObj_Convert, &itself)) return NULL;
1002 if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
1003 ((TEObject *)self)->ob_itself = itself;
1004 return self;
1007 #define TEObj_tp_free PyObject_Del
1010 PyTypeObject TE_Type = {
1011 PyObject_HEAD_INIT(NULL)
1012 0, /*ob_size*/
1013 "_TE.TE", /*tp_name*/
1014 sizeof(TEObject), /*tp_basicsize*/
1015 0, /*tp_itemsize*/
1016 /* methods */
1017 (destructor) TEObj_dealloc, /*tp_dealloc*/
1018 0, /*tp_print*/
1019 (getattrfunc)0, /*tp_getattr*/
1020 (setattrfunc)0, /*tp_setattr*/
1021 (cmpfunc) TEObj_compare, /*tp_compare*/
1022 (reprfunc) TEObj_repr, /*tp_repr*/
1023 (PyNumberMethods *)0, /* tp_as_number */
1024 (PySequenceMethods *)0, /* tp_as_sequence */
1025 (PyMappingMethods *)0, /* tp_as_mapping */
1026 (hashfunc) TEObj_hash, /*tp_hash*/
1027 0, /*tp_call*/
1028 0, /*tp_str*/
1029 PyObject_GenericGetAttr, /*tp_getattro*/
1030 PyObject_GenericSetAttr, /*tp_setattro */
1031 0, /*tp_as_buffer*/
1032 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1033 0, /*tp_doc*/
1034 0, /*tp_traverse*/
1035 0, /*tp_clear*/
1036 0, /*tp_richcompare*/
1037 0, /*tp_weaklistoffset*/
1038 0, /*tp_iter*/
1039 0, /*tp_iternext*/
1040 TEObj_methods, /* tp_methods */
1041 0, /*tp_members*/
1042 TEObj_getsetlist, /*tp_getset*/
1043 0, /*tp_base*/
1044 0, /*tp_dict*/
1045 0, /*tp_descr_get*/
1046 0, /*tp_descr_set*/
1047 0, /*tp_dictoffset*/
1048 TEObj_tp_init, /* tp_init */
1049 TEObj_tp_alloc, /* tp_alloc */
1050 TEObj_tp_new, /* tp_new */
1051 TEObj_tp_free, /* tp_free */
1054 /* ----------------------- End object type TE ----------------------- */
1057 static PyObject *TE_TEScrapHandle(PyObject *_self, PyObject *_args)
1059 PyObject *_res = NULL;
1060 Handle _rv;
1061 #ifndef TEScrapHandle
1062 PyMac_PRECHECK(TEScrapHandle);
1063 #endif
1064 if (!PyArg_ParseTuple(_args, ""))
1065 return NULL;
1066 _rv = TEScrapHandle();
1067 _res = Py_BuildValue("O&",
1068 ResObj_New, _rv);
1069 return _res;
1072 static PyObject *TE_TEGetScrapLength(PyObject *_self, PyObject *_args)
1074 PyObject *_res = NULL;
1075 long _rv;
1076 #ifndef TEGetScrapLength
1077 PyMac_PRECHECK(TEGetScrapLength);
1078 #endif
1079 if (!PyArg_ParseTuple(_args, ""))
1080 return NULL;
1081 _rv = TEGetScrapLength();
1082 _res = Py_BuildValue("l",
1083 _rv);
1084 return _res;
1087 static PyObject *TE_TENew(PyObject *_self, PyObject *_args)
1089 PyObject *_res = NULL;
1090 TEHandle _rv;
1091 Rect destRect;
1092 Rect viewRect;
1093 #ifndef TENew
1094 PyMac_PRECHECK(TENew);
1095 #endif
1096 if (!PyArg_ParseTuple(_args, "O&O&",
1097 PyMac_GetRect, &destRect,
1098 PyMac_GetRect, &viewRect))
1099 return NULL;
1100 _rv = TENew(&destRect,
1101 &viewRect);
1102 _res = Py_BuildValue("O&",
1103 TEObj_New, _rv);
1104 return _res;
1107 static PyObject *TE_TETextBox(PyObject *_self, PyObject *_args)
1109 PyObject *_res = NULL;
1110 char *text__in__;
1111 long text__len__;
1112 int text__in_len__;
1113 Rect box;
1114 short just;
1115 #ifndef TETextBox
1116 PyMac_PRECHECK(TETextBox);
1117 #endif
1118 if (!PyArg_ParseTuple(_args, "s#O&h",
1119 &text__in__, &text__in_len__,
1120 PyMac_GetRect, &box,
1121 &just))
1122 return NULL;
1123 text__len__ = text__in_len__;
1124 TETextBox(text__in__, text__len__,
1125 &box,
1126 just);
1127 Py_INCREF(Py_None);
1128 _res = Py_None;
1129 return _res;
1132 static PyObject *TE_TEStyleNew(PyObject *_self, PyObject *_args)
1134 PyObject *_res = NULL;
1135 TEHandle _rv;
1136 Rect destRect;
1137 Rect viewRect;
1138 #ifndef TEStyleNew
1139 PyMac_PRECHECK(TEStyleNew);
1140 #endif
1141 if (!PyArg_ParseTuple(_args, "O&O&",
1142 PyMac_GetRect, &destRect,
1143 PyMac_GetRect, &viewRect))
1144 return NULL;
1145 _rv = TEStyleNew(&destRect,
1146 &viewRect);
1147 _res = Py_BuildValue("O&",
1148 TEObj_New, _rv);
1149 return _res;
1152 static PyObject *TE_TESetScrapLength(PyObject *_self, PyObject *_args)
1154 PyObject *_res = NULL;
1155 long length;
1156 #ifndef TESetScrapLength
1157 PyMac_PRECHECK(TESetScrapLength);
1158 #endif
1159 if (!PyArg_ParseTuple(_args, "l",
1160 &length))
1161 return NULL;
1162 TESetScrapLength(length);
1163 Py_INCREF(Py_None);
1164 _res = Py_None;
1165 return _res;
1168 static PyObject *TE_TEFromScrap(PyObject *_self, PyObject *_args)
1170 PyObject *_res = NULL;
1171 OSErr _err;
1172 #ifndef TEFromScrap
1173 PyMac_PRECHECK(TEFromScrap);
1174 #endif
1175 if (!PyArg_ParseTuple(_args, ""))
1176 return NULL;
1177 _err = TEFromScrap();
1178 if (_err != noErr) return PyMac_Error(_err);
1179 Py_INCREF(Py_None);
1180 _res = Py_None;
1181 return _res;
1184 static PyObject *TE_TEToScrap(PyObject *_self, PyObject *_args)
1186 PyObject *_res = NULL;
1187 OSErr _err;
1188 #ifndef TEToScrap
1189 PyMac_PRECHECK(TEToScrap);
1190 #endif
1191 if (!PyArg_ParseTuple(_args, ""))
1192 return NULL;
1193 _err = TEToScrap();
1194 if (_err != noErr) return PyMac_Error(_err);
1195 Py_INCREF(Py_None);
1196 _res = Py_None;
1197 return _res;
1200 static PyObject *TE_TEGetScrapHandle(PyObject *_self, PyObject *_args)
1202 PyObject *_res = NULL;
1203 Handle _rv;
1204 #ifndef TEGetScrapHandle
1205 PyMac_PRECHECK(TEGetScrapHandle);
1206 #endif
1207 if (!PyArg_ParseTuple(_args, ""))
1208 return NULL;
1209 _rv = TEGetScrapHandle();
1210 _res = Py_BuildValue("O&",
1211 ResObj_New, _rv);
1212 return _res;
1215 static PyObject *TE_TESetScrapHandle(PyObject *_self, PyObject *_args)
1217 PyObject *_res = NULL;
1218 Handle value;
1219 #ifndef TESetScrapHandle
1220 PyMac_PRECHECK(TESetScrapHandle);
1221 #endif
1222 if (!PyArg_ParseTuple(_args, "O&",
1223 ResObj_Convert, &value))
1224 return NULL;
1225 TESetScrapHandle(value);
1226 Py_INCREF(Py_None);
1227 _res = Py_None;
1228 return _res;
1231 static PyObject *TE_LMGetWordRedraw(PyObject *_self, PyObject *_args)
1233 PyObject *_res = NULL;
1234 UInt8 _rv;
1235 #ifndef LMGetWordRedraw
1236 PyMac_PRECHECK(LMGetWordRedraw);
1237 #endif
1238 if (!PyArg_ParseTuple(_args, ""))
1239 return NULL;
1240 _rv = LMGetWordRedraw();
1241 _res = Py_BuildValue("b",
1242 _rv);
1243 return _res;
1246 static PyObject *TE_LMSetWordRedraw(PyObject *_self, PyObject *_args)
1248 PyObject *_res = NULL;
1249 UInt8 value;
1250 #ifndef LMSetWordRedraw
1251 PyMac_PRECHECK(LMSetWordRedraw);
1252 #endif
1253 if (!PyArg_ParseTuple(_args, "b",
1254 &value))
1255 return NULL;
1256 LMSetWordRedraw(value);
1257 Py_INCREF(Py_None);
1258 _res = Py_None;
1259 return _res;
1262 static PyObject *TE_as_TE(PyObject *_self, PyObject *_args)
1264 PyObject *_res = NULL;
1265 TEHandle _rv;
1266 Handle h;
1267 #ifndef as_TE
1268 PyMac_PRECHECK(as_TE);
1269 #endif
1270 if (!PyArg_ParseTuple(_args, "O&",
1271 ResObj_Convert, &h))
1272 return NULL;
1273 _rv = as_TE(h);
1274 _res = Py_BuildValue("O&",
1275 TEObj_New, _rv);
1276 return _res;
1279 static PyMethodDef TE_methods[] = {
1280 {"TEScrapHandle", (PyCFunction)TE_TEScrapHandle, 1,
1281 PyDoc_STR("() -> (Handle _rv)")},
1282 {"TEGetScrapLength", (PyCFunction)TE_TEGetScrapLength, 1,
1283 PyDoc_STR("() -> (long _rv)")},
1284 {"TENew", (PyCFunction)TE_TENew, 1,
1285 PyDoc_STR("(Rect destRect, Rect viewRect) -> (TEHandle _rv)")},
1286 {"TETextBox", (PyCFunction)TE_TETextBox, 1,
1287 PyDoc_STR("(Buffer text, Rect box, short just) -> None")},
1288 {"TEStyleNew", (PyCFunction)TE_TEStyleNew, 1,
1289 PyDoc_STR("(Rect destRect, Rect viewRect) -> (TEHandle _rv)")},
1290 {"TESetScrapLength", (PyCFunction)TE_TESetScrapLength, 1,
1291 PyDoc_STR("(long length) -> None")},
1292 {"TEFromScrap", (PyCFunction)TE_TEFromScrap, 1,
1293 PyDoc_STR("() -> None")},
1294 {"TEToScrap", (PyCFunction)TE_TEToScrap, 1,
1295 PyDoc_STR("() -> None")},
1296 {"TEGetScrapHandle", (PyCFunction)TE_TEGetScrapHandle, 1,
1297 PyDoc_STR("() -> (Handle _rv)")},
1298 {"TESetScrapHandle", (PyCFunction)TE_TESetScrapHandle, 1,
1299 PyDoc_STR("(Handle value) -> None")},
1300 {"LMGetWordRedraw", (PyCFunction)TE_LMGetWordRedraw, 1,
1301 PyDoc_STR("() -> (UInt8 _rv)")},
1302 {"LMSetWordRedraw", (PyCFunction)TE_LMSetWordRedraw, 1,
1303 PyDoc_STR("(UInt8 value) -> None")},
1304 {"as_TE", (PyCFunction)TE_as_TE, 1,
1305 PyDoc_STR("(Handle h) -> (TEHandle _rv)")},
1306 {NULL, NULL, 0}
1312 void init_TE(void)
1314 PyObject *m;
1315 PyObject *d;
1319 PyMac_INIT_TOOLBOX_OBJECT_NEW(TEHandle, TEObj_New);
1320 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(TEHandle, TEObj_Convert);
1323 m = Py_InitModule("_TE", TE_methods);
1324 d = PyModule_GetDict(m);
1325 TE_Error = PyMac_GetOSErrException();
1326 if (TE_Error == NULL ||
1327 PyDict_SetItemString(d, "Error", TE_Error) != 0)
1328 return;
1329 TE_Type.ob_type = &PyType_Type;
1330 if (PyType_Ready(&TE_Type) < 0) return;
1331 Py_INCREF(&TE_Type);
1332 PyModule_AddObject(m, "TE", (PyObject *)&TE_Type);
1333 /* Backward-compatible name */
1334 Py_INCREF(&TE_Type);
1335 PyModule_AddObject(m, "TEType", (PyObject *)&TE_Type);
1338 /* ========================= End module _TE ========================= */