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

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.  *   gui_calendar.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   Calendar - UI component
  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.  *------------------------------------------------------------------------------
  88.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  89.  *============================================================================
  90.  ****************************************************************************/
  91. /**
  92.  * Copyright Notice
  93.  * (c) 2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  94.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  95.  *  (It is illegal to remove this copyright notice from this software or any
  96.  *  portion of it)
  97.  */
  98. /**********************************************************************************
  99.    Filename:      gui_calendar.c
  100.    Author:        manju
  101.    Date Created:  July-07-2003
  102.    Contains:      Contains the calendar control
  103.    Remarks:    Currently not portable
  104. **********************************************************************************/
  105. #include "gui.h"
  106. #include "gui_themes.h"
  107. #include "gui_calendar.h"
  108. #include "wgui_calendar.h"
  109. #include "wgui_softkeys.h"
  110. #include "CalendarDef.h"
  111. #include "DebugInitDef.h"
  112. extern void ChangeCategory82Title1(U8 *title);
  113. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  114. extern void ChangeCategory82Title1Month(U8 *title);
  115. #endif 
  116. /* PMT VIKAS START 20051217 */
  117. #if defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__)
  118. /* PMT VIKAS END 20051217 */
  119. extern void ChangeCategory82Title2(U8 *title);
  120. #endif /* defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__) */ 
  121. extern void ChangeCategory82Title3(U8 *title);
  122. extern void SetCalendarPopupDay(S32 day, U8 *message1, U8 *message2, U8 *message3);
  123. /* PMT VIKAS START 20051217 */
  124. #if defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__)
  125. /* PMT VIKAS END 20051217 */
  126. extern U8 *Cat82_title1;
  127. extern U8 *Cat82_title2;
  128. extern U8 *Cat82_title3;
  129. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  130. extern U8 *Cat82_title1_month;
  131. #endif 
  132. #endif /* defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__) */ 
  133. extern BOOL r2lMMIFlag;
  134. BOOL ClndPopupFlag = FALSE;
  135. #if(ENABLE_CALENDAR_CONTROL)
  136. /*****************************************************************************
  137.  * FUNCTION
  138.  *  _temp_calendar_default_background_function
  139.  * DESCRIPTION
  140.  *  fill teh claendar screen with default background
  141.  * PARAMETERS
  142.  *  x1      [IN]        Start x posiion
  143.  *  y1      [IN]        Start y position
  144.  *  x2      [IN]        End x position
  145.  *  y2      [IN]        End y position
  146.  * RETURNS
  147.  *  void
  148.  *****************************************************************************/
  149. void _temp_calendar_default_background_function(S32 x1, S32 y1, S32 x2, S32 y2)
  150. {
  151.     /*----------------------------------------------------------------*/
  152.     /* Local Variables                                                */
  153.     /*----------------------------------------------------------------*/
  154.     color c = gui_color(192, 192, 200);
  155.     /*----------------------------------------------------------------*/
  156.     /* Code Body                                                      */
  157.     /*----------------------------------------------------------------*/
  158.     gui_reset_clip();
  159.     gui_fill_rectangle(x1, y1, x2, y2, c);
  160. }
  161. /*****************************************************************************
  162.  * FUNCTION
  163.  *  UI_dummy_function_u8u8u8u8
  164.  * DESCRIPTION
  165.  *  dummy function
  166.  * PARAMETERS
  167.  *  c1      [IN]        
  168.  *  c2      [IN]        
  169.  *  c3      [IN]        
  170.  *  c4      [IN]        
  171.  * RETURNS
  172.  *  void
  173.  *****************************************************************************/
  174. void UI_dummy_function_u8u8u8u8(U8 c1, U8 c2, U8 c3, U8 c4)
  175. {
  176.     /*----------------------------------------------------------------*/
  177.     /* Local Variables                                                */
  178.     /*----------------------------------------------------------------*/
  179.     /*----------------------------------------------------------------*/
  180.     /* Code Body                                                      */
  181.     /*----------------------------------------------------------------*/
  182.     UI_UNUSED_PARAMETER(c1);
  183.     UI_UNUSED_PARAMETER(c2);
  184.     UI_UNUSED_PARAMETER(c3);
  185.     UI_UNUSED_PARAMETER(c4);
  186. }
  187. /*****************************************************************************
  188.  * FUNCTION
  189.  *  gui_create_calendar
  190.  * DESCRIPTION
  191.  *  Initializes a calendar control object
  192.  * PARAMETERS
  193.  *  c               [IN]        Pointer to a calendar control object (pre-allocated)
  194.  *  x               [IN]        Left-Top corner location for the calendar control object
  195.  *  y               [IN]        Left-Top corner location for the calendar control object
  196.  *  n_columns       [IN]        Number of columns in the calendar control (Usually 7 for 7 days of the week)
  197.  *  n_rows          [IN]        Number of rows in the calendar control (Usually 6)
  198.  *  cell_width      [IN]        Width of each cell in pixels
  199.  *  cell_height     [IN]        Height of each cell in pixels
  200.  * RETURNS
  201.  *  void
  202.  *****************************************************************************/
  203. extern calendar_theme _calendar_control_theme_data;
  204. void gui_create_calendar(calendar_control *c, S32 x, S32 y, S32 n_columns, S32 n_rows, S32 cell_width, S32 cell_height)
  205. {
  206.     /*----------------------------------------------------------------*/
  207.     /* Local Variables                                                */
  208.     /*----------------------------------------------------------------*/
  209.     /*----------------------------------------------------------------*/
  210.     /* Code Body                                                      */
  211.     /*----------------------------------------------------------------*/
  212.     c->x = x;
  213.     c->y = y;
  214.     c->n_columns = n_columns;                   /* set thenumber of columns */
  215.     c->n_rows = n_rows;                         /* number of rows */
  216.     c->cell_height = cell_height;               /* each cell height */
  217.     c->cell_width = cell_width;                 /* each cell width */
  218.     c->cursor_save_bitmap.data = NULL;
  219.     c->popup_save_bitmap.data = NULL;
  220.     c->x1 = x;                                  /* satrt x postion */
  221.     c->y1 = y;                                  /* start y position */
  222.     c->x2 = x + cell_width * n_columns - 1;     /* end x position */
  223.     /* c->y2=y+cell_height*n_rows-1;        //end y position */
  224.     c->y2 = y + cell_height * n_rows;
  225.     c->draw_background_function = _temp_calendar_default_background_function;   /* set function pointer of deafult background */
  226.     c->item_highlighted_function = UI_dummy_function_s32;
  227.     c->item_unhighlighted_function = UI_dummy_function_s32;
  228.     c->month_previous_day_function = UI_dummy_function;
  229.     c->month_next_day_function = UI_dummy_function;
  230.     c->month_previous_week_function = UI_dummy_function;
  231.     c->month_next_week_function = UI_dummy_function;
  232.     c->popuptitle_lunarcalendar = UI_dummy_function_u8u8u8u8;
  233.     c->theme = &_calendar_control_theme_data;   /* _temp_calendar_control_theme; */
  234.     c->list_of_items = NULL;
  235.     c->highlighted_item = -1;
  236.     c->flags = 0;
  237.     c->display_popup = NULL;
  238. #ifdef __MMI_TOUCH_SCREEN__
  239.     c->pen_down_on_highlighted_item = 0;
  240.     c->previous_month_function = UI_dummy_function;
  241.     c->next_month_function = UI_dummy_function;
  242. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  243.     c->previous_year_function = UI_dummy_function;
  244.     c->next_year_function = UI_dummy_function;
  245. #endif /* __MMI_UI_CALENDAR_WITH_INFO_BOX__ */ 
  246. #endif /* __MMI_TOUCH_SCREEN__ */ 
  247. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  248.     c->info_x1 = 0;
  249.     c->info_y1 = 0;
  250.     c->info_x2 = 0;
  251.     c->info_y2 = 0;
  252.     c->max_n_info = 3;
  253.     c->flags |= CALENDAR_SHOW_INFO_BOX;
  254.     c->n_info = 0;
  255.     c->icon_list = NULL;
  256.     c->description_list = NULL;
  257.     c->update_info_box = NULL;
  258. #endif /* __MMI_UI_CALENDAR_WITH_INFO_BOX__ */ 
  259. }
  260. /*****************************************************************************
  261.  * FUNCTION
  262.  *  gui_set_calendar_background_function
  263.  * DESCRIPTION
  264.  *  Sets the background drawing function that a calendar control object should use
  265.  * PARAMETERS
  266.  *  c           [IN]        Pointer to a calendar control object
  267.  *  f           [IN]        Is a pointer to the function which draws the background.
  268.  *  y1(?)       [IN]        Left-Top corner of the drawing area
  269.  *  x2(?)       [IN]        Right-Bottom corner of the drawing area
  270.  *  This(?)     [IN]        Function takes the following parameters:
  271.  *  x1(?)       [IN]        Left-Top corner of the drawing area
  272.  *  y2(?)       [IN]        Right-Bottom corner of the drawing area
  273.  * RETURNS
  274.  *  void
  275.  *****************************************************************************/
  276. void gui_set_calendar_background_function(calendar_control *c, void (*f) (S32 x1, S32 y1, S32 x2, S32 y2))
  277. {
  278.     /*----------------------------------------------------------------*/
  279.     /* Local Variables                                                */
  280.     /*----------------------------------------------------------------*/
  281.     /*----------------------------------------------------------------*/
  282.     /* Code Body                                                      */
  283.     /*----------------------------------------------------------------*/
  284.     c->draw_background_function = f;    /* set function pointer */
  285. }
  286. /*****************************************************************************
  287.  * FUNCTION
  288.  *  gui_set_calendar_days
  289.  * DESCRIPTION
  290.  *  Sets the first day of week, last day of month -- etc.
  291.  * PARAMETERS
  292.  *  c                   [IN]        Pointer to a calendar control object
  293.  *  first_dow           [IN]        Is the first day of the week (See gui_calendar.h for the values)
  294.  *  last_day            [IN]        Is the last day of the month (ex: 28, 29, 30, 31 -- etc)
  295.  *  list_of_items       [IN]        This is the list of flags used. One entry for each day. (See gui_calendar.h for the values)
  296.  * RETURNS
  297.  *  void
  298.  *****************************************************************************/
  299. void gui_set_calendar_days(calendar_control *c, S32 first_dow, S32 last_day, U8 *list_of_items)
  300. {
  301.     /*----------------------------------------------------------------*/
  302.     /* Local Variables                                                */
  303.     /*----------------------------------------------------------------*/
  304.     /*----------------------------------------------------------------*/
  305.     /* Code Body                                                      */
  306.     /*----------------------------------------------------------------*/
  307.     c->first_item = first_dow;                  /* set first day of calendar of current month */
  308.     c->last_item = first_dow + last_day - 1;    /* setlast day of calendar of current minth */
  309.     c->list_of_items = list_of_items;
  310. }
  311. /*****************************************************************************
  312.  * FUNCTION
  313.  *  gui_show_calendar
  314.  * DESCRIPTION
  315.  *  Displays the calendar control
  316.  * PARAMETERS
  317.  *  c       [IN]        Pointer to a calendar control object
  318.  * RETURNS
  319.  *  void
  320.  *****************************************************************************/
  321. void gui_show_calendar(calendar_control *c)
  322. {
  323.     /*----------------------------------------------------------------*/
  324.     /* Local Variables                                                */
  325.     /*----------------------------------------------------------------*/
  326.     S32 i, j;
  327.     S32 x1, y1, x2, y2;
  328.     U8 s[20];
  329.     S32 sw, sh;
  330.     S32 cell_width = c->cell_width;
  331.     S32 cell_height = c->cell_height;
  332.     S32 ox = c->x1;
  333.     S32 oy = c->y1;
  334.     S32 cell_center_x;
  335.     S32 n_rows = c->n_rows;
  336.     S32 n_columns = c->n_columns;
  337.     S32 index = 0;
  338.     S32 day = 1;
  339.     S32 first_item = c->first_item;
  340.     S32 last_item = c->last_item;
  341.     UI_filled_area *blank_day_filler = c->theme->blank_day_filler;
  342.     UI_filled_area *normal_day_filler = c->theme->normal_day_filler;
  343.     UI_filled_area *task_day_filler = c->theme->task_day_filler;
  344.     UI_filled_area *current_day_filler = c->theme->current_day_filler;
  345.     UI_filled_area *week_start_day_filler = c->theme->week_start_day_filler;
  346.     UI_filled_area *week_end_day_filler = c->theme->week_end_day_filler;
  347.     color normal_day_text_color = c->theme->normal_day_text_color;
  348.     color task_day_text_color = c->theme->task_day_text_color;
  349.     color current_day_text_color = c->theme->current_day_text_color;
  350.     color week_start_day_text_color = c->theme->week_start_day_text_color;
  351.     color week_end_day_text_color = c->theme->week_end_day_text_color;
  352.     U8 *list_of_items = c->list_of_items;
  353.     UI_filled_area *special1_day_filler = c->theme->special1_day_filler;
  354.     color special1_day_text_color = c->theme->special1_day_text_color;
  355.     UI_filled_area *special2_day_filler = c->theme->special2_day_filler;
  356.     color special2_day_text_color = c->theme->special2_day_text_color;
  357.     UI_filled_area *special3_day_filler = c->theme->special3_day_filler;
  358.     color special3_day_text_color = c->theme->special3_day_text_color;
  359.     UI_filled_area *special4_day_filler = c->theme->special4_day_filler;
  360.     color special4_day_text_color = c->theme->special4_day_text_color;
  361.     /*----------------------------------------------------------------*/
  362.     /* Code Body                                                      */
  363.     /*----------------------------------------------------------------*/
  364.     gdi_layer_push_clip();
  365.     gdi_layer_push_text_clip();
  366.     gui_set_clip(c->x1, c->y1, c->x2, c->y2);
  367.     gui_set_font(&MMI_small_font);      /* set font to small */
  368.     cell_center_x = cell_width >> 1;    /* caluclate teh center x of cell */
  369.     c->draw_background_function(c->x1, c->y1, c->x2, c->y2);    /* draw bkg image of calenadra */
  370.     if (list_of_items == NULL)
  371.     {
  372.         gdi_layer_pop_clip();
  373.         gdi_layer_pop_text_clip();
  374.         return;
  375.     }
  376.     y1 = oy;
  377.     /* check type of day and fill that cell with particular color theme */
  378.     for (j = 0; j < n_rows; j++)
  379.     {
  380.         x1 = ox;
  381.         for (i = 0; i < n_columns; i++)
  382.         {
  383.             x2 = x1 + cell_width - 1;
  384.             y2 = y1 + cell_height - 1;
  385.             if ((index >= first_item) && (index <= last_item))
  386.             {
  387.                 if ((list_of_items[day] & 0x3f) == CALENDAR_CURRENT_DAY)
  388.                 {
  389.                     gui_draw_filled_area(x1, y1 + 1, x2, y2 + 1, current_day_filler);   /* fill color of current day */
  390.                     if (i == CALENDAR_WEEK_START)
  391.                     {
  392.                         gui_set_text_color(week_start_day_text_color);  /* set teh text color */
  393.                     }
  394.                     else if (i == CALENDAR_WEEK_END)
  395.                     {
  396.                         gui_set_text_color(week_end_day_text_color);
  397.                     }
  398.                     else
  399.                     {
  400.                         gui_set_text_color(current_day_text_color);
  401.                     }
  402.                 }
  403.                 else if ((list_of_items[day] & 0x3f) == CALENDAR_TASK_DAY)      /* if task is tore in particular day */
  404.                 {
  405.                     gui_draw_filled_area(x1, y1 + 1, x2, y2 + 1, task_day_filler);
  406.                     if (i == CALENDAR_WEEK_START)   /* if week start day */
  407.                     {
  408.                         gui_set_text_color(week_start_day_text_color);
  409.                     }
  410.                     else if (i == CALENDAR_WEEK_END)    /* if week end day */
  411.                     {
  412.                         gui_set_text_color(week_end_day_text_color);
  413.                     }
  414.                     else
  415.                     {
  416.                         gui_set_text_color(task_day_text_color);
  417.                     }
  418.                 }
  419.                 else if ((list_of_items[day] & 0x3f) == CALENDAR_SPECIAL_DAY1)  /* if spevcila day1 */
  420.                 {
  421.                     gui_draw_filled_area(x1, y1 + 1, x2, y2 + 1, special1_day_filler);
  422.                     gui_set_text_color(special1_day_text_color);
  423.                 }
  424.                 else if ((list_of_items[day] & 0x3f) == CALENDAR_SPECIAL_DAY2)  /* if specila daye */
  425.                 {
  426.                     gui_draw_filled_area(x1, y1 + 1, x2, y2 + 1, special2_day_filler);
  427.                     gui_set_text_color(special2_day_text_color);
  428.                 }
  429.                 else if ((list_of_items[day] & 0x3f) == CALENDAR_SPECIAL_DAY3)  /* if special day 3 */
  430.                 {
  431.                     gui_draw_filled_area(x1, y1 + 1, x2, y2 + 1, special3_day_filler);
  432.                     gui_set_text_color(special3_day_text_color);
  433.                 }
  434.                 else if ((list_of_items[day] & 0x3f) == CALENDAR_SPECIAL_DAY4)  /* if special day 4 */
  435.                 {
  436.                     gui_draw_filled_area(x1, y1 + 1, x2, y2 + 1, special4_day_filler);
  437.                     gui_set_text_color(special4_day_text_color);
  438.                 }
  439.                 else if ((list_of_items[day] & 0x3f) == CALENDAR_NORMAL_DAY)    /* if normal day */
  440.                 {
  441.                     if (i == CALENDAR_WEEK_START)
  442.                     {
  443.                         gui_draw_filled_area(x1, y1 + 1, x2, y2 + 1, week_start_day_filler);
  444.                         gui_set_text_color(week_start_day_text_color);
  445.                     }
  446.                     else if (i == CALENDAR_WEEK_END)    /* if week end */
  447.                     {
  448.                         gui_draw_filled_area(x1, y1 + 1, x2, y2 + 1, week_end_day_filler);
  449.                         gui_set_text_color(week_end_day_text_color);
  450.                     }
  451.                     else
  452.                     {
  453.                         gui_draw_filled_area(x1, y1 + 1, x2, y2 + 1, normal_day_filler);
  454.                         gui_set_text_color(normal_day_text_color);
  455.                     }
  456.                 }
  457.                 gdi_layer_push_text_clip();
  458.                 gdi_layer_set_text_clip(x1 + 1, y1, x2 - 1, y2);
  459.                 gui_itoa(day, (UI_string_type) s, 10);  /* convert day to string */
  460.                 /* mesaure height and wdth of current date string */
  461.                 gui_measure_string((UI_string_type) s, &sw, &sh);
  462.                 /* move cursor to x,y position */
  463.                 if (r2lMMIFlag)
  464.                 {
  465.                     gui_move_text_cursor(x1 + cell_center_x - (sw >> 1) + sw, y1 + (cell_height >> 1) - (sh >> 1) + 1);
  466.                 }
  467.                 else
  468.                 {
  469.                     gui_move_text_cursor(x1 + cell_center_x - (sw >> 1), y1 + (cell_height >> 1) - (sh >> 1) + 1);
  470.                 }
  471.                 /* print text */
  472.                 gui_print_text((UI_string_type) s);
  473.                 day++;
  474.                 gdi_layer_pop_text_clip();
  475.             }
  476.             else
  477.             {
  478.                 gui_draw_filled_area(x1, y1 + 1, x2, y2 + 1, blank_day_filler);
  479.             }
  480.             x1 += cell_width;
  481.             index++;
  482.         }
  483.         y1 += cell_height;
  484.     }
  485.     gdi_layer_pop_clip();
  486.     gdi_layer_pop_text_clip();
  487.     c->flags &= ~CALENDAR_HIGHLIGHT_BACKUP;
  488. }
  489. /*****************************************************************************
  490.  * FUNCTION
  491.  *  gui_calendar_refresh_highlight
  492.  * DESCRIPTION
  493.  *  Internal function: Refreshes the calendar display (when a new day is highlighted)
  494.  * PARAMETERS
  495.  *  c                           [IN]        Pointer to a calendar control object
  496.  *  old_highlighted_item        [IN]        Is the 0 based index of the previously highlighted item
  497.  *  new_highlighted_item        [IN]        Is the 0 based index of the newly highlighted item
  498.  * RETURNS
  499.  *  void
  500.  *****************************************************************************/
  501. void gui_calendar_refresh_highlight(calendar_control *c, S32 old_highlighted_item, S32 new_highlighted_item)
  502. {
  503.     /*----------------------------------------------------------------*/
  504.     /* Local Variables                                                */
  505.     /*----------------------------------------------------------------*/
  506.     S32 row, col;
  507.     S32 x1, y1, x2, y2;
  508.     U8 s[20];
  509.     S32 sw, sh;
  510.     /*----------------------------------------------------------------*/
  511.     /* Code Body                                                      */
  512.     /*----------------------------------------------------------------*/
  513.     gdi_layer_push_clip();
  514.     gdi_layer_push_text_clip();
  515.     gui_set_clip(c->x1, c->y1, c->x2, c->y2);
  516.     if (old_highlighted_item >= 0)
  517.     {
  518.         if (c->flags & CALENDAR_POPUP_BACKUP)
  519.         {
  520.             /* Temporarily disabled pop up bitmap backup since there is no available buffer to use on hardware    */
  521.             /* _show_bitmap(c->px1,c->py1,&c->popup_save_bitmap);                                     */
  522.         #if(UI_DOUBLE_BUFFER_SUPPORT)
  523.             /* gdi_layer_blt_previous(c->px1,c->py1,c->px2,c->py2);                                */
  524.         #endif 
  525.             /* Temporary: Redraw the whole calendar when any item is highlighted                         */
  526.             /* S32 h=c->highlighted_item; */
  527.             c->flags |= CALENDAR_HIDE_POPUP;
  528.             gui_show_calendar(c);
  529.             c->flags &= ~CALENDAR_HIDE_POPUP;
  530.             c->flags &= ~CALENDAR_HIGHLIGHT_BACKUP;
  531.         #if(UI_DOUBLE_BUFFER_SUPPORT)
  532.             gdi_layer_blt_previous(c->x1, c->y1, c->x2, c->y2);
  533.         #endif 
  534.             /* Temporary block ends                                                          */
  535.             c->flags &= ~CALENDAR_POPUP_BACKUP;
  536.         }
  537.         if (c->flags & CALENDAR_HIGHLIGHT_BACKUP)
  538.         {
  539.             row = old_highlighted_item / c->n_columns;
  540.             col = old_highlighted_item % c->n_columns;
  541.             x1 = c->x1 + c->cell_width * col;
  542.             y1 = c->y1 + c->cell_height * row;
  543.             x2 = x1 + c->cell_width - 1;
  544.             y2 = y1 + c->cell_height - 1;
  545.             _show_bitmap(x1, y1, &c->cursor_save_bitmap);   /* show bitmap */
  546.         #if(UI_DOUBLE_BUFFER_SUPPORT)
  547.             gdi_layer_blt_previous(x1, y1, x2, y2 + 1);
  548.         #endif 
  549.             c->flags &= ~CALENDAR_HIGHLIGHT_BACKUP;
  550.         }
  551.     }
  552.     if ((new_highlighted_item >= c->first_item) && (new_highlighted_item <= c->last_item))
  553.     {
  554.         c->flags |= CALENDAR_HIGHLIGHT_BACKUP;
  555.         row = new_highlighted_item / c->n_columns;
  556.         col = new_highlighted_item % c->n_columns;
  557.         x1 = c->x1 + c->cell_width * col;
  558.         y1 = c->y1 + c->cell_height * row;
  559.         x2 = x1 + c->cell_width - 1;
  560.         y2 = y1 + c->cell_height - 1;
  561.         _get_bitmap(x1, y1, x2, y2 + 1, &c->cursor_save_bitmap);        /* get bitmap */
  562.         /* Display the pop up if required   */
  563.         if ((c->flags & CALENDAR_ENABLE_POPUP) &&
  564.             (c->list_of_items[new_highlighted_item - c->first_item + 1] & CALENDAR_POPUP_DAY))
  565.         {
  566.             if (c->display_popup != NULL)
  567.             {
  568.                 c->flags |= CALENDAR_POPUP_BACKUP;
  569.                 c->px1 = x1;
  570.                 c->py1 = y1;
  571.                 c->px2 = x2;
  572.                 c->py2 = y2;
  573.                 c->display_popup(c->highlighted_item - c->first_item + 1, &c->px1, &c->py1, &c->px2, &c->py2);
  574.             }
  575.         }
  576.         /* Draw the new highlighted cell */
  577.         gui_set_font(c->theme->text_font);  /* set font */
  578.         gui_reset_clip();
  579.         gui_draw_filled_area(x1, y1 + 1, x2, y2 + 1, c->theme->selected_day_filler);
  580.         gui_set_text_color(c->theme->selected_day_text_color);
  581.         gdi_layer_set_text_clip(x1 + 1, y1, x2 - 1, y2);
  582.         gui_itoa(new_highlighted_item - c->first_item + 1, (UI_string_type) s, 10);
  583.         /* measure width and height of current date of string */
  584.         gui_measure_string((UI_string_type) s, &sw, &sh);
  585.         /* move text cursor */
  586.         if (r2lMMIFlag)
  587.         {
  588.             gui_move_text_cursor(
  589.                 x1 + (c->cell_width >> 1) - (sw >> 1) + sw,
  590.                 y1 + (c->cell_height >> 1) - (sh >> 1) + ((c->cell_height - sh) % 2));
  591.         }
  592.         else
  593.         {
  594.             gui_move_text_cursor(
  595.                 x1 + (c->cell_width >> 1) - (sw >> 1),
  596.                 y1 + (c->cell_height >> 1) - (sh >> 1) + ((c->cell_height - sh) % 2));
  597.         }
  598.         /* print string */
  599.         gui_print_text((UI_string_type) s);
  600.     #if(UI_DOUBLE_BUFFER_SUPPORT)
  601.         gdi_layer_blt_previous(x1, y1, x2, y2 + 1);
  602.     #endif 
  603.     }
  604.     gdi_layer_pop_clip();
  605.     gdi_layer_pop_text_clip();
  606. }
  607. /*****************************************************************************
  608.  * FUNCTION
  609.  *  gui_calendar_highlight_day
  610.  * DESCRIPTION
  611.  *  Selects a given day on the calendar
  612.  *  
  613.  *  Automatically refreshes the display
  614.  * PARAMETERS
  615.  *  c       [IN]        Pointer to a calendar control object
  616.  *  day     [IN]        Is the day to be selected
  617.  * RETURNS
  618.  *  void
  619.  *****************************************************************************/
  620. void gui_calendar_highlight_day(calendar_control *c, S32 day)
  621. {
  622.     /*----------------------------------------------------------------*/
  623.     /* Local Variables                                                */
  624.     /*----------------------------------------------------------------*/
  625.     S32 old_highlighted_item = c->highlighted_item; /* store current highlight day */
  626.     /*----------------------------------------------------------------*/
  627.     /* Code Body                                                      */
  628.     /*----------------------------------------------------------------*/
  629.     c->highlighted_item = c->first_item + day - 1;
  630.     if (old_highlighted_item != c->highlighted_item)
  631.     {
  632.         gui_calendar_refresh_highlight(c, old_highlighted_item, c->highlighted_item);
  633.         c->item_unhighlighted_function(old_highlighted_item - c->first_item + 1);       /* call unhighligted function */
  634.         c->item_highlighted_function(c->highlighted_item - c->first_item + 1);  /* call highlighted function */
  635.     }
  636. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  637.     if ((c->flags & CALENDAR_SHOW_INFO_BOX) && (c->update_info_box != NULL))
  638.     {
  639.         c->update_info_box(&c->n_info, &c->icon_list, &c->description_list);
  640.         gui_calendar_draw_info_box(c);
  641.     }
  642. #endif /* __MMI_UI_CALENDAR_WITH_INFO_BOX__ */ 
  643. }
  644. /*****************************************************************************
  645.  * FUNCTION
  646.  *  gui_calendar_previous_day
  647.  * DESCRIPTION
  648.  *  Selects the previous day
  649.  *  
  650.  *  Automatically refreshes the display
  651.  * PARAMETERS
  652.  *  c       [IN]        Pointer to a calendar control object
  653.  * RETURNS
  654.  *  void
  655.  *****************************************************************************/
  656. void gui_calendar_previous_day(calendar_control *c)
  657. {
  658.     /*----------------------------------------------------------------*/
  659.     /* Local Variables                                                */
  660.     /*----------------------------------------------------------------*/
  661.     S32 old_highlighted_item = c->highlighted_item; /* stor current highlighted day */
  662.     /*----------------------------------------------------------------*/
  663.     /* Code Body                                                      */
  664.     /*----------------------------------------------------------------*/
  665.     if (c->highlighted_item > c->first_item)
  666.     {
  667.         c->highlighted_item--;
  668.         c->popuptitle_lunarcalendar(PREV_DAY, 0, 0, 0); /* set title according to current day */
  669.         /* refresh calendar highlight */
  670.         gui_calendar_refresh_highlight(c, old_highlighted_item, c->highlighted_item);
  671.         /* call unhighlighted function */
  672.         c->item_unhighlighted_function(old_highlighted_item - c->first_item + 1);
  673.         /* call highlighted function */
  674.         c->item_highlighted_function(c->highlighted_item - c->first_item + 1);
  675.     }
  676.     else
  677.     {
  678.         c->month_previous_day_function();   /* call previous day function */
  679.     }
  680.     if (ClndPopupFlag)
  681.     {
  682.         ClndPopupFlag = FALSE;
  683.         return;
  684.     }
  685. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  686.     if ((c->flags & CALENDAR_SHOW_INFO_BOX) && (c->update_info_box != NULL))
  687.     {
  688.         c->update_info_box(&c->n_info, &c->icon_list, &c->description_list);
  689.         gui_calendar_draw_info_box(c);
  690.     }
  691. #endif /* __MMI_UI_CALENDAR_WITH_INFO_BOX__ */ 
  692.     /* PMT VIKAS START 20051217 */
  693. #if defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__)
  694.     /* PMT VIKAS END 20051217 */
  695.     ChangeCategory82Title1(Cat82_title1);
  696. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  697.     ChangeCategory82Title1Month(Cat82_title1_month);
  698. #endif 
  699.     ChangeCategory82Title2(Cat82_title2);
  700.     ChangeCategory82Title3(Cat82_title3);
  701.     show_left_softkey();
  702.     show_right_softkey();
  703. #endif /* defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__) */ 
  704. }
  705. #ifdef __MMI_TOUCH_SCREEN__
  706. /*****************************************************************************
  707.  * FUNCTION
  708.  *  gui_calendar_go_to_day
  709.  * DESCRIPTION
  710.  *  Go to the selected day of the month
  711.  *  
  712.  *  Automatically refreshes the display (Also Refreshes Lunar Calendar Titles)
  713.  *  Useful for Touch Screen (where user can select any day with pen)
  714.  * PARAMETERS
  715.  *  c           [IN]        Pointer to a calendar control object
  716.  *  index       [IN]        Day of the month
  717.  * RETURNS
  718.  *  void
  719.  *****************************************************************************/
  720. void gui_calendar_go_to_day(calendar_control *c, U8 index)
  721. {
  722.     /*----------------------------------------------------------------*/
  723.     /* Local Variables                                                */
  724.     /*----------------------------------------------------------------*/
  725.     U8 old_day;
  726.     /*----------------------------------------------------------------*/
  727.     /* Code Body                                                      */
  728.     /*----------------------------------------------------------------*/
  729.     old_day = c->highlighted_item - c->first_item + 1;
  730.     c->popuptitle_lunarcalendar(SELECTED_DAY, 0, index, old_day);       /* set the poup of calendar of current day */
  731.     SetCalendarHighlightedDay(index);
  732. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  733.     if ((c->flags & CALENDAR_SHOW_INFO_BOX) && (c->update_info_box != NULL))
  734.     {
  735.         c->update_info_box(&c->n_info, &c->icon_list, &c->description_list);
  736.         gui_calendar_draw_info_box(c);
  737.     }
  738. #endif /* __MMI_UI_CALENDAR_WITH_INFO_BOX__ */ 
  739.     /* PMT VIKAS START 20051217 */
  740. #if defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__)
  741.     /* PMT VIKAS END 20051217 */
  742.     ChangeCategory82Title1(Cat82_title1);
  743. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  744.     ChangeCategory82Title1Month(Cat82_title1_month);
  745. #endif 
  746.     ChangeCategory82Title2(Cat82_title2);
  747.     ChangeCategory82Title3(Cat82_title3);
  748.     show_left_softkey();
  749.     show_right_softkey();
  750. #endif /* defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__) */ 
  751. }
  752. #endif /* __MMI_TOUCH_SCREEN__ */ 
  753. /*****************************************************************************
  754.  * FUNCTION
  755.  *  gui_calendar_next_day
  756.  * DESCRIPTION
  757.  *  Selects the next day
  758.  *  
  759.  *  Automatically refreshes the display
  760.  * PARAMETERS
  761.  *  c       [IN]        Pointer to a calendar control object
  762.  * RETURNS
  763.  *  void
  764.  *****************************************************************************/
  765. void gui_calendar_next_day(calendar_control *c)
  766. {
  767.     /*----------------------------------------------------------------*/
  768.     /* Local Variables                                                */
  769.     /*----------------------------------------------------------------*/
  770.     S32 old_highlighted_item = c->highlighted_item; /* store current highlighted day */
  771.     /*----------------------------------------------------------------*/
  772.     /* Code Body                                                      */
  773.     /*----------------------------------------------------------------*/
  774.     if (c->highlighted_item < c->last_item)
  775.     {
  776.         c->highlighted_item++;
  777.         c->popuptitle_lunarcalendar(NEXT_DAY, 0, 0, 0); /* set the poup of calebdar of current day */
  778.         gui_calendar_refresh_highlight(c, old_highlighted_item, c->highlighted_item);
  779.         /* call unhighlighted function */
  780.         c->item_unhighlighted_function(old_highlighted_item - c->first_item + 1);
  781.         /* call highlighted func */
  782.         c->item_highlighted_function(c->highlighted_item - c->first_item + 1);
  783.     }
  784.     else
  785.     {
  786.         c->month_next_day_function();   /* move to 1st day of next month */
  787.     }
  788.     if (ClndPopupFlag)
  789.     {
  790.         ClndPopupFlag = FALSE;
  791.         return;
  792.     }
  793. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  794.     if ((c->flags & CALENDAR_SHOW_INFO_BOX) && (c->update_info_box != NULL))
  795.     {
  796.         c->update_info_box(&c->n_info, &c->icon_list, &c->description_list);
  797.         gui_calendar_draw_info_box(c);
  798.     }
  799. #endif /* __MMI_UI_CALENDAR_WITH_INFO_BOX__ */ 
  800.     /* PMT VIKAS START 20051217 */
  801. #if defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__)
  802.     /* PMT VIKAS END 20051217 */
  803.     ChangeCategory82Title1(Cat82_title1);
  804. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  805.     ChangeCategory82Title1Month(Cat82_title1_month);
  806. #endif 
  807.     ChangeCategory82Title2(Cat82_title2);
  808.     ChangeCategory82Title3(Cat82_title3);
  809.     show_left_softkey();
  810.     show_right_softkey();
  811. #endif /* defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__) */ 
  812. }
  813. /*****************************************************************************
  814.  * FUNCTION
  815.  *  gui_calendar_next_row
  816.  * DESCRIPTION
  817.  *  Selects a day in the next row of the calendar
  818.  *  
  819.  *  Automatically refreshes the display
  820.  * PARAMETERS
  821.  *  c       [IN]        Pointer to a calendar control object
  822.  * RETURNS
  823.  *  void
  824.  *****************************************************************************/
  825. void gui_calendar_next_row(calendar_control *c)
  826. {
  827.     /*----------------------------------------------------------------*/
  828.     /* Local Variables                                                */
  829.     /*----------------------------------------------------------------*/
  830.     S32 old_highlighted_item = c->highlighted_item; /* stor current highlihted day */
  831.     /*----------------------------------------------------------------*/
  832.     /* Code Body                                                      */
  833.     /*----------------------------------------------------------------*/
  834.     if ((c->highlighted_item + c->n_columns) <= c->last_item)
  835.     {
  836.         c->highlighted_item += c->n_columns;
  837.         /* set popup f current day */
  838.         c->popuptitle_lunarcalendar(NEXT_ROW, (U8) c->n_columns, 0, 0);
  839.         /* refresgh calendar */
  840.         gui_calendar_refresh_highlight(c, old_highlighted_item, c->highlighted_item);
  841.         /* call unhighlighted func */
  842.         c->item_unhighlighted_function(old_highlighted_item - c->first_item + 1);
  843.         /* call highlighted func */
  844.         c->item_highlighted_function(c->highlighted_item - c->first_item + 1);
  845.     }
  846.     else
  847.     {
  848.         c->month_next_week_function();  /* move to first week next month */
  849.     }
  850.     if (ClndPopupFlag)
  851.     {
  852.         ClndPopupFlag = FALSE;
  853.         return;
  854.     }
  855. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  856.     if ((c->flags & CALENDAR_SHOW_INFO_BOX) && (c->update_info_box != NULL))
  857.     {
  858.         c->update_info_box(&c->n_info, &c->icon_list, &c->description_list);
  859.         gui_calendar_draw_info_box(c);
  860.     }
  861. #endif /* __MMI_UI_CALENDAR_WITH_INFO_BOX__ */ 
  862.     /* PMT VIKAS START 20051217 */
  863. #if defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__)
  864.     /* PMT VIKAS END 20051217 */
  865.     ChangeCategory82Title1(Cat82_title1);
  866. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  867.     ChangeCategory82Title1Month(Cat82_title1_month);
  868. #endif 
  869.     ChangeCategory82Title2(Cat82_title2);
  870.     ChangeCategory82Title3(Cat82_title3);
  871.     show_left_softkey();
  872.     show_right_softkey();
  873. #endif /* defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__) */ 
  874. }
  875. /*****************************************************************************
  876.  * FUNCTION
  877.  *  gui_calendar_previous_row
  878.  * DESCRIPTION
  879.  *  Selects a day in the previous row of the calendar
  880.  *  
  881.  *  Automatically refreshes the display
  882.  * PARAMETERS
  883.  *  c       [IN]        Pointer to a calendar control object
  884.  * RETURNS
  885.  *  void
  886.  *****************************************************************************/
  887. void gui_calendar_previous_row(calendar_control *c)
  888. {
  889.     /*----------------------------------------------------------------*/
  890.     /* Local Variables                                                */
  891.     /*----------------------------------------------------------------*/
  892.     S32 old_highlighted_item = c->highlighted_item; /* store current day */
  893.     /*----------------------------------------------------------------*/
  894.     /* Code Body                                                      */
  895.     /*----------------------------------------------------------------*/
  896.     if ((c->highlighted_item - c->n_columns) >= c->first_item)
  897.     {
  898.         c->highlighted_item -= c->n_columns;
  899.         /* set poup and titel of current day */
  900.         c->popuptitle_lunarcalendar(PREV_ROW, (U8) c->n_columns, 0, 0);
  901.         gui_calendar_refresh_highlight(c, old_highlighted_item, c->highlighted_item);
  902.         /* call unhighlighted fun c */
  903.         c->item_unhighlighted_function(old_highlighted_item - c->first_item + 1);
  904.         /* call highlighted func */
  905.         c->item_highlighted_function(c->highlighted_item - c->first_item + 1);
  906.     }
  907.     else
  908.     {
  909.         c->month_previous_week_function();  /* move to last week of previous month */
  910.     }
  911.     if (ClndPopupFlag)
  912.     {
  913.         ClndPopupFlag = FALSE;
  914.         return;
  915.     }
  916. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  917.     if ((c->flags & CALENDAR_SHOW_INFO_BOX) && (c->update_info_box != NULL))
  918.     {
  919.         c->update_info_box(&c->n_info, &c->icon_list, &c->description_list);
  920.         gui_calendar_draw_info_box(c);
  921.     }
  922. #endif /* __MMI_UI_CALENDAR_WITH_INFO_BOX__ */ 
  923.     /* PMT VIKAS START 20051217 */
  924. #if defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__)
  925.     /* PMT VIKAS END 20051217 */
  926.     ChangeCategory82Title1(Cat82_title1);
  927. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  928.     ChangeCategory82Title1Month(Cat82_title1_month);
  929. #endif 
  930.     ChangeCategory82Title2(Cat82_title2);
  931.     ChangeCategory82Title3(Cat82_title3);
  932.     show_left_softkey();
  933.     show_right_softkey();
  934. #endif /* defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) || defined(__MMI_UI_DALMATIAN_CALENDAR__) */ 
  935. }
  936. /*****************************************************************************
  937.  * FUNCTION
  938.  *  gui_move_calendar
  939.  * DESCRIPTION
  940.  *  Moves the calendar to a different position
  941.  * PARAMETERS
  942.  *  c       [IN]        Pointer to a calendar control object
  943.  *  x       [IN]        Is the new location
  944.  *  y       [IN]        Is the new location
  945.  * RETURNS
  946.  *  void
  947.  *****************************************************************************/
  948. void gui_move_calendar(calendar_control *c, S32 x, S32 y)
  949. {
  950.     /*----------------------------------------------------------------*/
  951.     /* Local Variables                                                */
  952.     /*----------------------------------------------------------------*/
  953.     /*----------------------------------------------------------------*/
  954.     /* Code Body                                                      */
  955.     /*----------------------------------------------------------------*/
  956.     c->x = x;                                       /* star x position of calndar */
  957.     c->y = y;                                       /* satrt y position of calendar */
  958.     c->x1 = x;
  959.     c->y1 = y;
  960.     c->x2 = x + c->cell_width * c->n_columns - 1;   /* end x positiobn of calendar */
  961.     c->y2 = y + c->cell_height * c->n_rows - 1;     /* end y position of calendar */
  962.     c->y2 += 1;                                     /* 053005 Calvin Add for 1 more pixel display */
  963. }
  964. #ifdef __MMI_UI_CALENDAR_WITH_INFO_BOX__
  965. /*****************************************************************************
  966.  * FUNCTION
  967.  *  gui_calendar_draw_info_box
  968.  * DESCRIPTION
  969.  *  show info box embbed in the calendar
  970.  * PARAMETERS
  971.  *  c       [IN]        Pointer to a calendar control object
  972.  * RETURNS
  973.  *  void
  974.  *****************************************************************************/
  975. void gui_calendar_draw_info_box(calendar_control *c)
  976. {
  977.     /*----------------------------------------------------------------*/
  978.     /* Local Variables                                                */
  979.     /*----------------------------------------------------------------*/
  980.     S32 x1, y1, x2, y2;
  981.     S32 box_height, line_height;
  982.     S32 max_n_line, n_line;
  983.     S32 i;
  984.     S32 offset_x = 5;
  985.     S32 image_width, image_height;
  986.     S32 string_width, string_height;
  987.     S32 ix, iy, tx, ty;
  988.     S32 line_start_y = c->info_y1 + 1;
  989.     color bgc = {182, 200, 255, 100};
  990.     color brdc = {82, 200, 255, 100};
  991.     color linec = *(current_MMI_theme->UI_white_color);
  992.     color tc = *(current_MMI_theme->UI_black_color);
  993.     S8 *image;
  994.     /*----------------------------------------------------------------*/
  995.     /* Code Body                                                      */
  996.     /*----------------------------------------------------------------*/
  997.     gui_set_font(&MMI_default_font);
  998.     gui_set_text_color(tc);
  999.     x1 = c->info_x1;
  1000.     y1 = c->info_y1;
  1001.     x2 = c->info_x2;
  1002.     y2 = c->info_y2;
  1003.     box_height = c->info_y2 - c->info_y1 - 1;   /* decrease 2 pixel for border lines */
  1004.     max_n_line = c->max_n_info;
  1005.     /* n_line = 3; */
  1006.     n_line = c->n_info;
  1007.     if (n_line > max_n_line)
  1008.     {
  1009.         n_line = max_n_line;
  1010.     }
  1011.     line_height = box_height / n_line;
  1012.     ix = x1 + offset_x;
  1013.     gdi_layer_push_clip();
  1014.     gui_set_clip(x1, y1, x2, y2);
  1015.     gui_draw_rectangle(x1, y1, x2, y2, brdc);
  1016.     gui_fill_rectangle(x1 + 1, y1 + 1, x2 - 1, y2 - 1, bgc);
  1017.     for (i = 0; i < max_n_line - 1; i++)
  1018.     {
  1019.         line_start_y += line_height;
  1020.         gui_draw_horizontal_line(x1 + offset_x, x2 - offset_x, line_start_y, linec);
  1021.     }
  1022.     line_start_y = c->info_y1 + 1;
  1023.     for (i = 0; i < n_line; i++)
  1024.     {
  1025.         image = GetImage(c->icon_list[i]);
  1026.         if(c->icon_list [i] == 0)
  1027.         {
  1028.             image_width = image_height = 0;
  1029.         }
  1030.         else
  1031.         {
  1032.             gui_measure_image((PU8) image, &image_width, &image_height);
  1033.         }
  1034.         iy = line_start_y + ((line_height - image_height) >> 1);
  1035.         gui_show_image(ix, iy, (PU8) image);
  1036.         gui_measure_string((UI_string_type) c->description_list[i], &string_width, &string_height);
  1037.         tx = ix + image_width + offset_x;
  1038.         ty = line_start_y + ((line_height - string_height) >> 1);
  1039.         gui_move_text_cursor(tx, ty);
  1040.         gui_print_text((UI_string_type) c->description_list[i]);
  1041.         line_start_y += line_height;
  1042.     }
  1043.     gdi_layer_pop_clip();
  1044. #if(UI_DOUBLE_BUFFER_SUPPORT)
  1045.     gdi_layer_blt_previous(x1, y1, x2, y2);
  1046. #endif 
  1047. }
  1048. #endif /* __MMI_UI_CALENDAR_WITH_INFO_BOX__ */ 
  1049. #endif /* (ENABLE_CALENDAR_CONTROL) */ 
  1050. #ifdef __MMI_TOUCH_SCREEN__
  1051. /*****************************************************************************
  1052.  * FUNCTION
  1053.  *  gui_calendar_translate_pen_position
  1054.  * DESCRIPTION
  1055.  *  translate the pen position to the item
  1056.  * PARAMETERS
  1057.  *  c               [IN]        Pointer to a calendar control object
  1058.  *  x               [IN]        Pen position
  1059.  *  y               [IN]        Pen position
  1060.  *  item_index      [OUT]       Output the item index which is triggered
  1061.  * RETURNS
  1062.  *  void
  1063.  *****************************************************************************/
  1064. /* *item_index = 0 for fail */
  1065. void gui_calendar_translate_pen_position(calendar_control *c, S32 x, S32 y, S32 *item_index)
  1066. {
  1067.     /*----------------------------------------------------------------*/
  1068.     /* Local Variables                                                */
  1069.     /*----------------------------------------------------------------*/
  1070.     S32 xi, yi, row = 1, col = 1, i = 1, j, first_row_count = 0;
  1071.     /*----------------------------------------------------------------*/
  1072.     /* Code Body                                                      */
  1073.     /*----------------------------------------------------------------*/
  1074.     xi = c->x1 + (c->first_item) * (c->cell_width);
  1075.     yi = c->y1;
  1076.     if (x < c->x1 || x > c->x2 || y < c->y1 || y > c->y2)
  1077.     {
  1078.         *item_index = 0;
  1079.         return;
  1080.     }
  1081.     for (j = yi; j < c->y2; j += c->cell_height)
  1082.     {
  1083.         if (y >= j && y < j + c->cell_height)
  1084.         {
  1085.             row = i;
  1086.             break;
  1087.         }
  1088.         i++;
  1089.     }
  1090.     i = 1;
  1091.     for (j = c->x1; j < c->x2; j += c->cell_width)
  1092.     {
  1093.         if (x >= j && x < j + c->cell_width)
  1094.         {
  1095.             col = i;
  1096.             break;
  1097.         }
  1098.         i++;
  1099.     }
  1100.     switch (c->first_item)
  1101.     {
  1102.         case 0:
  1103.             first_row_count = 7;
  1104.             break;
  1105.         case 1:
  1106.             first_row_count = 6;
  1107.             break;
  1108.         case 2:
  1109.             first_row_count = 5;
  1110.             break;
  1111.         case 3:
  1112.             first_row_count = 4;
  1113.             break;
  1114.         case 4:
  1115.             first_row_count = 3;
  1116.             break;
  1117.         case 5:
  1118.             first_row_count = 2;
  1119.             break;
  1120.         case 6:
  1121.             first_row_count = 1;
  1122.             break;
  1123.         default:
  1124.             MMI_ASSERT(0);
  1125.     }
  1126.     if (row == 1)
  1127.     {
  1128.         *item_index = col - c->first_item;
  1129.     }
  1130.     else
  1131.     {
  1132.         *item_index = (row - 2) * c->n_columns + first_row_count + col;
  1133.     }
  1134. }
  1135. /*****************************************************************************
  1136.  * FUNCTION
  1137.  *  gui_calendar_translate_pen_event
  1138.  * DESCRIPTION
  1139.  *  translate the pen position to the event
  1140.  * PARAMETERS
  1141.  *  c                   [IN]        Pointer to a calendar control object
  1142.  *  pen_event           [IN]        Event type
  1143.  *  x                   [IN]        Pen position
  1144.  *  y                   [IN]        Pen position
  1145.  *  calendar_event      [OUT]       Event pointer
  1146.  * RETURNS
  1147.  *  void
  1148.  *****************************************************************************/
  1149. BOOL gui_calendar_translate_pen_event(
  1150.         calendar_control *c,
  1151.         mmi_pen_event_type_enum pen_event,
  1152.         S16 x,
  1153.         S16 y,
  1154.         gui_calendar_pen_enum *calendar_event)
  1155. {
  1156.     /*----------------------------------------------------------------*/
  1157.     /* Local Variables                                                */
  1158.     /*----------------------------------------------------------------*/
  1159.     BOOL ret;
  1160.     S32 item_index;
  1161.     /*----------------------------------------------------------------*/
  1162.     /* Code Body                                                      */
  1163.     /*----------------------------------------------------------------*/
  1164.     ret = MMI_TRUE;
  1165.     *calendar_event = GUI_CALENDAR_PEN_NONE;
  1166.     switch (pen_event)
  1167.     {
  1168.         case MMI_PEN_EVENT_DOWN:
  1169.             if (PEN_CHECK_BOUND(x, y, c->x1, c->y1, c->x2, c->y2))
  1170.             {
  1171.                 gui_calendar_translate_pen_position(c, x, y, &item_index);
  1172.                 if (item_index < 1 || item_index > c->last_item - c->first_item + 1)
  1173.                 {
  1174.                     ret = MMI_FALSE;
  1175.                     break;
  1176.                 }
  1177.                 if (item_index == c->highlighted_item - c->first_item + 1)
  1178.                 {
  1179.                     /* Down event on the highlighted item set flag to 1 so that now up event here will call LSK function */
  1180.                     c->pen_down_on_highlighted_item = 1;
  1181.                 }
  1182.                 if (item_index != c->highlighted_item - c->first_item + 1)
  1183.                 {
  1184.                 #ifdef __MMI_UI_DALMATIAN_CALENDAR__ 
  1185.                     gdi_layer_lock_frame_buffer();
  1186.                     set_dalmatian_calendar_highlighter_box();
  1187.                 #endif
  1188.                     gui_calendar_go_to_day(c, (U8) item_index);
  1189.                 #ifdef __MMI_UI_DALMATIAN_CALENDAR__ 
  1190.                     gdi_layer_unlock_frame_buffer();
  1191.                     gdi_layer_blt_previous(0,0,UI_device_width,UI_device_height);
  1192.                 #endif
  1193.                 }
  1194.                 *calendar_event = GUI_CALENDAR_PEN_HIGHLIGHT_CHANGED;
  1195.             }
  1196.             else
  1197.             {
  1198.                 ret = MMI_FALSE;
  1199.             }
  1200.             break;
  1201.         case MMI_PEN_EVENT_MOVE:
  1202.             if (PEN_CHECK_BOUND(x, y, c->x1, c->y1, (c->x2 - c->x1 + 1), (c->y2 - c->y1 + 1)))
  1203.             {
  1204.                 gui_calendar_translate_pen_position(c, x, y, &item_index);
  1205.                 if (item_index != c->highlighted_item - c->first_item + 1)
  1206.                 {
  1207.                     if (item_index < 1 || item_index > c->last_item - c->first_item + 1)
  1208.                     {
  1209.                         /* FIXME. handle this case better */
  1210.                         ret = MMI_FALSE;
  1211.                     }
  1212.                     else
  1213.                     {
  1214.                     #ifdef __MMI_UI_DALMATIAN_CALENDAR__ 
  1215.                         gdi_layer_lock_frame_buffer();
  1216.                         set_dalmatian_calendar_highlighter_box();
  1217.                     #endif
  1218.                         gui_calendar_go_to_day(c, (U8) item_index);
  1219.                     #ifdef __MMI_UI_DALMATIAN_CALENDAR__ 
  1220.                         gdi_layer_unlock_frame_buffer();
  1221.                         gdi_layer_blt_previous(0,0,UI_device_width,UI_device_height);
  1222.                     #endif
  1223.                         *calendar_event = GUI_CALENDAR_PEN_HIGHLIGHT_CHANGED;
  1224.                     }
  1225.                     c->pen_down_on_highlighted_item = 0;
  1226.                 }
  1227.             }
  1228.             else
  1229.             {
  1230.                 c->pen_down_on_highlighted_item = 0;
  1231.                 if (y < c->y1)
  1232.                 {
  1233.                     gui_calendar_previous_row(&MMI_calendar_control);   /* move to previous row */
  1234.                     *calendar_event = GUI_CALENDAR_PEN_NEED_REDRAW;
  1235.                 }
  1236.                 else if (y > c->y2)
  1237.                 {
  1238.                     gui_calendar_next_row(&MMI_calendar_control);
  1239.                     *calendar_event = GUI_CALENDAR_PEN_NEED_REDRAW;
  1240.                 }
  1241.             }
  1242.             break;
  1243.         case MMI_PEN_EVENT_UP:
  1244.             if (PEN_CHECK_BOUND(x, y, c->x1, c->y1, c->x2, c->y2))
  1245.             {
  1246.                 gui_calendar_translate_pen_position(c, x, y, &item_index);
  1247.                 if (item_index < 1 || item_index > c->last_item - c->first_item + 1)
  1248.                 {
  1249.                     ret = MMI_FALSE;
  1250.                     break;
  1251.                 }
  1252.                 if (item_index == c->highlighted_item - c->first_item + 1)
  1253.                 {
  1254.                     if (c->pen_down_on_highlighted_item == 1)
  1255.                     {
  1256.                         *calendar_event = GUI_CALENDAR_PEN_ITEM_SELECTED;
  1257.                         c->pen_down_on_highlighted_item = 0;    /* Reset again */
  1258.                         break;
  1259.                     }
  1260.                 }
  1261.             }
  1262.             else
  1263.             {
  1264.                 ret = MMI_FALSE;
  1265.             }
  1266.             break;
  1267.         case MMI_PEN_EVENT_LONG_TAP:
  1268.             /* Do nothing */
  1269.             break;
  1270.         case MMI_PEN_EVENT_REPEAT:
  1271.             /* Do nothing */
  1272.             break;
  1273.         case MMI_PEN_EVENT_ABORT:
  1274.             /* Do nothing */
  1275.             break;
  1276.         default:
  1277.             MMI_ASSERT(0);
  1278.     }
  1279.     return ret;
  1280. }
  1281. #endif /* __MMI_TOUCH_SCREEN__ */