749N/A/* $XConsortium: TextAction.c,v 1.53 95/06/14 15:07:27 kaleb Exp $ */
749N/A
749N/A/*
749N/A
749N/ACopyright (c) 1989, 1994 X Consortium
749N/A
749N/APermission is hereby granted, free of charge, to any person obtaining a copy
749N/Aof this software and associated documentation files (the "Software"), to deal
749N/Ain the Software without restriction, including without limitation the rights
749N/Ato use, copy, modify, merge, publish, distribute, sublicense, and/or sell
749N/Acopies of the Software, and to permit persons to whom the Software is
749N/Afurnished to do so, subject to the following conditions:
749N/A
749N/AThe above copyright notice and this permission notice shall be included in
749N/Aall copies or substantial portions of the Software.
749N/A
749N/ATHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
749N/AIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
749N/AFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
749N/AX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
749N/AAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
749N/ACONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
749N/A
749N/AExcept as contained in this notice, the name of the X Consortium shall not be
749N/Aused in advertising or otherwise to promote the sale, use or other dealings
749N/Ain this Software without prior written authorization from the X Consortium.
749N/A
749N/A*/
749N/A#include <X11/IntrinsicP.h>
749N/A#include <X11/StringDefs.h>
749N/A#include <X11/Xutil.h>
749N/A#include <X11/Xatom.h>
749N/A#include <X11/Xmu/Misc.h>
749N/A#include <X11/Xmu/StdSel.h> /* for XmuConvertStandardSelection */
749N/A#include <X11/Xmu/Atoms.h> /* for XA_COMPOUND_TEXT */
749N/A#include <X11/Xaw/TextP.h>
749N/A#include <X11/Xaw/MultiSrcP.h>
749N/A#include "XawImP.h"
749N/A#include <X11/Xfuncs.h>
749N/A#include "XawI18n.h"
749N/A#include <stdio.h>
749N/A#include <stdlib.h>
749N/A#include <ctype.h>
749N/A
749N/A#define SrcScan XawTextSourceScan
749N/A#define FindDist XawTextSinkFindDistance
749N/A#define FindPos XawTextSinkFindPosition
749N/A
749N/A#define XawTextActionMaxHexChars 100
749N/A
749N/A/*
749N/A * These are defined in TextPop.c
749N/A */
749N/A
749N/Avoid _XawTextInsertFileAction(), _XawTextInsertFile(), _XawTextSearch();
749N/Avoid _XawTextSearch(), _XawTextDoSearchAction(), _XawTextDoReplaceAction();
749N/Avoid _XawTextSetField(), _XawTextPopdownSearchAction();
749N/A
749N/A/*
749N/A * These are defined in Text.c
749N/A */
749N/A
749N/Achar * _XawTextGetText();
749N/Avoid _XawTextAlterSelection(), _XawTextVScroll();
749N/Avoid _XawTextSetSelection(), _XawTextCheckResize(), _XawTextExecuteUpdate();
749N/Avoid _XawTextSetScrollBars(), _XawTextClearAndCenterDisplay();
749N/AAtom * _XawTextSelectionList();
749N/Avoid _XawTextPrepareToUpdate();
749N/Aint _XawTextReplace();
749N/A
749N/Astatic void ParameterError(w, param)
749N/A Widget w;
749N/A String param;
749N/A{
749N/A String params[2];
749N/A Cardinal num_params = 2;
749N/A params[0] = XtName(w);
749N/A params[1] = param;
749N/A
749N/A XtAppWarningMsg( XtWidgetToApplicationContext(w),
749N/A "parameterError", "textAction", "XawError",
749N/A "Widget: %s Parameter: %s",
749N/A params, &num_params);
749N/A XBell( XtDisplay( w ), 50 );
749N/A}
749N/A
749N/Astatic void
749N/AStartAction(ctx, event)
749N/ATextWidget ctx;
749N/AXEvent *event;
749N/A{
749N/A _XawTextPrepareToUpdate(ctx);
749N/A if (event != NULL) {
749N/A switch (event->type) {
749N/A case ButtonPress:
749N/A case ButtonRelease:
749N/A ctx->text.time = event->xbutton.time;
749N/A break;
749N/A case KeyPress:
749N/A case KeyRelease:
749N/A ctx->text.time = event->xkey.time;
749N/A break;
749N/A case MotionNotify:
749N/A ctx->text.time = event->xmotion.time;
749N/A break;
749N/A case EnterNotify:
749N/A case LeaveNotify:
749N/A ctx->text.time = event->xcrossing.time;
749N/A }
749N/A }
749N/A}
749N/A
749N/Astatic void
749N/ANotePosition(ctx, event)
749N/ATextWidget ctx;
749N/AXEvent* event;
749N/A{
749N/A switch (event->type) {
749N/A case ButtonPress:
749N/A case ButtonRelease:
749N/A ctx->text.ev_x = event->xbutton.x;
749N/A ctx->text.ev_y = event->xbutton.y;
749N/A break;
749N/A case KeyPress:
749N/A case KeyRelease:
749N/A {
749N/A XRectangle cursor;
749N/A XawTextSinkGetCursorBounds(ctx->text.sink, &cursor);
749N/A ctx->text.ev_x = cursor.x + cursor.width / 2;;
749N/A ctx->text.ev_y = cursor.y + cursor.height / 2;;
749N/A }
749N/A break;
749N/A case MotionNotify:
749N/A ctx->text.ev_x = event->xmotion.x;
749N/A ctx->text.ev_y = event->xmotion.y;
749N/A break;
749N/A case EnterNotify:
749N/A case LeaveNotify:
749N/A ctx->text.ev_x = event->xcrossing.x;
749N/A ctx->text.ev_y = event->xcrossing.y;
749N/A }
749N/A}
749N/A
749N/Astatic void
749N/AEndAction(ctx)
749N/ATextWidget ctx;
749N/A{
749N/A _XawTextCheckResize(ctx);
749N/A _XawTextExecuteUpdate(ctx);
749N/A ctx->text.mult = 1;
749N/A}
749N/A
749N/A
749N/Astruct _SelectionList {
749N/A String* params;
749N/A Cardinal count;
749N/A Time time;
749N/A Boolean CT_asked; /* flag if asked XA_COMPOUND_TEXT */
749N/A Atom selection; /* selection atom when asking XA_COMPOUND_TEXT */
749N/A};
749N/A
749N/Astatic int ProbablyMB(s)
749N/A char* s;
749N/A{
749N/A int escapes = 0;
749N/A int has_hi_bit = False;
749N/A
749N/A /* if it has more than one ESC char, I assume it is COMPOUND_TEXT.
749N/A If it has at least one hi bit set character, I pretend it is multibyte. */
749N/A
749N/A while ( (*s) != (wchar_t)0 ) {
749N/A if ( *s & 128 )
749N/A has_hi_bit = True;
749N/A if ( *s++ == '\033' )
749N/A escapes++;
749N/A if ( escapes >= 2 )
749N/A return( 0 );
749N/A }
749N/A return( has_hi_bit );
749N/A}
749N/Astatic void GetSelection();
749N/A
749N/A/* ARGSUSED */
749N/Astatic void
749N/A_SelectionReceived(w, client_data, selection, type, value, length, format)
749N/AWidget w;
749N/AXtPointer client_data;
749N/AAtom *selection, *type;
749N/AXtPointer value;
749N/Aunsigned long *length;
749N/Aint* format;
749N/A{
749N/A TextWidget ctx = (TextWidget)w;
749N/A XawTextBlock text;
749N/A
749N/A if (*type == 0 /*XT_CONVERT_FAIL*/ || *length == 0) {
749N/A struct _SelectionList* list = (struct _SelectionList*)client_data;
749N/A if (list != NULL) {
749N/A if (list->CT_asked) {
749N/A
749N/A /* If we just asked for a XA_COMPOUND_TEXT and got a null
749N/A response, we'll ask again, this time for an XA_STRING. */
749N/A
749N/A list->CT_asked = False;
749N/A XtGetSelectionValue(w, list->selection, XA_STRING, _SelectionReceived,
749N/A (XtPointer)list, list->time);
749N/A } else {
749N/A GetSelection(w, list->time, list->params, list->count);
749N/A XtFree(client_data);
749N/A }
749N/A }
749N/A return;
749N/A }
749N/A
749N/A /* Many programs, especially old terminal emulators, give us multibyte text
749N/Abut tell us it is COMPOUND_TEXT :( The following routine checks to see if the
749N/Astring is a legal multibyte string in our locale using a spooky heuristic :O
749N/Aand if it is we can only assume the sending client is using the same locale as
749N/Awe are, and convert it. I also warn the user that the other client is evil. */
749N/A
749N/A StartAction( ctx, (XEvent*) NULL );
749N/A if (_XawTextFormat(ctx) == (int)XawFmtWide) {
749N/A XTextProperty textprop;
749N/A Display *d = XtDisplay((Widget)ctx);
749N/A wchar_t **wlist;
749N/A int count;
749N/A int try_CT = 1;
749N/A
749N/A /* IS THE SELECTION IN MULTIBYTE FORMAT? */
749N/A
749N/A if ( ProbablyMB( (char *) value ) ) {
749N/A char * list[1];
749N/A list[0] = (char *) value;
749N/A if ( XmbTextListToTextProperty( d, (char**) list, 1,
749N/A XCompoundTextStyle, &textprop ) == Success )
749N/A try_CT = 0;
749N/A }
749N/A
749N/A /* OR IN COMPOUND TEXT FORMAT? */
749N/A
749N/A if ( try_CT ) {
749N/A textprop.encoding = XA_COMPOUND_TEXT(d);
749N/A textprop.value = (unsigned char *)value;
749N/A textprop.nitems = strlen(value);
749N/A textprop.format = 8;
749N/A }
749N/A
749N/A if ( XwcTextPropertyToTextList( d, &textprop, (wchar_t***) &wlist, &count )
749N/A != Success) {
749N/A XwcFreeStringList( (wchar_t**) wlist );
749N/A
749N/A /* Notify the user on strerr and in the insertion :) */
749N/A textprop.value = (unsigned char *) " >> ILLEGAL SELECTION << ";
749N/A count = 1;
749N/A fprintf( stderr, "Xaw Text Widget: An attempt was made to insert an illegal selection.\n" );
749N/A
749N/A if ( XwcTextPropertyToTextList( d, &textprop, (wchar_t***) &wlist, &count )
749N/A != Success) return;
749N/A }
749N/A
749N/A XFree(value);
749N/A value = (XPointer)wlist[0];
749N/A
749N/A *length = wcslen(wlist[0]);
749N/A XtFree((XtPointer)wlist);
749N/A text.format = XawFmtWide;
749N/A } else
749N/A text.format = XawFmt8Bit;
749N/A text.ptr = (char*)value;
749N/A text.firstPos = 0;
749N/A text.length = *length;
749N/A if (_XawTextReplace(ctx, ctx->text.insertPos, ctx->text.insertPos, &text)) {
749N/A XBell(XtDisplay(ctx), 0);
749N/A return;
749N/A }
749N/A ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.insertPos,
749N/A XawstPositions, XawsdRight, text.length, TRUE);
749N/A
749N/A _XawTextSetScrollBars(ctx);
749N/A EndAction(ctx);
749N/A XtFree(client_data);
749N/A XFree(value); /* the selection value should be freed with XFree */
749N/A}
749N/A
749N/Astatic void
749N/AGetSelection(w, time, params, num_params)
749N/AWidget w;
749N/ATime time;
749N/AString* params; /* selections in precedence order */
749N/ACardinal num_params;
749N/A{
749N/A Atom selection;
749N/A int buffer;
749N/A
749N/A selection = XInternAtom(XtDisplay(w), *params, False);
749N/A switch (selection) {
749N/A case XA_CUT_BUFFER0: buffer = 0; break;
749N/A case XA_CUT_BUFFER1: buffer = 1; break;
749N/A case XA_CUT_BUFFER2: buffer = 2; break;
749N/A case XA_CUT_BUFFER3: buffer = 3; break;
749N/A case XA_CUT_BUFFER4: buffer = 4; break;
749N/A case XA_CUT_BUFFER5: buffer = 5; break;
749N/A case XA_CUT_BUFFER6: buffer = 6; break;
749N/A case XA_CUT_BUFFER7: buffer = 7; break;
749N/A default: buffer = -1;
749N/A }
749N/A if (buffer >= 0) {
749N/A int nbytes;
749N/A unsigned long length;
749N/A int fmt8 = 8;
749N/A Atom type = XA_STRING;
749N/A char *line = XFetchBuffer(XtDisplay(w), &nbytes, buffer);
749N/A if (length = nbytes)
749N/A _SelectionReceived(w, (XtPointer) NULL, &selection, &type, (XPointer)line,
749N/A &length, &fmt8);
749N/A else if (num_params > 1)
749N/A GetSelection(w, time, params+1, num_params-1);
749N/A } else {
749N/A struct _SelectionList* list;
749N/A if (--num_params) {
749N/A list = XtNew(struct _SelectionList);
749N/A list->params = params + 1;
749N/A list->count = num_params;
749N/A list->time = time;
749N/A list->CT_asked = True;
749N/A list->selection = selection;
749N/A } else list = NULL;
749N/A XtGetSelectionValue(w, selection, XA_COMPOUND_TEXT(XtDisplay(w)),
749N/A _SelectionReceived, (XtPointer)list, time);
749N/A }
749N/A}
749N/A
749N/Astatic void
749N/AInsertSelection(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params; /* precedence list of selections to try */
749N/ACardinal* num_params;
749N/A{
749N/A StartAction((TextWidget)w, event); /* Get Time. */
749N/A GetSelection(w, ((TextWidget)w)->text.time, params, *num_params);
749N/A EndAction((TextWidget)w);
749N/A}
749N/A
749N/A/************************************************************
749N/A *
749N/A * Routines for Moving Around.
749N/A *
749N/A ************************************************************/
749N/A
749N/Astatic void
749N/AMove(ctx, event, dir, type, include)
749N/ATextWidget ctx;
749N/AXEvent* event;
749N/AXawTextScanDirection dir;
749N/AXawTextScanType type;
749N/ABoolean include;
749N/A{
749N/A StartAction(ctx, event);
749N/A ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.insertPos,
749N/A type, dir, ctx->text.mult, include);
749N/A EndAction(ctx);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AMoveForwardChar(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A Move((TextWidget) w, event, XawsdRight, XawstPositions, TRUE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AMoveBackwardChar(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A Move((TextWidget) w, event, XawsdLeft, XawstPositions, TRUE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AMoveForwardWord(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A Move((TextWidget) w, event, XawsdRight, XawstWhiteSpace, FALSE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AMoveBackwardWord(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A Move((TextWidget) w, event, XawsdLeft, XawstWhiteSpace, FALSE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void MoveForwardParagraph(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A Move((TextWidget) w, event, XawsdRight, XawstParagraph, FALSE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void MoveBackwardParagraph(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A Move((TextWidget) w, event, XawsdLeft, XawstParagraph, FALSE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AMoveToLineEnd(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A Move((TextWidget) w, event, XawsdRight, XawstEOL, FALSE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AMoveToLineStart(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A Move((TextWidget) w, event, XawsdLeft, XawstEOL, FALSE);
749N/A}
749N/A
749N/A
749N/Astatic void
749N/AMoveLine(ctx, event, dir)
749N/ATextWidget ctx;
749N/AXEvent* event;
749N/AXawTextScanDirection dir;
749N/A{
749N/A XawTextPosition new, next_line, junk;
749N/A int from_left, garbage;
749N/A
749N/A StartAction(ctx, event);
749N/A
749N/A if (dir == XawsdLeft)
749N/A ctx->text.mult++;
749N/A
749N/A new = SrcScan(ctx->text.source, ctx->text.insertPos,
749N/A XawstEOL, XawsdLeft, 1, FALSE);
749N/A
749N/A FindDist(ctx->text.sink, new, ctx->text.margin.left, ctx->text.insertPos,
749N/A &from_left, &junk, &garbage);
749N/A
749N/A new = SrcScan(ctx->text.source, ctx->text.insertPos, XawstEOL, dir,
749N/A ctx->text.mult, (dir == XawsdRight));
749N/A
749N/A next_line = SrcScan(ctx->text.source, new, XawstEOL, XawsdRight, 1, FALSE);
749N/A
749N/A FindPos(ctx->text.sink, new, ctx->text.margin.left, from_left, FALSE,
749N/A &(ctx->text.insertPos), &garbage, &garbage);
749N/A
749N/A if (ctx->text.insertPos > next_line)
749N/A ctx->text.insertPos = next_line;
749N/A
749N/A EndAction(ctx);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AMoveNextLine(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A MoveLine( (TextWidget) w, event, XawsdRight);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AMovePreviousLine(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A MoveLine( (TextWidget) w, event, XawsdLeft);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AMoveBeginningOfFile(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A Move((TextWidget) w, event, XawsdLeft, XawstAll, TRUE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AMoveEndOfFile(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A Move((TextWidget) w, event, XawsdRight, XawstAll, TRUE);
749N/A}
749N/A
749N/Astatic void
749N/AScroll(ctx, event, dir)
749N/ATextWidget ctx;
749N/AXEvent* event;
749N/AXawTextScanDirection dir;
749N/A{
749N/A StartAction(ctx, event);
749N/A
749N/A if (dir == XawsdLeft)
749N/A _XawTextVScroll(ctx, ctx->text.mult);
749N/A else
749N/A _XawTextVScroll(ctx, -ctx->text.mult);
749N/A
749N/A EndAction(ctx);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AScrollOneLineUp(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A Scroll( (TextWidget) w, event, XawsdLeft);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AScrollOneLineDown(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A Scroll( (TextWidget) w, event, XawsdRight);
749N/A}
749N/A
749N/Astatic void
749N/AMovePage(ctx, event, dir)
749N/ATextWidget ctx;
749N/AXEvent* event;
749N/AXawTextScanDirection dir;
749N/A{
749N/A int scroll_val = Max(1, ctx->text.lt.lines - 2);
749N/A
749N/A if (dir == XawsdLeft)
749N/A scroll_val = -scroll_val;
749N/A
749N/A StartAction(ctx, event);
749N/A _XawTextVScroll(ctx, scroll_val);
749N/A ctx->text.insertPos = ctx->text.lt.top;
749N/A EndAction(ctx);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AMoveNextPage(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A MovePage((TextWidget) w, event, XawsdRight);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AMovePreviousPage(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A MovePage((TextWidget) w, event, XawsdLeft);
749N/A}
749N/A
749N/A/************************************************************
749N/A *
749N/A * Delete Routines.
749N/A *
749N/A ************************************************************/
749N/A
749N/Astatic Boolean
749N/AMatchSelection(selection, s)
749N/A Atom selection;
749N/A XawTextSelection* s;
749N/A{
749N/A Atom *match;
749N/A int count;
749N/A
749N/A for (count = 0, match = s->selections; count < s->atom_count; match++, count++)
749N/A if (*match == selection)
749N/A return True;
749N/A return False;
749N/A}
749N/A
749N/A#define SrcCvtSel XawTextSourceConvertSelection
749N/A
749N/Astatic Boolean
749N/AConvertSelection(w, selection, target, type, value, length, format)
749N/A Widget w;
749N/A Atom *selection, *target, *type;
749N/A XtPointer* value;
749N/A unsigned long* length;
749N/A int* format;
749N/A{
749N/A Display* d = XtDisplay(w);
749N/A TextWidget ctx = (TextWidget)w;
749N/A Widget src = ctx->text.source;
749N/A XawTextEditType edit_mode;
749N/A Arg args[1];
749N/A XawTextSelectionSalt *salt = NULL;
749N/A XawTextSelection *s;
749N/A
749N/A if (*target == XA_TARGETS(d)) {
749N/A Atom* targetP, * std_targets;
749N/A unsigned long std_length;
749N/A
749N/A if ( SrcCvtSel(src, selection, target, type, value, length, format) )
749N/A return True;
749N/A
749N/A XmuConvertStandardSelection(w, ctx->text.time, selection,
749N/A target, type, (XPointer*)&std_targets,
749N/A &std_length, format);
749N/A
749N/A *value = XtMalloc((unsigned) sizeof(Atom)*(std_length + 7));
749N/A targetP = *(Atom**)value;
749N/A
749N/A *length = std_length + 6;
749N/A *targetP++ = XA_STRING;
749N/A *targetP++ = XA_TEXT(d);
749N/A *targetP++ = XA_COMPOUND_TEXT(d);
749N/A *targetP++ = XA_LENGTH(d);
749N/A *targetP++ = XA_LIST_LENGTH(d);
749N/A *targetP++ = XA_CHARACTER_POSITION(d);
749N/A
749N/A XtSetArg(args[0], XtNeditType,&edit_mode);
749N/A XtGetValues(src, args, 1);
749N/A
749N/A if (edit_mode == XawtextEdit) {
749N/A *targetP++ = XA_DELETE(d);
749N/A (*length)++;
749N/A }
749N/A memcpy((char*)targetP, (char*)std_targets, sizeof(Atom)*std_length);
749N/A XtFree((char*)std_targets);
749N/A *type = XA_ATOM;
749N/A *format = 32;
749N/A return True;
749N/A }
749N/A
749N/A if ( SrcCvtSel(src, selection, target, type, value, length, format) )
749N/A return True;
749N/A
749N/A for (salt = ctx->text.salt2; salt; salt = salt->next)
749N/A if (MatchSelection (*selection, &salt->s))
749N/A break;
749N/A if (!salt)
749N/A return False;
749N/A s = &salt->s;
749N/A if (*target == XA_STRING ||
749N/A *target == XA_TEXT(d) ||
749N/A *target == XA_COMPOUND_TEXT(d)) {
749N/A if (*target == XA_TEXT(d)) {
749N/A if (_XawTextFormat(ctx) == (int)XawFmtWide)
749N/A *type = XA_COMPOUND_TEXT(d);
749N/A else
749N/A *type = XA_STRING;
749N/A } else {
749N/A *type = *target;
749N/A }
749N/A /*
749N/A * If salt is True, the salt->contents stores CT string,
749N/A * its length is measured in bytes.
749N/A * Refer to _XawTextSaltAwaySelection().
749N/A *
749N/A * by Li Yuhong, Mar. 20, 1991.
749N/A */
749N/A if (!salt) {
749N/A *value = (char *)_XawTextGetSTRING(ctx, s->left, s->right);
749N/A if (_XawTextFormat(ctx) == (int)XawFmtWide) {
749N/A XTextProperty textprop;
749N/A if (XwcTextListToTextProperty(d, (wchar_t**)value, 1,
749N/A XCompoundTextStyle, &textprop)
749N/A < Success) {
749N/A XtFree(*value);
749N/A return False;
749N/A }
749N/A XtFree(*value);
749N/A *value = (XtPointer)textprop.value;
749N/A *length = textprop.nitems;
749N/A } else {
749N/A *length = strlen(*value);
749N/A }
749N/A } else {
749N/A *value = XtMalloc((salt->length + 1) * sizeof(unsigned char));
749N/A strcpy (*value, salt->contents);
749N/A *length = salt->length;
749N/A }
749N/A if (_XawTextFormat(ctx) == (int)XawFmtWide && *type == XA_STRING) {
749N/A XTextProperty textprop;
749N/A wchar_t** wlist;
749N/A int count;
749N/A textprop.encoding = XA_COMPOUND_TEXT(d);
749N/A textprop.value = (unsigned char *)*value;
749N/A textprop.nitems = strlen(*value);
749N/A textprop.format = 8;
749N/A if (XwcTextPropertyToTextList(d, &textprop, (wchar_t***)&wlist, &count)
749N/A < Success) {
749N/A XtFree(*value);
749N/A return False;
749N/A }
749N/A XtFree(*value);
749N/A if (XwcTextListToTextProperty(d, (wchar_t**)wlist, 1,
749N/A XStringStyle, &textprop) < Success) {
749N/A XwcFreeStringList( (wchar_t**) wlist );
749N/A return False;
749N/A }
749N/A *value = (XtPointer)textprop.value;
749N/A *length = textprop.nitems;
749N/A XwcFreeStringList( (wchar_t**) wlist );
749N/A }
749N/A *format = 8;
749N/A return True;
749N/A }
749N/A
749N/A if ( (*target == XA_LIST_LENGTH(d)) || (*target == XA_LENGTH(d)) ) {
749N/A long * temp;
749N/A
749N/A temp = (long *) XtMalloc(sizeof(long));
749N/A if (*target == XA_LIST_LENGTH(d))
749N/A *temp = 1L;
749N/A else /* *target == XA_LENGTH(d) */
749N/A *temp = (long) (s->right - s->left);
749N/A
749N/A *value = (XPointer) temp;
749N/A *type = XA_INTEGER;
749N/A *length = 1L;
749N/A *format = 32;
749N/A return True;
749N/A }
749N/A
749N/A if (*target == XA_CHARACTER_POSITION(d)) {
749N/A long * temp;
749N/A
749N/A temp = (long *) XtMalloc(2 * sizeof(long));
749N/A temp[0] = (long) (s->left + 1);
749N/A temp[1] = s->right;
749N/A *value = (XPointer) temp;
749N/A *type = XA_SPAN(d);
749N/A *length = 2L;
749N/A *format = 32;
749N/A return True;
749N/A }
749N/A
749N/A if (*target == XA_DELETE(d)) {
749N/A void _XawTextZapSelection(); /* From TextAction.c */
749N/A
749N/A if (!salt)
749N/A _XawTextZapSelection( ctx, (XEvent *) NULL, TRUE);
749N/A *value = NULL;
749N/A *type = XA_NULL(d);
749N/A *length = 0;
749N/A *format = 32;
749N/A return True;
749N/A }
749N/A
749N/A if (XmuConvertStandardSelection(w, ctx->text.time, selection, target, type,
749N/A (XPointer *)value, length, format))
749N/A return True;
749N/A
749N/A /* else */
749N/A return False;
749N/A}
749N/A
749N/Astatic void
749N/ALoseSelection(w, selection)
749N/A Widget w;
749N/A Atom* selection;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A Atom* atomP;
749N/A int i;
749N/A XawTextSelectionSalt *salt, *prevSalt, *nextSalt;
749N/A
749N/A prevSalt = 0;
749N/A for (salt = ctx->text.salt2; salt; salt = nextSalt)
749N/A {
749N/A atomP = salt->s.selections;
749N/A nextSalt = salt->next;
749N/A for (i = 0 ; i < salt->s.atom_count; i++, atomP++)
749N/A if (*selection == *atomP)
749N/A *atomP = (Atom)0;
749N/A
749N/A while (salt->s.atom_count &&
749N/A salt->s.selections[salt->s.atom_count-1] == 0)
749N/A {
749N/A salt->s.atom_count--;
749N/A }
749N/A
749N/A /*
749N/A * Must walk the selection list in opposite order from UnsetSelection.
749N/A */
749N/A
749N/A atomP = salt->s.selections;
749N/A for (i = 0 ; i < salt->s.atom_count; i++, atomP++)
749N/A if (*atomP == (Atom)0)
749N/A {
749N/A *atomP = salt->s.selections[--salt->s.atom_count];
749N/A while (salt->s.atom_count &&
749N/A salt->s.selections[salt->s.atom_count-1] == 0)
749N/A salt->s.atom_count--;
749N/A }
749N/A if (salt->s.atom_count == 0)
749N/A {
749N/A XtFree ((char *) salt->s.selections);
749N/A
749N/A /* WARNING: the next line frees memory not allocated in Xaw. */
749N/A /* Could be a serious bug. Someone look into it. */
749N/A XtFree (salt->contents);
749N/A if (prevSalt)
749N/A prevSalt->next = nextSalt;
749N/A else
749N/A ctx->text.salt2 = nextSalt;
749N/A XtFree ((char *) salt);
749N/A }
749N/A else
749N/A prevSalt = salt;
749N/A }
749N/A}
749N/A
749N/Astatic void
749N/A_DeleteOrKill(ctx, from, to, kill)
749N/ATextWidget ctx;
749N/AXawTextPosition from, to;
749N/ABoolean kill;
749N/A{
749N/A XawTextBlock text;
749N/A
749N/A if (kill && from < to) {
749N/A XawTextSelectionSalt *salt;
749N/A Atom selection = XInternAtom(XtDisplay(ctx), "SECONDARY", False);
749N/A
749N/A LoseSelection ((Widget) ctx, &selection);
749N/A salt = (XawTextSelectionSalt *) XtMalloc (sizeof (XawTextSelectionSalt));
749N/A if (!salt)
749N/A return;
749N/A salt->s.selections = (Atom *) XtMalloc (sizeof (Atom));
749N/A if (!salt->s.selections)
749N/A {
749N/A XtFree ((char *) salt);
749N/A return;
749N/A }
749N/A salt->s.left = from;
749N/A salt->s.right = to;
749N/A salt->contents = (char *)_XawTextGetSTRING(ctx, from, to);
749N/A if (_XawTextFormat(ctx) == (int)XawFmtWide) {
749N/A XTextProperty textprop;
749N/A if (XwcTextListToTextProperty(XtDisplay((Widget)ctx),
749N/A (wchar_t**)(&(salt->contents)), 1, XCompoundTextStyle,
749N/A &textprop) < Success) {
749N/A XtFree(salt->contents);
749N/A salt->length = 0;
749N/A return;
749N/A }
749N/A XtFree(salt->contents);
749N/A salt->contents = (char *)textprop.value;
749N/A salt->length = textprop.nitems;
749N/A } else
749N/A salt->length = strlen (salt->contents);
749N/A salt->next = ctx->text.salt2;
749N/A ctx->text.salt2 = salt;
749N/A salt->s.selections[0] = selection;
749N/A XtOwnSelection ((Widget) ctx, selection, ctx->text.time,
749N/A ConvertSelection, LoseSelection, NULL);
749N/A salt->s.atom_count = 1;
749N/A/*
749N/A XStoreBuffer(XtDisplay(ctx), ptr, strlen(ptr), 1);
749N/A XtFree(ptr);
749N/A*/
749N/A }
749N/A text.length = 0;
749N/A text.firstPos = 0;
749N/A
749N/A text.format = _XawTextFormat(ctx);
749N/A text.ptr = ""; /* These two lines needed to make legal TextBlock */
749N/A
749N/A if (_XawTextReplace(ctx, from, to, &text)) {
749N/A XBell(XtDisplay(ctx), 50);
749N/A return;
749N/A }
749N/A ctx->text.insertPos = from;
749N/A ctx->text.showposition = TRUE;
749N/A}
749N/A
749N/Astatic void
749N/ADeleteOrKill(ctx, event, dir, type, include, kill)
749N/ATextWidget ctx;
749N/AXEvent* event;
749N/AXawTextScanDirection dir;
749N/AXawTextScanType type;
749N/ABoolean include, kill;
749N/A{
749N/A XawTextPosition from, to;
749N/A
749N/A StartAction(ctx, event);
749N/A to = SrcScan(ctx->text.source, ctx->text.insertPos,
749N/A type, dir, ctx->text.mult, include);
749N/A
749N/A/*
749N/A * If no movement actually happened, then bump the count and try again.
749N/A * This causes the character position at the very beginning and end of
749N/A * a boundary to act correctly.
749N/A */
749N/A
749N/A if (to == ctx->text.insertPos)
749N/A to = SrcScan(ctx->text.source, ctx->text.insertPos,
749N/A type, dir, ctx->text.mult + 1, include);
749N/A
749N/A if (dir == XawsdLeft) {
749N/A from = to;
749N/A to = ctx->text.insertPos;
749N/A }
749N/A else
749N/A from = ctx->text.insertPos;
749N/A
749N/A _DeleteOrKill(ctx, from, to, kill);
749N/A _XawTextSetScrollBars(ctx);
749N/A EndAction(ctx);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/ADeleteForwardChar(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A DeleteOrKill((TextWidget) w, event, XawsdRight, XawstPositions, TRUE, FALSE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/ADeleteBackwardChar(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A DeleteOrKill((TextWidget) w, event, XawsdLeft, XawstPositions, TRUE, FALSE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/ADeleteForwardWord(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A DeleteOrKill((TextWidget) w, event,
749N/A XawsdRight, XawstWhiteSpace, FALSE, FALSE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/ADeleteBackwardWord(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A DeleteOrKill((TextWidget) w, event,
749N/A XawsdLeft, XawstWhiteSpace, FALSE, FALSE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AKillForwardWord(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A DeleteOrKill((TextWidget) w, event,
749N/A XawsdRight, XawstWhiteSpace, FALSE, TRUE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AKillBackwardWord(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A DeleteOrKill((TextWidget) w, event,
749N/A XawsdLeft, XawstWhiteSpace, FALSE, TRUE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AKillToEndOfLine(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A XawTextPosition end_of_line;
749N/A
749N/A StartAction(ctx, event);
749N/A end_of_line = SrcScan(ctx->text.source, ctx->text.insertPos, XawstEOL,
749N/A XawsdRight, ctx->text.mult, FALSE);
749N/A if (end_of_line == ctx->text.insertPos)
749N/A end_of_line = SrcScan(ctx->text.source, ctx->text.insertPos, XawstEOL,
749N/A XawsdRight, ctx->text.mult, TRUE);
749N/A
749N/A _DeleteOrKill(ctx, ctx->text.insertPos, end_of_line, TRUE);
749N/A _XawTextSetScrollBars(ctx);
749N/A EndAction(ctx);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AKillToEndOfParagraph(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A DeleteOrKill((TextWidget) w, event, XawsdRight, XawstParagraph, FALSE, TRUE);
749N/A}
749N/A
749N/Avoid
749N/A_XawTextZapSelection(ctx, event, kill)
749N/ATextWidget ctx;
749N/AXEvent* event;
749N/ABoolean kill;
749N/A{
749N/A StartAction(ctx, event);
749N/A _DeleteOrKill(ctx, ctx->text.s.left, ctx->text.s.right, kill);
749N/A _XawTextSetScrollBars(ctx);
749N/A EndAction(ctx);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AKillCurrentSelection(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A _XawTextZapSelection( (TextWidget) w, event, TRUE);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/ADeleteCurrentSelection(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A _XawTextZapSelection( (TextWidget) w, event, FALSE);
749N/A}
749N/A
749N/A/************************************************************
749N/A *
749N/A * Insertion Routines.
749N/A *
749N/A ************************************************************/
749N/A
749N/Astatic int
749N/AInsertNewLineAndBackupInternal(ctx)
749N/ATextWidget ctx;
749N/A{
749N/A int count, error = XawEditDone;
749N/A XawTextBlock text;
749N/A
749N/A text.format = _XawTextFormat(ctx);
749N/A text.length = ctx->text.mult;
749N/A text.firstPos = 0;
749N/A
749N/A if ( text.format == XawFmtWide ) {
749N/A wchar_t* wptr;
749N/A text.ptr = XtMalloc(sizeof(wchar_t) * ctx->text.mult);
749N/A wptr = (wchar_t *)text.ptr;
749N/A for (count = 0; count < ctx->text.mult; count++ )
749N/A wptr[count] = _Xaw_atowc(XawLF);
749N/A }
749N/A else {
749N/A text.ptr = XtMalloc(sizeof(char) * ctx->text.mult);
749N/A for (count = 0; count < ctx->text.mult; count++ )
749N/A text.ptr[count] = XawLF;
749N/A }
749N/A
749N/A if (_XawTextReplace(ctx, ctx->text.insertPos, ctx->text.insertPos, &text)) {
749N/A XBell( XtDisplay(ctx), 50);
749N/A error = XawEditError;
749N/A }
749N/A else
749N/A ctx->text.showposition = TRUE;
749N/A
749N/A XtFree( text.ptr );
749N/A return( error );
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AInsertNewLineAndBackup(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A StartAction( (TextWidget) w, event );
749N/A (void) InsertNewLineAndBackupInternal( (TextWidget) w );
749N/A _XawTextSetScrollBars( (TextWidget) w);
749N/A EndAction( (TextWidget) w );
749N/A}
749N/A
749N/Astatic int
749N/ALocalInsertNewLine(ctx, event)
749N/A TextWidget ctx;
749N/A XEvent* event;
749N/A{
749N/A StartAction(ctx, event);
749N/A if (InsertNewLineAndBackupInternal(ctx) == XawEditError)
749N/A return(XawEditError);
749N/A ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.insertPos,
749N/A XawstPositions, XawsdRight, ctx->text.mult, TRUE);
749N/A _XawTextSetScrollBars(ctx);
749N/A EndAction(ctx);
749N/A return(XawEditDone);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AInsertNewLine(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A (void) LocalInsertNewLine( (TextWidget) w, event);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AInsertNewLineAndIndent(w, event, p, n)
749N/AWidget w;
749N/AXEvent *event;
749N/AString *p;
749N/ACardinal *n;
749N/A{
749N/A XawTextBlock text;
749N/A XawTextPosition pos1;
749N/A int length;
749N/A TextWidget ctx = (TextWidget) w;
749N/A String line_to_ip;
749N/A
749N/A StartAction(ctx, event);
749N/A pos1 = SrcScan(ctx->text.source, ctx->text.insertPos,
749N/A XawstEOL, XawsdLeft, 1, FALSE);
749N/A
749N/A line_to_ip = _XawTextGetText(ctx, pos1, ctx->text.insertPos);
749N/A
749N/A text.format = _XawTextFormat(ctx);
749N/A text.firstPos = 0;
749N/A
749N/A if ( text.format == XawFmtWide ) {
749N/A wchar_t* ptr;
749N/A text.ptr = XtMalloc( ( 1 + wcslen((wchar_t*)line_to_ip) ) * sizeof(wchar_t) );
749N/A
749N/A ptr = (wchar_t*)text.ptr;
749N/A ptr[0] = _Xaw_atowc( XawLF );
749N/A wcscpy( (wchar_t*) ++ptr, (wchar_t*) line_to_ip );
749N/A
749N/A length = wcslen((wchar_t*)text.ptr);
749N/A while ( length && ( iswspace(*ptr) || ( *ptr == _Xaw_atowc(XawTAB) ) ) )
749N/A ptr++, length--;
749N/A *ptr = (wchar_t)0;
749N/A text.length = wcslen((wchar_t*)text.ptr);
749N/A
749N/A } else {
749N/A char *ptr;
749N/A text.ptr = XtMalloc( ( 1 + strlen( line_to_ip ) ) * sizeof( char ) );
749N/A printf( "%p ", text.ptr );
749N/A ptr = text.ptr;
749N/A ptr[0] = XawLF;
749N/A strcpy( ++ptr, line_to_ip );
749N/A
749N/A length = strlen(text.ptr);
749N/A while ( length && ( isspace(*ptr) || ( *ptr == XawTAB ) ) )
749N/A ptr++, length--;
749N/A *ptr = '\0';
749N/A text.length = strlen(text.ptr);
749N/A }
749N/A XtFree( line_to_ip );
749N/A
749N/A if (_XawTextReplace(ctx,ctx->text.insertPos, ctx->text.insertPos, &text)) {
749N/A XBell(XtDisplay(ctx), 50);
749N/A XtFree(text.ptr);
749N/A EndAction(ctx);
749N/A return;
749N/A }
749N/A XtFree(text.ptr);
749N/A ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.insertPos,
749N/A XawstPositions, XawsdRight, text.length, TRUE);
749N/A _XawTextSetScrollBars(ctx);
749N/A EndAction(ctx);
749N/A}
749N/A
749N/A/************************************************************
749N/A *
749N/A * Selection Routines.
749N/A *
749N/A *************************************************************/
749N/A
749N/Astatic void
749N/ASelectWord(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params;
749N/ACardinal* num_params;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A XawTextPosition l, r;
749N/A
749N/A StartAction(ctx, event);
749N/A l = SrcScan(ctx->text.source, ctx->text.insertPos,
749N/A XawstWhiteSpace, XawsdLeft, 1, FALSE);
749N/A r = SrcScan(ctx->text.source, l, XawstWhiteSpace, XawsdRight, 1, FALSE);
749N/A _XawTextSetSelection(ctx, l, r, params, *num_params);
749N/A EndAction(ctx);
749N/A}
749N/A
749N/Astatic void
749N/ASelectAll(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params;
749N/ACardinal* num_params;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A
749N/A StartAction(ctx, event);
749N/A _XawTextSetSelection(ctx,zeroPosition,ctx->text.lastPos,params,*num_params);
749N/A EndAction(ctx);
749N/A}
749N/A
749N/Astatic void
749N/AModifySelection(ctx, event, mode, action, params, num_params)
749N/ATextWidget ctx;
749N/AXEvent* event;
749N/AXawTextSelectionMode mode;
749N/AXawTextSelectionAction action;
749N/AString* params; /* unused */
749N/ACardinal* num_params; /* unused */
749N/A{
749N/A StartAction(ctx, event);
749N/A NotePosition(ctx, event);
749N/A _XawTextAlterSelection(ctx, mode, action, params, num_params);
749N/A EndAction(ctx);
749N/A}
749N/A
749N/A/* ARGSUSED */
749N/Astatic void
749N/ASelectStart(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params; /* unused */
749N/ACardinal* num_params; /* unused */
749N/A{
749N/A ModifySelection((TextWidget) w, event,
749N/A XawsmTextSelect, XawactionStart, params, num_params);
749N/A}
749N/A
749N/A/* ARGSUSED */
749N/Astatic void
749N/ASelectAdjust(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params; /* unused */
749N/ACardinal* num_params; /* unused */
749N/A{
749N/A ModifySelection((TextWidget) w, event,
749N/A XawsmTextSelect, XawactionAdjust, params, num_params);
749N/A}
749N/A
749N/Astatic void
749N/ASelectEnd(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params;
749N/ACardinal* num_params;
749N/A{
749N/A ModifySelection((TextWidget) w, event,
749N/A XawsmTextSelect, XawactionEnd, params, num_params);
749N/A}
749N/A
749N/A/* ARGSUSED */
749N/Astatic void
749N/AExtendStart(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params; /* unused */
749N/ACardinal* num_params; /* unused */
749N/A{
749N/A ModifySelection((TextWidget) w, event,
749N/A XawsmTextExtend, XawactionStart, params, num_params);
749N/A}
749N/A
749N/A/* ARGSUSED */
749N/Astatic void
749N/AExtendAdjust(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params; /* unused */
749N/ACardinal* num_params; /* unused */
749N/A{
749N/A ModifySelection((TextWidget) w, event,
749N/A XawsmTextExtend, XawactionAdjust, params, num_params);
749N/A}
749N/A
749N/Astatic void
749N/AExtendEnd(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params;
749N/ACardinal* num_params;
749N/A{
749N/A ModifySelection((TextWidget) w, event,
749N/A XawsmTextExtend, XawactionEnd, params, num_params);
749N/A}
749N/A
749N/Astatic void
749N/ASelectSave(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params;
749N/ACardinal* num_params;
749N/A{
749N/A int num_atoms;
749N/A Atom* sel;
749N/A Display* dpy = XtDisplay(w);
749N/A Atom selections[256];
749N/A
749N/A StartAction( (TextWidget) w, event );
749N/A num_atoms = *num_params;
749N/A if (num_atoms > 256)
749N/A num_atoms = 256;
749N/A for (sel=selections; --num_atoms >= 0; sel++, params++)
749N/A *sel = XInternAtom(dpy, *params, False);
749N/A num_atoms = *num_params;
749N/A _XawTextSaltAwaySelection( (TextWidget) w, selections, num_atoms );
749N/A EndAction( (TextWidget) w );
749N/A}
749N/A
749N/A/************************************************************
749N/A *
749N/A * Misc. Routines.
749N/A *
749N/A ************************************************************/
749N/A
749N/A/* ARGSUSED */
749N/Astatic void
749N/ARedrawDisplay(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A StartAction( (TextWidget) w, event);
749N/A _XawTextClearAndCenterDisplay((TextWidget) w);
749N/A EndAction( (TextWidget) w);
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/ATextFocusIn (w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A
749N/A /* Let the input method know focus has arrived. */
749N/A _XawImSetFocusValues (w, NULL, 0);
749N/A if ( event->xfocus.detail == NotifyPointer ) return;
749N/A
749N/A ctx->text.hasfocus = TRUE;
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/ATextFocusOut(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A
749N/A /* Let the input method know focus has left.*/
749N/A _XawImUnsetFocus(w);
749N/A if ( event->xfocus.detail == NotifyPointer ) return;
749N/A ctx->text.hasfocus = FALSE;
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/ATextEnterWindow( w, event, params, num_params )
749N/A Widget w;
749N/A XEvent* event;
749N/A String* params;
749N/A Cardinal* num_params;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A
749N/A if ((event->xcrossing.detail != NotifyInferior) && event->xcrossing.focus &&
749N/A !ctx->text.hasfocus) {
749N/A _XawImSetFocusValues(w, NULL, 0);
749N/A }
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/ATextLeaveWindow( w, event, params, num_params )
749N/A Widget w;
749N/A XEvent* event;
749N/A String* params;
749N/A Cardinal* num_params;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A
749N/A if ((event->xcrossing.detail != NotifyInferior) && event->xcrossing.focus &&
749N/A !ctx->text.hasfocus) {
749N/A _XawImUnsetFocus(w);
749N/A }
749N/A}
749N/A
749N/Astatic XComposeStatus compose_status = {NULL, 0};
749N/A
749N/A/* Function Name: AutoFill
749N/A * Description: Breaks the line at the previous word boundry when
749N/A * called inside InsertChar.
749N/A * Arguments: ctx - The text widget.
749N/A * Returns: none
749N/A */
749N/A
749N/Astatic void
749N/AAutoFill(ctx)
749N/ATextWidget ctx;
749N/A{
749N/A int width, height, x, line_num, max_width;
749N/A XawTextPosition ret_pos;
749N/A XawTextBlock text;
749N/A
749N/A if ( !((ctx->text.auto_fill) && (ctx->text.mult == 1)) )
749N/A return;
749N/A
749N/A for ( line_num = 0; line_num < ctx->text.lt.lines ; line_num++)
749N/A if ( ctx->text.lt.info[line_num].position >= ctx->text.insertPos )
749N/A break;
749N/A line_num--; /* backup a line. */
749N/A
749N/A max_width = Max(0, (int)(ctx->core.width - HMargins(ctx)));
749N/A
749N/A x = ctx->text.margin.left;
749N/A XawTextSinkFindPosition( ctx->text.sink,ctx->text.lt.info[line_num].position,
749N/A x, max_width, TRUE, &ret_pos, &width, &height);
749N/A
749N/A if ( ret_pos >= ctx->text.insertPos )
749N/A return;
749N/A
749N/A text.format = XawFmt8Bit;
749N/A if (_XawTextFormat(ctx) == (int)XawFmtWide) {
749N/A text.format = XawFmtWide;
749N/A text.ptr = (char *)XtMalloc(sizeof(wchar_t) * 2);
749N/A ((wchar_t*)text.ptr)[0] = _Xaw_atowc(XawLF);
749N/A ((wchar_t*)text.ptr)[1] = 0;
749N/A } else
749N/A text.ptr = "\n";
749N/A text.length = 1;
749N/A text.firstPos = 0;
749N/A
749N/A if (_XawTextReplace(ctx, ret_pos - 1, ret_pos, &text))
749N/A XBell(XtDisplay((Widget) ctx), 0); /* Unable to edit, complain. */
749N/A}
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AInsertChar(w, event, p, n)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* p;
749N/ACardinal* n;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A char *ptr, strbuf[BUFSIZ];
749N/A int count, error;
749N/A KeySym keysym;
749N/A XawTextBlock text;
749N/A
749N/A if (XtIsSubclass (ctx->text.source, (WidgetClass) multiSrcObjectClass))
749N/A text.length = _XawImWcLookupString (w, &event->xkey,
749N/A (wchar_t*) strbuf, BUFSIZ, &keysym, (Status*) &compose_status);
749N/A else
749N/A text.length = XLookupString ((XKeyEvent*)event, strbuf, BUFSIZ, &keysym, &compose_status);
749N/A
749N/A if (text.length == 0)
749N/A return;
749N/A
749N/A text.format = _XawTextFormat( ctx );
749N/A if ( text.format == XawFmtWide ) {
749N/A text.ptr = ptr = XtMalloc(sizeof(wchar_t) * text.length * ctx->text.mult );
749N/A for (count = 0; count < ctx->text.mult; count++ ) {
749N/A memcpy((char*) ptr, (char *)strbuf, sizeof(wchar_t) * text.length );
749N/A ptr += sizeof(wchar_t) * text.length;
749N/A }
749N/A
749N/A } else { /* == XawFmt8Bit */
749N/A text.ptr = ptr = XtMalloc( sizeof(char) * text.length * ctx->text.mult );
749N/A for ( count = 0; count < ctx->text.mult; count++ ) {
749N/A strncpy( ptr, strbuf, text.length );
749N/A ptr += text.length;
749N/A }
749N/A }
749N/A
749N/A text.length = text.length * ctx->text.mult;
749N/A text.firstPos = 0;
749N/A
749N/A StartAction(ctx, event);
749N/A
749N/A error = _XawTextReplace(ctx, ctx->text.insertPos,ctx->text.insertPos, &text);
749N/A
749N/A if (error == XawEditDone) {
749N/A ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.insertPos,
749N/A XawstPositions, XawsdRight, text.length, TRUE);
749N/A AutoFill(ctx);
749N/A }
749N/A else
749N/A XBell(XtDisplay(ctx), 50);
749N/A
749N/A XtFree(text.ptr);
749N/A _XawTextSetScrollBars(ctx);
749N/A EndAction(ctx);
749N/A}
749N/A
749N/A
749N/A/* IfHexConvertHexElseReturnParam() - called by InsertString
749N/A *
749N/A * i18n requires the ability to specify multiple characters in a hexa-
749N/A * decimal string at once. Since Insert was already too long, I made
749N/A * this a seperate routine.
749N/A *
749N/A * A legal hex string in MBNF: '0' 'x' ( HEX-DIGIT HEX-DIGIT )+ '\0'
749N/A *
749N/A * WHEN: the passed param is a legal hex string
749N/A * RETURNS: a pointer to that converted, null terminated hex string;
749N/A * len_return holds the character count of conversion result
749N/A *
749N/A * WHEN: the passed param is not a legal hex string:
749N/A * RETURNS: the parameter passed;
749N/A * len_return holds the char count of param.
749N/A *
749N/A * NOTE: In neither case will there be strings to free. */
749N/A
749N/Astatic char*
749N/AIfHexConvertHexElseReturnParam(param, len_return)
749N/A char* param;
749N/A int* len_return;
749N/A{
749N/A char *p; /* steps through param char by char */
749N/A char c; /* holds the character pointed to by p */
749N/A
749N/A int ind; /* steps through hexval buffer char by char */
749N/A static char hexval[ XawTextActionMaxHexChars ];
749N/A Boolean first_digit;
749N/A
749N/A /* reject if it doesn't begin with 0x and at least one more character. */
749N/A
749N/A if ( ( param[0] != '0' ) || ( param[1] != 'x' ) || ( param[2] == '\0' ) ) {
749N/A *len_return = strlen( param );
749N/A return( param );
749N/A }
749N/A
749N/A /* Skip the 0x; go character by character shifting and adding. */
749N/A
749N/A first_digit = True;
749N/A ind = 0;
749N/A hexval[ ind ] = '\0';
749N/A
749N/A for ( p = param+2; ( c = *p ); p++ ) {
749N/A hexval[ ind ] *= 16;
749N/A if (c >= '0' && c <= '9')
749N/A hexval[ ind ] += c - '0';
749N/A else if (c >= 'a' && c <= 'f')
749N/A hexval[ ind ] += c - 'a' + 10;
749N/A else if (c >= 'A' && c <= 'F')
749N/A hexval[ ind ] += c - 'A' + 10;
749N/A else break;
749N/A
749N/A /* If we didn't break in preceding line, it was a good hex char. */
749N/A
749N/A if ( first_digit )
749N/A first_digit = False;
749N/A else {
749N/A first_digit = True;
749N/A if ( ++ind < XawTextActionMaxHexChars )
749N/A hexval[ ind ] = '\0';
749N/A else {
749N/A *len_return = strlen( param );
749N/A return( param );
749N/A }
749N/A }
749N/A }
749N/A
749N/A /* We quit the above loop becasue we hit a non hex. If that char is \0... */
749N/A
749N/A if ( ( c == '\0' ) && first_digit ) {
749N/A *len_return = strlen( hexval );
749N/A return( hexval ); /* ...it was a legal hex string, so return it.*/
749N/A }
749N/A
749N/A /* Else, there were non-hex chars or odd digit count, so... */
749N/A
749N/A *len_return = strlen( param );
749N/A return( param ); /* ...return the verbatim string. */
749N/A}
749N/A
749N/A
749N/A/* InsertString() - action
749N/A *
749N/A * Mostly rewritten for R6 i18n.
749N/A *
749N/A * Each parameter, in turn, will be insert at the inputPos
749N/A * and the inputPos advances to the insertion's end.
749N/A *
749N/A * The exception is that parameters composed of the two
749N/A * characters 0x, followed only by an even number of
749N/A * hexadecimal digits will be converted to characters. */
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AInsertString(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params;
749N/ACardinal* num_params;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A XtAppContext app_con = XtWidgetToApplicationContext(w);
749N/A XawTextBlock text;
749N/A int i;
749N/A
749N/A text.firstPos = 0;
749N/A text.format = _XawTextFormat( ctx );
749N/A
749N/A StartAction(ctx, event);
749N/A for ( i = *num_params; i; i--, params++ ) { /* DO FOR EACH PARAMETER */
749N/A
749N/A text.ptr = IfHexConvertHexElseReturnParam( *params, &text.length );
749N/A
749N/A if ( text.length == 0 ) continue;
749N/A
749N/A if ( _XawTextFormat( ctx ) == (int)XawFmtWide ) { /* convert to WC */
749N/A
749N/A int temp_len;
749N/A text.ptr = (char*) _XawTextMBToWC( XtDisplay(w), text.ptr,
749N/A &text.length );
749N/A
749N/A if ( text.ptr == NULL ) { /* conversion error */
749N/A XtAppWarningMsg( app_con,
749N/A "insertString", "textAction", "XawError",
749N/A "insert-string()'s parameter contents not legal in this locale.",
749N/A NULL, NULL );
749N/A ParameterError( w, *params );
749N/A continue;
749N/A }
749N/A
749N/A /* Double check that the new input is legal: try to convert to MB. */
749N/A
749N/A temp_len = text.length; /* _XawTextWCToMB's 3rd arg is in_out */
749N/A if ( _XawTextWCToMB( XtDisplay(w), (wchar_t*)text.ptr, &temp_len ) == NULL ) {
749N/A XtAppWarningMsg( app_con,
749N/A "insertString", "textAction", "XawError",
749N/A "insert-string()'s parameter contents not legal in this locale.",
749N/A NULL, NULL );
749N/A ParameterError( w, *params );
749N/A continue;
749N/A }
749N/A } /* convert to WC */
749N/A
749N/A if ( _XawTextReplace( ctx, ctx->text.insertPos,
749N/A ctx->text.insertPos, &text ) ) {
749N/A XBell( XtDisplay( ctx ), 50 );
749N/A EndAction( ctx );
749N/A return;
749N/A }
749N/A
749N/A /* Advance insertPos to the end of the string we just inserted. */
749N/A ctx->text.insertPos = SrcScan( ctx->text.source, ctx->text.insertPos,
749N/A XawstPositions, XawsdRight, text.length, TRUE );
749N/A
749N/A } /* DO FOR EACH PARAMETER */
749N/A
749N/A EndAction( ctx );
749N/A}
749N/A
749N/A
749N/A/* DisplayCaret() - action
749N/A *
749N/A * The parameter list should contain one boolean value. If the
749N/A * argument is true, the cursor will be displayed. If false, not.
749N/A *
749N/A * The exception is that EnterNotify and LeaveNotify events may
749N/A * have a second argument, "always". If they do not, the cursor
749N/A * is only affected if the focus member of the event is true. */
749N/A
749N/Astatic void
749N/ADisplayCaret(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event; /* CrossingNotify special-cased */
749N/AString* params; /* Off, False, No, On, True, Yes, etc. */
749N/ACardinal* num_params; /* 0, 1 or 2 */
749N/A{
749N/A TextWidget ctx = (TextWidget)w;
749N/A Boolean display_caret = True;
749N/A
749N/A if ( ( event->type == EnterNotify || event->type == LeaveNotify ) &&
749N/A ( ( *num_params >= 2 ) && ( strcmp( params[1], "always" ) == 0 ) ) &&
749N/A ( !event->xcrossing.focus ) )
749N/A return;
749N/A
749N/A if (*num_params > 0) { /* default arg is "True" */
749N/A XrmValue from, to;
749N/A from.size = strlen(from.addr = params[0]);
749N/A XtConvert( w, XtRString, &from, XtRBoolean, &to );
749N/A
749N/A if ( to.addr != NULL )
749N/A display_caret = *(Boolean*)to.addr;
749N/A if ( ctx->text.display_caret == display_caret )
749N/A return;
749N/A }
749N/A StartAction(ctx, event);
749N/A ctx->text.display_caret = display_caret;
749N/A EndAction(ctx);
749N/A}
749N/A
749N/A
749N/A/* Multiply() - action
749N/A *
749N/A * The parameter list may contain either a number or the string 'Reset'.
749N/A *
749N/A * A number will multiply the current multiplication factor by that number.
749N/A * Many of the text widget actions will will perform n actions, where n is
749N/A * the multiplication factor.
749N/A *
749N/A * The string reset will reset the mutiplication factor to 1. */
749N/A
749N/A/* ARGSUSED */
749N/Astatic void
749N/AMultiply(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params;
749N/ACardinal* num_params;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A int mult;
749N/A
749N/A if (*num_params != 1) {
749N/A XtAppError( XtWidgetToApplicationContext( w ),
749N/A "Xaw Text Widget: multiply() takes exactly one argument.");
749N/A XBell( XtDisplay( w ), 0 );
749N/A return;
749N/A }
749N/A
749N/A if ( ( params[0][0] == 'r' ) || ( params[0][0] == 'R' ) ) {
749N/A XBell( XtDisplay( w ), 0 );
749N/A ctx->text.mult = 1;
749N/A return;
749N/A }
749N/A
749N/A if ( ( mult = atoi( params[0] ) ) == 0 ) {
749N/A char buf[ BUFSIZ ];
749N/A sprintf(buf, "%s %s", "Xaw Text Widget: multiply() argument",
749N/A "must be a number greater than zero, or 'Reset'." );
749N/A XtAppError( XtWidgetToApplicationContext( w ), buf );
749N/A XBell( XtDisplay( w ), 50 );
749N/A return;
749N/A }
749N/A
749N/A ctx->text.mult *= mult;
749N/A}
749N/A
749N/A
749N/A/* StripOutOldCRs() - called from FormRegion
749N/A *
749N/A * removes CRs in widget ctx, from from to to.
749N/A *
749N/A * RETURNS: the new ending location (we may add some characters),
749N/A * or XawReplaceError if the widget can't be written to. */
749N/A
749N/Astatic XawTextPosition
749N/AStripOutOldCRs(ctx, from, to)
749N/ATextWidget ctx;
749N/AXawTextPosition from, to;
749N/A{
749N/A XawTextPosition startPos, endPos, eop_begin, eop_end, temp;
749N/A Widget src = ctx->text.source;
749N/A XawTextBlock text;
749N/A char *buf;
749N/A static wchar_t wc_two_spaces[ 3 ];
749N/A
749N/A /* Initialize our TextBlock with two spaces. */
749N/A
749N/A text.firstPos = 0;
749N/A text.format = _XawTextFormat(ctx);
749N/A if ( text.format == XawFmt8Bit )
749N/A text.ptr= " ";
749N/A else {
749N/A wc_two_spaces[0] = _Xaw_atowc(XawSP);
749N/A wc_two_spaces[1] = _Xaw_atowc(XawSP);
749N/A wc_two_spaces[2] = 0;
749N/A text.ptr = (char*) wc_two_spaces;
749N/A }
749N/A
749N/A /* Strip out CR's. */
749N/A
749N/A eop_begin = eop_end = startPos = endPos = from;
749N/A /* CONSTCOND */
749N/A while (TRUE) {
749N/A endPos=SrcScan(src, startPos, XawstEOL, XawsdRight, 1, FALSE);
749N/A
749N/A temp = SrcScan(src, endPos, XawstWhiteSpace, XawsdLeft, 1, FALSE);
749N/A temp = SrcScan(src, temp, XawstWhiteSpace, XawsdRight,1, FALSE);
749N/A
749N/A if (temp > startPos)
749N/A endPos = temp;
749N/A
749N/A if (endPos >= to)
749N/A break;
749N/A
749N/A if (endPos >= eop_begin) {
749N/A startPos = eop_end;
749N/A eop_begin=SrcScan(src, startPos, XawstParagraph, XawsdRight, 1,FALSE);
749N/A eop_end = SrcScan(src, startPos, XawstParagraph, XawsdRight, 1, TRUE);
749N/A }
749N/A else {
749N/A XawTextPosition periodPos, next_word;
749N/A int i, len;
749N/A
749N/A periodPos= SrcScan(src, endPos, XawstPositions, XawsdLeft, 1, TRUE);
749N/A next_word = SrcScan(src, endPos, XawstWhiteSpace, XawsdRight, 1, FALSE);
749N/A
749N/A len = (int)(next_word - periodPos);
749N/A
749N/A text.length = 1;
749N/A buf = _XawTextGetText(ctx, periodPos, next_word);
749N/A if (text.format == XawFmtWide) {
749N/A if ( (periodPos < endPos) && (((wchar_t*)buf)[0] == _Xaw_atowc('.')))
749N/A text.length++;
749N/A } else
749N/A if ( (periodPos < endPos) && (buf[0] == '.') )
749N/A text.length++; /* Put in two spaces. */
749N/A
749N/A /*
749N/A * Remove all extra spaces.
749N/A */
749N/A
749N/A for (i = 1 ; i < len; i++)
749N/A if (text.format == XawFmtWide) {
749N/A if ( !iswspace(((wchar_t*)buf)[i]) || ((periodPos + i) >= to) ) {
749N/A break;
749N/A }
749N/A } else
749N/A if ( !isspace(buf[i]) || ((periodPos + i) >= to) ) {
749N/A break;
749N/A }
749N/A
749N/A XtFree(buf);
749N/A
749N/A to -= (i - text.length - 1);
749N/A startPos = SrcScan(src, periodPos, XawstPositions, XawsdRight, i, TRUE);
749N/A if (_XawTextReplace(ctx, endPos, startPos, &text) != XawEditDone)
749N/A return XawReplaceError;
749N/A startPos -= i - text.length;
749N/A }
749N/A }
749N/A return(to);
749N/A}
749N/A
749N/A
749N/A/* InsertNewCRs() - called from FormRegion
749N/A *
749N/A * inserts new CRs for FormRegion, thus for FormParagraph action */
749N/A
749N/Astatic void
749N/AInsertNewCRs(ctx, from, to)
749N/ATextWidget ctx;
749N/AXawTextPosition from, to;
749N/A{
749N/A XawTextPosition startPos, endPos, space, eol;
749N/A XawTextBlock text;
749N/A int i, width, height, len;
749N/A char * buf;
749N/A static wchar_t wide_CR[ 2 ];
749N/A
749N/A text.firstPos = 0;
749N/A text.length = 1;
749N/A text.format = _XawTextFormat( ctx );
749N/A
749N/A if ( text.format == XawFmt8Bit )
749N/A text.ptr = "\n";
749N/A else {
749N/A wide_CR[0] = _Xaw_atowc(XawLF);
749N/A wide_CR[1] = 0;
749N/A text.ptr = (char*) wide_CR;
749N/A }
749N/A
749N/A startPos = from;
749N/A /* CONSTCOND */
749N/A while (TRUE) {
749N/A XawTextSinkFindPosition( ctx->text.sink, startPos,
749N/A (int) ctx->text.margin.left,
749N/A (int) (ctx->core.width - HMargins(ctx)),
749N/A TRUE, &eol, &width, &height);
749N/A if (eol >= to)
749N/A break;
749N/A
749N/A eol = SrcScan(ctx->text.source, eol, XawstPositions, XawsdLeft, 1, TRUE);
749N/A space= SrcScan(ctx->text.source, eol, XawstWhiteSpace,XawsdRight,1, TRUE);
749N/A
749N/A startPos = endPos = eol;
749N/A if (eol == space)
749N/A return;
749N/A
749N/A len = (int) (space - eol);
749N/A buf = _XawTextGetText(ctx, eol, space);
749N/A for ( i = 0 ; i < len ; i++)
749N/A if (text.format == XawFmtWide) {
749N/A if (!iswspace(((wchar_t*)buf)[i]))
749N/A break;
749N/A } else
749N/A if (!isspace(buf[i]))
749N/A break;
749N/A
749N/A to -= (i - 1);
749N/A endPos = SrcScan(ctx->text.source, endPos,
749N/A XawstPositions, XawsdRight, i, TRUE);
749N/A XtFree(buf);
749N/A
749N/A if (_XawTextReplace(ctx, startPos, endPos, &text))
749N/A return;
749N/A
749N/A startPos = SrcScan(ctx->text.source, startPos,
749N/A XawstPositions, XawsdRight, 1, TRUE);
749N/A }
749N/A}
749N/A
749N/A
749N/A/* FormRegion() - called by FormParagraph
749N/A *
749N/A * oversees the work of paragraph-forming a region
749N/A *
749N/A * RETURNS: XawEditDone if successful, or XawReplaceError. */
749N/A
749N/Astatic int
749N/AFormRegion(ctx, from, to)
749N/ATextWidget ctx;
749N/AXawTextPosition from, to;
749N/A{
749N/A if ( from >= to ) return XawEditDone;
749N/A
749N/A if ( ( to = StripOutOldCRs( ctx, from, to ) ) == XawReplaceError )
749N/A return XawReplaceError;
749N/A
749N/A /* insure that the insertion point is within legal bounds */
749N/A if ( ctx->text.insertPos > SrcScan( ctx->text.source, 0,
749N/A XawstAll, XawsdRight, 1, TRUE ) )
749N/A ctx->text.insertPos = to;
749N/A
749N/A InsertNewCRs(ctx, from, to);
749N/A _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE);
749N/A return XawEditDone;
749N/A}
749N/A
749N/A
749N/A/* FormParagraph() - action
749N/A *
749N/A * removes and reinserts CRs to maximize line length without clipping */
749N/A
749N/A/* ARGSUSED */
749N/Astatic void
749N/AFormParagraph(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params;
749N/ACardinal* num_params;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A XawTextPosition from, to;
749N/A
749N/A StartAction(ctx, event);
749N/A
749N/A from = SrcScan( ctx->text.source, ctx->text.insertPos,
749N/A XawstParagraph, XawsdLeft, 1, FALSE );
749N/A to = SrcScan( ctx->text.source, from,
749N/A XawstParagraph, XawsdRight, 1, FALSE );
749N/A
749N/A if ( FormRegion( ctx, from, to ) == XawReplaceError )
749N/A XBell( XtDisplay( w ), 0 );
749N/A _XawTextSetScrollBars( ctx );
749N/A EndAction( ctx );
749N/A}
749N/A
749N/A
749N/A/* TransposeCharacters() - action
749N/A *
749N/A * Swaps the character to the left of the mark
749N/A * with the character to the right of the mark. */
749N/A
749N/A/* ARGSUSED */
749N/Astatic void
749N/ATransposeCharacters(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params;
749N/ACardinal* num_params;
749N/A{
749N/A TextWidget ctx = (TextWidget) w;
749N/A XawTextPosition start, end;
749N/A XawTextBlock text;
749N/A char* buf;
749N/A int i;
749N/A
749N/A StartAction(ctx, event);
749N/A
749N/A /* Get bounds. */
749N/A
749N/A start = SrcScan( ctx->text.source, ctx->text.insertPos, XawstPositions,
749N/A XawsdLeft, 1, TRUE );
749N/A end = SrcScan( ctx->text.source, ctx->text.insertPos, XawstPositions,
749N/A XawsdRight, ctx->text.mult, TRUE );
749N/A
749N/A /* Make sure we aren't at the very beginning or end of the buffer. */
749N/A
749N/A if ( ( start == ctx->text.insertPos ) || ( end == ctx->text.insertPos ) ) {
749N/A XBell( XtDisplay( w ), 0 ); /* complain. */
749N/A EndAction( ctx );
749N/A return;
749N/A }
749N/A
749N/A ctx->text.insertPos = end;
749N/A
749N/A text.firstPos = 0;
749N/A text.format = _XawTextFormat(ctx);
749N/A
749N/A /* Retrieve text and swap the characters. */
749N/A
749N/A if ( text.format == XawFmtWide) {
749N/A wchar_t wc;
749N/A wchar_t* wbuf;
749N/A
749N/A wbuf = (wchar_t*) _XawTextGetText(ctx, start, end);
749N/A text.length = wcslen( wbuf );
749N/A wc = wbuf[ 0 ];
749N/A for ( i = 1; i < text.length; i++ )
749N/A wbuf[ i-1 ] = wbuf[ i ];
749N/A wbuf[ i-1 ] = wc;
749N/A buf = (char*) wbuf; /* so that it gets assigned and freed */
749N/A
749N/A } else { /* thus text.format == XawFmt8Bit */
749N/A char c;
749N/A buf = _XawTextGetText( ctx, start, end );
749N/A text.length = strlen( buf );
749N/A c = buf[ 0 ];
749N/A for ( i = 1; i < text.length; i++ )
749N/A buf[ i-1 ] = buf[ i ];
749N/A buf[ i-1 ] = c;
749N/A }
749N/A
749N/A text.ptr = buf;
749N/A
749N/A /* Store new text in source. */
749N/A
749N/A if (_XawTextReplace (ctx, start, end, &text)) /* Unable to edit, complain. */
749N/A XBell(XtDisplay(w), 0);
749N/A XtFree((char *) buf);
749N/A EndAction(ctx);
749N/A}
749N/A
749N/A
749N/A/* NoOp() - action
749N/A * This action performs no action, and allows the user or
749N/A * application programmer to unbind a translation.
749N/A *
749N/A * Note: If the parameter list contains the string "RingBell" then
749N/A * this action will ring the bell.
749N/A */
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/ANoOp(w, event, params, num_params)
749N/AWidget w;
749N/AXEvent* event;
749N/AString* params;
749N/ACardinal* num_params;
749N/A{
749N/A if (*num_params != 1)
749N/A return;
749N/A
749N/A switch(params[0][0]) {
749N/A case 'R':
749N/A case 'r':
749N/A XBell(XtDisplay(w), 0);
749N/A default: /* Fall Through */
749N/A break;
749N/A }
749N/A}
749N/A
749N/A/* Reconnect() - action
749N/A * This reconnects to the input method. The user will typically call
749N/A * this action if/when connection has been severed, or when the app
749N/A * was started up before an IM was started up.
749N/A */
749N/A
749N/A/*ARGSUSED*/
749N/Astatic void
749N/AReconnect( w, event, params, num_params )
749N/A Widget w;
749N/A XEvent* event;
749N/A String* params;
749N/A Cardinal* num_params;
749N/A{
749N/A _XawImReconnect( w );
749N/A}
749N/A
749N/A
749N/AXtActionsRec _XawTextActionsTable[] = {
749N/A
749N/A/* motion bindings */
749N/A
749N/A {"forward-character", MoveForwardChar},
749N/A {"backward-character", MoveBackwardChar},
749N/A {"forward-word", MoveForwardWord},
749N/A {"backward-word", MoveBackwardWord},
749N/A {"forward-paragraph", MoveForwardParagraph},
749N/A {"backward-paragraph", MoveBackwardParagraph},
749N/A {"beginning-of-line", MoveToLineStart},
749N/A {"end-of-line", MoveToLineEnd},
749N/A {"next-line", MoveNextLine},
749N/A {"previous-line", MovePreviousLine},
749N/A {"next-page", MoveNextPage},
749N/A {"previous-page", MovePreviousPage},
749N/A {"beginning-of-file", MoveBeginningOfFile},
749N/A {"end-of-file", MoveEndOfFile},
749N/A {"scroll-one-line-up", ScrollOneLineUp},
749N/A {"scroll-one-line-down", ScrollOneLineDown},
749N/A
749N/A/* delete bindings */
749N/A
749N/A {"delete-next-character", DeleteForwardChar},
749N/A {"delete-previous-character", DeleteBackwardChar},
749N/A {"delete-next-word", DeleteForwardWord},
749N/A {"delete-previous-word", DeleteBackwardWord},
749N/A {"delete-selection", DeleteCurrentSelection},
749N/A
749N/A/* kill bindings */
749N/A
749N/A {"kill-word", KillForwardWord},
749N/A {"backward-kill-word", KillBackwardWord},
749N/A {"kill-selection", KillCurrentSelection},
749N/A {"kill-to-end-of-line", KillToEndOfLine},
749N/A {"kill-to-end-of-paragraph", KillToEndOfParagraph},
749N/A
749N/A/* new line stuff */
749N/A
749N/A {"newline-and-indent", InsertNewLineAndIndent},
749N/A {"newline-and-backup", InsertNewLineAndBackup},
749N/A {"newline", InsertNewLine},
749N/A
749N/A/* Selection stuff */
749N/A
749N/A {"select-word", SelectWord},
749N/A {"select-all", SelectAll},
749N/A {"select-start", SelectStart},
749N/A {"select-adjust", SelectAdjust},
749N/A {"select-end", SelectEnd},
749N/A {"select-save", SelectSave},
749N/A {"extend-start", ExtendStart},
749N/A {"extend-adjust", ExtendAdjust},
749N/A {"extend-end", ExtendEnd},
749N/A {"insert-selection", InsertSelection},
749N/A
749N/A/* Miscellaneous */
749N/A
749N/A {"redraw-display", RedrawDisplay},
749N/A {"insert-file", _XawTextInsertFile},
749N/A {"search", _XawTextSearch},
749N/A {"insert-char", InsertChar},
749N/A {"insert-string", InsertString},
749N/A {"focus-in", TextFocusIn},
749N/A {"focus-out", TextFocusOut},
749N/A {"enter-window", TextEnterWindow},
749N/A {"leave-window", TextLeaveWindow},
749N/A {"display-caret", DisplayCaret},
749N/A {"multiply", Multiply},
749N/A {"form-paragraph", FormParagraph},
749N/A {"transpose-characters", TransposeCharacters},
749N/A {"no-op", NoOp},
749N/A
749N/A/* Action to bind special translations for text Dialogs. */
749N/A
749N/A {"InsertFileAction", _XawTextInsertFileAction},
749N/A {"DoSearchAction", _XawTextDoSearchAction},
749N/A {"DoReplaceAction", _XawTextDoReplaceAction},
749N/A {"SetField", _XawTextSetField},
749N/A {"PopdownSearchAction", _XawTextPopdownSearchAction},
749N/A
749N/A/* Reconnect to Input Method */
749N/A {"reconnect-im", Reconnect} /* Li Yuhong, Omron KK, 1991 */
749N/A};
749N/A
749N/ACardinal _XawTextActionsTableCount = XtNumber(_XawTextActionsTable);