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.
18 #include <Elementary.h>
19 #include <app_debug.h>
23 #include "util/ctxpopup.h"
24 #include "util/util.h"
27 void (*func)(void *data, int id);
33 struct _selected_cb cb;
36 static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,
37 Evas_Event_Key_Down *ev)
46 if (!strcmp(ev->keyname, KEY_BACK) ||
47 !strcmp(ev->keyname, KEY_ESC))
51 static void _mouse_move_cb(int id, void *data, Evas *e, Evas_Object *obj,
52 Evas_Event_Mouse_Move *ev)
57 if (!elm_object_focus_get(obj))
58 elm_object_focus_set(obj, EINA_TRUE);
61 static void _clicked_cb(int id, void *data, Evas_Object *obj)
71 m->cb.func(m->cb.data, id);
76 static void _dismissed_cb(void *data, Evas_Object *obj, void *event_info)
88 static input_handler _handler = {
89 .key_down = _key_down_cb,
90 .mouse_move = _mouse_move_cb,
91 .clicked = _clicked_cb
94 void ctxpopup_set_callback(struct ctxpopup *m, void (*func)(void *, int),
98 _ERR("failed to get ctxpopup info");
106 void ctxpopup_show(struct ctxpopup *m, int x, int y)
109 _ERR("failed to get ctxpopup info");
113 evas_object_move(m->popup, x * elm_config_scale_get(),
114 y * elm_config_scale_get());
116 evas_object_show(m->popup);
119 struct ctxpopup *ctxpopup_create(Evas_Object *base, const char *ctxpopup_style,
120 const char *btn_style, const char **text, int text_size)
123 Evas_Object *ctxpopup, *box, *btn;
124 Evas_Object *firstbtn;
127 if (!base || !text || text_size <= 0) {
128 _ERR("invalid argument");
132 m = calloc(1, sizeof(*m));
134 _ERR("failed to allocate");
138 ctxpopup = elm_ctxpopup_add(base);
140 _ERR("failed to create ctxpopup object");
146 elm_object_style_set(ctxpopup, ctxpopup_style);
148 box = util_add_box(ctxpopup, EINA_FALSE);
150 _ERR("failed to add box");
151 evas_object_del(ctxpopup);
156 elm_box_padding_set(box, 0, 0);
158 for (i = 0; i < text_size; i++) {
159 btn = util_add_button(box, btn_style, text[i]);
161 _ERR("failed to add button");
162 evas_object_del(ctxpopup);
167 elm_box_pack_end(box, btn);
169 evas_object_show(btn);
171 inputmgr_add_callback(btn, i, &_handler, m);
177 elm_object_focus_next_object_set(firstbtn, btn, ELM_FOCUS_UP);
178 elm_object_focus_next_object_set(btn, firstbtn, ELM_FOCUS_DOWN);
180 elm_object_content_set(ctxpopup, box);
182 evas_object_smart_callback_add(ctxpopup, SIG_DISMISSED,
190 void ctxpopup_destroy(struct ctxpopup *m)
193 _ERR("failed to get ctxpopup info");
197 evas_object_hide(m->popup);
198 evas_object_del(m->popup);