gui_panel.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.  *  gui_panel.c
  39.  *
  40.  * Project:
  41.  * --------
  42.  *  MAUI
  43.  *
  44.  * Description:
  45.  * ------------
  46.  *  Panel - UI component
  47.  *
  48.  * Author:
  49.  * -------
  50.  * -------
  51.  *
  52.  *============================================================================
  53.  *             HISTORY
  54.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  55.  *------------------------------------------------------------------------------
  56.  * removed!
  57.  *
  58.  * removed!
  59.  * removed!
  60.  * removed!
  61.  *
  62.  *------------------------------------------------------------------------------
  63.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  64.  *============================================================================
  65.  ****************************************************************************/
  66. #include "gui_panel.h"
  67. #include "DebugInitDef.h"
  68. #include "gdi_include.h"
  69. #include "GlobalConstants.h"
  70. /*****************************************************************************              
  71.  * Local Variable                                                                    
  72.  *****************************************************************************/
  73. /*****************************************************************************              
  74.  * Local Function                                                                    
  75.  *****************************************************************************/
  76. /*****************************************************************************
  77.  * FUNCTION
  78.  *  gui_panel_show_element
  79.  * DESCRIPTION
  80.  *  Draw a painter element
  81.  * PARAMETERS
  82.  *  panel                   [IN/OUT]    panel
  83.  *  element                 [IN]        panel element
  84.  *  state                   [IN]        state of panel element 
  85.  *  bg_is_already_drawn     [IN]        whether the panel background is already drawn.
  86.  * RETURNS
  87.  *  void
  88.  *****************************************************************************/
  89. static void gui_panel_show_element(
  90.                 gui_panel_struct *panel, 
  91.                 gui_panel_element_struct *element, 
  92.                 gui_panel_elem_state_enum state,
  93.                 MMI_BOOL bg_is_already_drawn)
  94. {
  95.     /*----------------------------------------------------------------*/
  96.     /* Local Variables                                                */
  97.     /*----------------------------------------------------------------*/
  98.     /*----------------------------------------------------------------*/
  99.     /* Code Body                                                      */
  100.     /*----------------------------------------------------------------*/
  101.     gui_lock_double_buffer();
  102.     if (!bg_is_already_drawn && element->redraw_bg_after_state_changed)
  103.     {
  104.         gui_util_painter_show_clipped(
  105.             &panel->background,
  106.             panel->x,
  107.             panel->y,
  108.             element->x1,
  109.             element->y1,
  110.             element->x2,
  111.             element->y2);
  112.     }
  113.     
  114.     gui_util_painter_show(
  115.         &element->painters[state],
  116.         element->x1,
  117.         element->y1,
  118.         element->x2,
  119.         element->y2);
  120.     gui_unlock_double_buffer();
  121.     gui_BLT_double_buffer(element->x1, element->y1, element->x2, element->y2);
  122. }
  123. /*****************************************************************************              
  124.  * Extern Global Function                                                                    
  125.  *****************************************************************************/
  126. /*****************************************************************************
  127.  * FUNCTION
  128.  *  gui_panel_create
  129.  * DESCRIPTION
  130.  *  Create a panel component
  131.  *
  132.  *  Note: the parameter 'display_focus' decides whether there is a focussed element.
  133.  *  For example, audio player has a focussed button (Play, Stop), but dialing screen
  134.  *  does not have a focussed button.
  135.  * PARAMETERS
  136.  *  panel                   [OUT]       panel
  137.  *  x                       [IN]        
  138.  *  y                       [IN]         
  139.  *  width                   [IN]
  140.  *  height                  [IN]
  141.  *  background              [IN]        panel background painter
  142.  *  display_focus           [IN]        whether to display focussed element differently
  143.  * RETURNS
  144.  *  void
  145.  *****************************************************************************/
  146. void gui_panel_create(
  147.         gui_panel_struct *panel,
  148.         S32 x, 
  149.         S32 y, 
  150.         S32 width, 
  151.         S32 height, 
  152.         gui_util_painter_struct background,
  153.         MMI_BOOL display_focus)
  154. {
  155.     /*----------------------------------------------------------------*/
  156.     /* Local Variables                                                */
  157.     /*----------------------------------------------------------------*/
  158.     /*----------------------------------------------------------------*/
  159.     /* Code Body                                                      */
  160.     /*----------------------------------------------------------------*/
  161.     memset(panel, 0, sizeof(gui_panel_struct));
  162.     panel->x = x;
  163.     panel->y = y;
  164.     panel->width = width;
  165.     panel->height = height;
  166.     panel->background = background;
  167.     panel->display_focus = display_focus ? 1 : 0;
  168. }
  169. /*****************************************************************************
  170.  * FUNCTION
  171.  *  gui_panel_show
  172.  * DESCRIPTION
  173.  *  Show a panel component
  174.  * PARAMETERS
  175.  *  panel           [IN/OUT]        panel
  176.  * RETURNS
  177.  *  void
  178.  *****************************************************************************/
  179. void gui_panel_show(gui_panel_struct *panel)
  180. {
  181.     /*----------------------------------------------------------------*/
  182.     /* Local Variables                                                */
  183.     /*----------------------------------------------------------------*/
  184.     S32 x1, y1, x2, y2;
  185.     S32 elem_idx;
  186.     /*----------------------------------------------------------------*/
  187.     /* Code Body                                                      */
  188.     /*----------------------------------------------------------------*/
  189.     x1 = panel->x;
  190.     y1 = panel->y;
  191.     x2 = panel->x + panel->width - 1;
  192.     y2 = panel->y + panel->height - 1;
  193.     
  194.     gui_lock_double_buffer();
  195.     
  196.     gui_util_painter_show(&panel->background, x1, y1, x2, y2);
  197.     for (elem_idx = 0; elem_idx < panel->element_count; elem_idx++)
  198.     {
  199.         gui_panel_element_struct *e = &panel->elements[elem_idx];
  200.         gui_panel_elem_state_enum state;
  201.         if (e->down_state)
  202.         {
  203.             state = GUI_PANEL_ELEM_STATE_DOWN;
  204.         }
  205.         else if (panel->display_focus && elem_idx == panel->element_focus_index)
  206.         {
  207.             state = GUI_PANEL_ELEM_STATE_FOCUSSED;
  208.         }
  209.         else
  210.         {
  211.             state = GUI_PANEL_ELEM_STATE_NORMAL;
  212.         }
  213.         
  214.         gui_util_painter_show(&e->painters[state], e->x1, e->y1, e->x2, e->y2);
  215.     }
  216.     gui_unlock_double_buffer();
  217.     gui_BLT_double_buffer(x1, y1, x2, y2);
  218. }
  219. /*****************************************************************************
  220.  * FUNCTION
  221.  *  gui_panel_set_element_focus
  222.  * DESCRIPTION
  223.  *  Set the foccused element
  224.  * PARAMETERS
  225.  *  panel                   [IN/OUT]    panel
  226.  *  element_index           [IN]        element index to be focussed
  227.  *  update_display          [IN]        whether to update the display
  228.  * RETURNS
  229.  *  void
  230.  *****************************************************************************/
  231. void gui_panel_set_element_focus(
  232.         gui_panel_struct *panel,
  233.         S32 element_index,
  234.         MMI_BOOL update_display)
  235. {
  236.     /*----------------------------------------------------------------*/
  237.     /* Local Variables                                                */
  238.     /*----------------------------------------------------------------*/
  239.     /*----------------------------------------------------------------*/
  240.     /* Code Body                                                      */
  241.     /*----------------------------------------------------------------*/
  242.     if (element_index >= 0 && element_index < panel->element_count &&
  243.         element_index != panel->element_focus_index)
  244.     {
  245.         if (update_display)
  246.         {
  247.             if (panel->display_focus)
  248.             {
  249.                 gui_panel_show_element(
  250.                     panel, 
  251.                     &panel->elements[panel->element_focus_index], 
  252.                     GUI_PANEL_ELEM_STATE_NORMAL,
  253.                     MMI_FALSE);
  254.             }
  255.             
  256.             gui_panel_show_element(
  257.                 panel, 
  258.                 &panel->elements[element_index], 
  259.                 panel->display_focus ? GUI_PANEL_ELEM_STATE_FOCUSSED : GUI_PANEL_ELEM_STATE_NORMAL,
  260.                 MMI_FALSE);
  261.         }
  262.         
  263.         panel->element_focus_index = element_index;
  264.     }
  265. }
  266. /*****************************************************************************
  267.  * FUNCTION
  268.  *  gui_panel_add_element
  269.  * DESCRIPTION
  270.  *  Set the foccused element
  271.  * 
  272.  *  Note: If 'redraw_bg_after_state_changed' is 1, it typically has worse performance.
  273.  *  It is usually used when painter is partially-transparent.
  274.  *  If art designer can create images carefully (put the background into element image), then
  275.  *  we can set redraw_bg_after_state_changed as 0.
  276.  * PARAMETERS
  277.  *  panel                           [IN/OUT]    panel
  278.  *  x                               [IN]        x
  279.  *  y                               [IN]        y
  280.  *  width                           [IN]        width
  281.  *  height                          [IN]        height
  282.  *  keycode                         [IN]        registered key event (KEY_INVALID if no key event registered)
  283.  *  up_event_callback               [IN]        callback when key/pen up
  284.  *  repeat_event_callback           [IN]        callback when key repeat or pen stays on element
  285.  *  normal_painter                  [IN]        painter when up 
  286.  *  down_painter                    [IN]        painter when down
  287.  *  focussed_painter                [IN]        painter when focussed. Only used when panel->display_focus is 1.
  288.  *  redraw_bg_after_state_changed   [IN]        redrawn panel background when pressed/released/focussed/unfocussed
  289.  * RETURNS
  290.  *  The element index. -1 if failed
  291.  *****************************************************************************/
  292. S32 gui_panel_add_element(
  293.         gui_panel_struct *panel,
  294.         S32 x,
  295.         S32 y,
  296.         S32 width,
  297.         S32 height,
  298.         U16 keycode,
  299.         FuncPtr up_event_callback,
  300.         FuncPtr repeat_event_callback,
  301.         gui_util_painter_struct normal_painter,
  302.         gui_util_painter_struct down_painter,
  303.         gui_util_painter_struct focussed_painter,
  304.         MMI_BOOL redraw_bg_after_state_changed)
  305. {
  306.     /*----------------------------------------------------------------*/
  307.     /* Local Variables                                                */
  308.     /*----------------------------------------------------------------*/
  309.     gui_panel_element_struct *e;
  310.     /*----------------------------------------------------------------*/
  311.     /* Code Body                                                      */
  312.     /*----------------------------------------------------------------*/
  313.     if (panel->element_count == GUI_PANEL_MAX_ELEMENT_COUNT)
  314.     {
  315.         MMI_DBG_ASSERT(0);
  316.         return -1;
  317.     }
  318.     e = &panel->elements[panel->element_count];
  319.     e->x1 = x;
  320.     e->y1 = y;
  321.     e->x2 = x + width - 1;
  322.     e->y2 = y + height - 1;
  323.     e->keycode = keycode;
  324.     e->up_event_callback = up_event_callback ? up_event_callback : UI_dummy_function;
  325.     e->repeat_event_callback = repeat_event_callback ? repeat_event_callback : UI_dummy_function;
  326.     e->painters[GUI_PANEL_ELEM_STATE_NORMAL] = normal_painter;
  327.     e->painters[GUI_PANEL_ELEM_STATE_DOWN] = down_painter;
  328.     e->painters[GUI_PANEL_ELEM_STATE_FOCUSSED] = focussed_painter;
  329.     e->down_state = 0;
  330.     e->redraw_bg_after_state_changed = redraw_bg_after_state_changed ? 1 : 0;
  331.     return panel->element_count++;
  332. }
  333. /*****************************************************************************
  334.  * FUNCTION
  335.  *  gui_panel_general_key_handler
  336.  * DESCRIPTION
  337.  *  General key handler for panel elements
  338.  * PARAMETERS
  339.  *  panel                   [IN/OUT]    panel
  340.  *  keycode                 [IN]        key code
  341.  *  state                   [IN]        key type
  342.  * RETURNS
  343.  *  void
  344.  *****************************************************************************/
  345. void gui_panel_general_key_handler(gui_panel_struct *panel, U16 keycode, U16 keytype)
  346. {
  347.     /*----------------------------------------------------------------*/
  348.     /* Local Variables                                                */
  349.     /*----------------------------------------------------------------*/
  350.     S32 i;
  351.     /*----------------------------------------------------------------*/
  352.     /* Code Body                                                      */
  353.     /*----------------------------------------------------------------*/
  354.     for (i = 0; i < panel->element_count; i++)
  355.     {
  356.         gui_panel_element_struct *e = &panel->elements[i];
  357.         if (e->keycode == keycode)
  358.         {
  359.         
  360.             switch (keytype)
  361.             {
  362.                 case KEY_EVENT_DOWN:
  363.                     if (panel->element_focus_index != i && panel->display_focus)
  364.                     {
  365.                         gui_panel_show_element(
  366.                             panel, 
  367.                             &panel->elements[panel->element_focus_index], 
  368.                             GUI_PANEL_ELEM_STATE_NORMAL,
  369.                             MMI_FALSE);
  370.                     }
  371.                     panel->element_focus_index = i;
  372.                     gui_panel_show_element(
  373.                         panel, 
  374.                         e, 
  375.                         GUI_PANEL_ELEM_STATE_DOWN,
  376.                         MMI_FALSE);
  377.                     e->down_state = 1;
  378.                     break;
  379.                     
  380.                 case KEY_EVENT_UP:
  381.                     gui_panel_show_element(
  382.                         panel, 
  383.                         e, 
  384.                         panel->display_focus ? GUI_PANEL_ELEM_STATE_FOCUSSED : GUI_PANEL_ELEM_STATE_NORMAL,
  385.                         MMI_FALSE);
  386.                     e->down_state = 0;
  387.                     /* Invoke callback */
  388.                     e->up_event_callback();
  389.                     break;
  390.                     
  391.                 case KEY_LONG_PRESS:
  392.                     /* FALLTHROUGH no break */
  393.                 case KEY_REPEAT:
  394.                     /* Invoke callback */
  395.                     e->repeat_event_callback();
  396.                     break;
  397.                     
  398.                 default:
  399.                     break;
  400.             }
  401.             
  402.             break;
  403.         }
  404.     }
  405. }