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

📄 list.c

📁 好记星的控件,包括button,list,对文件操作
💻 C
📖 第 1 页 / 共 3 页
字号:
/**************************************************************************
                                                                          
              Copyright (C) 2005 SHENZHEN MEIJIN CO.LTD                   
                                                                          
 FILE NAME:   List.C                                                      
 MODULE NAME: List                                                        
 DESCRIPTION: List C File
 对外函数声明:
 //获取总行数
UINT32      ListGetTotalLine(MList *pList);
//设置总行数
UINT32      ListSetTotalLine(MList *pList, UINT32 dwTotalLine);
//获取当前行号
UINT32      ListGetCurrentLine(MList *pList);
//设置当前行号
UINT32      ListSetCurrentLine(MList *pList,UINT32 dwCurrentLine);
//获取当前顶行行号
UINT32      ListGetTopLine(MList *pList);
//设置当前顶行行号
UINT32      ListSetTopLine(MList *pList, UINT32 dwTopLine);
//添加一个条目
VOID        ListAddItem(MList *pList, UINT8 *pDataSource, UINT32 dwItemNub );
//删除一个条目
BOOL        ListDeleteItem(MList *pList, UINT32 dwItemNo);
//设置获取图标的回调函数
VOID		ListSetIconCallBack(MList* pList,PLISTICONCALLBACK pfnIconCallBack);
//编辑器控件初始化.
VOID		ListInitialize(VOID);
//LIST消息处理函数
UINT32		ListHandleEvent(APGUI_STRUCT_MODEL *pGui, UINT uEvent, UINT uParam);
//LIST设置外观参数
VOID		ListSetFaceParam(MListFace *pFace );

 内部函数声明:
	VOID _ListChkForScroll(MList* pList);
	VOID _ListStopScroll(MList* pList);
	INT	 __ListPenDown(MList* pList,INT x, INT y);
	INT	 __ListPenUp(MList* pList,INT x, INT y);
	INT	 __ListPenMove(MList* pList,INT x, INT y);
		
**************************************************************************
    DTAE       AUTHOR     VERSION                 REMARKS                 
 =========== ==========  =========  ======================================
 2006-12-31    gaolinhui    V1.0					create                               
***************************************************************************/
#include "kernel.h"


//全局变量
MListFace  g_mListFace;
CMDEXP     g_mLstCmdParam;
LstCmdEx   g_mLstCmdEx;

//默认外观参数
const MListFace LISTFACE = {
    BLACK_COLOR,	//边框黑色
    BLACK_COLOR,	//行分隔线黑色
    WHITE_COLOR,	//背景颜色1白色
    WHITE_COLOR,	//背景颜色2
    BLACK_COLOR,	//文本颜色黑色
    WHITE_COLOR,	//当前行背景颜色黑色
    BLACK_COLOR		//当前行文本颜色白色
};



//销毁定时器
#define	LST_DESTROY_TIMER(pTimer) {if(pTimer){TimerStopTimer(pTimer); \
TimerDestroyTimer(pTimer); pTimer = NULL;}}
 




/****************************************************************************
	Function:
		VOID    ListDraw(MList *pList)
    Description:
		List 控件Draw消息处理函数
	input:
		pList - List模板句柄
	output:

	note:
  ****************************************************************************
	高林辉				2005-12-28				创建						
****************************************************************************/
VOID    ListDraw(MList *pList)
{
    UINT32  dwPnColor, dwBrushColor, dwTextColor;
    UINT    uX, uY, uWidth, i, j;
	UINT    uXIcon,uYIcon;
    UINT8   *pBuf;
	UINT8*  pRes = NULL;
	BOOL    bInvertCurrent = TRUE;;

	
	GraphDisableRefresh();
	//备份钢笔,刷子和txt颜色设置
    dwPnColor = GraphGetPenColor();
    dwBrushColor = GraphGetBrushColor();
    dwTextColor = GraphGetTextColor();

    //draw background
    GraphSetBrushColor( g_mListFace.dwBackColor1 );
    GraphFillRect( pList->uX, pList->uY, pList->uX + pList->uWidth - 1, 
            pList->uY + pList->uHeight - 1 );
	if(pList->pListInfo->dwTotalLine == 0)	//如果总行数为0,直接返回
	{
		GraphSetPenColor( dwPnColor );
		GraphSetBrushColor( dwBrushColor );
		GraphSetTextColor( dwTextColor );
		GraphEnableRefresh();
		return ;
	}
    
	//draw border
    if( pList->byStyle & LIST_BORDER )
	{
        GraphSetPenColor(g_mListFace.dwBoderColor);
        GraphDrawRect( pList->uX, pList->uY, pList->uX + pList->uWidth -1, 
            pList->uY + pList->uHeight - 1);
    }
    //draw text and Icon   
	//计算显示的行数
    if( pList->pListInfo->byPageLineNub + pList->pListInfo->dwTopLine > pList->pListInfo->dwTotalLine )
	{	//如果是最后一页,行数小于一页总行数,使用剩余的行数
        j = pList->pListInfo->dwTotalLine - pList->pListInfo->dwTopLine ;
    }
	else
	{	//否则使用一页可以显示的行数
        j = pList->pListInfo->byPageLineNub;
    }
	//初始化坐标值
    uX  = pList->pListInfo->nX0;		 //画文字的起始x坐标
	uY  = pList->pListInfo->nY0;		 //画文字的起始Y坐标
    uY += (pList->byLineSpace - FontGetHeight(pList->pListInfo->wFontLib))/2;
    uXIcon = pList->pListInfo->nIconX0;	 //画图标的起始X坐标
	uYIcon = pList->pListInfo->nIconY0;	 //画图标的起始Y坐标
	uWidth = pList->pListInfo->wValidDspWidth;	//画文字的区域		
	//设置钢笔的颜色
    GraphSetPenColor( g_mListFace.dwSpLineColor );
    for( i = 0; i < j; i ++ )
	{
        if( pList->pGetDataProgram != NULL )
		{
			//如果是通过回调函数取数据方式
            (pList->pGetDataProgram)( pList->pListInfo->pDspBuffer , i + pList->pListInfo->dwTopLine );
        }
		else
		{	//通过的一个条目的定长取数据
            pBuf = pList->pDataBuff + ( i + pList->pListInfo->dwTopLine ) * pList->wItemLength;
			strncpy(pList->pListInfo->pDspBuffer, pBuf, pList->wItemLength);
        }
        pBuf = pList->pListInfo->pDspBuffer;		
        if( i == pList->pListInfo->dwCurLine )
		{	//如果要画的行是当前选择项,设置显示颜色
/****************GAOLINHUI,06-6-9,为了使空白的当前行不反显****************/
			if(*pBuf == 0x00)
			{
				bInvertCurrent = FALSE;
			}
/*******************************************************************/
            GraphSetTextColor( g_mListFace.dwHLItemTextColor );
        }
		else
		{
            GraphSetTextColor( g_mListFace.dwTextColor );
        }
		if((i == pList->pListInfo->dwCurLine) && (pList->pListInfo->uState & STA_EN_SCROLL))
		{	//如果当前处于滚动状态		
			GraphDrawText( uX, uY, uWidth, pList->byLineSpace, pBuf+pList->pListInfo->nBufOffset );    
		}
		else
		{	//否则直接从数据的起始位置显示
			GraphDrawText( uX, uY, uWidth, pList->byLineSpace, pBuf);    
		}
		//draw icon
		if(pList->byStyle & LIST_ICON)
		{
			//如果设置了画图标的样式,通过回调函数取位图数据
			if(pList->pListInfo->pfnListGetIconCallBack)
				pRes = pList->pListInfo->pfnListGetIconCallBack(i+pList->pListInfo->dwTopLine);
			if(pRes)
				GraphDrawIcon(uXIcon,uYIcon,LIST_ICON_WIDTH,pList->byLineSpace,pRes);
		}
        uY     += pList->byLineSpace;
		uYIcon += pList->byLineSpace;
    }

	//反显当前项并画行分割线
    uX = pList->pListInfo->nX0;
	uY = pList->pListInfo->nY0;
	uWidth = pList->pListInfo->wValidDspWidth;
    for( i = 0; i < pList->pListInfo->byPageLineNub; i ++ )
	{
		//invert the current Item.
		//2006.3.1加入当前项不反显状态判断
		if( (i == pList->pListInfo->dwCurLine) && !(pList->byStyle & LIST_NOHILT) )
		{		
/****************GAOLINHUI,06-6-9,为了使空白的当前行不反显****************/
			if(bInvertCurrent)
			{
				GraphInvertRect(uX,uY,uX+uWidth-1,uY+pList->byLineSpace-1 );
			}
			//GraphInvertRect(uX,uY,uX+uWidth-1,uY+pList->byLineSpace-1 );
/*************************************************************************/
		}
        uY += pList->byLineSpace;
        //draw separate line
        if( pList->byStyle & LIST_SPLINE )
		{
            GraphDrawLine( pList->uX, uY -1, pList->uX + pList->uWidth -1, uY -1 );
        }
    }

    GraphSetPenColor( dwPnColor );
    GraphSetBrushColor( dwBrushColor );
    GraphSetTextColor( dwTextColor );
	GraphEnableRefresh();
}


/****************************************************************************
	Function:
	UINT32 ListHandleEvent(APGUI_STRUCT_MODEL *pGui, UINT uEvent, UINT uParam)
    Description:
	List 控件消息处理函数
	input:
		pGui - 模板句柄
		uEvent - 消息类型
		uParam - 消息参数
	output:
		消息被处理返回非0值,否则返回0
	note:
  ****************************************************************************
	高林辉				2005-12-29				创建						
****************************************************************************/
UINT32 ListHandleEvent(APGUI_STRUCT_MODEL *pGui, UINT uEvent, UINT uParam)
{
    MList   *pList;
	UINT16	wIDScl,wIDWt;
	UINT16  wData;
	UINT8   *pBuf;
	UINT32  dwRet = 0;
	UINT    uKey;		//按键值


    pList = (MList *)pGui;
    switch( uEvent ){
#ifdef LIST_SUPPORT_PEN		//如果支持笔点功能
	case EVENT_PENDOWN:
	case EVENT_PENUP:
	case EVENT_PENMOVE:
		if(pList->pListInfo->uState & STA_LST_INITED)
		{	//LIST未初始化,不处理消息
			dwRet = __ListPenProc(pList, uEvent, uParam);
		}
		break;
#endif
    case EVENT_KEYREPEAT:
    case EVENT_KEY:
		if( !(pList->pListInfo->uState & STA_LST_INITED) )
		{	//LIST未初始化,不处理消息
			break;	
		}
		if (pList->pListInfo->dwTotalLine == 0) 
		{// 如果当前没有数据返回
            break;
        }
        uKey = READKB_VALUE(uParam);
        if( uKey == MVK_UP )
		{
            if( pList->pListInfo->dwCurLine > 0 )
			{ //如果不是当前页面的第一个行,将当前行设置为上一行
                pList->pListInfo->dwCurLine --;
            }
			else
			{	//否则,如果当前顶行行号不为0,顶行上翻一行
                if( pList->pListInfo->dwTopLine > 0 )
				{
                    pList->pListInfo->dwTopLine --;
                }
				else
				//否则,当前行是所有数据的第一行,返回
				{
					dwRet = 1;
                    break;
                }
            }
			g_mLstCmdEx.uType = CMEX_LST_SELECTCHANGED;
			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);
			_ListStopScroll(pList);	//停止滚动
            ListDraw( pList );		
			_ListChkForScroll(pList);	//判断新的当前项是否要设置滚动功能.
			dwRet = 1;

        }else if( uKey == MVK_DOWN )
		{
            if( pList->pListInfo->dwCurLine + pList->pListInfo->dwTopLine == pList->pListInfo->dwTotalLine - 1)
			{//如果已经是最后一行,返回
					dwRet = 1;
                    break;
            }
			else
			{
                if( pList->pListInfo->dwCurLine == (UINT32)(pList->pListInfo->byPageLineNub - 1) )
				{
                    pList->pListInfo->dwTopLine ++;
                }
				else
				{
                    pList->pListInfo->dwCurLine ++;
                }
            }
			g_mLstCmdEx.uType = CMEX_LST_SELECTCHANGED;
			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);
			_ListStopScroll(pList);
            ListDraw( pList );
			_ListChkForScroll(pList);
			dwRet = 1;
			

        }
		else if( uKey == MVK_PAGEUP )
		{
            if( pList->pListInfo->dwCurLine > 0 )
			{
                pList->pListInfo->dwCurLine = 0;
            }
			else
			{
                if( pList->pListInfo->dwTopLine >= pList->pListInfo->byPageLineNub )
				{
                    pList->pListInfo->dwTopLine -= pList->pListInfo->byPageLineNub;
                }
				else if( pList->pListInfo->dwTopLine >0 )
				{
                    pList->pListInfo->dwTopLine = 0;
                }
				else
				{
					dwRet = 1;
                    break;
                }
            }
			g_mLstCmdEx.uType = CMEX_LST_SELECTCHANGED;
			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);
			_ListStopScroll(pList);
            ListDraw( pList );

⌨️ 快捷键说明

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