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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
|
#include "e.h"
/* FIXME: something is weird here - i had to reverse all stacking logic to make
* it work... */
typedef struct _E_Smart_Data E_Smart_Data;
typedef struct _E_Layout_Item E_Layout_Item;
struct _E_Smart_Data
{
Evas_Coord x, y, w, h;
Evas_Coord vw, vh;
Evas_Object *obj;
Evas_Object *clip;
int frozen;
unsigned char changed : 1;
Eina_List *items;
};
struct _E_Layout_Item
{
E_Smart_Data *sd;
Evas_Coord x, y, w, h;
Evas_Object *obj;
};
/* local subsystem functions */
static E_Layout_Item *_e_layout_smart_adopt(E_Smart_Data *sd, Evas_Object *obj);
static void _e_layout_smart_disown(Evas_Object *obj);
static void _e_layout_smart_item_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _e_layout_smart_reconfigure(E_Smart_Data *sd);
static void _e_layout_smart_move_resize_item(E_Layout_Item *li);
static void _e_layout_smart_init(void);
static void _e_layout_smart_add(Evas_Object *obj);
static void _e_layout_smart_del(Evas_Object *obj);
static void _e_layout_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
static void _e_layout_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
static void _e_layout_smart_show(Evas_Object *obj);
static void _e_layout_smart_hide(Evas_Object *obj);
static void _e_layout_smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
static void _e_layout_smart_clip_set(Evas_Object *obj, Evas_Object *clip);
static void _e_layout_smart_clip_unset(Evas_Object *obj);
/* local subsystem globals */
static Evas_Smart *_e_smart = NULL;
/* externally accessible functions */
EAPI Evas_Object *
e_layout_add(Evas *evas)
{
_e_layout_smart_init();
return evas_object_smart_add(evas, _e_smart);
}
EAPI int
e_layout_freeze(Evas_Object *obj)
{
E_Smart_Data *sd;
if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
sd = evas_object_smart_data_get(obj);
sd->frozen++;
return sd->frozen;
}
EAPI int
e_layout_thaw(Evas_Object *obj)
{
E_Smart_Data *sd;
if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
sd = evas_object_smart_data_get(obj);
sd->frozen--;
if (sd->frozen <= 0) _e_layout_smart_reconfigure(sd);
return sd->frozen;
}
EAPI void
e_layout_virtual_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
{
E_Smart_Data *sd;
if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
sd = evas_object_smart_data_get(obj);
if (w < 1) w = 1;
if (h < 1) h = 1;
if ((sd->vw == w) && (sd->vh == h)) return;
sd->vw = w;
sd->vh = h;
sd->changed = 1;
if (sd->frozen <= 0) _e_layout_smart_reconfigure(sd);
}
EAPI void
e_layout_virtual_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
{
E_Smart_Data *sd;
if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
sd = evas_object_smart_data_get(obj);
if (w) *w = sd->vw;
if (h) *h = sd->vh;
}
EAPI void
e_layout_coord_canvas_to_virtual(Evas_Object *obj, Evas_Coord cx, Evas_Coord cy, Evas_Coord *vx, Evas_Coord *vy)
{
E_Smart_Data *sd;
if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
sd = evas_object_smart_data_get(obj);
if (vx) *vx = (cx - sd->x) * ((double)(sd->vw) / sd->w);
if (vy) *vy = (cy - sd->y) * ((double)(sd->vh) / sd->h);
}
EAPI void
e_layout_coord_virtual_to_canvas(Evas_Object *obj, Evas_Coord vx, Evas_Coord vy, Evas_Coord *cx, Evas_Coord *cy)
{
E_Smart_Data *sd;
if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
sd = evas_object_smart_data_get(obj);
if (cx) *cx = vx * ((double)(sd->w) / sd->vw) + sd->x;
if (cy) *cy = vy * ((double)(sd->h) / sd->vh) + sd->y;
}
EAPI void
e_layout_pack(Evas_Object *obj, Evas_Object *child)
{
E_Smart_Data *sd;
E_Layout_Item *li;
if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
sd = evas_object_smart_data_get(obj);
_e_layout_smart_adopt(sd, child);
sd->items = eina_list_append(sd->items, child);
li = evas_object_data_get(child, "e_layout_data");
_e_layout_smart_move_resize_item(li);
}
EAPI void
e_layout_child_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
{
E_Layout_Item *li;
li = evas_object_data_get(obj, "e_layout_data");
if (!li) return;
if ((li->x == x) && (li->y == y)) return;
li->x = x;
li->y = y;
_e_layout_smart_move_resize_item(li);
}
EAPI void
e_layout_child_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
{
E_Layout_Item *li;
li = evas_object_data_get(obj, "e_layout_data");
if (!li) return;
if (w < 0) w = 0;
if (h < 0) h = 0;
if ((li->w == w) && (li->h == h)) return;
li->w = w;
li->h = h;
_e_layout_smart_move_resize_item(li);
}
EAPI void
e_layout_child_lower(Evas_Object *obj)
{
E_Layout_Item *li;
li = evas_object_data_get(obj, "e_layout_data");
if (!li) return;
if (!eina_list_data_find(li->sd->items, obj)) return;
if ((li->sd->items) && eina_list_next(li->sd->items))
{
li->sd->items = eina_list_remove(li->sd->items, obj);
evas_object_lower(obj);
li->sd->items = eina_list_prepend(li->sd->items, obj);
}
}
EAPI void
e_layout_child_raise(Evas_Object *obj)
{
E_Layout_Item *li;
li = evas_object_data_get(obj, "e_layout_data");
if (!li) return;
if (!eina_list_data_find(li->sd->items, obj)) return;
if ((li->sd->items) && eina_list_next(li->sd->items))
{
li->sd->items = eina_list_remove(li->sd->items, obj);
evas_object_raise(obj);
li->sd->items = eina_list_append(li->sd->items, obj);
}
}
EAPI void
e_layout_child_lower_below(Evas_Object *obj, Evas_Object *below)
{
E_Layout_Item *li;
li = evas_object_data_get(obj, "e_layout_data");
if (!li) return;
if (!eina_list_data_find(li->sd->items, below)) return;
if (!eina_list_data_find(li->sd->items, obj)) return;
if ((li->sd->items) && eina_list_next(li->sd->items))
{
li->sd->items = eina_list_remove(li->sd->items, obj);
evas_object_stack_below(obj, below);
li->sd->items = eina_list_prepend_relative(li->sd->items, obj, below);
}
}
EAPI void
e_layout_child_raise_above(Evas_Object *obj, Evas_Object *above)
{
E_Layout_Item *li;
li = evas_object_data_get(obj, "e_layout_data");
if (!li) return;
if (!eina_list_data_find(li->sd->items, above)) return;
if (!eina_list_data_find(li->sd->items, obj)) return;
if ((li->sd->items) && eina_list_next(li->sd->items))
{
li->sd->items = eina_list_remove(li->sd->items, obj);
evas_object_stack_above(obj, above);
li->sd->items = eina_list_append_relative(li->sd->items, obj, above);
}
}
EAPI void
e_layout_child_geometry_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
{
E_Layout_Item *li;
li = evas_object_data_get(obj, "e_layout_data");
if (!li) return;
if (x) *x = li->x;
if (y) *y = li->y;
if (w) *w = li->w;
if (h) *h = li->h;
}
EAPI void
e_layout_unpack(Evas_Object *obj)
{
E_Layout_Item *li;
E_Smart_Data *sd;
li = evas_object_data_get(obj, "e_layout_data");
if (!li) return;
sd = li->sd;
sd->items = eina_list_remove(sd->items, obj);
_e_layout_smart_disown(obj);
}
/* local subsystem functions */
static E_Layout_Item *
_e_layout_smart_adopt(E_Smart_Data *sd, Evas_Object *obj)
{
E_Layout_Item *li;
li = calloc(1, sizeof(E_Layout_Item));
if (!li) return NULL;
li->sd = sd;
li->obj = obj;
/* defaults */
li->x = 0;
li->y = 0;
li->w = 0;
li->h = 0;
evas_object_clip_set(obj, sd->clip);
evas_object_smart_member_add(obj, li->sd->obj);
evas_object_data_set(obj, "e_layout_data", li);
evas_object_event_callback_add(obj, EVAS_CALLBACK_FREE,
_e_layout_smart_item_del_hook, NULL);
if ((!evas_object_visible_get(sd->clip)) &&
(evas_object_visible_get(sd->obj)))
evas_object_show(sd->clip);
return li;
}
static void
_e_layout_smart_disown(Evas_Object *obj)
{
E_Layout_Item *li;
li = evas_object_data_get(obj, "e_layout_data");
if (!li) return;
if (!li->sd->items)
{
if (evas_object_visible_get(li->sd->clip))
evas_object_hide(li->sd->clip);
}
evas_object_event_callback_del(obj,
EVAS_CALLBACK_FREE,
_e_layout_smart_item_del_hook);
evas_object_smart_member_del(obj);
evas_object_data_del(obj, "e_layout_data");
free(li);
}
static void
_e_layout_smart_item_del_hook(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
{
e_layout_unpack(obj);
}
static void
_e_layout_smart_reconfigure(E_Smart_Data *sd)
{
Eina_List *l;
Evas_Object *obj;
if (!sd->changed) return;
EINA_LIST_FOREACH(sd->items, l, obj)
{
E_Layout_Item *li;
li = evas_object_data_get(obj, "e_layout_data");
_e_layout_smart_move_resize_item(li);
}
sd->changed = 0;
}
static void
_e_layout_smart_move_resize_item(E_Layout_Item *li)
{
evas_object_move(li->obj,
li->sd->x + ((li->x * li->sd->w) / li->sd->vw),
li->sd->y + ((li->y * li->sd->h) / li->sd->vh));
evas_object_resize(li->obj,
(li->w * li->sd->w) / li->sd->vw,
(li->h * li->sd->h) / li->sd->vh);
}
static void
_e_layout_smart_init(void)
{
if (_e_smart) return;
{
static const Evas_Smart_Class sc =
{
"e_layout",
EVAS_SMART_CLASS_VERSION,
_e_layout_smart_add,
_e_layout_smart_del,
_e_layout_smart_move,
_e_layout_smart_resize,
_e_layout_smart_show,
_e_layout_smart_hide,
_e_layout_smart_color_set,
_e_layout_smart_clip_set,
_e_layout_smart_clip_unset,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
_e_smart = evas_smart_class_new(&sc);
}
}
static void
_e_layout_smart_add(Evas_Object *obj)
{
E_Smart_Data *sd;
sd = calloc(1, sizeof(E_Smart_Data));
if (!sd) return;
sd->obj = obj;
sd->x = 0;
sd->y = 0;
sd->w = 0;
sd->h = 0;
sd->vw = 1;
sd->vh = 1;
sd->clip = evas_object_rectangle_add(evas_object_evas_get(obj));
evas_object_smart_member_add(sd->clip, obj);
evas_object_move(sd->clip, -100001, -100001);
evas_object_resize(sd->clip, 200002, 200002);
evas_object_color_set(sd->clip, 255, 255, 255, 255);
evas_object_smart_data_set(obj, sd);
}
static void
_e_layout_smart_del(Evas_Object *obj)
{
E_Smart_Data *sd;
sd = evas_object_smart_data_get(obj);
if (!sd) return;
while (sd->items)
{
Evas_Object *child;
child = eina_list_data_get(sd->items);
e_layout_unpack(child);
}
evas_object_del(sd->clip);
free(sd);
}
static void
_e_layout_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
{
E_Smart_Data *sd;
Evas_Object *item;
sd = evas_object_smart_data_get(obj);
if (!sd) return;
if ((x == sd->x) && (y == sd->y)) return;
if ((x == sd->x) && (y == sd->y)) return;
{
Eina_List *l;
Evas_Coord dx, dy;
dx = x - sd->x;
dy = y - sd->y;
EINA_LIST_FOREACH(sd->items, l, item)
{
Evas_Coord ox, oy;
evas_object_geometry_get(item, &ox, &oy, NULL, NULL);
evas_object_move(item, ox + dx, oy + dy);
}
}
sd->x = x;
sd->y = y;
}
static void
_e_layout_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
{
E_Smart_Data *sd;
sd = evas_object_smart_data_get(obj);
if (!sd) return;
if ((w == sd->w) && (h == sd->h)) return;
sd->w = w;
sd->h = h;
sd->changed = 1;
_e_layout_smart_reconfigure(sd);
}
static void
_e_layout_smart_show(Evas_Object *obj)
{
E_Smart_Data *sd;
sd = evas_object_smart_data_get(obj);
if (!sd) return;
if (sd->items) evas_object_show(sd->clip);
}
static void
_e_layout_smart_hide(Evas_Object *obj)
{
E_Smart_Data *sd;
sd = evas_object_smart_data_get(obj);
if (!sd) return;
evas_object_hide(sd->clip);
}
static void
_e_layout_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
{
E_Smart_Data *sd;
sd = evas_object_smart_data_get(obj);
if (!sd) return;
evas_object_color_set(sd->clip, r, g, b, a);
}
static void
_e_layout_smart_clip_set(Evas_Object *obj, Evas_Object *clip)
{
E_Smart_Data *sd;
sd = evas_object_smart_data_get(obj);
if (!sd) return;
evas_object_clip_set(sd->clip, clip);
}
static void
_e_layout_smart_clip_unset(Evas_Object *obj)
{
E_Smart_Data *sd;
sd = evas_object_smart_data_get(obj);
if (!sd) return;
evas_object_clip_unset(sd->clip);
}
|