summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/evas_key_grab.c
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-11-04 11:51:42 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-11-04 11:51:42 +0000
commitc15e9c6575c3b5f39ded167dda5259de3de96151 (patch)
tree5115d7ae3620af24c2bc094cd062575af7adeda9 /src/lib/evas/canvas/evas_key_grab.c
parenta5ac6a987caec5a7f7596a25d0a065b9cc94c50c (diff)
merge: and now Evas
I've tested make -j 3 install and it works nicely I've tested expedite with software and opengl xlib, and it works. Not tested other engines, so please report any problems (engines or other) on the ML. TODO: examples and tests, I'll add them later ISSUE: Eina_Unicode size check. It indirectly depends on eina_config.h, which is created at the end of the configure script. So its size is always 0. I don't know how that size is used, so I can't do a lot, for now. SVN revision: 78895
Diffstat (limited to 'src/lib/evas/canvas/evas_key_grab.c')
-rw-r--r--src/lib/evas/canvas/evas_key_grab.c208
1 files changed, 208 insertions, 0 deletions
diff --git a/src/lib/evas/canvas/evas_key_grab.c b/src/lib/evas/canvas/evas_key_grab.c
new file mode 100644
index 0000000..85e1761
--- /dev/null
+++ b/src/lib/evas/canvas/evas_key_grab.c
@@ -0,0 +1,208 @@
1#include "evas_common.h"
2#include "evas_private.h"
3
4/* private calls */
5
6/* FIXME: this is not optimal, but works. i should have a hash of keys per */
7/* Evas and then a linked lists of grabs for that key and what */
8/* modifiers/not_modifers they use */
9
10static Evas_Key_Grab *evas_key_grab_new (Evas_Object *eo_obj, Evas_Object_Protected_Data *obj, const char *keyname, Evas_Modifier_Mask modifiers, Evas_Modifier_Mask not_modifiers, Eina_Bool exclusive);
11static Evas_Key_Grab *evas_key_grab_find (Evas_Object *eo_obj, Evas_Object_Protected_Data *obj, const char *keyname, Evas_Modifier_Mask modifiers, Evas_Modifier_Mask not_modifiers, Eina_Bool exclusive);
12
13static Evas_Key_Grab *
14evas_key_grab_new(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj, const char *keyname, Evas_Modifier_Mask modifiers, Evas_Modifier_Mask not_modifiers, Eina_Bool exclusive)
15{
16 /* MEM OK */
17 Evas_Key_Grab *g;
18
19 g = evas_mem_calloc(sizeof(Evas_Key_Grab));
20 if (!g) return NULL;
21 g->object = eo_obj;
22 g->modifiers = modifiers;
23 g->not_modifiers = not_modifiers;
24 g->exclusive = exclusive;
25 g->keyname = strdup(keyname);
26 if (obj->layer->evas->walking_grabs)
27 g->just_added = EINA_TRUE;
28 if (!g->keyname)
29 {
30 if (!evas_mem_free(strlen(keyname) + 1))
31 {
32 free(g);
33 return NULL;
34 }
35 g->keyname = strdup(keyname);
36 if (!g->keyname)
37 {
38 free(g);
39 return NULL;
40 }
41 }
42 obj->grabs = eina_list_append(obj->grabs, g);
43 if (eina_error_get())
44 {
45 MERR_BAD();
46 evas_mem_free(sizeof(Eina_List));
47 obj->grabs = eina_list_append(obj->grabs, g);
48 if (eina_error_get())
49 {
50 MERR_FATAL();
51 free(g->keyname);
52 free(g);
53 return NULL;
54 }
55 }
56 obj->layer->evas->grabs = eina_list_append(obj->layer->evas->grabs, g);
57 if (eina_error_get())
58 {
59 MERR_BAD();
60 evas_mem_free(sizeof(Eina_List));
61 obj->layer->evas->grabs = eina_list_append(obj->layer->evas->grabs, g);
62 if (eina_error_get())
63 {
64 MERR_FATAL();
65 obj->grabs = eina_list_remove(obj->grabs, g);
66 free(g->keyname);
67 free(g);
68 return NULL;
69 }
70 }
71 return g;
72}
73
74static Evas_Key_Grab *
75evas_key_grab_find(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj, const char *keyname, Evas_Modifier_Mask modifiers, Evas_Modifier_Mask not_modifiers, Eina_Bool exclusive)
76{
77 /* MEM OK */
78 Eina_List *l;
79 Evas_Key_Grab *g;
80
81 EINA_LIST_FOREACH(obj->layer->evas->grabs, l, g)
82 {
83 if ((g->modifiers == modifiers) &&
84 (g->not_modifiers == not_modifiers) &&
85 (!strcmp(g->keyname, keyname)))
86 {
87 if ((exclusive) || (eo_obj == g->object)) return g;
88 }
89 }
90 return NULL;
91}
92
93/* local calls */
94
95void
96evas_object_grabs_cleanup(Evas_Object *eo_obj EINA_UNUSED, Evas_Object_Protected_Data *obj)
97{
98 if (obj->layer->evas->walking_grabs)
99 {
100 Eina_List *l;
101 Evas_Key_Grab *g;
102
103 EINA_LIST_FOREACH(obj->grabs, l, g)
104 g->delete_me = EINA_TRUE;
105 }
106 else
107 {
108 while (obj->grabs)
109 {
110 Evas_Key_Grab *g = obj->grabs->data;
111 if (g->keyname) free(g->keyname);
112 free(g);
113 obj->layer->evas->grabs = eina_list_remove(obj->layer->evas->grabs,
114 g);
115 obj->grabs = eina_list_remove(obj->grabs, g);
116 }
117 }
118}
119
120void
121evas_key_grab_free(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj, const char *keyname, Evas_Modifier_Mask modifiers, Evas_Modifier_Mask not_modifiers)
122{
123 /* MEM OK */
124 Evas_Key_Grab *g;
125
126 g = evas_key_grab_find(eo_obj, obj, keyname, modifiers, not_modifiers, 0);
127 if (!g) return;
128 Evas_Object_Protected_Data *g_object = eo_data_get(g->object, EVAS_OBJ_CLASS);
129 g_object->grabs = eina_list_remove(g_object->grabs, g);
130 obj->layer->evas->grabs = eina_list_remove(obj->layer->evas->grabs, g);
131 if (g->keyname) free(g->keyname);
132 free(g);
133}
134
135/* public calls */
136
137EAPI Eina_Bool
138evas_object_key_grab(Evas_Object *eo_obj, const char *keyname, Evas_Modifier_Mask modifiers, Evas_Modifier_Mask not_modifiers, Eina_Bool exclusive)
139{
140 MAGIC_CHECK(eo_obj, Evas_Object, MAGIC_OBJ);
141 return EINA_FALSE;
142 MAGIC_CHECK_END();
143 Eina_Bool ret = EINA_FALSE;
144 eo_do(eo_obj, evas_obj_key_grab(keyname, modifiers, not_modifiers, exclusive, &ret));
145 return ret;
146}
147
148void
149_key_grab(Eo *eo_obj, void *_pd, va_list *list)
150{
151 const char *keyname = va_arg(*list, const char *);
152 Evas_Modifier_Mask modifiers = va_arg(*list, Evas_Modifier_Mask);
153 Evas_Modifier_Mask not_modifiers = va_arg(*list, Evas_Modifier_Mask);
154 Eina_Bool exclusive = va_arg(*list, int);
155 Eina_Bool *ret = va_arg(*list, Eina_Bool *);
156
157 /* MEM OK */
158 Evas_Key_Grab *g;
159
160 Evas_Object_Protected_Data *obj = _pd;
161 if (!keyname)
162 *ret = EINA_FALSE;
163 if (exclusive)
164 {
165 g = evas_key_grab_find(eo_obj, obj, keyname, modifiers, not_modifiers,
166 exclusive);
167 if (g)
168 *ret = EINA_FALSE;
169 }
170 g = evas_key_grab_new(eo_obj, obj, keyname, modifiers, not_modifiers, exclusive);
171 *ret = (!g) ? EINA_FALSE : EINA_TRUE;
172}
173
174EAPI void
175evas_object_key_ungrab(Evas_Object *eo_obj, const char *keyname, Evas_Modifier_Mask modifiers, Evas_Modifier_Mask not_modifiers)
176{
177 MAGIC_CHECK(eo_obj, Evas_Object, MAGIC_OBJ);
178 return;
179 MAGIC_CHECK_END();
180 eo_do(eo_obj, evas_obj_key_ungrab(keyname, modifiers, not_modifiers));
181}
182
183void
184_key_ungrab(Eo *eo_obj, void *_pd, va_list *list)
185{
186 const char *keyname = va_arg(*list, const char *);
187 Evas_Modifier_Mask modifiers = va_arg(*list, Evas_Modifier_Mask);
188 Evas_Modifier_Mask not_modifiers = va_arg(*list, Evas_Modifier_Mask);
189
190 /* MEM OK */
191 Evas_Key_Grab *g;
192
193 if (!keyname) return;
194 Evas_Object_Protected_Data *obj = _pd;
195 g = evas_key_grab_find(eo_obj, obj, keyname, modifiers, not_modifiers, 0);
196 if (!g) return;
197 Evas_Object_Protected_Data *g_object = eo_data_get(g->object, EVAS_OBJ_CLASS);
198 if (g_object->layer->evas->walking_grabs)
199 {
200 if (!g->delete_me)
201 {
202 g_object->layer->evas->delete_grabs++;
203 g->delete_me = EINA_TRUE;
204 }
205 }
206 else
207 evas_key_grab_free(g->object, g_object, keyname, modifiers, not_modifiers);
208}