4360b013cd2cfb6c1aee459235e9c5339dd25d41
[framework/base/syspopup.git] / syspopup / syspopup_efl.c
1 /*
2  * syspopup
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23
24 #include "syspopup_core.h"
25 #include "syspopup.h"
26 #include "syspopup_api.h"
27 #include "simple_util.h"
28 #include <Evas.h>
29 #include <Ecore.h>
30 #include <Ecore_Input.h>
31 #include <Ecore_X.h>
32
33 static void __elm_popupwin_del_cb(void *data, Evas * e, Evas_Object * obj,
34                                   void *event_info)
35 {
36         int id;
37
38         id = (int)data;
39         _D("callback del called, destroy internal data - id = %d\n", id);
40
41         _syspopup_del(id);
42 }
43
44 static Eina_Bool __x_keydown_cb(void *data, int type, void *event)
45 {
46         int id = (int)data;
47         Ecore_Event_Key *ev = event;
48
49         if (ev == NULL)
50                 return 0;
51
52         X_syspopup_process_keydown(id, ev->keyname);
53
54         return ECORE_CALLBACK_DONE;
55 }
56
57 static Eina_Bool __x_rotate_cb(void *data, int type, void *event)
58 {
59         int id = (int)data;
60         Ecore_X_Event_Client_Message *ev = event;
61
62         if (!event)
63                 return ECORE_CALLBACK_RENEW;
64
65         if (ev->message_type == ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE)
66                 X_syspopup_process_rotate(id);
67
68         return ECORE_CALLBACK_RENEW;
69 }
70
71 static int __efl_rotate(Display *dpy, Window win, syspopup *sp)
72 {
73         int rotation;
74
75         rotation = X_syspopup_rotation_get(dpy, win);
76
77         if (rotation == -1) {
78                 rotation = 0;
79         }
80
81         if (rotation >= 0)
82                 elm_win_rotation_with_resize_set(sp->win, rotation);
83
84         return 0;
85 }
86
87 API int syspopup_create(bundle *b, syspopup_handler *handler,
88                         Evas_Object *parent, void *user_data)
89 {
90         Ecore_X_Window xwin;
91         Display *dpy;
92         const char *popup_name;
93         syspopup *sp = NULL;
94         int id;
95         XWindowAttributes attr;
96         int is_unviewable = 0;
97
98         popup_name = _syspopup_get_name_from_bundle(b);
99         if (popup_name == NULL || handler == NULL) {
100                 _E("popup_name or handler is NULL");
101                 return -1;
102         }
103
104         if (parent == NULL) {
105                 _E("parent window is NULL");
106                 return -1;
107         }
108
109         sp = _syspopup_find(popup_name);
110         if (sp) {
111                 _E("already exist - syspopup %s", popup_name);
112                 return -1;
113         } else {
114                 xwin = elm_win_xwindow_get(parent);
115                 dpy = ecore_x_display_get();
116
117                 id = X_make_syspopup(b, dpy, xwin, parent, __efl_rotate,
118                                      handler, user_data);
119                 if (id < 0) {   
120                         _E("fail to make X syspopup");
121                         return -1;
122                 }
123
124                 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __x_keydown_cb,
125                                         (void *)id);
126
127                 evas_object_event_callback_add(parent, EVAS_CALLBACK_DEL,
128                                          __elm_popupwin_del_cb, (void *)id);
129
130                 /* X_syspopup_core should process 2 events */
131                 /* First, rotate event */
132                 /* Second, keydown event */
133                 ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
134                                         __x_rotate_cb, (void *)id);
135
136         }
137
138         return 0;
139 }
140
141 API int syspopup_reset(bundle *b)
142 {
143         return X_syspopup_reset(b);
144 }
145