📄 atbeditor.c
字号:
/*******************************************************************************
CONDAT (UK)
********************************************************************************
This software product is the property of Condat (UK) Ltd and may not be
disclosed to any third party without the express permission of the owner.
********************************************************************************
$Project name:
$Project code:
$Module:
$File: ATBEditor.c
$Revision:
$Author: SH - Condat(UK)
$Date:
********************************************************************************
Description: ATB Editor component.
********************************************************************************
$History: ATBEditor.c
$End
*******************************************************************************/
#ifndef ATB_EDITOR_C
#define ATB_EDITOR_C
#if defined (NEW_FRAME)
#include "typedefs.h"
#include "vsi.h"
#include "pei.h"
#include "custom.h"
#include "gsm.h"
#else
#include "stddefs.h"
#include "custom.h"
#include "gsm.h"
#include "vsi.h"
#endif
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "dspl.h"
#include "ATBCommon.h"
#include "ATBDisplay.h"
#include "ATBEditor.h"
#include "font_bitmaps.h"
#include "cus_aci.h"
#include "p_sim.h"
#include "pcm.h"
#undef TRACE_ATBEDITOR
/*******************************************************************************
LOCAL FUNCTION PROTOTYPES
*******************************************************************************/
/* SPR#1983 - SH - Add 'text' parameter */
static int ATB_edit_Insert (T_ED_DATA *editor, T_ATB_TEXT *text, USHORT character);
static void ATB_edit_FindNext(T_ED_DATA *editor);
static USHORT ATB_edit_FindPrev(T_ED_DATA *editor);
static void ATB_edit_OutTextLines (T_ED_DATA *editor);
static void ATB_edit_WordWrap(T_ED_DATA *editor);
static void ATB_edit_UpdateCursorPos(T_ED_DATA *editor);
static ED_RES ATB_edit_Update (T_ED_DATA *editor, int dy);
static void ATB_edit_LineDestroyAll(T_ED_DATA *editor);
/*******************************************************************************
$Function: ATB_edit_Create
$Description: Create the editor. Allocate memory for the editor data and set up
some default parameters.
$Returns: Pointer to the editor data, or NULL if memory allocation failed.
$Arguments: editAttr - The editor attributes (caller allocated)
callback - Callback function
*******************************************************************************/
T_ED_DATA* ATB_edit_Create (T_ED_ATTR *editAttr, T_ED_CB callback)
{
T_ED_DATA *editor;
TRACE_FUNCTION("ATB_edit_Create()");
/* Allocate memory for editor data */
editor = (T_ED_DATA *) ATB_mem_Alloc(sizeof(T_ED_DATA));
if (!editor)
return NULL;
/* Reset editor data */
memset(editor, 0, sizeof(T_ED_DATA));
editor->display = FALSE;
editor->handler = callback;
editor->attr = editAttr;
editor->cursor.width = 8;
editor->initialised = FALSE;
editor->line = NULL;
return editor;
}
/*******************************************************************************
$Function: ATB_edit_Destroy
$Description: Delete the editor. Free the allocated memory.
$Returns: ED_OK - OK
ED_BAD_HANDLE - Editor data is null pointer
$Arguments: editor - The editor data
*******************************************************************************/
ED_RES ATB_edit_Destroy (T_ED_DATA *editor)
{
ED_RES result = ED_OK;
TRACE_FUNCTION("ATB_edit_Destroy()");
if (editor)
{
ATB_edit_LineDestroyAll(editor);
if (editor->hiddenText)
{
ATB_edit_HiddenExit(editor);
}
ATB_mem_Free((void *)editor, sizeof(T_ED_DATA));
}
else
result = ED_BAD_HANDLE;
return result;
}
/*******************************************************************************
$Function: ATB_edit_Init
$Description: Initialise the editor. Ensures that valid combinations of editing modes
are set. Sets uppercase/lowercase appropriately. Moves the cursor
to the correct place in the text. Performs a word-wrap.
$Returns: ED_OK - OK
$Arguments: editor - The editor data
*******************************************************************************/
ED_RES ATB_edit_Init (T_ED_DATA *editor)
{
TRACE_FUNCTION("ATB_edit_Init()");
if (!editor) /* If editor handle doesn't exist, return error */
return ED_BAD_HANDLE;
/* Get the length of the supplied string */
ATB_string_Length(&editor->attr->text);
/* SPR#1983 - SH - Set CAPS preference after moving cursor,
* as any cursor moves now reset CAPS to LOWER case. */
ATB_edit_SetCase(editor, ED_CASE_LOWER);
/* Non read-only modes*/
if (!ATB_edit_Mode(editor, ED_MODE_READONLY))
{
/* Initialise hidden mode */
if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
{
ATB_edit_HiddenInit(editor);
ATB_edit_SetMode(editor, ED_MODE_OVERWRITE);
}
/* Initialise formatted mode */
if (ATB_edit_Mode(editor, ED_MODE_FORMATTED))
{
ATB_edit_SetMode(editor, ED_MODE_OVERWRITE | ED_MODE_ALPHA);
ATB_edit_MoveCursor(editor,ctrlTop,FALSE); /* Send cursor to start of string */
/* Check for "M" & "m" formats; these set the case to upper/lower by default. */
/* SPR#1983 - SH - Also, overwrite mode can be switched off for these
* cases, free entry allowed.*/
ATB_edit_SetCase(editor, ED_CASE_CAPS); /* Caps is on by default */
if (strcmp(editor->attr->FormatString, "*M")==0)
{
ATB_edit_SetCase(editor, ED_CASE_UPPER);
ATB_edit_ResetMode(editor, ED_MODE_OVERWRITE);
}
if (strcmp(editor->attr->FormatString, "*m")==0)
{
ATB_edit_SetCase(editor, ED_CASE_LOWER);
ATB_edit_ResetMode(editor, ED_MODE_OVERWRITE);
}
}
/* Of the cursor modes, only formatted starts at the top, others start at the bottom */
else
{
ATB_edit_MoveCursor(editor, ctrlBottom, FALSE);
/* SPR#1983 - SH - If the buffer is empty, first character will be capitalised.
* Otherwise, lowercase is the default. */
if (editor->attr->text.len==0)
{
ATB_edit_SetCase(editor, ED_CASE_CAPS); /* Caps is on if first character */
}
}
}
/* No cursor modes */
else
{
ATB_edit_MoveCursor(editor, ctrlTop, FALSE);
}
/* Format text */
ATB_edit_Update(editor, 0);
/* Make editor visible */
editor->display = TRUE; /* really show it */
return ED_OK;
}
/*******************************************************************************
$Function: ATB_edit_Reset
$Description: Reset the editor - move the cursor to the start.
$Returns: ED_BAD_HANDLE - Editor data pointer is null
ED_OK - OK
$Arguments: editor - The editor data
*******************************************************************************/
ED_RES ATB_edit_Reset (T_ED_DATA *editor)
{
TRACE_FUNCTION("ATB_edit_Reset()");
if (!editor)
return ED_BAD_HANDLE; /* Editor does not exist */
editor->cursor.pos = 0; /* Reset cursor position */
editor->initialised = FALSE; /* Fully wrap all of text */
ATB_edit_Refresh(editor); /* Refresh word wrap */
return ED_OK;
}
/*******************************************************************************
$Function: ATB_edit_Show
$Description: Show the editor, if it is visible.
$Returns: ED_OK - OK
$Arguments: editor - The editor data
*******************************************************************************/
ED_RES ATB_edit_Show (T_ED_DATA *editor)
{
UBYTE previousFont = -1; // store previous font
USHORT editX = editor->attr->win_size.px; // pos. of left of edit window
USHORT editY = editor->attr->win_size.py; // pos. of top of edit window
USHORT editWidth = editor->attr->win_size.sx; // width of edit window
USHORT editHeight = editor->attr->win_size.sy; // height of edit window
TRACE_FUNCTION("ATB_edit_Show()");
if (!editor)
return ED_BAD_HANDLE; // Editor doesn't exist
if (editor->display)
{
resources_setColour(editor->attr->colour);
if (editor->attr->font != (UBYTE) -1)
previousFont = dspl_SelectFontbyID(editor->attr->font); // setup font
dspl_Clear(editX,editY,editX+editWidth-1,editY+editHeight-1); // Clear the editor window
ATB_edit_OutTextLines(editor); // Show text
/* Display cursor, if it's switched on and we're not in multitap */
if (editor->attr->cursor!=ED_CURSOR_NONE && !editor->multitap)
{
ATB_display_Cursor(&editor->attr->text, editor->cursor.pos, editor->attr->cursor, editX+editor->cursor.x,editY+editor->cursor.y,
editor->cursor.width,editor->cursor.height);
}
}
if (previousFont != (UBYTE) -1)
dspl_SelectFontbyID(previousFont); // Restore previous font
return ED_OK;
}
/*******************************************************************************
$Function: ATB_edit_Refresh
$Description: Refresh the editor word wrap etc.
$Returns: ED_OK - OK
$Arguments: editor - The editor data
*******************************************************************************/
ED_RES ATB_edit_Refresh (T_ED_DATA *editor)
{
TRACE_FUNCTION("ATB_edit_Refresh()");
if (!editor)
return ED_BAD_HANDLE; /* editor does not exist */
/* Get the length of the supplied string */
ATB_string_Length(&editor->attr->text);
/* Update word wrap */
ATB_edit_Update(editor, 0);
return ED_OK;
}
/*******************************************************************************
$Function: ATB_edit_Hide
$Description: Hide the editor
$Returns: ED_BAD_HANDLE - Editor data pointer is null
ED_OK - OK
$Arguments: editor - The editor data
*******************************************************************************/
ED_RES ATB_edit_Hide (T_ED_DATA *editor)
{
TRACE_FUNCTION("ATB_edit_Hide()");
if (!editor)
return ED_BAD_HANDLE; /* element does not exist */
editor->display = FALSE; /* editor is not visible */
if (editor->handler) /* call event handler */
{
editor->handler(ED_INVISIBLE,editor);
}
return ED_OK;
}
/*******************************************************************************
$Function: ATB_edit_Unhide
$Description: Unhide the editor
$Returns: ED_BAD_HANDLE - Editor data pointer is null
ED_OK - OK
$Arguments: editor - The editor data
*******************************************************************************/
ED_RES ATB_edit_Unhide (T_ED_DATA *editor)
{
TRACE_FUNCTION("ATB_edit_Unhide()");
if (!editor)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -