tizen 2.4 release
[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 Eina_Bool __x_keydown_cb(void *data, int type, void *event)
34 {
35         int id = (int)data;
36         Ecore_Event_Key *ev = event;
37
38         if (ev == NULL)
39                 return 0;
40
41         X_syspopup_process_keydown(id, ev->keyname);
42
43         return ECORE_CALLBACK_DONE;
44 }
45
46 #ifdef ROTATE_USING_X_CLIENT
47 static Eina_Bool __x_rotate_cb(void *data, int type, void *event)
48 {
49         int id = (int)data;
50         Ecore_X_Event_Client_Message *ev = event;
51
52         if (!event)
53                 return ECORE_CALLBACK_RENEW;
54
55         if (ev->message_type == ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE)
56                 X_syspopup_process_rotate(id);
57
58         return ECORE_CALLBACK_RENEW;
59 }
60
61 static int __efl_rotate(Display *dpy, Window win, syspopup *sp)
62 {
63         int rotation;
64
65         rotation = X_syspopup_rotation_get(dpy, win);
66
67         if (rotation == -1) {
68                 rotation = 0;
69         }
70
71         if (rotation >= 0)
72                 elm_win_rotation_with_resize_set(sp->win, rotation);
73
74         return 0;
75 }
76 #else
77 static int __efl_rotate(Display *dpy, Window win, syspopup *sp)
78 {
79         return 0;
80 }
81 #endif
82
83 API int syspopup_create(bundle *b, syspopup_handler *handler,
84                         Evas_Object *parent, void *user_data)
85 {
86         Ecore_X_Window xwin;
87         Display *dpy;
88         const char *popup_name;
89         syspopup *sp = NULL;
90         int id;
91         XWindowAttributes attr;
92
93         popup_name = _syspopup_get_name_from_bundle(b);
94         if (popup_name == NULL || handler == NULL) {
95                 _E("popup_name or handler is NULL");
96                 return -1;
97         }
98
99         if (parent == NULL) {
100                 _E("parent window is NULL");
101                 return -1;
102         }
103
104         sp = _syspopup_find(popup_name);
105         if (sp) {
106                 _E("already exist - syspopup %s", popup_name);
107                 return -1;
108         } else {
109                 xwin = elm_win_xwindow_get(parent);
110                 dpy = ecore_x_display_get();
111
112                 id = X_make_syspopup(b, dpy, xwin, parent, __efl_rotate,
113                                      handler, user_data);
114                 if (id < 0) {
115                         _E("fail to make X syspopup");
116                         return -1;
117                 }
118
119                 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __x_keydown_cb,
120                                         (void *)id);
121
122                 /* X_syspopup_core should process 2 events */
123                 /* First, rotate event */
124                 /* Second, keydown event */
125 #ifdef ROTATE_USING_X_CLIENT
126                 ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,__x_rotate_cb, (void *)id);
127 #endif
128         }
129
130         return 0;
131 }
132
133 API int syspopup_reset(bundle *b)
134 {
135         return X_syspopup_reset(b);
136 }
137