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

📄 list.c

📁 好记星的控件,包括button,list,对文件操作
💻 C
📖 第 1 页 / 共 3 页
字号:
			_ListChkForScroll(pList);
			dwRet = 1;
        }
		else if( uKey == MVK_PAGEDOWN )
		{
            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 += pList->pListInfo->byPageLineNub;
                    if( pList->pListInfo->dwTopLine + pList->pListInfo->byPageLineNub > pList->pListInfo->dwTotalLine )
					{
                        pList->pListInfo->dwCurLine = pList->pListInfo->dwTotalLine - pList->pListInfo->dwTopLine - 1;
                    }
                }
				else
				{
                    if( pList->pListInfo->dwTopLine + pList->pListInfo->byPageLineNub > pList->pListInfo->dwTotalLine )
					{
                        pList->pListInfo->dwCurLine = pList->pListInfo->dwTotalLine - pList->pListInfo->dwTopLine - 1;
                    }
					else
					{
                        pList->pListInfo->dwCurLine = pList->pListInfo->byPageLineNub - 1;
                    }
                }
            }
			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_ENTER)
		{
			_ListStopScroll(pList);
			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);
			dwRet = 1;

        }
		else
		{
			break;
        }
        break;
    case EVENT_DRAW:
		if(pList->pListInfo->uState & STA_LST_INITED)
		{
			ListDraw( pList );
			_ListChkForScroll(pList);
			dwRet = 1;
		}
        break;
	case EVENT_TIMER:
		if(!(pList->pListInfo->uState & STA_LST_INITED) )
		{
			break;
		}
		wIDWt = LIST_WTTIMER_ID(pList);
		wIDScl = LIST_SCLTIMER_ID(pList);
		if(uParam == wIDWt)
		{	
			//如果是等待滚动的定时器消息
			LST_DESTROY_TIMER(pList->pListInfo->hWtTimer);
			pList->pListInfo->uState &= ~STA_EN_WTTIMER;
			//启动scroll定时器
			if(!pList->pListInfo->hSclTimer)
			{
				//创建滚动定时器
				pList->pListInfo->hSclTimer = TimerCreateTimer(wIDScl,LIST_SCLTIMER_SET);
			}
			//设置滚动的显示起始位置为buffer的起始位置
			pList->pListInfo->nBufOffset = 0;
			if(pList->pListInfo->hSclTimer)
			{					
				pList->pListInfo->uState |= STA_EN_SCLTIMER;
			}
			else
			{
				//定时器创建失败
				pList->pListInfo->uState &= ~STA_EN_SCLTIMER;
				pList->pListInfo->uState &= ~STA_EN_SCROLL;				
			}
			dwRet = 1;									
		}
		else if(wIDScl == uParam)		//如果是滚动定时器
		{	
			//先停止定时器
			TimerStopTimer(pList->pListInfo->hSclTimer);
			//取当前选择项的数据
			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;
			if(pList->pListInfo->nBufOffset >= (INT16)strlen(pBuf))
			{
				_ListStopScroll(pList);
				_ListChkForScroll(pList);
			}
			else
			{
				//计算宽度判断是否还需要滚动
				wData = pList->pListInfo->wValidDspWidth;
				if(wData >= FontGetStringWidth(pList->pListInfo->wFontLib,pBuf+pList->pListInfo->nBufOffset))
				{	
					//如果当前可显示的宽度已经大于数据的显示宽度				
					_ListStopScroll(pList);
					_ListChkForScroll(pList);				
				}
				else
				{
					if( *(pBuf+pList->pListInfo->nBufOffset) & 0X80 )
					{	//如果是汉字或自造字,
						pList->pListInfo->nBufOffset += 2;
					}
					else
					{	//如果是Ascii码
						pList->pListInfo->nBufOffset++;
					}
					TimerResetTimer(pList->pListInfo->hSclTimer,wIDScl,LIST_SCLTIMER_SET);
				}
			}
			ListDraw(pList);			
			dwRet = 1;
			
		}		
		break;
		
    case EVENT_INITIALIZE:
		{
			UINT16 wHeight,wWidth;
			//初始化结构
			memset(pList->pListInfo,0,sizeof(LIST_INFO));
			//初始化字库
			pList->pListInfo->wFontLib = FontGetLib();
			//检查LIST参数
			wHeight = FontGetHeight(pList->pListInfo->wFontLib);
			if(pList->byLineSpace < wHeight)
			{
				break;		//如果行间距小于字符的高度,初始化失败
			}
			if( (!pList->pDataBuff) && (!pList->pGetDataProgram) )
			{
				break;		//回调函数和固定数据指针同时为0,返回失败
			}
			//申请显示buffer
			if( (pList->pListInfo->pDspBuffer = MemAlloc(LIST_DISP_BUFF_LEN)) == NULL)
			{
				break;	
			}
			//计算一页得行数
			wHeight = pList->uHeight;
			if(pList->byStyle & LIST_BORDER)
			{
				wHeight -= 2;	//如果是有边框的方式,高度要减去上下边框2个象数
			}
			pList->pListInfo->byPageLineNub = wHeight / pList->byLineSpace;
			//计算可显示的区域宽度
			wWidth = pList->uWidth;
			if(pList->byStyle & LIST_BORDER)	//如果有边框,宽度减2
				wWidth -= 2;
			if(pList->byStyle & LIST_ICON)		//如果有图标,减去图标的宽度
				wWidth -= LIST_ICON_WIDTH;
			pList->pListInfo->wValidDspWidth = wWidth;
			//计算图标区域的x0,y0坐标
			pList->pListInfo->nIconX0 = pList->uX;
			pList->pListInfo->nIconY0 = pList->uY;
			//如果有边框
			if(pList->byStyle & LIST_BORDER)
			{
				pList->pListInfo->nIconX0 += 1;
				pList->pListInfo->nIconY0 += 1;
			}
			//计算文字的显示区域x0,y0坐标
			pList->pListInfo->nX0 = pList->pListInfo->nIconX0;
			pList->pListInfo->nY0 = pList->pListInfo->nIconY0;
			if(pList->byStyle & LIST_ICON)
			{
				pList->pListInfo->nX0 += LIST_ICON_WIDTH;
			}
			//设置已经初始化状态.
			pList->pListInfo->uState |= STA_LST_INITED;
			dwRet = 1;

		}
        break;
		
	case EVENT_DESTROY:
		//销毁显示buffer
		if(pList->pListInfo->pDspBuffer)
		{
			MemFree(pList->pListInfo->pDspBuffer);
			pList->pListInfo->pDspBuffer = NULL;
		}
		//销毁定时器
		if(pList->pListInfo->hSclTimer)
		{
			LST_DESTROY_TIMER(pList->pListInfo->hSclTimer);
		}
		if(pList->pListInfo->hWtTimer)
		{
			LST_DESTROY_TIMER(pList->pListInfo->hWtTimer);
		}
		dwRet = 1;
		break;

		
    }

    return dwRet;
}



/****************************************************************************
	Function:
	VOID		ListSetFaceParam(MListFace *pFace )
    Description:
	设置list的外观参数
	input:
	pFace  - 要设置的外观参数的结构指针
	output:

	note:
  ****************************************************************************
	高林辉				2005-12-28				创建						
****************************************************************************/
VOID		ListSetFaceParam(MListFace *pFace )
{
    memcpy( &g_mListFace, pFace, sizeof(MListFace) );
}


/****************************************************************************
	Function:
	UINT32      ListGetTotalLine(MList *pList)
    Description:
	取得当前的总行数
	input:
		pList - list 模板
	output:
		list总行数
	note:
  ****************************************************************************
	高林辉				2005-12-28				创建						
****************************************************************************/
UINT32      ListGetTotalLine(MList *pList)
{
    return pList->pListInfo->dwTotalLine;
}

/****************************************************************************
	Function:
	UINT32      ListSetTotalLine(MList *pList, UINT32 dwTotalLine)
    Description:
	设置总行数
	input:
		pList - list 模板
		dwTotalLine - 要设置的总行数
	output:
		返回设置前的总行数
	note:
  ****************************************************************************
	高林辉				2005-12-28				创建						
****************************************************************************/
UINT32      ListSetTotalLine(MList *pList, UINT32 dwTotalLine)
{
    UINT32  dwLine;

    dwLine = pList->pListInfo->dwTotalLine;
    pList->pListInfo->dwTotalLine = dwTotalLine;

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

    return dwLine;
}

/****************************************************************************
	Function:
	UINT32      ListGetCurrentLine(MList* pList)
    Description:
	得到当前选择项在当前页面的行号
	input:
		pList - list模板
	output:
		当前选择项行号
	note:
  ****************************************************************************
	高林辉				2005-12-28				创建						
****************************************************************************/
UINT32      ListGetCurrentLine(MList* pList)
{
    return pList->pListInfo->dwCurLine;
}

/****************************************************************************
	Function:
	UINT32      ListSetCurrentLine(MList* pList, UINT32 dwCurrentLine)
    Description:
	设置当前行
	input:
		pList - list模板
		dwCurrentLine - 要设置的当前行号
	output:
		设置前的当前行号
	note:
		当前行号是指在页面中的行号,不是在所有数据中的行号
  ****************************************************************************
	高林辉				2005-12-30				创建						
****************************************************************************/
UINT32      ListSetCurrentLine(MList* pList, UINT32 dwCurrentLine)
{
    UINT32  dwLine;

    if( dwCurrentLine >= pList->pListInfo->byPageLineNub )
	{
        pList->pListInfo->dwTopLine = dwCurrentLine - pList->pListInfo->byPageLineNub + 1;
        dwCurrentLine = pList->pListInfo->byPageLineNub - 1;
    }
    dwLine = pList->pListInfo->dwCurLine;
    pList->pListInfo->dwCurLine = dwCurrentLine;

    return dwLine;
}

/****************************************************************************
	Function:
	UINT32      ListGetTopLine(MList *pList)
    Description:
	取得顶行的行号
	input:
	PList - 模板指针
	output:
	顶行号

⌨️ 快捷键说明

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