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

📄 uislider.c

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

**********************************************************/

    #include <pr2k.h> 
    #include <uiwnd.h>

#include <typedefine.h>
#include <uicontrol.h>
#include <uiUtility.h>
#include <uiGraph.h>
#include <uiIcon_img.h>
#include <uiSlider.h>

/*************************<<PRIVATE DEC>>**************************/
static STATUS  _guiSlider_Delete( HNDL handle );
static STATUS  _guiSlider_Show(HNDL handle);
static int  _guiSlider_Update( DWORD handle);
static int  _guiSlider_Update2( DWORD handle);
static int  _guiSlider_Action(HNDL handle , WORD Pen_Type, WORD x , WORD y);
static int  _guiSlider_Paint( DWORD handle);
/*************************<<PUBLIC FUN>>****************************/
DLL_EXP(HNDL)   guiSlider_Create(WORD left, WORD top,WORD ext, int min, int max, int style)
{
	TGUISLIDER  *ptSlider;

/*tong
    if( left<0 ||  top<0) 
		return 0;
*/
    if(min<0 || max<0 || max<=min)
    {        
		return 0; 
    }
    guiEnterWCS() ;
	 ptSlider=(TGUISLIDER *)kernelMalloc(sizeof(TGUISLIDER));
    if( ptSlider == NULL)
    {
		guiExitWCS() ;
        return 0;
     }
    memset( ptSlider,0,sizeof(TGUISLIDER));    

    ptSlider->base.handle =(HNDL) ptSlider;//handle is the pointer which point to this structure,identify the control
	 ptSlider->base.checkFlag = GUI_CONTROL_CHECK_FLAG;//9296 this field would be a special value, it's able to check,the handle available or not
	 ptSlider->base.left = left;
	 ptSlider->base.top = top;	 
     ptSlider->min = min;
     ptSlider->max = max;
    
    if(!GUI_IS_3D)
        style &= ~SLIDER_3DMODE;
    if(!( style & SLIDER_VERTICAL))
    {
            ptSlider->base.bottom = top +  SLIDER_H_HEIGHT;
            ptSlider->base.right = ext;
    }
    else
    {
            ptSlider->base.bottom = ext;
            ptSlider->base.right =left +  SLIDER_V_WIDTH;
    }
    
     ptSlider->current = ptSlider->min;                                                                                        \
                                                             
	 ptSlider->base.type = CONTROL_SLIDER;  // indicate the type of the control.
	 ptSlider->base.style = style;
	 ptSlider->base.status = 0;	//ACTIVE or not
	 ptSlider->base.vportHandle = NULL;
     ptSlider->base.container = NULL;
     ptSlider->base.font = GUI_DEFAULT_FONT;

	 ptSlider->base.actionFun =(PF_ACTION )_guiSlider_Action;
	 ptSlider->base.showFun =(PF_SHOW) _guiSlider_Show;
	 ptSlider->base.delFun =(PF_DELETE) _guiSlider_Delete;
	 guiExitWCS() ;
     return (DWORD) ptSlider;
}

//===================================================================
static STATUS  _guiSlider_Delete( HNDL handle )
{
	TGUISLIDER *ptSlider;
     
	if(handle == NULL)
    {         
	    return STATUS_ERR;
    }
    guiEnterWCS() ;
	ptSlider=(TGUISLIDER *)handle;
    if(ptSlider->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {
       guiExitWCS() ;
       return STATUS_ERR;
    }
	kernelFree((TGUISLIDER *)handle);
    guiExitWCS() ;

	return STATUS_OK;
}

//========================================================================
static STATUS  _guiSlider_Show(HNDL handle)
{
	TGUISLIDER *ptSlider;   
        
    if(handle == NULL)
    {        
	    return STATUS_ERR; 
    }
    if(!guiControl_IsVisible(handle))
       return STATUS_ERR;
    guiEnterWCS() ;
    ptSlider=(TGUISLIDER *)handle; 
    if(ptSlider->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {
       guiExitWCS() ;
       return STATUS_ERR;
    }
    if( ptSlider->current<ptSlider->min|| ptSlider->current>ptSlider->max)
    {
        guiExitWCS() ;
	    return STATUS_ERR; 
    }      
    
    _guiSlider_Update(  handle);
    _guiSlider_Paint( handle);     

    guiExitWCS() ;
	return STATUS_OK;
}

//===============================================================================
 DLL_EXP(STATUS)  guiSlider_SetValue( HNDL handle, int current )
{
	TGUISLIDER  * ptSlider;
    
	if(handle == NULL)
	{       
        return STATUS_ERR;
    }
	ptSlider=(TGUISLIDER *)handle;     	
    if(ptSlider->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {       
       return STATUS_ERR;
    }
     
    if(current<ptSlider->min || current>ptSlider->max)
       return STATUS_ERR;
    ptSlider->current = current;
      
    ptSlider->base.showFun(handle);
	return STATUS_OK;
}

//=======================================================================
DLL_EXP(int)  guiSlider_GetValue( HNDL handle)
{
	TGUISLIDER  * ptSlider;
    
	if(handle == NULL)
	{       
        return STATUS_ERR;
    }
	 ptSlider=(TGUISLIDER *)handle;
     if(ptSlider->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {       
       return STATUS_ERR;
    }
	return ptSlider->current;
}

//=========================================================
DLL_EXP(STATUS) guiSlider_Reset( HNDL handle, WORD left, WORD top,WORD ext ,int min, int max,int current)
{
    TGUISLIDER  * ptSlider;     
    
	if(handle == NULL)
	{       
        return STATUS_ERR;
    }
	ptSlider=(TGUISLIDER *)handle;
    if(ptSlider->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {       
       return STATUS_ERR;
    }
     ptSlider->base.left = left;
	 ptSlider->base.top = top;	 
     ptSlider->min = min;
     ptSlider->max = max;
   
    if(!( ptSlider->base.style & SLIDER_VERTICAL))
    {
        ptSlider->base.bottom = top +  SLIDER_H_HEIGHT;
        ptSlider->base.right = ext;
    }
    else
    {
        ptSlider->base.bottom = ext;
        ptSlider->base.right =left +  SLIDER_V_WIDTH;
    }
    
    if(current>= ptSlider->min && current<=ptSlider->max)
        ptSlider->current = current;
    else
        ptSlider->current = 0;
     ptSlider->base.showFun(handle);
    return STATUS_OK;
}

/********************************PRIVATE FUN>>*********************/
static int  _guiSlider_Update( DWORD handle)
{
	TGUISLIDER  * ptSlider;
    unsigned short left=0,right=0,top=0,bottom=0;
    
	if(handle == NULL)
	{       
    return STATUS_ERR;
    }
	 ptSlider=(TGUISLIDER *)handle;
     if(ptSlider->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {       
       return STATUS_ERR;

⌨️ 快捷键说明

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