📄 atbeditor.c
字号:
return ED_BAD_HANDLE; /* element does not exist */
editor->display = TRUE;
if (editor->handler) /* call event handler */
{
editor->handler(ED_VISIBLE,editor);
}
return ED_OK;
}
/*******************************************************************************
$Function: ATB_edit_MoveCursor
$Description: Move the cursor
$Returns: ED_ERROR - Unexpected cursor movement
ED_OK - OK
$Arguments: editor - The editor data
character - The control character (ctrlLeft etc)
update - TRUE if word wrap is to be carried out after move
*******************************************************************************/
ED_RES ATB_edit_MoveCursor (T_ED_DATA *editor, USHORT control, UBYTE update)
{
USHORT altCursorPos;
SHORT dy;
ED_RES result;
TRACE_FUNCTION("ATB_edit_MoveCursor");
if (!editor)
return ED_BAD_HANDLE; /* element does not exist */
/* Can't move cursor in hidden mode, except to start and end */
result = ED_OK;
dy = 0;
switch(control)
{
case ctrlLeft:
if (!ATB_edit_Mode(editor, ED_MODE_READONLY)) /* Not in read only mode*/
{
if (ATB_edit_Mode(editor, ED_MODE_FORMATTED)) /* formatted input */
{
ATB_edit_FindPrev(editor); /* find previous non-fixed character */
}
else
{
altCursorPos = editor->cursor.pos; /* Store original cursor position */
editor->cursor.pos = ATB_string_IndexMove(&editor->attr->text, editor->cursor.pos, -1);
if (editor->cursor.pos==altCursorPos) /* If we're at the start of text */
{
ATB_edit_MoveCursor(editor, ctrlBottom, FALSE); /* .. then go to the end of text! */
}
}
}
break;
case ctrlRight:
if (!ATB_edit_Mode(editor, ED_MODE_READONLY)) /* Not in read only mode*/
{
if (ATB_edit_Mode(editor, ED_MODE_FORMATTED)) /* formatted input */
{
ATB_edit_FindNext(editor); /* Move cursor forward once */
}
else
{
altCursorPos = editor->cursor.pos; /* Store original cursor position */
editor->cursor.pos = ATB_string_IndexMove(&editor->attr->text, editor->cursor.pos, 1);
if (editor->cursor.pos==altCursorPos) /* If we're at the end of text */
{
ATB_edit_MoveCursor(editor, ctrlTop, FALSE); /* .. then go to the start of text! */
}
}
}
break;
case ctrlUp:
if (editor->cursor.line > 0)
dy = -1;
break;
case ctrlDown:
if (editor->cursor.line < (editor->numLines-1))
dy = 1;
break;
case ctrlTop:
editor->cursor.pos = 0;
editor->initialised = FALSE; /* We need to recalculate whole editor */
/* For formatted mode, skip over any fixed characters at the start */
if (ATB_edit_Mode(editor, ED_MODE_FORMATTED))
{
editor->formatIndex = 0;
editor->fieldIndex = 0;
ATB_edit_FindNext(editor);
ATB_edit_FindPrev(editor);
}
break;
case ctrlBottom:
/* Search until we find end of text */
while (ATB_string_GetChar(&editor->attr->text, editor->cursor.pos)!=UNICODE_EOLN)
{
editor->cursor.pos++;
}
editor->initialised = FALSE; /* We need to recalculate whole editor */
break;
default:
TRACE_EVENT("** ERROR ** Unexpected cursor movement.");
return ED_ERROR;
break;
}
/* SPR#1983 - SH - In caps mode, any keypress switches to lower case */
if (editor->textcase==ED_CASE_CAPS)
editor->textcase = ED_CASE_LOWER;
if (update || dy!=0)
{
ATB_edit_Update(editor, dy);
}
return ED_OK;
}
/*******************************************************************************
$Function: ATB_edit_DeleteLeft
$Description: Delete the character to the left of the cursor
$Returns: ED_DONE - Deleted from start of editor, exit editor
ED_OK - OK
$Arguments: editor - The editor data
*******************************************************************************/
ED_RES ATB_edit_DeleteLeft (T_ED_DATA *editor)
{
ED_RES result = ED_OK;
USHORT altCursorPos;
char formatchar;
TRACE_FUNCTION("ATB_edit_DeleteLeft");
if (!editor)
return ED_BAD_HANDLE; /* element does not exist */
/* SPR#1983 - SH - Hidden text changes now mirror normal text changes. */
/* Formatted mode */
if (ATB_edit_Mode(editor, ED_MODE_FORMATTED)) /* Formatted input */
{
if (ATB_edit_FindPrev(editor)!=FINDPREV_FIRST_CHAR) /* Skip over fixed characters */
{
if (editor->formatIndex>0) /* So we don't look back beyond start of string */
{
/* If we're in a delimited field, do normal delete, otherwise just cursor back */
formatchar = editor->attr->FormatString[editor->formatIndex-1];
if ((formatchar>'0' && formatchar<='9') || formatchar=='*') /* If it's a number between 1 and 9, or a * */
{
ATB_string_MoveLeft(&editor->attr->text, editor->cursor.pos, 1);
if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
{
ATB_string_MoveLeft(editor->hiddenText, editor->cursor.pos, 1);
}
}
}
result = ED_OK;
}
else
{
result = ED_DONE; /* Delete with empty buffer - escape from editor */
}
}
/* Overwrite mode */
else if (ATB_edit_Mode(editor, ED_MODE_OVERWRITE))
{
/* If we're at the end of the string, shift the '0' back */
if (editor->cursor.pos>0)
{
if (editor->cursor.pos == editor->attr->text.len)
{
result = ATB_edit_MoveCursor(editor, ctrlLeft, FALSE);
ATB_string_SetChar(&editor->attr->text, editor->cursor.pos, UNICODE_EOLN);
editor->attr->text.len--;
if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
{
ATB_string_SetChar(editor->hiddenText, editor->cursor.pos, UNICODE_EOLN);
editor->hiddenText->len--;
}
}
/* Otherwise, overwrite with a space */
else
{
result = ATB_edit_MoveCursor(editor, ctrlLeft, FALSE);
ATB_string_SetChar(&editor->attr->text, editor->cursor.pos, UNICODE_SPACE);
if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
{
ATB_string_SetChar(editor->hiddenText, editor->cursor.pos, UNICODE_SPACE);
}
}
}
else
{
result = ED_DONE; /* Delete with empty buffer - escape from editor */
}
}
else
{
/* Otherwise, just perform normal delete operation */
altCursorPos = ATB_string_IndexMove(&editor->attr->text, editor->cursor.pos,-1);
if (altCursorPos!=editor->cursor.pos)
{
ATB_string_MoveLeft(&editor->attr->text, altCursorPos, editor->cursor.pos-altCursorPos); // Delete the difference!
if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
{
ATB_string_MoveLeft(editor->hiddenText, altCursorPos, editor->cursor.pos-altCursorPos); // Delete the difference!
}
editor->cursor.pos = altCursorPos;
result = ED_OK;
}
else
result = ED_DONE;
}
/* SPR#1983 - SH - In caps mode, any keypress switches to lower case */
if (editor->textcase==ED_CASE_CAPS)
editor->textcase = ED_CASE_LOWER;
ATB_edit_Update(editor,0);
return result;
}
/*******************************************************************************
$Function: ATB_edit_DeleteRight
$Description: Delete the character to the right of the cursor
$Returns: ED_OK - OK
$Arguments: editor - The editor data
*******************************************************************************/
ED_RES ATB_edit_DeleteRight (T_ED_DATA *editor)
{
ED_RES result;
char formatchar;
TRACE_FUNCTION("ATB_edit_DeleteRight");
if (!editor)
return ED_BAD_HANDLE; /* element does not exist */
/* SPR#1983 - SH - Hidden text changes now mirror normal text changes. */
/* Formatted mode */
if (ATB_edit_Mode(editor, ED_MODE_FORMATTED)) /* Formatted input */
{
/* If we're in a delimited field, do normal delete right, otherwise ignore */
if (editor->formatIndex>0)
{
formatchar = editor->attr->FormatString[editor->formatIndex-1];
if ((formatchar>'0' && formatchar<='9') || formatchar=='*') /* If it's a number between 1 and 9, or a * */
{
ATB_string_MoveLeft(&editor->attr->text, editor->cursor.pos, 1);
if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
{
ATB_string_MoveLeft(editor->hiddenText, editor->cursor.pos, 1);
}
}
}
}
/* Overwrite mode */
else if (ATB_edit_Mode(editor, ED_MODE_OVERWRITE))
{
/* Make sure we're not at the end of the string */
if (editor->cursor.pos<editor->attr->text.len)
{
if (!ATB_edit_Mode(editor, ED_MODE_HIDDEN))
{
ATB_string_SetChar(&editor->attr->text, editor->cursor.pos, UNICODE_SPACE);
}
}
}
else
{
ATB_string_MoveLeft(&editor->attr->text, editor->cursor.pos, 1); /* Otherwise, just perform normal delete operation */
if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
{
ATB_string_MoveLeft(&editor->attr->text, editor->cursor.pos, 1); /* Otherwise, just perform normal delete operation */
}
}
/* SPR#1983 - SH - In caps mode, any keypress switches to lower case, if we're
* not in multi-tap */
if (!editor->multitap && editor->textcase==ED_CASE_CAPS)
editor->textcase = ED_CASE_LOWER;
ATB_edit_Update(editor,0);
return ED_OK;
}
/*******************************************************************************
$Function: ATB_edit_ClearAll
$Description: Clear all text from the editor, move cursor to the top
$Returns: ED_BAD_HANDLE - Editor data pointer is null
ED_DONE - Deleted from start of editor, exit editor
ED_OK - OK
$Arguments: editor - The editor data
*******************************************************************************/
ED_RES ATB_edit_ClearAll (T_ED_DATA *editor)
{
USHORT textLength;
ED_RES result;
TRACE_FUNCTION("ATB_edit_ClearAll()");
if (!editor)
return ED_BAD_HANDLE; // element does not exist
/* FORMATTED MODE */
if (ATB_edit_Mode(editor, ED_MODE_FORMATTED))
{
/* Find first non-fixed character */
ATB_edit_MoveCursor(editor, ctrlTop, FALSE); // starting from the top.
while (editor->cursor.pos<textLength)
{
ATB_edit_Char(editor, UNICODE_SPACE, FALSE);
ATB_edit_FindNext(editor); // Overwrite everything with spaces
}
ATB_edit_MoveCursor(editor,ctrlTop,FALSE);
}
/* NORMAL MODE */
else
{
if (textLength==0)
{
result = ED_DONE;
}
else
{
memset(editor->attr->text.data,'\0',editor->attr->size*ATB_string_Size(&editor->attr->text)); /* Clear buffer */
editor->attr->text.len = 0;
if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
{
memset(editor->hiddenText->data,'\0',editor->attr->size*ATB_string_Size(&editor->attr->text));
editor->hiddenText->len = 0;
}
ATB_edit_Reset(editor); /* Send cursor to start */
result = ED_OK;
}
}
ATB_edit_Update(editor,0); /* Update word wrap & cursor */
return ED_OK;
}
/*******************************************************************************
$Function: ATB_edit_Char
$Description: Insert a character into the editor text, or execute a control code
$Returns: ED_OK - OK
$Arguments: editor - The editor data
character - The character - in unicode representation
update - TRUE if word wrap is to be carried out after insertion
*******************************************************************************/
ED_RES ATB_edit_Char (T_ED_DATA *editor, USHORT character, UBYTE update)
{
TRACE_FUNCTION("ATB_edit_Char()");
if (!editor)
return ED_BAD_HANDLE; // element does not exist
switch (character)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -