AsciiText.c revision 421c997b
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 */ 1267a84e134Smrg }, 1277a84e134Smrg /* simple */ 1287a84e134Smrg { 1297a84e134Smrg XtInheritChangeSensitive, /* change_sensitive */ 1307a84e134Smrg }, 1317a84e134Smrg /* text */ 1327a84e134Smrg { 1337a84e134Smrg NULL, /* extension */ 1347a84e134Smrg }, 1357a84e134Smrg /* ascii */ 1367a84e134Smrg { 1377a84e134Smrg NULL, /* extension */ 1387a84e134Smrg }, 1397a84e134Smrg}; 1407a84e134Smrg 1417a84e134SmrgWidgetClass asciiTextWidgetClass = (WidgetClass)&asciiTextClassRec; 1427a84e134Smrg 1437a84e134Smrg#ifdef ASCII_STRING 1447a84e134SmrgAsciiStringClassRec asciiStringClassRec = { 1457a84e134Smrg /* core */ 1467a84e134Smrg { 1477a84e134Smrg (WidgetClass)&asciiTextClassRec, /* superclass */ 1487a84e134Smrg "Text", /* class_name */ 1497a84e134Smrg sizeof(AsciiStringRec), /* widget_size */ 1507a84e134Smrg NULL, /* class_initialize */ 1517a84e134Smrg NULL, /* class_part_init */ 1527a84e134Smrg False, /* class_inited */ 1537a84e134Smrg NULL, /* initialize */ 1547a84e134Smrg NULL, /* initialize_hook */ 1557a84e134Smrg XtInheritRealize, /* realize */ 1567a84e134Smrg NULL, /* actions */ 1577a84e134Smrg 0, /* num_actions */ 1587a84e134Smrg NULL, /* resources */ 1597a84e134Smrg 0, /* num_resource */ 1607a84e134Smrg NULLQUARK, /* xrm_class */ 1617a84e134Smrg True, /* compress_motion */ 1627a84e134Smrg XtExposeGraphicsExpose | /* compress_exposure */ 1637a84e134Smrg XtExposeNoExpose, 1647a84e134Smrg True, /* compress_enterleave */ 1657a84e134Smrg False, /* visible_interest */ 1667a84e134Smrg NULL, /* destroy */ 1677a84e134Smrg XtInheritResize, /* resize */ 1687a84e134Smrg XtInheritExpose, /* expose */ 1697a84e134Smrg NULL, /* set_values */ 1707a84e134Smrg NULL, /* set_values_hook */ 1717a84e134Smrg XtInheritSetValuesAlmost, /* set_values_almost */ 1727a84e134Smrg NULL, /* get_values_hook */ 1737a84e134Smrg XtInheritAcceptFocus, /* accept_focus */ 1747a84e134Smrg XtVersion, /* version */ 1757a84e134Smrg NULL, /* callback_private */ 1767a84e134Smrg XtInheritTranslations, /* tm_table */ 1777a84e134Smrg XtInheritQueryGeometry, /* query_geometry */ 1787a84e134Smrg }, 1797a84e134Smrg /* simple */ 1807a84e134Smrg { 1817a84e134Smrg XtInheritChangeSensitive, /* change_sensitive */ 1827a84e134Smrg }, 1837a84e134Smrg /* text */ 1847a84e134Smrg { 1857a84e134Smrg NULL, /* extension */ 1867a84e134Smrg }, 1877a84e134Smrg /* ascii */ 1887a84e134Smrg { 1897a84e134Smrg NULL, /* extension */ 1907a84e134Smrg }, 1917a84e134Smrg /* string */ 1927a84e134Smrg { 1937a84e134Smrg NULL, /* extension */ 1947a84e134Smrg }, 1957a84e134Smrg}; 1967a84e134Smrg 1977a84e134SmrgWidgetClass asciiStringWidgetClass = (WidgetClass)&asciiStringClassRec; 1987a84e134Smrg#endif /* ASCII_STRING */ 1997a84e134Smrg 2007a84e134Smrg#ifdef ASCII_DISK 2017a84e134SmrgAsciiDiskClassRec asciiDiskClassRec = { 2027a84e134Smrg /* core */ 2037a84e134Smrg { 2047a84e134Smrg (WidgetClass)&asciiTextClassRec, /* superclass */ 2057a84e134Smrg "Text", /* class_name */ 2067a84e134Smrg sizeof(AsciiDiskRec), /* widget_size */ 2077a84e134Smrg NULL, /* class_initialize */ 2087a84e134Smrg NULL, /* class_part_init */ 2097a84e134Smrg False, /* class_inited */ 2107a84e134Smrg NULL, /* initialize */ 2117a84e134Smrg NULL, /* initialize_hook */ 2127a84e134Smrg XtInheritRealize, /* realize */ 2137a84e134Smrg NULL, /* actions */ 2147a84e134Smrg 0, /* num_actions */ 2157a84e134Smrg NULL, /* resources */ 2167a84e134Smrg 0, /* num_resource */ 2177a84e134Smrg NULLQUARK, /* xrm_class */ 2187a84e134Smrg True, /* compress_motion */ 2197a84e134Smrg True, /* compress_exposure */ 2207a84e134Smrg XtExposeGraphicsExpose | /* compress_enterleave */ 2217a84e134Smrg XtExposeNoExpose, 2227a84e134Smrg False, /* visible_interest */ 2237a84e134Smrg NULL, /* destroy */ 2247a84e134Smrg XtInheritResize, /* resize */ 2257a84e134Smrg XtInheritExpose, /* expose */ 2267a84e134Smrg NULL, /* set_values */ 2277a84e134Smrg NULL, /* set_values_hook */ 2287a84e134Smrg XtInheritSetValuesAlmost, /* set_values_almost */ 2297a84e134Smrg NULL, /* get_values_hook */ 2307a84e134Smrg XtInheritAcceptFocus, /* accept_focus */ 2317a84e134Smrg XtVersion, /* version */ 2327a84e134Smrg NULL, /* callback_private */ 2337a84e134Smrg XtInheritTranslations, /* tm_table */ 2347a84e134Smrg XtInheritQueryGeometry, /* query_geometry */ 2357a84e134Smrg }, 2367a84e134Smrg /* simple */ 2377a84e134Smrg { 2387a84e134Smrg XtInheritChangeSensitive, /* change_sensitive */ 2397a84e134Smrg }, 2407a84e134Smrg /* text */ 2417a84e134Smrg { 2427a84e134Smrg NULL, /* extension */ 2437a84e134Smrg }, 2447a84e134Smrg /* ascii */ 2457a84e134Smrg { 2467a84e134Smrg NULL, /* extension */ 2477a84e134Smrg }, 2487a84e134Smrg /* disk */ 2497a84e134Smrg { 2507a84e134Smrg NULL, /* extension */ 2517a84e134Smrg }, 2527a84e134Smrg}; 2537a84e134Smrg 2547a84e134SmrgWidgetClass asciiDiskWidgetClass = (WidgetClass)&asciiDiskClassRec; 2557a84e134Smrg#endif /* ASCII_DISK */ 2567a84e134Smrg 2577a84e134Smrg/* 2587a84e134Smrg * Implementation 2597a84e134Smrg */ 2607a84e134Smrgstatic void 2617a84e134SmrgXawAsciiInitialize(Widget request, Widget cnew, 2627a84e134Smrg ArgList args, Cardinal *num_args) 2637a84e134Smrg{ 2647a84e134Smrg AsciiWidget w = (AsciiWidget)cnew; 2657a84e134Smrg int i; 2667a84e134Smrg int tabs[TAB_COUNT], tab; 2677a84e134Smrg 2687a84e134Smrg MultiSinkObject sink; 2697a84e134Smrg 2707a84e134Smrg /* superclass Initialize can't set the following, 2717a84e134Smrg * as it didn't know the source or sink when it was called 2727a84e134Smrg */ 2737a84e134Smrg if (XtHeight(request) == DEFAULT_TEXT_HEIGHT) 2747a84e134Smrg XtHeight(cnew) = DEFAULT_TEXT_HEIGHT; 2757a84e134Smrg 2767a84e134Smrg /* This is the main change for internationalization */ 2777a84e134Smrg if (w->simple.international == True) { /* The multi* are international */ 2787a84e134Smrg if (w->text.sink == NULL) 2797a84e134Smrg w->text.sink = XtCreateWidget("textSink", multiSinkObjectClass, 2807a84e134Smrg cnew, args, *num_args); 2817a84e134Smrg else if (!XtIsSubclass(w->text.sink, multiSinkObjectClass)) 2827a84e134Smrg XtError("Sink object is not a subclass of multiSink"); 2837a84e134Smrg 2847a84e134Smrg if (w->text.source == NULL) 2857a84e134Smrg w->text.source = XtCreateWidget("textSource", multiSrcObjectClass, 2867a84e134Smrg cnew, args, *num_args); 2877a84e134Smrg else if (!XtIsSubclass(w->text.source, multiSrcObjectClass)) 2887a84e134Smrg XtError("Source object is not a subclass of multiSrc"); 2897a84e134Smrg#ifndef OLDXAW 2907a84e134Smrg else 2917a84e134Smrg _XawSourceAddText(w->text.source, cnew); 2927a84e134Smrg#endif 2937a84e134Smrg } 2947a84e134Smrg else { 2957a84e134Smrg if (w->text.sink == NULL) 2967a84e134Smrg w->text.sink = XtCreateWidget("textSink", asciiSinkObjectClass, 2977a84e134Smrg cnew, args, *num_args); 2987a84e134Smrg else if (!XtIsSubclass(w->text.source, asciiSinkObjectClass)) 2997a84e134Smrg XtError("Sink object is not a subclass of asciiSink"); 3007a84e134Smrg 3017a84e134Smrg if (w->text.source == NULL) 3027a84e134Smrg w->text.source = XtCreateWidget("textSource", asciiSrcObjectClass, 3037a84e134Smrg cnew, args, *num_args); 3047a84e134Smrg else if (!XtIsSubclass(w->text.source, asciiSrcObjectClass)) 3057a84e134Smrg XtError("Source object is not a subclass of asciiSrc"); 3067a84e134Smrg#ifndef OLDXAW 3077a84e134Smrg else 3087a84e134Smrg _XawSourceAddText(w->text.source, cnew); 3097a84e134Smrg#endif 3107a84e134Smrg } 3117a84e134Smrg 3127a84e134Smrg if (XtHeight(w) == DEFAULT_TEXT_HEIGHT) 3137a84e134Smrg XtHeight(w) = VMargins(w) + XawTextSinkMaxHeight(w->text.sink, 1); 3147a84e134Smrg 3157a84e134Smrg for (i = 0, tab = 0; i < TAB_COUNT; i++) 3167a84e134Smrg tabs[i] = (tab += 8); 317421c997bSmrg 3187a84e134Smrg XawTextSinkSetTabs(w->text.sink, TAB_COUNT, tabs); 3197a84e134Smrg 3207a84e134Smrg XawTextDisableRedisplay(cnew); 3217a84e134Smrg XawTextEnableRedisplay(cnew); 3227a84e134Smrg 3237a84e134Smrg _XawImRegister(cnew); 3247a84e134Smrg 3257a84e134Smrg /* If we are using a MultiSink we need to tell the input method stuff */ 3267a84e134Smrg if (w->simple.international == True) { 3277a84e134Smrg Arg list[4]; 3287a84e134Smrg Cardinal ac = 0; 3297a84e134Smrg 3307a84e134Smrg sink = (MultiSinkObject)w->text.sink; 3317a84e134Smrg XtSetArg(list[ac], XtNfontSet, sink->multi_sink.fontset); ac++; 3327a84e134Smrg XtSetArg(list[ac], XtNinsertPosition, w->text.insertPos); ac++; 3337a84e134Smrg XtSetArg(list[ac], XtNforeground, sink->text_sink.foreground); ac++; 3347a84e134Smrg XtSetArg(list[ac], XtNbackground, sink->text_sink.background); ac++; 3357a84e134Smrg _XawImSetValues(cnew, list, ac); 3367a84e134Smrg } 3377a84e134Smrg} 3387a84e134Smrg 339421c997bSmrgstatic void 3407a84e134SmrgXawAsciiDestroy(Widget w) 3417a84e134Smrg{ 3427a84e134Smrg AsciiWidget ascii = (AsciiWidget)w; 3437a84e134Smrg 3447a84e134Smrg _XawImUnregister(w); 3457a84e134Smrg 3467a84e134Smrg if (w == XtParent(ascii->text.sink)) 3477a84e134Smrg XtDestroyWidget(ascii->text.sink); 3487a84e134Smrg 3497a84e134Smrg#ifdef OLDXAW 3507a84e134Smrg if (w == XtParent(ascii->text.source)) 3517a84e134Smrg XtDestroyWidget(ascii->text.source); 3527a84e134Smrg#else 3537a84e134Smrg _XawSourceRemoveText(ascii->text.source, w, 3547a84e134Smrg ascii->text.source && 3557a84e134Smrg w == XtParent(ascii->text.source)); 3567a84e134Smrg#endif 3577a84e134Smrg} 358