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

📄 uickbtn.c

📁 嵌入工linux开发的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <uiWnd.h>

extern struct tagGuiWindow*   gpTopWindow ;

void _chkbtn_paint(HNDL handle)
{
	int  Font_Height,Dis_Ypos;
	WORD left,right,top,bottom,Back_Color,Font_Color,temp_num,temp_top;
	struct tagGuiChkButton	*pControl;
	pControl=(struct tagGuiChkButton *)handle;
	Back_Color=CHKBTN_BACK_COLOR;
	Font_Color=CHKBTN_FONT_COLOR;
	left=0;
	top=0;
	right=pControl->base.right-pControl->base.left;
	bottom=pControl->base.bottom-pControl->base.top;
	
	if(pControl->base.style == BUTTON_CHECKBOX1 || pControl->base.style == BUTTON_CHECKBOX2 || pControl->base.style == BUTTON_RADIO)
	{
		if(right-left+1 > 12 && bottom-top+1>12)
		{
			temp_num=bottom-top+1;
			temp_num=temp_num-12;
			temp_num=temp_num/2;
			temp_top=top+temp_num;
			
			if(pControl->fChecked == OFFCHECKED)
			{
				if(pControl->base.style == BUTTON_RADIO)
				{
					guiPutImage(handle,left, temp_top, left+11, temp_top+11, (unsigned char *)icon_Gui_Unchecked_Circle);
				}
				else
				{
					guiPutImage(handle,left, temp_top, left+11, temp_top+11, (unsigned char *)icon_Gui_Unchecked_Box);
				}
			}
			else if(pControl->fChecked == ONCHECKED)
			{
				if(pControl->base.style == BUTTON_RADIO)
				{
					guiPutImage(handle,left, temp_top, left+11, temp_top+11, (unsigned char *)icon_Gui_Checked_Circle);
				}
				else if(pControl->base.style == BUTTON_CHECKBOX1)
				{
					guiPutImage(handle,left, temp_top, left+11, temp_top+11, (unsigned char *)icon_Gui_Checked_Box1);
				}
				else
					guiPutImage(handle,left, temp_top, left+11, temp_top+11, (unsigned char *)icon_Gui_Checked_Box2);
			}
			if(pControl->fChecked != FAILCHECKED)
			{
				guiPushFont(pControl->base.font) ;
				
				Font_Height=guiGetCharHeight();
				Dis_Ypos=getAlignCenter(top,bottom,Font_Height);
				if(Dis_Ypos < top)
					Dis_Ypos=top;
				//guiClearBlock(0,left+12,top,right,bottom,Back_Color,REPLACE_STYLE);
				guiShowString(handle,(char *)pControl->caption,left+12,Dis_Ypos,Back_Color<<8 | Font_Color,FONT_TRANSPARENT);
				guiPopFont(); 	
			}
		}
	}
	else
	{
		if(pControl->base.style == BUTTON_LABEL  && pControl->fChecked != FAILCHECKED)
		{
			if(pControl->fChecked == OFFCHECKED)
			{
				Back_Color=CHKBTN_BACK_COLOR;
				Font_Color=CHKBTN_FONT_COLOR;
			}
			else if(pControl->fChecked == ONCHECKED)
			{
				Back_Color=CHKBTN_FONT_COLOR;
				Font_Color=CHKBTN_BACK_COLOR;
			}
			guiDrawRect(handle,left, top, right, bottom,CHKBTN_BORDER_COLOR, GUI_SOLID);
			guiClearBlock(handle,left+1,top+1,right-1,bottom-1,Back_Color,REPLACE_STYLE);
			
			guiPushFont(pControl->base.font) ;
			
			Font_Height=guiGetCharHeight();
			Dis_Ypos=getAlignCenter(top,bottom,Font_Height);
			if(Dis_Ypos < top)
				Dis_Ypos=top;
			guiShowString(handle,(char *)pControl->caption,left+1,Dis_Ypos,Back_Color<<8 | Font_Color,FONT_TRANSPARENT);
			
			guiPopFont(); 	
		}
	}
}

/*********************************************************************/
//para: check button's handle and it's check status
//dest: process check button in group and keep one check status 
//check button in the group
//return:void
/*********************************************************************/
void _chkbtn_group_handler(HNDL handle,WORD fchecked)
{	
	struct tagGuiChkButton	        *pControl;
	struct tagguiGroupItem	*pGroup_Item;
	struct tagguiGroup		*pGroup;
	if(handle == NULL)
		return;
	pControl=(struct tagGuiChkButton *)handle;
	pGroup=pControl->group;
	if(pGroup == NULL)
		return;
	pGroup_Item=pGroup->head;

	while(pGroup_Item)
	{
		if(pGroup_Item->button == pControl)
		{
			if(pGroup->current != NULL)
			{
				pGroup->current->button->fChecked = OFFCHECKED;
				//12.7
				if(guiControl_IsVisible((HNDL)(pGroup->current->button)) == TRUE)
					_chkbtn_paint((HNDL)(pGroup->current->button));     
				pGroup->current=NULL;
			}
			if(fchecked == ONCHECKED)
			{
				pControl->fChecked =fchecked;
				//12.7
				if(guiControl_IsVisible(handle) == TRUE)
					_chkbtn_paint(handle);			
				pGroup->current=pGroup_Item;
			}
			///////////////11.16 DDH added
			else 
			{
				pControl->fChecked =fchecked;
				//12.7
				if(guiControl_IsVisible(handle) == TRUE)
					_chkbtn_paint(handle);
			}
			///////////////
			break;
		}
		else
			pGroup_Item=pGroup_Item->next;
	}
}

void chkbuttonAction(HNDL handle , WORD Pen_Message, WORD x , WORD y)
{
	struct tagGuiMessage		message; 
	struct tagGuiChkButton		*pControl;
	pControl=(struct tagGuiChkButton *)handle;
	if(pControl->base.checkFlag != GUI_CONTROL_CHECK_FLAG || pControl->base.status & CONTROL_NOT_ACTIVE)
		return;
	if(Pen_Message == PENUP)
	{
		message.handle = handle;
		message.messageType=CHKBTN_CLICK;
		message.x=((struct tagGuiChkButton *)handle)->fChecked;
		//message.y=y;
		guiEnqueue(gpTopWindow->messageQueue,&message);           
			guiPenSound();
	//_chkbtn_paint(handle);	   
	}
	else if(Pen_Message >= PENMOVE)
	{
		if(Pen_Message == PENMOVE)
			return;
		else if(Pen_Message == PENROVE)
		{
			if(pControl->group == NULL)
			{
				if(pControl->fChecked == OFFCHECKED)
					pControl->fChecked = ONCHECKED;
				else
					pControl->fChecked = OFFCHECKED;
				_chkbtn_paint(handle);
			}
			else
			{
			//	if(prevChkBtn.base.handle == 0)
				if(pControl->group->select_handle == 0)
				{
					if(pControl->group->current != NULL)
						_chkbtn_group_handler((HNDL)(pControl->group->current->button),OFFCHECKED); 
				}
				else
					//_chkbtn_group_handler(prevChkBtn.base.handle,ONCHECKED);
					_chkbtn_group_handler(pControl->group->select_handle,ONCHECKED);
			}
		}
	}
	else if(Pen_Message == PENDOWN)
	{
		if(pControl->group == NULL)
		{
			if(pControl->fChecked == OFFCHECKED)
				pControl->fChecked = ONCHECKED;
			else
				pControl->fChecked = OFFCHECKED;
			_chkbtn_paint(handle);
		}
		else
		{
			if(pControl->group->current == NULL)
				//prevChkBtn.base.handle=0;
				pControl->group->select_handle=0;
			else
				//prevChkBtn.base.handle=(HNDL)(pControl->group->current->button);
				pControl->group->select_handle=(HNDL)(pControl->group->current->button);
			_chkbtn_group_handler(handle,ONCHECKED);
		}
	}
}

/*********************************************************************/
//para: left,top,right,bottom:refer to window or vport
//dest: create chkbtn
//return:
//fail: NULL
//sucess: chkbtn handle
/*********************************************************************/
DLL_EXP(HNDL) guiChkButton_Create( WORD left, WORD top,	WORD right, WORD bottom, char* caption, WORD style)
{
	struct tagGuiChkButton  *pControl;
	
	guiEnterWCS();
	pControl=(struct tagGuiChkButton *)kernelMalloc(sizeof(struct tagGuiChkButton));
    if(pControl == NULL)
	{
		guiExitWCS();
		return NULL;
	}
	pControl->base.handle=(HNDL)pControl;
	pControl->base.left=left;
	pControl->base.top=top;
	pControl->base.right=right;
	pControl->base.bottom=bottom;
	pControl->base.vportHandle=NULL;
	pControl->base.container=NULL;
	pControl->base.type=CONTROL_CHKBTN; 
	pControl->base.style=style;
	pControl->base.status=0;
	pControl->base.font=GUI_DEFAULT_FONT;
	pControl->base.checkFlag=GUI_CONTROL_CHECK_FLAG;
	pControl->base.actionFun=chkbuttonAction;
	pControl->base.showFun=guiChkButton_Show;
	pControl->base.delFun=guiChkButton_Delete;
	pControl->fChecked=OFFCHECKED;
	if(caption == NULL)
		pControl->caption[0]='\0';
	else
	{
		strncpy(pControl->caption,caption,GUI_CHKBTN_CAPTION_SIZE);
		pControl->caption[GUI_CHKBTN_CAPTION_SIZE]='\0';
	}
	pControl->group=NULL;
	guiExitWCS();
	return (HNDL)pControl;
}

/*********************************************************************/
//para: handle & select or not
//dest: select chkbtn or not
//return:
//fail: FAILCHECKED
//sucess: ONCHECKED or FAILCHECKED
/*********************************************************************/
DLL_EXP(WORD) guiChkButton_SetValue( HNDL handle, WORD fChecked)
{
	struct tagGuiChkButton  *pControl;
	if(handle == NULL)
		return FAILCHECKED;
	guiEnterWCS();
	pControl=(struct tagGuiChkButton *)handle;
	if(pControl->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS(); 
		return FAILCHECKED;
	}
	if(pControl->group != 0)
	{
		_chkbtn_group_handler(handle,fChecked);
		guiExitWCS();
		return pControl->fChecked;
	}
	else
	{
		if(fChecked == ONCHECKED || fChecked == OFFCHECKED)
		{
			pControl->fChecked = fChecked;
			if(guiControl_IsVisible(handle) == TRUE)
				_chkbtn_paint(handle); 
			guiExitWCS();
			return pControl->fChecked;
		}
		else
		{
			guiExitWCS(); 
			return FAILCHECKED;
		}
	}

⌨️ 快捷键说明

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