1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
#include "e.h"
/* local subsystem functions */
static void _e_dialog_free(E_Dialog *dia);
static void _e_dialog_del_func_cb(void *data, E_Dialog *dia);
static void _e_dialog_cb_delete(E_Win *win);
static void _e_dialog_cb_resize(E_Win *win);
static void _e_dialog_cb_key_down(void *data, Evas *e, Evas_Object *obj, void *event);
static void _e_dialog_cb_wid_on_focus(void *data, Evas_Object *obj);
/* local subsystem globals */
/* externally accessible functions */
static E_Dialog *
_e_dialog_internal_new(E_Container *con, const char *name, const char *class, int dialog)
{
E_Dialog *dia;
E_Manager *man;
Evas_Object *o;
Evas_Modifier_Mask mask;
Eina_Bool kg;
if (!con)
{
man = e_manager_current_get();
if (!man) return NULL;
con = e_container_current_get(man);
if (!con) con = e_container_number_get(man, 0);
if (!con) return NULL;
}
dia = E_OBJECT_ALLOC(E_Dialog, E_DIALOG_TYPE, _e_dialog_free);
if (!dia) return NULL;
dia->win = e_win_new(con);
if (!dia->win)
{
free(dia);
return NULL;
}
e_win_delete_callback_set(dia->win, _e_dialog_cb_delete);
e_win_resize_callback_set(dia->win, _e_dialog_cb_resize);
dia->win->data = dia;
if (dialog) e_win_dialog_set(dia->win, 1);
e_win_name_class_set(dia->win, name, class);
o = edje_object_add(e_win_evas_get(dia->win));
dia->bg_object = o;
e_theme_edje_object_set(o, "base/theme/dialog",
"e/widgets/dialog/main");
evas_object_move(o, 0, 0);
evas_object_show(o);
o = e_widget_list_add(e_win_evas_get(dia->win), 1, 1);
e_widget_on_focus_hook_set(o, _e_dialog_cb_wid_on_focus, dia);
dia->box_object = o;
edje_object_part_swallow(dia->bg_object, "e.swallow.buttons", o);
o = evas_object_rectangle_add(e_win_evas_get(dia->win));
dia->event_object = o;
mask = 0;
kg = evas_object_key_grab(o, "Tab", mask, ~mask, 0);
if (!kg)
fprintf(stderr,"ERROR: unable to redirect \"Tab\" key events to object %p.\n", o);
mask = evas_key_modifier_mask_get(e_win_evas_get(dia->win), "Shift");
kg = evas_object_key_grab(o, "Tab", mask, ~mask, 0);
if (!kg)
fprintf(stderr,"ERROR: unable to redirect \"Tab\" key events to object %p.\n", o);
mask = 0;
kg = evas_object_key_grab(o, "Return", mask, ~mask, 0);
if (!kg)
fprintf(stderr,"ERROR: unable to redirect \"Return\" key events to object %p.\n", o);
mask = 0;
kg = evas_object_key_grab(o, "KP_Enter", mask, ~mask, 0);
if (!kg)
fprintf(stderr,"ERROR: unable to redirect \"KP_Enter\" key events to object %p.\n", o);
evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN, _e_dialog_cb_key_down, dia);
return dia;
}
EAPI E_Dialog *
e_dialog_new(E_Container *con, const char *name, const char *class)
{
return _e_dialog_internal_new(con, name, class, 1);
}
EAPI E_Dialog *
e_dialog_normal_win_new(E_Container *con, const char *name, const char *class)
{
return _e_dialog_internal_new(con, name, class, 0);
}
EAPI void
e_dialog_button_add(E_Dialog *dia, const char *label, const char *icon, void (*func) (void *data, E_Dialog *dia), void *data)
{
Evas_Object *o;
if (!func) func = _e_dialog_del_func_cb;
o = e_widget_button_add(e_win_evas_get(dia->win), label, icon, (void (*) (void*, void*)) func, data, dia);
e_widget_list_object_append(dia->box_object, o, 1, 0, 0.5);
dia->buttons = eina_list_append(dia->buttons, o);
}
EAPI int
e_dialog_button_focus_num(E_Dialog *dia, int button)
{
Evas_Object *o;
o = eina_list_nth(dia->buttons, button);
if (o) e_widget_focus_steal(o);
return 1;
}
EAPI int
e_dialog_button_disable_num_set(E_Dialog *dia, int button, int disabled)
{
Evas_Object *o;
o = eina_list_nth(dia->buttons, button);
if (o) e_widget_disabled_set(o, disabled);
return 1;
}
EAPI int
e_dialog_button_disable_num_get(E_Dialog *dia, int button)
{
Evas_Object *o;
int ret = 0;
o = eina_list_nth(dia->buttons, button);
if (o) ret = e_widget_disabled_get(o);
return ret;
}
EAPI void
e_dialog_title_set(E_Dialog *dia, const char *title)
{
e_win_title_set(dia->win, title);
}
EAPI void
e_dialog_text_set(E_Dialog *dia, const char *text)
{
if (!dia->text_object)
{
Evas_Object *o;
o = edje_object_add(e_win_evas_get(dia->win));
dia->text_object = o;
e_theme_edje_object_set(o, "base/theme/dialog",
"e/widgets/dialog/text");
edje_object_part_swallow(dia->bg_object, "e.swallow.content", o);
evas_object_show(o);
}
edje_object_part_text_set(dia->text_object, "e.textblock.message", text);
}
EAPI void
e_dialog_icon_set(E_Dialog *dia, const char *icon, Evas_Coord size)
{
if (!icon) return;
dia->icon_object = e_icon_add(e_win_evas_get(dia->win));
e_util_icon_theme_set(dia->icon_object, icon);
edje_extern_object_min_size_set(dia->icon_object, size * e_scale, size * e_scale);
edje_object_part_swallow(dia->bg_object, "e.swallow.icon", dia->icon_object);
edje_object_signal_emit(dia->bg_object, "e,state,icon", "e");
evas_object_show(dia->icon_object);
}
EAPI void
e_dialog_border_icon_set(E_Dialog *dia, const char *icon)
{
E_Border *border;
border = dia->win->border;
if (!border) return;
if (border->internal_icon)
{
eina_stringshare_del(border->internal_icon);
border->internal_icon = NULL;
}
if (icon)
border->internal_icon = eina_stringshare_add(icon);
}
EAPI void
e_dialog_content_set(E_Dialog *dia, Evas_Object *obj, Evas_Coord minw, Evas_Coord minh)
{
dia->content_object = obj;
e_widget_on_focus_hook_set(obj, _e_dialog_cb_wid_on_focus, dia);
edje_extern_object_min_size_set(obj, minw, minh);
edje_object_part_swallow(dia->bg_object, "e.swallow.content", obj);
evas_object_show(obj);
}
EAPI void
e_dialog_resizable_set(E_Dialog *dia, int resizable)
{
dia->resizable = resizable;
if (dia->win)
{
if (resizable)
{
e_win_size_max_set(dia->win, 99999, 99999);
e_util_win_auto_resize_fill(dia->win);
edje_object_signal_emit(dia->bg_object, "e,state,resizeble", "e");
}
else
{
e_win_resize(dia->win, dia->min_w, dia->min_h);
e_win_size_max_set(dia->win, dia->min_w, dia->min_h);
edje_object_signal_emit(dia->bg_object, "e,state,no_resizeble", "e");
}
}
}
EAPI void
e_dialog_show(E_Dialog *dia)
{
Evas_Coord mw, mh;
Evas_Object *o;
o = dia->text_object;
if (o)
{
edje_object_size_min_calc(o, &mw, &mh);
edje_extern_object_min_size_set(o, mw, mh);
edje_object_part_swallow(dia->bg_object, "e.swallow.content", o);
}
o = dia->box_object;
e_widget_size_min_get(o, &mw, &mh);
edje_extern_object_min_size_set(o, mw, mh);
edje_object_part_swallow(dia->bg_object, "e.swallow.buttons", o);
edje_object_size_min_calc(dia->bg_object, &mw, &mh);
e_win_resize(dia->win, mw, mh);
e_win_size_min_set(dia->win, mw, mh);
dia->min_w = mw;
dia->min_h = mh;
if (!dia->resizable) e_win_size_max_set(dia->win, mw, mh);
else
{
e_win_size_max_set(dia->win, 99999, 99999);
e_util_win_auto_resize_fill(dia->win);
}
e_win_show(dia->win);
if (!e_widget_focus_get(dia->box_object))
e_widget_focus_set(dia->box_object, 1);
}
/* local subsystem functions */
static void
_e_dialog_free(E_Dialog *dia)
{
if (dia->buttons) eina_list_free(dia->buttons);
if (dia->text_object) evas_object_del(dia->text_object);
if (dia->icon_object) evas_object_del(dia->icon_object);
if (dia->box_object) evas_object_del(dia->box_object);
if (dia->bg_object) evas_object_del(dia->bg_object);
if (dia->content_object) evas_object_del(dia->content_object);
if (dia->event_object) evas_object_del(dia->event_object);
e_object_del(E_OBJECT(dia->win));
free(dia);
}
static void
_e_dialog_del_func_cb(void *data __UNUSED__, E_Dialog *dia)
{
e_util_defer_object_del(E_OBJECT(dia));
}
static void
_e_dialog_cb_key_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event)
{
Evas_Event_Key_Down *ev;
E_Dialog *dia;
ev = event;
dia = data;
if (!strcmp(ev->keyname, "Tab"))
{
if (evas_key_modifier_is_set(evas_key_modifier_get(e_win_evas_get(dia->win)), "Shift"))
{
if (e_widget_focus_get(dia->box_object))
{
if (!e_widget_focus_jump(dia->box_object, 0))
{
if (dia->text_object)
e_widget_focus_set(dia->box_object, 0);
else
{
e_widget_focus_set(dia->content_object, 0);
if (!e_widget_focus_get(dia->content_object))
e_widget_focus_set(dia->box_object, 0);
}
}
}
else
{
if (!e_widget_focus_jump(dia->content_object, 0))
e_widget_focus_set(dia->box_object, 0);
}
}
else
{
if (e_widget_focus_get(dia->box_object))
{
if (!e_widget_focus_jump(dia->box_object, 1))
{
if (dia->text_object)
e_widget_focus_set(dia->box_object, 1);
else
{
e_widget_focus_set(dia->content_object, 1);
if (!e_widget_focus_get(dia->content_object))
e_widget_focus_set(dia->box_object, 1);
}
}
}
else
{
if (!e_widget_focus_jump(dia->content_object, 1))
e_widget_focus_set(dia->box_object, 1);
}
}
}
else if (((!strcmp(ev->keyname, "Return")) ||
(!strcmp(ev->keyname, "KP_Enter"))))
{
Evas_Object *o = NULL;
if ((dia->content_object) && (e_widget_focus_get(dia->content_object)))
o = e_widget_focused_object_get(dia->content_object);
else
o = e_widget_focused_object_get(dia->box_object);
if (o) e_widget_activate(o);
}
}
static void
_e_dialog_cb_delete(E_Win *win)
{
E_Dialog *dia;
dia = win->data;
e_object_del(E_OBJECT(dia));
}
static void
_e_dialog_cb_resize(E_Win *win)
{
E_Dialog *dia;
dia = win->data;
evas_object_resize(dia->bg_object, dia->win->w, dia->win->h);
}
static void
_e_dialog_cb_wid_on_focus(void *data, Evas_Object *obj)
{
E_Dialog *dia;
dia = data;
if (obj == dia->content_object)
e_widget_focused_object_clear(dia->box_object);
else if (dia->content_object)
e_widget_focused_object_clear(dia->content_object);
}
|