8e2f0aa66719b498af070499e4431b66146cd805
[framework/uifw/xorg/lib/libxaw.git] / src / AsciiText.c
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  *          kit@expo.lcs.mit.edu
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   },
127   /* simple */
128   {
129     XtInheritChangeSensitive,           /* change_sensitive */
130   },
131   /* text */
132   {
133     NULL,                               /* extension */
134   },
135   /* ascii */
136   {
137     NULL,                               /* extension */
138   },
139 };
140
141 WidgetClass asciiTextWidgetClass = (WidgetClass)&asciiTextClassRec;
142
143 #ifdef ASCII_STRING
144 AsciiStringClassRec asciiStringClassRec = {
145   /* core */
146   {
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 */
156     NULL,                               /* actions */
157     0,                                  /* num_actions */
158     NULL,                               /* resources */
159     0,                                  /* num_resource */
160     NULLQUARK,                          /* xrm_class */
161     True,                               /* compress_motion */
162     XtExposeGraphicsExpose |            /* compress_exposure */
163         XtExposeNoExpose,
164     True,                               /* compress_enterleave */
165     False,                              /* visible_interest */
166     NULL,                               /* destroy */
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 */
178   },
179   /* simple */
180   {
181     XtInheritChangeSensitive,           /* change_sensitive */
182   },
183   /* text */
184   {
185     NULL,                               /* extension */
186   },
187   /* ascii */
188   {
189     NULL,                               /* extension */
190   },
191   /* string */
192   {
193     NULL,                               /* extension */
194   },
195 };
196
197 WidgetClass asciiStringWidgetClass = (WidgetClass)&asciiStringClassRec;
198 #endif /* ASCII_STRING */
199
200 #ifdef ASCII_DISK
201 AsciiDiskClassRec asciiDiskClassRec = {
202   /* core */
203   {
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 */
213     NULL,                               /* actions */
214     0,                                  /* num_actions */
215     NULL,                               /* resources */
216     0,                                  /* num_resource */
217     NULLQUARK,                          /* xrm_class */
218     True,                               /* compress_motion */
219     True,                               /* compress_exposure */
220     XtExposeGraphicsExpose |            /* compress_enterleave */
221         XtExposeNoExpose,
222     False,                              /* visible_interest */
223     NULL,                               /* destroy */
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 */
235   },
236   /* simple */
237   {
238     XtInheritChangeSensitive,           /* change_sensitive */
239   },
240   /* text */
241   {
242     NULL,                               /* extension */
243   },
244   /* ascii */
245   {
246     NULL,                               /* extension */
247   },
248   /* disk */
249   {
250     NULL,                               /* extension */
251   },
252 };
253
254 WidgetClass asciiDiskWidgetClass = (WidgetClass)&asciiDiskClassRec;
255 #endif /* ASCII_DISK */
256
257 /*
258  * Implementation
259  */
260 static void
261 XawAsciiInitialize(Widget request, Widget cnew,
262                    ArgList args, Cardinal *num_args)
263 {
264     AsciiWidget w = (AsciiWidget)cnew;
265     int i;
266     int tabs[TAB_COUNT], tab;
267
268     MultiSinkObject sink;
269
270     /* superclass Initialize can't set the following,
271      * as it didn't know the source or sink when it was called
272      */
273     if (XtHeight(request) == DEFAULT_TEXT_HEIGHT)
274         XtHeight(cnew) = DEFAULT_TEXT_HEIGHT;
275
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");
283
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");
289 #ifndef OLDXAW
290         else
291             _XawSourceAddText(w->text.source, cnew);
292 #endif
293     }
294     else {
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");
300
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");
306 #ifndef OLDXAW
307         else
308             _XawSourceAddText(w->text.source, cnew);
309 #endif
310     }
311
312     if (XtHeight(w) == DEFAULT_TEXT_HEIGHT)
313         XtHeight(w) = VMargins(w) + XawTextSinkMaxHeight(w->text.sink, 1);
314
315     for (i = 0, tab = 0; i < TAB_COUNT; i++)
316         tabs[i] = (tab += 8);
317
318     XawTextSinkSetTabs(w->text.sink, TAB_COUNT, tabs);
319
320     XawTextDisableRedisplay(cnew);
321     XawTextEnableRedisplay(cnew);
322
323     _XawImRegister(cnew);
324
325     /* If we are using a MultiSink we need to tell the input method stuff */
326     if (w->simple.international == True) {
327         Arg list[4];
328         Cardinal ac = 0;
329
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);
336     }
337 }
338
339 static void
340 XawAsciiDestroy(Widget w)
341 {
342     AsciiWidget ascii = (AsciiWidget)w;
343
344     _XawImUnregister(w);
345
346     if (w == XtParent(ascii->text.sink))
347         XtDestroyWidget(ascii->text.sink);
348
349 #ifdef OLDXAW
350     if (w == XtParent(ascii->text.source))
351         XtDestroyWidget(ascii->text.source);
352 #else
353     _XawSourceRemoveText(ascii->text.source, w,
354                          ascii->text.source &&
355                          w == XtParent(ascii->text.source));
356 #endif
357 }