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_pre_hook(Evas_Object *obj);
26 static void _del_hook(Evas_Object *obj);
27 static void _theme_hook(Evas_Object *obj);
28 static void _disable_hook(Evas_Object *obj);
29 static void _sizing_eval(Evas_Object *obj);
30 static void _changed_size_hints(void *data,
34 static void _button_clicked(void *data,
37 static void _on_focus_hook(void *data,
39 static void _selection_done(void *data,
42 static void _activate(Widget_Data *wd);
44 static const char SIG_FILE_CHOSEN[] = "file,chosen";
45 static const Evas_Smart_Cb_Description _signals[] = {
46 {SIG_FILE_CHOSEN, "s"},
51 _del_pre_hook(Evas_Object *obj)
53 Widget_Data *wd = elm_widget_data_get(obj);
55 evas_object_event_callback_del_full(wd->btn, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
56 _changed_size_hints, obj);
57 evas_object_smart_callback_del(wd->btn, "clicked", _button_clicked);
61 _del_hook(Evas_Object *obj)
66 wd = elm_widget_data_get(obj);
69 if (wd->window_title) eina_stringshare_del(wd->window_title);
70 if (wd->fsd.path) eina_stringshare_del(wd->fsd.path);
73 win = evas_object_data_del(obj, "win");
80 _on_focus_hook(void *data __UNUSED__,
83 Widget_Data *wd = elm_widget_data_get(obj);
85 if (elm_widget_focus_get(obj))
86 elm_widget_focus_steal(wd->btn);
90 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
92 Widget_Data *wd = elm_widget_data_get(obj);
94 elm_widget_mirrored_set(wd->btn, rtl);
95 elm_widget_mirrored_set(wd->fs, rtl);
99 _theme_hook(Evas_Object *obj)
101 Widget_Data *wd = elm_widget_data_get(obj);
104 _elm_widget_mirrored_reload(obj);
105 _mirrored_set(obj, elm_widget_mirrored_get(obj));
107 snprintf(buf, sizeof(buf), "fileselector_button/%s",
108 elm_widget_style_get(obj));
109 elm_object_style_set(wd->btn, buf);
114 _disable_hook(Evas_Object *obj)
116 Widget_Data *wd = elm_widget_data_get(obj);
118 elm_widget_disabled_set(wd->btn, elm_widget_disabled_get(obj));
122 _sizing_eval(Evas_Object *obj)
124 Widget_Data *wd = elm_widget_data_get(obj);
125 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
127 evas_object_size_hint_min_get(wd->btn, &minw, &minh);
128 evas_object_size_hint_max_get(wd->btn, &maxw, &maxh);
129 evas_object_size_hint_min_set(obj, minw, minh);
130 evas_object_size_hint_max_set(obj, maxw, maxh);
134 _changed_size_hints(void *data,
136 Evas_Object *obj __UNUSED__,
137 void *event_info __UNUSED__)
139 Widget_Data *wd = elm_widget_data_get(data);
145 _activate_hook(Evas_Object *obj)
148 wd = elm_widget_data_get(obj);
154 _button_clicked(void *data,
155 Evas_Object *obj __UNUSED__,
156 void *event_info __UNUSED__)
162 _parent_win_get(Evas_Object *obj)
164 while ((obj) && (strcmp(elm_widget_type_get(obj), "win")))
165 obj = elm_object_parent_widget_get(obj);
171 _new_window_add(Widget_Data *wd)
173 Evas_Object *win, *bg;
175 win = elm_win_add(NULL, "fileselector_button", ELM_WIN_DIALOG_BASIC);
176 elm_win_title_set(win, wd->window_title);
177 elm_win_autodel_set(win, EINA_TRUE);
179 bg = elm_bg_add(win);
180 elm_win_resize_object_add(win, bg);
181 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
182 evas_object_show(bg);
184 evas_object_resize(win, wd->w, wd->h);
189 _activate(Widget_Data *wd)
191 Eina_Bool is_inwin = EINA_FALSE;
197 wd->fsw = _parent_win_get(wd->self);
200 wd->fsw = _new_window_add(wd);
203 wd->fsw = elm_win_inwin_add(wd->fsw);
204 is_inwin = EINA_TRUE;
208 wd->fsw = _new_window_add(wd);
210 wd->fs = elm_fileselector_add(wd->fsw);
211 elm_widget_mirrored_set(wd->fs, elm_widget_mirrored_get(wd->self));
212 elm_widget_mirrored_automatic_set(wd->fs, EINA_FALSE);
213 elm_fileselector_expandable_set(wd->fs, wd->fsd.expandable);
214 elm_fileselector_folder_only_set(wd->fs, wd->fsd.folder_only);
215 elm_fileselector_is_save_set(wd->fs, wd->fsd.is_save);
216 elm_fileselector_selected_set(wd->fs, wd->fsd.path);
217 evas_object_size_hint_weight_set(wd->fs, EVAS_HINT_EXPAND,
219 evas_object_size_hint_align_set(wd->fs, EVAS_HINT_FILL, EVAS_HINT_FILL);
220 evas_object_smart_callback_add(wd->fs, "done", _selection_done, wd);
221 evas_object_show(wd->fs);
225 elm_win_inwin_content_set(wd->fsw, wd->fs);
226 elm_win_inwin_activate(wd->fsw);
230 elm_win_resize_object_add(wd->fsw, wd->fs);
231 evas_object_show(wd->fsw);
236 _selection_done(void *data,
237 Evas_Object *obj __UNUSED__,
240 const char *file = event_info;
241 Widget_Data *wd = data;
245 if (file) eina_stringshare_replace(&wd->fsd.path, file);
250 evas_object_del(del);
252 evas_object_smart_callback_call(wd->self, SIG_FILE_CHOSEN,
253 (void *)wd->fsd.path);
257 _elm_fileselector_button_label_set(Evas_Object *obj, const char *item,
260 ELM_CHECK_WIDTYPE(obj, widtype);
261 if (item && strcmp(item, "default")) return;
262 Widget_Data *wd = elm_widget_data_get(obj);
264 elm_object_text_set(wd->btn, label);
268 _elm_fileselector_button_label_get(const Evas_Object *obj, const char *item)
270 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
271 Widget_Data *wd = elm_widget_data_get(obj);
272 if (item && strcmp(item, "default")) return NULL;
273 if (!wd) return NULL;
274 return elm_object_text_get(wd->btn);
278 elm_fileselector_button_add(Evas_Object *parent)
284 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
286 ELM_SET_WIDTYPE(widtype, "fileselector_button");
287 elm_widget_type_set(obj, "fileselector_button");
288 elm_widget_sub_object_add(parent, obj);
289 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
290 elm_widget_data_set(obj, wd);
291 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
292 elm_widget_del_hook_set(obj, _del_hook);
293 elm_widget_theme_hook_set(obj, _theme_hook);
294 elm_widget_disable_hook_set(obj, _disable_hook);
295 elm_widget_can_focus_set(obj, EINA_TRUE);
296 elm_widget_activate_hook_set(obj, _activate_hook);
297 elm_widget_text_set_hook_set(obj, _elm_fileselector_button_label_set);
298 elm_widget_text_get_hook_set(obj, _elm_fileselector_button_label_get);
301 wd->window_title = eina_stringshare_add(DEFAULT_WINDOW_TITLE);
302 if (getenv("HOME")) wd->fsd.path = eina_stringshare_add(getenv("HOME"));
303 else wd->fsd.path = eina_stringshare_add("/");
304 wd->fsd.expandable = _elm_config->fileselector_expand_enable;
305 wd->inwin_mode = _elm_config->inwin_dialogs_enable;
309 wd->btn = elm_button_add(parent);
310 elm_widget_mirrored_automatic_set(wd->btn, EINA_FALSE);
311 elm_widget_resize_object_set(obj, wd->btn);
312 evas_object_event_callback_add(wd->btn, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
313 _changed_size_hints, obj);
314 evas_object_smart_callback_add(wd->btn, "clicked", _button_clicked, wd);
315 elm_widget_sub_object_add(obj, wd->btn);
318 evas_object_smart_callbacks_descriptions_set(obj, _signals);
323 elm_fileselector_button_label_set(Evas_Object *obj,
326 _elm_fileselector_button_label_set(obj, NULL, label);
330 elm_fileselector_button_label_get(const Evas_Object *obj)
332 return _elm_fileselector_button_label_get(obj, NULL);
336 elm_fileselector_button_window_title_set(Evas_Object *obj,
339 ELM_CHECK_WIDTYPE(obj, widtype);
340 Widget_Data *wd = elm_widget_data_get(obj);
343 eina_stringshare_replace(&wd->window_title, title);
346 elm_win_title_set(wd->fsw, wd->window_title);
350 elm_fileselector_button_window_title_get(const Evas_Object *obj)
352 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
353 Widget_Data *wd = elm_widget_data_get(obj);
355 if (!wd) return NULL;
356 return wd->window_title;
360 elm_fileselector_button_window_size_set(Evas_Object *obj,
364 ELM_CHECK_WIDTYPE(obj, widtype);
365 Widget_Data *wd = elm_widget_data_get(obj);
372 evas_object_resize(wd->fsw, wd->w, wd->h);
376 elm_fileselector_button_window_size_get(const Evas_Object *obj,
380 ELM_CHECK_WIDTYPE(obj, widtype);
381 Widget_Data *wd = elm_widget_data_get(obj);
384 if (width) *width = wd->w;
385 if (height) *height = wd->h;
389 elm_fileselector_button_path_set(Evas_Object *obj,
392 ELM_CHECK_WIDTYPE(obj, widtype);
393 Widget_Data *wd = elm_widget_data_get(obj);
396 eina_stringshare_replace(&wd->fsd.path, path);
399 elm_fileselector_selected_set(wd->fs, wd->fsd.path);
403 elm_fileselector_button_path_get(const Evas_Object *obj)
405 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
406 Widget_Data *wd = elm_widget_data_get(obj);
407 if (!wd) return NULL;
412 elm_fileselector_button_expandable_set(Evas_Object *obj,
415 ELM_CHECK_WIDTYPE(obj, widtype);
416 Widget_Data *wd = elm_widget_data_get(obj);
419 wd->fsd.expandable = value;
422 elm_fileselector_expandable_set(wd->fs, wd->fsd.expandable);
426 elm_fileselector_button_expandable_get(const Evas_Object *obj)
428 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
429 Widget_Data *wd = elm_widget_data_get(obj);
431 if (!wd) return EINA_FALSE;
432 return wd->fsd.expandable;
436 elm_fileselector_button_folder_only_set(Evas_Object *obj,
439 ELM_CHECK_WIDTYPE(obj, widtype);
440 Widget_Data *wd = elm_widget_data_get(obj);
443 wd->fsd.folder_only = value;
446 elm_fileselector_folder_only_set(wd->fs, wd->fsd.folder_only);
450 elm_fileselector_button_folder_only_get(const Evas_Object *obj)
452 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
453 Widget_Data *wd = elm_widget_data_get(obj);
455 if (!wd) return EINA_FALSE;
456 return wd->fsd.folder_only;
460 elm_fileselector_button_is_save_set(Evas_Object *obj,
463 ELM_CHECK_WIDTYPE(obj, widtype);
464 Widget_Data *wd = elm_widget_data_get(obj);
467 wd->fsd.is_save = value;
470 elm_fileselector_is_save_set(wd->fs, wd->fsd.is_save);
474 elm_fileselector_button_is_save_get(const Evas_Object *obj)
476 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
477 Widget_Data *wd = elm_widget_data_get(obj);
479 if (!wd) return EINA_FALSE;
480 return wd->fsd.is_save;
484 elm_fileselector_button_inwin_mode_set(Evas_Object *obj,
487 ELM_CHECK_WIDTYPE(obj, widtype);
488 Widget_Data *wd = elm_widget_data_get(obj);
491 wd->inwin_mode = value;
495 elm_fileselector_button_inwin_mode_get(const Evas_Object *obj)
497 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
498 Widget_Data *wd = elm_widget_data_get(obj);
500 if (!wd) return EINA_FALSE;
501 return wd->inwin_mode;
505 elm_fileselector_button_icon_set(Evas_Object *obj,
508 ELM_CHECK_WIDTYPE(obj, widtype);
509 Widget_Data *wd = elm_widget_data_get(obj);
512 evas_object_del(icon);
515 elm_object_part_content_set(wd->btn, "icon", icon);
519 elm_fileselector_button_icon_get(const Evas_Object *obj)
521 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
522 Widget_Data *wd = elm_widget_data_get(obj);
523 if (!wd) return NULL;
524 return elm_object_part_content_get(wd->btn, "icon");
528 elm_fileselector_button_icon_unset(Evas_Object *obj)
530 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
531 Widget_Data *wd = elm_widget_data_get(obj);
532 if (!wd) return NULL;
533 return elm_object_part_content_unset(wd->btn, "icon");