📄 mfw_edt.c
字号:
return MfwResOk;
}
//Create a copy of the current word.
//GW 18/09/01 - Use 'isAWordChar' procedure
MfwRes edtCopyString (MfwHnd e, char* removeWord)
{
MfwEdt *edit;
char *textBfr;
int i,j;
int stChr,endChr;
TRACE_FUNCTION("edtCopyString");
if (dspl_get_char_type() != DSPL_TYPE_ASCII)
{ //String is unicode - can't remove word (could remove a char but...)
return(MfwResIllHnd);
}
if (!e)
return MfwResIllHnd;
if (((MfwHdr *)e)->type != MfwTypEdt)
return MfwResIllHnd; //* not an editor *
edit = ((MfwHdr *) e)->data;
textBfr = edit->attr->text;
if ((textBfr[0] == 0x80) || (textBfr[0] == 0x81) || (textBfr[0] == 0x82))
{//String is unicode - can't remove word (could remove a char but...)
return(MfwResIllHnd);
}
findWordBounds(edit, &stChr, &endChr);
//Copy word out
j = 0;
for (i=stChr;i<endChr;i++)
{
if (j<MAXWORD_ARRAY-1)
{
removeWord[j] = textBfr[i];
if (isAWordChar(removeWord[j]))
j++;//not punctuation.
else if (removeWord[j] == ' ') //but do include last space (if it is a space)
j++;
}
}
removeWord[j] = 0x00;
edit->display = 1;
updateWindow( edit, 0);
edtUpdate(edit);
return MfwResOk;
}
MfwRes edtInsertUnicodeString (MfwHnd e, char* insWordChar)
{
MfwEdt *edit;
U16 *unicodeBfr;
int lenText;
int lenInsWord;
int maxTextBfrLen;
int i;
U16* insWordUnicode;
insWordUnicode = (U16*) insWordChar;
TRACE_FUNCTION("edtInsertUnicodeString");
if (!e)
return MfwResIllHnd;
if (((MfwHdr *)e)->type != MfwTypEdt)
return MfwResIllHnd; //* not an editor
edit = ((MfwHdr *) e)->data;
if (insWordUnicode == NULL)
return (MfwResOk); //no string to insert - trivial operation.
if (insWordUnicode[0] == 0x0000)
return (MfwResOk); //no string to insert - trivial operation.
unicodeBfr = (U16*) &edit->attr->text[2];
if ((edit->attr->text[0] != (char)0x80) &&
(edit->attr->text[0] != (char)0x81) &&
(edit->attr->text[0] != (char)0x82))
{//String is unicode
return (edtInsertString (e, insWordChar));
}
maxTextBfrLen = edit->attr->size;
lenText = strlenUnicode(unicodeBfr);
lenInsWord = strlenUnicode(insWordUnicode);
if ((lenText+lenInsWord) >= maxTextBfrLen)
return (MfwResErr); //String too long
//move text up by 'lemnInsWord' chars
for (i=lenText/2;i>=edit->cp;i--)
{
unicodeBfr[i+lenInsWord]=unicodeBfr[i];
}
//and copy string into buffer.
for (i=0;i<lenInsWord/2;i++)
unicodeBfr[edit->cp+i] = insWordUnicode[i];
edit->cp = edit->cp+lenInsWord/2;
//Update cursor position
//<TBD>
//And output updated text
edit->display = 1;
updateWindow( edit, 0);
edtUpdateUnicode(edit);
return MfwResOk;
}
/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417) MODULE : MFW_EDT |
| STATE : code ROUTINE : edtInsert |
+--------------------------------------------------------------------+
PURPOSE : insert editing char
SPR1017 - NH - Added "curMode" and "curCP" parameters.
*/
static int edtInsert (int c, char *b, int s, U8 curMode, U16 curCP)
{
int size = (c > 0x80) ? 2 : 1;
TRACE_FUNCTION("edtInsert");
if (!curMode)
return 0;
if (!(curMode & edtModOverWr))
{
if ((int) strlen(b) >= s - size) /* no more space in buffer */
return 0;
moveRight(b+curCP,strlen(b+curCP),size);
}
else
{
if (curCP > s-size ) /* SH - for overwrite mode, only stop input */
return 0; /* when the cursor is at the maximum string size */
}
if (size == 2)
*((U16 *) (b+curCP)) = (U16) c;
else
{
*(b+strlen(b)+1) = (char) 0; // SH - make sure string is null terminated
*(b+curCP) = (char) c;
}
return 1;
}
/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417) MODULE : MFW_EDT |
| STATE : code ROUTINE : moveRight |
+--------------------------------------------------------------------+
PURPOSE : move right memory
s = no of chars to move
d = size (no of chars to be inserted in string)
b = current position
*/
void moveRight (char *b, int s, int d)
{
char *p;
TRACE_FUNCTION("edtInsert");
b += s++; /* start with trailing zero */
p = b + d; /* new = old + distance */
while (s--)
{
*p = *b;
p--;
b--;
}
}
/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417) MODULE : MFW_EDT |
| STATE : code ROUTINE : moveLeft |
+--------------------------------------------------------------------+
PURPOSE : move left memory
s = no of chars to move
d = size (no of chars to be inserted in string)
b = current position
str - string
*/
void moveLeft (char * str, int ofs)
{
while (*str)
{
str[0] = str[ofs];
if (*str)
str++;
}
}
/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417) MODULE : MFW_EDT |
| STATE : code ROUTINE : edtCommand |
+--------------------------------------------------------------------+
PURPOSE : handle mfw windows command
*/
static int edtCommand (U32 cmd, void *h)
{
TRACE_FUNCTION("edtCommand");
switch (cmd)
{
case MfwCmdDelete: /* delete me */
if (!h)
return 0;
edtDelete(h);
return 1;
case MfwCmdUpdate: /* repaint */
if (!h || ((MfwHdr *) h)->type != MfwTypEdt)
return 0;
edtUpdate(((MfwHdr *) h)->data);
return 1;
default:
break;
}
return 0;
}
/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417) MODULE : MFW_EDT |
| STATE : code ROUTINE : |
+--------------------------------------------------------------------+
PURPOSE :
GW 06/09/01 - Created
*/
//Move part of string right (delete char)
void moveLeftUnicode(U16* unicodeStr, int nChars)
{
TRACE_FUNCTION("moveLeftUnicode");
//Copy until end of line char reached - do not overwrite existing EOLN char
while (unicodeStr[0] != UNICODE_EOLN)
{
unicodeStr[0] = unicodeStr[nChars];
if (unicodeStr[0] != UNICODE_EOLN)
unicodeStr++;
//else we have copied end of line char - stop.
}
}
/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417) MODULE : MFW_EDT |
| STATE : code ROUTINE : |
+--------------------------------------------------------------------+
PURPOSE :
GW 06/09/01 - Created
*/
U16 strlenUnicodePixels(U16* str)
{
U16 len = 0;
TRACE_FUNCTION("strlenUnicodePixels");
while (*str!=UNICODE_EOLN)
{ //Is next char an ascii char ?
if ((*str & UNICODE_NONASCII) != 0)
len = len+12;
else
len = len+6;
str++;
}
return (len);
}
/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417) MODULE : MFW_EDT |
| STATE : code ROUTINE : |
+--------------------------------------------------------------------+
PURPOSE :
GW 06/09/01 - Created
*/
U16* strchrUnicode(U16* str,U16 chr)
{
TRACE_FUNCTION("strchrUnicode");
while (*str!=UNICODE_EOLN)
{
if (*str==chr)
return (str);
else
str++;
}
return (NULL);
}
/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417) MODULE : MFW_EDT |
| STATE : code ROUTINE : |
+--------------------------------------------------------------------+
PURPOSE :
GW 06/09/01 - Created
*/
//Return pointer to end of unicode string.
U16* strendUnicode(U16* tp)
{ TRACE_FUNCTION("strendUnicode");
while (*tp!=UNICODE_EOLN)
{
tp++;
}
return (tp);
}
/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417) MODULE : MFW_EDT |
| STATE : code ROUTINE : |
+--------------------------------------------------------------------+
PURPOSE :
GW 06/09/01 - Created
*/
//Move string right by 'nChars' (insert char)
static void moveRightUnicode(U16 *unicodeStr, int nChars)
{
U16* strEndPtr;
TRACE_FUNCTION("moveRightUnicode");
strEndPtr = strendUnicode( unicodeStr);
while (strEndPtr >= unicodeStr)
{
strEndPtr[nChars] = strEndPtr[0];
strEndPtr--;
}
}
static int edtInsertUnicode (MfwEdt *edit, int c, U16 *b, int s)
{ //Unicode chars are always 2 bytes.
U16* bCursor;
TRACE_FUNCTION("edtInsertUnicode");
if (!edit->curMode)
return 0;
if ( strlenUnicode(b) >= s/* -2 MC SPR 1319, allow last 2 bytes to be used*/ ) //* no more space in buffer *
return 0;
bCursor = b+edit->cp;
if (!(edit->curMode & edtModOverWr))
moveRightUnicode(bCursor,1);
*((U16 *) (b+edit->cp )) = (U16) c;
return 1;
}
int wArray[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int getCharWidth(int nextChar)
{
int w;
if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR))
w = 6;
else
w = font_getCharWidth( ((nextChar & 0x00FF) <<8) | ((nextChar & 0xFF00) >>8) );
return (w);
}
static void edtOutTextLines (int px, int py, int ls, int ly, U16 *tpUnicode, unsigned char* tpAscii,
int fontHeight, int display)
{
U16 ctWord;
unsigned char ctByte;
unsigned int fitChars; //No of chars that fit on this line.
U16 nextChar; //next char to display
int lineWidth; //Width (so far) of the current line of text.
int dispEnd = 0;
int spaceChar;
int charWidth;
int punctuation;
char chr;
if ((tpAscii==NULL) && (tpUnicode == NULL))
return;
fitChars = 0;
if (tpAscii)
{
nextChar = (tpAscii[fitChars] << 8) & 0xFF00;
if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR))
{
fitChars++;
nextChar = (tpAscii[fitChars] << 8) & 0xFF00;
}
}
else
{
nextChar = tpUnicode[fitChars];
if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR))
{
fitChars++;
nextChar = tpUnicode[fitChars];
}
}
while ((nextChar != UNICODE_EOLN) && (!dispEnd)) /* any more to display */
{
fitChars = 0;
if (tpAscii)
{
charWidth = getCharWidth(nextChar);
nextChar = (tpAscii[fitChars] << 8) & 0xFF00;
if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR))
{ //linefeed - always start a new-line.
charWidth = ls+1;
}
}
else
{
nextChar = tpUnicode[fitChars];
charWidth = getCharWidth(nextChar);
if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR))
{ //linefeed - always start a new-line.
charWidth = ls+1;
}
}
lineWidth = 0;
spaceChar = -1;
while ((lineWidth <= ls) && (nextChar != UNICODE_EOLN))
{
lineWidth = lineWidth + charWidth;
//If the last char added still fits on the line
if (lineWidth <= ls)
{ //move on to the next character.
fitChars++;
//if the previous char was a space, we can cut the line on the next char.
punctuation = FALSE;
if ((nextChar & UNICODE_NONASCII) == 0)
{
chr = (nextChar >> 8) & 0x00FF;
if (chr==' ') // sbh - only space is punctuation now.
punctuation = TRUE;
}
//Remember when we find a space if it is not the first char of a new line
if ((fitChars > 1) &&
((punctuation) ||
(nextChar == UNICODE_STARTHIGHLIGHT)||
(nextChar == UNICODE_ENDHIGHLIGHT)))
{ //save char after space.
spaceChar = fitChars;
}
if (tpAscii)
{
charWidth = getCharWidth(nextChar);
nextChar = (tpAscii[fitChars] << 8) & 0xFF00;
}
else
{
nextChar = tpUnicode[fitChars];
charWidth = getCharWidth(nextChar);
}
if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR))
{ //linefeed - always start a new-line.
charWidth = ls+1;
}
}
}
if (nextChar == UNICODE_EOLN)
{ /* all fits fine ... */
dispEnd = TRUE;
}
else if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR))
{ //Break line on this linefeed char
}
else if (spaceChar != -1) // we have a space in the line
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -