summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_layout_pack.c
blob: a6cbd55853ac69c13aa57d27e5ce653ab3c4d4de (plain)
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
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#define ELM_LAYOUT_PROTECTED
#define EFL_UI_LAYOUT_INTERNAL_BOX_PROTECTED
#define EFL_UI_LAYOUT_INTERNAL_TABLE_PROTECTED

#include <Elementary.h>

#include "elm_priv.h"
#include "elm_widget_layout.h"
#include "elm_part_helper.h"

#include "efl_ui_layout_internal_box.eo.h"
#include "efl_ui_layout_internal_table.eo.h"
#include "../evas/canvas/evas_box.eo.h"
#include "../evas/canvas/evas_table.eo.h"

/* layout internals for box & table */
Eina_Bool    _efl_ui_layout_box_append(Eo *obj, Elm_Layout_Smart_Data *sd, const char *part, Evas_Object *child);
Eina_Bool    _efl_ui_layout_box_prepend(Eo *obj, Elm_Layout_Smart_Data *sd, const char *part, Evas_Object *child);
Eina_Bool    _efl_ui_layout_box_insert_before(Eo *obj, Elm_Layout_Smart_Data *sd, const char *part, Evas_Object *child, const Evas_Object *reference);
Eina_Bool    _efl_ui_layout_box_insert_at(Eo *obj, Elm_Layout_Smart_Data *sd, const char *part, Evas_Object *child, unsigned int pos);
Evas_Object *_efl_ui_layout_box_remove(Eo *obj, Elm_Layout_Smart_Data *sd, const char *part, Evas_Object *child);
Eina_Bool    _efl_ui_layout_box_remove_all(Eo *obj, Elm_Layout_Smart_Data *sd, const char *part, Eina_Bool clear);
Eina_Bool    _efl_ui_layout_table_pack(Eo *obj, Elm_Layout_Smart_Data *sd, const char *part, Evas_Object *child, unsigned short col, unsigned short row, unsigned short colspan, unsigned short rowspan);
Evas_Object *_efl_ui_layout_table_unpack(Eo *obj, Elm_Layout_Smart_Data *sd, const char *part, Evas_Object *child);
Eina_Bool    _efl_ui_layout_table_clear(Eo *obj, Elm_Layout_Smart_Data *sd, const char *part, Eina_Bool clear);

#define BOX_CLASS   EFL_UI_LAYOUT_INTERNAL_BOX_CLASS
#define TABLE_CLASS EFL_UI_LAYOUT_INTERNAL_TABLE_CLASS

typedef struct _Layout_Part_Data   Efl_Ui_Layout_Box_Data;
typedef struct _Layout_Part_Data   Efl_Ui_Layout_Table_Data;
typedef struct _Part_Item_Iterator Part_Item_Iterator;

struct _Layout_Part_Data
{
   Efl_Ui_Layout         *obj; // no ref
   Elm_Layout_Smart_Data *sd;  // data xref
   Eina_Stringshare      *part;
   unsigned char          temp;
};

struct _Part_Item_Iterator
{
   Eina_Iterator  iterator;
   Eina_List     *list;
   Eina_Iterator *real_iterator;
   Eo            *object;
};

Eo *
_efl_ui_layout_pack_proxy_get(Efl_Ui_Layout *obj, Edje_Part_Type type, const char *part)
{
   if (type == EDJE_PART_TYPE_BOX)
     return efl_add(BOX_CLASS, obj,
                   efl_ui_layout_internal_box_real_part_set(efl_added, obj, part));
   else if (type == EDJE_PART_TYPE_TABLE)
     return efl_add(TABLE_CLASS, obj,
                   efl_ui_layout_internal_table_real_part_set(efl_added, obj, part));
   else
     return NULL;
}

EOLIAN static void
_efl_ui_layout_internal_box_efl_object_destructor(Eo *obj, Efl_Ui_Layout_Table_Data *pd)
{
   ELM_PART_HOOK;
   efl_data_xunref(pd->obj, pd->sd, obj);
   eina_stringshare_del(pd->part);
   efl_destructor(efl_super(obj, BOX_CLASS));
}

EOLIAN static void
_efl_ui_layout_internal_box_real_part_set(Eo *obj, Efl_Ui_Layout_Box_Data *pd, Eo *layout, const char *part)
{
   pd->obj = layout;
   pd->sd = efl_data_xref(pd->obj, EFL_UI_LAYOUT_CLASS, obj);
   eina_stringshare_replace(&pd->part, part);
   pd->temp = 1;
}

/* this iterator is the same as efl_ui_box */
static Eina_Bool
_part_item_iterator_next(Part_Item_Iterator *it, void **data)
{
   Efl_Gfx *sub;

   if (!it->object) return EINA_FALSE;
   if (!eina_iterator_next(it->real_iterator, (void **) &sub))
     return EINA_FALSE;

   if (data) *data = sub;
   return EINA_TRUE;
}

static Eo *
_part_item_iterator_get_container(Part_Item_Iterator *it)
{
   return it->object;
}

static void
_part_item_iterator_free(Part_Item_Iterator *it)
{
   eina_iterator_free(it->real_iterator);
   efl_wref_del(it->object, &it->object);
   eina_list_free(it->list);
   free(it);
}

static Eina_Iterator *
_part_item_iterator_create(Eo *obj, Eina_Iterator *real_iterator, Eina_List *list)
{
   Part_Item_Iterator *it;

   it = calloc(1, sizeof(*it));
   if (!it) return NULL;

   EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);

   it->list = list;
   it->real_iterator = real_iterator;
   it->iterator.version = EINA_ITERATOR_VERSION;
   it->iterator.next = FUNC_ITERATOR_NEXT(_part_item_iterator_next);
   it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(_part_item_iterator_get_container);
   it->iterator.free = FUNC_ITERATOR_FREE(_part_item_iterator_free);
   efl_wref_add(obj, &it->object);

   return &it->iterator;
}

EOLIAN static Eina_Iterator *
_efl_ui_layout_internal_box_efl_container_content_iterate(Eo *obj, Efl_Ui_Layout_Box_Data *pd)
{
   Eina_Iterator *it;
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);
   it = evas_object_box_iterator_new(pack);
   ELM_PART_RETURN_VAL(_part_item_iterator_create(obj, it, NULL));
}

EOLIAN static int
_efl_ui_layout_internal_box_efl_container_content_count(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd)
{
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);
   ELM_PART_RETURN_VAL(evas_obj_box_count(pack));
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_box_efl_pack_pack_clear(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd)
{
   ELM_PART_RETURN_VAL(_efl_ui_layout_box_remove_all(pd->obj, pd->sd, pd->part, EINA_TRUE));
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_box_efl_pack_unpack_all(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd)
{
   ELM_PART_RETURN_VAL(_efl_ui_layout_box_remove_all(pd->obj, pd->sd, pd->part, EINA_FALSE));
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_box_efl_pack_unpack(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd, Efl_Gfx *subobj)
{
   ELM_PART_RETURN_VAL(_efl_ui_layout_box_remove(pd->obj, pd->sd, pd->part, subobj) != NULL);
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_box_efl_container_content_remove(Eo *obj, Efl_Ui_Layout_Box_Data *pd, Efl_Gfx *content)
{
   // alias for efl_pack_unpack
   return _efl_ui_layout_internal_box_efl_pack_unpack(obj, pd, content);
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_box_efl_pack_pack(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd, Efl_Gfx *subobj)
{
   ELM_PART_RETURN_VAL(_efl_ui_layout_box_append(pd->obj, pd->sd, pd->part, subobj));
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_box_efl_pack_linear_pack_begin(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd, Efl_Gfx *subobj)
{
   ELM_PART_RETURN_VAL(_efl_ui_layout_box_prepend(pd->obj, pd->sd, pd->part, subobj));
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_box_efl_pack_linear_pack_end(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd, Efl_Gfx *subobj)
{
   ELM_PART_RETURN_VAL(_efl_ui_layout_box_append(pd->obj, pd->sd, pd->part, subobj));
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_box_efl_pack_linear_pack_before(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd, Efl_Gfx *subobj, const Efl_Gfx *existing)
{
   ELM_PART_RETURN_VAL(_efl_ui_layout_box_insert_before(pd->obj, pd->sd, pd->part, subobj, existing));
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_box_efl_pack_linear_pack_after(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd, Efl_Gfx *subobj, const Efl_Gfx *existing)
{
   const Efl_Gfx *other;
   int index;
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);
   index = efl_pack_index_get(pack, existing);
   if (index < 0) ELM_PART_RETURN_VAL(EINA_FALSE);

   other = efl_pack_content_get(pack, index + 1);
   if (other)
     ELM_PART_RETURN_VAL(_efl_ui_layout_box_insert_before(pd->obj, pd->sd, pd->part, subobj, other));

   ELM_PART_CALL(efl_pack_end(obj, subobj));
   ELM_PART_RETURN_VAL(EINA_TRUE);
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_box_efl_pack_linear_pack_at(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd, Efl_Gfx *subobj, int index)
{
   ELM_PART_RETURN_VAL(_efl_ui_layout_box_insert_at(pd->obj, pd->sd, pd->part, subobj, index));
}

EOLIAN static Efl_Gfx *
_efl_ui_layout_internal_box_efl_pack_linear_pack_content_get(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd, int index)
{
   Evas_Object_Box_Option *opt;
   Evas_Object_Box_Data *priv;
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);

   priv = efl_data_scope_get(pack, EVAS_BOX_CLASS);
   opt = eina_list_nth(priv->children, index);
   if (!opt) ELM_PART_RETURN_VAL(NULL);
   ELM_PART_RETURN_VAL(opt->obj);
}

EOLIAN static Efl_Gfx *
_efl_ui_layout_internal_box_efl_pack_linear_pack_unpack_at(Eo *obj, Efl_Ui_Layout_Box_Data *pd, int index)
{
   Efl_Gfx *subobj;
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);

   subobj = efl_pack_content_get(pack, index);
   if (!subobj) ELM_PART_RETURN_VAL(NULL);
   if (efl_pack_unpack(obj, subobj))
     ELM_PART_RETURN_VAL(subobj);

   ERR("failed to remove %p from %p (item %d)", subobj, pd->obj, index);
   ELM_PART_RETURN_VAL(NULL);
}

EOLIAN static int
_efl_ui_layout_internal_box_efl_pack_linear_pack_index_get(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd, const Efl_Gfx *subobj)
{
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);
   ELM_PART_RETURN_VAL(efl_pack_index_get(pack, subobj));
}

EOLIAN static Efl_Orient
_efl_ui_layout_internal_box_efl_orientation_orientation_get(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Box_Data *pd)
{
   ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EFL_ORIENT_NONE);

   ELM_PART_RETURN_VAL(efl_orientation_get(efl_part(wd->resize_obj, pd->part)));
}


/* Table proxy implementation */

EOLIAN static void
_efl_ui_layout_internal_table_real_part_set(Eo *obj, Efl_Ui_Layout_Table_Data *pd, Eo *layout, const char *part)
{
   pd->obj = layout;
   pd->sd = efl_data_xref(pd->obj, EFL_UI_LAYOUT_CLASS, obj);
   eina_stringshare_replace(&pd->part, part);
   pd->temp = 1;
}

EOLIAN static void
_efl_ui_layout_internal_table_efl_object_destructor(Eo *obj, Efl_Ui_Layout_Table_Data *pd)
{
   ELM_PART_HOOK;
   efl_data_xunref(pd->obj, pd->sd, obj);
   eina_stringshare_del(pd->part);
   efl_destructor(efl_super(obj, TABLE_CLASS));
}

EOLIAN static Eina_Iterator *
_efl_ui_layout_internal_table_efl_container_content_iterate(Eo *obj, Efl_Ui_Layout_Table_Data *pd)
{
   Eina_Iterator *it;
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);

   it = evas_object_table_iterator_new(pack);

   ELM_PART_RETURN_VAL(_part_item_iterator_create(obj, it, NULL));
}

EOLIAN static int
_efl_ui_layout_internal_table_efl_container_content_count(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Table_Data *pd)
{
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);
   ELM_PART_RETURN_VAL(evas_obj_table_count(pack));
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_table_efl_pack_pack_clear(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Table_Data *pd)
{
   ELM_PART_RETURN_VAL(_efl_ui_layout_table_clear(pd->obj, pd->sd, pd->part, EINA_TRUE));
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_table_efl_pack_unpack_all(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Table_Data *pd)
{
   ELM_PART_RETURN_VAL(_efl_ui_layout_table_clear(pd->obj, pd->sd, pd->part, EINA_FALSE));
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_table_efl_pack_unpack(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Table_Data *pd, Efl_Gfx *subobj)
{
   if (!subobj) ELM_PART_RETURN_VAL(EINA_FALSE);
   ELM_PART_RETURN_VAL(_efl_ui_layout_table_unpack(pd->obj, pd->sd, pd->part, subobj) == subobj);
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_table_efl_container_content_remove(Eo *obj, Efl_Ui_Layout_Table_Data *pd, Efl_Gfx *content)
{
   // alias for efl_pack_unpack
   return _efl_ui_layout_internal_table_efl_pack_unpack(obj, pd, content);
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_table_efl_pack_grid_pack_grid(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Table_Data *pd, Efl_Gfx *subobj, int col, int row, int colspan, int rowspan)
{
   ELM_PART_RETURN_VAL(_efl_ui_layout_table_pack(pd->obj, pd->sd, pd->part, subobj, col, row, colspan, rowspan));
}

EOLIAN static Efl_Gfx *
_efl_ui_layout_internal_table_efl_pack_grid_grid_content_get(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Table_Data *pd, int col, int row)
{
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);
   ELM_PART_RETURN_VAL(evas_object_table_child_get(pack, col, row));
}

EOLIAN static Eina_Iterator *
_efl_ui_layout_internal_table_efl_pack_grid_grid_contents_get(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Table_Data *pd, int col, int row, Eina_Bool below)
{
   // contents at col,row - see also Efl.Ui.Grid or edje_containers.c
   // not reusing edje's iterator because the container would be wrong

   Eina_List *list, *l = NULL;
   Evas_Object *sobj;
   unsigned short c, r, cs, rs;
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);

   list = evas_object_table_children_get(pack);
   EINA_LIST_FREE(list, sobj)
     {
        evas_object_table_pack_get(pack, sobj, &c, &r, &cs, &rs);

        if (((int) c == col) && ((int) r == row))
          list = eina_list_append(list, sobj);
        else if (below)
          {
             if (((int) c <= col) && ((int) (c + cs) >= col) &&
                 ((int) r <= row) && ((int) (r + rs) >= row))
               list = eina_list_append(list, sobj);
          }
     }

   ELM_PART_RETURN_VAL(_part_item_iterator_create(pd->obj, eina_list_iterator_new(l), l));
}

EOLIAN static Eina_Bool
_efl_ui_layout_internal_table_efl_pack_grid_grid_position_get(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Table_Data *pd, Efl_Gfx * subobj, int *col, int *row, int *colspan, int *rowspan)
{
   unsigned short c, r, cs, rs;
   Eina_Bool ret;
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);

   ret = evas_object_table_pack_get(pack, subobj, &c, &r, &cs, &rs);
   if (col) *col = c;
   if (row) *row = r;
   if (colspan) *colspan = cs;
   if (rowspan) *rowspan = rs;

   ELM_PART_RETURN_VAL(ret);
}

EOLIAN static void
_efl_ui_layout_internal_table_efl_pack_grid_grid_size_get(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Table_Data *pd, int *cols, int *rows)
{
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);
   evas_object_table_col_row_size_get(pack, cols, rows);
}

EOLIAN static int
_efl_ui_layout_internal_table_efl_pack_grid_grid_columns_get(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Table_Data *pd)
{
   int cols, rows;
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);
   evas_object_table_col_row_size_get(pack, &cols, &rows);
   ELM_PART_RETURN_VAL(cols);
}

EOLIAN static int
_efl_ui_layout_internal_table_efl_pack_grid_grid_rows_get(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Table_Data *pd)
{
   int cols, rows;
   Eo *pack = (Eo *) edje_object_part_object_get(pd->obj, pd->part);
   evas_object_table_col_row_size_get(pack, &cols, &rows);
   ELM_PART_RETURN_VAL(rows);
}

#include "efl_ui_layout_internal_box.eo.c"
#include "efl_ui_layout_internal_table.eo.c"