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)
78 _FILE_CHOSEN_fwd(void *data, Evas_Object *obj __UNUSED__, void *event_info)
80 Widget_Data *wd = elm_widget_data_get(data);
81 const char *file = event_info;
82 elm_scrolled_entry_entry_set(wd->entry, file);
83 evas_object_smart_callback_call(data, SIG_FILE_CHOSEN, event_info);
87 _ACTIVATED_fwd(void *data, Evas_Object *obj __UNUSED__, void *event_info)
89 Widget_Data *wd = elm_widget_data_get(data);
90 const char *file = elm_scrolled_entry_entry_get(wd->entry);
91 elm_fileselector_button_path_set(wd->button, file);
92 evas_object_smart_callback_call(data, SIG_ACTIVATED, event_info);
96 _del_hook(Evas_Object *obj)
98 Widget_Data *wd = elm_widget_data_get(obj);
103 _sizing_eval(Evas_Object *obj)
105 Widget_Data *wd = elm_widget_data_get(obj);
106 Evas_Coord minw = -1, minh = -1;
108 edje_object_size_min_calc(wd->edje, &minw, &minh);
109 evas_object_size_hint_min_set(obj, minw, minh);
110 evas_object_size_hint_max_set(obj, -1, -1);
114 _elm_fileselector_entry_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
116 Widget_Data *wd = elm_widget_data_get(obj);
121 Evas_Object *chain[2];
124 if (dir == ELM_FOCUS_PREVIOUS)
126 chain[0] = wd->button;
127 chain[1] = wd->entry;
129 else if (dir == ELM_FOCUS_NEXT)
131 chain[0] = wd->entry;
132 chain[1] = wd->button;
137 unsigned char i = elm_widget_focus_get(chain[1]);
139 if (elm_widget_focus_next_get(chain[i], dir, next))
144 Evas_Object *to_focus;
145 if (elm_widget_focus_next_get(chain[i], dir, &to_focus))
155 _theme_hook(Evas_Object *obj)
157 Widget_Data *wd = elm_widget_data_get(obj);
158 const char *style = elm_widget_style_get(obj);
162 _elm_theme_object_set(obj, wd->edje, "fileselector_entry", "base", style);
163 if (elm_object_disabled_get(obj))
164 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
166 if (!style) style = "default";
167 snprintf(buf, sizeof(buf), "fileselector_entry/%s", style);
168 elm_widget_style_set(wd->button, buf);
169 elm_widget_style_set(wd->entry, buf);
171 edje_object_part_swallow(obj, "elm.swallow.button", wd->button);
172 edje_object_part_swallow(obj, "elm.swallow.entry", wd->entry);
174 edje_object_message_signal_process(wd->edje);
175 edje_object_scale_set
176 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
181 _disable_hook(Evas_Object *obj)
183 Widget_Data *wd = elm_widget_data_get(obj);
184 Eina_Bool val = elm_widget_disabled_get(obj);
187 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
189 edje_object_signal_emit(wd->edje, "elm,state,enabled", "elm");
191 elm_widget_disabled_set(wd->button, val);
192 elm_widget_disabled_set(wd->entry, val);
196 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
202 * Add a new file selector entry into the parent object.
204 * @param parent The parent object
205 * @return The new object or NULL if it cannot be created
207 * @ingroup File_Selector_Entry
210 elm_fileselector_entry_add(Evas_Object *parent)
213 Evas *e = evas_object_evas_get(parent);
217 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
219 wd = ELM_NEW(Widget_Data);
221 obj = elm_widget_add(e);
222 ELM_SET_WIDTYPE(widtype, "fileselector_entry");
223 elm_widget_type_set(obj, "fileselector_entry");
224 elm_widget_sub_object_add(parent, obj);
225 elm_widget_data_set(obj, wd);
226 elm_widget_del_hook_set(obj, _del_hook);
227 elm_widget_disable_hook_set(obj, _disable_hook);
228 elm_widget_focus_next_hook_set(obj, _elm_fileselector_entry_focus_next_hook);
229 elm_widget_can_focus_set(obj, EINA_FALSE);
230 elm_widget_theme_hook_set(obj, _theme_hook);
232 wd->edje = edje_object_add(e);
233 _elm_theme_object_set(obj, wd->edje, "fileselector_entry", "base", "default");
234 elm_widget_resize_object_set(obj, wd->edje);
236 wd->button = elm_fileselector_button_add(obj);
237 elm_widget_style_set(wd->button, "fileselector_entry/default");
238 edje_object_part_swallow(wd->edje, "elm.swallow.button", wd->button);
239 elm_widget_sub_object_add(obj, wd->button);
240 evas_object_event_callback_add
241 (wd->button, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
242 elm_fileselector_button_expandable_set(wd->button,
243 _elm_config->fileselector_expand_enable);
245 #define SIG_FWD(name) \
246 evas_object_smart_callback_add(wd->button, SIG_##name, _##name##_fwd, obj)
249 SIG_FWD(FILE_CHOSEN);
252 wd->entry = elm_scrolled_entry_add(obj);
253 elm_widget_style_set(wd->entry, "fileselector_entry/default");
254 elm_scrolled_entry_single_line_set(wd->entry, EINA_TRUE);
255 elm_scrolled_entry_editable_set(wd->entry, EINA_TRUE);
256 edje_object_part_swallow(wd->edje, "elm.swallow.entry", wd->entry);
257 elm_widget_sub_object_add(obj, wd->entry);
258 evas_object_event_callback_add
259 (wd->entry, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
261 #define SIG_FWD(name) \
262 evas_object_smart_callback_add(wd->entry, SIG_##name, _##name##_fwd, obj)
266 SIG_FWD(LONGPRESSED);
268 SIG_FWD(CLICKED_DOUBLE);
271 SIG_FWD(SELECTION_PASTE);
272 SIG_FWD(SELECTION_COPY);
273 SIG_FWD(SELECTION_CUT);
278 // TODO: convert Elementary to subclassing of Evas_Smart_Class
279 // TODO: and save some bytes, making descriptions per-class and not instance!
280 evas_object_smart_callbacks_descriptions_set(obj, _signals);
285 * Set the label used in the file selector entry.
287 * @param obj The entry object
288 * @param label The text label text to be displayed on the entry
290 * @ingroup File_Selector_Entry
293 elm_fileselector_entry_button_label_set(Evas_Object *obj, const char *label)
295 ELM_CHECK_WIDTYPE(obj, widtype);
296 Widget_Data *wd = elm_widget_data_get(obj);
298 elm_fileselector_button_label_set(wd->button, label);
302 elm_fileselector_entry_button_label_get(const Evas_Object *obj)
304 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
305 Widget_Data *wd = elm_widget_data_get(obj);
306 if (!wd) return NULL;
307 return elm_fileselector_button_label_get(wd->button);
311 * Set the path to start the entry's file selector with, when clicked.
313 * @param obj The entry object
314 * @param path Path to a file/directory
316 * Default path is "HOME" environment variable's value.
318 * @ingroup File_Selector_Entry
321 elm_fileselector_entry_selected_set(Evas_Object *obj, const char *path)
323 ELM_CHECK_WIDTYPE(obj, widtype);
324 Widget_Data *wd = elm_widget_data_get(obj);
326 elm_fileselector_button_path_set(wd->button, path);
330 * Get the <b>last</b> path which the entry's file selector was set to.
332 * @param obj The entry object
333 * @param path Path to a file/directory
335 * Default path is "HOME" environment variable's value.
337 * @ingroup File_Selector_Entry
340 elm_fileselector_entry_selected_get(const Evas_Object *obj)
342 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
343 Widget_Data *wd = elm_widget_data_get(obj);
344 if (!wd) return NULL;
345 return elm_fileselector_button_path_get(wd->button);
349 * Set the title of the file selector entry's window.
351 * @param obj The entry object
352 * @param title The title string
354 * Note that it will only take any effect if the fileselector entry
355 * not at "inwin mode".
357 * @ingroup File_Selector_Entry
360 elm_fileselector_entry_window_title_set(Evas_Object *obj, const char *title)
362 ELM_CHECK_WIDTYPE(obj, widtype);
363 Widget_Data *wd = elm_widget_data_get(obj);
365 elm_fileselector_button_window_title_set(wd->button, title);
369 * Get the title of the file selector entry's window.
371 * @param obj The entry object
373 * @ingroup File_Selector_Entry
376 elm_fileselector_entry_window_title_get(const Evas_Object *obj)
378 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
379 Widget_Data *wd = elm_widget_data_get(obj);
380 if (!wd) return NULL;
381 return elm_fileselector_button_window_title_get(wd->button);
385 * Set the size of the file selector entry's window.
387 * @param obj The entry object
388 * @param width The width
389 * @param height The height
391 * Note that it will only take any effect if the fileselector entry not at
392 * "inwin mode". Default size for the window (when applicable) is 400x400.
394 * @ingroup File_Selector_Entry
397 elm_fileselector_entry_window_size_set(Evas_Object *obj, Evas_Coord width, Evas_Coord height)
399 ELM_CHECK_WIDTYPE(obj, widtype);
400 Widget_Data *wd = elm_widget_data_get(obj);
402 elm_fileselector_button_window_size_set(wd->button, width, height);
406 * Get the size of the file selector entry's window.
408 * @param obj The entry object
409 * @param width Pointer into which to store the width value
410 * @param height Pointer into which to store the height value
412 * @ingroup File_Selector_Entry
415 elm_fileselector_entry_window_size_get(const Evas_Object *obj, Evas_Coord *width, Evas_Coord *height)
417 ELM_CHECK_WIDTYPE(obj, widtype);
418 Widget_Data *wd = elm_widget_data_get(obj);
420 elm_fileselector_button_window_size_get(wd->button, width, height);
424 * Set the starting path of the file selector entry's window.
426 * @param obj The entry object
427 * @param path The path string
429 * It must be a <b>directory</b> path.
431 * @ingroup File_Selector_Entry
434 elm_fileselector_entry_path_set(Evas_Object *obj, const char *path)
436 ELM_CHECK_WIDTYPE(obj, widtype);
437 Widget_Data *wd = elm_widget_data_get(obj);
439 elm_fileselector_button_path_set(wd->button, path);
440 elm_scrolled_entry_entry_set(wd->entry, path);
444 * Get the <b>last</b> path of the file selector entry's window.
446 * @param obj The entry object
448 * @ingroup File_Selector_Entry
451 elm_fileselector_entry_path_get(const Evas_Object *obj)
453 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
454 Widget_Data *wd = elm_widget_data_get(obj);
455 if (!wd) return NULL;
456 return elm_scrolled_entry_entry_get(wd->entry);
460 * Set whether the entry's file selector is to present itself as an
461 * Elementary Generic List (which will expand its entries for nested
462 * directories) or as canonical list, which will be rendered again
463 * with the contents of each selected directory.
465 * @param obj The entry object
466 * @param value The expandable flag
468 * @ingroup File_Selector_Entry
471 elm_fileselector_entry_expandable_set(Evas_Object *obj, Eina_Bool value)
473 ELM_CHECK_WIDTYPE(obj, widtype);
474 Widget_Data *wd = elm_widget_data_get(obj);
476 elm_fileselector_button_expandable_set(wd->button, value);
480 * Get the entry's file selector expandable flag.
482 * @param obj The entry object
483 * @return value The expandable flag
485 * @ingroup File_Selector_Entry
488 elm_fileselector_entry_expandable_get(const Evas_Object *obj)
490 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
491 Widget_Data *wd = elm_widget_data_get(obj);
492 if (!wd) return EINA_FALSE;
493 return elm_fileselector_button_expandable_get(wd->button);
497 * Set whether the entry's file selector list is to display folders
498 * only or the directory contents, as well.
500 * @param obj The entry object
501 * @param value The "folder only" flag
503 * @ingroup File_Selector_Entry
506 elm_fileselector_entry_folder_only_set(Evas_Object *obj, Eina_Bool value)
508 ELM_CHECK_WIDTYPE(obj, widtype);
509 Widget_Data *wd = elm_widget_data_get(obj);
511 elm_fileselector_button_folder_only_set(wd->button, value);
515 * Get the entry's file selector "folder only" flag.
517 * @param obj The entry object
518 * @return value The "folder only" flag
520 * @ingroup File_Selector_Entry
523 elm_fileselector_entry_folder_only_get(const Evas_Object *obj)
525 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
526 Widget_Data *wd = elm_widget_data_get(obj);
527 if (!wd) return EINA_FALSE;
528 return elm_fileselector_button_folder_only_get(wd->button);
532 * Set whether the entry's file selector has an editable text entry
533 * which will hold its current selection.
535 * @param obj The entry object
536 * @param value The "is save" flag
538 * @ingroup File_Selector_Entry
541 elm_fileselector_entry_is_save_set(Evas_Object *obj, Eina_Bool value)
543 ELM_CHECK_WIDTYPE(obj, widtype);
544 Widget_Data *wd = elm_widget_data_get(obj);
546 elm_fileselector_button_is_save_set(wd->button, value);
550 * Get the entry's file selector "is save" flag.
552 * @param obj The entry object
553 * @return value The "is save" flag
555 * @ingroup File_Selector_Entry
558 elm_fileselector_entry_is_save_get(const Evas_Object *obj)
560 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
561 Widget_Data *wd = elm_widget_data_get(obj);
562 if (!wd) return EINA_FALSE;
563 return elm_fileselector_button_is_save_get(wd->button);
567 * Set whether the entry's file selector will raise an Elementary
568 * Inner Window, instead of a dedicated Elementary Window. By default,
571 * @param obj The entry object
572 * @param value The "inwin mode" flag
574 * @ingroup File_Selector_Entry
577 elm_fileselector_entry_inwin_mode_set(Evas_Object *obj, Eina_Bool value)
579 ELM_CHECK_WIDTYPE(obj, widtype);
580 Widget_Data *wd = elm_widget_data_get(obj);
582 elm_fileselector_button_inwin_mode_set(wd->button, value);
586 * Get the entry's file selector "inwin mode" flag.
588 * @param obj The entry object
589 * @return value The "inwin mode" flag
591 * @ingroup File_Selector_Entry
594 elm_fileselector_entry_inwin_mode_get(const Evas_Object *obj)
596 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
597 Widget_Data *wd = elm_widget_data_get(obj);
598 if (!wd) return EINA_FALSE;
599 return elm_fileselector_button_inwin_mode_get(wd->button);
603 * Set the icon used for the entry button
605 * Once the icon object is set, a previously set one will be deleted.
607 * @param obj The entry object
608 * @param icon The image for the entry
610 * @ingroup File_Selector_Entry
613 elm_fileselector_entry_button_icon_set(Evas_Object *obj, Evas_Object *icon)
615 ELM_CHECK_WIDTYPE(obj, widtype);
616 Widget_Data *wd = elm_widget_data_get(obj);
618 elm_fileselector_button_icon_set(wd->button, icon);
622 * Get the icon used for the entry button
624 * @param obj The entry object
625 * @return The image for the entry
627 * @ingroup File_Selector_Entry
630 elm_fileselector_entry_button_icon_get(const Evas_Object *obj)
632 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
633 Widget_Data *wd = elm_widget_data_get(obj);
634 if (!wd) return NULL;
635 return elm_fileselector_button_icon_get(wd->button);
639 * Unset the icon used for the entry button
641 * Unparent and return the icon object which was set for this widget.
643 * @param obj The entry object
644 * @return The icon object that was being used
646 * @ingroup File_Selector_Entry
649 elm_fileselector_entry_button_icon_unset(Evas_Object *obj)
651 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
652 Widget_Data *wd = elm_widget_data_get(obj);
653 if (!wd) return NULL;
654 return elm_fileselector_button_icon_unset(wd->button);