📄 uilabel.c
字号:
/*********************************************************************/
// 文 件 名: uiLabel.cpp
// 程序说明: Label控件
// 程序设计: 产革宏
// 2001.10.19 设计完成 说明文档:R004-S201-0001
// 程序审查: 宋军霞
// 2002.01.22 审查完成 说明文档:R004-S201-0001
// 项目编号: R004-S201
// 版 本: V1.0
// 版 权: Reality Plus Technology (ShenZhen) Co.,Ltd.
/*********************************************************************/
#include <pr2k.h>
#include <uiwnd.h>
#include <typedefine.h>
#include <uicontrol.h>
#include <uiUtility.h>
#include <uiGraph.h>
#include <uiLabel.h>
#include <uiSound.h>
#define LABEL_BORDER 0x0003
#define LABEL_ALIGN 0x000c
/*************************<<PRIVATE DEC>>**************************/
static void _guiLabel_Action(HNDL handle , WORD Pen_Type, WORD x , WORD y);
static STATUS _guiLabel_Delete( HNDL handle );
static STATUS _guiLabel_Show( HNDL handle );
/*************************<<PUBLIC FUN>>****************************/
DLL_EXP(HNDL) guiLabel_Create( WORD left, WORD top,WORD right, WORD bottom,const char* caption, WORD style)
{
TGuiLabel *ptLabel;
guiEnterWCS() ;
ptLabel=(TGuiLabel *)kernelMalloc(sizeof(TGuiLabel));
if(ptLabel == NULL)
{
guiExitWCS() ;
return NULL;
}
ptLabel->base.handle =(HNDL)ptLabel;//handle is the pointer which point to this structure,identify the control
ptLabel->base.type = CONTROL_LABEL; // indicate the type of the control.
ptLabel->base.left = left;
ptLabel->base.top = top;
ptLabel->base.right = right;
ptLabel->base.bottom = bottom;
ptLabel->base.checkFlag = GUI_CONTROL_CHECK_FLAG;//9296 this field would be a special value, it's able to check,the handle available or not
ptLabel->base.style = style;
ptLabel->base.status = 0; //ACTIVE and Visable
ptLabel->base.font = GUI_DEFAULT_FONT;
ptLabel->base.vportHandle = NULL;
ptLabel->base.container = NULL;
ptLabel->base.actionFun =(PF_ACTION )_guiLabel_Action;
ptLabel->base.showFun =(PF_SHOW)_guiLabel_Show;
ptLabel->base.delFun =(PF_DELETE)_guiLabel_Delete;
ptLabel->fontColor= GUI_BLACK;
ptLabel->backColor= GUI_WHITE;
if(caption == NULL)
strcpy((char *)ptLabel->caption,"");
else
{
strncpy((char *)ptLabel->caption,(const char *)caption,GUI_LABEL_CAPTION_SIZE);
ptLabel->caption[GUI_LABEL_CAPTION_SIZE]='\0';
}
guiExitWCS() ;
return (HNDL)ptLabel;
}
/*---------------------------------------------------------------------------------------*/
DLL_EXP(STATUS) guiLabel_SetCaption ( HNDL handle,const char *caption )
{
TGuiLabel *ptLabel;
guiEnterWCS() ;
if(handle == NULL)
{
guiExitWCS() ;
return STATUS_ERR;
}
ptLabel=(TGuiLabel *)handle;
if(ptLabel->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
{
guiExitWCS() ;
return STATUS_ERR;
}
if(caption == NULL)
strcpy((char *)ptLabel->caption,"");
else
{
strncpy(ptLabel->caption,(const char *)caption,GUI_LABEL_CAPTION_SIZE);
ptLabel->caption[GUI_LABEL_CAPTION_SIZE]='\0';
}
_guiLabel_Show(handle);
guiExitWCS();
return STATUS_OK;
}
/*------------------------------------------------------------------------------------*/
DLL_EXP(char*) guiLabel_GetCaption ( HNDL handle )
{
TGuiLabel *ptLabel;
if(handle == NULL )
return NULL;
ptLabel=(TGuiLabel *)handle;
if(ptLabel->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
return NULL;
return ptLabel->caption;
}
/*------------------------------------------------------------------------------------*/
static STATUS _guiLabel_Delete( HNDL handle )
{
TGuiLabel *ptLabel;
guiEnterWCS() ;
if(handle == NULL )
{
guiExitWCS() ;
return STATUS_ERR;
}
ptLabel=(TGuiLabel *)handle;
if(ptLabel->base.checkFlag != GUI_CONTROL_CHECK_FLAG )
{
guiExitWCS() ;
return STATUS_ERR;
}
kernelFree((TGuiLabel *)handle);
ptLabel->base.checkFlag = 0;
handle = NULL;
guiExitWCS() ;
return STATUS_OK;
}
/*-------------------------------------------------------------------------------*/
static STATUS _guiLabel_Show(HNDL handle)
{
TGuiLabel *ptLabel;
WORD style;
short x,y;
short sHeigth,sWidth;
short left,right,top,bottom;
short offset;
if(handle == NULL)
return STATUS_ERR;
guiEnterWCS() ;
if(guiControl_IsVisible(handle) == FALSE)
{
guiExitWCS() ;
return STATUS_ERR;
}
ptLabel=(TGuiLabel *)handle;
if(ptLabel->base.checkFlag!=GUI_CONTROL_CHECK_FLAG)
{
guiExitWCS() ;
return STATUS_ERR;
}
left = 0;
right = ptLabel->base.right-ptLabel->base.left;
top = 0;
bottom = ptLabel->base.bottom-ptLabel->base.top;
style = ptLabel->base.style;
guiClearBlock(handle,left,top,right,bottom,ptLabel->backColor,0);
guiPushFont(ptLabel->base.font) ;
sWidth = guiGetStringWidth((char *)ptLabel->caption) ;
sHeigth = guiGetCharHeight();
offset=2;
switch( style & LABEL_BORDER)//BORDER STYLE
{
case LABEL_BORDER_SOLID:
guiDrawRect(handle,left,top,right,bottom,ptLabel->fontColor,GUI_SOLID);
break;
case LABEL_BORDER_HATCH:
guiDrawRect(handle,left,top,right,bottom,ptLabel->fontColor,GUI_HATCH);
break;
default:
offset=0;
break;
}
y = getAlignCenter(0,bottom,sHeigth);
switch(style & LABEL_ALIGN)//TEXT ALIGNMENT STYLE
{
case LABEL_ALIGN_CENTER:
x = getAlignCenter(offset,right-offset,sWidth);
guiShowString(handle,(char *)ptLabel->caption,x,y,ptLabel->fontColor,0);
break;
case LABEL_ALIGN_RIGHT:
x = getAlignRight(offset,right-offset,sWidth);
guiShowString(handle,(char *)ptLabel->caption,x, y,ptLabel->fontColor,0);
break;
default:
x = offset;
guiShowString(handle,(char *)ptLabel->caption,x,y ,ptLabel->fontColor,0);
break;
}
guiPopFont();
guiExitWCS() ;
return STATUS_OK;
}
/********************************PRIVATE FUN>>*********************/
static void _guiLabel_Action(HNDL handle , WORD Pen_Type, WORD x , WORD y)
{
TGuiLabel *ptLabel;
TGuiMessage tMessage;
if(handle == NULL)
return;
ptLabel=(TGuiLabel *)handle;
if( ptLabel->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
return;
if( ptLabel->base.status & CONTROL_NOT_ACTIVE)
return;
if(Pen_Type == PENUP)
{
_guiLabel_Show(handle);
tMessage.handle = handle;
tMessage.messageType=LABEL_CLICK;
tMessage.x=x;
tMessage.y=y;
guiEnqueue(gpTopWindow->messageQueue,&tMessage);
guiPenSound();
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -