4 * Copyright (c) 2009-2014 Samsung Electronics Co., Ltd All Rights Reserved
6 * Contact: Jin Yoon <jinny.yoon@samsung.com>
7 * Junkyu Han <junkyu.han@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 #include <Elementary.h>
25 #include "menu_screen.h"
28 #include "item_event.h"
32 #include "page_scroller.h"
35 #include "all_apps/layout.h"
36 #include "all_apps/list.h"
37 #include "all_apps/shortcut.h"
39 #define ALL_APPS_EDJE_PORTRAIT EDJEDIR"/all_apps_portrait.edj"
40 #define ALL_APPS_GROUP "all_apps"
42 #define GROUP_4X4_EDJE_PORTRAIT EDJEDIR"/group_4x4_portrait.edj";
44 #define ALL_APPS_EDIT_BUTTON_EDJE EDJEDIR"/button_edit.edj"
45 #define ALL_APPS_EDIT_BUTTON_GROUP "button_edit"
46 #define ALL_APPS_EDIT_BUTTON_PART "button_edit"
48 #define IDS_HS_BUTTON_DONE "IDS_HS_BUTTON_DONE"
52 HAPI bool all_apps_layout_is_edited(Evas_Object *all_apps)
54 retv_if(NULL == all_apps, false);
55 return (bool) evas_object_data_get(all_apps, "is_edited");
60 HAPI void all_apps_layout_edit(Evas_Object *all_apps)
62 Evas_Object *edit_button;
63 Evas_Object *scroller;
65 //elm_object_tree_focus_allow_set(all_apps, EINA_FALSE);
66 evas_object_data_set(all_apps, "is_edited", (void *) true);
68 edit_button = elm_object_part_content_get(all_apps, ALL_APPS_EDIT_BUTTON_PART);
69 ret_if(NULL == edit_button);
70 elm_object_signal_emit(edit_button, "edit_button_state,edit", "menu");
72 scroller = elm_object_part_content_get(all_apps, "content");
73 ret_if(NULL == scroller);
74 page_scroller_edit(scroller);
81 HAPI void all_apps_layout_unedit(Evas_Object *all_apps)
83 Evas_Object *edit_button;
85 ret_if(NULL == all_apps);
87 //elm_object_tree_focus_allow_set(all_apps, EINA_TRUE);
91 bool is_edited = (bool) evas_object_data_get(all_apps, "is_edited");
92 if (false == is_edited) return;
95 edit_button = elm_object_part_content_get(all_apps, ALL_APPS_EDIT_BUTTON_PART);
96 ret_if(NULL == edit_button);
97 elm_object_signal_emit(edit_button, "edit_button_state,unedit", "menu");
101 Evas_Object *scroller;
103 scroller = elm_object_part_content_get(all_apps, "content");
104 ret_if(NULL == scroller);
106 page_scroller_unedit(scroller);
112 static char *_access_info_cb(void *data, Evas_Object *obj)
114 Evas_Object *scroller = data;
117 if (page_scroller_is_edited(scroller)) {
118 info = _(IDS_HS_BUTTON_DONE);
125 if (!tmp) return NULL;
131 static void _focus_clicked_cb(void *data, Evas_Object *obj, void *event_info)
133 Evas_Object *scroller = data;
135 _D("Edit button is up");
137 Evas_Object *all_apps;
138 all_apps = evas_object_data_get(scroller, "tab");
139 ret_if(NULL == all_apps);
141 if (page_scroller_is_edited(scroller)) {
142 _D("Go to the normal mode");
143 all_apps_layout_unedit(all_apps);
145 _D("Go to the edit mode");
146 all_apps_layout_edit(all_apps);
149 elm_object_signal_emit(obj, "edit_button,release", "menu");
155 static void _edit_button_down_cb(void *data, Evas_Object *obj, const char* emission, const char* source)
157 _D("Edit button is down");
162 static void _edit_button_up_cb(void *data, Evas_Object *obj, const char* emission, const char* source)
164 _D("Edit button is up");
166 elm_object_signal_emit(obj, "edit_button,release", "menu");
171 static Evas_Object *_add_edit_button(Evas_Object *parent, Evas_Object *scroller)
175 retv_if(NULL == parent, NULL);
176 retv_if(NULL == scroller, NULL);
178 button = layout_load_edj(parent, ALL_APPS_EDIT_BUTTON_EDJE, ALL_APPS_EDIT_BUTTON_GROUP);
179 retv_if(NULL == button, NULL);
181 edje_object_signal_callback_add(_EDJ(button), "edit_button,down", "menu", _edit_button_down_cb, scroller);
182 edje_object_signal_callback_add(_EDJ(button), "edit_button,up", "menu", _edit_button_up_cb, scroller);
185 Evas_Object *focus= NULL;
186 focus = elm_button_add(button);
187 retv_if(NULL == focus, NULL);
189 elm_object_style_set(focus, "focus");
190 elm_object_part_content_set(button, "focus", focus);
191 elm_access_info_cb_set(focus, ELM_ACCESS_INFO, _access_info_cb, scroller);
192 evas_object_smart_callback_add(focus, "clicked", _focus_clicked_cb, scroller);
200 static void _remove_edit_button(Evas_Object *button)
202 ret_if(NULL == button);
205 Evas_Object *focus = NULL;
206 focus = elm_object_part_content_unset(button, "focus");
207 if (NULL == focus) break;
208 evas_object_smart_callback_del(focus, "clicked", _focus_clicked_cb);
209 evas_object_del(focus);
212 edje_object_signal_callback_del(_EDJ(button), "edit_button,down", "menu", _edit_button_down_cb);
213 edje_object_signal_callback_del(_EDJ(button), "edit_button,up", "menu", _edit_button_up_cb);
215 layout_unload_edj(button);
220 static menu_screen_error_e _load_item(Evas_Object *scroller, app_list_item *item)
224 retv_if(NULL == item, MENU_SCREEN_ERROR_FAIL);
226 if (ai->nodisplay || !ai->enabled) {
227 return MENU_SCREEN_ERROR_OK;
230 retv_if(NULL == page_scroller_push_item_by_order(scroller, ai), MENU_SCREEN_ERROR_FAIL);
232 return MENU_SCREEN_ERROR_OK;
238 static Eina_Bool _push_items_idler_cb(void *all_apps)
243 Evas_Object *scroller;
245 list = evas_object_data_get(all_apps, "list");
246 scroller = evas_object_data_get(all_apps, "scroller");
248 retv_if(NULL == list, ECORE_CALLBACK_CANCEL);
249 goto_if(NULL == scroller, ERROR);
250 goto_if(MENU_SCREEN_ERROR_OK != list_is_ended(list, &flag), ERROR);
251 goto_if(flag == true, ERROR);
252 goto_if(MENU_SCREEN_ERROR_OK != list_get_item(list, &item), ERROR);
253 goto_if(MENU_SCREEN_ERROR_OK != _load_item(scroller, item), ERROR);
254 goto_if(MENU_SCREEN_ERROR_OK != list_next(list), ERROR);
256 return ECORE_CALLBACK_RENEW;
259 all_apps_list_destroy(list);
260 evas_object_data_del(all_apps, "list");
261 page_scroller_bring_in(scroller, 0);
262 page_scroller_focus(scroller);
263 menu_screen_set_done(true);
264 menu_screen_inc_booting_state();
266 return ECORE_CALLBACK_CANCEL;
271 static menu_screen_error_e _push_items(Evas_Object *all_apps)
274 Ecore_Idler *idle_timer;
276 list = all_apps_list_create();
277 retv_if(MENU_SCREEN_ERROR_OK != list_first(list), MENU_SCREEN_ERROR_FAIL);
279 evas_object_data_set(all_apps, "list", list);
280 idle_timer = ecore_idler_add(_push_items_idler_cb, all_apps);
281 retv_if(NULL == idle_timer, MENU_SCREEN_ERROR_FAIL);
283 Evas_Object *scroller;
284 scroller = evas_object_data_get(all_apps, "scroller");
285 if (MENU_SCREEN_ERROR_OK != all_apps_shortcut_add_all(scroller))
286 _E("Cannot add shortcuts");
290 button = _add_edit_button(all_apps, scroller);
291 if (NULL == button) {
292 _D("cannot make the edit button");
294 elm_object_part_content_set(all_apps, ALL_APPS_EDIT_BUTTON_PART, button);
297 return MENU_SCREEN_ERROR_OK;
302 HAPI Evas_Object *all_apps_layout_create(Evas_Object *controlbar, int rotate)
304 Evas_Object *all_apps;
306 Evas_Object *scroller;
310 static const char item_edje[] = EDJEDIR"/item_4x4.edj";
311 static const char *page_edje;
312 static const char *all_apps_edje;
313 int item_width, item_height;
317 all_apps = elm_layout_add(controlbar);
318 retv_if(NULL == all_apps, NULL);
320 all_apps_edje = ALL_APPS_EDJE_PORTRAIT;
321 page_edje = GROUP_4X4_EDJE_PORTRAIT;
322 width = menu_screen_get_root_width();
323 height = menu_screen_get_root_height();
325 item_width = ITEM_WIDTH_PROP * menu_screen_get_root_width();
326 item_height = ITEM_HEIGHT_PROP * menu_screen_get_root_height();
328 if (EINA_FALSE == elm_layout_file_set(all_apps, all_apps_edje, ALL_APPS_GROUP)) {
329 evas_object_del(all_apps);
330 _E("cannot load layout");
334 evas = menu_screen_get_evas();
335 bg = evas_object_rectangle_add(evas);
336 evas_object_size_hint_min_set(bg, width, height);
337 evas_object_size_hint_max_set(bg, width, height);
338 evas_object_resize(bg, width, height);
339 elm_object_part_content_set(all_apps, "bg", bg);
340 evas_object_show(bg);
342 evas_object_data_set(all_apps, "win", evas_object_data_get(controlbar, "win"));
343 evas_object_data_set(all_apps, "layout", evas_object_data_get(controlbar, "layout"));
344 evas_object_data_set(all_apps, "controlbar", controlbar);
345 evas_object_data_set(all_apps, "page_edje", (void *) page_edje);
346 evas_object_data_set(all_apps, "page_max_app", (void *) PAGE_MAX_APP);
347 evas_object_data_set(all_apps, "item_edje", (void *) item_edje);
348 evas_object_data_set(all_apps, "item_width", (void *) item_width);
349 evas_object_data_set(all_apps, "item_height", (void *) item_height);
350 evas_object_data_set(all_apps, "item_enable_long_press", (void *) true);
351 evas_object_data_set(all_apps, "item_text_dual_line", (void *) true);
352 evas_object_data_set(all_apps, "is_under_pkgmgr", (void *) true);
353 evas_object_data_set(all_apps, "rotate", (void *) rotate);
354 evas_object_data_set(all_apps, "enable_bg_image", (void *) true);
355 evas_object_data_set(all_apps, "is_edited", (void *) true);
356 evas_object_size_hint_min_set(all_apps, width, height);
357 evas_object_size_hint_max_set(all_apps, width, height);
358 evas_object_resize(all_apps, width, height);
360 index = index_create(all_apps, 0, 0);
362 evas_object_del(all_apps);
363 _E("cannot create index.");
366 elm_object_part_content_set(all_apps, "index", index);
367 evas_object_data_set(all_apps, "index", index);
369 scroller = page_scroller_create(all_apps, index, PAGE_SCROLLER_SORT_BY_PACKAGE, rotate);
370 if (NULL == scroller) {
371 evas_object_del(all_apps);
372 index_destroy(index);
373 _E("cannot create scroller.");
377 elm_object_part_content_set(all_apps, "content", scroller);
378 evas_object_data_set(all_apps, "scroller", scroller);
379 if (!all_apps_shortcut_init(all_apps)) _E("Cannot initialize shortcut");
380 retv_if(MENU_SCREEN_ERROR_FAIL == _push_items(all_apps), NULL);
387 HAPI void all_apps_layout_destroy(Evas_Object *all_apps)
390 Evas_Object *scroller;
392 ret_if(NULL == all_apps);
394 all_apps_shortcut_fini();
399 button = elm_object_part_content_unset(all_apps, ALL_APPS_EDIT_BUTTON_PART);
400 _remove_edit_button(button);
402 _D("cannot find the all_apps object");
406 scroller = evas_object_data_get(all_apps, "scroller");
407 ret_if(NULL == scroller);
408 if (scroller) page_scroller_destroy(scroller);
410 index = evas_object_data_get(scroller, "index");
411 if (index) index_destroy(index);
413 evas_object_data_del(all_apps, "win");
414 evas_object_data_del(all_apps, "layout");
415 evas_object_data_del(all_apps, "controlbar");
416 evas_object_data_del(all_apps, "index");
417 evas_object_data_del(all_apps, "scroller");
418 evas_object_data_del(all_apps, "page_edje");
419 evas_object_data_del(all_apps, "page_max_app");
420 evas_object_data_del(all_apps, "item_edje");
421 evas_object_data_del(all_apps, "item_width");
422 evas_object_data_del(all_apps, "item_height");
423 evas_object_data_del(all_apps, "item_enable_long_press");
424 evas_object_data_del(all_apps, "item_text_dual_line");
425 evas_object_data_del(all_apps, "is_under_pkgmgr");
426 evas_object_data_del(all_apps, "rotate");
427 evas_object_data_del(all_apps, "enable_bg_image");
428 evas_object_data_del(all_apps, "is_edited");
430 evas_object_del(all_apps);