Clean up file mode
[platform/core/base/syspopup.git] / syspopup / syspopup_efl.c
1 /*
2  * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <Evas.h>
18 #include <Ecore.h>
19 #include <Ecore_Input.h>
20
21 #include "syspopup_core.h"
22 #include "syspopup.h"
23 #include "syspopup_api.h"
24 #include "simple_util.h"
25 #include "syspopup_wayland.h"
26
27 static Eina_Bool __keydown_cb(void *data, int type, void *event)
28 {
29         int id = (int)((intptr_t)data);
30         Ecore_Event_Key *ev = event;
31
32         if (ev == NULL)
33                 return ECORE_CALLBACK_DONE;
34
35         wl_syspopup_process_keypress(id, ev->keyname);
36
37         return ECORE_CALLBACK_PASS_ON;
38 }
39
40 static int __efl_rotate_cb(void *d, void *w, void *s)
41 {
42         return 0;
43 }
44
45 int syspopup_efl_create(const char *popup_name, bundle *b, Evas_Object *parent,
46                         syspopup_handler *handler, void *user_data)
47 {
48         syspopup *sp;
49         syspopup_info_t *info;
50
51         info = _syspopup_info_get(popup_name);
52         if (info == NULL) {
53                 _E("Failed to get syspopup info: %s", popup_name);
54                 return -1;
55         }
56
57         sp = (syspopup *)malloc(sizeof(syspopup));
58         if (sp == NULL) {
59                 _syspopup_info_free(info);
60                 return -1;
61         }
62
63         sp->name = strdup(info->name);
64         sp->def_term_fn = handler->def_term_fn;
65         sp->def_timeout_fn = handler->def_timeout_fn;
66         sp->user_data = user_data;
67         sp->win = (void *)parent;
68         sp->timeout_id = 0;
69         sp->dupped_bundle = bundle_dup(b);
70         sp->rotate_cb = __efl_rotate_cb;
71
72         _syspopup_add_new(sp);
73         _syspopup_set_term_type(sp, info);
74         _syspopup_set_endkey_type(sp, info);
75
76         sp->internal_data = (void *)elm_win_wl_window_get(parent);
77         if (wl_syspopup_init(sp, info) < 0) {
78                 _syspopup_info_free(info);
79                 _syspopup_del(sp->id);
80                 return -1;
81         }
82
83         _syspopup_reset_timeout(sp, info);
84         if (sp->endkey_act != SYSPOPUP_KEYEND_IGNORE) {
85                 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __keydown_cb,
86                                         (const void *)((intptr_t)sp->id));
87         }
88
89         _syspopup_info_free(info);
90
91         return sp->id;
92 }
93
94 int syspopup_efl_reset(bundle *b)
95 {
96         return wl_syspopup_reset(b);
97 }