bug fix: HomeScreen sometimes fails in connection with SystemController at the time...
[profile/ivi/ico-uxf-homescreen.git] / src / homescreen / CicoHSMenuWindow.cpp
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9 /**
10  * @brief   Menu Window class
11  *
12  * @date    Aug-08-2013
13  */
14 #include "CicoHSMenuWindow.h"
15 #include "CicoHSMenuTouch.h"
16 #include "CicoResourceConfig.h"
17 #include "CicoHomeScreen.h"
18 #include "CicoHSSystemState.h"
19 #include <stdio.h>
20
21 /*============================================================================*/
22 /* static members                                                             */
23 /*============================================================================*/
24 CicoHSMenuWindow *CicoHSMenuWindow::menu_window_instance;
25 int  CicoHSMenuWindow::menu_tile_width = 290;
26 int  CicoHSMenuWindow::menu_tile_height = 290;
27
28 /*============================================================================*/
29 /* functions                                                                  */
30 /*============================================================================*/
31 /*--------------------------------------------------------------------------*/
32 /**
33  * @brief   CicoHSMenuWindow::CicoHSMenuWindo
34  *          Constractor
35  *
36  * @param[in]   none
37  * @return      none
38  */
39 /*--------------------------------------------------------------------------*/
40 CicoHSMenuWindow::CicoHSMenuWindow(void)
41 {
42     /*initialzie values*/
43     terminate_mode = false;
44
45     InitAppTiles();
46
47     evas = NULL;
48     canvas = NULL;
49     rectangle = NULL;
50
51     for (int ii = 0;ii < ICO_HS_MENU_MAX_TILE_NUM;ii++) {
52         menu_tile[ii] = NULL;
53     }
54     for (int ii = 0;ii < ICO_HS_MENU_MAX_MENU_PAGE_NUM;ii++) {
55         page_pointer[ii] = NULL;
56     }
57
58     surface = 0;
59
60     menu_window_instance = this;
61
62     life_cycle_controller = CicoHSLifeCycleController::getInstance();
63
64     CicoResourceConfig::GetImagePath(img_dir_path, ICO_HS_MAX_PATH_BUFF_LEN);
65
66     m_showState = false;
67 }
68
69 /*--------------------------------------------------------------------------*/
70 /**
71  * @brief   CicoHSMenuWindow::~CicoHSMenuWindo
72  *          Destractor
73  *
74  * @param[in]   none
75  * @return      none
76  */
77 /*--------------------------------------------------------------------------*/
78 CicoHSMenuWindow::~CicoHSMenuWindow(void)
79 {
80     /* Do not somthing to do */
81 }
82
83 /*--------------------------------------------------------------------------*/
84 /**
85  * @brief   CicoHSMenuWindow::SetMenuBack
86  *          create object and show (background of menu)
87  *
88  * @param[in]   none
89  * @return      ERROR or OK
90  */
91 /*--------------------------------------------------------------------------*/
92 int
93 CicoHSMenuWindow::SetMenuBack(void)
94 {
95     char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
96     /* set menu back */
97     /* image file name*/
98     snprintf(img_path, sizeof(img_path), "%s%s",
99              img_dir_path, ICO_HS_IMAGE_FILE_MENU_BACK_GROUND);
100
101     /* set object*/
102     rectangle = evas_object_rectangle_add(evas);
103     if (true == CicoHSSystemState::getInstance()->getNightMode()) {
104         evas_object_color_set(rectangle,0,0,0,178);
105     }
106     else {
107         evas_object_color_set(rectangle,120,120,120,178);
108     }
109     evas_object_move(rectangle, 0, 0);
110     evas_object_resize(rectangle, width, height);
111     evas_object_show(rectangle);
112
113     /* set object*/
114     canvas = evas_object_image_filled_add(evas);
115     evas_object_image_file_set(canvas, img_path, NULL);
116     int err = evas_object_image_load_error_get(canvas);
117     if (err != EVAS_LOAD_ERROR_NONE) {
118         ICO_ERR("CicoHSMenuWindow::SetMenuBack: backgound image is not exist");
119         ICO_TRA("CicoHSMenuWindow::SetMenuBack Leave(ERR)");
120         evas_object_del(canvas);
121         return ICO_ERROR;
122     }
123     evas_object_event_callback_add(canvas, EVAS_CALLBACK_MOUSE_DOWN,
124                                    CicoHSMenuTouch::TouchDownMenu,NULL);
125     evas_object_event_callback_add(canvas, EVAS_CALLBACK_MOUSE_UP,
126                                    CicoHSMenuTouch::TouchUpMenu,NULL);
127     evas_object_move(canvas, 0, 0);
128     evas_object_resize(canvas, width, height);
129     evas_object_show(canvas);
130
131     ICO_TRA("CicoHSMenuWindow::SetMenuBack Leave(EOK)");
132     return ICO_OK;
133 }
134
135 /*--------------------------------------------------------------------------*/
136 /**
137  * @brief   CicoHSMenuWindow::FreeMenuBack
138  *          free object (background of menu)
139  *
140  * @param[in]   none
141  * @return      none
142  */
143 /*--------------------------------------------------------------------------*/
144 void
145 CicoHSMenuWindow::FreeMenuBack(void)
146 {
147     evas_object_del(canvas);
148     evas_object_del(rectangle);
149 }
150
151 /*--------------------------------------------------------------------------*/
152 /**
153  * @brief   CicoHSMenuWindow::GetLayout
154  *          read layout file
155  *
156  * @param[in]   filename   layout file name
157  * @param[out]   layout   layout data
158  * @param[out]   num      num of tile
159  * @return      none
160  */
161 /*--------------------------------------------------------------------------*/
162 void
163 CicoHSMenuWindow::GetLayout(const char *filename,CicoLayoutInfo *layout,int *num)
164 {
165     int ret;
166     FILE *fp;
167     *num = 0;
168     fp = fopen(filename,"r");
169     if(fp == NULL){
170         return;
171     }
172     int idx =0;
173     while( ( ret = fscanf( fp, "%d,%d,%d,%d,%d",
174         &layout[idx].appidx, &layout[idx].page, &layout[idx].position,
175         &layout[idx].tile_width, &layout[idx].tile_height ) ) != EOF ){
176         idx++;
177     }
178     *num = idx;
179     fclose(fp);
180
181 }
182
183 /*--------------------------------------------------------------------------*/
184 /**
185  * @brief   CicoHSMenuWindow::GetCategory
186  *          read category file
187  *
188  * @param[in]   filename   category file name
189  * @param[out]  category   category data
190  * @param[out]  num        num of category
191  * @return      none
192  */
193 /*--------------------------------------------------------------------------*/
194 void
195 CicoHSMenuWindow::GetCategory(const char *filename, int *category, int *num)
196 {
197     int ret;
198     FILE *fp;
199     *num = 0;
200     fp = fopen(filename,"r");
201     if(fp == NULL){
202         return;
203     }
204     int idx =0;
205     while( ( ret = fscanf( fp, "%d", &category[idx]
206         ) ) != EOF ){
207         idx++;
208     }
209     *num = idx;
210     fclose(fp);
211 }
212
213 /*--------------------------------------------------------------------------*/
214 /**
215  * @brief   CicoHSMenuWindow::SetLayout
216  *          write layout file
217  *
218  * @param[in]   filename   layout file name
219  * @param[in]   layout   layout data
220  * @param[in]   num      num of tile
221  * @return      none
222  */
223 /*--------------------------------------------------------------------------*/
224 void
225 CicoHSMenuWindow::SetLayout(const char *filename,CicoLayoutInfo *layout,int num)
226 {
227     int ret;
228     FILE *fp;
229
230     fp = fopen(filename,"w+");
231     if (fp == NULL) {
232         return;
233     }
234     for (int ii = 0;ii < num;ii++) {
235        ret = fprintf(fp, "%d,%d,%d,%d,%d\n",
236                      layout[ii].appidx,layout[ii].page,layout[ii].position,
237                      layout[ii].tile_width,layout[ii].tile_height);
238        if (ret < 0) {
239            break;
240        }
241     }
242     fclose(fp);
243 }
244
245 /*--------------------------------------------------------------------------*/
246 /**
247  * @brief   CicoHSMenuWindow::InitAppTiles
248  *          Initialization object (tiles)
249  *
250  * @param[in]   none
251  * @return      none
252  */
253 /*--------------------------------------------------------------------------*/
254 void
255 CicoHSMenuWindow::InitAppTiles(void)
256 {
257     ICO_TRA("CicoHSMenuWindow::InitAppTiles Enter");
258
259     current_page = 0;
260     subcurrent_page = 0;
261
262     for (int ii = 0; ii < ICO_HS_MENU_MAX_MENU_CATEGORY_NUM; ii++){
263         category_info[ii].id= 0;
264         category_info[ii].page = 0;
265         category_info[ii].subpage_max = 0;
266         category_info[ii].tile_num = 0;
267     }
268
269     all_tile_num = 0;
270     all_page_num = 0;
271
272     ICO_TRA("CicoHSMenuWindow::InitAppTiles Leave");
273 }
274
275 /*--------------------------------------------------------------------------*/
276 /**
277  * @brief   CicoHSMenuWindow::SetAppTiles
278  *          create object and show (tiles)
279  *
280  * @param[in]   none
281  * @return      ERROR or OK
282  */
283 /*--------------------------------------------------------------------------*/
284 int
285 CicoHSMenuWindow::SetAppTiles(void)
286 {
287     int tile_num = 0;
288     int category_num = 0;
289     int category[ICO_HS_MENU_MAX_TILE_NUM];
290     int ctg_idx = 0;
291     int position = 0;
292     int page = 0;
293     int subpage = 0;
294     current_page = 0;
295
296     /* get APP information */
297     std::vector<CicoAilItems> aillist =
298         life_cycle_controller->getAilList();
299
300     /* get category infomation */
301     GetCategory(ICO_HS_MENU_CATEGORY_FILE_PATH, category, &category_num);
302     ICO_DBG("CicoHSMenuWindow::SetAppTiles :category_num %d", category_num);
303
304     for (int ii = 0; ii < category_num ; ii++) {
305        ICO_DBG("CicoHSMenuWindow::SetAppTiles :category[%d] %d", ii, category[ii]);
306     }
307
308     /* other category add */
309     all_category_num = category_num + 1;
310
311     /* page set */
312     for (int ii = 0; ii < all_category_num ; ii++) {
313         if(ii == 0) {
314             /* other category */
315             category_info[ii].id = ICO_HS_MENU_OTHER_CATEGORY_ID;
316             category_info[ii].page = ii;
317         }
318         else {
319             /* category */
320             category_info[ii].id = category[ii - 1];
321             category_info[ii].page = ii;
322         }
323     }
324
325     /*first time layout*/
326     for (unsigned int ii = 0; ii < aillist.size(); ii++) {
327
328         /*all application num*/
329         if((aillist[ii].m_noIcon) ||
330                 (strcmp(aillist[ii].m_group.c_str(),
331                 ICO_HS_GROUP_SPECIAL) == 0)) {
332             ICO_DBG("CicoHSMenuWindow::SetAppTiles :ignore app appid = [%s] noIcon = [%d]",
333                     aillist[ii].m_appid.c_str(),aillist[ii].m_noIcon);
334             continue;
335         }
336         ICO_DBG("CicoHSMenuWindow::SetAppTiles :SetApp appid = [%s] noIcon =[%d]",
337                 aillist[ii].m_appid.c_str(),aillist[ii].m_noIcon);
338         ICO_DBG("CicoHSMenuWindow::SetAppTile :aillist[%d].m_categoryID = [%d]",
339                 ii, aillist[ii].m_categoryID);
340
341         /* Categories */
342         for (ctg_idx = 0; ctg_idx < category_num ; ctg_idx++ ) {
343             if (aillist[ii].m_categoryID == category[ctg_idx]) {
344                 SetCategoryInfo(category[ctg_idx]);
345                 GetTileInfo(category[ctg_idx], &page, &subpage, &position);
346                 break;
347             }
348         }
349
350         /* Other categories */
351         if (ctg_idx == category_num) {
352             SetCategoryInfo(ICO_HS_MENU_OTHER_CATEGORY_ID);
353             GetTileInfo(ICO_HS_MENU_OTHER_CATEGORY_ID,
354                         &page, &subpage, &position);
355         }
356
357         /* put tile */
358         menu_tile[tile_num] =
359             new CicoHSMenuTile(aillist[ii].m_appid.c_str(),
360             aillist[ii].m_icon.c_str(),page, subpage, position,
361             CicoHSMenuWindow::Tile_Width(), CicoHSMenuWindow::Tile_Height());
362
363         tile_num++;
364     }
365
366     /*menu num*/
367     all_tile_num = tile_num;
368     all_page_num = all_category_num;
369
370     for (int ii = 0; ii < all_category_num ; ii++) {
371         ICO_DBG("CicoHSMenuWindow::SetAppTile :category_info[%d].id = [%d]",
372                 ii, category_info[ii].id);
373         ICO_DBG("CicoHSMenuWindow::SetAppTile :category_info[%d].subpage_max = [%d]",
374                 ii, category_info[ii].subpage_max);
375         ICO_DBG("CicoHSMenuWindow::SetAppTile :category_info[%d].page = [%d]",
376                 ii, category_info[ii].page);
377         ICO_DBG("CicoHSMenuWindow::SetAppTile :category_info[%d].tile_num = [%d]",
378                 ii , category_info[ii].tile_num);
379     }
380
381     /*in case of over max num*/
382     if (all_page_num > ICO_HS_MENU_MAX_MENU_PAGE_NUM) {
383        all_page_num = ICO_HS_MENU_MAX_MENU_PAGE_NUM;
384     }
385
386     /*make tiles*/
387     for (int ii = 0; ii < tile_num; ii++) {
388         if (menu_tile[ii] == NULL) {
389             continue;
390         }
391         menu_tile[ii]->CreateObject(evas);
392         if (menu_tile[ii]->GetPage() != 0) {
393             /*out of window*/
394             menu_tile[ii]->OffsetMove(width,0);
395         }
396         if (menu_tile[ii]->GetSubPage() != 0) {
397             /*out of window*/
398             menu_tile[ii]->OffsetMove(height,0);
399         }
400     }
401     return ICO_OK;
402 }
403
404 /*--------------------------------------------------------------------------*/
405 /**
406  * @brief   CicoHSMenuWindow::FreeAppTiles
407  *          free object (tiles)
408  *
409  * @param[in]   none
410  * @return      none
411  */
412 /*--------------------------------------------------------------------------*/
413 void
414 CicoHSMenuWindow::FreeAppTiles(void)
415 {
416     for (int ii = 0; ii < all_tile_num; ii++) {
417         if (menu_tile[ii] == NULL) {
418             continue;
419         }
420         menu_tile[ii]->FreeObject();
421         delete menu_tile[ii];
422     }
423 }
424
425 /*--------------------------------------------------------------------------*/
426 /**
427  * @brief   CicoHSMenuWindow::RenewAppTiles
428  *          renewal of a menu
429  *
430  * @param   none
431  * @return  none
432  */
433 /*--------------------------------------------------------------------------*/
434 void
435 CicoHSMenuWindow::RenewAppTiles(void)
436 {
437     ICO_TRA("CicoHSMenuWindow::RenewAppTiles Enter");
438
439     int cnt, cnt2;
440     int ret;
441
442     /* backup old data */
443     int all_tile_num_org = all_tile_num;
444     CicoHSMenuTile *menu_tile_org[ICO_HS_MENU_MAX_TILE_NUM];
445     for (cnt=0; cnt < all_tile_num_org; cnt++) {
446         menu_tile_org[cnt]=menu_tile[cnt];
447     }
448
449     /* initialization */
450     InitAppTiles();
451
452     /* set app tiles */
453     ret = SetAppTiles();
454     if(ret != ICO_OK){
455         ICO_ERR("CicoHSMenuWindow::RenewAppTiles: could not make tiles.");
456     }
457
458     /* update app info list */
459     CicoHomeScreen::RenewAppInfoList();
460
461     /* set thumbnail from org */
462     for (cnt=0; cnt < all_tile_num; cnt++) {
463         if (menu_tile[cnt] == NULL) {
464             continue;
465         }
466         for (cnt2=0; cnt2 < all_tile_num_org; cnt2++) {
467             if (menu_tile_org[cnt2] == NULL) {
468                 continue;
469             }
470             if (strncmp(menu_tile[cnt]->GetAppId(),
471                         menu_tile_org[cnt2]->GetAppId(), ICO_HS_MAX_PROCESS_NAME) == 0) {
472                 menu_tile[cnt]->SetOrgThumbnail( menu_tile_org[cnt2] );
473                 break;
474             }
475         }
476     }
477
478     /* free org app tiles */
479     for (cnt2=0; cnt2 < all_tile_num_org; cnt2++) {
480         if (menu_tile_org[cnt2] == NULL) {
481             continue;
482         }
483         menu_tile_org[cnt2]->FreeObject();
484         delete menu_tile_org[cnt2];
485     }
486
487     ICO_TRA("CicoHSMenuWindow::RenewAppTiles Leave");
488 }
489
490 /*--------------------------------------------------------------------------*/
491 /**
492  * @brief   CicoHSMenuWindow::SetPagePointer
493  *          create object and show (page pointer)
494  *
495  * @param[in]   none
496  * @return      ERROR or OK
497  */
498 /*--------------------------------------------------------------------------*/
499 int
500 CicoHSMenuWindow::SetPagePointer(void)
501 {
502     /*debug*/
503     for (int ii = 0; ii < all_page_num; ii++) {
504
505         char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
506         /* set menu back */
507         /* image file name*/
508         if(ii == current_page){
509             snprintf(img_path,sizeof(img_path),"%s%s",
510                      img_dir_path,ICO_HS_IMAGE_FILE_MENU_PAGEPOINTER_P);
511         }else{
512             snprintf(img_path,sizeof(img_path),"%s%s",
513                      img_dir_path,ICO_HS_IMAGE_FILE_MENU_PAGEPOINTER_N);
514         }
515         /* set object*/
516         page_pointer[ii] = evas_object_image_filled_add(evas);
517         evas_object_image_file_set(page_pointer[ii], img_path, NULL);
518         int err = evas_object_image_load_error_get(page_pointer[ii]);
519         if (err != EVAS_LOAD_ERROR_NONE) {
520             ICO_ERR("CicoHSMenuWindow::SetPagePointer: page pointer image is not exist");
521             evas_object_del(page_pointer[ii]);
522             return ICO_ERROR;
523         }
524         evas_object_event_callback_add(page_pointer[ii],
525                                        EVAS_CALLBACK_MOUSE_DOWN,
526                                        CicoHSMenuTouch::TouchDownMenu,NULL);
527         evas_object_event_callback_add(page_pointer[ii],
528                                        EVAS_CALLBACK_MOUSE_UP,
529                                        CicoHSMenuTouch::TouchUpMenu,NULL);
530
531         int pos_x = ICO_HS_MENU_PAGE_POINTER_START_POS_X +
532                     (((width - ICO_HS_MENU_PAGE_POINTER_START_POS_X * 2) /
533                     all_page_num ) * ii) +
534                     (((width - ICO_HS_MENU_PAGE_POINTER_START_POS_X * 2) /
535                     all_page_num ) / 2)  -
536                     (ICO_HS_MENU_PAGE_POINTER_WIDTH / 2);
537         evas_object_move(page_pointer[ii], pos_x,
538                          ICO_HS_MENU_PAGE_POINTER_START_POS_Y);
539         evas_object_resize(page_pointer[ii],
540                          ICO_HS_MENU_PAGE_POINTER_WIDTH,
541                          ICO_HS_MENU_PAGE_POINTER_HEIGHT);
542         evas_object_show(page_pointer[ii]);
543     }
544     return ICO_OK;
545 }
546
547 /*--------------------------------------------------------------------------*/
548 /**
549  * @brief   CicoHSMenuWindow::FreePagePointer
550  *          free object (page pointer)
551  *
552  * @param[in]   none
553  * @return      none
554  */
555 /*--------------------------------------------------------------------------*/
556 void
557 CicoHSMenuWindow::FreePagePointer(void)
558 {
559     for (int ii = 0; ii < all_page_num; ii++) {
560         evas_object_del(page_pointer[ii]);
561     }
562 }
563
564 /*--------------------------------------------------------------------------*/
565 /**
566  * @brief   CicoHSMenuWindow::SetTerminateButton
567  *          create object and show (terminate button)
568  *
569  * @param[in]   none
570  * @return      ERROR or OK
571  */
572 /*--------------------------------------------------------------------------*/
573 int
574 CicoHSMenuWindow::SetTerminateButton(void)
575 {
576     int err;
577     char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
578     /* set menu back */
579     /* image file name*/
580
581     /* set object*/
582     terminate_back = evas_object_rectangle_add(evas);
583     evas_object_color_set(terminate_back,0,0,0,178);
584     evas_object_move(terminate_back, 0, 0);
585     evas_object_resize(terminate_back, width, height);
586     evas_object_layer_set(terminate_back, ICO_HS_MENU_TERMINATE_BUTTON_LAYER);
587     /* set object*/
588     snprintf(img_path,sizeof(img_path),"%s%s",
589                      img_dir_path,ICO_HS_IMAGE_FILE_MENU_TERMINATE_YES);
590     terminate_button_yes = evas_object_image_filled_add(evas);
591     evas_object_image_file_set(terminate_button_yes, img_path, NULL);
592     err = evas_object_image_load_error_get(terminate_button_yes);
593     if (err != EVAS_LOAD_ERROR_NONE) {
594         ICO_ERR("CicoHSMenuWindow::SetTerminateButton: image is not exist");
595         evas_object_del(terminate_button_yes);
596         return ICO_ERROR;
597     }
598     evas_object_event_callback_add(terminate_button_yes, EVAS_CALLBACK_MOUSE_UP,
599                                        CicoHSMenuTouch::TouchUpTerminateYes,
600                                        NULL);
601     evas_object_move(terminate_button_yes, width / 2  - 100 - 64,
602                                            height / 2 + 100);
603     evas_object_resize(terminate_button_yes,100,64);
604     evas_object_layer_set(terminate_button_yes, ICO_HS_MENU_TERMINATE_BUTTON_LAYER);
605
606     /* set object*/
607     snprintf(img_path,sizeof(img_path),"%s%s",
608                      img_dir_path, ICO_HS_IMAGE_FILE_MENU_TERMINATE_NO);
609     terminate_button_no = evas_object_image_filled_add(evas);
610     evas_object_image_file_set(terminate_button_no, img_path, NULL);
611     err = evas_object_image_load_error_get(terminate_button_no);
612     if (err != EVAS_LOAD_ERROR_NONE) {
613         ICO_ERR("CicoHSMenuWindow::SetTerminateButton: image is not exist");
614         evas_object_del(terminate_button_no);
615         return ICO_ERROR;
616     }
617     evas_object_event_callback_add(terminate_button_no, EVAS_CALLBACK_MOUSE_UP,
618                                        CicoHSMenuTouch::TouchUpTerminateNo,
619                                        NULL);
620     evas_object_move(terminate_button_no, width / 2  + 64,
621                                            height / 2 + 100);
622     evas_object_resize(terminate_button_no,100,64);
623     evas_object_layer_set(terminate_button_no, ICO_HS_MENU_TERMINATE_BUTTON_LAYER);
624
625     /* set object*/
626     snprintf(img_path,sizeof(img_path),"%s%s",
627                      img_dir_path,ICO_HS_IMAGE_FILE_MENU_TERMINATE_REALLY);
628     terminate_really = evas_object_image_filled_add(evas);
629     evas_object_image_file_set(terminate_really, img_path, NULL);
630     err = evas_object_image_load_error_get(terminate_really);
631     if (err != EVAS_LOAD_ERROR_NONE) {
632         ICO_ERR("CicoHSMenuWindow::SetTerminateButton: image is not exist");
633         evas_object_del(terminate_really);
634         return ICO_ERROR;
635     }
636     evas_object_move(terminate_really, width / 2 - 100,
637                                           height / 2 - 100);
638     evas_object_resize(terminate_really,200,64);
639     evas_object_layer_set(terminate_really, ICO_HS_MENU_TERMINATE_BUTTON_LAYER);
640
641     return ICO_OK;
642 }
643
644 /*--------------------------------------------------------------------------*/
645 /**
646  * @brief   CicoHSMenuWindow::FreeTeiminateButton
647  *          free object (terminate button)
648  *
649  * @param[in]   none
650  * @return      none
651  */
652 /*--------------------------------------------------------------------------*/
653 void
654 CicoHSMenuWindow::FreeTerminateButton(void)
655 {
656     evas_object_del(terminate_back);
657     evas_object_del(terminate_really);
658     evas_object_del(terminate_button_yes);
659     evas_object_del(terminate_button_no);
660 }
661
662 /*--------------------------------------------------------------------------*/
663 /**
664  * @brief   CicoHSMenuWindow::ShowTerminateButton
665  *          show terminate button
666  *
667  * @param[in]   none
668  * @return      ERROR or OK
669  */
670 /*--------------------------------------------------------------------------*/
671 void
672 CicoHSMenuWindow::ShowTerminateButton(void)
673 {
674    evas_object_show(terminate_back);
675    evas_object_show(terminate_really);
676    evas_object_show(terminate_button_yes);
677    evas_object_show(terminate_button_no);
678 }
679
680 /*--------------------------------------------------------------------------*/
681 /**
682  * @brief   CicoHSMenuWindow::HideTerminateButton
683  *          show terminate button
684  *
685  * @param[in]   none
686  * @return      none
687  */
688 /*--------------------------------------------------------------------------*/
689 void
690 CicoHSMenuWindow::HideTerminateButton(void)
691 {
692    evas_object_hide(terminate_back);
693    evas_object_hide(terminate_really);
694    evas_object_hide(terminate_button_yes);
695    evas_object_hide(terminate_button_no);
696 }
697
698 /*--------------------------------------------------------------------------*/
699 /**
700  * @brief   CicoHSMenuWindow::SetPageCursor
701  *          create object and show (page cursor)
702  *
703  * @param[in]   none
704  * @return      ERROR or OK
705  */
706 /*--------------------------------------------------------------------------*/
707 int
708 CicoHSMenuWindow::SetPageCursor(void)
709 {
710     char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
711
712     /* up cursor */
713     snprintf(img_path,sizeof(img_path),"%s%s",
714                  img_dir_path,ICO_HS_IMAGE_FILE_MENU_PAGE_UP_CURSOR);
715
716     /* set object*/
717     page_up_cursor = evas_object_image_filled_add(evas);
718     evas_object_image_file_set(page_up_cursor, img_path, NULL);
719     int err = evas_object_image_load_error_get(page_up_cursor);
720     if (err != EVAS_LOAD_ERROR_NONE) {
721         ICO_ERR("CicoHSMenuWindow::SetPagePointer: page up cursor image is not exist");
722         evas_object_del(page_up_cursor);
723         return ICO_ERROR;
724     }
725
726     evas_object_move(page_up_cursor, ICO_HS_MENU_PAGE_UP_CURSOR_START_POS_X,
727                      ICO_HS_MENU_PAGE_UP_CURSOR_START_POS_Y);
728     evas_object_resize(page_up_cursor,
729                      ICO_HS_MENU_PAGE_UP_CURSOR_WIDTH,
730                      ICO_HS_MENU_PAGE_UP_CURSOR_HEIGHT);
731
732     /* down cursor */
733     snprintf(img_path,sizeof(img_path),"%s%s",
734                  img_dir_path,ICO_HS_IMAGE_FILE_MENU_PAGE_DOWN_CURSOR);
735
736     /* set object*/
737     page_down_cursor = evas_object_image_filled_add(evas);
738     evas_object_image_file_set(page_down_cursor, img_path, NULL);
739     err = evas_object_image_load_error_get(page_down_cursor);
740     if (err != EVAS_LOAD_ERROR_NONE) {
741         ICO_ERR("CicoHSMenuWindow::SetPagePointer: page down cursor image is not exist");
742         evas_object_del(page_down_cursor);
743         return ICO_ERROR;
744     }
745
746     evas_object_move(page_down_cursor, ICO_HS_MENU_PAGE_DOWN_CURSOR_START_POS_X,
747                      ICO_HS_MENU_PAGE_DOWN_CURSOR_START_POS_Y);
748     evas_object_resize(page_down_cursor,
749                      ICO_HS_MENU_PAGE_DOWN_CURSOR_WIDTH,
750                      ICO_HS_MENU_PAGE_DOWN_CURSOR_HEIGHT);
751
752     DspCtrlPageCursor();
753
754     return ICO_OK;
755 }
756
757 /*--------------------------------------------------------------------------*/
758 /**
759  * @brief   CicoHSMenuWindow::FreePageCursor
760  *          free object (page cursor)
761  *
762  * @param[in]   none
763  * @return      none
764  */
765 /*--------------------------------------------------------------------------*/
766 void
767 CicoHSMenuWindow::FreePageCursor(void)
768 {
769     evas_object_del(page_up_cursor);
770     evas_object_del(page_down_cursor);
771 }
772
773 /*--------------------------------------------------------------------------*/
774 /**
775  * @brief   CicoHSMenuWindow::CreateMenuWindow
776  *          Create menu window (page pointer)
777  *
778  * @param[in]   pos_x   window position x
779  * @param[in]   pos_y   window position y
780  * @param[in]   width   window width
781  * @param[in]   height  window height
782  * @return      none
783  */
784 /*--------------------------------------------------------------------------*/
785 int
786 CicoHSMenuWindow::CreateMenuWindow(int pos_x, int pos_y, int width, int height)
787 {
788     int ret;
789
790     /*create window*/
791     ret = CreateWindow(ICO_HS_MENU_WINDOW_TITLE,
792                        pos_x, pos_y, width, height, EINA_TRUE);
793     if(ret != ICO_OK){
794        return ret;
795     }
796
797     /* set tile size    */
798     CicoHSMenuWindow::menu_tile_width = (width - (ICO_HS_MENUTILE_START_POS_X * 2)
799                                          - (ICO_HS_MENUTILE_SPACE_TILE_AND_TILE
800                                              * (ICO_HS_MENUTILE_ROW-1)))
801                                         / ICO_HS_MENUTILE_ROW;
802     if (CicoHSMenuWindow::menu_tile_width < 150)    {
803         CicoHSMenuWindow::menu_tile_width = 150;
804     }
805     CicoHSMenuWindow::menu_tile_height = (height - (ICO_HS_STATUSBAR_WINDOW_HEIGHT
806                                                     + ICO_HS_CONTROLBAR_WINDOW_HEIGHT
807                                                     + ICO_HS_MENUTILE_HEIGHT + 8)
808                                           - (ICO_HS_MENUTILE_SPACE_TILE_AND_TILE
809                                              * (ICO_HS_MENUTILE_COLUMN-1)))
810                                          / ICO_HS_MENUTILE_COLUMN;
811     if (CicoHSMenuWindow::menu_tile_height < 150)   {
812         CicoHSMenuWindow::menu_tile_height = 150;
813     }
814     ICO_DBG("CicoHSMenuWindow::CreateMenuWindow: tile size(w/h)=%d/%d",
815             CicoHSMenuWindow::menu_tile_width, CicoHSMenuWindow::menu_tile_height);
816     if (CicoHSMenuWindow::menu_tile_width > CicoHSMenuWindow::menu_tile_height) {
817         CicoHSMenuWindow::menu_tile_width = CicoHSMenuWindow::menu_tile_height;
818     }
819     else    {
820         CicoHSMenuWindow::menu_tile_height = CicoHSMenuWindow::menu_tile_width;
821     }
822
823     /*get evas*/
824     evas = ecore_evas_get(window);
825     if (!evas) {
826         ICO_ERR("CicoHSMenuWindow::CreateMenuWindow: could not get evas.");
827         return ICO_ERROR;
828     }
829
830     /* MenuBack */
831     ret = SetMenuBack();
832     if(ret != ICO_OK){
833         ICO_ERR("CicoHSMenuWindow::CreateMenuWindow: could not make back ground.");
834         FreeWindow();
835         return ICO_ERROR;
836     }
837     /* App tiles*/
838     ret = SetAppTiles();
839     if(ret != ICO_OK){
840         ICO_ERR("CicoHSMenuWindow::CreateMenuWindow: could not make tiles.");
841         FreeMenuBack();
842         FreeWindow();
843         return ICO_ERROR;
844     }
845
846     /* Page Pointer */
847     ret = SetPagePointer();
848     if(ret != ICO_OK){
849         ICO_ERR("CicoHSMenuWindow::CreateMenuWindow: could not make page pointer.");
850         FreeAppTiles();
851         FreeMenuBack();
852         FreeWindow();
853         return ICO_ERROR;
854     }
855
856     /* Page Cursor */
857     ret = SetPageCursor();
858     if(ret != ICO_OK){
859         ICO_ERR("CicoHSMenuWindow::CreateMenuWindow: could not make page cursor.");
860         FreePagePointer();
861         FreeAppTiles();
862         FreeMenuBack();
863         FreeWindow();
864         return ICO_ERROR;
865     }
866
867     /* Terminate Button */
868     ret = SetTerminateButton();
869     if(ret != ICO_OK){
870         ICO_ERR("CicoHSMenuWindow::CreateMenuWindow: could not make teminate button.");
871         FreePageCursor();
872         FreePagePointer();
873         FreeAppTiles();
874         FreeMenuBack();
875         FreeWindow();
876         return ICO_ERROR;
877     }
878
879     /* Initialize Action*/
880     CicoHSMenuTouch::Initialize(this);
881
882     return ICO_OK;
883 }
884
885 /*--------------------------------------------------------------------------*/
886 /**
887  * @brief   CicoHSMenuWindow::FreeMenuWindow
888  *          free menu window
889  *
890  * @param[in]   none
891  * @return      none
892  */
893 /*--------------------------------------------------------------------------*/
894 void
895 CicoHSMenuWindow::FreeMenuWindow(void)
896 {
897     FreeTerminateButton();
898     FreePageCursor();
899     FreePagePointer();
900     FreeAppTiles();
901     FreeMenuBack();
902     FreeWindow();
903 }
904
905 /*--------------------------------------------------------------------------*/
906 /**
907  * @brief   CicoHSMenuWindow::MoveToNextAnimation
908  *          animation parts (move to next)
909  *
910  * @param[in]   data
911  * @param[in]   pos
912  * @return      EINA_TRUE
913  */
914 /*--------------------------------------------------------------------------*/
915 Eina_Bool
916 CicoHSMenuWindow::MoveToNextAnimation(void *data,double pos)
917 {
918     int current_page;
919     double frame = ecore_animator_pos_map(pos, ECORE_POS_MAP_LINEAR, 0.5, 1);
920     current_page = reinterpret_cast<int>(data);
921
922     for (int ii = 0;ii < menu_window_instance->all_tile_num;ii++) {
923         if (menu_window_instance->menu_tile[ii] == NULL) {
924             continue;
925         }
926         if ((menu_window_instance->menu_tile[ii]->GetPage() != current_page -1) ||
927             (menu_window_instance->menu_tile[ii]->GetSubPage() != 0)) {
928             continue;
929         }
930         menu_window_instance->menu_tile[ii]->OffsetMove(-1 *
931                               (menu_window_instance->width * frame),0);
932     }
933
934     for (int ii = 0;ii < menu_window_instance->all_tile_num;ii++) {
935         if (menu_window_instance->menu_tile[ii] == NULL) {
936             continue;
937         }
938         if ((menu_window_instance->menu_tile[ii]->GetPage() != current_page) ||
939             (menu_window_instance->menu_tile[ii]->GetSubPage() != 0)) {
940             continue;
941         }
942         menu_window_instance->menu_tile[ii]->
943             OffsetMove(menu_window_instance->width
944                        - (menu_window_instance->width * frame),0);
945     }
946     return EINA_TRUE;
947 }
948
949 /*--------------------------------------------------------------------------*/
950 /**
951  * @brief   CicoHSMenuWindow::MoveToBackAnimation
952  *          animation parts (move to back)
953  *
954  * @param[in]   data
955  * @param[in]   pos
956  * @return      EINA_TRUE
957  */
958 /*--------------------------------------------------------------------------*/
959 Eina_Bool
960 CicoHSMenuWindow::MoveToBackAnimation(void *data,double pos)
961 {
962     int current_page;
963     double frame = ecore_animator_pos_map(pos, ECORE_POS_MAP_LINEAR, 0.5, 1);
964     current_page = reinterpret_cast<int>(data);
965
966     for (int ii = 0;ii < menu_window_instance->all_tile_num;ii++) {
967         if (menu_window_instance->menu_tile[ii] == NULL) {
968             continue;
969         }
970         if ((menu_window_instance->menu_tile[ii]->GetPage() != current_page) ||
971             (menu_window_instance->menu_tile[ii]->GetSubPage() != 0)) {
972             continue;
973         }
974         menu_window_instance->menu_tile[ii]->OffsetMove(-1 *
975                                  menu_window_instance->width +
976                                  (menu_window_instance->width * frame),0);
977     }
978     for (int ii = 0;ii < menu_window_instance->all_tile_num;ii++) {
979         if (menu_window_instance->menu_tile[ii] == NULL) {
980             continue;
981         }
982         if ((menu_window_instance->menu_tile[ii]->GetPage() != current_page + 1) ||
983             (menu_window_instance->menu_tile[ii]->GetSubPage() != 0)) {
984             continue;
985         }
986         menu_window_instance->menu_tile[ii]->
987             OffsetMove(menu_window_instance->width * frame,0);
988     }
989     return EINA_TRUE;
990 }
991
992 /*--------------------------------------------------------------------------*/
993 /**
994  * @brief   CicoHSMenuWindow::MoveToNextSubAnimation
995  *          animation parts (move to next)
996  *
997  * @param[in]   data
998  * @param[in]   pos
999  * @return      EINA_TRUE
1000  */
1001 /*--------------------------------------------------------------------------*/
1002 Eina_Bool
1003 CicoHSMenuWindow::MoveToNextSubAnimation(void *data,double pos)
1004 {
1005     CicoCurrentPage *current_info;
1006     double frame = ecore_animator_pos_map(pos, ECORE_POS_MAP_LINEAR, 0.5, 1);
1007     current_info = (CicoCurrentPage *)(data);
1008
1009     for (int ii = 0;ii < menu_window_instance->all_tile_num;ii++) {
1010         if (menu_window_instance->menu_tile[ii] == NULL) {
1011             continue;
1012         }
1013         if (menu_window_instance->menu_tile[ii]->GetSubPage()
1014             != current_info->subcurrent_page -1) {
1015             continue;
1016         }
1017         if (menu_window_instance->menu_tile[ii]->GetPage() != current_info->current_page) {
1018             continue;
1019         }
1020         menu_window_instance->menu_tile[ii]->
1021             OffsetMove(0, -1 * (menu_window_instance->height * frame));
1022     }
1023
1024     for (int ii = 0;ii < menu_window_instance->all_tile_num;ii++) {
1025         if (menu_window_instance->menu_tile[ii] == NULL) {
1026             continue;
1027         }
1028         if (menu_window_instance->menu_tile[ii]->GetSubPage()
1029             != current_info->subcurrent_page) {
1030             continue;
1031         }
1032
1033         if (menu_window_instance->menu_tile[ii]->GetPage() != current_info->current_page) {
1034             continue;
1035         }
1036         menu_window_instance->menu_tile[ii]->OffsetMove(0, menu_window_instance->height -
1037                                    (menu_window_instance->height * frame));
1038     }
1039     return EINA_TRUE;
1040 }
1041
1042 /*--------------------------------------------------------------------------*/
1043 /**
1044  * @brief   CicoHSMenuWindow::MoveToBackAnimation
1045  *          animation parts (move to back)
1046  *
1047  * @param[in]   data
1048  * @param[in]   pos
1049  * @return      EINA_TRUE
1050  */
1051 /*--------------------------------------------------------------------------*/
1052 Eina_Bool
1053 CicoHSMenuWindow::MoveToBackSubAnimation(void *data,double pos)
1054 {
1055
1056     CicoCurrentPage *current_info;
1057     double frame = ecore_animator_pos_map(pos, ECORE_POS_MAP_LINEAR, 0.5, 1);
1058     current_info = (CicoCurrentPage *)(data);
1059
1060     for (int ii = 0;ii < menu_window_instance->all_tile_num;ii++) {
1061         if (menu_window_instance->menu_tile[ii] == NULL) {
1062             continue;
1063         }
1064         if (menu_window_instance->menu_tile[ii]->GetSubPage()
1065             != current_info->subcurrent_page) {
1066             continue;
1067         }
1068         if (menu_window_instance->menu_tile[ii]->GetPage() != current_info->current_page) {
1069             continue;
1070         }
1071         menu_window_instance->menu_tile[ii]->
1072             OffsetMove(0, -1 * menu_window_instance->height +
1073                        (menu_window_instance->height * frame));
1074     }
1075     for (int ii = 0;ii < menu_window_instance->all_tile_num;ii++) {
1076         if (menu_window_instance->menu_tile[ii] == NULL) {
1077             continue;
1078         }
1079         if (menu_window_instance->menu_tile[ii]->GetSubPage()
1080             != current_info->subcurrent_page + 1) {
1081             continue;
1082         }
1083         if (menu_window_instance->menu_tile[ii]->GetPage() != current_info->current_page) {
1084             continue;
1085         }
1086         menu_window_instance->menu_tile[ii]->
1087             OffsetMove(0, menu_window_instance->height * frame);
1088     }
1089     return EINA_TRUE;
1090 }
1091
1092 /*--------------------------------------------------------------------------*/
1093 /**
1094  * @brief   CicoHSMenuWindow::GoNextMenu
1095  *          menu change to next
1096  *
1097  * @param[in]   none
1098  * @return      none
1099  */
1100 /*--------------------------------------------------------------------------*/
1101 void
1102 CicoHSMenuWindow::GoNextMenu(void)
1103 {
1104     char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
1105
1106     if ((current_page >= all_page_num -1) || (subcurrent_page > 0)) {
1107         return;
1108     }
1109
1110     /*page pointer*/
1111     snprintf(img_path, sizeof(img_path), "%s%s",
1112              img_dir_path, ICO_HS_IMAGE_FILE_MENU_PAGEPOINTER_N);
1113     evas_object_image_file_set(page_pointer[current_page], img_path, NULL);
1114
1115     /* increment*/
1116     ++current_page;
1117
1118     /* display cursor */
1119     DspCtrlPageCursor();
1120
1121     /*page pointer*/
1122     snprintf(img_path, sizeof(img_path), "%s%s",
1123              img_dir_path, ICO_HS_IMAGE_FILE_MENU_PAGEPOINTER_P);
1124     evas_object_image_file_set(page_pointer[current_page], img_path, NULL);
1125
1126     /*tile*/
1127     ecore_animator_frametime_set(1.0f / 30);
1128     ecore_animator_timeline_add(0.4, MoveToNextAnimation,
1129                                 reinterpret_cast<void*>(current_page));
1130 }
1131
1132 /*--------------------------------------------------------------------------*/
1133 /**
1134  * @brief   CicoHSMenuWindow::GoNextMenu
1135  *          menu change to back
1136  *
1137  * @param[in]   none
1138  * @return      none
1139  */
1140 /*--------------------------------------------------------------------------*/
1141 void
1142 CicoHSMenuWindow::GoBackMenu(void)
1143 {
1144     char img_path[ICO_HS_MAX_PATH_BUFF_LEN];
1145
1146     if((current_page <= 0) || (subcurrent_page > 0)){
1147         return;
1148     }
1149
1150     /*page pointer*/
1151     snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,ICO_HS_IMAGE_FILE_MENU_PAGEPOINTER_N);
1152     evas_object_image_file_set(page_pointer[current_page], img_path, NULL);
1153
1154     /*decrement*/
1155     --current_page;
1156
1157     /* display cursor */
1158     DspCtrlPageCursor();
1159
1160     /*page pointer*/
1161     snprintf(img_path,sizeof(img_path),"%s%s",img_dir_path,ICO_HS_IMAGE_FILE_MENU_PAGEPOINTER_P);
1162     evas_object_image_file_set(page_pointer[current_page], img_path, NULL);
1163
1164     /*tile*/
1165     ecore_animator_frametime_set(1.0f / 30);
1166     ecore_animator_timeline_add(0.4, MoveToBackAnimation,
1167                                 reinterpret_cast<void*>(current_page));
1168
1169 }
1170
1171 /*--------------------------------------------------------------------------*/
1172 /**
1173  * @brief   CicoHSMenuWindow::DownNextMenu
1174  *          menu change to next
1175  *
1176  * @param[in]   none
1177  * @return      none
1178  */
1179 /*--------------------------------------------------------------------------*/
1180 void
1181 CicoHSMenuWindow::DownNextMenu(void)
1182 {
1183     for (int i = 0; i < all_category_num; i++) {
1184         if (current_page == category_info[i].page) {
1185             if (subcurrent_page >= category_info[i].subpage_max){
1186                 return;
1187             }
1188         }
1189     }
1190
1191     /* increment*/
1192     ++subcurrent_page;
1193
1194     /* display cursor */
1195     DspCtrlPageCursor();
1196
1197     /* current page set */
1198     current_info.current_page = current_page;
1199     current_info.subcurrent_page = subcurrent_page;
1200
1201     /*tile*/
1202     ecore_animator_frametime_set(1.0f / 30);
1203     ecore_animator_timeline_add(0.4, MoveToNextSubAnimation,
1204                                 (void*)(&current_info));
1205 }
1206
1207 /*--------------------------------------------------------------------------*/
1208 /**
1209  * @brief   CicoHSMenuWindow::UpBackMenu
1210  *          menu change to back
1211  *
1212  * @param[in]   none
1213  * @return      none
1214  */
1215 /*--------------------------------------------------------------------------*/
1216 void
1217 CicoHSMenuWindow::UpBackMenu(void)
1218 {
1219     if(subcurrent_page <= 0){
1220         return;
1221     }
1222
1223     /*decrement*/
1224     --subcurrent_page;
1225
1226     /* display cursor */
1227     DspCtrlPageCursor();
1228
1229     /* current page set */
1230     current_info.current_page = current_page;
1231     current_info.subcurrent_page = subcurrent_page;
1232
1233     /*tile*/
1234     ecore_animator_frametime_set(1.0f / 30);
1235     ecore_animator_timeline_add(0.4, MoveToBackSubAnimation,
1236                                 (void*)(&current_info));
1237 }
1238
1239 /*--------------------------------------------------------------------------*/
1240 /**
1241  * @brief   CicoHSMenuWindow::DspCtrlPageCursor
1242  *          display control page cursor
1243  *
1244  * @param[in]   none
1245  * @return      none
1246  */
1247 /*--------------------------------------------------------------------------*/
1248 void
1249 CicoHSMenuWindow::DspCtrlPageCursor(void)
1250 {
1251     int subpage_max = 0;
1252     for (int i = 0; i < all_category_num ; i++) {
1253         if (current_page == category_info[i].page) {
1254             subpage_max = category_info[i].subpage_max;
1255             break;
1256         }
1257     }
1258
1259     if (subcurrent_page > 0) {
1260         evas_object_show(page_up_cursor);
1261     }
1262     else {
1263         evas_object_hide(page_up_cursor);
1264     }
1265
1266     if (subcurrent_page < subpage_max) {
1267         evas_object_show(page_down_cursor);
1268     }
1269     else {
1270         evas_object_hide(page_down_cursor);
1271     }
1272 }
1273
1274 /*--------------------------------------------------------------------------*/
1275 /**
1276  * @brief   CicoHSMenuWindow::SetCategoryInfo
1277  *          set category info
1278  *
1279  * @param[in]         id         menu category id
1280  * @return            none
1281  */
1282 /*--------------------------------------------------------------------------*/
1283 void
1284 CicoHSMenuWindow::SetCategoryInfo(int id)
1285 {
1286     for (int i = 0; i < all_category_num ; i++) {
1287         if (category_info[i].id == id) {
1288             /* sub page max */
1289             category_info[i].subpage_max =
1290                 category_info[i].tile_num / ICO_HS_MENUTILE_NUM;
1291
1292             /* tile num */
1293             category_info[i].tile_num++;
1294         }
1295     }
1296 }
1297
1298 /*--------------------------------------------------------------------------*/
1299 /**
1300  * @brief   CicoHSMenuWindow::GetTileInfo
1301  *          get tile info
1302  *
1303  * @param[in]       id         menu category id
1304  * @param[out]      page       menu page
1305  * @param[out]      subpage    menu sub page
1306  * @param[out]      position   menu tile position
1307  * @return          none
1308  */
1309 /*--------------------------------------------------------------------------*/
1310 void
1311 CicoHSMenuWindow::GetTileInfo(int id, int *page, int *subpage, int *position)
1312 {
1313     for (int i = 0; i < all_category_num ; i++) {
1314         if (category_info[i].id == id) {
1315             if (category_info[i].tile_num == 0) {
1316                 ICO_ERR("CicoHSMenuWindow::GetTileInfo: number of tiles is 0.");
1317                 return;
1318             }
1319
1320             /* page */
1321             *page = category_info[i].page;
1322             /* sub page */
1323             *subpage = (category_info[i].tile_num -1) / ICO_HS_MENUTILE_NUM;
1324             /* pasition */
1325             *position = (category_info[i].tile_num -1) % ICO_HS_MENUTILE_NUM;
1326         }
1327     }
1328 }
1329
1330 /*--------------------------------------------------------------------------*/
1331 /**
1332  * @brief   CicoHSMenuWindow::SetMenuWindowID
1333  *          set appid and surface
1334  *
1335  * @param[in]   none
1336  * @return      none
1337  */
1338 /*--------------------------------------------------------------------------*/
1339 void
1340 CicoHSMenuWindow::SetMenuWindowID(const char *appid,int surface)
1341 {
1342     strncpy(this->appid,appid,ICO_HS_MAX_PROCESS_NAME);
1343     this->surface = surface;
1344 }
1345
1346 /*--------------------------------------------------------------------------*/
1347 /**
1348  * @brief   CicoHSMenuWindow::Show
1349  *          show menu window
1350  *
1351  * @param[in]   none
1352  * @return      none
1353  */
1354 /*--------------------------------------------------------------------------*/
1355 void
1356 CicoHSMenuWindow::Show(ico_syc_animation_t *animation)
1357 {
1358     ICO_TRA("CicoHSMenuWindow::Show Enter");
1359
1360     // if regulation == true, forbid show window.
1361     if (true == CicoHSSystemState::getInstance()->getRegulation()) {
1362         return;
1363     }
1364     m_showState = true;
1365
1366     if (true == life_cycle_controller->isAilRenew()) {
1367         ICO_DBG("CicoHSMenuWindow::Show : renew app tiles");
1368         RenewAppTiles();
1369         life_cycle_controller->ailRenewFlagOff();
1370     }
1371
1372     // Show menu tiles
1373     for (int ii = 0; ii < all_tile_num; ii++) {
1374         if (menu_tile[ii])  {
1375             menu_tile[ii]->ShowMenu(true);
1376         }
1377     }
1378
1379     ico_syc_show(appid, surface, animation);
1380
1381     ICO_TRA("CicoHSMenuWindow::Show Leave");
1382 }
1383
1384 /*--------------------------------------------------------------------------*/
1385 /**
1386  * @brief   CicoHSMenuWindow::Hide
1387  *          hide menu window
1388  *
1389  * @param[in]   none
1390  * @return      none
1391  */
1392 /*--------------------------------------------------------------------------*/
1393 void
1394 CicoHSMenuWindow::Hide(ico_syc_animation_t *animation)
1395 {
1396     ICO_TRA("CicoHSMenuWindow::Hide Enter");
1397
1398     if(terminate_mode == true){
1399         ChangeNormalMode();
1400     }
1401     m_showState = false;
1402     ico_syc_hide(appid,surface,animation);
1403
1404     // Hide menu tiles
1405     for (int ii = 0; ii < all_tile_num; ii++) {
1406         if (menu_tile[ii])  {
1407             menu_tile[ii]->ShowMenu(false);
1408         }
1409     }
1410
1411     ICO_TRA("CicoHSMenuWindow::Hide Leave");
1412 }
1413
1414 /*--------------------------------------------------------------------------*/
1415 /**
1416  * @brief   CicoHSMenuWindow::ExecuteApp
1417  *          execute application
1418  *
1419  * @param[in]   appid   application id
1420  * @return      none
1421  */
1422 /*--------------------------------------------------------------------------*/
1423 void
1424 CicoHSMenuWindow::ExecuteApp(const char *appid)
1425 {
1426     if(terminate_mode == true){
1427         ICO_DBG("CicoHSMenuWindow::ExecuteApp: exet %s but terminate_mode", appid);
1428         return;
1429     }
1430     CicoHomeScreen::ExecuteApp(appid);
1431 }
1432
1433 /*--------------------------------------------------------------------------*/
1434 /**
1435  * @brief   CicoHSMenuWindow::TerminateApp
1436  *          teminate application
1437  *
1438  * @param[in]   appid   application id
1439  * @return      none
1440  */
1441 /*--------------------------------------------------------------------------*/
1442 void
1443 CicoHSMenuWindow::TerminateApp(const char *appid)
1444 {
1445     CicoHomeScreen::TerminateApp(appid);
1446
1447     HideTerminateButton();
1448     ChangeNormalMode();
1449 }
1450
1451 /*--------------------------------------------------------------------------*/
1452 /**
1453  * @brief   CicoHSMenuWindow::ChangeTerminateMode
1454  *          change to terminate mode
1455  *
1456  * @param[in]   none
1457  * @return      none
1458  */
1459 /*--------------------------------------------------------------------------*/
1460 void
1461 CicoHSMenuWindow::ChangeTerminateMode(void)
1462 {
1463     bool check = false;
1464
1465     /*check */
1466     for (int ii = 0; ii < all_tile_num; ii++) {
1467         if(menu_tile[ii] == NULL){
1468             continue;
1469         }
1470         if(CicoHomeScreen::GetAppStatus(menu_tile[ii]->GetAppId()) == true){
1471             check = true;
1472             break;
1473         }
1474     }
1475     if(check == false){
1476         return;
1477     }
1478
1479     /*show term icon*/
1480     for (int ii = 0; ii < all_tile_num; ii++) {
1481         if(menu_tile[ii] == NULL){
1482             continue;
1483         }
1484         if(CicoHomeScreen::GetAppStatus(menu_tile[ii]->GetAppId()) == false){
1485             continue;
1486         }
1487         menu_tile[ii]->ShowTermIcon();
1488     }
1489     terminate_mode = true;
1490     ICO_DBG("CicoHSMenuWindow::ChangeTerminateMode: change to terminate mode");
1491 }
1492
1493 /*--------------------------------------------------------------------------*/
1494 /**
1495  * @brief   CicoHSMenuWindow::ChangeNormalMode
1496  *          change to terminate mode
1497  *
1498  * @param[in]   none
1499  * @return      none
1500  */
1501 /*--------------------------------------------------------------------------*/
1502 void
1503 CicoHSMenuWindow::ChangeNormalMode(void)
1504 {
1505     /*hide term icon*/
1506     for (int ii = 0; ii < all_tile_num; ii++) {
1507         if(menu_tile[ii] == NULL){
1508             continue;
1509         }
1510         menu_tile[ii]->HideTermIcon();
1511     }
1512     terminate_mode = false;
1513     ICO_DBG("CicoHSMenuWindow::ChangeNormalMode: change to normal mode");
1514 }
1515
1516 /*--------------------------------------------------------------------------*/
1517 /**
1518  * @brief   CicoHSMenuWindow::ValidMenuIcon
1519  *          tile is icon
1520  *
1521  * @param[in]   appid    application ID
1522  * @return      none
1523  */
1524 /*--------------------------------------------------------------------------*/
1525 void
1526 CicoHSMenuWindow::ValidMenuIcon(const char *appid)
1527 {
1528     ICO_DBG("CicoHSMenuWindow::ValidMenuIcon(%s)", appid ? appid : "(NULL)" );
1529     for (int ii = 0; ii < all_tile_num; ii++) {
1530         if (strncmp(menu_tile[ii]->GetAppId(), appid, ICO_HS_MAX_PROCESS_NAME) == 0) {
1531             menu_tile[ii]->ValidMenuIcon();
1532             break;
1533         }
1534     }
1535 }
1536
1537 /*--------------------------------------------------------------------------*/
1538 /**
1539  * @brief   CicoHSMenuWindow::ValidThumbnail
1540  *          tile is thumbnail
1541  *
1542  * @param[in]   appid    application ID
1543  * @param[in]   surface  surface
1544  * @return      none
1545  */
1546 /*--------------------------------------------------------------------------*/
1547 void
1548 CicoHSMenuWindow::ValidThumbnail(const char *appid, int surface)
1549 {
1550     for (int ii = 0; ii < all_tile_num; ii++) {
1551         if (strncmp(menu_tile[ii]->GetAppId(), appid, ICO_HS_MAX_PROCESS_NAME) == 0) {
1552             menu_tile[ii]->ValidThumbnail(surface);
1553             break;
1554         }
1555     }
1556 }
1557
1558 /*--------------------------------------------------------------------------*/
1559 /**
1560  * @brief   CicoHSMenuWindow::SetThumbnail
1561  *          tile is thumbnail
1562  *
1563  * @param[in]   appid    application ID
1564  * @param[in]   info     thumbnail information
1565  * @return      none
1566  */
1567 /*--------------------------------------------------------------------------*/
1568 void
1569 CicoHSMenuWindow::SetThumbnail(const char *appid, ico_syc_thumb_info_t *info)
1570 {
1571     for (int ii = 0; ii < all_tile_num; ii++) {
1572         if (strncmp(menu_tile[ii]->GetAppId(), appid, ICO_HS_MAX_PROCESS_NAME) == 0) {
1573             menu_tile[ii]->SetThumbnail(info);
1574             break;
1575         }
1576     }
1577 }
1578
1579 /*--------------------------------------------------------------------------*/
1580 /**
1581  * @brief   CicoHSMenuWindow::SetNightMode
1582  *          set night mode color theme chagne
1583  *
1584  * @param   none
1585  * @return  none
1586  */
1587 /*--------------------------------------------------------------------------*/
1588 void
1589 CicoHSMenuWindow::SetNightMode(void)
1590 {
1591     ICO_TRA("CicoHSMenuWindow::SetNightMode Enter");
1592     if (true == CicoHSSystemState::getInstance()->getNightMode()) {
1593         evas_object_color_set(rectangle,0,0,0,178);
1594     }
1595     else {
1596         evas_object_color_set(rectangle,120,120,120,178);
1597     }
1598     ICO_TRA("CicoHSMenuWindow::SetNightMode Leave");
1599 }
1600
1601 /*--------------------------------------------------------------------------*/
1602 /**
1603  * @brief   CicoHSMenuWindow::Tile_Width
1604  *          menu tile width
1605  *
1606  * @param   none
1607  * @return  tile width
1608  */
1609 /*--------------------------------------------------------------------------*/
1610 int
1611 CicoHSMenuWindow::Tile_Width(void)
1612 {
1613     return CicoHSMenuWindow::menu_tile_width;
1614 }
1615
1616 /*--------------------------------------------------------------------------*/
1617 /**
1618  * @brief   CicoHSMenuWindow::Tile_Height
1619  *          menu tile height
1620  *
1621  * @param   none
1622  * @return  tile height
1623  */
1624 /*--------------------------------------------------------------------------*/
1625 int
1626 CicoHSMenuWindow::Tile_Height(void)
1627 {
1628     return CicoHSMenuWindow::menu_tile_height;
1629 }
1630 // vim: set expandtab ts=4 sw=4: