Annotation of researchv9/X11/src/X.V11R1/lib/oldXtk/TextActs.c, revision 1.1

1.1     ! root        1: /* $Header: TextActs.c,v 1.1 87/09/11 07:59:49 toddb Exp $ */
        !             2: #ifndef lint
        !             3: static char *sccsid = "@(#)TextActions.c       1.17    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: 
        !            30: #include "Xlib.h"
        !            31: #include "Intrinsic.h"
        !            32: #include "Text.h"
        !            33: #include "TextDisp.h"
        !            34: #include "Dialog.h"
        !            35: #include <sys/file.h>
        !            36: 
        !            37: #define min(x,y)        ((x) < (y) ? (x) : (y))
        !            38: #define max(x,y)        ((x) > (y) ? (x) : (y))
        !            39: 
        !            40: /* ||| Kludge, declar in .h file somewhere */
        !            41: 
        !            42: extern char *_XtTextGetText(); /* ctx, left, right */
        !            43:     /* TextContext    *ctx;            */
        !            44:     /* XtTextPosition left, right;     */
        !            45: 
        !            46: extern caddr_t XtSetActionBindings();/* eventTable, actionTable, defaultValue */
        !            47:     /* XtEventsPtr  eventTable;                */
        !            48:     /* XtActionsPtr actionTable;       */
        !            49:     /* caddr_t             defaultValue;       */
        !            50: 
        !            51: extern void AlterSelection(); /* ctx, mode, action */
        !            52:     /* TextContext     *ctx;                                             */
        !            53:     /* SelectionMode   mode;   /* {XtsmTextSelect, XtsmTextExtend}       */
        !            54:     /* SelectionAction action; /* {XtactionStart, XtactionAdjust, XtactionEnd} */
        !            55: 
        !            56: extern void ForceBuildLineTable(); /* ctx */
        !            57:     /* TextContext *ctx;               */
        !            58: 
        !            59: /* Misc. routines */
        !            60: 
        !            61: /*ARGSUSED*/
        !            62: static DoFeep(ctx)
        !            63:     TextContext *ctx;
        !            64: {
        !            65:     XBell(ctx->dpy, 50);
        !            66: }
        !            67: 
        !            68: static DeleteOrKill(ctx, from, to, kill)
        !            69:     TextContext           *ctx;
        !            70:     XtTextPosition from, to;
        !            71:     Boolean       kill;
        !            72: {
        !            73:     XtTextBlock text;
        !            74:     char *ptr;
        !            75: 
        !            76:     if (kill && from < to) {
        !            77:        ptr = _XtTextGetText(ctx, from, to);
        !            78:        XStoreBuffer(ctx->dpy, ptr, strlen(ptr), 1);
        !            79:        XtFree(ptr);
        !            80:     }
        !            81:     text.length = 0;
        !            82:     if (ReplaceText(ctx, from, to, &text)) {
        !            83:        XBell(ctx->dpy, 50);
        !            84:        return;
        !            85:     }
        !            86:     _XtTextSetNewSelection(ctx, from, from);
        !            87:     ctx->insertPos = from;
        !            88:     ctx->showposition = TRUE;
        !            89: }
        !            90: 
        !            91: 
        !            92: StuffFromBuffer(ctx, buffer)
        !            93:   TextContext *ctx;
        !            94:   int buffer;
        !            95: {
        !            96:     extern char *XFetchBuffer();
        !            97:     XtTextBlock text;
        !            98:     text.ptr = XFetchBuffer(ctx->dpy, &(text.length), buffer);
        !            99:     if (ReplaceText(ctx, ctx->insertPos, ctx->insertPos, &text)) {
        !           100:        XBell(ctx->dpy, 50);
        !           101:        return;
        !           102:     }
        !           103:     ctx->insertPos = ctx->source->scan(ctx->source, ctx->insertPos,
        !           104:            XtstPositions, XtsdRight, text.length, TRUE);
        !           105:     _XtTextSetNewSelection(ctx, ctx->insertPos, ctx->insertPos);
        !           106:     XtFree(text.ptr);
        !           107: }
        !           108: 
        !           109: 
        !           110: static UnKill(ctx)
        !           111:   TextContext *ctx;
        !           112: {
        !           113:     StuffFromBuffer(ctx, 1);
        !           114: }
        !           115: 
        !           116: static Stuff(ctx)
        !           117:   TextContext *ctx;
        !           118: {
        !           119:     StuffFromBuffer(ctx, 0);
        !           120: }
        !           121: 
        !           122: 
        !           123: static XtTextPosition NextPosition(ctx, position, kind, direction)
        !           124:     TextContext *ctx;
        !           125:     XtTextPosition position;
        !           126:     ScanType kind;
        !           127:     ScanDirection direction;
        !           128: {
        !           129:     XtTextPosition pos;
        !           130: 
        !           131:      pos = ctx->source->scan(
        !           132:            ctx->source, position, kind, direction, 1, FALSE);
        !           133:      if (pos == ctx->insertPos) 
        !           134:          pos = ctx->source->scan(
        !           135:             ctx->source, position, kind, direction, 2, FALSE);
        !           136:      return pos;
        !           137: }
        !           138: 
        !           139: /* routines for moving around */
        !           140: 
        !           141: static MoveForwardChar(ctx)
        !           142:     TextContext *ctx;
        !           143: {
        !           144:     ctx->insertPos = ctx->source->scan(
        !           145:             ctx->source, ctx->insertPos, XtstPositions, XtsdRight, 1, TRUE);
        !           146: }
        !           147: 
        !           148: static MoveBackwardChar(ctx)
        !           149:     TextContext *ctx;
        !           150: {
        !           151:     ctx->insertPos = ctx->source->scan(
        !           152:             ctx->source, ctx->insertPos, XtstPositions, XtsdLeft, 1, TRUE);
        !           153: }
        !           154: 
        !           155: static MoveForwardWord(ctx)
        !           156:     TextContext *ctx;
        !           157: {
        !           158:     ctx->insertPos = NextPosition(ctx, ctx->insertPos, XtstWhiteSpace, XtsdRight);
        !           159: }
        !           160: 
        !           161: static MoveBackwardWord(ctx)
        !           162:     TextContext *ctx;
        !           163: {
        !           164:     ctx->insertPos = NextPosition(ctx, ctx->insertPos, XtstWhiteSpace, XtsdLeft);
        !           165: }
        !           166: 
        !           167: static MoveBackwardParagraph(ctx)
        !           168:     TextContext *ctx;
        !           169: {
        !           170:     ctx->insertPos = NextPosition(ctx, ctx->insertPos, XtstEOL, XtsdLeft);
        !           171: }
        !           172: 
        !           173: static MoveForwardParagraph(ctx)
        !           174:     TextContext *ctx;
        !           175: {
        !           176:     ctx->insertPos = NextPosition(ctx, ctx->insertPos, XtstEOL, XtsdRight);
        !           177: }
        !           178: 
        !           179: 
        !           180: static MoveToLineStart(ctx)
        !           181:   TextContext *ctx;
        !           182: {
        !           183:     int line;
        !           184:     _XtTextShowPosition(ctx);
        !           185:     line = LineForPosition(ctx, ctx->insertPos);
        !           186:     ctx->insertPos = ctx->lt.info[line].position;
        !           187: }
        !           188: 
        !           189: static MoveToLineEnd(ctx)
        !           190:   TextContext *ctx;
        !           191: {
        !           192:     int line;
        !           193:     XtTextPosition next;
        !           194:     _XtTextShowPosition(ctx);
        !           195:     line = LineForPosition(ctx, ctx->insertPos);
        !           196:     next = ctx->lt.info[line+1].position;
        !           197:     if (next > ctx->lastPos)
        !           198:        next = ctx->lastPos;
        !           199:     else
        !           200:        next = ctx->source->scan(ctx->source, next, XtstPositions, XtsdLeft, 1, TRUE);
        !           201:     ctx->insertPos = next;
        !           202: }
        !           203: 
        !           204: 
        !           205: static int LineLastWidth = 0;
        !           206: static XtTextPosition LineLastPosition = 0;
        !           207: 
        !           208: static MoveNextLine(ctx)
        !           209:   TextContext *ctx;
        !           210: {
        !           211:     int     width, width2, height, line;
        !           212:     XtTextPosition position, maxp;
        !           213:     _XtTextShowPosition(ctx);
        !           214:     line = LineForPosition(ctx, ctx->insertPos);
        !           215:     if (line == ctx->lt.lines - 1) {
        !           216:        _XtTextScroll(ctx, 1);
        !           217:        line = LineForPosition(ctx, ctx->insertPos);
        !           218:     }
        !           219:     if (LineLastPosition == ctx->insertPos)
        !           220:        width = LineLastWidth;
        !           221:     else
        !           222:        ctx->sink->findDistance(ctx->sink, ctx->source,
        !           223:                ctx->lt.info[line].position, ctx->lt.info[line].x,
        !           224:                ctx->insertPos, &width, &position, &height);
        !           225:     line++;
        !           226:     if (ctx->lt.info[line].position > ctx->lastPos) {
        !           227:        ctx->insertPos = ctx->lastPos;
        !           228:        return;
        !           229:     }
        !           230:     ctx->sink->findPosition(ctx->sink, ctx->source,
        !           231:            ctx->lt.info[line].position, ctx->lt.info[line].x,
        !           232:            width, FALSE, &position, &width2, &height);
        !           233:     maxp = ctx->source->scan(ctx->source, ctx->lt.info[line+1].position,
        !           234:            XtstPositions, XtsdLeft, 1, TRUE);
        !           235:     if (position > maxp)
        !           236:        position = maxp;
        !           237:     ctx->insertPos = position;
        !           238:     LineLastWidth = width;
        !           239:     LineLastPosition = position;
        !           240: }
        !           241: 
        !           242: static MovePreviousLine(ctx)
        !           243:   TextContext *ctx;
        !           244: {
        !           245:     int     width, width2, height, line;
        !           246:     XtTextPosition position, maxp;
        !           247:     _XtTextShowPosition(ctx);
        !           248:     line = LineForPosition(ctx, ctx->insertPos);
        !           249:     if (line == 0) {
        !           250:        _XtTextScroll(ctx, -1);
        !           251:        line = LineForPosition(ctx, ctx->insertPos);
        !           252:     }
        !           253:     if (line > 0) {
        !           254:        if (LineLastPosition == ctx->insertPos)
        !           255:            width = LineLastWidth;
        !           256:        else
        !           257:            ctx->sink->findDistance(ctx->sink, ctx->source,
        !           258:                    ctx->lt.info[line].position, ctx->lt.info[line].x,
        !           259:                    ctx->insertPos, &width, &position, &height);
        !           260:        line--;
        !           261:        ctx->sink->findPosition(ctx->sink, ctx->source,
        !           262:                ctx->lt.info[line].position, ctx->lt.info[line].x,
        !           263:                width, FALSE, &position, &width2, &height);
        !           264:        maxp = ctx->source->scan(ctx->source, ctx->lt.info[line+1].position,
        !           265:                XtstPositions, XtsdLeft, 1, TRUE);
        !           266:        if (position > maxp)
        !           267:            position = maxp;
        !           268:        ctx->insertPos = position;
        !           269:        LineLastWidth = width;
        !           270:        LineLastPosition = position;
        !           271:     }
        !           272: }
        !           273: 
        !           274: 
        !           275: 
        !           276: static MoveBeginningOfFile(ctx)
        !           277:   TextContext *ctx;
        !           278: {
        !           279:     ctx->insertPos = ctx->source->scan(ctx->source, ctx->insertPos, XtstFile,
        !           280:            XtsdLeft, 1, TRUE);
        !           281: }
        !           282: 
        !           283: 
        !           284: static MoveEndOfFile(ctx)
        !           285:   TextContext *ctx;
        !           286: {
        !           287:     ctx->insertPos = ctx->source->scan(ctx->source, ctx->insertPos, XtstFile,
        !           288:            XtsdRight, 1, TRUE);
        !           289: }
        !           290: 
        !           291: static ScrollOneLineUp(ctx)
        !           292:   TextContext *ctx;
        !           293: {
        !           294:     _XtTextScroll(ctx, 1);
        !           295: }
        !           296: 
        !           297: static ScrollOneLineDown(ctx)
        !           298:   TextContext *ctx;
        !           299: {
        !           300:     _XtTextScroll(ctx, -1);
        !           301: }
        !           302: 
        !           303: static MoveNextPage(ctx)
        !           304:   TextContext *ctx;
        !           305: {
        !           306:     _XtTextScroll(ctx, max(1, ctx->lt.lines - 2));
        !           307:     ctx->insertPos = ctx->lt.top;
        !           308: }
        !           309: 
        !           310: static MovePreviousPage(ctx)
        !           311:   TextContext *ctx;
        !           312: {
        !           313:     _XtTextScroll(ctx, -max(1, ctx->lt.lines - 2));
        !           314:     ctx->insertPos = ctx->lt.top;
        !           315: }
        !           316: 
        !           317: 
        !           318: 
        !           319: 
        !           320: /* delete routines */
        !           321: 
        !           322: static DeleteForwardChar(ctx)
        !           323:     TextContext *ctx;
        !           324: {
        !           325:     XtTextPosition next;
        !           326: 
        !           327:     next = ctx->source->scan(
        !           328:             ctx->source, ctx->insertPos, XtstPositions, XtsdRight, 1, TRUE);
        !           329:     DeleteOrKill(ctx, ctx->insertPos, next, FALSE);
        !           330: }
        !           331: 
        !           332: static DeleteBackwardChar(ctx)
        !           333:     TextContext *ctx;
        !           334: {
        !           335:     XtTextPosition next;
        !           336: 
        !           337:     next = ctx->source->scan(
        !           338:             ctx->source, ctx->insertPos, XtstPositions, XtsdLeft, 1, TRUE);
        !           339:     DeleteOrKill(ctx, next, ctx->insertPos, FALSE);
        !           340: }
        !           341: 
        !           342: static DeleteForwardWord(ctx)
        !           343:     TextContext *ctx;
        !           344: {
        !           345:     XtTextPosition next;
        !           346: 
        !           347:     next = NextPosition(ctx, ctx->insertPos, XtstWhiteSpace, XtsdRight);
        !           348:     DeleteOrKill(ctx, ctx->insertPos, next, FALSE);
        !           349: }
        !           350: 
        !           351: static DeleteBackwardWord(ctx)
        !           352:     TextContext *ctx;
        !           353: {
        !           354:     XtTextPosition next;
        !           355: 
        !           356:     next = NextPosition(ctx, ctx->insertPos, XtstWhiteSpace, XtsdLeft);
        !           357:     DeleteOrKill(ctx, next, ctx->insertPos, FALSE);
        !           358: }
        !           359: 
        !           360: static KillForwardWord(ctx)
        !           361:     TextContext *ctx;
        !           362: {
        !           363:     XtTextPosition next;
        !           364: 
        !           365:     next = NextPosition(ctx, ctx->insertPos, XtstWhiteSpace, XtsdRight);
        !           366:     DeleteOrKill(ctx, ctx->insertPos, next, TRUE);
        !           367: }
        !           368: 
        !           369: static KillBackwardWord(ctx)
        !           370:     TextContext *ctx;
        !           371: {
        !           372:     XtTextPosition next;
        !           373: 
        !           374:     next = NextPosition(ctx, ctx->insertPos, XtstWhiteSpace, XtsdLeft);
        !           375:     DeleteOrKill(ctx, next, ctx->insertPos, TRUE);
        !           376: }
        !           377: 
        !           378: static KillCurrentSelection(ctx)
        !           379:     TextContext *ctx;
        !           380: {
        !           381:     DeleteOrKill(ctx, ctx->s.left, ctx->s.right, TRUE);
        !           382: }
        !           383: 
        !           384: static DeleteCurrentSelection(ctx)
        !           385:     TextContext *ctx;
        !           386: {
        !           387:     DeleteOrKill(ctx, ctx->s.left, ctx->s.right, FALSE);
        !           388: }
        !           389: 
        !           390: static KillToEndOfLine(ctx)
        !           391:     TextContext *ctx;
        !           392: {
        !           393:     int     line;
        !           394:     XtTextPosition last, next;
        !           395:     _XtTextShowPosition(ctx);
        !           396:     line = LineForPosition(ctx, ctx->insertPos);
        !           397:     last = ctx->lt.info[line + 1].position;
        !           398:     next = ctx->source->scan(ctx->source, ctx->insertPos, XtstEOL, XtsdRight,
        !           399:            1, FALSE);
        !           400:     if (last > ctx->lastPos)
        !           401:        last = ctx->lastPos;
        !           402:     if (last > next && ctx->insertPos < next)
        !           403:        last = next;
        !           404:     DeleteOrKill(ctx, ctx->insertPos, last, TRUE);
        !           405: }
        !           406: 
        !           407: static KillToEndOfParagraph(ctx)
        !           408:     TextContext *ctx;
        !           409: {
        !           410:     XtTextPosition next;
        !           411: 
        !           412:     next = ctx->source->scan(ctx->source, ctx->insertPos, XtstEOL, XtsdRight,
        !           413:            1, FALSE);
        !           414:     if (next == ctx->insertPos)
        !           415:        next = ctx->source->scan(ctx->source, next, XtstEOL, XtsdRight, 1, TRUE);
        !           416:     DeleteOrKill(ctx, ctx->insertPos, next, TRUE);
        !           417: }
        !           418: 
        !           419: static int InsertNewLineAndBackup(ctx)
        !           420:   TextContext *ctx;
        !           421: {
        !           422:     XtTextBlock text;
        !           423:     text.length = 1;
        !           424:     text.ptr = "\n";
        !           425:     text.firstPos = 0;
        !           426:     if (ReplaceText(ctx, ctx->insertPos, ctx->insertPos, &text)) {
        !           427:        XBell(ctx->dpy, 50);
        !           428:        return(EDITERROR);
        !           429:     }
        !           430:     _XtTextSetNewSelection(ctx, (XtTextPosition) 0, (XtTextPosition) 0);
        !           431:     ctx->showposition = TRUE;
        !           432:     return(EDITDONE);
        !           433: }
        !           434: 
        !           435: 
        !           436: 
        !           437: static int InsertNewLine(ctx)
        !           438:     TextContext *ctx;
        !           439: {
        !           440:     XtTextPosition next;
        !           441: 
        !           442:     if (InsertNewLineAndBackup(ctx))
        !           443:        return(EDITERROR);
        !           444:     next = ctx->source->scan(ctx->source, ctx->insertPos,
        !           445:            XtstPositions, XtsdRight, 1, TRUE);
        !           446:     ctx->insertPos = next;
        !           447:     return(EDITDONE);
        !           448: }
        !           449: 
        !           450: 
        !           451: static InsertNewLineAndIndent(ctx)
        !           452:   TextContext *ctx;
        !           453: {
        !           454:     XtTextBlock text;
        !           455:     XtTextPosition pos1, pos2;
        !           456: 
        !           457:     pos1 = ctx->source->scan(ctx->source, ctx->insertPos, XtstEOL, XtsdLeft,
        !           458:            1, FALSE);
        !           459:     pos2 = ctx->source->scan(ctx->source, pos1, XtstEOL, XtsdLeft, 1, TRUE);
        !           460:     pos2 = ctx->source->scan(ctx->source, pos2, XtstWhiteSpace, XtsdRight, 1, TRUE);
        !           461:     text.ptr = _XtTextGetText(ctx, pos1, pos2);
        !           462:     text.length = strlen(text.ptr);
        !           463:     if (InsertNewLine(ctx)) return;
        !           464:     if (ReplaceText(ctx, ctx->insertPos, ctx->insertPos, &text)) {
        !           465:        XBell(ctx->dpy, 50);
        !           466:        return;
        !           467:     }
        !           468:     ctx->insertPos = ctx->source->scan(ctx->source, ctx->insertPos,
        !           469:            XtstPositions, XtsdRight, text.length, TRUE);
        !           470:     XtFree(text.ptr);
        !           471: }
        !           472: 
        !           473: static NewSelection(ctx, l, r)
        !           474:   TextContext *ctx;
        !           475:   XtTextPosition l, r;
        !           476: {
        !           477:     char   *ptr;
        !           478:     _XtTextSetNewSelection(ctx, l, r);
        !           479:     if (l < r) {
        !           480:        ptr = _XtTextGetText(ctx, l, r);
        !           481:        XStoreBuffer(ctx->dpy, ptr, min(strlen(ptr), MAXCUT), 0);
        !           482:        XtFree(ptr);
        !           483:     }
        !           484: }
        !           485: 
        !           486: static SelectWord(ctx)
        !           487:   TextContext *ctx;
        !           488: {
        !           489:     XtTextPosition l, r;
        !           490:     l = ctx->source->scan(ctx->source, ctx->insertPos, XtstWhiteSpace, XtsdLeft,
        !           491:        1, FALSE);
        !           492:     r = ctx->source->scan(ctx->source, l, XtstWhiteSpace, XtsdRight, 1, FALSE);
        !           493:     NewSelection(ctx, l, r);
        !           494: }
        !           495: 
        !           496: 
        !           497: static SelectAll(ctx)
        !           498:   TextContext *ctx;
        !           499: {
        !           500:    NewSelection(ctx, (XtTextPosition) 0, ctx->lastPos);
        !           501: }
        !           502: 
        !           503: static SelectStart(ctx)
        !           504:   TextContext *ctx;
        !           505: {
        !           506:     AlterSelection(ctx, XtsmTextSelect, XtactionStart);
        !           507: }
        !           508: 
        !           509: static SelectAdjust(ctx)
        !           510:   TextContext *ctx;
        !           511: {
        !           512:     AlterSelection(ctx, XtsmTextSelect, XtactionAdjust);
        !           513: }
        !           514: 
        !           515: static SelectEnd(ctx)
        !           516:   TextContext *ctx;
        !           517: {
        !           518:     AlterSelection(ctx, XtsmTextSelect, XtactionEnd);
        !           519: }
        !           520: 
        !           521: static ExtendStart(ctx)
        !           522:   TextContext *ctx;
        !           523: {
        !           524:     AlterSelection(ctx, XtsmTextExtend, XtactionStart);
        !           525: }
        !           526: 
        !           527: static ExtendAdjust(ctx)
        !           528:   TextContext *ctx;
        !           529: {
        !           530:     AlterSelection(ctx, XtsmTextExtend, XtactionAdjust);
        !           531: }
        !           532: 
        !           533: static ExtendEnd(ctx)
        !           534:   TextContext *ctx;
        !           535: {
        !           536:     AlterSelection(ctx, XtsmTextExtend, XtactionEnd);
        !           537: }
        !           538: 
        !           539: 
        !           540: static RedrawDisplay(ctx)
        !           541:   TextContext *ctx;
        !           542: {
        !           543:     ForceBuildLineTable(ctx);
        !           544:     DisplayTextWindow(ctx);
        !           545: }
        !           546: 
        !           547: 
        !           548: _XtTextAbortDialog(ctx)
        !           549:   TextContext *ctx;
        !           550: {
        !           551:     if (ctx->dialog) {
        !           552:        XDestroyWindow(ctx->dpy, ctx->dialog);
        !           553:         (void) XtSendDestroyNotify(ctx->dpy, ctx->dialog);
        !           554:        ctx->dialog = NULL;
        !           555:     }
        !           556: }
        !           557: 
        !           558: 
        !           559: /* Insert a file of the given name into the text.  Returns 0 if file found, 
        !           560:    -1 if not. */
        !           561: 
        !           562: static InsertFileNamed(ctx, str)
        !           563:   TextContext *ctx;
        !           564:   char *str;
        !           565: {
        !           566:     int fid;
        !           567:     XtTextBlock text;
        !           568:     char    buf[1000];
        !           569:     XtTextPosition position;
        !           570: 
        !           571:     if (str == NULL || strlen(str) == 0) return -1;
        !           572:     fid = open(str, O_RDONLY);
        !           573:     if (fid <= 0) return -1;
        !           574:     _XtTextPrepareToUpdate(ctx);
        !           575:     position = ctx->insertPos;
        !           576:     while ((text.length = read(fid, buf, 512)) > 0) {
        !           577:        text.ptr = buf;
        !           578:        (void) ReplaceText(ctx, position, position, &text);
        !           579:        position = ctx->source->scan(ctx->source, position, XtstPositions,
        !           580:                XtsdRight, text.length, TRUE);
        !           581:     }
        !           582:     (void) close(fid);
        !           583:     ctx->insertPos = position;
        !           584:     _XtTextExecuteUpdate(ctx);
        !           585:     return 0;
        !           586: }
        !           587: 
        !           588: static DoInsert(ctx)
        !           589:   TextContext *ctx;
        !           590: {
        !           591:     if (InsertFileNamed(ctx, XtDialogGetValueString(ctx->dpy, ctx->dialog)))
        !           592:        XBell(ctx->dpy, 50);
        !           593:     else
        !           594:        _XtTextAbortDialog(ctx);
        !           595: }
        !           596: 
        !           597: static InsertFile(ctx)
        !           598:   TextContext *ctx;
        !           599: {
        !           600:     char *ptr;
        !           601:     XtTextBlock text;
        !           602: 
        !           603:     if (ctx->source->editType(ctx->source) != XttextEdit) {
        !           604:        XBell(ctx->dpy, 50);
        !           605:        return;
        !           606:     }
        !           607:     if (ctx->s.left < ctx->s.right) {
        !           608:        ptr = _XtTextGetText(ctx, ctx->s.left, ctx->s.right);
        !           609:        DeleteCurrentSelection(ctx);
        !           610:        if (InsertFileNamed(ctx, ptr)) {
        !           611:            XBell(ctx->dpy, 50);
        !           612:            text.ptr = ptr;
        !           613:            text.length = strlen(ptr);
        !           614:            (void) ReplaceText(ctx, ctx->insertPos, ctx->insertPos, &text);
        !           615:            ctx->s.left = ctx->insertPos;
        !           616:            ctx->s.right = ctx->insertPos = 
        !           617:                ctx->source->scan(ctx->source, ctx->insertPos, XtstPositions,
        !           618:                        XtsdRight, text.length, TRUE);
        !           619:        }
        !           620:        XtFree(ptr);
        !           621:        return;
        !           622:     }
        !           623:     if (ctx->dialog)
        !           624:        _XtTextAbortDialog(ctx);
        !           625:     ctx->dialog = XtDialogCreate(ctx->dpy, ctx->w, "Insert File:", "", (ArgList)NULL, 0);
        !           626:     XtDialogAddButton(ctx->dpy, ctx->dialog, "Abort", _XtTextAbortDialog, (caddr_t)ctx);
        !           627:     XtDialogAddButton(ctx->dpy, ctx->dialog, "DoIt", DoInsert, (caddr_t)ctx);
        !           628:     XMapWindow(ctx->dpy, ctx->dialog);
        !           629: }
        !           630: 
        !           631: /* Actions Table */
        !           632: 
        !           633: static XtActionsRec actionsTable [] = {
        !           634: /* motion bindings */
        !           635:   {"forward-character",        (caddr_t)MoveForwardChar},
        !           636:   {"backward-character",       (caddr_t)MoveBackwardChar},
        !           637:   {"forward-word",             (caddr_t)MoveForwardWord},
        !           638:   {"backward-word",            (caddr_t)MoveBackwardWord},
        !           639:   {"forward-paragraph",        (caddr_t)MoveForwardParagraph},
        !           640:   {"backward-paragraph",       (caddr_t)MoveBackwardParagraph},
        !           641:   {"beginning-of-line",        (caddr_t)MoveToLineStart},
        !           642:   {"end-of-line",              (caddr_t)MoveToLineEnd},
        !           643:   {"next-line",                (caddr_t)MoveNextLine},
        !           644:   {"previous-line",            (caddr_t)MovePreviousLine},
        !           645:   {"next-page",                (caddr_t)MoveNextPage},
        !           646:   {"previous-page",            (caddr_t)MovePreviousPage},
        !           647:   {"beginning-of-file",        (caddr_t)MoveBeginningOfFile},
        !           648:   {"end-of-file",              (caddr_t)MoveEndOfFile},
        !           649:   {"scroll-one-line-up",       (caddr_t)ScrollOneLineUp},
        !           650:   {"scroll-one-line-down",     (caddr_t)ScrollOneLineDown},
        !           651: /* delete bindings */
        !           652:   {"delete-next-character",    (caddr_t)DeleteForwardChar},
        !           653:   {"delete-previous-character", (caddr_t)DeleteBackwardChar},
        !           654:   {"delete-next-word",                 (caddr_t)DeleteForwardWord},
        !           655:   {"delete-previous-word",     (caddr_t)DeleteBackwardWord},
        !           656:   {"delete-selection",                 (caddr_t)DeleteCurrentSelection},
        !           657: /* kill bindings */
        !           658:   {"kill-word",                (caddr_t)KillForwardWord},
        !           659:   {"backward-kill-word",       (caddr_t)KillBackwardWord},
        !           660:   {"kill-selection",           (caddr_t)KillCurrentSelection},
        !           661:   {"kill-to-end-of-line",      (caddr_t)KillToEndOfLine},
        !           662:   {"kill-to-end-of-paragraph",         (caddr_t)KillToEndOfParagraph},
        !           663: /* unkill bindings */
        !           664:   {"unkill",                   (caddr_t)UnKill},
        !           665:   {"stuff",                    (caddr_t)Stuff},
        !           666: /* new line stuff */
        !           667:   {"newline-and-indent",       (caddr_t)InsertNewLineAndIndent},
        !           668:   {"newline-and-backup",       (caddr_t)InsertNewLineAndBackup},
        !           669:   {"newline",                  (caddr_t)InsertNewLine},
        !           670: /* Selection stuff */
        !           671:   {"select-word",              (caddr_t)SelectWord},
        !           672:   {"select-all",               (caddr_t)SelectAll},
        !           673:   {"select-start",             (caddr_t)SelectStart},
        !           674:   {"select-adjust",            (caddr_t)SelectAdjust},
        !           675:   {"select-end",               (caddr_t)SelectEnd},
        !           676:   {"extend-start",             (caddr_t)ExtendStart},
        !           677:   {"extend-adjust",            (caddr_t)ExtendAdjust},
        !           678:   {"extend-end",               (caddr_t)ExtendEnd},
        !           679: /* Miscellaneous */
        !           680:   {"redraw-display",           (caddr_t)RedrawDisplay},
        !           681:   {"insert-file",              (caddr_t)InsertFile},
        !           682:   {NULL,NULL}
        !           683: };
        !           684: 
        !           685: static char *defaultTextEventBindings[] = {
        !           686: /* motion bindings */
        !           687:     "<Ctrl>F:          forward-character\n",
        !           688:     "<Key>0xff53:      forward-character\n",
        !           689:     "<Ctrl>B:          backward-character\n",
        !           690:     "<Key>0xff51:      backward-character\n",
        !           691:     "<Meta>F:          forward-word\n",
        !           692:     "<Meta>B:          backward-word\n",
        !           693:     "<Meta>]:          forward-paragraph\n",
        !           694:     "<Ctrl>[:          backward-paragraph\n",
        !           695:     "<Ctrl>A:          beginning-of-line\n",
        !           696:     "<Ctrl>E:          end-of-line\n",
        !           697:     "<Ctrl>N:           next-line\n",
        !           698:     "<Key>0xff54:      next-line\n",
        !           699:     "<Ctrl>P:          previous-line\n",
        !           700:     "<Key>0xff52:       previous-line\n",
        !           701:     "<Ctrl>V:          next-page\n",
        !           702:     "<Meta>V:          previous-page\n",
        !           703:     "<Meta>\\<:                beginning-of-file\n",
        !           704:     "<Meta>\\>:                end-of-file\n",
        !           705:     "<Ctrl>Z:          scroll-one-line-up\n",
        !           706:     "<Meta>Z:          scroll-one-line-down\n",
        !           707: /* delete bindings */
        !           708:     "<Ctrl>D:          delete-next-character\n",
        !           709:     "<Ctrl>H:          delete-previous-character\n",
        !           710:     "<Key>0xff7f:      delete-previous-character\n",
        !           711:     "<Key>0xffff:      delete-previous-character\n",
        !           712:     "<Key>0xff08:      delete-previous-character\n",
        !           713:     "<Meta>D:          delete-next-word\n",
        !           714:     "<Meta>H:          delete-previous-word\n",
        !           715: /* kill bindings */
        !           716:     "s<Meta>D:         kill-word\n",
        !           717:     "s<Meta>H:         backward-kill-word\n",
        !           718:     "<Ctrl>W:          kill-selection\n",
        !           719:     "<Ctrl>K:          kill-to-end-of-line\n",
        !           720:     "<Meta>K:          kill-to-end-of-paragraph\n",
        !           721: /* unkill bindings */
        !           722:     "<Ctrl>Y:          unkill\n",
        !           723:     "<Meta>Y:          stuff\n",
        !           724: /* new line stuff */
        !           725:     "<Ctrl>J:          newline-and-indent\n",
        !           726:     "<Key>0xff0a:      newline-and-indent\n",
        !           727:     "<Ctrl>O:          newline-and-backup\n",
        !           728:     "<Ctrl>M:          newline\n",
        !           729:     "<Key>0xff0d:      newline\n",
        !           730: /* Miscellaneous */
        !           731:     "<Ctrl>L:          redraw-display\n",
        !           732:     "<Meta>I:          insert-file\n",
        !           733: /* selection stuff */
        !           734:     "<BtnDown>1:       select-start\n",
        !           735:     "<PtrMoved>1:      extend-adjust\n",
        !           736:     "<BtnUp>1:         extend-end\n",
        !           737:     "<BtnDown>2:       stuff\n",
        !           738:     "<BtnDown>3:       extend-start\n",
        !           739:     "<PtrMoved>3:      extend-adjust\n",
        !           740:     "<BtnUp>3:         extend-end\n",
        !           741:     NULL
        !           742: };
        !           743: 
        !           744: caddr_t XtSetTextEventBindings(dpy, eventTable)
        !           745:   Display *dpy;
        !           746:   XtEventsPtr eventTable;
        !           747: {
        !           748:     caddr_t state;
        !           749: 
        !           750:     if (eventTable == NULL) /* supply defaults */
        !           751:        eventTable = XtParseEventBindings(defaultTextEventBindings);
        !           752:     state = XtSetActionBindings(
        !           753:        dpy, eventTable, actionsTable, (caddr_t) DoFeep);
        !           754:     return state;
        !           755: }
        !           756: 

unix.superglobalmegacorp.com

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