📄 worldclock.c
字号:
/*******************************************************************************
Copyright(c) 1998 - 2006 DaTang Mobile Communications Equipment CO.,LTD.
All Rights Reserved. By using this module you agree to the terms of the
DaTang Mobile Communications Equipment CO.,LTD License Agreement for it.
*******************************************************************************/
/******************************************************************************
* Filename : worldclock.c
*
* Description : dynamic app world clock
*
* Notes : N/A
*
*------------------------------------------------------------------------------
* Change History:
*------------------------------------------------------------------------------
*
* 2007-10-23, qichen, create originally.
*
*******************************************************************************/
#include "worldclock.h"
extern CONST BITMAP bmp_worldmap;
/*y坐标全部减掉20*/
WORLDCLOCK_CITY_COORDINATE world_clock_city_location[WORLDCLOCK_CITY_COUNT] =
{
{-10, WEST_10, "-10:00", N_("Hawaii"), 5, 93},
{-8, WEST_8, "-08:00", N_("Los Angeles"), 33, 75},
{-5, WEST_5, "-05:00", N_("New York"), 65, 68},
{-8, WEST_8, "-08:00", N_("Vancouver"), 68, 65},
{-3, WEST_3, "-03:00", N_("Brasilia"), 76, 100},
{0, ZERO_TIMEZONE, "", N_("Greenwich"), 111, 62},
{0, ZERO_TIMEZONE, "", N_("Dublin"), 108, 62},
{0, ZERO_TIMEZONE, "", N_("London"), 111, 63},
{1, EAST_1, "+01:00", N_("Berlin"), 118, 64},
{1, EAST_1, "+01:00", N_("Rome"), 121, 69},
{2, EAST_2, "+02:00", N_("Cairo"), 132, 79},
{2, EAST_2, "+02:00", N_("Athens"), 128, 70},
{2, EAST_2, "+02:00", N_("Jerusalem"), 138, 76},
{3, EAST_3, "+03:00", N_("Bagdad"), 144, 75},
{3, EAST_3, "+03:00", N_("Moscow"), 142, 58},
{3, EAST_3, "+03:00", N_("Teheran"), 148, 75},
{5, EAST_5, "+05:00", N_("New Delhi"), 165, 80},
{7, EAST_7, "+07:00", N_("Bangkok"), 181, 88},
{7, EAST_7, "+07:00", N_("Djakarta"), 185, 102},
{8, EAST_8, "+08:00", N_("Peking"), 190, 70},
{8, EAST_8, "+08:00", N_("Shanghai"), 195, 77},
{8, EAST_8, "+08:00", N_("Hongkong"), 191, 83},
{8, EAST_8, "+08:00", N_("Macao"), 189, 83},
{8, EAST_8, "+08:00", N_("Taipei"), 195, 81},
{9, EAST_9, "+09:00", N_("Tokyo"), 206, 74},
{9, EAST_9, "+09:00", N_("Seoul"), 198, 73},
{9, EAST_10, "+10:00", N_("Melbourne"), 211, 123},
{10, EAST_10, "+10:00", N_("Sydney"), 214, 120}
};
static HDAPP g_worldclock_hdapp = 0;
/*当地城市索引*/
static SINT32 g_worldclock_index = 0;
/*系统城市索引,初始化为北京*/
static SINT32 g_worldclock_select_index = 19;
/**********************************************************************************
*
* Function: VOID worldclock_get_path(CHAR *path,CHAR *sub_path)
*
* Purpose: <get path>
*
* Relation: <describing the name, version and position of protocols involved by
* this function>
*
* Params:
*
*
* Name Type In/Out Description
* -------- ---- ------ -----------
*
*
* Return: <comment on the returned values>
*
* Note: <the limitations to use this function or other comments>
*
***********************************************************************************/
VOID worldclock_get_path(CHAR *path,CHAR *sub_path)
{
DYNC_APP_INFO app_info;
tp_dams_get_info(g_worldclock_hdapp, &app_info);
strcpy(path,app_info.path);
strcat(path,sub_path);
}
/**********************************************************************************
*
* Function: static SINT32 worldclock_get_cur_city(void)
*
* Purpose: <describing what the function is to do>
*
* Relation: <describing the name, version and position of protocols involved by
* this function>
*
* Params:
*
*
* Name Type In/Out Description
* -------- ---- ------ -----------
*
*
* Return: <comment on the returned values>
*
* Note: <the limitations to use this function or other comments>
*
***********************************************************************************/
static SINT32 worldclock_get_cur_city(void)
{
CHAR path[MAX_APP_PATH_LEN + 1];
worldclock_get_path(path,WORLDCLOCK_DATA_SUB_PATH);
if (GetIntValueFromEtcFile(path, "worldclock", "city", (int*)&g_worldclock_select_index)
!= ETC_OK)
{
return -1;
}
return g_worldclock_select_index;
}
/**********************************************************************************
*
* Function: static SINT32 worldclock_set_cur_city(void)
*
* Purpose: <describing what the function is to do>
*
* Relation: <describing the name, version and position of protocols involved by
* this function>
*
* Params:
*
*
* Name Type In/Out Description
* -------- ---- ------ -----------
*
*
* Return: <comment on the returned values>
*
* Note: <the limitations to use this function or other comments>
*
***********************************************************************************/
static SINT32 worldclock_set_cur_city(void)
{
CHAR select_index[4] = {0} ;
CHAR path[MAX_APP_PATH_LEN + 1];
if ((g_worldclock_select_index >= WORLDCLOCK_CITY_COUNT) || (g_worldclock_select_index < 0))
{
g_worldclock_select_index = 19;
}
sprintf(select_index, "%d", g_worldclock_select_index);
worldclock_get_path(path,WORLDCLOCK_DATA_SUB_PATH);
if (SetValueToEtcFile(path, "worldclock", "city", select_index) != ETC_OK)
{
return -1;
}
return 0;
}
/**********************************************************************************
*
* Function: static SINT32 worldclock_on_initdialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
*
* Purpose: <describing what the function is to do>
*
* Relation: <describing the name, version and position of protocols involved by
* this function>
*
* Params:
*
*
* Name Type In/Out Description
* -------- ---- ------ -----------
*
*
* Return: <comment on the returned values>
*
* Note: <the limitations to use this function or other comments>
*
***********************************************************************************/
static SINT32 worldclock_on_initdialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
HWND title = HWND_INVALID;
/*set title*/
title = GetDlgItem(hWnd, WORLDCLOCK_TITLE);
TCSetTitle( title, WORLDCLOCK_STR_TITLE, MAJOR_TITLE);
/*set softkeybar item*/
tp_skb_set_text_items(hWnd,WORLDCLOCK_STR_SAVE, NULL, WORLDCLOCK_STR_BACK);
tp_skb_update(hWnd);
worldclock_get_cur_city();
if ((g_worldclock_select_index >= WORLDCLOCK_CITY_COUNT) || (g_worldclock_select_index < 0))
{
g_worldclock_select_index = 19;
}
g_worldclock_index = g_worldclock_select_index;
return 0;
}
/**********************************************************************************
*
* Function: static SINT32 worldclock_on_paint(HWND hWnd, WPARAM wParam, LPARAM lParam)
*
* Purpose: <describing what the function is to do>
*
* Relation: <describing the name, version and position of protocols involved by
* this function>
*
* Params:
*
*
* Name Type In/Out Description
* -------- ---- ------ -----------
*
*
* Return: <comment on the returned values>
*
* Note: <the limitations to use this function or other comments>
*
***********************************************************************************/
static SINT32 worldclock_on_paint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
HDC hDc = BeginPaint(hWnd);
CHAR text[WORLDCLOCK_TEXT_MAX_LEN + 1];
CHAR text_info[WORLDCLOCK_TEXT_INFO_MAX_LEN + 1];
time_t ltime;
struct tm *system_time;
struct tm *local_time;
/* draw hint message */
/*set background color of the main window */
SetBkMode(hDc, BM_TRANSPARENT);
SetBrushColor(hDc, PIXEL_black);
FillBox(hDc, 0, 0, WORLDCLOCK_MAIN_W, WORLDCLOCK_MAIN_H);
/*worldmap*/
FillBoxWithBitmap(hDc, WORLDCLOCK_MAP_X, WORLDCLOCK_MAP_Y, WORLDCLOCK_MAP_W, WORLDCLOCK_MAP_H, &bmp_worldmap);
SetBrushColor(hDc, PIXEL_red);
FillCircle(hDc, world_clock_city_location[g_worldclock_index].x, world_clock_city_location[g_worldclock_index].y, 2);
/*set the text background color*/
SetTextColor(hDc, PIXEL_lightwhite);
/*系统时区*/
memset(text_info, 0, WORLDCLOCK_TEXT_INFO_MAX_LEN +1);
strncpy(text_info, _(world_clock_city_location[g_worldclock_select_index].zone_text), WORLDCLOCK_TEXT_INFO_MAX_LEN);
memset(text, 0, WORLDCLOCK_TEXT_MAX_LEN + 1);
strncpy(text, WORLDCLOCK_STR_SYSTEM_ZONE, WORLDCLOCK_TEXT_INFO_MAX_LEN);
strcat(text, text_info);
TextOut(hDc, WORLDCLOCK_TEXT_X, WORLDCLOCK_TEXT_SYSTEM_ZONE_Y, text);
/*系统时间*/
time(<ime);
system_time = gmtime(<ime);
system_time->tm_hour = system_time->tm_hour + world_clock_city_location[g_worldclock_select_index].time_offset ;
if (system_time->tm_hour < 0)
{
system_time->tm_hour = system_time->tm_hour + 24;
}
else if (system_time->tm_hour >= 24)
{
system_time->tm_hour = system_time->tm_hour - 24;
}
memset(text_info, 0, WORLDCLOCK_TEXT_INFO_MAX_LEN + 1);
snprintf(text_info, WORLDCLOCK_TEXT_INFO_MAX_LEN, "%02d:%02d", system_time->tm_hour, system_time->tm_min);
memset(text, 0, WORLDCLOCK_TEXT_MAX_LEN + 1);
strncpy(text, WORLDCLOCK_STR_SYSTEM_TIME, WORLDCLOCK_TEXT_INFO_MAX_LEN);
strcat(text, text_info);
TextOut(hDc, WORLDCLOCK_TEXT_X, WORLDCLOCK_TEXT_SYSTEM_TIME_Y, text);
/*当地城市*/
memset(text, 0, WORLDCLOCK_TEXT_MAX_LEN + 1);
strncpy(text, WORLDCLOCK_STR_LOCAL_CITY, WORLDCLOCK_TEXT_INFO_MAX_LEN);
strcat(text, _(world_clock_city_location[g_worldclock_index].city));
TextOut(hDc, WORLDCLOCK_TEXT_X, WORLDCLOCK_TEXT_LOCAL_CITY_Y, text);
/*当地时间*/
local_time = gmtime(<ime);
local_time->tm_hour = local_time->tm_hour + world_clock_city_location[g_worldclock_index].time_offset;
if (local_time->tm_hour < 0)
{
local_time->tm_hour = local_time->tm_hour + 24;
}
else if(local_time->tm_hour >= 24)
{
local_time->tm_hour = local_time->tm_hour - 24;
}
memset(text_info, 0, WORLDCLOCK_TEXT_INFO_MAX_LEN + 1 );
snprintf(text_info, WORLDCLOCK_TEXT_INFO_MAX_LEN, "%02d:%02d", local_time->tm_hour, local_time->tm_min);
memset(text, 0, WORLDCLOCK_TEXT_MAX_LEN + 1);
strncpy(text, WORLDCLOCK_STR_LOCAL_TIME, WORLDCLOCK_TEXT_INFO_MAX_LEN);
strcat(text, text_info);
TextOut(hDc, WORLDCLOCK_TEXT_X, WORLDCLOCK_TEXT_LOCAL_TIME_Y, text);
EndPaint(hWnd, hDc);
return 0;
}
/**********************************************************************************
*
* Function: static SINT32 worldclock_on_active(HWND hWnd, WPARAM wParam, LPARAM lParam)
*
* Purpose: <describing what the function is to do>
*
* Relation: <describing the name, version and position of protocols involved by
* this function>
*
* Params:
*
*
* Name Type In/Out Description
* -------- ---- ------ -----------
*
*
* Return: <comment on the returned values>
*
* Note: <the limitations to use this function or other comments>
*
***********************************************************************************/
static SINT32 worldclock_on_active(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
if( wParam )
{
/*set softkeybar item*/
tp_skb_set_text_items(hWnd, WORLDCLOCK_STR_SAVE, NULL, WORLDCLOCK_STR_BACK);
tp_skb_update(hWnd);
}
return 0;
}
/**********************************************************************************
*
* Function: static SINT32 worldclock_on_keydown(HWND hWnd, WPARAM wParam, LPARAM lParam)
*
* Purpose: <describing what the function is to do>
*
* Relation: <describing the name, version and position of protocols involved by
* this function>
*
* Params:
*
*
* Name Type In/Out Description
* -------- ---- ------ -----------
*
*
* Return: <comment on the returned values>
*
* Note: <the limitations to use this function or other comments>
*
***********************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -