Jack Jansen | 8a452d6 | 1996-04-10 14:41:08 +0000 | [diff] [blame] | 1 | |
| 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 | |
| 16 | extern PyObject *ResObj_New(Handle); |
| 17 | extern int ResObj_Convert(PyObject *, Handle *); |
| 18 | extern PyObject *OptResObj_New(Handle); |
| 19 | extern int OptResObj_Convert(PyObject *, Handle *); |
| 20 | |
| 21 | extern PyObject *WinObj_New(WindowPtr); |
| 22 | extern int WinObj_Convert(PyObject *, WindowPtr *); |
| 23 | extern PyTypeObject Window_Type; |
| 24 | #define WinObj_Check(x) ((x)->ob_type == &Window_Type) |
| 25 | |
| 26 | extern PyObject *DlgObj_New(DialogPtr); |
| 27 | extern int DlgObj_Convert(PyObject *, DialogPtr *); |
| 28 | extern PyTypeObject Dialog_Type; |
| 29 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 30 | |
| 31 | extern PyObject *MenuObj_New(MenuHandle); |
| 32 | extern int MenuObj_Convert(PyObject *, MenuHandle *); |
| 33 | |
| 34 | extern PyObject *CtlObj_New(ControlHandle); |
| 35 | extern int CtlObj_Convert(PyObject *, ControlHandle *); |
| 36 | |
| 37 | extern PyObject *GrafObj_New(GrafPtr); |
| 38 | extern int GrafObj_Convert(PyObject *, GrafPtr *); |
| 39 | |
| 40 | extern PyObject *BMObj_New(BitMapPtr); |
| 41 | extern int BMObj_Convert(PyObject *, BitMapPtr *); |
| 42 | |
| 43 | extern PyObject *PMObj_New(PixMapHandle); |
| 44 | extern int PMObj_Convert(PyObject *, PixMapHandle *); |
| 45 | |
| 46 | extern PyObject *WinObj_WhichWindow(WindowPtr); |
| 47 | |
| 48 | #include <TextEdit.h> |
| 49 | |
| 50 | /* Exported by Qdmodule.c: */ |
| 51 | extern PyObject *QdRGB_New(RGBColor *); |
| 52 | extern int QdRGB_Convert(PyObject *, RGBColor *); |
| 53 | |
| 54 | /* |
| 55 | ** Parse/generate TextStyle records |
| 56 | */ |
| 57 | PyObject *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 | |
| 65 | TextStyle_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 | |
| 79 | static PyObject *TE_Error; |
| 80 | |
| 81 | /* ------------------------- Object type TE ------------------------- */ |
| 82 | |
| 83 | PyTypeObject TE_Type; |
| 84 | |
| 85 | #define TEObj_Check(x) ((x)->ob_type == &TE_Type) |
| 86 | |
| 87 | typedef struct TEObject { |
| 88 | PyObject_HEAD |
| 89 | TEHandle ob_itself; |
| 90 | } TEObject; |
| 91 | |
| 92 | PyObject *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 | } |
| 105 | TEObj_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 | |
| 118 | static void TEObj_dealloc(self) |
| 119 | TEObject *self; |
| 120 | { |
| 121 | TEDispose(self->ob_itself); |
| 122 | PyMem_DEL(self); |
| 123 | } |
| 124 | |
| 125 | static 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 | |
| 145 | static 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 | |
| 159 | static 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 | |
| 172 | static 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 | |
| 191 | static 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 | |
| 204 | static 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 | |
| 217 | static PyObject *TEObj_TEKey(_self, _args) |
| 218 | TEObject *_self; |
| 219 | PyObject *_args; |
| 220 | { |
| 221 | PyObject *_res = NULL; |
| 222 | short key; |
| 223 | if (!PyArg_ParseTuple(_args, "h", |
| 224 | &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 | |
| 233 | static 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 | |
| 246 | static 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 | |
| 259 | static 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 | |
| 272 | static 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 | |
| 285 | static 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 | |
| 305 | static 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 | |
| 321 | static 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 | |
| 337 | static 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 | |
| 356 | static 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 | |
| 369 | static 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 | |
| 388 | static 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 | |
| 404 | static 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 | |
| 417 | static 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 | |
| 434 | static 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 | |
| 451 | static 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 | |
| 470 | static 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 | |
| 486 | static 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 | |
| 500 | static 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 | |
| 524 | static 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 | |
| 537 | static 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 | |
| 559 | static 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 | |
| 584 | static 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 | |
| 598 | static 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 | |
| 621 | static 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 | |
| 641 | static 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 | |
| 663 | static 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 | |
| 688 | static 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 | |
| 708 | static 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 | |
| 728 | static PyMethodDef TEObj_methods[] = { |
| 729 | {"TESetText", (PyCFunction)TEObj_TESetText, 1, |
| 730 | "(Buffer text) -> None"}, |
| 731 | {"TEGetText", (PyCFunction)TEObj_TEGetText, 1, |
| 732 | "() -> (CharsHandle _rv)"}, |
| 733 | {"TEIdle", (PyCFunction)TEObj_TEIdle, 1, |
| 734 | "() -> None"}, |
| 735 | {"TESetSelect", (PyCFunction)TEObj_TESetSelect, 1, |
| 736 | "(long selStart, long selEnd) -> None"}, |
| 737 | {"TEActivate", (PyCFunction)TEObj_TEActivate, 1, |
| 738 | "() -> None"}, |
| 739 | {"TEDeactivate", (PyCFunction)TEObj_TEDeactivate, 1, |
| 740 | "() -> None"}, |
| 741 | {"TEKey", (PyCFunction)TEObj_TEKey, 1, |
| 742 | "(short key) -> None"}, |
| 743 | {"TECut", (PyCFunction)TEObj_TECut, 1, |
| 744 | "() -> None"}, |
| 745 | {"TECopy", (PyCFunction)TEObj_TECopy, 1, |
| 746 | "() -> None"}, |
| 747 | {"TEPaste", (PyCFunction)TEObj_TEPaste, 1, |
| 748 | "() -> None"}, |
| 749 | {"TEDelete", (PyCFunction)TEObj_TEDelete, 1, |
| 750 | "() -> None"}, |
| 751 | {"TEInsert", (PyCFunction)TEObj_TEInsert, 1, |
| 752 | "(Buffer text) -> None"}, |
| 753 | {"TESetAlignment", (PyCFunction)TEObj_TESetAlignment, 1, |
| 754 | "(short just) -> None"}, |
| 755 | {"TEUpdate", (PyCFunction)TEObj_TEUpdate, 1, |
| 756 | "(Rect rUpdate) -> None"}, |
| 757 | {"TEScroll", (PyCFunction)TEObj_TEScroll, 1, |
| 758 | "(short dh, short dv) -> None"}, |
| 759 | {"TESelView", (PyCFunction)TEObj_TESelView, 1, |
| 760 | "() -> None"}, |
| 761 | {"TEPinScroll", (PyCFunction)TEObj_TEPinScroll, 1, |
| 762 | "(short dh, short dv) -> None"}, |
| 763 | {"TEAutoView", (PyCFunction)TEObj_TEAutoView, 1, |
| 764 | "(Boolean fAuto) -> None"}, |
| 765 | {"TECalText", (PyCFunction)TEObj_TECalText, 1, |
| 766 | "() -> None"}, |
| 767 | {"TEGetOffset", (PyCFunction)TEObj_TEGetOffset, 1, |
| 768 | "(Point pt) -> (short _rv)"}, |
| 769 | {"TEGetPoint", (PyCFunction)TEObj_TEGetPoint, 1, |
| 770 | "(short offset) -> (Point _rv)"}, |
| 771 | {"TEClick", (PyCFunction)TEObj_TEClick, 1, |
| 772 | "(Point pt, Boolean fExtend) -> None"}, |
| 773 | {"TESetStyleHandle", (PyCFunction)TEObj_TESetStyleHandle, 1, |
| 774 | "(TEStyleHandle theHandle) -> None"}, |
| 775 | {"TEGetStyleHandle", (PyCFunction)TEObj_TEGetStyleHandle, 1, |
| 776 | "() -> (TEStyleHandle _rv)"}, |
| 777 | {"TEGetStyle", (PyCFunction)TEObj_TEGetStyle, 1, |
| 778 | "(short offset) -> (TextStyle theStyle, short lineHeight, short fontAscent)"}, |
| 779 | {"TEStylePaste", (PyCFunction)TEObj_TEStylePaste, 1, |
| 780 | "() -> None"}, |
| 781 | {"TESetStyle", (PyCFunction)TEObj_TESetStyle, 1, |
| 782 | "(short mode, TextStyle newStyle, Boolean fRedraw) -> None"}, |
| 783 | {"TEReplaceStyle", (PyCFunction)TEObj_TEReplaceStyle, 1, |
| 784 | "(short mode, TextStyle oldStyle, TextStyle newStyle, Boolean fRedraw) -> None"}, |
| 785 | {"TEGetStyleScrapHandle", (PyCFunction)TEObj_TEGetStyleScrapHandle, 1, |
| 786 | "() -> (StScrpHandle _rv)"}, |
| 787 | {"TEStyleInsert", (PyCFunction)TEObj_TEStyleInsert, 1, |
| 788 | "(Buffer text, StScrpHandle hST) -> None"}, |
| 789 | {"TEGetHeight", (PyCFunction)TEObj_TEGetHeight, 1, |
| 790 | "(long endLine, long startLine) -> (long _rv)"}, |
| 791 | {"TEContinuousStyle", (PyCFunction)TEObj_TEContinuousStyle, 1, |
| 792 | "(short mode, TextStyle aStyle) -> (Boolean _rv, short mode, TextStyle aStyle)"}, |
| 793 | {"TEUseStyleScrap", (PyCFunction)TEObj_TEUseStyleScrap, 1, |
| 794 | "(long rangeStart, long rangeEnd, StScrpHandle newStyles, Boolean fRedraw) -> None"}, |
| 795 | {"TENumStyles", (PyCFunction)TEObj_TENumStyles, 1, |
| 796 | "(long rangeStart, long rangeEnd) -> (long _rv)"}, |
| 797 | {"TEFeatureFlag", (PyCFunction)TEObj_TEFeatureFlag, 1, |
| 798 | "(short feature, short action) -> (short _rv)"}, |
| 799 | {NULL, NULL, 0} |
| 800 | }; |
| 801 | |
| 802 | PyMethodChain TEObj_chain = { TEObj_methods, NULL }; |
| 803 | |
| 804 | static PyObject *TEObj_getattr(self, name) |
| 805 | TEObject *self; |
| 806 | char *name; |
| 807 | { |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 808 | |
| 809 | if( strcmp(name, "destRect") == 0 ) |
| 810 | return Py_BuildValue("O&", PyMac_BuildRect, |
Jack Jansen | 19171a2 | 1996-04-16 14:32:01 +0000 | [diff] [blame^] | 811 | &(*self->ob_itself)->destRect); |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 812 | if( strcmp(name, "viewRect") == 0 ) |
| 813 | return Py_BuildValue("O&", PyMac_BuildRect, |
Jack Jansen | 19171a2 | 1996-04-16 14:32:01 +0000 | [diff] [blame^] | 814 | &(*self->ob_itself)->viewRect); |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 815 | if( strcmp(name, "selRect") == 0 ) |
| 816 | return Py_BuildValue("O&", PyMac_BuildRect, |
Jack Jansen | 19171a2 | 1996-04-16 14:32:01 +0000 | [diff] [blame^] | 817 | &(*self->ob_itself)->selRect); |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 818 | if( strcmp(name, "lineHeight") == 0 ) |
| 819 | return Py_BuildValue("h", (*self->ob_itself)->lineHeight); |
| 820 | if( strcmp(name, "fontAscent") == 0 ) |
| 821 | return Py_BuildValue("h", (*self->ob_itself)->fontAscent); |
| 822 | if( strcmp(name, "selPoint") == 0 ) |
| 823 | return Py_BuildValue("O&", PyMac_BuildPoint, |
Jack Jansen | 19171a2 | 1996-04-16 14:32:01 +0000 | [diff] [blame^] | 824 | &(*self->ob_itself)->selPoint); |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 825 | if( strcmp(name, "selStart") == 0 ) |
| 826 | return Py_BuildValue("h", (*self->ob_itself)->selStart); |
| 827 | if( strcmp(name, "selEnd") == 0 ) |
| 828 | return Py_BuildValue("h", (*self->ob_itself)->selEnd); |
| 829 | if( strcmp(name, "active") == 0 ) |
| 830 | return Py_BuildValue("h", (*self->ob_itself)->active); |
Jack Jansen | 19171a2 | 1996-04-16 14:32:01 +0000 | [diff] [blame^] | 831 | if( strcmp(name, "just") == 0 ) |
| 832 | return Py_BuildValue("h", (*self->ob_itself)->just); |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 833 | if( strcmp(name, "teLength") == 0 ) |
| 834 | return Py_BuildValue("h", (*self->ob_itself)->teLength); |
Jack Jansen | 19171a2 | 1996-04-16 14:32:01 +0000 | [diff] [blame^] | 835 | if( strcmp(name, "txFont") == 0 ) |
| 836 | return Py_BuildValue("h", (*self->ob_itself)->txFont); |
| 837 | if( strcmp(name, "txFace") == 0 ) |
| 838 | return Py_BuildValue("h", (*self->ob_itself)->txFace); |
| 839 | if( strcmp(name, "txMode") == 0 ) |
| 840 | return Py_BuildValue("h", (*self->ob_itself)->txMode); |
| 841 | if( strcmp(name, "txSize") == 0 ) |
| 842 | return Py_BuildValue("h", (*self->ob_itself)->txSize); |
| 843 | if( strcmp(name, "nLines") == 0 ) |
| 844 | return Py_BuildValue("h", (*self->ob_itself)->nLines); |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 845 | |
Jack Jansen | 8a452d6 | 1996-04-10 14:41:08 +0000 | [diff] [blame] | 846 | return Py_FindMethodInChain(&TEObj_chain, (PyObject *)self, name); |
| 847 | } |
| 848 | |
| 849 | #define TEObj_setattr NULL |
| 850 | |
| 851 | PyTypeObject TE_Type = { |
| 852 | PyObject_HEAD_INIT(&PyType_Type) |
| 853 | 0, /*ob_size*/ |
| 854 | "TE", /*tp_name*/ |
| 855 | sizeof(TEObject), /*tp_basicsize*/ |
| 856 | 0, /*tp_itemsize*/ |
| 857 | /* methods */ |
| 858 | (destructor) TEObj_dealloc, /*tp_dealloc*/ |
| 859 | 0, /*tp_print*/ |
| 860 | (getattrfunc) TEObj_getattr, /*tp_getattr*/ |
| 861 | (setattrfunc) TEObj_setattr, /*tp_setattr*/ |
| 862 | }; |
| 863 | |
| 864 | /* ----------------------- End object type TE ----------------------- */ |
| 865 | |
| 866 | |
| 867 | static PyObject *TE_TEScrapHandle(_self, _args) |
| 868 | PyObject *_self; |
| 869 | PyObject *_args; |
| 870 | { |
| 871 | PyObject *_res = NULL; |
| 872 | Handle _rv; |
| 873 | if (!PyArg_ParseTuple(_args, "")) |
| 874 | return NULL; |
| 875 | _rv = TEScrapHandle(); |
| 876 | _res = Py_BuildValue("O&", |
| 877 | ResObj_New, _rv); |
| 878 | return _res; |
| 879 | } |
| 880 | |
| 881 | static PyObject *TE_TEGetScrapLength(_self, _args) |
| 882 | PyObject *_self; |
| 883 | PyObject *_args; |
| 884 | { |
| 885 | PyObject *_res = NULL; |
| 886 | long _rv; |
| 887 | if (!PyArg_ParseTuple(_args, "")) |
| 888 | return NULL; |
| 889 | _rv = TEGetScrapLength(); |
| 890 | _res = Py_BuildValue("l", |
| 891 | _rv); |
| 892 | return _res; |
| 893 | } |
| 894 | |
| 895 | static PyObject *TE_TENew(_self, _args) |
| 896 | PyObject *_self; |
| 897 | PyObject *_args; |
| 898 | { |
| 899 | PyObject *_res = NULL; |
| 900 | TEHandle _rv; |
| 901 | Rect destRect; |
| 902 | Rect viewRect; |
| 903 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 904 | PyMac_GetRect, &destRect, |
| 905 | PyMac_GetRect, &viewRect)) |
| 906 | return NULL; |
| 907 | _rv = TENew(&destRect, |
| 908 | &viewRect); |
| 909 | _res = Py_BuildValue("O&", |
| 910 | TEObj_New, _rv); |
| 911 | return _res; |
| 912 | } |
| 913 | |
| 914 | static PyObject *TE_TETextBox(_self, _args) |
| 915 | PyObject *_self; |
| 916 | PyObject *_args; |
| 917 | { |
| 918 | PyObject *_res = NULL; |
| 919 | char *text__in__; |
| 920 | long text__len__; |
| 921 | int text__in_len__; |
| 922 | Rect box; |
| 923 | short just; |
| 924 | if (!PyArg_ParseTuple(_args, "s#O&h", |
| 925 | &text__in__, &text__in_len__, |
| 926 | PyMac_GetRect, &box, |
| 927 | &just)) |
| 928 | return NULL; |
| 929 | text__len__ = text__in_len__; |
| 930 | TETextBox(text__in__, text__len__, |
| 931 | &box, |
| 932 | just); |
| 933 | Py_INCREF(Py_None); |
| 934 | _res = Py_None; |
| 935 | text__error__: ; |
| 936 | return _res; |
| 937 | } |
| 938 | |
| 939 | static PyObject *TE_TEStyleNew(_self, _args) |
| 940 | PyObject *_self; |
| 941 | PyObject *_args; |
| 942 | { |
| 943 | PyObject *_res = NULL; |
| 944 | TEHandle _rv; |
| 945 | Rect destRect; |
| 946 | Rect viewRect; |
| 947 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 948 | PyMac_GetRect, &destRect, |
| 949 | PyMac_GetRect, &viewRect)) |
| 950 | return NULL; |
| 951 | _rv = TEStyleNew(&destRect, |
| 952 | &viewRect); |
| 953 | _res = Py_BuildValue("O&", |
| 954 | TEObj_New, _rv); |
| 955 | return _res; |
| 956 | } |
| 957 | |
| 958 | static PyObject *TE_TESetScrapLength(_self, _args) |
| 959 | PyObject *_self; |
| 960 | PyObject *_args; |
| 961 | { |
| 962 | PyObject *_res = NULL; |
| 963 | long length; |
| 964 | if (!PyArg_ParseTuple(_args, "l", |
| 965 | &length)) |
| 966 | return NULL; |
| 967 | TESetScrapLength(length); |
| 968 | Py_INCREF(Py_None); |
| 969 | _res = Py_None; |
| 970 | return _res; |
| 971 | } |
| 972 | |
| 973 | static PyObject *TE_TEFromScrap(_self, _args) |
| 974 | PyObject *_self; |
| 975 | PyObject *_args; |
| 976 | { |
| 977 | PyObject *_res = NULL; |
| 978 | OSErr _err; |
| 979 | if (!PyArg_ParseTuple(_args, "")) |
| 980 | return NULL; |
| 981 | _err = TEFromScrap(); |
| 982 | if (_err != noErr) return PyMac_Error(_err); |
| 983 | Py_INCREF(Py_None); |
| 984 | _res = Py_None; |
| 985 | return _res; |
| 986 | } |
| 987 | |
| 988 | static PyObject *TE_TEToScrap(_self, _args) |
| 989 | PyObject *_self; |
| 990 | PyObject *_args; |
| 991 | { |
| 992 | PyObject *_res = NULL; |
| 993 | OSErr _err; |
| 994 | if (!PyArg_ParseTuple(_args, "")) |
| 995 | return NULL; |
| 996 | _err = TEToScrap(); |
| 997 | if (_err != noErr) return PyMac_Error(_err); |
| 998 | Py_INCREF(Py_None); |
| 999 | _res = Py_None; |
| 1000 | return _res; |
| 1001 | } |
| 1002 | |
| 1003 | static PyMethodDef TE_methods[] = { |
| 1004 | {"TEScrapHandle", (PyCFunction)TE_TEScrapHandle, 1, |
| 1005 | "() -> (Handle _rv)"}, |
| 1006 | {"TEGetScrapLength", (PyCFunction)TE_TEGetScrapLength, 1, |
| 1007 | "() -> (long _rv)"}, |
| 1008 | {"TENew", (PyCFunction)TE_TENew, 1, |
| 1009 | "(Rect destRect, Rect viewRect) -> (TEHandle _rv)"}, |
| 1010 | {"TETextBox", (PyCFunction)TE_TETextBox, 1, |
| 1011 | "(Buffer text, Rect box, short just) -> None"}, |
| 1012 | {"TEStyleNew", (PyCFunction)TE_TEStyleNew, 1, |
| 1013 | "(Rect destRect, Rect viewRect) -> (TEHandle _rv)"}, |
| 1014 | {"TESetScrapLength", (PyCFunction)TE_TESetScrapLength, 1, |
| 1015 | "(long length) -> None"}, |
| 1016 | {"TEFromScrap", (PyCFunction)TE_TEFromScrap, 1, |
| 1017 | "() -> None"}, |
| 1018 | {"TEToScrap", (PyCFunction)TE_TEToScrap, 1, |
| 1019 | "() -> None"}, |
| 1020 | {NULL, NULL, 0} |
| 1021 | }; |
| 1022 | |
| 1023 | |
| 1024 | |
| 1025 | |
| 1026 | void initTE() |
| 1027 | { |
| 1028 | PyObject *m; |
| 1029 | PyObject *d; |
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 | m = Py_InitModule("TE", TE_methods); |
| 1035 | d = PyModule_GetDict(m); |
| 1036 | TE_Error = PyMac_GetOSErrException(); |
| 1037 | if (TE_Error == NULL || |
| 1038 | PyDict_SetItemString(d, "Error", TE_Error) != 0) |
| 1039 | Py_FatalError("can't initialize TE.Error"); |
| 1040 | } |
| 1041 | |
| 1042 | /* ========================= End module TE ========================== */ |
| 1043 | |