1 /* Part of XPCE --- The SWI-Prolog GUI toolkit 2 3 Author: Jan Wielemaker and Anjo Anjewierden 4 E-mail: jan@swi.psy.uva.nl 5 WWW: http://www.swi.psy.uva.nl/projects/xpce/ 6 Copyright (c) 1985-2002, University of Amsterdam 7 All rights reserved. 8 9 Redistribution and use in source and binary forms, with or without 10 modification, are permitted provided that the following conditions 11 are met: 12 13 1. Redistributions of source code must retain the above copyright 14 notice, this list of conditions and the following disclaimer. 15 16 2. Redistributions in binary form must reproduce the above copyright 17 notice, this list of conditions and the following disclaimer in 18 the documentation and/or other materials provided with the 19 distribution. 20 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #ifndef _PCE_TXT_INCLUDED 36 #define _PCE_TXT_INCLUDED 37 38 #include <h/graphics.h> 39 40 /******************************** 41 * TEXT CLASSES * 42 ********************************/ 43 44 45 #define TXT_X_MARGIN 5 /* Margin between text and box of textimage */ 46 #define TXT_Y_MARGIN 2 47 48 #define TXT_UNDERLINED 0x1 /* underlined character */ 49 #define TXT_HIGHLIGHTED 0x2 /* highlighted character (inverse video) */ 50 #define TXT_GREYED 0x4 /* greyed character */ 51 #define TXT_BOLDEN 0x8 /* bold character */ 52 #define TXT_HIDDEN 0x10 /* invisible fragment */ 53 54 NewClass(text_buffer) 55 ABSTRACT_SOURCE_SINK 56 Fragment first_fragment; /* first fragment */ 57 Fragment last_fragment; /* last fragment */ 58 Chain editors; /* editors associated buffer */ 59 BoolObj modified; /* has textbuffer been modified? */ 60 Int undo_buffer_size; /* Size of the undo-buffer */ 61 SyntaxTable syntax; /* Syntax description */ 62 BoolObj indent_tabs; /* Indent with tabs? */ 63 Int generation; /* Increments on each change */ 64 /* start private data */ 65 intptr_t changed_start; /* start of changed region */ 66 intptr_t changed_end; /* end of changed region */ 67 intptr_t gap_start; /* first location of the gap */ 68 intptr_t gap_end; /* last location of the gap */ 69 intptr_t size; /* # characters in buffer */ 70 intptr_t lines; /* total number of lines */ 71 intptr_t allocated; /* allocated size */ 72 UndoBuffer undo_buffer; /* Undo log */ 73 string buffer; /* Actual buffer (with gap) */ 74 End; 75 76 #define tb_bufferA buffer.text_union.textA 77 #define tb_bufferW buffer.text_union.textW 78 79 #define FRAG_INCLUDES_START 0x1 /* <-start is included */ 80 #define FRAG_INCLUDES_END 0x2 /* <-end is included */ 81 82 NewClass(fragment) 83 TextBuffer textbuffer; /* text buffer fragment associated */ 84 Fragment next; /* next fragment */ 85 Fragment prev; /* previous fragment */ 86 Name style; /* style of fragment (via editor) */ 87 intptr_t start; /* start of fragment */ 88 intptr_t length; /* length of fragment (> 0) */ 89 intptr_t attributes; /* FRAG_... */ 90 End; 91 92 NewClass(style) 93 FontObj font; /* font of fragment */ 94 Colour colour; /* colour of fragment */ 95 Any background; /* Background for drawing */ 96 Image icon; /* margin marker */ 97 Int left_margin; /* left margin in pixels */ 98 Int right_margin; /* right margin in pixels */ 99 intptr_t attributes; /* style attributes */ 100 End; 101 102 typedef struct 103 { enum 104 { TXT_FRAGMENT_START, 105 TXT_FRAGMENT_END, 106 TXT_FRAGMENT_CHAR 107 } type; 108 109 union 110 { Fragment fragment; 111 int character; 112 } value; 113 } text_event; 114 115 typedef int (*TextEventFunction)(text_event *event); 116 117 118 typedef struct fragment_cache *FragmentCache; 119 typedef struct isearch_cache *ISearchCache; 120 121 NewClass(editor) 122 ABSTRACT_DEVICE /* abstract super class device */ 123 TextBuffer text_buffer; /* Buffer editor operates on */ 124 TextImage image; /* The text area */ 125 ScrollBar scroll_bar; /* The scrollbar */ 126 TextMargin margin; /* The margin */ 127 TextCursor text_cursor; /* The cursor */ 128 TextObj label_text; /* Text for the label */ 129 FontObj font; /* editors default font */ 130 Size size; /* Size in characters */ 131 Int caret; /* position of the caret */ 132 Int mark; /* position of the marker */ 133 Name mark_status; /* active,inactive,highlight */ 134 Vector mark_ring; /* ring of old marks */ 135 Int tab_distance; /* distance between tabs */ 136 Style selection_style; /* style for the <-selection */ 137 Fragment selected_fragment; /* Currently selected fragment */ 138 Style selected_fragment_style; /* style of selected_fragment */ 139 Sheet styles; /* Style-name --> Style-object */ 140 KeyBinding bindings; /* Key bindings */ 141 Name focus_function; /* Function in focus */ 142 BoolObj fill_mode; /* Auto fill */ 143 BoolObj exact_case; /* Search and replace do exact case */ 144 Name kill_location; /* Processing kill sequences */ 145 Name search_direction; /* direction of the search */ 146 StringObj search_string; /* Target of search */ 147 Int search_origin; /* Incremental search started here */ 148 Int search_base; /* Currently searching from here */ 149 Name search_wrapped; /* Whether search is wrapped */ 150 BoolObj search_wrapped_warned; /* ISearch hit end of buffer */ 151 Name selection_unit; /* Selection unit (char, word, line) */ 152 Name selection_origin; /* Original start of selection */ 153 BoolObj editable; /* Text may be changed by user */ 154 Code error_message; /* Forward error messages */ 155 Code modified_message; /* Forward <->modified changed */ 156 Int left_margin; /* Left margin indentation */ 157 Int right_margin; /* Right margin */ 158 Int indent_increment; /* Steps taken by region in/undent1 */ 159 BoolObj auto_newline; /* Auto newline on ->append */ 160 SourceSink file; /* Name of file or NIL */ 161 Name dabbrev_target; /* Base of the dabbrev expansion */ 162 Chain dabbrev_reject; /* Hits rejected by dabbrev */ 163 Int dabbrev_pos; /* Current search position */ 164 Int dabbrev_origin; /* Start of dabbrev word */ 165 Name dabbrev_mode; /* Current dabbrev mode */ 166 Chain dabbrev_candidates; /* Dabbrev user candidates */ 167 /* Private data */ 168 intptr_t internal_mark; /* Internally used mark */ 169 FragmentCache fragment_cache; /* Cache to compute frament overlap */ 170 ISearchCache isearch_cache; /* Cache for highlighting search hits */ 171 End; 172 173 NewClass(text_cursor) 174 ABSTRACT_GRAPHICAL /* Abstract class graphical */ 175 Name style; /* Block, arrow, bitmap */ 176 Image image; /* If there is an image; this is it */ 177 Point hot_spot; /* Hot spot of the bitmap image */ 178 End; 179 180 NewClass(text_margin) 181 ABSTRACT_GRAPHICAL /* Abstract class graphical */ 182 Editor editor; /* Editor we are associated with */ 183 Size gap; /* X and Y distance between icons */ 184 Any background; /* background of the margin */ 185 End; 186 187 188 /******************************** 189 * TEXTIMAGE * 190 ********************************/ 191 192 #define EOB (-1) /* end-of-buffer */ 193 194 #define TEXT_SCAN_FOR 0 195 #define TEXT_SKIP_OVER 1 196 197 typedef struct text_screen * TextScreen; 198 typedef struct text_char * TextChar; 199 typedef struct text_line * TextLine; 200 201 typedef void (*SeekFunction)(Any, long); 202 typedef long (*ScanFunction)(Any, long, int, int, int, int *); 203 typedef long (*FetchFunction)(Any, TextChar); 204 typedef void (*MarginFunction)(Any, int *, int*); 205 typedef void (*RewindFunction)(Any); 206 207 #define CHAR_ASCII (0) /* ASCII character */ 208 #define CHAR_GRAPHICAL (1) /* graphical object */ 209 #define CHAR_IMAGE (2) /* image object */ 210 211 struct text_char 212 { union 213 { int c; /* character at pos */ 214 Graphical graphical; /* graphical at pos */ 215 Image image; /* image at pos */ 216 } value; 217 FontObj font; /* Font of this character */ 218 Colour colour; /* Colour of this character */ 219 Any background; /* Background for the characters */ 220 intptr_t index; /* Index in line (relative) */ 221 short x; /* X-position in line (pixels) */ 222 unsigned char attributes; /* Its attributes */ 223 unsigned type : 2; /* type of character */ 224 }; 225 226 struct text_line 227 { intptr_t start; /* Start index (relative) */ 228 intptr_t end; /* Last index (relative) */ 229 short y; /* Y-position in pixels */ 230 short h; /* Height in pixels */ 231 short w; /* Width of displayed text */ 232 short base; /* Baseline (relative to y) */ 233 short length; /* Number of characters displayed */ 234 short allocated; /* Size of chars array */ 235 int changed; /* Line has been changed? */ 236 int ends_because; /* END_WRAP; END_EOF; END_NL */ 237 TextChar chars; /* Character descriptions */ 238 }; 239 240 struct text_screen 241 { short skip; /* Skip this many screen lines */ 242 short length; /* Number of lines displayed */ 243 short allocated; /* Allocated entries of the array */ 244 TextLine lines; /* The actual line structure */ 245 }; 246 247 248 NewClass(text_image) /* TBD: subclass of bitmap? */ 249 ABSTRACT_GRAPHICAL 250 Any text; /* Text we are operation on */ 251 Any background; /* Background of text */ 252 Int start; /* Start offset */ 253 Int end; /* First non-visible character */ 254 Name wrap; /* Wrap mode in effect */ 255 Int tab_distance; /* Tab distance in pixels */ 256 Vector tab_stops; /* Vector of tab-stops (pixels) */ 257 Graphical pointed; /* Graphical under the pointer */ 258 BoolObj eof_in_window; /* EOF is in the window */ 259 Elevation elevation; /* Box elevation */ 260 /* start private data */ 261 intptr_t w; /* Used width in pixels */ 262 intptr_t h; /* Used height in pixels */ 263 intptr_t change_start; /* Start of changes */ 264 intptr_t change_end; /* End of changes */ 265 intptr_t inserted; /* Number of chars inserted/deleted */ 266 SeekFunction seek; /* Seek to position */ 267 ScanFunction scan; /* Scan for character type */ 268 FetchFunction fetch; /* Function to fetch characters */ 269 MarginFunction margin; /* Function to fetch margins */ 270 RewindFunction rewind; /* Rewind (prepare) input */ 271 TextScreen map; /* Describes the text object */ 272 End; 273 274 #endif /* _PCE_TXT_INCLUDED */ 275