1 #if ( !defined(lint) && !defined(SABER) )
2 static char Xrcsid
[] = "$XConsortium: TextSrc.c,v 1.4 89/10/31 17:12:19 kit Exp $";
6 * Copyright 1989 Massachusetts Institute of Technology
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that
11 * copyright notice and this permission notice appear in supporting
12 * documentation, and that the name of M.I.T. not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission. M.I.T. makes no representations about the
15 * suitability of this software for any purpose. It is provided "as is"
16 * without express or implied warranty.
18 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
20 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
22 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
23 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * Author: Chris Peterson, MIT X Consortium.
27 * Much code taken from X11R3 String and Disk Sources.
31 * TextSrc.c - TextSrc object. (For use with the text widget).
37 #include <X11/IntrinsicP.h>
38 #include <X11/StringDefs.h>
39 #include <./Xaw3_1XawInit.h>
40 #include <./Xaw3_1TextSrcP.h>
42 /****************************************************************
44 * Full class record constant
46 ****************************************************************/
50 #define offset(field) XtOffset(TextSrcObject, textSrc.field)
51 static XtResource resources
[] = {
52 {XtNeditType
, XtCEditType
, XtREditMode
, sizeof(XawTextEditType
),
53 offset(edit_mode
), XtRString
, "read"},
56 static void ClassPartInitialize(), SetSelection();
57 static Boolean
ConvertSelection();
58 static XawTextPosition
Search(), Scan(), Read();
61 #define SuperClass (&objectClassRec)
62 TextSrcClassRec textSrcClassRec
= {
64 /* core_class fields */
65 /* superclass */ (WidgetClass
) SuperClass
,
66 /* class_name */ "TextSrc",
67 /* widget_size */ sizeof(TextSrcRec
),
68 /* class_initialize */ XawInitializeWidgetSet
,
69 /* class_part_initialize */ ClassPartInitialize
,
70 /* class_inited */ FALSE
,
71 /* initialize */ NULL
,
72 /* initialize_hook */ NULL
,
76 /* resources */ resources
,
77 /* num_resources */ XtNumber(resources
),
78 /* xrm_class */ NULLQUARK
,
79 /* compress_motion */ FALSE
,
80 /* compress_exposure */ FALSE
,
81 /* compress_enterleave */ FALSE
,
82 /* visible_interest */ FALSE
,
86 /* set_values */ NULL
,
87 /* set_values_hook */ NULL
,
88 /* set_values_almost */ NULL
,
89 /* get_values_hook */ NULL
,
90 /* accept_focus */ NULL
,
91 /* version */ XtVersion
,
92 /* callback_private */ NULL
,
94 /* query_geometry */ NULL
,
95 /* display_accelerator */ NULL
,
98 /* textSrc_class fields */
101 /* Replace */ Replace
,
104 /* SetSelection */ SetSelection
,
105 /* ConvertSelection */ ConvertSelection
109 WidgetClass textSrcObjectClass
= (WidgetClass
)&textSrcClassRec
;
112 ClassPartInitialize(wc
)
115 register TextSrcObjectClass t_src
, superC
;
117 t_src
= (TextSrcObjectClass
) wc
;
118 superC
= (TextSrcObjectClass
) t_src
->object_class
.superclass
;
121 * We don't need to check for null super since we'll get to TextSrc
125 if (t_src
->textSrc_class
.Read
== XtInheritRead
)
126 t_src
->textSrc_class
.Read
= superC
->textSrc_class
.Read
;
128 if (t_src
->textSrc_class
.Replace
== XtInheritReplace
)
129 t_src
->textSrc_class
.Replace
= superC
->textSrc_class
.Replace
;
131 if (t_src
->textSrc_class
.Scan
== XtInheritScan
)
132 t_src
->textSrc_class
.Scan
= superC
->textSrc_class
.Scan
;
134 if (t_src
->textSrc_class
.Search
== XtInheritSearch
)
135 t_src
->textSrc_class
.Search
= superC
->textSrc_class
.Search
;
137 if (t_src
->textSrc_class
.SetSelection
== XtInheritSetSelection
)
138 t_src
->textSrc_class
.SetSelection
= superC
->textSrc_class
.SetSelection
;
140 if (t_src
->textSrc_class
.ConvertSelection
== XtInheritConvertSelection
)
141 t_src
->textSrc_class
.ConvertSelection
=
142 superC
->textSrc_class
.ConvertSelection
;
145 /************************************************************
147 * Class specific methods.
149 ************************************************************/
151 /* Function Name: Read
152 * Description: This function reads the source.
153 * Arguments: w - the TextSrc Object.
154 * pos - position of the text to retreive.
155 * RETURNED text - text block that will contain returned text.
156 * length - maximum number of characters to read.
157 * Returns: The number of characters read into the buffer.
161 static XawTextPosition
162 Read(w
, pos
, text
, length
)
168 XtAppError(XtWidgetToApplicationContext(w
),
169 "TextSrc Object: No read function is defined.");
172 /* Function Name: Replace.
173 * Description: Replaces a block of text with new text.
174 * Arguments: src - the Text Source Object.
175 * startPos, endPos - ends of text that will be removed.
176 * text - new text to be inserted into buffer at startPos.
177 * Returns: XawEditError.
182 Replace (w
, startPos
, endPos
, text
)
184 XawTextPosition startPos
, endPos
;
187 return(XawEditError
);
190 /* Function Name: Scan
191 * Description: Scans the text source for the number and type
193 * Arguments: w - the TextSrc Object.
194 * position - the position to start scanning.
195 * type - type of thing to scan for.
196 * dir - direction to scan.
197 * count - which occurance if this thing to search for.
198 * include - whether or not to include the character found in
199 * the position that is returned.
200 * Returns: EXITS WITH AN ERROR MESSAGE.
207 Scan (w
, position
, type
, dir
, count
, include
)
209 XawTextPosition position
;
210 XawTextScanType type
;
211 XawTextScanDirection dir
;
215 XtAppError(XtWidgetToApplicationContext(w
),
216 "TextSrc Object: No SCAN function is defined.");
219 /* Function Name: Search
220 * Description: Searchs the text source for the text block passed
221 * Arguments: w - the TextSource Object.
222 * position - the position to start scanning.
223 * dir - direction to scan.
224 * text - the text block to search for.
225 * Returns: XawTextSearchError.
229 static XawTextPosition
230 Search(w
, position
, dir
, text
)
232 XawTextPosition position
;
233 XawTextScanDirection dir
;
236 return(XawTextSearchError
);
239 /* Function Name: ConvertSelection
240 * Description: Dummy selection converter.
241 * Arguments: w - the TextSrc object.
242 * selection - the current selection atom.
243 * target - the current target atom.
244 * type - the type to conver the selection to.
245 * RETURNED value, length - the return value that has been converted.
246 * RETURNED format - the format of the returned value.
247 * Returns: TRUE if the selection has been converted.
253 ConvertSelection(w
, selection
, target
, type
, value
, length
, format
)
255 Atom
* selection
, * target
, * type
;
257 unsigned long * length
;
263 /* Function Name: SetSelection
264 * Description: allows special setting of the selection.
265 * Arguments: w - the TextSrc object.
266 * left, right - bounds of the selection.
267 * selection - the selection atom.
273 SetSelection(w
, left
, right
, selection
)
275 XawTextPosition left
, right
;
278 /* This space intentionally left blank. */
281 /************************************************************
285 ************************************************************/
287 /* Function Name: XawTextSourceRead
288 * Description: This function reads the source.
289 * Arguments: w - the TextSrc Object.
290 * pos - position of the text to retreive.
291 * RETURNED text - text block that will contain returned text.
292 * length - maximum number of characters to read.
293 * Returns: The number of characters read into the buffer.
297 XawTextSourceRead(w
, pos
, text
, length
)
303 TextSrcObjectClass
class = (TextSrcObjectClass
) w
->core
.widget_class
;
305 return((*class->textSrc_class
.Read
)(w
, pos
, text
, length
));
308 /* Function Name: XawTextSourceReplace.
309 * Description: Replaces a block of text with new text.
310 * Arguments: src - the Text Source Object.
311 * startPos, endPos - ends of text that will be removed.
312 * text - new text to be inserted into buffer at startPos.
313 * Returns: XawEditError or XawEditDone.
318 XawTextSourceReplace (w
, startPos
, endPos
, text
)
320 XawTextPosition startPos
, endPos
;
323 TextSrcObjectClass
class = (TextSrcObjectClass
) w
->core
.widget_class
;
325 return((*class->textSrc_class
.Replace
)(w
, startPos
, endPos
, text
));
328 /* Function Name: XawTextSourceScan
329 * Description: Scans the text source for the number and type
331 * Arguments: w - the TextSrc Object.
332 * position - the position to start scanning.
333 * type - type of thing to scan for.
334 * dir - direction to scan.
335 * count - which occurance if this thing to search for.
336 * include - whether or not to include the character found in
337 * the position that is returned.
338 * Returns: The position of the text.
343 XawTextSourceScan(w
, position
, type
, dir
, count
, include
)
345 XawTextPosition position
;
346 XawTextScanType type
;
347 XawTextScanDirection dir
;
351 TextSrcObjectClass
class = (TextSrcObjectClass
) w
->core
.widget_class
;
353 return((*class->textSrc_class
.Scan
)(w
, position
, type
, dir
, count
, include
));
356 /* Function Name: XawTextSourceSearch
357 * Description: Searchs the text source for the text block passed
358 * Arguments: w - the TextSource Object.
359 * position - the position to start scanning.
360 * dir - direction to scan.
361 * text - the text block to search for.
362 * Returns: The position of the text we are searching for or
363 * XawTextSearchError.
367 XawTextSourceSearch(w
, position
, dir
, text
)
369 XawTextPosition position
;
370 XawTextScanDirection dir
;
373 TextSrcObjectClass
class = (TextSrcObjectClass
) w
->core
.widget_class
;
375 return((*class->textSrc_class
.Search
)(w
, position
, dir
, text
));
378 /* Function Name: XawTextSourceConvertSelection
379 * Description: Dummy selection converter.
380 * Arguments: w - the TextSrc object.
381 * selection - the current selection atom.
382 * target - the current target atom.
383 * type - the type to conver the selection to.
384 * RETURNED value, length - the return value that has been converted.
385 * RETURNED format - the format of the returned value.
386 * Returns: TRUE if the selection has been converted.
391 XawTextSourceConvertSelection(w
, selection
,
392 target
, type
, value
, length
, format
)
394 Atom
* selection
, * target
, * type
;
396 unsigned long * length
;
399 TextSrcObjectClass
class = (TextSrcObjectClass
) w
->core
.widget_class
;
401 return((*class->textSrc_class
.ConvertSelection
)(w
, selection
, target
, type
,
402 value
, length
, format
));
405 /* Function Name: XawTextSourceSetSelection
406 * Description: allows special setting of the selection.
407 * Arguments: w - the TextSrc object.
408 * left, right - bounds of the selection.
409 * selection - the selection atom.
414 XawTextSourceSetSelection(w
, left
, right
, selection
)
416 XawTextPosition left
, right
;
419 TextSrcObjectClass
class = (TextSrcObjectClass
) w
->core
.widget_class
;
421 (*class->textSrc_class
.SetSelection
)(w
, left
, right
, selection
);