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

📄 uiselector.c

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

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

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

#include <typedefine.h>
#include <uiGui_cfg.h>
#include <uiGraph.h>
#include <stdio.h>
#include <stdlib.h>
#include <uiIcon_img.h>
#include <uiselector.h>

/*************************<<PRIVATE DEC>>**************************/

static int _guiSelector_Action(HNDL handle , WORD Pen_Type, WORD x , WORD y);
static int  _guiSelector_Paint( HNDL handle );
static STATUS   _guiSelector_Delete( HNDL handle );
static STATUS   _guiSelector_Show( HNDL handle );
/*************************<<PUBLIC FUN>>****************************/
DLL_EXP(HNDL)  guiSelector_Create( WORD left, WORD top, WORD right, WORD bottom,WORD Style ) 
{
	TGUISELECTOR  *ptSelector;
    DList *pDList;
	
	
    if(right <= left || bottom <= top) 
		return 0;
    guiEnterWCS() ;
	ptSelector=(TGUISELECTOR *)kernelMalloc(sizeof(TGUISELECTOR));
    if( ptSelector == NULL)
    {
		guiExitWCS() ;
        return 0;
	}
	pDList=DList_Create();
	guiExitWCS();
	if(pDList==NULL)
	{
		sc_free(ptSelector);
		return 0;
	}
    memset( ptSelector,0,sizeof(TGUISELECTOR));    
	
	( ptSelector->base).handle =(HNDL) ptSelector;//handle is the pointer which point to this structure,identify the control
	ptSelector->base.checkFlag = GUI_CONTROL_CHECK_FLAG;//9296 this field would be a special value, it's able to check,the handle available or not
	ptSelector->base.left = left;
	ptSelector->base.top = top;
	ptSelector->base.right = right;
	ptSelector->base.bottom = bottom;    
	ptSelector->base.type = CONTROL_SELECTOR;  // indicate the type of the control.
	
	if(!GUI_IS_3D)
        Style &= ~SELECTOR_3DMODE;
	ptSelector->base.style =  Style;
	ptSelector->base.status = 0;	//ACTIVE or not
	ptSelector->base.vportHandle = NULL;
	ptSelector->base.container = NULL;
	ptSelector->base.font = GUI_DEFAULT_FONT;
	ptSelector->m_ItemCount = 0;
	ptSelector->m_Selected = 0;
	ptSelector->m_Speed = 1;
	ptSelector->m_ItemList = pDList;    
	
	ptSelector->base.actionFun =(PF_ACTION )_guiSelector_Action;
	ptSelector->base.showFun =(PF_SHOW) _guiSelector_Show;
	ptSelector->base.delFun =(PF_DELETE) _guiSelector_Delete;
	
    return (DWORD) ptSelector;
}

//==========================================================
static STATUS   _guiSelector_Delete( HNDL handle )
{	
	TGUISELECTOR *ptSelector;
    
	if(handle == NULL)
    {        
		return STATUS_ERR;
    }
    guiEnterWCS() ;
	ptSelector=(TGUISELECTOR *)handle;
	
    if(ptSelector->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_ERR;
	} 
    if(ptSelector->m_ItemList)
        DList_Delete( ptSelector->m_ItemList ) ;
    ptSelector->m_ItemList = 0;
	kernelFree((TGUISELECTOR *)handle);
    handle =0;
    guiExitWCS() ;
	
	return STATUS_OK;
}

//==========================================================
static STATUS   _guiSelector_Show( HNDL handle )
{	
    TGUISELECTOR *ptSelector;
	
    if(handle == NULL)
    {       
		return STATUS_ERR; 
    }
    guiEnterWCS();
	ptSelector=(TGUISELECTOR *)handle;
	if(ptSelector->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_ERR;
	}
	_guiSelector_Paint(handle);	
	guiExitWCS();
	return STATUS_OK;   
}

//=========================================================
DLL_EXP(STATUS)   guiSelector_AddItem( HNDL handle, const char *string)
{
	TGUISELECTOR  * ptSelector;
	
	if(handle == NULL)
	{       
        return STATUS_ERR;
    }
    guiEnterWCS() ;
	ptSelector=(TGUISELECTOR *)handle;
    
	guiSelector_InsertItem(handle,ptSelector->m_ItemCount,string);
	
    guiExitWCS() ;
	
	return STATUS_OK;
}

//==========================================================
DLL_EXP(STATUS)   guiSelector_InsertItem( HNDL handle, WORD index, const char *string)
{
    TGUISELECTOR  * ptSelector;
    TGUISELECTOR_ITEM *pItem;
    
    if(handle == NULL)
    {      
        return STATUS_ERR;
    }
    guiEnterWCS() ;
    ptSelector=(TGUISELECTOR *)handle;
    
    pItem=(TGUISELECTOR_ITEM *)kernelMalloc(sizeof( TGUISELECTOR_ITEM));
    if(pItem==NULL)
    {
        guiExitWCS();
        return STATUS_ERR;
    }
    memset(pItem,0,sizeof( TGUISELECTOR_ITEM));
    if(string==NULL )
    {
        kernelFree(pItem);
        guiExitWCS();
        return STATUS_ERR;
    }
    strncpy(pItem->m_Caption,string,GUI_SELECT_ITEM_LENGTH);
	
    if(index>=ptSelector->m_ItemCount && index!=0)
    {
        DList_Append(ptSelector->m_ItemList,pItem);
    }
    else
    {
        DList_Insert(ptSelector->m_ItemList,index,pItem);
    }
	ptSelector->m_ItemCount++;   
    _guiSelector_Paint( handle );
    guiExitWCS();
    return STATUS_OK;
}

//==========================================================
DLL_EXP(STATUS)   guiSelector_RemoveItem( HNDL handle, WORD index)
{
	void * pItem;
	TGUISELECTOR  * ptSelector;
	
	
	if(handle==NULL)
		return STATUS_ERR;
	guiEnterWCS();
	ptSelector=(TGUISELECTOR *)handle;
	
	if(ptSelector->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_ERR;
	}
	
	if(index>=ptSelector->m_ItemCount)
	{
		guiExitWCS();
		return STATUS_ERR;
	}
	
	pItem=DList_Remove(ptSelector->m_ItemList,index);
	ptSelector->m_ItemCount--;
	if(ptSelector->m_Selected>=ptSelector->m_ItemCount && ptSelector->m_ItemCount>0)
		ptSelector->m_Selected = ptSelector->m_ItemCount-1;
	else if(ptSelector->m_Selected<0 && ptSelector->m_ItemCount>0)	  
		ptSelector->m_Selected=0;
	
	kernelFree(pItem);
	_guiSelector_Paint( handle );
	guiExitWCS();
	return STATUS_OK;	
}

//==========================================================
DLL_EXP(char*)      guiSelector_GetItem( HNDL handle, WORD index)
{
	TGUISELECTOR  * ptSelector;
    TGUISELECTOR_ITEM *PItem;
	
	if(handle == NULL )
		return NULL;
    guiEnterWCS();
    ptSelector=(TGUISELECTOR *)handle;
    
    if(ptSelector->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {
        guiExitWCS();
        return NULL;
    }
	if(index>=ptSelector->m_ItemCount/*tong || index<0*/)
	{
        guiExitWCS();
        return NULL;
    }    
	PItem =   (TGUISELECTOR_ITEM*)DList_GetObject(  ptSelector->m_ItemList, index ) ; 
	guiExitWCS();
    return PItem->m_Caption;
}

//==========================================================
DLL_EXP(short)   guiSelector_GetIndex( HNDL handle )
{
	TGUISELECTOR  * ptSelector;
	
	if(handle == NULL )
		return STATUS_ERR;
	guiEnterWCS();
	ptSelector=(TGUISELECTOR *)handle;
	
	if(ptSelector->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_ERR;
    }
    guiExitWCS();
    if(ptSelector->m_ItemCount==0)
    {
    	return -1;
    }
    
	return  ptSelector->m_Selected;
}

//==========================================================
DLL_EXP(STATUS)   guiSelector_SetIndex( HNDL handle, WORD index)
{
	TGUISELECTOR  * ptSelector;
	
    if(handle == NULL )
		return STATUS_ERR;
    guiEnterWCS();
	ptSelector=(TGUISELECTOR *)handle;
    
    if(ptSelector->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {
        guiExitWCS();
        return STATUS_ERR;
    }
    if(index>=ptSelector->m_ItemCount )
    {
        guiExitWCS();
        return STATUS_ERR;
    } 
	
	ptSelector->m_Selected = index;
	guiExitWCS();
	_guiSelector_Paint( handle );
	return  STATUS_OK;
} 


//======================================================
DLL_EXP(STATUS)	  guiSelector_GetItemCount(HNDL handle,int *pCount)
{
	TGUISELECTOR  * ptSelector;
	
    if(handle == NULL )
		return STATUS_ERR;
    guiEnterWCS();
	ptSelector=(TGUISELECTOR *)handle;
    
    if(ptSelector->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {
        guiExitWCS();
        return STATUS_ERR;
    }
    
    *pCount=ptSelector->m_ItemCount;
    
    return STATUS_OK;
    
}


//======================================================
DLL_EXP(STATUS)   guiSelector_Setup( HNDL handle,int min,int max,int current )
{
	TGUISELECTOR  * ptSelector;
    int i;
    char szStr[GUI_SELECT_ITEM_LENGTH+1];
    
    if(handle == NULL )
		return STATUS_ERR;
    guiEnterWCS();
	ptSelector=(TGUISELECTOR *)handle;
	if(!(ptSelector->base.style&SELECTOR_NUMBER))    
    {
        guiExitWCS() ;
		return STATUS_ERR;
    }
    if(ptSelector->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {
        guiExitWCS();
        return STATUS_ERR;
    }
    if(min>max || (current>max || current<min))
    {
        guiExitWCS();
        return STATUS_ERR;
    }
    for(i=min;i<=max;i++)
    {
        strcpy(szStr,"");
        sprintf(szStr,"%d",i);
        guiSelector_AddItem(  handle, szStr);
    }
    guiSelector_SetIndex(  handle, current - min);
    guiExitWCS();
    return STATUS_OK;
}

//==========================================================
DLL_EXP(STATUS)   guiSelector_GetValue( HNDL handle,int *piVal_Num )
{
	TGUISELECTOR  * ptSelector;    
    short current;   
    
    if(handle == NULL )
		return STATUS_ERR;
    guiEnterWCS();
    ptSelector=(TGUISELECTOR *)handle;
    if(!(ptSelector->base.style&SELECTOR_NUMBER))    
    {
        guiExitWCS() ;
        return STATUS_ERR;
    }
    if(ptSelector->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {
        guiExitWCS();
        return STATUS_ERR;
    }
	
	current = guiSelector_GetIndex(  handle );
	*piVal_Num = atoi(guiSelector_GetItem(  handle, current));
    
	guiExitWCS();
	return STATUS_OK;
}

//==========================================================
DLL_EXP(STATUS)   guiSelector_SetSpeed( HNDL handle,WORD  nSpeed)
{
	TGUISELECTOR  * ptSelector;       
    
    if(handle == NULL )
		return STATUS_ERR;
    guiEnterWCS();
    ptSelector=(TGUISELECTOR *)handle;
	
    if(ptSelector->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
    {
        guiExitWCS();
        return STATUS_ERR;
    }
    if(nSpeed<=1)
    {
        guiExitWCS();
        return STATUS_ERR;
    }   

⌨️ 快捷键说明

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