2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <Elementary.h>
18 #include <app_debug.h>
26 #define ACTION_MENU_TITLE_RESET "Reset"
28 enum input_handler_type {
40 static void _focused(int id, void *data, Evas_Object *obj,
41 Elm_Object_Item *item)
43 elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
46 static void _unfocused(int id, void *data, Evas_Object *obj,
47 Elm_Object_Item *item)
49 elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
52 static void _select(int id, void *data, Evas_Object *obj)
54 /* It should be implemented later */
57 case INPUT_HANDLER_BTN:
59 case INPUT_HANDLER_ITEM:
66 static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
67 Evas_Event_Key_Down *ev)
69 if (!strcmp(ev->keyname, KEY_BACK) ||
70 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
71 viewmgr_hide_view(VIEW_ACTION_MENU);
72 } else if (!strcmp(ev->keyname, KEY_ENTER) ||
73 !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
74 _select(id, data, obj);
78 static void _mouse_down(int id, void *data, Evas *e, Evas_Object *obj,
79 Evas_Event_Mouse_Down *ev)
81 _select(id, data, obj);
84 static void _mouse_move(int id, void *data, Evas *e, Evas_Object *obj,
85 Evas_Event_Mouse_Move *ev)
87 if (!elm_object_focus_get(obj))
88 elm_object_focus_set(obj, EINA_TRUE);
91 static input_handler handler = {
93 .unfocused = _unfocused,
94 .key_down = _key_down,
95 .mouse_down = _mouse_down,
96 .mouse_move = _mouse_move
99 static Evas_Object *_add_item(Evas_Object *box, struct _priv *priv)
101 Evas_Object *item, *ic, *focus_ic, *lbl, *focus_lbl, *bg;
103 item = utils_add_layout(box, GRP_ACTION_MENU_TABLE_ITEM, true, NULL);
105 _ERR("failed to add item");
106 evas_object_del(box);
110 ic = utils_add_icon(item, IMAGE_ACTION_MENU_ICON_RESET,
111 PART_ACTION_MENU_TABLE_ITEM_ICON);
115 focus_ic = utils_add_icon(item, IMAGE_ACTION_MENU_ICON_RESET_FOCUS,
116 PART_ACTION_MENU_TABLE_ITEM_ICON_FOCUS);
120 lbl = utils_add_label(item, ACTION_MENU_TITLE_RESET,
121 STYLE_LABEL_ACTION_MENU_TITLE,
122 PART_ACTION_MENU_TABLE_ITEM_TEXT);
126 focus_lbl = utils_add_label(item, ACTION_MENU_TITLE_RESET,
127 STYLE_LABEL_ACTION_MENU_TITLE_FOCUS,
128 PART_ACTION_MENU_TABLE_ITEM_TEXT_FOCUS);
132 bg = utils_add_bg(item, COLOR_DEFAULT_R, COLOR_DEFAULT_G,
133 COLOR_DEFAULT_B, COLOR_DEFAULT_A,
134 PART_ACTION_MENU_TABLE_ITEM_BG);
138 evas_object_show(item);
139 inputmgr_add_callback(item, INPUT_HANDLER_ITEM, &handler, priv);
143 evas_object_del(item);
147 static bool _add_menu(struct _priv *priv)
149 Evas_Object *btn, *box, *item;
151 btn = utils_add_layout(priv->base, GRP_ACTION_MENU_LIVETV, true,
152 PART_ACTION_MENU_LIVETV);
154 _ERR("failed to add btn");
157 inputmgr_add_callback(btn, INPUT_HANDLER_BTN, &handler, priv);
160 box = utils_add_box(priv->base, true);
162 _ERR("failed to add box");
165 elm_object_part_content_set(priv->base, PART_ACTION_MENU_TABLE, box);
166 elm_box_align_set(box, 0.0, 0.5);
168 item = _add_item(box, priv);
170 _ERR("failed to add item");
171 evas_object_del(box);
175 elm_box_pack_start(box, item);
181 static Evas_Object *_create(Evas_Object *win, void *data)
186 priv = calloc(1, sizeof(*priv));
188 _ERR("failed to calloc priv");
192 base = utils_add_layout(win, GRP_ACTION_MENU, false, NULL);
194 _ERR("failed to create base");
198 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
200 elm_win_resize_object_add(win, base);
205 if (!_add_menu(priv)) {
206 _ERR("failed to add menu");
208 evas_object_del(base);
212 viewmgr_set_view_data(VIEW_ACTION_MENU, priv);
217 static void _show(void *data)
222 _ERR("Invalid argument");
228 evas_object_show(priv->base);
231 elm_object_focus_set(priv->btn, EINA_TRUE);
234 static void _hide(void *data)
239 _ERR("Invalid argument");
245 evas_object_hide(priv->base);
248 static void _destroy(void *data)
253 _ERR("Invalid argument");
259 evas_object_del(priv->base);
263 static view_class vclass = {
264 .view_id = VIEW_ACTION_MENU,
271 view_class *view_action_menu_get_vclass(void)