rebuild geeqie
[oi-userland.git] / components / x11 / libXaw4 / src / Xaw3_1TextSrc.c
blobe190151bf396577f65ce7cc4bf3bb1751310be86
1 #if ( !defined(lint) && !defined(SABER) )
2 static char Xrcsid[] = "$XConsortium: TextSrc.c,v 1.4 89/10/31 17:12:19 kit Exp $";
3 #endif
5 /*
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).
35 #include <stdio.h>
36 #include <ctype.h>
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 ****************************************************************/
48 /* Private Data */
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();
59 static int Replace();
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,
73 /* realize */ NULL,
74 /* actions */ NULL,
75 /* num_actions */ 0,
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,
83 /* destroy */ NULL,
84 /* resize */ NULL,
85 /* expose */ NULL,
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,
93 /* tm_table */ NULL,
94 /* query_geometry */ NULL,
95 /* display_accelerator */ NULL,
96 /* extension */ NULL
98 /* textSrc_class fields */
100 /* Read */ Read,
101 /* Replace */ Replace,
102 /* Scan */ Scan,
103 /* Search */ Search,
104 /* SetSelection */ SetSelection,
105 /* ConvertSelection */ ConvertSelection
109 WidgetClass textSrcObjectClass = (WidgetClass)&textSrcClassRec;
111 static void
112 ClassPartInitialize(wc)
113 WidgetClass 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
122 * eventually.
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.
160 /* ARGSUSED */
161 static XawTextPosition
162 Read(w, pos, text, length)
163 Widget w;
164 XawTextPosition pos;
165 XawTextBlock *text;
166 int 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.
180 /*ARGSUSED*/
181 static int
182 Replace (w, startPos, endPos, text)
183 Widget w;
184 XawTextPosition startPos, endPos;
185 XawTextBlock *text;
187 return(XawEditError);
190 /* Function Name: Scan
191 * Description: Scans the text source for the number and type
192 * of item specified.
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.
204 /* ARGSUSED */
205 static
206 XawTextPosition
207 Scan (w, position, type, dir, count, include)
208 Widget w;
209 XawTextPosition position;
210 XawTextScanType type;
211 XawTextScanDirection dir;
212 int count;
213 Boolean include;
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.
228 /* ARGSUSED */
229 static XawTextPosition
230 Search(w, position, dir, text)
231 Widget w;
232 XawTextPosition position;
233 XawTextScanDirection dir;
234 XawTextBlock * text;
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.
251 /* ARGSUSED */
252 static Boolean
253 ConvertSelection(w, selection, target, type, value, length, format)
254 Widget w;
255 Atom * selection, * target, * type;
256 caddr_t * value;
257 unsigned long * length;
258 int * format;
260 return(FALSE);
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.
268 * Returns: none
271 /* ARGSUSED */
272 static void
273 SetSelection(w, left, right, selection)
274 Widget w;
275 XawTextPosition left, right;
276 Atom selection;
278 /* This space intentionally left blank. */
281 /************************************************************
283 * Public Functions.
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.
296 XawTextPosition
297 XawTextSourceRead(w, pos, text, length)
298 Widget w;
299 XawTextPosition pos;
300 XawTextBlock *text;
301 int 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.
316 /*ARGSUSED*/
317 int
318 XawTextSourceReplace (w, startPos, endPos, text)
319 Widget w;
320 XawTextPosition startPos, endPos;
321 XawTextBlock *text;
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
330 * of item specified.
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.
342 XawTextPosition
343 XawTextSourceScan(w, position, type, dir, count, include)
344 Widget w;
345 XawTextPosition position;
346 XawTextScanType type;
347 XawTextScanDirection dir;
348 int count;
349 Boolean include;
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.
366 XawTextPosition
367 XawTextSourceSearch(w, position, dir, text)
368 Widget w;
369 XawTextPosition position;
370 XawTextScanDirection dir;
371 XawTextBlock * text;
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.
390 Boolean
391 XawTextSourceConvertSelection(w, selection,
392 target, type, value, length, format)
393 Widget w;
394 Atom * selection, * target, * type;
395 caddr_t * value;
396 unsigned long * length;
397 int * format;
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.
410 * Returns: none
413 void
414 XawTextSourceSetSelection(w, left, right, selection)
415 Widget w;
416 XawTextPosition left, right;
417 Atom selection;
419 TextSrcObjectClass class = (TextSrcObjectClass) w->core.widget_class;
421 (*class->textSrc_class.SetSelection)(w, left, right, selection);