1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 
5 #define EFL_ACCESS_OBJECT_PROTECTED
6 
7 #include <Elementary.h>
8 #include "Eio_Eo.h"
9 #include "elm_priv.h"
10 #include "elm_fileselector_button_eo.h"
11 #include "elm_fileselector_entry_eo.h"
12 #include "elm_interface_fileselector.h"
13 #include "elm_widget_fileselector_button.h"
14 #include "elm_fileselector_eo.h"
15 
16 #define MY_CLASS ELM_FILESELECTOR_BUTTON_CLASS
17 
18 #define MY_CLASS_NAME "Elm_Fileselector_Button"
19 #define MY_CLASS_NAME_LEGACY "elm_fileselector_button"
20 
21 /* FIXME: need a way to find a gap between the size of item and thumbnail */
22 #define GENGRID_PADDING 16
23 
24 #define DEFAULT_WINDOW_TITLE "Select a file"
25 
26 #define ELM_PRIV_FILESELECTOR_BUTTON_SIGNALS(cmd) \
27    cmd(SIG_FILE_CHOSEN, "file,chosen", "s") \
28 
29 ELM_PRIV_FILESELECTOR_BUTTON_SIGNALS(ELM_PRIV_STATIC_VARIABLE_DECLARE);
30 
31 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
32    ELM_PRIV_FILESELECTOR_BUTTON_SIGNALS(ELM_PRIV_SMART_CALLBACKS_DESC)
33    {SIG_WIDGET_LANG_CHANGED, ""}, /**<handled by elm_widget */
34    {SIG_WIDGET_ACCESS_CHANGED, ""}, /**<handled by elm_widget */
35    {SIG_LAYOUT_FOCUSED, ""}, /**< handled by elm_layout */
36    {SIG_LAYOUT_UNFOCUSED, ""}, /**< handled by elm_layout */
37    {NULL, NULL}
38 };
39 #undef ELM_PRIV_FILESELECTOR_BUTTON_SIGNALS
40 
41 EOLIAN static Eina_Error
_elm_fileselector_button_efl_ui_widget_theme_apply(Eo * obj,Elm_Fileselector_Button_Data * sd EINA_UNUSED)42 _elm_fileselector_button_efl_ui_widget_theme_apply(Eo *obj, Elm_Fileselector_Button_Data *sd EINA_UNUSED)
43 {
44    Eina_Error int_ret = EFL_UI_THEME_APPLY_ERROR_GENERIC;
45 
46    char buf[4096];
47    const char *style;
48 
49    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EFL_UI_THEME_APPLY_ERROR_GENERIC);
50 
51    style = eina_stringshare_add(elm_widget_style_get(obj));
52 
53    snprintf(buf, sizeof(buf), "fileselector_button/%s", style);
54 
55    /* file selector button's style has an extra bit */
56    eina_stringshare_replace(&(wd->style), buf);
57 
58    int_ret = efl_ui_widget_theme_apply(efl_super(obj, MY_CLASS));
59    if (int_ret == EFL_UI_THEME_APPLY_ERROR_GENERIC) return int_ret;
60 
61    eina_stringshare_replace(&(wd->style), style);
62 
63    eina_stringshare_del(style);
64 
65    return int_ret;
66 }
67 
68 static void
_selection_done(void * data,const Efl_Event * event EINA_UNUSED)69 _selection_done(void *data, const Efl_Event *event EINA_UNUSED)
70 {
71    Elm_Fileselector_Button_Data *sd = data;
72    Efl_Model *model;;
73    Evas_Object *del;
74 
75    model = elm_interface_fileselector_selected_model_get(sd->fs);
76    if (model)
77      {
78         Eina_Value *path;
79         char *file;
80 
81         efl_replace(&sd->fsd.model, model);
82 
83         path = efl_model_property_get(model, "path");
84         file = eina_value_to_string(path);
85         eina_stringshare_replace(&sd->fsd.path, file);
86 
87         efl_event_callback_call
88           (sd->obj, ELM_FILESELECTOR_BUTTON_EVENT_FILE_CHOSEN, model);
89         _event_to_legacy_call
90           (sd->obj, ELM_FILESELECTOR_BUTTON_EVENT_FILE_CHOSEN->name, file);
91 
92         eina_value_free(path);
93         free(file);
94      }
95    else
96      {
97         _model_event_call
98           (sd->obj, ELM_FILESELECTOR_BUTTON_EVENT_FILE_CHOSEN, ELM_FILESELECTOR_BUTTON_EVENT_FILE_CHOSEN->name, NULL, NULL);
99      }
100    eina_stringshare_replace(&sd->fsd.current_name, elm_interface_fileselector_current_name_get(sd->fs));
101    del = sd->fsw;
102    sd->fs = NULL;
103    sd->fsw = NULL;
104    evas_object_del(del);
105 }
106 
107 static Evas_Object *
_new_window_add(Elm_Fileselector_Button_Data * sd)108 _new_window_add(Elm_Fileselector_Button_Data *sd)
109 {
110    Evas_Object *win, *bg;
111 
112    win = elm_win_add(NULL, "fileselector_button", ELM_WIN_DIALOG_BASIC);
113    elm_win_title_set(win, sd->window_title);
114    elm_win_autodel_set(win, EINA_TRUE);
115    efl_event_callback_add
116          (win, EFL_UI_WIN_EVENT_DELETE_REQUEST, _selection_done, sd);
117 
118    bg = elm_bg_add(win);
119    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
120    elm_win_resize_object_add(win, bg);
121    evas_object_show(bg);
122 
123    evas_object_resize(win, sd->w, sd->h);
124    return win;
125 }
126 
127 static Evas_Object *
_parent_win_get(Evas_Object * obj)128 _parent_win_get(Evas_Object *obj)
129 {
130    while (!efl_isa(obj, EFL_UI_WIN_CLASS))
131      obj = elm_object_parent_widget_get(obj);
132 
133    return obj;
134 }
135 
136 static void
_activate(Elm_Fileselector_Button_Data * sd)137 _activate(Elm_Fileselector_Button_Data *sd)
138 {
139    Eina_Bool is_inwin = EINA_FALSE;
140 
141    if (sd->fs) return;
142 
143    if (sd->inwin_mode)
144      {
145         sd->fsw = _parent_win_get(sd->obj);
146 
147         if (!sd->fsw)
148           sd->fsw = _new_window_add(sd);
149         else
150           {
151              sd->fsw = elm_win_inwin_add(sd->fsw);
152              is_inwin = EINA_TRUE;
153           }
154      }
155    else
156      sd->fsw = _new_window_add(sd);
157 
158    sd->fs = elm_fileselector_add(sd->fsw);
159    elm_fileselector_hidden_visible_set(sd->fs, sd->fsd.hidden_visible);
160    efl_ui_mirrored_set
161      (sd->fs, efl_ui_mirrored_get(sd->obj));
162    efl_ui_mirrored_automatic_set(sd->fs, EINA_FALSE);
163    elm_fileselector_expandable_set(sd->fs, sd->fsd.expandable);
164    elm_fileselector_folder_only_set(sd->fs, sd->fsd.folder_only);
165    elm_fileselector_is_save_set(sd->fs, sd->fsd.is_save);
166    elm_interface_fileselector_selected_model_set(sd->fs, sd->fsd.model);
167    evas_object_size_hint_weight_set
168      (sd->fs, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
169    evas_object_size_hint_align_set(sd->fs, EVAS_HINT_FILL, EVAS_HINT_FILL);
170    efl_event_callback_add
171      (sd->fs, ELM_FILESELECTOR_EVENT_DONE, _selection_done, sd);
172    evas_object_show(sd->fs);
173 
174    if (is_inwin)
175      {
176         elm_win_inwin_content_set(sd->fsw, sd->fs);
177         elm_win_inwin_activate(sd->fsw);
178      }
179    else
180      {
181         elm_win_resize_object_add(sd->fsw, sd->fs);
182         evas_object_show(sd->fsw);
183      }
184 }
185 
186 static void
_button_clicked(void * data,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)187 _button_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
188 {
189    _activate(data);
190 }
191 
192 static void _noref_death(void *data EINA_UNUSED, const Efl_Event *event);
193 static void _invalidated(void *data EINA_UNUSED, const Efl_Event *event);
194 
195 EFL_CALLBACKS_ARRAY_DEFINE(noref_death,
196                            { EFL_EVENT_NOREF, _noref_death },
197                            { EFL_EVENT_INVALIDATE, _invalidated });
198 
199 static void
_noref_death(void * data EINA_UNUSED,const Efl_Event * event)200 _noref_death(void *data EINA_UNUSED, const Efl_Event *event)
201 {
202    efl_event_callback_array_del(event->object, noref_death(), NULL);
203    efl_del(event->object);
204 }
205 
206 static void
_invalidated(void * data EINA_UNUSED,const Efl_Event * event)207 _invalidated(void *data EINA_UNUSED, const Efl_Event *event)
208 {
209    // This means our parent is dying, EFL_EVENT_NOREF can be called after invalidated
210    efl_event_callback_array_del(event->object, noref_death(), NULL);
211 }
212 
213 EOLIAN static void
_elm_fileselector_button_efl_canvas_group_group_add(Eo * obj,Elm_Fileselector_Button_Data * priv)214 _elm_fileselector_button_efl_canvas_group_group_add(Eo *obj, Elm_Fileselector_Button_Data *priv)
215 {
216    const char *path;
217 
218    efl_canvas_group_add(efl_super(obj, MY_CLASS));
219 
220    priv->window_title = eina_stringshare_add(DEFAULT_WINDOW_TITLE);
221    path = eina_environment_home_get();
222    if (path) priv->fsd.path = eina_stringshare_add(path);
223    else priv->fsd.path = eina_stringshare_add("/");
224 
225    priv->fsd.model = efl_add_ref(EFL_IO_MODEL_CLASS, obj,
226                                  efl_io_model_path_set(efl_added, priv->fsd.path),
227                                  efl_event_callback_array_add(efl_added, noref_death(), NULL));
228 
229    priv->fsd.expandable = _elm_config->fileselector_expand_enable;
230    priv->inwin_mode = _elm_config->inwin_dialogs_enable;
231    priv->w = 400;
232    priv->h = 400;
233 
234    efl_ui_mirrored_automatic_set(obj, EINA_FALSE);
235 
236    evas_object_smart_callback_add(obj, "clicked", _button_clicked, priv);
237 
238 
239    efl_ui_widget_theme_apply(obj);
240    elm_widget_can_focus_set(obj, EINA_TRUE);
241 }
242 
243 EOLIAN static void
_elm_fileselector_button_efl_canvas_group_group_del(Eo * obj,Elm_Fileselector_Button_Data * sd)244 _elm_fileselector_button_efl_canvas_group_group_del(Eo *obj, Elm_Fileselector_Button_Data *sd)
245 {
246    efl_replace(&sd->fsd.model, NULL);
247    eina_stringshare_del(sd->window_title);
248    eina_stringshare_del(sd->fsd.path);
249    if (sd->fsd.selection)
250      efl_unref(sd->fsd.selection);
251    eina_stringshare_del(sd->fsd.selection_path);
252    evas_object_del(sd->fsw);
253 
254    efl_canvas_group_del(efl_super(obj, MY_CLASS));
255 }
256 
257 EOLIAN static void
_elm_fileselector_button_efl_ui_autorepeat_autorepeat_enabled_set(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd EINA_UNUSED,Eina_Bool enabled)258 _elm_fileselector_button_efl_ui_autorepeat_autorepeat_enabled_set(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd EINA_UNUSED, Eina_Bool enabled)
259 {
260    if (enabled)
261      ERR("You cannot enable autorepeat on this object");
262    efl_ui_autorepeat_enabled_set(efl_super(obj, MY_CLASS), EINA_FALSE);
263 }
264 
265 EAPI Evas_Object *
elm_fileselector_button_add(Evas_Object * parent)266 elm_fileselector_button_add(Evas_Object *parent)
267 {
268    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
269    return elm_legacy_add(MY_CLASS, parent);
270 }
271 
272 EOLIAN static Eo *
_elm_fileselector_button_efl_object_constructor(Eo * obj,Elm_Fileselector_Button_Data * sd)273 _elm_fileselector_button_efl_object_constructor(Eo *obj, Elm_Fileselector_Button_Data *sd)
274 {
275    obj = efl_constructor(efl_super(obj, MY_CLASS));
276    sd->obj = obj;
277 
278    efl_ui_autorepeat_enabled_set(obj, EINA_FALSE);
279    efl_canvas_object_type_set(obj, MY_CLASS_NAME_LEGACY);
280    evas_object_smart_callbacks_descriptions_set(obj, _smart_callbacks);
281    efl_access_object_role_set(obj, EFL_ACCESS_ROLE_PUSH_BUTTON);
282    legacy_object_focus_handle(obj);
283 
284    return obj;
285 }
286 
287 EAPI void
elm_fileselector_button_window_title_set(Eo * obj,const char * title)288 elm_fileselector_button_window_title_set(Eo *obj, const char *title)
289 {
290    ELM_FILESELECTOR_BUTTON_CHECK(obj);
291    ELM_FILESELECTOR_BUTTON_DATA_GET_OR_RETURN(obj, sd);
292    eina_stringshare_replace(&sd->window_title, title);
293    if (sd->fsw) elm_win_title_set(sd->fsw, sd->window_title);
294 }
295 
296 EAPI const char *
elm_fileselector_button_window_title_get(const Eo * obj)297 elm_fileselector_button_window_title_get(const Eo *obj)
298 {
299    ELM_FILESELECTOR_BUTTON_CHECK(obj) NULL;
300    ELM_FILESELECTOR_BUTTON_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
301    return sd->window_title;
302 }
303 
304 EAPI void
elm_fileselector_button_window_size_set(Eo * obj,Evas_Coord width,Evas_Coord height)305 elm_fileselector_button_window_size_set(Eo *obj, Evas_Coord width, Evas_Coord height)
306 {
307    ELM_FILESELECTOR_BUTTON_CHECK(obj);
308    ELM_FILESELECTOR_BUTTON_DATA_GET_OR_RETURN(obj, sd);
309    sd->w = width;
310    sd->h = height;
311    if (sd->fsw) evas_object_resize(sd->fsw, sd->w, sd->h);
312 }
313 
314 EAPI void
elm_fileselector_button_window_size_get(const Eo * obj,Evas_Coord * width,Evas_Coord * height)315 elm_fileselector_button_window_size_get(const Eo *obj, Evas_Coord *width, Evas_Coord *height)
316 {
317    if (width) *width = 0;
318    if (height) *height = 0;
319    ELM_FILESELECTOR_BUTTON_CHECK(obj);
320    ELM_FILESELECTOR_BUTTON_DATA_GET_OR_RETURN(obj, sd);
321    if (width) *width = sd->w;
322    if (height) *height = sd->h;
323 }
324 
325 void
_elm_fileselector_button_path_set_internal(Evas_Object * obj,const char * path)326 _elm_fileselector_button_path_set_internal(Evas_Object *obj, const char *path)
327 {
328    ELM_FILESELECTOR_BUTTON_DATA_GET_OR_RETURN(obj, sd);
329 
330    Efl_Model *model = efl_add(EFL_IO_MODEL_CLASS, obj, efl_io_model_path_set(efl_added, path));
331    if (!model)
332      {
333         ERR("Efl.Model allocation error");
334         return;
335      }
336 
337    // XXX: the efl_ref here smells wrong. fsd.model is only unreffed ONCE so this obj leaks...
338    efl_replace(&sd->fsd.model, model);
339 
340    eina_stringshare_replace(&sd->fsd.path, path);
341 
342    if (sd->fs) elm_interface_fileselector_selected_model_set(sd->fs, model);
343 }
344 
345 EINA_DEPRECATED EAPI void
elm_fileselector_button_path_set(Evas_Object * obj,const char * path)346 elm_fileselector_button_path_set(Evas_Object *obj, const char *path)
347 {
348    ELM_FILESELECTOR_INTERFACE_CHECK(obj);
349    elm_fileselector_path_set(obj, path);
350 }
351 
352 EOLIAN static void
_elm_fileselector_button_efl_ui_view_model_set(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd,Efl_Model * model)353 _elm_fileselector_button_efl_ui_view_model_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Efl_Model *model)
354 {
355    char *file = NULL;
356 
357    if (!efl_isa(model, EFL_IO_MODEL_CLASS))
358      return ;
359 
360    efl_replace(&sd->fsd.model, model);
361 
362    if (model)
363      {
364         Eina_Value *path;
365 
366         path = efl_model_property_get(model, "path");
367         file = eina_value_to_string(path);
368         eina_value_free(path);
369      }
370 
371    eina_stringshare_replace(&sd->fsd.path, file);
372 
373    _event_to_legacy_call
374      (sd->obj, ELM_FILESELECTOR_BUTTON_EVENT_FILE_CHOSEN->name, file);
375 
376    free(file);
377 
378    if (sd->fs) elm_interface_fileselector_selected_model_set(sd->fs, model);
379 }
380 
381 const char *
_elm_fileselector_button_path_get_internal(const Evas_Object * obj)382 _elm_fileselector_button_path_get_internal(const Evas_Object *obj)
383 {
384    ELM_FILESELECTOR_BUTTON_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
385    return sd->fsd.path;
386 }
387 
388 EINA_DEPRECATED EAPI const char *
elm_fileselector_button_path_get(const Evas_Object * obj)389 elm_fileselector_button_path_get(const Evas_Object *obj)
390 {
391    ELM_FILESELECTOR_INTERFACE_CHECK(obj, NULL);
392    return elm_fileselector_path_get(obj);
393 }
394 
395 EOLIAN static Efl_Model *
_elm_fileselector_button_efl_ui_view_model_get(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd)396 _elm_fileselector_button_efl_ui_view_model_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
397 {
398    return sd->fsd.model;
399 }
400 
401 EINA_DEPRECATED EAPI void
elm_fileselector_button_expandable_set(Evas_Object * obj,Eina_Bool value)402 elm_fileselector_button_expandable_set(Evas_Object *obj,
403                                        Eina_Bool value)
404 {
405    ELM_FILESELECTOR_INTERFACE_CHECK(obj);
406    elm_interface_fileselector_expandable_set(obj, value);
407 }
408 
409 EOLIAN static void
_elm_fileselector_button_elm_interface_fileselector_expandable_set(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd,Eina_Bool value)410 _elm_fileselector_button_elm_interface_fileselector_expandable_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Eina_Bool value)
411 {
412    sd->fsd.expandable = value;
413 
414    if (sd->fs) elm_fileselector_expandable_set(sd->fs, sd->fsd.expandable);
415 }
416 
417 EINA_DEPRECATED EAPI Eina_Bool
elm_fileselector_button_expandable_get(const Evas_Object * obj)418 elm_fileselector_button_expandable_get(const Evas_Object *obj)
419 {
420    ELM_FILESELECTOR_INTERFACE_CHECK(obj, EINA_FALSE);
421    Eina_Bool ret = EINA_FALSE;
422    ret = elm_interface_fileselector_expandable_get((Eo *) obj);
423    return ret;
424 }
425 
426 EOLIAN static Eina_Bool
_elm_fileselector_button_elm_interface_fileselector_expandable_get(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd)427 _elm_fileselector_button_elm_interface_fileselector_expandable_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
428 {
429    return sd->fsd.expandable;
430 }
431 
432 EINA_DEPRECATED EAPI void
elm_fileselector_button_folder_only_set(Evas_Object * obj,Eina_Bool value)433 elm_fileselector_button_folder_only_set(Evas_Object *obj,
434                                         Eina_Bool value)
435 {
436    ELM_FILESELECTOR_INTERFACE_CHECK(obj);
437    elm_interface_fileselector_folder_only_set(obj, value);
438 }
439 
440 EOLIAN static void
_elm_fileselector_button_elm_interface_fileselector_folder_only_set(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd,Eina_Bool value)441 _elm_fileselector_button_elm_interface_fileselector_folder_only_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Eina_Bool value)
442 {
443    sd->fsd.folder_only = value;
444 
445    if (sd->fs) elm_fileselector_folder_only_set(sd->fs, sd->fsd.folder_only);
446 }
447 
448 EINA_DEPRECATED EAPI Eina_Bool
elm_fileselector_button_folder_only_get(const Evas_Object * obj)449 elm_fileselector_button_folder_only_get(const Evas_Object *obj)
450 {
451    ELM_FILESELECTOR_INTERFACE_CHECK(obj, EINA_FALSE);
452    Eina_Bool ret = EINA_FALSE;
453    ret = elm_interface_fileselector_folder_only_get((Eo *) obj);
454    return ret;
455 }
456 
457 EOLIAN static Eina_Bool
_elm_fileselector_button_elm_interface_fileselector_folder_only_get(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd)458 _elm_fileselector_button_elm_interface_fileselector_folder_only_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
459 {
460    return sd->fsd.folder_only;
461 }
462 
463 EINA_DEPRECATED EAPI void
elm_fileselector_button_is_save_set(Evas_Object * obj,Eina_Bool value)464 elm_fileselector_button_is_save_set(Evas_Object *obj,
465                                     Eina_Bool value)
466 {
467    ELM_FILESELECTOR_INTERFACE_CHECK(obj);
468    elm_interface_fileselector_is_save_set(obj, value);
469 }
470 
471 EOLIAN static void
_elm_fileselector_button_elm_interface_fileselector_is_save_set(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd,Eina_Bool value)472 _elm_fileselector_button_elm_interface_fileselector_is_save_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Eina_Bool value)
473 {
474    sd->fsd.is_save = value;
475 
476    if (sd->fs) elm_fileselector_is_save_set(sd->fs, sd->fsd.is_save);
477 }
478 
479 EINA_DEPRECATED EAPI Eina_Bool
elm_fileselector_button_is_save_get(const Evas_Object * obj)480 elm_fileselector_button_is_save_get(const Evas_Object *obj)
481 {
482    ELM_FILESELECTOR_INTERFACE_CHECK(obj, EINA_FALSE);
483    Eina_Bool ret = EINA_FALSE;
484    ret = elm_interface_fileselector_is_save_get((Eo *) obj);
485    return ret;
486 }
487 
488 EOLIAN static Eina_Bool
_elm_fileselector_button_elm_interface_fileselector_is_save_get(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd)489 _elm_fileselector_button_elm_interface_fileselector_is_save_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
490 {
491    return sd->fsd.is_save;
492 }
493 
494 EOLIAN static void
_elm_fileselector_button_elm_interface_fileselector_mode_set(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd,Elm_Fileselector_Mode mode)495 _elm_fileselector_button_elm_interface_fileselector_mode_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Elm_Fileselector_Mode mode)
496 {
497    sd->fsd.mode = mode;
498 
499    if (sd->fs) elm_fileselector_mode_set(sd->fs, mode);
500 }
501 
502 EOLIAN static Elm_Fileselector_Mode
_elm_fileselector_button_elm_interface_fileselector_mode_get(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd)503 _elm_fileselector_button_elm_interface_fileselector_mode_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
504 {
505    return sd->fsd.mode;
506 }
507 
508 EOLIAN static void
_elm_fileselector_button_elm_interface_fileselector_sort_method_set(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd,Elm_Fileselector_Sort sort)509 _elm_fileselector_button_elm_interface_fileselector_sort_method_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Elm_Fileselector_Sort sort)
510 {
511    sd->fsd.sort_type = sort;
512 
513    if (sd->fs) elm_fileselector_sort_method_set(sd->fs, sort);
514 }
515 
516 EOLIAN static Elm_Fileselector_Sort
_elm_fileselector_button_elm_interface_fileselector_sort_method_get(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd)517 _elm_fileselector_button_elm_interface_fileselector_sort_method_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
518 {
519    return sd->fsd.sort_type;
520 }
521 
522 EOLIAN static void
_elm_fileselector_button_elm_interface_fileselector_multi_select_set(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd,Eina_Bool value)523 _elm_fileselector_button_elm_interface_fileselector_multi_select_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Eina_Bool value)
524 {
525    sd->fsd.multi = value;
526 
527    if (sd->fs) elm_fileselector_multi_select_set(sd->fs, sd->fsd.multi);
528 }
529 
530 EOLIAN static Eina_Bool
_elm_fileselector_button_elm_interface_fileselector_multi_select_get(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd)531 _elm_fileselector_button_elm_interface_fileselector_multi_select_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
532 {
533    return sd->fsd.multi;
534 }
535 
536 const Eina_List *
_elm_fileselector_button_selected_paths_get_internal(const Evas_Object * obj)537 _elm_fileselector_button_selected_paths_get_internal(const Evas_Object *obj)
538 {
539    ELM_FILESELECTOR_BUTTON_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
540 
541    if (sd->fs) return elm_fileselector_selected_paths_get(sd->fs);
542 
543    return NULL;
544 }
545 
546 EOLIAN static const Eina_List*
_elm_fileselector_button_elm_interface_fileselector_selected_models_get(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd)547 _elm_fileselector_button_elm_interface_fileselector_selected_models_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
548 {
549    if (sd->fs) return elm_interface_fileselector_selected_models_get(sd->fs);
550 
551    return NULL;
552 }
553 
554 const char *
_elm_fileselector_button_selected_get_internal(const Evas_Object * obj)555 _elm_fileselector_button_selected_get_internal(const Evas_Object *obj)
556 {
557    ELM_FILESELECTOR_BUTTON_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
558 
559    if (sd->fs) return elm_fileselector_selected_get(sd->fs);
560 
561    return sd->fsd.selection_path;
562 }
563 
564 EOLIAN static Efl_Model *
_elm_fileselector_button_elm_interface_fileselector_selected_model_get(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd)565 _elm_fileselector_button_elm_interface_fileselector_selected_model_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
566 {
567    if (sd->fs) return elm_interface_fileselector_selected_model_get(sd->fs);
568 
569    return sd->fsd.selection;
570 }
571 
572 Eina_Bool
_elm_fileselector_button_selected_set_internal(Evas_Object * obj,const char * _path)573 _elm_fileselector_button_selected_set_internal(Evas_Object *obj, const char *_path)
574 {
575    ELM_FILESELECTOR_BUTTON_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
576    Eina_Bool ret = EINA_TRUE;
577 
578    if (sd->fs) ret = elm_fileselector_selected_set(sd->fs, _path);
579    else
580      {
581         char *path = ecore_file_realpath(_path);
582         if (!ecore_file_is_dir(path) && !ecore_file_exists(path))
583           {
584              free(path);
585              return EINA_FALSE;
586           }
587         free(path);
588      }
589 
590    eina_stringshare_replace(&sd->fsd.selection_path, _path);
591 
592    return ret;
593 }
594 
595 EOLIAN static Eina_Bool
_elm_fileselector_button_elm_interface_fileselector_selected_model_set(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd,Efl_Model * model)596 _elm_fileselector_button_elm_interface_fileselector_selected_model_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Efl_Model *model)
597 {
598    if (sd->fs)
599      elm_interface_fileselector_selected_model_set(sd->fs, model);
600 
601    efl_replace(&sd->fsd.selection, model);
602 
603    return EINA_TRUE;
604 }
605 
606 EOLIAN static void
_elm_fileselector_button_elm_interface_fileselector_thumbnail_size_set(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd,Evas_Coord w,Evas_Coord h)607 _elm_fileselector_button_elm_interface_fileselector_thumbnail_size_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Evas_Coord w, Evas_Coord h)
608 {
609    if (sd->fs)
610      {
611         elm_fileselector_thumbnail_size_set(sd->fs, w, h);
612         elm_fileselector_thumbnail_size_get(sd->fs, &w, &h);
613      }
614    else if (!w || !h)
615      w = h = elm_config_finger_size_get() * 2 - GENGRID_PADDING;
616 
617    sd->fsd.thumbnail_size.w = w;
618    sd->fsd.thumbnail_size.h = h;
619 }
620 
621 EOLIAN static void
_elm_fileselector_button_elm_interface_fileselector_thumbnail_size_get(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd,Evas_Coord * w,Evas_Coord * h)622 _elm_fileselector_button_elm_interface_fileselector_thumbnail_size_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Evas_Coord *w, Evas_Coord *h)
623 {
624    if (w) *w = sd->fsd.thumbnail_size.w;
625    if (h) *h = sd->fsd.thumbnail_size.h;
626 }
627 
628 EOLIAN static void
_elm_fileselector_button_elm_interface_fileselector_hidden_visible_set(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd,Eina_Bool visible)629 _elm_fileselector_button_elm_interface_fileselector_hidden_visible_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Eina_Bool visible)
630 {
631    sd->fsd.hidden_visible = visible;
632 
633    if (sd->fs) elm_fileselector_hidden_visible_set(sd->fs, visible);
634 }
635 
636 EOLIAN static void
_elm_fileselector_button_elm_interface_fileselector_current_name_set(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd,const char * name)637 _elm_fileselector_button_elm_interface_fileselector_current_name_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, const char *name)
638 {
639    eina_stringshare_replace(&sd->fsd.current_name, name);
640    if (sd->fs) elm_fileselector_current_name_set(sd->fs, sd->fsd.current_name);
641 }
642 
643 EOLIAN static const char*
_elm_fileselector_button_elm_interface_fileselector_current_name_get(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd)644 _elm_fileselector_button_elm_interface_fileselector_current_name_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
645 {
646   if (sd->fs)
647     return elm_fileselector_current_name_get(sd->fs);
648 
649   return sd->fsd.current_name;
650 }
651 
652 #define FS_USAGE_API(ret)\
653    if (!pd->fs) \
654      { \
655         ERR("This function is only supported when there is a fileselector"); \
656         return ret; \
657      } \
658 
659 EOLIAN static Eina_Bool
_elm_fileselector_button_elm_interface_fileselector_custom_filter_append(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * pd,Elm_Fileselector_Filter_Func func,void * data,const char * filter_name)660 _elm_fileselector_button_elm_interface_fileselector_custom_filter_append(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *pd, Elm_Fileselector_Filter_Func func, void *data, const char *filter_name)
661 {
662    FS_USAGE_API(EINA_FALSE)
663 
664    return elm_interface_fileselector_custom_filter_append(pd->fs, func, data, filter_name);
665 }
666 
667 EOLIAN static Eina_Bool
_elm_fileselector_button_elm_interface_fileselector_mime_types_filter_append(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * pd,const char * mime_types,const char * filter_name)668 _elm_fileselector_button_elm_interface_fileselector_mime_types_filter_append(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *pd, const char *mime_types, const char *filter_name)
669 {
670    FS_USAGE_API(EINA_FALSE)
671 
672    return elm_interface_fileselector_mime_types_filter_append(pd->fs, mime_types, filter_name);
673 }
674 
675 EOLIAN static void
_elm_fileselector_button_elm_interface_fileselector_filters_clear(Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * pd)676 _elm_fileselector_button_elm_interface_fileselector_filters_clear(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *pd)
677 {
678    FS_USAGE_API()
679 
680    elm_interface_fileselector_filters_clear(pd->fs);
681 }
682 
683 
684 EOLIAN static Eina_Bool
_elm_fileselector_button_elm_interface_fileselector_hidden_visible_get(const Eo * obj EINA_UNUSED,Elm_Fileselector_Button_Data * sd)685 _elm_fileselector_button_elm_interface_fileselector_hidden_visible_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
686 {
687    return sd->fsd.hidden_visible;
688 }
689 
690 EAPI void
elm_fileselector_button_inwin_mode_set(Eo * obj,Eina_Bool value)691 elm_fileselector_button_inwin_mode_set(Eo *obj, Eina_Bool value)
692 {
693    ELM_FILESELECTOR_BUTTON_CHECK(obj);
694    ELM_FILESELECTOR_BUTTON_DATA_GET_OR_RETURN(obj, sd);
695    sd->inwin_mode = value;
696 }
697 
698 EAPI Eina_Bool
elm_fileselector_button_inwin_mode_get(const Eo * obj)699 elm_fileselector_button_inwin_mode_get(const Eo *obj)
700 {
701    ELM_FILESELECTOR_BUTTON_CHECK(obj) EINA_FALSE;
702    ELM_FILESELECTOR_BUTTON_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
703    return sd->inwin_mode;
704 }
705 
706 /* Internal EO APIs and hidden overrides */
707 
708 #define ELM_FILESELECTOR_BUTTON_EXTRA_OPS \
709    EFL_CANVAS_GROUP_ADD_DEL_OPS(elm_fileselector_button)
710 
711 #include "elm_fileselector_button_eo.c"
712