1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
14 static const char *widtype = NULL;
16 static const char SIG_CHANGED[] = "changed";
17 static const char SIG_ACTIVATED[] = "activated";
18 static const char SIG_PRESS[] = "press";
19 static const char SIG_LONGPRESSED[] = "longpressed";
20 static const char SIG_CLICKED[] = "clicked";
21 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
22 static const char SIG_FOCUSED[] = "focused";
23 static const char SIG_UNFOCUSED[] = "unfocused";
24 static const char SIG_SELECTION_PASTE[] = "selection,paste";
25 static const char SIG_SELECTION_COPY[] = "selection,copy";
26 static const char SIG_SELECTION_CUT[] = "selection,cut";
27 static const char SIG_UNPRESSED[] = "unpressed";
28 static const char SIG_FILE_CHOSEN[] = "file,chosen";
29 static const Evas_Smart_Cb_Description _signals[] =
34 {SIG_LONGPRESSED, ""},
36 {SIG_CLICKED_DOUBLE, ""},
39 {SIG_SELECTION_PASTE, ""},
40 {SIG_SELECTION_COPY, ""},
41 {SIG_SELECTION_CUT, ""},
43 {SIG_FILE_CHOSEN, "s"},
47 #define SIG_FWD(name) \
49 _##name##_fwd(void *data, Evas_Object *obj __UNUSED__, void *event_info) \
51 evas_object_smart_callback_call(data, SIG_##name, event_info); \
57 SIG_FWD(CLICKED_DOUBLE)
60 SIG_FWD(SELECTION_PASTE)
61 SIG_FWD(SELECTION_COPY)
62 SIG_FWD(SELECTION_CUT)
66 static void _del_pre_hook(Evas_Object *obj);
67 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
68 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
71 _FILE_CHOSEN_fwd(void *data, Evas_Object *obj __UNUSED__, void *event_info)
73 Widget_Data *wd = elm_widget_data_get(data);
74 const char *file = event_info;
77 s = elm_entry_utf8_to_markup(file);
79 elm_object_text_set(wd->entry, s);
81 evas_object_smart_callback_call(data, SIG_FILE_CHOSEN, event_info);
85 _ACTIVATED_fwd(void *data, Evas_Object *obj __UNUSED__, void *event_info)
87 Widget_Data *wd = elm_widget_data_get(data);
88 const char *file = elm_object_text_get(wd->entry);
89 elm_fileselector_button_path_set(wd->button, file);
90 evas_object_smart_callback_call(data, SIG_ACTIVATED, event_info);
94 _del_pre_hook(Evas_Object *obj)
96 Widget_Data *wd = elm_widget_data_get(obj);
98 evas_object_event_callback_del_full
99 (wd->button, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
100 evas_object_event_callback_del_full
101 (wd->entry, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
105 _del_hook(Evas_Object *obj)
107 Widget_Data *wd = elm_widget_data_get(obj);
108 if (wd->path) free(wd->path);
113 _sizing_eval(Evas_Object *obj)
115 Widget_Data *wd = elm_widget_data_get(obj);
116 Evas_Coord minw = -1, minh = -1;
118 edje_object_size_min_calc(wd->edje, &minw, &minh);
119 evas_object_size_hint_min_set(obj, minw, minh);
120 evas_object_size_hint_max_set(obj, -1, -1);
124 _elm_fileselector_entry_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
126 Widget_Data *wd = elm_widget_data_get(obj);
131 Evas_Object *chain[2];
134 if (dir == ELM_FOCUS_PREVIOUS)
136 chain[0] = wd->button;
137 chain[1] = wd->entry;
139 else if (dir == ELM_FOCUS_NEXT)
141 chain[0] = wd->entry;
142 chain[1] = wd->button;
147 unsigned char i = elm_widget_focus_get(chain[1]);
149 if (elm_widget_focus_next_get(chain[i], dir, next))
154 Evas_Object *to_focus;
155 if (elm_widget_focus_next_get(chain[i], dir, &to_focus))
165 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
167 Widget_Data *wd = elm_widget_data_get(obj);
169 elm_widget_mirrored_set(wd->button, rtl);
170 edje_object_mirrored_set(wd->edje, rtl);
174 _theme_hook(Evas_Object *obj)
176 Widget_Data *wd = elm_widget_data_get(obj);
177 const char *style = elm_widget_style_get(obj);
181 _elm_widget_mirrored_reload(obj);
182 _mirrored_set(obj, elm_widget_mirrored_get(obj));
184 _elm_theme_object_set(obj, wd->edje, "fileselector_entry", "base", style);
185 if (elm_object_disabled_get(obj))
186 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
188 if (!style) style = "default";
189 snprintf(buf, sizeof(buf), "fileselector_entry/%s", style);
190 elm_widget_style_set(wd->button, buf);
191 elm_widget_style_set(wd->entry, buf);
193 edje_object_part_swallow(obj, "elm.swallow.button", wd->button);
194 edje_object_part_swallow(obj, "elm.swallow.entry", wd->entry);
196 edje_object_message_signal_process(wd->edje);
197 edje_object_scale_set
198 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
203 _disable_hook(Evas_Object *obj)
205 Widget_Data *wd = elm_widget_data_get(obj);
206 Eina_Bool val = elm_widget_disabled_get(obj);
209 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
211 edje_object_signal_emit(wd->edje, "elm,state,enabled", "elm");
213 elm_widget_disabled_set(wd->button, val);
214 elm_widget_disabled_set(wd->entry, val);
218 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
224 _elm_fileselector_entry_button_label_set(Evas_Object *obj, const char *item, const char *label)
226 ELM_CHECK_WIDTYPE(obj, widtype);
227 Widget_Data *wd = elm_widget_data_get(obj);
228 if (item && strcmp(item, "default")) return;
230 elm_object_text_set(wd->button, label);
234 _elm_fileselector_entry_button_label_get(const Evas_Object *obj, const char *item)
236 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
237 Widget_Data *wd = elm_widget_data_get(obj);
238 if (item && strcmp(item, "default")) return NULL;
239 if (!wd) return NULL;
240 return elm_object_text_get(wd->button);
244 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
246 ELM_CHECK_WIDTYPE(obj, widtype);
247 Widget_Data *wd = elm_widget_data_get(obj);
249 if (part && strcmp(part, "button icon")) return;
250 elm_object_part_content_set(wd->button, NULL, content);
254 _content_get_hook(const Evas_Object *obj, const char *part)
256 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
257 Widget_Data *wd = elm_widget_data_get(obj);
258 if (!wd) return NULL;
259 if (part && strcmp(part, "button icon")) return NULL;
260 return elm_object_part_content_get(wd->button, NULL);
264 _content_unset_hook(Evas_Object *obj, const char *part)
266 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
267 Widget_Data *wd = elm_widget_data_get(obj);
268 if (!wd) return NULL;
269 if (part && strcmp(part, "button icon")) return NULL;
270 return elm_object_part_content_unset(wd->button, NULL);
274 elm_fileselector_entry_add(Evas_Object *parent)
280 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
282 ELM_SET_WIDTYPE(widtype, "fileselector_entry");
283 elm_widget_type_set(obj, "fileselector_entry");
284 elm_widget_sub_object_add(parent, obj);
285 elm_widget_data_set(obj, wd);
286 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
287 elm_widget_del_hook_set(obj, _del_hook);
288 elm_widget_disable_hook_set(obj, _disable_hook);
289 elm_widget_focus_next_hook_set(obj, _elm_fileselector_entry_focus_next_hook);
290 elm_widget_can_focus_set(obj, EINA_FALSE);
291 elm_widget_theme_hook_set(obj, _theme_hook);
292 elm_widget_text_set_hook_set(obj, _elm_fileselector_entry_button_label_set);
293 elm_widget_text_get_hook_set(obj, _elm_fileselector_entry_button_label_get);
294 elm_widget_content_set_hook_set(obj, _content_set_hook);
295 elm_widget_content_get_hook_set(obj, _content_get_hook);
296 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
298 wd->edje = edje_object_add(e);
299 _elm_theme_object_set(obj, wd->edje, "fileselector_entry", "base", "default");
300 elm_widget_resize_object_set(obj, wd->edje);
302 wd->button = elm_fileselector_button_add(obj);
303 elm_widget_mirrored_automatic_set(wd->button, EINA_FALSE);
304 ELM_SET_WIDTYPE(widtype, "fileselector_entry");
305 elm_widget_style_set(wd->button, "fileselector_entry/default");
306 edje_object_part_swallow(wd->edje, "elm.swallow.button", wd->button);
307 elm_widget_sub_object_add(obj, wd->button);
308 evas_object_event_callback_add
309 (wd->button, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
310 elm_fileselector_button_expandable_set(wd->button,
311 _elm_config->fileselector_expand_enable);
313 #define SIG_FWD(name) \
314 evas_object_smart_callback_add(wd->button, SIG_##name, _##name##_fwd, obj)
317 SIG_FWD(FILE_CHOSEN);
320 wd->entry = elm_entry_add(obj);
321 elm_entry_scrollable_set(wd->entry, EINA_TRUE);
322 elm_widget_mirrored_automatic_set(wd->entry, EINA_FALSE);
323 elm_widget_style_set(wd->entry, "fileselector_entry/default");
324 elm_entry_single_line_set(wd->entry, EINA_TRUE);
325 elm_entry_editable_set(wd->entry, EINA_TRUE);
326 edje_object_part_swallow(wd->edje, "elm.swallow.entry", wd->entry);
327 elm_widget_sub_object_add(obj, wd->entry);
328 evas_object_event_callback_add
329 (wd->entry, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
331 #define SIG_FWD(name) \
332 evas_object_smart_callback_add(wd->entry, SIG_##name, _##name##_fwd, obj)
336 SIG_FWD(LONGPRESSED);
338 SIG_FWD(CLICKED_DOUBLE);
341 SIG_FWD(SELECTION_PASTE);
342 SIG_FWD(SELECTION_COPY);
343 SIG_FWD(SELECTION_CUT);
346 _mirrored_set(obj, elm_widget_mirrored_get(obj));
349 // TODO: convert Elementary to subclassing of Evas_Smart_Class
350 // TODO: and save some bytes, making descriptions per-class and not instance!
351 evas_object_smart_callbacks_descriptions_set(obj, _signals);
356 elm_fileselector_entry_selected_set(Evas_Object *obj, const char *path)
358 ELM_CHECK_WIDTYPE(obj, widtype);
359 Widget_Data *wd = elm_widget_data_get(obj);
361 elm_fileselector_button_path_set(wd->button, path);
365 elm_fileselector_entry_selected_get(const Evas_Object *obj)
367 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
368 Widget_Data *wd = elm_widget_data_get(obj);
369 if (!wd) return NULL;
370 return elm_fileselector_button_path_get(wd->button);
374 elm_fileselector_entry_window_title_set(Evas_Object *obj, const char *title)
376 ELM_CHECK_WIDTYPE(obj, widtype);
377 Widget_Data *wd = elm_widget_data_get(obj);
379 elm_fileselector_button_window_title_set(wd->button, title);
383 elm_fileselector_entry_window_title_get(const Evas_Object *obj)
385 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
386 Widget_Data *wd = elm_widget_data_get(obj);
387 if (!wd) return NULL;
388 return elm_fileselector_button_window_title_get(wd->button);
392 elm_fileselector_entry_window_size_set(Evas_Object *obj, Evas_Coord width, Evas_Coord height)
394 ELM_CHECK_WIDTYPE(obj, widtype);
395 Widget_Data *wd = elm_widget_data_get(obj);
397 elm_fileselector_button_window_size_set(wd->button, width, height);
401 elm_fileselector_entry_window_size_get(const Evas_Object *obj, Evas_Coord *width, Evas_Coord *height)
403 ELM_CHECK_WIDTYPE(obj, widtype);
404 Widget_Data *wd = elm_widget_data_get(obj);
406 elm_fileselector_button_window_size_get(wd->button, width, height);
410 elm_fileselector_entry_path_set(Evas_Object *obj, const char *path)
412 ELM_CHECK_WIDTYPE(obj, widtype);
413 Widget_Data *wd = elm_widget_data_get(obj);
417 elm_fileselector_button_path_set(wd->button, path);
418 s = elm_entry_utf8_to_markup(path);
421 elm_object_text_set(wd->entry, s);
427 elm_fileselector_entry_path_get(const Evas_Object *obj)
429 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
430 Widget_Data *wd = elm_widget_data_get(obj);
432 if (!wd) return NULL;
433 if (wd->path) free(wd->path);
434 wd->path = elm_entry_markup_to_utf8(elm_object_text_get(wd->entry));
439 elm_fileselector_entry_expandable_set(Evas_Object *obj, Eina_Bool value)
441 ELM_CHECK_WIDTYPE(obj, widtype);
442 Widget_Data *wd = elm_widget_data_get(obj);
444 elm_fileselector_button_expandable_set(wd->button, value);
448 elm_fileselector_entry_expandable_get(const Evas_Object *obj)
450 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
451 Widget_Data *wd = elm_widget_data_get(obj);
452 if (!wd) return EINA_FALSE;
453 return elm_fileselector_button_expandable_get(wd->button);
457 elm_fileselector_entry_folder_only_set(Evas_Object *obj, Eina_Bool value)
459 ELM_CHECK_WIDTYPE(obj, widtype);
460 Widget_Data *wd = elm_widget_data_get(obj);
462 elm_fileselector_button_folder_only_set(wd->button, value);
466 elm_fileselector_entry_folder_only_get(const Evas_Object *obj)
468 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
469 Widget_Data *wd = elm_widget_data_get(obj);
470 if (!wd) return EINA_FALSE;
471 return elm_fileselector_button_folder_only_get(wd->button);
475 elm_fileselector_entry_is_save_set(Evas_Object *obj, Eina_Bool value)
477 ELM_CHECK_WIDTYPE(obj, widtype);
478 Widget_Data *wd = elm_widget_data_get(obj);
480 elm_fileselector_button_is_save_set(wd->button, value);
484 elm_fileselector_entry_is_save_get(const Evas_Object *obj)
486 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
487 Widget_Data *wd = elm_widget_data_get(obj);
488 if (!wd) return EINA_FALSE;
489 return elm_fileselector_button_is_save_get(wd->button);
493 elm_fileselector_entry_inwin_mode_set(Evas_Object *obj, Eina_Bool value)
495 ELM_CHECK_WIDTYPE(obj, widtype);
496 Widget_Data *wd = elm_widget_data_get(obj);
498 elm_fileselector_button_inwin_mode_set(wd->button, value);
502 elm_fileselector_entry_inwin_mode_get(const Evas_Object *obj)
504 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
505 Widget_Data *wd = elm_widget_data_get(obj);
506 if (!wd) return EINA_FALSE;
507 return elm_fileselector_button_inwin_mode_get(wd->button);