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

📄 button.c

📁 一个操作系统源代码 用于嵌入式设备 在Vc++环境下仿真 成功移植到多款处理器上
💻 C
📖 第 1 页 / 共 4 页
字号:
	S16		bitmap_width;
	S16		bitmap_hight;
	
	P_U8	bitmap;
	P_U8	tagbk_saved = NULL;
	
	char	*captionandtag;
	
	MSG		msg;
	ASIX_WINDOW	*wndptr;
	
//	static U32 mem;
	
	struct bt_ctrl_str	*pbtctrl;
	U32	pGC;
	
//	if (bt_msg_type != WM_PENDOWN && bt_msg_type != WM_PENDRAG &&
//		bt_msg_type != WM_PENDRAGUP && bt_msg_type != WM_PENUP)
		//return ASIX_OK; /* changed by Lingming */
//		return ASIX_ERROR;	//modified by xuanhui 2002/3/14
	
	pGC = GetGC();
	
	wndptr = (ASIX_WINDOW *)win_id;
	if( wndptr == NULL )
		return ASIX_ERROR;
	if( wndptr->wndclass == NULL || wndptr->wndclass->wndclass_id != WNDCLASS_BUTTON )
		return ASIX_ERROR;
	pbtctrl = (struct bt_ctrl_str *)wndptr->ctrl_str;
	
	/*Msg filtering. By Lingming 2001/11/27*/
	if (pbtctrl == NULL) return ASIX_ERROR;
//	if (pbtctrl->classid != WNDCLASS_BUTTON ) 
		//modified by xuanhui 2002/3/14
		//return ASIX_OK;
//		return ASIX_ERROR;

	Btn_style = pbtctrl->bt_style;
	
	bitmap = pbtctrl->bt_icon;
	captionandtag = pbtctrl->bt_caption;
	
	bitmap_width = pbtctrl->bt_icon_width;
	bitmap_hight = pbtctrl->bt_icon_hight;
	
	//read the coordinate of the button

	if( ActiveAreaRead( pbtctrl->bt_id, &xSrc, &ySrc, &xDest, &yDest ) == PPSM_ERROR )
		return ASIX_ERROR;
		
	switch( bt_msg_type )
	{
		
		case	WM_PENDOWN:
			{
				SetFocus( pbtctrl->wndid );
				if( LOWORD(Btn_style) & BS_PEN_DOWN_ACTIVE )
				{
					if( drawdownbutton( pbtctrl,xSrc,ySrc,xDest,yDest,Btn_style,captionandtag,tagbk_saved,bitmap,bitmap_width,bitmap_hight ) != ASIX_OK )
					{
						return ASIX_ERROR;
					}
				}
				else
				{
					char	*captionandtag = pbtctrl->bt_caption;
					char	*tag = NULL;

					//seprate the captionandtag into caption and tag
					if( captionandtag != NULL && *captionandtag != '\0' )
					{
						tag = strchr( captionandtag, '\\' );
						if( tag != NULL )
							tag++;	// skip the backslash
					}
					else
						tag = NULL;

					// show button tag
					if( drawbuttontag( pbtctrl, tag ) != ASIX_OK )
						return ASIX_ERROR;
				}
				if( LOWORD(Btn_style) & BS_PEN_DOWN_CMD )
				{
					memset( (void *)&msg, 0x0, sizeof(MSG) );
					msg.messageType = ASIX_MESSAGE;
					msg.message = WM_COMMAND;
					msg.lparam = pbtctrl->wndid;
					msg.data = NULL;		//don't use data in button		
					//modified by xuanhui 2002/4/4
					//msg.wparam = PPSM_ICON_TOUCH;	//don't use wparam in button
					msg.wparam = MS_ICON_TOUCH;//PPSM_ICON_TOUCH;	
					if( AdvSendMessage(GetCurTask()->id, (P_MESSAGE)&msg, NO_SWAP_TASK) == PPSM_ERROR )
						return ASIX_ERROR;
				}
				return ASIX_OK;
			}
		case	WM_PENDRAG:
			{
				SetFocus( pbtctrl->wndid );
				if( LOWORD(Btn_style) & BS_PEN_DOWN_ACTIVE )
				{
					if( drawdownbutton( pbtctrl,xSrc,ySrc,xDest,yDest,Btn_style,captionandtag,tagbk_saved,bitmap,bitmap_width,bitmap_hight ) != ASIX_OK )
					{
						return ASIX_ERROR;
					}
				}
				/*if( LOWORD(Btn_style) & BS_PEN_DOWN_CMD )
				{
					memset( (void *)&msg, 0x0, sizeof(struct MSG) );
					msg.message = WM_COMMAND;
					msg.lparam = pbtctrl->wndid;
					msg.data = NULL;		//don't use data in button		
					msg.wparam = PPSM_ICON_DRAG;		//don't use wparam in button
					if( AdvSendMessage(GetCurTask()->id, (P_MESSAGE)&msg, NO_SWAP_TASK) == PPSM_ERROR )
						return ASIX_ERROR;
				}*/
				return 	ASIX_OK;
			}
		case	WM_PENDRAGUP:
			{
				if( LOWORD(Btn_style) & BS_PEN_UP_ACTIVE )
				{
					/*if( pbtctrl->bt_face_saved!=NULL )
					{
						if( PutRec(pbtctrl->bt_face_saved,(U16) xSrc-1, (U16) ySrc-1, (U16) (xDest-xSrc+2), (U16) (yDest-ySrc+2),REPLACE_STYLE, 0) != PPSM_OK)
							return ASIX_ERROR;
						Lfree( pbtctrl->bt_face_saved );
					}*/		//changed by ZXW 2001/4/10
					//modified by xuanhui 2002/3/27
					if ( (Btn_style & BS_SHADOW) && ( (LOWORD(Btn_style)&BS_BOARD) == 0 ) )
					{
						InvRec(pGC, (U16)(xSrc), (U16)(yDest), (U16) (xDest-xSrc+1), 1);
						InvRec(pGC, (U16)(xDest), (U16)(ySrc), 1, (U16) (yDest-ySrc));	//modified by xuanhui 2002/4/4	
						InvRec(pGC, (U16)(xSrc), (U16)(ySrc), (U16) (xDest-xSrc), 1);		//modified by xuanhui 2002/4/4	
						InvRec(pGC, (U16)(xSrc), (U16)(ySrc+1), 1, (U16) (yDest-ySrc-1));	
					}
					InvRec(pGC, (U16)(xSrc+1), (U16)(ySrc+1), (U16) (xDest-xSrc-1), (U16) (yDest-ySrc-1) );	//changed by ZXW 2001/4/10
					pbtctrl->bt_state = BTN_STATUS_UP;
					/*if( pbtctrl->bt_tag_saved!=NULL )
					{
						if( PutRec(pbtctrl->bt_tag_saved,pbtctrl->tag_x, pbtctrl->tag_y, pbtctrl->tag_width, pbtctrl->tag_hight,REPLACE_STYLE, 0) != PPSM_OK )
							return ASIX_ERROR;
						
						TaskMemUsed(GetCurTask()->id, &mem);
						Lfree( (void*)pbtctrl->bt_tag_saved );
						TaskMemUsed(GetCurTask()->id, &mem);
					}*/
				}
				
				if( pbtctrl->bt_tag_saved!=NULL )
				{
					if( PutRec(pGC, (P_U16)pbtctrl->bt_tag_saved,pbtctrl->tag_x, pbtctrl->tag_y, pbtctrl->tag_width, pbtctrl->tag_hight,GPC_REPLACE_STYLE, 0) != PPSM_OK )
						return ASIX_ERROR;
					// longn_qi 2002/01/25 for monitor memory leak
					asix_bt_memdbgprintf( "button free mem of bt_tag_saved" );
					Lfree( (void*)pbtctrl->bt_tag_saved );
					

				}
				//modified by xuanhui 2002/4/4
				//if( LOWORD(Btn_style) & BS_PEN_DRAG_CMD )
/*				if( LOWORD(Btn_style) & BS_PEN_UP_CMD )
				{
					memset( (void *)&msg, 0x0, sizeof(MSG) );
					msg.message = WM_COMMAND;
					msg.lparam = pbtctrl->wndid;
					msg.data = NULL;		//don't use data in button		
					//modified by xuanhui 2002/4/4
					//msg.wparam = PPSM_ICON_DRAG_UP;		//don't use wparam in button
					msg.wparam = MS_ICON_DRAG_UP;	
					if( AdvSendMessage(GetCurTask()->id, (P_MESSAGE)&msg, NO_SWAP_TASK) == PPSM_ERROR )
						return ASIX_ERROR;
				}
*/				return	ASIX_OK;
			}
		case	WM_PENUP:
			{    
				if( LOWORD(Btn_style) & BS_PEN_UP_ACTIVE )
				{
					/*if( pbtctrl->bt_face_saved!=NULL )
					{
						if( PutRec(pbtctrl->bt_face_saved,(U16) xSrc-1, (U16) ySrc-1, (U16) (xDest-xSrc+2), (U16) (yDest-ySrc+2),REPLACE_STYLE, 0) != PPSM_OK )
							return ASIX_ERROR;
						Lfree( pbtctrl->bt_face_saved );
					}*/		//changed by ZXW 2001/4/10
					//modified by xuanhui 2002/3/27
					if ( (Btn_style & BS_SHADOW) &&( (LOWORD(Btn_style)&BS_BOARD) == 0 ) )
					{
						InvRec(pGC, (U16)(xSrc), (U16)(yDest), (U16) (xDest-xSrc+1), 1);
						InvRec(pGC, (U16)(xDest), (U16)(ySrc), 1, (U16) (yDest-ySrc));	//modified by xuanhui 2002/4/4	
						InvRec(pGC, (U16)(xSrc), (U16)(ySrc), (U16) (xDest-xSrc), 1);		//modified by xuanhui 2002/4/4	
						InvRec(pGC, (U16)(xSrc), (U16)(ySrc+1), 1, (U16) (yDest-ySrc-1));	
					}
					InvRec(pGC, (U16)(xSrc+1), (U16)(ySrc+1), (U16) (xDest-xSrc-1), (U16) (yDest-ySrc-1) );
					pbtctrl->bt_state = BTN_STATUS_UP;
					//changed by ZXW 2001/4/10
					/*if( pbtctrl->bt_tag_saved!=NULL )
					{
						if( PutRec(pbtctrl->bt_tag_saved,pbtctrl->tag_x, pbtctrl->tag_y, pbtctrl->tag_width, pbtctrl->tag_hight,REPLACE_STYLE, 0) != PPSM_OK )
							return ASIX_ERROR;
						TaskMemUsed(GetCurTask()->id, &mem);
						Lfree( pbtctrl->bt_tag_saved );
						TaskMemUsed(GetCurTask()->id, &mem);
					}*/
				}
				
				if( pbtctrl->bt_tag_saved!=NULL )
				{
					if( PutRec(pGC, (P_U16)pbtctrl->bt_tag_saved,pbtctrl->tag_x, pbtctrl->tag_y, pbtctrl->tag_width, pbtctrl->tag_hight,GPC_REPLACE_STYLE, 0) != PPSM_OK )
						return ASIX_ERROR;
					// longn_qi 2002/01/25 for monitor memory leak
					asix_bt_memdbgprintf( "button free mem of bt_tag_saved" );
					Lfree( pbtctrl->bt_tag_saved );
			

				}
				
				if( LOWORD(Btn_style) & BS_PEN_UP_CMD )
				{
					memset( (void *)&msg, 0x0, sizeof(MSG) );
					msg.message = WM_COMMAND;
					msg.lparam = pbtctrl->wndid;
					msg.data = NULL;		//don't use data in button		
					//modified by xuanhui 2002/4/4
					//msg.wparam = PPSM_ICON_PEN_UP;		//don't use wparam in button
					msg.wparam = MS_ICON_PEN_UP;		
					if( AdvSendMessage(GetCurTask()->id, (P_MESSAGE)&msg, NO_SWAP_TASK) == PPSM_ERROR )
						return ASIX_ERROR;
				}
				return 	ASIX_OK;
			}
		case WM_KEYUP:
		case WM_KEYDOWN:
			switch( wparam )
			{
				case ASIX_KEY_OK:	// press the button
					{
		    			msg.messageType = ASIX_MESSAGE;
						msg.lparam = pbtctrl->wndid;
						msg.data = (void *)pbtctrl;
						msg.message = WM_PENDOWN;
						AdvSendMessage(GetCurTask()->id, (P_MESSAGE)&msg, NO_SWAP_TASK );
						msg.message = WM_PENUP;
						AdvSendMessage(GetCurTask()->id, (P_MESSAGE)&msg, NO_SWAP_TASK );
					}
					break;
			}
			break;
		case WM_GETFOCUS:
//			if( pbtctrl->bt_state & BTN_STATUS_DOWN )
//				DrawRec( pGC, GPC_WHITE, xSrc+2, ySrc+2, xDest-2, yDest-2, GPC_DOT_LINE, GPC_REPLACE_STYLE );
//			else
			DrawRec( pGC, GPC_BLACK, xSrc+2, ySrc+2, xDest-2, yDest-2, GPC_DOT_LINE, GPC_XOR_STYLE );
			break;
		case WM_LOOSEFOCUS:
			pbtctrl->bt_state |= BTN_STATUS_REPAINT;
			
			if( pbtctrl->bt_state & BTN_STATUS_DOWN )
				drawdownbutton( pbtctrl, xSrc, ySrc, xDest, yDest,pbtctrl->bt_style, 
				pbtctrl->bt_caption, NULL, pbtctrl->bt_icon,pbtctrl->bt_icon_width,pbtctrl->bt_icon_hight );
			else	
				drawbutton( pbtctrl, xSrc,ySrc,xDest,yDest,pbtctrl->bt_style,pbtctrl->bt_caption,
				pbtctrl->bt_icon,pbtctrl->bt_icon_width,pbtctrl->bt_icon_hight );
			if( Btn_style & BS_TRANSPARENT )
				DrawRec( pGC, GPC_BLACK, xSrc+2, ySrc+2, xDest-2, yDest-2, GPC_DOT_LINE, GPC_XOR_STYLE );
			break;
	}
	return ASIX_OK;
}

//the function Btn_repaint() will helps to redraw the button if the caption or tag was changed
STATUS	Btn_caption(void *ctrl_str, char *caption, void *exdata)
{
	struct bt_ctrl_str	*ctrl_ptr;
	//char				*temp_ptr;
	S16					xSrc;
	S16					ySrc;
	S16					xDest;
	S16					yDest;
	U32					pGC;
	//wnd_ptr = (ASIX_WINDOW *)lparam;
	//if the function was used by ASISWIN system
	ctrl_ptr = (struct bt_ctrl_str *)ctrl_str;
	//if the function was used solely
	//ctrl_ptr = (struct bt_ctrl_str *)wnd_ptr->ctrl_str;
	pGC = GetGC();
	
	
	if( ActiveAreaRead( ctrl_ptr->bt_id, &xSrc, &ySrc, &xDest, &yDest ) == PPSM_ERROR )
		return ASIX_ERROR;
	
	//if the caption or the tag of the button will be changed 
	//if( caption != NULL )
	//{
		ctrl_ptr->bt_caption = caption;
	//}
	
	//if the bitmap will be changed
	//if( exdata!=NULL )
	//{
		ctrl_ptr->bt_icon = (P_U8)exdata;
	//}
	
	//clear the old button
//	if ( caption == NULL || exdata == NULL )
		//modified by xuanhui 2002/3/14
		//ClearRec(pGC,GPC_WHITE,(U16)xSrc,(U16)ySrc,(U16)(xDest-xSrc+1),(U16)(yDest-ySrc+1),GPC_REPLACE_STYLE);
//		ClearRec(pGC,ColorTheme.form_client,(U16)xSrc,(U16)ySrc,(U16)(xDest-xSrc+1),(U16)(yDest-ySrc+1),GPC_REPLACE_STYLE);
	
	//redraw the button
	drawbutton( ctrl_ptr, xSrc,ySrc,xDest,yDest,ctrl_ptr->bt_style,ctrl_ptr->bt_caption,ctrl_ptr->bt_icon,ctrl_ptr->bt_icon_width,ctrl_ptr->bt_icon_hight );
	
	// longn_qi 2002/10/06 added
	{
		ASIX_WINDOW	*wndptr = (ASIX_WINDOW	*)ctrl_ptr->wndid;
		if( wndptr->status & WST_FOCUS )
			DrawRec( pGC, GPC_BLACK, xSrc+2, ySrc+2, xDest-2, yDest-2, GPC_DOT_LINE, GPC_XOR_STYLE );
	}

	return ASIX_OK;
}


STATUS Btn_enable(void *ctrl_str, U8 enable)
{
	struct bt_ctrl_str	*ctrl_ptr;
	S16					xSrc;
	S16					ySrc;
	S16					xDest;
	S16					yDest;
	U32					pGC;

	pGC = GetGC();
	ctrl_ptr = (struct bt_ctrl_str *)ctrl_str;
	
	if( ActiveAreaRead( ctrl_ptr->bt_id, &xSrc, &ySrc, &xDest, &yDest ) == PPSM_ERROR )
		return ASIX_ERROR;


	if( enable == TRUE )
	{
		if( ctrl_ptr->bt_style & WS_DISABLED )
		{
			if( ActiveAreaSuspend(ctrl_ptr->bt_id, AREA_REENABLE ) == PPSM_ERROR )
				return 	ASIX_ERROR;
			ctrl_ptr->bt_style &= (~WS_DISABLED);
			//redraw the button
			//modified by xuanhui 2002/3/14
			//ClearRec(pGC, GPC_WHITE,(U16)(xSrc-1),(U16)(ySrc-1),(U16)(xDest-xSrc+2),(U16)(yDest-ySrc+2),GPC_REPLACE_STYLE);
			//drawbutton( xSrc,ySrc,xDest,yDest,ctrl_ptr->bt_style,ctrl_ptr->bt_caption,
			//ctrl_ptr->bt_icon,ctrl_ptr->bt_icon_width,ctrl_ptr->bt_icon_hight );
			//modified by pessia to use new shell 2002/3/26
			//ClearRec(pGC, ColorTheme.form_backcolor,(U16)(xSrc-1),(U16)(ySrc-1),(U16)(xDest-xSrc+2),(U16)(yDest-ySrc+2),GPC_REPLACE_STYLE);
			drawbutton( ctrl_ptr, xSrc,ySrc,xDest,yDest,ctrl_ptr->bt_style,ctrl_ptr->bt_caption,
			ctrl_ptr->bt_icon,ctrl_ptr->bt_icon_width,ctrl_ptr->bt_icon_hight );
		}
	//modified by xuanhui 2002/3/14
	//}else if( enable == FALSE){
	}else{		
		if( !( ctrl_ptr->bt_style & WS_DISABLED ) )
		{
			//suspend the button
			if( ActiveAreaSuspend(ctrl_ptr->bt_id, AREA_SUSPEND ) != PPSM_OK )
				return ASIX_ERROR;
			ctrl_ptr->bt_style |= WS_DISABLED;
			//redraw the button
			//ClearRec(WHITE,xSrc-1,ySrc-1,xDest-xSrc+2,yDest-ySrc+2,REPLACE_STYLE);
			//modified by xuanhui 2002/3/14
			
			//modified by pessia to use new shell 2002/3/26
			//ClearRec(pGC, ColorTheme.form_backcolor,(U16)(xSrc-1),(U16)(ySrc-1),(U16)(xDest-xSrc+2),(U16)(yDest-ySrc+2),GPC_REPLACE_STYLE);

			//modified by xuanhui 2002/3/14
			//drawbutton( xSrc,ySrc,xDest,yDest,ctrl_ptr->bt_style,ctrl_ptr->bt_caption,
			//ctrl_ptr->bt_icon,ctrl_ptr->bt_icon_width,ctrl_ptr->bt_icon_hight ); 
			drawbutton( ctrl_ptr, xSrc,ySrc,xDest,yDest,ctrl_ptr->bt_style,ctrl_ptr->bt_caption,
			ctrl_ptr->bt_icon,ctrl_ptr->bt_icon_width,ctrl_ptr->bt_icon_hight );			
		}
	}
	// longn_qi 2002/10/06 added
	// longn_qi 2002/11/08 removed
//	{
//		ASIX_WINDOW	*wndptr = (ASIX_WINDOW	*)ctrl_ptr->wndid;
//		if( wndptr->status & WST_FOCUS )
//			DrawRec( pGC, GPC_BLACK, xSrc+2, ySrc+2, xDest-2, yDest-2, GPC_DOT_LINE, GPC_XOR_STYLE );
//	}
	return ASIX_OK;
}
	
STATUS Btn_repaint(void *ctrl_str, U32 lparam)
{
	struct bt_ctrl_str	*ctrl_ptr;
	S16					xSrc;
	S16					ySrc;
	S16					xDest;
	S16					yDest;
	U32					pGC;

	pGC = GetGC();
	ctrl_ptr = (struct bt_ctrl_str *)ctrl_str;
	if( ActiveAreaRead( ctrl_ptr->bt_id, &xSrc, &ySrc, &xDest, &yDest ) == PPSM_ERROR )
		return ASIX_ERROR;
	

⌨️ 快捷键说明

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