📄 mfw_edt.c
字号:
{
fitChars = spaceChar;
}
if (tpAscii)
{
ctByte = tpAscii[fitChars]; /* save not fitting char */
tpAscii[fitChars] = 0x00;//UNICODE_EOLN; /* cut the line */
if (display)
dspl_TextOut((U16)px,(U16)py, 0, (char*)tpAscii); /* display line */
tpAscii[fitChars] = ctByte; /* restore */
tpAscii = &tpAscii[fitChars]; /* and go ahead */
//For linefeed char - move to next char.
if (((ctByte <<8) == UNICODE_LINEFEED) || ((ctByte <<8) == UNICODE_CR))
tpAscii++;
}
else
{
ctWord = tpUnicode[fitChars]; /* save not fitting char */
tpUnicode[fitChars] = UNICODE_EOLN; /* cut the line */
if (display)
dspl_TextOut((U16)px,(U16)py, DSPL_TXTATTR_UNICODE, (char*)tpUnicode); /* display line */
tpUnicode[fitChars] = ctWord; /* restore */
tpUnicode = &tpUnicode[fitChars]; /* and go ahead */
if ((ctWord == UNICODE_LINEFEED) || (ctWord == UNICODE_CR))
tpUnicode++;
}
py = py + fontHeight; /* move to next screen line */
if (py > ly - fontHeight) /* past end of screen ? */
dispEnd = TRUE; /* clip the rest */
}
}
/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417) MODULE : MFW_EDT |
| STATE : code ROUTINE : |
+--------------------------------------------------------------------+
PURPOSE :
GW 06/09/01 - Created
*/
MfwRes edtUpdateUnicode (MfwEdt *e)
{
int warn;
UBYTE temp;
S16 ls; /* width of edit window */
S16 ly; /* bottom of edit window */
U8 oldFont = -1; /* store previous font */
/* NM p004
U8 uMode;
*/
U16 *tpWord;
U16 *endChar;
static char bmp[5];
TRACE_FUNCTION("edtUpdateUnicode");
if (!e)
return MfwResIllHnd;
if (!e->attr->text)
return MfwResErr; /* no text to display */
if (((unsigned char)e->attr->text[0] < 0x80) || ((unsigned char)e->attr->text[0] > 0x83))
return MfwResErr; /* text is not unicode */
temp = dspl_get_char_type();
dspl_set_char_type(DSPL_TYPE_UNICODE);
if (!(e->flags & MfwEdtVisible))
e->display = 0; /* invisible editor */
tpWord = ((U16*)&e->attr->text[2]) + e->curOffs;
ls = e->attr->win.sx; /* width of edit window */
ly = (S16) (e->attr->win.py+e->attr->win.sy); /* bottom of edit window */
if (e->attr->font != (U8) -1)
oldFont = dspl_SelectFontbyID(e->attr->font); /* setup font */
e->fontHeight = dspl_GetFontHeight(); /* get height of curr font */
e->curMode = e->attr->mode; /* setup edi mode */
if (e->display)
dspl_Clear(e->attr->win.px,e->attr->win.py,(U16)(ls+e->attr->win.px-1),(U16)(ly-1));
dspl_SetCursor(0,(U8)(e->curMode&edtCurMask));
//Add a space to the end of the line
endChar = strendUnicode(tpWord);
if ((endChar[0] == UNICODE_EOLN) &&
(endChar[1] == UNICODE_EOLN))
{
endChar[0] = UNICODE_SPACE;
endChar[1] = UNICODE_EOLN;
edtOutTextLines(e->attr->win.px, e->attr->win.py, ls, ly, tpWord, NULL,
e->fontHeight, e->display); //* show it * /
//and remove space again.
endChar[0] = UNICODE_EOLN;
}
else
{ //Cannot add space
edtOutTextLines(e->attr->win.px, e->attr->win.py, ls, ly, tpWord, NULL,
e->fontHeight, e->display); //* show it * /
}
if (e->display && (e->curMode & edtCurMask))
dspl_SetCursorPos(e->curCX,e->curCY,e->curCSize,(S16)e->fontHeight); /* display cursor */
if (oldFont != (U8) -1)
dspl_SelectFontbyID(oldFont); /* restore previous font */
dspl_set_char_type(temp);
return MfwResOk;
}
/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417) MODULE : MFW_EDT |
| STATE : code ROUTINE : |
+--------------------------------------------------------------------+
PURPOSE :
GW 06/09/01 - Created
*/
//Incodmation relating to last 'space' char found.
typedef struct {
int charWidth;
int lineCharPos;
} T_SPACE_EDITINFO;
//Information about current editor
typedef struct {
int txtWidth;
int charWidth;
int endOfLine; //TRUE indicates end of a text line
int endOfText; //TRUE indicates no more chars in line.
int lineXpos; //Current x-pos (in pixels) of cursor.
int lineCharPos; //Current char/word position in array
int lastChar; //index of last char on cursor line
BOOL precedingEOL; // sbh - preceding character was a CR/LF
T_SPACE_EDITINFO space;
} T_EDITINFO;
//Calculate width of chars on screen so far.
//GW 18/09/01 - Corrected code dealing with linefeeds and also deal with carriage returns.
void getTotalWidth(U16 txtChar, int scrSxPixels, T_EDITINFO *editInfo )
{
char chr;
int punctuation;
TRACE_FUNCTION("getTotalWidth");
editInfo->endOfLine = FALSE;
if (editInfo->precedingEOL) // Previous character was CR/LF
{
editInfo->precedingEOL = FALSE;
editInfo->endOfLine = TRUE;
}
if (txtChar == UNICODE_EOLN)
{
editInfo->endOfText = TRUE;
editInfo->charWidth = getCharWidth(txtChar);//6; // sbh - Has width, so it can be wrapped if necessary
}
else if ((txtChar == UNICODE_LINEFEED) || (txtChar == UNICODE_CR))
{
editInfo->precedingEOL = TRUE;
editInfo->charWidth = getCharWidth(txtChar);//6;
}
else //GW-Get actual width for proportional fonts.
editInfo->charWidth = getCharWidth(txtChar);
if (editInfo->txtWidth+editInfo->charWidth > scrSxPixels)
{ //newline
editInfo->txtWidth = 0;
editInfo->endOfLine = TRUE;
//update start of window.
if ((txtChar == UNICODE_LINEFEED)||(txtChar == UNICODE_CR))
{
editInfo->lineCharPos = editInfo->space.lineCharPos+1;
}
else if (editInfo->space.lineCharPos > 0)
{ //reset editor position back to here
editInfo->lineCharPos = editInfo->space.lineCharPos+1;
editInfo->charWidth = editInfo->space.charWidth;
editInfo->endOfText = FALSE;
}
editInfo->space.lineCharPos = 0;
}
else
{
punctuation = FALSE;
if (txtChar==UNICODE_SPACE) // sbh - will only wrap on a space
punctuation = TRUE;
if ((punctuation) && (editInfo->txtWidth > 0))
{ //A space is a good point for a soft break - remember enough info so that this
//point can be restored
editInfo->space.lineCharPos = editInfo->lineCharPos;
if ((txtChar == UNICODE_LINEFEED) || (txtChar == UNICODE_CR))
editInfo->space.charWidth = getCharWidth(txtChar);
else
editInfo->space.charWidth = editInfo->charWidth;
}
}
}
//Update the cursor position
// SPR920 - NH (SH) - provide editor handle e, as cursor vars are now in structure
void updateCursorPos(MfwEdt *e, T_EDITINFO *editInfo)
{
TRACE_FUNCTION("updateCursorPos");
e->curCSize = editInfo->charWidth;
if (e->curCSize < 3)
e->curCSize = 3;
e->curCX = editInfo->txtWidth;
}
//dy - move cursor up/down screen by dy lines
MfwRes updateWindow (MfwEdt *e, int dy )
{
T_EDITINFO editInfo;
int winCharPos; //char position in string of the first text line in current window
int winLineNo; //line no of the first text line to be displayed
int ipCursorCharPos;
int opCursorCharPos;
int cursorLineNo; //line no the cursor is on
int linePos; //char pos in string of current line.
int lineNo; //overall displayed line (from start of text)
int editComplete; //flag indicating cursor position found/updated or end of line reached.
int scrSxPixels;
int scrSyLines;
char* textStartAscii;
U16* textStartUnicode;
U16 charUnicode; //current unicode char.
int textStrType;
TRACE_FUNCTION("UpdateWindow()");
//Set up screen size - the width in pixels and no of lines displayed.
if (e->fontHeight > 5)
scrSyLines = e->attr->win.sy / e->fontHeight;
else
scrSyLines = e->attr->win.sy / 6;
scrSxPixels = e->attr->win.sx;
ipCursorCharPos = e->cp;
if ((ipCursorCharPos < 0) || (ipCursorCharPos > 32767))
ipCursorCharPos = 0;
opCursorCharPos = ipCursorCharPos;
lineNo = 0;
winLineNo = 0;
winCharPos = 0;
editComplete = FALSE;
editInfo.endOfText = FALSE;
editInfo.lineCharPos = 0;
editInfo.lastChar = 9999;
editInfo.space.lineCharPos = 0;
editInfo.precedingEOL = FALSE;
linePos = 0;
editInfo.txtWidth = 0;
cursorLineNo = 0;
if ((e->attr->text[0] == (char)0x80) ||
(e->attr->text[0] == (char)0x81) ||
(e->attr->text[0] == (char)0x82))
{
textStrType = DSPL_TYPE_UNICODE;
textStartUnicode = (U16*) &e->attr->text[2]; /* start of edit text - 16 bits/char */
}
else
{
textStrType = DSPL_TYPE_ASCII;
textStartAscii = &e->attr->text[0]; /* start of edit text - 8 bits/char */
}
//Go through editor and work out
// (1) current x-pixel position for cursor
// (2) line number of the start of the display.
while( (!editInfo.endOfText) && (!editComplete) )
{
if (textStrType == DSPL_TYPE_UNICODE)
{
charUnicode = textStartUnicode[editInfo.lineCharPos];
getTotalWidth(charUnicode,scrSxPixels,&editInfo);
}
else
{
charUnicode = (textStartAscii[editInfo.lineCharPos] << 8) & 0xFF00;
getTotalWidth(charUnicode,scrSxPixels,&editInfo);
}
if (editInfo.endOfLine)
{
//newline or current char will not fit on previous line.
lineNo++;
linePos = editInfo.lineCharPos;
editInfo.txtWidth = 0;
//Is this the first line to be displayed in the editor?
if (editInfo.lineCharPos <= e->curOffs)
{
winLineNo = lineNo;
winCharPos= editInfo.lineCharPos;
}
}
if (editInfo.endOfText)
{
//Cursor is past end of line - move to char before end of line.
if (ipCursorCharPos > editInfo.lineCharPos)
{
ipCursorCharPos = editInfo.lineCharPos;
opCursorCharPos = editInfo.lineCharPos;
}
}
if (editInfo.lineCharPos == ipCursorCharPos)
{ //found the cursor position - either
// the new pos if dy=0 or
// the old pos if we have moved up/down a line.
updateCursorPos(e, &editInfo);
editInfo.lineXpos = editInfo.txtWidth;
cursorLineNo = lineNo;
}
else if ((editInfo.lineCharPos > ipCursorCharPos) &&
(lineNo > cursorLineNo ) &&
(lineNo > cursorLineNo + dy))
{
//we have moved far enough down to store all required information
editComplete = TRUE;
}
editInfo.txtWidth = editInfo.txtWidth + editInfo.charWidth;
editInfo.lineCharPos++;
} //end while
//We now know either (a) the line the cursor is on and the char offset of the cursor or (b) the
//original line the cursor was on and the x-pixel position of the cursor (for dy != 0)
if (dy)
{ //update line with the cursor on it
if (cursorLineNo+dy >lineNo )
cursorLineNo = lineNo; //last line of editor.
else if (cursorLineNo+dy < 0)
cursorLineNo = 0;
else
cursorLineNo = cursorLineNo+dy;
//Now we need to calculate cursor char pos. 'opCursorCharPos'
}
else
{
//Cursor line no is already set up.
//the new cursor position was passed into the procedure.
opCursorCharPos = ipCursorCharPos;
}
editInfo.lineCharPos = 0;
lineNo = 0;
editInfo.txtWidth = 0;
editComplete = FALSE;
editInfo.endOfText = FALSE;
editInfo.space.lineCharPos = 0;
//Update start of windows position
if (cursorLineNo < winLineNo || !(e->attr->mode & edtCurMask))
{//cursor is on a line before current window screen - search from the start
// sbh - or we're in read-only mode, no cursor, scroll with every up/down press
winLineNo = cursorLineNo;
winCharPos = 0;
}
else if (cursorLineNo >= winLineNo+scrSyLines)
{ //cursor is below the bottom of the screen
winLineNo = cursorLineNo-(scrSyLines-1);
winCharPos = 0;
}
else if (dy != 0)
{ //windows line no is unchanged - start search at win char pos.
editInfo.lineCharPos = winCharPos;
lineNo = winLineNo;
}
else
{ //we do not need to calculate new window position - it is unchanged.
//and we have already calculated the new cursor position.
editComplete = TRUE;
}
//Calculate last char on cursor line and winCharPos
if (!editComplete)
{
while( (!editInfo.endOfText) && (!editComplete) )
{
if (textStrType == DSPL_TYPE_UNICODE)
{
charUnicode = textStartUnicode[editInfo.lineCharPos];
getTotalWidth(charUnicode,scrSxPixels,&editInfo);
}
else
{
charUnicode = (textStartAscii[editInfo.lineCharPos] << 8) & 0xFF00;
getTotalWidth(charUnicode,scrSxPixels,&editInfo);
}
if (editInfo.endOfLine)
{ //newline
editInfo.txtWidth = 0;
//update start of window.
linePos = editInfo.lineCharPos;
//Remember char before first char on next line.
if (lineNo == cursorLineNo)
{
if (ipCursorCharPos >= editInfo.lineCharPos)
ipCursorCharPos = editInfo.lineCharPos-1;
}
lineNo++;
if (winLineNo == lineNo)
winCharPos = editInfo.lineCharPos;
}
if (dy!=0)
{ //line number has changed
//Once we have found the correct line, look for the char at the same x-pixel pos
//as before (or the last char before we pass the position).
if (lineNo == cursorLineNo)
{
if (editInfo.txtWidth <= editInfo.lineXpos)
{ //Update cursor char pos...
ipCursorCharPos = editInfo.lineCharPos;
}
}
}
else if (lineNo > cursorLineNo) //...or we start a new line
{
editComplete = TRUE;
}
editInfo.txtWidth = editInfo.txtWidth + editInfo.charWidth;
editInfo.lineCharPos++;
} //end while
editComplete = FALSE;
}
editInfo.lineCharPos = winCharPos;
lineNo = winLineNo;
editInfo.txtWidth = 0;
editInfo.endOfText = FALSE;
editInfo.space.lineCharPos = 0;
//Calculate where the window is to start from
while( (!editInfo.endOfText) && (!editComplete) )
{
if (textStrType == DSPL_TYPE_UNICODE)
{
charUnicode = textStartUnicode[editInfo.lineCharPos];
getTotalWidth(charUnicode,scrSxPixels,&editInfo);
}
else
{
charUnicode = (textStartAscii[editInfo.lineCharPos] << 8) & 0xFF00;
getTotalWidth(charUnicode,scrSxPixels,&editInfo);
}
if (editInfo.endOfLine)
{ //newline
editInfo.txtWidth = 0;
//update start of window.
linePos = editInfo.lineCharPos;
lineNo++;
}
if ((lineNo == cursorLineNo) &&
(ipCursorCharPos == editInfo.lineCharPos))
{ //we have reached desired char.
opCursorCharPos = editInfo.lineCharPos;
updateCursorPos(e, &editInfo);
cursorLineNo = lineNo;
editComplete = TRUE;
}
editInfo.txtWidth = editInfo.txtWidth + editInfo.charWidth;
editInfo.lineCharPos++;
} //end while
//Calculate y position of cursor
//GW 17/09/01 Place cursor for windows that have blank lines at the top of the screen
e->curCY = (cursorLineNo - winLineNo)*e->fontHeight+e->attr->win.py;
//Output updated window start position
e->curOffs = winCharPos;
e->cp = opCursorCharPos;
return (MfwResOk);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -