Merge "[edje_externals/elm_datefield.c] Datefield widget external file is updated...
[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       list_free((Eina_List *)items);
55
56    return ret;
57 }
58
59 static void
60 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
61 {
62    Widget_Data *wd = elm_widget_data_get(obj);
63    if ((!wd) || (!wd->grd)) return;
64    evas_object_grid_mirrored_set(wd->grd, rtl);
65 }
66
67 static void
68 _theme_hook(Evas_Object *obj)
69 {
70    _elm_widget_mirrored_reload(obj);
71    _mirrored_set(obj, elm_widget_mirrored_get(obj));
72 }
73
74 EAPI Evas_Object *
75 elm_grid_add(Evas_Object *parent)
76 {
77    Evas_Object *obj;
78    Evas *e;
79    Widget_Data *wd;
80
81    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
82
83    ELM_SET_WIDTYPE(widtype, "grid");
84    wd->obj = obj;
85    elm_widget_type_set(obj, "grid");
86    elm_widget_sub_object_add(parent, obj);
87    elm_widget_data_set(obj, wd);
88    elm_widget_del_hook_set(obj, _del_hook);
89    elm_widget_focus_next_hook_set(obj, _elm_grid_focus_next_hook);
90    elm_widget_can_focus_set(obj, EINA_FALSE);
91    elm_widget_theme_hook_set(obj, _theme_hook);
92
93    wd->grd = evas_object_grid_add(e);
94    evas_object_grid_size_set(wd->grd, 100, 100);
95    elm_widget_resize_object_set(obj, wd->grd);
96
97    _mirrored_set(obj, elm_widget_mirrored_get(obj));
98    return obj;
99 }
100
101 EAPI void
102 elm_grid_size_set(Evas_Object *obj, int w, int h)
103 {
104    ELM_CHECK_WIDTYPE(obj, widtype);
105    Widget_Data *wd = elm_widget_data_get(obj);
106    if (!wd) return;
107    evas_object_grid_size_set(wd->grd, w, h);
108 }
109
110 EAPI void
111 elm_grid_size_get(Evas_Object *obj, int *w, int *h)
112 {
113    ELM_CHECK_WIDTYPE(obj, widtype);
114    Widget_Data *wd = elm_widget_data_get(obj);
115    if (!wd) return;
116    evas_object_grid_size_get(wd->grd, w, h);
117 }
118
119 EAPI void
120 elm_grid_pack(Evas_Object *obj, Evas_Object *subobj, int x, int y, int w, int h)
121 {
122    ELM_CHECK_WIDTYPE(obj, widtype);
123    Widget_Data *wd = elm_widget_data_get(obj);
124    if (!wd) return;
125    elm_widget_sub_object_add(obj, subobj);
126    evas_object_grid_pack(wd->grd, subobj, x, y, w, h);
127 }
128
129 EAPI void
130 elm_grid_unpack(Evas_Object *obj, Evas_Object *subobj)
131 {
132    ELM_CHECK_WIDTYPE(obj, widtype);
133    Widget_Data *wd = elm_widget_data_get(obj);
134    if (!wd) return;
135    elm_widget_sub_object_del(obj, subobj);
136    evas_object_grid_unpack(wd->grd, subobj);
137 }
138
139 EAPI void
140 elm_grid_clear(Evas_Object *obj, Eina_Bool clear)
141 {
142    Eina_List *chld;
143    Evas_Object *o;
144    ELM_CHECK_WIDTYPE(obj, widtype);
145    Widget_Data *wd = elm_widget_data_get(obj);
146    if (!wd) return;
147    chld = evas_object_grid_children_get(wd->grd);
148    EINA_LIST_FREE(chld, o) elm_widget_sub_object_del(obj, o);
149    evas_object_grid_clear(wd->grd, clear);
150 }
151
152 EAPI void
153 elm_grid_pack_set(Evas_Object *subobj, int x, int y, int w, int h)
154 {
155    Evas_Object *obj = elm_widget_parent_widget_get(subobj);
156    ELM_CHECK_WIDTYPE(obj, widtype);
157    Widget_Data *wd = elm_widget_data_get(obj);
158    if (!wd) return;
159    evas_object_grid_pack(wd->grd, subobj, x, y, w, h);
160 }
161
162 EAPI void
163 elm_grid_pack_get(Evas_Object *subobj, int *x, int *y, int *w, int *h)
164 {
165    Evas_Object *obj = elm_widget_parent_widget_get(subobj);
166    ELM_CHECK_WIDTYPE(obj, widtype);
167    Widget_Data *wd = elm_widget_data_get(obj);
168    if (!wd) return;
169    evas_object_grid_pack_get(wd->grd, subobj, x, y, w, h);
170 }