Annotation of researchv9/X11/src/X.V11R1/lib/oldXtk/TextKinds.c, revision 1.1.1.1

1.1       root        1: /* $Header: TextKinds.c,v 1.1 87/09/11 07:58:58 toddb Exp $ */
                      2: #ifndef lint
                      3: static char *sccsid = "@(#)TextKinds.c 1.18    2/25/87";
                      4: #endif lint
                      5: 
                      6: /*
                      7:  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
                      8:  * 
                      9:  *                         All Rights Reserved
                     10:  * 
                     11:  * Permission to use, copy, modify, and distribute this software and its 
                     12:  * documentation for any purpose and without fee is hereby granted, 
                     13:  * provided that the above copyright notice appear in all copies and that
                     14:  * both that copyright notice and this permission notice appear in 
                     15:  * supporting documentation, and that the name of Digital Equipment
                     16:  * Corporation not be used in advertising or publicity pertaining to
                     17:  * distribution of the software without specific, written prior permission.  
                     18:  * 
                     19:  * 
                     20:  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
                     21:  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
                     22:  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
                     23:  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
                     24:  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
                     25:  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
                     26:  * SOFTWARE.
                     27:  */
                     28: 
                     29: #include "Xlib.h"
                     30: #include "Intrinsic.h"
                     31: #include "Text.h"
                     32: #include "Atoms.h"
                     33: #include "TextDisp.h"
                     34: #include <strings.h>
                     35: 
                     36: extern char *tmpnam();
                     37: 
                     38: /* ||| Bogus definitions to go in some .h file */
                     39: 
                     40: extern int *XtDiskSourceCreate (/* name, mode */);
                     41:     /* char       *name;       */
                     42:     /* XtEditType mode;                */
                     43: 
                     44: extern int *XtStringSourceCreate (/* str, maxLength, mode */);
                     45:     /* char            *str;           */
                     46:     /* int             maxLength;      */      
                     47:     /* XtEditType      mode;           */
                     48: 
                     49: 
                     50: /* Private definitions. */
                     51: 
                     52: typedef enum TextKinds {diskText, stringText};
                     53: 
                     54: static XtEditType editMode;
                     55: static XtEditType defaultEditMode = XttextRead;
                     56: static XFontStruct *defaultFont;
                     57: static XFontStruct *textFontStruct;
                     58: static char *nullValue = NULL;
                     59: static int *source, textLength;
                     60: static int defaultLength = 100;
                     61: static int foreground, background;
                     62: static char *fileName, *textString;
                     63: 
                     64: static Resource rawResources[] = {
                     65:     {XtNfont, XtCFont, XrmRFontStruct, sizeof (XFontStruct *),
                     66:         (caddr_t) &textFontStruct, (caddr_t) &defaultFont},
                     67:     {XtNforeground, XtCColor, XrmRPixel, sizeof (int),
                     68:         (caddr_t) &foreground, (caddr_t) &XtDefaultFGPixel},
                     69:     {XtNbackground, XtCColor, XrmRPixel, sizeof (int),
                     70:         (caddr_t) &background, (caddr_t) &XtDefaultBGPixel},
                     71: };
                     72: 
                     73: static Resource stringResources[] = {
                     74:     {XtNforeground, XtCColor, XrmRPixel, sizeof (int),
                     75:         (caddr_t) &foreground, (caddr_t) &XtDefaultFGPixel},
                     76:     {XtNbackground, XtCColor, XrmRPixel, sizeof (int),
                     77:         (caddr_t) &background, (caddr_t) &XtDefaultBGPixel},
                     78:     {XtNstring, XtCString, XrmRString, sizeof (char *),
                     79:         (caddr_t) &textString, (caddr_t) &nullValue},
                     80:     {XtNfont, XtCFont, XrmRFontStruct, sizeof (XFontStruct *),
                     81:         (caddr_t) &textFontStruct, (caddr_t) &defaultFont},
                     82:     {XtNlength, XtCLength, XrmRInt, sizeof (int), (caddr_t) &textLength,
                     83:         (caddr_t)&defaultLength},
                     84:     {XtNeditType, XtCEditType, XtREditMode, sizeof(editMode), 
                     85:        (caddr_t)&editMode, (caddr_t)&defaultEditMode},
                     86: };
                     87: 
                     88: static Resource diskResources[] = {
                     89:     {XtNforeground, XtCColor, XrmRPixel, sizeof (int),
                     90:         (caddr_t) &foreground, (caddr_t) &XtDefaultFGPixel},
                     91:     {XtNbackground, XtCColor, XrmRPixel, sizeof (int),
                     92:         (caddr_t) &background, (caddr_t) &XtDefaultBGPixel},
                     93:     {XtNfile, XtCFile, XrmRString, sizeof (char *),
                     94:         (caddr_t) &fileName, (caddr_t) &nullValue},
                     95:     {XtNfont, XtCFont, XrmRFontStruct, sizeof (XFontStruct *),
                     96:         (caddr_t) &textFontStruct, (caddr_t) &defaultFont},
                     97:     {XtNeditType, XtCEditType, XtREditMode, sizeof(editMode), 
                     98:        (caddr_t)&editMode, (caddr_t)&defaultEditMode},
                     99: };
                    100: 
                    101: static Boolean initialized = FALSE;
                    102: 
                    103: static TextKindsInitialize(dpy)
                    104: Display *dpy;
                    105: {
                    106:     if (initialized)
                    107:        return;
                    108:     initialized = TRUE;
                    109: 
                    110:     defaultFont = XLoadQueryFont(dpy, "fixed");
                    111: }
                    112: 
                    113: static Window AsciiTextCreate(dpy, parent, args, argCount, names, classes, src)
                    114:     Display    *dpy;
                    115:     Window     parent;
                    116:     Arg        *args;
                    117:     int        argCount;
                    118:     XrmNameList        names;
                    119:     XrmClassList classes;
                    120:     int        *src;
                    121: {
                    122:     Window textWidget;
                    123:     ArgList mergedArgs;
                    124:     Arg myArgs[2];
                    125: 
                    126:     XtSetArg(myArgs[0], XtNtextSource, (XtArgVal) src);
                    127:     XtSetArg(myArgs[1], XtNtextSink, 
                    128:        (XtArgVal) XtAsciiSinkCreate(dpy, textFontStruct,
                    129:                                     foreground, background));
                    130: 
                    131:     mergedArgs = XtMergeArgLists(args, argCount, myArgs, XtNumber(myArgs) );
                    132:     textWidget = XtTextCreate(
                    133:        dpy, parent, mergedArgs, argCount+XtNumber(myArgs));
                    134: 
                    135:     XtSetNameAndClass(dpy, textWidget, names, classes);
                    136:     XrmFreeNameList(names);
                    137:     XrmFreeClassList(classes);
                    138:     XtFree((char *) mergedArgs);
                    139:     return textWidget;
                    140: }
                    141: 
                    142: /* Public routines. */
                    143: 
                    144: Window XtTextDiskCreate(dpy, parent, args, argCount)
                    145:     Display    *dpy;
                    146:     Window  parent;
                    147:     ArgList args;
                    148:     int     argCount;
                    149: {
                    150:     XrmNameList        names;
                    151:     XrmClassList classes;
                    152:     char *tmpName;
                    153: 
                    154:     if (!initialized) TextKindsInitialize(dpy);
                    155:     XtGetResources (dpy,
                    156:        diskResources, XtNumber(diskResources), args, argCount, parent,
                    157:        "text", "Text", &names, &classes);
                    158:     /* NOTE:  Do not want to leave temp file around.  Must be unlinked
                    159:     somewhere */
                    160:     if (fileName == NULL) {
                    161:        tmpName = tmpnam (fileName);
                    162:        fileName = XtMalloc (sizeof (tmpName));
                    163:        (void) strcpy (fileName, tmpName);
                    164:     }
                    165:     source = XtDiskSourceCreate (fileName, editMode);
                    166:     return (AsciiTextCreate (dpy, parent, args, argCount, names, classes, source));
                    167: }
                    168: 
                    169: XtTextDiskDestroy(dpy, w)
                    170:   Display *dpy;
                    171:   Window w;
                    172: {
                    173:     XDestroyWindow(dpy, w);
                    174:     (void) XtSendDestroyNotify(dpy, w);
                    175: }
                    176: 
                    177: Window XtTextStringCreate(dpy, parent, args, argCount)
                    178:     Display *dpy;
                    179:     Window  parent;
                    180:     ArgList args;
                    181:     int     argCount;
                    182: {
                    183:     XrmNameList        names;
                    184:     XrmClassList classes;
                    185: 
                    186:     if (!initialized) TextKindsInitialize(dpy);
                    187:     XtGetResources (dpy, stringResources, XtNumber(stringResources), args, argCount,
                    188:         parent, "text", "Text", &names, &classes);
                    189:     if (textString == NULL) {
                    190:        textString = (char *) XtMalloc (1000);
                    191:        textLength = 1000;
                    192:     }
                    193:     /* need option for specifying read append mode */
                    194:     source = XtStringSourceCreate (textString, textLength, editMode);
                    195:     return (AsciiTextCreate (dpy, parent, args, argCount, names, classes, source));
                    196: }
                    197: 
                    198: XtTextStringDestroy(dpy, w)
                    199:   Display *dpy;
                    200:   Window w;
                    201: {
                    202:     XDestroyWindow(dpy, w);
                    203:     (void) XtSendDestroyNotify(dpy, w);
                    204: }
                    205: 
                    206: Window XtTextSourceCreate(dpy, parent, args, argCount, passedSource)
                    207:     Display *dpy;
                    208:     Window  parent;
                    209:     ArgList args;
                    210:     int     argCount;
                    211:     int     *passedSource;  /* ||| NOTE:  should be in args */
                    212: {
                    213:     XrmNameList        names;
                    214:     XrmClassList classes;
                    215: 
                    216:     if (!initialized) TextKindsInitialize(dpy);
                    217:     XtGetResources (dpy, rawResources, XtNumber(rawResources), args, argCount, parent,
                    218:        "text", "Text", &names, &classes);
                    219:     return (AsciiTextCreate (dpy, parent, args, argCount, names, classes,
                    220:         passedSource));
                    221: }
                    222: 
                    223: XtTextSourceDestroy(dpy, w)
                    224:   Display *dpy;
                    225:   Window w;
                    226: {
                    227:     XDestroyWindow(dpy, w);
                    228:     (void) XtSendDestroyNotify(dpy, w);
                    229: }
                    230: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.