/* $XConsortium: TextAction.c,v 1.53 95/06/14 15:07:27 kaleb Exp $ */
/*
Copyright (c) 1989, 1994 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include "XawImP.h"
#include "XawI18n.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
/*
* These are defined in TextPop.c
*/
void _XawTextSetField(), _XawTextPopdownSearchAction();
/*
* These are defined in Text.c
*/
char * _XawTextGetText();
void _XawTextAlterSelection(), _XawTextVScroll();
void _XawTextPrepareToUpdate();
int _XawTextReplace();
Widget w;
{
"parameterError", "textAction", "XawError",
"Widget: %s Parameter: %s",
}
static void
{
case ButtonPress:
case ButtonRelease:
break;
case KeyPress:
case KeyRelease:
break;
case MotionNotify:
break;
case EnterNotify:
case LeaveNotify:
}
}
}
static void
{
case ButtonPress:
case ButtonRelease:
break;
case KeyPress:
case KeyRelease:
{
}
break;
case MotionNotify:
break;
case EnterNotify:
case LeaveNotify:
}
}
static void
{
}
struct _SelectionList {
};
static int ProbablyMB(s)
char* s;
{
int escapes = 0;
/* if it has more than one ESC char, I assume it is COMPOUND_TEXT.
If it has at least one hi bit set character, I pretend it is multibyte. */
while ( (*s) != (wchar_t)0 ) {
if ( *s & 128 )
has_hi_bit = True;
if ( *s++ == '\033' )
escapes++;
if ( escapes >= 2 )
return( 0 );
}
return( has_hi_bit );
}
static void GetSelection();
/* ARGSUSED */
static void
Widget w;
unsigned long *length;
int* format;
{
/* If we just asked for a XA_COMPOUND_TEXT and got a null
response, we'll ask again, this time for an XA_STRING. */
} else {
}
}
return;
}
/* Many programs, especially old terminal emulators, give us multibyte text
but tell us it is COMPOUND_TEXT :( The following routine checks to see if the
string is a legal multibyte string in our locale using a spooky heuristic :O
and if it is we can only assume the sending client is using the same locale as
we are, and convert it. I also warn the user that the other client is evil. */
int count;
/* IS THE SELECTION IN MULTIBYTE FORMAT? */
if ( ProbablyMB( (char *) value ) ) {
try_CT = 0;
}
/* OR IN COMPOUND TEXT FORMAT? */
if ( try_CT ) {
}
!= Success) {
/* Notify the user on strerr and in the insertion :) */
count = 1;
!= Success) return;
}
} else
return;
}
}
static void
Widget w;
{
int buffer;
switch (selection) {
case XA_CUT_BUFFER0: buffer = 0; break;
default: buffer = -1;
}
if (buffer >= 0) {
int nbytes;
unsigned long length;
else if (num_params > 1)
} else {
if (--num_params) {
}
}
static void
Widget w;
{
EndAction((TextWidget)w);
}
/************************************************************
*
* Routines for Moving Around.
*
************************************************************/
static void
Boolean include;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
static void
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
static void
{
else
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
static void
{
scroll_val = -scroll_val;
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/************************************************************
*
* Delete Routines.
*
************************************************************/
static Boolean
XawTextSelection* s;
{
int count;
return True;
return False;
}
static Boolean
Widget w;
unsigned long* length;
int* format;
{
XawTextSelection *s;
if (*target == XA_TARGETS(d)) {
unsigned long std_length;
return True;
&std_length, format);
*targetP++ = XA_COMPOUND_TEXT(d);
*targetP++ = XA_LIST_LENGTH(d);
*targetP++ = XA_CHARACTER_POSITION(d);
if (edit_mode == XawtextEdit) {
(*length)++;
}
XtFree((char*)std_targets);
*format = 32;
return True;
}
return True;
break;
if (!salt)
return False;
s = &salt->s;
*target == XA_COMPOUND_TEXT(d)) {
*type = XA_COMPOUND_TEXT(d);
else
} else {
}
/*
* If salt is True, the salt->contents stores CT string,
* its length is measured in bytes.
* Refer to _XawTextSaltAwaySelection().
*
* by Li Yuhong, Mar. 20, 1991.
*/
if (!salt) {
< Success) {
return False;
}
} else {
}
} else {
}
int count;
< Success) {
return False;
}
return False;
}
}
*format = 8;
return True;
}
long * temp;
if (*target == XA_LIST_LENGTH(d))
*temp = 1L;
else /* *target == XA_LENGTH(d) */
*type = XA_INTEGER;
*length = 1L;
*format = 32;
return True;
}
if (*target == XA_CHARACTER_POSITION(d)) {
long * temp;
*length = 2L;
*format = 32;
return True;
}
void _XawTextZapSelection(); /* From TextAction.c */
if (!salt)
*length = 0;
*format = 32;
return True;
}
return True;
/* else */
return False;
}
static void
Widget w;
{
int i;
prevSalt = 0;
{
while (salt->s.atom_count &&
{
salt->s.atom_count--;
}
/*
* Must walk the selection list in opposite order from UnsetSelection.
*/
{
while (salt->s.atom_count &&
salt->s.atom_count--;
}
if (salt->s.atom_count == 0)
{
/* WARNING: the next line frees memory not allocated in Xaw. */
/* Could be a serious bug. Someone look into it. */
if (prevSalt)
else
}
else
}
}
static void
{
if (!salt)
return;
if (!salt->s.selections)
{
return;
}
return;
}
} else
/*
XStoreBuffer(XtDisplay(ctx), ptr, strlen(ptr), 1);
XtFree(ptr);
*/
}
return;
}
}
static void
{
/*
* If no movement actually happened, then bump the count and try again.
* This causes the character position at the very beginning and end of
* a boundary to act correctly.
*/
}
else
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
void
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/************************************************************
*
* Insertion Routines.
*
************************************************************/
static int
{
}
else {
}
}
else
return( error );
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
(void) InsertNewLineAndBackupInternal( (TextWidget) w );
_XawTextSetScrollBars( (TextWidget) w);
EndAction( (TextWidget) w );
}
static int
{
return(XawEditError);
return(XawEditDone);
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
}
/*ARGSUSED*/
static void
Widget w;
String *p;
Cardinal *n;
{
int length;
} else {
char *ptr;
*ptr = '\0';
}
XtFree( line_to_ip );
return;
}
}
/************************************************************
*
* Selection Routines.
*
*************************************************************/
static void
Widget w;
{
XawTextPosition l, r;
}
static void
Widget w;
{
}
static void
{
}
/* ARGSUSED */
static void
Widget w;
{
}
/* ARGSUSED */
static void
Widget w;
{
}
static void
Widget w;
{
}
/* ARGSUSED */
static void
Widget w;
{
}
/* ARGSUSED */
static void
Widget w;
{
}
static void
Widget w;
{
}
static void
Widget w;
{
int num_atoms;
num_atoms = *num_params;
if (num_atoms > 256)
num_atoms = 256;
num_atoms = *num_params;
EndAction( (TextWidget) w );
}
/************************************************************
*
* Misc. Routines.
*
************************************************************/
/* ARGSUSED */
static void
Widget w;
String* p;
Cardinal* n;
{
EndAction( (TextWidget) w);
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
/* Let the input method know focus has arrived. */
_XawImSetFocusValues (w, NULL, 0);
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
/* Let the input method know focus has left.*/
_XawImUnsetFocus(w);
}
/*ARGSUSED*/
static void
Widget w;
{
_XawImSetFocusValues(w, NULL, 0);
}
}
/*ARGSUSED*/
static void
Widget w;
{
_XawImUnsetFocus(w);
}
}
/* Function Name: AutoFill
* Description: Breaks the line at the previous word boundry when
* called inside InsertChar.
* Arguments: ctx - The text widget.
* Returns: none
*/
static void
{
return;
break;
line_num--; /* backup a line. */
return;
} else
}
/*ARGSUSED*/
static void
Widget w;
String* p;
Cardinal* n;
{
else
return;
}
} else { /* == XawFmt8Bit */
}
}
if (error == XawEditDone) {
}
else
}
/* IfHexConvertHexElseReturnParam() - called by InsertString
*
* i18n requires the ability to specify multiple characters in a hexa-
* decimal string at once. Since Insert was already too long, I made
* this a seperate routine.
*
* A legal hex string in MBNF: '0' 'x' ( HEX-DIGIT HEX-DIGIT )+ '\0'
*
* WHEN: the passed param is a legal hex string
* RETURNS: a pointer to that converted, null terminated hex string;
* len_return holds the character count of conversion result
*
* WHEN: the passed param is not a legal hex string:
* RETURNS: the parameter passed;
* len_return holds the char count of param.
*
* NOTE: In neither case will there be strings to free. */
static char*
char* param;
int* len_return;
{
char *p; /* steps through param char by char */
char c; /* holds the character pointed to by p */
/* reject if it doesn't begin with 0x and at least one more character. */
return( param );
}
/* Skip the 0x; go character by character shifting and adding. */
first_digit = True;
ind = 0;
for ( p = param+2; ( c = *p ); p++ ) {
if (c >= '0' && c <= '9')
else if (c >= 'a' && c <= 'f')
else if (c >= 'A' && c <= 'F')
else break;
/* If we didn't break in preceding line, it was a good hex char. */
if ( first_digit )
first_digit = False;
else {
first_digit = True;
if ( ++ind < XawTextActionMaxHexChars )
else {
return( param );
}
}
}
/* We quit the above loop becasue we hit a non hex. If that char is \0... */
if ( ( c == '\0' ) && first_digit ) {
return( hexval ); /* ...it was a legal hex string, so return it.*/
}
/* Else, there were non-hex chars or odd digit count, so... */
return( param ); /* ...return the verbatim string. */
}
/* InsertString() - action
*
* Mostly rewritten for R6 i18n.
*
* Each parameter, in turn, will be insert at the inputPos
* and the inputPos advances to the insertion's end.
*
* The exception is that parameters composed of the two
* characters 0x, followed only by an even number of
* hexadecimal digits will be converted to characters. */
/*ARGSUSED*/
static void
Widget w;
{
int i;
int temp_len;
"insertString", "textAction", "XawError",
"insert-string()'s parameter contents not legal in this locale.",
ParameterError( w, *params );
continue;
}
/* Double check that the new input is legal: try to convert to MB. */
"insertString", "textAction", "XawError",
"insert-string()'s parameter contents not legal in this locale.",
ParameterError( w, *params );
continue;
}
} /* convert to WC */
return;
}
/* Advance insertPos to the end of the string we just inserted. */
} /* DO FOR EACH PARAMETER */
}
/* DisplayCaret() - action
*
* The parameter list should contain one boolean value. If the
* argument is true, the cursor will be displayed. If false, not.
*
* The exception is that EnterNotify and LeaveNotify events may
* have a second argument, "always". If they do not, the cursor
* is only affected if the focus member of the event is true. */
static void
Widget w;
{
return;
if (*num_params > 0) { /* default arg is "True" */
return;
}
}
/* Multiply() - action
*
* The parameter list may contain either a number or the string 'Reset'.
*
* A number will multiply the current multiplication factor by that number.
* Many of the text widget actions will will perform n actions, where n is
* the multiplication factor.
*
* The string reset will reset the mutiplication factor to 1. */
/* ARGSUSED */
static void
Widget w;
{
int mult;
if (*num_params != 1) {
"Xaw Text Widget: multiply() takes exactly one argument.");
return;
}
return;
}
"must be a number greater than zero, or 'Reset'." );
return;
}
}
/* StripOutOldCRs() - called from FormRegion
*
* removes CRs in widget ctx, from from to to.
*
* RETURNS: the new ending location (we may add some characters),
* or XawReplaceError if the widget can't be written to. */
static XawTextPosition
{
char *buf;
/* Initialize our TextBlock with two spaces. */
else {
wc_two_spaces[2] = 0;
}
/* Strip out CR's. */
/* CONSTCOND */
while (TRUE) {
break;
}
else {
int i, len;
} else
/*
* Remove all extra spaces.
*/
for (i = 1 ; i < len; i++)
break;
}
} else
break;
}
return XawReplaceError;
}
}
return(to);
}
/* InsertNewCRs() - called from FormRegion
*
* inserts new CRs for FormRegion, thus for FormParagraph action */
static void
{
char * buf;
else {
wide_CR[1] = 0;
}
/* CONSTCOND */
while (TRUE) {
break;
return;
for ( i = 0 ; i < len ; i++)
break;
} else
break;
to -= (i - 1);
return;
}
}
/* FormRegion() - called by FormParagraph
*
* oversees the work of paragraph-forming a region
*
* RETURNS: XawEditDone if successful, or XawReplaceError. */
static int
{
return XawReplaceError;
/* insure that the insertion point is within legal bounds */
return XawEditDone;
}
/* FormParagraph() - action
*
* removes and reinserts CRs to maximize line length without clipping */
/* ARGSUSED */
static void
Widget w;
{
}
/* TransposeCharacters() - action
*
* Swaps the character to the left of the mark
* with the character to the right of the mark. */
/* ARGSUSED */
static void
Widget w;
{
char* buf;
int i;
/* Get bounds. */
/* Make sure we aren't at the very beginning or end of the buffer. */
return;
}
/* Retrieve text and swap the characters. */
} else { /* thus text.format == XawFmt8Bit */
char c;
c = buf[ 0 ];
buf[ i-1 ] = c;
}
/* Store new text in source. */
}
/* NoOp() - action
* This action performs no action, and allows the user or
* application programmer to unbind a translation.
*
* Note: If the parameter list contains the string "RingBell" then
* this action will ring the bell.
*/
/*ARGSUSED*/
static void
Widget w;
{
if (*num_params != 1)
return;
switch(params[0][0]) {
case 'R':
case 'r':
default: /* Fall Through */
break;
}
}
/* Reconnect() - action
* This reconnects to the input method. The user will typically call
* was started up before an IM was started up.
*/
/*ARGSUSED*/
static void
Widget w;
{
_XawImReconnect( w );
}
/* motion bindings */
{"forward-character", MoveForwardChar},
{"backward-character", MoveBackwardChar},
{"forward-word", MoveForwardWord},
{"backward-word", MoveBackwardWord},
{"forward-paragraph", MoveForwardParagraph},
{"backward-paragraph", MoveBackwardParagraph},
{"beginning-of-line", MoveToLineStart},
{"end-of-line", MoveToLineEnd},
{"next-line", MoveNextLine},
{"previous-line", MovePreviousLine},
{"next-page", MoveNextPage},
{"previous-page", MovePreviousPage},
{"beginning-of-file", MoveBeginningOfFile},
{"end-of-file", MoveEndOfFile},
{"scroll-one-line-up", ScrollOneLineUp},
{"scroll-one-line-down", ScrollOneLineDown},
/* delete bindings */
{"delete-next-character", DeleteForwardChar},
{"delete-previous-character", DeleteBackwardChar},
{"delete-next-word", DeleteForwardWord},
{"delete-previous-word", DeleteBackwardWord},
{"delete-selection", DeleteCurrentSelection},
/* kill bindings */
{"kill-word", KillForwardWord},
{"backward-kill-word", KillBackwardWord},
{"kill-selection", KillCurrentSelection},
{"kill-to-end-of-line", KillToEndOfLine},
{"kill-to-end-of-paragraph", KillToEndOfParagraph},
/* new line stuff */
{"newline-and-indent", InsertNewLineAndIndent},
{"newline-and-backup", InsertNewLineAndBackup},
{"newline", InsertNewLine},
/* Selection stuff */
{"select-word", SelectWord},
{"select-all", SelectAll},
{"select-start", SelectStart},
{"select-adjust", SelectAdjust},
{"select-end", SelectEnd},
{"select-save", SelectSave},
{"extend-start", ExtendStart},
{"extend-adjust", ExtendAdjust},
{"extend-end", ExtendEnd},
{"insert-selection", InsertSelection},
/* Miscellaneous */
{"redraw-display", RedrawDisplay},
{"insert-file", _XawTextInsertFile},
{"search", _XawTextSearch},
{"insert-char", InsertChar},
{"insert-string", InsertString},
{"focus-in", TextFocusIn},
{"focus-out", TextFocusOut},
{"enter-window", TextEnterWindow},
{"leave-window", TextLeaveWindow},
{"display-caret", DisplayCaret},
{"multiply", Multiply},
{"form-paragraph", FormParagraph},
{"transpose-characters", TransposeCharacters},
{"no-op", NoOp},
/* Action to bind special translations for text Dialogs. */
{"InsertFileAction", _XawTextInsertFileAction},
{"DoSearchAction", _XawTextDoSearchAction},
{"DoReplaceAction", _XawTextDoReplaceAction},
{"SetField", _XawTextSetField},
{"PopdownSearchAction", _XawTextPopdownSearchAction},
/* Reconnect to Input Method */
};