3 /* local subsystem functions */
4 static void _e_dialog_free(E_Dialog *dia);
5 static void _e_dialog_del_func_cb(void *data, E_Dialog *dia);
6 static void _e_dialog_cb_delete(E_Win *win);
7 static void _e_dialog_cb_resize(E_Win *win);
8 static void _e_dialog_cb_key_down(void *data, Evas *e, Evas_Object *obj, void *event);
9 static void _e_dialog_cb_wid_on_focus(void *data, Evas_Object *obj);
11 /* local subsystem globals */
13 /* externally accessible functions */
16 _e_dialog_internal_new(E_Container *con, const char *name, const char *class, int dialog)
21 Evas_Modifier_Mask mask;
26 man = e_manager_current_get();
27 if (!man) return NULL;
28 con = e_container_current_get(man);
29 if (!con) con = e_container_number_get(man, 0);
30 if (!con) return NULL;
32 dia = E_OBJECT_ALLOC(E_Dialog, E_DIALOG_TYPE, _e_dialog_free);
33 if (!dia) return NULL;
34 dia->win = e_win_new(con);
40 e_win_delete_callback_set(dia->win, _e_dialog_cb_delete);
41 e_win_resize_callback_set(dia->win, _e_dialog_cb_resize);
43 if (dialog) e_win_dialog_set(dia->win, 1);
44 e_win_name_class_set(dia->win, name, class);
45 o = edje_object_add(e_win_evas_get(dia->win));
47 e_theme_edje_object_set(o, "base/theme/dialog",
48 "e/widgets/dialog/main");
49 evas_object_move(o, 0, 0);
52 o = e_widget_list_add(e_win_evas_get(dia->win), 1, 1);
53 e_widget_on_focus_hook_set(o, _e_dialog_cb_wid_on_focus, dia);
55 edje_object_part_swallow(dia->bg_object, "e.swallow.buttons", o);
57 o = evas_object_rectangle_add(e_win_evas_get(dia->win));
58 dia->event_object = o;
60 kg = evas_object_key_grab(o, "Tab", mask, ~mask, 0);
62 fprintf(stderr, "ERROR: unable to redirect \"Tab\" key events to object %p.\n", o);
63 mask = evas_key_modifier_mask_get(e_win_evas_get(dia->win), "Shift");
64 kg = evas_object_key_grab(o, "Tab", mask, ~mask, 0);
66 fprintf(stderr, "ERROR: unable to redirect \"Tab\" key events to object %p.\n", o);
68 kg = evas_object_key_grab(o, "Return", mask, ~mask, 0);
70 fprintf(stderr, "ERROR: unable to redirect \"Return\" key events to object %p.\n", o);
72 kg = evas_object_key_grab(o, "Escape", mask, ~mask, 0);
74 fprintf(stderr, "ERROR: unable to redirect \"Escape\" key events to object %p.\n", o);
76 kg = evas_object_key_grab(o, "KP_Enter", mask, ~mask, 0);
78 fprintf(stderr, "ERROR: unable to redirect \"KP_Enter\" key events to object %p.\n", o);
80 evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN, _e_dialog_cb_key_down, dia);
86 e_dialog_new(E_Container *con, const char *name, const char *class)
88 return _e_dialog_internal_new(con, name, class, 1);
92 e_dialog_normal_win_new(E_Container *con, const char *name, const char *class)
94 return _e_dialog_internal_new(con, name, class, 0);
98 e_dialog_button_add(E_Dialog *dia, const char *label, const char *icon, E_Dialog_Cb func, void *data)
102 if (!func) func = _e_dialog_del_func_cb;
103 o = e_widget_button_add(e_win_evas_get(dia->win), label, icon, (void (*)(void *, void *))func, data, dia);
104 e_widget_list_object_append(dia->box_object, o, 1, 0, 0.5);
105 dia->buttons = eina_list_append(dia->buttons, o);
109 e_dialog_button_focus_num(E_Dialog *dia, int button)
113 o = eina_list_nth(dia->buttons, button);
114 if (o) e_widget_focus_steal(o);
119 e_dialog_button_disable_num_set(E_Dialog *dia, int button, int disabled)
123 o = eina_list_nth(dia->buttons, button);
124 if (o) e_widget_disabled_set(o, disabled);
129 e_dialog_button_disable_num_get(E_Dialog *dia, int button)
134 o = eina_list_nth(dia->buttons, button);
135 if (o) ret = e_widget_disabled_get(o);
140 e_dialog_title_set(E_Dialog *dia, const char *title)
142 e_win_title_set(dia->win, title);
146 e_dialog_text_set(E_Dialog *dia, const char *text)
148 if (!dia->text_object)
152 o = edje_object_add(e_win_evas_get(dia->win));
153 dia->text_object = o;
154 e_theme_edje_object_set(o, "base/theme/dialog",
155 "e/widgets/dialog/text");
156 edje_object_part_swallow(dia->bg_object, "e.swallow.content", o);
159 edje_object_part_text_set(dia->text_object, "e.textblock.message", text);
163 e_dialog_icon_set(E_Dialog *dia, const char *icon, Evas_Coord size)
167 dia->icon_object = e_icon_add(e_win_evas_get(dia->win));
168 if (!e_util_icon_theme_set(dia->icon_object, icon))
169 e_icon_file_edje_set(dia->icon_object, icon, "icon");
170 edje_extern_object_min_size_set(dia->icon_object, size * e_scale, size * e_scale);
171 edje_object_part_swallow(dia->bg_object, "e.swallow.icon", dia->icon_object);
172 edje_object_signal_emit(dia->bg_object, "e,state,icon", "e");
173 evas_object_show(dia->icon_object);
177 e_dialog_border_icon_set(E_Dialog *dia, const char *icon)
181 border = dia->win->border;
183 if (border->internal_icon)
185 eina_stringshare_del(border->internal_icon);
186 border->internal_icon = NULL;
189 border->internal_icon = eina_stringshare_add(icon);
193 e_dialog_content_set(E_Dialog *dia, Evas_Object *obj, Evas_Coord minw, Evas_Coord minh)
196 dia->content_object = obj;
197 e_widget_on_focus_hook_set(obj, _e_dialog_cb_wid_on_focus, dia);
198 edje_extern_object_min_size_set(obj, minw, minh);
199 edje_object_part_swallow(dia->bg_object, "e.swallow.content", obj);
200 edje_object_size_min_calc(dia->bg_object, &mw, &mh);
201 e_win_resize(dia->win, mw, mh);
202 e_win_size_min_set(dia->win, mw, mh);
205 evas_object_show(obj);
209 e_dialog_resizable_set(E_Dialog *dia, int resizable)
211 dia->resizable = resizable;
216 e_win_size_max_set(dia->win, 99999, 99999);
217 e_util_win_auto_resize_fill(dia->win);
218 edje_object_signal_emit(dia->bg_object, "e,state,resizeble", "e");
222 e_win_resize(dia->win, dia->min_w, dia->min_h);
223 e_win_size_max_set(dia->win, dia->min_w, dia->min_h);
224 edje_object_signal_emit(dia->bg_object, "e,state,no_resizeble", "e");
230 e_dialog_parent_set(E_Dialog *dia, E_Win *win)
234 ecore_x_icccm_transient_for_set(dia->win->evas_win, win->evas_win);
236 ecore_x_icccm_transient_for_unset(dia->win->evas_win);
237 ecore_evas_modal_set(dia->win->ecore_evas, !!win);
241 e_dialog_show(E_Dialog *dia)
246 o = dia->text_object;
249 edje_object_size_min_calc(o, &mw, &mh);
250 edje_extern_object_min_size_set(o, mw, mh);
251 edje_object_part_swallow(dia->bg_object, "e.swallow.content", o);
255 e_widget_size_min_get(o, &mw, &mh);
256 edje_extern_object_min_size_set(o, mw, mh);
257 edje_object_part_swallow(dia->bg_object, "e.swallow.buttons", o);
259 edje_object_size_min_calc(dia->bg_object, &mw, &mh);
260 e_win_resize(dia->win, mw, mh);
261 e_win_size_min_set(dia->win, mw, mh);
264 if (!dia->resizable) e_win_size_max_set(dia->win, mw, mh);
267 e_win_size_max_set(dia->win, 99999, 99999);
268 e_util_win_auto_resize_fill(dia->win);
270 e_win_show(dia->win);
272 if (!e_widget_focus_get(dia->box_object))
273 e_widget_focus_set(dia->box_object, 1);
276 /* local subsystem functions */
278 _e_dialog_free(E_Dialog *dia)
280 if (dia->buttons) eina_list_free(dia->buttons);
281 if (dia->text_object) evas_object_del(dia->text_object);
282 if (dia->icon_object) evas_object_del(dia->icon_object);
283 if (dia->box_object) evas_object_del(dia->box_object);
284 if (dia->bg_object) evas_object_del(dia->bg_object);
285 if (dia->content_object) evas_object_del(dia->content_object);
286 if (dia->event_object) evas_object_del(dia->event_object);
287 e_object_del(E_OBJECT(dia->win));
292 _e_dialog_del_func_cb(void *data __UNUSED__, E_Dialog *dia)
294 e_util_defer_object_del(E_OBJECT(dia));
298 _e_dialog_cb_key_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event)
300 Evas_Event_Key_Down *ev;
305 if (!strcmp(ev->keyname, "Tab"))
307 if (evas_key_modifier_is_set(evas_key_modifier_get(e_win_evas_get(dia->win)), "Shift"))
309 if (e_widget_focus_get(dia->box_object))
311 if (!e_widget_focus_jump(dia->box_object, 0))
313 if (dia->text_object)
314 e_widget_focus_set(dia->box_object, 0);
317 e_widget_focus_set(dia->content_object, 0);
318 if (!e_widget_focus_get(dia->content_object))
319 e_widget_focus_set(dia->box_object, 0);
325 if (!e_widget_focus_jump(dia->content_object, 0))
326 e_widget_focus_set(dia->box_object, 0);
331 if (e_widget_focus_get(dia->box_object))
333 if (!e_widget_focus_jump(dia->box_object, 1))
335 if (dia->text_object)
336 e_widget_focus_set(dia->box_object, 1);
339 e_widget_focus_set(dia->content_object, 1);
340 if (!e_widget_focus_get(dia->content_object))
341 e_widget_focus_set(dia->box_object, 1);
347 if (!e_widget_focus_jump(dia->content_object, 1))
348 e_widget_focus_set(dia->box_object, 1);
352 else if (((!strcmp(ev->keyname, "Return")) ||
353 (!strcmp(ev->keyname, "KP_Enter"))))
355 Evas_Object *o = NULL;
357 if ((dia->content_object) && (e_widget_focus_get(dia->content_object)))
358 o = e_widget_focused_object_get(dia->content_object);
360 o = e_widget_focused_object_get(dia->box_object);
361 if (o) e_widget_activate(o);
363 else if (!strcmp(ev->keyname, "Escape"))
364 e_object_del(E_OBJECT(dia));
368 _e_dialog_cb_delete(E_Win *win)
373 e_object_del(E_OBJECT(dia));
377 _e_dialog_cb_resize(E_Win *win)
382 evas_object_resize(dia->bg_object, dia->win->w, dia->win->h);
386 _e_dialog_cb_wid_on_focus(void *data, Evas_Object *obj)
391 if (obj == dia->content_object)
392 e_widget_focused_object_clear(dia->box_object);
393 else if (dia->content_object)
394 e_widget_focused_object_clear(dia->content_object);