1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
13 static const char *widtype = NULL;
15 static const char SIG_CHANGED[] = "changed";
16 static const char SIG_ACTIVATED[] = "activated";
17 static const char SIG_PRESS[] = "press";
18 static const char SIG_LONGPRESSED[] = "longpressed";
19 static const char SIG_CLICKED[] = "clicked";
20 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
21 static const char SIG_FOCUSED[] = "focused";
22 static const char SIG_UNFOCUSED[] = "unfocused";
23 static const char SIG_SELECTION_PASTE[] = "selection,paste";
24 static const char SIG_SELECTION_COPY[] = "selection,copy";
25 static const char SIG_SELECTION_CUT[] = "selection,cut";
26 static const char SIG_UNPRESSED[] = "unpressed";
27 static const char SIG_FILE_CHOSEN[] = "file,chosen";
28 static const Evas_Smart_Cb_Description _signals[] =
33 {SIG_LONGPRESSED, ""},
35 {SIG_CLICKED_DOUBLE, ""},
38 {SIG_SELECTION_PASTE, ""},
39 {SIG_SELECTION_COPY, ""},
40 {SIG_SELECTION_CUT, ""},
42 {SIG_FILE_CHOSEN, "s"},
46 #define SIG_FWD(name) \
48 _##name##_fwd(void *data, Evas_Object *obj __UNUSED__, void *event_info) \
50 evas_object_smart_callback_call(data, SIG_##name, event_info); \
56 SIG_FWD(CLICKED_DOUBLE)
59 SIG_FWD(SELECTION_PASTE)
60 SIG_FWD(SELECTION_COPY)
61 SIG_FWD(SELECTION_CUT)
65 static void _del_pre_hook(Evas_Object *obj);
66 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
67 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
70 _FILE_CHOSEN_fwd(void *data, Evas_Object *obj __UNUSED__, void *event_info)
72 Widget_Data *wd = elm_widget_data_get(data);
73 const char *file = event_info;
74 elm_entry_entry_set(wd->entry, file);
75 evas_object_smart_callback_call(data, SIG_FILE_CHOSEN, event_info);
79 _ACTIVATED_fwd(void *data, Evas_Object *obj __UNUSED__, void *event_info)
81 Widget_Data *wd = elm_widget_data_get(data);
82 const char *file = elm_entry_entry_get(wd->entry);
83 elm_fileselector_button_path_set(wd->button, file);
84 evas_object_smart_callback_call(data, SIG_ACTIVATED, event_info);
88 _del_pre_hook(Evas_Object *obj)
90 Widget_Data *wd = elm_widget_data_get(obj);
92 evas_object_event_callback_del_full
93 (wd->button, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
94 evas_object_event_callback_del_full
95 (wd->entry, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
99 _del_hook(Evas_Object *obj)
101 Widget_Data *wd = elm_widget_data_get(obj);
106 _sizing_eval(Evas_Object *obj)
108 Widget_Data *wd = elm_widget_data_get(obj);
109 Evas_Coord minw = -1, minh = -1;
111 edje_object_size_min_calc(wd->edje, &minw, &minh);
112 evas_object_size_hint_min_set(obj, minw, minh);
113 evas_object_size_hint_max_set(obj, -1, -1);
117 _elm_fileselector_entry_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
119 Widget_Data *wd = elm_widget_data_get(obj);
124 Evas_Object *chain[2];
127 if (dir == ELM_FOCUS_PREVIOUS)
129 chain[0] = wd->button;
130 chain[1] = wd->entry;
132 else if (dir == ELM_FOCUS_NEXT)
134 chain[0] = wd->entry;
135 chain[1] = wd->button;
140 unsigned char i = elm_widget_focus_get(chain[1]);
142 if (elm_widget_focus_next_get(chain[i], dir, next))
147 Evas_Object *to_focus;
148 if (elm_widget_focus_next_get(chain[i], dir, &to_focus))
158 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
160 Widget_Data *wd = elm_widget_data_get(obj);
162 elm_widget_mirrored_set(wd->button, rtl);
163 edje_object_mirrored_set(wd->edje, rtl);
167 _theme_hook(Evas_Object *obj)
169 Widget_Data *wd = elm_widget_data_get(obj);
170 const char *style = elm_widget_style_get(obj);
174 _elm_widget_mirrored_reload(obj);
175 _mirrored_set(obj, elm_widget_mirrored_get(obj));
177 _elm_theme_object_set(obj, wd->edje, "fileselector_entry", "base", style);
178 if (elm_object_disabled_get(obj))
179 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
181 if (!style) style = "default";
182 snprintf(buf, sizeof(buf), "fileselector_entry/%s", style);
183 elm_widget_style_set(wd->button, buf);
184 elm_widget_style_set(wd->entry, buf);
186 edje_object_part_swallow(obj, "elm.swallow.button", wd->button);
187 edje_object_part_swallow(obj, "elm.swallow.entry", wd->entry);
189 edje_object_message_signal_process(wd->edje);
190 edje_object_scale_set
191 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
196 _disable_hook(Evas_Object *obj)
198 Widget_Data *wd = elm_widget_data_get(obj);
199 Eina_Bool val = elm_widget_disabled_get(obj);
202 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
204 edje_object_signal_emit(wd->edje, "elm,state,enabled", "elm");
206 elm_widget_disabled_set(wd->button, val);
207 elm_widget_disabled_set(wd->entry, val);
211 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
217 _elm_fileselector_entry_button_label_set(Evas_Object *obj, const char *item, const char *label)
219 ELM_CHECK_WIDTYPE(obj, widtype);
220 Widget_Data *wd = elm_widget_data_get(obj);
221 if (item && strcmp(item, "default")) return;
223 elm_object_text_set(wd->button, label);
227 _elm_fileselector_entry_button_label_get(const Evas_Object *obj, const char *item)
229 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
230 Widget_Data *wd = elm_widget_data_get(obj);
231 if (item && strcmp(item, "default")) return NULL;
232 if (!wd) return NULL;
233 return elm_object_text_get(wd->button);
237 elm_fileselector_entry_add(Evas_Object *parent)
243 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
245 ELM_SET_WIDTYPE(widtype, "fileselector_entry");
246 elm_widget_type_set(obj, "fileselector_entry");
247 elm_widget_sub_object_add(parent, obj);
248 elm_widget_data_set(obj, wd);
249 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
250 elm_widget_del_hook_set(obj, _del_hook);
251 elm_widget_disable_hook_set(obj, _disable_hook);
252 elm_widget_focus_next_hook_set(obj, _elm_fileselector_entry_focus_next_hook);
253 elm_widget_can_focus_set(obj, EINA_FALSE);
254 elm_widget_theme_hook_set(obj, _theme_hook);
255 elm_widget_text_set_hook_set(obj, _elm_fileselector_entry_button_label_set);
256 elm_widget_text_get_hook_set(obj, _elm_fileselector_entry_button_label_get);
258 wd->edje = edje_object_add(e);
259 _elm_theme_object_set(obj, wd->edje, "fileselector_entry", "base", "default");
260 elm_widget_resize_object_set(obj, wd->edje);
262 wd->button = elm_fileselector_button_add(obj);
263 elm_widget_mirrored_automatic_set(wd->button, EINA_FALSE);
264 ELM_SET_WIDTYPE(widtype, "fileselector_entry");
265 elm_widget_style_set(wd->button, "fileselector_entry/default");
266 edje_object_part_swallow(wd->edje, "elm.swallow.button", wd->button);
267 elm_widget_sub_object_add(obj, wd->button);
268 evas_object_event_callback_add
269 (wd->button, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
270 elm_fileselector_button_expandable_set(wd->button,
271 _elm_config->fileselector_expand_enable);
273 #define SIG_FWD(name) \
274 evas_object_smart_callback_add(wd->button, SIG_##name, _##name##_fwd, obj)
277 SIG_FWD(FILE_CHOSEN);
280 wd->entry = elm_entry_add(obj);
281 elm_entry_scrollable_set(wd->entry, EINA_TRUE);
282 elm_widget_mirrored_automatic_set(wd->entry, EINA_FALSE);
283 elm_widget_style_set(wd->entry, "fileselector_entry/default");
284 elm_entry_single_line_set(wd->entry, EINA_TRUE);
285 elm_entry_editable_set(wd->entry, EINA_TRUE);
286 edje_object_part_swallow(wd->edje, "elm.swallow.entry", wd->entry);
287 elm_widget_sub_object_add(obj, wd->entry);
288 evas_object_event_callback_add
289 (wd->entry, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
291 #define SIG_FWD(name) \
292 evas_object_smart_callback_add(wd->entry, SIG_##name, _##name##_fwd, obj)
296 SIG_FWD(LONGPRESSED);
298 SIG_FWD(CLICKED_DOUBLE);
301 SIG_FWD(SELECTION_PASTE);
302 SIG_FWD(SELECTION_COPY);
303 SIG_FWD(SELECTION_CUT);
306 _mirrored_set(obj, elm_widget_mirrored_get(obj));
309 // TODO: convert Elementary to subclassing of Evas_Smart_Class
310 // TODO: and save some bytes, making descriptions per-class and not instance!
311 evas_object_smart_callbacks_descriptions_set(obj, _signals);
316 elm_fileselector_entry_button_label_set(Evas_Object *obj, const char *label)
318 _elm_fileselector_entry_button_label_set(obj, NULL, label);
322 elm_fileselector_entry_button_label_get(const Evas_Object *obj)
324 return _elm_fileselector_entry_button_label_get(obj, NULL);
328 elm_fileselector_entry_selected_set(Evas_Object *obj, const char *path)
330 ELM_CHECK_WIDTYPE(obj, widtype);
331 Widget_Data *wd = elm_widget_data_get(obj);
333 elm_fileselector_button_path_set(wd->button, path);
337 elm_fileselector_entry_selected_get(const Evas_Object *obj)
339 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
340 Widget_Data *wd = elm_widget_data_get(obj);
341 if (!wd) return NULL;
342 return elm_fileselector_button_path_get(wd->button);
346 elm_fileselector_entry_window_title_set(Evas_Object *obj, const char *title)
348 ELM_CHECK_WIDTYPE(obj, widtype);
349 Widget_Data *wd = elm_widget_data_get(obj);
351 elm_fileselector_button_window_title_set(wd->button, title);
355 elm_fileselector_entry_window_title_get(const Evas_Object *obj)
357 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
358 Widget_Data *wd = elm_widget_data_get(obj);
359 if (!wd) return NULL;
360 return elm_fileselector_button_window_title_get(wd->button);
364 elm_fileselector_entry_window_size_set(Evas_Object *obj, Evas_Coord width, Evas_Coord height)
366 ELM_CHECK_WIDTYPE(obj, widtype);
367 Widget_Data *wd = elm_widget_data_get(obj);
369 elm_fileselector_button_window_size_set(wd->button, width, height);
373 elm_fileselector_entry_window_size_get(const Evas_Object *obj, Evas_Coord *width, Evas_Coord *height)
375 ELM_CHECK_WIDTYPE(obj, widtype);
376 Widget_Data *wd = elm_widget_data_get(obj);
378 elm_fileselector_button_window_size_get(wd->button, width, height);
382 elm_fileselector_entry_path_set(Evas_Object *obj, const char *path)
384 ELM_CHECK_WIDTYPE(obj, widtype);
385 Widget_Data *wd = elm_widget_data_get(obj);
387 elm_fileselector_button_path_set(wd->button, path);
388 elm_entry_entry_set(wd->entry, path);
392 elm_fileselector_entry_path_get(const Evas_Object *obj)
394 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
395 Widget_Data *wd = elm_widget_data_get(obj);
396 if (!wd) return NULL;
397 return elm_entry_entry_get(wd->entry);
401 elm_fileselector_entry_expandable_set(Evas_Object *obj, Eina_Bool value)
403 ELM_CHECK_WIDTYPE(obj, widtype);
404 Widget_Data *wd = elm_widget_data_get(obj);
406 elm_fileselector_button_expandable_set(wd->button, value);
410 elm_fileselector_entry_expandable_get(const Evas_Object *obj)
412 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
413 Widget_Data *wd = elm_widget_data_get(obj);
414 if (!wd) return EINA_FALSE;
415 return elm_fileselector_button_expandable_get(wd->button);
419 elm_fileselector_entry_folder_only_set(Evas_Object *obj, Eina_Bool value)
421 ELM_CHECK_WIDTYPE(obj, widtype);
422 Widget_Data *wd = elm_widget_data_get(obj);
424 elm_fileselector_button_folder_only_set(wd->button, value);
428 elm_fileselector_entry_folder_only_get(const Evas_Object *obj)
430 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
431 Widget_Data *wd = elm_widget_data_get(obj);
432 if (!wd) return EINA_FALSE;
433 return elm_fileselector_button_folder_only_get(wd->button);
437 elm_fileselector_entry_is_save_set(Evas_Object *obj, Eina_Bool value)
439 ELM_CHECK_WIDTYPE(obj, widtype);
440 Widget_Data *wd = elm_widget_data_get(obj);
442 elm_fileselector_button_is_save_set(wd->button, value);
446 elm_fileselector_entry_is_save_get(const Evas_Object *obj)
448 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
449 Widget_Data *wd = elm_widget_data_get(obj);
450 if (!wd) return EINA_FALSE;
451 return elm_fileselector_button_is_save_get(wd->button);
455 elm_fileselector_entry_inwin_mode_set(Evas_Object *obj, Eina_Bool value)
457 ELM_CHECK_WIDTYPE(obj, widtype);
458 Widget_Data *wd = elm_widget_data_get(obj);
460 elm_fileselector_button_inwin_mode_set(wd->button, value);
464 elm_fileselector_entry_inwin_mode_get(const Evas_Object *obj)
466 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
467 Widget_Data *wd = elm_widget_data_get(obj);
468 if (!wd) return EINA_FALSE;
469 return elm_fileselector_button_inwin_mode_get(wd->button);
473 elm_fileselector_entry_button_icon_set(Evas_Object *obj, Evas_Object *icon)
475 ELM_CHECK_WIDTYPE(obj, widtype);
476 Widget_Data *wd = elm_widget_data_get(obj);
478 elm_fileselector_button_icon_set(wd->button, icon);
482 elm_fileselector_entry_button_icon_get(const Evas_Object *obj)
484 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
485 Widget_Data *wd = elm_widget_data_get(obj);
486 if (!wd) return NULL;
487 return elm_fileselector_button_icon_get(wd->button);
491 elm_fileselector_entry_button_icon_unset(Evas_Object *obj)
493 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
494 Widget_Data *wd = elm_widget_data_get(obj);
495 if (!wd) return NULL;
496 return elm_fileselector_button_icon_unset(wd->button);