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 _mirrored_set(obj, elm_widget_mirrored_get(obj));
174 _elm_theme_object_set(obj, wd->edje, "fileselector_entry", "base", style);
175 if (elm_object_disabled_get(obj))
176 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
178 if (!style) style = "default";
179 snprintf(buf, sizeof(buf), "fileselector_entry/%s", style);
180 elm_widget_style_set(wd->button, buf);
181 elm_widget_style_set(wd->entry, buf);
183 edje_object_part_swallow(obj, "elm.swallow.button", wd->button);
184 edje_object_part_swallow(obj, "elm.swallow.entry", wd->entry);
186 edje_object_message_signal_process(wd->edje);
187 edje_object_scale_set
188 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
193 _disable_hook(Evas_Object *obj)
195 Widget_Data *wd = elm_widget_data_get(obj);
196 Eina_Bool val = elm_widget_disabled_get(obj);
199 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
201 edje_object_signal_emit(wd->edje, "elm,state,enabled", "elm");
203 elm_widget_disabled_set(wd->button, val);
204 elm_widget_disabled_set(wd->entry, val);
208 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
214 * Add a new file selector entry into the parent object.
216 * @param parent The parent object
217 * @return The new object or NULL if it cannot be created
219 * @ingroup File_Selector_Entry
222 elm_fileselector_entry_add(Evas_Object *parent)
225 Evas *e = evas_object_evas_get(parent);
229 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
231 wd = ELM_NEW(Widget_Data);
233 obj = elm_widget_add(e);
234 ELM_SET_WIDTYPE(widtype, "fileselector_entry");
235 elm_widget_type_set(obj, "fileselector_entry");
236 elm_widget_sub_object_add(parent, obj);
237 elm_widget_data_set(obj, wd);
238 elm_widget_del_hook_set(obj, _del_hook);
239 elm_widget_disable_hook_set(obj, _disable_hook);
240 elm_widget_focus_next_hook_set(obj, _elm_fileselector_entry_focus_next_hook);
241 elm_widget_can_focus_set(obj, EINA_FALSE);
242 elm_widget_theme_hook_set(obj, _theme_hook);
244 wd->edje = edje_object_add(e);
245 _elm_theme_object_set(obj, wd->edje, "fileselector_entry", "base", "default");
246 elm_widget_resize_object_set(obj, wd->edje);
248 wd->button = elm_fileselector_button_add(obj);
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_style_set(wd->entry, "fileselector_entry/default");
266 elm_scrolled_entry_single_line_set(wd->entry, EINA_TRUE);
267 elm_scrolled_entry_editable_set(wd->entry, EINA_TRUE);
268 edje_object_part_swallow(wd->edje, "elm.swallow.entry", wd->entry);
269 elm_widget_sub_object_add(obj, wd->entry);
270 evas_object_event_callback_add
271 (wd->entry, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
273 #define SIG_FWD(name) \
274 evas_object_smart_callback_add(wd->entry, SIG_##name, _##name##_fwd, obj)
278 SIG_FWD(LONGPRESSED);
280 SIG_FWD(CLICKED_DOUBLE);
283 SIG_FWD(SELECTION_PASTE);
284 SIG_FWD(SELECTION_COPY);
285 SIG_FWD(SELECTION_CUT);
288 _mirrored_set(obj, elm_widget_mirrored_get(obj));
291 // TODO: convert Elementary to subclassing of Evas_Smart_Class
292 // TODO: and save some bytes, making descriptions per-class and not instance!
293 evas_object_smart_callbacks_descriptions_set(obj, _signals);
298 * Set the label used in the file selector entry.
300 * @param obj The entry object
301 * @param label The text label text to be displayed on the entry
303 * @ingroup File_Selector_Entry
306 elm_fileselector_entry_button_label_set(Evas_Object *obj, const char *label)
308 ELM_CHECK_WIDTYPE(obj, widtype);
309 Widget_Data *wd = elm_widget_data_get(obj);
311 elm_fileselector_button_label_set(wd->button, label);
315 elm_fileselector_entry_button_label_get(const Evas_Object *obj)
317 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
318 Widget_Data *wd = elm_widget_data_get(obj);
319 if (!wd) return NULL;
320 return elm_fileselector_button_label_get(wd->button);
324 * Set the path to start the entry's file selector with, when clicked.
326 * @param obj The entry object
327 * @param path Path to a file/directory
329 * Default path is "HOME" environment variable's value.
331 * @ingroup File_Selector_Entry
334 elm_fileselector_entry_selected_set(Evas_Object *obj, const char *path)
336 ELM_CHECK_WIDTYPE(obj, widtype);
337 Widget_Data *wd = elm_widget_data_get(obj);
339 elm_fileselector_button_path_set(wd->button, path);
343 * Get the <b>last</b> path which the entry's file selector was set to.
345 * @param obj The entry object
346 * @param path Path to a file/directory
348 * Default path is "HOME" environment variable's value.
350 * @ingroup File_Selector_Entry
353 elm_fileselector_entry_selected_get(const Evas_Object *obj)
355 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
356 Widget_Data *wd = elm_widget_data_get(obj);
357 if (!wd) return NULL;
358 return elm_fileselector_button_path_get(wd->button);
362 * Set the title of the file selector entry's window.
364 * @param obj The entry object
365 * @param title The title string
367 * Note that it will only take any effect if the fileselector entry
368 * not at "inwin mode".
370 * @ingroup File_Selector_Entry
373 elm_fileselector_entry_window_title_set(Evas_Object *obj, const char *title)
375 ELM_CHECK_WIDTYPE(obj, widtype);
376 Widget_Data *wd = elm_widget_data_get(obj);
378 elm_fileselector_button_window_title_set(wd->button, title);
382 * Get the title of the file selector entry's window.
384 * @param obj The entry object
386 * @ingroup File_Selector_Entry
389 elm_fileselector_entry_window_title_get(const Evas_Object *obj)
391 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
392 Widget_Data *wd = elm_widget_data_get(obj);
393 if (!wd) return NULL;
394 return elm_fileselector_button_window_title_get(wd->button);
398 * Set the size of the file selector entry's window.
400 * @param obj The entry object
401 * @param width The width
402 * @param height The height
404 * Note that it will only take any effect if the fileselector entry not at
405 * "inwin mode". Default size for the window (when applicable) is 400x400.
407 * @ingroup File_Selector_Entry
410 elm_fileselector_entry_window_size_set(Evas_Object *obj, Evas_Coord width, Evas_Coord height)
412 ELM_CHECK_WIDTYPE(obj, widtype);
413 Widget_Data *wd = elm_widget_data_get(obj);
415 elm_fileselector_button_window_size_set(wd->button, width, height);
419 * Get the size of the file selector entry's window.
421 * @param obj The entry object
422 * @param width Pointer into which to store the width value
423 * @param height Pointer into which to store the height value
425 * @ingroup File_Selector_Entry
428 elm_fileselector_entry_window_size_get(const Evas_Object *obj, Evas_Coord *width, Evas_Coord *height)
430 ELM_CHECK_WIDTYPE(obj, widtype);
431 Widget_Data *wd = elm_widget_data_get(obj);
433 elm_fileselector_button_window_size_get(wd->button, width, height);
437 * Set the starting path of the file selector entry's window.
439 * @param obj The entry object
440 * @param path The path string
442 * It must be a <b>directory</b> path.
444 * @ingroup File_Selector_Entry
447 elm_fileselector_entry_path_set(Evas_Object *obj, const char *path)
449 ELM_CHECK_WIDTYPE(obj, widtype);
450 Widget_Data *wd = elm_widget_data_get(obj);
452 elm_fileselector_button_path_set(wd->button, path);
453 elm_scrolled_entry_entry_set(wd->entry, path);
457 * Get the <b>last</b> path of the file selector entry's window.
459 * @param obj The entry object
461 * @ingroup File_Selector_Entry
464 elm_fileselector_entry_path_get(const Evas_Object *obj)
466 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
467 Widget_Data *wd = elm_widget_data_get(obj);
468 if (!wd) return NULL;
469 return elm_scrolled_entry_entry_get(wd->entry);
473 * Set whether the entry's file selector is to present itself as an
474 * Elementary Generic List (which will expand its entries for nested
475 * directories) or as canonical list, which will be rendered again
476 * with the contents of each selected directory.
478 * @param obj The entry object
479 * @param value The expandable flag
481 * @ingroup File_Selector_Entry
484 elm_fileselector_entry_expandable_set(Evas_Object *obj, Eina_Bool value)
486 ELM_CHECK_WIDTYPE(obj, widtype);
487 Widget_Data *wd = elm_widget_data_get(obj);
489 elm_fileselector_button_expandable_set(wd->button, value);
493 * Get the entry's file selector expandable flag.
495 * @param obj The entry object
496 * @return value The expandable flag
498 * @ingroup File_Selector_Entry
501 elm_fileselector_entry_expandable_get(const Evas_Object *obj)
503 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
504 Widget_Data *wd = elm_widget_data_get(obj);
505 if (!wd) return EINA_FALSE;
506 return elm_fileselector_button_expandable_get(wd->button);
510 * Set whether the entry's file selector list is to display folders
511 * only or the directory contents, as well.
513 * @param obj The entry object
514 * @param value The "folder only" flag
516 * @ingroup File_Selector_Entry
519 elm_fileselector_entry_folder_only_set(Evas_Object *obj, Eina_Bool value)
521 ELM_CHECK_WIDTYPE(obj, widtype);
522 Widget_Data *wd = elm_widget_data_get(obj);
524 elm_fileselector_button_folder_only_set(wd->button, value);
528 * Get the entry's file selector "folder only" flag.
530 * @param obj The entry object
531 * @return value The "folder only" flag
533 * @ingroup File_Selector_Entry
536 elm_fileselector_entry_folder_only_get(const Evas_Object *obj)
538 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
539 Widget_Data *wd = elm_widget_data_get(obj);
540 if (!wd) return EINA_FALSE;
541 return elm_fileselector_button_folder_only_get(wd->button);
545 * Set whether the entry's file selector has an editable text entry
546 * which will hold its current selection.
548 * @param obj The entry object
549 * @param value The "is save" flag
551 * @ingroup File_Selector_Entry
554 elm_fileselector_entry_is_save_set(Evas_Object *obj, Eina_Bool value)
556 ELM_CHECK_WIDTYPE(obj, widtype);
557 Widget_Data *wd = elm_widget_data_get(obj);
559 elm_fileselector_button_is_save_set(wd->button, value);
563 * Get the entry's file selector "is save" flag.
565 * @param obj The entry object
566 * @return value The "is save" flag
568 * @ingroup File_Selector_Entry
571 elm_fileselector_entry_is_save_get(const Evas_Object *obj)
573 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
574 Widget_Data *wd = elm_widget_data_get(obj);
575 if (!wd) return EINA_FALSE;
576 return elm_fileselector_button_is_save_get(wd->button);
580 * Set whether the entry's file selector will raise an Elementary
581 * Inner Window, instead of a dedicated Elementary Window. By default,
584 * @param obj The entry object
585 * @param value The "inwin mode" flag
587 * @ingroup File_Selector_Entry
590 elm_fileselector_entry_inwin_mode_set(Evas_Object *obj, Eina_Bool value)
592 ELM_CHECK_WIDTYPE(obj, widtype);
593 Widget_Data *wd = elm_widget_data_get(obj);
595 elm_fileselector_button_inwin_mode_set(wd->button, value);
599 * Get the entry's file selector "inwin mode" flag.
601 * @param obj The entry object
602 * @return value The "inwin mode" flag
604 * @ingroup File_Selector_Entry
607 elm_fileselector_entry_inwin_mode_get(const Evas_Object *obj)
609 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
610 Widget_Data *wd = elm_widget_data_get(obj);
611 if (!wd) return EINA_FALSE;
612 return elm_fileselector_button_inwin_mode_get(wd->button);
616 * Set the icon used for the entry button
618 * Once the icon object is set, a previously set one will be deleted.
620 * @param obj The entry object
621 * @param icon The image for the entry
623 * @ingroup File_Selector_Entry
626 elm_fileselector_entry_button_icon_set(Evas_Object *obj, Evas_Object *icon)
628 ELM_CHECK_WIDTYPE(obj, widtype);
629 Widget_Data *wd = elm_widget_data_get(obj);
631 elm_fileselector_button_icon_set(wd->button, icon);
635 * Get the icon used for the entry button
637 * @param obj The entry object
638 * @return The image for the entry
640 * @ingroup File_Selector_Entry
643 elm_fileselector_entry_button_icon_get(const Evas_Object *obj)
645 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
646 Widget_Data *wd = elm_widget_data_get(obj);
647 if (!wd) return NULL;
648 return elm_fileselector_button_icon_get(wd->button);
652 * Unset the icon used for the entry button
654 * Unparent and return the icon object which was set for this widget.
656 * @param obj The entry object
657 * @return The icon object that was being used
659 * @ingroup File_Selector_Entry
662 elm_fileselector_entry_button_icon_unset(Evas_Object *obj)
664 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
665 Widget_Data *wd = elm_widget_data_get(obj);
666 if (!wd) return NULL;
667 return elm_fileselector_button_icon_unset(wd->button);