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.
17 #include <Elementary.h>
20 #include "homescreen-efl.h"
21 #include "page_scroller.h"
22 #include "option_menu.h"
23 #include "dynamic_index.h"
24 #include "data_model.h"
31 #include "livebox/livebox_panel.h"
32 #include "livebox/livebox_animator.h"
33 #include "livebox/grid_item_resize.h"
34 #include "livebox/grid_reposition.h"
35 #include "livebox/livebox_utils.h"
36 #include "livebox/livebox_widget.h"
38 static Evas_Object *__livebox_panel_create_page(Evas_Object *livebox_scroller);
39 static void __livebox_panel_freeze_scroller(void);
40 static bool __livebox_panel_is_page_empty(Evas_Object *page);
42 static void __livebox_panel_register_longpress_callbacks(Evas_Object *livebox_scroller,
43 Evas_Object *page_layout, Evas_Object *livebox);
44 static void __livebox_panel_scrolled_cb(void *data, Evas_Object *obj,
46 static void __livebox_panel_page_changed_cb(void *data, Evas_Object *obj,
48 static void __livebox_panel_mouse_down_cb(void *data, Evas *evas, Evas_Object *object,
50 static void __livebox_panel_mouse_up_cb(void *data, Evas *evas, Evas_Object *object,
52 static Eina_Bool __livebox_panel_longpress_cb(void *data);
54 static void __livebox_panel_update_edit_mode_layout(Evas_Object *livebox_scroller_layout);
55 static void __livebox_panel_add_page_clicked_cb(void *data, Evas_Object *obj,
56 const char *emission, const char *source);
58 static void __libebox_panel_toggle_selected_livebox(Evas_Object *livebox, Evas_Object *page);
59 static void __livebox_panel_set_remove_buttons_visiblity(Evas_Object *page, bool visible);
60 static void __livebox_panel_set_reposition_bg_visibility(bool visible);
61 static void __livebox_panel_del_cb(void *data, Evas_Object *obj,
62 const char *emission, const char *source);
63 static Evas_Object *__livebox_panel_get_widget_layout(Evas_Object *obj);
65 static void __livebox_panel_scroll_start_cb(void *data, Evas_Object *obj, void *info);
66 static Eina_Bool __livebox_panel_change_page_timer_start_cb(void *data);
68 static void __livebox_panel_page_count_changed_cb(void *data, Evas_Object *obj,
69 const char *emission, const char *source);
70 static void __livebox_panel_set_remove_button_visibility(Evas_Object *livebox,
72 static void __livebox_panel_hide_remove_button(Evas_Object *livebox);
74 static bool __livebox_panel_iterate_page_fill_cb(Tree_node_t *parent,
75 Tree_node_t *page_node, void *data);
76 static bool __livebox_panel_iterate_node_fill_cb(Tree_node_t *page_node,
77 Tree_node_t *node, void *data);
79 static void __livebox_panel_show_warning_popup(void);
80 static bool __livebox_panel_find_empty_space(Evas_Object *page,
81 int span_w, int span_h, int *pos_x, int *pos_y);
83 static int __livebox_panel_get_mouse_move_distance_square(int x, int y);
86 Ecore_Timer *longpress_timer;
87 int origination_page_num;
88 Ecore_Timer *page_change_timer;
90 } livebox_reposition_info_s = {
91 .longpress_timer = NULL,
92 .origination_page_num = 0,
93 .page_change_timer = NULL,
94 .page_change = LIVEBOX_PAGE_NO_CHANGE,
99 Evas_Object *livebox_page_scroller;
100 Evas_Object *livebox_page_box;
101 Evas_Object *add_page;
102 dynamic_index_t *dynamic_index;
104 Eina_List *livebox_page_list;
111 bool livebox_remove_button_state;
113 Eina_Bool is_resizing;
114 Eina_Bool is_longpress;
116 Evas_Object *item_moved;
117 Eina_Rectangle no_move_pos;
118 Evas_Point mouse_press_pos;
121 .livebox_page_scroller = NULL,
122 .livebox_page_box = NULL,
124 .dynamic_index = NULL,
126 .livebox_page_list = NULL,
133 .livebox_remove_button_state = false,
134 .is_resizing = false,
136 .is_longpress = false,
144 .mouse_press_pos = {-1, -1},
147 void livebox_panel_update_dynamic_index(void)
149 if (!s_info.livebox_page_scroller) {
150 LOGE("s_info.livebox_page_scroller == NULL");
154 elm_object_signal_emit(s_info.livebox_page_scroller,
155 SIGNAL_SCROLLER_PAGE_COUNT_CHANGED, SIGNAL_SOURCE);
158 void livebox_panel_create_dynamic_index(void)
160 if (!s_info.livebox_page_scroller) {
161 LOGE("s_info.livebox_page_scroller == NULL");
166 s_info.dynamic_index = dynamic_index_new(s_info.livebox_page_scroller);
167 if (!s_info.dynamic_index) {
168 LOGE("s_info.dynamic_index == NULL");
173 void livebox_panel_fill(void)
175 Tree_node_t *home = NULL;
176 int widget_pos_h = 0;
178 home = data_model_get_home();
180 LOGE("home == NULL");
184 if (home->count == 0) {
185 LOGW("home->count == NULL");
188 LOGI("home->count == %d", home->count);
191 data_model_iterate_pages(home, __livebox_panel_iterate_page_fill_cb,
192 __livebox_panel_iterate_node_fill_cb, &widget_pos_h);
193 livebox_panel_create_dynamic_index();
196 Evas_Object *livebox_panel_create(Evas_Object *parent)
198 Evas_Object *liveboxes = NULL;
201 LOGE("parent == NULL");
205 liveboxes = livebox_panel_create_scroller();
207 LOGE("liveboxes == NULL");
211 livebox_widget_init();
216 void livebox_panel_set_content(Evas_Object *layout)
218 if(s_info.dynamic_index->box)
219 elm_layout_content_set(layout, PART_INDEX, s_info.dynamic_index->box);
222 void livebox_panel_unset_content(Evas_Object *layout)
224 Evas_Object *dynamic_index = NULL;
226 dynamic_index = elm_object_part_content_unset(layout, PART_INDEX);
228 if (!dynamic_index) {
229 LOGE("dyamic_index == NULL");
233 evas_object_hide(dynamic_index);
237 Evas_Object *livebox_scroller_get_page(void)
239 int current_page_number = page_scroller_get_current_page(
240 s_info.livebox_page_scroller);
241 return page_scroller_get_page(s_info.livebox_page_scroller,
242 current_page_number);
245 void livebox_panel_refresh_content_size(void)
247 Evas_Object *page_container = NULL;
248 Evas_Object *item = NULL;
249 Eina_List *it = NULL;
250 Eina_List *items_in_grid = NULL;
251 Evas_Coord container_x = -1;
252 Evas_Coord container_y = -1;
253 Evas_Coord container_width = -1;
254 Evas_Coord container_height = -1;
255 Evas_Coord x = -1, y = -1, w = -1, h = -1;
257 if (!s_info.livebox_page_scroller) {
261 page_container = page_scroller_get_page(
262 s_info.livebox_page_scroller,
263 page_scroller_get_current_page(s_info.livebox_page_scroller));
265 if (!page_container) {
266 LOGE("page_container == NULL");
270 evas_object_geometry_get(s_info.livebox_page_scroller,
271 &container_x, &container_y, &container_width,
274 items_in_grid = livebox_utils_get_liveboxes_on_page_list(
277 EINA_LIST_FOREACH(items_in_grid, it, item) {
279 LOGE("item == NULL");
283 elm_grid_pack_get(item, &x, &y, &w, &h);
284 evas_object_move(item,
285 (x*(container_width-LIVEBOX_HORIZONTAL_PADDING) / 100) +
286 LIVEBOX_HORIZONTAL_PADDING / 2 + container_x,
287 container_height * y / 100 + container_y);
288 evas_object_resize(item,
289 (int)((float) w/100 * (container_width)) -
290 (w * LIVEBOX_HORIZONTAL_PADDING)/100,
291 (int)((float)h/100 * (container_height)) -
292 (y*LIVEBOX_HORIZONTAL_PADDING)/100);
296 Evas_Object *livebox_panel_create_scroller(void)
298 Evas_Object *livebox_page_scroller = NULL;
299 Evas_Object *win = home_screen_get_win();
300 Evas_Object *box = NULL;
301 Eina_List *lvb_page_list = NULL;
307 LOGE("Window is NULL");
311 livebox_page_scroller =
312 page_scroller_create(home_screen_get_root_width(),
313 LIVEBOX_PAGE_HEIGHT_REL*home_screen_get_root_height());
314 if (!livebox_page_scroller) {
315 LOGE("Cannot create livebox page scroller");
319 box = elm_object_content_get(livebox_page_scroller);
321 LOGE("Cannot get the box");
322 evas_object_del(livebox_page_scroller);
326 livebox_utils_create_shadow(livebox_page_scroller);
327 evas_object_smart_callback_add(livebox_page_scroller,
328 "scroll,drag,start", __livebox_panel_scroll_start_cb, NULL);
329 elm_object_signal_callback_add(livebox_page_scroller,
330 SIGNAL_SCROLLER_PAGE_COUNT_CHANGED, SIGNAL_LAYOUT_SOURCE,
331 __livebox_panel_page_count_changed_cb, NULL);
333 /*After creation empty one empty space should be created.*/
335 s_info.livebox_page_scroller = livebox_page_scroller;
336 s_info.current_page = cur_page;
337 s_info.pages_count = p_count;
338 s_info.livebox_page_list = lvb_page_list;
340 return livebox_page_scroller;
344 void livebox_panel_destroy(void)
346 Eina_List *pages = s_info.livebox_page_list;
348 Evas_Object *livebox_scroller_page = NULL;
351 LOGE("Pages pointer is NULL");
355 EINA_LIST_FREE(pages, livebox_scroller_page) {
356 livebox_panel_destroy_page(livebox_scroller_page);
359 page_scroller_destroy(s_info.livebox_page_scroller);
361 livebox_widget_fini();
364 void livebox_panel_paused(void)
366 livebox_widget_viewer_paused();
369 void livebox_panel_resumed(void)
371 livebox_widget_viewer_resumed();
374 void livebox_panel_add_livebox(Tree_node_t *node, Evas_Object *page,
375 const char *livebox_pkgname, int pos_x, int pos_y,
376 int width, int height,
379 Evas_Object *livebox = NULL;
380 Evas_Object *livebox_layout = NULL;
381 Evas_Object *grid = NULL;
384 livebox_layout = elm_layout_add(s_info.livebox_page_scroller);
385 if (!livebox_layout) {
386 evas_object_del(page);
387 LOGE("livebox_layout is not created");
392 LOGE("node == NULL");
396 #ifdef LIVEBOX_RESIZE_TEST
397 livebox = elm_image_add(livebox_layout);
398 elm_image_file_set(livebox, livebox_pkgname, NULL);
400 livebox = livebox_widget_add(livebox_pkgname, livebox_layout, content_info);
404 LOGE("Livebox is not created");
408 node->data->layout = livebox_layout;
409 evas_object_data_set(livebox_layout, KEY_ICON_DATA, node);
411 elm_layout_file_set(livebox_layout, EDJE_LIVEBOX_LAYOUT_FILENAME,
412 GROUP_LIVEBOX_LAYOUT);
413 elm_layout_content_set(livebox_layout, PART_LIVEBOX, livebox);
414 evas_object_size_hint_weight_set(livebox_layout, EVAS_HINT_EXPAND,
416 evas_object_show(livebox_layout);
417 elm_layout_signal_callback_add(livebox_layout, SIGNAL_CLICKED,
418 SIGNAL_REMOVE_SOURCE, __livebox_panel_del_cb, NULL);
420 grid = elm_object_part_content_get(page, SIGNAL_CONTENT_SOURCE);
422 LOGE("grid == NULL");
427 livebox_layout, pos_x * LIVEBOX_GRID_ROWS_CELLS_MULTI,
428 pos_y * LIVEBOX_GRID_ROWS_CELLS_MULTI,
429 width * LIVEBOX_GRID_ROWS_CELLS_MULTI,
430 height * LIVEBOX_GRID_ROWS_CELLS_MULTI);
432 __livebox_panel_register_longpress_callbacks(NULL, page, livebox_layout);
434 LOGD("Adding [%s] at: [%d, %d] <>[%d, %d]",
435 livebox_pkgname, pos_x, pos_y, width, height);
439 Evas_Object *livebox_panel_add_page(Tree_node_t *node,
440 Evas_Object *livebox_scroller)
442 Evas_Object *page = NULL;
444 page = livebox_panel_create_empty_page(node, livebox_scroller);
447 LOGE("page == NULL");
451 if (!page_scroller_add_page(livebox_scroller, page)) {
452 LOGE("Can not create page");
454 livebox_panel_destroy_page(page);
458 /*update pages list*/
459 s_info.livebox_page_list = page_scroller_get_all_pages(
461 __livebox_panel_freeze_scroller();
466 bool livebox_panel_add_empty_page(Evas_Object *livebox_scroller)
468 /*@todo add check if page count will not be over the limit*/
469 Evas_Object *page = __livebox_panel_create_page(livebox_scroller);
470 return page_scroller_add_page(livebox_scroller, page);
474 Evas_Object *livebox_panel_create_empty_page(Tree_node_t *node,
475 Evas_Object *livebox_scroller)
477 Evas_Object *page = NULL;
479 if (!livebox_scroller) {
480 LOGE("Livebox panel is NULL");
485 LOGE("node == NULL");
489 page = __livebox_panel_create_page(livebox_scroller);
491 LOGE("page == NULL");
495 evas_object_data_set(page, KEY_ICON_DATA, node);
501 void livebox_panel_change_edit_mode_state(bool close)
503 Evas_Object *livebox_scroller = s_info.livebox_page_scroller;
504 if (!livebox_scroller) {
505 LOGE("Livebox panel is NULL");
509 if (!s_info.edit_mode && close) {
510 /*if edit mode is disabled closing doesn't take any effect*/
514 if (s_info.edit_mode && close) {
515 s_info.edit_mode = false;
516 /*closing edit mode*/
517 __livebox_panel_update_edit_mode_layout(livebox_scroller);
518 } else if (!s_info.edit_mode) {
519 s_info.edit_mode = true;
520 __livebox_panel_update_edit_mode_layout(livebox_scroller);
524 void livebox_panel_destroy_page(Evas_Object *livebox_scroller_page)
526 Eina_List *lb_layouts_list = NULL;
528 Evas_Object *lb_layout = NULL;
529 Evas_Object *widget = NULL;
530 Tree_node_t *page_node = NULL;
532 if (!livebox_scroller_page) {
533 LOGE("Livebox panel is NULL");
537 page_node = evas_object_data_get(livebox_scroller_page, KEY_ICON_DATA);
539 LOGE("page_node == NULL");
543 data_model_del_item(page_node);
545 lb_layouts_list = livebox_utils_get_liveboxes_on_page_list(
546 livebox_scroller_page);
547 if (!lb_layouts_list) {
548 LOGE("pages == NULL");
549 evas_object_del(livebox_scroller_page);
550 home_screen_print_tree();
554 EINA_LIST_FOREACH(lb_layouts_list, l, lb_layout) {
555 widget = __livebox_panel_get_widget_layout(lb_layout);
557 LOGE("widget == NULL");
561 livebox_widget_del(widget);
562 evas_object_del(lb_layout);
565 eina_list_free(lb_layouts_list);
566 evas_object_del(livebox_scroller_page);
568 __livebox_panel_freeze_scroller();
569 home_screen_print_tree();
572 bool livebox_panel_is_add_page_selected(void)
574 int current_page_number = page_scroller_get_current_page(
575 s_info.livebox_page_scroller);
576 Evas_Object *page_container = page_scroller_get_page(
577 s_info.livebox_page_scroller, current_page_number);
579 return (page_container == s_info.add_page &&
580 livebox_panel_check_if_add_page_is_visible());
583 void livebox_panel_move_mouse_cb(int x, int y)
585 int mouse_move_distance = __livebox_panel_get_mouse_move_distance_square(x, y);
587 if (mouse_move_distance > LIVEBOX_MIN_MOUSE_MOVE) {
588 ecore_timer_del(livebox_reposition_info_s.longpress_timer);
589 livebox_reposition_info_s.longpress_timer = NULL;
591 if(!s_info.is_longpress)
592 page_scroller_unfreeze(s_info.livebox_page_scroller);
595 if (s_info.is_longpress &&
596 !livebox_reposition_info_s.page_change_timer) {
597 if (x < LIVEBOX_PAGE_CHANGE_RECT_SIZE) {
598 livebox_reposition_info_s.page_change_timer =
599 ecore_timer_add(LIVEBOX_PAGE_CHANGE_PERIOD,
600 __livebox_panel_change_page_timer_start_cb, (void *)false);
601 LOGI("PAGE CHANGE TIMER CREATED <LEFT>");
602 } else if (x > home_screen_get_root_width() -
603 LIVEBOX_PAGE_CHANGE_RECT_SIZE) {
604 livebox_reposition_info_s.page_change_timer =
605 ecore_timer_add(LIVEBOX_PAGE_CHANGE_PERIOD,
606 __livebox_panel_change_page_timer_start_cb, (void *)true);
607 LOGI("PAGE CHANGE TIMER CREATED <RIGHT>");
610 grid_reposition_move(x, y);
611 } else if (livebox_reposition_info_s.page_change_timer &&
612 x > LIVEBOX_PAGE_CHANGE_RECT_SIZE &&
613 x < home_screen_get_root_width() -
614 LIVEBOX_PAGE_CHANGE_RECT_SIZE) {
615 ecore_timer_del(livebox_reposition_info_s.page_change_timer);
616 livebox_reposition_info_s.page_change_timer = NULL;
617 LOGI("PAGE CHANGE TIMER DESTROYED");
619 grid_reposition_move(x, y);
623 Eina_List *livebox_panel_get_pages(void)
625 return s_info.livebox_page_list;
628 Evas_Object *livebox_panel_get(void)
630 return s_info.livebox_page_scroller;
633 Evas_Object *livebox_panel_get_index(void)
635 if (!s_info.dynamic_index) {
636 LOGE("s_info.dynamic_index == NULL");
640 if (!s_info.dynamic_index->box) {
641 LOGE("s_info.dynamic_index->box == NULL");
645 return s_info.dynamic_index->box;
648 bool livebox_panel_check_if_add_page_is_visible(void)
650 Evas_Object *lvb_scorller = NULL;
651 Evas_Object *page = NULL;
652 Evas_Object *page_edje = NULL;
655 const char *state = NULL;
657 lvb_scorller = s_info.livebox_page_scroller;
659 LOGE("Faield to get livebox scroller");
663 p_count = page_scroller_get_page_count(lvb_scorller);
665 LOGE("Failed to get page count");
669 LOGD("p_count is %d ", p_count);
671 page = page_scroller_get_page(lvb_scorller, --p_count);
673 LOGE("Failed to get page");
677 page_edje = elm_layout_edje_get(page);
679 LOGE("Failed to get page edje");
683 state = edje_object_part_state_get(page_edje,
684 PART_ADD_PAGE_BUTTON, NULL);
687 LOGE("Failed to get state");
691 LOGD("state is : %s ", state);
693 return strncmp(state, "default", LIVEBOX_MAX_STATE_LEN);
696 void livebox_panel_set_edit_mode_layout(bool turn_on)
698 Evas_Object *lvb_scorller = NULL;
699 Evas_Object *page = NULL;
700 char *signal_to_send = NULL;
701 Eina_List *all_pages = NULL;
702 Eina_List *it = NULL;
704 lvb_scorller = s_info.livebox_page_scroller;
706 LOGE("Failed to get livebox scroller");
710 all_pages = page_scroller_get_all_pages(lvb_scorller);
712 LOGE("Failed to get page");
717 signal_to_send = SIGNAL_EDIT_START;
719 signal_to_send = SIGNAL_EDIT_STOP;
722 EINA_LIST_FOREACH(all_pages, it, page) {
724 LOGE("page == NULL");
728 elm_object_signal_emit(page, signal_to_send,
729 SIGNAL_LAYOUT_SOURCE);
733 void livebox_panel_add_page_visible_state_set(bool visible)
735 Evas_Object *page = NULL;
737 page = livebox_scroller_get_last_page();
739 LOGE("page == NULL");
744 s_info.add_page = page;
746 elm_object_signal_emit(page, SIGNAL_ADD_SHOW,
747 SIGNAL_LAYOUT_SOURCE);
748 elm_object_signal_emit(page, SIGNAL_EDIT_START,
749 SIGNAL_LAYOUT_SOURCE);
751 elm_object_signal_emit(page, SIGNAL_ADD_HIDE,
752 SIGNAL_LAYOUT_SOURCE);
756 bool livebox_panel_can_add_page(void)
759 Eina_List *pages = page_scroller_get_all_pages(livebox_panel_get());
760 count = eina_list_count(pages);
763 if (count < LIVEBOX_SCROLLER_MAX_PAGES) {
765 } else if (count == LIVEBOX_SCROLLER_MAX_PAGES &&
766 livebox_panel_check_if_add_page_is_visible()) {
770 __livebox_panel_show_warning_popup();
775 int livebox_panel_find_empty_space(int span_w, int span_h,
776 int *pos_x, int *pos_y)
778 Evas_Object *current_page = NULL;
779 Evas_Object *page = NULL;
783 Eina_List *pages = page_scroller_get_all_pages(livebox_panel_get());
785 LOGE("pages == NULL");
790 current_page = livebox_scroller_get_page();
792 LOGE("current_page == NULL");
793 eina_list_free(pages);
797 if (__livebox_panel_find_empty_space(current_page,
798 span_w, span_h, pos_x, pos_y)) {
799 eina_list_free(pages);
800 return page_scroller_get_current_page(livebox_panel_get());
803 EINA_LIST_FOREACH(pages, l, page) {
807 LOGE("page == NULL");
811 if (page == current_page)
814 if (__livebox_panel_find_empty_space(page, span_w, span_h,
816 eina_list_free(pages);
821 eina_list_free(pages);
825 static int __livebox_panel_get_mouse_move_distance_square(int x, int y)
827 int dx = x - s_info.mouse_press_pos.x;
828 int dy = y - s_info.mouse_press_pos.y;
830 return (dx * dx) + (dy * dy);
833 static bool __livebox_panel_find_empty_space(Evas_Object *page, int span_w,
834 int span_h, int *pos_x, int *pos_y)
836 Evas_Object *livebox;
838 Eina_List *livebox_list = NULL;
839 Eina_Rectangle *grid_item_rec = NULL;
843 livebox_list = livebox_utils_get_liveboxes_on_page_list(page);
845 LOGE("livebox_list == NULL");
851 if (eina_list_count(livebox_list) == 0) {
854 eina_list_free(livebox_list);
858 Eina_Rectangle *moved_item_rec = eina_rectangle_new(0, 0,
860 if (!moved_item_rec) {
861 LOGE("moved_item_rec == NULL");
862 eina_list_free(livebox_list);
866 for (y = 0; y + span_h <= LIVEBOX_GRID_ROWS; ++y) {
867 moved_item_rec->y = y;
869 EINA_LIST_FOREACH(livebox_list, l, livebox) {
870 grid_item_rec = livebox_utils_get_grid_widget_rectangle(
872 if (!grid_item_rec) {
873 LOGE("grid_item_rec == NULL");
874 eina_rectangle_free(grid_item_rec);
878 if (eina_rectangle_intersection(moved_item_rec,
881 eina_rectangle_free(grid_item_rec);
889 eina_rectangle_free(grid_item_rec);
893 eina_list_free(livebox_list);
894 eina_rectangle_free(moved_item_rec);
899 eina_rectangle_free(moved_item_rec);
900 eina_list_free(livebox_list);
904 static void __livebox_panel_show_warning_popup(void)
906 popup_data_t *data = popup_create_data();
908 LOGE("data == NULL");
912 data->orientation = ELM_POPUP_ORIENT_CENTER;
913 data->popup_cancel_text = NULL;
914 data->popup_confirm_text = NULL;
915 data->popup_content_text = strdup(_("IDS_HS_POP_THERE_IS_NOT_ENOUGH_SPACE_ON_THE_HOME_SCREEN_REMOVE_SOME_WIDGETS_AND_TRY_AGAIN"));
916 data->popup_title_text = NULL;
917 data->type = POPUP_INFO;
918 data->visible_time = 5.0;
920 popup_show(data, NULL, NULL, NULL);
923 static void __livebox_panel_freeze_scroller(void)
926 if (page_scroller_get_page_count(s_info.livebox_page_scroller) > 1) {
927 page_scroller_unfreeze(s_info.livebox_page_scroller);
929 page_scroller_freeze(s_info.livebox_page_scroller);
933 static void __livebox_panel_page_count_changed_cb(void *data, Evas_Object *obj,
934 const char *emission, const char *source)
936 __livebox_panel_freeze_scroller();
940 static Evas_Object *__livebox_panel_create_page(Evas_Object *livebox_scroller)
942 Evas_Object *grid = NULL;
943 Evas_Object *rect = NULL;
944 Evas_Object *livebox_container = util_create_edje_layout(
945 livebox_scroller, EDJE_LIVEBOX_CONTAINER_FILENAME,
946 GROUP_LIVEBOX_CONTAINER);
948 if (!livebox_container) {
949 LOGE("Cannot create scroller layout");
953 grid = elm_grid_add(livebox_container);
955 LOGE("grid == NULL");
956 evas_object_del(livebox_container);
960 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND,
962 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL,
964 elm_grid_size_set(grid, LIVEBOX_TOTAL_COLUMNS, LIVEBOX_TOTAL_ROWS);
966 elm_object_part_content_set(livebox_container, SIGNAL_CONTENT_SOURCE,
968 livebox_utils_create_grid_shadow_clipper(livebox_container);
970 rect = evas_object_rectangle_add(evas_object_evas_get(
973 LOGE("rect == NULL");
974 evas_object_del(grid);
975 evas_object_del(livebox_container);
980 evas_object_color_set(rect, 0, 0, 0, 0);
981 evas_object_size_hint_min_set(rect, home_screen_get_root_width(),
982 LIVEBOX_SIZE_REL * home_screen_get_root_height() -
983 (2.0*LIVEBOX_X_MIN * home_screen_get_root_width()));
984 evas_object_size_hint_max_set(rect, home_screen_get_root_width(),
985 LIVEBOX_SIZE_REL * home_screen_get_root_height() -
986 (2.0*LIVEBOX_X_MIN * home_screen_get_root_width()));
988 elm_object_part_content_set(livebox_container, PART_PAGE_BG, rect);
990 elm_object_signal_emit(livebox_container, SIGNAL_RESIZE_SLIDERS_HIDE,
991 SIGNAL_LIVEBOX_SOURCE);
992 elm_object_signal_callback_add(livebox_container,
993 SIGNAL_ADD_PAGE_CLICKED, SIGNAL_LAYOUT_SOURCE,
994 __livebox_panel_add_page_clicked_cb, NULL);
996 grid_item_init_resize_callbacks(livebox_scroller, livebox_container);
998 return livebox_container;
1002 static void __livebox_panel_update_edit_mode_layout(Evas_Object *livebox_scroller_scroller)
1004 Eina_List *livebox_container_list;
1006 Evas_Object *livebox_container = NULL;
1008 if (!livebox_scroller_scroller) {
1009 LOGE("Livebox panel layout is NULL");
1013 livebox_container_list = page_scroller_get_all_pages(
1014 livebox_scroller_scroller);
1015 if (s_info.edit_mode) {
1016 EINA_LIST_FOREACH(livebox_container_list, node,
1019 if (!livebox_container) {
1020 LOGE("livebox_container == NULL");
1024 if (!__livebox_panel_is_page_empty(livebox_container)) {
1025 __livebox_panel_set_remove_buttons_visiblity(
1026 livebox_container, true);
1028 elm_object_signal_emit(livebox_container,
1029 SIGNAL_EMPTY_PAGE_EDIT_START,
1030 SIGNAL_LIVEBOX_SOURCE);
1032 elm_object_signal_emit(livebox_container,
1033 SIGNAL_EDIT_START, SIGNAL_LIVEBOX_SOURCE);
1036 EINA_LIST_FOREACH(livebox_container_list, node,
1037 livebox_container) {
1038 if (!livebox_container) {
1039 LOGE("livebox_container == NULL");
1043 __livebox_panel_set_remove_buttons_visiblity(livebox_container,
1046 elm_object_signal_emit(livebox_container,
1047 SIGNAL_EMPTY_PAGE_EDIT_STOP,
1048 SIGNAL_LIVEBOX_SOURCE);
1049 elm_object_signal_emit(livebox_container,
1050 SIGNAL_EDIT_STOP, SIGNAL_LIVEBOX_SOURCE);
1052 elm_object_signal_emit(livebox_container,
1053 SIGNAL_RESIZE_SLIDERS_HIDE, SIGNAL_LIVEBOX_SOURCE);
1057 eina_list_free(livebox_container_list);
1060 static bool __livebox_panel_is_page_empty(Evas_Object *page)
1062 Eina_List *lb_list = NULL;
1065 LOGE("page == NULL");
1069 if (page == s_info.add_page &&
1070 livebox_panel_check_if_add_page_is_visible()) {
1074 lb_list = livebox_utils_get_liveboxes_on_page_list(page);
1076 LOGD("lb_list == NULL");
1080 if (eina_list_count(lb_list) > 0) {
1088 static void _livebox_remove_button_mouse_cb(void *data, Evas_Object *obj,
1089 const char *emission, const char *source)
1091 LOGD("rm btn %s", emission);
1094 LOGE("obj == NULL");
1098 s_info.livebox_remove_button_state = (bool) strstr(emission,
1102 static void __livebox_panel_register_longpress_callbacks(Evas_Object *livebox_scroller,
1103 Evas_Object *page_layout, Evas_Object *livebox)
1105 Evas_Object *scroller = s_info.livebox_page_scroller;
1107 evas_object_event_callback_add(livebox, EVAS_CALLBACK_MOUSE_DOWN,
1108 __livebox_panel_mouse_down_cb, page_layout);
1109 evas_object_event_callback_add(livebox, EVAS_CALLBACK_MOUSE_UP,
1110 __livebox_panel_mouse_up_cb, livebox_scroller);
1111 elm_layout_signal_callback_add(livebox, SIGNAL_MOUSE_DOWN,
1112 SIGNAL_REMOVE_SOURCE, _livebox_remove_button_mouse_cb, NULL);
1113 elm_layout_signal_callback_add(livebox, SIGNAL_MOUSE_UP,
1114 SIGNAL_REMOVE_SOURCE, _livebox_remove_button_mouse_cb, NULL);
1117 /*this callback should abort longpress*/
1118 evas_object_smart_callback_add(scroller,
1119 SIGNAL_SCROLLER_DRAG_START, __livebox_panel_scrolled_cb,
1121 evas_object_smart_callback_add(scroller,
1122 SIGNAL_SCROLLER_SCROLL, __livebox_panel_page_changed_cb,
1128 static void __livebox_panel_mouse_down_cb(void *data, Evas *evas,
1129 Evas_Object *object, void *event_info)
1131 Evas_Event_Mouse_Down *ev = (Evas_Event_Mouse_Down *) event_info;
1132 int current_page_number = page_scroller_get_current_page(
1133 s_info.livebox_page_scroller);
1134 Evas_Object *page_layout = page_scroller_get_page(
1135 s_info.livebox_page_scroller, current_page_number);
1136 int obj_x = 0, obj_y = 0, obj_w = 0, obj_h = 0;
1137 Evas_Object *widget = NULL;
1139 if (!ev || !page_layout) {
1140 LOGE("Invalid event info");
1144 page_scroller_freeze(s_info.livebox_page_scroller);
1146 s_info.mouse_press_pos.x = ev->output.x;
1147 s_info.mouse_press_pos.y = ev->output.y;
1149 evas_object_geometry_get(object, &obj_x, &obj_y, &obj_w, &obj_h);
1151 if (s_info.edit_mode) {
1153 widget = elm_layout_content_get(object, PART_LIVEBOX);
1155 LOGE("widget == NULL");
1159 livebox_widget_set_event_blocking(widget);
1162 if (livebox_reposition_info_s.longpress_timer) {
1163 LOGD("Longpress timer existed - this should not happen");
1164 ecore_timer_del(livebox_reposition_info_s.longpress_timer);
1165 livebox_reposition_info_s.longpress_timer = NULL;
1168 if (!s_info.livebox_remove_button_state) {
1169 livebox_reposition_info_s.longpress_timer = ecore_timer_add(
1170 LIVEBOX_LONGPRESS_TIME, __livebox_panel_longpress_cb, object);
1172 LOGD("Remove button pressed");
1176 static void __libebox_panel_toggle_selected_livebox(Evas_Object *livebox, Evas_Object *page)
1178 Evas_Object *prev_selected_page = NULL;
1181 LOGE("livebox == NULL");
1186 LOGE("page == NULL");
1190 livebox_utils_set_selected_livebox(livebox, page);
1191 prev_selected_page = livebox_utils_get_prev_livebox_layout();
1192 if (prev_selected_page && page != prev_selected_page) {
1193 /*page != prev_selected_page' when page is not change the sliders
1194 should not disappear */
1195 LOGD("Previous page found");
1196 elm_object_signal_emit(prev_selected_page,
1197 SIGNAL_RESIZE_SLIDERS_HIDE, SIGNAL_LIVEBOX_SOURCE);
1198 elm_object_signal_emit(prev_selected_page,
1199 SIGNAL_GRID_SHADOW_HIDE, PART_GRID_BG);
1202 elm_object_signal_emit(page, SIGNAL_GRID_SHADOW_SHOW, PART_GRID_BG);
1205 static void __livebox_panel_mouse_up_cb(void *data, Evas *evas,
1206 Evas_Object *object, void *event_info)
1208 int current_page_number = page_scroller_get_current_page(
1209 s_info.livebox_page_scroller);
1210 Evas_Object *livebox_container = page_scroller_get_page(
1211 s_info.livebox_page_scroller, current_page_number);
1213 s_info.is_longpress = false;
1214 page_scroller_unfreeze(s_info.livebox_page_scroller);
1216 __livebox_panel_freeze_scroller();
1218 __livebox_panel_set_remove_button_visibility(
1219 grid_reposition_get_repositioned_item(), true);
1220 __livebox_panel_set_reposition_bg_visibility(false);
1222 grid_reposition_end();
1223 livebox_utils_set_shadow_visibility(false);
1225 LOGD("PAGE CHANGE TIMER DEL: %p",
1226 livebox_reposition_info_s.page_change_timer);
1227 ecore_timer_del(livebox_reposition_info_s.page_change_timer);
1228 livebox_reposition_info_s.page_change_timer = NULL;
1230 if (livebox_reposition_info_s.longpress_timer) {
1231 LOGD("NOT LONGPRESS");
1232 ecore_timer_del(livebox_reposition_info_s.longpress_timer);
1234 if (home_screen_get_view_type() != HOMESCREEN_VIEW_HOME_EDIT) {
1235 LOGD("No edit mode exiting...");
1239 livebox_reposition_info_s.longpress_timer = NULL;
1240 __libebox_panel_toggle_selected_livebox(object, livebox_container);
1241 grid_item_set_resize_livebox_sliders(object, livebox_container);
1245 static void __livebox_panel_scrolled_cb(void *data, Evas_Object *obj,
1248 if (livebox_reposition_info_s.longpress_timer) {
1249 ecore_timer_del(livebox_reposition_info_s.longpress_timer);
1250 livebox_reposition_info_s.longpress_timer = NULL;
1254 static void __livebox_panel_page_changed_cb(void *data, Evas_Object *obj,
1257 /*livebox_utils_set_shadow_visibility(false);*/
1261 static Eina_Bool _longpress_timer_cb(void *data)
1263 grid_reposition_start();
1264 __livebox_panel_hide_remove_button(
1265 grid_reposition_get_repositioned_item());
1266 __livebox_panel_set_reposition_bg_visibility(true);
1268 return ECORE_CALLBACK_CANCEL;
1271 /*@todo add check to proceed only if edit mode is ON*/
1272 static Eina_Bool __livebox_panel_longpress_cb(void *data)
1275 int current_page_number = page_scroller_get_current_page(
1276 s_info.livebox_page_scroller);
1277 Evas_Object *longpressed_page = page_scroller_get_page(
1278 s_info.livebox_page_scroller, current_page_number);
1280 livebox_reposition_info_s.longpress_timer = NULL;
1281 Evas_Object *livebox = (Evas_Object *) data;
1282 Evas_Object *widget = elm_layout_content_get(livebox, PART_LIVEBOX);
1285 LOGE("widget == NULL");
1288 livebox_widget_set_event_blocking(widget);
1290 if (!longpressed_page) {
1291 LOGE("No longpressed object stored");
1295 if (s_info.is_resizing)
1299 if (s_info.livebox_remove_button_state)
1302 s_info.is_longpress = true;
1304 __libebox_panel_toggle_selected_livebox(livebox, longpressed_page);
1306 grid_item_set_resize_sliders_visibility(longpressed_page, false);
1307 grid_reposition_init(livebox_utils_get_livebox_container_grid(
1308 longpressed_page), livebox);
1309 page_scroller_freeze(s_info.livebox_page_scroller);
1311 if (home_screen_get_view_type() != HOMESCREEN_VIEW_HOME_EDIT) {
1312 home_screen_set_view_type(HOMESCREEN_VIEW_HOME_EDIT);
1313 livebox_panel_set_edit_mode_layout(true);
1314 livebox_panel_change_edit_mode_state(false);
1315 ecore_timer_add(0.1, _longpress_timer_cb, longpressed_page);
1317 grid_reposition_start();
1318 __livebox_panel_hide_remove_button(livebox);
1319 __livebox_panel_set_reposition_bg_visibility(true);
1325 static void __livebox_panel_add_page_clicked_cb(void *data, Evas_Object *obj,
1326 const char *emission, const char *source)
1328 Evas_Object *lvb_scorller = NULL;
1329 int page_count = -1;
1331 lvb_scorller = livebox_panel_get();
1332 if (!lvb_scorller) {
1333 LOGE("Failed to get scroller");
1337 page_count = page_scroller_get_page_count(lvb_scorller);
1339 if (page_count < LIVEBOX_SCROLLER_MAX_PAGES) {
1340 /*remove add_page button from last page*/
1341 livebox_panel_add_page_visible_state_set(false);
1344 livebox_panel_add_empty_page(lvb_scorller);
1346 /*show add button on last page*/
1347 livebox_panel_add_page_visible_state_set(true);
1349 livebox_panel_add_page_visible_state_set(false);
1350 /*elm_object_signal_emit(dynamic_index->indices[5],
1351 EDJE_SIGNAL_ADD_PAGE_HIDE, EDJE_SIGNAL_LAYOUT_SOURCE);*/
1354 elm_object_signal_emit(lvb_scorller, SIGNAL_SCROLLER_PAGE_COUNT_CHANGED,
1355 SIGNAL_LAYOUT_SOURCE);
1358 Evas_Object *livebox_scroller_get_last_page(void)
1360 Evas_Object *lvb_scorller = NULL;
1361 Evas_Object *page = NULL;
1363 Eina_List *all_pages = NULL;
1364 int page_count = -1;
1366 lvb_scorller = s_info.livebox_page_scroller;
1367 if (!lvb_scorller) {
1368 LOGE("Failed to get livebox scroller");
1372 all_pages = page_scroller_get_all_pages(lvb_scorller);
1374 LOGE("Failed to get page");
1378 page_count = eina_list_count(all_pages);
1380 LOGE("Failed to get page count!");
1384 page = eina_list_nth(all_pages, --page_count);
1386 LOGE("Failed to get page");
1393 static void __livebox_panel_scroll_start_cb(void *data, Evas_Object *obj, void *info)
1395 Evas_Object *page = livebox_utils_get_selected_livebox_layout();
1397 LOGE("page == NULL");
1401 grid_item_set_resize_sliders_visibility(page, false);
1405 static Eina_Bool __livebox_panel_change_page_timer_start_cb(void *data)
1407 bool is_right = (bool)data;
1408 int page_count = -1;
1409 int current_page = -1;
1410 Evas_Object *grid = NULL;
1411 Evas_Object *page = NULL;
1412 int mx = -1, my = -1;
1414 if (!s_info.livebox_page_scroller) {
1415 LOGE("s_info.livebox_page_scroller == NULL");
1419 page_count = page_scroller_get_page_count(
1420 s_info.livebox_page_scroller);
1421 current_page = page_scroller_get_current_page(
1422 s_info.livebox_page_scroller);
1424 LOGD("PAGE CHANGE... %s", is_right ? "Going right" : "Going left");
1426 livebox_utils_repack_grid_object(NULL, livebox_utils_get_shadow(),
1427 livebox_utils_get_livebox_container_grid(
1428 livebox_utils_get_selected_livebox_layout()), NULL);
1430 /*TODO: Check if this can be removed*/
1431 livebox_utils_repack_grid_object(NULL,
1432 livebox_utils_selected_livebox_get(),
1433 livebox_utils_get_livebox_container_grid(
1434 livebox_utils_get_selected_livebox_layout()),
1437 page_scroller_unfreeze(s_info.livebox_page_scroller);
1445 current_page = current_page % page_count;
1446 LOGD("CURRENT PAGE: %d", current_page);
1448 page = page_scroller_get_page(s_info.livebox_page_scroller,
1451 LOGE("page == NULL");
1452 return ECORE_CALLBACK_CANCEL;
1455 grid = livebox_utils_get_livebox_container_grid(page);
1457 LOGE("grid == NULL");
1458 return ECORE_CALLBACK_CANCEL;
1461 elm_scroller_page_bring_in(s_info.livebox_page_scroller,
1464 page_scroller_freeze(s_info.livebox_page_scroller);
1465 __libebox_panel_toggle_selected_livebox(livebox_utils_selected_livebox_get(), page);
1466 grid_reposition_set_current_grid(grid);
1467 livebox_utils_repack_grid_object(livebox_utils_selected_livebox_get(),
1468 livebox_utils_get_shadow(), NULL, grid);
1470 livebox_utils_get_cursor_pos(&mx, &my);
1471 grid_reposition_move(mx, my);
1473 livebox_utils_set_shadow_visibility(true);
1475 return ECORE_CALLBACK_RENEW;
1478 static void __livebox_panel_set_remove_button_visibility(
1479 Evas_Object *livebox, bool visible)
1482 LOGE("livebox == NULL");
1487 elm_layout_signal_emit(livebox,
1488 SIGNAL_LIVEBOX_REMOVE_BUTTON_SHOW,
1489 SIGNAL_LIVEBOX_SOURCE);
1491 elm_layout_signal_emit(livebox,
1492 SIGNAL_LIVEBOX_REMOVE_BUTTON_HIDE,
1493 SIGNAL_LIVEBOX_SOURCE);
1497 static void __livebox_panel_hide_remove_button(Evas_Object *livebox)
1500 LOGE("livebox == NULL");
1504 elm_layout_signal_emit(livebox, SIGNAL_REMOVE_BUTTON_INSTANT_HIDE,
1505 SIGNAL_LIVEBOX_SOURCE);
1508 static void __livebox_panel_set_remove_buttons_visiblity(Evas_Object *page, bool visible)
1510 Eina_List *l = NULL;
1511 Evas_Object *lb = NULL;
1514 LOGE("page == NULL");
1518 Eina_List *list = livebox_utils_get_liveboxes_on_page_list(page);
1521 LOGE("list == NULL");
1525 EINA_LIST_FOREACH(list, l, lb) {
1530 __livebox_panel_set_remove_button_visibility(lb, visible);
1534 static void __livebox_panel_set_reposition_bg_visibility(bool visible)
1536 Evas_Object *livebox = grid_reposition_get_repositioned_item();
1538 LOGE("livebox == NULL");
1543 elm_object_signal_emit(livebox,
1544 SIGNAL_LIVEBOX_REPOSITION_BG_SHOW,
1545 SIGNAL_LIVEBOX_SOURCE);
1547 elm_object_signal_emit(livebox,
1548 SIGNAL_LIVEBOX_REPOSITION_BG_HIDE,
1549 SIGNAL_LIVEBOX_SOURCE);
1553 static Evas_Object *__livebox_panel_get_widget_layout(Evas_Object* obj)
1555 Evas_Object *widget = elm_layout_content_get(obj, PART_LIVEBOX);
1557 LOGE("widget == NULL");
1564 static void __livebox_panel_del_cb(void *data, Evas_Object *obj, const char *emission,
1567 Evas_Object *grid = NULL;
1568 Evas_Object *widget = NULL;
1569 Tree_node_t *node = NULL;
1571 int current_page_number =
1572 page_scroller_get_current_page(s_info.livebox_page_scroller);
1574 Evas_Object *page_container =
1575 page_scroller_get_page(
1576 s_info.livebox_page_scroller, current_page_number);
1577 if (!page_container) {
1578 LOGE("page_container == NULL");
1581 elm_object_signal_emit(page_container, SIGNAL_RESIZE_SLIDERS_HIDE,
1582 SIGNAL_LIVEBOX_SOURCE);
1584 LOGI("DELETE LIVEBOX BUTTON PRESSED");
1586 node = evas_object_data_get(obj, KEY_ICON_DATA);
1588 LOGE("node == NULL");
1592 widget = __livebox_panel_get_widget_layout(obj);
1593 livebox_widget_del(widget);
1594 data_model_del_item(node);
1596 evas_object_del(obj);
1598 grid = livebox_utils_get_livebox_container_grid(page_container);
1600 LOGE("page_container == NULL");
1604 livebox_utils_repack_grid_object(NULL, livebox_utils_get_shadow(),
1607 home_screen_print_tree();
1610 static bool __livebox_panel_iterate_node_fill_cb(Tree_node_t *page_node, Tree_node_t *node,
1613 int *widget_pos_h = (int *)data;
1615 Evas_Object *page = page_node->data->layout;
1617 LOGE("page == NULL");
1621 livebox_panel_add_livebox(node, page, node->data->appid,
1622 node->data->col, node->data->row, node->data->col_span,
1623 node->data->row_span,
1624 node->data->content_info);
1626 *widget_pos_h += LIVEBOX_ON_CREATE_SIZE/2;
1630 static bool __livebox_panel_iterate_page_fill_cb(Tree_node_t *parent, Tree_node_t *page_node,
1633 Evas_Object *page = NULL;
1634 Evas_Object *liveboxes = s_info.livebox_page_scroller;
1635 int *widget_pos_h = (int *)data;
1638 page = livebox_panel_add_page(page_node, liveboxes);
1640 LOGE("[FAILED][page]");
1641 data_model_del_item(page_node);
1645 page_node->data->layout = page;