3 Copyright 1987, 1988, 1994, 1998 The Open Group
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
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
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.
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.
26 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
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.
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
49 * AsciiText.c - Source code for AsciiText Widget
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
56 * By: Chris D. Peterson
58 * kit@expo.lcs.mit.edu
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>
82 static void XawAsciiInitialize(Widget, Widget, ArgList, Cardinal*);
83 static void XawAsciiDestroy(Widget);
88 void _XawSourceAddText(Widget, Widget);
89 void _XawSourceRemoveText(Widget, Widget, Bool);
91 #define Superclass (&textClassRec)
92 AsciiTextClassRec asciiTextClassRec = {
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 */
106 NULL, /* resources */
107 0, /* num_resource */
108 NULLQUARK, /* xrm_class */
109 True, /* compress_motion */
110 XtExposeGraphicsExpose | /* compress_exposure */
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 */
129 XtInheritChangeSensitive, /* change_sensitive */
133 NULL, /* extension */
137 NULL, /* extension */
141 WidgetClass asciiTextWidgetClass = (WidgetClass)&asciiTextClassRec;
144 AsciiStringClassRec asciiStringClassRec = {
147 (WidgetClass)&asciiTextClassRec, /* superclass */
148 "Text", /* class_name */
149 sizeof(AsciiStringRec), /* widget_size */
150 NULL, /* class_initialize */
151 NULL, /* class_part_init */
152 False, /* class_inited */
153 NULL, /* initialize */
154 NULL, /* initialize_hook */
155 XtInheritRealize, /* realize */
158 NULL, /* resources */
159 0, /* num_resource */
160 NULLQUARK, /* xrm_class */
161 True, /* compress_motion */
162 XtExposeGraphicsExpose | /* compress_exposure */
164 True, /* compress_enterleave */
165 False, /* visible_interest */
167 XtInheritResize, /* resize */
168 XtInheritExpose, /* expose */
169 NULL, /* set_values */
170 NULL, /* set_values_hook */
171 XtInheritSetValuesAlmost, /* set_values_almost */
172 NULL, /* get_values_hook */
173 XtInheritAcceptFocus, /* accept_focus */
174 XtVersion, /* version */
175 NULL, /* callback_private */
176 XtInheritTranslations, /* tm_table */
177 XtInheritQueryGeometry, /* query_geometry */
181 XtInheritChangeSensitive, /* change_sensitive */
185 NULL, /* extension */
189 NULL, /* extension */
193 NULL, /* extension */
197 WidgetClass asciiStringWidgetClass = (WidgetClass)&asciiStringClassRec;
198 #endif /* ASCII_STRING */
201 AsciiDiskClassRec asciiDiskClassRec = {
204 (WidgetClass)&asciiTextClassRec, /* superclass */
205 "Text", /* class_name */
206 sizeof(AsciiDiskRec), /* widget_size */
207 NULL, /* class_initialize */
208 NULL, /* class_part_init */
209 False, /* class_inited */
210 NULL, /* initialize */
211 NULL, /* initialize_hook */
212 XtInheritRealize, /* realize */
215 NULL, /* resources */
216 0, /* num_resource */
217 NULLQUARK, /* xrm_class */
218 True, /* compress_motion */
219 True, /* compress_exposure */
220 XtExposeGraphicsExpose | /* compress_enterleave */
222 False, /* visible_interest */
224 XtInheritResize, /* resize */
225 XtInheritExpose, /* expose */
226 NULL, /* set_values */
227 NULL, /* set_values_hook */
228 XtInheritSetValuesAlmost, /* set_values_almost */
229 NULL, /* get_values_hook */
230 XtInheritAcceptFocus, /* accept_focus */
231 XtVersion, /* version */
232 NULL, /* callback_private */
233 XtInheritTranslations, /* tm_table */
234 XtInheritQueryGeometry, /* query_geometry */
238 XtInheritChangeSensitive, /* change_sensitive */
242 NULL, /* extension */
246 NULL, /* extension */
250 NULL, /* extension */
254 WidgetClass asciiDiskWidgetClass = (WidgetClass)&asciiDiskClassRec;
255 #endif /* ASCII_DISK */
261 XawAsciiInitialize(Widget request, Widget cnew,
262 ArgList args, Cardinal *num_args)
264 AsciiWidget w = (AsciiWidget)cnew;
266 int tabs[TAB_COUNT], tab;
268 MultiSinkObject sink;
270 /* superclass Initialize can't set the following,
271 * as it didn't know the source or sink when it was called
273 if (XtHeight(request) == DEFAULT_TEXT_HEIGHT)
274 XtHeight(cnew) = DEFAULT_TEXT_HEIGHT;
276 /* This is the main change for internationalization */
277 if (w->simple.international == True) { /* The multi* are international */
278 if (w->text.sink == NULL)
279 w->text.sink = XtCreateWidget("textSink", multiSinkObjectClass,
280 cnew, args, *num_args);
281 else if (!XtIsSubclass(w->text.sink, multiSinkObjectClass))
282 XtError("Sink object is not a subclass of multiSink");
284 if (w->text.source == NULL)
285 w->text.source = XtCreateWidget("textSource", multiSrcObjectClass,
286 cnew, args, *num_args);
287 else if (!XtIsSubclass(w->text.source, multiSrcObjectClass))
288 XtError("Source object is not a subclass of multiSrc");
291 _XawSourceAddText(w->text.source, cnew);
295 if (w->text.sink == NULL)
296 w->text.sink = XtCreateWidget("textSink", asciiSinkObjectClass,
297 cnew, args, *num_args);
298 else if (!XtIsSubclass(w->text.source, asciiSinkObjectClass))
299 XtError("Sink object is not a subclass of asciiSink");
301 if (w->text.source == NULL)
302 w->text.source = XtCreateWidget("textSource", asciiSrcObjectClass,
303 cnew, args, *num_args);
304 else if (!XtIsSubclass(w->text.source, asciiSrcObjectClass))
305 XtError("Source object is not a subclass of asciiSrc");
308 _XawSourceAddText(w->text.source, cnew);
312 if (XtHeight(w) == DEFAULT_TEXT_HEIGHT)
313 XtHeight(w) = VMargins(w) + XawTextSinkMaxHeight(w->text.sink, 1);
315 for (i = 0, tab = 0; i < TAB_COUNT; i++)
316 tabs[i] = (tab += 8);
318 XawTextSinkSetTabs(w->text.sink, TAB_COUNT, tabs);
320 XawTextDisableRedisplay(cnew);
321 XawTextEnableRedisplay(cnew);
323 _XawImRegister(cnew);
325 /* If we are using a MultiSink we need to tell the input method stuff */
326 if (w->simple.international == True) {
330 sink = (MultiSinkObject)w->text.sink;
331 XtSetArg(list[ac], XtNfontSet, sink->multi_sink.fontset); ac++;
332 XtSetArg(list[ac], XtNinsertPosition, w->text.insertPos); ac++;
333 XtSetArg(list[ac], XtNforeground, sink->text_sink.foreground); ac++;
334 XtSetArg(list[ac], XtNbackground, sink->text_sink.background); ac++;
335 _XawImSetValues(cnew, list, ac);
340 XawAsciiDestroy(Widget w)
342 AsciiWidget ascii = (AsciiWidget)w;
346 if (w == XtParent(ascii->text.sink))
347 XtDestroyWidget(ascii->text.sink);
350 if (w == XtParent(ascii->text.source))
351 XtDestroyWidget(ascii->text.source);
353 _XawSourceRemoveText(ascii->text.source, w,
354 ascii->text.source &&
355 w == XtParent(ascii->text.source));