Calendar.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:160k
源码类别:

MTK

开发平台:

C/C++

  1.     /*----------------------------------------------------------------*/
  2.     /*----------------------------------------------------------------*/
  3.     /* Code Body                                                      */
  4.     /*----------------------------------------------------------------*/
  5.     return mmi_clndr_periodly_movement((U32) CLNDR_PRIVOUS_PERIOD);
  6. }
  7. /* void mmi_clndr_periodly_movement(CLNDR_CLNDAR_MOVEMENT type) */
  8. /*****************************************************************************
  9.  * FUNCTION
  10.  *  mmi_clndr_periodly_movement
  11.  * DESCRIPTION
  12.  *  
  13.  * PARAMETERS
  14.  *  type        [IN]        
  15.  * RETURNS
  16.  *  
  17.  *****************************************************************************/
  18. MMI_BOOL mmi_clndr_periodly_movement(U32 type)
  19. {
  20.     /*----------------------------------------------------------------*/
  21.     /* Local Variables                                                */
  22.     /*----------------------------------------------------------------*/
  23.     U32 highlightY;
  24.     /*----------------------------------------------------------------*/
  25.     /* Code Body                                                      */
  26.     /*----------------------------------------------------------------*/
  27.     highlightY = g_clndr_cntx->CurrPeriodIndex - g_clndr_cntx->PeriodStartIndex;
  28.     switch (type)
  29.     {
  30.         case CLNDR_NEXT_PERIOD:
  31.             /* the boundary of period */
  32.             if (g_clndr_cntx->PeriodStartIndex == g_clndr_cntx->RowNumber - CLNDR_ROW)
  33.             {
  34.                 return MMI_FALSE;
  35.             }
  36.             /* clndr_cntx->CalTime.nHour += g_clndr_cntx->PeriodInterval; */
  37.             g_clndr_cntx->PeriodStartIndex++;
  38.             if (highlightY > 0)
  39.             {
  40.                 highlightY--;
  41.             }
  42.             break;
  43.             /* return; */
  44.         case CLNDR_PRIVOUS_PERIOD:
  45.             /* the boundary of period */
  46.             if (g_clndr_cntx->PeriodStartIndex == 0)
  47.             {
  48.                 return MMI_FALSE;
  49.             }
  50.             /* clndr_cntx->CalTime.nHour -= g_clndr_cntx->PeriodInterval; */
  51.             g_clndr_cntx->PeriodStartIndex--;
  52.             if (highlightY < CLNDR_ROW - 1)
  53.             {
  54.                 highlightY++;
  55.             }
  56.             break;
  57.             /* return; */
  58.         case CLNDR_NEXT_MULTI_PERIOD:
  59.             g_clndr_cntx->PeriodStartIndex += CLNDR_ROW;
  60.             if (g_clndr_cntx->PeriodStartIndex >= g_clndr_cntx->RowNumber - CLNDR_ROW)
  61.             {
  62.                 g_clndr_cntx->PeriodStartIndex = g_clndr_cntx->RowNumber - CLNDR_ROW;
  63.             }
  64.             break;
  65.         case CLNDR_PRIVOUS_MULTI_PERIOD:
  66.             if (g_clndr_cntx->PeriodStartIndex <= CLNDR_ROW)
  67.             {
  68.                 g_clndr_cntx->PeriodStartIndex = 0;
  69.             }
  70.             else
  71.             {
  72.                 g_clndr_cntx->PeriodStartIndex -= CLNDR_ROW;
  73.             }
  74.             break;
  75.         default:
  76.             ASSERT(0);
  77.     }
  78.     mmi_clndr_get_period_range(g_clndr_cntx->PeriodStartIndex, g_clndr_cntx->VerticalList);
  79.     wgui_cat83_set_select_vertical(
  80.         IMG_TOP_UP,
  81.         IMG_TOP_DOWN,
  82.         IMG_BOTTOM_UP,
  83.         IMG_BOTTOM_DOWN,
  84.         g_clndr_cntx->VerticalList,
  85.         CAT83_SELECT_ALIGN_LINE);
  86.     mmi_clndr_weekly_set_content();
  87.     wgui_cat83_set_highlight(highlightY, g_clndr_cntx->CalTime.DayIndex);
  88.     return MMI_TRUE;
  89. }
  90. #endif /* __MMI_TOUCH_SCREEN__ */ 
  91. #endif /* __MMI_CLNDR_WEEKLY_VIEW_SUPPORT__ */ 
  92. #ifdef __MMI_TODOLIST__
  93. /*****************************************************************************
  94.  * FUNCTION
  95.  *  mmi_prepare_for_add_task
  96.  * DESCRIPTION
  97.  *  
  98.  * PARAMETERS
  99.  *  void
  100.  * RETURNS
  101.  *  void
  102.  *****************************************************************************/
  103. void mmi_prepare_for_add_task(void)
  104. {
  105.     /*----------------------------------------------------------------*/
  106.     /* Local Variables                                                */
  107.     /*----------------------------------------------------------------*/
  108.     /*----------------------------------------------------------------*/
  109.     /* Code Body                                                      */
  110.     /*----------------------------------------------------------------*/
  111.     mmi_tdl_set_clndr(&g_clndr_cntx->CalTime, g_clndr_cntx->DisplayType);
  112.     /* TDLAddDefaultRecord(); */
  113.     mmi_tdl_entry_select_task_type();
  114. }
  115. /*****************************************************************************
  116.  * FUNCTION
  117.  *  mmi_clndr_highlight_add_task
  118.  * DESCRIPTION
  119.  *  
  120.  * PARAMETERS
  121.  *  void
  122.  * RETURNS
  123.  *  void
  124.  *****************************************************************************/
  125. void mmi_clndr_highlight_add_task(void)
  126. {
  127.     /*----------------------------------------------------------------*/
  128.     /* Local Variables                                                */
  129.     /*----------------------------------------------------------------*/
  130.     /*----------------------------------------------------------------*/
  131.     /* Code Body                                                      */
  132.     /*----------------------------------------------------------------*/
  133.     g_tdl_cntx.CurrHiliteOption = TODO_LIST_TASK_OPTION_ADD;    /* set tdl option as "ADD" */
  134.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  135.     SetKeyHandler(mmi_prepare_for_add_task, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  136.     SetLeftSoftkeyFunction(mmi_prepare_for_add_task, KEY_EVENT_UP);
  137.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  138. }
  139. #endif /* __MMI_TODOLIST__ */ 
  140. #ifdef __MMI_CLNDR_ICON_SUPPORT__
  141. /*****************************************************************************
  142.  * FUNCTION
  143.  *  mmi_momthly_clndr_set_info_box
  144.  * DESCRIPTION
  145.  *  
  146.  * PARAMETERS
  147.  *  void
  148.  * RETURNS
  149.  *  void
  150.  *****************************************************************************/
  151. void mmi_momthly_clndr_set_info_box(void)
  152. {
  153.     /*----------------------------------------------------------------*/
  154.     /* Local Variables                                                */
  155.     /*----------------------------------------------------------------*/
  156.     clndr_task_icon_struct task;
  157.     /* ToDoListNode todoItem; */
  158.     U8 taskNum[6];  /* two digits number */
  159.     S8 timeString[CLNDR_TIME_STRING_LENGTH * 2 + 1 + 1];    /* HH:MM-HH:MM */
  160. #ifdef __MMI_BIRTHDAY_REMINDER__    
  161.     U8 pbNumber[MAX_PB_NUMBER_LENGTH + 1], pbName[(MAX_PB_NAME_LENGTH +1 )* ENCODING_LENGTH];
  162.     U8 maxStrLen;
  163. #endif
  164.     /*----------------------------------------------------------------*/
  165.     /* Code Body                                                      */
  166.     /*----------------------------------------------------------------*/
  167.     memset(g_clndr_cntx->info_box_text[0], 0, CLNDR_MAX_INFO_BOX_LEN + ENCODING_LENGTH);
  168.     memset(g_clndr_cntx->info_box_text[1], 0, CLNDR_MAX_INFO_BOX_LEN + ENCODING_LENGTH);
  169.     g_clndr_cntx->info_box_icon[0] = 0;
  170.     g_clndr_cntx->info_box_icon[1] = 0;
  171.     memcpy(&task, &(g_clndr_cntx->TaskDayList[g_clndr_cntx->CalTime.nDay]), sizeof(clndr_task_icon_struct));
  172. #ifdef __MMI_BIRTHDAY_REMINDER__
  173.     if (g_clndr_cntx->BirthdayInfo[g_clndr_cntx->CalTime.nDay].count > 0)       /* someone's birthday */
  174.     {
  175.         /* birthday reminder */
  176.         g_clndr_cntx->info_box_icon[0] = IMG_CLNDR_BIRTHDAY_REMINDER;
  177.         memset(pbNumber, 0, MAX_PB_NUMBER_LENGTH + 1);
  178.         memset(pbName, 0, (MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH);
  179.         mmi_phb_get_name_number(
  180.             g_clndr_cntx->BirthdayInfo[g_clndr_cntx->CalTime.nDay].firstMatchedIndex,
  181.             pbName,
  182.             pbNumber);
  183.         pfnUnicodeStrcpy((S8*) g_clndr_cntx->info_box_text[0], (PS8) L"(");
  184.         mmi_clndr_util_num_to_unicode(g_clndr_cntx->BirthdayInfo[g_clndr_cntx->CalTime.nDay].count, taskNum, 3);
  185.         pfnUnicodeStrcat((S8*) g_clndr_cntx->info_box_text[0], (S8*) taskNum);
  186.         pfnUnicodeStrcat((S8*) g_clndr_cntx->info_box_text[0], (PS8) L") ");
  187.         maxStrLen = (CLNDR_MAX_INFO_BOX_LEN / ENCODING_LENGTH) - pfnUnicodeStrlen((S8*)L"() ") - pfnUnicodeStrlen((S8*)taskNum);
  188.         if(pfnUnicodeStrlen((S8*)pbName) > maxStrLen)
  189.         {
  190.             pfnUnicodeStrncat((S8*)g_clndr_cntx->info_box_text[0], (S8*)pbName, (U32)maxStrLen);
  191.         }
  192.         else
  193.         {
  194.             pfnUnicodeStrcat((S8*)g_clndr_cntx->info_box_text[0], (S8*)pbName);
  195.         }
  196.         
  197.         /* todo reminder */
  198.         if (task.date > 0)
  199.         {
  200.             g_clndr_cntx->info_box_icon[1] = task.icon;
  201.                        
  202.             pfnUnicodeStrcpy((S8*) g_clndr_cntx->info_box_text[1], (PS8) L"(");
  203.             mmi_clndr_util_num_to_unicode(task.date, taskNum, 3);
  204.             pfnUnicodeStrcat((S8*) g_clndr_cntx->info_box_text[1], (S8*) taskNum);
  205.             pfnUnicodeStrcat((S8*) g_clndr_cntx->info_box_text[1], (PS8) L") ");
  206.             if(pfnUnicodeStrlen((S8*)task.maxPriorityTask->Note) > maxStrLen)
  207.             {
  208.                 pfnUnicodeStrncat((S8*)g_clndr_cntx->info_box_text[1], (S8*)task.maxPriorityTask->Note, (U32)maxStrLen);
  209.             }
  210.             else
  211.             {
  212.                 pfnUnicodeStrcat((S8*)g_clndr_cntx->info_box_text[1], (S8*)task.maxPriorityTask->Note);
  213.             }
  214.         }
  215.     }
  216.     else
  217. #endif /* __MMI_BIRTHDAY_REMINDER__ */ 
  218.     if (task.date > 0)
  219.     {
  220.         g_clndr_cntx->info_box_icon[0] = IMG_CLNDR_TASK_CLOCK;
  221.         memset(timeString, 0, CLNDR_TIME_STRING_LENGTH * 2 + 1 + 1);
  222.         mmi_tdl_get_time_string(
  223.             task.maxPriorityTask,
  224.             &(g_clndr_cntx->CalTime),
  225.             timeString);
  226.         AnsiiToUnicodeString((S8*) g_clndr_cntx->info_box_text[0], (S8*) timeString);
  227.         pfnUnicodeStrcat((S8*) g_clndr_cntx->info_box_text[0], (PS8) L"(");
  228.         mmi_clndr_util_num_to_unicode(task.date, taskNum, 2);
  229.         pfnUnicodeStrcat((S8*) g_clndr_cntx->info_box_text[0], (S8*) taskNum);
  230.         pfnUnicodeStrcat((S8*) g_clndr_cntx->info_box_text[0], (PS8) L"-1)");
  231.         g_clndr_cntx->info_box_icon[1] = task.icon;
  232.         memcpy(g_clndr_cntx->info_box_text[1], task.maxPriorityTask->Note, CLNDR_MAX_INFO_BOX_LEN);
  233.     }
  234.     else
  235.     {
  236.         g_clndr_cntx->info_box_icon[0] = 0;
  237.         g_clndr_cntx->info_box_icon[1] = 0;
  238.     }
  239.     wgui_cat83_set_infobox(g_clndr_cntx->info_box_icon, g_clndr_cntx->info_box_text, CLNDR_INFO_BOX_ROW);
  240. }
  241. /*****************************************************************************
  242.  * FUNCTION
  243.  *  mmi_weekly_clndr_set_info_box
  244.  * DESCRIPTION
  245.  *  
  246.  * PARAMETERS
  247.  *  void
  248.  * RETURNS
  249.  *  void
  250.  *****************************************************************************/
  251. void mmi_weekly_clndr_set_info_box(void)
  252. {
  253.     /*----------------------------------------------------------------*/
  254.     /* Local Variables                                                */
  255.     /*----------------------------------------------------------------*/
  256.     clndr_task_icon_struct task;
  257.     ToDoListNode todoItem;
  258.     U8 taskNum[6];                                          /* two digits number */
  259.     S8 timeString[CLNDR_TIME_STRING_LENGTH * 2 + 1 + 1];    /* hh:mm-hh:mm */
  260.     U32 index;
  261.     /*----------------------------------------------------------------*/
  262.     /* Code Body                                                      */
  263.     /*----------------------------------------------------------------*/
  264.     memset(g_clndr_cntx->info_box_text[0], 0, CLNDR_MAX_INFO_BOX_LEN + ENCODING_LENGTH);
  265.     memset(g_clndr_cntx->info_box_text[1], 0, CLNDR_MAX_INFO_BOX_LEN + ENCODING_LENGTH);
  266.     index = g_clndr_cntx->CurrPeriodIndex * CLNDR_COLUMN + g_clndr_cntx->CalTime.DayIndex;
  267.     memcpy(&task, &(g_clndr_cntx->TaskDayList[index]), sizeof(clndr_task_icon_struct));
  268.     if (task.date > 0)
  269.     {
  270.         memcpy(&todoItem, task.maxPriorityTask, sizeof(ToDoListNode));
  271.         g_clndr_cntx->info_box_icon[0] = IMG_CLNDR_TASK_CLOCK;
  272.         memset(timeString, 0, CLNDR_TIME_STRING_LENGTH * 2 + 1 + 1);
  273.         
  274.         /* start time */
  275.         mmi_tdl_get_time_string(
  276.             task.maxPriorityTask,
  277.             &(g_clndr_cntx->CalTime),
  278.             timeString);
  279.         AnsiiToUnicodeString((S8*) g_clndr_cntx->info_box_text[0], timeString);
  280.         
  281.         pfnUnicodeStrcat((S8*) g_clndr_cntx->info_box_text[0], (PS8) L"(");
  282.         mmi_clndr_util_num_to_unicode(task.date, taskNum, 2);
  283.         pfnUnicodeStrcat((S8*) g_clndr_cntx->info_box_text[0], (S8*) taskNum);
  284.         pfnUnicodeStrcat((S8*) g_clndr_cntx->info_box_text[0], (PS8) L"-1)");
  285.  g_clndr_cntx->info_box_icon[1] = todoItem.Type + IMG_CLNDR_ICON_REMINDER;
  286.         memcpy(g_clndr_cntx->info_box_text[1], task.maxPriorityTask->Note, CLNDR_MAX_INFO_BOX_LEN);
  287.         //g_clndr_cntx->info_box_icon[1] = task.maxPriorityTask->Type + IMG_CLNDR_ICON_MEETING;
  288.         //memcpy(g_clndr_cntx->info_box_text[1],task.maxPriorityTask->Note, CLNDR_MAX_INFO_BOX_LEN);
  289.     }
  290.     else
  291.     {
  292.         g_clndr_cntx->info_box_icon[0] = 0;
  293.         g_clndr_cntx->info_box_icon[1] = 0;
  294.         /* g_clndr_cntx->info_box_icon[1] = NULL; */
  295.     }
  296.     wgui_cat83_set_infobox(g_clndr_cntx->info_box_icon, g_clndr_cntx->info_box_text, CLNDR_INFO_BOX_ROW);
  297. }
  298. #endif /* __MMI_CLNDR_ICON_SUPPORT__ */ 
  299. #else /* __MMI_CALENDAR_V2__ */ 
  300. /*****************************************************************************
  301.  * FUNCTION
  302.  *  HighlightClndrDate
  303.  * DESCRIPTION
  304.  *  Highlight handler of a date on calendar
  305.  * PARAMETERS
  306.  *  date        [IN]        
  307.  * RETURNS
  308.  *  void
  309.  *****************************************************************************/
  310. void HighlightClndrDate(S32 date)
  311. {
  312.     /*----------------------------------------------------------------*/
  313.     /* Local Variables                                                */
  314.     /*----------------------------------------------------------------*/
  315.     /*----------------------------------------------------------------*/
  316.     /* Code Body                                                      */
  317.     /*----------------------------------------------------------------*/
  318.     g_clndr_cntx->CalTime.nDay = (U8) date;
  319. }
  320. #endif /* __MMI_CALENDAR_V2__ */ 
  321. /*****************************************************************************
  322.  * FUNCTION
  323.  *  mmi_clndr_set_date
  324.  * DESCRIPTION
  325.  *  
  326.  * PARAMETERS
  327.  *  date        [?]     
  328.  * RETURNS
  329.  *  void
  330.  *****************************************************************************/
  331. void mmi_clndr_set_date(MYTIME *date)
  332. {
  333.     /*----------------------------------------------------------------*/
  334.     /* Local Variables                                                */
  335.     /*----------------------------------------------------------------*/
  336.     /*----------------------------------------------------------------*/
  337.     /* Code Body                                                      */
  338.     /*----------------------------------------------------------------*/
  339.     if (g_clndr_cntx != NULL)
  340.     {
  341.         memcpy(&(g_clndr_cntx->CalTime), date, sizeof(MYTIME));
  342.     }
  343. }
  344. /*****************************************************************************
  345.  * FUNCTION
  346.  *  ClndrInit
  347.  * DESCRIPTION
  348.  *  Register highlight handlers
  349.  * PARAMETERS
  350.  *  void
  351.  * RETURNS
  352.  *  void
  353.  *****************************************************************************/
  354. void ClndrInit(void)
  355. {
  356.     /*----------------------------------------------------------------*/
  357.     /* Local Variables                                                */
  358.     /*----------------------------------------------------------------*/
  359.     /*----------------------------------------------------------------*/
  360.     /* Code Body                                                      */
  361.     /*----------------------------------------------------------------*/
  362.     SetHiliteHandler(ORGANIZER_CALENDER_MENU, HighlightClndrMenu);
  363.     SetHintHandler(MENU_CAL_TYPE, ClndrLunarHintHandler);
  364.     SetHiliteHandler(MENU_GOTO_TASK_CAL, HighlightClndrViewTask);
  365.     SetHiliteHandler(MENU_CAL_TYPE, HighlightClndrLunar);
  366.     SetHiliteHandler(MENU_ID_CLNDR_JUMP_TO_DATE, HighlightJumpToDate);
  367. #ifdef __MMI_CALENDAR_V2__
  368. #ifdef __MMI_CLNDR_WEEKLY_VIEW_SUPPORT__
  369.     SetHiliteHandler(MENU_ID_CLNDR_MONTHLY_VIEW, mmi_clndr_highlight_monthly_view);
  370.     SetHiliteHandler(MENU_ID_CLNDR_WEEKLY_VIEW, mmi_clndr_highlight_weekly_view);
  371. #endif /* __MMI_CLNDR_WEEKLY_VIEW_SUPPORT__ */ 
  372.     SetHiliteHandler(MENU_ID_CLNDR_ADD_TASK, mmi_clndr_highlight_add_task);
  373. #endif /* __MMI_CALENDAR_V2__ */ 
  374. }
  375. /*****************************************************************************
  376.  * FUNCTION
  377.  *  ClndrDeInit
  378.  * DESCRIPTION
  379.  *  Free allocated memory
  380.  * PARAMETERS
  381.  *  void
  382.  * RETURNS
  383.  *  void
  384.  *****************************************************************************/
  385. void ClndrDeInit(void)
  386. {
  387.     /*----------------------------------------------------------------*/
  388.     /* Local Variables                                                */
  389.     /*----------------------------------------------------------------*/
  390.     /*----------------------------------------------------------------*/
  391.     /* Code Body                                                      */
  392.     /*----------------------------------------------------------------*/
  393.     if (g_clndr_cntx)
  394.     {
  395.         OslMfree(g_clndr_cntx);
  396.         g_clndr_cntx = NULL;
  397.     }
  398. }
  399. /*****************************************************************************
  400.  * FUNCTION
  401.  *  HighlightClndrMenu
  402.  * DESCRIPTION
  403.  *  Highlight handler of Calendar menu item.
  404.  *  Register key handlers.
  405.  * PARAMETERS
  406.  *  void
  407.  * RETURNS
  408.  *  void
  409.  *****************************************************************************/
  410. void HighlightClndrMenu(void)
  411. {
  412.     /*----------------------------------------------------------------*/
  413.     /* Local Variables                                                */
  414.     /*----------------------------------------------------------------*/
  415.     /*----------------------------------------------------------------*/
  416.     /* Code Body                                                      */
  417.     /*----------------------------------------------------------------*/
  418.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  419.     ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
  420.     SetLeftSoftkeyFunction(ClndrPreEntryApp, KEY_EVENT_UP);
  421.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  422.     SetKeyHandler(ClndrPreEntryApp, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  423.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  424. }
  425. #define CLNDR_APP_SCREEN
  426. /*****************************************************************************
  427.  * FUNCTION
  428.  *  ClndrPreEntryApp
  429.  * DESCRIPTION
  430.  *  Initialize variables and go to calendar screen.
  431.  * PARAMETERS
  432.  *  void
  433.  * RETURNS
  434.  *  void
  435.  *****************************************************************************/
  436. void ClndrPreEntryApp(void)
  437. {
  438.     /*----------------------------------------------------------------*/
  439.     /* Local Variables                                                */
  440.     /*----------------------------------------------------------------*/
  441.     MYTIME currentTime;
  442.     S16 error;
  443.     /*----------------------------------------------------------------*/
  444.     /* Code Body                                                      */
  445.     /*----------------------------------------------------------------*/
  446.     if (g_clndr_cntx == NULL)
  447.     {
  448.         g_clndr_cntx = OslMalloc(sizeof(clndr_context_struct));
  449.     }
  450.     GetDateTime(&currentTime);
  451.     memset(&g_clndr_cntx->CalTime, 0, sizeof(MYTIME));
  452.     g_clndr_cntx->CalTime.nDay = currentTime.nDay;
  453.     g_clndr_cntx->CalTime.nMonth = currentTime.nMonth;
  454.     g_clndr_cntx->CalTime.nYear = currentTime.nYear;
  455. #ifdef __MMI_CLNDR_WEEKLY_VIEW_SUPPORT__
  456.     g_clndr_cntx->CalTime.nHour = currentTime.nHour;
  457.     ReadValue(NVRAM_CLNDR_PERIOD_INTERVAL, &(g_clndr_cntx->PeriodInterval), DS_BYTE, &error);
  458.     if (g_clndr_cntx->PeriodInterval == 0 || g_clndr_cntx->PeriodInterval == 0xFF)
  459.     {
  460.         g_clndr_cntx->PeriodInterval = CLNDR_WEEKLY_PERIOD_INTERVAL;
  461.         WriteValue(NVRAM_CLNDR_PERIOD_INTERVAL, &(g_clndr_cntx->PeriodInterval), DS_BYTE, &error);
  462.     }
  463.     
  464.     g_clndr_cntx->PeriodStartIndex = (currentTime.nHour / g_clndr_cntx->PeriodInterval);
  465. #endif /* __MMI_CLNDR_WEEKLY_VIEW_SUPPORT__ */ 
  466.     /* lunar state */
  467.     ReadValue(LUNAR_CALENDAR, (void*)&g_clndr_cntx->LunarState, DS_BYTE, &error);
  468.     if (g_clndr_cntx->LunarState != TRUE)
  469.     {
  470.         g_clndr_cntx->LunarState = FALSE;
  471.     }
  472. #ifdef __MMI_CALENDAR_V2__
  473.     g_clndr_cntx->DisplayType = CLNDR_MONTHLY_VIEW;
  474.     g_clndr_cntx->RowNumber = CLNDR_ROW;
  475. #endif /* __MMI_CALENDAR_V2__ */ 
  476.     EntryClndrScreen();
  477. }
  478. /*****************************************************************************
  479.  * FUNCTION
  480.  *  UpdateClndrContext
  481.  * DESCRIPTION
  482.  *  Callback from GUI layer to update calendar application
  483.  * PARAMETERS
  484.  *  day         [IN]        
  485.  *  month       [IN]        
  486.  *  year        [IN]        
  487.  * RETURNS
  488.  *  void
  489.  *****************************************************************************/
  490. void UpdateClndrContext(S32 day, S32 month, S32 year)
  491. {
  492.     /*----------------------------------------------------------------*/
  493.     /* Local Variables                                                */
  494.     /*----------------------------------------------------------------*/
  495.     MYTIME myTime;
  496. #ifndef __MMI_CLNDR_ICON_SUPPORT__    
  497.    S32 i;
  498. #endif
  499.     /*----------------------------------------------------------------*/
  500.     /* Code Body                                                      */
  501.     /*----------------------------------------------------------------*/
  502.     g_clndr_cntx->CalTime.nDay = day;
  503.     g_clndr_cntx->CalTime.nMonth = month;
  504.     g_clndr_cntx->CalTime.nYear = year;
  505.     /* get the list of days to be highlithed */
  506.     memset(&myTime, 0, sizeof(MYTIME));
  507. #ifdef __MMI_TODOLIST__
  508.     myTime.nYear = g_clndr_cntx->CalTime.nYear;
  509.     myTime.nMonth = g_clndr_cntx->CalTime.nMonth;
  510.     myTime.nDay = g_clndr_cntx->CalTime.nDay;
  511. #ifdef __MMI_CLNDR_ICON_SUPPORT__
  512. #else /* __MMI_CLNDR_ICON_SUPPORT__ */ 
  513.     TDLGetDaysToBeHilited(myTime, g_clndr_cntx->TaskDayList);
  514.     if (g_clndr_cntx->TaskDayList[0] != CLNDR_MAX_DAYS)
  515.     {
  516.         for (i = 1; i <= g_clndr_cntx->TaskDayList[0]; i++)
  517.         {
  518.             SetCalendarDay(g_clndr_cntx->TaskDayList[i], CALENDAR_TASK_DAY);
  519.         }
  520.     }
  521.     else
  522.     {
  523.         for (i = 1; i <= CLNDR_MAX_DAYS; i++)
  524.         {
  525.             SetCalendarDay(i, CALENDAR_TASK_DAY);
  526.         }
  527.     }
  528. #endif /* __MMI_CLNDR_ICON_SUPPORT__ */ 
  529. #endif /* __MMI_TODOLIST__ */ 
  530.     /* browsing to current month */
  531.     GetDateTime(&myTime);
  532.     if (myTime.nMonth == month && myTime.nYear == year)
  533.     {
  534.         SetCalendarDay(myTime.nDay, CALENDAR_CURRENT_DAY);
  535.     }
  536.     if (g_clndr_cntx->LunarState == TRUE && IsChineseSet())
  537.     {
  538.         g_clndr_cntx->LunarInfo.SolarMonth = g_clndr_cntx->CalTime.nMonth;
  539.         g_clndr_cntx->LunarInfo.SolarYear = g_clndr_cntx->CalTime.nYear;
  540.         g_clndr_cntx->LunarInfo.SolarDay = g_clndr_cntx->CalTime.nDay;
  541.         ClndrComputeLunarInfo(&g_clndr_cntx->LunarInfo);
  542.         SetCalendarPopupDay(
  543.             g_clndr_cntx->LunarInfo.SolarDay,
  544.             (U8*) g_clndr_cntx->LunarInfo.MessageLine1,
  545.             (U8*) g_clndr_cntx->LunarInfo.MessageLine2,
  546.             (U8*) g_clndr_cntx->LunarInfo.MessageLine3);
  547.         SetCategory82Title1((U8*) g_clndr_cntx->LunarInfo.TitleInfo1); /* OR calInfo.totlestring */
  548.         SetCategory82Title3((U8*) g_clndr_cntx->LunarInfo.TitleInfo2);
  549.     }
  550. }
  551. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  552. U16 g_image_list[3];
  553. U8 *g_description_list[3];
  554. /*****************************************************************************
  555.  * FUNCTION
  556.  *  ClndrUpdateInfoBox
  557.  * DESCRIPTION
  558.  *  
  559.  * PARAMETERS
  560.  *  num_info                [?]         [?]         [?]
  561.  *  icon_list               [IN]        
  562.  *  description_list        [IN]        
  563.  * RETURNS
  564.  *  void
  565.  *****************************************************************************/
  566. void ClndrUpdateInfoBox(S32 *num_info, U16 **icon_list, U8 ***description_list)
  567. {
  568.     /*----------------------------------------------------------------*/
  569.     /* Local Variables                                                */
  570.     /*----------------------------------------------------------------*/
  571.     /*----------------------------------------------------------------*/
  572.     /* Code Body                                                      */
  573.     /*----------------------------------------------------------------*/
  574.     *num_info = 3;
  575.     g_description_list[0] = (U8*) g_clndr_cntx->LunarInfo.MessageLine1;
  576.     g_description_list[1] = (U8*) g_clndr_cntx->LunarInfo.MessageLine2;
  577.     g_description_list[2] = (U8*) g_clndr_cntx->LunarInfo.MessageLine3;
  578.     *description_list = g_description_list;
  579.     g_image_list[0] = g_image_list[1] = g_image_list[2] = 0;
  580.     *icon_list = g_image_list;
  581. }
  582. #endif /* __MMI_UI_CALENDAR_WITH_INFO_BOX__ */ 
  583. /*****************************************************************************
  584.  * FUNCTION
  585.  *  EntryClndrScreen
  586.  * DESCRIPTION
  587.  *  Display calendar screen.
  588.  * PARAMETERS
  589.  *  void
  590.  * RETURNS
  591.  *  void
  592.  *****************************************************************************/
  593. void EntryClndrScreen(void)
  594. {
  595.     /*----------------------------------------------------------------*/
  596.     /* Local Variables                                                */
  597.     /*----------------------------------------------------------------*/
  598.     MYTIME myTime;
  599. #ifdef __MMI_CALENDAR_V2__
  600.     S32 j, highlightCell, currCell = -1;
  601.     wgui_cat83_cell_struct *startCell;
  602. #else
  603.     U8 lunarOptionInternal;    
  604. #ifdef __MMI_TODOLIST__
  605.     S32 i;
  606. #endif     
  607. #endif /* __MMI_CALENDAR_V2__ */ 
  608.     /*----------------------------------------------------------------*/
  609.     /* Code Body                                                      */
  610.     /*----------------------------------------------------------------*/
  611. #ifdef __MMI_CALENDAR_V2__
  612.     EntryNewScreen(SCR_ID_CLNDR_SCREEN, ExitClndrScreen, EntryClndrScreen, NULL);
  613.     g_clndr_cntx->Title = mmi_frm_scrmem_alloc(CLNDR_TITLE_LEN * CLNDR_COLUMN);
  614.     g_clndr_cntx->HorizonList[0] =
  615.         (U8*) mmi_frm_scrmem_alloc(CLNDR_HORIZON_LIST_CELL_LEN * ENCODING_LENGTH * CLNDR_COLUMN);
  616.     g_clndr_cntx->VerticalList[0] =
  617.         (U8*) mmi_frm_scrmem_alloc(CLNDR_VERTICAL_LIST_CELL_LEN * ENCODING_LENGTH * CLNDR_ROW);
  618.     g_clndr_cntx->CalendarCell = mmi_frm_scrmem_alloc((g_clndr_cntx->RowNumber * CLNDR_COLUMN) * CLNDR_CELL_SIZE);
  619.     /* allocate memory for reminder */
  620.     g_clndr_cntx->info_box_text[0] = OslMalloc(CLNDR_MAX_INFO_BOX_LEN + ENCODING_LENGTH);
  621.     g_clndr_cntx->info_box_text[1] = OslMalloc(CLNDR_MAX_INFO_BOX_LEN + ENCODING_LENGTH);
  622.     for (j = 1; j < CLNDR_COLUMN; j++)
  623.     {
  624.         g_clndr_cntx->HorizonList[j] = g_clndr_cntx->HorizonList[j - 1] + CLNDR_HORIZON_LIST_CELL_LEN * ENCODING_LENGTH;
  625.     }
  626.     for (j = 1; j < CLNDR_ROW; j++)
  627.     {
  628.         g_clndr_cntx->VerticalList[j] =
  629.             g_clndr_cntx->VerticalList[j - 1] + CLNDR_VERTICAL_LIST_CELL_LEN * ENCODING_LENGTH;
  630.     }
  631.     /* reset memory */
  632.     memset(g_clndr_cntx->Title, 0, CLNDR_TITLE_LEN * CLNDR_COLUMN);
  633.     memset(g_clndr_cntx->HorizonList[0], 0, CLNDR_HORIZON_LIST_CELL_LEN * ENCODING_LENGTH * CLNDR_COLUMN);
  634.     memset(g_clndr_cntx->VerticalList[0], 0, CLNDR_VERTICAL_LIST_CELL_LEN * ENCODING_LENGTH * CLNDR_ROW);
  635.     memset(g_clndr_cntx->CalendarCell, 0, g_clndr_cntx->RowNumber * CLNDR_COLUMN * CLNDR_CELL_SIZE);
  636.     ClndrGetScreenInfo();
  637.     wgui_cat83_set_horizontal_string(g_clndr_cntx->HorizonList);
  638.     if (g_clndr_cntx->DisplayType == CLNDR_MONTHLY_VIEW)
  639.     {
  640.         highlightCell = g_clndr_cntx->DayOnFirst + g_clndr_cntx->CalTime.nDay - 1;
  641.         /* set current date */
  642.         GetDateTime(&myTime);
  643.         if (myTime.nMonth == g_clndr_cntx->CalTime.nMonth && myTime.nYear == g_clndr_cntx->CalTime.nYear)
  644.         {
  645.             currCell = g_clndr_cntx->DayOnFirst + myTime.nDay - 1;
  646.         }
  647.         wgui_cat83_register_cell_highlight_handler(mmi_clndr_monthly_highlight);
  648.         wgui_cat83_register_left_arrow_key_handler(mmi_clndr_left_out_of_boundary);
  649.         wgui_cat83_register_right_arrow_key_handler(mmi_clndr_right_out_of_boundary);
  650.         wgui_cat83_register_up_arrow_key_handler(mmi_clndr_up_out_of_boundary);
  651.         wgui_cat83_register_down_arrow_key_handler(mmi_clndr_down_out_of_boundary);
  652.         wgui_cat83_register_up_side_key_handler(mmi_clndr_up_side_key);
  653.         wgui_cat83_register_down_side_key_handler(mmi_clndr_down_side_key);
  654.     #ifdef __MMI_TOUCH_SCREEN__
  655.         wgui_cat83_set_select_horizontal1_handler(mmi_clndr_touch_year_decrease, mmi_clndr_touch_year_increase);
  656.         wgui_cat83_set_select_horizontal2_handler(mmi_clndr_touch_month_decrease, mmi_clndr_touch_month_increase);
  657.     #endif
  658.         mmi_momthly_clndr_set_info_box();
  659.         mmi_clndr_monthly_set_content();
  660.         ShowCategory83Screen(
  661.             IMG_CALENDAR_JAN,
  662.             (U8 **) g_clndr_cntx->HorizonList,
  663.             (wgui_cat83_cell_struct*) g_clndr_cntx->CalendarCell,
  664.             CLNDR_ROW,
  665.             CLNDR_COLUMN,
  666.             currCell / CLNDR_COLUMN,
  667.             currCell % CLNDR_COLUMN,
  668.             highlightCell / CLNDR_COLUMN,
  669.             highlightCell % CLNDR_COLUMN,
  670.             CAT83_CELL_BG_FILL_HORIZONTAL,
  671.             CAT83_CELL_TEXT_DISPLAY_LEFT_BOTTOM,
  672.             CAT83_CELL_ICON_DISPLAY_RIGHT_TOP);
  673.     }
  674. #ifdef __MMI_CLNDR_WEEKLY_VIEW_SUPPORT__
  675.     else if (g_clndr_cntx->DisplayType == CLNDR_WEEKLY_VIEW)
  676.     {
  677.         wgui_cat83_register_cell_highlight_handler(mmi_clndr_weekly_highlight);
  678.         wgui_cat83_register_left_arrow_key_handler(mmi_clndr_left_out_of_boundary);
  679.         wgui_cat83_register_right_arrow_key_handler(mmi_clndr_right_out_of_boundary);
  680.         wgui_cat83_register_up_arrow_key_handler(mmi_clndr_up_out_of_boundary);
  681.         wgui_cat83_register_down_arrow_key_handler(mmi_clndr_down_out_of_boundary);
  682.         wgui_cat83_register_up_side_key_handler(mmi_clndr_weekly_decrease);
  683.         wgui_cat83_register_down_side_key_handler(mmi_clndr_weekly_increase);
  684.     #ifdef __MMI_TOUCH_SCREEN__
  685.         wgui_cat83_set_select_horizontal1_handler(mmi_clndr_weekly_decrease,mmi_clndr_weekly_increase);
  686.         wgui_cat83_set_select_horizontal2_handler(
  687.             mmi_clndr_touch_multi_periodly_decrease,
  688.             mmi_clndr_touch_multi_periodly_increase);
  689.         wgui_cat83_set_select_vertical_handler(
  690.             mmi_clndr_touch_single_periodly_decrease,
  691.             mmi_clndr_touch_single_periodly_increase);
  692.     #endif
  693.         ClndrGetScreenInfo();
  694.         mmi_weekly_clndr_set_info_box();
  695.         mmi_clndr_weekly_set_content();
  696.         startCell = g_clndr_cntx->CalendarCell + (g_clndr_cntx->PeriodStartIndex * CLNDR_COLUMN);
  697.         ShowCategory83Screen(
  698.             IMG_CALENDAR_JAN,
  699.             (U8 **) g_clndr_cntx->HorizonList,
  700.             startCell,
  701.             CLNDR_ROW,
  702.             CLNDR_COLUMN,
  703.             0xFFFFFFFF, /* do not mark current period */
  704.             0xFFFFFFFF,
  705.             g_clndr_cntx->CurrPeriodIndex - g_clndr_cntx->PeriodStartIndex,
  706.             DOW(g_clndr_cntx->CalTime.nYear, g_clndr_cntx->CalTime.nMonth, g_clndr_cntx->CalTime.nDay),
  707.             CAT83_CELL_BG_FILL_VERTICAL,
  708.             CAT83_CELL_TEXT_DISPLAY_LEFT_BOTTOM,
  709.             CAT83_CELL_ICON_DISPLAY_CENTER);
  710.     }
  711. #endif /* __MMI_CLNDR_WEEKLY_VIEW_SUPPORT__ */ 
  712.     ChangeRightSoftkey(STR_GLOBAL_BACK, 0);
  713.     ChangeLeftSoftkey(STR_GLOBAL_OPTIONS, 0);
  714. #else /* __MMI_CALENDAR_V2__ */ 
  715.     gClndrAddToHistory = FALSE;
  716.     EntryNewScreen(SCR_ID_CLNDR_SCREEN, ExitClndrScreen, NULL, NULL);
  717.     gClndrAddToHistory = TRUE;
  718.     ClndrGetScreenInfo();
  719.     if (g_clndr_cntx->LunarState == TRUE && IsChineseSet())
  720.     {
  721.         lunarOptionInternal = TRUE;
  722.         InitializeCategory82Screen(
  723.             g_clndr_cntx->DayOnFirst,
  724.             g_clndr_cntx->NumDaysInMonth,
  725.             g_clndr_cntx->CalTime.nDay,
  726.             g_clndr_cntx->CalTime.nMonth,
  727.             g_clndr_cntx->CalTime.nYear);
  728.     }
  729.     else
  730.     {
  731.         lunarOptionInternal = FALSE;
  732.         InitializeCategory80Screen(
  733.             g_clndr_cntx->DayOnFirst,
  734.             g_clndr_cntx->NumDaysInMonth,
  735.             g_clndr_cntx->CalTime.nDay,
  736.             g_clndr_cntx->CalTime.nMonth,
  737.             g_clndr_cntx->CalTime.nYear);
  738.     }
  739. #ifdef __MMI_TODOLIST__
  740.     if (g_clndr_cntx->TaskDayList[0] != CLNDR_MAX_DAYS)
  741.     {
  742.         for (i = 1; i <= g_clndr_cntx->TaskDayList[0]; i++)
  743.         {
  744.             SetCalendarDay(g_clndr_cntx->TaskDayList[i], CALENDAR_TASK_DAY);
  745.         }
  746.     }
  747.     else
  748.     {
  749.         for (i = 1; i <= CLNDR_MAX_DAYS; i++)
  750.         {
  751.             SetCalendarDay(i, CALENDAR_TASK_DAY);
  752.         }
  753.     }
  754. #endif /* __MMI_TODOLIST__ */ 
  755.     /* browsing to current month */
  756.     GetDateTime(&myTime);
  757.     if (myTime.nMonth == g_clndr_cntx->CalTime.nMonth && myTime.nYear == g_clndr_cntx->CalTime.nYear)
  758.     {
  759.         SetCalendarDay(myTime.nDay, CALENDAR_CURRENT_DAY);
  760.     }
  761.     RegisterCalendarHighlightHandler(HighlightClndrDate);
  762.     RegisterCalendarUpdateHandler(UpdateClndrContext);
  763. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  764.     if (lunarOptionInternal == TRUE)
  765.     {
  766.         RegisterCalendarUpdateInfoBoxHandler(ClndrUpdateInfoBox);
  767.     }
  768. #endif /* __MMI_UI_CALENDAR_WITH_INFO_BOX__ */ 
  769.     if (IsChineseSet())
  770.     {
  771.         SetCalendarTitleImage(CAL_CHINESE_DAYS_IMAGE);
  772.     }
  773.     else
  774.     {
  775.         SetCalendarTitleImage(CAL_ENGLISH_DAYS_IMAGE);
  776.     }
  777.     if (lunarOptionInternal == FALSE)
  778.     {
  779.         ShowCategory80Screen(STR_GLOBAL_OPTIONS, IMG_GLOBAL_OPTIONS, STR_GLOBAL_BACK, IMG_GLOBAL_BACK, 0);
  780.     }
  781.     else
  782.     {
  783.         g_clndr_cntx->LunarInfo.SolarMonth = g_clndr_cntx->CalTime.nMonth;
  784.         g_clndr_cntx->LunarInfo.SolarYear = g_clndr_cntx->CalTime.nYear;
  785.         g_clndr_cntx->LunarInfo.SolarDay = g_clndr_cntx->CalTime.nDay;
  786.         ClndrComputeLunarInfo(&g_clndr_cntx->LunarInfo);
  787.         SetCalendarPopupDay(
  788.             g_clndr_cntx->LunarInfo.SolarDay,
  789.             (U8*) g_clndr_cntx->LunarInfo.MessageLine1,
  790.             (U8*) g_clndr_cntx->LunarInfo.MessageLine2,
  791.             (U8*) g_clndr_cntx->LunarInfo.MessageLine3);
  792.         SetCategory82Title1((U8*) g_clndr_cntx->LunarInfo.TitleInfo1); /* OR calInfo.totlestring */
  793.         /* SetCategory82Title2((U8*)g_clndr_cntx->TitleString); */
  794.         SetCategory82Title3((U8*) g_clndr_cntx->LunarInfo.TitleInfo2);
  795.         SetCalendarPopupTitleLunarFunc(ClndrGeneratePopupInfo);
  796.         ShowCategory82Screen(STR_GLOBAL_OPTIONS, IMG_GLOBAL_OPTIONS, STR_GLOBAL_BACK, IMG_GLOBAL_OK, 0);
  797.     }
  798.     SetKeyHandler(wgui_calendar_previous_month, KEY_VOL_UP, KEY_EVENT_DOWN);
  799.     SetKeyHandler(wgui_calendar_previous_month, KEY_VOL_UP, KEY_LONG_PRESS);
  800.     SetKeyHandler(wgui_calendar_next_month, KEY_VOL_DOWN, KEY_EVENT_DOWN);
  801.     SetKeyHandler(wgui_calendar_next_month, KEY_VOL_DOWN, KEY_LONG_PRESS);
  802.     SetCalendarMonthFunctions(
  803.         wgui_calendar_previous_month_day,
  804.         wgui_calendar_next_month_day,
  805.         wgui_calendar_previous_month_week,
  806.         wgui_calendar_next_month_week);
  807. #ifdef __MMI_TOUCH_SCREEN__
  808.     SetCalendarMonthChangeFunctions(wgui_calendar_previous_month, wgui_calendar_next_month);
  809.     /* 053005 Calvin Start */
  810. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  811.     SetCalendarYearChangeFunctions(wgui_calendar_previous_year, wgui_calendar_next_year);
  812. #endif 
  813.     /* 053005 Calvin End */
  814. #endif /* __MMI_TOUCH_SCREEN__ */ 
  815. #endif /* __MMI_CALENDAR_V2__ */ 
  816.     SetLeftSoftkeyFunction(EntryClndrOptions, KEY_EVENT_UP);
  817.     SetRightSoftkeyFunction(ClndrGoBackFromCalendar, KEY_EVENT_UP);
  818. }
  819. /*****************************************************************************
  820.  * FUNCTION
  821.  *  ExitClndrScreen
  822.  * DESCRIPTION
  823.  *  Exit function of calendar screen.
  824.  * PARAMETERS
  825.  *  void
  826.  * RETURNS
  827.  *  void
  828.  *****************************************************************************/
  829. void ExitClndrScreen(void)
  830. {
  831.     /*----------------------------------------------------------------*/
  832.     /* Local Variables                                                */
  833.     /*----------------------------------------------------------------*/
  834.     /*----------------------------------------------------------------*/
  835.     /* Code Body                                                      */
  836.     /*----------------------------------------------------------------*/
  837. #ifdef __MMI_CALENDAR_V2__
  838.     mmi_frm_scrmem_free((void*)g_clndr_cntx->Title);
  839.     mmi_frm_scrmem_free((void*)g_clndr_cntx->HorizonList[0]);
  840.     mmi_frm_scrmem_free((void*)g_clndr_cntx->VerticalList[0]);
  841.     mmi_frm_scrmem_free((void*)g_clndr_cntx->CalendarCell);
  842.     OslMfree(g_clndr_cntx->info_box_text[0]);
  843.     OslMfree(g_clndr_cntx->info_box_text[1]);
  844. #else /* __MMI_CALENDAR_V2__ */ 
  845.     if (gClndrAddToHistory)
  846.     {
  847.         history Scr;
  848.         S16 nHistory = 0;
  849.         Scr.scrnID = SCR_ID_CLNDR_SCREEN;
  850.         Scr.entryFuncPtr = EntryClndrScreen;
  851.         GetCategoryHistory(Scr.guiBuffer);
  852.         pfnUnicodeStrcpy((S8*) Scr.inputBuffer, (S8*) & nHistory);
  853.         AddHistory(Scr);
  854.     }
  855. #endif /* __MMI_CALENDAR_V2__ */ 
  856. }
  857. /*****************************************************************************
  858.  * FUNCTION
  859.  *  ClndrGetScreenInfo
  860.  * DESCRIPTION
  861.  *  Get screen display information of.
  862.  * PARAMETERS
  863.  *  void
  864.  * RETURNS
  865.  *  void
  866.  *****************************************************************************/
  867. void ClndrGetScreenInfo(void)
  868. {
  869.     /*----------------------------------------------------------------*/
  870.     /* Local Variables                                                */
  871.     /*----------------------------------------------------------------*/
  872. #ifdef __MMI_TODOLIST__
  873.     MYTIME myTime;
  874. #endif 
  875.     /*----------------------------------------------------------------*/
  876.     /* Code Body                                                      */
  877.     /*----------------------------------------------------------------*/
  878.     /* get the DOW 1st of todays month */
  879.     g_clndr_cntx->DayOnFirst = DOW(g_clndr_cntx->CalTime.nYear, g_clndr_cntx->CalTime.nMonth, 1);
  880.     /* get the num of days in todays month */
  881.     g_clndr_cntx->NumDaysInMonth = LastDayOfMonth(g_clndr_cntx->CalTime.nMonth, g_clndr_cntx->CalTime.nYear);
  882.     /* get the list of days to be highlithed */
  883. #ifdef __MMI_TODOLIST__
  884.     memset(&myTime, 0, sizeof(MYTIME));
  885.     myTime.nYear = g_clndr_cntx->CalTime.nYear;
  886.     myTime.nMonth = g_clndr_cntx->CalTime.nMonth;
  887.     myTime.nDay = g_clndr_cntx->CalTime.nDay;
  888. #ifdef __MMI_CALENDAR_V2__
  889.     /* reset task list */
  890.     memset(g_clndr_cntx->TaskDayList, 0, CLNDR_COLUMN * CLNDR_ROW * sizeof(clndr_task_icon_struct));
  891.     mmi_clndr_get_date_str(&(g_clndr_cntx->CalTime), g_clndr_cntx->Title);
  892.     if (g_clndr_cntx->DisplayType == CLNDR_MONTHLY_VIEW)
  893.     {
  894.         mmi_clndr_get_weekday(g_clndr_cntx->HorizonList);
  895.         mmi_clndr_get_week_numbers(
  896.             g_clndr_cntx->CalTime.nYear,
  897.             g_clndr_cntx->CalTime.nMonth,
  898.             g_clndr_cntx->VerticalList);
  899.         mmi_clndr_construct_monthly_cell_info();
  900.     }
  901. #ifdef __MMI_CLNDR_WEEKLY_VIEW_SUPPORT__
  902.     else
  903.     {
  904.         mmi_clndr_get_weekly_dates(&g_clndr_cntx->CalTime, g_clndr_cntx->HorizonList);
  905.         /* todo : compute the start period index */
  906.         mmi_clndr_get_period_range(g_clndr_cntx->PeriodStartIndex, g_clndr_cntx->VerticalList);
  907.         mmi_clndr_construct_weekly_cell_info();
  908. #ifdef MMI_ON_WIN32
  909. g_clndr_cntx->WeekNum = mmi_dt_get_week_number(& g_clndr_cntx->CalTime);
  910. #else
  911.         g_clndr_cntx->WeekNum = applib_dt_get_week_number((applib_time_struct*) & g_clndr_cntx->CalTime);
  912. #endif
  913.     }
  914. #endif /* __MMI_CLNDR_WEEKLY_VIEW_SUPPORT__ */ 
  915. #else /* __MMI_CALENDAR_V2__ */ 
  916.     TDLGetDaysToBeHilited(myTime, g_clndr_cntx->TaskDayList);
  917. #endif /* __MMI_CALENDAR_V2__ */ 
  918. #endif /* __MMI_TODOLIST__ */ 
  919. }
  920. /*****************************************************************************
  921.  * FUNCTION
  922.  *  ClndrGoBackFromCalendar
  923.  * DESCRIPTION
  924.  *  Free memory and go back to previous screen.
  925.  * PARAMETERS
  926.  *  void
  927.  * RETURNS
  928.  *  void
  929.  *****************************************************************************/
  930. void ClndrGoBackFromCalendar(void)
  931. {
  932.     /*----------------------------------------------------------------*/
  933.     /* Local Variables                                                */
  934.     /*----------------------------------------------------------------*/
  935.     /*----------------------------------------------------------------*/
  936.     /* Code Body                                                      */
  937.     /*----------------------------------------------------------------*/
  938.     GoBackHistory();
  939.     ClndrDeInit();
  940. }
  941. /*****************************************************************************
  942.  * FUNCTION
  943.  *  ClndrGeneratePopupInfo
  944.  * DESCRIPTION
  945.  *  Adjust solar day accoding and get lunar info.
  946.  * PARAMETERS
  947.  *  type            [IN]        
  948.  *  num_cols        [IN]        
  949.  *  new_day         [IN]        
  950.  *  old_day         [IN]        
  951.  * RETURNS
  952.  *  void
  953.  *****************************************************************************/
  954. void ClndrGeneratePopupInfo(U8 type, U8 num_cols, U8 new_day, U8 old_day)
  955. {
  956.     /*----------------------------------------------------------------*/
  957.     /* Local Variables                                                */
  958.     /*----------------------------------------------------------------*/
  959.     /*----------------------------------------------------------------*/
  960.     /* Code Body                                                      */
  961.     /*----------------------------------------------------------------*/
  962.     switch (type)
  963.     {
  964.         case NEXT_DAY:
  965.             g_clndr_cntx->LunarInfo.SolarDay += 1;
  966.             break;
  967.         case PREV_DAY:
  968.             g_clndr_cntx->LunarInfo.SolarDay -= 1;
  969.             break;
  970.         case NEXT_ROW:
  971.             g_clndr_cntx->LunarInfo.SolarDay += (S16) num_cols;
  972.             break;
  973.         case PREV_ROW:
  974.             g_clndr_cntx->LunarInfo.SolarDay -= (S16) num_cols;
  975.             break;
  976.         case SELECTED_DAY:
  977.             g_clndr_cntx->LunarInfo.SolarDay += new_day - old_day;
  978.             break;
  979.         default:
  980.             break;
  981.     }
  982.     ClndrComputeLunarInfo(&g_clndr_cntx->LunarInfo);
  983.     SetCalendarPopupDay(
  984.         g_clndr_cntx->LunarInfo.SolarDay,
  985.         (U8*) g_clndr_cntx->LunarInfo.MessageLine1,
  986.         (U8*) g_clndr_cntx->LunarInfo.MessageLine2,
  987.         (U8*) g_clndr_cntx->LunarInfo.MessageLine3);
  988.     ChangeCategory82Title1((U8*) g_clndr_cntx->LunarInfo.TitleInfo1);  /* OR calInfo.totlestring */
  989.     ChangeCategory82Title3((U8*) g_clndr_cntx->LunarInfo.TitleInfo2);
  990. }
  991. #define CLNDR_OPTION
  992. /*****************************************************************************
  993.  * FUNCTION
  994.  *  EntryClndrOptions
  995.  * DESCRIPTION
  996.  *  Side down key handler, go to 1st day of next month.
  997.  * PARAMETERS
  998.  *  void
  999.  * RETURNS
  1000.  *  void
  1001.  *****************************************************************************/
  1002. void EntryClndrOptions(void)
  1003. {
  1004.     /*----------------------------------------------------------------*/
  1005.     /* Local Variables                                                */
  1006.     /*----------------------------------------------------------------*/
  1007.     U8 *guiBuffer;
  1008.     U8 *pop_up_desc[5];
  1009.     U16 nStrItemList[5];    /* Stores the strings id of submenus returned */
  1010.     U16 nNumofItem;         /* Stores no of children in the submenu */
  1011.     U16 menuId;
  1012.     /*----------------------------------------------------------------*/
  1013.     /* Code Body                                                      */
  1014.     /*----------------------------------------------------------------*/
  1015.     gClndrAddToHistory = TRUE;
  1016.     EntryNewScreen(SCR_ID_CLNDR_OPTION, ExitClndrOptions, EntryClndrOptions, NULL);
  1017.     gClndrAddToHistory = FALSE;
  1018. #ifdef __MMI_CALENDAR_V2__
  1019.     if (g_clndr_cntx->DisplayType == CLNDR_MONTHLY_VIEW)
  1020.     {
  1021.         menuId = ORGANIZER_CALENDER_MONTHLY_OPTIONS_MENU;
  1022.     }
  1023.     else
  1024.     {
  1025.         menuId = ORGANIZER_CALENDER_WEEKLY_OPTIONS_MENU;
  1026.     }
  1027. #else /* __MMI_CALENDAR_V2__ */ 
  1028.     menuId = ORGANIZER_CALENDER_MENU;
  1029. #endif /* __MMI_CALENDAR_V2__ */ 
  1030. #if defined(__MMI_CALENDAR_V2__) && defined(__MMI_TODOLIST__)    
  1031.     /* Hide options of adding task if the amount of todolist equals to max value */
  1032.     if (TDLGetTotalItem() >= NUM_OF_TDL)
  1033.     {
  1034.         mmi_frm_hide_menu_item(MENU_ID_CLNDR_ADD_TASK);
  1035.     }
  1036.     else if (mmi_frm_test_menu_item_hide(MENU_ID_CLNDR_ADD_TASK))
  1037.     {
  1038.         mmi_frm_unhide_menu_item(MENU_ID_CLNDR_ADD_TASK);
  1039.     }
  1040. #endif  
  1041.     guiBuffer = GetCurrGuiBuffer(SCR_ID_CLNDR_OPTION);
  1042.     /*  Retrieve no of child of menu item to be displayed */
  1043.     nNumofItem = GetNumOfChild_Ext(menuId);
  1044.     /*  Retrieve string ids in sequence of given menu item to be displayed */
  1045.     GetSequenceStringIds_Ext(menuId, nStrItemList);
  1046.     ConstructHintsList(menuId, pop_up_desc);
  1047.     /*  Set current parent id */
  1048.     SetParentHandler(menuId);
  1049.     /*  Register highlight handler to be called in menu screen */
  1050.     RegisterHighlightHandler(ExecuteCurrHiliteHandler);
  1051.     if (IsChineseSet())
  1052.     {
  1053.         ShowCategory52Screen(
  1054.             STR_GLOBAL_OPTIONS,
  1055.             GetRootTitleIcon(ORGANIZER_CALENDER_MENU),
  1056.             STR_GLOBAL_OK,
  1057.             IMG_GLOBAL_OK,
  1058.             STR_GLOBAL_BACK,
  1059.             IMG_GLOBAL_OK,
  1060.             nNumofItem,
  1061.             nStrItemList,
  1062.             (PU16) gIndexIconsImageList,
  1063.             pop_up_desc,
  1064.             0,
  1065.             0,
  1066.             guiBuffer);
  1067.     }
  1068.     else
  1069.     {
  1070.         ShowCategory52Screen(
  1071.             STR_GLOBAL_OPTIONS,
  1072.             ORGANIZER_TITLE_IMAGEID,
  1073.             STR_GLOBAL_OK,
  1074.             IMG_GLOBAL_OK,
  1075.             STR_GLOBAL_BACK,
  1076.             IMG_GLOBAL_OK,
  1077.             (nNumofItem - 1),
  1078.             nStrItemList,
  1079.             (PU16) gIndexIconsImageList,
  1080.             pop_up_desc,
  1081.             0,
  1082.             0,
  1083.             guiBuffer);
  1084.     }
  1085.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1086. }
  1087. /*****************************************************************************
  1088.  * FUNCTION
  1089.  *  ExitClndrOptions
  1090.  * DESCRIPTION
  1091.  *  Exit function of calendar option screen. write lunar state to nvram.
  1092.  * PARAMETERS
  1093.  *  void
  1094.  * RETURNS
  1095.  *  void
  1096.  *****************************************************************************/
  1097. void ExitClndrOptions(void)
  1098. {
  1099.     /*----------------------------------------------------------------*/
  1100.     /* Local Variables                                                */
  1101.     /*----------------------------------------------------------------*/
  1102.     S16 error;
  1103.     /*----------------------------------------------------------------*/
  1104.     /* Code Body                                                      */
  1105.     /*----------------------------------------------------------------*/
  1106.     WriteValue(LUNAR_CALENDAR, &g_clndr_cntx->LunarState, DS_BYTE, &error);
  1107. }
  1108. /*****************************************************************************
  1109.  * FUNCTION
  1110.  *  ClndrSetLunarState
  1111.  * DESCRIPTION
  1112.  *  Toggle state of lunar calendar.
  1113.  * PARAMETERS
  1114.  *  void
  1115.  * RETURNS
  1116.  *  void
  1117.  *****************************************************************************/
  1118. void ClndrSetLunarState(void)
  1119. {
  1120.     /*----------------------------------------------------------------*/
  1121.     /* Local Variables                                                */
  1122.     /*----------------------------------------------------------------*/
  1123.     U16 indexPopup;
  1124.     /*----------------------------------------------------------------*/
  1125.     /* Code Body                                                      */
  1126.     /*----------------------------------------------------------------*/
  1127.     indexPopup = GetCurrHiliteID();
  1128.     if (g_clndr_cntx->LunarState == TRUE)
  1129.     {
  1130.         g_clndr_cntx->LunarState = FALSE;
  1131.         pfnUnicodeStrcpy((S8*) hintData[indexPopup], (S8*) GetString(STR_GLOBAL_OFF));
  1132.         ChangeLeftSoftkey(STR_GLOBAL_ON, IMG_CAL_ON);
  1133.     }
  1134.     else
  1135.     {
  1136.         g_clndr_cntx->LunarState = TRUE;
  1137.         pfnUnicodeStrcpy((S8*) hintData[indexPopup], (S8*) GetString(STR_GLOBAL_ON));
  1138.         ChangeLeftSoftkey(STR_GLOBAL_OFF, IMG_CAL_OFF);
  1139.     }
  1140.     Category52ChangeItemDescription(indexPopup, hintData[indexPopup]);
  1141.     SetLeftSoftkeyFunction(ClndrSetLunarState, KEY_EVENT_UP);
  1142.     RedrawCategoryFunction();
  1143. }
  1144. /*****************************************************************************
  1145.  * FUNCTION
  1146.  *  ClndrDisplayTask
  1147.  * DESCRIPTION
  1148.  *  Display to do list task of selected date.
  1149.  * PARAMETERS
  1150.  *  void
  1151.  * RETURNS
  1152.  *  void
  1153.  *****************************************************************************/
  1154. void ClndrDisplayTask(void)
  1155. {
  1156.     /*----------------------------------------------------------------*/
  1157.     /* Local Variables                                                */
  1158.     /*----------------------------------------------------------------*/
  1159.     /*----------------------------------------------------------------*/
  1160.     /* Code Body                                                      */
  1161.     /*----------------------------------------------------------------*/
  1162. #ifdef __MMI_TODOLIST__
  1163. #ifdef __MMI_CALENDAR_V2__
  1164.     mmi_tdl_set_clndr(&g_clndr_cntx->CalTime, g_clndr_cntx->DisplayType);
  1165. #else 
  1166.     mmi_tdl_set_clndr(&g_clndr_cntx->CalTime, MMI_TRUE);
  1167. #endif 
  1168.     TDLShowSpecificDateList();
  1169. #endif /* __MMI_TODOLIST__ */ 
  1170. }
  1171. /*****************************************************************************
  1172.  * FUNCTION
  1173.  *  ClndrLunarHintHandler
  1174.  * DESCRIPTION
  1175.  *  Hint handler of lunar calendar option.
  1176.  * PARAMETERS
  1177.  *  index       [IN]        
  1178.  * RETURNS
  1179.  *  void
  1180.  *****************************************************************************/
  1181. void ClndrLunarHintHandler(U16 index)
  1182. {
  1183.     /*----------------------------------------------------------------*/
  1184.     /* Local Variables                                                */
  1185.     /*----------------------------------------------------------------*/
  1186.     /*----------------------------------------------------------------*/
  1187.     /* Code Body                                                      */
  1188.     /*----------------------------------------------------------------*/
  1189.     if (g_clndr_cntx->LunarState == FALSE)
  1190.     {
  1191.         pfnUnicodeStrcpy((S8*) hintData[index], (S8*) GetString(STR_GLOBAL_OFF));
  1192.     }
  1193.     else
  1194.     {
  1195.         pfnUnicodeStrcpy((S8*) hintData[index], (S8*) GetString(STR_GLOBAL_ON));
  1196.     }
  1197. }
  1198. /*****************************************************************************
  1199.  * FUNCTION
  1200.  *  HighlightClndrViewTask
  1201.  * DESCRIPTION
  1202.  *  Highlight handler of View Task option.
  1203.  * PARAMETERS
  1204.  *  void
  1205.  * RETURNS
  1206.  *  void
  1207.  *****************************************************************************/
  1208. void HighlightClndrViewTask(void)
  1209. {
  1210.     /*----------------------------------------------------------------*/
  1211.     /* Local Variables                                                */
  1212.     /*----------------------------------------------------------------*/
  1213.     /*----------------------------------------------------------------*/
  1214.     /* Code Body                                                      */
  1215.     /*----------------------------------------------------------------*/
  1216.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  1217.     SetLeftSoftkeyFunction(ClndrDisplayTask, KEY_EVENT_UP);
  1218.     SetKeyHandler(ClndrDisplayTask, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1219.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1220. }
  1221. /*****************************************************************************
  1222.  * FUNCTION
  1223.  *  HighlightClndrLunar
  1224.  * DESCRIPTION
  1225.  *  Highlight handler on lunar calendar option.
  1226.  * PARAMETERS
  1227.  *  void
  1228.  * RETURNS
  1229.  *  void
  1230.  *****************************************************************************/
  1231. void HighlightClndrLunar(void)
  1232. {
  1233.     /*----------------------------------------------------------------*/
  1234.     /* Local Variables                                                */
  1235.     /*----------------------------------------------------------------*/
  1236.     U16 indexPopup = GetCurrHiliteID();
  1237.     /*----------------------------------------------------------------*/
  1238.     /* Code Body                                                      */
  1239.     /*----------------------------------------------------------------*/
  1240.     if (g_clndr_cntx->LunarState == FALSE)
  1241.     {
  1242.         pfnUnicodeStrcpy((S8*) hintData[indexPopup], (S8*) GetString(STR_GLOBAL_OFF));
  1243.         ChangeLeftSoftkey(STR_GLOBAL_ON, IMG_CAL_ON);
  1244.     }
  1245.     else
  1246.     {
  1247.         pfnUnicodeStrcpy((S8*) hintData[indexPopup], (S8*) GetString(STR_GLOBAL_ON));
  1248.         ChangeLeftSoftkey(STR_GLOBAL_OFF, IMG_CAL_OFF);
  1249.     }
  1250.     SetLeftSoftkeyFunction(ClndrSetLunarState, KEY_EVENT_UP);
  1251.     ClearKeyHandler(KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1252.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1253. }
  1254. #define CLNDR_JUMP_TO_DATE
  1255. /*****************************************************************************
  1256.  * FUNCTION
  1257.  *  ClndrValidateInput
  1258.  * DESCRIPTION
  1259.  *  Validate correctness of date and jump to the date in calendar.
  1260.  * PARAMETERS
  1261.  *  void
  1262.  * RETURNS
  1263.  *  void
  1264.  *****************************************************************************/
  1265. void ClndrValidateInput(void)
  1266. {
  1267.     /*----------------------------------------------------------------*/
  1268.     /* Local Variables                                                */
  1269.     /*----------------------------------------------------------------*/
  1270.     S8 tmpMon[CLNDR_DAY_LEN];
  1271.     S8 tmpDay[CLNDR_MON_LEN];
  1272.     S8 tmpYear[CLNDR_YEAR_LEN];
  1273.     U8 DayOfMon;
  1274.     U8 nDay, nMonth;
  1275.     U16 nYear;
  1276.     /*----------------------------------------------------------------*/
  1277.     /* Code Body                                                      */
  1278.     /*----------------------------------------------------------------*/
  1279.     CloseCategory57Screen();
  1280.     /* validate day */
  1281.     UnicodeToAnsii(tmpDay, g_clndr_cntx->DayBuf);
  1282.     UnicodeToAnsii(tmpMon, g_clndr_cntx->MonBuf);
  1283.     UnicodeToAnsii(tmpYear, g_clndr_cntx->YearBuf);
  1284.     nDay = atoi(tmpDay);
  1285.     nMonth = atoi(tmpMon);
  1286.     nYear = atoi(tmpYear);
  1287.     /* daty out of boundary */
  1288.     DayOfMon = LastDayOfMonth(nMonth, nYear);
  1289.     if (nDay > DayOfMon)
  1290.     {
  1291.         DisplayPopup(
  1292.             (U8*) GetString(STR_CLNDR_WRONG_DATE),
  1293.             IMG_GLOBAL_WARNING,
  1294.             0,
  1295.             UI_POPUP_NOTIFYDURATION_TIME,
  1296.             (U8) WARNING_TONE);
  1297.     }
  1298.     else
  1299.     {
  1300.         g_clndr_cntx->CalTime.nDay = nDay;
  1301.         g_clndr_cntx->CalTime.nMonth = nMonth;
  1302.         g_clndr_cntx->CalTime.nYear = nYear;
  1303.         GoBackToHistory(SCR_ID_CLNDR_SCREEN);
  1304.     }
  1305. }
  1306. /*****************************************************************************
  1307.  * FUNCTION
  1308.  *  ClndrFillInilineStruct
  1309.  * DESCRIPTION
  1310.  *  Fill inline structure of date input screen
  1311.  * PARAMETERS
  1312.  *  void
  1313.  * RETURNS
  1314.  *  void
  1315.  *****************************************************************************/
  1316. void ClndrFillInilineStruct(void)
  1317. {
  1318.     /*----------------------------------------------------------------*/
  1319.     /* Local Variables                                                */
  1320.     /*----------------------------------------------------------------*/
  1321.     S8 tmpMon[CLNDR_DAY_LEN];
  1322.     S8 tmpDay[CLNDR_MON_LEN];
  1323.     /*----------------------------------------------------------------*/
  1324.     /* Code Body                                                      */
  1325.     /*----------------------------------------------------------------*/
  1326.     gui_itoa((S32) g_clndr_cntx->CalTime.nYear, (U16*) g_clndr_cntx->YearBuf, 10);
  1327.     sprintf(tmpMon, "%02d", g_clndr_cntx->CalTime.nMonth);
  1328.     AnsiiToUnicodeString(g_clndr_cntx->MonBuf, tmpMon);
  1329.     sprintf(tmpDay, "%02d", g_clndr_cntx->CalTime.nDay);
  1330.     AnsiiToUnicodeString(g_clndr_cntx->DayBuf, tmpDay);
  1331.     SetInlineItemActivation(&wgui_inline_items[0], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  1332.     SetInlineItemCaption(&wgui_inline_items[0], (U8*) GetString(STR_CLNDR_DATE));
  1333.     SetInlineItemActivation(&wgui_inline_items[1], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  1334.     SetInlineItemDate(
  1335.         &wgui_inline_items[1],
  1336.         (U8*) g_clndr_cntx->DayBuf,
  1337.         (U8*) g_clndr_cntx->MonBuf,
  1338.         (U8*) g_clndr_cntx->YearBuf,
  1339.         ClndrDateEditorCallBack);
  1340.     RightJustifyInlineItem(&wgui_inline_items[1]);
  1341.     EnableInlineItemBoundary(&wgui_inline_items[1]);
  1342.     set_inline_date_boundary(2030, 1970, 12, 1);
  1343. }
  1344. /*****************************************************************************
  1345.  * FUNCTION
  1346.  *  HighlightClndrInputItem
  1347.  * DESCRIPTION
  1348.  *  Highlight handler of inline editor items.
  1349.  * PARAMETERS
  1350.  *  nIndex      [IN]        
  1351.  * RETURNS
  1352.  *  void
  1353.  *****************************************************************************/
  1354. void HighlightClndrInputItem(S32 nIndex)
  1355. {
  1356.     /*----------------------------------------------------------------*/
  1357.     /* Local Variables                                                */
  1358.     /*----------------------------------------------------------------*/
  1359.     /*----------------------------------------------------------------*/
  1360.     /* Code Body                                                      */
  1361.     /*----------------------------------------------------------------*/
  1362.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  1363.     SetLeftSoftkeyFunction(ClndrValidateInput, KEY_EVENT_UP);
  1364. }
  1365. /*****************************************************************************
  1366.  * FUNCTION
  1367.  *  ExitClndrJumpToDate
  1368.  * DESCRIPTION
  1369.  *  Exit function of Jump To screen.
  1370.  * PARAMETERS
  1371.  *  void
  1372.  * RETURNS
  1373.  *  void
  1374.  *****************************************************************************/
  1375. void ExitClndrJumpToDate(void)
  1376. {
  1377.     /*----------------------------------------------------------------*/
  1378.     /* Local Variables                                                */
  1379.     /*----------------------------------------------------------------*/
  1380.     history Scr;
  1381.     U16 inputBufferSize;    /* added for inline edit history */
  1382.     S16 nHistory = 0;
  1383.     /*----------------------------------------------------------------*/
  1384.     /* Code Body                                                      */
  1385.     /*----------------------------------------------------------------*/
  1386.     Scr.scrnID = SCR_ID_CLNDR_JUMP;
  1387.     CloseCategory57Screen();
  1388.     Scr.entryFuncPtr = EntryClndrJumpToDate;
  1389.     pfnUnicodeStrcpy((S8*) Scr.inputBuffer, (S8*) & nHistory);
  1390.     GetCategoryHistory(Scr.guiBuffer);
  1391.     GetCategory57Data((U8*) Scr.inputBuffer);           /* added for inline edit history */
  1392.     inputBufferSize = (U16) GetCategory57DataSize();    /* added for inline edit history */
  1393.     AddNHistory(Scr, inputBufferSize);                  /* added for inline edit history */
  1394. }
  1395. /*****************************************************************************
  1396.  * FUNCTION
  1397.  *  EntryClndrJumpToDate
  1398.  * DESCRIPTION
  1399.  *  Entry function of Jump To screen.
  1400.  * PARAMETERS
  1401.  *  void
  1402.  * RETURNS
  1403.  *  void
  1404.  *****************************************************************************/
  1405. void EntryClndrJumpToDate(void)
  1406. {
  1407.     /*----------------------------------------------------------------*/
  1408.     /* Local Variables                                                */
  1409.     /*----------------------------------------------------------------*/
  1410.     U8 *guiBuffer;  /* Buffer holding history data */
  1411.     U8 *inputBuffer;
  1412.     U16 inputBufferSize;    /* added for inline edit history */
  1413.     /*----------------------------------------------------------------*/
  1414.     /* Code Body                                                      */
  1415.     /*----------------------------------------------------------------*/
  1416.     EntryNewScreen(SCR_ID_CLNDR_JUMP, ExitClndrJumpToDate, NULL, NULL);
  1417.     InitializeCategory57Screen();
  1418.     ClndrFillInilineStruct();
  1419.     RegisterHighlightHandler(HighlightClndrInputItem);
  1420.     guiBuffer = GetCurrGuiBuffer(SCR_ID_CLNDR_JUMP);
  1421.     inputBuffer = GetCurrNInputBuffer(SCR_ID_CLNDR_JUMP, &inputBufferSize);
  1422.     if (inputBuffer != NULL)    /* added for inline edit history */
  1423.     {
  1424.         SetCategory57Data(wgui_inline_items, 2, inputBuffer);   /* sets the data */
  1425.     }
  1426.     DisableCategory57ScreenDone();
  1427.     ShowCategory57Screen(
  1428.         STR_CLNDR_JUMP_TO,
  1429.         GetRootTitleIcon(ORGANIZER_CALENDER_MENU),
  1430.         STR_GLOBAL_OK,
  1431.         IMG_GLOBAL_OK,
  1432.         STR_GLOBAL_BACK,
  1433.         IMG_GLOBAL_BACK,
  1434.         2,
  1435.         NULL,
  1436.         wgui_inline_items,
  1437.         1,
  1438.         guiBuffer);
  1439.     SetKeyHandler(ClndrValidateInput, KEY_LSK, KEY_EVENT_UP);
  1440.     SetCategory57RightSoftkeyFunctions(ClndrValidateInput, GoBackHistory);
  1441. }
  1442. /*****************************************************************************
  1443.  * FUNCTION
  1444.  *  HighlightJumpToDate
  1445.  * DESCRIPTION
  1446.  *  Highlight handler on lunar calendar option.
  1447.  * PARAMETERS
  1448.  *  void
  1449.  * RETURNS
  1450.  *  void
  1451.  *****************************************************************************/
  1452. void HighlightJumpToDate(void)
  1453. {
  1454.     /*----------------------------------------------------------------*/
  1455.     /* Local Variables                                                */
  1456.     /*----------------------------------------------------------------*/
  1457.     /*----------------------------------------------------------------*/
  1458.     /* Code Body                                                      */
  1459.     /*----------------------------------------------------------------*/
  1460.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  1461.     SetKeyHandler(EntryClndrJumpToDate, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1462.     SetLeftSoftkeyFunction(EntryClndrJumpToDate, KEY_EVENT_UP);
  1463.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1464. }
  1465. #define CLNDR_LUNAR_CALENDAR
  1466. /*****************************************************************************
  1467.  * FUNCTION
  1468.  *  ClndrComputeSolarTerm
  1469.  * DESCRIPTION
  1470.  *  This function is to calculate the date of solar item in given year.
  1471.  * PARAMETERS
  1472.  *  year            [IN]        Year in solar calendar, e.g. 2003
  1473.  *  month           [IN]        
  1474.  *  solar_index     [IN]        Index of solar term, 0 = SC (Slight Cold), 1 = GC,...
  1475.  * RETURNS
  1476.  *  the solar day of given solar item
  1477.  *****************************************************************************/
  1478. S16 ClndrComputeSolarTerm(S16 year, S16 month, S16 solar_index)
  1479. {
  1480.     /*----------------------------------------------------------------*/
  1481.     /* Local Variables                                                */
  1482.     /*----------------------------------------------------------------*/
  1483.     /*----------------------------------------------------------------*/
  1484.     /* Code Body                                                      */
  1485.     /*----------------------------------------------------------------*/
  1486.     /* adjust the solar term days for lunarinfo by feifan 8/1/2005 */
  1487.     return solar_term_table[year - CLNDR_FIRST_NAVI_YEAR][solar_index];
  1488. #if 0
  1489. /* under construction !*/
  1490. /* under construction !*/
  1491. /* under construction !*/
  1492. /* under construction !*/
  1493. /* under construction !*/
  1494. /* under construction !*/
  1495. /* under construction !*/
  1496. /* under construction !*/
  1497. /* under construction !*/
  1498. /* under construction !*/
  1499. /* under construction !*/
  1500. /* under construction !*/
  1501. /* under construction !*/
  1502. /* under construction !*/
  1503. /* under construction !*/
  1504. /* under construction !*/
  1505. /* under construction !*/
  1506. /* under construction !*/
  1507. /* under construction !*/
  1508. /* under construction !*/
  1509. /* under construction !*/
  1510. /* under construction !*/
  1511. /* under construction !*/
  1512. #endif /* 0 */ 
  1513. }
  1514. /*****************************************************************************
  1515.  * FUNCTION
  1516.  *  ClndrComputeLunarInfo
  1517.  * DESCRIPTION
  1518.  *  This function is to convert solar date infomation to lunar date.
  1519.  * CALLS
  1520.  * PARAMETERS
  1521.  *  DI      [IN/OUT]        A struct contains solar date information and lunar information will also be stored here
  1522.  * RETURNS
  1523.  *  void
  1524.  *****************************************************************************/
  1525. void ClndrComputeLunarInfo(clndr_lnuar_date_info_struct *DI)
  1526. {
  1527.     /*----------------------------------------------------------------*/
  1528.     /* Local Variables                                                */
  1529.     /*----------------------------------------------------------------*/
  1530.     U8 LeapDay;
  1531.     S16 StartMonth;
  1532.     S16 YearIndex;
  1533.     S16 AccumulateDay;
  1534.     S16 KanChiDay;
  1535.     S16 DateDiff;
  1536.     S16 IntercalaryMonth;
  1537.     S16 LunarDays;
  1538.     S16 SolarDate1, SolarDate2, SolarDate3;
  1539.     S16 MonthIndex;
  1540.     S8 dummyString[CLNDR_TITLE_LEN];
  1541.     /*----------------------------------------------------------------*/
  1542.     /* Code Body                                                      */
  1543.     /*----------------------------------------------------------------*/
  1544.     /* to check if the month out of boundary */
  1545.     StartMonth = DI->SolarMonth - 1;
  1546.     /* to calculate the number of days in Feb. this year */
  1547.     if (StartMonth > 1)
  1548.     {
  1549.         LeapDay = (U8) IsLeapYear(DI->SolarYear);
  1550.     }
  1551.     else
  1552.     {
  1553.         LeapDay = 0;
  1554.     }
  1555.     YearIndex = DI->SolarYear - CLNDR_TABLE_START_YEAR;
  1556.     /* to calculate weekday */
  1557.     AccumulateDay = (gClndrAccuDays[StartMonth] + LeapDay + DI->SolarDay);
  1558.     /* to calculate the Kan and Chin of today */
  1559.     KanChiDay = AccumulateDay + gClndrLunarInfo[YearIndex].BaseKanChi;
  1560.     /* to check if today is earlier than the Chinese New Year day of this year */
  1561.     if (AccumulateDay <= gClndrLunarInfo[YearIndex].BaseDays)
  1562.     {
  1563.         YearIndex--;
  1564.         DI->LunarYear = DI->SolarYear - 1;
  1565.         LeapDay = (U8) IsLeapYear(DI->LunarYear);
  1566.         StartMonth += 12;
  1567.         AccumulateDay = (gClndrAccuDays[StartMonth] + LeapDay + DI->SolarDay);
  1568.     }
  1569.     else
  1570.     {
  1571.         DI->LunarYear = DI->SolarYear;
  1572.     }
  1573.     /* to calculate the lunar month and day */
  1574.     IntercalaryMonth = gClndrLunarInfo[YearIndex].Intercalary;
  1575.     DateDiff = gClndrLunarInfo[YearIndex].BaseDays;
  1576.     for (MonthIndex = 0; MonthIndex < 13; MonthIndex++)
  1577.     {
  1578.         LunarDays = DateDiff + 29;
  1579.         if (gClndrLunarInfo[YearIndex].MonthDays & (0x01 << MonthIndex))
  1580.         {
  1581.             LunarDays++;
  1582.         }
  1583.         if (AccumulateDay <= LunarDays)
  1584.         {
  1585.             break;
  1586.         }
  1587.         DateDiff = LunarDays;
  1588.     }
  1589.     DI->LunarMonth = (MonthIndex + 1);
  1590.     DI->LunarDay = AccumulateDay - DateDiff;
  1591.     /* to adjust Lunar month if there is a intercalary month in this year */
  1592.     if (IntercalaryMonth != 0 && DI->LunarMonth > IntercalaryMonth)
  1593.     {
  1594.         DI->LunarMonth--;
  1595.     }
  1596.     if (DI->LunarMonth > 12)
  1597.     {
  1598.         DI->LunarMonth -= 12;
  1599.     }
  1600.     /* the unfortunate direction, age, and animal today */
  1601.     DI->Direction = KanChiDay % 4;
  1602.     DI->Age = (82 - (KanChiDay % 60) + (DI->LunarYear - CLNDR_BASE)) % 60;
  1603.     if (DI->Age <= 10)
  1604.     {
  1605.         DI->Age += 60;
  1606.     }
  1607.     DI->Animal = (KanChiDay + 6) % 12;
  1608.     /* to calculate the Kan and Chin of this year */
  1609.     if (DI->LunarYear == DI->SolarYear)
  1610.     {
  1611.         DI->KanYear = (DI->SolarYear - 1900 + 36) % 10;
  1612.         DI->ChiYear = (DI->SolarYear - 1900 + 36) % 12;
  1613.         /* to calculate the animal of this year */
  1614.         DI->YearAnimal = (DI->SolarYear + 8) % 12;
  1615.     }
  1616.     else
  1617.     {
  1618.         DI->KanYear = (DI->SolarYear - 1900 + 36 - 1) % 10;
  1619.         DI->ChiYear = (DI->SolarYear - 1900 + 36 - 1) % 12;
  1620.         /* to calculate the animal of this year */
  1621.         DI->YearAnimal = (DI->SolarYear + 8 - 1) % 12;
  1622.     }
  1623.     /* to calculate the lunar day of solar term in this month */
  1624.     SolarDate1 = ClndrComputeSolarTerm(DI->SolarYear, DI->SolarMonth, (S16) ((DI->SolarMonth - 1) * 2));
  1625.     SolarDate2 = ClndrComputeSolarTerm(DI->SolarYear, DI->SolarMonth, (S16) ((DI->SolarMonth - 1) * 2 + 1));
  1626.     if (DI->SolarMonth < 12)
  1627.     {
  1628.         SolarDate3 = ClndrComputeSolarTerm(DI->SolarYear, (S16) (DI->SolarMonth + 1), (S16) ((DI->SolarMonth - 1) * 2 + 2));
  1629.     }
  1630.     else
  1631.     {
  1632.         SolarDate3 = ClndrComputeSolarTerm((S16) (DI->SolarYear + 1), (S16) 1, (S16) (0));
  1633.     }
  1634.     if (DI->SolarDay < SolarDate1)
  1635.     {
  1636.         DI->SolarTerm = 0;
  1637.         DI->SolarDate = SolarDate1 - DI->SolarDay + DI->LunarDay;
  1638.     }
  1639.     else if (DI->SolarDay == SolarDate1)
  1640.     {
  1641.         DI->SolarTerm = 0;
  1642.         DI->SolarDate = 0;
  1643.     }
  1644.     else if (DI->SolarDay < SolarDate2)
  1645.     {
  1646.         DI->SolarTerm = 1;
  1647.         DI->SolarDate = SolarDate2 - DI->SolarDay + DI->LunarDay;
  1648.     }
  1649.     else if (DI->SolarDay == SolarDate2)
  1650.     {
  1651.         DI->SolarTerm = 1;
  1652.         DI->SolarDate = 0;
  1653.     }
  1654.     else
  1655.     {
  1656.         DI->SolarTerm = 2;
  1657.         if (DI->SolarMonth == 2)
  1658.         {
  1659.             DI->SolarDate = gDaysInMonth[DI->SolarMonth - 1] - DI->SolarDay + SolarDate3 + DI->LunarDay + LeapDay;
  1660.         }
  1661.         else
  1662.         {
  1663.             DI->SolarDate = gDaysInMonth[DI->SolarMonth - 1] - DI->SolarDay + SolarDate3 + DI->LunarDay;
  1664.         }
  1665.     }
  1666.     if (gClndrLunarInfo[YearIndex].MonthDays & (0x01 << MonthIndex))
  1667.     {
  1668.         LunarDays = 30;
  1669.     }
  1670.     else
  1671.     {
  1672.         LunarDays = 29;
  1673.     }
  1674.     if (DI->SolarDate > LunarDays)
  1675.     {
  1676.         DI->SolarDate -= LunarDays;
  1677.     }
  1678.     /* to recode the information to present */
  1679.     /* Chinese year/month/day information */
  1680.     pfnUnicodeStrcpy(DI->TitleInfo1, GetString((U16) (STR_CAL_KAN1 + DI->KanYear)));
  1681.     pfnUnicodeStrcat(DI->TitleInfo1, GetString((U16) (STR_CAL_CHI1 + DI->ChiYear)));
  1682.     pfnUnicodeStrcat(DI->TitleInfo1, GetString(STR_CAL_YEAR));
  1683.     if (DI->LunarMonth < 10)
  1684.     {
  1685.         pfnUnicodeStrcat(DI->TitleInfo1, GetString((U16) (STR_CAL_CHINESE_NO1 + DI->LunarMonth - 1)));
  1686.     }
  1687.     else
  1688.     {
  1689.         pfnUnicodeStrcat(DI->TitleInfo1, GetString(STR_CAL_CHINESE_NO10));
  1690.         if (DI->LunarMonth > 10)
  1691.         {
  1692.             pfnUnicodeStrcat(DI->TitleInfo1, GetString((U16) (STR_CAL_CHINESE_NO1 + (DI->LunarMonth % 10 - 1))));
  1693.         }
  1694.     }
  1695.     pfnUnicodeStrcat(DI->TitleInfo1, GetString(STR_CAL_MONTH));
  1696.     if (DI->LunarDay < 10)
  1697.     {
  1698.         pfnUnicodeStrcat(DI->TitleInfo1, GetString((U16) (STR_CAL_CHINESE_NO1 + DI->LunarDay - 1)));
  1699.     }
  1700.     else if (DI->LunarDay < 20)
  1701.     {
  1702.         pfnUnicodeStrcat(DI->TitleInfo1, GetString(STR_CAL_CHINESE_NO10));
  1703.         if (DI->LunarDay > 10)
  1704.         {
  1705.             pfnUnicodeStrcat(DI->TitleInfo1, GetString((U16) (STR_CAL_CHINESE_NO1 + DI->LunarDay % 10 - 1)));
  1706.         }
  1707.     }
  1708.     else if (DI->LunarDay < 30)
  1709.     {
  1710.         pfnUnicodeStrcat(DI->TitleInfo1, GetString(STR_CAL_CHINESE_NO20));
  1711.         if (DI->LunarDay > 20)
  1712.         {
  1713.             pfnUnicodeStrcat(DI->TitleInfo1, GetString((U16) (STR_CAL_CHINESE_NO1 + DI->LunarDay % 10 - 1)));
  1714.         }
  1715.     }
  1716.     else
  1717.     {
  1718.         pfnUnicodeStrcat(DI->TitleInfo1, GetString(STR_CAL_CHINESE_NO30));
  1719.         if (DI->LunarDay > 30)
  1720.         {
  1721.             pfnUnicodeStrcat(DI->TitleInfo1, GetString((U16) (STR_CAL_CHINESE_NO1 + DI->LunarDay % 10 - 1)));
  1722.         }
  1723.     }
  1724.     pfnUnicodeStrcat(DI->TitleInfo1, GetString(STR_CAL_DAY));
  1725.     /* Animal index */
  1726.     pfnUnicodeStrcpy(DI->TitleInfo2, GetString((U16) (STR_CAL_ANIMAL1 + DI->YearAnimal)));
  1727.     /* Solar Term */
  1728.     if (DI->SolarDate == 0)
  1729.     {
  1730.         pfnUnicodeStrcpy(
  1731.             DI->MessageLine1,
  1732.             GetString((U16) (STR_CAL_SOLARTERM1 + (DI->SolarMonth - 1) * 2 + DI->SolarTerm)));
  1733.     }
  1734.     else
  1735.     {
  1736.         sprintf(dummyString, "%d", DI->SolarDate);
  1737.         AnsiiToUnicodeString(DI->MessageLine1, dummyString);
  1738.         if (DI->SolarTerm == 2 && DI->SolarMonth == 12)
  1739.         {
  1740.             pfnUnicodeStrcat(DI->MessageLine1, GetString(STR_CAL_SOLARTERM1));
  1741.         }
  1742.         else
  1743.         {
  1744.             pfnUnicodeStrcat(
  1745.                 DI->MessageLine1,
  1746.                 GetString((U16) (STR_CAL_SOLARTERM1 + (DI->SolarMonth - 1) * 2 + DI->SolarTerm)));
  1747.         }
  1748.     }
  1749.     /* Unfortunate */
  1750.     pfnUnicodeStrcpy(DI->MessageLine2, GetString(STR_CAL_UNLUCKY));
  1751.     pfnUnicodeStrcat(DI->MessageLine2, GetString((U16) (STR_CAL_DIRECTION1 + DI->Direction)));
  1752.     /* Unlucky */
  1753.     sprintf(DI->MessageLine3, "%d", DI->Age);
  1754.     AnsiiToUnicodeString(dummyString, DI->MessageLine3);
  1755.     pfnUnicodeStrcpy(DI->MessageLine3, GetString(STR_CAL_UNFORTUNATE));
  1756.     pfnUnicodeStrcat(DI->MessageLine3, GetString((U16) (STR_CAL_ANIMAL1 + DI->Animal)));
  1757.     pfnUnicodeStrcat(DI->MessageLine3, dummyString);
  1758. }
  1759. #endif /* __MMI_CALENDAR__ */ 
  1760. /*****************************************************************************
  1761.  * FUNCTION
  1762.  *  ClndrDateEditorCallBack
  1763.  * DESCRIPTION
  1764.  *  Call back funtion for inline date input.
  1765.  * PARAMETERS
  1766.  *  DateStr     [?]     
  1767.  *  day         [?]     
  1768.  *  month       [?]     
  1769.  *  year        [?]     
  1770.  * RETURNS
  1771.  *  void
  1772.  *****************************************************************************/
  1773. void ClndrDateEditorCallBack(U8 *DateStr, U8 *day, U8 *month, U8 *year)
  1774. {
  1775.     /*----------------------------------------------------------------*/
  1776.     /* Local Variables                                                */
  1777.     /*----------------------------------------------------------------*/
  1778.     /*----------------------------------------------------------------*/
  1779.     /* Code Body                                                      */
  1780.     /*----------------------------------------------------------------*/
  1781.     pfnUnicodeStrcpy((S8*) DateStr, (S8*) year);
  1782.     pfnUnicodeStrcat((S8*) DateStr, (S8*) "/");
  1783.     pfnUnicodeStrcat((S8*) DateStr, (S8*) month);
  1784.     pfnUnicodeStrcat((S8*) DateStr, (S8*) "/");
  1785.     pfnUnicodeStrcat((S8*) DateStr, (S8*) day);
  1786. }
  1787. #ifdef __MMI_BIRTHDAY_REMINDER__
  1788. /*****************************************************************************
  1789.  * FUNCTION
  1790.  *  mmi_clndr_get_monthly_birthday_info
  1791.  * DESCRIPTION
  1792.  *  
  1793.  * PARAMETERS
  1794.  *  month               [IN]        
  1795.  *  BirthdayInfo        [?]         
  1796.  * RETURNS
  1797.  *  void
  1798.  *****************************************************************************/
  1799. void mmi_clndr_get_monthly_birthday_info(U16 year, U8 month, birthday_info_struct *BirthdayInfo)
  1800. {
  1801.     /*----------------------------------------------------------------*/
  1802.     /* Local Variables                                                */
  1803.     /*----------------------------------------------------------------*/
  1804.     U32 i, date;
  1805.     MMI_PHB_BDAY_STRUCT *bday;
  1806.     /*----------------------------------------------------------------*/
  1807.     /* Code Body                                                      */
  1808.     /*----------------------------------------------------------------*/
  1809.     bday = (MMI_PHB_BDAY_STRUCT*) mmi_frm_scrmem_alloc(NVRAM_EF_PHB_BIRTHDAY_SIZE * NVRAM_EF_PHB_BIRTHDAY_TOTAL);
  1810.     mmi_clndr_read_birthday_info(bday);
  1811.     for (i = 0; i < MAX_PB_PHONE_ENTRIES; i++)
  1812.     {
  1813.         date = bday[i].bDay;
  1814.         if (bday[i].bMonth == month && year >= bday[i].bYear)
  1815.         {
  1816.             if (BirthdayInfo[date].count == 0)
  1817.             {
  1818.                 BirthdayInfo[date].firstMatchedIndex = i;
  1819.                 BirthdayInfo[date].count++;
  1820.             }
  1821.             else
  1822.             {
  1823.                 BirthdayInfo[date].count++;
  1824.             }
  1825.         }
  1826.     }
  1827.     mmi_frm_scrmem_free((void*)bday);
  1828. }
  1829. /*****************************************************************************
  1830.  * FUNCTION
  1831.  *  mmi_clndr_get_daily_birthday_info
  1832.  * DESCRIPTION
  1833.  *  
  1834.  * PARAMETERS
  1835.  *  month           [IN]        
  1836.  *  day             [IN]        
  1837.  *  amount          [IN]        
  1838.  *  PBIndexList     [?]         
  1839.  * RETURNS
  1840.  *  void
  1841.  *****************************************************************************/
  1842. void mmi_clndr_get_daily_birthday_info(U16 year, U8 month, U8 day, U16 amount, U16 *PBIndexList)
  1843. {
  1844.     /*----------------------------------------------------------------*/
  1845.     /* Local Variables                                                */
  1846.     /*----------------------------------------------------------------*/
  1847.     U32 i, count = 0;
  1848.     MMI_PHB_BDAY_STRUCT *bday;
  1849.     /*----------------------------------------------------------------*/
  1850.     /* Code Body                                                      */
  1851.     /*----------------------------------------------------------------*/
  1852.     bday = (MMI_PHB_BDAY_STRUCT*) mmi_frm_scrmem_alloc(NVRAM_EF_PHB_BIRTHDAY_SIZE * NVRAM_EF_PHB_BIRTHDAY_TOTAL);
  1853.     mmi_clndr_read_birthday_info(bday);
  1854.     for (i = 0; i < MAX_PB_PHONE_ENTRIES; i++)
  1855.     {
  1856.         if (bday[i].bMonth == month && bday[i].bDay == day && year >= bday[i].bYear)
  1857.         {
  1858.             PBIndexList[count] = i;
  1859.             count++;
  1860.         }
  1861.         if (count >= amount)
  1862.         {
  1863.             break;
  1864.         }
  1865.     }
  1866.     mmi_frm_scrmem_free((void*)bday);
  1867. }
  1868. /*****************************************************************************
  1869.  * FUNCTION
  1870.  *  mmi_clndr_read_birthday_info
  1871.  * DESCRIPTION
  1872.  *  
  1873.  * PARAMETERS
  1874.  *  bday_data       [?]     
  1875.  * RETURNS
  1876.  *  void
  1877.  *****************************************************************************/
  1878. void mmi_clndr_read_birthday_info(MMI_PHB_BDAY_STRUCT *bday_data)
  1879. {
  1880.     /*----------------------------------------------------------------*/
  1881.     /* Local Variables                                                */
  1882.     /*----------------------------------------------------------------*/
  1883.     S16 error;
  1884.     U32 bday_record;
  1885.     MMI_PHB_BDAY_STRUCT *data_pos = bday_data;
  1886.     /*----------------------------------------------------------------*/
  1887.     /* Code Body                                                      */
  1888.     /*----------------------------------------------------------------*/
  1889.     for (bday_record = 1; bday_record <= NVRAM_EF_PHB_BIRTHDAY_TOTAL; bday_record++)
  1890.     {
  1891.         data_pos = bday_data + ((bday_record - 1) * NVRAM_EF_PHB_BIRTHDAY_COUNT);
  1892.         ReadRecord(NVRAM_EF_PHB_BIRTHDAY_LID, bday_record, (void*)data_pos, NVRAM_EF_PHB_BIRTHDAY_SIZE, &error);
  1893.     }
  1894. #if 0
  1895. /* under construction !*/
  1896. /* under construction !*/
  1897. /* under construction !*/
  1898. #if 1
  1899. /* under construction !*/
  1900. /* under construction !*/
  1901. /* under construction !*/
  1902. /* under construction !*/
  1903. /* under construction !*/
  1904. /* under construction !*/
  1905. /* under construction !*/
  1906. /* under construction !*/
  1907. /* under construction !*/
  1908. /* under construction !*/
  1909. /* under construction !*/
  1910. /* under construction !*/
  1911. /* under construction !*/
  1912. /* under construction !*/
  1913. #else /* MMI_ON_WIN32 */ 
  1914. /* under construction !*/
  1915. /* under construction !*/
  1916. /* under construction !*/
  1917. /* under construction !*/
  1918. /* under construction !*/
  1919. /* under construction !*/
  1920. /* under construction !*/
  1921. /* under construction !*/
  1922. /* under construction !*/
  1923. /* under construction !*/
  1924. /* under construction !*/
  1925. /* under construction !*/
  1926. #endif /* MMI_ON_WIN32 */ 
  1927. #endif /* 0 */ 
  1928. }
  1929. /*****************************************************************************
  1930.  * FUNCTION
  1931.  *  mmi_clndr_get_daily_birthday_amount
  1932.  * DESCRIPTION
  1933.  *  
  1934.  * PARAMETERS
  1935.  *  date        [IN]        
  1936.  * RETURNS
  1937.  *  
  1938.  *****************************************************************************/
  1939. U16 mmi_clndr_get_daily_birthday_amount(U8 date)
  1940. {
  1941.     /*----------------------------------------------------------------*/
  1942.     /* Local Variables                                                */
  1943.     /*----------------------------------------------------------------*/
  1944.     /*----------------------------------------------------------------*/
  1945.     /* Code Body                                                      */
  1946.     /*----------------------------------------------------------------*/
  1947.     if (g_clndr_cntx != NULL)
  1948.     {
  1949.         return g_clndr_cntx->BirthdayInfo[date].count;
  1950.     }
  1951.     else
  1952.     {
  1953.         return 0;
  1954.     }
  1955. }
  1956. /*****************************************************************************
  1957.  * FUNCTION
  1958.  *  mmi_clndr_set_birthday_table
  1959.  * DESCRIPTION
  1960.  *  Set birthday information when month is changed.
  1961.  * PARAMETERS
  1962.  *  date        [IN]        
  1963.  * RETURNS
  1964.  *  
  1965.  *****************************************************************************/
  1966. void mmi_clndr_set_birthday_table(U16 year, U8 month)
  1967. {
  1968. #ifdef __MMI_BIRTHDAY_REMINDER__
  1969.         memset(g_clndr_cntx->BirthdayInfo, 0, sizeof(birthday_info_struct) * (CLNDR_MONTH_DAYS + 1));
  1970.         /* get birthday information */
  1971.         mmi_clndr_get_monthly_birthday_info(year, month, g_clndr_cntx->BirthdayInfo);
  1972. #endif /* __MMI_BIRTHDAY_REMINDER__ */ 
  1973. }
  1974. #endif /* __MMI_BIRTHDAY_REMINDER__ */ 
  1975. #endif /* _MMI_CALENDAR_C */ // #ifndef _MMI_CALENDAR_C