worldclock.c
资源名称:mmi.rar [点击查看]
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:100k
源码类别:
MTK
开发平台:
C/C++
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * Worldclock.c
- *
- * Project:
- * --------
- * MAUI
- *
- * Description:
- * ------------
- * This file implements world clock application.
- *
- * Author:
- * -------
- * -------
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- /**
- * Copyright Notice
- * (c) 2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
- * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
- * (It is illegal to remove this copyright notice from this software or any
- * portion of it)
- */
- /**********************************************************************************
- Filename: Worldclock.c
- Author: Vandana M
- Date Created: June-14-2003
- Contains: World Clock
- **********************************************************************************/
- #ifndef _MMI_WORLDCLOCK_C
- #define _MMI_WORLDCLOCK_C
- /* Include: MMI header file */
- #include "MMI_features.h"
- #include "DebugInitDef.h"
- #include "OrganizerDef.h"
- #include "PixtelDataTypes.h"
- #include "NVRAMType.h"
- #include "NVRAMProt.h"
- #include "NVRAMEnum.h"
- #include "worldclock.h"
- #include "KeyBrd.h"
- #include "IdleAppProt.h"
- #include "CustMenuRes.h"
- #include "CustDataProts.h"
- #include "DebugInitDef.h"
- #include "worldclock.h"
- #include "HistoryGprot.h"
- #include "GlobalDefs.h"
- #include "Unicodexdcl.h"
- #include "GlobalMenuItems.h"
- #include "OrganizerDef.h"
- #include "CommonScreens.h"
- #include "wgui_categories.h"
- #include "CommonScreens.h"
- #include "DateTimeGprot.h"
- #include "Gdi_include.h"
- #ifdef __MMI_WORLDCLOCK_DST__
- #include "WallpaperDefs.h"
- #include "DownloadDefs.h"
- #include "PhoneSetup.h"
- #include "Calculator.h"
- #endif /* __MMI_WORLDCLOCK_DST__ */
- /* ... Add More MMI header */
- /* Include: PS header file */
- /* ... Add More PS header */
- /*
- * Define
- */
- #ifdef __MMI_MAINLCD_128X160__
- #define WC_CITY_NAME_HEIGHT MMI_TITLE_HEIGHT
- #define WC_HEIGHT_160
- #else /* __MMI_MAINLCD_128X160__ */
- #define WC_CITY_NAME_HEIGHT 0
- #endif /* __MMI_MAINLCD_128X160__ */
- #define WC_V_LINE_Y (MMI_TITLE_Y+MMI_TITLE_HEIGHT+WC_CITY_NAME_HEIGHT) /* y-coordinate of vertical line */
- #define WC_H_LINE_X 0 /* x-coordinate of horizontal line */
- #define WC_LINE_WIDTH (gdi_layer_get_bit_per_pixel()>>3)
- #define WC_NUM_CITY STR_TOTAL_NUM_CITY - STR_WCLOCK_CITY_NONE
- // #ifdef __MMI_TOUCH_SCREEN__//061705 Calvin marked
- #if defined(__MMI_MAINLCD_240X320__) /* 041205 Calvin modifed */
- #define WC_TITLE_HEIGHT 40
- #define WC_DATE_HEIGHT 35
- #define WC_TIME_HEIGHT 35
- #else /* defined(__MMI_MAINLCD_240X320__) */
- #define WC_TITLE_HEIGHT 24
- #define WC_DATE_HEIGHT 22
- #define WC_TIME_HEIGHT 23
- #endif /* defined(__MMI_MAINLCD_240X320__) */
- #ifdef __MMI_WC_TZ_SUPPORT__
- #define WC_INDEX_NUM 2
- #define WC_MAX_INDEX_INFO_LEN 40
- #define WC_TZ_INDEX 0
- #define WC_CITY_INDEX 1
- #define WC_TZ_SIGN_POS 3
- #define WC_GMT_LEN (WC_TZ_SIGN_POS * sizeof(UI_character_type))
- #define WC_MAX_TZ_STR_LEN 5
- #define WC_SYM_COMMA (UI_character_type)','
- #define WC_SYM_POSITIVE (UI_character_type)'+'
- #define WC_SYM_NEGATIVE (UI_character_type)'-'
- #define WC_SYM_SPACE (UI_character_type)' '
- #endif /* __MMI_WC_TZ_SUPPORT__ */
- #ifdef __MMI_NITZ_TZ_SUPPORT__
- #define WC_DEFAULT_TZ_NUM 37
- #endif
- /*
- * Typedef
- */
- #ifdef __MMI_TOUCH_SCREEN__
- typedef enum
- {
- WC_TOUCH_NONE,
- WC_TOUCH_ON_LEFT_ARROW_UP,
- WC_TOUCH_ON_LEFT_ARROW_DOWN,
- WC_TOUCH_ON_RIGHT_ARROW_UP,
- WC_TOUCH_ON_RIGHT_ARROW_DOWN,
- WC_TOUCH_ON_MAP,
- WC_TOUCH_ON_RSK
- } WORLD_CLOCK_PEN_EVENTS;
- #endif /* __MMI_TOUCH_SCREEN__ */
- /*
- * Local Variable
- */
- static U8 gWcTimeZoneIndex[WC_NUM_CITY];
- #ifdef __MMI_WC_TZ_SUPPORT__
- U8 *homeTime, *foreTime;
- #endif /* __MMI_WC_TZ_SUPPORT__ */
- /*
- * Local Function
- */
- /*
- * Global Variable
- */
- #ifdef __MMI_WORLD_CLOCK__
- wc_context_struct g_wc_cntx;
- #endif
- #ifdef __MMI_WC_TZ_SUPPORT__
- U8 *gIndexInfo[WC_INDEX_NUM];
- #endif
- #if defined (__MMI_NITZ_TZ_SUPPORT__) || defined (__MMI_WC_TZ_SUPPORT__)
- const S16 validTZ[WC_DEFAULT_TZ_NUM] =
- { -48, -44, -40, -38, -36, -34, -32, -28, -24, -20, -16, -14, -12, -8, -4, 0, 4, 8, 12, 14, 16, 18, 20, 22, 23, 24,
- 26, 28, 32, 36, 38, 40, 42, 44, 46, 48, 49};
- U8 gWcDefaultCityForTZ[WC_DEFAULT_TZ_NUM];
- #endif
- U8 g_dst;
- /*
- * Global Function
- */
- extern void _show_bitmap(S32 x1, S32 y1, bitmap *b);
- extern void _get_bitmap(S32 x1, S32 y1, S32 x2, S32 y2, bitmap *b);
- extern U8 PhnsetGetHomeCity(void);
- #ifdef __MMI_WC_TZ_SUPPORT__
- BOOL ATSetHomeCity(U8 CityIndex);
- #endif
- /* MTK Elvis for R2L character */
- extern BOOL r2lMMIFlag;
- /* MTK end */
- #define WC_INITIALIZE
- /*****************************************************************************
- * FUNCTION
- * WcInit
- * DESCRIPTION
- * Initailze world clock
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void WcInit(void)
- {
- #ifdef __MMI_WORLD_CLOCK__
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- #ifdef __MMI_WC_TZ_SUPPORT__
- U8 currentHomeCity;
- S16 currentTimeZone, error;
- #endif /* __MMI_WC_TZ_SUPPORT__ */
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- memset(&g_wc_cntx, 0, sizeof(wc_context_struct));
- g_wc_cntx.CurrCityIndex = 0xff;
- #if defined(__MMI_MAINLCD_176X220__) || defined (__MMI_MAINLCD_240X320__) /* 041205 Calvin modieid */
- gui_measure_image(get_image(WORLD_CLOCK_LEFT_ARROW_UP), &(g_wc_cntx.arrow_width), &(g_wc_cntx.arrow_height));
- #endif
- #ifdef __MMI_TOUCH_SCREEN__
- g_wc_cntx.event_on_object = WC_TOUCH_NONE;
- #endif
- SetHiliteHandler(ORGANIZER_WORLDCLOCK_MENU, HighlightWCMenu);
- SetHiliteHandler(MITEM_WORLDCLOCK_BROWSECITY, HighlightWcBrowseCity);
- #if defined(__MMI_WORLD_CLOCK_SUBLCD_SETTING__)
- SetHiliteHandler(MITEM_WORLDCLOCK_SUBLCDDISPLAY, HighlightWcSubLcd);
- SetHintHandler(MITEM_WORLDCLOCK_SUBLCDDISPLAY_CITY1, WcHintCity1);
- SetHintHandler(MITEM_WORLDCLOCK_SUBLCDDISPLAY_CITY2, WcHintCity2);
- #endif /* defined(__MMI_WORLD_CLOCK_SUBLCD_SETTING__) */
- #endif /* __MMI_WORLD_CLOCK__ */
- WcGenerateTimeZoneIndex();
- mmi_wc_is_dst();
- #ifdef __MMI_NITZ_TZ_SUPPORT__
- mmi_wc_set_default_city_for_tz();
- #endif
- #ifdef __MMI_WC_TZ_SUPPORT__
- currentHomeCity = PhnsetGetHomeCity() + 1;
- currentTimeZone = (S16)(TimeZoneData[currentHomeCity].CityTimeZone * 4);
- WriteValue(NVRAM_TIMEZONE, ¤tTimeZone, DS_SHORT, &error);
- #endif /* __MMI_WC_TZ_SUPPORT__ */
- }
- #define WC_UTILITY_FUNCTION
- /*****************************************************************************
- * FUNCTION
- * GetTimeZone
- * DESCRIPTION
- * Return the time zone of a city
- * PARAMETERS
- * cityIndex [IN] Index of city
- * RETURNS
- * Time zone
- *****************************************************************************/
- FLOAT GetTimeZone(U8 cityIndex)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- return TimeZoneData[cityIndex + 1].CityTimeZone;
- }
- /*****************************************************************************
- * FUNCTION
- * WcGenerateTimeZoneIndex
- * DESCRIPTION
- * Generate indexing table of world clock. The table is sorted by time zone and x/y-coordinate.
- * PARAMETERS
- * void
- * nIndex(?) [IN] Index of item.(?)
- * RETURNS
- * void
- *****************************************************************************/
- void WcGenerateTimeZoneIndex(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 i, j;
- U8 tmp;
- U8 swap = FALSE;
- U8 index1, index2;
- U8 num_city = NUMBER_OF_CITY;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- for (i = 0; i < num_city - 1; i++)
- {
- gWcTimeZoneIndex[i] = i + 1;
- }
- for (i = 0; i < num_city - 1; i++)
- {
- for (j = 0; j < (num_city - 1) - i - 1; j++)
- {
- index1 = gWcTimeZoneIndex[j + 1];
- index2 = gWcTimeZoneIndex[j];
- if (TimeZoneData[index1].CityTimeZone < TimeZoneData[index2].CityTimeZone)
- {
- swap = TRUE;
- }
- else if (TimeZoneData[index1].CityTimeZone == TimeZoneData[index2].CityTimeZone)
- {
- if (TimeZoneData[index1].CityX < TimeZoneData[index2].CityX)
- {
- swap = TRUE;
- }
- else if (TimeZoneData[index1].CityX == TimeZoneData[index2].CityX)
- if (TimeZoneData[index1].CityY < TimeZoneData[index2].CityY)
- {
- swap = TRUE;
- }
- }
- if (swap)
- {
- tmp = gWcTimeZoneIndex[j]; /* swap a[j] and a[j+1] */
- gWcTimeZoneIndex[j] = gWcTimeZoneIndex[j + 1];
- gWcTimeZoneIndex[j + 1] = tmp;
- swap = FALSE;
- }
- }
- }
- }
- #ifdef __MMI_NITZ_TZ_SUPPORT__
- /*****************************************************************************
- * FUNCTION
- * mmi_wc_set_default_city_for_tz
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_wc_set_default_city_for_tz(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 i;
- U32 count = 0;
- FLOAT tz;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- for (i = 0; i < NUMBER_OF_CITY; i++)
- {
- tz = (FLOAT) validTZ[count] / (FLOAT) 4;
- if (TimeZoneData[gWcTimeZoneIndex[i]].CityTimeZone == tz)
- {
- gWcDefaultCityForTZ[count] = gWcTimeZoneIndex[i];
- count++;
- }
- else if (TimeZoneData[gWcTimeZoneIndex[i]].CityTimeZone > tz)
- {
- count++;
- /* find the matched timezone for this city, therefore decrease first to balence i++ */
- i--;
- }
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_wc_set_home_city_from_nitz
- * DESCRIPTION
- *
- * PARAMETERS
- * nitz_tz [IN]
- * RETURNS
- *
- *****************************************************************************/
- S16 mmi_wc_set_home_city_from_nitz(S16 nitz_tz)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U32 count;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- for (count = 0; count < WC_DEFAULT_TZ_NUM; count++)
- {
- if (nitz_tz == validTZ[count])
- {
- ATSetHomeCity(gWcDefaultCityForTZ[count]);
- break;
- }
- }
- /* There's no matched city */
- if (count == WC_DEFAULT_TZ_NUM)
- {
- return -1;
- }
- else
- {
- return (S32) gWcDefaultCityForTZ[count];
- }
- }
- #endif /* __MMI_NITZ_TZ_SUPPORT__ */
- /*****************************************************************************
- * FUNCTION
- * mmi_wc_get_home_city
- * DESCRIPTION
- * Return string of home city
- * PARAMETERS
- * void
- * RETURNS
- * String pointer to home city name
- *****************************************************************************/
- S8 *mmi_wc_get_home_city(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- return GetString(TimeZoneData[PhnsetGetHomeCity() + 1].CityName);
- }
- /*****************************************************************************
- * FUNCTION
- * WcSetCityIndex
- * DESCRIPTION
- * Set current city.
- * PARAMETERS
- * index [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void WcSetCityIndex(U16 index)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- #if defined(__MMI_WORLD_CLOCK__)
- g_wc_cntx.CurrCityIndex = (U8) index;
- #endif
- }
- #ifdef __MMI_WORLD_CLOCK__
- #define WC_BROWSE_CITY
- /*****************************************************************************
- * FUNCTION
- * HighlightWCMenu
- * DESCRIPTION
- * Highlight handler of World Clock menu item.
- * Register key handlers.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void HighlightWCMenu(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
- ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
- #if defined(__MMI_WORLD_CLOCK_SUBLCD_SETTING__)
- SetKeyHandler(EntryWcApp, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
- SetLeftSoftkeyFunction(EntryWcApp, KEY_EVENT_UP);
- #else /* defined(__MMI_WORLD_CLOCK_SUBLCD_SETTING__) */
- SetLeftSoftkeyFunction(EntryWcBrowseCity, KEY_EVENT_UP);
- SetKeyHandler(EntryWcBrowseCity, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
- #endif /* defined(__MMI_WORLD_CLOCK_SUBLCD_SETTING__) */
- SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
- SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
- }
- /*****************************************************************************
- * FUNCTION
- * HighlightWcBrowseCity
- * DESCRIPTION
- * Highlight handler of browse city menu
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void HighlightWcBrowseCity(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- SetLeftSoftkeyFunction(EntryWcBrowseCity, KEY_EVENT_UP);
- }
- /*****************************************************************************
- * FUNCTION
- * EntryWcBrowseCity
- * DESCRIPTION
- * Display browse city screen.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- #ifdef __MMI_DRAW_MANAGER__
- void WcShowCategory(void);
- #endif
- void EntryWcBrowseCity(void)
- {
- #ifdef __MMI_WORLDCLOCK_DST__
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 error;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- ReadValue(NVRAM_WC_DST, &g_wc_cntx.DSTForeign, DS_BYTE, &error);
- if (g_wc_cntx.DSTForeign == 0xff)
- {
- g_wc_cntx.DSTForeign = 0;
- }
- #endif /* __MMI_WORLDCLOCK_DST__ */
- EntryWcBrowseCityEx(EntryWcBrowseCity, ExitWcBrowseCity);
- }
- /*****************************************************************************
- * FUNCTION
- * EntryWcBrowseCityEx
- * DESCRIPTION
- * Display browse city screen
- * PARAMETERS
- * entry_func [IN]
- * exit_func [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void EntryWcBrowseCityEx(void (*entry_func) (void), void (*exit_func) (void))
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- #ifdef __MMI_WC_TZ_SUPPORT__
- S16 error;
- S16 tmpTimeZone;
- U8 *guiBuffer;
- #endif /* __MMI_WC_TZ_SUPPORT__ */
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* initialize UI related variables */
- EntryNewScreen(SCR_ID_WC_BROWSE_CITY, exit_func, entry_func, NULL);
- g_wc_cntx.CurrMap = 0xff;
- MMI_title_icon = NULL;
- MMI_menu_shortcut_number = -1;
- if (g_wc_cntx.CurrCityIndex == 0xff)
- {
- if (PhnsetGetHomeCity() != 0xff)
- {
- g_wc_cntx.CurrCityIndex = PhnsetGetHomeCity() + 1;
- }
- else
- {
- g_wc_cntx.CurrCityIndex = 0;
- }
- }
- #ifndef __MMI_WC_TZ_SUPPORT__
- if (g_wc_cntx.VLine == NULL)
- {
- g_wc_cntx.VLine = OslMalloc(sizeof(bitmap));
- g_wc_cntx.VLine->data = OslMalloc(UI_device_height * WC_LINE_WIDTH);
- }
- if (g_wc_cntx.HLine == NULL)
- {
- g_wc_cntx.HLine = OslMalloc(sizeof(bitmap));
- g_wc_cntx.HLine->data = OslMalloc(UI_device_width * WC_LINE_WIDTH);
- }
- /* draw UI */
- #ifdef __MMI_DRAW_MANAGER__
- WcShowCategory();
- #else
- WcRedrawWorldClock(0, UI_device_height);
- #endif
- SetKeyHandler(WcHandleKeyLeft, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
- SetKeyHandler(WcHandleKeyLeft, KEY_LEFT_ARROW, KEY_LONG_PRESS);
- SetKeyHandler(WcHandleKeyRight, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
- SetKeyHandler(WcHandleKeyRight, KEY_RIGHT_ARROW, KEY_LONG_PRESS);
- RedrawCategoryFunction = WcRedrawCategory;
- #ifdef __MMI_WORLDCLOCK_DST__
- SetLeftSoftkeyFunction(WcEntryDST, KEY_EVENT_UP);
- #endif
- #else /*#ifndef __MMI_WC_TZ_SUPPORT__*/
- gIndexInfo[WC_TZ_INDEX] = OslMalloc(WC_MAX_INDEX_INFO_LEN);
- gIndexInfo[1] = OslMalloc(WC_MAX_INDEX_INFO_LEN);
- memcpy(gIndexInfo[WC_TZ_INDEX], (S8*) GetString(STR_WORLD_CLOCK_GMT), WC_GMT_LEN);
- homeTime = OslMalloc(WC_MAX_INDEX_INFO_LEN);
- foreTime = OslMalloc(WC_MAX_INDEX_INFO_LEN);
- guiBuffer = GetCurrGuiBuffer(SCR_ID_WC_BROWSE_CITY);
- if (guiBuffer == NULL) /* not goback from history */
- {
- ReadValue(NVRAM_TIMEZONE, &tmpTimeZone, DS_SHORT, &error);
- g_wc_cntx.CurrTZ = (FLOAT)tmpTimeZone / 4;
- }
- /* Check if the time zone and city are matched */
- if (g_wc_cntx.CurrTZ != TimeZoneData[g_wc_cntx.CurrCityIndex].CityTimeZone && g_wc_cntx.CurrCityIndex != 0)
- {
- g_wc_cntx.CurrCityIndex = mmi_wc_default_city_of_tz(g_wc_cntx.CurrTZ);
- ATSetHomeCity((U8) (g_wc_cntx.CurrCityIndex));
- g_wc_cntx.CurrTZ = TimeZoneData[g_wc_cntx.CurrCityIndex].CityTimeZone;
- }
- /* get time zone string */
- mmi_wc_get_tz_string(g_wc_cntx.CurrTZ, (S8*) & gIndexInfo[WC_TZ_INDEX][WC_GMT_LEN]);
- /* get Home city */
- mmi_wc_get_city_string(g_wc_cntx.CurrCityIndex);
- #ifdef __MMI_TOUCH_SCREEN__
- RegisterCat230PaintPenEventHandler(mmi_wc_paint_pen_handler);
- #endif
- ShowCategory230Screen(
- (U8*) GetString(STR_WORLD_CLOCK_TITLE),
- 2,
- gIndexInfo,
- 0,
- CAT230_WC_DT,
- mmi_wc_leftkey_handler,
- mmi_wc_rightkey_handler, /* Cat230RedrawPaint_WC, */
- mmi_wc_get_index_info);
- #endif /* __MMI_WC_TZ_SUPPORT__ */
- SetRightSoftkeyFunction(WcHandleRSK, KEY_EVENT_UP);
- #ifdef __MMI_WC_TZ_SUPPORT__
- if (mmi_wc_entry_from_phnset())
- {
- ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
- SetLeftSoftkeyFunction(PhnsetSetHomeCity, KEY_EVENT_UP); /* set home city */
- }
- else
- #endif /* __MMI_WC_TZ_SUPPORT__ */
- {
- #ifdef __MMI_WORLDCLOCK_DST__
- ChangeLeftSoftkey(STR_GLOBAL_OPTIONS, IMG_GLOBAL_OPTIONS);
- SetLeftSoftkeyFunction(WcEntryDST, KEY_EVENT_UP);
- #else /* __MMI_WORLDCLOCK_DST__ */
- ChangeLeftSoftkey(0, 0);
- #endif /* __MMI_WORLDCLOCK_DST__ */
- }
- ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
- SetKeyHandler(WcHandleKeyEnd, KEY_END, KEY_EVENT_DOWN);
- }
- #ifdef __MMI_WC_TZ_SUPPORT__
- /*****************************************************************************
- * FUNCTION
- * mmi_wc_get_index_info
- * DESCRIPTION
- * This function is used to get the index information.
- * PARAMETERS
- * index_info [?]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_wc_get_index_info(void *index_info)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- MYTIME currTime, foreignTime;
- cat230_paint_wc_info_struct *index_infomation = (cat230_paint_wc_info_struct*) index_info;
- U8 homeCity = PhnsetGetHomeCity() + 1;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- memset(&currTime, 0, sizeof(MYTIME));
- memset(&foreignTime, 0, sizeof(MYTIME));
- index_infomation->static_x = TimeZoneData[homeCity].CityX;
- index_infomation->static_y = TimeZoneData[homeCity].CityY;
- if (g_wc_cntx.CurrCityIndex == 0)
- {
- index_infomation->dynamic_x = -1;
- index_infomation->dynamic_y = -1;
- }
- else
- {
- index_infomation->dynamic_x = TimeZoneData[g_wc_cntx.CurrCityIndex].CityX;
- index_infomation->dynamic_y = TimeZoneData[g_wc_cntx.CurrCityIndex].CityY;
- }
- index_infomation->hint_string = (U8*) GetString(STR_WORLD_CLOCK_LOCAL);
- index_infomation->city_string = (U8*) GetString(TimeZoneData[homeCity].CityName);
- /* get date/time of home city */
- DTGetRTCTime(&currTime);
- mmi_wc_dt_format(&currTime, homeTime);
- index_infomation->static_string = homeTime;
- /* index_infomation->static_string = (U8*)GetString(STR_WORLD_CLOCK_LOCAL); */
- mmi_wc_get_foreign_city_dt(&foreignTime);
- mmi_wc_dt_format(&foreignTime, foreTime);
- index_infomation->dynamic_string = foreTime;
- /* index_infomation->dynamic_string = (U8*)GetString(STR_WORLD_CLOCK_LOCAL); */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_wc_dt_format
- * DESCRIPTION
- *
- * PARAMETERS
- * dt [?]
- * dtString [?]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_wc_dt_format(MYTIME *dt, U8 *dtString)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 ascii[WC_MAX_INDEX_INFO_LEN], UniStr[WC_MAX_INDEX_INFO_LEN];
- U8 sizeT = 0, sizeD = 0;
- UI_character_type separate = WC_SYM_COMMA;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- memset(dtString, 0, WC_MAX_INDEX_INFO_LEN);
- memset(UniStr, 0, WC_MAX_INDEX_INFO_LEN);
- memset(ascii, 0, WC_MAX_INDEX_INFO_LEN);
- date_string(dt, (UI_string_type) dtString, DT_IDLE_SCREEN_2);
- //UnicodeToAnsii((S8*) ascii, (S8*) dtString);
- //sizeD = strlen((S8*) ascii);
- sizeD = pfnUnicodeStrlen((S8*) dtString);
- memcpy(&(dtString[sizeD * 2]), &separate, sizeof(UI_character_type));
- sizeD++;
- memset(ascii, 0, WC_MAX_INDEX_INFO_LEN);
- time_string(dt, (UI_string_type) UniStr, DT_IDLE_SCREEN_2);
- //UnicodeToAnsii((S8*) ascii, (S8*) UniStr);
- //sizeT = strlen((S8*) ascii);
- sizeT = pfnUnicodeStrlen((S8*) UniStr);
- memcpy(&(dtString[sizeD * 2]), UniStr, sizeT * 2);
- /* UnicodeToAnsii((S8*) &(dtString[size]), (S8*) UniStr); */
- /*
- * time_string(&dt, (UI_string_type) UniStr, DT_IDLE_SCREEN);
- * UnicodeToAnsii((S8*) dtString, (S8*) UniStr);
- * size = strlen(dtString);
- * date_string(&dt, (UI_string_type)UniStr, DT_IDLE_SCREEN);
- * UnicodeToAnsii((S8*) &(dtString[size]), (S8*) UniStr);
- * AnsiiToUnicodeString(out_buffer, ansii_str);
- */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_wc_get_foreign_city_dt
- * DESCRIPTION
- *
- * PARAMETERS
- * dt [?]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_wc_get_foreign_city_dt(MYTIME *dt)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- MYTIME incTime;
- U8 HomeCity;
- FLOAT TimeDiff;
- U8 TimeFlag = 0;
- S32 temp;
- #ifdef __MMI_WORLDCLOCK_DST__
- MYTIME dstTime;
- #endif
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* get time zone difference */
- HomeCity = PhnsetGetHomeCity() + 1;
- /* TimeDiff = WcTimeZoneDiff(g_wc_cntx.CurrCityIndex, HomeCity); */
- TimeDiff = g_wc_cntx.CurrTZ - TimeZoneData[HomeCity].CityTimeZone;
- memset(&incTime, 0, sizeof(MYTIME));
- DTGetRTCTime(dt);
- if (TimeDiff < 0)
- {
- TimeDiff = TimeDiff * (-1);
- TimeFlag = 1;
- }
- temp = (S32) (TimeDiff * 60);
- incTime.nDay = (U8) (TimeDiff / 24);
- incTime.nHour = ((S32) TimeDiff) % 24;
- incTime.nMin = temp % 60;
- if (TimeFlag) /* decrement */
- {
- DecrementTime(*dt, incTime, dt);
- }
- else
- {
- IncrementTime(*dt, incTime, dt);
- }
- #ifdef __MMI_WORLDCLOCK_DST__
- if (HomeCity != g_wc_cntx.CurrCityIndex) /* not home city */
- {
- memset(&dstTime, 0, sizeof(MYTIME));
- dstTime.nHour = 1;
- if (g_wc_cntx.DSTForeign && g_phnset_cntx_p->currentDST) /* both date light saving is on */
- {
- /* do nothing */
- }
- else if (g_phnset_cntx_p->currentDST) /* only home city turns on DST */
- {
- DecrementTime(*dt, dstTime, dt);
- }
- else if (g_wc_cntx.DSTForeign) /* only foreign city turns on DST */
- {
- IncrementTime(*dt, dstTime, dt);
- }
- }
- #endif /* __MMI_WORLDCLOCK_DST__ */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_wc_leftkey_handler
- * DESCRIPTION
- *
- * PARAMETERS
- * index_num [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_wc_leftkey_handler(U8 index_num)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 curr_index;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- switch (index_num)
- {
- case WC_TZ_INDEX:
- if (g_wc_cntx.CurrTZ <= -12)
- {
- g_wc_cntx.CurrTZ = 12;
- }
- else
- {
- g_wc_cntx.CurrTZ--;
- }
- g_wc_cntx.CurrCityIndex = mmi_wc_default_city_of_tz(g_wc_cntx.CurrTZ);
- /* Modify the current time zone to the default city's time zone, ex: GMT 5.5 */
- if (g_wc_cntx.CurrTZ != TimeZoneData[g_wc_cntx.CurrCityIndex].CityTimeZone && g_wc_cntx.CurrCityIndex != 0)
- {
- g_wc_cntx.CurrTZ = TimeZoneData[g_wc_cntx.CurrCityIndex].CityTimeZone;
- }
- break;
- case WC_CITY_INDEX:
- /* a time zone without default city is selected as home city */
- if (g_wc_cntx.CurrCityIndex == 0)
- {
- while (g_wc_cntx.CurrCityIndex == 0)
- {
- if (g_wc_cntx.CurrTZ <= -12)
- {
- g_wc_cntx.CurrTZ = 12;
- }
- else
- {
- g_wc_cntx.CurrTZ--;
- }
- g_wc_cntx.CurrCityIndex = mmi_wc_default_city_of_tz(g_wc_cntx.CurrTZ);
- }
- break;
- }
- curr_index = WcGetCityPosition(g_wc_cntx.CurrCityIndex);
- if (curr_index == 0)
- {
- curr_index = (NUMBER_OF_CITY - 2);
- }
- else
- {
- curr_index--;
- }
- g_wc_cntx.CurrCityIndex = gWcTimeZoneIndex[curr_index];
- g_wc_cntx.CurrTZ = TimeZoneData[g_wc_cntx.CurrCityIndex].CityTimeZone;
- break;
- }
- /* get time zone string */
- mmi_wc_get_tz_string(g_wc_cntx.CurrTZ, (S8*) & gIndexInfo[WC_TZ_INDEX][WC_GMT_LEN]);
- mmi_wc_get_city_string(g_wc_cntx.CurrCityIndex);
- SetCat230IndexInfo(WC_TZ_INDEX, (U8*) gIndexInfo[WC_TZ_INDEX]);
- SetCat230IndexInfo(WC_CITY_INDEX, (U8*) gIndexInfo[WC_CITY_INDEX]);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_wc_rightkey_handler
- * DESCRIPTION
- *
- * PARAMETERS
- * index_num [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_wc_rightkey_handler(U8 index_num)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 curr_index;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- switch (index_num)
- {
- case WC_TZ_INDEX:
- if (g_wc_cntx.CurrTZ >= 12)
- {
- g_wc_cntx.CurrTZ = -12;
- }
- else
- {
- g_wc_cntx.CurrTZ++;
- }
- g_wc_cntx.CurrCityIndex = mmi_wc_default_city_of_tz(g_wc_cntx.CurrTZ);
- /* Modify the current time zone to the default city's time zone, ex: GMT 5.5 */
- if (g_wc_cntx.CurrTZ != TimeZoneData[g_wc_cntx.CurrCityIndex].CityTimeZone && g_wc_cntx.CurrCityIndex != 0)
- {
- g_wc_cntx.CurrTZ = TimeZoneData[g_wc_cntx.CurrCityIndex].CityTimeZone;
- }
- break;
- case WC_CITY_INDEX:
- if (g_wc_cntx.CurrCityIndex == 0)
- {
- while (g_wc_cntx.CurrCityIndex == 0)
- {
- if (g_wc_cntx.CurrTZ == 12)
- {
- g_wc_cntx.CurrTZ = -12;
- }
- else
- {
- g_wc_cntx.CurrTZ++;
- }
- g_wc_cntx.CurrCityIndex = mmi_wc_default_city_of_tz(g_wc_cntx.CurrTZ);
- }
- break;
- }
- curr_index = WcGetCityPosition(g_wc_cntx.CurrCityIndex);
- if (curr_index == (NUMBER_OF_CITY - 2))
- {
- curr_index = 0;
- }
- else
- {
- curr_index++;
- }
- g_wc_cntx.CurrCityIndex = gWcTimeZoneIndex[curr_index];
- g_wc_cntx.CurrTZ = TimeZoneData[g_wc_cntx.CurrCityIndex].CityTimeZone;
- break;
- }
- /* get time zone string */
- mmi_wc_get_tz_string(g_wc_cntx.CurrTZ, (S8*) & gIndexInfo[WC_TZ_INDEX][WC_GMT_LEN]);
- mmi_wc_get_city_string(g_wc_cntx.CurrCityIndex);
- SetCat230IndexInfo(WC_TZ_INDEX, (U8*) gIndexInfo[WC_TZ_INDEX]);
- SetCat230IndexInfo(WC_CITY_INDEX, (U8*) gIndexInfo[WC_CITY_INDEX]);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_wc_default_city_of_tz
- * DESCRIPTION
- *
- * PARAMETERS
- * tz [IN]
- * RETURNS
- *
- *****************************************************************************/
- U8 mmi_wc_default_city_of_tz(FLOAT tz)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U32 i;
- S16 TZmap = (S16) tz * 4;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- for (i = 0; i < WC_DEFAULT_TZ_NUM; i++)
- {
- if (validTZ[i] == TZmap)
- {
- return gWcDefaultCityForTZ[i];
- }
- }
- return 0xFF;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_wc_get_tz_string
- * DESCRIPTION
- *
- * PARAMETERS
- * tz [IN]
- * outStr [?]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_wc_get_tz_string(FLOAT tz, S8 *outStr)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- UI_character_type sym;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* U8* tmpStr; */
- if (g_wc_cntx.CurrTZ >= 0)
- {
- if (g_wc_cntx.CurrTZ == 0)
- {
- sym = WC_SYM_SPACE;
- }
- else
- {
- sym = WC_SYM_POSITIVE;
- }
- memcpy(outStr, &sym, sizeof(UI_character_type));
- tz = g_wc_cntx.CurrTZ;
- }
- else
- {
- sym = WC_SYM_NEGATIVE;
- memcpy(outStr, &sym, sizeof(UI_character_type));
- tz = -(g_wc_cntx.CurrTZ);
- }
- CalcDouble2String(tz, (S8*) & outStr[sizeof(UI_character_type)], WC_MAX_TZ_STR_LEN);
- //tmpStr = outStr;
- //CalcDouble2String(tz, (S8*) tmpStr, 1);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_wc_get_city_string
- * DESCRIPTION
- *
- * PARAMETERS
- * tz [IN]
- * outStr [?]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_wc_get_city_string(U8 cityIndex)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 *cityName;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- cityName = (U8*) GetString(TimeZoneData[g_wc_cntx.CurrCityIndex].CityName);
- /* if home city length to large */
- if (pfnUnicodeStrlen((S8*) cityName) >= WC_MAX_INDEX_INFO_LEN / ENCODING_LENGTH)
- {
- memcpy(gIndexInfo[WC_CITY_INDEX], cityName, WC_MAX_INDEX_INFO_LEN - ENCODING_LENGTH);
- pfnUnicodeStrcat((S8*)gIndexInfo[WC_CITY_INDEX], (S8*)L"