summaryrefslogtreecommitdiff
path: root/src/examples/elementary/hoversel_example_01.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-03-23 12:56:14 -0700
committerCedric BAIL <cedric@osg.samsung.com>2016-03-23 13:24:41 -0700
commitc2a1c49ab2042f559b28e840e54feb8494888e0e (patch)
treec6eb110b7c479499854eede9d0c3ab0a80c9a11a /src/examples/elementary/hoversel_example_01.c
parent9340855597e7e465435c69b6278650346688da14 (diff)
elementary: move all legacy files to their expected new location.
Diffstat (limited to 'src/examples/elementary/hoversel_example_01.c')
-rw-r--r--src/examples/elementary/hoversel_example_01.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/examples/elementary/hoversel_example_01.c b/src/examples/elementary/hoversel_example_01.c
new file mode 100644
index 0000000000..2c6f70a8f5
--- /dev/null
+++ b/src/examples/elementary/hoversel_example_01.c
@@ -0,0 +1,128 @@
1//Compile with:
2//gcc -o hoversel_example_01 hoversel_example_01.c -g `pkg-config --cflags --libs elementary`
3
4#include <Elementary.h>
5
6static void _print_items(void *data, Evas_Object *obj, void *event_info);
7static void _free(void *data, Evas_Object *obj, void *event_info);
8static void _add_item(void *data, Evas_Object *obj, void *event_info);
9
10static void
11_clear_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
12{
13 if (!data) return;
14 elm_hoversel_clear((Evas_Object *)data);
15}
16
17static void
18_reverse_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
19{
20 if (!data) return;
21 elm_object_mirrored_set(data, !elm_object_mirrored_get (data));
22 printf("\nMirrored mode is now %s", elm_object_mirrored_get(data) ? "ON" : "OFF" );
23 fflush(stdout);
24}
25
26Eina_Bool is_eng = EINA_TRUE;
27static void
28_arabic_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
29{
30 if (!data) return;
31 is_eng = !is_eng;
32 elm_object_text_set(data, is_eng ?
33 "Enable Arabic for new items" :
34 "Enable English for new items");
35}
36
37EAPI_MAIN int
38elm_main(int argc, char **argv)
39{
40 Evas_Object *win, *rect, *hoversel, *btn = NULL;
41
42 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
43
44 win = elm_win_util_standard_add("hoversel", "Hoversel");
45 elm_win_autodel_set(win, EINA_TRUE);
46
47 rect = evas_object_rectangle_add(evas_object_evas_get(win));
48 evas_object_color_set(rect, 255, 0, 0, 255);
49 evas_object_show(rect);
50
51 hoversel = elm_hoversel_add(win);
52 elm_hoversel_hover_parent_set(hoversel, win);
53 elm_hoversel_horizontal_set(hoversel, EINA_FALSE);
54 elm_object_text_set(hoversel, "Add an item to Hoversel");
55 elm_object_part_content_set(hoversel, "icon", rect);
56 elm_hoversel_item_add(hoversel, "Print items", NULL, ELM_ICON_NONE,
57 _print_items, NULL);
58 elm_hoversel_item_add(hoversel, "Option 2", "home", ELM_ICON_STANDARD, NULL,
59 NULL);
60 evas_object_smart_callback_add(hoversel, "clicked", _add_item, NULL);
61
62 evas_object_resize(hoversel, 180, 30);
63 evas_object_move(hoversel, 10, 10);
64 evas_object_show(hoversel);
65
66 btn = elm_button_add(win);
67 elm_object_text_set(btn, "Clear all Items");
68 evas_object_smart_callback_add(btn, "clicked", _clear_btn_clicked_cb, hoversel);
69 evas_object_resize(btn, 180, 30);
70 evas_object_move(btn, 10, 50);
71 evas_object_show(btn);
72
73 btn = elm_button_add(win);
74 elm_object_text_set(btn, "Change Mirror Mode");
75 evas_object_smart_callback_add(btn, "clicked", _reverse_btn_clicked_cb, hoversel);
76 evas_object_resize(btn, 180, 30);
77 evas_object_move(btn, 10, 90);
78 evas_object_show(btn);
79
80 btn = elm_button_add(win);
81 elm_object_text_set(btn, "Enable Arabic for new items");
82 evas_object_smart_callback_add(btn, "clicked", _arabic_btn_clicked_cb, btn);
83 evas_object_resize(btn, 180, 30);
84 evas_object_move(btn, 10, 130);
85 evas_object_show(btn);
86
87 evas_object_resize(win, 200, 300);
88 evas_object_show(win);
89
90 elm_run();
91
92 return 0;
93}
94ELM_MAIN()
95
96static void
97_print_items(void *data, Evas_Object *obj, void *event_info)
98{
99 const Eina_List *items = elm_hoversel_items_get(obj);
100 const Eina_List *l;
101 Elm_Object_Item *hoversel_it;
102
103 EINA_LIST_FOREACH(items, l, hoversel_it)
104 printf("%s\n", elm_object_item_text_get(hoversel_it));
105}
106
107static void
108_add_item(void *data, Evas_Object *obj, void *event_info)
109{
110 static int num = 0;
111 char *str = malloc(sizeof(char) * 11);
112 Elm_Object_Item *hoversel_it;
113
114 if(is_eng)
115 snprintf(str, 11, "item %d", ++num);
116 else
117 snprintf(str, 11, "بند %d", ++num);
118
119 hoversel_it = elm_hoversel_item_add(obj, str, NULL, ELM_ICON_NONE, NULL,
120 str);
121 elm_object_item_del_cb_set(hoversel_it, _free);
122}
123
124static void
125_free(void *data, Evas_Object *obj, void *event_info)
126{
127 free(data);
128}