Debian Codegraph @

src/AsciiText.c

raw
1 /*
2
3 Copyright 1987, 1988, 1994, 1998 The Open Group
4
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24
25
26 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
27
28 All Rights Reserved
29
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
37
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44 SOFTWARE.
45
46 */
47
48 /*
49 * AsciiText.c - Source code for AsciiText Widget
50 *
51 * This Widget is intended to be used as a simple front end to the
52 * text widget with an ascii source and ascii sink attached to it
53 *
54 * Date: June 29, 1989
55 *
56 * By: Chris D. Peterson
57 * MIT X Consortium
58 * [email protected]
59 */
60
61 #ifdef HAVE_CONFIG_H
62 #include <config.h>
63 #endif
64 #include <stdio.h>
65 #include <X11/IntrinsicP.h>
66 #include <X11/StringDefs.h>
67 #include <X11/Xaw/AsciiTextP.h>
68 #include <X11/Xaw/AsciiSrcP.h>
69 #include <X11/Xaw/AsciiSink.h>
70 #include <X11/Xaw/Cardinals.h>
71 #include <X11/Xaw/MultiSinkP.h>
72 #include <X11/Xaw/MultiSrc.h>
73 #include <X11/Xaw/XawImP.h>
74 #include <X11/Xaw/XawInit.h>
75 #include "Private.h"
76
77 #define TAB_COUNT 32
78
79 /*
80 * Class Methods
81 */
82 static void XawAsciiInitialize(Widget, Widget, ArgList, Cardinal*);
83 static void XawAsciiDestroy(Widget);
84
85 /*
86 * From TextSrc.c
87 */
88 void _XawSourceAddText(Widget, Widget);
89 void _XawSourceRemoveText(Widget, Widget, Bool);
90
91 #define Superclass (&textClassRec)
92 AsciiTextClassRec asciiTextClassRec = {
93 /* core */
94 {
95 (WidgetClass)Superclass, /* superclass */
96 "Text", /* class_name */
97 sizeof(AsciiRec), /* widget_size */
98 XawInitializeWidgetSet, /* class_initialize */
99 NULL, /* class_part_init */
100 False, /* class_inited */
101 XawAsciiInitialize, /* initialize */
102 NULL, /* initialize_hook */
103 XtInheritRealize, /* realize */
104 NULL, /* actions */
105 0, /* num_actions */
106 NULL, /* resources */
107 0, /* num_resource */
108 NULLQUARK, /* xrm_class */
109 True, /* compress_motion */
110 XtExposeGraphicsExpose | /* compress_exposure */
111 XtExposeNoExpose,
112 True, /* compress_enterleave */
113 False, /* visible_interest */
114 XawAsciiDestroy, /* destroy */
115 XtInheritResize, /* resize */
116 XtInheritExpose, /* expose */
117 NULL, /* set_values */
118 NULL, /* set_values_hook */
119 XtInheritSetValuesAlmost, /* set_values_almost */
120 NULL, /* get_values_hook */
121 XtInheritAcceptFocus, /* accept_focus */
122 XtVersion, /* version */
123 NULL, /* callback_private */
124 XtInheritTranslations, /* tm_table */
125 XtInheritQueryGeometry, /* query_geometry */
126 NULL, /* display_accelerator */
127 NULL, /* extension */
128 },
129 /* simple */
130 {
131 XtInheritChangeSensitive, /* change_sensitive */
132 #ifndef OLDXAW
133 NULL,
134 #endif
135 },
136 /* text */
137 {
138 NULL, /* extension */
139 },
140 /* ascii */
141 {
142 NULL, /* extension */
143 },
144 };
145
146 WidgetClass asciiTextWidgetClass = (WidgetClass)&asciiTextClassRec;
147
148 #ifdef ASCII_STRING
149 AsciiStringClassRec asciiStringClassRec = {
150 /* core */
151 {
152 (WidgetClass)&asciiTextClassRec, /* superclass */
153 "Text", /* class_name */
154 sizeof(AsciiStringRec), /* widget_size */
155 NULL, /* class_initialize */
156 NULL, /* class_part_init */
157 False, /* class_inited */
158 NULL, /* initialize */
159 NULL, /* initialize_hook */
160 XtInheritRealize, /* realize */
161 NULL, /* actions */
162 0, /* num_actions */
163 NULL, /* resources */
164 0, /* num_resource */
165 NULLQUARK, /* xrm_class */
166 True, /* compress_motion */
167 XtExposeGraphicsExpose | /* compress_exposure */
168 XtExposeNoExpose,
169 True, /* compress_enterleave */
170 False, /* visible_interest */
171 NULL, /* destroy */
172 XtInheritResize, /* resize */
173 XtInheritExpose, /* expose */
174 NULL, /* set_values */
175 NULL, /* set_values_hook */
176 XtInheritSetValuesAlmost, /* set_values_almost */
177 NULL, /* get_values_hook */
178 XtInheritAcceptFocus, /* accept_focus */
179 XtVersion, /* version */
180 NULL, /* callback_private */
181 XtInheritTranslations, /* tm_table */
182 XtInheritQueryGeometry, /* query_geometry */
183 },
184 /* simple */
185 {
186 XtInheritChangeSensitive, /* change_sensitive */
187 },
188 /* text */
189 {
190 NULL, /* extension */
191 },
192 /* ascii */
193 {
194 NULL, /* extension */
195 },
196 /* string */
197 {
198 NULL, /* extension */
199 },
200 };
201
202 WidgetClass asciiStringWidgetClass = (WidgetClass)&asciiStringClassRec;
203 #endif /* ASCII_STRING */
204
205 #ifdef ASCII_DISK
206 AsciiDiskClassRec asciiDiskClassRec = {
207 /* core */
208 {
209 (WidgetClass)&asciiTextClassRec, /* superclass */
210 "Text", /* class_name */
211 sizeof(AsciiDiskRec), /* widget_size */
212 NULL, /* class_initialize */
213 NULL, /* class_part_init */
214 False, /* class_inited */
215 NULL, /* initialize */
216 NULL, /* initialize_hook */
217 XtInheritRealize, /* realize */
218 NULL, /* actions */
219 0, /* num_actions */
220 NULL, /* resources */
221 0, /* num_resource */
222 NULLQUARK, /* xrm_class */
223 True, /* compress_motion */
224 True, /* compress_exposure */
225 XtExposeGraphicsExpose | /* compress_enterleave */
226 XtExposeNoExpose,
227 False, /* visible_interest */
228 NULL, /* destroy */
229 XtInheritResize, /* resize */
230 XtInheritExpose, /* expose */
231 NULL, /* set_values */
232 NULL, /* set_values_hook */
233 XtInheritSetValuesAlmost, /* set_values_almost */
234 NULL, /* get_values_hook */
235 XtInheritAcceptFocus, /* accept_focus */
236 XtVersion, /* version */
237 NULL, /* callback_private */
238 XtInheritTranslations, /* tm_table */
239 XtInheritQueryGeometry, /* query_geometry */
240 },
241 /* simple */
242 {
243 XtInheritChangeSensitive, /* change_sensitive */
244 },
245 /* text */
246 {
247 NULL, /* extension */
248 },
249 /* ascii */
250 {
251 NULL, /* extension */
252 },
253 /* disk */
254 {
255 NULL, /* extension */
256 },
257 };
258
259 WidgetClass asciiDiskWidgetClass = (WidgetClass)&asciiDiskClassRec;
260 #endif /* ASCII_DISK */
261
262 /*
263 * Implementation
264 */
265 static void
266 XawAsciiInitialize(Widget request, Widget cnew,
267 ArgList args, Cardinal *num_args)
268 {
269 AsciiWidget w = (AsciiWidget)cnew;
270 int i;
271 int tabs[TAB_COUNT], tab;
272
273 MultiSinkObject sink;
274
275 /* superclass Initialize can't set the following,
276 * as it didn't know the source or sink when it was called
277 */
278 if (XtHeight(request) == DEFAULT_TEXT_HEIGHT)
279 XtHeight(cnew) = DEFAULT_TEXT_HEIGHT;
280
281 /* This is the main change for internationalization */
282 if (w->simple.international == True) { /* The multi* are international */
283 if (w->text.sink == NULL)
284 w->text.sink = XtCreateWidget("textSink", multiSinkObjectClass,
285 cnew, args, *num_args);
286 else if (!XtIsSubclass(w->text.sink, multiSinkObjectClass))
287 XtError("Sink object is not a subclass of multiSink");
288
289 if (w->text.source == NULL)
290 w->text.source = XtCreateWidget("textSource", multiSrcObjectClass,
291 cnew, args, *num_args);
292 else if (!XtIsSubclass(w->text.source, multiSrcObjectClass))
293 XtError("Source object is not a subclass of multiSrc");
294 #ifndef OLDXAW
295 else
296 _XawSourceAddText(w->text.source, cnew);
297 #endif
298 }
299 else {
300 if (w->text.sink == NULL)
301 w->text.sink = XtCreateWidget("textSink", asciiSinkObjectClass,
302 cnew, args, *num_args);
303 else if (!XtIsSubclass(w->text.source, asciiSinkObjectClass))
304 XtError("Sink object is not a subclass of asciiSink");
305
306 if (w->text.source == NULL)
307 w->text.source = XtCreateWidget("textSource", asciiSrcObjectClass,
308 cnew, args, *num_args);
309 else if (!XtIsSubclass(w->text.source, asciiSrcObjectClass))
310 XtError("Source object is not a subclass of asciiSrc");
311 #ifndef OLDXAW
312 else
313 _XawSourceAddText(w->text.source, cnew);
314 #endif
315 }
316
317 if (XtHeight(w) == DEFAULT_TEXT_HEIGHT)
318 XtHeight(w) = (Dimension)(VMargins(w) + XawTextSinkMaxHeight(w->text.sink, 1));
319
320 for (i = 0, tab = 0; i < TAB_COUNT; i++)
321 tabs[i] = (tab += 8);
322
323 XawTextSinkSetTabs(w->text.sink, TAB_COUNT, tabs);
324
325 XawTextDisableRedisplay(cnew);
326 XawTextEnableRedisplay(cnew);
327
328 _XawImRegister(cnew);
329
330 /* If we are using a MultiSink we need to tell the input method stuff */
331 if (w->simple.international == True) {
332 Arg list[4];
333 Cardinal ac = 0;
334
335 sink = (MultiSinkObject)w->text.sink;
336 XtSetArg(list[ac], XtNfontSet, sink->multi_sink.fontset); ac++;
337 XtSetArg(list[ac], XtNinsertPosition, w->text.insertPos); ac++;
338 XtSetArg(list[ac], XtNforeground, sink->text_sink.foreground); ac++;
339 XtSetArg(list[ac], XtNbackground, sink->text_sink.background); ac++;
340 _XawImSetValues(cnew, list, ac);
341 }
342 }
343
344 static void
345 XawAsciiDestroy(Widget w)
346 {
347 AsciiWidget ascii = (AsciiWidget)w;
348
349 _XawImUnregister(w);
350
351 if (w == XtParent(ascii->text.sink))
352 XtDestroyWidget(ascii->text.sink);
353
354 #ifdef OLDXAW
355 if (w == XtParent(ascii->text.source))
356 XtDestroyWidget(ascii->text.source);
357 #else
358 _XawSourceRemoveText(ascii->text.source, w,
359 ascii->text.source &&
360 w == XtParent(ascii->text.source));
361 #endif
362 }