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

📄 uilistbox.c

📁 嵌入工linux开发的源码
💻 C
📖 第 1 页 / 共 2 页
字号:

	if(guiControl_IsVisible(hListbox)==TRUE)
	{
		top=0;
		left=0;
		bottom=pListbox->base.bottom-pListbox->base.top;
		right=pListbox->base.right-pListbox->base.left;

		if(pListbox->base.style&LISTBOX_NONE_BORDER)
		{
			guiClearBlock(hListbox,left,top,right,bottom,GUI_WHITE,REPLACE_STYLE);
		}
		else
		{
			guiClearBlock(hListbox,left+1,top+1,right-1,bottom-1,GUI_WHITE,REPLACE_STYLE);
		}
	}
	for(i=0;i<pListbox->nItemCount;i++)
	{
		pItem=DList_Remove(pListbox->pItemList,0);
		sc_free(pItem);
	}

	pListbox->nItemCount=0;
	pListbox->nLastHited=-1;
	pListbox->nLastSelected=-1;
	pListbox->nOffset=0;
	pListbox->nSelectedCount=0;

	guiExitWCS();
	return STATUS_OK;
}

/* get item content */
DLL_EXP(char*) guiListbox_GetItem( HNDL hListbox, WORD index)
{
	TListboxItem * pItem;
	TListbox * pListbox;
	pListbox=(TListbox *)hListbox;

	guiEnterWCS();

	if(pListbox->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS();
		return 0;
	}
	if(index>=pListbox->nItemCount)
	{
		guiExitWCS();
		return 0;
	}

	pItem=(TListboxItem *)DList_GetObject(pListbox->pItemList,index);

	guiExitWCS();
	return pItem->szCaption;
}

/* select item */
DLL_EXP(int) guiListbox_Select( HNDL hListbox, WORD index)
{
	TListboxItem * pItem;
	TListbox * pListbox;
	pListbox=(TListbox *)hListbox;

	guiEnterWCS();
	if(pListbox->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_ERR;
	}
	if(index>=pListbox->nItemCount)
	{
		guiExitWCS();
		return STATUS_ERR;
	}

//1	if(pListbox->nLastHited>=0&&(pListbox->base.style&LISTBOX_MULTI_SELECT)==0)
	if(guiListbox_IsSelected(hListbox,index)==FALSE&&(pListbox->base.style&LISTBOX_MULTI_SELECT)==0)
	{
		guiListbox_Deselect(hListbox,pListbox->nLastHited);
//1		guiListbox_Deselect(hListbox,pListbox->nLastSelected);
	}

	pItem=(TListboxItem *)DList_GetObject(pListbox->pItemList,index);
	if(pItem->nStatus!=ITEM_SELECTED)
	{
		pItem->nStatus=ITEM_SELECTED;
	//tong 020603
		_guiListbox_DrawItem(pListbox,index,index);
		//pListbox->nOffset=index;
		//_guiListbox_Paint(pListbox ,pListbox->nOffset);
		pListbox->nSelectedCount++;

	}

	if(pListbox->nLastSelected==index)
	{
		pListbox->nSecondSelect=LISTBOX_SECOND_CLICK;
	}
	else
	{
		pListbox->nSecondSelect=0;
	}
	pListbox->nLastHited=index;
//1	pListbox->nLastHited=pListbox->nLastSelected;
	pListbox->nLastSelected=index;

	guiExitWCS();
	return STATUS_OK;
}

/* de-select item */
DLL_EXP(int) guiListbox_Deselect( HNDL hListbox, WORD index)
{
	TListboxItem * pItem;
	TListbox * pListbox;
	pListbox=(TListbox *)hListbox;

	guiEnterWCS();
	if(pListbox->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_ERR;
	}
	if(index>=pListbox->nItemCount)
	{
		guiExitWCS();
		return STATUS_ERR;
	}

	pItem=(TListboxItem *)DList_GetObject(pListbox->pItemList,index);
	if(pItem->nStatus==ITEM_SELECTED)
	{
		pItem->nStatus=ITEM_NOT_SELECTED;
		_guiListbox_DrawItem(pListbox,index,index);
		pListbox->nLastSelected=-1;;
		pListbox->nSelectedCount--;
	}

	pListbox->nLastHited=index;

	guiExitWCS();
	return STATUS_OK;
}

/* get item status */
DLL_EXP(BOOL) guiListbox_IsSelected( HNDL hListbox, WORD index)
{
	TListboxItem * pItem;
	TListbox * pListbox;
	pListbox=(TListbox *)hListbox;

	guiEnterWCS();
	if(pListbox->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS();
		return FALSE;
	}
	if(index>=pListbox->nItemCount)
	{
		guiExitWCS();
		return FALSE;
	}

	pItem=(TListboxItem *)DList_GetObject(pListbox->pItemList,index);
	if(pItem->nStatus==ITEM_SELECTED)
	{
		guiExitWCS();
		return TRUE;
	}

	guiExitWCS();

	return FALSE;
}

/* get listbox property */
DLL_EXP(short) guiListbox_GetValue( HNDL hListbox, short type)
{
	TListbox * pListbox;
	pListbox=(TListbox *)hListbox;

	guiEnterWCS();
	if(pListbox->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS();
		return 0;
	}

	switch(type)
	{
	case LISTBOX_SEL_INDEX:
		guiExitWCS();
		return pListbox->nLastSelected;
	case LISTBOX_COUNT:
		guiExitWCS();
		return pListbox->nItemCount;
	case LISTBOX_SEL_COUNT:
		guiExitWCS();
		return pListbox->nSelectedCount;
/*	case LISTBOX_LAST_HITED:
		guiExitWCS();
		return pListbox->nLastHited;
*/
	}
	guiExitWCS();
	return -1;
}

/* set item icon */
DLL_EXP(int) guiListbox_SetIcon( HNDL hListbox, WORD index, const BYTE *icon)
{
	TListbox *pListbox;
	TListboxItem *pItem;

	guiEnterWCS();
	pListbox=(TListbox *)hListbox;
	if(pListbox->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_ERR;
	}

	if(index>=pListbox->nItemCount||pListbox->nItemCount==0)
	{
		guiExitWCS();
		return STATUS_ERR;
	}

	pItem=(TListboxItem *)DList_GetObject(pListbox->pItemList,index);
	pItem->icon=(BYTE *)icon;

	guiExitWCS();
	return STATUS_OK;
}

DLL_EXP(int) guiListbox_Move( HNDL hListbox, WORD index)
{
	TListbox *pListbox;

	guiEnterWCS();
	pListbox=(TListbox *)hListbox;
	if(pListbox->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_ERR;
	}

	if(index>=pListbox->nItemCount||pListbox->nItemCount==0)
	{
		guiExitWCS();
		return STATUS_ERR;
	}

	pListbox->nOffset=index;
	_guiListbox_Paint(pListbox ,pListbox->nOffset);

	guiExitWCS();
	return STATUS_OK;
}



#define POPUP_BORDER_BLANK			2

/* popup a listbox */
DLL_EXP(int) guiListbox_Popup( HNDL hListbox)
{
	int left,top,right,bottom;
	int iTemp,iOffset;

	HNDL hContainer=0;
	TListbox *pListbox;

	pListbox=(TListbox *)hListbox;

	guiEnterWCS();

	//shrink previous popup list
	guiListbox_Shrink();

	if(POPUP.handle!=0)
	{
		guiExitWCS();
		return STATUS_ERR;
	}

	if(pListbox->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_ERR;
	}

	pListbox->nOffset = 0;          //display first item every time. by zhangxp 2003/06/09

	//save original data
	POPUP.left=pListbox->base.left;
	POPUP.top=pListbox->base.top;
	POPUP.right=pListbox->base.right;
	POPUP.bottom=pListbox->base.bottom;

	//get related coordinate of listbox
	left=0;
	top=0;
	right=pListbox->base.right-pListbox->base.left;
	bottom=pListbox->base.bottom-pListbox->base.top;

	//adjust height and width
	if(bottom-top+1>GUI_SCREEN_HEIGHT-2*POPUP_BORDER_BLANK)
	{
		bottom=top+(GUI_SCREEN_HEIGHT-2*POPUP_BORDER_BLANK)-1;
		pListbox->base.bottom=pListbox->base.top+(GUI_SCREEN_HEIGHT-2*POPUP_BORDER_BLANK)-1;
	}

	if(right-left+1>GUI_SCREEN_WIDTH-2*POPUP_BORDER_BLANK)
	{
		right=left+(GUI_SCREEN_WIDTH-2*POPUP_BORDER_BLANK)-1;
		pListbox->base.right=pListbox->base.left+(GUI_SCREEN_WIDTH-2*POPUP_BORDER_BLANK)-1;
	}

	//convert to physical coordinate
	_guiConvertXY(hListbox,&left,&top);
	_guiConvertXY(hListbox,&right,&bottom);

	//modidy y direction
	if(top<POPUP_BORDER_BLANK)
	{
		iOffset=POPUP_BORDER_BLANK-top;
		pListbox->base.bottom+=iOffset;
		pListbox->base.top+=iOffset;
		top=POPUP_BORDER_BLANK;
		bottom+=iOffset;
	}
	else if(bottom>GUI_SCREEN_HEIGHT-1-POPUP_BORDER_BLANK)
	{
		iOffset=bottom-(GUI_SCREEN_HEIGHT-1-POPUP_BORDER_BLANK);
		pListbox->base.bottom-=iOffset;
		pListbox->base.top-=iOffset;
		top-=iOffset;
		bottom=GUI_SCREEN_HEIGHT-1-POPUP_BORDER_BLANK;
	}

	//modify x direction
	if(left<POPUP_BORDER_BLANK)
	{
		iOffset=POPUP_BORDER_BLANK-left;
		pListbox->base.right+=iOffset;
		pListbox->base.left+=iOffset;
		left=POPUP_BORDER_BLANK;
		right+=iOffset;
	}
	else if(right>GUI_SCREEN_WIDTH-1-POPUP_BORDER_BLANK)
	{
		iOffset=right-(GUI_SCREEN_WIDTH-1-POPUP_BORDER_BLANK);
		pListbox->base.right-=iOffset;
		pListbox->base.left-=iOffset;
		left-=iOffset;
		right=GUI_SCREEN_WIDTH-1-POPUP_BORDER_BLANK;
	}

	guiCaret_Disable();
	
	//save background
	if(POPUP.img_buf==NULL)
	{
		iTemp=guiGetImageSize(left,top,right,bottom);
		POPUP.img_buf=(BYTE *)kernelMalloc(iTemp);
	}
	if(POPUP.img_buf!=NULL)
	{
		guiGetImage(0,left,top,right,bottom,POPUP.img_buf);
	}

	//draw popup list
	pListbox->base.status&=~(CONTROL_NOT_ACTIVE|CONTROL_NOT_VISIBLE);
	guiClearBlock(0,left,top,right,bottom,GUI_WHITE,REPLACE_STYLE);
	pListbox->base.showFun(hListbox);

	//save handle of popup list
	POPUP.handle=hListbox;

	guiExitWCS();
	return STATUS_OK;
}


/* shrink a popuped listbox */
DLL_EXP(int) guiListbox_Shrink(void)
{
	int left,top,right,bottom;

	TGuiMessage tMessage;
	TListbox *pListbox;

	if(POPUP.handle==0)
	{
		return STATUS_OK;
	}

	pListbox=(TListbox *)POPUP.handle;

	//get and convert coordinate
	left=0;
	top=0;
	right=((TGuiControl *)POPUP.handle)->right-((TGuiControl *)POPUP.handle)->left;
	bottom=((TGuiControl *)POPUP.handle)->bottom-((TGuiControl *)POPUP.handle)->top;
	_guiConvertXY(POPUP.handle,&left,&top);
	_guiConvertXY(POPUP.handle,&right,&bottom);

	//restore saved image
	if(POPUP.img_buf!=NULL)
	{
		guiPutImage(0,left,top,right,bottom,POPUP.img_buf);
		sc_free(POPUP.img_buf);
		POPUP.img_buf=NULL;
	}

	//set the control is NOT_ACTIVE and NOT VISIBLE;
	((TGuiControl *)POPUP.handle)->status|=CONTROL_NOT_ACTIVE|CONTROL_NOT_VISIBLE;

	//restore control coordinate
	pListbox->base.left=POPUP.left;
	pListbox->base.top=POPUP.top;
	pListbox->base.right=POPUP.right;
	pListbox->base.bottom=POPUP.bottom;

	//send message to the top window
	tMessage.handle=POPUP.handle;
	tMessage.messageType=LISTBOX_CLOSED;
	tMessage.x=0;
	tMessage.y=0;
	if(gpTopWindow!=NULL)
	{
		guiEnqueue(gpTopWindow->messageQueue,&tMessage);
	}

	POPUP.handle=0;
	
	guiCaret_Enable();
	return STATUS_OK;
}

/* popup-list handler: used by touch-pen call-back function */
BOOL guiListbox_PopupListHandler( WORD type, WORD x, WORD y )
{
	int left=0,top=0,right=0,bottom=0;
	int iX=0,iY=0;
	HNDL hContainer;
	TListbox *pListbox;

	if(POPUP.handle==0)
	{
		return FALSE;
	}

	pListbox=(TListbox *)POPUP.handle;

	if(guiQueryWindowOfControl(POPUP.handle)!=(HNDL)gpTopWindow)
	{
		return FALSE;
	}

	//get handle of container
	if(((TGuiControl *)POPUP.handle)->container)
	{
		hContainer=((TGuiControl *)POPUP.handle)->container;
	}
	else
	{
		hContainer=((TGuiControl *)POPUP.handle)->vportHandle;
	}

	//convert physical coordinate to related coodinate of container
	_guiConvertXY(hContainer,&iX,&iY);
	iX=x-iX;
	iY=y-iY;

	//call action funtion or shrink
	if(iX>=pListbox->base.left&&iX<=pListbox->base.right&&iY>=pListbox->base.top&&iY<=pListbox->base.bottom)
	{
		((TGuiControl *)POPUP.handle)->actionFun((HNDL)POPUP.handle,type,iX,iY);
	}
	else
	{
		if(type==PENUP)
		{
			guiListbox_Shrink();
		}
	}
	return TRUE;
}
/*******************************************************************/
//		below function for multi column
/*******************************************************************/
DLL_EXP(int) guiListbox_SetColumn(HNDL hListbox,short *pColumn)
{
	int i;
	TListbox *pListbox;

	pListbox=(TListbox *)hListbox;

	if(pListbox==NULL)
	{
		return STATUS_ERR;
	}

	guiEnterWCS();

	if(pListbox->base.checkFlag!=GUI_CONTROL_CHECK_FLAG||pListbox->base.type!=CONTROL_LISTBOX)
	{
		guiExitWCS();
		return STATUS_ERR;
	}

	if(pListbox->base.status&LISTBOX_MAX_COLUMN==0)
	{
		guiExitWCS();
		return STATUS_ERR;
	}

	for(i=0;i<LISTBOX_MAX_COLUMN;i++)
	{
		pListbox->a_nColumn_Start[i]=pColumn[i];
		if(pColumn[i]==-1)
		{
			break;
		}
	}

	guiExitWCS();
	return STATUS_OK;
}

int _guiListbox_ShowString(HNDL hListbox,char *str,int x,int y)
{
	char pTempStr[100];
	char *pStart;
	WORD rightBlank;
	int i,j;
	int iStart,iWidth,iEnd,iTemp=0;

	TListbox * pListbox;

	pListbox=(TListbox *)hListbox;

	if((pListbox->base.style&LISTBOX_NONE_BORDER)==0)
	{
		rightBlank=RIGHT_BLANK_BORDER;
	}
	else
	{
		rightBlank=RIGHT_BLANK_NONE_BORDER;
	}

	for(i=0;i<LISTBOX_MAX_COLUMN;i++)
	{
		if(pListbox->a_nColumn_Start[i]==-1)
		{
			return STATUS_OK;
		}

		//get string position and width
		iStart=x+pListbox->a_nColumn_Start[i];
		iEnd=pListbox->base.right-pListbox->base.left-rightBlank;
		if(pListbox->base.style&LISTBOX_POPUP)
		{
			_guiConvertXY(hListbox,&iEnd,&iTemp);
		}

		iWidth=iEnd-iStart+1;
		if((pListbox->base.style&LISTBOX_MULTI_COLUMN)==0)
		{
			if(pListbox->base.style&LISTBOX_POPUP)
			{
				guiShowStringEx(0,str,iStart,y,iWidth,GUI_BLACK,FONT_NON_TRANSPARENT);
			}
			else
			{
				guiShowStringEx(hListbox,str,iStart,y,iWidth,GUI_BLACK,FONT_NON_TRANSPARENT);
			}
			return STATUS_OK;
		}

		if(i<(LISTBOX_MAX_COLUMN-1)&&pListbox->a_nColumn_Start[i+1]!=-1&&pListbox->a_nColumn_Start[i+1]<iEnd)
		{
			iEnd=pListbox->a_nColumn_Start[i+1]+x;
			iWidth=iEnd-iStart+1;
		}

		//get string
		for(j=0;j<100;j++)
		{
			pTempStr[j]=*str;
			if(pTempStr[j]=='\t'||pTempStr[j]=='\0')
			{
				pTempStr[j]='\0';
				if(pListbox->base.style&LISTBOX_POPUP)
				{
					guiShowStringEx(0,pTempStr,iStart,y,iWidth,GUI_BLACK,FONT_NON_TRANSPARENT);
				}
				else
				{
					guiShowStringEx(hListbox,pTempStr,iStart,y,iWidth,GUI_BLACK,FONT_NON_TRANSPARENT);
				}
				if(*str=='\0')
				{
					return STATUS_OK;
				}
				str++;
				break;
			}
			str++;
		}
	}
	return STATUS_OK;

}

static void  guiShowStringEx(HNDL handle, const char *szText,int x,int y,int ext, int complex_color, int style)
{
	unsigned char ch1, ch2;
	unsigned char *pText;
	int left, top, iRet;
	TRect   ViewRect;

	int ViewLeft, ViewTop, ViewRight, ViewBottom;


	iRet = _guiGetHandleView(handle, &ViewLeft, &ViewTop, &ViewRight, &ViewBottom);

	if(iRet!=STATUS_OK)
		return;

	ViewRect.left  = ViewLeft;   ViewRect.top    = ViewTop;
	ViewRect.right = ViewRight;  ViewRect.bottom = ViewBottom;



	left = x;
	top  = y;
	_guiConvertXY(handle, &left, &top);

	if(ViewRect.right>left+ext-1)
	{
		ViewRect.right=left+ext-1;
	}

	pText = (unsigned char *)szText;

	while(*pText)
	{
		ch1 = *pText;
		if(ch1<0x80)
		{
			_guiShowCharInView(&ViewRect, ch1, left, top, complex_color, style);
			pText++;
			left += guiGetCharWidth(ch1)+FONT_CHAR_GAP;
		}
		else
		{
			_guiShowWordInView(&ViewRect, (const char *)pText, left, top, complex_color, style);
			pText+=2;
			left += guiGetWordWidth()+FONT_CHAR_GAP;
		}
	}
}
                            

⌨️ 快捷键说明

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