📄 atbeditor.c
字号:
/* Quit editor */
case ctrlEscape:
return ED_DONE;
break;
/* Cursor movements*/
case ctrlLeft:
case ctrlRight:
case ctrlUp:
case ctrlDown:
case ctrlTop:
case ctrlBottom:
ATB_edit_MoveCursor(editor, character, update);
break;
/* Backspace */
case ctrlBack:
ATB_edit_DeleteLeft(editor);
if (update)
{
ATB_edit_Update(editor, 0);
}
break;
/* Delete character under cursor */
case ctrlDel:
ATB_edit_DeleteRight(editor);
if (update)
{
ATB_edit_Update(editor, 0);
}
break;
/* CR/LF */
case ctrlEnter:
character = UNICODE_LINEFEED;
/* SPR#1983 - SH - Insert into normal buffer */
if (ATB_edit_Insert(editor, &editor->attr->text, character))
{
ATB_edit_MoveCursor(editor,ctrlRight,update);
}
break;
/* Normal character */
default:
/* SPR#1983 - SH - Insert into normal buffer */
if (ATB_edit_Insert(editor, &editor->attr->text, character))
{
/* Character inserted OK. Move cursor to right if we're not in multitap */
if (!editor->multitap)
{
ATB_edit_MoveCursor(editor,ctrlRight,FALSE);
}
if (update)
{
ATB_edit_Update(editor, 0);
}
}
break;
}
/* SPR#1983 - SH - In caps mode, any keypress switches to lower case */
if (!editor->multitap && editor->textcase==ED_CASE_CAPS)
editor->textcase = ED_CASE_LOWER;
return ED_OK;
}
/*******************************************************************************
$Function: ATB_edit_AsciiChar
$Description: Insert an ascii character into the editor text, or execute a control code
$Returns: ED_OK - OK
$Arguments: editor - The editor data
character - The ascii character
update - TRUE if word wrap is to be carried out after insertion
*******************************************************************************/
ED_RES ATB_edit_AsciiChar (T_ED_DATA *editor, char character, UBYTE update)
{
USHORT unicodeChar;
if (character<ctrlMax)
unicodeChar = (USHORT)character;
else
unicodeChar = ATB_char_Unicode(character);
return ATB_edit_Char(editor, unicodeChar, update);
}
/*******************************************************************************
$Function: ATB_edit_Insert
$Description: Insert a character into the editor text
SPR#1983 - SH - Added 'text' parameter.
$Returns: TRUE if character was inserted
$Arguments: editor - The editor data
text - The text string (normal or hidden buffer)
character - The character - in unicode representation
*******************************************************************************/
static int ATB_edit_Insert (T_ED_DATA *editor, T_ATB_TEXT *text, USHORT character)
{
int result = FALSE;
TRACE_FUNCTION("ATB_edit_Insert()");
if (!ATB_edit_Mode(editor, ED_MODE_READONLY)) // Can't insert into read only mode
{
if (ATB_edit_Mode(editor, ED_MODE_OVERWRITE))
{
if (editor->cursor.pos < (editor->attr->size-1)) /* Make sure character will fit */
{
result = TRUE; /* We can write the cahracter */
/* If overwriting end of line, we need to increment length of string */
if (ATB_string_GetChar(text, editor->cursor.pos)==UNICODE_EOLN)
{
/* Ensure string ends with end of line character */
ATB_string_SetChar(text, editor->cursor.pos+1, UNICODE_EOLN);
text->len++;
}
}
}
else /* For insert mode, check if we have space */
{
result = ATB_string_MoveRight(text, editor->cursor.pos, 1, editor->attr->size); // move rest of text right to leave space
}
if (result)
{
ATB_string_SetChar(text, editor->cursor.pos, character); // Insert the character
}
}
else
{
result = FALSE;
}
return result;
}
/*******************************************************************************
$Function: ATB_edit_MultiTap
$Description: Displays the specified character over the cursor
$Returns: None.
$Arguments: editor - The editor data
character - The character to display
multitap - TRUE if multi-tap is currently in progress
*******************************************************************************/
ED_RES ATB_edit_MultiTap(T_ED_DATA *editor, USHORT character, BOOL multitap)
{
UBYTE oldmultitap;
ED_RES result = ED_OK;
TRACE_FUNCTION("ATB_edit_MultiTap()");
if (!editor)
return ED_BAD_HANDLE; // element does not exist
oldmultitap = editor->multitap;
editor->multitap = multitap;
/* If we were previously in multitap, and in insert mode, delete character under cursor.
* SPR#1983 - SH - Since this deletes current character in both visible and
* hidden buffer, do this before inserting character to either buffer. */
if (oldmultitap && !ATB_edit_Mode(editor, ED_MODE_OVERWRITE))
{
ATB_edit_DeleteRight(editor);
}
/* Hidden mode */
if (ATB_edit_Mode(editor, ED_MODE_HIDDEN)) /* In hidden mode... */
{
/* SPR#1983 - SH - Now use ATB_edit_Insert */
ATB_edit_Insert(editor, editor->hiddenText, character);
if (!multitap) /* n multi-tap, show character...*/
character = UNICODE_STAR; /* ...otherwise show star */
}
result = ATB_edit_Char(editor,character,FALSE);
ATB_edit_Update(editor, 0);
return result;
}
/*******************************************************************************
$Function: ATB_edit_AsciiMultiTap
$Description: Displays the specified ascii character over the cursor
$Returns: None.
$Arguments: editor - The editor data
character - The ascii character to display
multitap - TRUE if multi-tap is currently in progress
*******************************************************************************/
ED_RES ATB_edit_AsciiMultiTap(T_ED_DATA *editor, char character, BOOL multitap)
{
USHORT unicodeChar;
if (character<ctrlMax)
unicodeChar = (USHORT)character;
else
unicodeChar = ATB_char_Unicode(character);
return ATB_edit_MultiTap(editor, unicodeChar, multitap);
}
/*******************************************************************************
$Function: ATB_edit_FindNext
$Description: For formatted input, adds a character to the input buffer then finds
the next non-fixed character space for the cursor to occupy
$Returns: None
$Arguments: editor - The editor data
character - The character (or code) to insert
*******************************************************************************/
static void ATB_edit_FindNext(T_ED_DATA *editor)
{
char *format = editor->attr->FormatString;
char formatchar;
UBYTE inField = ENTRY_NOT_IN_FIELD;
TRACE_FUNCTION("ATB_edit_FindNext()");
/* Check for delimited field */
if (editor->formatIndex>0)
{
formatchar = format[editor->formatIndex-1];
if ((formatchar>'0' && formatchar<='9') || formatchar=='*')
inField = ENTRY_IN_FIELD;
}
formatchar = format[editor->formatIndex];
if ((formatchar>'0' && formatchar<='9') || formatchar=='*')
inField = ENTRY_ENTERING_FIELD;
/* Check for cursor right at end of string - don't allow */
if (editor->cursor.pos>=editor->attr->text.len
&& editor->formatIndex>-1 && inField==ENTRY_NOT_IN_FIELD)
{
return;
}
/* Move cursor position right */
editor->cursor.pos = ATB_string_IndexMove(&editor->attr->text, editor->cursor.pos, 1);
/* Check for start of fixed input field */
if (inField==ENTRY_ENTERING_FIELD)
{
editor->formatIndex++; // Get us into the field...
editor->fieldIndex = 0; // ...and reset the field index
formatchar = format[editor->formatIndex];
if (formatchar=='M')
editor->textcase = ED_CASE_UPPER;
if (formatchar=='m')
editor->textcase = ED_CASE_LOWER;
inField = ENTRY_IN_FIELD;
}
/* Check whether we're in a fixed input field, e.g. "4N" or "8X" */
if (inField==ENTRY_IN_FIELD) // So we don't look back beyond start of string
{
formatchar = format[editor->formatIndex-1];
editor->fieldIndex++; // Increment the position in the field
if (editor->fieldIndex==(int)(formatchar-'0')) // If we've entered the number of characters specified (note- will never happen for the '*' !)
{
editor->formatIndex++; // point to NULL at end of string (no more input)
}
return;
}
/* If not, just look at next format character as usual */
editor->formatIndex++; // Point to next character
while (editor->formatIndex<strlen(format) && format[editor->formatIndex]=='\\') // Fixed characters encountered
{
editor->cursor.pos = ATB_string_IndexMove(&editor->attr->text, editor->cursor.pos, 1); // Skip over them
editor->formatIndex+=2;
}
if (editor->formatIndex>(strlen(format))) // Don't look beyond end of string
editor->formatIndex = strlen(format);
return;
}
/*******************************************************************************
$Function: ATB_edit_FindPrev
$Description: For formatted input, finds the previous non-fixed character and
moves the cursor there if possible
$Returns: FINDPREV_NO_CHANGE if the cursor position is not changed (nowhere to go)
FINDPREV_PREV_FOUND if the previous character has been found
FINDPREV_FIRST_CHAR if the cursor was over the first non-fixed character
FINDPREV_LAST_CHAR if the cursor is at the last non-fixed character
$Arguments: editor - The editor data
*******************************************************************************/
static USHORT ATB_edit_FindPrev(T_ED_DATA *editor)
{
char *format = editor->attr->FormatString;
char formatchar;
SHORT editIndex;
TRACE_FUNCTION("ATB_edit_FindPrev()");
/* Check if cursor is at start of string, return 2 */
if (editor->cursor.pos == 0)
{
return FINDPREV_FIRST_CHAR;
}
/* Check whether we're in a fixed input field, e.g. "4N" or "8X" */
if (editor->formatIndex>0) // So we don't look back beyond start of string
{
formatchar = format[editor->formatIndex-1];
if ((formatchar>'0' && formatchar<='9') || formatchar=='*') // If it's a number between 1 and 9, or a *
{
if (editor->cursor.pos > 0)
editor->cursor.pos--;
if (editor->cursor.pos < editor->attr->size-1) // (Don't decrement if at last char in string)
editor->fieldIndex--; // Decrement the position in the field
if (editor->fieldIndex==0) // If we've reached the beginning of the field
editor->formatIndex--; // Get out of the field
if (editor->cursor.pos==editor->attr->text.len-1) // Special case if last character - tell editor to shorten the string
return FINDPREV_LAST_CHAR;
return FINDPREV_PREV_FOUND; // then we're done
}
}
/* If not (or if we've just come out of one) just look at next format character as usual */
editIndex = editor->formatIndex-1; // Make copy of format position, starting off to left
while (editIndex>0)
{
if (format[editIndex-1]=='\\') // If there's a fixed char
editIndex -=2; // Look back a further 2 characters
else // If there's a non-fixed character
break; // then exit loop
}
if (editIndex==-1) // Go back from 1st character in editor
{
return FINDPREV_FIRST_CHAR;
}
formatchar = format[editIndex-1];
if ((formatchar>'0' && formatchar<='9') || formatchar=='*')
editor->fieldIndex--;
if (editIndex>-1) // Provided there is somewhere to go....
{
while(editor->formatIndex>editIndex)
{
if (editor->cursor.pos > 0)
{
editor->cursor.pos--; // move cursor there
editor->formatIndex--;
}
if (format[editor->formatIndex]=='\\')
editor->formatIndex--;
}
return FINDPREV_PREV_FOUND; // Found new position
}
return FINDPREV_NO_CHANGE; // Position unchanged
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -