The source code moved from the SPIN with license changed to Flora 1.1
[apps/native/home/homescreen-efl.git] / src / livebox / grid_item_resize.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 "livebox/grid_item_resize.h"
18 #include "homescreen-efl.h"
19 #include "layout.h"
20 #include "livebox/livebox_panel.h"
21 #include "livebox/livebox_widget.h"
22 #include "page_scroller.h"
23 #include "conf.h"
24 #include "data_model.h"
25
26 typedef enum {
27         GRID_RESIZE_LEFT,
28         GRID_RESIZE_RIGHT,
29         GRID_RESIZE_UP,
30         GRID_RESIZE_DOWN,
31 } gird_item_resize_dir_t;
32
33 static struct {
34         int x_at_drag_start;
35         int y_at_drag_start;
36         int w_at_drag_start;
37         int h_at_drag_start;
38         Eina_Bool is_resizing;
39 } s_info = {
40         .x_at_drag_start = 0,
41         .y_at_drag_start = 0,
42         .w_at_drag_start = 0,
43         .h_at_drag_start = 0,
44         .is_resizing = false
45 };
46
47 static void __gird_item_resize_button_pressed_cb(void *data, Evas_Object *obj,
48         const char *emission, const char *source);
49 static int __grid_item_resize_drag_pos_get(Evas_Object *obj, const char *part,
50         Eina_Bool is_horizontal);
51 static void __grid_item_resize_finalize(Evas_Object *obj);
52 static Eina_Bool __grid_item_resize_get_available_sizes(Evas_Object *livebox, int w, int h);
53 static void __grid_item_resize_drag(Evas_Object *livebox, int new_x, int new_y, int new_w,
54         int new_h);
55 static void __grid_item_resize_drag_stop_cb(void *data, Evas_Object *obj, const char *emission,
56         const char *source);
57 static void __grid_item_resize_get_sliders_geometry(Evas_Object *page, int *out_x,
58         int *out_y, int *out_w, int *out_h);
59 static void __grid_item_resize_drag_cb(void *data, Evas_Object *obj, const char *emission,
60         const char *source);
61 static void __grid_item_resize_page_background_clicked_cb(void *data, Evas_Object *obj,
62         const char *emission, const char *source);
63
64 #ifdef LIVEBOX_RESIZE_ENABLED
65         static void __grid_item_resize_set_slider_pos(Evas_Object *page, const char *part,
66                 int pos, Eina_Bool is_horizontal);
67 #endif
68
69
70 void grid_item_set_resize_livebox_sliders(Evas_Object *livebox,
71         Evas_Object *page)
72 {
73 #ifdef LIVEBOX_RESIZE_ENABLED
74         Evas_Coord x = -1;
75         Evas_Coord y = -1;
76         Evas_Coord w = -1;
77         Evas_Coord h = -1;
78
79         if (!page) {
80                 LOGE("page == NULL");
81                 return;
82         }
83
84         if (!livebox) {
85                 LOGE("livebox == NULL");
86                 return;
87         }
88
89         elm_grid_pack_get(livebox, &x, &y, &w, &h);
90         LOGD("LIVEBOX NEW POS: %d %d %d %d", x, y, w, h);
91
92         __grid_item_resize_set_slider_pos(page, PART_RESIZE_BUTTON_UP, y, EINA_FALSE);
93         __grid_item_resize_set_slider_pos(page, PART_RESIZE_BUTTON_DOWN, y + h, EINA_FALSE);
94         __grid_item_resize_set_slider_pos(page, PART_RESIZE_BUTTON_LEFT, x, EINA_TRUE);
95         __grid_item_resize_set_slider_pos(page, PART_RESIZE_BUTTON_RIGHT, x + w, EINA_TRUE);
96
97         elm_layout_signal_emit(page, SIGNAL_RESIZE_SLIDERS_SHOW,
98                 SIGNAL_LIVEBOX_SOURCE);
99
100 #endif
101 }
102
103 bool grid_item_init_resize_callbacks(Evas_Object *livebox_container_scroller,
104         Evas_Object *livebox_container)
105 {
106         Evas_Object *edje = NULL;
107
108         if (!livebox_container_scroller) {
109                 LOGE("livebox_container_scroller == NULL");
110                 return false;
111         }
112
113         if (!livebox_container) {
114                 LOGE("livebox_container == NULL");
115                 return false;
116         }
117
118         edje = elm_layout_edje_get(livebox_container);
119         if (!edje) {
120                 LOGE("edje == NULL");
121                 return false;
122         }
123
124         edje_object_signal_callback_add(edje, SIGNAL_MOUSE_DOWN,
125                 PART_RESIZE_BUTTON_DOWN, __gird_item_resize_button_pressed_cb,
126                 livebox_container_scroller);
127         edje_object_signal_callback_add(edje, SIGNAL_MOUSE_DOWN,
128                 PART_RESIZE_BUTTON_LEFT, __gird_item_resize_button_pressed_cb,
129                 livebox_container_scroller);
130         edje_object_signal_callback_add(edje, SIGNAL_MOUSE_DOWN,
131                 PART_RESIZE_BUTTON_UP, __gird_item_resize_button_pressed_cb,
132                 livebox_container_scroller);
133         edje_object_signal_callback_add(edje,
134                 SIGNAL_MOUSE_DOWN, PART_RESIZE_BUTTON_RIGHT,
135                 __gird_item_resize_button_pressed_cb, livebox_container_scroller);
136         edje_object_part_drag_value_set(edje,
137                 PART_RESIZE_BUTTON_DOWN, 0.0, 0.999);
138         edje_object_part_drag_value_set(edje,
139                 PART_RESIZE_BUTTON_UP, 0.0, 0.001);
140         edje_object_signal_callback_add(edje,
141                 SIGNAL_RESIZING, PART_RESIZE_BUTTON_DOWN,
142                 __grid_item_resize_drag_cb, livebox_container);
143         edje_object_signal_callback_add(edje,
144                 SIGNAL_RESIZE_END, PART_RESIZE_BUTTON_DOWN,
145                 __grid_item_resize_drag_stop_cb, NULL);
146         edje_object_signal_callback_add(edje, SIGNAL_RESIZING,
147                 PART_RESIZE_BUTTON_UP, __grid_item_resize_drag_cb, livebox_container);
148         edje_object_signal_callback_add(edje,
149                 SIGNAL_RESIZE_END, PART_RESIZE_BUTTON_UP, __grid_item_resize_drag_stop_cb, NULL);
150         edje_object_part_drag_value_set(edje,
151                 PART_RESIZE_BUTTON_LEFT, 0.001, 0.0);
152         edje_object_part_drag_value_set(edje,
153                 PART_RESIZE_BUTTON_RIGHT, 0.999, 0.0);
154         edje_object_signal_callback_add(edje,
155                 SIGNAL_RESIZING, PART_RESIZE_BUTTON_LEFT, __grid_item_resize_drag_cb,
156                 livebox_container);
157         edje_object_signal_callback_add(edje,
158                 SIGNAL_RESIZE_END, PART_RESIZE_BUTTON_LEFT,
159                 __grid_item_resize_drag_stop_cb, NULL);
160         edje_object_signal_callback_add(edje,
161                 SIGNAL_RESIZING, PART_RESIZE_BUTTON_RIGHT,
162                 __grid_item_resize_drag_cb, livebox_container);
163         edje_object_signal_callback_add(edje,
164                 SIGNAL_RESIZE_END, PART_RESIZE_BUTTON_RIGHT,
165                 __grid_item_resize_drag_stop_cb, NULL);
166
167         elm_layout_signal_callback_add(livebox_container, SIGNAL_CLICKED,
168                 PART_PAGE_BG, __grid_item_resize_page_background_clicked_cb, NULL);
169
170         return true;
171 }
172
173 void grid_item_set_resize_sliders_visibility(Evas_Object *page, bool visible)
174 {
175         if (!page) {
176                 LOGE("page == NULL");
177                 return;
178         }
179
180         if (visible) {
181                 elm_object_signal_emit(page, SIGNAL_RESIZE_SLIDERS_SHOW,
182                         SIGNAL_LIVEBOX_SOURCE);
183         } else {
184                 elm_object_signal_emit(page, SIGNAL_RESIZE_SLIDERS_HIDE,
185                         SIGNAL_LIVEBOX_SOURCE);
186         }
187 }
188
189 static void __gird_item_resize_button_pressed_cb(void *data, Evas_Object *obj,
190         const char *emission, const char *source)
191 {
192         Evas_Object *livebox = NULL;
193         Evas_Object *livebox_scroller = NULL;
194
195         if (!obj || !emission || !source) {
196                 LOGE("Wrong arguments provided: %p %p %p", obj,
197                         emission, source);
198                 return;
199         }
200
201         livebox_scroller = data;
202         if (!livebox_scroller) {
203                 LOGE("livebox_scroller == NULL");
204                 return;
205
206         }
207
208         page_scroller_freeze(livebox_scroller);
209
210         livebox = livebox_utils_selected_livebox_get();
211         if (!livebox) {
212                 LOGE("livebox == NULL");
213                 return;
214         }
215
216         elm_grid_pack_get(livebox, &s_info.x_at_drag_start,
217                 &s_info.y_at_drag_start,
218                 &s_info.w_at_drag_start,
219                 &s_info.h_at_drag_start);
220
221         s_info.is_resizing = EINA_TRUE;
222
223         LOGD("BUTTON PRESSED: %p !!! x = %d; y = %d; w = %d; h = %d", livebox,
224                 s_info.x_at_drag_start,
225                 s_info.y_at_drag_start,
226                 s_info.w_at_drag_start,
227                 s_info.h_at_drag_start);
228 }
229
230 static int __grid_item_resize_drag_pos_get(Evas_Object *obj, const char *part,
231         Eina_Bool is_horizontal)
232 {
233         double val;
234         int pos;
235
236         if (!obj || !part) {
237                 LOGE("Wrong arguments provided: %p %p", obj, part);
238                 return -1;
239         }
240
241         if (is_horizontal) {
242                 edje_object_part_drag_value_get(obj, part, &val, NULL);
243                 pos = (int)(val * LIVEBOX_GRID_COLUMNS);
244         } else {
245                 edje_object_part_drag_value_get(obj, part, NULL, &val);
246                 pos = (int)(val * LIVEBOX_GRID_ROWS);
247         }
248
249
250         LOGD("DRAG UP STOP: %f POS: %d", val, pos);
251         return pos;
252 }
253
254
255 static void __grid_item_resize_finalize(Evas_Object *obj)
256 {
257         LOGD("Resize");
258         Evas_Object *lb_scroller = NULL;
259         if (!obj) {
260                 LOGE("o == NULL");
261                 return;
262         }
263
264         edje_object_signal_emit(obj, SIGNAL_RESIZE_SLIDER_DRAG_OK,
265          SIGNAL_RESIZE_SLIDER_DRAG_OK);
266
267         s_info.is_resizing = EINA_FALSE;
268
269         lb_scroller = livebox_panel_get();
270         if (!lb_scroller) {
271                 LOGE("lb_scroller == NULL");
272                 return;
273         }
274
275         page_scroller_unfreeze(lb_scroller);
276 }
277
278 static Eina_Bool __grid_item_resize_get_available_sizes(Evas_Object *livebox, int w, int h)
279 {
280         int cnt = 0;
281         int *size_list = NULL;
282         Evas_Object *widget = NULL;
283         int test_h = 0;
284         int test_w = 0;
285         int i = 0;
286
287         if (!livebox) {
288                 LOGE("livebox == NULL");
289                 return EINA_FALSE;
290         }
291
292         widget = elm_layout_content_get(livebox, PART_LIVEBOX);
293         if (!widget) {
294                 LOGE("widget == NULL");
295                 return EINA_FALSE;
296         }
297
298         livebox_widget_get_size_available(widget, &cnt, &size_list);
299
300         LOGD("Size count: %d", cnt);
301
302         if (!size_list) {
303                 LOGE("size_list == NULL");
304                 return EINA_FALSE;
305         }
306
307         for (i = 0; i < cnt; ++i) {
308                 livebox_widget_get_dimensions(size_list[i], &test_w, &test_h);
309
310                 if (w == test_w * LIVEBOX_GRID_ROWS_CELLS_MULTI &&
311                         h == test_h * LIVEBOX_GRID_ROWS_CELLS_MULTI) {
312                         LOGD("RESIZE AVAILABLE SIZE FOUND: %d %d",
313                                 test_w, test_h);
314                         free(size_list);
315                         return EINA_TRUE;
316                 }
317         }
318
319         free(size_list);
320         return EINA_FALSE;
321 }
322
323
324 static void __grid_item_resize_drag(Evas_Object *livebox,
325         int new_x, int new_y, int new_w, int new_h)
326 {
327         LOGD("resize2");
328         Evas_Object *page = NULL;
329         Eina_Rectangle *rect = NULL;
330         Eina_List *list;
331         int out_x = -1, out_y = -1, out_w = -1, out_h = -1;
332
333         if (!livebox) {
334                 LOGE("livebox == NULL");
335                 return;
336         }
337
338         page = livebox_utils_get_selected_livebox_layout();
339         if (!page) {
340                 LOGE("page == NULL");
341                 return;
342         }
343
344         list = livebox_utils_get_liveboxes_on_page_list(page);
345         if (!list) {
346                 LOGE("list == NULL");
347                 return;
348
349         }
350
351         __grid_item_resize_get_sliders_geometry(page, &out_x, &out_y, &out_w, &out_h);
352         rect = eina_rectangle_new(out_x, out_y, out_w, out_h);
353
354         if (__grid_item_resize_get_available_sizes(livebox, new_w, new_h) &&
355                 !livebox_utils_check_rect_list_grid_interesction(rect,
356                         livebox, list)) {
357                 elm_grid_pack_set(livebox, new_x, new_y, new_w, new_h);
358                 LOGD("RESIZE OK: %d %d %d %d", new_x, new_y, new_w, new_h);
359         } else {
360                 elm_grid_pack_set(livebox, s_info.x_at_drag_start,
361                         s_info.y_at_drag_start,
362                         s_info.w_at_drag_start,
363                         s_info.h_at_drag_start);
364                 LOGD("RESIZE FAIL: %d %d %d %d; ", new_x, new_y, new_w, new_h);
365         }
366
367         eina_rectangle_free(rect);
368 }
369
370 static void _drag_size_new_get(gird_item_resize_dir_t dir, Evas_Object *livebox,
371         int pos, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
372 {
373         Evas_Coord x2, y2;
374
375         if (!livebox) {
376                 LOGE("livebox == NULL");
377                 return;
378         }
379
380         if (!x || !y || !w || !h) { /*Other arguments can be NULL*/
381                 LOGE("Wrong arguments: x = %p; y = %p; w = %p; h = %p",
382                         x, y, w, h);
383                 return;
384         }
385
386         elm_grid_pack_get(livebox, x, y, w, h);
387
388         switch (dir) {
389         case GRID_RESIZE_LEFT:
390                 x2 = *x + *w;
391                 *w = x2 - (pos * LIVEBOX_GRID_ROWS_CELLS_MULTI);
392                 *x = (pos * LIVEBOX_GRID_ROWS_CELLS_MULTI);
393                 break;
394         case GRID_RESIZE_RIGHT:
395                 *w = (pos - *x) * LIVEBOX_GRID_ROWS_CELLS_MULTI;
396                 break;
397         case GRID_RESIZE_UP:
398                 y2 = *y + *h;
399                 *h = y2 - (pos * LIVEBOX_GRID_ROWS_CELLS_MULTI);
400                 *y = (pos * LIVEBOX_GRID_ROWS_CELLS_MULTI);
401                 break;
402         case GRID_RESIZE_DOWN:
403                 *h = (pos - *y) * LIVEBOX_GRID_ROWS_CELLS_MULTI;
404                 break;
405         }
406 }
407
408 static void __grid_item_resize_drag_stop_cb(void *data, Evas_Object *obj, const char *emission,
409         const char *source)
410 {
411         int pos = -1;
412         Evas_Coord x = -1;
413         Evas_Coord y = -1;
414         Evas_Coord w = -1;
415         Evas_Coord h = -1;
416         Evas_Object *livebox = NULL;
417         Tree_node_t *item_node = NULL;
418         gird_item_resize_dir_t resize_dir;
419         bool horizontal = false;
420
421
422         if (!obj || !emission || !source) {
423                 LOGE("Wrong arguments provided: %p %p %p",
424                         obj, emission, source);
425                 return;
426         }
427
428         livebox = livebox_utils_selected_livebox_get();
429         if (!livebox) {
430                 LOGE("livebox == NULL");
431                 return;
432         }
433
434         __grid_item_resize_finalize(obj);
435
436         if (!strncmp(PART_RESIZE_BUTTON_DOWN, source,
437                 LIVEBOX_MAX_BUTTON_NAME_LENGTH)) {
438                 horizontal = EINA_FALSE;
439                 resize_dir = GRID_RESIZE_DOWN;
440         } else if (!strncmp(PART_RESIZE_BUTTON_UP, source,
441                 LIVEBOX_MAX_BUTTON_NAME_LENGTH)) {
442                 horizontal = EINA_FALSE;
443                 resize_dir = GRID_RESIZE_UP;
444         } else if (!strncmp(PART_RESIZE_BUTTON_LEFT, source,
445                 LIVEBOX_MAX_BUTTON_NAME_LENGTH)) {
446                 horizontal = EINA_TRUE;
447                 resize_dir = GRID_RESIZE_LEFT;
448         } else if (!strncmp(PART_RESIZE_BUTTON_RIGHT, source,
449                 LIVEBOX_MAX_BUTTON_NAME_LENGTH)) {
450                 horizontal = EINA_TRUE;
451                 resize_dir = GRID_RESIZE_RIGHT;
452         } else {
453                 LOGE("UNKNOWN PART");
454                 return;
455         }
456
457         pos = __grid_item_resize_drag_pos_get(obj, source, horizontal);
458         _drag_size_new_get(resize_dir, livebox, pos, &x, &y, &w, &h);
459
460         __grid_item_resize_drag(livebox, x, y, w, h);
461         elm_grid_pack_get(livebox, &x, &y, &w, &h);
462
463         edje_object_part_drag_value_set(obj, PART_RESIZE_BUTTON_DOWN, 0,
464                         (y + h) * LIVEBOX_RESIZE_POS_MULTI_ROWS);
465
466         edje_object_part_drag_value_set(obj, PART_RESIZE_BUTTON_UP, 0,
467                         (float) y * LIVEBOX_RESIZE_POS_MULTI_ROWS);
468
469         edje_object_part_drag_value_set(obj, PART_RESIZE_BUTTON_LEFT,
470                         (float) x * LIVEBOX_RESIZE_POS_MULTI_COLS, 0);
471
472         edje_object_part_drag_value_set(obj, PART_RESIZE_BUTTON_RIGHT,
473                         (float) (x + w) * LIVEBOX_RESIZE_POS_MULTI_COLS, 0);
474
475         item_node = evas_object_data_get(livebox, KEY_ICON_DATA);
476         if (!item_node) {
477                 LOGE("item_node == NULL");
478                 return;
479         }
480
481         data_model_resize_widget(item_node, x, y, w, h);
482         home_screen_print_tree();
483 }
484
485 static void __grid_item_resize_get_sliders_geometry(Evas_Object *page, int *out_x,
486         int *out_y, int *out_w, int *out_h)
487 {
488         Evas_Object *edje = elm_layout_edje_get(page);
489         Evas_Object *grid = NULL;
490         double val = 0;
491
492         if (!edje) {
493                 LOGE("edje == NULL");
494                 return;
495         }
496
497         grid = edje_object_part_swallow_get(edje, SIGNAL_CONTENT_SOURCE);
498         if (!grid) {
499                 LOGE("grid == NULL");
500                 return;
501         }
502
503         if (!out_x || !out_y || !out_w || !out_h) {
504                 LOGE("x = %p; y = %p; w = %p; h = %p",
505                         out_x, out_y, out_w, out_h);
506                 return;
507         }
508
509         edje_object_part_drag_value_get(edje, PART_RESIZE_BUTTON_LEFT,
510                 &val, NULL);
511         *out_x = round(val * LIVEBOX_TOTAL_COLUMNS);
512
513         edje_object_part_drag_value_get(edje, PART_RESIZE_BUTTON_UP,
514                 NULL, &val);
515         *out_y = round(val * LIVEBOX_TOTAL_ROWS);
516
517         edje_object_part_drag_value_get(edje, PART_RESIZE_BUTTON_RIGHT,
518                 &val, NULL);
519         *out_w = round(val * LIVEBOX_TOTAL_COLUMNS - *out_x);
520
521         edje_object_part_drag_value_get(edje, PART_RESIZE_BUTTON_DOWN,
522                 NULL, &val);
523         *out_h = round(val * LIVEBOX_TOTAL_ROWS - *out_y);
524 }
525
526 static void __grid_item_resize_drag_cb(void *data, Evas_Object *obj, const char *emission,
527         const char *source)
528 {
529         int pos = -1;
530         Evas_Coord x = -1;
531         Evas_Coord y = -1;
532         Evas_Coord w = -1;
533         Evas_Coord h = -1;
534         Evas_Object *livebox = NULL;
535         Eina_List   *list = NULL;
536         Eina_Rectangle *rect;
537         int out_x = -1, out_y = -1, out_w = -1, out_h = -1;
538
539         Evas_Object *page_container = data;
540         if (!page_container) {
541                 LOGE("page_container == NULL");
542                 return;
543         }
544
545         if (!obj || !emission || !source) {
546                 LOGE("Wrong arguments provided: obj == %p; \
547                         emission == %p; source == %p", obj, emission, source);
548                 return;
549         }
550
551         livebox = livebox_utils_selected_livebox_get();
552         if (!livebox) {
553                 LOGE("livebox == NULL");
554                 return;
555         }
556
557         list = livebox_utils_get_liveboxes_on_page_list(page_container);
558         if (!list) {
559                 LOGE("list == NULL");
560                 return;
561
562         }
563
564         if (!strncmp(source, PART_RESIZE_BUTTON_DOWN,
565                 LIVEBOX_MAX_BUTTON_NAME_LENGTH)) {
566                 pos = __grid_item_resize_drag_pos_get(obj, source, EINA_FALSE);
567                 _drag_size_new_get(GRID_RESIZE_DOWN, livebox, pos,
568                         &x, &y, &w, &h);
569
570                 LOGD("pos = %d", pos);
571         } else if (!strncmp(source, PART_RESIZE_BUTTON_UP,
572                 LIVEBOX_MAX_BUTTON_NAME_LENGTH)) {
573                 pos = __grid_item_resize_drag_pos_get(obj, source, EINA_FALSE);
574                 _drag_size_new_get(GRID_RESIZE_UP, livebox,
575                         pos, &x, &y, &w, &h);
576
577                 LOGD("pos = %d", pos);
578         } else if (!strncmp(source, PART_RESIZE_BUTTON_LEFT,
579                 LIVEBOX_MAX_BUTTON_NAME_LENGTH)) {
580                 pos = __grid_item_resize_drag_pos_get(obj, source, EINA_TRUE);
581                 _drag_size_new_get(GRID_RESIZE_LEFT, livebox,
582                         pos, &x, &y, &w, &h);
583         } else if (!strncmp(source, PART_RESIZE_BUTTON_RIGHT,
584                 LIVEBOX_MAX_BUTTON_NAME_LENGTH)) {
585                 pos = __grid_item_resize_drag_pos_get(obj, source, EINA_TRUE);
586                 _drag_size_new_get(GRID_RESIZE_RIGHT, livebox,
587                         pos, &x, &y, &w, &h);
588         } else {
589                 pos = 0;
590         }
591
592         __grid_item_resize_get_sliders_geometry(page_container, &out_x,
593                 &out_y, &out_w, &out_h);
594         rect = eina_rectangle_new(out_x, out_y, out_w, out_h);
595
596         if (!__grid_item_resize_get_available_sizes(livebox, w, h) ||
597                 livebox_utils_check_rect_list_grid_interesction(rect,
598                         livebox, list)) {
599                 edje_object_signal_emit(obj, SIGNAL_RESIZE_SLIDER_DRAG_ERR,
600                         SIGNAL_LIVEBOX_SOURCE);
601         } else {
602                 edje_object_signal_emit(obj, SIGNAL_RESIZE_SLIDER_DRAG_OK,
603                         SIGNAL_LIVEBOX_SOURCE);
604         }
605
606         eina_rectangle_free(rect);
607 }
608
609 #ifdef LIVEBOX_RESIZE_ENABLED
610 static void __grid_item_resize_set_slider_pos(Evas_Object *page, const char *part,
611         int pos, Eina_Bool is_horizontal)
612 {
613         Evas_Object *edje = NULL;
614
615         if (!page) {
616                 LOGE("page == NULL");
617                 return;
618         }
619
620         edje = elm_layout_edje_get(page);
621         if (!edje) {
622                 LOGE("page == NULL");
623                 return;
624         }
625
626         if (!part) {
627                 LOGE("part == NULL");
628                 return;
629         }
630
631         if (is_horizontal) {
632                 if (pos < 0 || pos > LIVEBOX_TOTAL_COLUMNS) {
633                         LOGE("Wrong value of pos = %d", pos);
634                         return;
635                 }
636
637                 LOGD("NEW POS OF %s is %f", part,
638                         (float)pos / LIVEBOX_TOTAL_COLUMNS);
639                 edje_object_part_drag_value_set(edje, part,
640                         (float)pos / LIVEBOX_TOTAL_COLUMNS, 0);
641         } else {
642                 if (pos < 0 || pos > LIVEBOX_TOTAL_ROWS) {
643                         LOGE("Wrong value of pos = %d", pos);
644                         return;
645                 }
646
647                 LOGD("NEW POS OF %s is %f", part,
648                         (float)pos / LIVEBOX_TOTAL_ROWS);
649                 edje_object_part_drag_value_set(edje, part, 0,
650                         (float)pos / LIVEBOX_TOTAL_ROWS);
651         }
652 }
653 #endif
654
655 static void __grid_item_resize_page_background_clicked_cb(void *data, Evas_Object *obj,
656         const char *emission, const char *source)
657 {
658         if (!obj) {
659                 LOGE("obj == NULL");
660                 return;
661         }
662
663         LOGD("Background clicked");
664         elm_layout_signal_emit(obj, SIGNAL_RESIZE_SLIDERS_HIDE,
665                 SIGNAL_LIVEBOX_SOURCE);
666 }
667