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

MTK

开发平台:

C/C++

  1. /*******************************************************************************
  2. *  Modification Notice:
  3. *  --------------------------
  4. *  This software is modified by MediaTek Inc. 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_buttons.c
  39.  *
  40.  * Project:
  41.  * --------
  42.  *  Maui_Software
  43.  *
  44.  * Description:
  45.  * ------------
  46.  *  UI component - buttons
  47.  *  
  48.  *  o Button
  49.  *  o Icon button
  50.  *  o Text button
  51.  *  o Icontext button
  52.  *
  53.  * Author:
  54.  * -------
  55.  * -------
  56.  *
  57.  *============================================================================
  58.  *             HISTORY
  59.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  60.  *------------------------------------------------------------------------------
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  *******************************************************************************/
  92. /**
  93.  * Copyright Notice
  94.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  95.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  96.  *  (It is illegal to remove this copyright notice from this software or any
  97.  *  portion of it)
  98.  */
  99. #include "gui_buttons.h"
  100. #include "MMI_features.h"
  101. #include "BIDIDEF.h"
  102. #include "BIDIProt.h"
  103. #include "UCS2Prot.h"
  104. #include "DebugInitDef.h"
  105. #ifdef __MMI_IDLE_FULL_SCREEN__
  106. extern U16 on_idle_screen;
  107. #endif 
  108. extern BOOL r2lMMIFlag;
  109. #ifdef __MMI_MATRIX_MAIN_MENU_FULL_BACKGROUND__
  110. extern BOOL inMatrixNoTitleFlag;
  111. #endif 
  112. #ifdef __MMI_UI_DALMATIAN_SOFTKEYS__
  113. extern U8 is_button_bar_shuffled;
  114. extern void gui_call_shuffle(void);
  115. #endif /* __MMI_UI_DALMATIAN_SOFTKEYS__ */ 
  116. UI_button_theme *current_button_theme = NULL;
  117. extern S32 UI_get_font_height(UI_font_type f);
  118. /***************************************************************************** 
  119.  * Simple Button (filler only)
  120.  *****************************************************************************/
  121. /*****************************************************************************
  122.  * FUNCTION
  123.  *  gui_set_button_current_theme
  124.  * DESCRIPTION
  125.  *  Applies the current theme for a button
  126.  * PARAMETERS
  127.  *  b       [IN]        Is the button to use
  128.  * RETURNS
  129.  *  void
  130.  *****************************************************************************/
  131. void gui_set_button_current_theme(button *b)
  132. {
  133.     /* set the theme of button when the state of button is up */
  134.     /*----------------------------------------------------------------*/
  135.     /* Local Variables                                                */
  136.     /*----------------------------------------------------------------*/
  137.     /*----------------------------------------------------------------*/
  138.     /* Code Body                                                      */
  139.     /*----------------------------------------------------------------*/
  140.     b->normal_up_filler = current_button_theme->normal_up_filler;
  141.     /* set the theme of button when the state of button is down */
  142.     b->normal_down_filler = current_button_theme->normal_down_filler;
  143.     /* set the theme of button when the  button is disabled */
  144.     b->disabled_up_filler = current_button_theme->disabled_up_filler;
  145.     b->disabled_down_filler = current_button_theme->disabled_down_filler;
  146.     /* set the theme of button when the  button is focussed */
  147.     b->focussed_up_filler = current_button_theme->focussed_up_filler;
  148.     b->focussed_down_filler = current_button_theme->focussed_down_filler;
  149.     b->clicked_up_filler = current_button_theme->clicked_up_filler;
  150.     b->clicked_down_filler = current_button_theme->clicked_down_filler;
  151. }
  152. /*****************************************************************************
  153.  * FUNCTION
  154.  *  gui_set_button_theme
  155.  * DESCRIPTION
  156.  *  Applies the given theme to a button
  157.  * PARAMETERS
  158.  *  b       [IN]        Is the button to use
  159.  *  t       [IN]        Is the button theme to use
  160.  * RETURNS
  161.  *  void
  162.  *****************************************************************************/
  163. void gui_set_button_theme(button *b, UI_button_theme *t)
  164. {
  165.     /*----------------------------------------------------------------*/
  166.     /* Local Variables                                                */
  167.     /*----------------------------------------------------------------*/
  168.     /*----------------------------------------------------------------*/
  169.     /* Code Body                                                      */
  170.     /*----------------------------------------------------------------*/
  171.     b->normal_up_filler = t->normal_up_filler;
  172.     b->normal_down_filler = t->normal_down_filler;
  173.     b->disabled_up_filler = t->disabled_up_filler;
  174.     b->disabled_down_filler = t->disabled_down_filler;
  175.     b->focussed_up_filler = t->focussed_up_filler;
  176.     b->focussed_down_filler = t->focussed_down_filler;
  177.     b->clicked_up_filler = t->clicked_up_filler;
  178.     b->clicked_down_filler = t->clicked_down_filler;
  179. }
  180. /*****************************************************************************
  181.  * FUNCTION
  182.  *  gui_create_button
  183.  * DESCRIPTION
  184.  *  Creates a button
  185.  *  
  186.  *  Note: Memory must be allocated to the button structure before
  187.  *  being passed to this function.
  188.  * PARAMETERS
  189.  *  b           [IN]        Is the button  (pre-allocated)
  190.  *  x           [IN]        Is the position of the left-top corner of the button
  191.  *  y           [IN]        Is the position of the left-top corner of the button
  192.  *  width       [IN]        Is the width of the button
  193.  *  height      [IN]        Is the height of the button
  194.  * RETURNS
  195.  *  void
  196.  *****************************************************************************/
  197. void gui_create_button(button *b, S32 x, S32 y, S32 width, S32 height)
  198. {
  199.     /*----------------------------------------------------------------*/
  200.     /* Local Variables                                                */
  201.     /*----------------------------------------------------------------*/
  202.     /*----------------------------------------------------------------*/
  203.     /* Code Body                                                      */
  204.     /*----------------------------------------------------------------*/
  205.     b->x = x;                           /* start x position of button */
  206.     b->y = y;                           /* start y position of button */
  207.     b->width = width;                   /* width of button */
  208.     b->height = height;                 /* height of button */
  209.     b->flags = 0;
  210.     b->clear_background_fp = NULL;
  211.     
  212.     gui_set_button_current_theme(b);    /* set the theme of button to current theme */
  213. }
  214. /*****************************************************************************
  215.  * FUNCTION
  216.  *  gui_show_button
  217.  * DESCRIPTION
  218.  *  Displays a button
  219.  * PARAMETERS
  220.  *  b       [IN]        Is the button
  221.  * RETURNS
  222.  *  void
  223.  *****************************************************************************/
  224. void gui_show_button(button *b)
  225. {
  226.     /*----------------------------------------------------------------*/
  227.     /* Local Variables                                                */
  228.     /*----------------------------------------------------------------*/
  229.     S32 x1, y1, x2, y2;
  230.     UI_filled_area *f;
  231.     /*----------------------------------------------------------------*/
  232.     /* Code Body                                                      */
  233.     /*----------------------------------------------------------------*/
  234.     x1 = b->x;                  /* start x position of button */
  235.     y1 = b->y;                  /* start y position of button */
  236.     x2 = x1 + b->width - 1;     /* end x position of button */
  237.     y2 = y1 + b->height - 1;    /* end y position of button */
  238.     if (b->flags & UI_BUTTON_STATE_CLICKED)
  239.     {
  240.     #ifndef __MMI_UI_DALMATIAN_SOFTKEYS__
  241.         if (b->flags & UI_BUTTON_STATE_DOWN)
  242.         {
  243.     if (b->flags & UI_BUTTON_NO_SHIFT_BUTTON)
  244.     {
  245.         /* No action */
  246.     }
  247.             else if (b->flags & UI_BUTTON_SHIFT_BUTTON2)
  248.             {
  249.                 x1 += 2;
  250.                 y1 += 2;
  251.                 x2 += 2;
  252.                 y2 += 2;
  253.             }
  254.             else if (b->flags & UI_BUTTON_SHIFT_BUTTON1)
  255.             {
  256.                 x1 += 1;
  257.                 y1 += 1;
  258.                 x2 += 1;
  259.                 y2 += 1;
  260.             }
  261.             f = b->clicked_down_filler;
  262.         }
  263.         else
  264.     #endif /* __MMI_UI_DALMATIAN_SOFTKEYS__ */ 
  265.         {
  266.             f = b->clicked_up_filler;
  267.         }
  268.     }
  269.     else if (b->flags & UI_BUTTON_STATE_FOCUSSED)
  270.     {
  271.         if (b->flags & UI_BUTTON_STATE_DOWN)
  272.         {
  273.             f = b->focussed_down_filler;
  274.         }
  275.         else
  276.         {
  277.             f = b->focussed_up_filler;
  278.         }
  279.     }
  280.     else if (b->flags & UI_BUTTON_STATE_DISABLED)
  281.     {
  282.         if (b->flags & UI_BUTTON_STATE_DOWN)
  283.         {
  284.             f = b->disabled_down_filler;
  285.         }
  286.         else
  287.         {
  288.             f = b->disabled_up_filler;
  289.         }
  290.     }
  291.     else
  292.     {
  293.         if (b->flags & UI_BUTTON_STATE_DOWN)
  294.         {
  295.             f = b->normal_down_filler;
  296.         }
  297.         else
  298.         {
  299.             f = b->normal_up_filler;
  300.         }
  301.     }
  302.     
  303.     gui_push_clip();
  304.     gui_set_clip(x1, y1, x2 + 2, y2 + 2);
  305.     gui_draw_filled_area(x1, y1, x2, y2, f);    /* fill the area with color */
  306.     gui_pop_clip();
  307. }
  308. /***************************************************************************** 
  309.  * Text Button
  310.  *****************************************************************************/
  311. UI_text_button_theme *current_text_button_theme = NULL;
  312. /*****************************************************************************
  313.  * FUNCTION
  314.  *  gui_set_text_button_current_theme
  315.  * DESCRIPTION
  316.  *  Applies the current theme for a text button
  317.  * PARAMETERS
  318.  *  b       [IN]        Is the text button to use
  319.  * RETURNS
  320.  *  void
  321.  *****************************************************************************/
  322. void gui_set_text_button_current_theme(text_button *b)
  323. {
  324.     /*----------------------------------------------------------------*/
  325.     /* Local Variables                                                */
  326.     /*----------------------------------------------------------------*/
  327.     /*----------------------------------------------------------------*/
  328.     /* Code Body                                                      */
  329.     /*----------------------------------------------------------------*/
  330.     b->normal_up_filler = current_button_theme->normal_up_filler;
  331.     b->normal_down_filler = current_button_theme->normal_down_filler;
  332.     b->disabled_up_filler = current_button_theme->disabled_up_filler;
  333.     b->disabled_down_filler = current_button_theme->disabled_down_filler;
  334.     b->focussed_up_filler = current_button_theme->focussed_up_filler;
  335.     b->focussed_down_filler = current_button_theme->focussed_down_filler;
  336.     b->clicked_up_filler = current_button_theme->clicked_up_filler;
  337.     b->clicked_down_filler = current_button_theme->clicked_down_filler;
  338.     b->normal_up_text_color = current_text_button_theme->normal_up_text_color;
  339.     b->normal_down_text_color = current_text_button_theme->normal_down_text_color;
  340.     b->disabled_up_text_color = current_text_button_theme->disabled_up_text_color;
  341.     b->disabled_down_text_color = current_text_button_theme->disabled_down_text_color;
  342.     b->focussed_up_text_color = current_text_button_theme->focussed_up_text_color;
  343.     b->focussed_down_text_color = current_text_button_theme->focussed_down_text_color;
  344.     b->clicked_up_text_color = current_text_button_theme->clicked_up_text_color;
  345.     b->clicked_down_text_color = current_text_button_theme->clicked_down_text_color;
  346.     b->text_font = current_text_button_theme->text_font;
  347.     b->flags |= current_text_button_theme->flags;
  348. }
  349. /*****************************************************************************
  350.  * FUNCTION
  351.  *  gui_set_text_button_theme
  352.  * DESCRIPTION
  353.  *  Applies the given theme to a text button
  354.  * PARAMETERS
  355.  *  b       [IN]        Is the text button to use
  356.  *  t       [IN]        Button theme
  357.  * RETURNS
  358.  *  void
  359.  *****************************************************************************/
  360. void gui_set_text_button_theme(text_button *b, UI_text_button_theme *t)
  361. {
  362.     /*----------------------------------------------------------------*/
  363.     /* Local Variables                                                */
  364.     /*----------------------------------------------------------------*/
  365.     /*----------------------------------------------------------------*/
  366.     /* Code Body                                                      */
  367.     /*----------------------------------------------------------------*/
  368.     b->normal_up_filler = current_button_theme->normal_up_filler;
  369.     b->normal_down_filler = current_button_theme->normal_down_filler;
  370.     b->disabled_up_filler = current_button_theme->disabled_up_filler;
  371.     b->disabled_down_filler = current_button_theme->disabled_down_filler;
  372.     b->focussed_up_filler = current_button_theme->focussed_up_filler;
  373.     b->focussed_down_filler = current_button_theme->focussed_down_filler;
  374.     b->clicked_up_filler = current_button_theme->clicked_up_filler;
  375.     b->clicked_down_filler = current_button_theme->clicked_down_filler;
  376.     b->normal_up_text_color = t->normal_up_text_color;
  377.     b->normal_down_text_color = t->normal_down_text_color;
  378.     b->disabled_up_text_color = t->disabled_up_text_color;
  379.     b->disabled_down_text_color = t->disabled_down_text_color;
  380.     b->focussed_up_text_color = t->focussed_up_text_color;
  381.     b->focussed_down_text_color = t->focussed_down_text_color;
  382.     b->clicked_up_text_color = t->clicked_up_text_color;
  383.     b->clicked_down_text_color = t->clicked_down_text_color;
  384.     b->text_font = t->text_font;
  385.     b->flags |= t->flags;
  386. }
  387. /*****************************************************************************
  388.  * FUNCTION
  389.  *  gui_set_text_button_BG_theme
  390.  * DESCRIPTION
  391.  *  Applies the given button theme to a text button
  392.  * PARAMETERS
  393.  *  b       [IN]        Is the text button to use
  394.  *  t       [IN]        Is the button theme (Note: This is not a text button theme)
  395.  * RETURNS
  396.  *  void
  397.  *****************************************************************************/
  398. void gui_set_text_button_BG_theme(text_button *b, UI_button_theme *t)
  399. {
  400.     /*----------------------------------------------------------------*/
  401.     /* Local Variables                                                */
  402.     /*----------------------------------------------------------------*/
  403.     /*----------------------------------------------------------------*/
  404.     /* Code Body                                                      */
  405.     /*----------------------------------------------------------------*/
  406.     b->normal_up_filler = t->normal_up_filler;
  407.     b->normal_down_filler = t->normal_down_filler;
  408.     b->disabled_up_filler = t->disabled_up_filler;
  409.     b->disabled_down_filler = t->disabled_down_filler;
  410.     b->focussed_up_filler = t->focussed_up_filler;
  411.     b->focussed_down_filler = t->focussed_down_filler;
  412.     b->clicked_up_filler = t->clicked_up_filler;
  413.     b->clicked_down_filler = t->clicked_down_filler;
  414. }
  415. /*****************************************************************************
  416.  * FUNCTION
  417.  *  gui_create_text_button
  418.  * DESCRIPTION
  419.  *  Creates a text button
  420.  *  
  421.  *  Note: Memory must be allocated to the button structure before
  422.  *  being passed to this function.
  423.  * PARAMETERS
  424.  *  b           [IN]        Is the text button
  425.  *  x           [IN]        Is the position of the left-top corner of the button
  426.  *  y           [IN]        Is the position of the left-top corner of the button
  427.  *  width       [IN]        Is the width of the button
  428.  *  height      [IN]        Is the height of the button
  429.  *  text        [IN]        
  430.  * RETURNS
  431.  *  void
  432.  *****************************************************************************/
  433. void gui_create_text_button(text_button *b, S32 x, S32 y, S32 width, S32 height, UI_string_type text)
  434. {
  435.     /*----------------------------------------------------------------*/
  436.     /* Local Variables                                                */
  437.     /*----------------------------------------------------------------*/
  438.     S32 sw, sh;
  439.     /*----------------------------------------------------------------*/
  440.     /* Code Body                                                      */
  441.     /*----------------------------------------------------------------*/
  442.     b->x = x;                               /* start x position of button */
  443.     b->y = y;                               /* start y position of button */
  444.     b->width = width;                       /* width of button */
  445.     b->height = height;                     /* height of button */
  446.     b->flags = 0;
  447.     b->text = text;                         /* text of button */
  448.     b->clear_background_fp = NULL;
  449.     
  450.     gui_set_text_button_current_theme(b);   /* set the theme of button equal to current theme */
  451.     
  452.     /* Autocalculate the text position based on font   */
  453.     gui_set_font(b->text_font);             /* set font of text button */
  454.     gui_measure_string(text, &sw, &sh);     /* measure width and height of string */
  455.     b->text_height = sh;                    /* text height of button */
  456.     if (b->flags & UI_BUTTON_CENTER_TEXT_X)
  457.     {
  458.         b->text_x = (width >> 1) - (sw >> 1);   /* start x position of text of button */
  459.         if (b->text_x < 0)
  460.         {
  461.             if (r2lMMIFlag)
  462.             {
  463.                 b->text_x = width - sw;
  464.             }
  465.             else
  466.             {
  467.                 b->text_x = 0;
  468.             }
  469.         }
  470.     }
  471.     else
  472.     {
  473.         b->text_x = 0;  /* start x position of text of button */
  474.     }
  475.     if (b->flags & UI_BUTTON_CENTER_TEXT_Y)
  476.     {
  477.         b->text_y = (height >> 1) - (sh >> 1);  /* start y position of text of button */
  478.     }
  479.     else
  480.     {
  481.         b->text_y = 0;  /* start y position of text of button */
  482.     }
  483. }
  484. /*****************************************************************************
  485.  * FUNCTION
  486.  *  gui_text_button_set_text_position
  487.  * DESCRIPTION
  488.  *  Changes the position of the text in the text button
  489.  * PARAMETERS
  490.  *  b       [IN]        Is the text button
  491.  *  x       [IN]        Is the position text (Offset from the left-top corner of the button)
  492.  *  y       [IN]        Is the position text (Offset from the left-top corner of the button)
  493.  * RETURNS
  494.  *  void
  495.  *****************************************************************************/
  496. void gui_text_button_set_text_position(text_button *b, S32 x, S32 y)
  497. {
  498.     /*----------------------------------------------------------------*/
  499.     /* Local Variables                                                */
  500.     /*----------------------------------------------------------------*/
  501.     /*----------------------------------------------------------------*/
  502.     /* Code Body                                                      */
  503.     /*----------------------------------------------------------------*/
  504.     b->x = x;
  505.     b->y = y;
  506. }
  507. /*****************************************************************************
  508.  * FUNCTION
  509.  *  gui_show_text_button
  510.  * DESCRIPTION
  511.  *  Displays the text button
  512.  * PARAMETERS
  513.  *  b       [IN]        Is the text button
  514.  * RETURNS
  515.  *  void
  516.  *****************************************************************************/
  517. void gui_show_text_button(text_button *b)
  518. {
  519.     /*----------------------------------------------------------------*/
  520.     /* Local Variables                                                */
  521.     /*----------------------------------------------------------------*/
  522.     S32 x1, y1, x2, y2;
  523.     S32 text_x, text_y;
  524.     color text_color;
  525.     UI_filled_area *f;
  526.     S32 w;
  527.     /*----------------------------------------------------------------*/
  528.     /* Code Body                                                      */
  529.     /*----------------------------------------------------------------*/
  530.     x1 = b->x;                  /* start x position of button */
  531.     y1 = b->y;                  /* start y position of button */
  532.     x2 = x1 + b->width - 1;     /* end x position of button */
  533.     y2 = y1 + b->height - 1;    /* end y position of button */
  534.     text_x = b->text_x;         /* start x position of texr */
  535.     text_y = b->text_y;         /* start y position of text */
  536.     if (b->flags & UI_BUTTON_STATE_CLICKED)
  537.     {
  538.         if (b->flags & UI_BUTTON_STATE_DOWN)
  539.         {
  540.             if (b->flags & UI_BUTTON_NO_SHIFT_BUTTON)
  541.             {
  542.                 /* No action */
  543.             }
  544.             else if (b->flags & UI_BUTTON_SHIFT_BUTTON2)
  545.             {
  546.                 x1 += 2;
  547.                 y1 += 2;
  548.                 x2 += 2;
  549.                 y2 += 2;
  550.             }
  551.             else if (b->flags & UI_BUTTON_SHIFT_BUTTON1)
  552.             {
  553.                 x1 += 1;
  554.                 y1 += 1;
  555.                 x2 += 1;
  556.                 y2 += 1;
  557.             }
  558.             f = b->clicked_down_filler;
  559.             text_color = b->clicked_down_text_color;    /* set the text color if button is clicked */
  560.         }
  561.         else
  562.         {
  563.             f = b->clicked_up_filler;
  564.             text_color = b->clicked_up_text_color;  /* set the text color if button is up */
  565.         }
  566.     }
  567.     else if (b->flags & UI_BUTTON_STATE_FOCUSSED)
  568.     {
  569.         if (b->flags & UI_BUTTON_STATE_DOWN)
  570.         {
  571.             f = b->focussed_down_filler;
  572.             text_color = b->focussed_down_text_color;
  573.         }
  574.         else
  575.         {
  576.             f = b->focussed_up_filler;
  577.             text_color = b->focussed_up_text_color;
  578.         }
  579.     }
  580.     else if (b->flags & UI_BUTTON_STATE_DISABLED)
  581.     {
  582.         if (b->flags & UI_BUTTON_STATE_DOWN)
  583.         {
  584.             f = b->disabled_down_filler;
  585.             text_color = b->disabled_down_text_color;   /* color of text when button is disabled */
  586.         }
  587.         else
  588.         {
  589.             f = b->disabled_up_filler;
  590.             text_color = b->disabled_up_text_color;
  591.         }
  592.     }
  593.     else
  594.     {
  595.         if (b->flags & UI_BUTTON_STATE_DOWN)
  596.         {
  597.             f = b->normal_down_filler;
  598.             text_color = b->normal_down_text_color;
  599.         }
  600.         else
  601.         {
  602.             f = b->normal_up_filler;
  603.             text_color = b->normal_up_text_color;
  604.         }
  605.     }
  606.     
  607.     if ((b->flags & UI_BUTTON_SHIFT_TEXT) && (b->flags & UI_BUTTON_STATE_DOWN))
  608.     {
  609.         text_x += 1;
  610.         text_y += 1;
  611.     }
  612.     
  613.     gui_push_clip();
  614.     gui_set_clip(x1, y1, x2 + 2, y2 + 2);
  615.     gui_draw_filled_area(x1, y1, x2, y2, f);
  616.     gui_push_text_clip();
  617.     gui_set_text_clip(x1, y1, x2, y2);
  618.     w = gui_get_string_width((UI_string_type) b->text);
  619.     if (r2lMMIFlag)
  620.     {
  621.         gui_move_text_cursor(x1 + text_x + w, y1 + text_y); /* move cursor to x,y position */
  622.     }
  623.     else
  624.     {
  625.         gui_move_text_cursor(x1 + text_x, y1 + text_y); /* move cursor to x,y position */
  626.     }
  627.     gui_set_text_color(text_color); /* set color of text */
  628.     gui_set_font(b->text_font);     /* set text font */
  629.     gui_set_line_height(b->text_height);
  630.     gui_print_text(b->text);        /* print text */
  631.     gui_pop_text_clip();
  632.     gui_pop_clip();
  633. }
  634. /***************************************************************************** 
  635.  * Icon Button
  636.  *****************************************************************************/
  637. UI_icon_button_theme *current_icon_button_theme = NULL;
  638. /*****************************************************************************
  639.  * FUNCTION
  640.  *  gui_set_icon_button_current_theme
  641.  * DESCRIPTION
  642.  *  Applies the current theme for an icon button
  643.  * PARAMETERS
  644.  *  b       [IN]        Is the icon button
  645.  * RETURNS
  646.  *  void
  647.  *****************************************************************************/
  648. void gui_set_icon_button_current_theme(icon_button *b)
  649. {
  650.     /*----------------------------------------------------------------*/
  651.     /* Local Variables                                                */
  652.     /*----------------------------------------------------------------*/
  653.     /*----------------------------------------------------------------*/
  654.     /* Code Body                                                      */
  655.     /*----------------------------------------------------------------*/
  656.     b->normal_up_filler = current_icon_button_theme->normal_up_filler;
  657.     b->normal_down_filler = current_icon_button_theme->normal_down_filler;
  658.     b->disabled_up_filler = current_icon_button_theme->disabled_up_filler;
  659.     b->disabled_down_filler = current_icon_button_theme->disabled_down_filler;
  660.     b->focussed_up_filler = current_icon_button_theme->focussed_up_filler;
  661.     b->focussed_down_filler = current_icon_button_theme->focussed_down_filler;
  662.     b->clicked_up_filler = current_icon_button_theme->clicked_up_filler;
  663.     b->clicked_down_filler = current_icon_button_theme->clicked_down_filler;
  664.     b->flags |= current_icon_button_theme->flags;
  665. }
  666. /*****************************************************************************
  667.  * FUNCTION
  668.  *  gui_set_icon_button_theme
  669.  * DESCRIPTION
  670.  *  Applies the given theme to an icon button
  671.  * PARAMETERS
  672.  *  b       [IN]        Is the icon button
  673.  *  t       [IN]        Is the theme to be applied
  674.  * RETURNS
  675.  *  void
  676.  *****************************************************************************/
  677. void gui_set_icon_button_theme(icon_button *b, UI_icon_button_theme *t)
  678. {
  679.     /*----------------------------------------------------------------*/
  680.     /* Local Variables                                                */
  681.     /*----------------------------------------------------------------*/
  682.     /*----------------------------------------------------------------*/
  683.     /* Code Body                                                      */
  684.     /*----------------------------------------------------------------*/
  685.     b->normal_up_filler = t->normal_up_filler;
  686.     b->normal_down_filler = t->normal_down_filler;
  687.     b->disabled_up_filler = t->disabled_up_filler;
  688.     b->disabled_down_filler = t->disabled_down_filler;
  689.     b->focussed_up_filler = t->focussed_up_filler;
  690.     b->focussed_down_filler = t->focussed_down_filler;
  691.     b->clicked_up_filler = t->clicked_up_filler;
  692.     b->clicked_down_filler = t->clicked_down_filler;
  693.     b->flags |= t->flags;
  694. }
  695. /*****************************************************************************
  696.  * FUNCTION
  697.  *  gui_set_icon_button_BG_theme
  698.  * DESCRIPTION
  699.  *  Applies the given button theme to an icon button
  700.  * PARAMETERS
  701.  *  b       [IN]        Is the icon button
  702.  *  t       [IN]        Is the button theme to be applied
  703.  * RETURNS
  704.  *  void
  705.  *****************************************************************************/
  706. void gui_set_icon_button_BG_theme(icon_button *b, UI_button_theme *t)
  707. {
  708.     /*----------------------------------------------------------------*/
  709.     /* Local Variables                                                */
  710.     /*----------------------------------------------------------------*/
  711.     /*----------------------------------------------------------------*/
  712.     /* Code Body                                                      */
  713.     /*----------------------------------------------------------------*/
  714.     b->normal_up_filler = t->normal_up_filler;
  715.     b->normal_down_filler = t->normal_down_filler;
  716.     b->disabled_up_filler = t->disabled_up_filler;
  717.     b->disabled_down_filler = t->disabled_down_filler;
  718.     b->focussed_up_filler = t->focussed_up_filler;
  719.     b->focussed_down_filler = t->focussed_down_filler;
  720.     b->clicked_up_filler = t->clicked_up_filler;
  721.     b->clicked_down_filler = t->clicked_down_filler;
  722. }
  723. /*****************************************************************************
  724.  * FUNCTION
  725.  *  gui_create_icon_button
  726.  * DESCRIPTION
  727.  *  Creates an icon button
  728.  *  
  729.  *  Note: Memory must be allocated to the button structure before
  730.  *  being passed to this function.
  731.  *  See PU8 (Abstract type) for the icon
  732.  * PARAMETERS
  733.  *  b               [IN]        Is the icon button   (pre-allocated)
  734.  *  x               [IN]        Is the position of the left-top corner of the button
  735.  *  y               [IN]        Is the position of the left-top corner of the button
  736.  *  width           [IN]        Is the width of the button
  737.  *  height          [IN]        Is the height of the button
  738.  *  button_icon     [IN]        Is the icon to be used in the button
  739.  * RETURNS
  740.  *  void
  741.  *****************************************************************************/
  742. void gui_create_icon_button(icon_button *b, S32 x, S32 y, S32 width, S32 height, PU8 button_icon)
  743. {
  744.     /*----------------------------------------------------------------*/
  745.     /* Local Variables                                                */
  746.     /*----------------------------------------------------------------*/
  747.     /*----------------------------------------------------------------*/
  748.     /* Code Body                                                      */
  749.     /*----------------------------------------------------------------*/
  750.     b->x = x;           /* start x position of icon button */
  751.     b->y = y;           /* start y position of icon button */
  752.     b->width = width;   /* width of icon button */
  753.     b->height = height; /* height of icon button */
  754.     b->flags = 0;
  755.     b->normal_down_icon = button_icon;
  756.     b->normal_up_icon = button_icon;
  757.     b->disabled_down_icon = button_icon;
  758.     b->disabled_up_icon = button_icon;
  759.     b->clicked_down_icon = button_icon;
  760.     b->clicked_up_icon = button_icon;
  761.     b->focussed_down_icon = button_icon;
  762.     b->focussed_up_icon = button_icon;
  763.     b->clear_background_fp = NULL;
  764.     
  765.     gui_set_icon_button_current_theme(b);
  766.     
  767.     /* Autocalculate the icon position */
  768.     if (button_icon != UI_NULL_IMAGE)
  769.     {
  770.         S32 icon_width, icon_height;
  771.         gui_measure_image(button_icon, &icon_width, &icon_height);
  772.         if (b->flags & UI_BUTTON_CENTER_ICON_X)
  773.         {
  774.             b->icon_x = (width >> 1) - (icon_width >> 1);
  775.         }
  776.         else
  777.         {
  778.             b->icon_x = 0;
  779.         }
  780.         if (b->flags & UI_BUTTON_CENTER_ICON_Y)
  781.         {
  782.             b->icon_y = (height >> 1) - (icon_height >> 1);
  783.         }
  784.         else
  785.         {
  786.             b->icon_y = 0;
  787.         }
  788.         b->icon_transparent_color = gui_transparent_color(0, 0, 0);
  789.     }
  790. }
  791. /*****************************************************************************
  792.  * FUNCTION
  793.  *  gui_resize_icon_button
  794.  * DESCRIPTION
  795.  *  Changes the size of an icon button
  796.  * PARAMETERS
  797.  *  b           [IN]        Is the icon button
  798.  *  width       [IN]        Is the new width of the button
  799.  *  height      [IN]        Is the new height of the button
  800.  * RETURNS
  801.  *  void
  802.  *****************************************************************************/
  803. void gui_resize_icon_button(icon_button *b, S32 width, S32 height)
  804. {
  805.     /*----------------------------------------------------------------*/
  806.     /* Local Variables                                                */
  807.     /*----------------------------------------------------------------*/
  808.     /*----------------------------------------------------------------*/
  809.     /* Code Body                                                      */
  810.     /*----------------------------------------------------------------*/
  811.     b->width = width;   /* width of button */
  812.     b->height = height; /* height of button */
  813.     /* Autocalculate the icon position              */
  814.     if (b->normal_up_icon != UI_NULL_IMAGE)
  815.     {
  816.         S32 icon_width, icon_height;
  817.         /* measure width and height of icon */
  818.         gui_measure_image(b->normal_up_icon, &icon_width, &icon_height);
  819.         /* set start x and start y positon of icon */
  820.         if (b->flags & UI_BUTTON_CENTER_ICON_X)
  821.         {
  822.             b->icon_x = (width >> 1) - (icon_width >> 1);
  823.         }
  824.         else
  825.         {
  826.             b->icon_x = 0;
  827.         }
  828.         if (b->flags & UI_BUTTON_CENTER_ICON_Y)
  829.         {
  830.             b->icon_y = (height >> 1) - (icon_height >> 1);
  831.         }
  832.         else
  833.         {
  834.             b->icon_y = 0;
  835.         }
  836.         b->icon_transparent_color = gui_transparent_color(0, 0, 0);
  837.     }
  838. }
  839. /*****************************************************************************
  840.  * FUNCTION
  841.  *  gui_move_icon_button
  842.  * DESCRIPTION
  843.  *  Changes the location of an icon button
  844.  * PARAMETERS
  845.  *  b       [IN]        Is the icon button
  846.  *  x       [IN]        Is the new location
  847.  *  y       [IN]        Is the new location
  848.  * RETURNS
  849.  *  void
  850.  *****************************************************************************/
  851. void gui_move_icon_button(icon_button *b, S32 x, S32 y)
  852. {
  853.     /*----------------------------------------------------------------*/
  854.     /* Local Variables                                                */
  855.     /*----------------------------------------------------------------*/
  856.     /*----------------------------------------------------------------*/
  857.     /* Code Body                                                      */
  858.     /*----------------------------------------------------------------*/
  859.     b->x = x;
  860.     b->y = y;
  861. }
  862. /*****************************************************************************
  863.  * FUNCTION
  864.  *  gui_icon_button_set_icon_positon
  865.  * DESCRIPTION
  866.  *  Changes the position of the icon within the icon button
  867.  * PARAMETERS
  868.  *  b       [IN]        Is the icon button
  869.  *  x       [IN]        Is the position of the icon (offset from the left-top corner of the button)
  870.  *  y       [IN]        Is the position of the icon (offset from the left-top corner of the button)
  871.  * RETURNS
  872.  *  void
  873.  *****************************************************************************/
  874. void gui_icon_button_set_icon_positon(icon_button *b, S32 x, S32 y)
  875. {
  876.     /*----------------------------------------------------------------*/
  877.     /* Local Variables                                                */
  878.     /*----------------------------------------------------------------*/
  879.     /*----------------------------------------------------------------*/
  880.     /* Code Body                                                      */
  881.     /*----------------------------------------------------------------*/
  882.     b->icon_x = x;
  883.     b->icon_y = y;
  884. }
  885. /*****************************************************************************
  886.  * FUNCTION
  887.  *  gui_icon_button_set_icon
  888.  * DESCRIPTION
  889.  *  Changes the icon used in the icon button
  890.  *  
  891.  *  See UI_transparent_color_type (Abstract type)
  892.  * PARAMETERS
  893.  *  b                           [IN]        Is the icon button
  894.  *  button_icon                 [IN]        
  895.  *  icon_transparent_color      [IN]        Is the transparent color to use
  896.  * RETURNS
  897.  *  void
  898.  *****************************************************************************/
  899. void gui_icon_button_set_icon(icon_button *b, PU8 button_icon, UI_transparent_color_type icon_transparent_color)
  900. {
  901.     /*----------------------------------------------------------------*/
  902.     /* Local Variables                                                */
  903.     /*----------------------------------------------------------------*/
  904.     /*----------------------------------------------------------------*/
  905.     /* Code Body                                                      */
  906.     /*----------------------------------------------------------------*/
  907.     b->normal_down_icon = button_icon;
  908.     b->normal_up_icon = button_icon;
  909.     b->disabled_down_icon = button_icon;
  910.     b->disabled_up_icon = button_icon;
  911.     b->clicked_down_icon = button_icon;
  912.     b->clicked_up_icon = button_icon;
  913.     b->focussed_down_icon = button_icon;
  914.     b->focussed_up_icon = button_icon;
  915.     b->icon_transparent_color = icon_transparent_color;
  916.     
  917.     /* Autocalculate the icon position              */
  918.     if (button_icon != UI_NULL_IMAGE)
  919.     {
  920.         S32 icon_width, icon_height;
  921.         gui_measure_image(button_icon, &icon_width, &icon_height);
  922.         if (b->flags & UI_BUTTON_CENTER_ICON_X)
  923.         {
  924.             b->icon_x = (b->width >> 1) - (icon_width >> 1);
  925.         }
  926.         else
  927.         {
  928.             b->icon_x = 0;
  929.         }
  930.         if (b->flags & UI_BUTTON_CENTER_ICON_Y)
  931.         {
  932.             b->icon_y = (b->height >> 1) - (icon_height >> 1);
  933.         }
  934.         else
  935.         {
  936.             b->icon_y = 0;
  937.         }
  938.         b->icon_transparent_color = gui_transparent_color(0, 0, 0);
  939.     }
  940. }
  941. /*****************************************************************************
  942.  * FUNCTION
  943.  *  gui_show_icon_button
  944.  * DESCRIPTION
  945.  *  Displays an icon button
  946.  * PARAMETERS
  947.  *  b       [IN]        Is the icon button
  948.  * RETURNS
  949.  *  void
  950.  *****************************************************************************/
  951. void gui_show_icon_button(icon_button *b)
  952. {
  953.     /*----------------------------------------------------------------*/
  954.     /* Local Variables                                                */
  955.     /*----------------------------------------------------------------*/
  956.     S32 x1, y1, x2, y2;
  957.     UI_filled_area *f;
  958.     PU8 button_icon;
  959.     /*----------------------------------------------------------------*/
  960.     /* Code Body                                                      */
  961.     /*----------------------------------------------------------------*/
  962.     x1 = b->x;
  963.     y1 = b->y;
  964.     x2 = x1 + b->width - 1;
  965.     y2 = y1 + b->height - 1;
  966.     if (b->flags & UI_BUTTON_STATE_CLICKED)
  967.     {
  968.         if (b->flags & UI_BUTTON_STATE_DOWN)
  969.         {
  970.             if (b->flags & UI_BUTTON_NO_SHIFT_BUTTON)
  971.             {
  972.                 /* No action */
  973.             }
  974.             else if (b->flags & UI_BUTTON_SHIFT_BUTTON2)
  975.             {
  976.                 x1 += 2;
  977.                 y1 += 2;
  978.                 x2 += 2;
  979.                 y2 += 2;
  980.             }
  981.             else if (b->flags & UI_BUTTON_SHIFT_BUTTON1)
  982.             {
  983.                 x1 += 1;
  984.                 y1 += 1;
  985.                 x2 += 1;
  986.                 y2 += 1;
  987.             }
  988.             f = b->clicked_down_filler;
  989.             button_icon = b->clicked_down_icon;
  990.         }
  991.         else
  992.         {
  993.             f = b->clicked_up_filler;
  994.             button_icon = b->clicked_up_icon;
  995.         }
  996.     }
  997.     else if (b->flags & UI_BUTTON_STATE_FOCUSSED)   /* if button is focused */
  998.     {
  999.         if (b->flags & UI_BUTTON_STATE_DOWN)
  1000.         {
  1001.             f = b->focussed_down_filler;
  1002.             button_icon = b->focussed_down_icon;
  1003.         }
  1004.         else
  1005.         {
  1006.             f = b->focussed_up_filler;
  1007.             button_icon = b->focussed_up_icon;
  1008.         }
  1009.     }
  1010.     else if (b->flags & UI_BUTTON_STATE_DISABLED)   /* if flag of button is disabled */
  1011.     {
  1012.         if (b->flags & UI_BUTTON_STATE_DOWN)
  1013.         {
  1014.             f = b->disabled_down_filler;
  1015.             button_icon = b->disabled_down_icon;
  1016.         }
  1017.         else
  1018.         {
  1019.             f = b->disabled_up_filler;
  1020.             button_icon = b->disabled_up_icon;
  1021.         }
  1022.     }
  1023.     else
  1024.     {
  1025.         if (b->flags & UI_BUTTON_STATE_DOWN)    /* if button is down */
  1026.         {
  1027.             f = b->normal_down_filler;
  1028.             button_icon = b->normal_down_icon;
  1029.         }
  1030.         else
  1031.         {
  1032.             f = b->normal_up_filler;
  1033.             button_icon = b->normal_up_icon;
  1034.         }
  1035.     }
  1036.     
  1037.     gui_push_clip();
  1038.     gui_set_clip(x1, y1, x2 + 2, y2 + 2);
  1039.     /* fill the buton with color */
  1040.     gui_draw_filled_area(x1, y1, x2, y2, f);
  1041.     if (button_icon != UI_NULL_IMAGE)
  1042.     {
  1043.         gui_show_transparent_image(x1 + b->icon_x, y1 + b->icon_y, button_icon, b->icon_transparent_color);
  1044.     }
  1045.     gui_pop_clip();
  1046. }
  1047. /***************************************************************************** 
  1048.  * IconText Button
  1049.  *****************************************************************************/
  1050. UI_icontext_button_theme *current_icontext_button_theme = NULL;
  1051. /*****************************************************************************
  1052.  * FUNCTION
  1053.  *  gui_set_icontext_button_current_theme
  1054.  * DESCRIPTION
  1055.  *  Applies the current theme for an icontext button
  1056.  * PARAMETERS
  1057.  *  b       [IN]        Is the icontext button
  1058.  * RETURNS
  1059.  *  void
  1060.  *****************************************************************************/
  1061. void gui_set_icontext_button_current_theme(icontext_button *b)
  1062. {
  1063.     /*----------------------------------------------------------------*/
  1064.     /* Local Variables                                                */
  1065.     /*----------------------------------------------------------------*/
  1066.     /*----------------------------------------------------------------*/
  1067.     /* Code Body                                                      */
  1068.     /*----------------------------------------------------------------*/
  1069.     b->normal_up_filler = current_icontext_button_theme->normal_up_filler;
  1070.     b->normal_down_filler = current_icontext_button_theme->normal_down_filler;
  1071.     b->disabled_up_filler = current_icontext_button_theme->disabled_up_filler;
  1072.     b->disabled_down_filler = current_icontext_button_theme->disabled_down_filler;
  1073.     b->focussed_up_filler = current_icontext_button_theme->focussed_up_filler;
  1074.     b->focussed_down_filler = current_icontext_button_theme->focussed_down_filler;
  1075.     b->clicked_up_filler = current_icontext_button_theme->clicked_up_filler;
  1076.     b->clicked_down_filler = current_icontext_button_theme->clicked_down_filler;
  1077.     b->normal_up_text_color = current_icontext_button_theme->normal_up_text_color;
  1078.     b->normal_down_text_color = current_icontext_button_theme->normal_down_text_color;
  1079.     b->disabled_up_text_color = current_icontext_button_theme->disabled_up_text_color;
  1080.     b->disabled_down_text_color = current_icontext_button_theme->disabled_down_text_color;
  1081.     b->focussed_up_text_color = current_icontext_button_theme->focussed_up_text_color;
  1082.     b->focussed_down_text_color = current_icontext_button_theme->focussed_down_text_color;
  1083.     b->clicked_up_text_color = current_icontext_button_theme->clicked_up_text_color;
  1084.     b->clicked_down_text_color = current_icontext_button_theme->clicked_down_text_color;
  1085.     b->text_font = current_icontext_button_theme->text_font;
  1086.     b->flags |= current_icontext_button_theme->flags;
  1087. }
  1088. /*****************************************************************************
  1089.  * FUNCTION
  1090.  *  gui_set_icontext_button_theme
  1091.  * DESCRIPTION
  1092.  *  Applies the given theme to an icontext button
  1093.  * PARAMETERS
  1094.  *  b       [IN]        Is the icontext button
  1095.  *  t       [IN]        Is the theme to be applied
  1096.  * RETURNS
  1097.  *  void
  1098.  *****************************************************************************/
  1099. void gui_set_icontext_button_theme(icontext_button *b, UI_icontext_button_theme *t)
  1100. {
  1101.     /*----------------------------------------------------------------*/
  1102.     /* Local Variables                                                */
  1103.     /*----------------------------------------------------------------*/
  1104.     /*----------------------------------------------------------------*/
  1105.     /* Code Body                                                      */
  1106.     /*----------------------------------------------------------------*/
  1107.     b->normal_up_filler = t->normal_up_filler;
  1108.     b->normal_down_filler = t->normal_down_filler;
  1109.     b->disabled_up_filler = t->disabled_up_filler;
  1110.     b->disabled_down_filler = t->disabled_down_filler;
  1111.     b->focussed_up_filler = t->focussed_up_filler;
  1112.     b->focussed_down_filler = t->focussed_down_filler;
  1113.     b->clicked_up_filler = t->clicked_up_filler;
  1114.     b->clicked_down_filler = t->clicked_down_filler;
  1115.     b->normal_up_text_color = t->normal_up_text_color;
  1116.     b->normal_down_text_color = t->normal_down_text_color;
  1117.     b->disabled_up_text_color = t->disabled_up_text_color;
  1118.     b->disabled_down_text_color = t->disabled_down_text_color;
  1119.     b->focussed_up_text_color = t->focussed_up_text_color;
  1120.     b->focussed_down_text_color = t->focussed_down_text_color;
  1121.     b->clicked_up_text_color = t->clicked_up_text_color;
  1122.     b->clicked_down_text_color = t->clicked_down_text_color;
  1123.     b->text_font = t->text_font;
  1124.     b->flags |= t->flags;
  1125. }
  1126. /*****************************************************************************
  1127.  * FUNCTION
  1128.  *  gui_set_icontext_button_BG_theme
  1129.  * DESCRIPTION
  1130.  *  Applies the given button theme to an icontext button
  1131.  * PARAMETERS
  1132.  *  b       [IN]        Is the icontext button
  1133.  *  t       [IN]        Is the button theme to be applied
  1134.  * RETURNS
  1135.  *  void
  1136.  *****************************************************************************/
  1137. void gui_set_icontext_button_BG_theme(icontext_button *b, UI_button_theme *t)
  1138. {
  1139.     /*----------------------------------------------------------------*/
  1140.     /* Local Variables                                                */
  1141.     /*----------------------------------------------------------------*/
  1142.     /*----------------------------------------------------------------*/
  1143.     /* Code Body                                                      */
  1144.     /*----------------------------------------------------------------*/
  1145.     b->normal_up_filler = t->normal_up_filler;
  1146.     b->normal_down_filler = t->normal_down_filler;
  1147.     b->disabled_up_filler = t->disabled_up_filler;
  1148.     b->disabled_down_filler = t->disabled_down_filler;
  1149.     b->focussed_up_filler = t->focussed_up_filler;
  1150.     b->focussed_down_filler = t->focussed_down_filler;
  1151.     b->clicked_up_filler = t->clicked_up_filler;
  1152.     b->clicked_down_filler = t->clicked_down_filler;
  1153. }
  1154. /*****************************************************************************
  1155.  * FUNCTION
  1156.  *  gui_create_icontext_button
  1157.  * DESCRIPTION
  1158.  *  Creates an icontext button
  1159.  *  
  1160.  *  Note: Memory must be allocated to the button structure before
  1161.  *  being passed to this function.
  1162.  * PARAMETERS
  1163.  *  b               [IN]        Is the icontext button  (pre-allocated)
  1164.  *  x               [IN]        Is the position of the left-top corner of the button
  1165.  *  y               [IN]        Is the position of the left-top corner of the button
  1166.  *  width           [IN]        Is the width of the button
  1167.  *  height          [IN]        Is the height of the button
  1168.  *  text            [IN]        
  1169.  *  button_icon     [IN]        Is the icon to be used in the button
  1170.  * RETURNS
  1171.  *  void
  1172.  *****************************************************************************/
  1173. void gui_create_icontext_button(
  1174.         icontext_button *b,
  1175.         S32 x,
  1176.         S32 y,
  1177.         S32 width,
  1178.         S32 height,
  1179.         UI_string_type text,
  1180.         PU8 button_icon)
  1181. {
  1182.     /*----------------------------------------------------------------*/
  1183.     /* Local Variables                                                */
  1184.     /*----------------------------------------------------------------*/
  1185.     S32 sw, sh;
  1186.     /*----------------------------------------------------------------*/
  1187.     /* Code Body                                                      */
  1188.     /*----------------------------------------------------------------*/
  1189.     b->x = x;
  1190.     b->y = y;
  1191.     b->width = width;
  1192.     b->height = height;
  1193.     b->flags = 0;
  1194.     b->normal_down_icon = button_icon;
  1195.     b->normal_up_icon = button_icon;
  1196.     b->disabled_down_icon = button_icon;
  1197.     b->disabled_up_icon = button_icon;
  1198.     b->clicked_down_icon = button_icon;
  1199.     b->clicked_up_icon = button_icon;
  1200.     b->focussed_down_icon = button_icon;
  1201.     b->focussed_up_icon = button_icon;
  1202.     b->text = text;
  1203.     b->clear_background_fp = NULL;
  1204.     
  1205.     /* set the theme of button eqaul to current theme */
  1206.     gui_set_icontext_button_current_theme(b);
  1207.     /* Autocalculate the icon position              */
  1208.     /* set font of text of button */
  1209.     gui_set_font(b->text_font);
  1210.     /* measure width and height of text */
  1211.     gui_measure_string(text, &sw, &sh);
  1212.     /* if button icon is not null */
  1213.     if (button_icon != UI_NULL_IMAGE)
  1214.     {
  1215.         S32 icon_width, icon_height;
  1216.         /* measure width and height of icon of button */
  1217.         gui_measure_image(button_icon, &icon_width, &icon_height);
  1218.         /* set x and y position of button icon */
  1219.         if (b->flags & UI_BUTTON_CENTER_ICON_X)
  1220.         {
  1221.             b->icon_x = (width >> 1) - (icon_width >> 1);
  1222.         }
  1223.         else
  1224.         {
  1225.             b->icon_x = 0;
  1226.         }
  1227.         if (b->flags & UI_BUTTON_CENTER_ICON_Y)
  1228.         {
  1229.             b->icon_y = (height >> 1) - (icon_height >> 1);
  1230.         }
  1231.         else
  1232.         {
  1233.             b->icon_y = 0;
  1234.         }
  1235.         b->icon_transparent_color = gui_transparent_color(0, 0, 0);
  1236.     }
  1237.     /* Autocalculate the text position based on font   */
  1238.     b->text_height = sh;
  1239.     /* set start x and y of text position of button */
  1240.     if (b->flags & UI_BUTTON_CENTER_TEXT_X)
  1241.     {
  1242.         b->text_x = (width >> 1) - (sw >> 1);
  1243.         if (b->text_x < 0)
  1244.         {
  1245.             if (r2lMMIFlag)
  1246.             {
  1247.                 b->text_x = width - sw;
  1248.             }
  1249.             else
  1250.             {
  1251.                 b->text_x = 0;
  1252.             }
  1253.         }
  1254.     }
  1255.     else
  1256.     {
  1257.         b->text_x = 0;
  1258.     }
  1259.     if (b->flags & UI_BUTTON_CENTER_TEXT_Y)
  1260.     {
  1261.         b->text_y = (height >> 1) - (sh >> 1);
  1262.     }
  1263.     else
  1264.     {
  1265.         b->text_y = 0;
  1266.     }
  1267. }
  1268. /*****************************************************************************
  1269.  * FUNCTION
  1270.  *  gui_resize_icontext_button
  1271.  * DESCRIPTION
  1272.  *  Changes the size of an icontext button
  1273.  * PARAMETERS
  1274.  *  b           [IN]        Is the icon button
  1275.  *  width       [IN]        Is the new width of the button
  1276.  *  height      [IN]        Is the new height of the button
  1277.  * RETURNS
  1278.  *  void
  1279.  *****************************************************************************/
  1280. void gui_resize_icontext_button(icontext_button *b, S32 width, S32 height)
  1281. {
  1282.     /*----------------------------------------------------------------*/
  1283.     /* Local Variables                                                */
  1284.     /*----------------------------------------------------------------*/
  1285.     S32 sw, sh;
  1286.     UI_font_type f = UI_font;
  1287.     /*----------------------------------------------------------------*/
  1288.     /* Code Body                                                      */
  1289.     /*----------------------------------------------------------------*/
  1290.     b->width = width;   /* width of button */
  1291.     b->height = height; /* height of button */
  1292.     
  1293.     /* Autocalculate the icon position              */
  1294.     if (b->normal_up_icon != UI_NULL_IMAGE)
  1295.     {
  1296.         S32 icon_width, icon_height;
  1297.         /* measure width and height of button icon */
  1298.         gui_measure_image(b->normal_up_icon, &icon_width, &icon_height);
  1299.         /* set x and y position of button icon */
  1300.         if (b->flags & UI_BUTTON_CENTER_ICON_X)
  1301.         {
  1302.             b->icon_x = (width >> 1) - (icon_width >> 1);
  1303.         }
  1304.         else
  1305.         {
  1306.             b->icon_x = 2;
  1307.         }
  1308.         if (b->flags & UI_BUTTON_CENTER_ICON_Y)
  1309.         {
  1310.             b->icon_y = (height >> 1) - (icon_height >> 1);
  1311.         }
  1312.         else
  1313.         {
  1314.             b->icon_y = 2;
  1315.         }
  1316.         b->icon_transparent_color = gui_transparent_color(0, 0, 0);
  1317.     }
  1318.     
  1319.     /* Autocalculate the text position based on font   */
  1320.     gui_set_font(b->text_font);             /* set font of text */
  1321.     gui_measure_string(b->text, &sw, &sh);  /* measure width and height of string */
  1322.     b->text_height = sh;
  1323.     b->text_width = sw;
  1324.     
  1325.     /* set start x and y position of text */
  1326.     if (b->flags & UI_BUTTON_CENTER_TEXT_X)
  1327.     {
  1328.         b->text_x = (width >> 1) - (sw >> 1);
  1329.     #ifdef __MMI_UI_DALMATIAN_SOFTKEYS__
  1330.         /* To center alline the text on buttons specially for dalmatian. */
  1331.         if (width > (UI_device_width >> 1))
  1332.         {
  1333.             if (b->clicked_down_filler->flags & UI_FILLED_AREA_LEFT_ROUNDED_BORDER)
  1334.             {
  1335.                 b->text_x += (width - (UI_device_width >> 1)) >> 1;
  1336.             }
  1337.             if (b->clicked_down_filler->flags & UI_FILLED_AREA_RIGHT_ROUNDED_BORDER)
  1338.             {
  1339.                 b->text_x -= (width - (UI_device_width >> 1)) >> 1;
  1340.             }
  1341.         }
  1342.     #endif /* __MMI_UI_DALMATIAN_SOFTKEYS__ */ 
  1343.         if (b->text_x < 0)
  1344.         {
  1345.             if (r2lMMIFlag)
  1346.             {
  1347.                 b->text_x = width - sw;
  1348.             }
  1349.             else
  1350.             {
  1351.                 b->text_x = 0;
  1352.             }
  1353.         }
  1354.     }
  1355.     else if (b->flags & UI_BUTTON_LEFT_ALIGN)
  1356.     {
  1357.         b->text_x = 2;
  1358.     }
  1359.     else if (b->flags & UI_BUTTON_RIGHT_ALIGN)
  1360.     {
  1361.         b->text_x = width - sw - 2;
  1362.     }
  1363.     else
  1364.     {
  1365.         b->text_x = 0;
  1366.     }
  1367.     
  1368.     if (b->flags & UI_BUTTON_CENTER_TEXT_Y)
  1369.     {
  1370.         /* Adjust the string position -- move down */
  1371.         b->text_y = 2 + ((height - 2) >> 1) - (sh >> 1);
  1372.     #ifdef __MMI_UI_DALMATIAN_SOFTKEYS__
  1373.         /* To adjust the string position for Dalmatian */
  1374.         b->text_y = ((height) >> 1) - (sh >> 1);
  1375.     #endif /* __MMI_UI_DALMATIAN_SOFTKEYS__ */ 
  1376.     }
  1377.     else
  1378.     {
  1379.         b->text_y = 0;
  1380.     }
  1381.     
  1382.     gui_set_font(f);
  1383. }
  1384. /*****************************************************************************
  1385.  * FUNCTION
  1386.  *  gui_move_icontext_button
  1387.  * DESCRIPTION
  1388.  *  Changes the location of an icon button
  1389.  * PARAMETERS
  1390.  *  b       [IN]        Is the icon button
  1391.  *  x       [IN]        Is the new location
  1392.  *  y       [IN]        Is the new location
  1393.  * RETURNS
  1394.  *  void
  1395.  *****************************************************************************/
  1396. void gui_move_icontext_button(icontext_button *b, S32 x, S32 y)
  1397. {
  1398.     /*----------------------------------------------------------------*/
  1399.     /* Local Variables                                                */
  1400.     /*----------------------------------------------------------------*/
  1401.     /*----------------------------------------------------------------*/
  1402.     /* Code Body                                                      */
  1403.     /*----------------------------------------------------------------*/
  1404.     b->x = x;
  1405.     b->y = y;
  1406. }
  1407. /*****************************************************************************
  1408.  * FUNCTION
  1409.  *  gui_icontext_button_set_icon_positon
  1410.  * DESCRIPTION
  1411.  *  Changes the position of the icon within the icontext button
  1412.  * PARAMETERS
  1413.  *  b       [IN]        Is the icontext button
  1414.  *  x       [IN]        Is the position of the icon (offset from the left-top corner of the button)
  1415.  *  y       [IN]        Is the position of the icon (offset from the left-top corner of the button)
  1416.  * RETURNS
  1417.  *  void
  1418.  *****************************************************************************/
  1419. void gui_icontext_button_set_icon_positon(icontext_button *b, S32 x, S32 y)
  1420. {
  1421.     /*----------------------------------------------------------------*/
  1422.     /* Local Variables                                                */
  1423.     /*----------------------------------------------------------------*/
  1424.     /*----------------------------------------------------------------*/
  1425.     /* Code Body                                                      */
  1426.     /*----------------------------------------------------------------*/
  1427.     b->icon_x = x;
  1428.     b->icon_y = y;
  1429. }
  1430. /*****************************************************************************
  1431.  * FUNCTION
  1432.  *  gui_icontext_button_set_text_position
  1433.  * DESCRIPTION
  1434.  *  Changes the position of the text within the icontext button
  1435.  * PARAMETERS
  1436.  *  b       [IN]        Is the icontext button
  1437.  *  x       [IN]        Is the position of the icon (offset from the left-top corner of the button)
  1438.  *  y       [IN]        Is the position of the icon (offset from the left-top corner of the button)
  1439.  * RETURNS
  1440.  *  void
  1441.  *****************************************************************************/
  1442. void gui_icontext_button_set_text_position(icontext_button *b, S32 x, S32 y)
  1443. {
  1444.     /*----------------------------------------------------------------*/
  1445.     /* Local Variables                                                */
  1446.     /*----------------------------------------------------------------*/
  1447.     /*----------------------------------------------------------------*/
  1448.     /* Code Body                                                      */
  1449.     /*----------------------------------------------------------------*/
  1450.     b->text_x = x;
  1451.     b->text_y = y;
  1452. }
  1453. /*****************************************************************************
  1454.  * FUNCTION
  1455.  *  gui_icontext_button_set_icon
  1456.  * DESCRIPTION
  1457.  *  Changes the icon used in the icontext button
  1458.  *  
  1459.  *  See UI_transparent_color_type (Abstract type)
  1460.  * PARAMETERS
  1461.  *  b                           [IN]        Is the icontext button
  1462.  *  button_icon                 [IN]        
  1463.  *  icon_transparent_color      [IN]        Is the transparent color to use
  1464.  * RETURNS
  1465.  *  void
  1466.  *****************************************************************************/
  1467. void gui_icontext_button_set_icon(
  1468.         icontext_button *b,
  1469.         PU8 button_icon,
  1470.         UI_transparent_color_type icon_transparent_color)
  1471. {
  1472.     /*----------------------------------------------------------------*/
  1473.     /* Local Variables                                                */
  1474.     /*----------------------------------------------------------------*/
  1475.     /*----------------------------------------------------------------*/
  1476.     /* Code Body                                                      */
  1477.     /*----------------------------------------------------------------*/
  1478.     b->normal_down_icon = button_icon;
  1479.     b->normal_up_icon = button_icon;
  1480.     b->disabled_down_icon = button_icon;
  1481.     b->disabled_up_icon = button_icon;
  1482.     b->clicked_down_icon = button_icon;
  1483.     b->clicked_up_icon = button_icon;
  1484.     b->focussed_down_icon = button_icon;
  1485.     b->focussed_up_icon = button_icon;
  1486.     b->icon_transparent_color = icon_transparent_color;
  1487.     
  1488.     /* Autocalculate the icon position              */
  1489.     if (button_icon != UI_NULL_IMAGE)
  1490.     {
  1491.         S32 icon_width, icon_height;
  1492.         /* measure width and height of icon */
  1493.         gui_measure_image(button_icon, &icon_width, &icon_height);
  1494.         /* set x and y position of icon */
  1495.         if (b->flags & UI_BUTTON_CENTER_ICON_X)
  1496.         {
  1497.             b->icon_x = (b->width >> 1) - (icon_width >> 1);
  1498.         }
  1499.         else
  1500.         {
  1501.             b->icon_x = 2;
  1502.         }
  1503.         if (b->flags & UI_BUTTON_CENTER_ICON_Y)
  1504.         {
  1505.             b->icon_y = (b->height >> 1) - (icon_height >> 1);
  1506.         }
  1507.         else
  1508.         {
  1509.             b->icon_y = 2;
  1510.         }
  1511.         b->icon_transparent_color = gui_transparent_color(0, 0, 0);
  1512.     }
  1513. }
  1514. /*****************************************************************************
  1515.  * FUNCTION
  1516.  *  gui_show_icontext_button
  1517.  * DESCRIPTION
  1518.  *  Displays an icontext button
  1519.  * PARAMETERS
  1520.  *  b       [IN]        Is the icontext button
  1521.  * RETURNS
  1522.  *  void
  1523.  *****************************************************************************/
  1524. extern MMI_theme *current_MMI_theme;
  1525. void gui_show_icontext_button(icontext_button *b)
  1526. {
  1527.     /*----------------------------------------------------------------*/
  1528.     /* Local Variables                                                */
  1529.     /*----------------------------------------------------------------*/
  1530.     S32 x1, y1, x2, y2;
  1531.     UI_filled_area *f;
  1532.     color text_color;
  1533.     PU8 button_icon;
  1534.     S32 ix, iy, tx, ty;
  1535.     S32 iwidth, iheight;
  1536.     UI_font_type font = UI_font;
  1537.     extern const color MMI_white_color; /* ={255,255,255,100}; */
  1538.     /*----------------------------------------------------------------*/
  1539.     /* Code Body                                                      */
  1540.     /*----------------------------------------------------------------*/
  1541.     x1 = b->x;                  /* start x position of button */
  1542.     y1 = b->y;                  /* satrt y position of button */
  1543.     x2 = x1 + b->width - 1;     /* end x position of button */
  1544.     y2 = y1 + b->height - 1;    /* end y position of button */
  1545.     if (b->flags & UI_BUTTON_STATE_CLICKED)
  1546.     {
  1547.     #ifndef __MMI_UI_DALMATIAN_SOFTKEYS__
  1548.         if (b->flags & UI_BUTTON_STATE_DOWN)
  1549.         {
  1550.             if (b->flags & UI_BUTTON_NO_SHIFT_BUTTON)
  1551.             {
  1552.                 /* No action */
  1553.             }
  1554.             else if (b->flags & UI_BUTTON_SHIFT_BUTTON2)
  1555.             {
  1556.                 x1 += 2;
  1557.                 y1 += 2;
  1558.                 x2 += 2;
  1559.                 y2 += 2;
  1560.             }
  1561.             else if (b->flags & UI_BUTTON_SHIFT_BUTTON1)
  1562.             {
  1563.                 x1 += 1;
  1564.                 y1 += 1;
  1565.                 x2 += 1;
  1566.                 y2 += 1;
  1567.             }
  1568.             f = b->clicked_down_filler;
  1569.             text_color = b->clicked_down_text_color;
  1570.             button_icon = b->clicked_down_icon;
  1571.         }
  1572.         else
  1573.     #endif /* __MMI_UI_DALMATIAN_SOFTKEYS__ */ 
  1574.         {
  1575.             f = b->clicked_up_filler;
  1576.             text_color = b->clicked_up_text_color;
  1577.             button_icon = b->clicked_up_icon;
  1578.         }
  1579.     }
  1580.     else if (b->flags & UI_BUTTON_STATE_FOCUSSED)
  1581.     {
  1582.     #ifndef __MMI_UI_DALMATIAN_SOFTKEYS__
  1583.         if (b->flags & UI_BUTTON_STATE_DOWN)
  1584.         {
  1585.             f = b->focussed_down_filler;
  1586.             text_color = b->focussed_down_text_color;
  1587.             button_icon = b->focussed_down_icon;
  1588.         }
  1589.         else
  1590.     #endif /* __MMI_UI_DALMATIAN_SOFTKEYS__ */ 
  1591.         {
  1592.             f = b->focussed_up_filler;
  1593.             text_color = b->focussed_up_text_color;
  1594.             button_icon = b->focussed_up_icon;
  1595.         }
  1596.     }
  1597.     else if (b->flags & UI_BUTTON_STATE_DISABLED)
  1598.     {
  1599.     #ifndef __MMI_UI_DALMATIAN_SOFTKEYS__
  1600.         if (b->flags & UI_BUTTON_STATE_DOWN)
  1601.         {
  1602.             f = b->disabled_down_filler;
  1603.             text_color = b->disabled_down_text_color;
  1604.             button_icon = b->disabled_down_icon;
  1605.         }
  1606.         else
  1607.     #endif /* __MMI_UI_DALMATIAN_SOFTKEYS__ */ 
  1608.         {
  1609.             f = b->disabled_up_filler;
  1610.             text_color = b->disabled_up_text_color; /* set text color */
  1611.             button_icon = b->disabled_up_icon;
  1612.         }
  1613.     }
  1614.     else
  1615.     {
  1616.     #ifndef __MMI_UI_DALMATIAN_SOFTKEYS__
  1617.         if (b->flags & UI_BUTTON_STATE_DOWN)
  1618.         {
  1619.             f = b->normal_down_filler;
  1620.             text_color = b->normal_down_text_color;
  1621.             button_icon = b->normal_down_icon;
  1622.         }
  1623.         else
  1624.     #endif /* __MMI_UI_DALMATIAN_SOFTKEYS__ */ 
  1625.         {
  1626.             f = b->normal_up_filler;
  1627.             text_color = b->normal_up_text_color;
  1628.             button_icon = b->normal_up_icon;
  1629.         }
  1630.     }
  1631.     gui_push_clip();
  1632.     if (!(b->flags & UI_BUTTON_DISABLE_BACKGND_DISPLAY))
  1633.     {
  1634.         gui_set_clip(x1, y1, x2 + 2, y2 + 2);
  1635.         gui_draw_filled_area(x1, y1, x2, y2, f);
  1636.     }
  1637.     else
  1638.     {
  1639.         gui_set_clip(x1, y1, x2, y2);
  1640.     }
  1641.     ix = x1 + b->icon_x;
  1642.     iy = y1 + b->icon_y;
  1643.     if (button_icon != UI_NULL_IMAGE)
  1644.     {
  1645.         gui_show_transparent_image(ix, iy, button_icon, b->icon_transparent_color);
  1646.     }
  1647.     if (!(b->flags & UI_BUTTON_DISABLE_TEXT_DISPLAY))
  1648.     {
  1649.         S32 sw, sh;
  1650.         gui_push_text_clip();
  1651.         gui_set_text_clip(x1, y1, x2, y2);
  1652.         gui_set_text_color(text_color);
  1653.         gui_set_font(b->text_font);
  1654.         tx = x1 + b->text_x;
  1655. //KP Jerry modify on 2007-3-28 start
  1656. #ifdef __MMI_24X24_CHINESE_FONT__
  1657.     ty = y1;
  1658. #else
  1659.         ty = y1 + b->text_y;
  1660. #endif
  1661. //KP Jerry modify on 2007-3-28 end
  1662.         gui_measure_string(b->text, &sw, &sh);
  1663.         if (b->flags & UI_BUTTON_ALIGN_ICON_TEXT)
  1664.         {
  1665.             if (button_icon != UI_NULL_IMAGE)
  1666.             {
  1667.                 gui_measure_image(button_icon, &iwidth, &iheight);      /* measure width and height of image */
  1668.                 if ((ix - x1) < ((x2 - x1) >> 1))
  1669.                 {
  1670.                     tx = ix + iwidth + 1;
  1671.                 }
  1672.                 else
  1673.                 {
  1674.                     tx = ix - sw - 1;
  1675.                 }
  1676.             }
  1677.         }
  1678.         if (r2lMMIFlag)
  1679.         {
  1680.             tx += sw;
  1681.         }
  1682.         gui_move_text_cursor(tx, ty);   /* move cursor to x,y position */
  1683.         gui_set_line_height(sh);
  1684.     #ifdef __MMI_UI_DALMATIAN_SOFTKEYS__
  1685.         gui_set_text_color((text_color));
  1686.         gui_set_text_border_color(*current_MMI_theme->title_text_color);
  1687.         gui_print_text(b->text);                    /* print text on button */
  1688.     #else /* __MMI_UI_DALMATIAN_SOFTKEYS__ */ 
  1689.         gui_set_text_border_color(MMI_white_color); /* set bordered colr */
  1690.         /* 030705 Calvin added */
  1691.     #ifdef __MMI_MATRIX_MAIN_MENU_FULL_BACKGROUND__
  1692.         if (inMatrixNoTitleFlag)
  1693.         {
  1694.             gui_set_text_border_color(gui_color(0, 0, 255));    /* set bordered colr */
  1695.         }
  1696.     #endif /* __MMI_MATRIX_MAIN_MENU_FULL_BACKGROUND__ */ 
  1697.     #endif /* __MMI_UI_DALMATIAN_SOFTKEYS__ */ 
  1698.         gui_print_bordered_text(b->text);   /* print bordered text on button */
  1699.         gui_pop_text_clip();
  1700.     }
  1701.     gui_pop_clip();
  1702.     gui_set_font(font);
  1703. }
  1704. /***************************************************************************** 
  1705.  * Touch Screen Adaptation
  1706.  *****************************************************************************/
  1707. #ifdef __MMI_TOUCH_SCREEN__
  1708. /*****************************************************************************
  1709.  * FUNCTION
  1710.  *  gui_general_button_translate_pen_event
  1711.  * DESCRIPTION
  1712.  *  
  1713.  * PARAMETERS
  1714.  *  button_object           [IN/OUT]         
  1715.  *  flags                   [IN]        
  1716.  *  pen_state               [IN/OUT]         
  1717.  *  button_x                [IN]        
  1718.  *  button_y                [IN]        
  1719.  *  button_width            [IN]        
  1720.  *  button_height           [IN]        
  1721.  *  draw_down_fp            [IN]        
  1722.  *  draw_up_fp              [IN]        
  1723.  *  clear_background_fp     [IN]        
  1724.  *  pen_event               [IN]        
  1725.  *  x                       [IN]        
  1726.  *  y                       [IN]        
  1727.  *  button_event            [OUT]         
  1728.  * RETURNS
  1729.  *  
  1730.  *****************************************************************************/
  1731. static BOOL gui_general_button_translate_pen_event(
  1732.                 void *button_object,
  1733.                 U32 flags,
  1734.                 gui_button_pen_state_struct *pen_state,
  1735.                 S32 button_x,
  1736.                 S32 button_y,
  1737.                 S32 button_width,
  1738.                 S32 button_height,
  1739.                 void draw_down_fp(void*),
  1740.                 void draw_up_fp(void*),
  1741.                 gui_button_clear_background_hdlr clear_background_fp,
  1742.                 mmi_pen_event_type_enum pen_event,
  1743.                 S16 x,
  1744.                 S16 y,
  1745.                 gui_button_pen_enum *button_event)
  1746. {
  1747.     /*----------------------------------------------------------------*/
  1748.     /* Local Variables                                                */
  1749.     /*----------------------------------------------------------------*/
  1750.     BOOL ret = MMI_TRUE;
  1751.     /*----------------------------------------------------------------*/
  1752.     /* Code Body                                                      */
  1753.     /*----------------------------------------------------------------*/
  1754.     switch (pen_event)
  1755.     {
  1756.         case MMI_PEN_EVENT_DOWN:
  1757.             if (PEN_CHECK_BOUND(x, y, button_x, button_y, button_width, button_height))
  1758.             {
  1759.                 ret = MMI_TRUE;
  1760.                 *button_event = GUI_BUTTON_PEN_DOWN;
  1761.                 pen_state->pen_inside = MMI_TRUE;
  1762.                 if (clear_background_fp)
  1763.                 {
  1764.                     clear_background_fp(button_object);
  1765.                 }
  1766.                 draw_down_fp(button_object);
  1767.             }
  1768.             else
  1769.             {
  1770.                 ret = MMI_FALSE;
  1771.             }
  1772.             break;
  1773.         case MMI_PEN_EVENT_UP:
  1774.             if ((flags & UI_BUTTON_ALWAYS_SEND_PEN_UP_INSIDE) ||
  1775.                 PEN_CHECK_BOUND(x, y, button_x, button_y, button_width, button_height))
  1776.             {
  1777.                 *button_event = GUI_BUTTON_PEN_UP_INSIDE;
  1778.             }
  1779.             else
  1780.             {
  1781.                 *button_event = GUI_BUTTON_PEN_UP_OUTSIDE;
  1782.             }
  1783.             if (pen_state->pen_inside)
  1784.             {
  1785.                 /* Even if the screen change, still need 'draw_up_fp' to set up states of button */
  1786.                 if (clear_background_fp)
  1787.                 {
  1788.                     clear_background_fp(button_object);
  1789.                 }
  1790.                 draw_up_fp(button_object);
  1791.             }
  1792.             pen_state->pen_inside = MMI_FALSE;  /* new change...on up event it should be set to 0 again */
  1793.             break;
  1794.         case MMI_PEN_EVENT_LONG_TAP:
  1795.             *button_event = GUI_BUTTON_PEN_LONGTAP;
  1796.             break;
  1797.         case MMI_PEN_EVENT_REPEAT:
  1798.             if (pen_state->pen_inside)
  1799.             {
  1800.                 *button_event = GUI_BUTTON_PEN_REPEAT;
  1801.             }
  1802.             break;
  1803.         case MMI_PEN_EVENT_MOVE:
  1804.             if (PEN_CHECK_BOUND(x, y, button_x, button_y, button_width, button_height))
  1805.             {
  1806.                 if (!pen_state->pen_inside)
  1807.                 {
  1808.                     *button_event = GUI_BUTTON_PEN_MOVE_INSIDE;
  1809.                     pen_state->pen_inside = MMI_TRUE;
  1810.                     if (clear_background_fp)
  1811.                     {
  1812.                         clear_background_fp(button_object);
  1813.                     }
  1814.                     draw_down_fp(button_object);
  1815.                 }
  1816.                 else
  1817.                 {
  1818.                     *button_event = GUI_BUTTON_PEN_NONE;
  1819.                 }
  1820.             }
  1821.             else
  1822.             {
  1823.                 if (pen_state->pen_inside)
  1824.                 {
  1825.                     *button_event = GUI_BUTTON_PEN_MOVE_OUTSIDE;
  1826.                     pen_state->pen_inside = MMI_FALSE;
  1827.                     if (clear_background_fp)
  1828.                     {
  1829.                         clear_background_fp(button_object);
  1830.                     }
  1831.                     draw_up_fp(button_object);
  1832.                 }
  1833.                 else
  1834.                 {
  1835.                     *button_event = GUI_BUTTON_PEN_NONE;
  1836.                 }
  1837.             }
  1838.             break;
  1839.         case MMI_PEN_EVENT_ABORT:
  1840.             if (pen_state->pen_inside)
  1841.             {
  1842.                 if (clear_background_fp)
  1843.                 {
  1844.                     clear_background_fp(button_object);
  1845.                 }
  1846.                 draw_up_fp(button_object);
  1847.             }
  1848.             if (flags & UI_BUTTON_ALWAYS_SEND_PEN_UP_INSIDE)
  1849.             {
  1850.                 *button_event = GUI_BUTTON_PEN_UP_INSIDE;
  1851.             }
  1852.             else
  1853.             {
  1854.                 *button_event = GUI_BUTTON_PEN_UP_OUTSIDE;
  1855.             }
  1856.             break;
  1857.         default:
  1858.             MMI_ASSERT(0);
  1859.     }
  1860.     return ret;
  1861. }
  1862. /*****************************************************************************
  1863.  * FUNCTION
  1864.  *  gui_button_show_down_by_pen
  1865.  * DESCRIPTION
  1866.  *  
  1867.  * PARAMETERS
  1868.  *  button_object       [IN/OUT]     
  1869.  * RETURNS
  1870.  *  void
  1871.  *****************************************************************************/
  1872. static void gui_button_show_down_by_pen(void *button_object)
  1873. {
  1874.     /*----------------------------------------------------------------*/
  1875.     /* Local Variables                                                */
  1876.     /*----------------------------------------------------------------*/
  1877.     button *b = (button*) button_object;
  1878.     /*----------------------------------------------------------------*/
  1879.     /* Code Body                                                      */
  1880.     /*----------------------------------------------------------------*/
  1881.     b->flags |= (UI_BUTTON_STATE_CLICKED | UI_BUTTON_STATE_DOWN);
  1882.     gui_show_button(b);
  1883.     gui_BLT_double_buffer(b->x, b->y, b->x + b->width - 1 + 2, b->y + b->height - 1 + 2);
  1884. }
  1885. /*****************************************************************************
  1886.  * FUNCTION
  1887.  *  gui_button_show_up_by_pen
  1888.  * DESCRIPTION
  1889.  *  
  1890.  * PARAMETERS
  1891.  *  button_object       [IN/OUT]     
  1892.  * RETURNS
  1893.  *  void
  1894.  *****************************************************************************/
  1895. static void gui_button_show_up_by_pen(void *button_object)
  1896. {
  1897.     /*----------------------------------------------------------------*/
  1898.     /* Local Variables                                                */
  1899.     /*----------------------------------------------------------------*/
  1900.     button *b = (button*) button_object;
  1901.     /*----------------------------------------------------------------*/
  1902.     /* Code Body                                                      */
  1903.     /*----------------------------------------------------------------*/
  1904.     b->flags &= ~(UI_BUTTON_STATE_CLICKED | UI_BUTTON_STATE_DOWN);
  1905.     gui_show_button(b);
  1906.     gui_BLT_double_buffer(b->x, b->y, b->x + b->width - 1 + 2, b->y + b->height - 1 + 2);
  1907. }
  1908. /*****************************************************************************
  1909.  * FUNCTION
  1910.  *  gui_text_button_show_down_by_pen
  1911.  * DESCRIPTION
  1912.  *  
  1913.  * PARAMETERS
  1914.  *  button_object       [IN/OUT]     
  1915.  * RETURNS
  1916.  *  void
  1917.  *****************************************************************************/
  1918. static void gui_text_button_show_down_by_pen(void *button_object)
  1919. {
  1920.     /*----------------------------------------------------------------*/
  1921.     /* Local Variables                                                */
  1922.     /*----------------------------------------------------------------*/
  1923.     text_button *b = (text_button*) button_object;
  1924.     /*----------------------------------------------------------------*/
  1925.     /* Code Body                                                      */
  1926.     /*----------------------------------------------------------------*/
  1927.     b->flags |= (UI_BUTTON_STATE_CLICKED | UI_BUTTON_STATE_DOWN);
  1928.     gui_show_text_button(b);
  1929.     gui_BLT_double_buffer(b->x, b->y, b->x + b->width - 1 + 2, b->y + b->height - 1 + 2);
  1930. }
  1931. /*****************************************************************************
  1932.  * FUNCTION
  1933.  *  gui_text_button_show_up_by_pen
  1934.  * DESCRIPTION
  1935.  *  
  1936.  * PARAMETERS
  1937.  *  button_object       [IN/OUT]     
  1938.  * RETURNS
  1939.  *  void
  1940.  *****************************************************************************/
  1941. static void gui_text_button_show_up_by_pen(void *button_object)
  1942. {
  1943.     /*----------------------------------------------------------------*/
  1944.     /* Local Variables                                                */
  1945.     /*----------------------------------------------------------------*/
  1946.     text_button *b = (text_button*) button_object;
  1947.     /*----------------------------------------------------------------*/
  1948.     /* Code Body                                                      */
  1949.     /*----------------------------------------------------------------*/
  1950.     b->flags &= ~(UI_BUTTON_STATE_CLICKED | UI_BUTTON_STATE_DOWN);
  1951.     gui_show_text_button(b);
  1952.     gui_BLT_double_buffer(b->x, b->y, b->x + b->width - 1 + 2, b->y + b->height - 1 + 2);
  1953. }
  1954. /*****************************************************************************
  1955.  * FUNCTION
  1956.  *  gui_icon_button_show_down_by_pen
  1957.  * DESCRIPTION
  1958.  *  
  1959.  * PARAMETERS
  1960.  *  button_object       [IN/OUT]     
  1961.  * RETURNS
  1962.  *  void
  1963.  *****************************************************************************/
  1964. static void gui_icon_button_show_down_by_pen(void *button_object)
  1965. {
  1966.     /*----------------------------------------------------------------*/
  1967.     /* Local Variables                                                */
  1968.     /*----------------------------------------------------------------*/
  1969.     icon_button *b = (icon_button*) button_object;
  1970.     /*----------------------------------------------------------------*/
  1971.     /* Code Body                                                      */
  1972.     /*----------------------------------------------------------------*/
  1973.     b->flags |= (UI_BUTTON_STATE_CLICKED | UI_BUTTON_STATE_DOWN);
  1974.     gui_show_icon_button(b);
  1975.     gui_BLT_double_buffer(b->x, b->y, b->x + b->width - 1 + 2, b->y + b->height - 1 + 2);
  1976. }
  1977. /*****************************************************************************
  1978.  * FUNCTION
  1979.  *  gui_icon_button_show_up_by_pen
  1980.  * DESCRIPTION
  1981.  *  
  1982.  * PARAMETERS
  1983.  *  button_object       [IN/OUT]     
  1984.  * RETURNS
  1985.  *  void
  1986.  *****************************************************************************/
  1987. static void gui_icon_button_show_up_by_pen(void *button_object)
  1988. {
  1989.     /*----------------------------------------------------------------*/
  1990.     /* Local Variables                                                */
  1991.     /*----------------------------------------------------------------*/
  1992.     icon_button *b = (icon_button*) button_object;
  1993.     /*----------------------------------------------------------------*/
  1994.     /* Code Body                                                      */
  1995.     /*----------------------------------------------------------------*/
  1996.     b->flags &= ~(UI_BUTTON_STATE_CLICKED | UI_BUTTON_STATE_DOWN);
  1997.     gui_show_icon_button(b);
  1998.     gui_BLT_double_buffer(b->x, b->y, b->x + b->width - 1 + 2, b->y + b->height - 1 + 2);
  1999. }
  2000. /*****************************************************************************
  2001.  * FUNCTION
  2002.  *  gui_icontext_button_show_down_by_pen
  2003.  * DESCRIPTION
  2004.  *  
  2005.  * PARAMETERS
  2006.  *  button_object       [IN/OUT]     
  2007.  * RETURNS
  2008.  *  void
  2009.  *****************************************************************************/
  2010. static void gui_icontext_button_show_down_by_pen(void *button_object)
  2011. {
  2012.     /*----------------------------------------------------------------*/
  2013.     /* Local Variables                                                */
  2014.     /*----------------------------------------------------------------*/
  2015.     icontext_button *b = (icontext_button*) button_object;
  2016.     /*----------------------------------------------------------------*/
  2017.     /* Code Body                                                      */
  2018.     /*----------------------------------------------------------------*/
  2019.     b->flags |= (UI_BUTTON_STATE_CLICKED | UI_BUTTON_STATE_DOWN);
  2020.     gui_show_icontext_button(b);
  2021. #ifdef __MMI_UI_DALMATIAN_SOFTKEYS__
  2022.     /* To handle shuffle on pen click */
  2023.     is_button_bar_shuffled = 0;
  2024.     gui_call_shuffle();
  2025. #endif /* __MMI_UI_DALMATIAN_SOFTKEYS__ */ 
  2026.     gui_BLT_double_buffer(b->x, b->y, b->x + b->width - 1 + 2, b->y + b->height - 1 + 2);
  2027. }
  2028. /*****************************************************************************
  2029.  * FUNCTION
  2030.  *  gui_icontext_button_show_up_by_pen
  2031.  * DESCRIPTION
  2032.  *  
  2033.  * PARAMETERS
  2034.  *  button_object       [IN/OUT]     
  2035.  * RETURNS
  2036.  *  void
  2037.  *****************************************************************************/
  2038. static void gui_icontext_button_show_up_by_pen(void *button_object)
  2039. {
  2040.     /*----------------------------------------------------------------*/
  2041.     /* Local Variables                                                */
  2042.     /*----------------------------------------------------------------*/
  2043.     icontext_button *b = (icontext_button*) button_object;
  2044.     /*----------------------------------------------------------------*/
  2045.     /* Code Body                                                      */
  2046.     /*----------------------------------------------------------------*/
  2047.     b->flags &= ~(UI_BUTTON_STATE_CLICKED | UI_BUTTON_STATE_DOWN);
  2048.     gui_show_icontext_button(b);
  2049. #ifdef __MMI_UI_DALMATIAN_SOFTKEYS__
  2050.     /* To handle shuffle on pen click */
  2051.     is_button_bar_shuffled = 1;
  2052.     gui_call_shuffle();
  2053. #endif /* __MMI_UI_DALMATIAN_SOFTKEYS__ */ 
  2054.     gui_BLT_double_buffer(b->x, b->y, b->x + b->width - 1 + 2, b->y + b->height - 1 + 2);
  2055. }
  2056. /* Translate low-level pen events to high-level button events in button */
  2057. /*****************************************************************************
  2058.  * FUNCTION
  2059.  *  gui_button_translate_pen_event
  2060.  * DESCRIPTION
  2061.  *  
  2062.  * PARAMETERS
  2063.  *  b                   [IN/OUT]         
  2064.  *  pen_event           [IN]        
  2065.  *  x                   [IN]        
  2066.  *  y                   [IN]        
  2067.  *  button_event        [OUT]         
  2068.  * RETURNS
  2069.  *  
  2070.  *****************************************************************************/
  2071. BOOL gui_button_translate_pen_event(
  2072.         button *b,
  2073.         mmi_pen_event_type_enum pen_event,
  2074.         S16 x,
  2075.         S16 y,
  2076.         gui_button_pen_enum *button_event)
  2077. {
  2078.     /*----------------------------------------------------------------*/
  2079.     /* Local Variables                                                */
  2080.     /*----------------------------------------------------------------*/
  2081.     /*----------------------------------------------------------------*/
  2082.     /* Code Body                                                      */
  2083.     /*----------------------------------------------------------------*/
  2084.     return gui_general_button_translate_pen_event(
  2085.             b,
  2086.             b->flags,
  2087.             &b->pen_state,
  2088.             b->x,
  2089.             b->y,
  2090.             b->width,
  2091.             b->height,
  2092.             gui_button_show_down_by_pen,
  2093.             gui_button_show_up_by_pen,
  2094.             b->clear_background_fp,
  2095.             pen_event,
  2096.             x,
  2097.             y,
  2098.             button_event);
  2099. }
  2100. /* Translate low-level pen events to high-level button events in text button */
  2101. /*****************************************************************************
  2102.  * FUNCTION
  2103.  *  gui_text_button_translate_pen_event
  2104.  * DESCRIPTION
  2105.  *  
  2106.  * PARAMETERS
  2107.  *  b                   [IN/OUT]         
  2108.  *  pen_event           [IN]        
  2109.  *  x                   [IN]        
  2110.  *  y                   [IN]        
  2111.  *  button_event        [OUT]         
  2112.  * RETURNS
  2113.  *  
  2114.  *****************************************************************************/
  2115. BOOL gui_text_button_translate_pen_event(
  2116.         text_button *b,
  2117.         mmi_pen_event_type_enum pen_event,
  2118.         S16 x,
  2119.         S16 y,
  2120.         gui_button_pen_enum *button_event)
  2121. {
  2122.     /*----------------------------------------------------------------*/
  2123.     /* Local Variables                                                */
  2124.     /*----------------------------------------------------------------*/
  2125.     /*----------------------------------------------------------------*/
  2126.     /* Code Body                                                      */
  2127.     /*----------------------------------------------------------------*/
  2128.     if (!b->text)
  2129.     {
  2130.         return MMI_FALSE;
  2131.     }
  2132.     return gui_general_button_translate_pen_event(
  2133.             b,
  2134.             b->flags,
  2135.             &b->pen_state,
  2136.             b->x,
  2137.             b->y,
  2138.             b->width,
  2139.             b->height,
  2140.             gui_text_button_show_down_by_pen,
  2141.             gui_text_button_show_up_by_pen,
  2142.             b->clear_background_fp,
  2143.             pen_event,
  2144.             x,
  2145.             y,
  2146.             button_event);
  2147. }
  2148. /* Translate low-level pen events to high-level button events in icon button */
  2149. /*****************************************************************************
  2150.  * FUNCTION
  2151.  *  gui_icon_button_translate_pen_event
  2152.  * DESCRIPTION
  2153.  *  
  2154.  * PARAMETERS
  2155.  *  b                   [IN/OUT]         
  2156.  *  pen_event           [IN]        
  2157.  *  x                   [IN]        
  2158.  *  y                   [IN]        
  2159.  *  button_event        [OUT]         
  2160.  * RETURNS
  2161.  *  
  2162.  *****************************************************************************/
  2163. BOOL gui_icon_button_translate_pen_event(
  2164.         icon_button *b,
  2165.         mmi_pen_event_type_enum pen_event,
  2166.         S16 x,
  2167.         S16 y,
  2168.         gui_button_pen_enum *button_event)
  2169. {
  2170.     /*----------------------------------------------------------------*/
  2171.     /* Local Variables                                                */
  2172.     /*----------------------------------------------------------------*/
  2173.     /*----------------------------------------------------------------*/
  2174.     /* Code Body                                                      */
  2175.     /*----------------------------------------------------------------*/
  2176.     if (!b->normal_up_icon)
  2177.     {
  2178.         return MMI_FALSE;
  2179.     }
  2180.     return gui_general_button_translate_pen_event(
  2181.             b,
  2182.             b->flags,
  2183.             &b->pen_state,
  2184.             b->x,
  2185.             b->y,
  2186.             b->width,
  2187.             b->height,
  2188.             gui_icon_button_show_down_by_pen,
  2189.             gui_icon_button_show_up_by_pen,
  2190.             b->clear_background_fp,
  2191.             pen_event,
  2192.             x,
  2193.             y,
  2194.             button_event);
  2195. }
  2196. /* Translate low-level pen events to high-level button events in icon-text button */
  2197. /*****************************************************************************
  2198.  * FUNCTION
  2199.  *  gui_icontext_button_translate_pen_event
  2200.  * DESCRIPTION
  2201.  *  
  2202.  * PARAMETERS
  2203.  *  b                   [IN/OUT]         
  2204.  *  pen_event           [IN]        
  2205.  *  x                   [IN]        
  2206.  *  y                   [IN]        
  2207.  *  button_event        [OUT]         
  2208.  * RETURNS
  2209.  *  
  2210.  *****************************************************************************/
  2211. BOOL gui_icontext_button_translate_pen_event(
  2212.         icontext_button *b,
  2213.         mmi_pen_event_type_enum pen_event,
  2214.         S16 x,
  2215.         S16 y,
  2216.         gui_button_pen_enum *button_event)
  2217. {
  2218.     /*----------------------------------------------------------------*/
  2219.     /* Local Variables                                                */
  2220.     /*----------------------------------------------------------------*/
  2221.     /*----------------------------------------------------------------*/
  2222.     /* Code Body                                                      */
  2223.     /*----------------------------------------------------------------*/
  2224.     if (!b->text && !b->normal_up_icon)
  2225.     {
  2226.         return MMI_FALSE;
  2227.     }
  2228.     return gui_general_button_translate_pen_event(
  2229.             b,
  2230.             b->flags,
  2231.             &b->pen_state,
  2232.             b->x,
  2233.             b->y,
  2234.             b->width,
  2235.             b->height,
  2236.             gui_icontext_button_show_down_by_pen,
  2237.             gui_icontext_button_show_up_by_pen,
  2238.             b->clear_background_fp,
  2239.             pen_event,
  2240.             x,
  2241.             y,
  2242.             button_event);
  2243. }
  2244. #endif /* __MMI_TOUCH_SCREEN__ */