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

📄 list.c

📁 好记星的控件,包括button,list,对文件操作
💻 C
📖 第 1 页 / 共 3 页
字号:
	note:
  ****************************************************************************
	高林辉				2005-12-28				创建						
****************************************************************************/
UINT32      ListGetTopLine(MList *pList)
{
    return pList->pListInfo->dwTopLine;
}

/****************************************************************************
	Function:
		UINT32      ListSetTopLine(MList *pList, UINT32 dwTopLine)
    Description:
	设置顶行号
	input:
	pList - list模板指针
	dwTopLine - 设置的顶行号
	output:
	设置前的顶行号
	note:
  ****************************************************************************
	高林辉				2005-12-28				创建						
****************************************************************************/
UINT32      ListSetTopLine(MList *pList, UINT32 dwTopLine)
{
    UINT32  dwLine;

    if( dwTopLine >= pList->pListInfo->dwTotalLine ){
        return 0;
    }
    dwLine = pList->pListInfo->dwTopLine;
    pList->pListInfo->dwTopLine = dwTopLine;

    return dwLine;
}

/****************************************************************************
	Function:
		UINT8      ListGetPageLines(MList* pList)
    Description:
	得到List一页的条目数
	input:
	pList - list模板指针
	output:
	一页的条目数
	note:
  ****************************************************************************
	高林辉				2005-12-28				创建						
****************************************************************************/
UINT8      ListGetPageLines(MList* pList)
{
	return pList->pListInfo->byPageLineNub;
}


/****************************************************************************
	Function:
		VOID		ListInitialize(VOID)
    Description:
		List控件初始化
	input:

	output:

	note:
	此函数并非为创建一个List时使用,在系统内核初始化时,调用此函数,它规定了所有list控件的
	一个风格.
  ****************************************************************************
	高林辉				2005-12-28				创建						
****************************************************************************/
VOID		ListInitialize(VOID)
{
    ListSetFaceParam((MListFace *)(&LISTFACE) );
}


/****************************************************************************
	Function:
	VOID		ListSetIconCallBack(MList* pList,PLISTICONCALLBACK pfnIconCallBack)
    Description:
	设置获取ICON的回调函数
	input:
	pList - List模板指针
	pfnIconCallBack - 回调函数
	output:

	note:
		typedef UINT8* (*PLISTICONCALLBACK)(UINT);
  ****************************************************************************
	高林辉				2005-12-28				创建						
****************************************************************************/
VOID		ListSetIconCallBack(MList* pList,PLISTICONCALLBACK pfnIconCallBack)
{
	pList->pListInfo->pfnListGetIconCallBack = pfnIconCallBack;
}

/****************************************************************************
	Function:
	BOOL		ListSetBuffer(MList* pList, UINT8* pBuff)
    Description:
	设置LIST的buffer
	input:
	pList - List handle.
	pBuff - buffer
	output:
	if success return TRUE,Otherwise return FALSE.
  ****************************************************************************
	高林辉				2006-2-23				创建						
****************************************************************************/
BOOL		ListSetBuffer(MList* pList, UINT8* pBuff)
{
	BOOL bRet = FALSE;
	//如果List已初始化,不允许再次设置buffer.
	if(pBuff && !(pList->pListInfo->uState & STA_LST_INITED))
	{
		//设置Listbuffer
		pList->pDataBuff = pBuff;
		MsgSend2((APGUI_STRUCT_MODEL*)pList, EVENT_INITIALIZE, 0);
		bRet = TRUE;
	}
	return bRet;
}


//List停止滚动
VOID _ListStopScroll(MList* pList)
{
	//停止并销毁滚动定时器和等待定时器
	if(pList->pListInfo->hSclTimer)
	{
		LST_DESTROY_TIMER(pList->pListInfo->hSclTimer);
	}
	if(pList->pListInfo->hWtTimer)
	{
		LST_DESTROY_TIMER(pList->pListInfo->hWtTimer);
	}
	//设置退出滚动模式状态
	pList->pListInfo->uState &= ~STA_EN_SCLTIMER;
	pList->pListInfo->uState &= ~STA_EN_WTTIMER;
	pList->pListInfo->nBufOffset = 0;
	pList->pListInfo->uState &= ~STA_EN_SCROLL;
}

//List检查是否可以滚动,如果可以滚动,进入滚动模式
VOID _ListChkForScroll(MList* pList)
{
	UINT strlen;
	UINT width;
	UINT16 wID;
	UINT8* pBuf;

	if( (pList->pListInfo->dwTotalLine == 0 )
		&& (pList->pListInfo->dwCurLine >= pList->pListInfo->dwTotalLine) )
	{
		return; 
	}
	if( pList->pListInfo->uState & STA_EN_SCROLL )	//如果当前已启动scroll功能,返回
	{
		return;
	}
	if(pList->pListInfo->hSclTimer)
	{	//停止并销毁滚动Timer
		LST_DESTROY_TIMER(pList->pListInfo->hSclTimer);
		pList->pListInfo->uState &= ~STA_EN_SCLTIMER;
	}
	//取当前项的List数据
    if( pList->pGetDataProgram != NULL )
	{
		//如果是通过回调函数取数据方式
		(pList->pGetDataProgram)( pList->pListInfo->pDspBuffer , pList->pListInfo->dwCurLine + pList->pListInfo->dwTopLine );
	}
	else
	{
		pBuf = pList->pDataBuff + ( pList->pListInfo->dwCurLine + pList->pListInfo->dwTopLine ) * pList->wItemLength;
		strncpy(pList->pListInfo->pDspBuffer, pBuf, pList->wItemLength);
	}
	pBuf = pList->pListInfo->pDspBuffer;
	//判断list当前项的数据是否超出list显示范围,如果超出,启动scroll功能.
	strlen = FontGetStringWidth(SYSTLIB,pBuf);		
	width = pList->pListInfo->wValidDspWidth;
	if(strlen > width)
	{
		if(!(pList->pListInfo->hWtTimer))
		{	//如果没有等待定时器,则创建
			wID = LIST_WTTIMER_ID(pList);
			pList->pListInfo->hWtTimer = TimerCreateTimer(wID,LIST_WTTIMER_SET);
		}
		if(pList->pListInfo->hWtTimer)
		{//创建wait_timer成功
			wID = LIST_WTTIMER_ID(pList);
			//开启等待定时器
			TimerResetTimer(pList->pListInfo->hWtTimer,wID,LIST_WTTIMER_SET);
			pList->pListInfo->uState |= STA_EN_WTTIMER;		//设置等待定时器有效
			pList->pListInfo->uState |= STA_EN_SCROLL;		//设置进入滚动模式
			pList->pListInfo->nBufOffset = 0;
		}
		else
		{
			pList->pListInfo->uState &= ~STA_EN_WTTIMER;	//设置等待定时器无效
			pList->pListInfo->uState &= ~STA_EN_SCROLL;		//设置滚动模式无效
		}
		
	}

}

#ifdef LIST_SUPPORT_PEN
//List笔点处理函数
INT  __ListPenProc(MList* pList,UINT uEvent, UINT uParam)
{
	INT iX, iY, X0, X1, Y0, Y1;
	INT nRet = 0;
	INT8 chItem, chPageLines;
	UINT32 dwTopLine,dwTotalLine,dwCurItem;
	BOOL bSelChange = FALSE;
	BOOL bReDraw = FALSE;
	BOOL bDBClk = FALSE;

	iX = GET_PEN_X(uParam);				//取当前笔点的位置
	iY = GET_PEN_Y(uParam);
	//计算List左上角和右下角的坐标
	X0 = pList->uX;
	X1 = pList->uX + pList->uWidth -1;
	if(pList->byStyle & LIST_ICON)
	{
		X0 += LIST_ICON_WIDTH;
	}
	Y0 = pList->uY;
	Y1 = pList->uY + pList->uHeight -1;
	if(pList->byStyle & LIST_BORDER)
	{
		X0 += 1;
		X1 -= 1;
	}
	//List当前项
	dwCurItem = ListGetCurrentLine(pList);
	//当前笔点位置对应的行
	chItem = (iY - Y0) / (pList->byLineSpace);
	//List的顶行
	dwTopLine = ListGetTopLine(pList);
	//List的总行数
	dwTotalLine = ListGetTotalLine(pList);
	//一页的总行数
	chPageLines = (pList->uHeight) / (pList->byLineSpace);
	switch(uEvent)
	{
	case EVENT_PENDOWN:
		//判断笔点的位置是否在当前的List控件的区域内
		if ( DotInArea(iX, iY, X0, Y0, X1, Y1) )
		{
			//如果笔点的位置还有数据
			if( chItem+dwTopLine+1 <= dwTotalLine )
			{		
				if(dwCurItem != (UINT8)chItem)//如果笔点项不是当前项,设置该行为当前行
				{
					ListSetCurrentLine(pList, (UINT32)chItem);	//设置当前行
					bSelChange = TRUE;
					bReDraw = TRUE;
				}
					
			}
			nRet = 1;	//表明List已经处理了该消息
		}
		break;

	case EVENT_PENMOVE:
		if( (iX >= X0) && (iX <= X1) )
		{
			if( iY > Y1-5 )
			{
				if( dwTopLine+chPageLines < dwTotalLine )
				{
					ListSetTopLine(pList, dwTopLine+1);
					ListSetCurrentLine(pList, (chPageLines-1) );
					bReDraw = TRUE;
					bSelChange = TRUE;
				}
			}
			else if(iY < Y0+5)
			{
				if(dwTopLine > 0)
				{
					ListSetTopLine(pList, dwTopLine-1);
					ListSetCurrentLine(pList, 0 );
					bReDraw = TRUE;
					bSelChange = TRUE;
				}
			}
			else
			{
				if( dwTopLine+chItem+1 <= dwTotalLine)
				{
					ListSetCurrentLine(pList, chItem);
					bReDraw = TRUE;
					bSelChange = TRUE;
				}
			}
			
			nRet = 1;	//表明List处理该消息
		}
		
		break;

	case EVENT_PENUP:
		//只处理笔点在控件范围内的消息
		if( DotInArea(iX, iY, X0, Y0, X1, Y1) )
		{
			if( (chItem+dwTopLine+1) <= dwTotalLine )
			{
				if(dwCurItem == (UINT32)chItem)//只有松开时的选择项为当前项,笔点才是有效的
				{
					bDBClk = TRUE;
					_ListStopScroll(pList);
				}	
			}
			nRet = 1;	//表示处理了该消息
		}	
		break;
		
	}
	
	if(bSelChange)
	{
		//发送一个List当前项改变消息	
		g_mLstCmdEx.uType = CMEX_LST_SELECTCHANGED;
		g_mLstCmdEx.pListHdl = (APGUI_STRUCT_MODEL*)pList;
		g_mLstCmdParam.wCmdType = EVENT_CMDEXP_LST;
		g_mLstCmdParam.pCmdExp = &g_mLstCmdEx;				
		MsgSend2(GetApHandle(), EVENT_CMDEXP, (UINT)&g_mLstCmdParam);
	}
	if(bDBClk)
	{
		g_mLstCmdEx.uType = CMEX_LST_SELECTDBCLICK;
		g_mLstCmdEx.pListHdl = (APGUI_STRUCT_MODEL*)pList;
		g_mLstCmdParam.wCmdType = EVENT_CMDEXP_LST;
		g_mLstCmdParam.pCmdExp = &g_mLstCmdEx;				
		MsgPost(NULL, EVENT_CMDEXP, (UINT)&g_mLstCmdParam);

	}
	if(bReDraw)
	{
		GraphDisableRefresh();
		_ListStopScroll(pList);
		ListDraw( pList );
		_ListChkForScroll(pList);
		GraphEnableRefresh();
	}
	
	return nRet;

}


#endif



⌨️ 快捷键说明

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