Initialize Tizen 2.3
[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         int is_unviewable = 0;
93
94         popup_name = _syspopup_get_name_from_bundle(b);
95         if (popup_name == NULL || handler == NULL) {
96                 _E("popup_name or handler is NULL");
97                 return -1;
98         }
99
100         if (parent == NULL) {
101                 _E("parent window is NULL");
102                 return -1;
103         }
104
105         sp = _syspopup_find(popup_name);
106         if (sp) {
107                 _E("already exist - syspopup %s", popup_name);
108                 return -1;
109         } else {
110                 xwin = elm_win_xwindow_get(parent);
111                 dpy = ecore_x_display_get();
112
113                 id = X_make_syspopup(b, dpy, xwin, parent, __efl_rotate,
114                                      handler, user_data);
115                 if (id < 0) {
116                         _E("fail to make X syspopup");
117                         return -1;
118                 }
119
120                 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __x_keydown_cb,
121                                         (void *)id);
122
123                 /* X_syspopup_core should process 2 events */
124                 /* First, rotate event */
125                 /* Second, keydown event */
126 #ifdef ROTATE_USING_X_CLIENT
127                 ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,__x_rotate_cb, (void *)id);
128 #endif
129         }
130
131         return 0;
132 }
133
134 API int syspopup_reset(bundle *b)
135 {
136         return X_syspopup_reset(b);
137 }
138