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