📄 uiprogress.c
字号:
/*********************************************************
FILE: progress.c
Basic Window Widget : progress
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 <uicontrol.h>
#include <uiUtility.h>
#include <uiGraph.h>
#include <uiProgress.h>
/*************************<<PRIVATE DEC>>**************************/
static int _guiProgressBar_Action(HNDL handle , WORD Pen_Type, WORD x , WORD y);
static STATUS _guiProgressBar_Delete( HNDL handle );
static STATUS _guiProgressBar_Show(HNDL handle);
/*************************<<PUBLIC FUN>>****************************/
DLL_EXP(HNDL) guiProgressBar_Create( WORD left, WORD top,WORD right, WORD bottom,int start, int end, int progress,WORD Style)
{
TGUIPRESSBAR *ptProgress;
if(right <= left || bottom <= top || (bottom - top)<6)
return 0;
if(start<0 || end<0 || end<=start || progress<start || progress>end)
{
return 0;
}
guiEnterWCS() ;
ptProgress=(TGUIPRESSBAR *)kernelMalloc(sizeof(TGUIPRESSBAR));
if(ptProgress == NULL)
{
guiExitWCS() ;
return 0;
}
memset(ptProgress,0,sizeof(TGUIPRESSBAR));
(ptProgress->base).handle =(HNDL)ptProgress;//handle is the pointer which point to this structure,identify the control
ptProgress->base.checkFlag = GUI_CONTROL_CHECK_FLAG;//9296 this field would be a special value, it's able to check,the handle available or not
ptProgress->base.left = left;
ptProgress->base.top = top;
ptProgress->base.right = right;
ptProgress->base.bottom = bottom;
ptProgress->base.font = GUI_DEFAULT_FONT;
ptProgress->start = start;
ptProgress->end = end;
ptProgress->progress = progress;
ptProgress->bColor=GUI_WHITE;
ptProgress->fColor= GUI_BLACK;
ptProgress->base.type = CONTROL_PROGRESS_BAR; // indicate the type of the control.
if(!GUI_IS_3D)
Style &= ~PROGRESS_3DMODE;
ptProgress->base.style = Style;
ptProgress->base.status = 0; //ACTIVE or not
ptProgress->base.vportHandle = NULL;
ptProgress->base.container = NULL;
ptProgress->base.actionFun =(PF_ACTION )_guiProgressBar_Action;
ptProgress->base.showFun =(PF_SHOW)_guiProgressBar_Show;
ptProgress->base.delFun =(PF_DELETE)_guiProgressBar_Delete;
guiExitWCS() ;
return (DWORD)ptProgress;
}
/*---------------------------------------------------------------------------------------------------------------*/
DLL_EXP(STATUS) guiProgressBar_Setup( HNDL handle,WORD start,WORD end,WORD progress )
{
TGUIPRESSBAR *ptProgress;
if(handle == NULL)
{
return STATUS_ERR;
}
if(end<start || progress<start || progress>end)
{
return STATUS_ERR;
}
ptProgress=(TGUIPRESSBAR *)handle;
if(ptProgress->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
return STATUS_ERR;
ptProgress->start = start;
ptProgress->end = end;
ptProgress->progress = progress;
ptProgress->base.showFun(handle);
return STATUS_OK;
}
/*--------------------------------------------------------------------------------------------------------------*/
DLL_EXP(STATUS) guiProgressBar_SetColor( HNDL handle, short bColor,short fColor)
{
TGUIPRESSBAR *ptProgress;
if(handle == NULL)
{
return STATUS_ERR;
}
ptProgress=(TGUIPRESSBAR *)handle;
if(ptProgress->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
return STATUS_ERR;
ptProgress->bColor=bColor;
ptProgress->fColor= fColor;
ptProgress->base.showFun(handle);
return STATUS_OK;
}
/*------------------------------------------------------------------------------------------------------------*/
static STATUS _guiProgressBar_Delete( HNDL handle )
{
TGUIPRESSBAR *ptProgress;
if(handle == NULL)
{
return STATUS_ERR;
}
guiEnterWCS() ;
ptProgress=(TGUIPRESSBAR *)handle;
if(ptProgress->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
{
guiExitWCS() ;
return STATUS_ERR;
}
kernelFree((TGUIPRESSBAR *)handle);
handle = 0;
guiExitWCS() ;
return STATUS_OK;
}
/*-----------------------------------------------------------------------------------------------------------*/
static STATUS _guiProgressBar_Show(HNDL handle)
{
TGUIPRESSBAR *ptProgress;
unsigned short left=0,right=0,top=0,bottom=0,wGap;
WORD progress;
if(handle == NULL)
{
return STATUS_ERR;
}
if(!guiControl_IsVisible(handle))
return STATUS_ERR;
guiEnterWCS() ;
ptProgress=(TGUIPRESSBAR *)handle;
if(ptProgress->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
{
guiExitWCS() ;
return STATUS_ERR;
}
if( ptProgress->progress<ptProgress->start || ptProgress->progress>ptProgress->end)
{
guiExitWCS() ;
return STATUS_ERR;
}
left = 0;
right = ptProgress->base.right-ptProgress->base.left;
top = 0;
bottom = ptProgress->base.bottom-ptProgress->base.top;
//tong 020808 progress =(WORD)(( (float)(right - left +1)/(ptProgress->end - ptProgress->start+1))*ptProgress->progress);
progress =(WORD)(( (float)(right - left +1)/(ptProgress->end - ptProgress->start))*ptProgress->progress);
if(PROGRESS_3DMODE & ptProgress->base.style)
{
guiClearBlock(handle, left,top,right,bottom,GUI_DARKGRAY,REPLACE_STYLE);
guiDrawLine ( handle, left,top,left,bottom,GUI_BLACK, GUI_SOLID );
guiDrawLine ( handle, left,top,right,top,GUI_BLACK, GUI_SOLID );
guiDrawLine ( handle, left,bottom,right,bottom,GUI_LIGHTGRAY, GUI_SOLID );
guiDrawLine ( handle, right,top,right,bottom,GUI_LIGHTGRAY, GUI_SOLID );
guiClearBlock(handle, left+1,top+2,right-1,bottom-2,GUI_LIGHTGRAY,REPLACE_STYLE);
if( progress>(right-left-3))
progress = right-left-3;
if(progress)
guiFillRect (handle, left+2,top+2, left+1+progress,bottom-2,GUI_BLACK,GUI_SOLID );
if(!(PROGRESS_NOGAP & ptProgress->base.style))
for(wGap = left+1;wGap<(left+1+progress);wGap += PROGRESS_GAP_PIXEL)
{
guiDrawLine ( handle,wGap, top+2, wGap, bottom-1,GUI_LIGHTGRAY, GUI_SOLID );
}
}
else
{
guiClearBlock(handle, left,top,right,bottom,ptProgress->bColor,REPLACE_STYLE);
guiDrawRect(handle, left,top,right,bottom,ptProgress->fColor,GUI_SOLID);
guiClearBlock(handle, left+1,top+2,right-1,bottom-2,ptProgress->bColor,REPLACE_STYLE);
if( progress>(right-left-3))
progress = right-left-3;
if(progress)
guiFillRect (handle, left+2,top+2, left+1+progress,bottom-2,ptProgress->fColor,GUI_SOLID );
if(!(PROGRESS_NOGAP & ptProgress->base.style))
for(wGap = left+1;wGap<(left+1+progress);wGap += PROGRESS_GAP_PIXEL)
{
guiDrawLine ( handle,wGap, top+2, wGap, bottom-1,ptProgress->bColor, GUI_SOLID );
}
}
guiExitWCS() ;
return STATUS_OK;
}
/*---------------------------------------------------------------------------------------------------------*/
DLL_EXP(STATUS) guiProgressBar_Update( HNDL handle, WORD progress )
{
TGUIPRESSBAR *ptProgress;
if(handle == NULL)
{
return STATUS_ERR;
}
ptProgress=(TGUIPRESSBAR *)handle;
if( ptProgress->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
return STATUS_ERR;
if(progress<ptProgress->start)
ptProgress->progress = ptProgress->start;
else if(progress>ptProgress->end)
ptProgress->progress = ptProgress->end;
ptProgress->progress = progress;
ptProgress->base.showFun(handle);
return STATUS_OK;
}
/********************************PRIVATE FUN>>*********************/
static int _guiProgressBar_Action(HNDL handle , WORD Pen_Type, WORD x , WORD y)
{
TGUIPRESSBAR *ptProgress;
TGuiMessage tMessage;
if(handle == NULL)
return STATUS_ERR;
ptProgress=(TGUIPRESSBAR *)handle;
if( ptProgress->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
return STATUS_ERR;
if( ptProgress->base.status & CONTROL_NOT_ACTIVE)
{
// guiExitWCS() ;
return STATUS_ERR;
}
tMessage.handle = handle;
tMessage.messageType=Pen_Type;
tMessage.x=x;
tMessage.y=y;
switch(Pen_Type)
{
case WIN_PEN_DOWN:
tMessage.elseInfo=WIN_PEN_DOWN;
break;
case WIN_PEN_UP:
tMessage.elseInfo=WIN_PEN_UP;
//guiEnqueue(gpTopWindow->messageQueue,&tMessage);
break;
case CTRL_SET_STYLE:
_guiProgressBar_Show( handle);
tMessage.elseInfo=CTRL_SET_STYLE;
break;
case CTRL_GET_FOCUS:
tMessage.elseInfo=CTRL_GET_FOCUS;
break;
case CTRL_DISABLE:
tMessage.elseInfo=CTRL_DISABLE;
break;
case CTRL_ENABLE:
tMessage.elseInfo=CTRL_ENABLE;
break;
default :
break;
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -