diff options
Diffstat (limited to 'libraries/elementary/src/bin/test_ctxpopup.c')
-rw-r--r-- | libraries/elementary/src/bin/test_ctxpopup.c | 321 |
1 files changed, 321 insertions, 0 deletions
diff --git a/libraries/elementary/src/bin/test_ctxpopup.c b/libraries/elementary/src/bin/test_ctxpopup.c new file mode 100644 index 0000000..2933ae4 --- /dev/null +++ b/libraries/elementary/src/bin/test_ctxpopup.c | |||
@@ -0,0 +1,321 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "elementary_config.h" | ||
3 | #endif | ||
4 | #include <Elementary.h> | ||
5 | #ifndef ELM_LIB_QUICKLAUNCH | ||
6 | |||
7 | |||
8 | static void | ||
9 | _dismissed(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__) | ||
10 | { | ||
11 | Evas_Object *ctxpopup_data = evas_object_data_get(obj, "im"); | ||
12 | if (ctxpopup_data) evas_object_del(ctxpopup_data); | ||
13 | evas_object_del(obj); | ||
14 | } | ||
15 | |||
16 | static void | ||
17 | _print_current_dir(Evas_Object *obj) | ||
18 | { | ||
19 | Elm_Ctxpopup_Direction dir; | ||
20 | dir = elm_ctxpopup_direction_get(obj); | ||
21 | |||
22 | switch(dir) | ||
23 | { | ||
24 | case ELM_CTXPOPUP_DIRECTION_LEFT: | ||
25 | printf("ctxpopup direction: left!\n"); | ||
26 | break; | ||
27 | case ELM_CTXPOPUP_DIRECTION_RIGHT: | ||
28 | printf("ctxpopup direction: right!\n"); | ||
29 | break; | ||
30 | case ELM_CTXPOPUP_DIRECTION_UP: | ||
31 | printf("ctxpopup direction: up!\n"); | ||
32 | break; | ||
33 | case ELM_CTXPOPUP_DIRECTION_DOWN: | ||
34 | printf("ctxpopup direction: down!\n"); | ||
35 | break; | ||
36 | case ELM_CTXPOPUP_DIRECTION_UNKNOWN: | ||
37 | printf("ctxpopup direction: unknow!\n"); | ||
38 | break; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | static void | ||
43 | _btn_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__) | ||
44 | { | ||
45 | printf("Button Clicked\n"); | ||
46 | |||
47 | Evas_Object *im; | ||
48 | char buf[PATH_MAX]; | ||
49 | void *ctxpopup_data; | ||
50 | |||
51 | ctxpopup_data = evas_object_data_get(data, "id"); | ||
52 | if (!ctxpopup_data) return; | ||
53 | |||
54 | if (!strcmp("list_item_6", (char *) ctxpopup_data)) | ||
55 | { | ||
56 | ctxpopup_data = evas_object_data_get(data, "im"); | ||
57 | if (ctxpopup_data) return; | ||
58 | |||
59 | im = evas_object_image_filled_add(evas_object_evas_get(obj)); | ||
60 | snprintf(buf, sizeof(buf), "%s/images/%s", | ||
61 | elm_app_data_dir_get(), "twofish.jpg"); | ||
62 | evas_object_image_file_set(im, buf, NULL); | ||
63 | evas_object_move(im, 40, 40); | ||
64 | evas_object_resize(im, 320, 320); | ||
65 | evas_object_show(im); | ||
66 | evas_object_data_set((Evas_Object *)data, "im", im); | ||
67 | |||
68 | evas_object_raise((Evas_Object *)data); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | _ctxpopup_item_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info) | ||
74 | { | ||
75 | printf("ctxpopup item selected: %s\n", | ||
76 | elm_object_item_text_get(event_info)); | ||
77 | } | ||
78 | |||
79 | #define ITEM_NEW(_hov, _label, _icon) \ | ||
80 | if (_icon) \ | ||
81 | { \ | ||
82 | ic = elm_icon_add(obj); \ | ||
83 | elm_icon_standard_set(ic, _icon); \ | ||
84 | elm_icon_resizable_set(ic, EINA_FALSE, EINA_FALSE); \ | ||
85 | } \ | ||
86 | else \ | ||
87 | ic = NULL; \ | ||
88 | it = elm_ctxpopup_item_append(_hov, _label, ic, _ctxpopup_item_cb, NULL); \ | ||
89 | |||
90 | static void | ||
91 | _list_item_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
92 | { | ||
93 | Evas_Object *ctxpopup, *ic; | ||
94 | Elm_Object_Item *it; | ||
95 | Evas_Coord x,y; | ||
96 | |||
97 | ctxpopup = elm_ctxpopup_add(obj); | ||
98 | evas_object_smart_callback_add(ctxpopup, | ||
99 | "dismissed", | ||
100 | _dismissed, | ||
101 | NULL); | ||
102 | |||
103 | ITEM_NEW(ctxpopup, "Go to home folder", "home"); | ||
104 | ITEM_NEW(ctxpopup, "Save file", "file"); | ||
105 | ITEM_NEW(ctxpopup, "Delete file", "delete"); | ||
106 | ITEM_NEW(ctxpopup, "Navigate to folder", "folder"); | ||
107 | elm_object_item_disabled_set(it, EINA_TRUE); | ||
108 | ITEM_NEW(ctxpopup, "Edit entry", "edit"); | ||
109 | ITEM_NEW(ctxpopup, "Set date and time", "clock"); | ||
110 | elm_object_item_disabled_set(it, EINA_TRUE); | ||
111 | |||
112 | evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y); | ||
113 | evas_object_size_hint_max_set(ctxpopup, 240, 240); | ||
114 | evas_object_move(ctxpopup, x, y); | ||
115 | evas_object_show(ctxpopup); | ||
116 | _print_current_dir(ctxpopup); | ||
117 | } | ||
118 | |||
119 | static void | ||
120 | _list_item_cb2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
121 | { | ||
122 | Evas_Object *ctxpopup, *ic; | ||
123 | Elm_Object_Item *it; | ||
124 | Evas_Coord x,y; | ||
125 | |||
126 | ctxpopup = elm_ctxpopup_add(obj); | ||
127 | evas_object_smart_callback_add(ctxpopup, | ||
128 | "dismissed", | ||
129 | _dismissed, | ||
130 | NULL); | ||
131 | |||
132 | ITEM_NEW(ctxpopup, NULL, "home"); | ||
133 | ITEM_NEW(ctxpopup, NULL, "file"); | ||
134 | ITEM_NEW(ctxpopup, NULL, "delete"); | ||
135 | ITEM_NEW(ctxpopup, NULL, "folder"); | ||
136 | ITEM_NEW(ctxpopup, NULL, "edit"); | ||
137 | elm_object_item_disabled_set(it, EINA_TRUE); | ||
138 | ITEM_NEW(ctxpopup, NULL, "clock"); | ||
139 | |||
140 | evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y); | ||
141 | evas_object_size_hint_max_set(ctxpopup, 240, 240); | ||
142 | evas_object_move(ctxpopup, x, y); | ||
143 | evas_object_show(ctxpopup); | ||
144 | _print_current_dir(ctxpopup); | ||
145 | } | ||
146 | |||
147 | static void | ||
148 | _list_item_cb3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
149 | { | ||
150 | Evas_Object *ctxpopup, *ic; | ||
151 | Elm_Object_Item *it; | ||
152 | Evas_Coord x,y; | ||
153 | |||
154 | ctxpopup = elm_ctxpopup_add(obj); | ||
155 | evas_object_smart_callback_add(ctxpopup, | ||
156 | "dismissed", | ||
157 | _dismissed, | ||
158 | NULL); | ||
159 | |||
160 | ITEM_NEW(ctxpopup, "Eina", NULL); | ||
161 | ITEM_NEW(ctxpopup, "Eet", NULL); | ||
162 | ITEM_NEW(ctxpopup, "Evas", NULL); | ||
163 | ITEM_NEW(ctxpopup, "Ecore", NULL); | ||
164 | elm_object_item_disabled_set(it, EINA_TRUE); | ||
165 | ITEM_NEW(ctxpopup, "Embryo", NULL); | ||
166 | ITEM_NEW(ctxpopup, "Edje", NULL); | ||
167 | |||
168 | evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y); | ||
169 | evas_object_move(ctxpopup, x, y); | ||
170 | evas_object_show(ctxpopup); | ||
171 | _print_current_dir(ctxpopup); | ||
172 | } | ||
173 | |||
174 | static void | ||
175 | _list_item_cb4(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
176 | { | ||
177 | Evas_Object *ctxpopup, *ic; | ||
178 | Elm_Object_Item *it; | ||
179 | Evas_Coord x,y; | ||
180 | |||
181 | ctxpopup = elm_ctxpopup_add(obj); | ||
182 | evas_object_smart_callback_add(ctxpopup, | ||
183 | "dismissed", | ||
184 | _dismissed, | ||
185 | NULL); | ||
186 | |||
187 | elm_ctxpopup_horizontal_set(ctxpopup, EINA_TRUE); | ||
188 | |||
189 | ITEM_NEW(ctxpopup, NULL, "home"); | ||
190 | ITEM_NEW(ctxpopup, NULL, "file"); | ||
191 | ITEM_NEW(ctxpopup, NULL, "delete"); | ||
192 | ITEM_NEW(ctxpopup, NULL, "folder"); | ||
193 | ITEM_NEW(ctxpopup, NULL, "edit"); | ||
194 | ITEM_NEW(ctxpopup, NULL, "clock"); | ||
195 | |||
196 | evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y); | ||
197 | evas_object_size_hint_max_set(ctxpopup, 240, 240); | ||
198 | evas_object_move(ctxpopup, x, y); | ||
199 | evas_object_show(ctxpopup); | ||
200 | _print_current_dir(ctxpopup); | ||
201 | } | ||
202 | |||
203 | |||
204 | static void | ||
205 | _list_item_cb5(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
206 | { | ||
207 | Evas_Object *ctxpopup, *btn, *sc, *bx; | ||
208 | Evas_Coord x,y; | ||
209 | |||
210 | bx = elm_box_add(obj); | ||
211 | evas_object_size_hint_min_set(bx, 150, 150); | ||
212 | |||
213 | sc = elm_scroller_add(bx); | ||
214 | elm_scroller_bounce_set(sc, EINA_FALSE, EINA_TRUE); | ||
215 | evas_object_size_hint_fill_set(sc, EVAS_HINT_FILL, EVAS_HINT_FILL); | ||
216 | evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
217 | evas_object_show(sc); | ||
218 | |||
219 | btn = elm_button_add(sc); | ||
220 | elm_object_text_set(btn, "Enlightenment"); | ||
221 | evas_object_size_hint_min_set(btn, 140, 140); | ||
222 | |||
223 | elm_object_content_set(sc, btn); | ||
224 | |||
225 | elm_box_pack_end(bx, sc); | ||
226 | |||
227 | ctxpopup = elm_ctxpopup_add(obj); | ||
228 | evas_object_smart_callback_add(ctxpopup, | ||
229 | "dismissed", | ||
230 | _dismissed, | ||
231 | NULL); | ||
232 | |||
233 | elm_object_content_set(ctxpopup, bx); | ||
234 | |||
235 | evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y); | ||
236 | evas_object_move(ctxpopup, x, y); | ||
237 | evas_object_show(ctxpopup); | ||
238 | _print_current_dir(ctxpopup); | ||
239 | |||
240 | evas_object_smart_callback_add(btn, "clicked", _btn_clicked, "list_item_5"); | ||
241 | } | ||
242 | |||
243 | static void | ||
244 | _list_item_cb6(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
245 | { | ||
246 | Evas_Object *ctxpopup, *btn, *sc, *bx; | ||
247 | Evas_Coord x,y; | ||
248 | |||
249 | bx = elm_box_add(obj); | ||
250 | evas_object_size_hint_min_set(bx, 200, 150); | ||
251 | |||
252 | sc = elm_scroller_add(bx); | ||
253 | elm_scroller_bounce_set(sc, EINA_FALSE, EINA_TRUE); | ||
254 | evas_object_size_hint_fill_set(sc, EVAS_HINT_FILL, EVAS_HINT_FILL); | ||
255 | evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
256 | evas_object_show(sc); | ||
257 | |||
258 | btn = elm_button_add(sc); | ||
259 | elm_object_text_set(btn, "Ctxpop will be on the top of layer"); | ||
260 | evas_object_size_hint_min_set(btn, 190, 140); | ||
261 | |||
262 | elm_object_content_set(sc, btn); | ||
263 | |||
264 | elm_box_pack_end(bx, sc); | ||
265 | |||
266 | ctxpopup = elm_ctxpopup_add(obj); | ||
267 | evas_object_smart_callback_add(ctxpopup, | ||
268 | "dismissed", | ||
269 | _dismissed, | ||
270 | NULL); | ||
271 | |||
272 | elm_object_content_set(ctxpopup, bx); | ||
273 | |||
274 | evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y); | ||
275 | evas_object_move(ctxpopup, x, y); | ||
276 | evas_object_show(ctxpopup); | ||
277 | _print_current_dir(ctxpopup); | ||
278 | |||
279 | evas_object_data_set(ctxpopup, "id", "list_item_6"); | ||
280 | evas_object_smart_callback_add(btn, "clicked", _btn_clicked, ctxpopup); | ||
281 | } | ||
282 | |||
283 | static void _list_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info) | ||
284 | { | ||
285 | elm_list_item_selected_set(event_info, EINA_FALSE); | ||
286 | } | ||
287 | |||
288 | void | ||
289 | test_ctxpopup(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
290 | { | ||
291 | Evas_Object *win, *list; | ||
292 | |||
293 | win = elm_win_util_standard_add("contextual-popup", "Contextual Popup"); | ||
294 | elm_win_autodel_set(win, EINA_TRUE); | ||
295 | |||
296 | list = elm_list_add(win); | ||
297 | elm_win_resize_object_add(win, list); | ||
298 | evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
299 | elm_list_mode_set(list, ELM_LIST_COMPRESS); | ||
300 | evas_object_smart_callback_add(list, "selected", _list_clicked, NULL); | ||
301 | |||
302 | #undef ITEM_NEW | ||
303 | elm_list_item_append(list, "Ctxpopup with icons and labels", NULL, NULL, | ||
304 | _list_item_cb, NULL); | ||
305 | elm_list_item_append(list, "Ctxpopup with icons only", NULL, NULL, | ||
306 | _list_item_cb2, NULL); | ||
307 | elm_list_item_append(list, "Ctxpopup with labels only", NULL, NULL, | ||
308 | _list_item_cb3, NULL); | ||
309 | elm_list_item_append(list, "Ctxpopup at horizontal mode", NULL, NULL, | ||
310 | _list_item_cb4, NULL); | ||
311 | elm_list_item_append(list, "Ctxpopup with user content", NULL, NULL, | ||
312 | _list_item_cb5, NULL); | ||
313 | elm_list_item_append(list, "Ctxpopup with restacking", NULL, NULL, | ||
314 | _list_item_cb6, NULL); | ||
315 | evas_object_show(list); | ||
316 | elm_list_go(list); | ||
317 | |||
318 | evas_object_resize(win, 400, 400); | ||
319 | evas_object_show(win); | ||
320 | } | ||
321 | #endif | ||