e48013b6326021d44bd90cb45b49be1c77bae204
[framework/uifw/elementary.git] / src / bin / test_fileselector_button.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5
6 #ifndef ELM_LIB_QUICKLAUNCH
7 static void
8 _file_chosen(void            *data,
9              Evas_Object *obj __UNUSED__,
10              void            *event_info)
11 {
12    Evas_Object *entry = data;
13    const char *file = event_info;
14    if (file)
15      {
16         elm_entry_entry_set(entry, file);
17         printf("File chosen: %s\n", file);
18      }
19    else
20      printf("File selection canceled.\n");
21 }
22
23 static void
24 _inwin_mode_toggle(void            *data,
25                    Evas_Object *obj __UNUSED__,
26                    void *event_info __UNUSED__)
27 {
28    Evas_Object *fs_bt = data;
29    Eina_Bool value = elm_fileselector_button_inwin_mode_get(fs_bt);
30    elm_fileselector_button_inwin_mode_set(fs_bt, !value);
31    printf("Inwin mode set to: %s\n", value ? "false" : "true");
32 }
33
34 static void
35 _current_sel_toggle(void            *data,
36                     Evas_Object *obj __UNUSED__,
37                     void *event_info __UNUSED__)
38 {
39    Evas_Object *fs_bt = data;
40    Eina_Bool value = elm_fileselector_button_is_save_get(fs_bt);
41    elm_fileselector_button_is_save_set(fs_bt, !value);
42    printf("Current selection editable entry set to: %s\n",
43           value ? "false" : "true");
44 }
45
46 static void
47 _folder_only_toggle(void            *data,
48                     Evas_Object *obj __UNUSED__,
49                     void *event_info __UNUSED__)
50 {
51    Evas_Object *fs_bt = data;
52    Eina_Bool value = elm_fileselector_button_folder_only_get(fs_bt);
53    elm_fileselector_button_folder_only_set(fs_bt, !value);
54    printf("Folder only flag set to: %s\n", value ? "false" : "true");
55 }
56
57 static void
58 _expandable_toggle(void            *data,
59                    Evas_Object *obj __UNUSED__,
60                    void *event_info __UNUSED__)
61 {
62    Evas_Object *fs_bt = data;
63    Eina_Bool value = elm_fileselector_button_expandable_get(fs_bt);
64    elm_fileselector_button_expandable_set(fs_bt, !value);
65    printf("Expandable flag set to: %s\n", value ? "false" : "true");
66 }
67
68 void
69 test_fileselector_button(void *data       __UNUSED__,
70                          Evas_Object *obj __UNUSED__,
71                          void *event_info __UNUSED__)
72 {
73    Evas_Object *win, *bg, *vbox, *hbox, *ic, *bt, *fs_bt, *en, *lb;
74
75    win = elm_win_add(NULL, "fileselector-button", ELM_WIN_BASIC);
76    elm_win_title_set(win, "File Selector Button");
77    elm_win_autodel_set(win, 1);
78
79    bg = elm_bg_add(win);
80    elm_win_resize_object_add(win, bg);
81    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
82    evas_object_show(bg);
83
84    vbox = elm_box_add(win);
85    elm_win_resize_object_add(win, vbox);
86    evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
87    evas_object_show(vbox);
88
89    /* file selector button */
90    ic = elm_icon_add(win);
91    elm_icon_standard_set(ic, "file");
92    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
93    fs_bt = elm_fileselector_button_add(win);
94    elm_fileselector_button_label_set(fs_bt, "Select a file");
95    elm_fileselector_button_icon_set(fs_bt, ic);
96
97    elm_box_pack_end(vbox, fs_bt);
98    evas_object_show(fs_bt);
99    evas_object_show(ic);
100
101    /* attribute setting buttons */
102    hbox = elm_box_add(win);
103    elm_box_horizontal_set(hbox, EINA_TRUE);
104    elm_box_pack_end(vbox, hbox);
105    evas_object_show(hbox);
106
107    bt = elm_button_add(win);
108    elm_object_text_set(bt, "Toggle current selection text entry");
109    evas_object_smart_callback_add(bt, "clicked", _current_sel_toggle, fs_bt);
110    elm_box_pack_end(hbox, bt);
111    evas_object_show(bt);
112
113    bt = elm_button_add(win);
114    elm_object_text_set(bt, "Toggle inwin mode");
115    evas_object_smart_callback_add(bt, "clicked", _inwin_mode_toggle, fs_bt);
116    elm_box_pack_end(hbox, bt);
117    evas_object_show(bt);
118
119    bt = elm_button_add(win);
120    elm_object_text_set(bt, "Toggle folder only mode");
121    evas_object_smart_callback_add(bt, "clicked", _folder_only_toggle, fs_bt);
122    elm_box_pack_end(hbox, bt);
123    evas_object_show(bt);
124
125    bt = elm_button_add(win);
126    elm_object_text_set(bt, "Toggle expandable mode");
127    evas_object_smart_callback_add(bt, "clicked", _expandable_toggle, fs_bt);
128    elm_box_pack_end(hbox, bt);
129    evas_object_show(bt);
130
131    lb = elm_label_add(win);
132    elm_object_text_set(lb, "Last selection:");
133    elm_box_pack_end(vbox, lb);
134    evas_object_show(lb);
135
136    en = elm_entry_add(win);
137    elm_entry_line_wrap_set(en, EINA_FALSE);
138    elm_entry_editable_set(en, EINA_FALSE);
139    evas_object_smart_callback_add(fs_bt, "file,chosen", _file_chosen, en);
140    elm_box_pack_end(vbox, en);
141    evas_object_show(en);
142
143    evas_object_resize(win, 400, 400);
144    evas_object_show(win);
145 }
146
147 #endif