The source code moved from the SPIN with license changed to Flora 1.1
[apps/native/home/homescreen-efl.git] / src / util.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <Elementary.h>
18 #include <stdbool.h>
19
20 #include "homescreen-efl.h"
21 #include "util.h"
22 #include "data_model.h"
23
24 HAPI Evas_Object *util_create_edje_layout(Evas_Object *parent, const char *edje_filename, const char *edje_group)
25 {
26         Evas_Object *layout = NULL;
27
28         if (!edje_filename || !edje_group) {
29                 LOGE("Filename or groupname is NULL");
30                 return NULL;
31         }
32
33         if (!parent) {
34                 LOGE("Parent is NULL");
35                 return NULL;
36         }
37
38         layout = elm_layout_add(parent);
39         if (!layout) {
40                 LOGE("Cannot create layout");
41                 return NULL;
42         }
43
44         if (!elm_layout_file_set(layout, edje_filename, edje_group)) {
45                 evas_object_del(layout);
46                 LOGE("Cannot load layout");
47                 return NULL;
48         }
49
50         evas_object_show(layout);
51
52         return layout;
53 }
54
55 /* TEST FUNCTIONS : TO BE REMOVED*/
56 HAPI void tst_resize_cb(void *data, Evas *e, Evas_Object *obj, void *ei)
57 {
58         Evas_Coord x, y, w, h;
59
60         evas_object_geometry_get(obj, &x, &y, &w, &h);
61         LOGD("Obj_Type[%s] %d %d %d %d", evas_object_type_get(obj), x, y, w, h);
62 }
63
64 HAPI void tst_show_cb(void *data, Evas *e, Evas_Object *obj, void *ei)
65 {
66         LOGD("MSZ ");
67
68 }
69
70 HAPI void tst_hide_cb(void *data, Evas *e, Evas_Object *obj, void *ei)
71 {
72         LOGD("MSZ ");
73 }
74
75 HAPI void tst_move_cb(void *data, Evas *e, Evas_Object *obj, void *ei)
76 {
77         Evas_Coord x, y, w, h;
78
79         evas_object_geometry_get(obj, &x, &y, &w, &h);
80         LOGD("MSZ %d %d %d %d", x, y, w, h);
81 }
82
83 HAPI void tst_del_cb(void *data, Evas *e, Evas_Object *obj, void *ei)
84 {
85         LOGD("tst_del_cb: obj type [%s]", evas_object_type_get(obj));
86
87         Tree_node_t *t_data = evas_object_data_get(obj, KEY_ICON_DATA);
88         if (t_data)
89                 LOGI("[obtained data [%s]]", t_data->data->label);
90 }
91
92 HAPI Eina_List *elm_gengrid_get_evas_objects_from_items(Evas_Object *gengrid)
93 {
94         Eina_List *items = NULL;
95         Eina_List *it = NULL;
96         Elm_Object_Item *data = NULL;
97
98         Eina_List *tmp = NULL;
99         Evas_Object *obj = NULL;
100
101         if (!gengrid) {
102                 LOGE("[INVALID_PARAM][gengrid='%p']", gengrid);
103                 return NULL;
104         }
105
106         tmp = elm_gengrid_realized_items_get(gengrid);
107         if (!tmp) {
108                 LOGE("[FAILED][elm_gengrid_realized_items_get]");
109                 return NULL;
110         }
111
112         EINA_LIST_FOREACH(tmp, it, data) {
113                 if (!data)
114                         continue;
115
116                 obj = elm_object_item_part_content_get(data, GRID_CONTENT);
117                 if (!obj) {
118                         LOGE("[FAILED][elm_object_item_part_content_get]");
119                         eina_list_free(tmp);
120                         eina_list_free(items);
121                         return NULL;
122                 }
123
124                 items = eina_list_append(items, obj);
125
126                 if (!items) {
127                         LOGE("[FAILED][eina_list_append]");
128                         eina_list_free(tmp);
129                         return NULL;
130                 }
131         }
132
133         eina_list_free(tmp);
134
135         return items;
136 }
137
138 HAPI Elm_Object_Item *elm_gengrid_get_item_at_index(Evas_Object *gengrid, int idx)
139 {
140         Eina_List *items = NULL;
141         Elm_Object_Item *found = NULL;
142
143         if (!gengrid || idx < 0) {
144                 LOGE("[INVALID_PARAM][gengrid='%p'][idx='%d']", gengrid, idx);
145                 return NULL;
146         }
147
148         items = elm_gengrid_realized_items_get(gengrid);
149         if (!items) {
150                 LOGE("[FAILED][elm_gengrid_realized_items_get]");
151                 return NULL;
152         }
153
154         if (idx > eina_list_count(items)) {
155                 LOGE("[INVALID_INDEX]");
156                 eina_list_free(items);
157                 return NULL;
158         }
159
160         found = eina_list_nth(items, idx);
161         eina_list_free(items);
162
163         return found;
164 }