blob: 5b6502031f88fda5548b53bbd379260d87c0fc05 [file] [log] [blame]
Jack Jansen8a452d61996-04-10 14:41:08 +00001
2/* =========================== Module TE ============================ */
3
4#include "Python.h"
5
6
7
8#define SystemSevenOrLater 1
9
10#include "macglue.h"
11#include <Memory.h>
12#include <Dialogs.h>
13#include <Menus.h>
14#include <Controls.h>
15
16extern PyObject *ResObj_New(Handle);
17extern int ResObj_Convert(PyObject *, Handle *);
18extern PyObject *OptResObj_New(Handle);
19extern int OptResObj_Convert(PyObject *, Handle *);
20
21extern PyObject *WinObj_New(WindowPtr);
22extern int WinObj_Convert(PyObject *, WindowPtr *);
23extern PyTypeObject Window_Type;
24#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
25
26extern PyObject *DlgObj_New(DialogPtr);
27extern int DlgObj_Convert(PyObject *, DialogPtr *);
28extern PyTypeObject Dialog_Type;
29#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
30
31extern PyObject *MenuObj_New(MenuHandle);
32extern int MenuObj_Convert(PyObject *, MenuHandle *);
33
34extern PyObject *CtlObj_New(ControlHandle);
35extern int CtlObj_Convert(PyObject *, ControlHandle *);
36
37extern PyObject *GrafObj_New(GrafPtr);
38extern int GrafObj_Convert(PyObject *, GrafPtr *);
39
40extern PyObject *BMObj_New(BitMapPtr);
41extern int BMObj_Convert(PyObject *, BitMapPtr *);
42
Jack Jansen8a452d61996-04-10 14:41:08 +000043extern PyObject *WinObj_WhichWindow(WindowPtr);
44
45#include <TextEdit.h>
46
Jack Jansena1a0fef1999-12-23 14:32:06 +000047#define as_TE(h) ((TEHandle)h)
48#define as_Handle(teh) ((Handle)teh)
49
Jack Jansen8a452d61996-04-10 14:41:08 +000050/* Exported by Qdmodule.c: */
51extern PyObject *QdRGB_New(RGBColor *);
52extern int QdRGB_Convert(PyObject *, RGBColor *);
53
54/*
55** Parse/generate TextStyle records
56*/
57PyObject *TextStyle_New(itself)
58 TextStylePtr itself;
59{
60
61 return Py_BuildValue("lllO&", (long)itself->tsFont, (long)itself->tsFace, (long)itself->tsSize, QdRGB_New,
62 &itself->tsColor);
63}
64
65TextStyle_Convert(v, p_itself)
66 PyObject *v;
67 TextStylePtr p_itself;
68{
69 long font, face, size;
70
71 if( !PyArg_ParseTuple(v, "lllO&", &font, &face, &size, QdRGB_Convert, &p_itself->tsColor) )
72 return 0;
73 p_itself->tsFont = (short)font;
74 p_itself->tsFace = (Style)face;
75 p_itself->tsSize = (short)size;
76 return 1;
77}
78
79static PyObject *TE_Error;
80
81/* ------------------------- Object type TE ------------------------- */
82
83PyTypeObject TE_Type;
84
85#define TEObj_Check(x) ((x)->ob_type == &TE_Type)
86
87typedef struct TEObject {
88 PyObject_HEAD
89 TEHandle ob_itself;
90} TEObject;
91
92PyObject *TEObj_New(itself)
93 TEHandle itself;
94{
95 TEObject *it;
96 if (itself == NULL) {
97 PyErr_SetString(TE_Error,"Cannot create null TE");
98 return NULL;
99 }
100 it = PyObject_NEW(TEObject, &TE_Type);
101 if (it == NULL) return NULL;
102 it->ob_itself = itself;
103 return (PyObject *)it;
104}
105TEObj_Convert(v, p_itself)
106 PyObject *v;
107 TEHandle *p_itself;
108{
109 if (!TEObj_Check(v))
110 {
111 PyErr_SetString(PyExc_TypeError, "TE required");
112 return 0;
113 }
114 *p_itself = ((TEObject *)v)->ob_itself;
115 return 1;
116}
117
118static void TEObj_dealloc(self)
119 TEObject *self;
120{
121 TEDispose(self->ob_itself);
122 PyMem_DEL(self);
123}
124
125static PyObject *TEObj_TESetText(_self, _args)
126 TEObject *_self;
127 PyObject *_args;
128{
129 PyObject *_res = NULL;
130 char *text__in__;
131 long text__len__;
132 int text__in_len__;
133 if (!PyArg_ParseTuple(_args, "s#",
134 &text__in__, &text__in_len__))
135 return NULL;
136 text__len__ = text__in_len__;
137 TESetText(text__in__, text__len__,
138 _self->ob_itself);
139 Py_INCREF(Py_None);
140 _res = Py_None;
141 text__error__: ;
142 return _res;
143}
144
145static PyObject *TEObj_TEGetText(_self, _args)
146 TEObject *_self;
147 PyObject *_args;
148{
149 PyObject *_res = NULL;
150 CharsHandle _rv;
151 if (!PyArg_ParseTuple(_args, ""))
152 return NULL;
153 _rv = TEGetText(_self->ob_itself);
154 _res = Py_BuildValue("O&",
155 ResObj_New, _rv);
156 return _res;
157}
158
159static PyObject *TEObj_TEIdle(_self, _args)
160 TEObject *_self;
161 PyObject *_args;
162{
163 PyObject *_res = NULL;
164 if (!PyArg_ParseTuple(_args, ""))
165 return NULL;
166 TEIdle(_self->ob_itself);
167 Py_INCREF(Py_None);
168 _res = Py_None;
169 return _res;
170}
171
172static PyObject *TEObj_TESetSelect(_self, _args)
173 TEObject *_self;
174 PyObject *_args;
175{
176 PyObject *_res = NULL;
177 long selStart;
178 long selEnd;
179 if (!PyArg_ParseTuple(_args, "ll",
180 &selStart,
181 &selEnd))
182 return NULL;
183 TESetSelect(selStart,
184 selEnd,
185 _self->ob_itself);
186 Py_INCREF(Py_None);
187 _res = Py_None;
188 return _res;
189}
190
191static PyObject *TEObj_TEActivate(_self, _args)
192 TEObject *_self;
193 PyObject *_args;
194{
195 PyObject *_res = NULL;
196 if (!PyArg_ParseTuple(_args, ""))
197 return NULL;
198 TEActivate(_self->ob_itself);
199 Py_INCREF(Py_None);
200 _res = Py_None;
201 return _res;
202}
203
204static PyObject *TEObj_TEDeactivate(_self, _args)
205 TEObject *_self;
206 PyObject *_args;
207{
208 PyObject *_res = NULL;
209 if (!PyArg_ParseTuple(_args, ""))
210 return NULL;
211 TEDeactivate(_self->ob_itself);
212 Py_INCREF(Py_None);
213 _res = Py_None;
214 return _res;
215}
216
217static PyObject *TEObj_TEKey(_self, _args)
218 TEObject *_self;
219 PyObject *_args;
220{
221 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000222 CharParameter key;
Jack Jansen0c4d9471998-04-17 14:07:56 +0000223 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen8a452d61996-04-10 14:41:08 +0000224 &key))
225 return NULL;
226 TEKey(key,
227 _self->ob_itself);
228 Py_INCREF(Py_None);
229 _res = Py_None;
230 return _res;
231}
232
233static PyObject *TEObj_TECut(_self, _args)
234 TEObject *_self;
235 PyObject *_args;
236{
237 PyObject *_res = NULL;
238 if (!PyArg_ParseTuple(_args, ""))
239 return NULL;
240 TECut(_self->ob_itself);
241 Py_INCREF(Py_None);
242 _res = Py_None;
243 return _res;
244}
245
246static PyObject *TEObj_TECopy(_self, _args)
247 TEObject *_self;
248 PyObject *_args;
249{
250 PyObject *_res = NULL;
251 if (!PyArg_ParseTuple(_args, ""))
252 return NULL;
253 TECopy(_self->ob_itself);
254 Py_INCREF(Py_None);
255 _res = Py_None;
256 return _res;
257}
258
259static PyObject *TEObj_TEPaste(_self, _args)
260 TEObject *_self;
261 PyObject *_args;
262{
263 PyObject *_res = NULL;
264 if (!PyArg_ParseTuple(_args, ""))
265 return NULL;
266 TEPaste(_self->ob_itself);
267 Py_INCREF(Py_None);
268 _res = Py_None;
269 return _res;
270}
271
272static PyObject *TEObj_TEDelete(_self, _args)
273 TEObject *_self;
274 PyObject *_args;
275{
276 PyObject *_res = NULL;
277 if (!PyArg_ParseTuple(_args, ""))
278 return NULL;
279 TEDelete(_self->ob_itself);
280 Py_INCREF(Py_None);
281 _res = Py_None;
282 return _res;
283}
284
285static PyObject *TEObj_TEInsert(_self, _args)
286 TEObject *_self;
287 PyObject *_args;
288{
289 PyObject *_res = NULL;
290 char *text__in__;
291 long text__len__;
292 int text__in_len__;
293 if (!PyArg_ParseTuple(_args, "s#",
294 &text__in__, &text__in_len__))
295 return NULL;
296 text__len__ = text__in_len__;
297 TEInsert(text__in__, text__len__,
298 _self->ob_itself);
299 Py_INCREF(Py_None);
300 _res = Py_None;
301 text__error__: ;
302 return _res;
303}
304
305static PyObject *TEObj_TESetAlignment(_self, _args)
306 TEObject *_self;
307 PyObject *_args;
308{
309 PyObject *_res = NULL;
310 short just;
311 if (!PyArg_ParseTuple(_args, "h",
312 &just))
313 return NULL;
314 TESetAlignment(just,
315 _self->ob_itself);
316 Py_INCREF(Py_None);
317 _res = Py_None;
318 return _res;
319}
320
321static PyObject *TEObj_TEUpdate(_self, _args)
322 TEObject *_self;
323 PyObject *_args;
324{
325 PyObject *_res = NULL;
326 Rect rUpdate;
327 if (!PyArg_ParseTuple(_args, "O&",
328 PyMac_GetRect, &rUpdate))
329 return NULL;
330 TEUpdate(&rUpdate,
331 _self->ob_itself);
332 Py_INCREF(Py_None);
333 _res = Py_None;
334 return _res;
335}
336
337static PyObject *TEObj_TEScroll(_self, _args)
338 TEObject *_self;
339 PyObject *_args;
340{
341 PyObject *_res = NULL;
342 short dh;
343 short dv;
344 if (!PyArg_ParseTuple(_args, "hh",
345 &dh,
346 &dv))
347 return NULL;
348 TEScroll(dh,
349 dv,
350 _self->ob_itself);
351 Py_INCREF(Py_None);
352 _res = Py_None;
353 return _res;
354}
355
356static PyObject *TEObj_TESelView(_self, _args)
357 TEObject *_self;
358 PyObject *_args;
359{
360 PyObject *_res = NULL;
361 if (!PyArg_ParseTuple(_args, ""))
362 return NULL;
363 TESelView(_self->ob_itself);
364 Py_INCREF(Py_None);
365 _res = Py_None;
366 return _res;
367}
368
369static PyObject *TEObj_TEPinScroll(_self, _args)
370 TEObject *_self;
371 PyObject *_args;
372{
373 PyObject *_res = NULL;
374 short dh;
375 short dv;
376 if (!PyArg_ParseTuple(_args, "hh",
377 &dh,
378 &dv))
379 return NULL;
380 TEPinScroll(dh,
381 dv,
382 _self->ob_itself);
383 Py_INCREF(Py_None);
384 _res = Py_None;
385 return _res;
386}
387
388static PyObject *TEObj_TEAutoView(_self, _args)
389 TEObject *_self;
390 PyObject *_args;
391{
392 PyObject *_res = NULL;
393 Boolean fAuto;
394 if (!PyArg_ParseTuple(_args, "b",
395 &fAuto))
396 return NULL;
397 TEAutoView(fAuto,
398 _self->ob_itself);
399 Py_INCREF(Py_None);
400 _res = Py_None;
401 return _res;
402}
403
404static PyObject *TEObj_TECalText(_self, _args)
405 TEObject *_self;
406 PyObject *_args;
407{
408 PyObject *_res = NULL;
409 if (!PyArg_ParseTuple(_args, ""))
410 return NULL;
411 TECalText(_self->ob_itself);
412 Py_INCREF(Py_None);
413 _res = Py_None;
414 return _res;
415}
416
417static PyObject *TEObj_TEGetOffset(_self, _args)
418 TEObject *_self;
419 PyObject *_args;
420{
421 PyObject *_res = NULL;
422 short _rv;
423 Point pt;
424 if (!PyArg_ParseTuple(_args, "O&",
425 PyMac_GetPoint, &pt))
426 return NULL;
427 _rv = TEGetOffset(pt,
428 _self->ob_itself);
429 _res = Py_BuildValue("h",
430 _rv);
431 return _res;
432}
433
434static PyObject *TEObj_TEGetPoint(_self, _args)
435 TEObject *_self;
436 PyObject *_args;
437{
438 PyObject *_res = NULL;
439 Point _rv;
440 short offset;
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;
449}
450
451static PyObject *TEObj_TEClick(_self, _args)
452 TEObject *_self;
453 PyObject *_args;
454{
455 PyObject *_res = NULL;
456 Point pt;
457 Boolean fExtend;
458 if (!PyArg_ParseTuple(_args, "O&b",
459 PyMac_GetPoint, &pt,
460 &fExtend))
461 return NULL;
462 TEClick(pt,
463 fExtend,
464 _self->ob_itself);
465 Py_INCREF(Py_None);
466 _res = Py_None;
467 return _res;
468}
469
470static PyObject *TEObj_TESetStyleHandle(_self, _args)
471 TEObject *_self;
472 PyObject *_args;
473{
474 PyObject *_res = NULL;
475 TEStyleHandle theHandle;
476 if (!PyArg_ParseTuple(_args, "O&",
477 ResObj_Convert, &theHandle))
478 return NULL;
479 TESetStyleHandle(theHandle,
480 _self->ob_itself);
481 Py_INCREF(Py_None);
482 _res = Py_None;
483 return _res;
484}
485
486static PyObject *TEObj_TEGetStyleHandle(_self, _args)
487 TEObject *_self;
488 PyObject *_args;
489{
490 PyObject *_res = NULL;
491 TEStyleHandle _rv;
492 if (!PyArg_ParseTuple(_args, ""))
493 return NULL;
494 _rv = TEGetStyleHandle(_self->ob_itself);
495 _res = Py_BuildValue("O&",
496 ResObj_New, _rv);
497 return _res;
498}
499
500static PyObject *TEObj_TEGetStyle(_self, _args)
501 TEObject *_self;
502 PyObject *_args;
503{
504 PyObject *_res = NULL;
505 short offset;
506 TextStyle theStyle;
507 short lineHeight;
508 short fontAscent;
509 if (!PyArg_ParseTuple(_args, "h",
510 &offset))
511 return NULL;
512 TEGetStyle(offset,
513 &theStyle,
514 &lineHeight,
515 &fontAscent,
516 _self->ob_itself);
517 _res = Py_BuildValue("O&hh",
518 TextStyle_New, &theStyle,
519 lineHeight,
520 fontAscent);
521 return _res;
522}
523
524static PyObject *TEObj_TEStylePaste(_self, _args)
525 TEObject *_self;
526 PyObject *_args;
527{
528 PyObject *_res = NULL;
529 if (!PyArg_ParseTuple(_args, ""))
530 return NULL;
531 TEStylePaste(_self->ob_itself);
532 Py_INCREF(Py_None);
533 _res = Py_None;
534 return _res;
535}
536
537static PyObject *TEObj_TESetStyle(_self, _args)
538 TEObject *_self;
539 PyObject *_args;
540{
541 PyObject *_res = NULL;
542 short mode;
543 TextStyle newStyle;
544 Boolean fRedraw;
545 if (!PyArg_ParseTuple(_args, "hO&b",
546 &mode,
547 TextStyle_Convert, &newStyle,
548 &fRedraw))
549 return NULL;
550 TESetStyle(mode,
551 &newStyle,
552 fRedraw,
553 _self->ob_itself);
554 Py_INCREF(Py_None);
555 _res = Py_None;
556 return _res;
557}
558
559static PyObject *TEObj_TEReplaceStyle(_self, _args)
560 TEObject *_self;
561 PyObject *_args;
562{
563 PyObject *_res = NULL;
564 short mode;
565 TextStyle oldStyle;
566 TextStyle newStyle;
567 Boolean fRedraw;
568 if (!PyArg_ParseTuple(_args, "hO&O&b",
569 &mode,
570 TextStyle_Convert, &oldStyle,
571 TextStyle_Convert, &newStyle,
572 &fRedraw))
573 return NULL;
574 TEReplaceStyle(mode,
575 &oldStyle,
576 &newStyle,
577 fRedraw,
578 _self->ob_itself);
579 Py_INCREF(Py_None);
580 _res = Py_None;
581 return _res;
582}
583
584static PyObject *TEObj_TEGetStyleScrapHandle(_self, _args)
585 TEObject *_self;
586 PyObject *_args;
587{
588 PyObject *_res = NULL;
589 StScrpHandle _rv;
590 if (!PyArg_ParseTuple(_args, ""))
591 return NULL;
592 _rv = TEGetStyleScrapHandle(_self->ob_itself);
593 _res = Py_BuildValue("O&",
594 ResObj_New, _rv);
595 return _res;
596}
597
598static PyObject *TEObj_TEStyleInsert(_self, _args)
599 TEObject *_self;
600 PyObject *_args;
601{
602 PyObject *_res = NULL;
603 char *text__in__;
604 long text__len__;
605 int text__in_len__;
606 StScrpHandle hST;
607 if (!PyArg_ParseTuple(_args, "s#O&",
608 &text__in__, &text__in_len__,
609 ResObj_Convert, &hST))
610 return NULL;
611 text__len__ = text__in_len__;
612 TEStyleInsert(text__in__, text__len__,
613 hST,
614 _self->ob_itself);
615 Py_INCREF(Py_None);
616 _res = Py_None;
617 text__error__: ;
618 return _res;
619}
620
621static PyObject *TEObj_TEGetHeight(_self, _args)
622 TEObject *_self;
623 PyObject *_args;
624{
625 PyObject *_res = NULL;
626 long _rv;
627 long endLine;
628 long startLine;
629 if (!PyArg_ParseTuple(_args, "ll",
630 &endLine,
631 &startLine))
632 return NULL;
633 _rv = TEGetHeight(endLine,
634 startLine,
635 _self->ob_itself);
636 _res = Py_BuildValue("l",
637 _rv);
638 return _res;
639}
640
641static PyObject *TEObj_TEContinuousStyle(_self, _args)
642 TEObject *_self;
643 PyObject *_args;
644{
645 PyObject *_res = NULL;
646 Boolean _rv;
647 short mode;
648 TextStyle aStyle;
649 if (!PyArg_ParseTuple(_args, "hO&",
650 &mode,
651 TextStyle_Convert, &aStyle))
652 return NULL;
653 _rv = TEContinuousStyle(&mode,
654 &aStyle,
655 _self->ob_itself);
656 _res = Py_BuildValue("bhO&",
657 _rv,
658 mode,
659 TextStyle_New, &aStyle);
660 return _res;
661}
662
663static PyObject *TEObj_TEUseStyleScrap(_self, _args)
664 TEObject *_self;
665 PyObject *_args;
666{
667 PyObject *_res = NULL;
668 long rangeStart;
669 long rangeEnd;
670 StScrpHandle newStyles;
671 Boolean fRedraw;
672 if (!PyArg_ParseTuple(_args, "llO&b",
673 &rangeStart,
674 &rangeEnd,
675 ResObj_Convert, &newStyles,
676 &fRedraw))
677 return NULL;
678 TEUseStyleScrap(rangeStart,
679 rangeEnd,
680 newStyles,
681 fRedraw,
682 _self->ob_itself);
683 Py_INCREF(Py_None);
684 _res = Py_None;
685 return _res;
686}
687
688static PyObject *TEObj_TENumStyles(_self, _args)
689 TEObject *_self;
690 PyObject *_args;
691{
692 PyObject *_res = NULL;
693 long _rv;
694 long rangeStart;
695 long rangeEnd;
696 if (!PyArg_ParseTuple(_args, "ll",
697 &rangeStart,
698 &rangeEnd))
699 return NULL;
700 _rv = TENumStyles(rangeStart,
701 rangeEnd,
702 _self->ob_itself);
703 _res = Py_BuildValue("l",
704 _rv);
705 return _res;
706}
707
708static PyObject *TEObj_TEFeatureFlag(_self, _args)
709 TEObject *_self;
710 PyObject *_args;
711{
712 PyObject *_res = NULL;
713 short _rv;
714 short feature;
715 short action;
716 if (!PyArg_ParseTuple(_args, "hh",
717 &feature,
718 &action))
719 return NULL;
720 _rv = TEFeatureFlag(feature,
721 action,
722 _self->ob_itself);
723 _res = Py_BuildValue("h",
724 _rv);
725 return _res;
726}
727
Jack Jansena05ac601999-12-12 21:41:51 +0000728static PyObject *TEObj_TEGetHiliteRgn(_self, _args)
729 TEObject *_self;
730 PyObject *_args;
731{
732 PyObject *_res = NULL;
733 OSErr _err;
734 RgnHandle region;
735 if (!PyArg_ParseTuple(_args, "O&",
736 ResObj_Convert, &region))
737 return NULL;
738 _err = TEGetHiliteRgn(region,
739 _self->ob_itself);
740 if (_err != noErr) return PyMac_Error(_err);
741 Py_INCREF(Py_None);
742 _res = Py_None;
743 return _res;
744}
745
Jack Jansena1a0fef1999-12-23 14:32:06 +0000746static PyObject *TEObj_as_Handle(_self, _args)
747 TEObject *_self;
748 PyObject *_args;
749{
750 PyObject *_res = NULL;
751 Handle _rv;
752 if (!PyArg_ParseTuple(_args, ""))
753 return NULL;
754 _rv = as_Handle(_self->ob_itself);
755 _res = Py_BuildValue("O&",
756 ResObj_New, _rv);
757 return _res;
758}
759
Jack Jansen8a452d61996-04-10 14:41:08 +0000760static PyMethodDef TEObj_methods[] = {
761 {"TESetText", (PyCFunction)TEObj_TESetText, 1,
762 "(Buffer text) -> None"},
763 {"TEGetText", (PyCFunction)TEObj_TEGetText, 1,
764 "() -> (CharsHandle _rv)"},
765 {"TEIdle", (PyCFunction)TEObj_TEIdle, 1,
766 "() -> None"},
767 {"TESetSelect", (PyCFunction)TEObj_TESetSelect, 1,
768 "(long selStart, long selEnd) -> None"},
769 {"TEActivate", (PyCFunction)TEObj_TEActivate, 1,
770 "() -> None"},
771 {"TEDeactivate", (PyCFunction)TEObj_TEDeactivate, 1,
772 "() -> None"},
773 {"TEKey", (PyCFunction)TEObj_TEKey, 1,
Jack Jansen21f96871998-02-20 16:02:09 +0000774 "(CharParameter key) -> None"},
Jack Jansen8a452d61996-04-10 14:41:08 +0000775 {"TECut", (PyCFunction)TEObj_TECut, 1,
776 "() -> None"},
777 {"TECopy", (PyCFunction)TEObj_TECopy, 1,
778 "() -> None"},
779 {"TEPaste", (PyCFunction)TEObj_TEPaste, 1,
780 "() -> None"},
781 {"TEDelete", (PyCFunction)TEObj_TEDelete, 1,
782 "() -> None"},
783 {"TEInsert", (PyCFunction)TEObj_TEInsert, 1,
784 "(Buffer text) -> None"},
785 {"TESetAlignment", (PyCFunction)TEObj_TESetAlignment, 1,
786 "(short just) -> None"},
787 {"TEUpdate", (PyCFunction)TEObj_TEUpdate, 1,
788 "(Rect rUpdate) -> None"},
789 {"TEScroll", (PyCFunction)TEObj_TEScroll, 1,
790 "(short dh, short dv) -> None"},
791 {"TESelView", (PyCFunction)TEObj_TESelView, 1,
792 "() -> None"},
793 {"TEPinScroll", (PyCFunction)TEObj_TEPinScroll, 1,
794 "(short dh, short dv) -> None"},
795 {"TEAutoView", (PyCFunction)TEObj_TEAutoView, 1,
796 "(Boolean fAuto) -> None"},
797 {"TECalText", (PyCFunction)TEObj_TECalText, 1,
798 "() -> None"},
799 {"TEGetOffset", (PyCFunction)TEObj_TEGetOffset, 1,
800 "(Point pt) -> (short _rv)"},
801 {"TEGetPoint", (PyCFunction)TEObj_TEGetPoint, 1,
802 "(short offset) -> (Point _rv)"},
803 {"TEClick", (PyCFunction)TEObj_TEClick, 1,
804 "(Point pt, Boolean fExtend) -> None"},
805 {"TESetStyleHandle", (PyCFunction)TEObj_TESetStyleHandle, 1,
806 "(TEStyleHandle theHandle) -> None"},
807 {"TEGetStyleHandle", (PyCFunction)TEObj_TEGetStyleHandle, 1,
808 "() -> (TEStyleHandle _rv)"},
809 {"TEGetStyle", (PyCFunction)TEObj_TEGetStyle, 1,
810 "(short offset) -> (TextStyle theStyle, short lineHeight, short fontAscent)"},
811 {"TEStylePaste", (PyCFunction)TEObj_TEStylePaste, 1,
812 "() -> None"},
813 {"TESetStyle", (PyCFunction)TEObj_TESetStyle, 1,
814 "(short mode, TextStyle newStyle, Boolean fRedraw) -> None"},
815 {"TEReplaceStyle", (PyCFunction)TEObj_TEReplaceStyle, 1,
816 "(short mode, TextStyle oldStyle, TextStyle newStyle, Boolean fRedraw) -> None"},
817 {"TEGetStyleScrapHandle", (PyCFunction)TEObj_TEGetStyleScrapHandle, 1,
818 "() -> (StScrpHandle _rv)"},
819 {"TEStyleInsert", (PyCFunction)TEObj_TEStyleInsert, 1,
820 "(Buffer text, StScrpHandle hST) -> None"},
821 {"TEGetHeight", (PyCFunction)TEObj_TEGetHeight, 1,
822 "(long endLine, long startLine) -> (long _rv)"},
823 {"TEContinuousStyle", (PyCFunction)TEObj_TEContinuousStyle, 1,
824 "(short mode, TextStyle aStyle) -> (Boolean _rv, short mode, TextStyle aStyle)"},
825 {"TEUseStyleScrap", (PyCFunction)TEObj_TEUseStyleScrap, 1,
826 "(long rangeStart, long rangeEnd, StScrpHandle newStyles, Boolean fRedraw) -> None"},
827 {"TENumStyles", (PyCFunction)TEObj_TENumStyles, 1,
828 "(long rangeStart, long rangeEnd) -> (long _rv)"},
829 {"TEFeatureFlag", (PyCFunction)TEObj_TEFeatureFlag, 1,
830 "(short feature, short action) -> (short _rv)"},
Jack Jansena05ac601999-12-12 21:41:51 +0000831 {"TEGetHiliteRgn", (PyCFunction)TEObj_TEGetHiliteRgn, 1,
832 "(RgnHandle region) -> None"},
Jack Jansena1a0fef1999-12-23 14:32:06 +0000833 {"as_Handle", (PyCFunction)TEObj_as_Handle, 1,
834 "() -> (Handle _rv)"},
Jack Jansen8a452d61996-04-10 14:41:08 +0000835 {NULL, NULL, 0}
836};
837
838PyMethodChain TEObj_chain = { TEObj_methods, NULL };
839
840static PyObject *TEObj_getattr(self, name)
841 TEObject *self;
842 char *name;
843{
Jack Jansen46d9e791996-04-12 16:29:23 +0000844
845 if( strcmp(name, "destRect") == 0 )
846 return Py_BuildValue("O&", PyMac_BuildRect,
Jack Jansen19171a21996-04-16 14:32:01 +0000847 &(*self->ob_itself)->destRect);
Jack Jansen46d9e791996-04-12 16:29:23 +0000848 if( strcmp(name, "viewRect") == 0 )
849 return Py_BuildValue("O&", PyMac_BuildRect,
Jack Jansen19171a21996-04-16 14:32:01 +0000850 &(*self->ob_itself)->viewRect);
Jack Jansen46d9e791996-04-12 16:29:23 +0000851 if( strcmp(name, "selRect") == 0 )
852 return Py_BuildValue("O&", PyMac_BuildRect,
Jack Jansen19171a21996-04-16 14:32:01 +0000853 &(*self->ob_itself)->selRect);
Jack Jansen46d9e791996-04-12 16:29:23 +0000854 if( strcmp(name, "lineHeight") == 0 )
855 return Py_BuildValue("h", (*self->ob_itself)->lineHeight);
856 if( strcmp(name, "fontAscent") == 0 )
857 return Py_BuildValue("h", (*self->ob_itself)->fontAscent);
858 if( strcmp(name, "selPoint") == 0 )
859 return Py_BuildValue("O&", PyMac_BuildPoint,
Jack Jansen19171a21996-04-16 14:32:01 +0000860 &(*self->ob_itself)->selPoint);
Jack Jansen46d9e791996-04-12 16:29:23 +0000861 if( strcmp(name, "selStart") == 0 )
862 return Py_BuildValue("h", (*self->ob_itself)->selStart);
863 if( strcmp(name, "selEnd") == 0 )
864 return Py_BuildValue("h", (*self->ob_itself)->selEnd);
865 if( strcmp(name, "active") == 0 )
866 return Py_BuildValue("h", (*self->ob_itself)->active);
Jack Jansen19171a21996-04-16 14:32:01 +0000867 if( strcmp(name, "just") == 0 )
868 return Py_BuildValue("h", (*self->ob_itself)->just);
Jack Jansen46d9e791996-04-12 16:29:23 +0000869 if( strcmp(name, "teLength") == 0 )
870 return Py_BuildValue("h", (*self->ob_itself)->teLength);
Jack Jansen19171a21996-04-16 14:32:01 +0000871 if( strcmp(name, "txFont") == 0 )
872 return Py_BuildValue("h", (*self->ob_itself)->txFont);
873 if( strcmp(name, "txFace") == 0 )
874 return Py_BuildValue("h", (*self->ob_itself)->txFace);
875 if( strcmp(name, "txMode") == 0 )
876 return Py_BuildValue("h", (*self->ob_itself)->txMode);
877 if( strcmp(name, "txSize") == 0 )
878 return Py_BuildValue("h", (*self->ob_itself)->txSize);
879 if( strcmp(name, "nLines") == 0 )
880 return Py_BuildValue("h", (*self->ob_itself)->nLines);
Jack Jansen46d9e791996-04-12 16:29:23 +0000881
Jack Jansen8a452d61996-04-10 14:41:08 +0000882 return Py_FindMethodInChain(&TEObj_chain, (PyObject *)self, name);
883}
884
885#define TEObj_setattr NULL
886
Jack Jansena05ac601999-12-12 21:41:51 +0000887#define TEObj_compare NULL
888
889#define TEObj_repr NULL
890
891#define TEObj_hash NULL
892
Jack Jansen8a452d61996-04-10 14:41:08 +0000893PyTypeObject TE_Type = {
894 PyObject_HEAD_INIT(&PyType_Type)
895 0, /*ob_size*/
896 "TE", /*tp_name*/
897 sizeof(TEObject), /*tp_basicsize*/
898 0, /*tp_itemsize*/
899 /* methods */
900 (destructor) TEObj_dealloc, /*tp_dealloc*/
901 0, /*tp_print*/
902 (getattrfunc) TEObj_getattr, /*tp_getattr*/
903 (setattrfunc) TEObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000904 (cmpfunc) TEObj_compare, /*tp_compare*/
905 (reprfunc) TEObj_repr, /*tp_repr*/
906 (PyNumberMethods *)0, /* tp_as_number */
907 (PySequenceMethods *)0, /* tp_as_sequence */
908 (PyMappingMethods *)0, /* tp_as_mapping */
909 (hashfunc) TEObj_hash, /*tp_hash*/
Jack Jansen8a452d61996-04-10 14:41:08 +0000910};
911
912/* ----------------------- End object type TE ----------------------- */
913
914
915static PyObject *TE_TEScrapHandle(_self, _args)
916 PyObject *_self;
917 PyObject *_args;
918{
919 PyObject *_res = NULL;
920 Handle _rv;
921 if (!PyArg_ParseTuple(_args, ""))
922 return NULL;
923 _rv = TEScrapHandle();
924 _res = Py_BuildValue("O&",
925 ResObj_New, _rv);
926 return _res;
927}
928
929static PyObject *TE_TEGetScrapLength(_self, _args)
930 PyObject *_self;
931 PyObject *_args;
932{
933 PyObject *_res = NULL;
934 long _rv;
935 if (!PyArg_ParseTuple(_args, ""))
936 return NULL;
937 _rv = TEGetScrapLength();
938 _res = Py_BuildValue("l",
939 _rv);
940 return _res;
941}
942
943static PyObject *TE_TENew(_self, _args)
944 PyObject *_self;
945 PyObject *_args;
946{
947 PyObject *_res = NULL;
948 TEHandle _rv;
949 Rect destRect;
950 Rect viewRect;
951 if (!PyArg_ParseTuple(_args, "O&O&",
952 PyMac_GetRect, &destRect,
953 PyMac_GetRect, &viewRect))
954 return NULL;
955 _rv = TENew(&destRect,
956 &viewRect);
957 _res = Py_BuildValue("O&",
958 TEObj_New, _rv);
959 return _res;
960}
961
962static PyObject *TE_TETextBox(_self, _args)
963 PyObject *_self;
964 PyObject *_args;
965{
966 PyObject *_res = NULL;
967 char *text__in__;
968 long text__len__;
969 int text__in_len__;
970 Rect box;
971 short just;
972 if (!PyArg_ParseTuple(_args, "s#O&h",
973 &text__in__, &text__in_len__,
974 PyMac_GetRect, &box,
975 &just))
976 return NULL;
977 text__len__ = text__in_len__;
978 TETextBox(text__in__, text__len__,
979 &box,
980 just);
981 Py_INCREF(Py_None);
982 _res = Py_None;
983 text__error__: ;
984 return _res;
985}
986
987static PyObject *TE_TEStyleNew(_self, _args)
988 PyObject *_self;
989 PyObject *_args;
990{
991 PyObject *_res = NULL;
992 TEHandle _rv;
993 Rect destRect;
994 Rect viewRect;
995 if (!PyArg_ParseTuple(_args, "O&O&",
996 PyMac_GetRect, &destRect,
997 PyMac_GetRect, &viewRect))
998 return NULL;
999 _rv = TEStyleNew(&destRect,
1000 &viewRect);
1001 _res = Py_BuildValue("O&",
1002 TEObj_New, _rv);
1003 return _res;
1004}
1005
1006static PyObject *TE_TESetScrapLength(_self, _args)
1007 PyObject *_self;
1008 PyObject *_args;
1009{
1010 PyObject *_res = NULL;
1011 long length;
1012 if (!PyArg_ParseTuple(_args, "l",
1013 &length))
1014 return NULL;
1015 TESetScrapLength(length);
1016 Py_INCREF(Py_None);
1017 _res = Py_None;
1018 return _res;
1019}
1020
1021static PyObject *TE_TEFromScrap(_self, _args)
1022 PyObject *_self;
1023 PyObject *_args;
1024{
1025 PyObject *_res = NULL;
1026 OSErr _err;
1027 if (!PyArg_ParseTuple(_args, ""))
1028 return NULL;
1029 _err = TEFromScrap();
1030 if (_err != noErr) return PyMac_Error(_err);
1031 Py_INCREF(Py_None);
1032 _res = Py_None;
1033 return _res;
1034}
1035
1036static PyObject *TE_TEToScrap(_self, _args)
1037 PyObject *_self;
1038 PyObject *_args;
1039{
1040 PyObject *_res = NULL;
1041 OSErr _err;
1042 if (!PyArg_ParseTuple(_args, ""))
1043 return NULL;
1044 _err = TEToScrap();
1045 if (_err != noErr) return PyMac_Error(_err);
1046 Py_INCREF(Py_None);
1047 _res = Py_None;
1048 return _res;
1049}
1050
Jack Jansena1a0fef1999-12-23 14:32:06 +00001051static PyObject *TE_as_TE(_self, _args)
1052 PyObject *_self;
1053 PyObject *_args;
1054{
1055 PyObject *_res = NULL;
1056 TEHandle _rv;
1057 Handle h;
1058 if (!PyArg_ParseTuple(_args, "O&",
1059 ResObj_Convert, &h))
1060 return NULL;
1061 _rv = as_TE(h);
1062 _res = Py_BuildValue("O&",
1063 TEObj_New, _rv);
1064 return _res;
1065}
1066
Jack Jansen8a452d61996-04-10 14:41:08 +00001067static PyMethodDef TE_methods[] = {
1068 {"TEScrapHandle", (PyCFunction)TE_TEScrapHandle, 1,
1069 "() -> (Handle _rv)"},
1070 {"TEGetScrapLength", (PyCFunction)TE_TEGetScrapLength, 1,
1071 "() -> (long _rv)"},
1072 {"TENew", (PyCFunction)TE_TENew, 1,
1073 "(Rect destRect, Rect viewRect) -> (TEHandle _rv)"},
1074 {"TETextBox", (PyCFunction)TE_TETextBox, 1,
1075 "(Buffer text, Rect box, short just) -> None"},
1076 {"TEStyleNew", (PyCFunction)TE_TEStyleNew, 1,
1077 "(Rect destRect, Rect viewRect) -> (TEHandle _rv)"},
1078 {"TESetScrapLength", (PyCFunction)TE_TESetScrapLength, 1,
1079 "(long length) -> None"},
1080 {"TEFromScrap", (PyCFunction)TE_TEFromScrap, 1,
1081 "() -> None"},
1082 {"TEToScrap", (PyCFunction)TE_TEToScrap, 1,
1083 "() -> None"},
Jack Jansena1a0fef1999-12-23 14:32:06 +00001084 {"as_TE", (PyCFunction)TE_as_TE, 1,
1085 "(Handle h) -> (TEHandle _rv)"},
Jack Jansen8a452d61996-04-10 14:41:08 +00001086 {NULL, NULL, 0}
1087};
1088
1089
1090
1091
1092void initTE()
1093{
1094 PyObject *m;
1095 PyObject *d;
1096
1097
1098
1099
1100 m = Py_InitModule("TE", TE_methods);
1101 d = PyModule_GetDict(m);
1102 TE_Error = PyMac_GetOSErrException();
1103 if (TE_Error == NULL ||
1104 PyDict_SetItemString(d, "Error", TE_Error) != 0)
1105 Py_FatalError("can't initialize TE.Error");
Jack Jansena755e681997-09-20 17:40:22 +00001106 TE_Type.ob_type = &PyType_Type;
1107 Py_INCREF(&TE_Type);
1108 if (PyDict_SetItemString(d, "TEType", (PyObject *)&TE_Type) != 0)
1109 Py_FatalError("can't initialize TEType");
Jack Jansen8a452d61996-04-10 14:41:08 +00001110}
1111
1112/* ========================= End module TE ========================== */
1113