17a84e134Smrg/*
27a84e134Smrg
37a84e134SmrgCopyright 1987, 1988, 1994, 1998  The Open Group
47a84e134Smrg
57a84e134SmrgPermission to use, copy, modify, distribute, and sell this software and its
67a84e134Smrgdocumentation for any purpose is hereby granted without fee, provided that
77a84e134Smrgthe above copyright notice appear in all copies and that both that
87a84e134Smrgcopyright notice and this permission notice appear in supporting
97a84e134Smrgdocumentation.
107a84e134Smrg
117a84e134SmrgThe above copyright notice and this permission notice shall be included in
127a84e134Smrgall copies or substantial portions of the Software.
137a84e134Smrg
147a84e134SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157a84e134SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
167a84e134SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
177a84e134SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
187a84e134SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
197a84e134SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
207a84e134Smrg
217a84e134SmrgExcept as contained in this notice, the name of The Open Group shall not be
227a84e134Smrgused in advertising or otherwise to promote the sale, use or other dealings
237a84e134Smrgin this Software without prior written authorization from The Open Group.
247a84e134Smrg
257a84e134Smrg
267a84e134SmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
277a84e134Smrg
287a84e134Smrg                        All Rights Reserved
297a84e134Smrg
30421c997bSmrgPermission to use, copy, modify, and distribute this software and its
31421c997bSmrgdocumentation for any purpose and without fee is hereby granted,
327a84e134Smrgprovided that the above copyright notice appear in all copies and that
33421c997bSmrgboth that copyright notice and this permission notice appear in
347a84e134Smrgsupporting documentation, and that the name of Digital not be
357a84e134Smrgused in advertising or publicity pertaining to distribution of the
36421c997bSmrgsoftware without specific, written prior permission.
377a84e134Smrg
387a84e134SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
397a84e134SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
407a84e134SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
417a84e134SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
427a84e134SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
437a84e134SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
447a84e134SmrgSOFTWARE.
457a84e134Smrg
467a84e134Smrg*/
477a84e134Smrg
487a84e134Smrg/*
497a84e134Smrg * AsciiText.c - Source code for AsciiText Widget
507a84e134Smrg *
51421c997bSmrg * This Widget is intended to be used as a simple front end to the
527a84e134Smrg * text widget with an ascii source and ascii sink attached to it
537a84e134Smrg *
547a84e134Smrg * Date:    June 29, 1989
557a84e134Smrg *
567a84e134Smrg * By:      Chris D. Peterson
57421c997bSmrg *          MIT X Consortium
587a84e134Smrg *          kit@expo.lcs.mit.edu
597a84e134Smrg */
607a84e134Smrg
617a84e134Smrg#ifdef HAVE_CONFIG_H
627a84e134Smrg#include <config.h>
637a84e134Smrg#endif
647a84e134Smrg#include <stdio.h>
657a84e134Smrg#include <X11/IntrinsicP.h>
667a84e134Smrg#include <X11/StringDefs.h>
677a84e134Smrg#include <X11/Xaw/AsciiTextP.h>
687a84e134Smrg#include <X11/Xaw/AsciiSrcP.h>
697a84e134Smrg#include <X11/Xaw/AsciiSink.h>
707a84e134Smrg#include <X11/Xaw/Cardinals.h>
717a84e134Smrg#include <X11/Xaw/MultiSinkP.h>
727a84e134Smrg#include <X11/Xaw/MultiSrc.h>
737a84e134Smrg#include <X11/Xaw/XawImP.h>
747a84e134Smrg#include <X11/Xaw/XawInit.h>
757a84e134Smrg#include "Private.h"
767a84e134Smrg
777a84e134Smrg#define TAB_COUNT 32
787a84e134Smrg
797a84e134Smrg/*
807a84e134Smrg * Class Methods
817a84e134Smrg */
827a84e134Smrgstatic void XawAsciiInitialize(Widget, Widget, ArgList, Cardinal*);
837a84e134Smrgstatic void XawAsciiDestroy(Widget);
847a84e134Smrg
857a84e134Smrg/*
867a84e134Smrg * From TextSrc.c
877a84e134Smrg */
887a84e134Smrgvoid _XawSourceAddText(Widget, Widget);
897a84e134Smrgvoid _XawSourceRemoveText(Widget, Widget, Bool);
907a84e134Smrg
917a84e134Smrg#define Superclass	(&textClassRec)
927a84e134SmrgAsciiTextClassRec asciiTextClassRec = {
937a84e134Smrg  /* core */
947a84e134Smrg  {
957a84e134Smrg    (WidgetClass)Superclass,		/* superclass */
967a84e134Smrg    "Text",				/* class_name */
977a84e134Smrg    sizeof(AsciiRec),			/* widget_size */
987a84e134Smrg    XawInitializeWidgetSet,		/* class_initialize */
997a84e134Smrg    NULL,				/* class_part_init */
1007a84e134Smrg    False,				/* class_inited */
1017a84e134Smrg    XawAsciiInitialize,			/* initialize */
1027a84e134Smrg    NULL,				/* initialize_hook */
1037a84e134Smrg    XtInheritRealize,			/* realize */
1047a84e134Smrg    NULL,				/* actions */
1057a84e134Smrg    0,					/* num_actions */
1067a84e134Smrg    NULL,				/* resources */
1077a84e134Smrg    0,					/* num_resource */
1087a84e134Smrg    NULLQUARK,				/* xrm_class */
1097a84e134Smrg    True,				/* compress_motion */
1107a84e134Smrg    XtExposeGraphicsExpose |		/* compress_exposure */
1117a84e134Smrg	XtExposeNoExpose,
1127a84e134Smrg    True,				/* compress_enterleave */
1137a84e134Smrg    False,				/* visible_interest */
1147a84e134Smrg    XawAsciiDestroy,			/* destroy */
1157a84e134Smrg    XtInheritResize,			/* resize */
1167a84e134Smrg    XtInheritExpose,			/* expose */
1177a84e134Smrg    NULL,				/* set_values */
1187a84e134Smrg    NULL,				/* set_values_hook */
1197a84e134Smrg    XtInheritSetValuesAlmost,		/* set_values_almost */
1207a84e134Smrg    NULL,				/* get_values_hook */
1217a84e134Smrg    XtInheritAcceptFocus,		/* accept_focus */
1227a84e134Smrg    XtVersion,				/* version */
1237a84e134Smrg    NULL,				/* callback_private */
1247a84e134Smrg    XtInheritTranslations,		/* tm_table */
1257a84e134Smrg    XtInheritQueryGeometry,		/* query_geometry */
126efbcb2bfSmrg    NULL,				/* display_accelerator */
127efbcb2bfSmrg    NULL,				/* extension */
1287a84e134Smrg  },
1297a84e134Smrg  /* simple */
1307a84e134Smrg  {
1317a84e134Smrg    XtInheritChangeSensitive,		/* change_sensitive */
132efbcb2bfSmrg#ifndef OLDXAW
133efbcb2bfSmrg    NULL,
134efbcb2bfSmrg#endif
1357a84e134Smrg  },
1367a84e134Smrg  /* text */
1377a84e134Smrg  {
1387a84e134Smrg    NULL,				/* extension */
1397a84e134Smrg  },
1407a84e134Smrg  /* ascii */
1417a84e134Smrg  {
1427a84e134Smrg    NULL,				/* extension */
1437a84e134Smrg  },
1447a84e134Smrg};
1457a84e134Smrg
1467a84e134SmrgWidgetClass asciiTextWidgetClass = (WidgetClass)&asciiTextClassRec;
1477a84e134Smrg
1487a84e134Smrg#ifdef ASCII_STRING
1497a84e134SmrgAsciiStringClassRec asciiStringClassRec = {
1507a84e134Smrg  /* core */
1517a84e134Smrg  {
1527a84e134Smrg    (WidgetClass)&asciiTextClassRec,	/* superclass */
1537a84e134Smrg    "Text",				/* class_name */
1547a84e134Smrg    sizeof(AsciiStringRec),		/* widget_size */
1557a84e134Smrg    NULL,				/* class_initialize */
1567a84e134Smrg    NULL,				/* class_part_init */
1577a84e134Smrg    False,				/* class_inited */
1587a84e134Smrg    NULL,				/* initialize */
1597a84e134Smrg    NULL,				/* initialize_hook */
1607a84e134Smrg    XtInheritRealize,			/* realize */
1617a84e134Smrg    NULL,				/* actions */
1627a84e134Smrg    0,					/* num_actions */
1637a84e134Smrg    NULL,				/* resources */
1647a84e134Smrg    0,					/* num_resource */
1657a84e134Smrg    NULLQUARK,				/* xrm_class */
1667a84e134Smrg    True,				/* compress_motion */
1677a84e134Smrg    XtExposeGraphicsExpose |		/* compress_exposure */
1687a84e134Smrg	XtExposeNoExpose,
1697a84e134Smrg    True,				/* compress_enterleave */
1707a84e134Smrg    False,				/* visible_interest */
1717a84e134Smrg    NULL,				/* destroy */
1727a84e134Smrg    XtInheritResize,			/* resize */
1737a84e134Smrg    XtInheritExpose,			/* expose */
1747a84e134Smrg    NULL,				/* set_values */
1757a84e134Smrg    NULL,				/* set_values_hook */
1767a84e134Smrg    XtInheritSetValuesAlmost,		/* set_values_almost */
1777a84e134Smrg    NULL,				/* get_values_hook */
1787a84e134Smrg    XtInheritAcceptFocus,		/* accept_focus */
1797a84e134Smrg    XtVersion,				/* version */
1807a84e134Smrg    NULL,				/* callback_private */
1817a84e134Smrg    XtInheritTranslations,		/* tm_table */
1827a84e134Smrg    XtInheritQueryGeometry,		/* query_geometry */
1837a84e134Smrg  },
1847a84e134Smrg  /* simple */
1857a84e134Smrg  {
1867a84e134Smrg    XtInheritChangeSensitive,		/* change_sensitive */
1877a84e134Smrg  },
1887a84e134Smrg  /* text */
1897a84e134Smrg  {
1907a84e134Smrg    NULL,				/* extension */
1917a84e134Smrg  },
1927a84e134Smrg  /* ascii */
1937a84e134Smrg  {
1947a84e134Smrg    NULL,				/* extension */
1957a84e134Smrg  },
1967a84e134Smrg  /* string */
1977a84e134Smrg  {
1987a84e134Smrg    NULL,				/* extension */
1997a84e134Smrg  },
2007a84e134Smrg};
2017a84e134Smrg
2027a84e134SmrgWidgetClass asciiStringWidgetClass = (WidgetClass)&asciiStringClassRec;
2037a84e134Smrg#endif /* ASCII_STRING */
2047a84e134Smrg
2057a84e134Smrg#ifdef ASCII_DISK
2067a84e134SmrgAsciiDiskClassRec asciiDiskClassRec = {
2077a84e134Smrg  /* core */
2087a84e134Smrg  {
2097a84e134Smrg    (WidgetClass)&asciiTextClassRec,	/* superclass */
2107a84e134Smrg    "Text",				/* class_name */
2117a84e134Smrg    sizeof(AsciiDiskRec),		/* widget_size */
2127a84e134Smrg    NULL,				/* class_initialize */
2137a84e134Smrg    NULL,				/* class_part_init */
2147a84e134Smrg    False,				/* class_inited */
2157a84e134Smrg    NULL,				/* initialize */
2167a84e134Smrg    NULL,				/* initialize_hook */
2177a84e134Smrg    XtInheritRealize,			/* realize */
2187a84e134Smrg    NULL,				/* actions */
2197a84e134Smrg    0,					/* num_actions */
2207a84e134Smrg    NULL,				/* resources */
2217a84e134Smrg    0,					/* num_resource */
2227a84e134Smrg    NULLQUARK,				/* xrm_class */
2237a84e134Smrg    True,				/* compress_motion */
2247a84e134Smrg    True,				/* compress_exposure */
2257a84e134Smrg    XtExposeGraphicsExpose |		/* compress_enterleave */
2267a84e134Smrg	XtExposeNoExpose,
2277a84e134Smrg    False,				/* visible_interest */
2287a84e134Smrg    NULL,				/* destroy */
2297a84e134Smrg    XtInheritResize,			/* resize */
2307a84e134Smrg    XtInheritExpose,			/* expose */
2317a84e134Smrg    NULL,				/* set_values */
2327a84e134Smrg    NULL,				/* set_values_hook */
2337a84e134Smrg    XtInheritSetValuesAlmost,		/* set_values_almost */
2347a84e134Smrg    NULL,				/* get_values_hook */
2357a84e134Smrg    XtInheritAcceptFocus,		/* accept_focus */
2367a84e134Smrg    XtVersion,				/* version */
2377a84e134Smrg    NULL,				/* callback_private */
2387a84e134Smrg    XtInheritTranslations,		/* tm_table */
2397a84e134Smrg    XtInheritQueryGeometry,		/* query_geometry */
2407a84e134Smrg  },
2417a84e134Smrg  /* simple */
2427a84e134Smrg  {
2437a84e134Smrg    XtInheritChangeSensitive,		/* change_sensitive */
2447a84e134Smrg  },
2457a84e134Smrg  /* text */
2467a84e134Smrg  {
2477a84e134Smrg    NULL,				/* extension */
2487a84e134Smrg  },
2497a84e134Smrg  /* ascii */
2507a84e134Smrg  {
2517a84e134Smrg    NULL,				/* extension */
2527a84e134Smrg  },
2537a84e134Smrg  /* disk */
2547a84e134Smrg  {
2557a84e134Smrg    NULL,				/* extension */
2567a84e134Smrg  },
2577a84e134Smrg};
2587a84e134Smrg
2597a84e134SmrgWidgetClass asciiDiskWidgetClass = (WidgetClass)&asciiDiskClassRec;
2607a84e134Smrg#endif /* ASCII_DISK */
2617a84e134Smrg
2627a84e134Smrg/*
2637a84e134Smrg * Implementation
2647a84e134Smrg */
2657a84e134Smrgstatic void
2667a84e134SmrgXawAsciiInitialize(Widget request, Widget cnew,
2677a84e134Smrg		   ArgList args, Cardinal *num_args)
2687a84e134Smrg{
2697a84e134Smrg    AsciiWidget w = (AsciiWidget)cnew;
2707a84e134Smrg    int i;
2717a84e134Smrg    int tabs[TAB_COUNT], tab;
2727a84e134Smrg
2737a84e134Smrg    MultiSinkObject sink;
2747a84e134Smrg
2757a84e134Smrg    /* superclass Initialize can't set the following,
2767a84e134Smrg     * as it didn't know the source or sink when it was called
2777a84e134Smrg     */
2787a84e134Smrg    if (XtHeight(request) == DEFAULT_TEXT_HEIGHT)
2797a84e134Smrg	XtHeight(cnew) = DEFAULT_TEXT_HEIGHT;
2807a84e134Smrg
2817a84e134Smrg    /* This is the main change for internationalization  */
2827a84e134Smrg    if (w->simple.international == True) { /* The multi* are international */
2837a84e134Smrg	if (w->text.sink == NULL)
2847a84e134Smrg	    w->text.sink = XtCreateWidget("textSink", multiSinkObjectClass,
2857a84e134Smrg					  cnew, args, *num_args);
2867a84e134Smrg	else if (!XtIsSubclass(w->text.sink, multiSinkObjectClass))
2877a84e134Smrg	    XtError("Sink object is not a subclass of multiSink");
2887a84e134Smrg
2897a84e134Smrg	if (w->text.source == NULL)
2907a84e134Smrg	    w->text.source = XtCreateWidget("textSource", multiSrcObjectClass,
2917a84e134Smrg					    cnew, args, *num_args);
2927a84e134Smrg	else if (!XtIsSubclass(w->text.source, multiSrcObjectClass))
2937a84e134Smrg	    XtError("Source object is not a subclass of multiSrc");
2947a84e134Smrg#ifndef OLDXAW
2957a84e134Smrg	else
2967a84e134Smrg	    _XawSourceAddText(w->text.source, cnew);
2977a84e134Smrg#endif
2987a84e134Smrg    }
2997a84e134Smrg    else {
3007a84e134Smrg	if (w->text.sink == NULL)
3017a84e134Smrg	    w->text.sink = XtCreateWidget("textSink", asciiSinkObjectClass,
3027a84e134Smrg					  cnew, args, *num_args);
3037a84e134Smrg	else if (!XtIsSubclass(w->text.source, asciiSinkObjectClass))
3047a84e134Smrg	    XtError("Sink object is not a subclass of asciiSink");
3057a84e134Smrg
3067a84e134Smrg	if (w->text.source == NULL)
3077a84e134Smrg	    w->text.source = XtCreateWidget("textSource", asciiSrcObjectClass,
3087a84e134Smrg					    cnew, args, *num_args);
3097a84e134Smrg	else if (!XtIsSubclass(w->text.source, asciiSrcObjectClass))
3107a84e134Smrg	    XtError("Source object is not a subclass of asciiSrc");
3117a84e134Smrg#ifndef OLDXAW
3127a84e134Smrg	else
3137a84e134Smrg	    _XawSourceAddText(w->text.source, cnew);
3147a84e134Smrg#endif
3157a84e134Smrg    }
3167a84e134Smrg
3177a84e134Smrg    if (XtHeight(w) == DEFAULT_TEXT_HEIGHT)
3185ec34c4cSmrg	XtHeight(w) = (Dimension)(VMargins(w) + XawTextSinkMaxHeight(w->text.sink, 1));
3197a84e134Smrg
3207a84e134Smrg    for (i = 0, tab = 0; i < TAB_COUNT; i++)
3217a84e134Smrg	tabs[i] = (tab += 8);
322421c997bSmrg
3237a84e134Smrg    XawTextSinkSetTabs(w->text.sink, TAB_COUNT, tabs);
3247a84e134Smrg
3257a84e134Smrg    XawTextDisableRedisplay(cnew);
3267a84e134Smrg    XawTextEnableRedisplay(cnew);
3277a84e134Smrg
3287a84e134Smrg    _XawImRegister(cnew);
3297a84e134Smrg
3307a84e134Smrg    /* If we are using a MultiSink we need to tell the input method stuff */
3317a84e134Smrg    if (w->simple.international == True) {
3327a84e134Smrg	Arg list[4];
3337a84e134Smrg	Cardinal ac = 0;
3347a84e134Smrg
3357a84e134Smrg	sink = (MultiSinkObject)w->text.sink;
3367a84e134Smrg	XtSetArg(list[ac], XtNfontSet, sink->multi_sink.fontset);	ac++;
3377a84e134Smrg	XtSetArg(list[ac], XtNinsertPosition, w->text.insertPos);	ac++;
3387a84e134Smrg	XtSetArg(list[ac], XtNforeground, sink->text_sink.foreground);	ac++;
3397a84e134Smrg	XtSetArg(list[ac], XtNbackground, sink->text_sink.background);	ac++;
3407a84e134Smrg	_XawImSetValues(cnew, list, ac);
3417a84e134Smrg    }
3427a84e134Smrg}
3437a84e134Smrg
344421c997bSmrgstatic void
3457a84e134SmrgXawAsciiDestroy(Widget w)
3467a84e134Smrg{
3477a84e134Smrg    AsciiWidget ascii = (AsciiWidget)w;
3487a84e134Smrg
3497a84e134Smrg    _XawImUnregister(w);
3507a84e134Smrg
3517a84e134Smrg    if (w == XtParent(ascii->text.sink))
3527a84e134Smrg	XtDestroyWidget(ascii->text.sink);
3537a84e134Smrg
3547a84e134Smrg#ifdef OLDXAW
3557a84e134Smrg    if (w == XtParent(ascii->text.source))
3567a84e134Smrg	XtDestroyWidget(ascii->text.source);
3577a84e134Smrg#else
3587a84e134Smrg    _XawSourceRemoveText(ascii->text.source, w,
3597a84e134Smrg			 ascii->text.source &&
3607a84e134Smrg			 w == XtParent(ascii->text.source));
3617a84e134Smrg#endif
3627a84e134Smrg}
363