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

📄 uiscroll.c

📁 嵌入工linux开发的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*********************************************************
FILE: scroll.c 
Basic Window Widget : ScrollBar
Copyright (c) 2001, Reality Technology CO. LTD.
AUTHOR: Cangers <gh_chan@sina.com>
HISTORY: >2001-10-16

**********************************************************/
#include <pr2k.h>
#include <uiwnd.h>
#include <uiGui_Cfg.h>
#include <typedefine.h>
#include <uiGraph.h>
#include <uiUtility.h>
#include <uicontrol.h>
#include <uiIcon_img.h>
#include <uiScroll.h> 

/*************************<<PRIVATE DEC>>**************************/
static STATUS _guiScroll_Show(HNDL handle);
static STATUS _guiScroll_Delete( HNDL handle );
static int _guiScroll_Paint(HNDL handle);
static int _Scroll_Update(HNDL handle);
static int _guiBar_Update(HNDL handle,WORD wFlag);
static int _guiScroll_GetRegion_type(HNDL handle , WORD wx , WORD wy);
static int _guiScroll_Action(HNDL handle , WORD Pen_Type, WORD x , WORD y);
static void _guiDeConvertXY(HNDL handle,int* x,int* y);
/*************************<<PUBLIC FUN>>****************************/
DLL_EXP(HNDL)  guiScroll_Create(WORD left, WORD top, WORD ext, WORD total, WORD page, WORD style)
{
	PTGUISCROLL ptScroll;
	/*tong
    if( left<0 ||  top<0  ) 
	return 0;
	*/
	
    guiEnterWCS() ;
	ptScroll = (PTGUISCROLL)kernelMalloc(sizeof(TGUISCROLL)+4);
    if(ptScroll == NULL)
    {
		guiExitWCS() ;
        return NULL;
	}
    memset(ptScroll,0,sizeof(TGUISCROLL));    
	
	ptScroll->base.handle =(HNDL)ptScroll;//handle is the pointer which point to this structure,identify the control
	ptScroll->base.checkFlag = GUI_CONTROL_CHECK_FLAG;//9296 this field would be a special value, it's able to check,the handle available or not
	ptScroll->base.left = left;
	ptScroll->base.top = top;
    
    if(!GUI_IS_3D)
        style &= ~SCROLL_3DMODE;
    if(!(style & SCROLL_HORIZONTAL) && !(style &SCROLL_SPIN))
    {
        ptScroll->base.right = ptScroll->base.left+_SCROLLBAR_WIDTH_-1;          
		ptScroll->base.bottom = ext;
    }
    else  if((style & SCROLL_HORIZONTAL) && !(style & SCROLL_SPIN))
    {
        ptScroll->base.right = ext;
		ptScroll->base.bottom = ptScroll->base.top+_SCROLLBAR_WIDTH_-1;
    }
    else  if(!(style & SCROLL_HORIZONTAL) && (style & SCROLL_SPIN))
    {
		ptScroll->base.right = ptScroll->base.left+_SCROLLBAR_WIDTH_-1;          
		ptScroll->base.bottom = ptScroll->base.top +_SCROLLBAR_WIDTH_*2-1;
    }
	else  if((style & SCROLL_HORIZONTAL) && (style & SCROLL_SPIN))
    {
        ptScroll->base.right = ptScroll->base.left + _SCROLLBAR_WIDTH_*2-1;          
		ptScroll->base.bottom = ptScroll->base.top + _SCROLLBAR_WIDTH_-1;
    }    
    else 
    {
		kernelFree(ptScroll);
		ptScroll = 0;
		guiExitWCS() ;
		return NULL;
    }	
	
    ptScroll->Bar_Max = 0;   
    ptScroll->Bar_Min = 0;
    ptScroll->current = 0;
    ptScroll->total=total;
    ptScroll->page= page;
    ptScroll->nOld_x = 0;
    ptScroll->nOld_y = 0 ;
	
    ptScroll->base.type = CONTROL_SCROLL;  // indicate the type of the control.
	
	ptScroll->base.style = style;
	ptScroll->base.status = 0;	//ACTIVE or not
	ptScroll->base.vportHandle = NULL;
    ptScroll->base.container = NULL;
    ptScroll->base.font = GUI_DEFAULT_FONT;
    guiExitWCS() ;
	
	ptScroll->base.actionFun =(PF_ACTION )_guiScroll_Action;
	ptScroll->base.showFun =(PF_SHOW)_guiScroll_Show;
	ptScroll->base.delFun =(PF_DELETE)_guiScroll_Delete;
	
    return (HNDL)ptScroll;
}

//=======================================================
static STATUS _guiScroll_Delete( HNDL handle )
{	
	PTGUISCROLL ptScroll;	
	
	if(handle == NULL)
    {        
		return STATUS_ERR;
    }
    guiEnterWCS() ;
	ptScroll=(PTGUISCROLL)handle;
	if(ptScroll->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
        guiExitWCS() ;
		return STATUS_ERR;
	}
	
	kernelFree((PTGUISCROLL)handle);
    handle = 0;
    guiExitWCS() ;
	
	return STATUS_OK;
}


//===========================================================
static STATUS _guiScroll_Show(HNDL handle)
{
	PTGUISCROLL ptScroll;   
    unsigned short left=0,right=0,top=0,bottom=0;
	
    if(handle == NULL)
    {       
		return STATUS_ERR; 
    }
    if(!guiControl_IsVisible(handle))
		return STATUS_ERR;
	
    guiEnterWCS() ;
    ptScroll=(PTGUISCROLL)handle;   
    if(ptScroll->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
        guiExitWCS() ;
		return STATUS_ERR;
	}
	
    left = 0;
    right = ptScroll->base.right - ptScroll->base.left;
    top = 0;
    bottom = ptScroll->base.bottom - ptScroll->base.top;
	
    _Scroll_Update( handle);     
    _guiBar_Update( handle,1);     
    _guiScroll_Paint( handle);
	
    guiExitWCS() ;
	return STATUS_OK;
}

//===========================================================
DLL_EXP(STATUS) guiScroll_Update(HNDL handle, WORD total, WORD page, WORD current)
{
	PTGUISCROLL ptScroll;
    
	if(handle == NULL)
	{       
        return STATUS_ERR;
    }
    
	guiEnterWCS();
	ptScroll=(PTGUISCROLL)handle;
    if(ptScroll->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {
		guiExitWCS();
        return STATUS_ERR;
    }
	/*tong   
    if(total<0 || current<0 || page<0)
    {
	guiExitWCS();
	return STATUS_ERR;
    }
	*/
    else if(total<=page)
		current = 0;
    else if(current>(total-1))
        current = (total-1);
    if(current == ptScroll->current 
        && ptScroll->total == total
        && ptScroll->page == page)
    {
		_guiScroll_Paint(handle);   
        guiExitWCS() ;
		return STATUS_OK;
    }
	ptScroll->total = total;
    ptScroll->page = page;
    ptScroll->current = current;
	
    _Scroll_Update( handle);     
    _guiBar_Update( handle,1);
    _guiScroll_Paint(handle);
	
    guiExitWCS() ;
	return STATUS_OK;
}

//===========================================================
DLL_EXP(STATUS) guiScroll_SetPos( HNDL handle ,WORD currentpos)
{
    PTGUISCROLL ptScroll;
    
	if(handle == NULL)
	{       
        return STATUS_ERR;
    }
	ptScroll=(PTGUISCROLL)handle;
	if(ptScroll->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
		return STATUS_ERR;   
	if(/*tong  currentpos<0 || */currentpos>= ptScroll->total) 	
		return STATUS_ERR;
    
    if(ptScroll->current != currentpos)
    {   
        ptScroll->current = currentpos; 
        _Scroll_Update( handle);     
        //_guiBar_Update( handle,1); 
		_guiBar_Update( handle,0);   // by zhangxp  2003/05/24 fix Press Key_Up can't return top
    }                 
    _guiScroll_Paint( handle);
	return STATUS_OK;
}

//==========================================================
DLL_EXP(short) guiScroll_GetPos( HNDL handle)
{
    PTGUISCROLL ptScroll;
    
	if(handle == NULL)
	{       
        return STATUS_ERR;
    }
	ptScroll=(PTGUISCROLL)handle;
    if(ptScroll->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
		return STATUS_ERR;    
    
	return ptScroll->current;
}

//==========================================================
DLL_EXP(STATUS) guiScroll_PageUp( HNDL handle )
{
    PTGUISCROLL ptScroll;
    
	if(handle == NULL)
	{       
        return STATUS_ERR;
    }
	ptScroll=(PTGUISCROLL)handle;
	if(ptScroll->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
		return STATUS_ERR; 
	if(ptScroll->current == 0)
        return 1; 
	if((ptScroll->current - ptScroll->page)>=0)
        ptScroll->current -=ptScroll->page;
	else
        ptScroll->current = 0; 
    ptScroll->base.showFun(handle);
    return STATUS_OK;
}

//===========================================================
DLL_EXP(STATUS) guiScroll_PageDown( HNDL handle )
{
    PTGUISCROLL ptScroll;
    
	if(handle == NULL)
	{       
        return STATUS_ERR;
    }
	ptScroll=(PTGUISCROLL)handle;
	if(ptScroll->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
		return STATUS_ERR; 
	if(ptScroll->current >=  ptScroll->total - ptScroll->page)
        return 1; 
	if(ptScroll->total<=ptScroll->page)
	{
		ptScroll->current = 0;               
	} 
	else
	{ 
		if((ptScroll->current + ptScroll->page)<(ptScroll->total-ptScroll->page))
			ptScroll->current += ptScroll->page; 
		else
			ptScroll->current = ptScroll->total-ptScroll->page; 
    } 
    ptScroll->base.showFun(handle);    
    return STATUS_OK;
}
/********************************PRIVATE FUN>>*********************/
static int _guiScroll_GetRegion_type(HNDL handle , WORD wx , WORD wy)
{
    PTGUISCROLL ptScroll;  
    WORD ntype;
	WORD x = wx ,y = wy;   
	
    if(handle == NULL)
    {        
		return STATUS_ERR; 
    }
    ptScroll=(PTGUISCROLL)handle;   
	if(ptScroll->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
		return STATUS_ERR;   
	
	if(!(ptScroll->base.style&SCROLL_HORIZONTAL))
	{
		if(y>=ptScroll->base.top&&y<=(ptScroll->base.top+_SCROLL_ICON_HEIGHT_-1))
			ntype = VSCROLL_LINE_UP;
		else if(y>=(ptScroll->base.bottom-_SCROLL_ICON_HEIGHT_+1)&&y<=ptScroll->base.bottom)
			ntype = VSCROLL_LINE_DOWN;
		else if(y>(ptScroll->base.top+_SCROLL_ICON_HEIGHT_-1)&&y<(ptScroll->Bar_Min+ptScroll->base.top))
		{
			if(!(ptScroll->base.style&SCROLL_SPIN))
				ntype = VSCROLL_PAGE_UP; 
		}
		else  if(y>(ptScroll->Bar_Max+ptScroll->base.top)&&y<(ptScroll->base.bottom-_SCROLL_ICON_HEIGHT_+1))
		{
			if(!(ptScroll->base.style&SCROLL_SPIN))
				ntype = VSCROLL_PAGE_DOWN;
		}
		else if(y>=(ptScroll->Bar_Min+ptScroll->base.top)&&y<=(ptScroll->Bar_Max+ptScroll->base.top))
		{
			if(!(ptScroll->base.style&SCROLL_SPIN))
				ntype = VSCROLL_MOVE;
		}
		else return -1;
	}
	else
	{
		if(x>=ptScroll->base.left&&x<=(ptScroll->base.left+_SCROLL_ICON_WIDTH_-1))
			ntype = HSCROLL_LINE_LEFT;
		else if(x>=(ptScroll->base.right-_SCROLL_ICON_WIDTH_+1)&&x<=ptScroll->base.right)
			ntype = HSCROLL_LINE_RIGHT;
		else if(x>(ptScroll->base.left+_SCROLL_ICON_WIDTH_-1)&&x<(ptScroll->Bar_Min+ptScroll->base.left))
		{
			if(!(ptScroll->base.style&SCROLL_SPIN))
				ntype = HSCROLL_PAGE_LEFT;
		} 
		else if(x>(ptScroll->base.left+ptScroll->Bar_Max)&&x<(ptScroll->base.right-_SCROLL_ICON_WIDTH_+1))
		{
			if(!(ptScroll->base.style&SCROLL_SPIN))
				ntype = HSCROLL_PAGE_RIGHT;
		}
		else if(x>=(ptScroll->Bar_Min+ptScroll->base.left)&&x<=(ptScroll->base.left+ptScroll->Bar_Max))

⌨️ 快捷键说明

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