txt 27.1 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843
/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/****************************************************************************
 * This source file was written by Acorn Computers Limited. It is part of   *
 * the RISCOS library for writing applications in C for RISC OS. It may be  *
 * used freely in the creation of programs for Archimedes. It should be     *
 * used with Acorn's C Compiler Release 3 or later.                         *
 *                                                                          *
 ***************************************************************************/

/*
 * Title:   txt.h
 * Purpose: Text display object.
 *
 */

#ifndef __txt_h
#define __txt_h

#ifndef BOOL
#define BOOL int
#define TRUE 1
#define FALSE 0
#endif

/*
 * A txt is an array of characters, displayed in a window on the screen. It
 * behaves in many ways in a manner similar to a single buffer from a
 * conventional full screen text editor.
 *
 */

/*
 * This interface is intended to be independent of any underlying window
 * system.
 *
 */

/****************************** TXT DATA TYPE *****************************/

/* This is an abstract handle on a text object. */

typedef struct txt1_str *txt;



/****************************** INTERFACE FUNCTIONS ************************/


/* ------------------------------- txt_new ---------------------------------
 * Description:   Creates a new txt object, containing no charcters, with a
 *                given title (to appear in its window).
 *
 * Parameters:    char *title -- the text title to appear in its window
 * Returns:       pointer to the newly created text.
 * Other Info:    This function does not result in the text being displayed
 *                on the screen; it purely creates a new text object.
 *                0 is returned if there is not enough space to create the
 *                object.
 *
 */

txt txt_new(char *title);


/* -------------------------------- txt_show -------------------------------
 * Description:   Display a given text object in a free standing window of
 *                its own.
 *
 * Parameters:    txt t -- the text to be displayed.
 * Returns:       void.
 * Other Info:    "t" should have been created using txt_new.
 *
 */

void txt_show(txt t);


/* ------------------------------ txt_hide ---------------------------------
 * Description:   Hide a text which has been displayed.
 *
 * Parameters:    txt t -- the text to be hidden.
 * Returns:       void.
 * Other Info:    none.
 *
 */

void txt_hide(txt t);


/* ---------------------------- txt_settitle -------------------------------
 * Description:   Change the title of the window used to display a text
 *                object.
 *
 * Parameters:    txt t -- the text object
 *                char *title -- new title of window.
 * Returns:       void.
 * Other Info:    Long titles may be truncated when displayed.
 *
 */

void txt_settitle(txt, char *title);


/* ----------------------------- txt_dispose -------------------------------
 * Description:   Destroy a text and the window associated with it.
 *
 * Parameters:    txt *t -- pointer to the text.
 * Returns:       void.
 * Other Info:    none.
 *
 */

void txt_dispose(txt *t);


/*************************** General control operations. *******************/

/* A text object's main data content is an array of characters. This resides
 * in a buffer of known size. The characters of the array are not laid out
 * precisely in the buffer, gaps and wraparound of various forms are used in
 * order to make insertion and deletion fast. When initially created a text
 * has bufsize=0. If the buffer size is precisely the same as the number of
 * characters in the array then some operations (e.g. moving around in the
 * array) become even faster, this may be relevant when building fixed-size
 * VDU emulations.
 *
 */


/* ----------------------------- txt_bufsize -------------------------------
 * Description:   Informs caller of how many characters can be stored in the
 *                buffer, before more memory needs to be requested from the
 *                operating system.
 *
 * Parameters:    txt t -- the text.
 * Returns:       size of buffer.
 * Other Info:    none.
 *
 */

int txt_bufsize(txt);


/* --------------------------- txt_setbufsize ------------------------------
 * Description:   Allocates more space for the text buffer.
 *
 * Parameters:    txt t -- the text.
 *                int b -- new buffer size
 * Returns:       TRUE if space could be allocated successfully.
 * Other Info:    This call increases the buffer size, such that at least
 *                "b" characters can be stored, before requiring more from
 *                the operating system.
 *
 */

BOOL txt_setbufsize(txt, int);


/*
 * The character array is displayed on the screen in a window.  The
 * characters travel horizontally from left to right. If a '\n' is
 * encountered this signifies the end of the current text line, and the
 * start of a new one. All lines have the same height, although characters
 * may be of differing widths. There is no limit on the number of characters
 * allowed in a line. There is no restriction on the characters allowed in
 * the array, [0..255] are all acceptable.
 * Clearing the DISPLAY flag can be used during a long and complex sequence
 * of edits, to reduce the overall amount of display activity. The UPDATED
 * flag is set by the insertion or deletion of any characters in the array.
 *
 */

typedef enum { txt_DISPLAY = 1,     /* display changes to text as made */
               txt_CARET = 2,       /* give visible indictaion of "dot" */
               txt_UPDATED = 4      /* set when chars are inserted/deleted */
             } txt_charoption;


/* ----------------------------- txt_charoptions ---------------------------
 * Description:   Informs caller of currenly set charoptions.
 *
 * Parameters:    txt t -- text object.
 * Returns:       Currently set charoptions.
 * Other Info:    none.
 *
 */

txt_charoption txt_charoptions(txt);


/* ----------------------------- txt_setcharoptions ------------------------
 * Description:   Sets flags which are used to control display of text in
 *                screen window.
 *
 * Parameters:    txt t -- text object
 *                txt_charoption affect -- flags to affect
 *                txt_charoption values -- values to give to affected flags
 * Returns:       void.
 * Other Info:    Only the flags named in "affect" are affected - they are
 *                set to the value "values".
 *                Thus this has the meaning:
 *                  (previousState & ~affect) | (affect & values).
 *
 */

void txt_setcharoptions(txt, txt_charoption affect, txt_charoption values);

/* ----------------------------- txt_lastref -------------------------------
 * Description:   Returns last_ref field (for Message_DataSaved).
 *
 * Parameters:    txt t -- text object.
 * Returns:       Current value of last_ref (for Message_DataSaved).
 * Other Info:    none.
 *
 */

int txt_lastref(txt);


/* ----------------------------- txt_setlastref ----------------------------
 * Description:   Sets value of last_ref (for Message_DataSaved).
 *
 * Parameters:    txt t -- text object
 *                int newvalue -- new value
 * Returns:       void.
 * Other Info:    Sets the last_ref field in a txt, so that subsequently a
 *                Message_DataSaved can mark the data unmodified.
 *
 */

void txt_setlastref(txt, int newvalue);


/* -------------------------- txt_setdisplayok -----------------------------
 * Description:   Sets the display flag in charoptions for a given text
 *
 * Parameters:    txt t -- text object
 * Returns:       void.
 * Other Info:    You may have unset the display flag during a long/complex
 *                update to the array of characters. A call to this function
 *                turns display back on.
 *
 */

void txt_setdisplayok(txt);


/******************** Operations on the array of characters. ***************/

/*
 * "dot" is an index into the character array. If there are n chars in the
 * array, with indices in [0..n-1], then dot is in [0..n]. It is thought of
 * as pointing just before the character with the same index, but it can also
 * point just after the last one. When the text is displayed, the character
 * after the dot is always visible. The Caret is a visible indication of the
 * position of the dot within the array, it can be made visible using
 * SetCharOptions above.
 */

typedef int txt_index; /* An index into the char array */


/* ------------------------------ txt_dot ----------------------------------
 * Description:   Informs caller of where the "dot" (current position) is in
 *                the array of characters.
 *
 * Parameters:    txt t -- text object
 * Returns:       An index into the array of characters.
 * Other Info:    none.
 *
 */

txt_index txt_dot(txt t);


/* ------------------------------- txt_size --------------------------------
 * Description:   Informs the caller as to the maximum value "dot" can take
 *
 * Parameters:    txt t -- text object.
 * Returns:       Maximum permissible value of "dot".
 * Other Info:    none.
 *
 */

txt_index txt_size(txt t);


/* ------------------------------- txt_setdot ------------------------------
 * Description:   Sets the "dot" at a given index in the array of characters.
 *
 * Parameters:    txt t -- text object.
 *                txt_index i -- index at which to set "dot".
 * Returns:       void.
 * Other Info:    If "i" is outside the bounds of the array it is set to the
 *                beginning/end of the array appropriately.
 *
 */

void txt_setdot(txt t, txt_index i);


/* ------------------------------ txt_movedot ------------------------------
 * Description:   Move the "dot" by a given distance in the array.
 *
 * Parameters:    txt t -- text object
 *                int by -- distance to move by.
 * Returns:       void
 * Other Info:    If the resulting "dot" is outside the bounds of the array
 *                it is set to the beginning/end of the array appropriately.
 *
 */

void txt_movedot(txt, int by);


/* ----------------------------- txt_insertchar ----------------------------
 * Description:   Insert a character into the text just after the "dot".
 *
 * Parameters:    txt t -- text object
 *                char c -- the character to be inserted.
 * Returns:       void.
 * Other Info:    If the DISPLAY option flag is set, the window is
 *                redisplayed after insertion.
 *
 */

void txt_insertchar(txt t, char c);


/* --------------------------- txt_insertstring ----------------------------
 * Description:   Inserts a given character string into a text.
 *
 * Parameters:    txt t -- text object
 *                char *s -- the character string.
 * Returns:       void.
 * Other Info:    If the DISPLAY option flag is set, the window is
 *                redisplayed after insertion.
 *
 */

void txt_insertstring(txt t, char *s);


/* ------------------------------ txt_delete -------------------------------
 * Description:   Deletes "n" characters from the "dot" onwards.
 *
 * Parameters:    txt t -- text object
 *                int n -- number of characters to delete.
 * Returns:       void.
 * Other Info:    If "dot +n" is beyond the end of the array, then deletion
 *                is to end of array.
 *
 */

void txt_delete(txt t, int n);


/* ---------------------------- txt_replacechars ---------------------------
 * Description:   Deletes "ntodelete" charcters from "dot", and inserts "n"
 *                characters in their place, where the characters are
 *                pointed at by "a".
 *
 * Parameters:    txt t -- text object
 *                int ntodelete -- number of characters to delete
 *                char *a -- pointer to characters to insert
 *                int n -- number of characters to insert.
 * Returns:       void.
 * Other Info:    none.
 *
 */

void txt_replacechars(txt t, int ntodelete, char *a, int n);


/* ---------------------------- txt_charatdot ------------------------------
 * Description:   Informs caller of the character held at "dot" in the array.
 *
 * Parameters:    txt t -- text object.
 * Returns:       Character at "dot".
 * Other Info:    Returns 0 if "dot" is at/beyond end of array.
 *
 */

char txt_charatdot(txt t);


/* ------------------------------ txt_charat -------------------------------
 * Description:   Informs caller of the character at a given index in the
 *                array.
 *
 * Parameters:    txt t -- text object
 *                txt_index i -- the index into the array.
 * Returns:       Character at given index in array.
 * Other Info:    Returns 0 if index is at/beyond end of array.
 *
 */

char txt_charat(txt t, txt_index i);


/* ---------------------------- txt_charsatdot -----------------------------
 * Description:   Copies at most "n" characters from "dot" in the array into
 *                a supplied buffer.
 *
 * Parameters:    txt t -- text object
 *                char *buffer -- the buffer
 *                int *n -- maximum characters to copy.
 * Returns:       void.
 * Other Info:    If you are close to the end of the array, then "n" chars
 *                may not be available. In this case, chars up to the end of
 *                the array are copied, and *n is updated to report how many
 *                were copied.
 *
 */

void txt_charsatdot(txt, char/*out*/ *buffer, int /*inout*/ *n);


/* -------------------------- txt_replaceatend -----------------------------
 * Description:   Deletes a specified number of characters from the end of
 *                the array and then inserts specified characters.
 *
 * Parameters:    txt t -- text object
 *                int ntodelete -- number of characters to delete
 *                char *s -- pointer to characters to insert
 *                int n -- number of characters to insert.
 * Returns:       void.
 * Other Info:    none.
 *
 */

void txt_replaceatend(txt, int ntodelete, char*, int);


/************************ Layout-dependent Operations. *********************/

/*
 * These operations are provided specifically for the support of cursor-
 * key-driven editing.
 */


/* ------------------------- txt_movevertical ------------------------------
 * Description:   Moves the "dot" by a specified number of textual lines,
 *                with the caret staying in the same horizontal position
 *                on the screen.
 *
 * Parameters:    txt t -- text object
 *                int by -- number of lines to move by
 *                int caretstill -- set to non-zero, if you want the text to
 *                                  move rather than the caret.
 * Returns:       void.
 * Other Info:    none.
 *
 */

void txt_movevertical(txt t, int by, int caretstill);


/* --------------------------- txt_movehorizontal --------------------------
 * Description:   Move the caret (and "dot") "horizontally".
 *
 * Parameters:    txt t -- text object
 *                int by -- distance to move by.
 * Returns:       void.
 * Other Info:    This behaves like txt_movedot(), except that if "by" is
 *                positive and the end of the current text line is
 *                encountered, then the caret will continue to move to the
 *                right on the screen.
 *
 */

void txt_movehorizontal(txt, int by);


/* -------------------------- txt_visiblelinecount -------------------------
 * Description:   Gives the number of lines visible or partially visible
 *                on the display.
 *
 * Parameters:    txt t -- text object.
 * Returns:       Number of visible lines.
 * Other Info:    Takes into account current window size, font etc.
 *
 */

int txt_visiblelinecount(txt t);


/* -------------------------- txt_visiblecolcount --------------------------
 * Description:   Gives the number of columns currently visible.
 *
 * Parameters:    txt t -- text object.
 * Returns:       Visible column count.
 * Other Info:    If a fixed pitch font is currently in use, then this gives
 *                the number of display columns, otherwise it makes a guess
 *                for "average" characters.
 *
 */

int txt_visiblecolcount(txt t);


/*************************** Operations on Markers. ************************/

/*
 * Markers are indices into the array. Once set, a marker will point to the
 * same character in the array regardless of insertions or deletions within
 * the array. If the character pointed at by the marker is deleted then the
 * marker will point to the next character. Markers never "fall off the end"
 * of the array, but stay at the top or bottom of it if that's where they
 * end up.
 */

typedef struct {int a; int b;} txt_marker;
/* Abstract record, uses of fields not public. */


/* ---------------------------- txt_newmarker ------------------------------
 * Description:   Create a new "marker" in the text.
 *
 * Parameters:    txt t -- text object
 *                txt_marker *mark -- pointer to your text marker.
 * Returns:       void.
 * Other Info:    Marker itself is kept by the client of this function, but
 *                the text object retains a pointer to it. The client's
 *                marker is updated by the text object whenever necessary.
 *                Its initial value is the same as "dot". If the character
 *                at which a marker points is deleted, then the marker gets
 *                moved to the value of "dot" when the deletion occurred. If
 *                characters are inserted when the marker is at dot, the
 *                marker stays with "dot".
 *
 */

void txt_newmarker(txt, txt_marker *mark);


/* -------------------------- txt_movemarker -------------------------------
 * Description:   Resets an existing marker.
 *
 * Parameters:    txt t  - text object
 *                txt_marker *mark -- the marker
 *                txt_index to -- place to move the marker to
 * Returns:       void.
 * Other Info:    The amrker must already point into this text object
 *
 */

void txt_movemarker(txt t, txt_marker *mark, txt_index to);


/* ------------------------- txt_movedottomarker ---------------------------
 * Description:   Moves the "dot" to a given marker.
 *
 * Parameters:    txt t -- text object
 *                txt_marker *mark -- pointer to the marker
 * Returns:       void.
 * Other Info:    none.
 *
 */

void txt_movedottomarker(txt t, txt_marker *mark);


/* ----------------------- txt_indexofmarker -------------------------------
 * Description:   Gives the current index into the array of a given marker
 *
 * Parameters:    txt t -- text object
 *                txt_marker *mark.
 * Returns:       Index of marker
 * Other Info:    none.
 *
 */

txt_index txt_indexofmarker(txt t, txt_marker *mark);


/* ---------------------------- txt_disposemarker --------------------------
 * Description:   Delete a marker from a text object.
 *
 * Parameters:    txt t -- text object
 *                txt_marker *mark -- the marker to be deleted.
 * Returns:       void.
 * Other Info:    WARNING: You should remember to dispose of a marker which
 *                logically ceases to exist, otherwise the text object will
 *                continue to update the location where it was!.
 *
 */

void txt_disposemarker(txt, txt_marker*);


/*********************** Operations on a selection. ************************/

/* The selection is a contiguous portion of the array which is
 * displayed highlighted.
 */

/* ---------------------------- txt_selectset ------------------------------
 * Description:   Informs caller whether there is a selction made in a text.
 *
 * Parameters:    txt t -- text object.
 * Returns:       TRUE if there is a selection in this text.
 * Other Info:    none.
 *
 */

BOOL txt_selectset(txt t);


/* --------------------------- txt_selectstart -----------------------------
 * Description:   Gives the index into the array of the start of the current
 *                selection.
 *
 * Parameters:    txt t -- text object.
 * Returns:       Index of selection start.
 * Other Info:    none.
 *
 */

txt_index txt_selectstart(txt t);


/* --------------------------- txt_selectend -------------------------------
 * Description:   Gives the index into the array of the end of the current
 *                selection.
 *
 * Parameters:    txt t -- text object.
 * Returns:       Index of selection end.
 * Other Info:    none.
 *
 */

txt_index txt_selectend(txt t);


/* -------------------------- txt_setselect --------------------------------
 * Description:   Sets a selection in a given text, from "start" to "end"
 *
 * Parameters:    txt t -- text object
 *                txt_index start -- array index of start of selection
 *                txt_index end -- array index of end of selection.
 *
 * Returns:       void.
 * Other Info:    If "start" >= "end" then the selection will be unset.
 *
 */

void txt_setselect(txt, txt_index start, txt_index end);


/*************************** Input from the user ***************************/

/* Characters entered into the keyboard, and various mouse events, are
buffered up by the text object for use by the client. */

typedef int txt_eventcode;


/* ------------------------------- txt_get ---------------------------------
 * Description:   Gives the next user event code to the caller.
 *
 * Parameters:    txt t -- text object.
 * Returns:       The event code.
 * Other Info:    The returned code can be ASCII, or various other (system-
 *                specific) values for function keys etc.
 *
 */

txt_eventcode txt_get(txt t);


/* ------------------------------- txt_queue -------------------------------
 * Description:   Informs caller of how many event codes are currently
 *                buffered for a given text.
 *
 * Parameters:    txt t -- text object.
 * Returns:       No. of buffered event codes.
 * Other Info:    none.
 *
 */

int txt_queue(txt t);


/* ----------------------------- txt_unget ---------------------------------
 * Description:   Puts an event code back on the front of the event queue
 *                for a given text.
 *
 * Parameters:    txt t -- text object
 *                txt_eventcode code -- the event code.
 * Returns:       void.
 * Other Info:    none.
 *
 */

void txt_unget(txt t, txt_eventcode code);


/****************************** Mouse events *******************************/

typedef enum {
  txt_MSELECT = 0x01000000,
  txt_MEXTEND = 0x02000000,
  txt_MSELOLD = 0x04000000,
  txt_MEXTOLD = 0x08000000,
  txt_MEXACT = 0x10000000,
  txt_EXTRACODE = 0x40000000,
  txt_MOUSECODE = ~0x7fffffff
} txt_mouseeventflag; /* used as a set */

/* A mouse event occurs when the mouse is pointing in the text object and a
 * button is pressed or released, or the mouse moves while any button is
 * depressed. A mouse event will result in Get producing an EventCode with
 * bit 31 set, bits 24..28 as a mouseeventflags value, and the rest of the
 * word containing an index value.
 *
 * The index shows where in the visible representation of the array the mouse
 * event happened. If all three index bytes are 255 then the event happened
 * outside the window. The mouseeventflags show what button transitions
 * occurred:
 *    MSELECT -- select's new value
 *    MEXTEND -- extend's new value
 *    MSELOLD -- select's old value
 *    MEXTOLD -- extend's old value
 *    MEXACT -- the event is in exactly the same place as the last one
 * The byte gives the values of the select and extend buttons, 1 for
 * depressed and 0 for not depressed. It gives their previous values,
 * allowing transitions to be detected. It says if the position of the mouse
 * is exactly the same as for the last event, so that multiple clicks may be
 * detected. No assumptions should be made concerning the relationship of
 * these bits to the last mouse event sent to the programmer, as polling
 * delays etc. could cause any combinations to happen.
 *
 * If txt_EXTRACODE is set then the identity of the event is not defined
 * by this interface. This is used for any expansion. Clients of this
 * interface which receive such events that they do not recognise, should
 * ignore them without reporting an error.
 *
 * The menu button on the mouse is not transmitted through this interface,
 * but caught elsewhere.
 *
 */

typedef void (*txt_event_proc)(txt,void *handle);


/* ---------------------------- txt_eventhandler ---------------------------
 * Description:   Register an eventhandler function for a given text,
 *                which will be called whenever there is a value ready which
 *                can be picked up by txt_get().
 *
 * Parameters:    txt t -- text object
 *                txt_event_proc func -- event handler function
 *                void *handle -- caller-defined handle to be passed to func.
 * Returns:       void.
 * Other Info:    If func==0 then no function is registered.
 *
 */

void txt_eventhandler(txt, txt_event_proc, void *handle);


/* -------------------------- txt_readeventhandler -------------------------
 * Description:   Informs caller of the currently registered eventhandler
 *                function associated with a given text, and the handle which
 *                is passed to it.
 *
 * Parameters:    txt t -- text object
 *                txt_event_proc *func -- returned pointer to handler func
 *                void **handle -- returned pointer to handle.
 * Returns:       void.
 * Other Info:    none.
 *
 */

void txt_readeventhandler(txt t, txt_event_proc *func, void **handle);


/******************* Direct Access to the array of characters **************/

/* ---------------------------- txt_arrayseg -------------------------------
 * Description:   Gives a direct pointer into the memory used to hold the
 *                characters in a text.
 *
 * Parameters:    txt t -- text object
 *                txt_index at -- index into the text
 *                char **a -- *a will point at the character whose index
 *                            in the text is "at"
 *                int *n -- *n == no. of contiguous bytes after "at"
 * Returns:       void.
 * Other Info:    It is permissible for the caller of this function to change
 *                the characters pointed at by *a, provided that a redsiplay
 *                is prompted (using setcharoptions).
 *
 */

void txt_arrayseg(txt t, txt_index at, char **a /*out*/, int *n /*out*/);


/******************************* System hook *******************************/


/* ---------------------------- txt_syshandle ------------------------------
 * Description:   Obtains a system_dependent handle on the object underlying
 *                a text.
 *
 * Parameters:    txt t -- text object.
 * Returns:       System-dependent handle for the given text.
 * Other Info:    none.
 *
 */

int txt_syshandle(txt t);


/* ---------------------------------- txt_init -----------------------------
 * Description:   Initialise the txt module of the library
 *
 * Parameters:    void.
 * Returns:       void.
 * Other Info:    none.
 *
 */

void txt_init(void);

# endif

/* end txt.h */