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