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