1 #include <Elementary.h>
5 * @defgroup File_Selector_Entry File Selector Entry
7 * An entry that shows to enter/display path and have an associated
8 * button to allow selecting the file from a dialog.
10 * The button, when clicked, creates an Elementary window (or inner
11 * window) with an Elementary File Selector within. When a file is
12 * chosen, the (inner) window is closed and the selected file is
13 * exposed as an evas_object_smart_callback_call() of the button.
16 typedef struct _Widget_Data Widget_Data;
25 static const char *widtype = NULL;
27 static const char SIG_CHANGED[] = "changed";
28 static const char SIG_ACTIVATED[] = "activated";
29 static const char SIG_PRESS[] = "press";
30 static const char SIG_LONGPRESSED[] = "longpressed";
31 static const char SIG_CLICKED[] = "clicked";
32 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
33 static const char SIG_FOCUSED[] = "focused";
34 static const char SIG_UNFOCUSED[] = "unfocused";
35 static const char SIG_SELECTION_PASTE[] = "selection,paste";
36 static const char SIG_SELECTION_COPY[] = "selection,copy";
37 static const char SIG_SELECTION_CUT[] = "selection,cut";
38 static const char SIG_UNPRESSED[] = "unpressed";
39 static const char SIG_FILE_CHOSEN[] = "file,chosen";
40 static const Evas_Smart_Cb_Description _signals[] =
45 {SIG_LONGPRESSED, ""},
47 {SIG_CLICKED_DOUBLE, ""},
50 {SIG_SELECTION_PASTE, ""},
51 {SIG_SELECTION_COPY, ""},
52 {SIG_SELECTION_CUT, ""},
54 {SIG_FILE_CHOSEN, "s"},
58 #define SIG_FWD(name) \
60 _##name##_fwd(void *data, Evas_Object *obj __UNUSED__, void *event_info) \
62 evas_object_smart_callback_call(data, SIG_##name, event_info); \
68 SIG_FWD(CLICKED_DOUBLE)
71 SIG_FWD(SELECTION_PASTE)
72 SIG_FWD(SELECTION_COPY)
73 SIG_FWD(SELECTION_CUT)
77 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
80 _FILE_CHOSEN_fwd(void *data, Evas_Object *obj __UNUSED__, void *event_info)
82 Widget_Data *wd = elm_widget_data_get(data);
83 const char *file = event_info;
84 elm_scrolled_entry_entry_set(wd->entry, file);
85 evas_object_smart_callback_call(data, SIG_FILE_CHOSEN, event_info);
89 _ACTIVATED_fwd(void *data, Evas_Object *obj __UNUSED__, void *event_info)
91 Widget_Data *wd = elm_widget_data_get(data);
92 const char *file = elm_scrolled_entry_entry_get(wd->entry);
93 elm_fileselector_button_path_set(wd->button, file);
94 evas_object_smart_callback_call(data, SIG_ACTIVATED, event_info);
98 _del_hook(Evas_Object *obj)
100 Widget_Data *wd = elm_widget_data_get(obj);
105 _sizing_eval(Evas_Object *obj)
107 Widget_Data *wd = elm_widget_data_get(obj);
108 Evas_Coord minw = -1, minh = -1;
110 edje_object_size_min_calc(wd->edje, &minw, &minh);
111 evas_object_size_hint_min_set(obj, minw, minh);
112 evas_object_size_hint_max_set(obj, -1, -1);
116 _elm_fileselector_entry_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
118 Widget_Data *wd = elm_widget_data_get(obj);
123 Evas_Object *chain[2];
126 if (dir == ELM_FOCUS_PREVIOUS)
128 chain[0] = wd->button;
129 chain[1] = wd->entry;
131 else if (dir == ELM_FOCUS_NEXT)
133 chain[0] = wd->entry;
134 chain[1] = wd->button;
139 unsigned char i = elm_widget_focus_get(chain[1]);
141 if (elm_widget_focus_next_get(chain[i], dir, next))
146 Evas_Object *to_focus;
147 if (elm_widget_focus_next_get(chain[i], dir, &to_focus))
157 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
159 Widget_Data *wd = elm_widget_data_get(obj);
161 elm_widget_mirrored_set(wd->button, rtl);
162 edje_object_mirrored_set(wd->edje, rtl);
166 _theme_hook(Evas_Object *obj)
168 Widget_Data *wd = elm_widget_data_get(obj);
169 const char *style = elm_widget_style_get(obj);
173 _elm_widget_mirrored_reload(obj);
174 _mirrored_set(obj, elm_widget_mirrored_get(obj));
176 _elm_theme_object_set(obj, wd->edje, "fileselector_entry", "base", style);
177 if (elm_object_disabled_get(obj))
178 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
180 if (!style) style = "default";
181 snprintf(buf, sizeof(buf), "fileselector_entry/%s", style);
182 elm_widget_style_set(wd->button, buf);
183 elm_widget_style_set(wd->entry, buf);
185 edje_object_part_swallow(obj, "elm.swallow.button", wd->button);
186 edje_object_part_swallow(obj, "elm.swallow.entry", wd->entry);
188 edje_object_message_signal_process(wd->edje);
189 edje_object_scale_set
190 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
195 _disable_hook(Evas_Object *obj)
197 Widget_Data *wd = elm_widget_data_get(obj);
198 Eina_Bool val = elm_widget_disabled_get(obj);
201 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
203 edje_object_signal_emit(wd->edje, "elm,state,enabled", "elm");
205 elm_widget_disabled_set(wd->button, val);
206 elm_widget_disabled_set(wd->entry, val);
210 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
216 * Add a new file selector entry into the parent object.
218 * @param parent The parent object
219 * @return The new object or NULL if it cannot be created
221 * @ingroup File_Selector_Entry
224 elm_fileselector_entry_add(Evas_Object *parent)
230 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
232 ELM_SET_WIDTYPE(widtype, "fileselector_entry");
233 elm_widget_type_set(obj, "fileselector_entry");
234 elm_widget_sub_object_add(parent, obj);
235 elm_widget_data_set(obj, wd);
236 elm_widget_del_hook_set(obj, _del_hook);
237 elm_widget_disable_hook_set(obj, _disable_hook);
238 elm_widget_focus_next_hook_set(obj, _elm_fileselector_entry_focus_next_hook);
239 elm_widget_can_focus_set(obj, EINA_FALSE);
240 elm_widget_theme_hook_set(obj, _theme_hook);
242 wd->edje = edje_object_add(e);
243 _elm_theme_object_set(obj, wd->edje, "fileselector_entry", "base", "default");
244 elm_widget_resize_object_set(obj, wd->edje);
246 wd->button = elm_fileselector_button_add(obj);
247 elm_widget_mirrored_automatic_set(wd->button, EINA_FALSE);
248 ELM_SET_WIDTYPE(widtype, "fileselector_entry");
249 elm_widget_style_set(wd->button, "fileselector_entry/default");
250 edje_object_part_swallow(wd->edje, "elm.swallow.button", wd->button);
251 elm_widget_sub_object_add(obj, wd->button);
252 evas_object_event_callback_add
253 (wd->button, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
254 elm_fileselector_button_expandable_set(wd->button,
255 _elm_config->fileselector_expand_enable);
257 #define SIG_FWD(name) \
258 evas_object_smart_callback_add(wd->button, SIG_##name, _##name##_fwd, obj)
261 SIG_FWD(FILE_CHOSEN);
264 wd->entry = elm_scrolled_entry_add(obj);
265 elm_widget_mirrored_automatic_set(wd->entry, EINA_FALSE);
266 elm_widget_style_set(wd->entry, "fileselector_entry/default");
267 elm_scrolled_entry_single_line_set(wd->entry, EINA_TRUE);
268 elm_scrolled_entry_editable_set(wd->entry, EINA_TRUE);
269 edje_object_part_swallow(wd->edje, "elm.swallow.entry", wd->entry);
270 elm_widget_sub_object_add(obj, wd->entry);
271 evas_object_event_callback_add
272 (wd->entry, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
274 #define SIG_FWD(name) \
275 evas_object_smart_callback_add(wd->entry, SIG_##name, _##name##_fwd, obj)
279 SIG_FWD(LONGPRESSED);
281 SIG_FWD(CLICKED_DOUBLE);
284 SIG_FWD(SELECTION_PASTE);
285 SIG_FWD(SELECTION_COPY);
286 SIG_FWD(SELECTION_CUT);
289 _mirrored_set(obj, elm_widget_mirrored_get(obj));
292 // TODO: convert Elementary to subclassing of Evas_Smart_Class
293 // TODO: and save some bytes, making descriptions per-class and not instance!
294 evas_object_smart_callbacks_descriptions_set(obj, _signals);
299 * Set the label used in the file selector entry.
301 * @param obj The entry object
302 * @param label The text label text to be displayed on the entry
304 * @ingroup File_Selector_Entry
307 elm_fileselector_entry_button_label_set(Evas_Object *obj, const char *label)
309 ELM_CHECK_WIDTYPE(obj, widtype);
310 Widget_Data *wd = elm_widget_data_get(obj);
312 elm_fileselector_button_label_set(wd->button, label);
316 elm_fileselector_entry_button_label_get(const Evas_Object *obj)
318 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
319 Widget_Data *wd = elm_widget_data_get(obj);
320 if (!wd) return NULL;
321 return elm_fileselector_button_label_get(wd->button);
325 * Set the path to start the entry's file selector with, when clicked.
327 * @param obj The entry object
328 * @param path Path to a file/directory
330 * Default path is "HOME" environment variable's value.
332 * @ingroup File_Selector_Entry
335 elm_fileselector_entry_selected_set(Evas_Object *obj, const char *path)
337 ELM_CHECK_WIDTYPE(obj, widtype);
338 Widget_Data *wd = elm_widget_data_get(obj);
340 elm_fileselector_button_path_set(wd->button, path);
344 * Get the <b>last</b> path which the entry's file selector was set to.
346 * @param obj The entry object
347 * @param path Path to a file/directory
349 * Default path is "HOME" environment variable's value.
351 * @ingroup File_Selector_Entry
354 elm_fileselector_entry_selected_get(const Evas_Object *obj)
356 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
357 Widget_Data *wd = elm_widget_data_get(obj);
358 if (!wd) return NULL;
359 return elm_fileselector_button_path_get(wd->button);
363 * Set the title of the file selector entry's window.
365 * @param obj The entry object
366 * @param title The title string
368 * Note that it will only take any effect if the fileselector entry
369 * not at "inwin mode".
371 * @ingroup File_Selector_Entry
374 elm_fileselector_entry_window_title_set(Evas_Object *obj, const char *title)
376 ELM_CHECK_WIDTYPE(obj, widtype);
377 Widget_Data *wd = elm_widget_data_get(obj);
379 elm_fileselector_button_window_title_set(wd->button, title);
383 * Get the title of the file selector entry's window.
385 * @param obj The entry object
387 * @ingroup File_Selector_Entry
390 elm_fileselector_entry_window_title_get(const Evas_Object *obj)
392 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
393 Widget_Data *wd = elm_widget_data_get(obj);
394 if (!wd) return NULL;
395 return elm_fileselector_button_window_title_get(wd->button);
399 * Set the size of the file selector entry's window.
401 * @param obj The entry object
402 * @param width The width
403 * @param height The height
405 * Note that it will only take any effect if the fileselector entry not at
406 * "inwin mode". Default size for the window (when applicable) is 400x400.
408 * @ingroup File_Selector_Entry
411 elm_fileselector_entry_window_size_set(Evas_Object *obj, Evas_Coord width, Evas_Coord height)
413 ELM_CHECK_WIDTYPE(obj, widtype);
414 Widget_Data *wd = elm_widget_data_get(obj);
416 elm_fileselector_button_window_size_set(wd->button, width, height);
420 * Get the size of the file selector entry's window.
422 * @param obj The entry object
423 * @param width Pointer into which to store the width value
424 * @param height Pointer into which to store the height value
426 * @ingroup File_Selector_Entry
429 elm_fileselector_entry_window_size_get(const Evas_Object *obj, Evas_Coord *width, Evas_Coord *height)
431 ELM_CHECK_WIDTYPE(obj, widtype);
432 Widget_Data *wd = elm_widget_data_get(obj);
434 elm_fileselector_button_window_size_get(wd->button, width, height);
438 * Set the starting path of the file selector entry's window.
440 * @param obj The entry object
441 * @param path The path string
443 * It must be a <b>directory</b> path.
445 * @ingroup File_Selector_Entry
448 elm_fileselector_entry_path_set(Evas_Object *obj, const char *path)
450 ELM_CHECK_WIDTYPE(obj, widtype);
451 Widget_Data *wd = elm_widget_data_get(obj);
453 elm_fileselector_button_path_set(wd->button, path);
454 elm_scrolled_entry_entry_set(wd->entry, path);
458 * Get the <b>last</b> path of the file selector entry's window.
460 * @param obj The entry object
462 * @ingroup File_Selector_Entry
465 elm_fileselector_entry_path_get(const Evas_Object *obj)
467 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
468 Widget_Data *wd = elm_widget_data_get(obj);
469 if (!wd) return NULL;
470 return elm_scrolled_entry_entry_get(wd->entry);
474 * Set whether the entry's file selector is to present itself as an
475 * Elementary Generic List (which will expand its entries for nested
476 * directories) or as canonical list, which will be rendered again
477 * with the contents of each selected directory.
479 * @param obj The entry object
480 * @param value The expandable flag
482 * @ingroup File_Selector_Entry
485 elm_fileselector_entry_expandable_set(Evas_Object *obj, Eina_Bool value)
487 ELM_CHECK_WIDTYPE(obj, widtype);
488 Widget_Data *wd = elm_widget_data_get(obj);
490 elm_fileselector_button_expandable_set(wd->button, value);
494 * Get the entry's file selector expandable flag.
496 * @param obj The entry object
497 * @return value The expandable flag
499 * @ingroup File_Selector_Entry
502 elm_fileselector_entry_expandable_get(const Evas_Object *obj)
504 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
505 Widget_Data *wd = elm_widget_data_get(obj);
506 if (!wd) return EINA_FALSE;
507 return elm_fileselector_button_expandable_get(wd->button);
511 * Set whether the entry's file selector list is to display folders
512 * only or the directory contents, as well.
514 * @param obj The entry object
515 * @param value The "folder only" flag
517 * @ingroup File_Selector_Entry
520 elm_fileselector_entry_folder_only_set(Evas_Object *obj, Eina_Bool value)
522 ELM_CHECK_WIDTYPE(obj, widtype);
523 Widget_Data *wd = elm_widget_data_get(obj);
525 elm_fileselector_button_folder_only_set(wd->button, value);
529 * Get the entry's file selector "folder only" flag.
531 * @param obj The entry object
532 * @return value The "folder only" flag
534 * @ingroup File_Selector_Entry
537 elm_fileselector_entry_folder_only_get(const Evas_Object *obj)
539 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
540 Widget_Data *wd = elm_widget_data_get(obj);
541 if (!wd) return EINA_FALSE;
542 return elm_fileselector_button_folder_only_get(wd->button);
546 * Set whether the entry's file selector has an editable text entry
547 * which will hold its current selection.
549 * @param obj The entry object
550 * @param value The "is save" flag
552 * @ingroup File_Selector_Entry
555 elm_fileselector_entry_is_save_set(Evas_Object *obj, Eina_Bool value)
557 ELM_CHECK_WIDTYPE(obj, widtype);
558 Widget_Data *wd = elm_widget_data_get(obj);
560 elm_fileselector_button_is_save_set(wd->button, value);
564 * Get the entry's file selector "is save" flag.
566 * @param obj The entry object
567 * @return value The "is save" flag
569 * @ingroup File_Selector_Entry
572 elm_fileselector_entry_is_save_get(const Evas_Object *obj)
574 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
575 Widget_Data *wd = elm_widget_data_get(obj);
576 if (!wd) return EINA_FALSE;
577 return elm_fileselector_button_is_save_get(wd->button);
581 * Set whether the entry's file selector will raise an Elementary
582 * Inner Window, instead of a dedicated Elementary Window. By default,
585 * @param obj The entry object
586 * @param value The "inwin mode" flag
588 * @ingroup File_Selector_Entry
591 elm_fileselector_entry_inwin_mode_set(Evas_Object *obj, Eina_Bool value)
593 ELM_CHECK_WIDTYPE(obj, widtype);
594 Widget_Data *wd = elm_widget_data_get(obj);
596 elm_fileselector_button_inwin_mode_set(wd->button, value);
600 * Get the entry's file selector "inwin mode" flag.
602 * @param obj The entry object
603 * @return value The "inwin mode" flag
605 * @ingroup File_Selector_Entry
608 elm_fileselector_entry_inwin_mode_get(const Evas_Object *obj)
610 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
611 Widget_Data *wd = elm_widget_data_get(obj);
612 if (!wd) return EINA_FALSE;
613 return elm_fileselector_button_inwin_mode_get(wd->button);
617 * Set the icon used for the entry button
619 * Once the icon object is set, a previously set one will be deleted.
621 * @param obj The entry object
622 * @param icon The image for the entry
624 * @ingroup File_Selector_Entry
627 elm_fileselector_entry_button_icon_set(Evas_Object *obj, Evas_Object *icon)
629 ELM_CHECK_WIDTYPE(obj, widtype);
630 Widget_Data *wd = elm_widget_data_get(obj);
632 elm_fileselector_button_icon_set(wd->button, icon);
636 * Get the icon used for the entry button
638 * @param obj The entry object
639 * @return The image for the entry
641 * @ingroup File_Selector_Entry
644 elm_fileselector_entry_button_icon_get(const Evas_Object *obj)
646 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
647 Widget_Data *wd = elm_widget_data_get(obj);
648 if (!wd) return NULL;
649 return elm_fileselector_button_icon_get(wd->button);
653 * Unset the icon used for the entry button
655 * Unparent and return the icon object which was set for this widget.
657 * @param obj The entry object
658 * @return The icon object that was being used
660 * @ingroup File_Selector_Entry
663 elm_fileselector_entry_button_icon_unset(Evas_Object *obj)
665 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
666 Widget_Data *wd = elm_widget_data_get(obj);
667 if (!wd) return NULL;
668 return elm_fileselector_button_icon_unset(wd->button);