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/controller.h"
26 void (*func)(void *data, const char *ev);
41 static void _btn_cb(void *data, Evas_Object *obj,
42 const char *emission, const char *source)
47 _ERR("invalid parameter");
54 p->cb.func(p->cb.data, source);
57 static void _mouse_move_cb(int id, void *data, Evas *e,
58 Evas_Object *obj, Evas_Event_Mouse_Move *ev)
60 if (!elm_object_focus_get(obj))
61 elm_object_focus_set(obj, EINA_TRUE);
64 static void _clicked_cb(int id, void *data, Evas_Object *obj)
66 elm_object_signal_emit(obj, SIG_BTN_CLICKED, "");
69 static input_handler _handler = {
70 .mouse_move = _mouse_move_cb,
71 .clicked = _clicked_cb,
74 static Evas_Object *_add_btn(Evas_Object *base, const char *style)
78 btn = elm_button_add(base);
82 elm_object_style_set(btn, style);
87 static bool _add_control(void *handle, const char *name, int loc,
88 const char *style, const char *part)
95 if (!handle || !name || !style || !part) {
96 _ERR("invalid parameter");
102 snprintf(buf, sizeof(buf), "%s_%s", style, name);
103 btn = _add_btn(p->base, buf);
105 _ERR("failed to add button");
109 snprintf(buf, sizeof(buf), "%s%d", part, loc);
111 ctl = calloc(1, sizeof(*ctl));
113 _ERR("failed to allocate");
118 ctl->part = strdup(buf);
120 p->list = eina_list_append(p->list, ctl);
122 inputmgr_add_callback(btn, 0, &_handler, p);
123 elm_object_signal_callback_add(btn, SIG_BTN_CALLBACK, name, _btn_cb, p);
128 static void _add_callback(void *handle,
129 void (*func)(void *, const char *), void *data)
134 _ERR("invalid parameter");
143 static void _focus(void *handle, int loc, bool foc)
146 struct _control *ctl;
149 _ERR("invalid parameter");
154 ctl = eina_list_nth(p->list, loc);
157 elm_object_focus_set(ctl->obj, foc);
160 static void _signal(void *handle, int loc, const char *signal)
163 struct _control *ctl;
166 _ERR("invalid parameter");
171 ctl = eina_list_nth(p->list, loc);
174 elm_object_signal_emit(ctl->obj, signal, "");
177 static void _enable(void *handle)
180 struct _control *ctl;
184 _ERR("invalid parameter");
190 EINA_LIST_FOREACH(p->list, l, ctl) {
194 evas_object_freeze_events_set(ctl->obj, EINA_FALSE);
198 static void _disable(void *handle)
201 struct _control *ctl;
205 _ERR("invalid parameter");
211 EINA_LIST_FOREACH(p->list, l, ctl) {
215 evas_object_freeze_events_set(ctl->obj, EINA_TRUE);
219 static void _show(void *handle)
222 struct _control *ctl;
226 _ERR("invalid parameter");
232 EINA_LIST_FOREACH(p->list, l, ctl) {
236 evas_object_show(ctl->obj);
237 elm_object_part_content_set(p->base, ctl->part, ctl->obj);
243 static void _hide(void *handle)
246 struct _control *ctl;
250 _ERR("invalid parameter");
256 EINA_LIST_FOREACH(p->list, l, ctl) {
260 elm_object_focus_set(ctl->obj, false);
262 evas_object_hide(ctl->obj);
263 elm_object_part_content_unset(p->base, ctl->part);
269 static Evas_Object *_get_object(void *handle, int loc)
272 struct _control *ctl;
275 _ERR("invalid parameter");
281 ctl = eina_list_nth(p->list, loc);
288 static int _get_count(void *handle)
293 _ERR("invalid parameter");
299 return eina_list_count(p->list);
302 static struct controller_ops _operations = {
303 .add_control = _add_control,
304 .add_callback = _add_callback,
311 .get_object = _get_object,
312 .get_count = _get_count,
315 struct controller *controller_create(Evas_Object *base)
317 struct controller *m;
321 _ERR("invalid parameter");
325 m = calloc(1, sizeof(*m));
327 _ERR("failed to allocate");
331 p = calloc(1, sizeof(*p));
333 _ERR("failed to allocate");
340 m->handle = (void *)p;
341 m->ops = &_operations;
346 void controller_destroy(struct controller *m)
349 struct _control *ctl;
358 EINA_LIST_FREE(p->list, ctl) {
360 inputmgr_remove_callback(ctl->obj, &_handler);