Merge remote-tracking branch 'remotes/origin/upstream'
[framework/uifw/elementary.git] / src / lib / elm_grid.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 typedef struct _Widget_Data Widget_Data;
5
6 struct _Widget_Data
7 {
8    Evas_Object *obj, *grd;
9 };
10
11 static const char *widtype = NULL;
12 static void _del_hook(Evas_Object *obj);
13 static void _theme_hook(Evas_Object *obj);
14
15 static void
16 _del_hook(Evas_Object *obj)
17 {
18    Widget_Data *wd = elm_widget_data_get(obj);
19    if (!wd) return;
20    free(wd);
21 }
22
23 static Eina_Bool
24 _elm_grid_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
25 {
26    Widget_Data *wd = elm_widget_data_get(obj);
27    const Eina_List *items;
28    void *(*list_data_get) (const Eina_List *list);
29    Eina_List *(*list_free) (Eina_List *list);
30
31    if ((!wd) || (!wd->grd))
32       return EINA_FALSE;
33
34    /* Focus chain */
35    /* TODO: Change this to use other chain */
36    if ((items = elm_widget_focus_custom_chain_get(obj)))
37      {
38         list_data_get = eina_list_data_get;
39         list_free = NULL;
40      }
41    else
42      {
43         items = evas_object_grid_children_get(wd->grd);
44         list_data_get = eina_list_data_get;
45         list_free = eina_list_free;
46
47         if (!items) return EINA_FALSE;
48      }
49
50    Eina_Bool ret = elm_widget_focus_list_next_get(obj, items, list_data_get,
51                                                   dir, next);
52
53    if (list_free)
54 <<<<<<< HEAD
55       list_free((Eina_List *)items);
56 =======
57      list_free((Eina_List *)items);
58 >>>>>>> remotes/origin/upstream
59
60    return ret;
61 }
62
63 static void
64 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
65 {
66    Widget_Data *wd = elm_widget_data_get(obj);
67    if ((!wd) || (!wd->grd)) return;
68    evas_object_grid_mirrored_set(wd->grd, rtl);
69 }
70
71 static void
72 _theme_hook(Evas_Object *obj)
73 {
74    _elm_widget_mirrored_reload(obj);
75    _mirrored_set(obj, elm_widget_mirrored_get(obj));
76 }
77
78 EAPI Evas_Object *
79 elm_grid_add(Evas_Object *parent)
80 {
81    Evas_Object *obj;
82    Evas *e;
83    Widget_Data *wd;
84
85    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
86 <<<<<<< HEAD
87
88    ELM_SET_WIDTYPE(widtype, "grid");
89    wd->obj = obj;
90 =======
91    ELM_SET_WIDTYPE(widtype, "grid");
92 >>>>>>> remotes/origin/upstream
93    elm_widget_type_set(obj, "grid");
94    elm_widget_sub_object_add(parent, obj);
95    elm_widget_data_set(obj, wd);
96    elm_widget_del_hook_set(obj, _del_hook);
97    elm_widget_focus_next_hook_set(obj, _elm_grid_focus_next_hook);
98    elm_widget_can_focus_set(obj, EINA_FALSE);
99    elm_widget_theme_hook_set(obj, _theme_hook);
100
101    wd->grd = evas_object_grid_add(e);
102    evas_object_grid_size_set(wd->grd, 100, 100);
103    elm_widget_resize_object_set(obj, wd->grd);
104
105    _mirrored_set(obj, elm_widget_mirrored_get(obj));
106    return obj;
107 }
108
109 EAPI void
110 <<<<<<< HEAD
111 elm_grid_size_set(Evas_Object *obj, int w, int h)
112 =======
113 elm_grid_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
114 >>>>>>> remotes/origin/upstream
115 {
116    ELM_CHECK_WIDTYPE(obj, widtype);
117    Widget_Data *wd = elm_widget_data_get(obj);
118    if (!wd) return;
119    evas_object_grid_size_set(wd->grd, w, h);
120 }
121
122 EAPI void
123 <<<<<<< HEAD
124 elm_grid_size_get(Evas_Object *obj, int *w, int *h)
125 =======
126 elm_grid_size_get(const Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
127 >>>>>>> remotes/origin/upstream
128 {
129    ELM_CHECK_WIDTYPE(obj, widtype);
130    Widget_Data *wd = elm_widget_data_get(obj);
131    if (!wd) return;
132    evas_object_grid_size_get(wd->grd, w, h);
133 }
134
135 EAPI void
136 <<<<<<< HEAD
137 elm_grid_pack(Evas_Object *obj, Evas_Object *subobj, int x, int y, int w, int h)
138 =======
139 elm_grid_pack(Evas_Object *obj, Evas_Object *subobj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
140 >>>>>>> remotes/origin/upstream
141 {
142    ELM_CHECK_WIDTYPE(obj, widtype);
143    Widget_Data *wd = elm_widget_data_get(obj);
144    if (!wd) return;
145    elm_widget_sub_object_add(obj, subobj);
146    evas_object_grid_pack(wd->grd, subobj, x, y, w, h);
147 }
148
149 EAPI void
150 elm_grid_unpack(Evas_Object *obj, Evas_Object *subobj)
151 {
152    ELM_CHECK_WIDTYPE(obj, widtype);
153    Widget_Data *wd = elm_widget_data_get(obj);
154    if (!wd) return;
155    elm_widget_sub_object_del(obj, subobj);
156    evas_object_grid_unpack(wd->grd, subobj);
157 }
158
159 EAPI void
160 elm_grid_clear(Evas_Object *obj, Eina_Bool clear)
161 {
162    Eina_List *chld;
163    Evas_Object *o;
164    ELM_CHECK_WIDTYPE(obj, widtype);
165    Widget_Data *wd = elm_widget_data_get(obj);
166    if (!wd) return;
167    chld = evas_object_grid_children_get(wd->grd);
168    EINA_LIST_FREE(chld, o) elm_widget_sub_object_del(obj, o);
169    evas_object_grid_clear(wd->grd, clear);
170 }
171
172 EAPI void
173 <<<<<<< HEAD
174 elm_grid_pack_set(Evas_Object *subobj, int x, int y, int w, int h)
175 =======
176 elm_grid_pack_set(Evas_Object *subobj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
177 >>>>>>> remotes/origin/upstream
178 {
179    Evas_Object *obj = elm_widget_parent_widget_get(subobj);
180    ELM_CHECK_WIDTYPE(obj, widtype);
181    Widget_Data *wd = elm_widget_data_get(obj);
182    if (!wd) return;
183    evas_object_grid_pack(wd->grd, subobj, x, y, w, h);
184 }
185
186 EAPI void
187 elm_grid_pack_get(Evas_Object *subobj, int *x, int *y, int *w, int *h)
188 {
189    Evas_Object *obj = elm_widget_parent_widget_get(subobj);
190    ELM_CHECK_WIDTYPE(obj, widtype);
191    Widget_Data *wd = elm_widget_data_get(obj);
192    if (!wd) return;
193    evas_object_grid_pack_get(wd->grd, subobj, x, y, w, h);
194 }
195 <<<<<<< HEAD
196 =======
197
198 EAPI Eina_List *
199 elm_grid_children_get(const Evas_Object *obj)
200 {
201    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
202    Widget_Data *wd = elm_widget_data_get(obj);
203    if (!wd) return NULL;
204    return evas_object_grid_children_get(wd->grd);
205 }
206 >>>>>>> remotes/origin/upstream