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

📄 uitimepanel.c

📁 嵌入工linux开发的源码
💻 C
字号:
/*********************************************************************/
//	文 件 名:	uiTimepanel.cpp
//	程序说明:	Timepanel控件
//	程序设计:	党德华
//				2001.11.05		设计完成		说明文档:R004-S215-0001
//	程序审查:	宋军霞
//				2002.01.22		审查完成		说明文档:R004-S215-0001
//	项目编号:	R004-S215
//	版	  本:	V1.0
//	版    权:	Reality Plus Technology (ShenZhen) Co.,Ltd.
/*********************************************************************/
#include <uiwnd.h>
#include <uiGraph.h>
#include <stdio.h>

extern TGuiWindow *gpTopWindow;

/*********************************************************************/
//para: tiempanel coordinate ,struce refer to uiTimepanel.h and title
//dest: popup the timepanel dialog
//return:
//cancel: 0
//confirm: 1
/*********************************************************************/
DLL_EXP(int) guiTimePanel_Popup(WORD left,WORD top,TGuiTimePanel *time,const char *caption)
{
	sysTime		now ;
	int			oldFontType;
	int			total=0;
	int         temp_width,char_width,word_width,word_height,gap_width;
	int			sel_width1,sel_width2,sel_height,win_width,win_height;
	int			button_width;
	int			x,y,xText,yText;
	int		    i,index;
	char        buf[3];
	WORD		style;

	HNDL		hDialog,hSel[4],hButton_OK,hButton_Cancel;

	TGuiTimePanel	tTimePanel;
	TGuiWindow		*pWin;
    TGuiMessage		message;
	char            langType;	
	tTimePanel=*time;

	langType = guiQueryLanguageType();
	if(langType>2)
		langType = LANGUAGE_CHS;

	style = tTimePanel.style;

	sc_getTime(&now);		//判断时间的合法性
	if(/*tongtTimePanel.hour < 0 || */tTimePanel.hour > 23 ||
	   /*tongtTimePanel.min  < 0 || */tTimePanel.min  > 59 || 
	   /*tongtTimePanel.sec  < 0 || */tTimePanel.sec  > 59 )
	{
		tTimePanel.hour=now.hour;
		tTimePanel.min =now.minute;
		tTimePanel.sec =now.second;
	}

	if(!(style & TIMEPANEL_NO_APM))		//计算选择器数
		total++;
	if(!(style & TIMEPANEL_NO_SEC))
		total++;
	if(!(style & TIMEPANEL_NO_MIN))
		total++;
	if(!(style & TIMEPANEL_NO_HOUR))
		total++;

	if(total == 0)
		return  TIMEPANEL_CANCLE;		//没有选项时,返回

	guiEnterWCS();
	oldFontType=guiGetFont();			//保存系统当前字体,并设置控件字体
	guiSetFont(GUI_DEFAULT_FONT);

	char_width=guiGetCharWidth('0');	//文字的宽度和高度
	word_width=guiGetWordWidth();
	word_height=guiGetWordHeight();

	for(i=1;i<10;i++)					//计算数字0-9的最大宽度
	{
		temp_width=guiGetCharWidth('0'+i);
		if(char_width<temp_width)
			char_width=temp_width;
	}
	sel_width1=2*char_width+1;			//时、分、秒选择器的宽度

	sel_width2=guiGetStringWidth("AM");	// AM/PM选择器宽度
	temp_width=guiGetStringWidth("PM");
	sel_width2=sel_width2>temp_width?sel_width2:temp_width;

	guiSetFont(oldFontType);			//恢复系统当前字体
	guiExitWCS();

	sel_height=word_height+12;			//选择器高度:字高+18

	win_width=GUI_SCREEN_WIDTH-2*left;	// 对话框的高度和宽度
	win_height=2*(word_height+4)+sel_height+6*2+2+WIN_BORDER_WIDTH;
		// word_heigth+4为标题条和Button的高度
		// 10*2为标题条、选择器行、Button行之间的间隔

	//计算两个按钮座标并创建它们
	button_width=word_width*2+21;
	gap_width=(win_width-WIN_BORDER_WIDTH*2-2*button_width)/3;
	x=gap_width+WIN_BORDER_WIDTH;
	y=win_height-WIN_BORDER_WIDTH-2-word_height-4;                               

	// "确定"
	hButton_OK=guiButton_Create(x,y,x+button_width-1,y+word_height+3,RES_STR_OK[langType],BUTTON_WIN3D );
	x=win_width-WIN_BORDER_WIDTH-gap_width-button_width;                  

	// "取消"
	hButton_Cancel=guiButton_Create(x,y,x+button_width-1,y+word_height+3, RES_STR_CANCEL[langType], BUTTON_WIN3D );

	temp_width=win_width-WIN_BORDER_WIDTH*2;	//计算选择器总间隔
	if(!(style & TIMEPANEL_NO_APM))
		temp_width-=sel_width2;					// AM或PM
	if(!(style & TIMEPANEL_NO_SEC))
		temp_width-=sel_width1+word_width+1;	// XX时
	if(!(style & TIMEPANEL_NO_MIN))
		temp_width-=sel_width1+word_width+1;	// XX分
	if(!(style & TIMEPANEL_NO_HOUR))
		temp_width-=sel_width1+word_width+1;	// XX秒

	if(total==1)				//第一个选择器的座标
	{
		x=temp_width/2;
		gap_width=x;
	}
	else
	{
		gap_width=temp_width/(total+1);
		if(gap_width>11)
			gap_width=11;
		x=(temp_width-gap_width*(total-1))/2;
	}
	x+=WIN_BORDER_WIDTH;
	y=word_height+4+6;

	xText=x+sel_width1+1;		//第一个文字(时/分/秒)的座标
	yText=y+6;

	if(!(style & TIMEPANEL_NO_HOUR))	// 创建时钟选择器
	{
		hSel[0]=guiSelector_Create(x,y,x+sel_width1-1,y+sel_height-1,SELECTOR_VERTICAL|SELECTOR_ISLOOP);
		if(style & TIMEPANEL_24HR)		//24小时制
		{
			for(i=0;i<24;i++)
			{
				sprintf(buf,"%02d",i);
				guiSelector_AddItem(hSel[0],buf);
			}
		}
		else							//12小时制
		{
			for(i=0;i<24;i++)
			{
				if(i==12)
					sprintf(buf,"%02d",i);
				else
					sprintf(buf,"%02d",i%12);
				guiSelector_AddItem(hSel[0],buf);
			}
		}
		guiSelector_Select(hSel[0],tTimePanel.hour);
		guiSelector_SetSpeed(hSel[0],tTimePanel.interval_hour);
		x+=sel_width1+word_width+1+gap_width;
	}
	if(!(style & TIMEPANEL_NO_MIN))		// 创建分钟选择器
	{
		hSel[1]=guiSelector_Create(x,y,x+sel_width1-1,y+sel_height-1,SELECTOR_VERTICAL|SELECTOR_ISLOOP);
		for(i=0;i<60;i++)
		{
			sprintf(buf,"%02d",i);
			guiSelector_AddItem(hSel[1],buf);
		}
		guiSelector_Select(hSel[1],tTimePanel.min);
		guiSelector_SetSpeed(hSel[1],tTimePanel.interval_min);
		x+=sel_width1+word_width+1+gap_width;
	}
	if(!(style & TIMEPANEL_NO_SEC))		// 创建秒钟选择器
	{
		hSel[2]=guiSelector_Create(x,y,x+sel_width1-1,y+sel_height-1,SELECTOR_VERTICAL|SELECTOR_ISLOOP);
		for(i=0;i<60;i++)
		{
			sprintf(buf,"%02d",i);	
			guiSelector_AddItem(hSel[2],buf);
		}
		guiSelector_Select(hSel[2],tTimePanel.sec);
		guiSelector_SetSpeed(hSel[2],tTimePanel.interval_sec);
		x+=sel_width1+word_width+1+gap_width;
	}
	if(!(style & TIMEPANEL_NO_APM))		// 创建AM/PM选择器
	{
		hSel[3]=guiSelector_Create(x,y,x+sel_width2-1,y+sel_height-1,SELECTOR_VERTICAL|SELECTOR_ISLOOP);
		
		guiSelector_AddItem(hSel[3],"AM");
		guiSelector_AddItem(hSel[3],"PM");
		
		if(tTimePanel.hour < 12)
			guiSelector_Select(hSel[3],0);
		else 
			guiSelector_Select(hSel[3],1);
	}

/*
	if(caption == NULL)	//创建对话框
	{
		hDialog=guiDialog_Create(gpTopWindow->handle,left,top,left+win_width-1,top+win_height-1,"时间面板",
			GUIWIN_BORDER|GUIWIN_CAPTION_CENTER|GUIWIN_CLOSE_NONE);
	}
	else
	{
		hDialog=guiDialog_Create(gpTopWindow->handle,left,top,left+win_width-1,top+win_height-1,(char *)caption,
			GUIWIN_BORDER|GUIWIN_CAPTION_CENTER|GUIWIN_CLOSE_NONE);
	}
*/
	if(caption == NULL)	//创建对话框
	{
		hDialog=guiDialog_Create(0,left,top,left+win_width-1,top+win_height-1,"时间面板",
			GUIWIN_BORDER|GUIWIN_CAPTION_CENTER|GUIWIN_CLOSE_NONE);
	}
	else
	{
		hDialog=guiDialog_Create(0,left,top,left+win_width-1,top+win_height-1,(char *)caption,
			GUIWIN_BORDER|GUIWIN_CAPTION_CENTER|GUIWIN_CLOSE_NONE);
	}

	
	//将控件加入对放框
	if(!(style & TIMEPANEL_NO_HOUR))	// 时钟选择器
		guiControl_Add(hDialog,hSel[0]);
	if(!(style & TIMEPANEL_NO_MIN))		// 分钟选择器
		guiControl_Add(hDialog,hSel[1]);
	if(!(style & TIMEPANEL_NO_SEC))		// 秒钟选择器
		guiControl_Add(hDialog,hSel[2]);
	if(!(style & TIMEPANEL_NO_APM))		// AM/PM选择器
		guiControl_Add(hDialog,hSel[3]);

	guiControl_Add(hDialog,hButton_OK);
	guiControl_Add(hDialog,hButton_Cancel);

	guiDialog_Show(hDialog);

	// 显示文字
	guiEnterWCS();
	oldFontType=guiGetFont();			//保存系统当前字体,并设置控件字体
	guiSetFont(GUI_DEFAULT_FONT);
	if(!(style & TIMEPANEL_NO_HOUR))	// 时钟选择器
	{                                             
		// "时"
		guiShowWord(hDialog,RES_STR_HOUR[langType],xText,yText,GUI_BLACK,0);
		xText+=sel_width1+gap_width+word_width+1;
	}
	if(!(style & TIMEPANEL_NO_MIN))		// 分钟选择器
	{                                 
		// "分"
		guiShowWord(hDialog,RES_STR_MINUTE[langType],xText,yText,GUI_BLACK,0);
		xText+=sel_width1+gap_width+word_width+1;
	}
	if(!(style & TIMEPANEL_NO_SEC))		// 秒钟选择器
	{                                 
		// "秒"
		guiShowWord(hDialog,RES_STR_SECOND[langType],xText,yText,GUI_BLACK,0);
		xText+=sel_width1+gap_width+word_width+1;
	}
	guiSetFont(oldFontType);			//恢复系统当前字体
	guiExitWCS();

	pWin = (TGuiWindow *)hDialog;
	while(1)
    {
        if( guiDequeue(pWin->messageQueue, &message) == -1)
			continue;
		switch(message.messageType)
		{
		case BUTTON_CLICK:
			if(message.handle == hButton_OK)
			{
				if(!(style & TIMEPANEL_NO_HOUR))	// 时钟选择器
					tTimePanel.hour=guiSelector_GetSelectIndex(hSel[0]);
				if(!(style & TIMEPANEL_NO_MIN))		// 时钟选择器
					tTimePanel.min=guiSelector_GetSelectIndex(hSel[1]);
				if(!(style & TIMEPANEL_NO_SEC))		// 时钟选择器
					tTimePanel.sec=guiSelector_GetSelectIndex(hSel[2]);
				*time=tTimePanel;
				guiDialog_Delete(hDialog);
				return TIMEPANEL_OK;
			}
			else if(message.handle == hButton_Cancel)
			{
				guiDialog_Delete(hDialog);
				return TIMEPANEL_CANCLE;
			}
			break;
		case SELECTOR_CLICK:
			if( !(style & TIMEPANEL_NO_HOUR) && 
				!(style & TIMEPANEL_NO_APM) &&
				 message.handle == hSel[0])
			{
				index=guiSelector_GetSelectIndex(hSel[0]);
				if(index < 12)
					guiSelector_Select(hSel[3],0);
				else 
					guiSelector_Select(hSel[3],1);
			}
			if( !(style & TIMEPANEL_NO_HOUR) && 
				!(style & TIMEPANEL_NO_APM) &&
				 message.handle == hSel[3])
			{
				index=guiSelector_GetSelectIndex(hSel[0]);
				index=(index+12)%24;
				guiSelector_Select(hSel[0],index);
			}
			break;
		case WIN_CLOSE:
			guiDialog_Delete(hDialog);
			return TIMEPANEL_CANCLE;
		default:
			break;
		}
	}
}

⌨️ 快捷键说明

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