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

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.  * gui_dynamic_menus.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.  * -------
  52.  * -------
  53.  *
  54.  *============================================================================
  55.  *             HISTORY
  56.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  57.  *------------------------------------------------------------------------------
  58.  * removed!
  59.  *
  60.  * removed!
  61.  * removed!
  62.  * removed!
  63.  *
  64.  * removed!
  65.  * removed!
  66.  * removed!
  67.  *
  68.  * removed!
  69.  * removed!
  70.  * removed!
  71.  *
  72.  * removed!
  73.  * removed!
  74.  * removed!
  75.  *
  76.  * removed!
  77.  * removed!
  78.  * removed!
  79.  *
  80.  * removed!
  81.  * removed!
  82.  * removed!
  83.  *
  84.  * removed!
  85.  * removed!
  86.  * removed!
  87.  *
  88.  * removed!
  89.  * removed!
  90.  * removed!
  91.  *
  92.  * removed!
  93.  * removed!
  94.  * removed!
  95.  *
  96.  * removed!
  97.  * removed!
  98.  * removed!
  99.  *
  100.  * removed!
  101.  * removed!
  102.  * removed!
  103.  *
  104.  * removed!
  105.  * removed!
  106.  * removed!
  107.  *
  108.  *------------------------------------------------------------------------------
  109.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  110.  *============================================================================
  111.  ****************************************************************************/
  112. #include "gui_asyncdynamic_menus.h"
  113. #include "wgui_asyncdynamic_menuitems.h"
  114. #include "DebugInitDef.h"
  115. #include "wgui_categories_util.h"
  116. /* Variable which will be set in case of data loading failed from application */
  117. S32 gui_asyncdynamic_list_error = 0;
  118. extern BOOL r2lMMIFlag;
  119. #ifdef __MMI_TOUCH_SCREEN__
  120. static void gui_asyncdynamic_list_abort_scroll_timer(void);
  121. #endif 
  122. /*****************************************************************************
  123.  * FUNCTION
  124.  *  gui_asyncdynamic_list_menu_locate_highlighted_item
  125.  * DESCRIPTION
  126.  *  
  127.  * PARAMETERS
  128.  *  m       [?]     
  129.  * RETURNS
  130.  *  void
  131.  *****************************************************************************/
  132. void gui_asyncdynamic_list_menu_locate_highlighted_item(fixed_list_menu *m)
  133. {
  134.     /*----------------------------------------------------------------*/
  135.     /* Local Variables                                                */
  136.     /*----------------------------------------------------------------*/
  137.     /* FIXME. handle the case that m->height < iheight */
  138.     S32 iwidth, iheight;
  139.     /*----------------------------------------------------------------*/
  140.     /* Code Body                                                      */
  141.     /*----------------------------------------------------------------*/
  142.     if (!(m->flags & UI_LIST_MENU_FIRST_SHIFT_HIGHLIGHTED_ITEM) &&
  143.         !(m->flags & UI_LIST_MENU_LAST_SHIFT_HIGHLIGHTED_ITEM))
  144.     {
  145.         /* 
  146.          * m->first_dispalyed_item & m->last_displayed_item is set properly in asyncdynamic_list_goto_item().
  147.          *
  148.          * However, the value of m->first_dispalyed_item & m->last_displayed_item is undefined 
  149.          * on entering a new menu (asyncdynamic_list_goto_item_no_redraw()) without list menu history.
  150.          *
  151.          */
  152.         if (m->first_displayed_item >= m->n_items || m->last_displayed_item >= m->n_items)
  153.         {
  154.             m->first_displayed_item = 0;
  155.             m->last_displayed_item = 0;
  156.         }
  157.         if (m->highlighted_item < m->first_displayed_item)
  158.         {
  159.             m->flags |= UI_LIST_MENU_FIRST_SHIFT_HIGHLIGHTED_ITEM;
  160.         }
  161.         else if (m->highlighted_item > m->last_displayed_item)
  162.         {
  163.             m->flags |= UI_LIST_MENU_LAST_SHIFT_HIGHLIGHTED_ITEM;
  164.         }
  165.     }
  166.     if (m->flags & UI_LIST_MENU_FIRST_SHIFT_HIGHLIGHTED_ITEM)
  167.     {
  168.         S32 total_height = 0, i;
  169.         U8 done = 0;
  170.         S32 list_height = m->height;
  171.         m->flags &= ~UI_LIST_MENU_FIRST_SHIFT_HIGHLIGHTED_ITEM;
  172.         m->first_displayed_item = m->highlighted_item;
  173.         /* Check if in the last page */
  174.         for (i = m->n_items - 1; (i >= 0) && (!done); i--)
  175.         {
  176.             /* Use NULL to measure menu item height because the data of menu item might not be loaded yet */
  177.             //PMT NEERAJ START 20050712
  178.             //PMT NEERAJ START 20050825
  179.         #if defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__)
  180.             /* PMT NEERAJ END 20050825 */
  181.             if (i == m->highlighted_item)
  182.             {
  183.                 current_fixed_list_menuitem_display_index = -1;
  184.             }
  185.             else
  186.             {
  187.                 current_fixed_list_menuitem_display_index = i;
  188.             }
  189.         #endif /* defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__) */ 
  190.             /* PMT NEERAJ END 20050712 */
  191.             m->item_measure_function(NULL, m->common_item_data, &iwidth, &iheight);
  192.             total_height += iheight;
  193.             /* 052305 Calvin modified: one pixel on top */
  194.             /* if( total_height > list_height + 1 ) */
  195.             if (total_height > list_height)
  196.                 /* Calvin end */
  197.             {
  198.                 if (m->first_displayed_item > i)
  199.                 {
  200.                     done = 1;
  201.                     m->first_displayed_item = i + 1;
  202.                     m->last_displayed_item = m->n_items - 1;
  203.                 }
  204.                 break;
  205.             }
  206.         }
  207.         /* Check if in the last page */
  208.         if (!done && total_height <= list_height)
  209.         {
  210.             done = 1;
  211.             m->first_displayed_item = 0;
  212.             m->last_displayed_item = m->n_items - 1;
  213.         }
  214.         /* Align to the top */
  215.         total_height = 0;
  216.         if (!done)
  217.         {
  218.             for (i = m->first_displayed_item; (i < m->n_items) && (!done); i++)
  219.             {
  220.                 //PMT NEERAJ START 20050712
  221.                 //PMT NEERAJ START 20050825
  222.             #if defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__)
  223.                 /* PMT NEERAJ END 20050825 */
  224.                 if (i == m->highlighted_item)
  225.                 {
  226.                     current_fixed_list_menuitem_display_index = -1;
  227.                 }
  228.                 else
  229.                 {
  230.                     current_fixed_list_menuitem_display_index = i;
  231.                 }
  232.             #endif /* defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__) */ 
  233.                 /* PMT NEERAJ END 20050712 */
  234.                 m->item_measure_function(NULL, m->common_item_data, &iwidth, &iheight);
  235.                 total_height += iheight;
  236.                 /* 052305 Calvin modified: one pixel on top */
  237.                 /* if( total_height > list_height + 1 ) */
  238.                 if (total_height > list_height)
  239.                     /* Calvin end */
  240.                 {
  241.                     done = 1;
  242.                     m->last_displayed_item = i - 1;
  243.                 }
  244.             }
  245.             if (!done)
  246.             {
  247.                 m->last_displayed_item = m->n_items - 1;
  248.             }
  249.         }
  250.     }
  251.     else if (m->flags & UI_LIST_MENU_LAST_SHIFT_HIGHLIGHTED_ITEM)
  252.     {
  253.         S32 total_height = 0, i;
  254.         U8 done = 0;
  255.         S32 list_height = m->height;
  256.         m->flags &= ~UI_LIST_MENU_LAST_SHIFT_HIGHLIGHTED_ITEM;
  257.         m->last_displayed_item = m->highlighted_item;
  258.         /* Check if in the first page */
  259.         for (i = 0; (i < m->n_items) && !done; i++)
  260.         {
  261.             //PMT NEERAJ START 20050712
  262.             //PMT NEERAJ START 20050825
  263.         #if defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__)
  264.             /* PMT NEERAJ END 20050825 */
  265.             if (i == m->highlighted_item)
  266.             {
  267.                 current_fixed_list_menuitem_display_index = -1;
  268.             }
  269.             else
  270.             {
  271.                 current_fixed_list_menuitem_display_index = i;
  272.             }
  273.         #endif /* defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__) */ 
  274.             /* PMT NEERAJ END 20050712 */
  275.             /* Use NULL to measure menu item height because the data of menu item might not be loaded yet */
  276.             m->item_measure_function(NULL, m->common_item_data, &iwidth, &iheight);
  277.             total_height += iheight;
  278.             /* 052305 Calvin modified: one pixel on top */
  279.             /* if( total_height > list_height + 1 ) */
  280.             if (total_height > list_height)
  281.                 /* Calvin end */
  282.             {
  283.                 if (m->last_displayed_item < i)
  284.                 {
  285.                     done = 1;
  286.                     m->first_displayed_item = 0;
  287.                     m->last_displayed_item = i - 1;
  288.                 }
  289.                 break;
  290.             }
  291.         }
  292.         /* Check if in the last page */
  293.         if (!done && total_height <= list_height)
  294.         {
  295.             done = 1;
  296.             m->first_displayed_item = 0;
  297.             m->last_displayed_item = m->n_items - 1;
  298.         }
  299.         /* Align to the bottom */
  300.         total_height = 0;
  301.         if (!done)
  302.         {
  303.             for (i = m->last_displayed_item; (i >= 0) && (!done); i--)
  304.             {
  305.                 //PMT NEERAJ START 20050712
  306.                 //PMT NEERAJ START 20050825
  307.             #if defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__)
  308.                 /* PMT NEERAJ END 20050825 */
  309.                 if (i == m->highlighted_item)
  310.                 {
  311.                     current_fixed_list_menuitem_display_index = -1;
  312.                 }
  313.                 else
  314.                 {
  315.                     current_fixed_list_menuitem_display_index = i;
  316.                 }
  317.             #endif /* defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__) */ 
  318.                 /* PMT NEERAJ END 20050712 */
  319.                 m->item_measure_function(NULL, m->common_item_data, &iwidth, &iheight);
  320.                 total_height += iheight;
  321.                 /* 052305 Calvin modified: one pixel on top */
  322.                 /* if( total_height > list_height + 1 ) */
  323.                 if (total_height > list_height)
  324.                     /* Calvin end */
  325.                 {
  326.                     done = 1;
  327.                     m->first_displayed_item = i + 1;
  328.                 }
  329.             }
  330.             if (!done)
  331.             {
  332.                 m->first_displayed_item = 0;
  333.             }
  334.         }
  335.     }
  336.     else
  337.     {
  338.         /* 
  339.          * Condition: m->first_displayed_item <= m->highlighted_item <= m->last_displayed_item 
  340.          * Do not change m->first_displayed_item if no problem occurs
  341.          */
  342.         U8 done = 0;
  343.         S32 total_height = 0, i;
  344.         S32 list_height = m->height;
  345.         /* Re-compute last_displayed_item */
  346.         for (i = m->first_displayed_item; i < m->n_items && (!done); i++)
  347.         {
  348.             //PMT NEERAJ START 20050712
  349.             //PMT NEERAJ START 20050825
  350.         #if defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__)
  351.             /* PMT NEERAJ END 20050825 */
  352.             if (i == m->highlighted_item)
  353.             {
  354.                 current_fixed_list_menuitem_display_index = -1;
  355.             }
  356.             else
  357.             {
  358.                 current_fixed_list_menuitem_display_index = i;
  359.             }
  360.         #endif /* defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__) */ 
  361.             /* PMT NEERAJ END 20050712 */
  362.             m->item_measure_function(NULL, m->common_item_data, &iwidth, &iheight);
  363.             total_height += iheight;
  364.             /* 052305 Calvin modified: one pixel on top */
  365.             /* if( total_height > list_height + 1 ) */
  366.             if (total_height > list_height)
  367.                 /* Calvin end */
  368.             {
  369.                 done = 1;
  370.                 m->last_displayed_item = i - 1;
  371.             }
  372.         }
  373.         /* Check if in the last page */
  374.         if (total_height < list_height)
  375.         {
  376.             total_height = 0;
  377.             for (i = m->n_items - 1; (i >= 0) && (!done); i--)
  378.             {
  379.                 //PMT NEERAJ START 20050712
  380.                 //PMT NEERAJ START 20050825
  381.             #if defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__)
  382.                 /* PMT NEERAJ END 20050825 */
  383.                 if (i == m->highlighted_item)
  384.                 {
  385.                     current_fixed_list_menuitem_display_index = -1;
  386.                 }
  387.                 else
  388.                 {
  389.                     current_fixed_list_menuitem_display_index = i;
  390.                 }
  391.             #endif /* defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__) */ 
  392.                 /* PMT NEERAJ END 20050712 */
  393.                 m->item_measure_function(NULL, m->common_item_data, &iwidth, &iheight);
  394.                 total_height += iheight;
  395.                 /* 052305 Calvin modified: one pixel on top */
  396.                 /* if( total_height > list_height + 1 ) */
  397.                 if (total_height > list_height)
  398.                     /* Calvin end */
  399.                 {
  400.                     if (m->first_displayed_item > i)
  401.                     {
  402.                         done = 1;
  403.                         m->first_displayed_item = i + 1;
  404.                         m->last_displayed_item = m->n_items - 1;
  405.                     }
  406.                     break;
  407.                 }
  408.             }
  409.             if (total_height <= list_height)
  410.             {
  411.                 m->first_displayed_item = 0;
  412.                 m->last_displayed_item = m->n_items - 1;
  413.             }
  414.         }
  415.         MMI_DBG_ASSERT(m->first_displayed_item <= m->highlighted_item);
  416.         if (m->highlighted_item > m->last_displayed_item)
  417.         {
  418.             done = 0;
  419.             total_height = 0;
  420.             m->last_displayed_item = m->highlighted_item;
  421.             for (i = m->last_displayed_item; i >= 0 && (!done); i--)
  422.             {
  423.                 //PMT NEERAJ START 20050712
  424.                 //PMT NEERAJ START 20050825
  425.             #if defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__)
  426.                 /* PMT NEERAJ END 20050825 */
  427.                 if (i == m->highlighted_item)
  428.                 {
  429.                     current_fixed_list_menuitem_display_index = -1;
  430.                 }
  431.                 else
  432.                 {
  433.                     current_fixed_list_menuitem_display_index = i;
  434.                 }
  435.             #endif /* defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__) */ 
  436.                 /* PMT NEERAJ END 20050712 */
  437.                 m->item_measure_function(NULL, m->common_item_data, &iwidth, &iheight);
  438.                 total_height += iheight;
  439.                 /* 052305 Calvin modified: one pixel on top */
  440.                 /* if( total_height > list_height + 1 ) */
  441.                 if (total_height > list_height)
  442.                     /* Calvin end */
  443.                 {
  444.                     done = 1;
  445.                     m->first_displayed_item = i + 1;
  446.                 }
  447.             }
  448.         }
  449.     }
  450.     /* Load one more item because it might be accessed in gui_show_asyncdynamic_list_menu() */
  451.     if (!load_chunk_asyncdynamic_item_buffer
  452.         (m->first_displayed_item, m->last_displayed_item - m->first_displayed_item + 2))
  453.     {
  454.         gui_asyncdynamic_list_error = 1;
  455.     }
  456. }
  457. /*****************************************************************************
  458.  * FUNCTION
  459.  *  gui_asyncdynamic_list_menu_locate_previous_item
  460.  * DESCRIPTION
  461.  *  
  462.  * PARAMETERS
  463.  *  m       [?]     
  464.  * RETURNS
  465.  *  void
  466.  *****************************************************************************/
  467. void gui_asyncdynamic_list_menu_locate_previous_item(fixed_list_menu *m)
  468. {
  469.     /*----------------------------------------------------------------*/
  470.     /* Local Variables                                                */
  471.     /*----------------------------------------------------------------*/
  472.     /*----------------------------------------------------------------*/
  473.     /* Code Body                                                      */
  474.     /*----------------------------------------------------------------*/
  475.     if (m->highlighted_item < m->first_displayed_item)
  476.     {
  477.         m->first_displayed_item = m->highlighted_item;
  478.         if (!load_chunk_asyncdynamic_item_buffer(m->highlighted_item, 1))
  479.         {
  480.             gui_asyncdynamic_list_error = 1;
  481.         }
  482.     }
  483. }
  484. /*****************************************************************************
  485.  * FUNCTION
  486.  *  gui_asyncdynamic_list_menu_locate_next_item
  487.  * DESCRIPTION
  488.  *  
  489.  * PARAMETERS
  490.  *  m       [?]     
  491.  * RETURNS
  492.  *  void
  493.  *****************************************************************************/
  494. void gui_asyncdynamic_list_menu_locate_next_item(fixed_list_menu *m)
  495. {
  496.     /*----------------------------------------------------------------*/
  497.     /* Local Variables                                                */
  498.     /*----------------------------------------------------------------*/
  499.     S32 iwidth, iheight;
  500.     /*----------------------------------------------------------------*/
  501.     /* Code Body                                                      */
  502.     /*----------------------------------------------------------------*/
  503.     if (m->highlighted_item > m->last_displayed_item)
  504.     {
  505.         S32 total_height = 0, i;
  506.         /* S32 list_height = m->height-4; */
  507.         S32 list_height = m->height;    /* 032505 Calvin modified */
  508.         m->last_displayed_item = m->highlighted_item;
  509.         for (i = m->last_displayed_item; i >= 0; i--)
  510.         {
  511.             //PMT NEERAJ START 20050712
  512.             //PMT NEERAJ START 20050825
  513.         #if defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__)
  514.             /* PMT NEERAJ END 20050825 */
  515.             if (i == m->highlighted_item)
  516.             {
  517.                 current_fixed_list_menuitem_display_index = -1;
  518.             }
  519.             else
  520.             {
  521.                 current_fixed_list_menuitem_display_index = i;
  522.             }
  523.         #endif /* defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__) */ 
  524.             /* PMT NEERAJ END 20050712 */
  525.             m->item_measure_function(NULL, m->common_item_data, &iwidth, &iheight);
  526.             total_height += iheight;
  527.             /* 052305 Calvin modified: one pixel on top */
  528.             /* if( total_height > list_height + 1 ) */
  529.             if (total_height > list_height)
  530.                 /* Calvin end */
  531.             {
  532.                 m->first_displayed_item = i + 1;
  533.                 break;
  534.             }
  535.         }
  536.         /* Load one more item because it might be accessed in gui_show_asyncdynamic_list_menu() */
  537.         if (!load_chunk_asyncdynamic_item_buffer(m->highlighted_item, 2))
  538.         {
  539.             gui_asyncdynamic_list_error = 1;
  540.         }
  541.     }
  542. }
  543. /*****************************************************************************
  544.  * FUNCTION
  545.  *  switch_asynchighlighted_item
  546.  * DESCRIPTION
  547.  *  
  548.  * PARAMETERS
  549.  *  m                           [?]         
  550.  *  last_highlighted_item       [IN]        
  551.  * RETURNS
  552.  *  void
  553.  *****************************************************************************/
  554. void switch_asynchighlighted_item(fixed_list_menu *m, S32 last_highlighted_item)
  555. {
  556.     /*----------------------------------------------------------------*/
  557.     /* Local Variables                                                */
  558.     /*----------------------------------------------------------------*/
  559.     /*----------------------------------------------------------------*/
  560.     /* Code Body                                                      */
  561.     /*----------------------------------------------------------------*/
  562.     if (last_highlighted_item != m->highlighted_item)
  563.     {
  564.         if ((last_highlighted_item >= 0) && (last_highlighted_item < m->n_items))
  565.         {
  566.             if (in_asyncdynamic_item_buffer(last_highlighted_item))
  567.             {
  568.                 m->item_remove_highlight_function(
  569.                     get_asyncdynamic_item_from_buffer(last_highlighted_item),
  570.                     m->common_item_data);
  571.             }
  572.         }
  573.         if ((m->highlighted_item >= 0) && (m->highlighted_item < m->n_items))
  574.         {
  575.             m->item_highlight_function(get_asyncdynamic_item_from_buffer(m->highlighted_item), m->common_item_data);
  576.         }
  577.         m->item_unhighlighted(last_highlighted_item);
  578.     #ifdef __MMI_TOUCH_SCREEN__
  579.         m->pen_event_current_selected_callback_function = m->pen_event_default_selected_callback_function;
  580.     #endif 
  581.         m->item_highlighted(m->highlighted_item);
  582.     }
  583. }
  584. /*****************************************************************************
  585.  * FUNCTION
  586.  *  gui_asyncdynamic_list_menu_goto_item
  587.  * DESCRIPTION
  588.  *  
  589.  * PARAMETERS
  590.  *  m       [?]         
  591.  *  i       [IN]        
  592.  * RETURNS
  593.  *  void
  594.  *****************************************************************************/
  595. void gui_asyncdynamic_list_menu_goto_item(fixed_list_menu *m, S32 i)
  596. {
  597.     /*----------------------------------------------------------------*/
  598.     /* Local Variables                                                */
  599.     /*----------------------------------------------------------------*/
  600.     S32 last_highlighted_item;
  601.     /*----------------------------------------------------------------*/
  602.     /* Code Body                                                      */
  603.     /*----------------------------------------------------------------*/
  604. #ifdef __MMI_TOUCH_SCREEN__
  605.     /* If highlight is changed by keypad, abort scroll timer */
  606.     gui_asyncdynamic_list_abort_scroll_timer();
  607. #endif /* __MMI_TOUCH_SCREEN__ */ 
  608.     if ((i < 0) || (i > m->n_items - 1))
  609.     {
  610.         return;
  611.     }
  612.     if (i == m->highlighted_item)
  613.     {
  614.         return;
  615.     }
  616.     last_highlighted_item = m->highlighted_item;
  617.     m->highlighted_item = i;
  618.     gui_asyncdynamic_list_menu_locate_highlighted_item(m);
  619.     /* Return In Case Of Error */
  620.     if (gui_asyncdynamic_list_error)
  621.     {
  622.         return;
  623.     }
  624.     switch_asynchighlighted_item(m, last_highlighted_item);
  625. }
  626. /*****************************************************************************
  627.  * FUNCTION
  628.  *  gui_asyncdynamic_list_menu_goto_next_item
  629.  * DESCRIPTION
  630.  *  
  631.  * PARAMETERS
  632.  *  m       [?]     
  633.  * RETURNS
  634.  *  void
  635.  *****************************************************************************/
  636. void gui_asyncdynamic_list_menu_goto_next_item(fixed_list_menu *m)
  637. {
  638.     /*----------------------------------------------------------------*/
  639.     /* Local Variables                                                */
  640.     /*----------------------------------------------------------------*/
  641.     S32 last_highlighted_item;
  642.     U8 loop_flag = 0;
  643.     /*----------------------------------------------------------------*/
  644.     /* Code Body                                                      */
  645.     /*----------------------------------------------------------------*/
  646. #ifdef __MMI_TOUCH_SCREEN__
  647.     /* If highlight is changed by keypad, abort scroll timer */
  648.     gui_asyncdynamic_list_abort_scroll_timer();
  649. #endif /* __MMI_TOUCH_SCREEN__ */ 
  650.     if (m->highlighted_item >= m->n_items - 1)
  651.     {
  652.         if (m->flags & UI_LIST_MENU_LOOP)
  653.         {
  654.             loop_flag = 1;
  655.         }
  656.         else
  657.         {
  658.             return;
  659.         }
  660.     }
  661.     last_highlighted_item = m->highlighted_item;
  662.     if (loop_flag)
  663.     {
  664.         m->highlighted_item = 0;
  665.         gui_asyncdynamic_list_menu_locate_highlighted_item(m);
  666.     }
  667.     else
  668.     {
  669.         m->highlighted_item++;
  670.         gui_asyncdynamic_list_menu_locate_next_item(m);
  671.     }
  672.     /* Return In Case Of Error */
  673.     if (gui_asyncdynamic_list_error)
  674.     {
  675.         return;
  676.     }
  677.     switch_asynchighlighted_item(m, last_highlighted_item);
  678. }
  679. /*****************************************************************************
  680.  * FUNCTION
  681.  *  gui_asyncdynamic_list_menu_goto_previous_item
  682.  * DESCRIPTION
  683.  *  
  684.  * PARAMETERS
  685.  *  m       [?]     
  686.  * RETURNS
  687.  *  void
  688.  *****************************************************************************/
  689. void gui_asyncdynamic_list_menu_goto_previous_item(fixed_list_menu *m)
  690. {
  691.     /*----------------------------------------------------------------*/
  692.     /* Local Variables                                                */
  693.     /*----------------------------------------------------------------*/
  694.     S32 last_highlighted_item;
  695.     U8 loop_flag = 0;
  696.     /*----------------------------------------------------------------*/
  697.     /* Code Body                                                      */
  698.     /*----------------------------------------------------------------*/
  699. #ifdef __MMI_TOUCH_SCREEN__
  700.     /* If highlight is changed by keypad, abort scroll timer */
  701.     gui_asyncdynamic_list_abort_scroll_timer();
  702. #endif /* __MMI_TOUCH_SCREEN__ */ 
  703.     if (m->highlighted_item <= 0)
  704.     {
  705.         if (m->flags & UI_LIST_MENU_LOOP)
  706.         {
  707.             loop_flag = 1;
  708.         }
  709.         else
  710.         {
  711.             return;
  712.         }
  713.     }
  714.     last_highlighted_item = m->highlighted_item;
  715.     if (loop_flag)
  716.     {
  717.         m->highlighted_item = m->n_items - 1;
  718.         gui_asyncdynamic_list_menu_locate_highlighted_item(m);
  719.     }
  720.     else
  721.     {
  722.         m->highlighted_item--;
  723.         gui_asyncdynamic_list_menu_locate_previous_item(m);
  724.     }
  725.     /* Return In Case Of Error */
  726.     if (gui_asyncdynamic_list_error)
  727.     {
  728.         return;
  729.     }
  730.     switch_asynchighlighted_item(m, last_highlighted_item);
  731. }
  732. /*****************************************************************************
  733.  * FUNCTION
  734.  *  gui_show_asyncdynamic_list_menu
  735.  * DESCRIPTION
  736.  *  
  737.  * PARAMETERS
  738.  *  m       [?]     
  739.  * RETURNS
  740.  *  void
  741.  *****************************************************************************/
  742. void gui_show_asyncdynamic_list_menu(fixed_list_menu *m)
  743. {
  744.     /*----------------------------------------------------------------*/
  745.     /* Local Variables                                                */
  746.     /*----------------------------------------------------------------*/
  747.     S32 x1, y1, x2, y2, y_offset;
  748.     UI_filled_area *f;
  749.     S32 i;
  750.     S32 iwidth, iheight;
  751.     fixed_icontext_list_menuitem_type *item_p;
  752.     U8 done = 0;
  753.     S32 total_height, counter, list_height;
  754.     U8 disable_draw = 0;
  755.     /*----------------------------------------------------------------*/
  756.     /* Code Body                                                      */
  757.     /*----------------------------------------------------------------*/
  758.     if (gui_asyncdynamic_list_error)
  759.     {
  760.         /* Context is invalid, and screen is exiting */
  761.         MMI_DBG_ASSERT(0);
  762.         return;
  763.     }
  764.     if (m->flags & UI_LIST_MENU_DISABLE_DRAW)
  765.     {
  766.         disable_draw = 1;
  767.     }
  768.     gui_push_clip();
  769.     gui_push_text_clip();
  770.     x1 = m->x;
  771.     y1 = m->y;
  772.     x2 = x1 + m->width - 1;
  773.     y2 = y1 + m->height - 1;
  774.     if (m->flags & UI_LIST_MENU_STATE_FOCUSSED)
  775.     {
  776.         f = m->focussed_filler;
  777.     }
  778.     else
  779.     {
  780.         f = m->normal_filler;
  781.     }
  782.     gui_set_clip(x1, y1, x2, y2);
  783.     if (!disable_draw && !(m->flags & UI_LIST_MENU_DISABLE_BACKGROUND))
  784.     {
  785.         if (!(m->flags & UI_LIST_MENU_DISABLE_BKGRND_IN_LAYER) && (wgui_is_wallpaper_on_bottom() == MMI_TRUE))
  786.         {
  787.             gdi_draw_solid_rect(x1, y1, x2, y2, GDI_COLOR_TRANSPARENT);
  788.         #if defined (__MMI_UI_TRANSPARENT_EFFECT__) || defined (__MMI_UI_LIST_HIGHLIGHT_EFFECTS__)
  789.             if (gui_get_transparent_source_layer() == GDI_LAYER_EMPTY_HANDLE)   /* 110705 WAP menu Clavin add */
  790.             {
  791.                 gui_set_transparent_source_layer(dm_get_scr_bg_layer());        /* should remove */
  792.             }
  793.         #endif /* defined (__MMI_UI_TRANSPARENT_EFFECT__) || defined (__MMI_UI_LIST_HIGHLIGHT_EFFECTS__) */ 
  794.         }
  795.     #ifdef __MMI_UI_LIST_CACHE_BACKGROUND__
  796.         else if (!(m->flags & UI_LIST_MENU_DISABLE_BKGRND_IN_LAYER) && (gui_get_multilayer_mask() & UI_MUL_BKG_SUBMENU))
  797.         {
  798.             gui_show_menu_background_in_layer(x1, y1, x2, y2, f);
  799.         }
  800.     #endif /* __MMI_UI_LIST_CACHE_BACKGROUND__ */ 
  801.         else
  802.         {
  803.         #if !defined(MT6205B) && !defined(MT6208)
  804.             gui_draw_filled_area(x1, y1, x2, y2, f);
  805.         #else /* !defined(MT6205B) && !defined(MT6208) */
  806.             /* For low-end phone, disable list menu background can greately improve menu performance. 
  807.                We use the color of filler to draw the background (typically white). */
  808.             color c = f->c;
  809.             gdi_draw_solid_rect(x1, y1, x2, y2, gdi_act_color_from_rgb(255, c.r, c.g, c.b));
  810.         #endif /* !defined(MT6205B) && !defined(MT6208) */
  811.         }
  812.     }
  813.     if (m->n_items <= 0)
  814.     {
  815.         gui_pop_clip();
  816.         gui_pop_text_clip();
  817.         return;
  818.     }
  819.     if (!(m->flags & UI_LIST_MENU_DISABLE_SCROLLBAR))
  820.     {
  821.         if (r2lMMIFlag)
  822.         {
  823.             x1 += m->vbar.width;
  824.         }
  825.         else
  826.         {
  827.             x2 -= m->vbar.width;
  828.         }
  829.     }
  830.     /* Modified to separate title bar and list menu */
  831.     y1 = m->y + m->top;
  832.     list_height = m->height;
  833.     gui_set_text_clip(x1, y1, x2, y2);
  834.     gui_set_clip(x1, y1, x2, y2);
  835.     total_height = 0;
  836.     counter = 0;
  837.     current_fixed_list_menuitem_display_index = -1;
  838.     for (i = m->first_displayed_item; (i < m->n_items && !done); i++)
  839.     {
  840.         item_p = get_asyncdynamic_item_from_buffer(i);
  841.         current_fixed_list_menuitem_display_index = (i == m->highlighted_item) ? -1 : i;
  842.         m->item_measure_function(NULL, m->common_item_data, &iwidth, &iheight);
  843.         y_offset = total_height;
  844.         total_height += iheight;
  845.         /* 052305 Calvin modified: one pixel on top */
  846.         /* if( total_height > list_height + 1 ) */
  847.         if (total_height > list_height)
  848.             /* Calvin end */
  849.         {
  850.             done = 1;
  851.             if ((counter == 0) && !disable_draw)
  852.             {
  853.                 m->item_display_function(item_p, m->common_item_data, x1, y_offset + y1);
  854.             }
  855.         }
  856.         else
  857.         {
  858.             if (!disable_draw)
  859.             {
  860.                 m->item_display_function(item_p, m->common_item_data, x1, y_offset + y1);
  861.             }
  862.             counter++;
  863.         }
  864.     }
  865.     current_fixed_list_menuitem_display_index = -1;
  866.     if (counter == 0)
  867.     {
  868.         counter = 1;
  869.     }
  870.     m->last_displayed_item = m->first_displayed_item + counter - 1;
  871.     m->displayed_items = counter;
  872.     if (!disable_draw && !(m->flags & UI_LIST_MENU_DISABLE_SCROLLBAR))
  873.     {
  874.         S32 vbar_x = 0, vbar_button_x = 0;
  875.         gui_set_vertical_scrollbar_range(&m->vbar, m->n_items);
  876.         gui_set_vertical_scrollbar_scale(&m->vbar, m->displayed_items);
  877.         gui_set_vertical_scrollbar_value(&m->vbar, m->first_displayed_item);
  878.         gui_set_clip(m->x, m->y, m->x + m->width - 1, m->y + m->height - 1);
  879.         if (m->flags & UI_LIST_MENU_AUTO_DISABLE_SCROLLBAR)
  880.         {
  881.             if (m->displayed_items < m->n_items)
  882.             {
  883.                 if (r2lMMIFlag)
  884.                 {
  885.                     vbar_x = m->vbar.x;
  886.                     vbar_button_x = m->vbar.scroll_button.x;
  887.                     m->vbar.x = m->vbar.x + m->vbar.width - m->width;
  888.                     m->vbar.scroll_button.x = m->vbar.scroll_button.x + m->vbar.scroll_button.width - m->width;
  889.                     gui_show_vertical_scrollbar(&m->vbar);
  890.                     m->vbar.x = vbar_x;
  891.                     m->vbar.scroll_button.x = vbar_button_x;
  892.                 }
  893.                 else
  894.                 {
  895.                     gui_show_vertical_scrollbar(&m->vbar);
  896.                 }
  897.             }
  898.         }
  899.         else
  900.         {
  901.             if (r2lMMIFlag)
  902.             {
  903.                 vbar_x = m->vbar.x;
  904.                 vbar_button_x = m->vbar.scroll_button.x;
  905.                 m->vbar.x = m->vbar.x + m->vbar.width - m->width;
  906.                 m->vbar.scroll_button.x = m->vbar.scroll_button.x + m->vbar.scroll_button.width - m->width;
  907.                 gui_show_vertical_scrollbar(&m->vbar);
  908.                 m->vbar.x = vbar_x;
  909.                 m->vbar.scroll_button.x = vbar_button_x;
  910.             }
  911.             else
  912.             {
  913.                 gui_show_vertical_scrollbar(&m->vbar);
  914.             }
  915.         }
  916.     }
  917.     gui_pop_clip();
  918.     gui_pop_text_clip();
  919. }
  920. /*****************************************************************************
  921.  * FUNCTION
  922.  *  gui_show_asyncdynamic_list_menu_no_draw
  923.  * DESCRIPTION
  924.  *  
  925.  * PARAMETERS
  926.  *  m       [?]     
  927.  * RETURNS
  928.  *  void
  929.  *****************************************************************************/
  930. void gui_show_asyncdynamic_list_menu_no_draw(fixed_list_menu *m)
  931. {
  932.     /*----------------------------------------------------------------*/
  933.     /* Local Variables                                                */
  934.     /*----------------------------------------------------------------*/
  935.     S32 i;
  936.     S32 iwidth, iheight;
  937.     U8 done = 0;
  938.     S32 total_height, counter, list_height;
  939.     /*----------------------------------------------------------------*/
  940.     /* Code Body                                                      */
  941.     /*----------------------------------------------------------------*/
  942.     list_height = m->height;
  943.     total_height = 0;
  944.     counter = 0;
  945.     current_fixed_list_menuitem_display_index = -1;
  946.     for (i = m->first_displayed_item; (i < m->n_items && !done); i++)
  947.     {
  948.         current_fixed_list_menuitem_display_index = (i == m->highlighted_item) ? -1 : i;
  949.         m->item_measure_function(NULL, m->common_item_data, &iwidth, &iheight);
  950.         total_height += iheight;
  951.         if (total_height > list_height + 1)
  952.         {
  953.             done = 1;
  954.         }
  955.         else
  956.         {
  957.             counter++;
  958.         }
  959.     }
  960.     current_fixed_list_menuitem_display_index = -1;
  961.     m->last_displayed_item = (counter == 0) ? m->first_displayed_item : m->first_displayed_item + counter - 1;
  962.     m->displayed_items = counter;
  963.     if (!(m->flags & UI_LIST_MENU_DISABLE_SCROLLBAR))
  964.     {
  965.         gui_set_vertical_scrollbar_range(&m->vbar, m->n_items);
  966.         gui_set_vertical_scrollbar_scale(&m->vbar, m->displayed_items);
  967.         gui_set_vertical_scrollbar_value(&m->vbar, m->first_displayed_item);
  968.     }
  969. }
  970. #ifdef __MMI_TOUCH_SCREEN__
  971. static void gui_asyncdynamic_list_menu_scroll_by_pen(
  972.                 fixed_list_menu *m,
  973.                 S32 first_displayed,
  974.                 gui_list_pen_enum *menu_event);
  975. /* Target menu for scroll timer */
  976. static fixed_list_menu *gui_pen_scroll_asyncdynamic_menu = NULL;
  977. /* Because loading data takes some time (depending on the applications using dynamic list), 
  978.    we use a timer to reduce gui_asyncdynamic_list_menu_scroll_by_pen().  */
  979. /*****************************************************************************
  980.  * FUNCTION
  981.  *  gui_asyncdynamic_list_menu_scroll_timer_hdlr
  982.  * DESCRIPTION
  983.  *  
  984.  * PARAMETERS
  985.  *  void
  986.  * RETURNS
  987.  *  void
  988.  *****************************************************************************/
  989. static void gui_asyncdynamic_list_menu_scroll_timer_hdlr(void)
  990. {
  991.     /*----------------------------------------------------------------*/
  992.     /* Local Variables                                                */
  993.     /*----------------------------------------------------------------*/
  994.     fixed_list_menu *m = gui_pen_scroll_asyncdynamic_menu;
  995.     gui_list_pen_enum menu_event;
  996.     /*----------------------------------------------------------------*/
  997.     /* Code Body                                                      */
  998.     /*----------------------------------------------------------------*/
  999.     gui_pen_scroll_asyncdynamic_menu = NULL;
  1000.     if (!m)
  1001.     {
  1002.         return;
  1003.     }
  1004.     if (gui_asyncdynamic_list_error)
  1005.     {
  1006.         return;
  1007.     }
  1008.     gui_asyncdynamic_list_menu_scroll_by_pen(m, m->pen_scroll_after_delay, &menu_event);
  1009.     if (gui_asyncdynamic_list_error)
  1010.     {
  1011.         return;
  1012.     }
  1013.     if (menu_event == GUI_LIST_PEN_HIGHLIGHT_CHANGED || menu_event == GUI_LIST_PEN_NEED_REDRAW)
  1014.     {
  1015.         if (m->pen_redraw_menu_function)
  1016.         {
  1017.             m->pen_redraw_menu_function();
  1018.         }
  1019.         else
  1020.         {
  1021.             MMI_DBG_ASSERT(0);
  1022.         }
  1023.     }
  1024. }
  1025. /*****************************************************************************
  1026.  * FUNCTION
  1027.  *  gui_asyncdynamic_list_abort_scroll_timer
  1028.  * DESCRIPTION
  1029.  *  
  1030.  * PARAMETERS
  1031.  *  void
  1032.  * RETURNS
  1033.  *  void
  1034.  *****************************************************************************/
  1035. static void gui_asyncdynamic_list_abort_scroll_timer(void)
  1036. {
  1037.     /*----------------------------------------------------------------*/
  1038.     /* Local Variables                                                */
  1039.     /*----------------------------------------------------------------*/
  1040.     /*----------------------------------------------------------------*/
  1041.     /* Code Body                                                      */
  1042.     /*----------------------------------------------------------------*/
  1043.     gui_pen_scroll_asyncdynamic_menu = NULL;
  1044. }
  1045. /*****************************************************************************
  1046.  * FUNCTION
  1047.  *  gui_asyncdynamic_list_start_scroll_timer
  1048.  * DESCRIPTION
  1049.  *  
  1050.  * PARAMETERS
  1051.  *  m           [?]         
  1052.  *  value       [IN]        
  1053.  * RETURNS
  1054.  *  void
  1055.  *****************************************************************************/
  1056. static void gui_asyncdynamic_list_start_scroll_timer(fixed_list_menu *m, S32 value)
  1057. {
  1058.     /*----------------------------------------------------------------*/
  1059.     /* Local Variables                                                */
  1060.     /*----------------------------------------------------------------*/
  1061.     /*----------------------------------------------------------------*/
  1062.     /* Code Body                                                      */
  1063.     /*----------------------------------------------------------------*/
  1064.     /* assert that no two menu scroll at the same time */
  1065.     MMI_DBG_ASSERT(!gui_pen_scroll_asyncdynamic_menu || gui_pen_scroll_asyncdynamic_menu == m);
  1066.     m->pen_scroll_after_delay = value;
  1067.     gui_pen_scroll_asyncdynamic_menu = m;
  1068.     gui_cancel_timer(gui_asyncdynamic_list_menu_scroll_timer_hdlr);
  1069.     gui_start_timer(m->pen_scroll_delay_time, gui_asyncdynamic_list_menu_scroll_timer_hdlr);
  1070.     gui_add_cleanup_hook(gui_asyncdynamic_list_abort_scroll_timer);
  1071. }
  1072. /*****************************************************************************
  1073.  * FUNCTION
  1074.  *  gui_asyncdynamic_list_menu_translate_pen_position
  1075.  * DESCRIPTION
  1076.  *  
  1077.  * PARAMETERS
  1078.  *  m               [?]         
  1079.  *  y               [IN]        
  1080.  *  item_index      [?]         
  1081.  * RETURNS
  1082.  *  
  1083.  *****************************************************************************/
  1084. static BOOL gui_asyncdynamic_list_menu_translate_pen_position(fixed_list_menu *m, S32 y, S32 *item_index)
  1085. {
  1086.     /*----------------------------------------------------------------*/
  1087.     /* Local Variables                                                */
  1088.     /*----------------------------------------------------------------*/
  1089.     S32 total_height = 0, i;
  1090.     S32 iwidth, iheight;
  1091.     BOOL ret = MMI_FALSE;
  1092.     /*----------------------------------------------------------------*/
  1093.     /* Code Body                                                      */
  1094.     /*----------------------------------------------------------------*/
  1095.     y -= m->y;
  1096.     if (y < 0)
  1097.     {
  1098.         *item_index = (m->first_displayed_item > 0) ? m->first_displayed_item - 1 : 0;
  1099.     }
  1100.     else if (y >= m->height)
  1101.     {
  1102.         *item_index = (m->last_displayed_item < m->n_items - 1) ? m->last_displayed_item + 1 : m->n_items - 1;
  1103.     }
  1104.     else
  1105.     {
  1106.         *item_index = m->n_items - 1;
  1107.         for (i = m->first_displayed_item; i < m->n_items; i++)
  1108.         {
  1109.         #if defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__)
  1110.             if (i == m->highlighted_item)
  1111.             {
  1112.                 current_fixed_list_menuitem_display_index = -1;
  1113.             }
  1114.             else
  1115.             {
  1116.                 current_fixed_list_menuitem_display_index = i;
  1117.             }
  1118.         #endif /* defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__) */ 
  1119.             /* Use null because menu item might not be loaded yet */
  1120.             m->item_measure_function(NULL, m->common_item_data, &iwidth, &iheight);
  1121.             total_height += iheight;
  1122.             if (total_height > y)
  1123.             {
  1124.                 *item_index = i;
  1125.                 ret = MMI_TRUE;
  1126.                 break;
  1127.             }
  1128.         }
  1129.     }
  1130.     return ret;
  1131. }
  1132. /*****************************************************************************
  1133.  * FUNCTION
  1134.  *  gui_asyncdynamic_list_menu_scroll_by_pen
  1135.  * DESCRIPTION
  1136.  *  
  1137.  * PARAMETERS
  1138.  *  m                   [?]         
  1139.  *  first_displayed     [IN]        
  1140.  *  menu_event          [?]         
  1141.  * RETURNS
  1142.  *  void
  1143.  *****************************************************************************/
  1144. static void gui_asyncdynamic_list_menu_scroll_by_pen(
  1145.                 fixed_list_menu *m,
  1146.                 S32 first_displayed,
  1147.                 gui_list_pen_enum *menu_event)
  1148. {
  1149.     /*----------------------------------------------------------------*/
  1150.     /* Local Variables                                                */
  1151.     /*----------------------------------------------------------------*/
  1152.     S32 total_height = 0, i;
  1153.     S32 iwidth, iheight;
  1154.     S32 last_displayed;
  1155.     /*----------------------------------------------------------------*/
  1156.     /* Code Body                                                      */
  1157.     /*----------------------------------------------------------------*/
  1158.     if (first_displayed > m->highlighted_item)
  1159.     {
  1160.         m->flags |= UI_LIST_MENU_FIRST_SHIFT_HIGHLIGHTED_ITEM;
  1161.         gui_asyncdynamic_list_menu_goto_item(m, first_displayed);
  1162.         m->flags &= ~UI_LIST_MENU_FIRST_SHIFT_HIGHLIGHTED_ITEM;
  1163.         *menu_event = GUI_LIST_PEN_HIGHLIGHT_CHANGED;
  1164.     }
  1165.     else
  1166.     {
  1167.         last_displayed = m->n_items - 1;
  1168.         for (i = first_displayed; i < m->n_items; i++)
  1169.         {
  1170.         #if defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__)
  1171.             if (i == m->highlighted_item)
  1172.             {
  1173.                 current_fixed_list_menuitem_display_index = -1;
  1174.             }
  1175.             else
  1176.             {
  1177.                 current_fixed_list_menuitem_display_index = i;
  1178.             }
  1179.         #endif /* defined(__MMI_UI_TWO_LINE_MENUITEM_STYLES__) || defined(__MMI_UI_HINTS_IN_MENUITEM__) */ 
  1180.             /* Use null because menu item might not be loaded yet */
  1181.             m->item_measure_function(NULL, m->common_item_data, &iwidth, &iheight);
  1182.             total_height += iheight;
  1183.             if (total_height > m->height + 1)
  1184.             {
  1185.                 last_displayed = i - 1;
  1186.                 break;
  1187.             }
  1188.         }
  1189.         if (last_displayed < m->highlighted_item)
  1190.         {
  1191.             m->flags |= UI_LIST_MENU_LAST_SHIFT_HIGHLIGHTED_ITEM;
  1192.             gui_asyncdynamic_list_menu_goto_item(m, last_displayed);
  1193.             m->flags &= ~UI_LIST_MENU_LAST_SHIFT_HIGHLIGHTED_ITEM;
  1194.             *menu_event = GUI_LIST_PEN_HIGHLIGHT_CHANGED;
  1195.         }
  1196.         else
  1197.         {
  1198.             m->first_displayed_item = first_displayed;
  1199.             m->last_displayed_item = last_displayed;
  1200.             /* Handle this in similar way to asyncdynamic_list_goto_item_no_redraw */
  1201.             if (load_chunk_asyncdynamic_item_buffer
  1202.                 (m->first_displayed_item, m->last_displayed_item - m->first_displayed_item + 2))
  1203.             {
  1204.                 switch_asynchighlighted_item(m, -1);
  1205.             }
  1206.             else
  1207.             {
  1208.                 gui_asyncdynamic_list_error = 1;
  1209.             }
  1210.             *menu_event = GUI_LIST_PEN_NEED_REDRAW;
  1211.         }
  1212.     }
  1213.     if (gui_asyncdynamic_list_error)
  1214.     {
  1215.         *menu_event = GUI_LIST_PEN_NONE;
  1216.     }
  1217. }
  1218. /*****************************************************************************
  1219.  * FUNCTION
  1220.  *  gui_asyncdynamic_list_menu_translate_pen_event
  1221.  * DESCRIPTION
  1222.  *  
  1223.  * PARAMETERS
  1224.  *  m               [?]         
  1225.  *  pen_event       [IN]        
  1226.  *  x               [IN]        
  1227.  *  y               [IN]        
  1228.  *  menu_event      [?]         
  1229.  * RETURNS
  1230.  *  
  1231.  *****************************************************************************/
  1232. BOOL gui_asyncdynamic_list_menu_translate_pen_event(
  1233.         fixed_list_menu *m,
  1234.         mmi_pen_event_type_enum pen_event,
  1235.         S16 x,
  1236.         S16 y,
  1237.         gui_list_pen_enum *menu_event)
  1238. {
  1239.     /*----------------------------------------------------------------*/
  1240.     /* Local Variables                                                */
  1241.     /*----------------------------------------------------------------*/
  1242.     BOOL ret;
  1243.     gui_list_pen_state_struct *pen_state;
  1244.     gui_scrollbar_pen_enum scrollbar_event;
  1245.     gui_pen_event_param_struct scrollbar_param;
  1246.     S32 item_index;
  1247.     /*----------------------------------------------------------------*/
  1248.     /* Code Body                                                      */
  1249.     /*----------------------------------------------------------------*/
  1250.     pen_state = &m->pen_state;
  1251.     ret = MMI_TRUE;
  1252.     *menu_event = GUI_LIST_PEN_NONE;
  1253.     if (gui_asyncdynamic_list_error)
  1254.     {
  1255.         return MMI_FALSE;
  1256.     }
  1257.     if (pen_event != MMI_PEN_EVENT_DOWN && pen_state->pen_on_scrollbar)
  1258.     {
  1259.         gui_vertical_scrollbar_translate_pen_event(&m->vbar, pen_event, x, y, &scrollbar_event, &scrollbar_param);
  1260.         if (scrollbar_event == GUI_SCROLLBAR_PEN_JUMP_TO_I)
  1261.         {
  1262.             if (m->pen_scroll_delay_time > 0)   /* Delay time for scrollbar scrolling */
  1263.             {
  1264.                 gui_asyncdynamic_list_start_scroll_timer(m, scrollbar_param._u.i);
  1265.             }
  1266.             else
  1267.             {
  1268.                 gui_asyncdynamic_list_menu_scroll_by_pen(m, scrollbar_param._u.i, menu_event);
  1269.             }
  1270.         }
  1271.     }
  1272.     else
  1273.     {
  1274.         switch (pen_event)
  1275.         {
  1276.             case MMI_PEN_EVENT_DOWN:
  1277.                 if (m->n_items <= 0)
  1278.                 {
  1279.                     /* In current design, scrollbar is hiden if m->n_items == 0 */
  1280.                     ret = MMI_FALSE;
  1281.                 }
  1282.                 else if (PEN_CHECK_BOUND(x, y, m->x, m->y, m->width, m->height))
  1283.                 {
  1284.                     pen_state->pen_on_scrollbar = 0;
  1285.                     if (!(m->flags & UI_LIST_MENU_DISABLE_SCROLLBAR) &&
  1286.                         gui_vertical_scrollbar_translate_pen_event(
  1287.                             &m->vbar,
  1288.                             MMI_PEN_EVENT_DOWN,
  1289.                             x,
  1290.                             y,
  1291.                             &scrollbar_event,
  1292.                             &scrollbar_param))
  1293.                     {
  1294.                         pen_state->pen_on_scrollbar = 1;
  1295.                         if (scrollbar_event == GUI_SCROLLBAR_PEN_JUMP_TO_I)
  1296.                         {
  1297.                             if (m->pen_scroll_delay_time > 0)   /* Delay time for scrollbar scrolling */
  1298.                             {
  1299.                                 gui_asyncdynamic_list_start_scroll_timer(m, scrollbar_param._u.i);
  1300.                             }
  1301.                             else
  1302.                             {
  1303.                                 gui_asyncdynamic_list_menu_scroll_by_pen(m, scrollbar_param._u.i, menu_event);
  1304.                             }
  1305.                         }
  1306.                     }
  1307.                     else
  1308.                     {
  1309.                         if (gui_asyncdynamic_list_menu_translate_pen_position(m, y, &item_index))
  1310.                         {
  1311.                             if (item_index != m->highlighted_item)
  1312.                             {
  1313.                                 gui_asyncdynamic_list_menu_goto_item(m, item_index);
  1314.                                 *menu_event = GUI_LIST_PEN_HIGHLIGHT_CHANGED;
  1315.                             }
  1316.                         }
  1317.                         else
  1318.                         {
  1319.                             /* # of menu items < # of displayable menu items */
  1320.                             ret = MMI_FALSE;
  1321.                         }
  1322.                     }
  1323.                     pen_state->first_highlighed_item = m->highlighted_item;
  1324.                     pen_state->highlight_changed = 0;
  1325.                 }
  1326.                 else
  1327.                 {
  1328.                     ret = MMI_FALSE;
  1329.                 }
  1330.                 break;
  1331.             case MMI_PEN_EVENT_LONG_TAP:
  1332.                 /* FALLTHROUGH no break */
  1333.             case MMI_PEN_EVENT_REPEAT:
  1334.                 /* FALLTHROUGH no break */
  1335.             case MMI_PEN_EVENT_MOVE:
  1336.                 gui_asyncdynamic_list_menu_translate_pen_position(m, y, &item_index);
  1337.                 if (item_index != m->highlighted_item)
  1338.                 {
  1339.                     gui_asyncdynamic_list_menu_goto_item(m, item_index);
  1340.                     *menu_event = GUI_LIST_PEN_HIGHLIGHT_CHANGED;
  1341.                 }
  1342.                 break;
  1343.             case MMI_PEN_EVENT_UP:
  1344.                 if (PEN_CHECK_BOUND(x, y, m->x, m->y, m->width, m->height))
  1345.                 {
  1346.                     gui_asyncdynamic_list_menu_translate_pen_position(m, y, &item_index);
  1347.                     if (item_index != m->highlighted_item)
  1348.                     {
  1349.                         /* If MMI_PEN_EVENT_MOVE is not delivered before moving to this item */
  1350.                         gui_asyncdynamic_list_menu_goto_item(m, item_index);
  1351.                         *menu_event = GUI_LIST_PEN_HIGHLIGHT_CHANGED;
  1352.                     }
  1353.                     else if (pen_state->highlight_changed)
  1354.                     {
  1355.                         *menu_event = GUI_LIST_PEN_NONE;
  1356.                     }
  1357.                     else
  1358.                     {
  1359.                         *menu_event = GUI_LIST_PEN_ITEM_SELECTED;
  1360.                     }
  1361.                 }
  1362.                 break;
  1363.             case MMI_PEN_EVENT_ABORT:
  1364.                 /* Do nothing */
  1365.                 break;
  1366.             default:
  1367.                 MMI_ASSERT(0);
  1368.         }
  1369.     }
  1370.     if (gui_asyncdynamic_list_error)
  1371.     {
  1372.         *menu_event = GUI_LIST_PEN_NONE;
  1373.         return MMI_FALSE;
  1374.     }
  1375.     if (ret)
  1376.     {
  1377.         if (pen_state->first_highlighed_item != m->highlighted_item)
  1378.         {
  1379.             pen_state->highlight_changed = 1;
  1380.         }
  1381.     }
  1382.     return ret;
  1383. }
  1384. #endif /* __MMI_TOUCH_SCREEN__ */