4 * Copyright (c) 2009-2014 Samsung Electronics Co., Ltd All Rights Reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <Elementary.h>
22 #include "menu_screen.h"
25 #include "item_event.h"
28 #include "page_scroller.h"
30 #include "all_apps/layout.h"
31 #include "all_apps/list.h"
32 #include "all_apps/shortcut.h"
34 #define ALL_APPS_EDJE_PORTRAIT EDJEDIR"/all_apps_portrait.edj"
35 #define ALL_APPS_GROUP "all_apps"
37 #define GROUP_4X4_EDJE_PORTRAIT EDJEDIR"/group_4x4_portrait.edj";
39 #define ALL_APPS_EDIT_BUTTON_EDJE EDJEDIR"/button_edit.edj"
40 #define ALL_APPS_EDIT_BUTTON_GROUP "button_edit"
41 #define ALL_APPS_EDIT_BUTTON_PART "button_edit"
43 #define IDS_HS_BUTTON_DONE "IDS_HS_BUTTON_DONE"
46 HAPI void all_apps_layout_edit(Evas_Object *all_apps)
48 Evas_Object *edit_button;
49 Evas_Object *scroller;
51 edit_button = elm_object_part_content_get(all_apps, ALL_APPS_EDIT_BUTTON_PART);
52 ret_if(NULL == edit_button);
53 edje_object_signal_emit(_EDJ(edit_button), "edit_button,enable", "menu");
54 if (edje_object_part_text_set(_EDJ(edit_button), "edit_button_text", _(IDS_HS_BUTTON_DONE)) == EINA_FALSE) {
55 _E("Failed to set text on the part, edje:%p, part:%s, text:%s", _EDJ(edit_button), "edit_button_text", _(IDS_HS_BUTTON_DONE));
58 scroller = elm_object_part_content_get(all_apps, "content");
59 ret_if(NULL == scroller);
60 page_scroller_edit(scroller);
65 HAPI void all_apps_layout_unedit(Evas_Object *all_apps)
67 Evas_Object *edit_button;
69 ret_if(NULL == all_apps);
72 edit_button = elm_object_part_content_get(all_apps, ALL_APPS_EDIT_BUTTON_PART);
73 ret_if(NULL == edit_button);
75 edje_object_signal_emit(_EDJ(edit_button), "edit_button,disable", "menu");
76 if (edje_object_part_text_set(_EDJ(edit_button), "edit_button_text", "") == EINA_FALSE) {
77 _E("Failed to set text on the part, edje:%p, part:%s, text:(null)", _EDJ(edit_button), "edit_button_text");
82 Evas_Object *scroller;
84 scroller = elm_object_part_content_get(all_apps, "content");
85 ret_if(NULL == scroller);
87 page_scroller_unedit(scroller);
93 static void _press_edit_button(Evas_Object *edje)
95 edje_object_signal_emit(edje, "edit_button,enable,press", "menu");
100 static void _release_edit_button(Evas_Object *edje)
102 edje_object_signal_emit(edje, "edit_button,enable,release", "menu");
107 static void _edit_button_down_cb(void *data, Evas_Object *obj, const char* emission, const char* source)
109 Evas_Object *scroller = data;
111 _D("Edit button is down");
113 if (page_scroller_is_edited(scroller)) {
114 _press_edit_button(obj);
120 static void _edit_button_up_cb(void *data, Evas_Object *obj, const char* emission, const char* source)
122 Evas_Object *scroller = data;
123 Evas_Object *all_apps;
125 _D("Edit button is up");
127 all_apps = evas_object_data_get(scroller, "tab");
128 if (page_scroller_is_edited(scroller)) {
130 bool pressed = false;
132 eo = evas_object_data_get(obj, "evas_object");
133 pressed = (bool) evas_object_data_get(eo, "pressed");
135 all_apps_layout_unedit(all_apps);
137 _release_edit_button(obj);
140 all_apps_layout_edit(all_apps);
146 static void _button_out_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
148 _D("Edit button is out");
149 evas_object_data_set(obj, "pressed", (void *) false);
154 static void _button_in_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
156 _D("Edit button is in");
157 evas_object_data_set(obj, "pressed", (void *) true);
162 static Evas_Object *_add_edit_button(Evas_Object *parent, Evas_Object *scroller)
166 retv_if(NULL == parent, NULL);
167 retv_if(NULL == scroller, NULL);
169 button = layout_load_edj(parent, ALL_APPS_EDIT_BUTTON_EDJE, ALL_APPS_EDIT_BUTTON_GROUP);
170 retv_if(NULL == button, NULL);
172 edje_object_signal_callback_add(_EDJ(button), "edit_button,down", "menu", _edit_button_down_cb, scroller);
173 edje_object_signal_callback_add(_EDJ(button), "edit_button,up", "menu", _edit_button_up_cb, scroller);
174 evas_object_event_callback_add(button, EVAS_CALLBACK_MOUSE_OUT, _button_out_cb, NULL);
175 evas_object_event_callback_add(button, EVAS_CALLBACK_MOUSE_IN, _button_in_cb, NULL);
176 evas_object_data_set(button, "pressed", (void *) false);
183 static void _remove_edit_button(Evas_Object *button)
185 ret_if(NULL == button);
187 edje_object_signal_callback_del(_EDJ(button), "edit_button,down", "menu", _edit_button_down_cb);
188 edje_object_signal_callback_del(_EDJ(button), "edit_button,up", "menu", _edit_button_up_cb);
189 evas_object_event_callback_del(button, EVAS_CALLBACK_MOUSE_OUT, _button_out_cb);
190 evas_object_event_callback_del(button, EVAS_CALLBACK_MOUSE_IN, _button_in_cb);
191 evas_object_data_del(button, "pressed");
193 layout_unload_edj(button);
198 static menu_screen_error_e _load_item(Evas_Object *scroller, app_list_item *item)
202 retv_if(NULL == item, MENU_SCREEN_ERROR_FAIL);
204 if (ai->nodisplay || !ai->enabled) {
205 return MENU_SCREEN_ERROR_OK;
208 retv_if(NULL == page_scroller_push_item(scroller, ai), MENU_SCREEN_ERROR_FAIL);
210 return MENU_SCREEN_ERROR_OK;
216 static Eina_Bool _push_items_idler_cb(void *all_apps)
221 Evas_Object *scroller;
223 list = evas_object_data_get(all_apps, "list");
224 scroller = evas_object_data_get(all_apps, "scroller");
226 retv_if(NULL == list, ECORE_CALLBACK_CANCEL);
227 goto_if(NULL == scroller, ERROR);
228 goto_if(MENU_SCREEN_ERROR_OK != list_is_ended(list, &flag), ERROR);
229 goto_if(flag == true, ERROR);
230 goto_if(MENU_SCREEN_ERROR_OK != list_get_item(list, &item), ERROR);
231 goto_if(MENU_SCREEN_ERROR_OK != _load_item(scroller, item), ERROR);
232 goto_if(MENU_SCREEN_ERROR_OK != list_next(list), ERROR);
234 return ECORE_CALLBACK_RENEW;
237 all_apps_list_destroy(list);
238 evas_object_data_del(all_apps, "list");
239 page_scroller_bring_in(scroller, 0);
240 menu_screen_set_done(true);
242 return ECORE_CALLBACK_CANCEL;
247 static menu_screen_error_e _push_items(Evas_Object *all_apps)
250 Ecore_Idler *idle_timer;
252 list = all_apps_list_create();
253 retv_if(MENU_SCREEN_ERROR_OK != list_first(list), MENU_SCREEN_ERROR_FAIL);
255 evas_object_data_set(all_apps, "list", list);
256 idle_timer = ecore_idler_add(_push_items_idler_cb, all_apps);
257 retv_if(NULL == idle_timer, MENU_SCREEN_ERROR_FAIL);
259 Evas_Object *scroller;
260 scroller = evas_object_data_get(all_apps, "scroller");
261 if (MENU_SCREEN_ERROR_OK != all_apps_shortcut_add_all(scroller))
262 _E("Cannot add shortcuts");
266 button = _add_edit_button(all_apps, scroller);
267 if (NULL == button) {
268 _D("cannot make the edit button");
270 elm_object_part_content_set(all_apps, ALL_APPS_EDIT_BUTTON_PART, button);
273 return MENU_SCREEN_ERROR_OK;
278 HAPI Evas_Object *all_apps_layout_create(Evas_Object *controlbar, int rotate)
280 Evas_Object *all_apps;
282 Evas_Object *scroller;
284 static const char item_edje[] = EDJEDIR"/item_4x4.edj";
285 static const char *page_edje;
286 static const char *all_apps_edje;
287 int item_width, item_height;
291 all_apps = elm_layout_add(controlbar);
292 retv_if(NULL == all_apps, NULL);
294 all_apps_edje = ALL_APPS_EDJE_PORTRAIT;
295 page_edje = GROUP_4X4_EDJE_PORTRAIT;
296 width = menu_screen_get_root_width();
297 height = menu_screen_get_root_height() - INDEX_HEIGHT;
299 item_width = ITEM_WIDTH_PROP * menu_screen_get_root_width();
300 item_height = ITEM_HEIGHT_PROP * menu_screen_get_root_height();
302 if (EINA_FALSE == elm_layout_file_set(all_apps, all_apps_edje, ALL_APPS_GROUP)) {
303 evas_object_del(all_apps);
304 _E("cannot load layout");
308 evas_object_data_set(all_apps, "win", evas_object_data_get(controlbar, "win"));
309 evas_object_data_set(all_apps, "layout", evas_object_data_get(controlbar, "layout"));
310 evas_object_data_set(all_apps, "controlbar", controlbar);
311 evas_object_data_set(all_apps, "page_edje", (void *) page_edje);
312 evas_object_data_set(all_apps, "page_max_app", (void *) PAGE_MAX_APP);
313 evas_object_data_set(all_apps, "item_edje", (void *) item_edje);
314 evas_object_data_set(all_apps, "item_width", (void *) item_width);
315 evas_object_data_set(all_apps, "item_height", (void *) item_height);
316 evas_object_data_set(all_apps, "item_enable_long_press", (void *) true);
317 evas_object_data_set(all_apps, "item_text_dual_line", (void *) true);
318 evas_object_data_set(all_apps, "is_under_pkgmgr", (void *) true);
319 evas_object_data_set(all_apps, "rotate", (void *) rotate);
320 evas_object_data_set(all_apps, "enable_bg_image", (void *) true);
321 evas_object_size_hint_min_set(all_apps, width, height);
322 evas_object_size_hint_max_set(all_apps, width, height);
323 evas_object_resize(all_apps, width, height);
325 index = index_create(all_apps, 0,0);
327 evas_object_del(all_apps);
328 _E("cannot create index.");
331 elm_object_part_content_set(all_apps, "index", index);
332 evas_object_data_set(all_apps, "index", index);
334 scroller = page_scroller_create(all_apps, index, PAGE_SCROLLER_SORT_BY_PACKAGE, rotate);
335 if (NULL == scroller) {
336 evas_object_del(all_apps);
337 index_destroy(index);
338 _E("cannot create scroller.");
342 elm_object_part_content_set(all_apps, "content", scroller);
343 evas_object_data_set(all_apps, "scroller", scroller);
344 if (!all_apps_shortcut_init(all_apps)) _E("Cannot initialize shortcut");
345 retv_if(MENU_SCREEN_ERROR_FAIL == _push_items(all_apps), NULL);
352 HAPI void all_apps_layout_destroy(Evas_Object *all_apps)
355 Evas_Object *scroller;
357 ret_if(NULL == all_apps);
359 all_apps_shortcut_fini();
364 button = elm_object_part_content_unset(all_apps, ALL_APPS_EDIT_BUTTON_PART);
365 _remove_edit_button(button);
367 _D("cannot find the all_apps object");
371 index = evas_object_data_get(all_apps, "index");
372 scroller = evas_object_data_get(all_apps, "scroller");
374 if (scroller) page_scroller_destroy(scroller);
375 if (index) index_destroy(index);
377 evas_object_data_del(all_apps, "win");
378 evas_object_data_del(all_apps, "layout");
379 evas_object_data_del(all_apps, "controlbar");
380 evas_object_data_del(all_apps, "index");
381 evas_object_data_del(all_apps, "scroller");
382 evas_object_data_del(all_apps, "page_edje");
383 evas_object_data_del(all_apps, "page_max_app");
384 evas_object_data_del(all_apps, "item_edje");
385 evas_object_data_del(all_apps, "item_width");
386 evas_object_data_del(all_apps, "item_height");
387 evas_object_data_del(all_apps, "item_enable_long_press");
388 evas_object_data_del(all_apps, "item_text_dual_line");
389 evas_object_data_del(all_apps, "is_under_pkgmgr");
390 evas_object_data_del(all_apps, "rotate");
391 evas_object_data_del(all_apps, "enable_bg_image");
393 evas_object_del(all_apps);