]> cvs.zerfleddert.de Git - micropolis/blob - src/tk/tktext.h
allow scenario window to be closed
[micropolis] / src / tk / tktext.h
1 /*
2 * tkText.h --
3 *
4 * Declarations shared among the files that implement text
5 * widgets.
6 *
7 * Copyright 1992 Regents of the University of California.
8 * Permission to use, copy, modify, and distribute this
9 * software and its documentation for any purpose and without
10 * fee is hereby granted, provided that the above copyright
11 * notice appear in all copies. The University of California
12 * makes no representations about the suitability of this
13 * software for any purpose. It is provided "as is" without
14 * express or implied warranty.
15 *
16 * $Header: /user6/ouster/wish/RCS/tkText.h,v 1.13 92/07/31 13:43:26 ouster Exp $ SPRITE (Berkeley)
17 */
18
19 #ifndef _TKTEXT
20 #define _TKTEXT
21
22 #ifndef _TK
23 #include "tk.h"
24 #endif
25
26 /*
27 * Opaque types for structures whose guts are only needed by a single
28 * file:
29 */
30
31 typedef struct TkTextBTree *TkTextBTree;
32
33 /*
34 * The data structure below defines a single line of text (from newline
35 * to newline, not necessarily what appears on one line of the screen).
36 */
37
38 typedef struct TkTextLine {
39 struct Node *parentPtr; /* Pointer to parent node containing
40 * line. */
41 struct TkTextLine *nextPtr; /* Next in linked list of lines with
42 * same parent node in B-tree. NULL
43 * means end of list. */
44 struct TkAnnotation *annotPtr; /* First in list of annotations for
45 * this line. */
46 int numBytes; /* Number of bytes in line, including
47 * newline but not terminating NULL. */
48 char bytes[4]; /* Contents of line, null-terminated.
49 * The actual length of the array will
50 * be as large as needed to hold the
51 * line. THIS MUST BE THE LAST FIELD
52 * OF THE STRUCT. */
53 } TkTextLine;
54
55 /*
56 * The structures below are used to describe annotations to the text
57 * (such as marks and embedded windows). Annotations are placed at
58 * a given place in the text and then float to keep their position
59 * as text is inserted and deleted. Each actual annotation
60 * contains a standard set of fields, plus a type-specific set of
61 * fields. The types are as follows:
62 *
63 * TK_ANNOT_TOGGLE - Marks the beginning or end of a range of
64 * characters that have a given tag.
65 * TK_ANNOT_MARK - Holds information about a given "mark" (see
66 * user doc. for information on marks).
67 * TK_ANNOT_WINDOW - Holds information on a window embedded in the
68 * text. Not implemented yet.
69 */
70
71 typedef enum {TK_ANNOT_TOGGLE, TK_ANNOT_MARK, TK_ANNOT_WINDOW} TkAnnotType;
72
73 typedef struct TkAnnotation {
74 TkAnnotType type; /* Type of annotation. */
75 TkTextLine *linePtr; /* Pointer to line structure
76 * containing this annotation. */
77 int ch; /* Index of character that annotation
78 * is attached to (annotation is
79 * considered to be just before this
80 * character). */
81 struct TkAnnotation *nextPtr; /* Next in list of annotations for
82 * same line of text, or NULL if
83 * end of list. */
84 union { /* Type-specific information. */
85 struct TkTextTag *tagPtr; /* Type == TK_ANNOT_TOGGLE. */
86 Tcl_HashEntry *hPtr; /* Type == TK_ANNOT_MARK. */
87 } info;
88 } TkAnnotation;
89
90 /*
91 * One data structure of the following type is used for each tag that
92 * is currently being used in a text widget. These structures are kept
93 * in textPtr->tagTable and referred to in other structures, like
94 * TkTagToggles.
95 */
96
97 typedef struct TkTextTag {
98 char *name; /* Name of this tag. This field is actually
99 * a pointer to the key from the entry in
100 * textPtr->tagTable, so it needn't be freed
101 * explicitly. */
102 int priority; /* Priority of this tag within widget. 0
103 * means lowest priority. Exactly one tag
104 * has each integer value between 0 and
105 * numTags-1. */
106
107 /*
108 * Information for displaying text with this tag. The information
109 * belows acts as an override on information specified by lower-priority
110 * tags. If no value is specified, then the next-lower-priority tag
111 * on the text determins the value. The text widget itself provides
112 * defaults if no tag specifies an override.
113 */
114
115 Tk_3DBorder border; /* Used for drawing background. NULL means
116 * no value specified here. */
117 int borderWidth; /* Width of 3-D border for background. */
118 int relief; /* 3-D relief for background. */
119 Pixmap bgStipple; /* Stipple bitmap for background. None
120 * means no value specified here. */
121 XColor *fgColor; /* Foreground color for text. NULL means
122 * no value specified here. */
123 XFontStruct *fontPtr; /* Font for displaying text. NULL means
124 * no value specified here. */
125 Pixmap fgStipple; /* Stipple bitmap for text and other
126 * foreground stuff. None means no value
127 * specified here.*/
128 int underline; /* Non-zero means draw underline underneath
129 * text. */
130 } TkTextTag;
131
132 /*
133 * The macro below determines whether or not a particular tag affects
134 * the way information is displayed on the screen. It's used, for
135 * example, to determine when to redisplay in response to tag changes.
136 */
137
138 #define TK_TAG_AFFECTS_DISPLAY(tagPtr) \
139 (((tagPtr)->border != NULL) || ((tagPtr)->bgStipple != None) \
140 || ((tagPtr)->fgColor != NULL) || ((tagPtr)->fontPtr != NULL) \
141 || ((tagPtr)->fgStipple != None) || ((tagPtr)->underline))
142
143 /*
144 * The data structure below is used for searching a B-tree for transitions
145 * on a single tag (or for all tag transitions). No code outside of
146 * tkTextBTree.c should ever modify any of the fields in these structures,
147 * but it's OK to use them for read-only information.
148 */
149
150 typedef struct TkTextSearch {
151 TkTextBTree tree; /* Tree being searched. */
152 int line1, ch1; /* Position of last tag returned
153 * by TkBTreeNextTag. */
154 int line2, ch2; /* Stop search after all tags at this
155 * character position have been
156 * processed. */
157 TkTextTag *tagPtr; /* Tag to search for (or tag found, if
158 * allTags is non-zero). */
159 int allTags; /* Non-zero means ignore tag check:
160 * search for transitions on all
161 * tags. */
162 TkTextLine *linePtr; /* Line currently being searched. NULL
163 * means search is over. */
164 TkAnnotation *annotPtr; /* Pointer to next annotation to
165 * consider. NULL means no annotations
166 * left in current line; must go on
167 * to next line. */
168 } TkTextSearch;
169
170 /*
171 * A data structure of the following type is kept for each text widget that
172 * currently exists for this process:
173 */
174
175 typedef struct TkText {
176 Tk_Window tkwin; /* Window that embodies the text. NULL
177 * means that the window has been destroyed
178 * but the data structures haven't yet been
179 * cleaned up.*/
180 Tcl_Interp *interp; /* Interpreter associated with widget. Used
181 * to delete widget command. */
182 TkTextBTree tree; /* B-tree representation of text and tags for
183 * widget. */
184 Tcl_HashTable tagTable; /* Hash table that maps from tag names to
185 * pointers to TkTextTag structures. */
186 int numTags; /* Number of tags currently defined for
187 * widget; needed to keep track of
188 * priorities. */
189 Tcl_HashTable markTable; /* Hash table that maps from mark names to
190 * pointer to TkAnnotation structures of
191 * type TK_ANNOT_MARK. */
192 Tk_Uid state; /* Normal or disabled. Text is read-only
193 * when disabled. */
194
195 /*
196 * Default information for displaying (may be overridden by tags
197 * applied to ranges of characters).
198 */
199
200 Tk_3DBorder border; /* Structure used to draw 3-D border and
201 * default background. */
202 int borderWidth; /* Width of 3-D border to draw around entire
203 * widget. */
204 int padX, padY; /* Padding between text and window border. */
205 int relief; /* 3-d effect for border around entire
206 * widget: TK_RELIEF_RAISED etc. */
207 Cursor cursor; /* Current cursor for window, or None. */
208 XColor *fgColor; /* Default foreground color for text. */
209 XFontStruct *fontPtr; /* Default font for displaying text. */
210
211 /*
212 * Additional information used for displaying:
213 */
214
215 Tk_Uid wrapMode; /* How to handle wrap-around. Must be
216 * tkTextCharUid, tkTextNoneUid, or
217 * tkTextWordUid. */
218 int width, height; /* Desired dimensions for window, measured
219 * in characters. */
220 int setGrid; /* Non-zero means pass gridding information
221 * to window manager. */
222 int prevWidth, prevHeight; /* Last known dimensions of window; used to
223 * detect changes in size. */
224 TkTextLine *topLinePtr; /* Text line that is supposed to be displayed
225 * at top of the window: set only by
226 * tkTextDisp.c. */
227 struct DInfo *dInfoPtr; /* Additional information maintained by
228 * tkTextDisp.c. */
229 Tk_TimerToken updateTimerToken; /* Added by Don to optimize rapid
230 * updates. */
231
232 /*
233 * Information related to selection.
234 */
235
236 TkTextTag *selTagPtr; /* Pointer to "sel" tag. Used to tell when
237 * a new selection has been made. */
238 Tk_3DBorder selBorder; /* Border and background for selected
239 * characters. This is a copy of information
240 * in *cursorTagPtr, so it shouldn't be
241 * explicitly freed. */
242 int selBorderWidth; /* Width of border around selection. */
243 XColor *selFgColorPtr; /* Foreground color for selected text.
244 * This is a copy of information in
245 * *cursorTagPtr, so it shouldn't be
246 * explicitly freed. */
247 int exportSelection; /* Non-zero means tie "sel" tag to X
248 * selection. */
249 int selLine, selCh; /* Used during multi-pass selection retrievals.
250 * These identify the next character to be
251 * returned from the selection. */
252 int selOffset; /* Offset in selection corresponding to
253 * selLine and selCh. -1 means neither
254 * this information nor selLine or selCh
255 * is of any use. */
256
257 /*
258 * Information related to insertion cursor:
259 */
260
261 TkAnnotation *insertAnnotPtr;
262 /* Always points to annotation for "insert"
263 * mark. */
264 Tk_3DBorder insertBorder; /* Used to draw vertical bar for insertion
265 * cursor. */
266 int insertWidth; /* Total width of insert cursor. */
267 int insertBorderWidth; /* Width of 3-D border around insert cursor. */
268 int insertOnTime; /* Number of milliseconds cursor should spend
269 * in "on" state for each blink. */
270 int insertOffTime; /* Number of milliseconds cursor should spend
271 * in "off" state for each blink. */
272 Tk_TimerToken insertBlinkHandler;
273 /* Timer handler used to blink cursor on and
274 * off. */
275
276 /*
277 * Information used for event bindings associated with tags:
278 */
279
280 Tk_BindingTable bindingTable;
281 /* Table of all bindings currently defined
282 * for this widget. NULL means that no
283 * bindings exist, so the table hasn't been
284 * created. Each "object" used for this
285 * table is the address of a tag. */
286 TkAnnotation *currentAnnotPtr;
287 /* Pointer to annotation for "current" mark,
288 * or NULL if none. */
289 XEvent pickEvent; /* The event from which the current character
290 * was chosen. Must be saved so that we
291 * can repick after insertions and deletions. */
292
293 /*
294 * Miscellaneous additional information:
295 */
296
297 char *yScrollCmd; /* Prefix of command to issue to update
298 * vertical scrollbar when view changes. */
299 int scanMarkLine; /* Line that was at the top of the window
300 * when the scan started. */
301 int scanMarkY; /* Y-position of mouse at time scan started. */
302 int flags; /* Miscellaneous flags; see below for
303 * definitions. */
304 } TkText;
305
306 /*
307 * Flag values for TkText records:
308 *
309 * GOT_SELECTION: Non-zero means we've already claimed the
310 * selection.
311 * INSERT_ON: Non-zero means insertion cursor should be
312 * displayed on screen.
313 * GOT_FOCUS: Non-zero means this window has the input
314 * focus.
315 * BUTTON_DOWN: 1 means that a mouse button is currently
316 * down; this is used to implement grabs
317 * for the duration of button presses.
318 * IN_CURRENT: 1 means that an EnterNotify event has been
319 * delivered to the current character with
320 * no matching LeaveNotify event yet.
321 */
322
323 #define GOT_SELECTION 1
324 #define INSERT_ON 2
325 #define GOT_FOCUS 4
326 #define BUTTON_DOWN 8
327 #define IN_CURRENT 0x10
328
329 /*
330 * The constant below is used to specify a line when what is really
331 * wanted is the entire text. For now, just use a very big number.
332 */
333
334 #define TK_END_OF_TEXT 1000000
335
336 /*
337 * Declarations for variables shared among the text-related files:
338 */
339
340 extern int tkBTreeDebug;
341 extern Tk_Uid tkTextCharUid;
342 extern Tk_Uid tkTextDisabledUid;
343 extern Tk_Uid tkTextNoneUid;
344 extern Tk_Uid tkTextNormalUid;
345 extern Tk_Uid tkTextWordUid;
346
347 /*
348 * Declarations for procedures that are used by the text-related files
349 * but shouldn't be used anywhere else in Tk (or by Tk clients):
350 */
351
352 extern void TkBTreeAddAnnotation _ANSI_ARGS_((
353 TkAnnotation *annotPtr));
354 extern int TkBTreeCharTagged _ANSI_ARGS_((TkTextLine *linePtr,
355 int index, TkTextTag *tagPtr));
356 extern void TkBTreeCheck _ANSI_ARGS_((TkTextBTree tree));
357 extern TkTextBTree TkBTreeCreate _ANSI_ARGS_((void));
358 extern void TkBTreeDestroy _ANSI_ARGS_((TkTextBTree tree));
359 extern void TkBTreeDeleteChars _ANSI_ARGS_((TkTextBTree tree,
360 TkTextLine *line1Ptr, int ch1,
361 TkTextLine *line2Ptr, int ch2));
362 extern TkTextLine * TkBTreeFindLine _ANSI_ARGS_((TkTextBTree tree,
363 int line));
364 extern TkTextTag ** TkBTreeGetTags _ANSI_ARGS_((TkTextBTree tree,
365 TkTextLine *linePtr, int ch, int *numTagsPtr));
366 extern void TkBTreeInsertChars _ANSI_ARGS_((TkTextBTree tree,
367 TkTextLine *linePtr, int ch, char *string));
368 extern int TkBTreeLineIndex _ANSI_ARGS_((TkTextLine *linePtr));
369 extern TkTextLine * TkBTreeNextLine _ANSI_ARGS_((TkTextLine *linePtr));
370 extern int TkBTreeNextTag _ANSI_ARGS_((TkTextSearch *searchPtr));
371 extern int TkBTreeNumLines _ANSI_ARGS_((TkTextBTree tree));
372 extern void TkBTreeRemoveAnnotation _ANSI_ARGS_((
373 TkAnnotation *annotPtr));
374 extern void TkBTreeStartSearch _ANSI_ARGS_((TkTextBTree tree,
375 int line1, int ch1, int line2, int ch2,
376 TkTextTag *tagPtr, TkTextSearch *searchPtr));
377 extern void TkBTreeTag _ANSI_ARGS_((TkTextBTree tree, int line1,
378 int ch1, int line2, int ch2, TkTextTag *tagPtr,
379 int add));
380 extern void TkTextBindProc _ANSI_ARGS_((ClientData clientData,
381 XEvent *eventPtr));
382 extern TkTextLine * TkTextCharAtLoc _ANSI_ARGS_((TkText *textPtr,
383 int x, int y, int *chPtr));
384 extern void TkTextCreateDInfo _ANSI_ARGS_((TkText *textPtr));
385 extern TkTextTag * TkTextCreateTag _ANSI_ARGS_((TkText *textPtr,
386 char *tagName));
387 extern void TkTextFreeDInfo _ANSI_ARGS_((TkText *textPtr));
388 extern void TkTextFreeTag _ANSI_ARGS_((TkTextTag *tagPtr));
389 extern int TkTextGetIndex _ANSI_ARGS_((Tcl_Interp *interp,
390 TkText *textPtr, char *string, int *lineIndexPtr,
391 int *chPtr));
392 extern void TkTextLinesChanged _ANSI_ARGS_((TkText *textPtr,
393 int first, int last));
394 extern void TkTextLostSelection _ANSI_ARGS_((
395 ClientData clientData));
396 extern void TkTextPickCurrent _ANSI_ARGS_((TkText *textPtr,
397 XEvent *eventPtr));
398 extern void TkTextPrintIndex _ANSI_ARGS_((int line, int ch,
399 char *string));
400 extern TkTextLine * TkTextRoundIndex _ANSI_ARGS_((TkText *textPtr,
401 int *lineIndexPtr, int *chPtr));
402 extern void TkTextRedrawRegion _ANSI_ARGS_((TkText *textPtr,
403 int x, int y, int width, int height));
404 extern void TkTextRedrawTag _ANSI_ARGS_((TkText *textPtr,
405 int line1, int ch1, int line2, int ch2,
406 TkTextTag *tagPtr, int withTag));
407 extern void TkTextRelayoutWindow _ANSI_ARGS_((TkText *textPtr));
408 extern TkAnnotation * TkTextSetMark _ANSI_ARGS_((TkText *textPtr, char *name,
409 int line, int ch));
410 extern void TkTextSetView _ANSI_ARGS_((TkText *textPtr,
411 int line, int pickPlace));
412 extern int TkTextTagCmd _ANSI_ARGS_((TkText *textPtr,
413 Tcl_Interp *interp, int argc, char **argv));
414 extern void TkTextUnpickCurrent _ANSI_ARGS_((TkText *textPtr));
415
416 #endif /* _TKTEXT */
Impressum, Datenschutz