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