2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://floralicense.org/license/
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.
19 #include "quickpanel-ui.h"
21 #include "list_util.h"
22 #include "quickpanel_def.h"
23 #include "noti_gridbox.h"
26 #define E_DATA_LAYOUT_PORTRAIT "layout_portrait"
27 #define E_DATA_LAYOUT_LANDSCAPE "layout_landscape"
28 #define E_DATA_CB_DELETE_ITEM "cb_delete_item"
29 #define E_DATA_CB_REMOVED "cb_removed"
30 #define E_DATA_APP_DATA "app_data"
32 typedef struct _gridbox_info_layout {
43 } gridbox_info_layout;
45 typedef struct _gridbox_info_animation {
49 void (*update_cb)(Evas_Object *list, void *data, int is_prepend);
50 Evas_Object *container;
53 } gridbox_info_animation;
55 static void _gridbox_layout_get_pos(int order, int *x, int *y, void *data) {
56 gridbox_info_layout *info_layout = data;
58 retif(data == NULL, , "invalid parameter");
59 retif(x == NULL, , "invalid parameter");
60 retif(y == NULL, , "invalid parameter");
62 int n_per_row = info_layout->n_per_rows;
64 int row = (order - 1) / n_per_row;
65 int column = (order - 1) - (row * n_per_row);
67 //DBG("order:%d r:%d c:%d", order, row, column);
69 int row_x = info_layout->padding_left
70 + ((info_layout->child_w + info_layout->padding_between) * column);
72 int row_y = info_layout->padding_top
73 + ((info_layout->child_h + info_layout->padding_between) * row);
79 static void _gridbox_layout(Evas_Object *o, Evas_Object_Box_Data *priv,
83 int off_x = 0, off_y = 0;
86 Evas_Object_Box_Option *opt;
89 int num_padding_between = 0;
91 retif(o == NULL, , "invalid parameter");
92 retif(priv == NULL, , "invalid parameter");
93 retif(data == NULL, , "invalid parameter");
95 gridbox_info_layout *info_layout = (gridbox_info_layout *) data;
97 n_children = eina_list_count(priv->children);
98 DBG("layout function:%d", n_children);
100 evas_object_size_hint_min_set(o, -1, 0);
105 evas_object_geometry_get(o, &x, &y, &w, &h);
107 num_padding_between = info_layout->n_per_rows / 2;
108 num_padding_between += (info_layout->n_per_rows > 1 && (info_layout->n_per_rows % 2) > 0) ? 1 : 0;
110 space_w = (info_layout->padding_left * 2) + (info_layout->padding_between * num_padding_between);
111 child_w = (info_layout->limit_w - space_w) / info_layout->n_per_rows;
113 info_layout->child_w = child_w;
115 DBG("grid layout children pos:%d %d", info_layout->child_w, info_layout->child_h);
117 int order_children = 1;
118 EINA_LIST_FOREACH_SAFE(priv->children, l, l_next, opt)
120 _gridbox_layout_get_pos(order_children, &off_x, &off_y, info_layout);
121 evas_object_move(opt->obj, x + off_x, y + off_y);
122 evas_object_size_hint_min_set(opt->obj, info_layout->child_w,
123 info_layout->child_h);
124 evas_object_resize(opt->obj, info_layout->child_w,
125 info_layout->child_h);
129 evas_object_size_hint_min_set(o, -1,
130 off_y + info_layout->child_h + info_layout->padding_bottom);
133 HAPI Evas_Object *gridbox_create(Evas_Object *parent, void *data) {
135 retif(parent == NULL, NULL, "invalid parameter");
136 retif(data == NULL, NULL, "invalid parameter");
137 struct appdata *ad = data;
138 Evas_Object *gridbox = NULL;
140 gridbox_info_layout *info_layout_portrait = NULL;
141 gridbox_info_layout *info_layout_landscape = NULL;
143 info_layout_portrait = (gridbox_info_layout *) malloc(
144 sizeof(gridbox_info_layout));
145 retif(info_layout_portrait == NULL, NULL, "memory allocation failed");
146 info_layout_portrait->padding_between = 12 * ad->scale;
147 info_layout_portrait->padding_top = 0;
148 info_layout_portrait->padding_left = 14 * ad->scale;
149 info_layout_portrait->padding_bottom = 12 * ad->scale;
150 info_layout_portrait->n_per_rows = 2;
151 info_layout_portrait->child_w = 0; //340;
152 info_layout_portrait->child_h = BOX_HEIGHT_P * ad->scale; //400;
153 info_layout_portrait->limit_w = ad->win_width; //400;
154 info_layout_portrait->scale = ad->scale;
156 info_layout_landscape = (gridbox_info_layout *) malloc(
157 sizeof(gridbox_info_layout));
158 retif(info_layout_landscape == NULL, NULL, "memory allocation failed");
159 info_layout_landscape->padding_between = 12 * ad->scale;
160 info_layout_landscape->padding_top = 0;
161 info_layout_landscape->padding_left = 14 * ad->scale;
162 info_layout_landscape->padding_bottom = 12 * ad->scale;
163 info_layout_landscape->n_per_rows = 3;
164 info_layout_landscape->child_w = 0; //409;
165 info_layout_landscape->child_h = BOX_HEIGHT_L * ad->scale; //400;
166 info_layout_landscape->limit_w = ad->win_height; //400;
167 info_layout_landscape->scale = ad->scale;
169 gridbox = elm_box_add(parent);
170 evas_object_size_hint_weight_set(gridbox, EVAS_HINT_EXPAND,
172 evas_object_size_hint_align_set(gridbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
174 if (ad->angle == 270 || ad->angle == 90)
175 elm_box_layout_set(gridbox, _gridbox_layout, info_layout_landscape,
178 elm_box_layout_set(gridbox, _gridbox_layout, info_layout_portrait,
181 evas_object_show(gridbox);
183 evas_object_data_set(gridbox, E_DATA_LAYOUT_PORTRAIT, info_layout_portrait);
184 evas_object_data_set(gridbox, E_DATA_LAYOUT_LANDSCAPE,
185 info_layout_landscape);
186 evas_object_data_set(gridbox, E_DATA_CB_DELETE_ITEM, NULL);
187 evas_object_data_set(gridbox, E_DATA_APP_DATA, ad);
190 = quickpanel_list_util_item_new(QP_ITEM_TYPE_NOTI, NULL);
191 quickpanel_list_util_item_set_tag(gridbox, qid);
196 HAPI void gridbox_remove(Evas_Object *gridbox) {
198 retif(gridbox == NULL, , "invalid parameter");
200 gridbox_info_layout *info_layout_portrait = evas_object_data_get(gridbox,
201 E_DATA_LAYOUT_PORTRAIT);
202 gridbox_info_layout *info_layout_landscape = evas_object_data_get(gridbox,
203 E_DATA_LAYOUT_LANDSCAPE);
205 gridbox_remove_all_item(gridbox, 0);
206 evas_object_data_del(gridbox, E_DATA_LAYOUT_PORTRAIT);
207 evas_object_data_del(gridbox, E_DATA_LAYOUT_LANDSCAPE);
208 evas_object_data_del(gridbox, E_DATA_CB_DELETE_ITEM);
209 evas_object_data_del(gridbox, E_DATA_APP_DATA);
210 quickpanel_list_util_item_del_tag(gridbox);
211 evas_object_del(gridbox);
213 if (info_layout_portrait != NULL)
214 free(info_layout_portrait);
215 if (info_layout_landscape != NULL)
216 free(info_layout_landscape);
219 HAPI void gridbox_set_item_deleted_cb(Evas_Object *gridbox,
220 void(*deleted_cb)(void *data, Evas_Object *obj)) {
221 retif(gridbox == NULL, , "invalid parameter");
222 retif(deleted_cb == NULL, , "invalid parameter");
224 evas_object_data_set(gridbox, E_DATA_CB_DELETE_ITEM, deleted_cb);
227 static void _gridbox_call_item_deleted_cb(Evas_Object *gridbox, void *data,
229 retif(gridbox == NULL, , "invalid parameter");
231 void (*deleted_cb)(void *data, Evas_Object *obj) = NULL;
233 deleted_cb = evas_object_data_get(gridbox, E_DATA_CB_DELETE_ITEM);
235 if (deleted_cb != NULL) {
236 deleted_cb(data, obj);
240 HAPI void gridbox_add_item(Evas_Object *gridbox, Evas_Object *item, int is_prepend) {
241 const char *signal = NULL;
243 retif(gridbox == NULL, , "invalid parameter");
244 retif(item == NULL, , "invalid parameter");
246 struct appdata *ad = evas_object_data_get(gridbox, E_DATA_APP_DATA);
249 if (ad->angle == 270 || ad->angle == 90) {
250 signal = "box.landscape";
252 signal = "box.portrait";
256 DBG("set to %s, %x", signal, item);
258 elm_object_signal_emit(item, signal, "box.prog");
259 edje_object_message_signal_process(_EDJ(item));
260 elm_layout_sizing_eval(item);
262 if (is_prepend == GRIDBOX_PREPEND)
263 elm_box_pack_start(gridbox, item);
265 elm_box_pack_end(gridbox, item);
268 static void _gridbox_remove_item_anim_cb(void *data, Elm_Transit *transit) {
270 retif(data == NULL, , "invalid parameter");
271 retif(transit == NULL, , "invalid parameter");
273 gridbox_info_animation *info_animation = data;
275 retif(info_animation->gridbox == NULL, , "invalid parameter");
276 retif(info_animation->item == NULL, , "invalid parameter");
278 DBG("remove:%p", info_animation->item);
280 void *node = noti_box_node_get(info_animation->item);
281 elm_box_unpack(info_animation->gridbox, info_animation->item);
282 noti_box_remove(info_animation->item);
283 _gridbox_call_item_deleted_cb(info_animation->gridbox,
286 if (info_animation->update_cb != NULL) {
287 retif(info_animation->container == NULL, , "invalid parameter");
288 retif(info_animation->noti == NULL, , "invalid parameter");
290 info_animation->update_cb(info_animation->container,
291 info_animation->noti, info_animation->pos);
294 free(info_animation);
295 info_animation = NULL;
298 HAPI void gridbox_remove_item(Evas_Object *gridbox, Evas_Object *item, int with_animation) {
299 DBG("remove:%p", item);
300 retif(gridbox == NULL, , "invalid parameter");
301 retif(item == NULL, , "invalid parameter");
303 if (noti_box_get_status(item) == STATE_DELETING) {
306 noti_box_set_status(item, STATE_DELETING);
308 if (with_animation == 1) {
309 gridbox_info_animation *info_animation = (gridbox_info_animation *) malloc(
310 sizeof(gridbox_info_animation));
311 if (info_animation == NULL)
313 info_animation->gridbox = gridbox;
314 info_animation->item = item;
315 info_animation->update_cb = NULL;
316 info_animation->container = NULL;
317 info_animation->noti = NULL;
318 info_animation->pos = 0;
320 Elm_Transit *transit = elm_transit_add();
321 //Fade in and out with layout object.
322 elm_transit_object_add(transit, item);
323 elm_transit_effect_fade_add(transit);
324 elm_transit_duration_set(transit, 0.7);
325 elm_transit_del_cb_set(transit, _gridbox_remove_item_anim_cb,
327 elm_transit_go(transit);
329 void *node = noti_box_node_get(item);
330 elm_box_unpack(gridbox, item);
331 noti_box_remove(item);
332 _gridbox_call_item_deleted_cb(gridbox,
337 HAPI void gridbox_remove_all_item(Evas_Object *gridbox, int with_animation) {
339 retif(gridbox == NULL, , "invalid parameter");
344 Eina_List *item_list = elm_box_children_get(gridbox);
346 EINA_LIST_FOREACH_SAFE(item_list, l, l_next, obj)
349 // call deleted callback
350 gridbox_remove_item(gridbox, obj, with_animation);
355 HAPI void gridbox_update_item(Evas_Object *gridbox, Evas_Object *item) {
357 retif(gridbox == NULL, , "invalid parameter");
358 retif(item == NULL, , "invalid parameter");
361 HAPI void gridbox_remove_and_add_item(Evas_Object *gridbox, Evas_Object *item
362 ,void (*update_cb)(Evas_Object *list, void *data, int is_prepend)
363 ,void *container, void *data, int pos) {
365 retif(gridbox == NULL, , "invalid parameter");
366 retif(item == NULL, , "invalid parameter");
367 retif(update_cb == NULL, , "invalid parameter");
368 retif(container == NULL, , "invalid parameter");
369 retif(data == NULL, , "invalid parameter");
371 if (noti_box_get_status(item) == STATE_DELETING) {
374 noti_box_set_status(item, STATE_DELETING);
376 gridbox_info_animation *info_animation = (gridbox_info_animation *) malloc(
377 sizeof(gridbox_info_animation));
378 if (info_animation == NULL)
380 info_animation->gridbox = gridbox;
381 info_animation->item = item;
382 info_animation->update_cb = update_cb;
383 info_animation->container = container;
384 info_animation->noti = data;
385 info_animation->pos = pos;
387 Elm_Transit *transit = elm_transit_add();
388 //Fade in and out with layout object.
389 elm_transit_object_add(transit, item);
390 elm_transit_effect_fade_add(transit);
391 elm_transit_duration_set(transit, 0.4);
392 elm_transit_del_cb_set(transit, _gridbox_remove_item_anim_cb,
394 elm_transit_go(transit);
397 HAPI void gridbox_finalize_rotation_cb(void *data) {
398 retif(data == NULL, , "invalid parameter");
399 Evas_Object *gridbox = data;
401 elm_box_recalculate(gridbox);
404 HAPI void gridbox_rotation(Evas_Object *gridbox, int angle) {
405 const char *signal = NULL;
407 retif(gridbox == NULL, , "invalid parameter");
409 gridbox_info_layout *info_layout_portrait = evas_object_data_get(gridbox,
410 E_DATA_LAYOUT_PORTRAIT);
411 gridbox_info_layout *info_layout_landscape = evas_object_data_get(gridbox,
412 E_DATA_LAYOUT_LANDSCAPE);
414 retif(info_layout_portrait == NULL || info_layout_landscape == NULL, ,
415 "gridbox is crashed");
420 Eina_List *item_list = elm_box_children_get(gridbox);
422 if (angle == 270 || angle == 90) {
423 signal = "box.landscape";
425 signal = "box.portrait";
428 DBG("all count:%d", eina_list_count (item_list));
430 EINA_LIST_FOREACH_SAFE(item_list, l, l_next, obj)
433 elm_object_signal_emit(obj, signal, "box.prog");
434 edje_object_message_signal_process(_EDJ(obj));
435 elm_layout_sizing_eval(obj);
436 DBG("set to %s, %x", signal, obj);
440 if (angle == 270 || angle == 90) {
441 elm_box_layout_set(gridbox, _gridbox_layout, info_layout_landscape,
445 layout_data = elm_box_transition_new(0.0, _gridbox_layout,
446 info_layout_portrait, NULL, _gridbox_layout,
447 info_layout_landscape, NULL, gridbox_finalize_rotation_cb,
451 elm_box_layout_set(gridbox, _gridbox_layout, info_layout_portrait,
454 layout_data = elm_box_transition_new(0.0, _gridbox_layout,
455 info_layout_landscape, NULL, _gridbox_layout,
456 info_layout_portrait, NULL, gridbox_finalize_rotation_cb,
462 elm_box_layout_set(gridbox, elm_box_layout_transition, layout_data,
463 elm_box_transition_free);
465 DBG("Angle Rotation is %d", angle);