📄 mfw_edt.c
字号:
return(0xFF); /* not an editor */
edit = ((MfwHdr *) e)->data;
chPos = offset + edit->cp;
if( (chPos < 0) || (chPos > strlen(edit->attr->text)) )
return(0x00);
else
return(edit->attr->text[chPos]);
}
int isAWordChar( char chr)
{
if( ((chr >='A') && (chr <='Z')) ||
((chr >='a') && (chr <='z')) )
return(TRUE);
else
return(FALSE);
}
MfwRes edtSymbol (MfwHnd e, int c)
{
MfwEdt *edit;
unsigned char firstChar;
U16 bs; // buffer size
char *tbString;
char tmpBuffer[256];
unsigned int tmpLen;
TRACE_EVENT("edtSymbol()");
if( !e )
return MfwResIllHnd;
if( ((MfwHdr *)e)->type != MfwTypEdt )
return MfwResIllHnd; /* not an editor */
edit = ((MfwHdr *) e)->data;
firstChar = (unsigned char)edit->attr->text[0];
tbString = &(edit->attr->text[0]);
if( (firstChar != 0x80) && (c <= 0xff) ) //All text in buffer is ascii or No symbol in buffer, and the input symbol c is ascii or control code; control code is less than 0
return edtChar (e, c);
else if( (firstChar != 0x80) && (c > 0xff) ) //All text in buffer is ascii or No symbol in buffer, and the input symbol c is unicode
{
if( firstChar != 0 ) // there are symbol in buffer, and all is ascii
{
//把当前已输入的ascii字符全部转为unicode
//Note: 如果当前的ascii码转为双字节后超出空间,此时应不作转换,返回异常值,mmi层应该出现提示信息
strcpy(tmpBuffer, tbString);
AscEx_To_Unicode(tmpBuffer, tbString); //AscEx_To_Unicode(tmpBuffer, strlen(tmpBuffer), tbString); //首字符已置为0x80
return edtCharUnicode (e, c);
}
else // firstChar is zero; for the first time, No symbol in buffer.
{
edit->attr->text[0] = 0x80; // Set the first Flag Byte to 0x80
return edtCharUnicode (e, c);
}
}
else if( (firstChar == 0x80) && (c > 0) && (c <= 0xff) ) //All text in buffer is unicode, and the input symbol c is ascii;
{
if( ecDel_uniFlag )
{
ecDel_uniFlag = 0;
//TRACE_EVENT("zgz,ecDel_uniFlag is reset to 0");
// 上一次调用过unicode的删除控制,应判断当前的字符串是否可以全部转为ascii
//step1: 如果可以全部转为ascii,转换后,插入一个ascii字符;
//step2: 否则把ascii 码c转为unicode, 输入到buffer 中
tmpLen = strlenUnicode((U16 *)( tbString + 1));
if( All_Is_AscEx(tbString, tmpLen) ) //if (All_Is_AscEx(tbString, tmpLen))
{
memset(tmpBuffer, 0, sizeof(tmpBuffer));
Unicode_To_AscEx(tbString, &tmpBuffer[0]); //Unicode_To_AscEx(tbString, tmpLen, &tmpBuffer[0]);
strcpy(tbString, tmpBuffer);
return edtChar(e, c);
}
else
{
return edtCharUnicode(e, ConvertToUni(c));
}
}
else //把ascii 码c转为unicode, 输入到buffer 中
{
return edtCharUnicode(e, ConvertToUni(c));
}
}
else if( (firstChar == 0x80) && ((c < 0) || (c > 0xff)) ) //All text in buffer is unicode, and the input symbol c is also unicode or control code
{
if( (c == ecBack) || (c == ecDel) )
{
ecDel_uniFlag = 1;
//note: 判断当前还可以输入的字符数;是否可以全部转为ascii, 计算出txtLen 的值
// 这一步计算可以放到一个合适的地方统一执行,然后供显示给用户
}
return edtCharUnicode (e, c);
}
return MfwResOk;
}
MfwRes edtChar (MfwHnd e, int c)
{
int warn99;
MfwEdt *edit;
U16 bs;
int dy; //Change in cursor y position when moving up/down lines.
char *tbString;
int found;
U16 pre_offs;
char Trace_data[10]="";
TRACE_EVENT("edtChar()");
if( !e )
return MfwResIllHnd;
if( ((MfwHdr *)e)->type != MfwTypEdt )
return MfwResIllHnd; /* not an editor */
edit = ((MfwHdr *) e)->data;
tbString = &edit->attr->text[0];
if( (unsigned char)tbString[0] == 0x80 ) //zgz change, 2002.9.6
{
return(edtCharUnicode(e,c));
}
if( wstrlen(edit->attr->text)==0 )
edit->cp=0;
curCP = edit->cp;
if( edit->attr->e_size==0 )
bs = edit->attr->size;
else
bs=edit->attr->e_size;
curMode = edit->attr->mode;
dy = 0;
switch( c )
{
case ecEscape: //* quit editor
return MfwResDone;
case ecLeft: //* cursor left
if( edit->cp == 0 )
edit->cp = strlen(tbString); // zgz, change it
else
{
edit->cp = edit->cp-1;
}
pre_offs=edit->curOffs;
updateWindow( edit, 0);
if( edit->curOffs==pre_offs )
redrawcursor(preCX,preCY, preCSize,curCX,curCY,curCSize,0,edit->attr->fgColor);
else
{
display=1;
edtUpdate(edit,1);
}
break;
case ecRight: //* cursor right
edit->cp = edit->cp+1;
if( edit->cp > (strlen(tbString)) )
{
edit->cp = 0;
}
pre_offs=edit->curOffs;
updateWindow( edit, 0);
if( edit->curOffs==pre_offs )
redrawcursor(preCX,preCY, preCSize,curCX,curCY,curCSize,0,edit->attr->fgColor);
else
{
display=1;
edtUpdate(edit,1);
}
// redrawcursor(cp_pre_x, cp_pre_y, cp_pre_w,edit->cp_curr_x,edit->cp_curr_y, edit->cp_curr_width,0,edit->attr->fgColor);
break;
case ecUp: //* cursor up
dy = -1;
pre_offs=edit->curOffs;
TRACE_EVENT("press the up in ascii");
updateWindow( edit, dy);
if( edit->curOffs==pre_offs )
redrawcursor(preCX,preCY, preCSize,curCX,curCY,curCSize,0,edit->attr->fgColor);
else
{
display=1;
edtUpdate(edit,1);
}
break;
case ecDown: //* cursor down
dy = 1;
pre_offs=edit->curOffs;
TRACE_EVENT("press the down in ascii");
updateWindow( edit, dy);
Sprintf(Trace_data,"%d",edit->cp);
TRACE_EVENT(Trace_data);
if( edit->curOffs==pre_offs )
redrawcursor(preCX,preCY, preCSize,curCX,curCY,curCSize,0,edit->attr->fgColor);
else
{
display=1;
edtUpdate(edit,1);
}
break;
case ecTop: //* cursor to start of text
edit->cp = 0;
updateWindow(edit,0);
display=1;
edtUpdate(edit,1);
break;
case ecBottom: //* cursor to end of text
edit->cp = strlen(tbString);
updateWindow(edit,0);
display=1;
edtUpdate(edit,1);
break;
case ecBack: //* backspace *
if( (edit->cp != 0) && (strlen(tbString)+1 > edit->cp) )
{
moveLeft(&tbString[edit->cp-1],1);
// edit->cp = edit->cp-1;
}
pre_offs=edit->curOffs;
if( edit->cp == 0 )
edit->cp = strlen(tbString); // zgz, change it
else
{
edit->cp = edit->cp-1;
}
updateWindow( edit, dy);
display=1;
if( pre_offs==edit->curOffs )
edtUpdate(edit,0);
else
edtUpdate(edit,1);
break;
case ecDel: //* delete *
if( strlen(tbString) > edit->cp )
{
moveLeft(&tbString[edit->cp],1);
}
break;
case ecEnter: //* cr/lf
c = UNICODE_LINEFEED;
edtInsert(c,tbString,bs);
return(edtChar(e,ecRight));
break;
default: //* normal char
if( edtInsert(c,tbString,bs) ) //zgz,2002.5.15 ,if the buffer is full, don't make the cursor right
{
updateWindow( edit, 0);
display=1;
edtUpdate(edit,0);
return(edtChar(e,ecRight));
}
else
return MfwResDone;
break;
}
return MfwResOk;
}
/////zgz,2002.0621 this function update the screen by disp. if disp is 1, update the screen . or not do it, just intert c to editor.
MfwRes edtCharf (MfwHnd e, int c, int disp)
{
int warn99;
MfwEdt *edit;
U16 bs;
int dy; //Change in cursor y position when moving up/down lines.
char *tbString;
int found;
if( !e )
return MfwResIllHnd;
if( ((MfwHdr *)e)->type != MfwTypEdt )
return MfwResIllHnd; /* not an editor */
edit = ((MfwHdr *) e)->data;
curCP = edit->cp;
tbString = &edit->attr->text[0];
if( (unsigned char)tbString[0] == 0x80 ) //zgz change, 2002.9.6
{
return(edtCharUnicode(e,c));
}
if( edit->attr->e_size==0 )
bs = edit->attr->size;
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -