1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
8 Evas_Object *self, *btn, *fs, *fsw;
9 const char *window_title;
14 Eina_Bool expandable : 1;
15 Eina_Bool folder_only : 1;
16 Eina_Bool is_save : 1;
18 Eina_Bool inwin_mode : 1;
21 #define DEFAULT_WINDOW_TITLE "Select a file"
23 static const char *widtype = NULL;
25 static void _del_hook(Evas_Object *obj);
26 static void _theme_hook(Evas_Object *obj);
27 static void _disable_hook(Evas_Object *obj);
28 static void _sizing_eval(Evas_Object *obj);
29 static void _changed_size_hints(void *data,
33 static void _on_focus_hook(void *data,
35 static void _selection_done(void *data,
38 static void _activate(Widget_Data *wd);
40 static const char SIG_FILE_CHOSEN[] = "file,chosen";
41 static const Evas_Smart_Cb_Description _signals[] = {
42 {SIG_FILE_CHOSEN, "s"},
47 _del_hook(Evas_Object *obj)
52 wd = elm_widget_data_get(obj);
55 if (wd->window_title) eina_stringshare_del(wd->window_title);
56 if (wd->fsd.path) eina_stringshare_del(wd->fsd.path);
59 win = evas_object_data_del(obj, "win");
66 _on_focus_hook(void *data __UNUSED__,
69 Widget_Data *wd = elm_widget_data_get(obj);
71 if (elm_widget_focus_get(obj))
72 elm_widget_focus_steal(wd->btn);
76 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
78 Widget_Data *wd = elm_widget_data_get(obj);
80 elm_widget_mirrored_set(wd->btn, rtl);
81 elm_widget_mirrored_set(wd->fs, rtl);
85 _theme_hook(Evas_Object *obj)
87 Widget_Data *wd = elm_widget_data_get(obj);
90 _elm_widget_mirrored_reload(obj);
91 _mirrored_set(obj, elm_widget_mirrored_get(obj));
93 snprintf(buf, sizeof(buf), "fileselector_button/%s",
94 elm_widget_style_get(obj));
95 elm_object_style_set(wd->btn, buf);
100 _disable_hook(Evas_Object *obj)
102 Widget_Data *wd = elm_widget_data_get(obj);
104 elm_widget_disabled_set(wd->btn, elm_widget_disabled_get(obj));
108 _sizing_eval(Evas_Object *obj)
110 Widget_Data *wd = elm_widget_data_get(obj);
111 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
113 evas_object_size_hint_min_get(wd->btn, &minw, &minh);
114 evas_object_size_hint_max_get(wd->btn, &maxw, &maxh);
115 evas_object_size_hint_min_set(obj, minw, minh);
116 evas_object_size_hint_max_set(obj, maxw, maxh);
120 _changed_size_hints(void *data,
122 Evas_Object *obj __UNUSED__,
123 void *event_info __UNUSED__)
125 Widget_Data *wd = elm_widget_data_get(data);
131 _activate_hook(Evas_Object *obj)
134 wd = elm_widget_data_get(obj);
140 _button_clicked(void *data,
141 Evas_Object *obj __UNUSED__,
142 void *event_info __UNUSED__)
148 _parent_win_get(Evas_Object *obj)
150 while ((obj) && (strcmp(elm_widget_type_get(obj), "win")))
151 obj = elm_object_parent_widget_get(obj);
157 _new_window_add(Widget_Data *wd)
159 Evas_Object *win, *bg;
161 win = elm_win_add(NULL, "fileselector_button", ELM_WIN_DIALOG_BASIC);
162 elm_win_title_set(win, wd->window_title);
163 elm_win_autodel_set(win, EINA_TRUE);
165 bg = elm_bg_add(win);
166 elm_win_resize_object_add(win, bg);
167 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
168 evas_object_show(bg);
170 evas_object_resize(win, wd->w, wd->h);
175 _activate(Widget_Data *wd)
177 Eina_Bool is_inwin = EINA_FALSE;
183 wd->fsw = _parent_win_get(wd->self);
186 wd->fsw = _new_window_add(wd);
189 wd->fsw = elm_win_inwin_add(wd->fsw);
190 is_inwin = EINA_TRUE;
194 wd->fsw = _new_window_add(wd);
196 wd->fs = elm_fileselector_add(wd->fsw);
197 elm_widget_mirrored_set(wd->fs, elm_widget_mirrored_get(wd->self));
198 elm_widget_mirrored_automatic_set(wd->fs, EINA_FALSE);
199 elm_fileselector_expandable_set(wd->fs, wd->fsd.expandable);
200 elm_fileselector_folder_only_set(wd->fs, wd->fsd.folder_only);
201 elm_fileselector_is_save_set(wd->fs, wd->fsd.is_save);
202 elm_fileselector_selected_set(wd->fs, wd->fsd.path);
203 evas_object_size_hint_weight_set(wd->fs, EVAS_HINT_EXPAND,
205 evas_object_size_hint_align_set(wd->fs, EVAS_HINT_FILL, EVAS_HINT_FILL);
206 evas_object_smart_callback_add(wd->fs, "done", _selection_done, wd);
207 evas_object_show(wd->fs);
211 elm_win_inwin_content_set(wd->fsw, wd->fs);
212 elm_win_inwin_activate(wd->fsw);
216 elm_win_resize_object_add(wd->fsw, wd->fs);
217 evas_object_show(wd->fsw);
222 _selection_done(void *data,
223 Evas_Object *obj __UNUSED__,
226 const char *file = event_info;
227 Widget_Data *wd = data;
231 if (file) eina_stringshare_replace(&wd->fsd.path, file);
236 evas_object_del(del);
238 evas_object_smart_callback_call(wd->self, SIG_FILE_CHOSEN,
239 (void *)wd->fsd.path);
243 _elm_fileselector_button_label_set(Evas_Object *obj, const char *item,
246 ELM_CHECK_WIDTYPE(obj, widtype);
247 if (item && strcmp(item, "default")) return;
248 Widget_Data *wd = elm_widget_data_get(obj);
250 elm_object_text_set(wd->btn, label);
254 _elm_fileselector_button_label_get(const Evas_Object *obj, const char *item)
256 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
257 Widget_Data *wd = elm_widget_data_get(obj);
258 if (item && strcmp(item, "default")) return NULL;
259 if (!wd) return NULL;
260 return elm_object_text_get(wd->btn);
264 elm_fileselector_button_add(Evas_Object *parent)
270 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
272 ELM_SET_WIDTYPE(widtype, "fileselector_button");
273 elm_widget_type_set(obj, "fileselector_button");
274 elm_widget_sub_object_add(parent, obj);
275 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
276 elm_widget_data_set(obj, wd);
277 elm_widget_del_hook_set(obj, _del_hook);
278 elm_widget_theme_hook_set(obj, _theme_hook);
279 elm_widget_disable_hook_set(obj, _disable_hook);
280 elm_widget_can_focus_set(obj, EINA_TRUE);
281 elm_widget_activate_hook_set(obj, _activate_hook);
282 elm_widget_text_set_hook_set(obj, _elm_fileselector_button_label_set);
283 elm_widget_text_get_hook_set(obj, _elm_fileselector_button_label_get);
286 wd->window_title = eina_stringshare_add(DEFAULT_WINDOW_TITLE);
287 if (getenv("HOME")) wd->fsd.path = eina_stringshare_add(getenv("HOME"));
288 else wd->fsd.path = eina_stringshare_add("/");
289 wd->fsd.expandable = _elm_config->fileselector_expand_enable;
290 wd->inwin_mode = _elm_config->inwin_dialogs_enable;
294 wd->btn = elm_button_add(parent);
295 elm_widget_mirrored_automatic_set(wd->btn, EINA_FALSE);
296 elm_widget_resize_object_set(obj, wd->btn);
297 evas_object_event_callback_add(wd->btn, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
298 _changed_size_hints, obj);
299 evas_object_smart_callback_add(wd->btn, "clicked", _button_clicked, wd);
300 elm_widget_sub_object_add(obj, wd->btn);
303 evas_object_smart_callbacks_descriptions_set(obj, _signals);
308 elm_fileselector_button_label_set(Evas_Object *obj,
311 _elm_fileselector_button_label_set(obj, NULL, label);
315 elm_fileselector_button_label_get(const Evas_Object *obj)
317 return _elm_fileselector_button_label_get(obj, NULL);
321 elm_fileselector_button_window_title_set(Evas_Object *obj,
324 ELM_CHECK_WIDTYPE(obj, widtype);
325 Widget_Data *wd = elm_widget_data_get(obj);
328 eina_stringshare_replace(&wd->window_title, title);
331 elm_win_title_set(wd->fsw, wd->window_title);
335 elm_fileselector_button_window_title_get(const Evas_Object *obj)
337 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
338 Widget_Data *wd = elm_widget_data_get(obj);
340 if (!wd) return NULL;
341 return wd->window_title;
345 elm_fileselector_button_window_size_set(Evas_Object *obj,
349 ELM_CHECK_WIDTYPE(obj, widtype);
350 Widget_Data *wd = elm_widget_data_get(obj);
357 evas_object_resize(wd->fsw, wd->w, wd->h);
361 elm_fileselector_button_window_size_get(const Evas_Object *obj,
365 ELM_CHECK_WIDTYPE(obj, widtype);
366 Widget_Data *wd = elm_widget_data_get(obj);
369 if (width) *width = wd->w;
370 if (height) *height = wd->h;
374 elm_fileselector_button_path_set(Evas_Object *obj,
377 ELM_CHECK_WIDTYPE(obj, widtype);
378 Widget_Data *wd = elm_widget_data_get(obj);
381 eina_stringshare_replace(&wd->fsd.path, path);
384 elm_fileselector_selected_set(wd->fs, wd->fsd.path);
388 elm_fileselector_button_path_get(const Evas_Object *obj)
390 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
391 Widget_Data *wd = elm_widget_data_get(obj);
392 if (!wd) return NULL;
397 elm_fileselector_button_expandable_set(Evas_Object *obj,
400 ELM_CHECK_WIDTYPE(obj, widtype);
401 Widget_Data *wd = elm_widget_data_get(obj);
404 wd->fsd.expandable = value;
407 elm_fileselector_expandable_set(wd->fs, wd->fsd.expandable);
411 elm_fileselector_button_expandable_get(const Evas_Object *obj)
413 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
414 Widget_Data *wd = elm_widget_data_get(obj);
416 if (!wd) return EINA_FALSE;
417 return wd->fsd.expandable;
421 elm_fileselector_button_folder_only_set(Evas_Object *obj,
424 ELM_CHECK_WIDTYPE(obj, widtype);
425 Widget_Data *wd = elm_widget_data_get(obj);
428 wd->fsd.folder_only = value;
431 elm_fileselector_folder_only_set(wd->fs, wd->fsd.folder_only);
435 elm_fileselector_button_folder_only_get(const Evas_Object *obj)
437 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
438 Widget_Data *wd = elm_widget_data_get(obj);
440 if (!wd) return EINA_FALSE;
441 return wd->fsd.folder_only;
445 elm_fileselector_button_is_save_set(Evas_Object *obj,
448 ELM_CHECK_WIDTYPE(obj, widtype);
449 Widget_Data *wd = elm_widget_data_get(obj);
452 wd->fsd.is_save = value;
455 elm_fileselector_is_save_set(wd->fs, wd->fsd.is_save);
459 elm_fileselector_button_is_save_get(const Evas_Object *obj)
461 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
462 Widget_Data *wd = elm_widget_data_get(obj);
464 if (!wd) return EINA_FALSE;
465 return wd->fsd.is_save;
469 elm_fileselector_button_inwin_mode_set(Evas_Object *obj,
472 ELM_CHECK_WIDTYPE(obj, widtype);
473 Widget_Data *wd = elm_widget_data_get(obj);
476 wd->inwin_mode = value;
480 elm_fileselector_button_inwin_mode_get(const Evas_Object *obj)
482 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
483 Widget_Data *wd = elm_widget_data_get(obj);
485 if (!wd) return EINA_FALSE;
486 return wd->inwin_mode;
490 elm_fileselector_button_icon_set(Evas_Object *obj,
493 ELM_CHECK_WIDTYPE(obj, widtype);
494 Widget_Data *wd = elm_widget_data_get(obj);
497 evas_object_del(icon);
500 elm_button_icon_set(wd->btn, icon);
504 elm_fileselector_button_icon_get(const Evas_Object *obj)
506 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
507 Widget_Data *wd = elm_widget_data_get(obj);
508 if (!wd) return NULL;
509 return elm_button_icon_get(wd->btn);
513 elm_fileselector_button_icon_unset(Evas_Object *obj)
515 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
516 Widget_Data *wd = elm_widget_data_get(obj);
517 if (!wd) return NULL;
518 return elm_button_icon_unset(wd->btn);