elemetary - notify, factory, frame, panel, mapbuf
[framework/uifw/elementary.git] / src / bin / test_panel.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 static Elm_Genlist_Item_Class itc;
8
9 static void _bstatus(void *data, Evas_Object *obj, void *event_info);
10 static void _tstatus(void *data, Evas_Object *obj, void *event_info);
11 static char *_label_get(void *data, Evas_Object *obj, const char *source);
12 static Evas_Object *_content_get(void *data, Evas_Object *obj, const char *source);
13 static Eina_Bool _state_get(void *data, Evas_Object *obj, const char *source);
14 static void _item_del(void *data, Evas_Object *obj);
15 static void _fill_list(Evas_Object *obj);
16 static Eina_Bool _dir_has_subs(const char *path);
17
18 static void
19 _tstatus(void *data, Evas_Object *obj, void *event_info __UNUSED__)
20 {
21    Elm_Toolbar_Item *sel;
22    const char *status;
23
24    if (elm_panel_hidden_get((Evas_Object*)data))
25      status = "hidden";
26    else
27      status = "shown";
28    printf("The top panel is currently %s\n", status);
29    sel = elm_toolbar_selected_item_get(obj);
30    elm_toolbar_item_selected_set(sel, EINA_FALSE);
31 }
32
33 static void
34 _bstatus(void *data, Evas_Object *obj, void *event_info __UNUSED__)
35 {
36    Elm_Toolbar_Item *sel;
37    const char *status;
38
39    if (elm_panel_hidden_get((Evas_Object*)data))
40      status = "hidden";
41    else
42      status = "shown";
43    printf("The bottom panel is currently %s\n", status);
44    sel = elm_toolbar_selected_item_get(obj);
45    elm_toolbar_item_selected_set(sel, EINA_FALSE);
46 }
47
48 static char *
49 _label_get(void *data, Evas_Object *obj __UNUSED__, const char *source __UNUSED__)
50 {
51    return strdup(ecore_file_file_get(data));
52 }
53
54 static Evas_Object *
55 _content_get(void *data, Evas_Object *obj, const char *source)
56 {
57    if (!strcmp(source, "elm.swallow.icon"))
58      {
59         Evas_Object *ic;
60
61         ic = elm_icon_add(obj);
62         if (ecore_file_is_dir((char *)data))
63           elm_icon_standard_set(ic, "folder");
64         else
65           elm_icon_standard_set(ic, "file");
66         evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
67         evas_object_show(ic);
68         return ic;
69      }
70    return NULL;
71 }
72
73 static Eina_Bool
74 _state_get(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *source __UNUSED__)
75 {
76    return EINA_FALSE;
77 }
78
79 static void
80 _item_del(void *data, Evas_Object *obj __UNUSED__)
81 {
82    eina_stringshare_del(data);
83 }
84
85 static void
86 _fill_list(Evas_Object *obj)
87 {
88    DIR *d;
89    struct dirent *de;
90    Eina_List *dirs = NULL, *l;
91    char *real;
92
93    if (!(d = opendir(getenv("HOME")))) return;
94    while ((de = readdir(d)))
95      {
96         char buff[PATH_MAX];
97
98         if (de->d_name[0] == '.') continue;
99         snprintf(buff, sizeof(buff), "%s/%s", getenv("HOME"), de->d_name);
100         if (!ecore_file_is_dir(buff)) continue;
101         real = ecore_file_realpath(buff);
102         dirs = eina_list_append(dirs, real);
103      }
104    closedir(d);
105
106    dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
107
108    EINA_LIST_FOREACH(dirs, l, real)
109      {
110         Eina_Bool result = EINA_FALSE;
111
112         result = _dir_has_subs(real);
113         if (!result)
114           elm_genlist_item_append(obj, &itc, eina_stringshare_add(real),
115                                   NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
116         else
117           elm_genlist_item_append(obj, &itc, eina_stringshare_add(real),
118                                   NULL, ELM_GENLIST_ITEM_SUBITEMS,
119                                   NULL, NULL);
120         free(real);
121      }
122    eina_list_free(dirs);
123 }
124
125 static Eina_Bool
126 _dir_has_subs(const char *path)
127 {
128    DIR *d;
129    struct dirent *de;
130    Eina_Bool result = EINA_FALSE;
131
132    if (!path) return result;
133    if (!(d = opendir(path))) return result;
134    while ((de = readdir(d)))
135      {
136         char buff[PATH_MAX];
137
138         if (de->d_name[0] == '.') continue;
139         snprintf(buff, sizeof(buff), "%s/%s", path, de->d_name);
140         if (ecore_file_is_dir(buff))
141           {
142              result = EINA_TRUE;
143              break;
144           }
145      }
146    closedir(d);
147    return result;
148 }
149
150 void
151 test_panel(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
152 {
153    Evas_Object *win, *bg, *panel, *bx, *vbx, *toolbar;
154    Evas_Object *list;
155
156    win = elm_win_add(NULL, "panel", ELM_WIN_BASIC);
157    elm_win_title_set(win, "Panel");
158    elm_win_autodel_set(win, EINA_TRUE);
159
160    bg = elm_bg_add(win);
161    elm_win_resize_object_add(win, bg);
162    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
163    evas_object_show(bg);
164
165    vbx = elm_box_add(win);
166    elm_win_resize_object_add(win, vbx);
167    evas_object_size_hint_weight_set(vbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
168    evas_object_size_hint_align_set(vbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
169    evas_object_show(vbx);
170
171    bx = elm_box_add(win);
172    elm_box_horizontal_set(bx, EINA_TRUE);
173    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
174    evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
175    evas_object_show(bx);
176
177    panel = elm_panel_add(win);
178    elm_panel_orient_set(panel, ELM_PANEL_ORIENT_TOP);
179    evas_object_size_hint_weight_set(panel, EVAS_HINT_EXPAND, 0);
180    evas_object_size_hint_align_set(panel, EVAS_HINT_FILL, EVAS_HINT_FILL);
181
182    toolbar = elm_toolbar_add(win);
183    elm_toolbar_homogeneous_set(toolbar, 0);
184    elm_toolbar_mode_shrink_set(toolbar, ELM_TOOLBAR_SHRINK_NONE);
185    evas_object_size_hint_weight_set(toolbar, EVAS_HINT_EXPAND, 0);
186    evas_object_size_hint_align_set(toolbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
187    evas_object_show(toolbar);
188
189    elm_toolbar_item_append(toolbar, "home", "Hello", _tstatus, panel);
190
191    elm_object_content_set(panel, toolbar);
192    elm_box_pack_end(vbx, panel);
193    evas_object_show(panel);
194
195    panel = elm_panel_add(win);
196    elm_panel_orient_set(panel, ELM_PANEL_ORIENT_LEFT);
197    evas_object_size_hint_weight_set(panel, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
198    evas_object_size_hint_align_set(panel, 0, EVAS_HINT_FILL);
199
200    itc.item_style = "default";
201    itc.func.label_get = _label_get;
202    itc.func.content_get = _content_get;
203    itc.func.state_get = _state_get;
204    itc.func.del = _item_del;
205
206    list = elm_genlist_add(win);
207    evas_object_size_hint_min_set(list, 100, -1);
208    evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
209    evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
210    evas_object_show(list);
211
212    elm_object_content_set(panel, list);
213
214    elm_box_pack_end(bx, panel);
215    evas_object_show(panel);
216
217    _fill_list(list);
218
219    panel = elm_panel_add(win);
220    elm_panel_orient_set(panel, ELM_PANEL_ORIENT_RIGHT);
221    evas_object_size_hint_weight_set(panel, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
222    evas_object_size_hint_align_set(panel, 1, EVAS_HINT_FILL);
223    elm_panel_hidden_set(panel, EINA_TRUE);
224
225    list = elm_genlist_add(win);
226    evas_object_size_hint_min_set(list, 100, -1);
227    evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
228    evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
229    evas_object_show(list);
230
231    elm_object_content_set(panel, list);
232
233    elm_box_pack_end(bx, panel);
234    evas_object_show(panel);
235
236    _fill_list(list);
237
238    elm_box_pack_end(vbx, bx);
239
240    panel = elm_panel_add(win);
241    elm_panel_orient_set(panel, ELM_PANEL_ORIENT_BOTTOM);
242    evas_object_size_hint_weight_set(panel, EVAS_HINT_EXPAND, 0);
243    evas_object_size_hint_align_set(panel, EVAS_HINT_FILL, EVAS_HINT_FILL);
244    elm_panel_hidden_set(panel, EINA_TRUE);
245
246    toolbar = elm_toolbar_add(win);
247    elm_toolbar_homogeneous_set(toolbar, 0);
248    elm_toolbar_mode_shrink_set(toolbar, ELM_TOOLBAR_SHRINK_NONE);
249    evas_object_size_hint_weight_set(toolbar, EVAS_HINT_EXPAND, 0);
250    evas_object_size_hint_align_set(toolbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
251    evas_object_show(toolbar);
252
253    elm_toolbar_item_append(toolbar, "home", "Hello", _bstatus, panel);
254
255    elm_object_content_set(panel, toolbar);
256    elm_box_pack_end(vbx, panel);
257    evas_object_show(panel);
258
259    evas_object_resize(win, 320, 400);
260    evas_object_show(win);
261 }
262
263
264 #endif