1 /***********************************************************
2 
3 Copyright (c) 1987, 1988, 1994  X Consortium
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11 
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14 
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
25 
26 
27 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
28 
29                         All Rights Reserved
30 
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
38 
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 SOFTWARE.
46 
47 ******************************************************************/
48 
49 #ifndef _XawTextP_h
50 #define _XawTextP_h
51 
52 #include <X11/Xaw3dxft/Text.h>
53 #include <X11/Xaw3dxft/SimpleP.h>
54 #include <X11/Xaw3dxft/Xaw3dXft.h>
55 
56 /****************************************************************
57  *
58  * Text widget private
59  *
60  ****************************************************************/
61 #define MAXCUT	30000	/* Maximum number of characters that can be cut. */
62 
63 #define GETLASTPOS  XawTextSourceScan(ctx->text.source, 0, \
64 				      XawstAll, XawsdRight, 1, TRUE)
65 
66 #define zeroPosition ((XawTextPosition) 0)
67 
68 extern XtActionsRec _XawTextActionsTable[];
69 extern Cardinal _XawTextActionsTableCount;
70 
71 #define XawLF	0x0a
72 #define XawCR	0x0d
73 #define XawTAB	0x09
74 #define XawBS	0x08
75 #define XawSP	0x20
76 #define XawDEL	0x7f
77 #define XawESC  0x1b
78 #define XawBSLASH '\\'
79 
80 /* constants that subclasses may want to know */
81 #define DEFAULT_TEXT_HEIGHT ((Dimension)~0)
82 
83 /* displayable text management data structures */
84 
85 typedef struct {
86   XawTextPosition position;
87   Position y;
88   Dimension textWidth;
89 } XawTextLineTableEntry, *XawTextLineTableEntryPtr;
90 
91 typedef struct {
92     XawTextPosition   left, right;
93     XawTextSelectType type;
94     Atom*	     selections;
95     int		     atom_count;
96     int		     array_size;
97 } XawTextSelection;
98 
99 typedef struct _XawTextSelectionSalt {
100     struct _XawTextSelectionSalt    *next;
101     XawTextSelection	s;
102     /*
103      * The element "contents" stores the CT string which is gotten in the
104      * function _XawTextSaltAwaySelection().
105     */
106     char		*contents;
107     int			length;
108 } XawTextSelectionSalt;
109 
110 /* Line Tables are n+1 long - last position displayed is in last lt entry */
111 typedef struct {
112   XawTextPosition	 top;	/* Top of the displayed text.		*/
113   int			 lines;	/* How many lines in this table.	*/
114   XawTextLineTableEntry *info;  /* A dynamic array, one entry per line  */
115 } XawTextLineTable, *XawTextLineTablePtr;
116 
117 
118 typedef struct _XawTextMargin {
119   Position left, right, top, bottom;
120 } XawTextMargin;
121 
122 #define VMargins(ctx) ( (ctx)->text.margin.top + (ctx)->text.margin.bottom )
123 #define HMargins(ctx) ( (ctx)->text.margin.left + (ctx)->text.margin.right )
124 
125 #define IsPositionVisible(ctx, pos) \
126 		(pos >= ctx->text.lt.info[0].position && \
127 		 pos < ctx->text.lt.info[ctx->text.lt.lines].position)
128 
129 /*
130  * Search & Replace data structure.
131  */
132 
133 struct SearchAndReplace {
134   Boolean selection_changed;	/* flag so that the selection cannot be
135 				   changed out from underneath query-replace.*/
136   Widget search_popup;		/* The poppup widget that allows searches.*/
137   Widget label1;		/* The label widgets for the search window. */
138   Widget label2;
139   Widget left_toggle;		/* The left search toggle radioGroup. */
140   Widget right_toggle;		/* The right search toggle radioGroup. */
141   Widget rep_label;		/* The Replace label string. */
142   Widget rep_text;		/* The Replace text field. */
143   Widget search_text;		/* The Search text field. */
144   Widget rep_one;		/* The Replace one button. */
145   Widget rep_all;		/* The Replace all button. */
146 };
147 
148 /* Private Text Definitions */
149 
150 /* New fields for the Text widget class record */
151 
152 typedef struct {int empty;} TextClassPart;
153 
154 struct text_move {
155     int h, v;
156     struct text_move * next;
157 };
158 
159 /* Full class record declaration */
160 typedef struct _TextClassRec {
161     CoreClassPart	core_class;
162     SimpleClassPart	simple_class;
163     TextClassPart	text_class;
164 } TextClassRec;
165 
166 extern TextClassRec textClassRec;
167 
168 /* New fields for the Text widget record */
169 typedef struct _TextPart {
170     /* resources */
171 
172     Widget              source, sink;
173     XawTextPosition	insertPos;
174     XawTextSelection	s;
175     XawTextSelectType	*sarray;	   /* Array to cycle for selections. */
176     XawTextSelectionSalt    *salt;	     /* salted away selections */
177     int			options;	     /* wordbreak, scroll, etc. */
178     int			dialog_horiz_offset; /* position for popup dialog */
179     int			dialog_vert_offset;  /* position for popup dialog */
180     Boolean		display_caret;	     /* insertion pt visible iff T */
181     Boolean             auto_fill;           /* Auto fill mode? */
182     XawTextScrollMode   scroll_vert, scroll_horiz; /*what type of scrollbars.*/
183     XawTextWrapMode     wrap;            /* The type of wrapping. */
184     XawTextResizeMode   resize;	             /* what to resize */
185     XawTextMargin       r_margin;            /* The real margins. */
186     XtCallbackList	unrealize_callbacks; /* used for scrollbars */
187 
188     /* private state */
189     XawTextMargin       margin;            /* The current margins. */
190     XawTextLineTable	lt;
191     XawTextScanDirection extendDir;
192     XawTextSelection	origSel;    /* the selection being modified */
193     Time	    lasttime;	    /* timestamp of last processed action */
194     Time	    time;	    /* time of last key or button action */
195     Position	    ev_x, ev_y;	    /* x, y coords for key or button action */
196     Widget          vbar, hbar;	    /* The scroll bars (none = NULL). */
197     struct SearchAndReplace * search;/* Search and replace structure. */
198     Widget          file_insert;    /* The file insert popup widget. */
199     XawTextPosition  *updateFrom;   /* Array of start positions for update. */
200     XawTextPosition  *updateTo;	    /* Array of end positions for update. */
201     int		    numranges;	    /* How many update ranges there are. */
202     int		    maxranges;	    /* How many ranges we have space for */
203     XawTextPosition  lastPos;	    /* Last position of source. */
204     GC              gc;
205     Boolean	    showposition;   /* True if we need to show the position. */
206     Boolean         hasfocus;       /* TRUE if we currently have input focus.*/
207     Boolean	    update_disabled; /* TRUE if display updating turned off */
208     Boolean         single_char;    /* Single character replaced. */
209     XawTextPosition  old_insert;    /* Last insertPos for batched updates */
210     short           mult;	    /* Multiplier. */
211     struct text_move * copy_area_offsets; /* Text offset area (linked list) */
212     Widget          threeD;	    /* shadow drawing */
213 
214     /* private state, shared w/Source and Sink */
215     Boolean	    redisplay_needed; /* in SetValues */
216     XawTextSelectionSalt    *salt2;	     /* salted away selections */
217     XIC             xic;	/* used to handle UTF8 input */
218     XIM             xim;	/* used to handle UTF8 input */
219 } TextPart;
220 
221 /*************************************************************
222  *
223  * Resource types private to Text widget.
224  *
225  *************************************************************/
226 
227 #define XtRScrollMode "ScrollMode"
228 #define XtRWrapMode "WrapMode"
229 #define XtRResizeMode "ResizeMode"
230 
231 /****************************************************************
232  *
233  * Full instance record declaration
234  *
235  ****************************************************************/
236 
237 typedef struct _TextRec {
238     CorePart	core;
239     SimplePart	simple;
240     TextPart	text;
241 } TextRec;
242 
243 /********************************************
244  *
245  * Semi-private functions
246  * for use by other Xaw modules only
247  *
248  *******************************************/
249 
250 extern void _XawTextBuildLineTable (
251     TextWidget /*ctx*/,
252     XawTextPosition /*top pos*/,
253     _XtBoolean /* force_rebuild */
254 );
255 
256 extern char* _XawTextGetSTRING(
257     TextWidget /*ctx*/,
258     XawTextPosition /*left*/,
259     XawTextPosition /*right*/
260 );
261 
262 extern void _XawTextSaltAwaySelection(
263     TextWidget /*ctx*/,
264     Atom* /*selections*/,
265     int /*num_atoms*/
266 );
267 
268 extern void _XawTextPosToXY(
269     Widget			/* w */,
270     XawTextPosition		/* pos */,
271     Position *			/* x */,
272     Position *			/*y */
273 );
274 
275 #endif /* _XawTextP_h */
276 
277 
278