1 /**
2  *
3  * $Header: /cvsroot/lesstif/lesstif/include/Motif-2.1/Xm/TextFP.h,v 1.1 2004/08/28 19:23:26 dannybackx Exp $
4  *
5  * Copyright (C) 1995 Free Software Foundation, Inc.
6  * Copyright � 1995-2001, 2002 LessTif Development Team
7  *
8  * This file is part of the GNU LessTif Library.
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the Free
22  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  **/
25 
26 #ifndef _XM_TEXTFP_H
27 #define _XM_TEXTFP_H
28 
29 #include <Xm/PrimitiveP.h>
30 #include <Xm/TextF.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 typedef struct {
37 	Boolean Echo;		/* Echo characters to window? */
38 	Boolean AllowSelection;	/* Allow selections to be copied/pasted? */
39 
40 	  /* Stuff that will go away with the Clipboard routines */
41 	char *SelectionText;	/* pointer to text selection, when needed */
42 	int SelectionLen;		/* length */
43 
44 	XmTextPosition OldHighlightStart;	/* save data */
45 	XmTextPosition OldHighlightEnd;
46 	XmTextPosition OldCursorPos;	/* previous position */
47 	int OldCursorX;		/* previous pixel pos of cursor */
48 
49 	int FastInsertCursorStart;	/* data storage for some text optimization */
50 	int FastInsertTextLen;
51 
52 	Dimension FontHeight;
53 	int XDraw;			/* x location of text drawing area */
54 	int YDraw;			/* y location of text drawing area */
55 	int XOffset;		/* offset from x=0 to start of text string */
56 	int OldXOffset;
57 	int YOffset;		/* y pixel offset to baseline of font */
58 	int TextWidth;		/* char width of text */
59 	int OldTextWidth;
60 } XmTextFieldPartLesstifExtension;
61 
62 typedef struct {
63 	XtCallbackList activate_callback;	/* Command activate callback */
64 	XtCallbackList focus_callback;		/* Verify losing focus callback */
65 	XtCallbackList losing_focus_callback;	/* Verify losing focus callback */
66 	XtCallbackList modify_verify_callback;	/* Verify value to change callback */
67 	XtCallbackList wcs_modify_verify_callback; /* Verify value to change callback */
68 	XtCallbackList motion_verify_callback; /* Verify insert cursor position to
69 						  change callback */
70 	XtCallbackList gain_primary_callback; /* Gained ownership of Primary Selection */
71 	XtCallbackList lose_primary_callback; /* Lost ownership of Primary Selection */
72 	XtCallbackList value_changed_callback; /* Notify that value has change callback */
73 	char * value;		/* pointer to widget value stored as char* */
74 	wchar_t * wc_value;		/* pointer to widget value stored as wchar_t* */
75 
76 	XmFontList font_list;	/* Uses only the font portion of fontlist */
77 	XFontStruct *font;	        /* font retrieved from the fontlist */
78 	XmTextScanType *selection_array; /* Description of what to cycle
79 					     through on selections */
80 	_XmHighlightData highlight;    /* Info on the highlighting regions. */
81 
82 	GC gc;			/* Normal GC for drawing text and cursor */
83 	GC image_gc;		/* Image GC for drawing text cursor*/
84 	GC save_gc;                 /* GC for saving/restoring under IBeam */
85 
86 	Pixmap ibeam_off;		/* pixmap for area under the IBeam */
87 	Pixmap add_mode_cursor;	/* The add mode cursor pixmap */
88 	Pixmap cursor;		/* The ibeam cursor stencil */
89 	Pixmap putback;		/* AVAILABLE: was in 1.1 but not really used */
90 	Pixmap stipple_tile;	/* The tile pattern for the stippled I-beam */
91 	Pixmap image_clip;		/* The clip rect needed for image gc */
92 
93 	XmTextPosition cursor_position;/* CursorPos - text cursor position */
94 	XmTextPosition new_h_offset;/* Used in setvaluesalmost proc */
95 	XmTextPosition h_offset;  	/* The x position of the first character
96 	                               (relative to left edge of the widget) */
97 	XmTextPosition orig_left;     /* unused */
98 	XmTextPosition orig_right;    /* unused */
99 	XmTextPosition prim_pos_left; /* HighlightStart */
100 	XmTextPosition prim_pos_right; /* HighlightEnd */
101 	XmTextPosition prim_anchor;	/* HighlightPivot */
102 
103 	XmTextPosition sec_pos_left; /* usused */
104 	XmTextPosition sec_pos_right; /* usused */
105 	XmTextPosition sec_anchor;	/* usused */
106 
107 	XmTextPosition stuff_pos;	/* Position to stuff the primary selection */
108 
109 	Position select_pos_x;    /* x position for timer-based scrolling */
110 
111 	Time prim_time;             /* Timestamp of primary selection */
112 	Time dest_time;             /* Timestamp of destination selection */
113 	Time sec_time;              /* Timestamp of secondary selection */
114 	Time last_time;             /* Time of last selection event */
115 
116 	XtIntervalId timer_id;	/* Blinking cursor timer */
117 	XtIntervalId select_id;     /* Timer based scrolling identifier */
118 
119 	int blink_rate;		/* Rate of blinking text cursor in msec */
120 	int selection_array_count;  /* Selection array count */
121 	int threshold;		/* Selection threshold */
122 	int size_allocd;		/* Size allocated for value string */
123 	int string_length;          /* The number of characters in the string
124 				   (including the trailing NULL) */
125 	int cursor_height;		/* Save cursor dimensions */
126 	int cursor_width;		/* Save cursor dimensions */
127 	int sarray_index;		/* Index into selection array */
128 	int max_length;		/* Maximum number of character that can be
129 				   inserted into the text field widget */
130 
131 	int max_char_size;          /* Max bytes per character in cur locale */
132 	short columns;		/* The number of characters in the width */
133 
134 	Dimension margin_width;	/* Height between text borders and text */
135 	Dimension margin_height;	/* Width between text borders and text */
136 	Dimension average_char_width;/* Average character width based on font */
137 	Dimension margin_top;   /* Height between text borders and top of text */
138 	Dimension margin_bottom;/* Height between text borders and bottom of text */
139 	Dimension font_ascent;  /* Ascent of font or fontset used by widget */
140 	Dimension font_descent;  /* Descent of font or fontset used by widget */
141 
142 	Boolean resize_width;	/* Allows the widget to grow horizontally
143 				   when borders are reached */
144 	Boolean pending_delete;	/* Delete primary selection on insert when
145 				   set to True */
146 	Boolean editable;		/* Sets editablility of text */
147 	Boolean verify_bell;          /* Determines if bell is sounded when verify
148 	                               *  callback returns doit - False
149 	                               */
150 	Boolean cursor_position_visible;	/* Sets visibility of insert cursor */
151 
152 	Boolean traversed;          /* Flag used with losing focus verification to
153 	                               indicate a traversal key pressed event */
154 	Boolean add_mode;		/* Add mode for cursor movement */
155 	Boolean has_focus;		/* Flag that indicates whether the widget
156 			           has input focus */
157 	Boolean blink_on;		/* State of Blinking insert cursor */
158 	short int cursor_on;	/* Indicates whether the cursor is visible */
159 	Boolean refresh_ibeam_off;	/* Indicates whether the area under IBeam needs
160 				   to be re-captured */
161 	Boolean have_inverted_image_gc;  /* fg/bg of image gc have been swapped */
162 	Boolean has_primary;	/* Indicates that is has the
163 				   primary selection */
164 	Boolean has_secondary;	/* Indicates that is has the
165 				   secondary selection */
166 	Boolean has_destination;	/* Indicates that is has the
167 				   destination selection */
168 	Boolean sec_drag;           /* Indicates a secondary drag was made */
169 	Boolean selection_move;	/* Indicates that the action requires a
170 				   secondary move (i.e. copy & cut) */
171 	Boolean pending_off;	/* indicates pending delete state */
172 	Boolean fontlist_created;   /* Indicates that the text field widget created
173 				   it's own fontlist */
174 	Boolean has_rect;		/* currently has clipping rectangle */
175 	Boolean do_drop;		/* Indicates that the widget the recieved the
176 				   button release, did not have a previous
177 	                               button press, so it is o.k. to request
178 				   the MOTIF_DROP selection. */
179 	Boolean cancel;		/* Cancels selection actions when true */
180 	Boolean extending;		/* Indicates extending primary selection */
181 	Boolean sec_extending;      /* Indicates extending secondary selection */
182 	Boolean changed_visible;    /* Indicates whether the dest_visible flag
183 	                               is in a temporary changed state */
184 	Boolean have_fontset;       /* The widgets font is a fontset, not a
185 				 * fontstruct... use R5 draw routines */
186 	Boolean in_setvalues;	/* used to disable unnecessary redisplays */
187 	Boolean do_resize;		/* used to prevent inappropriate resizes */
188 	Boolean redisplay;		/* used to set redisplay flag in setvalues */
189 	Boolean overstrike;		/* overstrike mode for character input */
190 	Boolean sel_start;		/* overstrike mode for character input */
191 	XtPointer extension;	/* Pointer to extension record. */
192 
193 #ifdef BIDI
194 /* BIDI: Add the following for bi-directional text support */
195 	XmTextMode text_mode;       /* mode is VISUAL, IMPLICIT */
196 	XmCsdMode  csd_mode;        /* csd is AUTO,INITIAL,MIDDLE,FINAL, etc.*/
197 	XmNssMode  nss_mode;        /* nss is BILINGUAL,ARABIC.HINDU or PASSTHR */
198 	Boolean symmetric_swap;     /* should we perform symmetric swapping? */
199 	Boolean expand_tail;        /* should we expand the tail for seen family */
200 	Boolean word_break;
201 	Boolean text_compose;       /* composed tashkeel over letter */
202 /* end BIDI */
203 #endif
204 
205 	Boolean	check_set_render_table;
206 	Boolean	use_xft;
207 } XmTextFieldPart;
208 
209 /* Define the full instance record */
210 typedef struct _XmTextFieldRec {
211 	CorePart core;
212 	XmPrimitivePart primitive;
213 	XmTextFieldPart text;
214 } XmTextFieldRec;
215 
216 /* Define class part structure */
217 typedef struct {
218 	XtPointer extension;
219 } XmTextFieldClassPart;
220 
221 /* Define the full class record */
222 typedef struct _XmTextFieldClassRec {
223 	CoreClassPart core_class;
224 	XmPrimitiveClassPart primitive_class;
225 	XmTextFieldClassPart textfield_class;
226 } XmTextFieldClassRec;
227 
228 /* External definition for class record */
229 
230 XMLIBEXPORT extern XmTextFieldClassRec xmTextFieldClassRec;
231 
232 #define TF_ALLOC_SIZE 256
233 
234 #define TextF__(w) ((XmTextFieldWidget)(w))->text
235 #define TextF__E__(w) ((XmTextFieldPartLesstifExtension *) (((XmTextFieldWidget)(w))->text.extension))
236 
237 #define TextF_Alloc(w) (TextF__(w).size_allocd)
238 #define TextF_BlinkRate(w) (TextF__(w).blink_rate)
239 #define TextF_BlinkOn(w) (TextF__(w).blink_on)
240 #define TextF_Columns(w) (TextF__(w).columns)
241 #define TextF_CursorPos(w) (TextF__(w).cursor_position)
242 #define TextF_CursorPositionVisible(w) (TextF__(w).cursor_position_visible)
243 #define TextF_Editable(w) (TextF__(w).editable)
244 #define TextF_Font(w) (TextF__(w).font)
245 #define TextF_FontList(w) (TextF__(w).font_list)
246 #define TextF_FontListCreated(w) (TextF__(w).fontlist_created)
247 #define TextF_HasFocus(w) (TextF__(w).has_focus)
248 #define TextF_HighlightStart(w) (TextF__(w).prim_pos_left)
249 #define TextF_HighlightEnd(w) (TextF__(w).prim_pos_right)
250 #define TextF_HighlightPivot(w) (TextF__(w).prim_anchor)
251 #define TextF_SecondaryStart(w) (TextF__(w).sec_pos_left)
252 #define TextF_SecondaryEnd(w) (TextF__(w).sec_pos_right)
253 #define TextF_SecondaryPivot(w) (TextF__(w).sec_anchor)
254 #define TextF_MarginHeight(w) (TextF__(w).margin_height)
255 #define TextF_MarginWidth(w) (TextF__(w).margin_width)
256 #define TextF_MaxLength(w) (TextF__(w).max_length)
257 #define TextF_Length(w) (TextF__(w).string_length)
258 #define TextF_PendingDelete(w) (TextF__(w).pending_delete)
259 #define TextF_ResizeWidth(w) (TextF__(w).resize_width)
260 #define TextF_SelectId(w) (TextF__(w).select_id)
261 #define TextF_SelectionArray(w) (TextF__(w).selection_array)
262 #define TextF_SelectionArrayCount(w) (TextF__(w).selection_array_count)
263 #define TextF_SelectThreshold(w) (TextF__(w).select_threshold)
264 #define TextF_TimerId(w) (TextF__(w).timer_id)
265 #define TextF_Value(w) (TextF__(w).value)
266 #define TextF_ValueWcs(w) (TextF__(w).wc_value)
267 #define TextF_VerifyBell(w) (TextF__(w).verify_bell)
268 #define TextF_ViewHeight(w) (TextF__(w).margin_top)
269 #define TextF_ViewWidth(w) (TextF__(w).margin_bottom)
270 
271 #define TextF_HighlightMode(w) (TextF__(w).highlight.list->mode)
272 
273 
274 	/* Lesstif Extensions */
275 #define TextF_XOffset(w) (TextF__E__(w)->XOffset)
276 #define TextF_YOffset(w) (TextF__E__(w)->YOffset)
277 #define TextF_OldXOffset(w) (TextF__E__(w)->OldXOffset)
278 #define TextF_OldCursorPos(w) (TextF__E__(w)->OldCursorPos)
279 #define TextF_OldCursorX(w) (TextF__E__(w)->OldCursorX)
280 #define TextF_Echo(w) (TextF__E__(w)->Echo)
281 #define TextF_AllowSelection(w) (TextF__E__(w)->AllowSelection)
282 #define TextF_SelectionText(w) (TextF__E__(w)->SelectionText)
283 #define TextF_SelectionLen(w) (TextF__E__(w)->SelectionLen)
284 #define TextF_OldHighlightStart(w) (TextF__E__(w)->OldHighlightStart)
285 #define TextF_OldHighlightEnd(w) (TextF__E__(w)->OldHighlightEnd)
286 #define TextF_FastInsertCursorStart(w) (TextF__E__(w)->FastInsertCursorStart)
287 #define TextF_FastInsertTextLen(w) (TextF__E__(w)->FastInsertTextLen)
288 #define TextF_FontHeight(w) (TextF__E__(w)->FontHeight)
289 #define TextF_XDraw(w) (TextF__E__(w)->XDraw)
290 #define TextF_YDraw(w) (TextF__E__(w)->YDraw)
291 #define TextF_TextWidth(w) (TextF__E__(w)->TextWidth)
292 #define TextF_OldTextWidth(w) (TextF__E__(w)->OldTextWidth)
293 
294 #define TextF_ActivateCallback(w) (TextF__(w).activate_callback)
295 #define TextF_FocusCallback(w) (TextF__(w).focus_callback)
296 #define TextF_LosingFocusCallback(w) (TextF__(w).losing_focus_callback)
297 #define TextF_ModifyVerifyCallback(w) (TextF__(w).modify_verify_callback)
298 #define TextF_WcsModifyVerifyCallback(w) (TextF__(w).wcs_modify_verify_callback)
299 #define TextF_MotionVerifyCallback(w) (TextF__(w).motion_verify_callback)
300 #define TextF_GainPrimaryCallback(w) (TextF__(w).gain_primary_callback)
301 #define TextF_LosePrimaryCallback(w) (TextF__(w).lose_primary_callback)
302 #define TextF_ValueChangedCallback(w) (TextF__(w).value_changed_callback)
303 
304 	/* GC stuff */
305 #define TextF_DrawGC(w) (TextF__(w).gc)		/* drawing and copying */
306 #define TextF_DrawGCInverted(w) (TextF__(w).have_inverted_image_gc)
307 #define TextF_CursorGC(w) (TextF__(w).image_gc) /* highlighting text */
308 #define TextF_CopyGC(w) (TextF__(w).save_gc)     /* cursor (not clipped) */
309 #define TextF_CursorSave(w) (TextF__(w).ibeam_off)
310 #define TextF_CursorSaveValid(w) (TextF__(w).refresh_ibeam_off)
311 #define TextF_CursorIBeam(w) (TextF__(w).cursor)
312 #define TextF_CursorAddMode(w) (TextF__(w).add_mode_cursor)
313 #define TextF_AddMode(w) (TextF__(w).add_mode)
314 #define TextF_CursorStipple(w) (TextF__(w).stipple_tile)
315 
316 	/* Font functions */
317 #define TextF_FontTextWidth(w,s,l) (int)XTextWidth(TextF__(w).font, s, l)
318 #define TextF_FontAverageWidth(w) (TextF__(w).average_char_width)
319 
320 #ifdef	USE_XFT
321 #define TextF_FontAscent(w)			\
322 	(TextF_UseXft(w) ? 			\
323 		(TextF_XftFont(w)->ascent) :	\
324 		(TextF__(w).font->max_bounds.ascent))
325 
326 #define TextF_FontDescent(w)			\
327 	(TextF_UseXft(w) ?			\
328 		(TextF_XftFont(w)->descent) :	\
329 		(TextF__(w).font->max_bounds.descent))
330 #else
331 #define TextF_FontAscent(w) (TextF__(w).font->max_bounds.ascent)
332 #define TextF_FontDescent(w) (TextF__(w).font->max_bounds.descent)
333 #endif
334 
335 #define	TextF_UseXft(w)	(((XmTextFieldWidget)(w))->text.use_xft)
336 #define	TextF_XftFont(w)	(((XmTextFieldWidget)(w))->text.font_list->renditions[0]->xft_font)
337 
338 /* Highlight */
339 #define TextF_Highlight(w) (TextF__(w).highlight)
340 
341 #ifdef __cplusplus
342 }
343 #endif
344 
345 #endif /* _XM_TEXTFP_H */
346