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

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  * HalethMenstrual.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  * MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  * This file implements Menstrual application.
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  *------------------------------------------------------------------------------
  104.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  105.  *============================================================================
  106.  ****************************************************************************/
  107. #ifndef _MMI_HEALTHMENSTRUAL_C
  108. #define _MMI_HEALTHMENSTRUAL_C
  109. #include "MMI_features.h"
  110. #ifdef __MMI_MENSTRUAL__
  111. #include "healthmenstural.h"
  112. #include "gui_data_types.h"
  113. #include "DateTimeGprot.h"
  114. #include "OrganizerDef.h"
  115. #include "wgui_categories.h"
  116. #include "wgui_categories_inputs.h"
  117. #include "wgui_calendar.h"
  118. #include "gui.h"
  119. #include "GlobalDefs.h"
  120. #include "HistoryGprot.h"
  121. #include "Unicodexdcl.h"
  122. #include "CalendarDef.h"
  123. #include "CommonScreens.h"
  124. #ifdef __MMI_CALENDAR_V2__
  125. #include "app_datetime.h"
  126. #endif 
  127. /* 
  128.  * Define
  129.  */
  130. #define  MENS_ZERO_PROB_PERIOD      3
  131. #define  MENS_OVULATION_DAYS        2
  132. #define  MENS_PERIOD             5
  133. #define  MENS_DAY_LEN         3*ENCODING_LENGTH
  134. #define  MENS_MON_LEN         3*ENCODING_LENGTH
  135. #define  MENS_YEAR_LEN        5*ENCODING_LENGTH
  136. #define  MENS_PERIOD_LEN         3*ENCODING_LENGTH
  137. #define  MENS_TITLE_LEN       9*ENCODING_LENGTH
  138. #define  MENS_MAX_PERIOD         99
  139. #define  MENS_MIN_PERIOD         14
  140. #define  MENS_NUM_PREV_MON    3 /* maximal prediction month */
  141. #define  MENS_MAX_NAVI_MON    6 /* maximal navigation month */
  142. /* 
  143.  * Typedef 
  144.  */
  145. typedef struct
  146. {
  147.     MYTIME InputDate;
  148.     S8 DayBuf[MENS_DAY_LEN];
  149.     S8 MonBuf[MENS_MON_LEN];
  150.     S8 YearBuf[MENS_YEAR_LEN];
  151.     S8 PeriodBuf[MENS_PERIOD_LEN];
  152.     S8 TitleString[MENS_TITLE_LEN];
  153.     U16 CurrYear;
  154.     U8 CurrMonth;
  155.     U8 CurrDay;
  156.     U8 NumOfMon;
  157.     U8 AvgPeriod;
  158.     U8 IsAddToHistory;
  159.     U8 DayOnFirst;
  160.     U8 DayOfMon;
  161. #ifdef __MMI_CALENDAR_V2__
  162.     MYTIME MensTime;
  163.     U8 *Title;
  164.     U8 *HorizonList[CLNDR_COLUMN];
  165.     U8 *VerticalList[CLNDR_ROW];
  166.     wgui_cat83_cell_struct *MenstrulCell;
  167.     /* U8 RowNumber; */
  168.     U8 horizon_select1[CLNDR_VERTICAL_SELECT_LEN];
  169.     U8 horizon_select2[CLNDR_VERTICAL_SELECT_LEN];
  170. #endif /* __MMI_CALENDAR_V2__ */ 
  171. } mens_context_struct;
  172. /* 
  173.  * Local Variable
  174.  */
  175. /* 
  176.  * Local Function
  177.  */
  178. U8 MensDelScrCB(void *p);
  179. /* 
  180.  * Global Variable
  181.  */
  182. mens_context_struct *g_mens_cntx = NULL;
  183. extern wgui_inline_item wgui_inline_items[];
  184. extern BOOL ClndPopupFlag;  /* 090605 Calendar Calvin added */
  185. /* 
  186.  * Global Function
  187.  */
  188. extern void ClndrDateEditorCallBack(U8 *DateStr, U8 *day, U8 *month, U8 *year);
  189. #define MENS_INITIALIZE
  190. /*****************************************************************************
  191.  * FUNCTION
  192.  *  MensInit
  193.  * DESCRIPTION
  194.  *  Initialize mens app.
  195.  * PARAMETERS
  196.  *  void
  197.  * RETURNS
  198.  *  void
  199.  *****************************************************************************/
  200. void MensInit(void)
  201. {
  202.     /*----------------------------------------------------------------*/
  203.     /* Local Variables                                                */
  204.     /*----------------------------------------------------------------*/
  205.     /*----------------------------------------------------------------*/
  206.     /* Code Body                                                      */
  207.     /*----------------------------------------------------------------*/
  208.     SetHiliteHandler(EXTRA_HEALTH_MENU_MENSTRUAL, HighlightMensApp);
  209. }
  210. /*****************************************************************************
  211.  * FUNCTION
  212.  *  MensDeInit
  213.  * DESCRIPTION
  214.  *  Free allocated memory for global context.
  215.  * PARAMETERS
  216.  *  void
  217.  * RETURNS
  218.  *  void
  219.  *****************************************************************************/
  220. void MensDeInit(void)
  221. {
  222.     /*----------------------------------------------------------------*/
  223.     /* Local Variables                                                */
  224.     /*----------------------------------------------------------------*/
  225.     /*----------------------------------------------------------------*/
  226.     /* Code Body                                                      */
  227.     /*----------------------------------------------------------------*/
  228.     if (g_mens_cntx)
  229.     {
  230.     #ifdef __MMI_CALENDAR_V2__
  231. if (g_mens_cntx->HorizonList[0] != NULL)
  232. {
  233. mmi_frm_scrmem_free((void*)g_mens_cntx->HorizonList[0]);
  234. mmi_frm_scrmem_free((void*)g_mens_cntx->VerticalList[0]);
  235. mmi_frm_scrmem_free((void*)g_mens_cntx->MenstrulCell);
  236. }
  237.     #endif /* __MMI_CALENDAR_V2__ */ 
  238.         OslMfree(g_mens_cntx);
  239.         g_mens_cntx = NULL;
  240.     }
  241. }
  242. /*****************************************************************************
  243.  * FUNCTION
  244.  *  MensDelScrCB
  245.  * DESCRIPTION
  246.  *  Callback function of delete menstural screen
  247.  * PARAMETERS
  248.  *  p       [?]     
  249.  * RETURNS
  250.  *  void
  251.  *****************************************************************************/
  252. U8 MensDelScrCB(void *p)
  253. {
  254.     /*----------------------------------------------------------------*/
  255.     /* Local Variables                                                */
  256.     /*----------------------------------------------------------------*/
  257.     /*----------------------------------------------------------------*/
  258.     /* Code Body                                                      */
  259.     /*----------------------------------------------------------------*/
  260.     if (GetActiveScreenId() == SCR_ID_MENS_INPUT)
  261.     {
  262.         CloseCategory57Screen();
  263.     }
  264.     MensDeInit();
  265.     return MMI_FALSE;
  266. }
  267. /*****************************************************************************
  268.  * FUNCTION
  269.  *  HighlightMensApp
  270.  * DESCRIPTION
  271.  *  Highlight handler of Menstrual menu item.
  272.  *  Register key handlers.
  273.  * PARAMETERS
  274.  *  void
  275.  * RETURNS
  276.  *  void
  277.  *****************************************************************************/
  278. void HighlightMensApp(void)
  279. {
  280.     /*----------------------------------------------------------------*/
  281.     /* Local Variables                                                */
  282.     /*----------------------------------------------------------------*/
  283.     /*----------------------------------------------------------------*/
  284.     /* Code Body                                                      */
  285.     /*----------------------------------------------------------------*/
  286.     SetLeftSoftkeyFunction(EntryMensWelcome, KEY_EVENT_UP);
  287.     SetKeyHandler(EntryMensWelcome, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  288. }
  289. /*****************************************************************************
  290.  * FUNCTION
  291.  *  EntryMensWelcome
  292.  * DESCRIPTION
  293.  *  Display welcome screen of mens application.
  294.  *  Register key handlers.
  295.  * PARAMETERS
  296.  *  void
  297.  * RETURNS
  298.  *  void
  299.  *****************************************************************************/
  300. void EntryMensWelcome(void)
  301. {
  302. #ifndef __MMI_MAINLCD_240X320__
  303.     /*----------------------------------------------------------------*/
  304.     /* Local Variables                                                */
  305.     /*----------------------------------------------------------------*/
  306.     U8 *guiBuffer;  /* Buffer holding history data */
  307.     /*----------------------------------------------------------------*/
  308.     /* Code Body                                                      */
  309.     /*----------------------------------------------------------------*/
  310.     guiBuffer = GetCurrGuiBuffer(SCR_ID_MENS_WELCOME);
  311.     EntryNewScreen(SCR_ID_MENS_WELCOME, NULL, EntryMensWelcome, NULL);
  312.     ShowCategory129Screen(
  313.         (U8*) get_string(STR_SCR_HEALTH_MENSIS_CAPTION),
  314.         GetRootTitleIcon(EXTRA_HEALTH_MENU),
  315.         STR_GLOBAL_OK,
  316.         0,
  317.         STR_GLOBAL_BACK,
  318.         IMG_GLOBAL_BACK,
  319.         IMG_SCR_HEALTH_MENSIS,
  320.         guiBuffer);
  321.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  322.     SetLeftSoftkeyFunction(MensPreEntryInput, KEY_EVENT_UP);
  323. #else /* __MMI_MAINLCD_240X320__ */ 
  324.     MensPreEntryInput();
  325. #endif /* __MMI_MAINLCD_240X320__ */ 
  326. }
  327. #define MENS_INPUT_SCREEN
  328. /*****************************************************************************
  329.  * FUNCTION
  330.  *  MensFillInlineStruct
  331.  * DESCRIPTION
  332.  *  
  333.  * PARAMETERS
  334.  *  void
  335.  * RETURNS
  336.  *  void
  337.  *****************************************************************************/
  338. void MensFillInlineStruct(void)
  339. {
  340.     /*----------------------------------------------------------------*/
  341.     /* Local Variables                                                */
  342.     /*----------------------------------------------------------------*/
  343.     /*----------------------------------------------------------------*/
  344.     /* Code Body                                                      */
  345.     /*----------------------------------------------------------------*/
  346.     SetInlineItemActivation(&wgui_inline_items[MENS_INLINE_DATE_CAP], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  347.     SetInlineItemCaption(&wgui_inline_items[MENS_INLINE_DATE_CAP], (U8*) GetString(STR_LAST_DATE));
  348.     SetInlineItemActivation(&wgui_inline_items[MEMS_INLINE_DATE], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  349.     SetInlineItemDate(
  350.         &wgui_inline_items[MEMS_INLINE_DATE],
  351.         (U8*) g_mens_cntx->DayBuf,
  352.         (U8*) g_mens_cntx->MonBuf,
  353.         (U8*) g_mens_cntx->YearBuf,
  354.         ClndrDateEditorCallBack);
  355.     RightJustifyInlineItem(&wgui_inline_items[MEMS_INLINE_DATE]);
  356.     EnableInlineItemBoundary(&wgui_inline_items[MEMS_INLINE_DATE]);
  357.     set_inline_date_boundary(2030, 1970, 12, 1);
  358.     SetInlineItemActivation(&wgui_inline_items[MEMS_INLINE_PERIOD_CAP], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  359.     SetInlineItemCaption(&wgui_inline_items[MEMS_INLINE_PERIOD_CAP], (U8*) GetString(STR_AVERAGE_DAYS_HEALTH_MENSIS));
  360.     SetInlineItemActivation(&wgui_inline_items[MEMS_INLINE_PERIOD], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  361.     SetInlineItemTextEdit(&wgui_inline_items[MEMS_INLINE_PERIOD], (U8*) g_mens_cntx->PeriodBuf, 3, INPUT_TYPE_NUMERIC);
  362.     RightJustifyInlineItem(&wgui_inline_items[MEMS_INLINE_PERIOD]);
  363.     EnableInlineItemBoundary(&wgui_inline_items[MEMS_INLINE_PERIOD]);
  364.     SetInlineItemActivation(&wgui_inline_items[MEMS_INLINE_NUM_DAYS], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  365.     SetInlineItemCaption(&wgui_inline_items[MEMS_INLINE_NUM_DAYS], (U8*) GetString(STR_DATE_FORMAT_HEALTH_MENSIS));
  366. }
  367. /*****************************************************************************
  368.  * FUNCTION
  369.  *  MensPreEntryInput
  370.  * DESCRIPTION
  371.  *  Initialize variables for input screen and then go to input screen.
  372.  * PARAMETERS
  373.  *  void
  374.  * RETURNS
  375.  *  void
  376.  *****************************************************************************/
  377. void MensPreEntryInput(void)
  378. {
  379.     /*----------------------------------------------------------------*/
  380.     /* Local Variables                                                */
  381.     /*----------------------------------------------------------------*/
  382.     MYTIME currTime;
  383.     S8 tmpMon[MENS_MON_LEN];
  384.     S8 tmpDay[MENS_MON_LEN];
  385.     /*----------------------------------------------------------------*/
  386.     /* Code Body                                                      */
  387.     /*----------------------------------------------------------------*/
  388.     if (g_mens_cntx == NULL)
  389.     {
  390.         g_mens_cntx = OslMalloc(sizeof(mens_context_struct));
  391.     }
  392.     memset(g_mens_cntx, 0, sizeof(mens_context_struct));
  393.     GetDateTime(&currTime);
  394.     gui_itoa((S32) currTime.nYear, (U16*) g_mens_cntx->YearBuf, 10);
  395.     sprintf(tmpMon, "%02d", currTime.nMonth);
  396.     AnsiiToUnicodeString(g_mens_cntx->MonBuf, tmpMon);
  397.     sprintf(tmpDay, "%02d", currTime.nDay);
  398.     AnsiiToUnicodeString(g_mens_cntx->DayBuf, tmpDay);
  399.     EntryMensInput();
  400. }
  401. /*****************************************************************************
  402.  * FUNCTION
  403.  *  EntryMensInput
  404.  * DESCRIPTION
  405.  *  Display screen to input
  406.  * PARAMETERS
  407.  *  void
  408.  * RETURNS
  409.  *  void
  410.  *****************************************************************************/
  411. void EntryMensInput(void)
  412. {
  413.     /*----------------------------------------------------------------*/
  414.     /* Local Variables                                                */
  415.     /*----------------------------------------------------------------*/
  416.     U8 *guiBuffer;  /* Buffer holding history data */
  417.     U8 *inputBuffer;
  418.     U16 inputBufferSize;    /* added for inline edit history */
  419.     /*----------------------------------------------------------------*/
  420.     /* Code Body                                                      */
  421.     /*----------------------------------------------------------------*/
  422.     EntryNewScreen(SCR_ID_MENS_INPUT, ExitMensInput, NULL, NULL);
  423.     SetDelScrnIDCallbackHandler(SCR_ID_MENS_INPUT, (HistoryDelCBPtr) MensDelScrCB);
  424.     InitializeCategory57Screen();
  425.     MensFillInlineStruct();
  426.     RegisterHighlightHandler(HighlightMensInputItem);
  427.     guiBuffer = GetCurrGuiBuffer(SCR_ID_MENS_INPUT);
  428.     inputBuffer = GetCurrNInputBuffer(SCR_ID_MENS_INPUT, &inputBufferSize);
  429.     if (inputBuffer != NULL)    /* added for inline edit history */
  430.     {
  431.         SetCategory57Data(wgui_inline_items, MEMS_INLINE_TOTAL, inputBuffer);   /* sets the data */
  432.     }
  433.     DisableCategory57ScreenDone();
  434. #ifndef __MMI_MAINLCD_240X320__
  435.     ShowCategory57Screen(
  436.         STR_HEALTH_MENSIS_DATE_CAPTION,
  437.         GetRootTitleIcon(EXTRA_HEALTH_MENU),
  438.         STR_GLOBAL_OK,
  439.         IMG_GLOBAL_OK,
  440.         STR_GLOBAL_BACK,
  441.         IMG_GLOBAL_BACK,
  442.         MEMS_INLINE_TOTAL,
  443.         NULL,
  444.         wgui_inline_items,
  445.         1,
  446.         guiBuffer);
  447. #else /* __MMI_MAINLCD_240X320__ */ 
  448.     ShowCategory357Screen(
  449.         STR_HEALTH_MENSIS_DATE_CAPTION,
  450.         GetRootTitleIcon(EXTRA_HEALTH_MENU),
  451.         STR_GLOBAL_OK,
  452.         IMG_GLOBAL_OK,
  453.         STR_GLOBAL_BACK,
  454.         IMG_GLOBAL_BACK,
  455.         IMG_SCR_HEALTH_MENSIS,
  456.         MEMS_INLINE_TOTAL,
  457.         NULL,
  458.         wgui_inline_items,
  459.         1,
  460.         guiBuffer);
  461. #endif /* __MMI_MAINLCD_240X320__ */ 
  462.     SetKeyHandler(MensDisplayResult, KEY_LSK, KEY_EVENT_UP);
  463.     SetCategory57RightSoftkeyFunctions(MensDisplayResult, GoBackHistory);
  464. }
  465. /*****************************************************************************
  466.  * FUNCTION
  467.  *  ExitMensInput
  468.  * DESCRIPTION
  469.  *  Exit function of input screen.
  470.  * PARAMETERS
  471.  *  void
  472.  * RETURNS
  473.  *  void
  474.  *****************************************************************************/
  475. void ExitMensInput(void)
  476. {
  477.     /*----------------------------------------------------------------*/
  478.     /* Local Variables                                                */
  479.     /*----------------------------------------------------------------*/
  480.     history Scr;
  481.     U16 inputBufferSize;    /* added for inline edit history */
  482.     S16 nHistory = 0;
  483.     /*----------------------------------------------------------------*/
  484.     /* Code Body                                                      */
  485.     /*----------------------------------------------------------------*/
  486.     Scr.scrnID = SCR_ID_MENS_INPUT;
  487.     if (g_mens_cntx)
  488.     {
  489.         CloseCategory57Screen();
  490.     }
  491.     Scr.entryFuncPtr = EntryMensInput;
  492.     pfnUnicodeStrcpy((S8*) Scr.inputBuffer, (S8*) & nHistory);
  493.     GetCategoryHistory(Scr.guiBuffer);
  494.     GetCategory57Data((U8*) Scr.inputBuffer);           /* added for inline edit history */
  495.     inputBufferSize = (U16) GetCategory57DataSize();    /* added for inline edit history */
  496.     AddNHistory(Scr, inputBufferSize);                  /* added for inline edit history */
  497. }
  498. /*****************************************************************************
  499.  * FUNCTION
  500.  *  HighlightMensInputItem
  501.  * DESCRIPTION
  502.  *  Highlight handler of inline item in input screen.
  503.  * PARAMETERS
  504.  *  nIndex      [IN]        
  505.  * RETURNS
  506.  *  void
  507.  *****************************************************************************/
  508. void HighlightMensInputItem(S32 nIndex)
  509. {
  510.     /*----------------------------------------------------------------*/
  511.     /* Local Variables                                                */
  512.     /*----------------------------------------------------------------*/
  513.     /*----------------------------------------------------------------*/
  514.     /* Code Body                                                      */
  515.     /*----------------------------------------------------------------*/
  516.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  517.     SetCategory57LeftSoftkeyFunction(MensDisplayResult);
  518. }
  519. #define MENS_RESULT_SCREEN
  520. /*****************************************************************************
  521.  * FUNCTION
  522.  *  MensDisplayResult
  523.  * DESCRIPTION
  524.  *  Display corresponding screen according to computation result.
  525.  * PARAMETERS
  526.  *  void
  527.  * RETURNS
  528.  *  void
  529.  *****************************************************************************/
  530. void MensDisplayResult(void)
  531. {
  532.     /*----------------------------------------------------------------*/
  533.     /* Local Variables                                                */
  534.     /*----------------------------------------------------------------*/
  535.     S8 error;
  536.     /*----------------------------------------------------------------*/
  537.     /* Code Body                                                      */
  538.     /*----------------------------------------------------------------*/
  539.     CloseCategory57Screen();
  540.     error = MensValidateInput();
  541.     switch (error)
  542.     {
  543.         case MENS_ERR_DATE:
  544.             DisplayPopup(
  545.                 (U8*) GetString(STR_HEALTH_WRONG_DATE_MSG),
  546.                 IMG_GLOBAL_WARNING,
  547.                 0,
  548.                 UI_POPUP_NOTIFYDURATION_TIME,
  549.                 (U8) WARNING_TONE);
  550.             break;
  551.         case MENS_ERR_PERIOD:
  552.             DisplayPopup(
  553.                 (U8*) GetString(STR_INVALID_AVERAGE_DAY_MESSAGE),
  554.                 IMG_GLOBAL_WARNING,
  555.                 0,
  556.                 UI_POPUP_NOTIFYDURATION_TIME,
  557.                 (U8) WARNING_TONE);
  558.             break;
  559.         default:    /* correct */
  560.             MensPreEntryResult();
  561.             break;
  562.     }
  563. }
  564. /*****************************************************************************
  565.  * FUNCTION
  566.  *  MensValidateInput
  567.  * DESCRIPTION
  568.  *  Validate the correctness of user input.
  569.  * PARAMETERS
  570.  *  void
  571.  * RETURNS
  572.  *  void
  573.  *****************************************************************************/
  574. U8 MensValidateInput(void)
  575. {
  576.     /*----------------------------------------------------------------*/
  577.     /* Local Variables                                                */
  578.     /*----------------------------------------------------------------*/
  579.     S8 tmpMon[MENS_MON_LEN];
  580.     S8 tmpDay[MENS_DAY_LEN];
  581.     S8 tmpYear[MENS_YEAR_LEN];
  582.     S8 AvgDays[MENS_PERIOD_LEN];
  583.     MYTIME currTime, incTime, finalTime;
  584.     U8 tmpPeriod;
  585.     /*----------------------------------------------------------------*/
  586.     /* Code Body                                                      */
  587.     /*----------------------------------------------------------------*/
  588.     /* validate period */
  589.     UnicodeToAnsii(AvgDays, g_mens_cntx->PeriodBuf);
  590.     g_mens_cntx->AvgPeriod = tmpPeriod = (U8) atoi(AvgDays);
  591.     if (tmpPeriod < MENS_MIN_PERIOD || tmpPeriod > MENS_MAX_PERIOD)
  592.     {
  593.         return MENS_ERR_PERIOD;
  594.     }
  595.     /* validate day */
  596.     UnicodeToAnsii(tmpDay, g_mens_cntx->DayBuf);
  597.     UnicodeToAnsii(tmpMon, g_mens_cntx->MonBuf);
  598.     UnicodeToAnsii(tmpYear, g_mens_cntx->YearBuf);
  599.     memset(&g_mens_cntx->InputDate, 0, sizeof(MYTIME));
  600.     g_mens_cntx->InputDate.nDay = atoi(tmpDay);
  601.     g_mens_cntx->InputDate.nMonth = atoi(tmpMon);
  602.     g_mens_cntx->InputDate.nYear = atoi(tmpYear);
  603.     /* daty out of boundary */
  604.     g_mens_cntx->DayOfMon = LastDayOfMonth(g_mens_cntx->InputDate.nMonth, g_mens_cntx->InputDate.nYear);
  605.     if (g_mens_cntx->InputDate.nDay > g_mens_cntx->DayOfMon)
  606.     {
  607.         return MENS_ERR_DATE;
  608.     }
  609.     /* date too large */
  610.     GetDateTime(&currTime);
  611.     if (CompareTime(currTime, g_mens_cntx->InputDate, NULL) == TIME_LESS)
  612.     {
  613.         return MENS_ERR_DATE;
  614.     }
  615.     /* date too small */
  616.     memset(&incTime, 0, sizeof(MYTIME));
  617.     incTime.nMonth = MENS_NUM_PREV_MON;
  618.     DecrementTime(currTime, incTime, &finalTime);
  619.     if (CompareTime(g_mens_cntx->InputDate, finalTime, NULL) == TIME_LESS)
  620.     {
  621.         return MENS_ERR_DATE;
  622.     }
  623.     return MENS_ERR_NONE;
  624. }
  625. /*****************************************************************************
  626.  * FUNCTION
  627.  *  ExitMensResult
  628.  * DESCRIPTION
  629.  *  Exit function of calendar screen.
  630.  * PARAMETERS
  631.  *  void
  632.  * RETURNS
  633.  *  void
  634.  *****************************************************************************/
  635. void ExitMensResult(void)
  636. {
  637.     /*----------------------------------------------------------------*/
  638.     /* Local Variables                                                */
  639.     /*----------------------------------------------------------------*/
  640.     /*----------------------------------------------------------------*/
  641.     /* Code Body                                                      */
  642.     /*----------------------------------------------------------------*/
  643.     if (g_mens_cntx != NULL && g_mens_cntx->IsAddToHistory)
  644.     {
  645.         history Scr;    /* Variable to hold the history data */
  646.         S16 nHistory = 0;
  647.         Scr.scrnID = SCR_ID_MENS_RESULT;
  648.         Scr.entryFuncPtr = EntryMensResult;
  649.         pfnUnicodeStrcpy((S8*) Scr.inputBuffer, (S8*) & nHistory);
  650.         if (g_mens_cntx->CurrDay > 0)
  651.         {
  652.             g_mens_cntx->CurrDay = g_mens_cntx->CurrDay;
  653.         }
  654.         AddHistory(Scr);
  655.     }
  656. #ifdef __MMI_CALENDAR_V2__
  657.     /* Deinit has not been executed */
  658.     if (g_mens_cntx != NULL)
  659.     {
  660.         mmi_frm_scrmem_free((void*)g_mens_cntx->HorizonList[0]);
  661.         mmi_frm_scrmem_free((void*)g_mens_cntx->VerticalList[0]);
  662.         mmi_frm_scrmem_free((void*)g_mens_cntx->MenstrulCell);
  663.         g_mens_cntx->HorizonList[0] = NULL;
  664.         g_mens_cntx->VerticalList[0] = NULL;
  665.         g_mens_cntx->MenstrulCell = NULL;
  666.     }
  667. #endif /* __MMI_CALENDAR_V2__ */ 
  668. }
  669. /*****************************************************************************
  670.  * FUNCTION
  671.  *  EntryMensResult
  672.  * DESCRIPTION
  673.  *  Display result calendar of computation.
  674.  * PARAMETERS
  675.  *  void
  676.  * RETURNS
  677.  *  void
  678.  *****************************************************************************/
  679. void EntryMensResult(void)
  680. {
  681.     /*----------------------------------------------------------------*/
  682.     /* Local Variables                                                */
  683.     /*----------------------------------------------------------------*/
  684.     U8 *guiBuffer;  /* Buffer holding history data */
  685.     MYTIME currTime;
  686.     S32 i, j;
  687. #ifdef __MMI_CALENDAR_V2__
  688.     S32 highlightCell;
  689. #else /* __MMI_CALENDAR_V2__ */ 
  690.     S16 Color[31];
  691.     S16 DiffDays;
  692. #endif /* __MMI_CALENDAR_V2__ */ 
  693.     S8 tmpString[MENS_TITLE_LEN];
  694.     /*----------------------------------------------------------------*/
  695.     /* Code Body                                                      */
  696.     /*----------------------------------------------------------------*/
  697.     EntryNewScreen(SCR_ID_MENS_RESULT, ExitMensResult, NULL, NULL);
  698.     g_mens_cntx->IsAddToHistory = TRUE;
  699.     RegisterCalendarHighlightHandler(HighlightMensNevigeteDate);
  700.     guiBuffer = GetCurrGuiBuffer(SCR_ID_MENS_RESULT);
  701.     /* back ground initialize */
  702.     g_mens_cntx->DayOnFirst = DOW((U16) g_mens_cntx->CurrYear, (U8) g_mens_cntx->CurrMonth, 1);
  703.     g_mens_cntx->DayOfMon = LastDayOfMonth((U8) g_mens_cntx->CurrMonth, (U16) g_mens_cntx->CurrYear);
  704. #ifdef __MMI_CALENDAR_V2__
  705.     g_mens_cntx->HorizonList[0] =
  706.         (U8*) mmi_frm_scrmem_alloc(CLNDR_HORIZON_LIST_CELL_LEN * ENCODING_LENGTH * CLNDR_COLUMN);
  707.     g_mens_cntx->VerticalList[0] =
  708.         (U8*) mmi_frm_scrmem_alloc(CLNDR_VERTICAL_LIST_CELL_LEN * ENCODING_LENGTH * CLNDR_ROW);
  709.     g_mens_cntx->MenstrulCell =
  710.         (wgui_cat83_cell_struct*) mmi_frm_scrmem_alloc((CLNDR_ROW * CLNDR_COLUMN) * CLNDR_CELL_SIZE);
  711.     for (j = 1; j < CLNDR_COLUMN; j++)
  712.     {
  713.         g_mens_cntx->HorizonList[j] = g_mens_cntx->HorizonList[j - 1] + CLNDR_HORIZON_LIST_CELL_LEN * ENCODING_LENGTH;
  714.     }
  715.     for (j = 1; j < CLNDR_ROW; j++)
  716.     {
  717.         g_mens_cntx->VerticalList[j] =
  718.             g_mens_cntx->VerticalList[j - 1] + CLNDR_VERTICAL_LIST_CELL_LEN * ENCODING_LENGTH;
  719.     }
  720.     /* reset memory */
  721.     memset(g_mens_cntx->HorizonList[0], 0, CLNDR_HORIZON_LIST_CELL_LEN * ENCODING_LENGTH * CLNDR_COLUMN);
  722.     memset(g_mens_cntx->VerticalList[0], 0, CLNDR_VERTICAL_LIST_CELL_LEN * ENCODING_LENGTH * CLNDR_ROW);
  723.     memset(g_mens_cntx->MenstrulCell, 0, CLNDR_ROW * CLNDR_COLUMN * CLNDR_CELL_SIZE);
  724.     /* Set Calendar info */
  725.     g_mens_cntx->MensTime.nYear = g_mens_cntx->CurrYear;
  726.     g_mens_cntx->MensTime.nMonth = g_mens_cntx->CurrMonth;
  727.     g_mens_cntx->MensTime.nDay = g_mens_cntx->CurrDay;
  728.     /* GetDateTime(&currTime); */
  729.     sprintf(tmpString, "%d %02d", (U16) g_mens_cntx->CurrYear, g_mens_cntx->CurrMonth);
  730.     AnsiiToUnicodeString(g_mens_cntx->TitleString, tmpString);
  731.     mmi_clndr_get_weekday(g_mens_cntx->HorizonList);
  732.     mmi_mens_construct_cell_info();
  733.     wgui_cat83_set_horizontal_string(g_mens_cntx->HorizonList);
  734.     highlightCell = g_mens_cntx->DayOnFirst + g_mens_cntx->CurrDay - 1;
  735.     wgui_cat83_register_cell_highlight_handler(mmi_mens_highlight);
  736.     wgui_cat83_register_left_arrow_key_handler(mmi_mens_left_out_of_boundary);
  737.     wgui_cat83_register_right_arrow_key_handler(mmi_mens_right_out_of_boundary);
  738.     wgui_cat83_register_up_arrow_key_handler(mmi_mens_up_out_of_boundary);
  739.     wgui_cat83_register_down_arrow_key_handler(mmi_mens_down_out_of_boundary);
  740.     wgui_cat83_register_up_side_key_handler(mmi_mens_up_side_key);
  741.     wgui_cat83_register_down_side_key_handler(mmi_mens_down_side_key);
  742.     mmi_mens_set_content();
  743.     ShowCategory83Screen(
  744.         IMG_CALENDAR_JAN,
  745.         (U8 **) g_mens_cntx->HorizonList,
  746.         (wgui_cat83_cell_struct*) g_mens_cntx->MenstrulCell,
  747.         CLNDR_ROW,
  748.         CLNDR_COLUMN,
  749.         -1,
  750.         -1,
  751.         highlightCell / CLNDR_COLUMN,
  752.         highlightCell % CLNDR_COLUMN,
  753.         CAT83_CELL_BG_FILL_HORIZONTAL,
  754.         CAT83_CELL_TEXT_DISPLAY_LEFT_BOTTOM,
  755.         CAT83_CELL_ICON_DISPLAY_RIGHT_TOP);
  756.     ChangeRightSoftkey(STR_GLOBAL_BACK, 0);
  757.     ChangeLeftSoftkey(STR_GLOBAL_OPTIONS, 0);
  758. #else /* __MMI_CALENDAR_V2__ */ 
  759.     memset(&currTime, 0, sizeof(MYTIME));
  760.     currTime.nMonth = (U8) g_mens_cntx->CurrMonth;
  761.     currTime.nYear = (U16) g_mens_cntx->CurrYear;
  762.     currTime.nDay = 1;
  763.     InitializeCategory81Screen(
  764.         g_mens_cntx->DayOnFirst,
  765.         g_mens_cntx->DayOfMon,
  766.         g_mens_cntx->CurrDay,
  767.         g_mens_cntx->CurrMonth,
  768.         g_mens_cntx->CurrYear);
  769. #ifdef __MMI_SLIM_CALENDAR__
  770.     SetCalendarBackground((U16) IMG_CALENDAR_JAN);
  771. #else 
  772.     SetCalendarBackground((U16) (IMG_CALENDAR_JAN + g_mens_cntx->CurrMonth - 1));
  773. #endif 
  774.     /* title string */
  775.     sprintf(tmpString, "%d %02d", (U16) g_mens_cntx->CurrYear, g_mens_cntx->CurrMonth);
  776.     AnsiiToUnicodeString(g_mens_cntx->TitleString, tmpString);
  777.     /* get/set color of days */
  778.     DiffDays = MensGetDaysDifference(&currTime, &g_mens_cntx->InputDate);
  779.     for (i = 1; i <= g_mens_cntx->DayOfMon; i++, DiffDays++)
  780.     {
  781.         Color[i] = (MensGetDisplayColor(DiffDays, g_mens_cntx->AvgPeriod));
  782.         if (Color[i] != COLOR_NONE)
  783.         {
  784.             SetCalendarDay(i, (U8) (CALENDAR_SPECIAL_DAY1 + Color[i] - 1));
  785.         }
  786.     }
  787.     ShowCategory81Screen(
  788.         (U8*) g_mens_cntx->TitleString,
  789.         STR_GLOBAL_OK,
  790.         IMG_GLOBAL_OK,
  791.         STR_GLOBAL_BACK,
  792.         IMG_GLOBAL_BACK,
  793.         (U8*) GetString(STR_CALENDER_MESSAAGE1),
  794.         (U8*) GetString(STR_CALENDER_MESSAAGE2),
  795.         guiBuffer);
  796.     SetCalendarMonthFunctions(MensGoToPreviousDay, MensGoToNextDay, MensGoToPreviousWeek, MensGoToNextWeek);
  797. #ifdef __MMI_TOUCH_SCREEN__
  798.     SetCalendarMonthChangeFunctions(MensGoToPreviousDay, MensGoToNextDay);
  799. #endif 
  800.     SetKeyHandler(MensGoToNextMonth, KEY_VOL_DOWN, KEY_EVENT_DOWN);
  801.     SetKeyHandler(MensGoToPreviousMonth, KEY_VOL_UP, KEY_EVENT_DOWN);
  802. #endif /* __MMI_CALENDAR_V2__ */ 
  803.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  804.     SetLeftSoftkeyFunction(EntryMensProbability, KEY_EVENT_UP);
  805. }
  806. /*****************************************************************************
  807.  * FUNCTION
  808.  *  MensPreEntryResult
  809.  * DESCRIPTION
  810.  *  Initialize variables and go to result screen.
  811.  * PARAMETERS
  812.  *  void
  813.  * RETURNS
  814.  *  void
  815.  *****************************************************************************/
  816. void MensPreEntryResult(void)
  817. {
  818.     /*----------------------------------------------------------------*/
  819.     /* Local Variables                                                */
  820.     /*----------------------------------------------------------------*/
  821.     MYTIME currTime;
  822.     /*----------------------------------------------------------------*/
  823.     /* Code Body                                                      */
  824.     /*----------------------------------------------------------------*/
  825.     GetDateTime(&currTime);
  826.     g_mens_cntx->NumOfMon = 0;
  827.     g_mens_cntx->CurrMonth = currTime.nMonth;
  828.     g_mens_cntx->CurrYear = currTime.nYear;
  829.     g_mens_cntx->CurrDay = currTime.nDay;
  830.     EntryMensResult();
  831. }
  832. /*****************************************************************************
  833.  * FUNCTION
  834.  *  HighlightMensNevigeteDate
  835.  * DESCRIPTION
  836.  *  Highlight handler of calendar screen.
  837.  * PARAMETERS
  838.  *  index       [IN]        
  839.  * RETURNS
  840.  *  void
  841.  *****************************************************************************/
  842. void HighlightMensNevigeteDate(S32 index)
  843. {
  844.     /*----------------------------------------------------------------*/
  845.     /* Local Variables                                                */
  846.     /*----------------------------------------------------------------*/
  847.     /*----------------------------------------------------------------*/
  848.     /* Code Body                                                      */
  849.     /*----------------------------------------------------------------*/
  850.     g_mens_cntx->CurrDay = (U8) index;
  851. }
  852. /*****************************************************************************
  853.  * FUNCTION
  854.  *  MensGoToPreviousDay
  855.  * DESCRIPTION
  856.  *  Handle left arrow key when highlighting on 1st day of month.
  857.  * PARAMETERS
  858.  *  void
  859.  * RETURNS
  860.  *  void
  861.  *****************************************************************************/
  862. void MensGoToPreviousDay(void)
  863. {
  864.     /*----------------------------------------------------------------*/
  865.     /* Local Variables                                                */
  866.     /*----------------------------------------------------------------*/
  867.     /*----------------------------------------------------------------*/
  868.     /* Code Body                                                      */
  869.     /*----------------------------------------------------------------*/
  870.     if (g_mens_cntx->NumOfMon > 0)
  871.     {
  872.         MYTIME myTime, incTime, finaltime;
  873.         /* do not have to prevent 1970/01/01 because can not nevigate previous month */
  874.         memset(&myTime, 0, sizeof(MYTIME));
  875.         myTime.nDay = 1;
  876.         myTime.nMonth = (U8) g_mens_cntx->CurrMonth;
  877.         myTime.nYear = (U16) g_mens_cntx->CurrYear;
  878.         memset(&incTime, 0, sizeof(MYTIME));
  879.         incTime.nDay = 1;
  880.         DecrementTime(myTime, incTime, &finaltime);
  881.         g_mens_cntx->NumOfMon--;
  882.         g_mens_cntx->CurrYear = finaltime.nYear;
  883.         g_mens_cntx->CurrMonth = finaltime.nMonth;
  884.         g_mens_cntx->CurrDay = finaltime.nDay;
  885.         g_mens_cntx->IsAddToHistory = FALSE;
  886.         EntryMensResult();
  887.     }
  888.     else
  889.     {
  890.         g_mens_cntx->IsAddToHistory = TRUE;
  891.         MensDisplayBoundaryPopup();
  892.         ClndPopupFlag = TRUE;   /* 090605 Calendar Calvin added */
  893.     }
  894. }
  895. /*****************************************************************************
  896.  * FUNCTION
  897.  *  MensGoToNextDay
  898.  * DESCRIPTION
  899.  *  Handle right arrow key when highlighting on last day of month.
  900.  * PARAMETERS
  901.  *  void
  902.  * RETURNS
  903.  *  void
  904.  *****************************************************************************/
  905. void MensGoToNextDay(void)
  906. {
  907.     /*----------------------------------------------------------------*/
  908.     /* Local Variables                                                */
  909.     /*----------------------------------------------------------------*/
  910.     /*----------------------------------------------------------------*/
  911.     /* Code Body                                                      */
  912.     /*----------------------------------------------------------------*/
  913.     if (g_mens_cntx->NumOfMon < MENS_MAX_NAVI_MON)
  914.     {
  915.         if (g_mens_cntx->CurrYear != 2030 || g_mens_cntx->CurrMonth != 12)
  916.         {
  917.             MYTIME myTime, incTime, finaltime;
  918.             memset(&myTime, 0, sizeof(MYTIME));
  919.             myTime.nDay = 1;
  920.             myTime.nMonth = (U8) g_mens_cntx->CurrMonth;
  921.             myTime.nYear = (U16) g_mens_cntx->CurrYear;
  922.             memset(&incTime, 0, sizeof(MYTIME));
  923.             incTime.nMonth = 1;
  924.             IncrementTime(myTime, incTime, &finaltime);
  925.             g_mens_cntx->NumOfMon++;
  926.             g_mens_cntx->CurrYear = finaltime.nYear;
  927.             g_mens_cntx->CurrMonth = finaltime.nMonth;
  928.             g_mens_cntx->CurrDay = finaltime.nDay;
  929.             g_mens_cntx->IsAddToHistory = FALSE;
  930.             EntryMensResult();
  931.             return;
  932.         }
  933.     }
  934.     g_mens_cntx->IsAddToHistory = TRUE;
  935.     MensDisplayBoundaryPopup();
  936.     ClndPopupFlag = TRUE;   /* 090605 Calendar Calvin added */
  937. }
  938. /*****************************************************************************
  939.  * FUNCTION
  940.  *  MensGoToPreviousWeek
  941.  * DESCRIPTION
  942.  *  Handle up arrow key when highlighting on first week of the month.
  943.  * PARAMETERS
  944.  *  void
  945.  * RETURNS
  946.  *  void
  947.  *****************************************************************************/
  948. void MensGoToPreviousWeek(void)
  949. {
  950.     /*----------------------------------------------------------------*/
  951.     /* Local Variables                                                */
  952.     /*----------------------------------------------------------------*/
  953.     /*----------------------------------------------------------------*/
  954.     /* Code Body                                                      */
  955.     /*----------------------------------------------------------------*/
  956.     if (g_mens_cntx->NumOfMon > 0)
  957.     {
  958.         MYTIME myTime, incTime, finaltime;
  959.         memset(&myTime, 0, sizeof(MYTIME));
  960.         myTime.nDay = (U8) g_mens_cntx->CurrDay;
  961.         myTime.nMonth = (U8) g_mens_cntx->CurrMonth;
  962.         myTime.nYear = (U16) g_mens_cntx->CurrYear;
  963.         memset(&incTime, 0, sizeof(MYTIME));
  964.         incTime.nDay = 7;
  965.         DecrementTime(myTime, incTime, &finaltime);
  966.         g_mens_cntx->CurrYear = finaltime.nYear;
  967.         g_mens_cntx->CurrMonth = finaltime.nMonth;
  968.         g_mens_cntx->CurrDay = finaltime.nDay;
  969.         g_mens_cntx->NumOfMon--;
  970.         g_mens_cntx->IsAddToHistory = FALSE;
  971.         EntryMensResult();
  972.     }
  973.     else
  974.     {
  975.         g_mens_cntx->IsAddToHistory = TRUE;
  976.         MensDisplayBoundaryPopup();
  977.         ClndPopupFlag = TRUE;   /* 090605 Calendar Calvin added */
  978.     }
  979. }
  980. /*****************************************************************************
  981.  * FUNCTION
  982.  *  MensGoToNextWeek
  983.  * DESCRIPTION
  984.  *  Handle down arrow key when highlighting on last week of the month.
  985.  * PARAMETERS
  986.  *  void
  987.  * RETURNS
  988.  *  void
  989.  *****************************************************************************/
  990. void MensGoToNextWeek(void)
  991. {
  992.     /*----------------------------------------------------------------*/
  993.     /* Local Variables                                                */
  994.     /*----------------------------------------------------------------*/
  995.     /*----------------------------------------------------------------*/
  996.     /* Code Body                                                      */
  997.     /*----------------------------------------------------------------*/
  998.     if (g_mens_cntx->NumOfMon < MENS_MAX_NAVI_MON)
  999.     {
  1000.         if (g_mens_cntx->CurrYear != 2030 || g_mens_cntx->CurrMonth != 12)
  1001.         {
  1002.             MYTIME myTime, incTime, finaltime;
  1003.             memset(&myTime, 0, sizeof(MYTIME));
  1004.             myTime.nDay = (U8) g_mens_cntx->CurrDay;
  1005.             myTime.nMonth = (U8) g_mens_cntx->CurrMonth;
  1006.             myTime.nYear = (U16) g_mens_cntx->CurrYear;
  1007.             memset(&incTime, 0, sizeof(MYTIME));
  1008.             incTime.nDay = 7;
  1009.             IncrementTime(myTime, incTime, &finaltime);
  1010.             g_mens_cntx->CurrYear = finaltime.nYear;
  1011.             g_mens_cntx->CurrMonth = finaltime.nMonth;
  1012.             g_mens_cntx->CurrDay = finaltime.nDay;
  1013.             g_mens_cntx->NumOfMon++;
  1014.             g_mens_cntx->IsAddToHistory = FALSE;
  1015.             EntryMensResult();
  1016.             return;
  1017.         }
  1018.     }
  1019.     g_mens_cntx->IsAddToHistory = TRUE;
  1020.     MensDisplayBoundaryPopup();
  1021.     ClndPopupFlag = TRUE;   /* 090605 Calendar Calvin added */
  1022. }
  1023. /*****************************************************************************
  1024.  * FUNCTION
  1025.  *  MensGoToPreviousMonth
  1026.  * DESCRIPTION
  1027.  *  Side up key handler, go to the first day of previois month.
  1028.  * PARAMETERS
  1029.  *  void
  1030.  * RETURNS
  1031.  *  void
  1032.  *****************************************************************************/
  1033. void MensGoToPreviousMonth(void)
  1034. {
  1035.     /*----------------------------------------------------------------*/
  1036.     /* Local Variables                                                */
  1037.     /*----------------------------------------------------------------*/
  1038.     /*----------------------------------------------------------------*/
  1039.     /* Code Body                                                      */
  1040.     /*----------------------------------------------------------------*/
  1041.     if (g_mens_cntx->NumOfMon > 0)
  1042.     {
  1043.         MYTIME myTime, incTime, finaltime;
  1044.         memset(&myTime, 0, sizeof(MYTIME));
  1045.         myTime.nDay = 1;
  1046.         myTime.nMonth = (U8) g_mens_cntx->CurrMonth;
  1047.         myTime.nYear = (U16) g_mens_cntx->CurrYear;
  1048.         memset(&incTime, 0, sizeof(MYTIME));
  1049.         incTime.nMonth = 1;
  1050.         DecrementTime(myTime, incTime, &finaltime);
  1051.         g_mens_cntx->CurrYear = finaltime.nYear;
  1052.         g_mens_cntx->CurrMonth = finaltime.nMonth;
  1053.         g_mens_cntx->CurrDay = finaltime.nDay;
  1054.         g_mens_cntx->NumOfMon--;
  1055.         g_mens_cntx->IsAddToHistory = FALSE;
  1056.         EntryMensResult();
  1057.     }
  1058.     else
  1059.     {
  1060.         g_mens_cntx->IsAddToHistory = TRUE;
  1061.         MensDisplayBoundaryPopup();
  1062.     }
  1063. }
  1064. /*****************************************************************************
  1065.  * FUNCTION
  1066.  *  MensGoToNextMonth
  1067.  * DESCRIPTION
  1068.  *  Side down key handler, go to the first day of next month.
  1069.  * PARAMETERS
  1070.  *  void
  1071.  * RETURNS
  1072.  *  void
  1073.  *****************************************************************************/
  1074. void MensGoToNextMonth()
  1075. {
  1076.     /*----------------------------------------------------------------*/
  1077.     /* Local Variables                                                */
  1078.     /*----------------------------------------------------------------*/
  1079.     /*----------------------------------------------------------------*/
  1080.     /* Code Body                                                      */
  1081.     /*----------------------------------------------------------------*/
  1082.     if (g_mens_cntx->NumOfMon < MENS_MAX_NAVI_MON)
  1083.     {
  1084.         if (g_mens_cntx->CurrYear != 2030 || g_mens_cntx->CurrMonth != 12)
  1085.         {
  1086.             MYTIME myTime, incTime, finaltime;
  1087.             memset(&myTime, 0, sizeof(MYTIME));
  1088.             myTime.nDay = 1;
  1089.             myTime.nMonth = (U8) g_mens_cntx->CurrMonth;
  1090.             myTime.nYear = (U16) g_mens_cntx->CurrYear;
  1091.             memset(&incTime, 0, sizeof(MYTIME));
  1092.             incTime.nMonth = 1;
  1093.             IncrementTime(myTime, incTime, &finaltime);
  1094.             g_mens_cntx->NumOfMon++;
  1095.             g_mens_cntx->CurrYear = finaltime.nYear;
  1096.             g_mens_cntx->CurrMonth = finaltime.nMonth;
  1097.             g_mens_cntx->CurrDay = finaltime.nDay;
  1098.             g_mens_cntx->IsAddToHistory = FALSE;
  1099.             EntryMensResult();
  1100.             return;
  1101.         }
  1102.     }
  1103.     g_mens_cntx->IsAddToHistory = TRUE;
  1104.     MensDisplayBoundaryPopup();
  1105. }
  1106. /*****************************************************************************
  1107.  * FUNCTION
  1108.  *  MensDisplayBoundaryPopup
  1109.  * DESCRIPTION
  1110.  *  Display popup screen for out of boundary.
  1111.  * PARAMETERS
  1112.  *  void
  1113.  * RETURNS
  1114.  *  void
  1115.  *****************************************************************************/
  1116. void MensDisplayBoundaryPopup(void)
  1117. {
  1118.     /*----------------------------------------------------------------*/
  1119.     /* Local Variables                                                */
  1120.     /*----------------------------------------------------------------*/
  1121.     /*----------------------------------------------------------------*/
  1122.     /* Code Body                                                      */
  1123.     /*----------------------------------------------------------------*/
  1124.     DisplayPopup(
  1125.         (U8*) GetString(STR_CANNOT_NAVIGATE_FURTHER_MESSAGE),
  1126.         IMG_GLOBAL_WARNING,
  1127.         0,
  1128.         UI_POPUP_NOTIFYDURATION_TIME,
  1129.         (U8) WARNING_TONE);
  1130. }
  1131. #define MENS_PROBABILITY
  1132. /*****************************************************************************
  1133.  * FUNCTION
  1134.  *  MensCalcProbability
  1135.  * DESCRIPTION
  1136.  *  To calculate the probablity of ovulation.
  1137.  * PARAMETERS
  1138.  *  void
  1139.  * RETURNS
  1140.  *  probablity value
  1141.  *****************************************************************************/
  1142. S32 MensCalcProbability(void)
  1143. {
  1144.     /*----------------------------------------------------------------*/
  1145.     /* Local Variables                                                */
  1146.     /*----------------------------------------------------------------*/
  1147.     FLOAT prob;
  1148.     S16 DiffDays;
  1149.     MYTIME tmpDate;
  1150.     /*----------------------------------------------------------------*/
  1151.     /* Code Body                                                      */
  1152.     /*----------------------------------------------------------------*/
  1153.     memset(&tmpDate, 0, sizeof(MYTIME));
  1154.     tmpDate.nDay = (U8) g_mens_cntx->CurrDay;
  1155.     tmpDate.nMonth = (U8) g_mens_cntx->CurrMonth;
  1156.     tmpDate.nYear = (U16) g_mens_cntx->CurrYear;
  1157.     DiffDays = MensGetDaysDifference(&tmpDate, &g_mens_cntx->InputDate);
  1158.     prob = (MensGetPregancyProb((S16) DiffDays, (S16) g_mens_cntx->AvgPeriod));
  1159.     return (S32) (prob * 100);
  1160. }
  1161. /*****************************************************************************
  1162.  * FUNCTION
  1163.  *  EntryMensProbability
  1164.  * DESCRIPTION
  1165.  *  Display probability screen.
  1166.  * PARAMETERS
  1167.  *  void
  1168.  * RETURNS
  1169.  *  void
  1170.  *****************************************************************************/
  1171. void EntryMensProbability(void)
  1172. {
  1173.     /*----------------------------------------------------------------*/
  1174.     /* Local Variables                                                */
  1175.     /*----------------------------------------------------------------*/
  1176.     U8 *guiBuffer;  /* Buffer holding history data */
  1177.     S32 Prob;
  1178.     /*----------------------------------------------------------------*/
  1179.     /* Code Body                                                      */
  1180.     /*----------------------------------------------------------------*/
  1181.     EntryNewScreen(SCR_ID_MENS_PROB, NULL, EntryMensProbability, NULL);
  1182.     guiBuffer = GetCurrGuiBuffer(SCR_ID_MENS_PROB);
  1183.     Prob = MensCalcProbability();
  1184.     ShowCategory72Screen(
  1185.         STR_SCR_HEALTH_MENSIS_PROBABILITY_CAPTION,
  1186.         GetRootTitleIcon(EXTRA_HEALTH_MENU),
  1187.         STR_GLOBAL_OK,
  1188.         IMG_GLOBAL_OK,
  1189.         0,
  1190.         0,
  1191.         (U8*) GetString(STR_SCR_HEALTH_MENSIS_PROBABILITY_MESSAGE),
  1192.         Prob,
  1193.         guiBuffer);
  1194.     SetLeftSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1195. }
  1196. #define MENS_UTILITY
  1197. /*****************************************************************************
  1198.  * FUNCTION
  1199.  *  MensGetPregancyProb
  1200.  * DESCRIPTION
  1201.  *  This function is to calculate probability of pregnancy.
  1202.  * PARAMETERS
  1203.  *  DiffDay         [IN]        The number of diffenent dates between given date and menstrual date
  1204.  *  AvgPeriod       [IN]        Average perviods
  1205.  * RETURNS
  1206.  *  FLOAT    the probability of pregnancy
  1207.  *****************************************************************************/
  1208. FLOAT MensGetPregancyProb(S16 DiffDay, S16 AvgPeriod)
  1209. {
  1210.     /*----------------------------------------------------------------*/
  1211.     /* Local Variables                                                */
  1212.     /*----------------------------------------------------------------*/
  1213.     S16 i;
  1214.     S16 Nth;    /* the Nth day from menstrual date */
  1215.     S16 OD;     /* the estimated ovulated date */
  1216.     /*----------------------------------------------------------------*/
  1217.     /* Code Body                                                      */
  1218.     /*----------------------------------------------------------------*/
  1219.     for (i = 0; DiffDay < 0; i++)
  1220.     {
  1221.         DiffDay += AvgPeriod * i;
  1222.     }
  1223.     Nth = DiffDay % AvgPeriod;
  1224.     OD = AvgPeriod / 2;
  1225.     if (Nth < MENS_ZERO_PROB_PERIOD)
  1226.     {
  1227.         return (FLOAT) 0.01;
  1228.     }
  1229.     else if (Nth <= (OD + MENS_OVULATION_DAYS) && Nth >= (OD - MENS_OVULATION_DAYS))
  1230.     {
  1231.         return (FLOAT) 0.99;
  1232.     }
  1233.     else if (Nth < AvgPeriod / 2)
  1234.     {
  1235.         return (FLOAT) Nth *2 / AvgPeriod;
  1236.     }
  1237.     else
  1238.     {
  1239.         return (2 - (FLOAT) 2 * Nth / (AvgPeriod));
  1240.     }
  1241. }
  1242. /*****************************************************************************
  1243.  * FUNCTION
  1244.  *  MensGetDisplayColor
  1245.  * DESCRIPTION
  1246.  *  This function is to calculate which color to display of a given date.
  1247.  * PARAMETERS
  1248.  *  DiffDay         [IN]        The number of diffenent dates between given date and menstrual date
  1249.  *  AvgPeriod       [IN]        Average perviods
  1250.  * RETURNS
  1251.  *  enum MENS_COLOR_EMUM the color to be display
  1252.  *****************************************************************************/
  1253. MENS_COLOR_EMUM MensGetDisplayColor(S16 DiffDay, U8 AvgPeriod)
  1254. {
  1255.     /*----------------------------------------------------------------*/
  1256.     /* Local Variables                                                */
  1257.     /*----------------------------------------------------------------*/
  1258.     S16 i;
  1259.     S16 Nth;    /* the Nth day from menstrual date */
  1260.     S16 OD;     /* the estimated ovulated date */
  1261.     /*----------------------------------------------------------------*/
  1262.     /* Code Body                                                      */
  1263.     /*----------------------------------------------------------------*/
  1264.     for (i = 0; DiffDay < 0; i++)
  1265.     {
  1266.         DiffDay += AvgPeriod * i;
  1267.     }
  1268.     Nth = DiffDay % AvgPeriod;
  1269.     OD = AvgPeriod / 2;
  1270.     if (Nth < MENS_PERIOD)
  1271.     {
  1272.         return RED_COLOR;
  1273.     }
  1274.     else if (Nth == OD)
  1275.     {
  1276.         return ORANGE_COLOR;
  1277.     }
  1278.     else if (Nth <= (OD + MENS_OVULATION_DAYS) && Nth >= (OD - MENS_OVULATION_DAYS))
  1279.     {
  1280.         return YELLOW_COLOR;
  1281.     }
  1282.     else
  1283.     {
  1284.         return COLOR_NONE;
  1285.     }
  1286. }
  1287. /*****************************************************************************
  1288.  * FUNCTION
  1289.  *  MensGetDaysDifference
  1290.  * DESCRIPTION
  1291.  *  This function is to calculate number difference days between two date.
  1292.  * PARAMETERS
  1293.  *  t1      [IN]        Date to be computed
  1294.  *  t2      [IN]        Date to be computed
  1295.  * RETURNS
  1296.  *  Difference between t1 and t2 (t1 - t2).
  1297.  *****************************************************************************/
  1298. S16 MensGetDaysDifference(MYTIME *t1, MYTIME *t2)
  1299. {
  1300.     /*----------------------------------------------------------------*/
  1301.     /* Local Variables                                                */
  1302.     /*----------------------------------------------------------------*/
  1303.     S16 Result;
  1304.     MYTIME startTime, endTime, incTime;
  1305.     U8 SignFlag;
  1306.     TIME_EQUALITY eq = CompareTime(*t1, *t2, NULL);
  1307.     /*----------------------------------------------------------------*/
  1308.     /* Code Body                                                      */
  1309.     /*----------------------------------------------------------------*/
  1310.     memset(&incTime, 0, sizeof(MYTIME));
  1311.     if (eq == TIME_LESS)    /* t1 < t2 */
  1312.     {
  1313.         startTime = *t1;
  1314.         endTime = *t2;
  1315.         SignFlag = 0;
  1316.     }
  1317.     else if (eq == TIME_GREATER)    /* t1 > t2 */
  1318.     {
  1319.         startTime = *t2;
  1320.         endTime = *t1;
  1321.         SignFlag = 1;
  1322.     }
  1323.     else    /* no difference */
  1324.     {
  1325.         return 0;
  1326.     }
  1327.     /* day */
  1328.     if (endTime.nMonth > startTime.nMonth || endTime.nYear > startTime.nYear)
  1329.     {
  1330.         Result = endTime.nDay + LastDayOfMonth(startTime.nMonth, startTime.nYear) - startTime.nDay;
  1331.         incTime.nMonth = 1;
  1332.         IncrementTime(startTime, incTime, &startTime);
  1333.         startTime.nDay = 1; /* to prevent day out of boundary */
  1334.         /* month */
  1335.         while (!(endTime.nMonth == startTime.nMonth && endTime.nYear == startTime.nYear))
  1336.         {
  1337.             Result += LastDayOfMonth(startTime.nMonth, startTime.nYear);
  1338.             IncrementTime(startTime, incTime, &startTime);
  1339.         }
  1340.     }
  1341.     else
  1342.     {
  1343.         Result = endTime.nDay - startTime.nDay;
  1344.     }
  1345.     if (SignFlag == 1)
  1346.     {
  1347.         return Result;
  1348.     }
  1349.     else
  1350.     {
  1351.         return Result * (-1);
  1352.     }
  1353. }
  1354. #ifdef __MMI_CALENDAR_V2__
  1355. /*****************************************************************************
  1356.  * FUNCTION
  1357.  *  mmi_mens_construct_cell_info
  1358.  * DESCRIPTION
  1359.  *  
  1360.  * PARAMETERS
  1361.  *  void
  1362.  * RETURNS
  1363.  *  void
  1364.  *****************************************************************************/
  1365. void mmi_mens_construct_cell_info(void)
  1366. {
  1367.     /*----------------------------------------------------------------*/
  1368.     /* Local Variables                                                */
  1369.     /*----------------------------------------------------------------*/
  1370.     S32 i, taskPos, nextMonthBoundary;
  1371.     wgui_cat83_cell_struct *cell;
  1372.     MYTIME preMonth, incTime, currTime;
  1373.     U8 lastDayofPreMonth;
  1374.     S16 DiffDays;
  1375.     S16 Color[31];
  1376.     /*----------------------------------------------------------------*/
  1377.     /* Code Body                                                      */
  1378.     /*----------------------------------------------------------------*/
  1379.     memset(&preMonth, 0, sizeof(MYTIME));
  1380.     memset(&incTime, 0, sizeof(MYTIME));
  1381.     memset(&currTime, 0, sizeof(MYTIME));
  1382.     /* GetDateTime(&currTime); */
  1383.     currTime.nMonth = (U8) g_mens_cntx->CurrMonth;
  1384.     currTime.nYear = (U16) g_mens_cntx->CurrYear;
  1385.     currTime.nDay = 1;
  1386.     incTime.nMonth = 1;
  1387. #ifdef MMI_ON_WIN32
  1388.     DecrementTime(currTime, incTime, & preMonth);
  1389.     lastDayofPreMonth = LastDayOfMonth(preMonth.nMonth, preMonth.nYear);
  1390. #else
  1391.     applib_dt_decrease_time(
  1392.         (applib_time_struct*) & currTime,
  1393.         (applib_time_struct*) & incTime,
  1394.         (applib_time_struct*) & preMonth);
  1395.     lastDayofPreMonth = applib_dt_last_day_of_mon(preMonth.nMonth, preMonth.nYear);
  1396. #endif    
  1397.     cell = g_mens_cntx->MenstrulCell + (g_mens_cntx->DayOnFirst);
  1398.     /* last month */
  1399.     for (i = g_mens_cntx->DayOnFirst - 1; i >= 0; i--)
  1400.     {
  1401.         cell--;
  1402.         mmi_clndr_util_num_to_unicode(lastDayofPreMonth, (U8*) cell->text, CAT83_MAX_CELL_TEXT);
  1403.         cell->valid = MMI_FALSE;
  1404.         cell->bg_index = CAT83_COLOR_NONE;
  1405.         lastDayofPreMonth--;
  1406.     }
  1407.     /* this month */
  1408.     cell = g_mens_cntx->MenstrulCell + g_mens_cntx->DayOnFirst;
  1409.     DiffDays = MensGetDaysDifference(&currTime, &g_mens_cntx->InputDate);
  1410.     for (i = 1; i <= g_mens_cntx->DayOfMon; i++)
  1411.     {
  1412.         /* get/set color of days */
  1413.         Color[i] = (MensGetDisplayColor(DiffDays, g_mens_cntx->AvgPeriod));
  1414.         if (Color[i] != COLOR_NONE)
  1415.         {
  1416.             cell->bg_index = CAT83_COLOR_MENSTRUAL + Color[i] - 1;
  1417.         }
  1418.         else
  1419.         {
  1420.             cell->bg_index = CAT83_COLOR_NONE;
  1421.         }
  1422.         mmi_clndr_util_num_to_unicode(i, (U8*) cell->text, CAT83_MAX_CELL_TEXT);
  1423.         cell->valid = MMI_TRUE;
  1424.         cell++;
  1425.         DiffDays++;
  1426.     }
  1427.     /* next month */
  1428.     nextMonthBoundary = CLNDR_ROW * CLNDR_COLUMN - (g_mens_cntx->DayOnFirst + g_mens_cntx->DayOfMon);
  1429.     for (i = 1; i <= nextMonthBoundary; i++)
  1430.     {
  1431.         mmi_clndr_util_num_to_unicode(i, (U8*) cell->text, CAT83_MAX_CELL_TEXT);
  1432.         cell->bg_index = CAT83_COLOR_NONE;
  1433.         cell->valid = MMI_FALSE;
  1434.         cell++;
  1435.     }
  1436. }
  1437. /*****************************************************************************
  1438.  * FUNCTION
  1439.  *  mmi_mens_highlight
  1440.  * DESCRIPTION
  1441.  *  
  1442.  * PARAMETERS
  1443.  *  row         [IN]        
  1444.  *  column      [IN]        
  1445.  * RETURNS
  1446.  *  
  1447.  *****************************************************************************/
  1448. MMI_BOOL mmi_mens_highlight(U32 row, U32 column)
  1449. {
  1450.     /*----------------------------------------------------------------*/
  1451.     /* Local Variables                                                */
  1452.     /*----------------------------------------------------------------*/
  1453.     U8 totaldays;
  1454.     S8 tmpString[MENS_TITLE_LEN];
  1455.     /*----------------------------------------------------------------*/
  1456.     /* Code Body                                                      */
  1457.     /*----------------------------------------------------------------*/
  1458.     totaldays = (row * CLNDR_COLUMN) + column + 1;
  1459.     g_mens_cntx->CurrDay = totaldays - g_mens_cntx->DayOnFirst;
  1460.     /* g_mens_cntx->CalTime.DayIndex = DOW(g_clndr_cntx->CalTime.nYear, g_clndr_cntx->CalTime.nMonth, g_clndr_cntx->CalTime.nDay); */
  1461.     sprintf(tmpString, "%d %02d", (U16) g_mens_cntx->CurrYear, g_mens_cntx->CurrMonth);
  1462.     AnsiiToUnicodeString(g_mens_cntx->TitleString, tmpString);
  1463.     wgui_cat83_set_normal_title((U8*) g_mens_cntx->TitleString);
  1464.     return MMI_FALSE;
  1465. }
  1466. /*****************************************************************************
  1467.  * FUNCTION
  1468.  *  mmi_mens_left_out_of_boundary
  1469.  * DESCRIPTION
  1470.  *  
  1471.  * PARAMETERS
  1472.  *  row         [IN]        
  1473.  *  column      [IN]        
  1474.  * RETURNS
  1475.  *  
  1476.  *****************************************************************************/
  1477. MMI_BOOL mmi_mens_left_out_of_boundary(U32 row, U32 column)
  1478. {
  1479.     /*----------------------------------------------------------------*/
  1480.     /* Local Variables                                                */
  1481.     /*----------------------------------------------------------------*/
  1482.     MYTIME nextDate, incTime;
  1483.     S8 tmpString[MENS_TITLE_LEN];
  1484.     U32 highlightDays, highlightX, highlightY;
  1485.     /*----------------------------------------------------------------*/
  1486.     /* Code Body                                                      */
  1487.     /*----------------------------------------------------------------*/
  1488.     memset(&nextDate, 0, sizeof(MYTIME));
  1489.     memset(&incTime, 0, sizeof(MYTIME));
  1490.     nextDate.nYear = g_mens_cntx->CurrYear;
  1491.     nextDate.nMonth = g_mens_cntx->CurrMonth;
  1492.     nextDate.nDay = g_mens_cntx->CurrDay;
  1493.     incTime.nDay = 1;
  1494. #ifdef MMI_ON_WIN32
  1495.     DecrementTime(nextDate, incTime, & nextDate);
  1496. #else
  1497.     applib_dt_decrease_time(
  1498.         (applib_time_struct*) & nextDate,
  1499.         (applib_time_struct*) & incTime,
  1500.         (applib_time_struct*) & nextDate);
  1501. #endif
  1502.     if (g_mens_cntx->CurrYear == nextDate.nYear && g_mens_cntx->CurrMonth == nextDate.nMonth)
  1503.     {
  1504.         g_mens_cntx->CurrDay--;
  1505.         sprintf(tmpString, "%d %02d", (U16) g_mens_cntx->CurrYear, g_mens_cntx->CurrMonth);
  1506.         highlightDays = g_mens_cntx->DayOnFirst + g_mens_cntx->CurrDay - 1;
  1507.         highlightX = highlightDays % CLNDR_TOTAL_WEEKDAY;
  1508.         highlightY = highlightDays / CLNDR_TOTAL_WEEKDAY;
  1509.         wgui_cat83_set_highlight(highlightY, highlightX);
  1510.         AnsiiToUnicodeString(g_mens_cntx->TitleString, tmpString);
  1511.         wgui_cat83_set_normal_title((U8*) g_mens_cntx->TitleString);
  1512.     }
  1513.     else
  1514.     {
  1515.         MensGoToPreviousDay();
  1516.         /* Check if out of boundary and have a popup */
  1517.         if (g_mens_cntx->IsAddToHistory == TRUE)
  1518.         {
  1519.             return MMI_FALSE;
  1520.         }
  1521.     }
  1522.     return MMI_TRUE;
  1523. }
  1524. /*****************************************************************************
  1525.  * FUNCTION
  1526.  *  mmi_mens_right_out_of_boundary
  1527.  * DESCRIPTION
  1528.  *  
  1529.  * PARAMETERS
  1530.  *  row         [IN]        
  1531.  *  column      [IN]        
  1532.  * RETURNS
  1533.  *  
  1534.  *****************************************************************************/
  1535. MMI_BOOL mmi_mens_right_out_of_boundary(U32 row, U32 column)
  1536. {
  1537.     /*----------------------------------------------------------------*/
  1538.     /* Local Variables                                                */
  1539.     /*----------------------------------------------------------------*/
  1540.     MYTIME nextDate, incTime;
  1541.     S8 tmpString[MENS_TITLE_LEN];
  1542.     U32 highlightDays, highlightX, highlightY;
  1543.     /*----------------------------------------------------------------*/
  1544.     /* Code Body                                                      */
  1545.     /*----------------------------------------------------------------*/
  1546.     memset(&nextDate, 0, sizeof(MYTIME));
  1547.     memset(&incTime, 0, sizeof(MYTIME));
  1548.     nextDate.nYear = g_mens_cntx->CurrYear;
  1549.     nextDate.nMonth = g_mens_cntx->CurrMonth;
  1550.     nextDate.nDay = g_mens_cntx->CurrDay;
  1551.     incTime.nDay = 1;
  1552. #ifdef MMI_ON_WIN32
  1553.     IncrementTime(nextDate, incTime, &nextDate);
  1554. #else
  1555.     applib_dt_increase_time(
  1556.         (applib_time_struct*) & nextDate,
  1557.         (applib_time_struct*) & incTime,
  1558.         (applib_time_struct*) & nextDate);
  1559. #endif
  1560.     if (g_mens_cntx->CurrYear == nextDate.nYear && g_mens_cntx->CurrMonth == nextDate.nMonth)
  1561.     {
  1562.         g_mens_cntx->CurrDay++;
  1563.         sprintf(tmpString, "%d %02d", (U16) g_mens_cntx->CurrYear, g_mens_cntx->CurrMonth);
  1564.         highlightDays = g_mens_cntx->DayOnFirst + g_mens_cntx->CurrDay - 1;
  1565.         highlightX = highlightDays % CLNDR_TOTAL_WEEKDAY;
  1566.         highlightY = highlightDays / CLNDR_TOTAL_WEEKDAY;
  1567.         wgui_cat83_set_highlight(highlightY, highlightX);
  1568.         AnsiiToUnicodeString(g_mens_cntx->TitleString, tmpString);
  1569.         wgui_cat83_set_normal_title((U8*) g_mens_cntx->TitleString);
  1570.     }
  1571.     else
  1572.     {
  1573.         MensGoToNextDay();
  1574.         /* Check if out of boundary and have a popup */
  1575.         if (g_mens_cntx->IsAddToHistory == TRUE)
  1576.         {
  1577.             return MMI_FALSE;
  1578.         }
  1579.     }
  1580.     return MMI_TRUE;
  1581. }
  1582. /*****************************************************************************
  1583.  * FUNCTION
  1584.  *  mmi_mens_up_out_of_boundary
  1585.  * DESCRIPTION
  1586.  *  
  1587.  * PARAMETERS
  1588.  *  row         [IN]        
  1589.  *  column      [IN]        
  1590.  * RETURNS
  1591.  *  
  1592.  *****************************************************************************/
  1593. MMI_BOOL mmi_mens_up_out_of_boundary(U32 row, U32 column)
  1594. {
  1595.     /*----------------------------------------------------------------*/
  1596.     /* Local Variables                                                */
  1597.     /*----------------------------------------------------------------*/
  1598.     /*----------------------------------------------------------------*/
  1599.     /* Code Body                                                      */
  1600.     /*----------------------------------------------------------------*/
  1601.     MensGoToPreviousWeek();
  1602.     /* Check if out of boundary and have a popup */
  1603.     if (g_mens_cntx->IsAddToHistory == TRUE)
  1604.     {
  1605.         return MMI_FALSE;
  1606.     }
  1607.     else
  1608.     {
  1609.         return MMI_TRUE;
  1610.     }
  1611. }
  1612. /*****************************************************************************
  1613.  * FUNCTION
  1614.  *  mmi_mens_down_out_of_boundary
  1615.  * DESCRIPTION
  1616.  *  
  1617.  * PARAMETERS
  1618.  *  row         [IN]        
  1619.  *  column      [IN]        
  1620.  * RETURNS
  1621.  *  
  1622.  *****************************************************************************/
  1623. MMI_BOOL mmi_mens_down_out_of_boundary(U32 row, U32 column)
  1624. {
  1625.     /*----------------------------------------------------------------*/
  1626.     /* Local Variables                                                */
  1627.     /*----------------------------------------------------------------*/
  1628.     /*----------------------------------------------------------------*/
  1629.     /* Code Body                                                      */
  1630.     /*----------------------------------------------------------------*/
  1631.     MensGoToNextWeek();
  1632.     /* Check if out of boundary and have a popup */
  1633.     if (g_mens_cntx->IsAddToHistory == TRUE)
  1634.     {
  1635.         return MMI_FALSE;
  1636.     }
  1637.     else
  1638.     {
  1639.         return MMI_TRUE;
  1640.     }
  1641. }
  1642. /*****************************************************************************
  1643.  * FUNCTION
  1644.  *  mmi_mens_up_side_key
  1645.  * DESCRIPTION
  1646.  *  
  1647.  * PARAMETERS
  1648.  *  row         [IN]        
  1649.  *  column      [IN]        
  1650.  * RETURNS
  1651.  *  
  1652.  *****************************************************************************/
  1653. MMI_BOOL mmi_mens_up_side_key(U32 row, U32 column)
  1654. {
  1655.     /*----------------------------------------------------------------*/
  1656.     /* Local Variables                                                */
  1657.     /*----------------------------------------------------------------*/
  1658.     /*----------------------------------------------------------------*/
  1659.     /* Code Body                                                      */
  1660.     /*----------------------------------------------------------------*/
  1661.     MensGoToPreviousMonth();
  1662.     /* Check if out of boundary and have a popup */
  1663.     if (g_mens_cntx->IsAddToHistory == TRUE)
  1664.     {
  1665.         return MMI_FALSE;
  1666.     }
  1667.     else
  1668.     {
  1669.         return MMI_TRUE;
  1670.     }
  1671. }
  1672. /*****************************************************************************
  1673.  * FUNCTION
  1674.  *  mmi_mens_down_side_key
  1675.  * DESCRIPTION
  1676.  *  
  1677.  * PARAMETERS
  1678.  *  row         [IN]        
  1679.  *  column      [IN]        
  1680.  * RETURNS
  1681.  *  
  1682.  *****************************************************************************/
  1683. MMI_BOOL mmi_mens_down_side_key(U32 row, U32 column)
  1684. {
  1685.     /*----------------------------------------------------------------*/
  1686.     /* Local Variables                                                */
  1687.     /*----------------------------------------------------------------*/
  1688.     /*----------------------------------------------------------------*/
  1689.     /* Code Body                                                      */
  1690.     /*----------------------------------------------------------------*/
  1691.     MensGoToNextMonth();
  1692.     /* Check if out of boundary and have a popup */
  1693.     if (g_mens_cntx->IsAddToHistory == TRUE)
  1694.     {
  1695.         return MMI_FALSE;
  1696.     }
  1697.     else
  1698.     {
  1699.         return MMI_TRUE;
  1700.     }
  1701. }
  1702. /*****************************************************************************
  1703.  * FUNCTION
  1704.  *  mmi_mens_set_content
  1705.  * DESCRIPTION
  1706.  *  
  1707.  * PARAMETERS
  1708.  *  void
  1709.  * RETURNS
  1710.  *  void
  1711.  *****************************************************************************/
  1712. void mmi_mens_set_content(void)
  1713. {
  1714.     /*----------------------------------------------------------------*/
  1715.     /* Local Variables                                                */
  1716.     /*----------------------------------------------------------------*/
  1717.     /*----------------------------------------------------------------*/
  1718.     /* Code Body                                                      */
  1719.     /*----------------------------------------------------------------*/
  1720.     memset(g_mens_cntx->horizon_select1, 0, CLNDR_VERTICAL_SELECT_LEN);
  1721.     memset(g_mens_cntx->horizon_select2, 0, CLNDR_VERTICAL_SELECT_LEN);
  1722.     pfnUnicodeStrcpy((S8*) g_mens_cntx->horizon_select1, GetString(STR_CALENDER_MESSAAGE1));
  1723.     pfnUnicodeStrcpy((S8*) g_mens_cntx->horizon_select2, GetString(STR_CALENDER_MESSAAGE2));
  1724.     wgui_cat83_set_select_horizontal1(
  1725.         IMG_HEALTH_MENSIS_PP,
  1726.         IMG_HEALTH_MENSIS_PP,
  1727.         0,
  1728.         0,
  1729.         g_mens_cntx->horizon_select1,
  1730.         CAT83_SELECT_ALIGN_LEFT);
  1731.     wgui_cat83_set_select_horizontal2(
  1732.         IMG_HEALTH_MENSIS_MENSES,
  1733.         IMG_HEALTH_MENSIS_MENSES,
  1734.         0,
  1735.         0,
  1736.         g_mens_cntx->horizon_select2,
  1737.         CAT83_SELECT_ALIGN_LEFT);
  1738.     wgui_cat83_set_normal_title((U8*) g_mens_cntx->TitleString);
  1739.     wgui_cat83_set_cell_array(
  1740.         g_mens_cntx->MenstrulCell,
  1741.         CAT83_CELL_BG_FILL_HORIZONTAL,
  1742.         CAT83_CELL_TEXT_DISPLAY_LEFT_BOTTOM,
  1743.         CAT83_CELL_ICON_DISPLAY_RIGHT_TOP);
  1744. }
  1745. #endif /* __MMI_CALENDAR_V2__ */ 
  1746. #endif /* __MMI_MENSTRUAL__ */ // #ifdef __MMI_MENSTRUAL__
  1747. #endif /* _MMI_HEALTHMENSTRUAL_C */