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