gui_panel.c
资源名称:mmi.rar [点击查看]
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:17k
源码类别:
MTK
开发平台:
C/C++
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- * Filename:
- * ---------
- * gui_panel.c
- *
- * Project:
- * --------
- * MAUI
- *
- * Description:
- * ------------
- * Panel - UI component
- *
- * Author:
- * -------
- * -------
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- #include "gui_panel.h"
- #include "DebugInitDef.h"
- #include "gdi_include.h"
- #include "GlobalConstants.h"
- /*****************************************************************************
- * Local Variable
- *****************************************************************************/
- /*****************************************************************************
- * Local Function
- *****************************************************************************/
- /*****************************************************************************
- * FUNCTION
- * gui_panel_show_element
- * DESCRIPTION
- * Draw a painter element
- * PARAMETERS
- * panel [IN/OUT] panel
- * element [IN] panel element
- * state [IN] state of panel element
- * bg_is_already_drawn [IN] whether the panel background is already drawn.
- * RETURNS
- * void
- *****************************************************************************/
- static void gui_panel_show_element(
- gui_panel_struct *panel,
- gui_panel_element_struct *element,
- gui_panel_elem_state_enum state,
- MMI_BOOL bg_is_already_drawn)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- gui_lock_double_buffer();
- if (!bg_is_already_drawn && element->redraw_bg_after_state_changed)
- {
- gui_util_painter_show_clipped(
- &panel->background,
- panel->x,
- panel->y,
- element->x1,
- element->y1,
- element->x2,
- element->y2);
- }
- gui_util_painter_show(
- &element->painters[state],
- element->x1,
- element->y1,
- element->x2,
- element->y2);
- gui_unlock_double_buffer();
- gui_BLT_double_buffer(element->x1, element->y1, element->x2, element->y2);
- }
- /*****************************************************************************
- * Extern Global Function
- *****************************************************************************/
- /*****************************************************************************
- * FUNCTION
- * gui_panel_create
- * DESCRIPTION
- * Create a panel component
- *
- * Note: the parameter 'display_focus' decides whether there is a focussed element.
- * For example, audio player has a focussed button (Play, Stop), but dialing screen
- * does not have a focussed button.
- * PARAMETERS
- * panel [OUT] panel
- * x [IN]
- * y [IN]
- * width [IN]
- * height [IN]
- * background [IN] panel background painter
- * display_focus [IN] whether to display focussed element differently
- * RETURNS
- * void
- *****************************************************************************/
- void gui_panel_create(
- gui_panel_struct *panel,
- S32 x,
- S32 y,
- S32 width,
- S32 height,
- gui_util_painter_struct background,
- MMI_BOOL display_focus)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- memset(panel, 0, sizeof(gui_panel_struct));
- panel->x = x;
- panel->y = y;
- panel->width = width;
- panel->height = height;
- panel->background = background;
- panel->display_focus = display_focus ? 1 : 0;
- }
- /*****************************************************************************
- * FUNCTION
- * gui_panel_show
- * DESCRIPTION
- * Show a panel component
- * PARAMETERS
- * panel [IN/OUT] panel
- * RETURNS
- * void
- *****************************************************************************/
- void gui_panel_show(gui_panel_struct *panel)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 x1, y1, x2, y2;
- S32 elem_idx;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- x1 = panel->x;
- y1 = panel->y;
- x2 = panel->x + panel->width - 1;
- y2 = panel->y + panel->height - 1;
- gui_lock_double_buffer();
- gui_util_painter_show(&panel->background, x1, y1, x2, y2);
- for (elem_idx = 0; elem_idx < panel->element_count; elem_idx++)
- {
- gui_panel_element_struct *e = &panel->elements[elem_idx];
- gui_panel_elem_state_enum state;
- if (e->down_state)
- {
- state = GUI_PANEL_ELEM_STATE_DOWN;
- }
- else if (panel->display_focus && elem_idx == panel->element_focus_index)
- {
- state = GUI_PANEL_ELEM_STATE_FOCUSSED;
- }
- else
- {
- state = GUI_PANEL_ELEM_STATE_NORMAL;
- }
- gui_util_painter_show(&e->painters[state], e->x1, e->y1, e->x2, e->y2);
- }
- gui_unlock_double_buffer();
- gui_BLT_double_buffer(x1, y1, x2, y2);
- }
- /*****************************************************************************
- * FUNCTION
- * gui_panel_set_element_focus
- * DESCRIPTION
- * Set the foccused element
- * PARAMETERS
- * panel [IN/OUT] panel
- * element_index [IN] element index to be focussed
- * update_display [IN] whether to update the display
- * RETURNS
- * void
- *****************************************************************************/
- void gui_panel_set_element_focus(
- gui_panel_struct *panel,
- S32 element_index,
- MMI_BOOL update_display)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (element_index >= 0 && element_index < panel->element_count &&
- element_index != panel->element_focus_index)
- {
- if (update_display)
- {
- if (panel->display_focus)
- {
- gui_panel_show_element(
- panel,
- &panel->elements[panel->element_focus_index],
- GUI_PANEL_ELEM_STATE_NORMAL,
- MMI_FALSE);
- }
- gui_panel_show_element(
- panel,
- &panel->elements[element_index],
- panel->display_focus ? GUI_PANEL_ELEM_STATE_FOCUSSED : GUI_PANEL_ELEM_STATE_NORMAL,
- MMI_FALSE);
- }
- panel->element_focus_index = element_index;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * gui_panel_add_element
- * DESCRIPTION
- * Set the foccused element
- *
- * Note: If 'redraw_bg_after_state_changed' is 1, it typically has worse performance.
- * It is usually used when painter is partially-transparent.
- * If art designer can create images carefully (put the background into element image), then
- * we can set redraw_bg_after_state_changed as 0.
- * PARAMETERS
- * panel [IN/OUT] panel
- * x [IN] x
- * y [IN] y
- * width [IN] width
- * height [IN] height
- * keycode [IN] registered key event (KEY_INVALID if no key event registered)
- * up_event_callback [IN] callback when key/pen up
- * repeat_event_callback [IN] callback when key repeat or pen stays on element
- * normal_painter [IN] painter when up
- * down_painter [IN] painter when down
- * focussed_painter [IN] painter when focussed. Only used when panel->display_focus is 1.
- * redraw_bg_after_state_changed [IN] redrawn panel background when pressed/released/focussed/unfocussed
- * RETURNS
- * The element index. -1 if failed
- *****************************************************************************/
- S32 gui_panel_add_element(
- gui_panel_struct *panel,
- S32 x,
- S32 y,
- S32 width,
- S32 height,
- U16 keycode,
- FuncPtr up_event_callback,
- FuncPtr repeat_event_callback,
- gui_util_painter_struct normal_painter,
- gui_util_painter_struct down_painter,
- gui_util_painter_struct focussed_painter,
- MMI_BOOL redraw_bg_after_state_changed)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- gui_panel_element_struct *e;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (panel->element_count == GUI_PANEL_MAX_ELEMENT_COUNT)
- {
- MMI_DBG_ASSERT(0);
- return -1;
- }
- e = &panel->elements[panel->element_count];
- e->x1 = x;
- e->y1 = y;
- e->x2 = x + width - 1;
- e->y2 = y + height - 1;
- e->keycode = keycode;
- e->up_event_callback = up_event_callback ? up_event_callback : UI_dummy_function;
- e->repeat_event_callback = repeat_event_callback ? repeat_event_callback : UI_dummy_function;
- e->painters[GUI_PANEL_ELEM_STATE_NORMAL] = normal_painter;
- e->painters[GUI_PANEL_ELEM_STATE_DOWN] = down_painter;
- e->painters[GUI_PANEL_ELEM_STATE_FOCUSSED] = focussed_painter;
- e->down_state = 0;
- e->redraw_bg_after_state_changed = redraw_bg_after_state_changed ? 1 : 0;
- return panel->element_count++;
- }
- /*****************************************************************************
- * FUNCTION
- * gui_panel_general_key_handler
- * DESCRIPTION
- * General key handler for panel elements
- * PARAMETERS
- * panel [IN/OUT] panel
- * keycode [IN] key code
- * state [IN] key type
- * RETURNS
- * void
- *****************************************************************************/
- void gui_panel_general_key_handler(gui_panel_struct *panel, U16 keycode, U16 keytype)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 i;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- for (i = 0; i < panel->element_count; i++)
- {
- gui_panel_element_struct *e = &panel->elements[i];
- if (e->keycode == keycode)
- {
- switch (keytype)
- {
- case KEY_EVENT_DOWN:
- if (panel->element_focus_index != i && panel->display_focus)
- {
- gui_panel_show_element(
- panel,
- &panel->elements[panel->element_focus_index],
- GUI_PANEL_ELEM_STATE_NORMAL,
- MMI_FALSE);
- }
- panel->element_focus_index = i;
- gui_panel_show_element(
- panel,
- e,
- GUI_PANEL_ELEM_STATE_DOWN,
- MMI_FALSE);
- e->down_state = 1;
- break;
- case KEY_EVENT_UP:
- gui_panel_show_element(
- panel,
- e,
- panel->display_focus ? GUI_PANEL_ELEM_STATE_FOCUSSED : GUI_PANEL_ELEM_STATE_NORMAL,
- MMI_FALSE);
- e->down_state = 0;
- /* Invoke callback */
- e->up_event_callback();
- break;
- case KEY_LONG_PRESS:
- /* FALLTHROUGH no break */
- case KEY_REPEAT:
- /* Invoke callback */
- e->repeat_event_callback();
- break;
- default:
- break;
- }
- break;
- }
- }
- }