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

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. * Filename:
  37. * ---------
  38. *  wgui_dynamic_menuitems.c
  39. *
  40. * Project:
  41. * --------
  42. *   PlutoMMI
  43. *
  44. * Description:
  45. * ------------
  46. *   In order to use limited memory (size decided in compile-time) to load unlimited items (size decide in run-time) 
  47. *   to a category screen, a modification in MMI for dynamic item loading is required as the following.
  48. *
  49. * Author:
  50. * -------
  51. *  Tim Chen
  52. *
  53. *******************************************************************************/
  54. #include "MMI_features.h"
  55. #include "gui_setting.h"
  56. #include "wgui.h"
  57. #include "wgui_fixed_menuitems.h"
  58. #include "wgui_dynamic_menuitems.h"
  59. #include "DebugInitDef.h"
  60. /* global variables */
  61. dynamic_item_circular_buffer_t dynamic_item_buffer;
  62. BOOL dynamic_item_text_align_left = FALSE;  /* 032905 Calvin added */
  63. /*****************************************************************************
  64.  * FUNCTION
  65.  *  init_dynamic_item_buffer
  66.  * DESCRIPTION
  67.  *  initialize the global dynamic item buffer
  68.  * PARAMETERS
  69.  *  n_items             [IN]        total number of items
  70.  *  get_item_func       [IN]        a callback function for filling in item text & image at run time
  71.  *  get_hint_func       [IN]        a callback function to get hint data
  72.  *  flush_data_func     [IN]        a callback function when cached data is flushed )flush_dynamic_item_buffer_before_load_chunk())
  73.  * RETURNS
  74.  *  void
  75.  *****************************************************************************/
  76. void init_dynamic_item_buffer(
  77.         S32 n_items,
  78.         GetItemFuncPtr get_item_func,
  79.         GetHintFuncPtr get_hint_func,
  80.         FlushDataFuncPtr flush_data_func)
  81. {
  82.     /*----------------------------------------------------------------*/
  83.     /* Local Variables                                                */
  84.     /*----------------------------------------------------------------*/
  85.     /*----------------------------------------------------------------*/
  86.     /* Code Body                                                      */
  87.     /*----------------------------------------------------------------*/
  88.     dynamic_item_buffer.load_func = get_item_func;
  89.     dynamic_item_buffer.hint_func = get_hint_func;
  90.     dynamic_item_buffer.flush_func = flush_data_func;
  91.     /* PMT VIKAS START 20051202 */
  92. #ifdef __MMI_UI_LIST_HIGHLIGHT_EFFECTS__
  93.     gui_add_cleanup_hook(gui_stop_list_highlight_effect);
  94. #endif 
  95.     /* PMT VIKAS END 20051202 */
  96.     if (MMI_fixed_list_menu.flags & UI_LIST_MENU_DISABLE_CACHE_DYNAMIC_DATA)
  97.     {
  98.         /* Special case for JAM (Java application manager) */
  99.         if (flush_data_func)
  100.         {
  101.             flush_data_func();
  102.         }
  103.         load_dynamic_item_buffer((MMI_MAX_MENUITEMS_IN_CONTENT < n_items) ? MMI_MAX_MENUITEMS_IN_CONTENT : n_items);
  104.     }
  105.     else
  106.     {
  107.         load_dynamic_item_buffer(n_items);
  108.     }
  109.     dynamic_item_buffer.n_total_items = n_items;
  110. }
  111. /*****************************************************************************
  112.  * FUNCTION
  113.  *  load_dynamic_item_buffer
  114.  * DESCRIPTION
  115.  *  Used internally by init_dynamic_item_buffer()
  116.  * PARAMETERS
  117.  *  n_items     [IN]        total number of items
  118.  * RETURNS
  119.  *  void
  120.  *****************************************************************************/
  121. void load_dynamic_item_buffer(S32 n_items)
  122. {
  123.     /*----------------------------------------------------------------*/
  124.     /* Local Variables                                                */
  125.     /*----------------------------------------------------------------*/
  126.     S32 i;
  127.     PU8 image;
  128.     U32 flags = 0;  /* 032905 Calvin added */
  129.     /*----------------------------------------------------------------*/
  130.     /* Code Body                                                      */
  131.     /*----------------------------------------------------------------*/
  132.     dynamic_item_buffer.head_item_index = 0;
  133.     dynamic_item_buffer.head = 0;
  134.     dynamic_item_buffer.tail = 0;
  135.     dynamic_item_buffer.count = 0;
  136.     dynamic_item_buffer.n_total_items = n_items;
  137.     if (n_items > MAX_DYNAMIC_ITEMS_BUFF)
  138.     {
  139.         n_items = MAX_DYNAMIC_ITEMS_BUFF;
  140.     }
  141.     /* 032905 Calvin added */
  142.     if (dynamic_item_text_align_left)
  143.     {
  144.         flags = UI_MENUITEM_DISABLE_ICON;
  145.     }
  146.     for (i = 0; i < n_items; i++)
  147.     {
  148.         if (dynamic_item_buffer.load_func(i, (UI_string_type) subMenuData[i], &image, 3))
  149.         {
  150.             MMI_fixed_icontext_menuitems[i].item_icon = image;
  151.             MMI_fixed_icontext_menuitems[i].item_text = (UI_string_type) subMenuData[i];
  152.             MMI_fixed_icontext_menuitems[i].flags = flags;  /* 032905 Calvin modified */
  153.             dynamic_item_buffer.count++;
  154.         }
  155.         else
  156.         {
  157.             break;
  158.         }
  159.     }
  160.     dynamic_item_buffer.tail = dynamic_item_buffer.count & MASK_DYNAMIC_ITEMS_BUFF;
  161. }
  162. /*****************************************************************************
  163.  * FUNCTION
  164.  *  get_dynamic_item_from_buffer
  165.  * DESCRIPTION
  166.  *  a convenient function to get the pointer of a item in the buffer
  167.  * PARAMETERS
  168.  *  index       [IN]        index of the item to be retrieved
  169.  * RETURNS
  170.  *  fixed_icontext_menuitem_type*
  171.  *****************************************************************************/
  172. fixed_icontext_menuitem_type *get_dynamic_item_from_buffer(S32 index)
  173. {
  174.     /*----------------------------------------------------------------*/
  175.     /* Local Variables                                                */
  176.     /*----------------------------------------------------------------*/
  177.     /*----------------------------------------------------------------*/
  178.     /* Code Body                                                      */
  179.     /*----------------------------------------------------------------*/
  180.     /* pre-condition: in_dynamic_item_buffer( index ) return TRUE */
  181.     return &MMI_fixed_icontext_menuitems[(index - dynamic_item_buffer.head_item_index +
  182.                                           dynamic_item_buffer.head) & MASK_DYNAMIC_ITEMS_BUFF];
  183. }
  184. /*****************************************************************************
  185.  * FUNCTION
  186.  *  in_dynamic_item_buffer
  187.  * DESCRIPTION
  188.  *  a convenient function to check whether a item is loaded in buffer
  189.  * PARAMETERS
  190.  *  index       [IN]        index of the item to be checked
  191.  * RETURNS
  192.  *  pBOOL : TRUE / FALSE
  193.  *****************************************************************************/
  194. pBOOL in_dynamic_item_buffer(S32 index)
  195. {
  196.     /*----------------------------------------------------------------*/
  197.     /* Local Variables                                                */
  198.     /*----------------------------------------------------------------*/
  199.     S32 count;
  200.     /*----------------------------------------------------------------*/
  201.     /* Code Body                                                      */
  202.     /*----------------------------------------------------------------*/
  203.     if (dynamic_item_buffer.count == 0)
  204.     {
  205.         return FALSE;
  206.     }
  207.     count = index - dynamic_item_buffer.head_item_index;
  208.     if (count < 0 || count >= dynamic_item_buffer.count)
  209.     {
  210.         return FALSE;
  211.     }
  212.     return TRUE;
  213. }
  214. /*****************************************************************************
  215.  * FUNCTION
  216.  *  flush_dynamic_item_buffer_before_load_chunk
  217.  * DESCRIPTION
  218.  *  Used before load_chunk_dynamic_item_buffer to flush all cached data.
  219.  * PARAMETERS
  220.  *  void
  221.  * RETURNS
  222.  *  void
  223.  *****************************************************************************/
  224. void flush_dynamic_item_buffer_before_load_chunk(void)
  225. {
  226.     /*----------------------------------------------------------------*/
  227.     /* Local Variables                                                */
  228.     /*----------------------------------------------------------------*/
  229.     /*----------------------------------------------------------------*/
  230.     /* Code Body                                                      */
  231.     /*----------------------------------------------------------------*/
  232.     dynamic_item_buffer.head_item_index = 0;
  233.     dynamic_item_buffer.head = 0;
  234.     dynamic_item_buffer.tail = 0;
  235.     dynamic_item_buffer.count = 0;
  236.     if (dynamic_item_buffer.flush_func)
  237.     {
  238.         dynamic_item_buffer.flush_func();
  239.     }
  240.     /* Keep n_total_items, load_func, flush_func, and hint_func unchanged */
  241. }
  242. /*****************************************************************************
  243.  * FUNCTION
  244.  *  load_chunk_dynamic_item_buffer
  245.  * DESCRIPTION
  246.  *  load a chunk of items, starting from [start_index] to [start_index+n_items-1], to buffer
  247.  *  the loading machnism will try to maintain the contiguous buffer as big as possible
  248.  * IMPACT
  249.  *  this function may unload some other items in the buffer
  250.  * PARAMETERS
  251.  *  start_index     [IN]        the starting index of requested items
  252.  *  n_items         [IN]        the number of items to be loaded
  253.  * RETURNS
  254.  *  S32 : the number of items that are loaded successfully
  255.  *****************************************************************************/
  256. S32 load_chunk_dynamic_item_buffer(S32 start_index, S32 n_items)
  257. {
  258.     /*----------------------------------------------------------------*/
  259.     /* Local Variables                                                */
  260.     /*----------------------------------------------------------------*/
  261.     S32 size;
  262.     S32 i, count, start, offset, index;
  263.     PU8 image;
  264.     U32 flags = 0;  /* 032905 Calvin added */
  265.     /*----------------------------------------------------------------*/
  266.     /* Code Body                                                      */
  267.     /*----------------------------------------------------------------*/
  268.     /*
  269.      * If UI_LIST_MENU_DISABLE_CACHE_DYNAMIC_DATA is set, flush_dynamic_item_buffer_before_load_chunk()
  270.      * * should be invoked before load_chunk_dynamic_item_buffer().
  271.      */
  272.     MMI_ASSERT(!(MMI_fixed_list_menu.flags & UI_LIST_MENU_DISABLE_CACHE_DYNAMIC_DATA) ||
  273.                (n_items <= MMI_MAX_MENUITEMS_IN_CONTENT && dynamic_item_buffer.count == 0));
  274.     if (dynamic_item_buffer.count == 0)
  275.     {
  276.         offset = 0;
  277.     }
  278.     else
  279.     {
  280.         offset = start_index - dynamic_item_buffer.head_item_index;
  281.     }
  282.     /* protect when n_items > MAX_DYNAMIC_ITEMS_BUFF */
  283.     if (n_items > MAX_DYNAMIC_ITEMS_BUFF)
  284.     {
  285.         n_items = MAX_DYNAMIC_ITEMS_BUFF;
  286.     }
  287.     else if (start_index + n_items > dynamic_item_buffer.n_total_items)
  288.     {
  289.         n_items = dynamic_item_buffer.n_total_items - start_index;
  290.     }
  291.     if (n_items <= 0)
  292.     {
  293.         return 0;
  294.     }
  295.     /* protect when index out of bound */
  296.     if (offset + n_items > dynamic_item_buffer.n_total_items)
  297.     {
  298.         n_items = dynamic_item_buffer.n_total_items - offset;
  299.     }
  300.     start = (offset + dynamic_item_buffer.head) & MASK_DYNAMIC_ITEMS_BUFF;
  301.     /* 032905 Calvin added */
  302.     if (dynamic_item_text_align_left)
  303.     {
  304.         flags = UI_MENUITEM_DISABLE_ICON;
  305.     }
  306.     for (count = 0, index = start_index, i = start; count < n_items;
  307.          count++, index++, i = (i + 1) & MASK_DYNAMIC_ITEMS_BUFF)
  308.     {
  309.         if (!in_dynamic_item_buffer(index))
  310.         {
  311.             if (dynamic_item_buffer.load_func(index, (UI_string_type) subMenuData[i], &image, 3))
  312.             {
  313.                 MMI_fixed_icontext_menuitems[i].item_icon = image;
  314.                 MMI_fixed_icontext_menuitems[i].item_text = (UI_string_type) subMenuData[i];
  315.                 MMI_fixed_icontext_menuitems[i].flags = flags;  /* 032905 Calvin modified */
  316.             }
  317.             else
  318.             {
  319.                 break;
  320.             }
  321.         }
  322.     }
  323.     if (count == 0)
  324.     {
  325.         return 0;
  326.     }
  327.     if (dynamic_item_buffer.count == 0 || (offset < 0 && offset + count < 0) || (offset > dynamic_item_buffer.count))
  328.     {
  329.         dynamic_item_buffer.head_item_index = start_index;
  330.         dynamic_item_buffer.head = start;
  331.         dynamic_item_buffer.tail = i;
  332.         dynamic_item_buffer.count = count;
  333.     }
  334.     else if (offset < 0)
  335.     {
  336.         dynamic_item_buffer.head_item_index = start_index;
  337.         dynamic_item_buffer.head = start;
  338.         size = dynamic_item_buffer.count - offset;
  339.         if (size > MAX_DYNAMIC_ITEMS_BUFF)
  340.         {
  341.             size = MAX_DYNAMIC_ITEMS_BUFF;
  342.         }
  343.         else if (size < count)
  344.         {
  345.             size = count;
  346.         }
  347.         dynamic_item_buffer.tail = (start + size) & MASK_DYNAMIC_ITEMS_BUFF;
  348.         dynamic_item_buffer.count = size;
  349.     }
  350.     else
  351.     {
  352.         size = count + offset;
  353.         if (size > MAX_DYNAMIC_ITEMS_BUFF)
  354.         {
  355.             dynamic_item_buffer.head = dynamic_item_buffer.tail = i;
  356.             dynamic_item_buffer.head_item_index = index - MAX_DYNAMIC_ITEMS_BUFF;
  357.             dynamic_item_buffer.count = MAX_DYNAMIC_ITEMS_BUFF;
  358.         }
  359.         else if (size > dynamic_item_buffer.count)
  360.         {
  361.             dynamic_item_buffer.tail = (dynamic_item_buffer.head + size) & MASK_DYNAMIC_ITEMS_BUFF;
  362.             dynamic_item_buffer.count = size;
  363.         }
  364.     }
  365.     return count;
  366. }
  367. /*****************************************************************************
  368.  * FUNCTION
  369.  *  resize_dynamic_icontext_menuitems_to_list_width
  370.  * DESCRIPTION
  371.  *  adjust the menu width if needed
  372.  * PARAMETERS
  373.  *  void
  374.  * RETURNS
  375.  *  void
  376.  *****************************************************************************/
  377. void resize_dynamic_icontext_menuitems_to_list_width(void)
  378. {
  379.     /*----------------------------------------------------------------*/
  380.     /* Local Variables                                                */
  381.     /*----------------------------------------------------------------*/
  382.     /*----------------------------------------------------------------*/
  383.     /* Code Body                                                      */
  384.     /*----------------------------------------------------------------*/
  385.     if (MMI_fixed_list_menu.flags & UI_LIST_MENU_AUTO_DISABLE_SCROLLBAR)
  386.     {
  387.         MMI_fixed_list_menu.flags |= UI_LIST_MENU_DISABLE_DRAW;
  388.         gui_show_dynamic_list_menu(&MMI_fixed_list_menu);
  389.         MMI_fixed_list_menu.flags &= ~UI_LIST_MENU_DISABLE_DRAW;
  390.         if (MMI_fixed_list_menu.vbar.scale >= MMI_fixed_list_menu.vbar.range)
  391.         {
  392.             resize_fixed_icontext_menuitems(
  393.                 MMI_fixed_list_menu.width - 4,
  394.                 get_menu_item_height() /* MMI_fixed_icontext_menuitem.height */ );
  395.         }
  396.     }
  397.     else if (MMI_fixed_list_menu.flags & UI_LIST_MENU_DISABLE_SCROLLBAR)
  398.     {
  399.         resize_fixed_icontext_menuitems(MMI_fixed_list_menu.width - 4, get_menu_item_height());
  400.     }
  401. }