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"
27 #define COUNT_MENU_ITEM 4
29 enum input_handler_type {
30 INPUT_HANDLER_TYPE_BTN,
31 INPUT_HANDLER_TYPE_ITEM_RESET,
32 INPUT_HANDLER_TYPE_RESET,
33 INPUT_HANDLER_TYPE_DISCARD,
34 INPUT_HANDLER_TYPE_CANCEL
56 static void _focused(int id, void *data, Evas_Object *obj,
57 Elm_Object_Item *item)
59 elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
62 static void _unfocused(int id, void *data, Evas_Object *obj,
63 Elm_Object_Item *item)
65 elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
68 static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
69 Evas_Event_Key_Down *ev);
71 static void _mouse_down(int id, void *data, Evas *e, Evas_Object *obj,
72 Evas_Event_Mouse_Down *ev);
74 static void _mouse_move(int id, void *data, Evas *e, Evas_Object *obj,
75 Evas_Event_Mouse_Move *ev)
77 if (!elm_object_focus_get(obj))
78 elm_object_focus_set(obj, EINA_TRUE);
81 static input_handler handler = {
83 .unfocused = _unfocused,
84 .key_down = _key_down,
85 .mouse_down = _mouse_down,
86 .mouse_move = _mouse_move
89 static void _add_popup(struct _priv *priv, char *title, char *message,
90 char *first_btn_message, int first_btn_id,
91 char *second_btn_message, int second_btn_id)
93 Evas_Object *popup, *first_btn, *second_btn;
95 popup = utils_add_popup(priv->base, title, message);
97 _ERR("failed to add popup");
101 first_btn = utils_add_button(popup, first_btn_message,
102 PART_POPUP_BUTTON_1);
104 _ERR("failed to add delete btn");
105 evas_object_del(popup);
108 inputmgr_add_callback(first_btn, first_btn_id, &handler, priv);
110 second_btn = utils_add_button(popup, second_btn_message,
111 PART_POPUP_BUTTON_2);
113 _ERR("failed to add cancel btn");
114 evas_object_del(popup);
117 inputmgr_add_callback(second_btn, second_btn_id, &handler, priv);
118 elm_object_focus_set(second_btn, EINA_TRUE);
123 static void _delete_popup(struct _priv *priv, Evas_Object *obj)
125 inputmgr_remove_callback(obj, &handler);
126 evas_object_del(priv->popup);
130 static void _select(int id, void *data, Evas_Object *obj)
137 case INPUT_HANDLER_TYPE_BTN:
139 _add_popup(priv, MESSAGE_DISCARD,
140 MESSAGE_DISCARD_CONTENTS,
142 INPUT_HANDLER_TYPE_DISCARD,
144 INPUT_HANDLER_TYPE_CANCEL);
147 viewmgr_update_view(VIEW_USER_EDIT, UPDATE_TYPE_RESET, NULL);
148 viewmgr_hide_view(VIEW_ACTION_MENU);
150 case INPUT_HANDLER_TYPE_ITEM_RESET:
151 _add_popup(priv, MESSAGE_RESET, MESSAGE_RESET_CONTENTS,
152 MESSAGE_RESET, INPUT_HANDLER_TYPE_RESET,
153 MESSAGE_CANCEL, INPUT_HANDLER_TYPE_CANCEL);
155 case INPUT_HANDLER_TYPE_RESET:
156 case INPUT_HANDLER_TYPE_DISCARD:
157 viewmgr_update_view(VIEW_USER_EDIT, UPDATE_TYPE_RESET, NULL);
158 viewmgr_hide_view(VIEW_ACTION_MENU);
159 _delete_popup(priv, obj);
161 case INPUT_HANDLER_TYPE_CANCEL:
162 _delete_popup(priv, obj);
169 static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
170 Evas_Event_Key_Down *ev)
175 _ERR("Invalid argument");
180 if (!strcmp(ev->keyname, KEY_BACK) ||
181 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
183 case INPUT_HANDLER_TYPE_BTN:
184 case INPUT_HANDLER_TYPE_ITEM_RESET:
185 viewmgr_hide_view(VIEW_ACTION_MENU);
187 case INPUT_HANDLER_TYPE_RESET:
188 case INPUT_HANDLER_TYPE_DISCARD:
189 case INPUT_HANDLER_TYPE_CANCEL:
191 _delete_popup(priv, obj);
196 } else if (!strcmp(ev->keyname, KEY_ENTER) ||
197 !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
198 _select(id, data, obj);
202 static void _mouse_down(int id, void *data, Evas *e, Evas_Object *obj,
203 Evas_Event_Mouse_Down *ev)
206 _ERR("Invalid argument");
210 _select(id, data, obj);
213 static bool _add_base(struct _priv *priv)
215 Evas_Object *btn, *box;
217 btn = utils_add_layout(priv->base, GRP_ACTION_MENU_LIVETV, true,
218 PART_ACTION_MENU_LIVETV);
220 _ERR("failed to add btn");
223 inputmgr_add_callback(btn, INPUT_HANDLER_TYPE_BTN, &handler, priv);
226 box = utils_add_box(priv->base, true);
228 _ERR("failed to add box");
231 elm_object_part_content_set(priv->base, PART_ACTION_MENU_TABLE, box);
232 elm_box_padding_set(box, 1, 0);
233 elm_box_align_set(box, 0.0, 0.5);
239 static Evas_Object *_create(Evas_Object *win, void *data)
244 priv = calloc(1, sizeof(*priv));
246 _ERR("failed to calloc priv");
250 base = utils_add_layout(win, GRP_ACTION_MENU, false, NULL);
252 _ERR("failed to create base");
256 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
258 elm_win_resize_object_add(win, base);
263 if (!_add_base(priv)) {
264 _ERR("failed to add menu");
266 evas_object_del(base);
270 viewmgr_set_view_data(VIEW_ACTION_MENU, priv);
275 static void _add_empty_item(struct _priv *priv, int len)
280 for (i = 0; i < len; i++) {
281 item = utils_add_layout(priv->box, GRP_ACTION_MENU_TABLE_ITEM,
284 _ERR("failed to add item");
288 evas_object_show(item);
289 elm_box_pack_end(priv->box, item);
290 priv->list = eina_list_append(priv->list, item);
294 static bool _add_item(struct _priv *priv)
296 Evas_Object *item, *ic, *focus_ic, *lbl, *focus_lbl, *bg;
297 struct _btn_info btn_info[] = {
299 IMAGE_ACTION_MENU_ICON_RESET,
300 IMAGE_ACTION_MENU_ICON_RESET_FOCUS,
301 IMAGE_ACTION_MENU_ICON_RESET_DIS,
302 ACTION_MENU_TITLE_RESET,
303 INPUT_HANDLER_TYPE_ITEM_RESET
308 elm_box_clear(priv->box);
310 for (i = 0; i < sizeof(btn_info) / sizeof(*btn_info); i++) {
311 item = utils_add_layout(priv->box, GRP_ACTION_MENU_TABLE_ITEM,
314 _ERR("failed to add item");
318 ic = utils_add_icon(item, priv->edited ?
319 btn_info[i].icon : btn_info[i].dis_icon,
320 PART_ACTION_MENU_TABLE_ITEM_ICON);
324 lbl = utils_add_label(item, btn_info[i].title,
325 priv->edited ? STYLE_LABEL_ACTION_MENU_TITLE :
326 STYLE_LABEL_ACTION_MENU_TITLE_DIS,
327 PART_ACTION_MENU_TABLE_ITEM_TEXT);
332 focus_ic = utils_add_icon(item, btn_info[i].focus_icon,
333 PART_ACTION_MENU_TABLE_ITEM_ICON_FOCUS);
337 focus_lbl = utils_add_label(item, btn_info[i].title,
338 STYLE_LABEL_ACTION_MENU_TITLE_FOCUS,
339 PART_ACTION_MENU_TABLE_ITEM_TEXT_FOCUS);
343 bg = utils_add_bg(item, COLOR_DEFAULT_R,
344 COLOR_DEFAULT_G, COLOR_DEFAULT_B,
346 PART_ACTION_MENU_TABLE_ITEM_BG);
350 inputmgr_add_callback(item, btn_info[i].handler_id,
353 evas_object_show(item);
354 elm_box_pack_end(priv->box, item);
355 priv->list = eina_list_append(priv->list, item);
358 _add_empty_item(priv, COUNT_MENU_ITEM -
359 sizeof(btn_info) / sizeof(*btn_info));
363 evas_object_del(item);
367 static void _show(void *data)
372 _ERR("Invalid argument");
378 if (!_add_item(priv)) {
379 _ERR("failed to add item");
383 evas_object_show(priv->base);
386 elm_object_focus_set(priv->btn, EINA_TRUE);
389 static void _hide(void *data)
395 _ERR("Invalid argument");
401 EINA_LIST_FREE(priv->list, eo) {
403 inputmgr_remove_callback(eo, &handler);
406 evas_object_hide(priv->base);
408 priv->edited = false;
411 static void _destroy(void *data)
416 _ERR("Invalid argument");
422 inputmgr_remove_callback(priv->btn, &handler);
424 evas_object_del(priv->base);
428 static void _update(void *view_data, int update_type, void *data)
433 _ERR("Invalid argument");
439 switch (update_type) {
440 case UPDATE_TYPE_EDIT:
441 priv->edited = *(bool *)data;
444 _ERR("Invalid type");
449 static view_class vclass = {
450 .view_id = VIEW_ACTION_MENU,
458 view_class *view_action_menu_get_vclass(void)