bug fix: TC-1152
[profile/ivi/ico-uxf-homescreen.git] / src / homescreen / CicoHSMenuTile.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   tile in menu
11  *
12  * @date    Aug-08-2013
13  */
14 #include "CicoHSMenuTile.h"
15 #include "CicoHSMenuTouch.h"
16 #include <stdio.h>
17 #include <unistd.h>
18 #include <sys/mman.h>
19 #include <sys/stat.h>
20 #include <fcntl.h>
21 #include <tzplatform_config.h>
22
23 /*============================================================================*/
24 /* functions                                                                  */
25 /*============================================================================*/
26 /*--------------------------------------------------------------------------*/
27 /**
28  * @brief   CicoHSMenuTile::CicoHSMenuTile
29  *          Constractor
30  *
31  * @param[in]   appid
32  * @param[in]   icon_image_path
33  * @param[in]   page
34  * @param[in]   position
35  * @param[in]   width
36  * @param[in]   height
37  * @return      none
38  */
39 /*--------------------------------------------------------------------------*/
40 CicoHSMenuTile::CicoHSMenuTile(const char *appid,
41                                const char *icon_image_path,
42                                int page, int subpage,
43                                int position, int width, int height)
44 {
45     ICO_TRA("CicoHSMenuTile::CicoHSMenuTile Enter");
46
47     if (appid != NULL) {
48         strncpy(this->appid, appid, ICO_HS_MAX_PROCESS_NAME);
49     }
50     if ((icon_image_path != NULL) && (strlen(icon_image_path) != 0)) {
51         strncpy(this->icon_image_path,icon_image_path,ICO_HS_MAX_PATH_BUFF_LEN);
52     }
53     else {
54         strncpy(this->icon_image_path,
55                 tzplatform_mkpath(TZ_SYS_RO_APP,
56                                   ICO_HS_MENUTILE_DEFAULT_ICON_PATH),
57                 ICO_HS_MAX_PATH_BUFF_LEN);
58     }
59     ICO_DBG("CicoHSMenuTile::CicoHSMenuTile:image_path %s:%s",
60             appid, this->icon_image_path);
61     thumb.surface = 0;
62     thumb.fbcount = 0;
63     thumb.pixel_data = NULL;
64     thumb.thumb_timer = NULL;
65     thumb.orgsurface = 0;
66     this->page = page;
67     this->subpage = subpage;
68     this->position = position;
69     this->width = width;
70     this->height = height;
71     pos_x = GetPositionX();
72     pos_y = GetPositionY();
73
74     (void) mkdir(ICO_HS_THUMB_ICODIR, 0755);
75     (void) mkdir(ICO_HS_THUMB_ICODIR ICO_HS_THUMB_FILEDIR, 0755);
76
77     ICO_TRA("CicoHSMenuTile::CicoHSMenuTile Leave");
78 }
79
80 /*--------------------------------------------------------------------------*/
81 /**
82  * @brief   CicoHSMenuTile::CicoHSMenuTile
83  *          Destractor
84  *
85  * @param[in]   none
86  * @return      none
87  */
88 /*--------------------------------------------------------------------------*/
89 CicoHSMenuTile::~CicoHSMenuTile(void)
90 {
91     if (thumb.thumb_timer)  {
92         ecore_timer_del(thumb.thumb_timer);
93         thumb.thumb_timer = NULL;
94     }
95 }
96
97 /*--------------------------------------------------------------------------*/
98 /**
99  * @brief   CicoHSMenuTile::CreateObject
100  *          create tile object
101  *
102  * @param[in]   evas
103  * @return      none
104  */
105 /*--------------------------------------------------------------------------*/
106 void
107 CicoHSMenuTile::CreateObject(Evas *evas)
108 {
109     ICO_DBG("CicoHSMenuTile::CreateObject Enter(appid=<%s> x/y=%d/%d)",
110             appid, pos_x, pos_y);
111
112     /*initial vaule*/
113     menu_evas = evas;
114     menu_show = false;
115     app_running = false;
116     thumb_tile = NULL;
117     small_icon = NULL;
118     thumb_reduce_x = ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX;
119     thumb_reduce_y = ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX;
120     if (thumb.thumb_timer)  {
121         ecore_timer_del(thumb.thumb_timer);
122         thumb.thumb_timer = NULL;
123     }
124
125     /*tile*/
126     tile = evas_object_image_filled_add(evas);
127     evas_object_image_file_set(tile, icon_image_path, NULL);
128     evas_object_move(tile, pos_x, pos_y);
129     evas_object_resize(tile, width, height);
130     evas_object_event_callback_add(tile, EVAS_CALLBACK_MOUSE_DOWN,
131                                    CicoHSMenuTouch::TouchDownMenu, appid);
132     evas_object_event_callback_add(tile, EVAS_CALLBACK_MOUSE_UP,
133                                    CicoHSMenuTouch::TouchUpMenu, appid);
134     icon = tile;
135     evas_object_show(icon);
136
137     /*term Icon*/
138     term_icon = evas_object_image_filled_add(evas);
139     evas_object_image_file_set(term_icon,
140                                tzplatform_mkpath(TZ_SYS_RO_APP,
141                                                  ICO_HS_MENUTILE_TERM_ICON_PATH), NULL);
142     evas_object_move(term_icon, pos_x + width - ICO_HS_MENUTILE_TERM_ICON_WIDTH, pos_y);
143     evas_object_resize(term_icon, ICO_HS_MENUTILE_TERM_ICON_WIDTH,
144                        ICO_HS_MENUTILE_TERM_ICON_HEIGHT);
145     evas_object_event_callback_add(term_icon, EVAS_CALLBACK_MOUSE_DOWN,
146                                    CicoHSMenuTouch::TouchDownTerm, appid);
147     evas_object_event_callback_add(term_icon, EVAS_CALLBACK_MOUSE_UP,
148                                    CicoHSMenuTouch::TouchUpTerm, appid);
149     ICO_DBG("CicoHSMenuTile::CreateObject Leave(%s Tile=(%d,%d) w/h=%d/%d",
150             appid, pos_x, pos_y, width, height);
151 }
152
153 /*--------------------------------------------------------------------------*/
154 /**
155  * @brief   CicoHSMenuTile::ShowTermIcon
156  *          showing term icon
157  *
158  * @param[in]   none
159  * @return      none
160  */
161 /*--------------------------------------------------------------------------*/
162 void
163 CicoHSMenuTile::ShowTermIcon()
164 {
165     evas_object_raise(term_icon);
166     evas_object_show(term_icon);
167 }
168
169 /*--------------------------------------------------------------------------*/
170 /**
171  * @brief   CicoHSMenuTile::HideTermIcon
172  *          hiding term icon
173  *
174  * @param[in]   none
175  * @return      none
176  */
177 /*--------------------------------------------------------------------------*/
178 void
179 CicoHSMenuTile::HideTermIcon(void)
180 {
181     evas_object_hide(term_icon);
182 }
183
184 /*--------------------------------------------------------------------------*/
185 /**
186  * @brief   CicoHSMenuTile::FreeObject
187  *          free tile object
188  *
189  * @param[in]   none
190  * @return      none
191  */
192 /*--------------------------------------------------------------------------*/
193 void
194 CicoHSMenuTile::FreeObject(void)
195 {
196     char    sWork[PATH_MAX];
197
198     ICO_DBG("CicoHSMenuTile::FreeObject(appid=%p<%s>)", this->appid, appid);
199
200     if (thumb.surface)  {
201         sprintf(sWork, "%s/%08x.bpm", ICO_HS_THUMB_ICODIR ICO_HS_THUMB_FILEDIR,
202                 thumb.surface);
203         (void) unlink(sWork);
204         ico_syc_unmap_thumb(thumb.surface);
205         thumb.surface = 0;
206     }
207     if (thumb.thumb_timer)  {
208         ecore_timer_del(thumb.thumb_timer);
209         thumb.thumb_timer = NULL;
210     }
211     if (tile != NULL){
212         evas_object_del(tile);
213         tile = NULL;
214     }
215     if (small_icon != NULL){
216         evas_object_del(small_icon);
217         small_icon = NULL;
218     }
219     if (thumb_tile != NULL)  {
220         evas_object_del(thumb_tile);
221         thumb_tile = NULL;
222     }
223     if (term_icon != NULL)  {
224         evas_object_del(term_icon);
225         term_icon = NULL;
226     }
227 }
228
229 /*--------------------------------------------------------------------------*/
230 /**
231  * @brief   CicoHSMenuTile::Resize
232  *          resize tile(currently unused)
233  *
234  * @param[in]   width         width
235  * @param[in]   height        height
236  * @return      none
237  */
238 /*--------------------------------------------------------------------------*/
239 void
240 CicoHSMenuTile::Resize(int width, int height)
241 {
242     ICO_DBG("CicoHSMenuTile::Resize (%d,%d)-(%d,%d) Unused",
243             this->width, this->height, width, height);
244 }
245
246 /*--------------------------------------------------------------------------*/
247 /**
248  * @brief   CicoHSMenuTile::MovePosition
249  *          move tile base position
250  *
251  * @param[in]   page        page
252  * @param[in]   position    position of tile
253  * @return      none
254  */
255 /*--------------------------------------------------------------------------*/
256 void
257 CicoHSMenuTile::MovePosition(int page, int position)
258 {
259     this->page = page;
260     this->position= position;
261     pos_x = GetPositionX();
262     pos_y = GetPositionY();
263
264     ICO_DBG("CicoHSMenuTile::MovePosition(appid=%p<%s> tile=(%d,%d))",
265             this->appid, appid, pos_x, pos_y);
266
267     evas_object_move(tile, pos_x, pos_y);
268     if (thumb_tile) {
269         evas_object_move(thumb_tile, pos_x + thumb_reduce_x, pos_y + thumb_reduce_y);
270     }
271     if (small_icon) {
272         evas_object_move(small_icon,
273                          pos_x + thumb_reduce_x - ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX2,
274                          pos_y + height - thumb_reduce_y - height
275                              / ICO_HS_MENUTILE_THUMBNAIL_REDUCTION
276                              + ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX2);
277     }
278     evas_object_move(term_icon, pos_x + width - ICO_HS_MENUTILE_TERM_ICON_WIDTH, pos_y);
279 }
280
281 /*--------------------------------------------------------------------------*/
282 /**
283  * @brief   CicoHSMenuTile::OffsetMove
284  *          move from base position
285  *
286  * @param[in]   offset_x    offset_x from base position
287  * @param[in]   offset_y    offset_y from base position
288  * @return      none
289  */
290 /*--------------------------------------------------------------------------*/
291 void
292 CicoHSMenuTile::OffsetMove(int offset_x, int offset_y)
293 {
294     pos_x = GetPositionX() + offset_x;
295     pos_y = GetPositionY() + offset_y;
296
297     ICO_DBG("CicoHSMenuTile::OffsetMove(appid=%p<%s> offset=%d,%d tile=(%d,%d) obj=%p %p %p)",
298             this->appid, appid, offset_x, offset_y, pos_x, pos_y,
299             this->icon, this->tile, this->thumb_tile);
300
301     evas_object_move(tile, pos_x, pos_y);
302     if (thumb_tile) {
303         evas_object_move(thumb_tile, pos_x + thumb_reduce_x, pos_y + thumb_reduce_y);
304     }
305     if (small_icon) {
306         evas_object_move(small_icon,
307                          pos_x + thumb_reduce_x - ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX2,
308                          pos_y + height - thumb_reduce_y - height
309                              / ICO_HS_MENUTILE_THUMBNAIL_REDUCTION
310                              + ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX2);
311     }
312     evas_object_move(term_icon, pos_x + width - ICO_HS_MENUTILE_TERM_ICON_WIDTH, pos_y);
313 }
314
315 /*--------------------------------------------------------------------------*/
316 /**
317  * @brief   CicoHSMenuTile::GetImagePath
318  *          get icon image path
319  *
320  * @param[in]   none
321  * @return      icon image path
322  */
323 /*--------------------------------------------------------------------------*/
324 const char*
325 CicoHSMenuTile::GetImagePath(void)
326 {
327     return icon_image_path;
328 }
329
330 /*--------------------------------------------------------------------------*/
331 /**
332  * @brief   CicoHSMenuTile::GetAppId
333  *          get application id
334  *
335  * @param[in]   none
336  * @return      application id
337  */
338 /*--------------------------------------------------------------------------*/
339 const char*
340 CicoHSMenuTile::GetAppId(void)
341 {
342     return appid;
343 }
344
345 /*--------------------------------------------------------------------------*/
346 /**
347  * @brief   CicoHSMenuTile::GetWidth
348  *          get width
349  *
350  * @param[in]   none
351  * @return      width
352  */
353 /*--------------------------------------------------------------------------*/
354 int
355 CicoHSMenuTile::GetWidth(void)
356 {
357     return width;
358 }
359
360 /*--------------------------------------------------------------------------*/
361 /**
362  * @brief   CicoHSMenuTile::GetHeight
363  *          get height
364  *
365  * @param[in]   none
366  * @return      height
367  */
368 /*--------------------------------------------------------------------------*/
369 int
370 CicoHSMenuTile::GetHeight(void)
371 {
372     return height;
373 }
374
375 /*--------------------------------------------------------------------------*/
376 /**
377  * @brief   CicoHSMenuTile::GetPosition
378  *          get position
379  *
380  * @param[in]   none
381  * @return      position
382  */
383 /*--------------------------------------------------------------------------*/
384 int
385 CicoHSMenuTile::GetPosition(void)
386 {
387     return position;
388 }
389
390 /*--------------------------------------------------------------------------*/
391 /**
392  * @brief   CicoHSMenuTile::GetPage
393  *          get page
394  *
395  * @param[in]   none
396  * @return      page
397  */
398 /*--------------------------------------------------------------------------*/
399 int
400 CicoHSMenuTile::GetPage(void)
401 {
402     return page;
403 }
404
405 /*--------------------------------------------------------------------------*/
406 /**
407  * @brief   CicoHSMenuTile::GetSubPage
408  *          get sub page
409  *
410  * @param[in]   none
411  * @return      page
412  */
413 /*--------------------------------------------------------------------------*/
414 int
415 CicoHSMenuTile::GetSubPage(void)
416 {
417     return subpage;
418 }
419
420 /*--------------------------------------------------------------------------*/
421 /**
422  * @brief   CicoHSMenuTile::GetPositionX
423  *          get position x
424  *
425  * @param[in]   none
426  * @return      position x
427  */
428 /*--------------------------------------------------------------------------*/
429 int
430 CicoHSMenuTile::GetPositionX(void)
431 {
432     int ret = 0;
433
434     if ((position == ICO_HS_MENUTILE_POSITION_0) ||
435         (position == ICO_HS_MENUTILE_POSITION_3) ||
436         (position == ICO_HS_MENUTILE_POSITION_6) ||
437         (position == ICO_HS_MENUTILE_POSITION_9))   {
438         ret = ICO_HS_MENUTILE_START_POS_X;
439     }
440     else if ((position == ICO_HS_MENUTILE_POSITION_1) ||
441              (position == ICO_HS_MENUTILE_POSITION_4) ||
442              (position == ICO_HS_MENUTILE_POSITION_7) ||
443              (position == ICO_HS_MENUTILE_POSITION_10)) {
444         ret = ICO_HS_MENUTILE_START_POS_X +
445               (CicoHSMenuWindow::Tile_Width() + ICO_HS_MENUTILE_SPACE_TILE_AND_TILE);
446     }
447     else if ((position == ICO_HS_MENUTILE_POSITION_2) ||
448              (position == ICO_HS_MENUTILE_POSITION_5) ||
449              (position == ICO_HS_MENUTILE_POSITION_8) ||
450              (position == ICO_HS_MENUTILE_POSITION_11)) {
451         ret = ICO_HS_MENUTILE_START_POS_X +
452               ((CicoHSMenuWindow::Tile_Width() + ICO_HS_MENUTILE_SPACE_TILE_AND_TILE) * 2);
453     }
454     return ret;
455 }
456
457 /*--------------------------------------------------------------------------*/
458 /**
459  * @brief   CicoHSMenuTile::GetPositionY
460  *          get position y
461  *
462  * @param[in]   none
463  * @return      position y
464  */
465 /*--------------------------------------------------------------------------*/
466 int
467 CicoHSMenuTile::GetPositionY(void)
468 {
469     int ret = 0;
470
471     if ((position == ICO_HS_MENUTILE_POSITION_0) ||
472         (position == ICO_HS_MENUTILE_POSITION_1) ||
473         (position == ICO_HS_MENUTILE_POSITION_2))   {
474         ret = ICO_HS_MENUTILE_START_POS_Y;
475     }
476     else if ((position == ICO_HS_MENUTILE_POSITION_3) ||
477              (position == ICO_HS_MENUTILE_POSITION_4) ||
478              (position == ICO_HS_MENUTILE_POSITION_5))  {
479         ret = ICO_HS_MENUTILE_START_POS_Y +
480               (CicoHSMenuWindow::Tile_Height() + ICO_HS_MENUTILE_SPACE_TILE_AND_TILE);
481     }
482     else if ((position == ICO_HS_MENUTILE_POSITION_6) ||
483              (position == ICO_HS_MENUTILE_POSITION_7) ||
484              (position == ICO_HS_MENUTILE_POSITION_8))  {
485         ret = ICO_HS_MENUTILE_START_POS_Y +
486               ((CicoHSMenuWindow::Tile_Height() + ICO_HS_MENUTILE_SPACE_TILE_AND_TILE) * 2);
487     }
488     else if ((position == ICO_HS_MENUTILE_POSITION_9) ||
489              (position == ICO_HS_MENUTILE_POSITION_10) ||
490              (position == ICO_HS_MENUTILE_POSITION_11)) {
491         ret = ICO_HS_MENUTILE_START_POS_Y +
492               ((CicoHSMenuWindow::Tile_Height() + ICO_HS_MENUTILE_SPACE_TILE_AND_TILE) * 3);
493     }
494     return ret;
495 }
496
497 /*--------------------------------------------------------------------------*/
498 /**
499  * @brief   CicoHSMenuTile::ValidMenuIcon
500  *          tile is icon(app terminated)
501  *
502  * @param[in]   none
503  * @return      none
504  */
505 /*--------------------------------------------------------------------------*/
506 void
507 CicoHSMenuTile::ValidMenuIcon(void)
508 {
509     if (app_running)    {
510         ICO_DBG("CicoHSMenuTile::ValidMenuIcon: %s show icon", appid);
511         app_running = false;
512         free(thumb.pixel_data);
513         thumb.pixel_data = NULL;
514         if (icon == thumb_tile) {
515             icon = tile;
516             if (thumb_tile) {
517                 evas_object_hide(thumb_tile);
518             }
519             if (tile)   {
520                 evas_object_show(tile);
521             }
522         }
523         if (thumb.thumb_timer)  {
524             ecore_timer_del(thumb.thumb_timer);
525             thumb.thumb_timer = NULL;
526         }
527         if (small_icon) {
528             evas_object_hide(small_icon);
529         }
530     }
531 }
532
533 /*--------------------------------------------------------------------------*/
534 /**
535  * @brief   CicoHSMenuTile::ValidThumbnail
536  *          tile is thumbnail(app started)
537  *
538  * @param[in]   surface   surface
539  * @return      none
540  */
541 /*--------------------------------------------------------------------------*/
542 void
543 CicoHSMenuTile::ValidThumbnail(int surface)
544 {
545     char    sWork[PATH_MAX];
546
547     ICO_DBG("CicoHSMenuTile::ValidThumbnail(appid=%p<%s>) run=%d surf=%08x",
548             this->appid, appid, app_running, surface);
549
550     thumb.orgsurface = surface;
551
552     if ((! app_running) || (surface == 0))  {
553         if (thumb.surface != 0) {
554             sprintf(sWork, ICO_HS_THUMB_ICODIR ICO_HS_THUMB_FILEDIR "/%08x."
555                     ICO_HS_THUMB_FILEEXT, thumb.surface);
556             (void) unlink(sWork);
557             ico_syc_unmap_thumb(thumb.surface);
558             if (surface == 0)   {
559                 free(thumb.pixel_data);
560                 thumb.pixel_data = NULL;
561             }
562         }
563         thumb.surface = surface;
564         if (surface)    {
565             app_running = true;
566             sprintf(sWork, ICO_HS_THUMB_ICODIR ICO_HS_THUMB_FILEDIR "/%08x."
567                     ICO_HS_THUMB_FILEEXT, thumb.surface);
568             (void) unlink(sWork);
569             ico_syc_map_thumb(thumb.surface,
570                               menu_show ? ICO_HS_MENUTILE_THUMBNAIL_FPS_SHOW :
571                                           ICO_HS_MENUTILE_THUMBNAIL_FPS_HIDE, sWork);
572             if (! small_icon)   {
573                 small_icon = evas_object_image_filled_add(menu_evas);
574                 evas_object_image_file_set(small_icon, icon_image_path, NULL);
575                 evas_object_move(small_icon,
576                                  pos_x + thumb_reduce_x
577                                      - ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX2,
578                                  pos_y + height - thumb_reduce_y - height
579                                      / ICO_HS_MENUTILE_THUMBNAIL_REDUCTION
580                                      + ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX2);
581                 evas_object_resize(small_icon, width / ICO_HS_MENUTILE_THUMBNAIL_REDUCTION,
582                                    height / ICO_HS_MENUTILE_THUMBNAIL_REDUCTION);
583                 evas_object_event_callback_add(small_icon, EVAS_CALLBACK_MOUSE_DOWN,
584                                                CicoHSMenuTouch::TouchDownMenu, appid);
585                 evas_object_event_callback_add(small_icon, EVAS_CALLBACK_MOUSE_UP,
586                                                CicoHSMenuTouch::TouchUpMenu, appid);
587                 evas_object_raise(small_icon);
588                 evas_object_raise(term_icon);
589             }
590             evas_object_show(small_icon);
591             ICO_DBG("CicoHSMenuTile::ValidThumbnail: %s(%08x) show small icon",
592                     appid, surface);
593         }
594         else    {
595             app_running = false;
596             if (icon == thumb_tile) {
597                 ICO_DBG("CicoHSMenuTile::ValidThumbnail: %s change thumb->icon", appid);
598                 icon = tile;
599                 if (thumb_tile) {
600                     evas_object_hide(thumb_tile);
601                 }
602                 evas_object_show(tile);
603             }
604             if (small_icon) {
605                 evas_object_hide(small_icon);
606             }
607             if (thumb.thumb_timer)  {
608                 ecore_timer_del(thumb.thumb_timer);
609                 thumb.thumb_timer = NULL;
610             }
611             ICO_DBG("CicoHSMenuTile::ValidThumbnail: %s(%08x) hide small icon",
612                     appid, surface);
613         }
614     }
615 }
616
617 /*--------------------------------------------------------------------------*/
618 /**
619  * @brief   CicoHSMenuTile::RetryThumbnail
620  *          check and retry thumbnail
621  *
622  * @param       none
623  * @return      none
624  */
625 /*--------------------------------------------------------------------------*/
626 void
627 CicoHSMenuTile::RetryThumbnail(void)
628 {
629     thumb.thumb_timer = NULL;
630
631     ICO_DBG("CicoHSMenuTile::RetryThumbnaili: surf=%08x app=%s", thumb.orgsurface, appid);
632
633     if ((icon == tile) && (thumb.orgsurface != 0))  {
634         app_running = false;
635         ValidThumbnail(thumb.orgsurface);
636     }
637 }
638
639 /*--------------------------------------------------------------------------*/
640 /**
641  * @brief   CicoHSMenuTile::SetThumbnail
642  *          tile is thumbnail
643  *
644  * @param[in]   info      thumbnail information, if NULL reset thumbnail
645  * @return      none
646  */
647 /*--------------------------------------------------------------------------*/
648 void
649 CicoHSMenuTile::SetThumbnail(ico_syc_thumb_info_t *info)
650 {
651     Evas_Object         *old_icon = icon;
652     int                 svx, svy;
653     int                 unmap;
654     int                 fd;
655     char                sWork[PATH_MAX];
656 #if     0           /* for BMP format   */
657 #pragma pack(push, 1)
658         struct _bmphead {
659             short   magic;
660             uint32_t fullsize;
661             short   res1;
662             short   res2;
663             int     offset;
664             int     headsize;
665             int     width;
666             int     height;
667             short   planes;
668             short   bitperpixel;
669             int     compress;
670             int     datasize;
671             int     xp;
672             int     yp;
673             int     colors;
674             int     colors2;
675         }   bmphead;
676 #pragma pack(pop)
677 #endif
678
679     ICO_DBG("CicoHSMenuTile::SetThumbnail(appid=%p<%s>) info=%p surf=%08x",
680             this->appid, appid, info, info ? info->surface : 0);
681
682     if ((info == NULL) || (info->surface == 0)) {
683         unmap = 1;
684     }
685     else    {
686         unmap = 0;
687         if (thumb.surface != info->surface) {
688             if (thumb.surface != 0) {
689                 ICO_DBG("CicoHSMenuTile::SetThumbnail: surface change(%08x->%08x)",
690                         thumb.surface, info->surface);
691                 ico_syc_unmap_thumb(thumb.surface);
692                 sprintf(sWork, ICO_HS_THUMB_ICODIR ICO_HS_THUMB_FILEDIR "/%08x."
693                         ICO_HS_THUMB_FILEEXT, thumb.surface);
694                 (void) unlink(sWork);
695             }
696             thumb.surface = info->surface;
697             sprintf(sWork, ICO_HS_THUMB_ICODIR ICO_HS_THUMB_FILEDIR "/%08x."
698                     ICO_HS_THUMB_FILEEXT, thumb.surface);
699             ico_syc_map_thumb(thumb.surface,
700                               menu_show ? ICO_HS_MENUTILE_THUMBNAIL_FPS_SHOW :
701                                           ICO_HS_MENUTILE_THUMBNAIL_FPS_HIDE, sWork);
702         }
703         else    {
704             sprintf(sWork, ICO_HS_THUMB_ICODIR ICO_HS_THUMB_FILEDIR "/%08x."
705                     ICO_HS_THUMB_FILEEXT, thumb.surface);
706         }
707         thumb.type = info->type;
708         thumb.width = info->width;
709         thumb.height = info->height;
710         thumb.stride = info->stride;
711         thumb.format = info->format;
712 #if 0       /* too many log */
713         ICO_DBG("CicoHSMenuTile::SetThumbnail: make thumbnail %s(%08x) "
714                 "type=%d w/h/s=%d/%d/%d tile w/h=%d/%d",
715                 appid, thumb.surface, thumb.type,
716                 thumb.width, thumb.height, thumb.stride, width, height);
717 #endif
718         if ((info->width <= 1) || (info->height <= 1))  {
719             ICO_DBG("CicoHSMenuTile::SetThumbnail: small surface(%d,%d) skip",
720                     info->width, info->height);
721         }
722         else    {
723             // create thumbnail image
724             svx = thumb_reduce_x;
725             svy = thumb_reduce_y;
726             if (thumb.width > (thumb.height + 64))  {
727                 thumb_reduce_x = ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX;
728                 thumb_reduce_y = height / ICO_HS_MENUTILE_THUMBNAIL_REDUCE_RATE;
729             }
730             else if (thumb.width < (thumb.height - 64)) {
731                 thumb_reduce_y = ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX;
732                 thumb_reduce_x = width / ICO_HS_MENUTILE_THUMBNAIL_REDUCE_RATE;
733             }
734             else    {
735                 thumb_reduce_x = ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX;
736                 thumb_reduce_y = ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX;
737             }
738             if (! thumb_tile)   {
739                 thumb_tile = evas_object_image_filled_add(menu_evas);
740                 evas_object_resize(thumb_tile, width - thumb_reduce_x * 2,
741                                                height - thumb_reduce_y * 2);
742                 evas_object_move(thumb_tile, pos_x + thumb_reduce_x,
743                                  pos_y + thumb_reduce_y);
744                 evas_object_event_callback_add(thumb_tile, EVAS_CALLBACK_MOUSE_DOWN,
745                                                CicoHSMenuTouch::TouchDownMenu, appid);
746                 evas_object_event_callback_add(thumb_tile, EVAS_CALLBACK_MOUSE_UP,
747                                                CicoHSMenuTouch::TouchUpMenu, appid);
748                 ICO_DBG("CicoHSMenuTile::SetThumbnail: create thumb_tile %s "
749                         "tile=(%d+%d,%d+%d)", appid,
750                         pos_x, thumb_reduce_x, pos_y, thumb_reduce_y);
751                 if (small_icon) {
752                     evas_object_move(small_icon,
753                                      pos_x + thumb_reduce_x
754                                          - ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX2,
755                                      pos_y + height - thumb_reduce_y - height
756                                          / ICO_HS_MENUTILE_THUMBNAIL_REDUCTION
757                                          + ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX2);
758                     evas_object_raise(small_icon);
759                 }
760                 evas_object_raise(term_icon);
761             }
762             else if ((svx != thumb_reduce_x) || (svy != thumb_reduce_y))    {
763                 evas_object_resize(thumb_tile, width - thumb_reduce_x * 2,
764                                                height - thumb_reduce_y * 2);
765                 evas_object_move(thumb_tile, pos_x + thumb_reduce_x,
766                                  pos_y + thumb_reduce_y);
767                 if (small_icon) {
768                     evas_object_move(small_icon,
769                                      pos_x + thumb_reduce_x
770                                          - ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX2,
771                                      pos_y + height - thumb_reduce_y - height
772                                          / ICO_HS_MENUTILE_THUMBNAIL_REDUCTION
773                                          + ICO_HS_MENUTILE_THUMBNAIL_REDUCE_PIX2);
774                 }
775             }
776             /* read surface image pixel         */
777             int bufsize = ((thumb.width * thumb.height * 4 + 4095) / 4096) * 4096;
778             if ((! thumb.pixel_data) || (bufsize > thumb.pixel_bufsize))    {
779                 free(thumb.pixel_data);
780                 thumb.pixel_data = (char *)malloc(bufsize);
781                 thumb.pixel_bufsize = bufsize;
782                 if (thumb.pixel_data)   {
783                     memset(thumb.pixel_data, 0, bufsize);
784                 }
785             }
786             if (thumb.pixel_data)   {
787                 fd = open(sWork, O_RDONLY, 0644);
788                 if (fd >= 0)    {
789 #if     0           /* for BMP format   */
790                     if (read(fd, &bmphead, sizeof(bmphead)) != sizeof(bmphead)) {
791                         ICO_ERR("CicoHSMenuTile::SetThumbnail: can not read pixel file(%s)",
792                                 sWork);
793                     }
794                     else
795 #endif
796                     if (read(fd, thumb.pixel_data, bufsize) <= 0)   {
797                         ICO_ERR("CicoHSMenuTile::SetThumbnail: can not read pixel file(%s)",
798                                 sWork);
799                     }
800                 }
801                 else    {
802                     ICO_DBG("CicoHSMenuTile::SetThumbnail: can not open pixel file(%s)",
803                             sWork);
804                 }
805                 if (fd >= 0)    {
806                     close(fd);
807                     (void) unlink(sWork);
808                 }
809                 evas_object_image_data_update_add(
810                                     thumb_tile, 0, 0, thumb.width, thumb.height);
811                 icon = thumb_tile;
812                 evas_object_image_size_set(thumb_tile, thumb.width, thumb.height);
813                 evas_object_image_data_set(thumb_tile, thumb.pixel_data);
814                 evas_object_image_filled_set(thumb_tile, EINA_TRUE);
815                 evas_object_resize(thumb_tile, width - thumb_reduce_x * 2,
816                                    height - thumb_reduce_y * 2);
817                 evas_object_move(thumb_tile,
818                                  pos_x + thumb_reduce_x, pos_y + thumb_reduce_y);
819             }
820             else    {
821                 ICO_ERR("CicoHSMenuTile::SetThumbnail: can not malloc pixel buffer");
822                 unmap = 1;
823             }
824         }
825     }
826
827     if (unmap > 0)  {
828         ICO_DBG("CicoHSMenuTile::SetThumbnail: unmap thumbnail %08x", thumb.surface);
829         if (thumb.surface)  {
830             sprintf(sWork, ICO_HS_THUMB_ICODIR ICO_HS_THUMB_FILEDIR "/%08x."
831                     ICO_HS_THUMB_FILEEXT, thumb.surface);
832             (void) unlink(sWork);
833             ico_syc_unmap_thumb(thumb.surface);
834             thumb.surface = 0;
835         }
836         free(thumb.pixel_data);
837         thumb.pixel_data = NULL;
838         icon = tile;
839         if (thumb.thumb_timer)  {
840             ecore_timer_del(thumb.thumb_timer);
841         }
842         thumb.thumb_timer = ecore_timer_add(ICO_HS_MENUTILE_THUMBNAIL_RETRYTIME,
843                                             CicoHSMenuTile::TimerThumbnail, (void *)this);
844     }
845
846     if (icon != old_icon)   {
847         if (old_icon)   {
848             evas_object_hide(old_icon);
849         }
850         evas_object_show(icon);
851         if (small_icon) {
852             if (icon == thumb_tile) {
853                 evas_object_show(small_icon);
854                 // remake thumbnail for first build image
855                 CicoHSMenuTile::SetThumbnail(info);
856             }
857             else    {
858                 evas_object_hide(small_icon);
859             }
860         }
861     }
862 }
863
864 /*--------------------------------------------------------------------------*/
865 /**
866  * @brief   CicoHSMenuTile::TimerThumbnail
867  *          recheck thumbnail
868  *
869  * @param[in]   data    CicoHSMenuTile object
870  * @return      fixed ECORE_CALLBACK_CANCEL
871  */
872 /*--------------------------------------------------------------------------*/
873 Eina_Bool
874 CicoHSMenuTile::TimerThumbnail(void *data)
875 {
876     CicoHSMenuTile  *tile = (CicoHSMenuTile *)data;
877
878     tile->RetryThumbnail();
879
880     return ECORE_CALLBACK_CANCEL;
881 }
882
883 /*--------------------------------------------------------------------------*/
884 /**
885  * @brief   CicoHSMenuTile::ShowMenu
886  *          change menu show/hide for live thumbnail update cycle
887  *
888  * @param[in]   show    surface
889  * @return      nonmenu show(true)/fide(false)
890  */
891 /*--------------------------------------------------------------------------*/
892 void
893 CicoHSMenuTile::ShowMenu(bool show)
894 {
895     char    sWork[PATH_MAX];
896     menu_show = show;
897     if ((thumb_tile) && (thumb.surface != 0)) {
898         sprintf(sWork, ICO_HS_THUMB_ICODIR ICO_HS_THUMB_FILEDIR "/%08x."
899                 ICO_HS_THUMB_FILEEXT, thumb.surface);
900         (void) unlink(sWork);
901         ico_syc_map_thumb(thumb.surface,
902                           menu_show ? ICO_HS_MENUTILE_THUMBNAIL_FPS_SHOW :
903                                       ICO_HS_MENUTILE_THUMBNAIL_FPS_HIDE, sWork);
904     }
905 }
906
907 /*--------------------------------------------------------------------------*/
908 /**
909  * @brief   CicoHSMenuTile::SetOrgThumbnail
910  *          set thumbnail form org tile
911  *
912  * @param[in]   info    org tile
913  * @return      none
914  */
915 /*--------------------------------------------------------------------------*/
916 void
917 CicoHSMenuTile::SetOrgThumbnail(CicoHSMenuTile *orgTile)
918 {
919
920     ICO_DBG("CicoHSMenuTile::SetOrgThumbnail Enter(appid=%p<%s>) run=%d surf=%08x",
921             this->appid, this->appid, app_running, orgTile->thumb.surface );
922
923     /* check surface of orgTile */
924     if ( orgTile == NULL || orgTile->thumb.surface == 0 ) {
925         return;
926     }
927
928     /* set surface */
929     this->ValidThumbnail( orgTile->thumb.surface );
930
931     /* set new thumbnail */
932     ico_syc_thumb_info_t info;
933
934     info.surface = orgTile->thumb.surface;
935     info.type = orgTile->thumb.type;
936     info.width = orgTile->thumb.width;
937     info.height = orgTile->thumb.height;
938     info.stride = orgTile->thumb.stride;
939     info.format = orgTile->thumb.format;
940
941     SetThumbnail( &info );
942
943     ICO_DBG("CicoHSMenuTile::SetOrgThumbnail Leave(appid=%p<%s>) run=%d surf=%08x",
944             this->appid, this->appid, app_running, orgTile->thumb.surface );
945
946 }
947 // vim: set expandtab ts=4 sw=4: