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 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
280 ELM_CHECK_WIDTYPE(obj, widtype);
281 Widget_Data *wd = elm_widget_data_get(obj);
283 elm_object_part_content_set(wd->btn, part, content);
287 _content_get_hook(const Evas_Object *obj, const char *part)
289 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
290 Widget_Data *wd = elm_widget_data_get(obj);
291 if (!wd) return NULL;
292 return elm_object_part_content_get(wd->btn, part);
296 _content_unset_hook(Evas_Object *obj, const char *part)
298 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
299 Widget_Data *wd = elm_widget_data_get(obj);
300 if (!wd) return NULL;
301 return elm_object_part_content_unset(wd->btn, part);
305 elm_fileselector_button_add(Evas_Object *parent)
311 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
313 ELM_SET_WIDTYPE(widtype, "fileselector_button");
314 elm_widget_type_set(obj, "fileselector_button");
315 elm_widget_sub_object_add(parent, obj);
316 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
317 elm_widget_data_set(obj, wd);
318 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
319 elm_widget_del_hook_set(obj, _del_hook);
320 elm_widget_theme_hook_set(obj, _theme_hook);
321 elm_widget_disable_hook_set(obj, _disable_hook);
322 elm_widget_can_focus_set(obj, EINA_TRUE);
323 elm_widget_activate_hook_set(obj, _activate_hook);
324 elm_widget_text_set_hook_set(obj, _elm_fileselector_button_label_set);
325 elm_widget_text_get_hook_set(obj, _elm_fileselector_button_label_get);
326 elm_widget_content_set_hook_set(obj, _content_set_hook);
327 elm_widget_content_get_hook_set(obj, _content_get_hook);
328 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
331 wd->window_title = eina_stringshare_add(DEFAULT_WINDOW_TITLE);
332 if (getenv("HOME")) wd->fsd.path = eina_stringshare_add(getenv("HOME"));
333 else wd->fsd.path = eina_stringshare_add("/");
334 wd->fsd.expandable = _elm_config->fileselector_expand_enable;
335 wd->inwin_mode = _elm_config->inwin_dialogs_enable;
339 wd->btn = elm_button_add(parent);
340 elm_widget_mirrored_automatic_set(wd->btn, EINA_FALSE);
341 elm_widget_resize_object_set(obj, wd->btn);
342 evas_object_event_callback_add(wd->btn, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
343 _changed_size_hints, obj);
344 evas_object_smart_callback_add(wd->btn, "clicked", _button_clicked, wd);
345 elm_widget_sub_object_add(obj, wd->btn);
348 evas_object_smart_callbacks_descriptions_set(obj, _signals);
354 elm_fileselector_button_window_title_set(Evas_Object *obj,
357 ELM_CHECK_WIDTYPE(obj, widtype);
358 Widget_Data *wd = elm_widget_data_get(obj);
361 eina_stringshare_replace(&wd->window_title, title);
364 elm_win_title_set(wd->fsw, wd->window_title);
368 elm_fileselector_button_window_title_get(const Evas_Object *obj)
370 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
371 Widget_Data *wd = elm_widget_data_get(obj);
373 if (!wd) return NULL;
374 return wd->window_title;
378 elm_fileselector_button_window_size_set(Evas_Object *obj,
382 ELM_CHECK_WIDTYPE(obj, widtype);
383 Widget_Data *wd = elm_widget_data_get(obj);
390 evas_object_resize(wd->fsw, wd->w, wd->h);
394 elm_fileselector_button_window_size_get(const Evas_Object *obj,
398 ELM_CHECK_WIDTYPE(obj, widtype);
399 Widget_Data *wd = elm_widget_data_get(obj);
402 if (width) *width = wd->w;
403 if (height) *height = wd->h;
407 elm_fileselector_button_path_set(Evas_Object *obj,
410 ELM_CHECK_WIDTYPE(obj, widtype);
411 Widget_Data *wd = elm_widget_data_get(obj);
414 eina_stringshare_replace(&wd->fsd.path, path);
417 elm_fileselector_selected_set(wd->fs, wd->fsd.path);
421 elm_fileselector_button_path_get(const Evas_Object *obj)
423 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
424 Widget_Data *wd = elm_widget_data_get(obj);
425 if (!wd) return NULL;
430 elm_fileselector_button_expandable_set(Evas_Object *obj,
433 ELM_CHECK_WIDTYPE(obj, widtype);
434 Widget_Data *wd = elm_widget_data_get(obj);
437 wd->fsd.expandable = value;
440 elm_fileselector_expandable_set(wd->fs, wd->fsd.expandable);
444 elm_fileselector_button_expandable_get(const Evas_Object *obj)
446 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
447 Widget_Data *wd = elm_widget_data_get(obj);
449 if (!wd) return EINA_FALSE;
450 return wd->fsd.expandable;
454 elm_fileselector_button_folder_only_set(Evas_Object *obj,
457 ELM_CHECK_WIDTYPE(obj, widtype);
458 Widget_Data *wd = elm_widget_data_get(obj);
461 wd->fsd.folder_only = value;
464 elm_fileselector_folder_only_set(wd->fs, wd->fsd.folder_only);
468 elm_fileselector_button_folder_only_get(const Evas_Object *obj)
470 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
471 Widget_Data *wd = elm_widget_data_get(obj);
473 if (!wd) return EINA_FALSE;
474 return wd->fsd.folder_only;
478 elm_fileselector_button_is_save_set(Evas_Object *obj,
481 ELM_CHECK_WIDTYPE(obj, widtype);
482 Widget_Data *wd = elm_widget_data_get(obj);
485 wd->fsd.is_save = value;
488 elm_fileselector_is_save_set(wd->fs, wd->fsd.is_save);
492 elm_fileselector_button_is_save_get(const Evas_Object *obj)
494 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
495 Widget_Data *wd = elm_widget_data_get(obj);
497 if (!wd) return EINA_FALSE;
498 return wd->fsd.is_save;
502 elm_fileselector_button_inwin_mode_set(Evas_Object *obj,
505 ELM_CHECK_WIDTYPE(obj, widtype);
506 Widget_Data *wd = elm_widget_data_get(obj);
509 wd->inwin_mode = value;
513 elm_fileselector_button_inwin_mode_get(const Evas_Object *obj)
515 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
516 Widget_Data *wd = elm_widget_data_get(obj);
518 if (!wd) return EINA_FALSE;
519 return wd->inwin_mode;