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_object_text_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_object_text_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 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
239 ELM_CHECK_WIDTYPE(obj, widtype);
240 Widget_Data *wd = elm_widget_data_get(obj);
242 if (part && strcmp(part, "button icon")) return;
243 elm_object_part_content_set(wd->button, NULL, content);
247 _content_get_hook(const Evas_Object *obj, const char *part)
249 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
250 Widget_Data *wd = elm_widget_data_get(obj);
251 if (!wd) return NULL;
252 if (part && strcmp(part, "button icon")) return NULL;
253 return elm_object_part_content_get(wd->button, NULL);
257 _content_unset_hook(Evas_Object *obj, const char *part)
259 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
260 Widget_Data *wd = elm_widget_data_get(obj);
261 if (!wd) return NULL;
262 if (part && strcmp(part, "button icon")) return NULL;
263 return elm_object_part_content_unset(wd->button, NULL);
267 elm_fileselector_entry_add(Evas_Object *parent)
273 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
275 ELM_SET_WIDTYPE(widtype, "fileselector_entry");
276 elm_widget_type_set(obj, "fileselector_entry");
277 elm_widget_sub_object_add(parent, obj);
278 elm_widget_data_set(obj, wd);
279 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
280 elm_widget_del_hook_set(obj, _del_hook);
281 elm_widget_disable_hook_set(obj, _disable_hook);
282 elm_widget_focus_next_hook_set(obj, _elm_fileselector_entry_focus_next_hook);
283 elm_widget_can_focus_set(obj, EINA_FALSE);
284 elm_widget_theme_hook_set(obj, _theme_hook);
285 elm_widget_text_set_hook_set(obj, _elm_fileselector_entry_button_label_set);
286 elm_widget_text_get_hook_set(obj, _elm_fileselector_entry_button_label_get);
287 elm_widget_content_set_hook_set(obj, _content_set_hook);
288 elm_widget_content_get_hook_set(obj, _content_get_hook);
289 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
291 wd->edje = edje_object_add(e);
292 _elm_theme_object_set(obj, wd->edje, "fileselector_entry", "base", "default");
293 elm_widget_resize_object_set(obj, wd->edje);
295 wd->button = elm_fileselector_button_add(obj);
296 elm_widget_mirrored_automatic_set(wd->button, EINA_FALSE);
297 ELM_SET_WIDTYPE(widtype, "fileselector_entry");
298 elm_widget_style_set(wd->button, "fileselector_entry/default");
299 edje_object_part_swallow(wd->edje, "elm.swallow.button", wd->button);
300 elm_widget_sub_object_add(obj, wd->button);
301 evas_object_event_callback_add
302 (wd->button, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
303 elm_fileselector_button_expandable_set(wd->button,
304 _elm_config->fileselector_expand_enable);
306 #define SIG_FWD(name) \
307 evas_object_smart_callback_add(wd->button, SIG_##name, _##name##_fwd, obj)
310 SIG_FWD(FILE_CHOSEN);
313 wd->entry = elm_entry_add(obj);
314 elm_entry_scrollable_set(wd->entry, EINA_TRUE);
315 elm_widget_mirrored_automatic_set(wd->entry, EINA_FALSE);
316 elm_widget_style_set(wd->entry, "fileselector_entry/default");
317 elm_entry_single_line_set(wd->entry, EINA_TRUE);
318 elm_entry_editable_set(wd->entry, EINA_TRUE);
319 edje_object_part_swallow(wd->edje, "elm.swallow.entry", wd->entry);
320 elm_widget_sub_object_add(obj, wd->entry);
321 evas_object_event_callback_add
322 (wd->entry, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
324 #define SIG_FWD(name) \
325 evas_object_smart_callback_add(wd->entry, SIG_##name, _##name##_fwd, obj)
329 SIG_FWD(LONGPRESSED);
331 SIG_FWD(CLICKED_DOUBLE);
334 SIG_FWD(SELECTION_PASTE);
335 SIG_FWD(SELECTION_COPY);
336 SIG_FWD(SELECTION_CUT);
339 _mirrored_set(obj, elm_widget_mirrored_get(obj));
342 // TODO: convert Elementary to subclassing of Evas_Smart_Class
343 // TODO: and save some bytes, making descriptions per-class and not instance!
344 evas_object_smart_callbacks_descriptions_set(obj, _signals);
349 elm_fileselector_entry_selected_set(Evas_Object *obj, const char *path)
351 ELM_CHECK_WIDTYPE(obj, widtype);
352 Widget_Data *wd = elm_widget_data_get(obj);
354 elm_fileselector_button_path_set(wd->button, path);
358 elm_fileselector_entry_selected_get(const Evas_Object *obj)
360 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
361 Widget_Data *wd = elm_widget_data_get(obj);
362 if (!wd) return NULL;
363 return elm_fileselector_button_path_get(wd->button);
367 elm_fileselector_entry_window_title_set(Evas_Object *obj, const char *title)
369 ELM_CHECK_WIDTYPE(obj, widtype);
370 Widget_Data *wd = elm_widget_data_get(obj);
372 elm_fileselector_button_window_title_set(wd->button, title);
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 elm_fileselector_entry_window_size_set(Evas_Object *obj, Evas_Coord width, Evas_Coord height)
387 ELM_CHECK_WIDTYPE(obj, widtype);
388 Widget_Data *wd = elm_widget_data_get(obj);
390 elm_fileselector_button_window_size_set(wd->button, width, height);
394 elm_fileselector_entry_window_size_get(const Evas_Object *obj, Evas_Coord *width, Evas_Coord *height)
396 ELM_CHECK_WIDTYPE(obj, widtype);
397 Widget_Data *wd = elm_widget_data_get(obj);
399 elm_fileselector_button_window_size_get(wd->button, width, height);
403 elm_fileselector_entry_path_set(Evas_Object *obj, const char *path)
405 ELM_CHECK_WIDTYPE(obj, widtype);
406 Widget_Data *wd = elm_widget_data_get(obj);
408 elm_fileselector_button_path_set(wd->button, path);
409 elm_object_text_set(wd->entry, path);
413 elm_fileselector_entry_path_get(const Evas_Object *obj)
415 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
416 Widget_Data *wd = elm_widget_data_get(obj);
417 if (!wd) return NULL;
418 return elm_object_text_get(wd->entry);
422 elm_fileselector_entry_expandable_set(Evas_Object *obj, Eina_Bool value)
424 ELM_CHECK_WIDTYPE(obj, widtype);
425 Widget_Data *wd = elm_widget_data_get(obj);
427 elm_fileselector_button_expandable_set(wd->button, value);
431 elm_fileselector_entry_expandable_get(const Evas_Object *obj)
433 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
434 Widget_Data *wd = elm_widget_data_get(obj);
435 if (!wd) return EINA_FALSE;
436 return elm_fileselector_button_expandable_get(wd->button);
440 elm_fileselector_entry_folder_only_set(Evas_Object *obj, Eina_Bool value)
442 ELM_CHECK_WIDTYPE(obj, widtype);
443 Widget_Data *wd = elm_widget_data_get(obj);
445 elm_fileselector_button_folder_only_set(wd->button, value);
449 elm_fileselector_entry_folder_only_get(const Evas_Object *obj)
451 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
452 Widget_Data *wd = elm_widget_data_get(obj);
453 if (!wd) return EINA_FALSE;
454 return elm_fileselector_button_folder_only_get(wd->button);
458 elm_fileselector_entry_is_save_set(Evas_Object *obj, Eina_Bool value)
460 ELM_CHECK_WIDTYPE(obj, widtype);
461 Widget_Data *wd = elm_widget_data_get(obj);
463 elm_fileselector_button_is_save_set(wd->button, value);
467 elm_fileselector_entry_is_save_get(const Evas_Object *obj)
469 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
470 Widget_Data *wd = elm_widget_data_get(obj);
471 if (!wd) return EINA_FALSE;
472 return elm_fileselector_button_is_save_get(wd->button);
476 elm_fileselector_entry_inwin_mode_set(Evas_Object *obj, Eina_Bool value)
478 ELM_CHECK_WIDTYPE(obj, widtype);
479 Widget_Data *wd = elm_widget_data_get(obj);
481 elm_fileselector_button_inwin_mode_set(wd->button, value);
485 elm_fileselector_entry_inwin_mode_get(const Evas_Object *obj)
487 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
488 Widget_Data *wd = elm_widget_data_get(obj);
489 if (!wd) return EINA_FALSE;
490 return elm_fileselector_button_inwin_mode_get(wd->button);