⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfw_edt.c

📁 GSM手机设计软件代码
💻 C
📖 第 1 页 / 共 4 页
字号:
	resources_setColour(e->attr->edtCol);	
    tp = e->attr->text + e->curOffs;    /* start of display buffer  */
    px = e->attr->win.px;               /* left of edit window      */
    py = e->attr->win.py;               /* top of edit window       */
    ls = e->attr->win.sx;               /* width of edit window     */
    ly = (S16) (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_TextOut (e->attr->win.px, e->attr->win.py, 0, endHtext);
        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 = &tp[strlen(tp)];
	if ((endChar[0] == 0x00) &&
		(endChar[1] == 0x00))
	{
		endChar[0] = ' ';
		endChar[1] = 0x00;
		//For some editors, we want to highlight a complete word
		if (e->curMode & edtModWordSkip)
		{

			//find char at the start of the word
			findWordBounds(e,&stChr,&endChr);
			saveChr[0] = e->attr->text[stChr];
			saveChr[1] = e->attr->text[endChr];
			if (endChr == e->cp) // do not highlight if at the start of a word
			{
				if (stChr > e->curOffs)
					e->attr->text[stChr] = 0x01;
				else
					dspl_TextOut (e->attr->win.px, e->attr->win.py, 0, startHtext);
				e->attr->text[endChr] = 0x02;
			}

		}
		edtOutTextLines(e->attr->win.px, e->attr->win.py, ls, ly, NULL, (unsigned char*)tp,
						e->fontHeight, e->display); //* show it     * /
		if (e->curMode & edtModWordSkip)
		{
			e->attr->text[stChr] = saveChr[0];
			e->attr->text[endChr]= saveChr[1];
		}
		//and remove space again.
		endChar[0] = 0x00;
	}
	else
	{	//Cannot add space
		edtOutTextLines(e->attr->win.px, e->attr->win.py, ls, ly, NULL, (unsigned char*)tp,
						e->fontHeight, e->display); //* show it     * /
	}
	//GW 18/09/01 - Display predicted word.
    if (e->display)
	{
		if ((e->attr->predText[0] != '\0') && (e->attr->win.py >=e->fontHeight))
        {
			dspl_TextOut(0,e->attr->win.py-e->fontHeight,0,"             " );
			dspl_TextOut(0,e->attr->win.py-e->fontHeight,1,e->attr->predText );
        }
	}

    if (e->display && (e->curMode & edtCurMask))
    	{
        dspl_SetCursorPos(e->curCX+e->attr->win.px,e->curCY,e->curCSize,(S16)e->fontHeight); // sbh 19/02/02, position cursor correctly
    	}
    if (oldFont != (U8) -1)
        dspl_SelectFontbyID(oldFont);   /* restore previous font    */

#ifdef MFW_DEBUG_DISPLAY_SIZE
	{
		USHORT ax,ay,aw,ah;
		ax = e->attr->win.px;
		ay = e->attr->win.py;
		aw = e->attr->win.sx;
		ah = e->attr->win.sy;
    	dspl_DrawRect(ax,ay,(ax+aw-1),(ay+ah-1));
	    {
	    	char dbg[80];
	    	sprintf(dbg," ax:%d ay:%d aw:%d ah:%d",ax,ay,aw,ah);
	    	TRACE_EVENT(dbg);
	    } 	
    }
#endif
	dspl_set_char_type(temp);
	resources_restoreColour();
TIME_TRACE_EVENT("edtUpdate-end");
    return MfwResOk;
}



//GW 18/09/01 - Corrected linefeed definition and added carriage return definition.
#define UNICODE_SPACE			0x2000
#define UNICODE_LINEFEED		0x0A00
#define UNICODE_CR				0x0D00
#define UNICODE_EOLN			0x0000
#define UNICODE_NONASCII		0x00FF
#define UNICODE_STARTHIGHLIGHT	0x0100 
#define UNICODE_ENDHIGHLIGHT	0x0200


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_EDT            |
| STATE   : code                        ROUTINE : edtChar            |
+--------------------------------------------------------------------+

  PURPOSE : handle editing char
//GW 06/09/01 - Call chinese procedure if first char is 0x80,0x81 or 0x82 or display type is not ascii.

*/
char getCursorChar(MfwHnd e, int offset )
{
    MfwEdt *edit; 
	int chPos;

	TRACE_FUNCTION("getCursorChar()")

	if (!e)
        return (0xFF);

    if (((MfwHdr *)e)->type != MfwTypEdt)
        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)
{	TRACE_FUNCTION("isAWordChar()");



	if ( ((chr >='A') && (chr <='Z')) || 
		 ((chr >='a') && (chr <='z')) )
		return (TRUE);
	else
		return(FALSE);
}
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;

	TRACE_FUNCTION("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 (tbString[0] & 0x80)
	{
		return(edtCharUnicode(e,c));
	}
	bs = edit->attr->size;
	dy = 0;
    switch (c)
    {
		
        case ecEscape:                  //* quit editor              
            return MfwResDone;
        case ecLeft:					//* cursor left              
			if (edit->attr->mode & edtModWordSkip) 
			{
				edit->cp = edit->cp-1;
				if (isAWordChar(edit->attr->text[edit->cp]))
				{	//pointing to a letter in a word. Move left until next char is not a word char
					found = FALSE;
					while (!found)
					{
				        if (edit->cp == 0)
							found = TRUE;
						else if (isAWordChar(edit->attr->text[edit->cp-1]))
							edit->cp = edit->cp-1;
						else
							found = TRUE;
					}
				}
			}
			else
				edit->cp = edit->cp-1;
	        if (edit->cp <= 0)
				edit->cp = 0;
            break;
        case ecRight:                   //* cursor right 
			if (edit->attr->mode & edtModWordSkip) 
			{
				if (!isAWordChar(edit->attr->text[edit->cp]))
					edit->cp = edit->cp+1;//current char is not a word - move to next and stop.
				else 
				{
					found = FALSE;
					while (!found)
					{
						edit->cp = edit->cp+1;
				        if (!isAWordChar(edit->attr->text[edit->cp]))
							found = TRUE;//found a non-word char (could be the end of the string
					}
				}
			}
			else
				edit->cp = edit->cp+1;
            break;
        case ecUp:                      //* cursor up      
  			dy =  -1;
            break;
        case ecDown:                    //* cursor down           
  			dy = 1;
            break;
        case ecTop:                     //* cursor to start of text  
            edit->cp = 0;
            edit->curOffs = 0;
            break;
        case ecBottom:                  //* cursor to end of text   
            edit->cp = strlen(tbString);
            edit->curOffs = 0;
            break;
        case ecBack:                    //* backspace                *
            if ((edit->cp != 0) && (strlen(tbString)+1 > edit->cp))
			{
				moveLeft(&tbString[edit->cp-1],1);
			}
			edit->cp = edit->cp-1;
	        if (edit->cp <= 0)
				edit->cp = 0;
            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, edit->curMode, edit->cp);
			return (edtChar(e,ecRight));
            break;
        default:                        //* normal char              
            edtInsert(c,tbString,bs, edit->curMode, edit->cp);

			if (edit->attr->alphaMode NEQ TRUE)
				return (edtChar(e,ecRight));
			/*NM, p003 end*/	
            break;
    }
    edit->display = 1;                        //* really show it           
  	updateWindow( edit, dy);
    edtUpdate(edit);

    return MfwResOk;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_EDT            |
| STATE   : code                        ROUTINE : edtCharUnicode     |
+--------------------------------------------------------------------+

  PURPOSE : 

  GW 06/09/01 - Created
*/
MfwRes edtCharUnicode (MfwHnd e, int c)
{
    MfwEdt *edit; 
    U16 bs; 
	int dy;
    U16 *tbUnicode; 

 	TRACE_FUNCTION("edtCharUnicode()");
 	
    if (!e)
        return MfwResIllHnd;

    if (((MfwHdr *)e)->type != MfwTypEdt)
        return MfwResIllHnd;            //* not an editor            

	edit = ((MfwHdr *) e)->data;
	bs = edit->attr->size;
	tbUnicode = (U16*) &edit->attr->text[2];

	dy = 0;
    switch (c)
    {
        case ecEscape:                  //* quit editor              
            return MfwResDone;
        case ecLeft:                    //* cursor left              
            if (edit->cp <= 0)
				edit->cp = 0;
			else
	            edit->cp = edit->cp-1;
            break;
        case ecRight:                   //* cursor right             
			if (tbUnicode[edit->cp]!=UNICODE_EOLN)
	            edit->cp = edit->cp +1;
            break;
        case ecUp:                      //* cursor up                
  			dy = -1;
            break;
        case ecDown:                    //* cursor down              
  			dy = 1;
            break;
        case ecTop:                     //* cursor to start of text  
            edit->cp = 0;
            edit->curOffs = 0;
  			dy = 0;
            break;
        case ecBottom:                  //* cursor to end of text    
			while (tbUnicode[edit->cp]!=UNICODE_EOLN)
			{
	            edit->cp = edit->cp +1;
			}
            break;
        case ecBack:                    //* backspace                
            if (edit->cp != 0)
	            moveLeftUnicode(tbUnicode+edit->cp-1,1);
            return edtCharUnicode(e,ecLeft);
        case ecDel:                     //* delete                   
            moveLeftUnicode(tbUnicode+edit->cp,1);
            break;
        case ecEnter:                   //* cr/lf                    
            c = UNICODE_LINEFEED;
            edtInsertUnicode(edit,c,tbUnicode,bs);
            return edtCharUnicode(e,ecRight);
        default:                        //* normal char  
            edtInsertUnicode(edit,c,tbUnicode,bs);

			if (edit->attr->alphaMode NEQ TRUE)
				return (edtCharUnicode(e,ecRight));
			/*MC end*/	
            break;

    }
    edit->display = 1;                        // really show it           
  	updateWindow( edit, dy);
    edtUpdateUnicode(edit);


    return MfwResOk;
}




/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_EDT            |
| STATE   : code                        ROUTINE :        |
+--------------------------------------------------------------------+

  PURPOSE : Return no of chinese chars in a string

  GW 06/09/01 - Created
  GW 25/09/01 - Corrected length - now skips first two chars.
*/

U16 strlenUnicode(U16* str)
{
	U16 len = 2; //First char is 0x80, second char is 0x00

	TRACE_FUNCTION("strlenUnicode()");
	
	while (*str!=UNICODE_EOLN)
	{
		//treat ascii chars as half size chinese chars.
		len = len + 2;
		str++;
	}
	return (len);
}


//Assumptions :-
//str is a null-terminated string 
//edit->cp is the cursor position of the char 
//The string is inserted before the cursor char
//The cursor is moved strlen(str) chars forward.
MfwRes edtInsertString (MfwHnd e, char* insWord)
{
    MfwEdt *edit;
    char *textBfr;

	int lenText;
	int lenInsWord;
    int maxTextBfrLen;
	int i;


TRACE_FUNCTION("edtInsertString()");

    if (!e)
        return MfwResIllHnd;

    if (((MfwHdr *)e)->type != MfwTypEdt)
        return MfwResIllHnd;            /* not an editor            */

	edit = ((MfwHdr *) e)->data;
	if (insWord == NULL)
		return (MfwResOk);	//no string to insert - trivial operation.
	if (insWord[0] == 0x00)
		return (MfwResOk);	//no string to insert - trivial operation.
	textBfr			= edit->attr->text;
	if ((textBfr[0] == 0x80) || (textBfr[1] == 0x81) || (textBfr[2] == 0x82))
	{//String is unicode
		return (edtInsertUnicodeString (e, insWord));
	}
	maxTextBfrLen	= edit->attr->size;
	lenText		= strlen(textBfr);
	lenInsWord	= strlen(insWord);
	if ((lenText+lenInsWord) >= maxTextBfrLen)
		return (MfwResErr); //String too long 

	//move text up by 'lemnInsWord' words
	for (i=lenText;i>=edit->cp;i--)
	{
		textBfr[i+lenInsWord]=textBfr[i];
	}
	//and copy string into buffer.
	for (i=0;i<lenInsWord;i++)
		textBfr[edit->cp+i] = insWord[i];
	edit->cp = edit->cp+lenInsWord;
	//Update cursor position
	//<TBD>
	//And output updated text
	edit->display = 1;
	updateWindow( edit, 0);
    edtUpdate(edit);

    return MfwResOk;
}
#define MAXWORD_ARRAY 32
//Assumptions :-
//'removeWord' is char array of MAXWORD chars 
//edit->cp is the cursor position of the char 
//The word removed is at or just before the cursor char
//The cursor is placed before the previous word.
//a space char (start or end) will be removed if there is one.
//GW 18/09/01 - Use 'isAWordChar' procedure
MfwRes edtRemoveString (MfwHnd e, char* removeWord)
{
    MfwEdt *edit;
    char *textBfr;

	int i,j;
	int stChr,endChr;

	TRACE_FUNCTION("edtRemoveString");
	
	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[1] == 0x81) || (textBfr[2] == 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;

	//and now move text up by 'j' chars.
	i=stChr;
	j=endChr; 
	//skip one space at start/end.
	if (textBfr[i] != ' ')
	{
		i++;
		if (textBfr[j] == ' ')
			j++;
	}
	//else overwrite first space
	edit->cp = i;

	while((textBfr[i] != 0x00) && (i < j))
	{
		textBfr[i] = textBfr[j];
		i++;
		j++;
	}

	edit->display = 1;
	updateWindow( edit, 0);
    edtUpdate(edit);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -