164 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			164 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include "mywin_inc.h"
 | 
						|
 | 
						|
 | 
						|
 | 
						|
#define WIN_INPUTBOX_TYPE "WIN_InputboxStruct"
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
WIN_InputboxStruct *WIN_CreatInputbox (WIN_WindowStruct *base,
 | 
						|
			void (*msgLoop)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg),
 | 
						|
			int x,int y,int x_size,int y_size)
 | 
						|
{
 | 
						|
	//重设消息循环
 | 
						|
	if (msgLoop==0)
 | 
						|
	{
 | 
						|
		msgLoop=(void (*)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg))INPUTBOX_DefaultMsgLoop;   
 | 
						|
	} 
 | 
						|
	
 | 
						|
	WIN_InputboxStruct *ret=mymalloc (sizeof ( WIN_InputboxStruct));
 | 
						|
	//调用父类的构造函数
 | 
						|
	if (ret)
 | 
						|
	{
 | 
						|
		mymemset (ret,0,sizeof ( WIN_InputboxStruct));
 | 
						|
		if (0==WIN_CreatWindowExt((WIN_WindowStruct *)ret,base,msgLoop,x,y,x_size,y_size))
 | 
						|
		{
 | 
						|
			//创建失败
 | 
						|
			myfree (ret);
 | 
						|
			ret=0;
 | 
						|
		}
 | 
						|
		else
 | 
						|
		{
 | 
						|
			//构造一个
 | 
						|
			((WIN_WindowStruct *)ret)->winType=WIN_INPUTBOX_TYPE;
 | 
						|
			((WIN_WindowStruct *)ret)->bkcolor=0x342f2a;
 | 
						|
			((WIN_WindowStruct *)ret)->color=0xc2ae9b;
 | 
						|
			((WIN_WindowStruct *)ret)->keyChid=1;		//作为子窗口被创建
 | 
						|
			ret->color_light=0xffffff;
 | 
						|
			ret->color_dark=0x808080;
 | 
						|
		}
 | 
						|
	}
 | 
						|
	
 | 
						|
	
 | 
						|
	return ret;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
int INPUTBOX_Clear(WIN_InputboxStruct *box)
 | 
						|
{
 | 
						|
	mymemset(box->inputs,0,INPUTBOX_MAX_CHAR_NUM);
 | 
						|
	WIN_SetInvalid ((WIN_WindowStruct *)box);
 | 
						|
	return 0;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
int INPUTBOX_SetChars(WIN_InputboxStruct *box,char *str)
 | 
						|
{
 | 
						|
	int len=strlen(str)+1;
 | 
						|
	if (len>INPUTBOX_MAX_CHAR_NUM)
 | 
						|
		return -1;
 | 
						|
	mymemcpy(box->inputs,str,len);
 | 
						|
	WIN_SetInvalid ((WIN_WindowStruct *)box);
 | 
						|
	return 0;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
void INPUTBOX_DefaultPaint (WIN_InputboxStruct *box)
 | 
						|
{
 | 
						|
	int x=0;
 | 
						|
	int y=0;
 | 
						|
	int x_size=((WIN_WindowStruct *)box)->x_size;
 | 
						|
	int y_size=((WIN_WindowStruct *)box)->y_size;
 | 
						|
	
 | 
						|
	WIN_PaintBackGround ((WIN_WindowStruct *)box);
 | 
						|
 | 
						|
	WIN_SetLcdColor (((WIN_WindowStruct *)box)->color);
 | 
						|
	WIN_DrawTxtAtRect(box->inputs,x+1,y+1,x_size-2,y_size-2);
 | 
						|
 | 
						|
	//绘制边框
 | 
						|
	if (box->press)
 | 
						|
		WIN_SetLcdColor (box->color_light);
 | 
						|
	else
 | 
						|
		WIN_SetLcdColor (box->color_dark);
 | 
						|
	
 | 
						|
	WIN_DrawRect (0,0,((WIN_WindowStruct *)box)->x_size,((WIN_WindowStruct *)box)->y_size);
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
void INPUTBOX_DefaultMsgLoop (WIN_InputboxStruct *box,WIN_MsgStruct *msg)
 | 
						|
{
 | 
						|
	WIN_MoveStruct *m=0;
 | 
						|
	WIN_KeyStruct *k=0;
 | 
						|
	switch (msg->msg)
 | 
						|
	{	
 | 
						|
		case WIN_MSG_PAINT:
 | 
						|
			INPUTBOX_DefaultPaint(box);
 | 
						|
		break;
 | 
						|
		case WIN_MSG_KEY:
 | 
						|
			k=msg->data.p;
 | 
						|
			if (k->shortPress& KEY_VALUE_DOWN)
 | 
						|
			{
 | 
						|
			}
 | 
						|
			else if (k->shortPress&KEY_VALUE_UP)
 | 
						|
			{
 | 
						|
			}
 | 
						|
		break;
 | 
						|
		case WIN_MSG_MOVE:
 | 
						|
			m=msg->data.p;
 | 
						|
			switch (m->moveType)
 | 
						|
			{
 | 
						|
				case MOVE_DATA_TOUCHIN:
 | 
						|
					box->press=1;
 | 
						|
					WIN_SetInvalid ((WIN_WindowStruct *)box);
 | 
						|
					break;
 | 
						|
				case MOVE_DATA_TOUCHOUT:
 | 
						|
					if (box->press)
 | 
						|
					{
 | 
						|
						box->press=0;
 | 
						|
						//打开输入法
 | 
						|
						INPUT_KeyBoard(((WIN_WindowStruct *)box)->baseWin,box->inputs,INPUTBOX_MAX_CHAR_NUM);
 | 
						|
						WIN_SetInvalid ((WIN_WindowStruct *)box);
 | 
						|
					}
 | 
						|
					break;
 | 
						|
				case MOVE_DATA_MOVEOUT:
 | 
						|
					box->press=0;
 | 
						|
					WIN_SetInvalid ((WIN_WindowStruct *)box);
 | 
						|
				default:
 | 
						|
					break;
 | 
						|
			}
 | 
						|
			break;
 | 
						|
		default:
 | 
						|
			WIN_DefaultMsgLoop((WIN_WindowStruct *)box,msg);
 | 
						|
		break;
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
WIN_InputboxStruct *INPUTBOX_InputChars (WIN_WindowStruct *base,int x,int y,int x_size,int y_size)
 | 
						|
{
 | 
						|
	WIN_InputboxStruct *box=WIN_CreatInputbox(base,0,x,y,x_size,y_size);
 | 
						|
	
 | 
						|
	//设置弹出框的背景	
 | 
						|
	WIN_SetBackPic ((WIN_WindowStruct *)box);
 | 
						|
		
 | 
						|
	WIN_ShowWindow((WIN_WindowStruct *)box);
 | 
						|
	return box;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 |