📄 uiinfo_box.c
字号:
#include <uiwnd.h>
#include <battery.h>
#include <stdio.h>
extern int gLanguage;
extern TGuiWindow *gpTopWindow;//Kevin, for low battery message
WORD battery=VOLT_LEVEL4, BatteryMessage=1;//Kevin, 2003/6/9
void InfoBox_GetBatt( void )
{
unsigned short Temp;
TGuiMessage msgTemp;
#ifdef __WIN32__
battery = 5;
#else
if ( (Temp = GetVoltLevel()) != VOLT_NODETECT )
{
battery = Temp;
#ifndef PR2001B
if ( !getONCradleStatus() )
{
if(BatteryMessage)
{
if ( battery == VOLT_LEVEL0 )
{
msgTemp.handle=(HNDL)gpTopWindow; // notice thread to process interface
msgTemp.messageType=SYS_MESSAGE_LOWBATTERY;
msgTemp.x = VOLT_LEVEL0;
_guiEnqueue(gpTopWindow->messageQueue, &msgTemp);
BatteryMessage = 0;
}
}
if ( battery == DANGER_LEVEL )
{
msgTemp.handle=(HNDL)gpTopWindow; // notice thread to process interface
msgTemp.messageType=SYS_MESSAGE_LOWBATTERY;
msgTemp.x = DANGER_LEVEL;
_guiEnqueue(gpTopWindow->messageQueue, &msgTemp);
}
}
#endif
}
#endif
}
void InfoBox_Show(struct tagGuiSysInfoBox *pControl)
{
int i,mode=GUI_SOLID,X_Pos,Y_Pos,height,dis_battery;
char buf1[11],buf2[5];
WORD temp_hour,lunar_month,lunar_day,week_day,Back_Color,Front_Color;
WORD Class,left=0,top=0,right=pControl->base.right-pControl->base.left,bottom=pControl->base.bottom-pControl->base.top;
WORD temp_width;
HNDL handle=(HNDL)pControl;
sysTime now ;
char *str_runyue[3] = {"Runyue","秥る","闰月"};
memset(buf1,0,11);
memset(buf2,0,5);
if(pControl->Dis_Normal_Invert == SYSINFO_NORMAL_DISPLAY)
{
Back_Color=GUI_WHITE;
Front_Color=GUI_BLACK;
}
else
{
Back_Color=GUI_BLACK;
Front_Color=GUI_WHITE;
}
sc_getTime(&now);
Class=pControl->Cur_Class;
guiClearBlock(handle,left,top,right,bottom,Back_Color,REPLACE_STYLE);
if(pControl->base.style & GUI_RUNTIME_HATCH || pControl->base.style & GUI_RUNTIME_BORDER)
{
if(pControl->base.style & GUI_RUNTIME_HATCH)
mode=GUI_HATCH;
else
mode=GUI_SOLID;
guiDrawLine(handle,left,top,right,top,Front_Color,mode);
guiDrawLine(handle,left,bottom,right,bottom,Front_Color,mode);
guiDrawLine(handle,left,top,left,bottom,Front_Color,mode);
guiDrawLine(handle,right,top,right,bottom,Front_Color,mode);
}
guiPushFont(pControl->base.font) ;
if(Class == GUI_RUNTIME_NON_CLOCK)
{
temp_hour=now.hour;
if(temp_hour > 12)
temp_hour-=12;
sprintf(buf2,"%d",temp_hour);
if(temp_hour > 9)
strcpy(buf1,buf2);
else
{
strcpy(buf1,"0");
strcat(buf1,buf2);
}
strcat(buf1,":");
sprintf(buf2,"%d",now.minute);
if(now.minute > 9)
strcat(buf1,buf2);
else
{
strcat(buf1,"0");
strcat(buf1,buf2);
}
memset(buf2,'\0',5);
if(now.hour < 12)
strcat(buf2,"AM");
else
strcat(buf2,"PM");
temp_width=guiGetStringWidth(buf1)+guiGetStringWidth(buf2)+2;
X_Pos=getAlignCenter(left+1, right-1,temp_width);
Y_Pos=getAlignCenter(top+1, bottom-1,guiGetCharHeight());
guiShowString(handle,(char *)buf1,X_Pos,Y_Pos,Back_Color<<8 | Front_Color,FONT_TRANSPARENT);
guiShowString(handle,(char *)buf2,X_Pos+guiGetStringWidth(buf1)+2,Y_Pos,Back_Color<<8 | Front_Color,FONT_TRANSPARENT);
}
else if(Class == GUI_RUNTIME_NON_SOLAR_DAY)
{
// by zhang xue ping
//sprintf(buf2,"%d",(now.year+1990));
sprintf(buf2,"%d",(now.year));
//strcpy(buf1,"01");
strcpy(buf1,buf2);
strcat(buf1,".");
sprintf(buf2,"%d",now.month);
if(now.month > 9)
strcat(buf1,buf2);
else
{
strcat(buf1,"0");
strcat(buf1,buf2);
}
strcat(buf1,".");
sprintf(buf2,"%d",now.day);
if(now.day > 9)
strcat(buf1,buf2);
else
{
strcat(buf1,"0");
strcat(buf1,buf2);
}
X_Pos=getAlignCenter(left+1, right-1,guiGetStringWidth(buf1));
Y_Pos=getAlignCenter(top+1, bottom-1,guiGetCharHeight());
guiShowString(handle,(char *)buf1,X_Pos,Y_Pos,Back_Color<<8 | Front_Color,FONT_TRANSPARENT);
}
else if(Class == GUI_RUNTIME_NON_LUNAR_DAY)
{
// by zhang xue ping
//guiCalendar_GetNongli((now.year+1990),now.month,now.day, &lunar_month,&lunar_day);
guiCalendar_GetNongli((now.year),now.month,now.day, &lunar_month,&lunar_day);
//当lunar_month的值是大于12的时候,表示该月为闰月__CaoJM 03.08.26
if(lunar_month>12)
{
strcpy(buf1,str_runyue[gLanguage]);}
else
{
strcpy(buf1,RES_STR_MONTH[gLanguage][lunar_month-1]);
}
if(lunar_day < 11 )
{
strcat(buf1,RES_STR_DAY[gLanguage][10]);
strcat(buf1,RES_STR_DAY[gLanguage][lunar_day-1]);
}
else if(lunar_day < 20)
{
strcat(buf1,RES_STR_DAY[gLanguage][9]);
strcat(buf1,RES_STR_DAY[gLanguage][lunar_day%10-1]);
}
else if(lunar_day == 20)
{
strcat(buf1,RES_STR_DAY[gLanguage][1]);
strcat(buf1,RES_STR_DAY[gLanguage][9]);
}
else if(lunar_day < 30)
{
strcat(buf1,RES_STR_DAY[gLanguage][11]);
strcat(buf1,RES_STR_DAY[gLanguage][lunar_day%20-1]);
}
else if(lunar_day == 30)
{
strcat(buf1,RES_STR_DAY[gLanguage][2]);
strcat(buf1,RES_STR_DAY[gLanguage][9]);
}
height=(guiGetWordHeight() > guiGetCharHeight())?guiGetWordHeight():guiGetCharHeight();
X_Pos=getAlignCenter(left+1, right-1,guiGetStringWidth(buf1));
Y_Pos=getAlignCenter(top+1, bottom-1,height);
guiShowString(handle,(char *)buf1,X_Pos,Y_Pos,Back_Color<<8 | Front_Color,FONT_TRANSPARENT);
}
else if(Class == GUI_RUNTIME_NON_WEEK)
{
// by zhang xue ping
//week_day=guiCalendar_GetWeek((now.year+1990), now.month, now.day);
week_day=guiCalendar_GetWeek((now.year), now.month, now.day);
strcpy(buf1, RES_STR_WEEKWORD[gLanguage]); //"星期"
strcat(buf1,(char *)RES_STR_WEEK[gLanguage][week_day]);
X_Pos=getAlignCenter(left+1, right-1,guiGetStringWidth(buf1));
Y_Pos=getAlignCenter(top+1, bottom-1,guiGetCharHeight());
guiShowString(handle,(char *)buf1,X_Pos,Y_Pos,Back_Color<<8 | Front_Color,FONT_TRANSPARENT);
}
else if(Class == GUI_RUNTIME_NON_BATTERY_REMAIN)
{
if((battery!=VOLT_NODETECT)&&((battery<=VOLT_LEVEL4)||(battery==DANGER_LEVEL)))
{
if ( battery == DANGER_LEVEL )
dis_battery = VOLT_LEVEL0-1;
else
dis_battery = battery-1;
/*
dis_battery=(battery / 3.0)*100-25;
if(dis_battery <= 0)
dis_battery =0;
else
{
dis_battery/=25;
dis_battery+=1;
}
*/
// by zhang xue ping 2002/09/27
X_Pos=getAlignCenter(left+1, right-1,guiGetImageWidth((BYTE *)icon_Gui_Battery));
Y_Pos=getAlignCenter(top+1, bottom-1,guiGetImageHeight((BYTE *)icon_Gui_Battery));
guiPutImage(handle,X_Pos,Y_Pos,X_Pos+guiGetImageWidth((BYTE *)icon_Gui_Battery),Y_Pos+guiGetImageHeight((BYTE *)icon_Gui_Battery),(BYTE *)icon_Gui_Battery);
for(i=0;i<dis_battery;i++)
guiPutImage(handle,X_Pos+6+i*(guiGetImageWidth((BYTE *)icon_Gui_Battery_Hole)+2),Y_Pos+2,X_Pos+6+(i+1)*(guiGetImageWidth((BYTE *)icon_Gui_Battery_Hole)+2),Y_Pos+2+guiGetImageHeight((BYTE *)icon_Gui_Battery_Hole),(BYTE *)icon_Gui_Battery_Hole);
}
}
guiPopFont();
}
void InfoBox_Action(HNDL handle,WORD Pen_Message,WORD x,WORD y)
{
int i,j,flag=0;
WORD Class,New_Class,Old_Class;
struct tagGuiSysInfoBox *pControl;
struct tagGuiMessage message;
guiEnterWCS();
pControl=(struct tagGuiSysInfoBox *)handle;
if(pControl->base.checkFlag != GUI_CONTROL_CHECK_FLAG && pControl->base.status & CONTROL_NOT_ACTIVE)
{
guiExitWCS();
return;
}
if(Pen_Message == PENUP)
{
guiPenSound();
//InfoBox_Show(pControl); //11.16 hide
for(i=0;i<GUI_RUNTIME_MAX_STYLE_NO;i++)
{
Class= (pControl->base.style >> i) & 0x01;
if(!Class)
{
Old_Class= 0x01 << i;
if(Old_Class == pControl->Cur_Class)
break;
}
}
for(j=i+1;j<GUI_RUNTIME_MAX_STYLE_NO;j++)
{
Class= (pControl->base.style >> j) & 0x01;
if(!Class)
{
New_Class= 0x01 << j;
pControl->Cur_Class=New_Class;
flag=1;
break;
}
}
if(flag==0)
{
for(i=0;i<GUI_RUNTIME_MAX_STYLE_NO;i++)
{
Class= (pControl->base.style >> i) & 0x01;
if(!Class)
{
New_Class= 0x01 << i;
pControl->Cur_Class=New_Class;
break;
}
}
}
pControl->Dis_Normal_Invert=SYSINFO_NORMAL_DISPLAY;
InfoBox_Show(pControl);
}
else if(Pen_Message == PENDOWN)
{
if(pControl->base.style & 0x80)
pControl->Dis_Normal_Invert=SYSINFO_INVERT_DISPLAY;
InfoBox_Show(pControl);
}
else if(Pen_Message >= PENMOVE)
{
if(Pen_Message == PENROVE)
{
pControl->Dis_Normal_Invert=SYSINFO_NORMAL_DISPLAY;
InfoBox_Show(pControl);
}
}
guiExitWCS();
}
/*********************************************************************/
//para: info box coordinate and style
//dest: create handle
//return:
//fail: NULL
//sucess: return info box handle
/*********************************************************************/
DLL_EXP(HNDL) guiInfoBox_Create( WORD left, WORD top,WORD right,WORD bottom,WORD style)
{
int i;
WORD Class;
struct tagGuiSysInfoBox *pControl;
guiEnterWCS();
pControl=(struct tagGuiSysInfoBox *)kernelMalloc(sizeof(struct tagGuiSysInfoBox));
if(pControl == NULL)
{
guiExitWCS();
return NULL;
}
pControl->base.handle =(HNDL)pControl;
pControl->base.left = left;
pControl->base.top = top;
pControl->base.right = right;
pControl->base.bottom = bottom;
pControl->base.style = style;
pControl->base.vportHandle = 0;
pControl->base.container=0;
pControl->base.type = CONTROL_SYS_INFO_BOX;
pControl->base.status = 0;
pControl->base.font = GUI_DEFAULT_FONT;
pControl->base.checkFlag = GUI_CONTROL_CHECK_FLAG;
pControl->base.actionFun =(PF_ACTION )InfoBox_Action;
pControl->base.showFun =(PF_SHOW)guiInfoBox_Show;
pControl->base.delFun =(PF_DELETE)guiInfoBox_Delete;
pControl->Dis_Normal_Invert=SYSINFO_NORMAL_DISPLAY;
for(i=0;i<GUI_RUNTIME_MAX_STYLE_NO;i++)
{
Class= (pControl->base.style >> i) & 0x01;
if(!Class)
{
pControl->Cur_Class= 0x01 << i;
break;
}
}
guiExitWCS();
return (HNDL)pControl;
}
/*********************************************************************/
//para: info box handle
//dest: delete the info box
//return:
//fail: STATUS_ERR
//sucess: STATUS_OK
/*********************************************************************/
DLL_EXP(STATUS) guiInfoBox_Delete( HNDL handle )
{
struct tagGuiControl *pControl;
if(handle == NULL)
return STATUS_ERR;
guiEnterWCS();
pControl=(struct tagGuiControl *)handle;
if(pControl->checkFlag != GUI_CONTROL_CHECK_FLAG)
{
guiExitWCS();
return STATUS_ERR;
}
pControl->checkFlag=0;
kernelFree((struct tagGuiSysInfoBox *)handle);
guiExitWCS();
return STATUS_OK;
}
/*********************************************************************/
//para: info box handle
//dest: show the info box
//return:
//fail: STATUS_ERR
//sucess: STATUS_OK
/*********************************************************************/
DLL_EXP(STATUS) guiInfoBox_Show( HNDL handle )
{
struct tagGuiSysInfoBox *pControl;
if(handle == NULL)
return STATUS_ERR;
if(guiControl_IsVisible(handle) == FALSE)
return STATUS_ERR;
guiEnterWCS();
pControl=(struct tagGuiSysInfoBox *)handle;
if(pControl->base.checkFlag != GUI_CONTROL_CHECK_FLAG)
{
guiExitWCS();
return STATUS_ERR;
}
InfoBox_Show(pControl);
guiExitWCS();
return STATUS_OK;
}
/*********************************************************************/
//para: void
//dest: window thread would call this function to modify the content
// of the topest window's system info. box.
//return:void
/*********************************************************************/
DLL_EXP(void) sysInfoBoxEventHandling(void)
{
struct dLinkList *pList;
struct dLinkList *pList1;
struct tagGuiSysInfoBox *pControl;
struct tagViewport *pViewport;
guiEnterWCS();
if(gpTopWindow == NULL)
{
guiExitWCS();
return;
}
if(gpTopWindow->controlList.back == 0)
{
guiExitWCS();
return;
}
pList=(struct dLinkList *)gpTopWindow->controlList.back;
while(pList)
{
pControl=(struct tagGuiSysInfoBox *)pList->elementPointer;
if(pControl->base.type == CONTROL_SYS_INFO_BOX && guiControl_IsVisible((HNDL)pControl) && !(pControl->base.status & CONTROL_NOT_ACTIVE))
//InfoBox_Show(pControl);
guiInfoBox_Show( (HNDL)pControl);
else if(pControl->base.type == CONTROL_VIEWPORT)
{
pViewport=(struct tagViewport *)pList->elementPointer;
pList1=(struct dLinkList *)pViewport->tControlList.back;
while(pList1)
{
pControl=(struct tagGuiSysInfoBox *)pList->elementPointer;
if(pControl->base.type == CONTROL_SYS_INFO_BOX && guiControl_IsVisible((HNDL)pControl) && !(pControl->base.status & CONTROL_NOT_ACTIVE))
//InfoBox_Show(pControl);
guiInfoBox_Show( (HNDL)pControl);
pList1=pList1->back;
}
}
pList=pList->back;
}
guiExitWCS();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -