diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/evas/src/lib/canvas/evas_key_grab.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/evas/src/lib/canvas/evas_key_grab.c')
-rw-r--r-- | libraries/evas/src/lib/canvas/evas_key_grab.c | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/libraries/evas/src/lib/canvas/evas_key_grab.c b/libraries/evas/src/lib/canvas/evas_key_grab.c new file mode 100644 index 0000000..3fc2172 --- /dev/null +++ b/libraries/evas/src/lib/canvas/evas_key_grab.c | |||
@@ -0,0 +1,179 @@ | |||
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 | |||
10 | static Evas_Key_Grab *evas_key_grab_new (Evas_Object *obj, const char *keyname, Evas_Modifier_Mask modifiers, Evas_Modifier_Mask not_modifiers, Eina_Bool exclusive); | ||
11 | static Evas_Key_Grab *evas_key_grab_find (Evas_Object *obj, const char *keyname, Evas_Modifier_Mask modifiers, Evas_Modifier_Mask not_modifiers, Eina_Bool exclusive); | ||
12 | |||
13 | static Evas_Key_Grab * | ||
14 | evas_key_grab_new(Evas_Object *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 = 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 | g->object->grabs = eina_list_append(g->object->grabs, g); | ||
43 | if (eina_error_get()) | ||
44 | { | ||
45 | MERR_BAD(); | ||
46 | evas_mem_free(sizeof(Eina_List)); | ||
47 | g->object->grabs = eina_list_append(g->object->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 | g->object->grabs = eina_list_remove(g->object->grabs, g); | ||
66 | free(g->keyname); | ||
67 | free(g); | ||
68 | return NULL; | ||
69 | } | ||
70 | } | ||
71 | return g; | ||
72 | } | ||
73 | |||
74 | static Evas_Key_Grab * | ||
75 | evas_key_grab_find(Evas_Object *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) || (obj == g->object)) return g; | ||
88 | } | ||
89 | } | ||
90 | return NULL; | ||
91 | } | ||
92 | |||
93 | /* local calls */ | ||
94 | |||
95 | void | ||
96 | evas_object_grabs_cleanup(Evas_Object *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 | |||
120 | void | ||
121 | evas_key_grab_free(Evas_Object *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(obj, keyname, modifiers, not_modifiers, 0); | ||
127 | if (!g) return; | ||
128 | g->object->grabs = eina_list_remove(g->object->grabs, g); | ||
129 | obj->layer->evas->grabs = eina_list_remove(obj->layer->evas->grabs, g); | ||
130 | if (g->keyname) free(g->keyname); | ||
131 | free(g); | ||
132 | } | ||
133 | |||
134 | /* public calls */ | ||
135 | |||
136 | EAPI Eina_Bool | ||
137 | evas_object_key_grab(Evas_Object *obj, const char *keyname, Evas_Modifier_Mask modifiers, Evas_Modifier_Mask not_modifiers, Eina_Bool exclusive) | ||
138 | { | ||
139 | /* MEM OK */ | ||
140 | Evas_Key_Grab *g; | ||
141 | |||
142 | MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ); | ||
143 | return EINA_FALSE; | ||
144 | MAGIC_CHECK_END(); | ||
145 | if (!keyname) return EINA_FALSE; | ||
146 | if (exclusive) | ||
147 | { | ||
148 | g = evas_key_grab_find(obj, keyname, modifiers, not_modifiers, | ||
149 | exclusive); | ||
150 | if (g) return EINA_FALSE; | ||
151 | } | ||
152 | g = evas_key_grab_new(obj, keyname, modifiers, not_modifiers, exclusive); | ||
153 | if (!g) return EINA_FALSE; | ||
154 | return EINA_TRUE; | ||
155 | } | ||
156 | |||
157 | EAPI void | ||
158 | evas_object_key_ungrab(Evas_Object *obj, const char *keyname, Evas_Modifier_Mask modifiers, Evas_Modifier_Mask not_modifiers) | ||
159 | { | ||
160 | /* MEM OK */ | ||
161 | Evas_Key_Grab *g; | ||
162 | |||
163 | MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ); | ||
164 | return; | ||
165 | MAGIC_CHECK_END(); | ||
166 | if (!keyname) return; | ||
167 | g = evas_key_grab_find(obj, keyname, modifiers, not_modifiers, 0); | ||
168 | if (!g) return; | ||
169 | if (g->object->layer->evas->walking_grabs) | ||
170 | { | ||
171 | if (!g->delete_me) | ||
172 | { | ||
173 | g->object->layer->evas->delete_grabs++; | ||
174 | g->delete_me = EINA_TRUE; | ||
175 | } | ||
176 | } | ||
177 | else | ||
178 | evas_key_grab_free(g->object, keyname, modifiers, not_modifiers); | ||
179 | } | ||