add set/unset rotation sensing status when app_pause
[framework/uifw/cbhm.git] / src / clipdrawer.c
1 #include "common.h"
2 #include "cbhm_main.h"
3 #include "storage.h"
4 #include "xcnphandler.h"
5 #include "clipdrawer.h"
6
7 #define DELETE_ICON_PATH "/usr/share/cbhm/icons/05_delete.png"
8 #define IM      "/usr/share/cbhm/icons/"
9 static const char *g_images_path[] = {
10         IM"cbhm_default_img.png",
11 };
12 #define N_IMAGES (1)
13
14 #define GRID_ITEM_SPACE_W 6
15 #define GRID_ITEM_SINGLE_W 185
16 #define GRID_ITEM_SINGLE_H 161
17 #define GRID_ITEM_W (GRID_ITEM_SINGLE_W+(GRID_ITEM_SPACE_W*2))
18 #define GRID_ITEM_H (GRID_ITEM_SINGLE_H)
19 #define GRID_IMAGE_LIMIT_W 91
20 #define GRID_IMAGE_LIMIT_H 113
21
22 #define ANIM_DURATION 30 // 1 seconds
23 #define ANIM_FLOPS (0.5/30)
24
25 // gic should live at gengrid callback functions
26 Elm_Gengrid_Item_Class gic;
27 Ecore_Timer *tm_anim;
28
29 typedef struct tag_griditem
30 {
31         int itype;
32         Elm_Gengrid_Item *item;
33         const char *ipathdata;
34         Eina_Strbuf *istrdata;
35         Evas_Object *delbtn;
36         Evas_Object *ilayout;
37 } griditem_t;
38
39
40 int clipdrawer_update_contents(void *data)
41 {
42         struct appdata *ad = data;
43         int i, pos;
44         char *unesc = NULL;
45
46         for (i = 0; i < HISTORY_QUEUE_MAX_ITEMS; i++)
47         {
48                 pos = get_current_history_position() - i;
49                 if (pos < 0)
50                         pos = pos+HISTORY_QUEUE_MAX_ITEMS;
51
52                 if (clipdrawer_get_item_data(ad, pos) != NULL && strlen(clipdrawer_get_item_data(ad, pos)) > 0)
53                 {
54                         unesc = clipdrawer_get_plain_string_from_escaped(clipdrawer_get_item_data(ad, pos));
55                         unesc = unesc ? unesc : "";
56                         elm_list_item_append(ad->txtlist, unesc, NULL, NULL, NULL, ad);
57                         free(unesc);
58                 }
59         }
60
61         /* FIXME : sometimes when list update, screen isn't updated */
62
63         return 0;
64 }
65
66 const char* clipdrawer_get_plain_string_from_escaped(char *escstr)
67 {
68         /* TODO : is it should be here? besides, remove dependency for entry */
69         /* NOTE : return string should be freed */
70         return elm_entry_markup_to_utf8(escstr);
71 }
72
73 static void _grid_del_response_cb(void *data, Evas_Object *obj, void *event_info)
74 {
75         Elm_Gengrid_Item *it = (Elm_Gengrid_Item *)data;
76         evas_object_del(obj);
77
78         if((int)event_info == ELM_POPUP_RESPONSE_OK)
79                 elm_gengrid_item_del(it);
80 }
81
82 static void _grid_click_delete(void *data, Evas_Object *obj, void *event_info)
83 {
84         struct appdata *ad = data;
85 }
86
87 static void
88 _grid_item_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
89 {
90         struct appdata *ad = g_get_main_appdata();
91
92         if (ad->anim_status != STATUS_NONE)
93                 return;
94
95         Elm_Gengrid_Item *sgobj = NULL;
96         sgobj = elm_gengrid_selected_item_get(ad->hig);
97         griditem_t *ti = NULL;
98         ti = elm_gengrid_item_data_get(sgobj);
99
100         #define EDJE_DELBTN_PART_PREFIX "delbtn"
101         if (strncmp(source, EDJE_DELBTN_PART_PREFIX, strlen(EDJE_DELBTN_PART_PREFIX)))
102         {
103                 if (!sgobj || !ti)
104                 {
105                         DTRACE("ERR: cbhm can't get the selected image\n");
106                         return;
107                 }
108
109                 elm_gengrid_item_selected_set(sgobj, EINA_FALSE);
110
111                 if (ti->itype == GI_TEXT)
112                 {
113                         char *p = strdup(eina_strbuf_string_get(ti->istrdata));
114
115                         elm_selection_set(1, obj, /*ELM_SEL_FORMAT_TEXT*/1, p);
116                 }
117                 else //if (ti->itype == GI_IMAGE)
118                 {
119                         if (!clipdrawer_paste_textonly_get(ad))
120                         {
121                                 int len = strlen(ti->ipathdata);
122                                 char *p = malloc(len + 10);
123                                 snprintf(p,len+10, "file:///%s", ti->ipathdata);
124
125                                 elm_selection_set(/*secondary*/1,obj,/*ELM_SEL_FORMAT_IMAGE*/4,p);
126                         }
127                         else
128                         {
129                                 DTRACE("ERR: cbhm image paste mode is false\n");
130                         }
131                 }
132
133                 return;
134         }
135
136         if (!sgobj)
137         {
138                 DTRACE("ERR: cbhm can't get the selected item\n");
139                 return;
140         }
141
142         elm_gengrid_item_selected_set(sgobj, EINA_FALSE);
143
144         Evas_Object *popup = elm_popup_add(ad->win_main);
145         elm_popup_timeout_set(popup, 5);
146         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
147         elm_popup_desc_set(popup, "Are you sure delete this?");
148         elm_popup_buttons_add(popup, 2,
149                                                   "Yes", ELM_POPUP_RESPONSE_OK,
150                                                   "No", ELM_POPUP_RESPONSE_CANCEL,
151                                                   NULL);
152         evas_object_smart_callback_add(popup, "response", _grid_del_response_cb, sgobj);
153         evas_object_show(popup);
154 }
155
156 Evas_Object* _grid_icon_get(const void *data, Evas_Object *obj, const char *part)
157 {
158         griditem_t *ti = (griditem_t *)data;
159
160         if (!strcmp(part, "elm.swallow.icon"))
161         {
162                 if (ti->itype == GI_TEXT)
163                 {
164                         Evas_Object *layout = elm_layout_add (obj);
165                         elm_layout_theme_set(layout, "gengrid", "widestyle", "horizontal_layout");
166                         edje_object_signal_callback_add(elm_layout_edje_get(layout), 
167                                                                                         "mouse,up,1", "*", _grid_item_ly_clicked, data);
168                         Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(obj));
169                         evas_object_resize(rect, GRID_ITEM_W, GRID_ITEM_H);
170                         evas_object_color_set(rect, 242, 233, 183, 255);
171                         evas_object_show(rect);
172                         elm_layout_content_set(layout, "elm.swallow.icon", rect);
173
174                         // FIXME: add string length check
175                         Evas_Object *ientry = elm_scrolled_entry_add(obj);
176                         evas_object_size_hint_weight_set(ientry, 0, 0);
177                         Eina_Strbuf *strent = NULL;
178                         char *strdata = eina_strbuf_string_get(ti->istrdata);
179                         int i, skipflag, strcnt;
180                         
181                         strent = eina_strbuf_new();
182                         skipflag = 0;
183                         strcnt = 0;
184                         for (i = 0; i < eina_strbuf_length_get(ti->istrdata); i++)
185                         {
186                                 switch (strdata[i])
187                                 {
188                                         case '>':
189                                                 skipflag = 0;
190                                                 break;
191                                         case '<':
192                                                 skipflag = 1;
193                                                 break;
194                                         default:
195                                                 if (!skipflag)
196                                                         strcnt++;
197                                                 break;
198                                 }
199                                 if (strcnt > 100)
200                                         break;
201                         }
202                         eina_strbuf_append_n(strent, strdata, i);
203 //                      eina_strbuf_append(strent, strdata);
204                         eina_strbuf_replace_all(strent, " absize=240x180 ", " absize=52x39 ");
205                         if (strcnt > 100)
206                                 eina_strbuf_append(strent, "...");
207                         eina_strbuf_prepend(strent, "<font_size=18>");
208
209                         elm_scrolled_entry_entry_set(ientry, eina_strbuf_string_get(strent));
210                         elm_scrolled_entry_editable_set(ientry, EINA_FALSE);
211                         elm_scrolled_entry_context_menu_disabled_set(ientry, EINA_TRUE);
212                         evas_object_show(ientry);
213                         elm_layout_content_set(layout, "elm.swallow.inner", ientry);
214
215                         eina_strbuf_free(strent);
216
217                         return layout;
218                 }
219                 else// if (ti->itype == GI_IMAGE)
220                 {
221                         Evas_Object *layout = elm_layout_add (obj);
222                         elm_layout_theme_set(layout, "gengrid", "widestyle", "horizontal_layout");
223                         edje_object_signal_callback_add(elm_layout_edje_get(layout), 
224                                                                                         "mouse,up,1", "*", _grid_item_ly_clicked, data);
225
226                         Evas_Object *sicon;
227                         sicon = evas_object_image_add(evas_object_evas_get(obj));
228                         evas_object_image_load_size_set(sicon, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
229                         evas_object_image_file_set(sicon, ti->ipathdata, NULL);
230                         evas_object_image_fill_set(sicon, 0, 0, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
231                         evas_object_resize(sicon, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
232                         elm_layout_content_set(layout, "elm.swallow.icon", sicon);
233
234                         struct appdata *ad = g_get_main_appdata();
235                         
236                         if (!clipdrawer_paste_textonly_get(ad))
237                         {
238                                 edje_object_signal_emit(elm_layout_edje_get(layout), "elm,state,hide,delbtn", "elm");
239                                 Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(obj));
240                                 evas_object_color_set(rect, 0, 0, 0, 200);
241                                 evas_object_show(rect);
242                                 elm_layout_content_set(layout, "elm.swallow.cover", rect);
243                         }
244
245                         ti->ilayout = layout;
246                         return layout;
247
248 /*
249                         Evas_Object *icon = elm_icon_add(obj);
250                         elm_icon_file_set(icon, ti->ipathdata, NULL);
251                         evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
252                         evas_object_show(icon);
253 */
254
255 /*
256                         Ecore_Evas *my_ee;
257                         Evas *my_e;
258                         Evas_Object *fgimg;
259                         Evas_Object *bgrect;
260                         Evas_Object *delbtn;
261                         Evas_Object *icon;
262                         my_ee = ecore_evas_buffer_new(GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
263                         my_e = ecore_evas_get(my_ee);
264
265                         bgrect = evas_object_rectangle_add(my_e);
266                         evas_object_color_set(bgrect, 255, 255, 255, 255);
267                         evas_object_resize(bgrect, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
268                         evas_object_move(bgrect, 0, 0);
269                         evas_object_show(bgrect);
270
271 #define BORDER_SIZE 1
272                         fgimg = evas_object_image_add(my_e);
273                         evas_object_image_load_size_set(fgimg, GRID_ITEM_SINGLE_W-BORDER_SIZE*2, GRID_ITEM_SINGLE_H-BORDER_SIZE*2);
274                         evas_object_image_file_set(fgimg, ti->ipathdata, NULL);
275                         evas_object_image_fill_set(fgimg, 0, 0, GRID_ITEM_SINGLE_W-BORDER_SIZE*2, GRID_ITEM_SINGLE_H-BORDER_SIZE*2);
276                         evas_object_image_filled_set(fgimg, 1);
277                         int x,y;
278                         evas_object_image_size_get(fgimg, &x, &y);
279                         //fprintf(stderr, "## img x = %d, y = %d\n", x, y);
280                         evas_object_resize(fgimg, GRID_ITEM_SINGLE_W-BORDER_SIZE*2, GRID_ITEM_SINGLE_H-BORDER_SIZE*2);
281                         evas_object_move(fgimg, BORDER_SIZE, BORDER_SIZE);
282                         evas_object_show(fgimg);
283
284                         icon = evas_object_image_add(evas_object_evas_get(obj));
285
286                         evas_object_image_data_set(icon, NULL);
287                         evas_object_image_size_set(icon, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
288                         evas_object_image_fill_set(icon, 0, 0, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
289                         evas_object_image_filled_set(icon, EINA_TRUE);
290                         evas_object_image_data_copy_set(icon, (int *)ecore_evas_buffer_pixels_get(my_ee));
291                         evas_object_image_data_update_add(icon, 0, 0, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
292
293                         evas_object_del(bgrect);
294                         evas_object_del(fgimg);
295                         ecore_evas_free(my_ee);
296
297                         return icon;
298 */
299                 }
300
301 //              return icon;
302         }
303 /*
304         else if (!strcmp(part, "elm.swallow.end"))
305         {
306                 ti->delbtn = elm_check_add(obj);
307                 elm_object_style_set(ti->delbtn, "extended/itemcheck");
308                 //evas_object_propagate_events_set(ti->delbtn, 0);
309                 elm_check_state_set(ti->delbtn, tcm);
310                 evas_object_smart_callback_add(ti->delbtn, "changed", _grid_item_check_changed, data);
311                 evas_object_show(ti->delbtn);
312                 return ti->delbtn;
313         }
314 */
315         return NULL;
316 }
317
318 static void _grid_longpress(void *data, Evas_Object *obj, void *event_info)
319 {
320         struct appdata *ad = data;
321 }
322
323 static void _grid_click_paste(void *data, Evas_Object *obj, void *event_info)
324 {
325         struct appdata *ad = data;
326         if (ad->anim_status != STATUS_NONE)
327                 return;
328
329         Elm_Gengrid_Item *sgobj = NULL;
330         sgobj = elm_gengrid_selected_item_get(ad->hig);
331         griditem_t *ti = NULL;
332         ti = elm_gengrid_item_data_get(sgobj);
333 }
334
335 void _grid_del(const void *data, Evas_Object *obj)
336 {
337         griditem_t *ti = (griditem_t *)data;
338         if (ti->itype == GI_TEXT)
339                 eina_strbuf_free(ti->istrdata);
340         else
341                 eina_stringshare_del(ti->ipathdata);
342         free(ti);
343 }
344
345 char* clipdrawer_get_item_data(void *data, int pos)
346 {
347         struct appdata *ad = data;
348         griditem_t *ti = NULL;
349         griditem_t *newgi = NULL;
350         int count = 0;
351
352         if (pos < 0 || pos > ad->hicount)
353                 return NULL;
354
355         Elm_Gengrid_Item *item = elm_gengrid_first_item_get(ad->hig);
356         while (item)    
357         {
358                 ti = elm_gengrid_item_data_get(item);
359                 if (count == pos)
360                 {
361                         if (!ti)
362                                 break;
363                         if (ti->itype == GI_TEXT)
364                                 return (char*)eina_strbuf_string_get(ti->istrdata);
365                         else
366                                 return ti->ipathdata;
367                 }
368                 count++;
369                 item = elm_gengrid_item_next_get(item);      
370         }
371
372         return NULL;
373 }
374
375 // FIXME: how to remove calling g_get_main_appdata()? 
376 //        it's mainly used at 'clipdrawer_image_item'
377 int clipdrawer_add_item(char *idata, int type)
378 {
379         struct appdata *ad = g_get_main_appdata();
380         griditem_t *newgi = NULL;
381
382         newgi = malloc(sizeof(griditem_t));
383         newgi->itype = type;
384
385         fprintf(stderr, "## add - %d : %s\n", newgi->itype, idata);
386         if (type == GI_TEXT)
387         {
388                 newgi->istrdata = eina_strbuf_new();
389                 eina_strbuf_append(newgi->istrdata, idata);
390         }
391         else //if (type == GI_IMAGE)
392         {
393                 Elm_Gengrid_Item *item = elm_gengrid_first_item_get(ad->hig);
394                 griditem_t *ti = NULL;
395
396                 if (!check_regular_file(idata))
397                 {
398                         DTRACE("Error : it isn't normal file = %s\n", idata);
399                         return -1;
400                 }
401
402                 while (item)    
403                 {
404                         ti = elm_gengrid_item_data_get(item);
405                         if ((ti->itype == type) && !strcmp(ti->ipathdata, idata))
406                         {
407                                 DTRACE("Error : duplicated file path = %s\n", idata);
408                                 return -1;
409                         }
410                         item = elm_gengrid_item_next_get(item);      
411                 }
412                 newgi->ipathdata = eina_stringshare_add(idata);
413         }
414
415         if (ad->hicount >= HISTORY_QUEUE_MAX_ITEMS)
416         {
417                 ad->hicount--;
418                 // FIXME: add routine that is removing its elements
419                 elm_gengrid_item_del(elm_gengrid_last_item_get(ad->hig));
420         }
421
422         ad->hicount++;
423         newgi->item = elm_gengrid_item_prepend(ad->hig, &gic, newgi, NULL, NULL);
424
425         return TRUE;
426 }
427
428 static void
429 clipdrawer_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
430 {
431         struct appdata *ad = data;
432
433         if (ad->anim_status != STATUS_NONE)
434                 return;
435
436         #define EDJE_CLOSE_PART_PREFIX "background/close"
437         if (!strncmp(source, EDJE_CLOSE_PART_PREFIX, strlen(EDJE_CLOSE_PART_PREFIX)))
438         {
439                 clipdrawer_lower_view(ad);
440         }
441 }
442
443 void set_rotation_to_clipdrawer(void *data, int angle)
444 {
445         struct appdata *ad = data;
446         double wh, wy;
447         int wposx, wwidth;
448
449         if (angle == 180) // reverse
450         {
451                 wh = (1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h;
452                 wy = 0;
453                 wwidth = ad->root_w;
454                 wposx = CLIPDRAWER_POS_X;
455         }
456         else if (angle == 90) // right rotate
457         {
458                 wh = (1.0*CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w;
459                 wy = (1.0*CLIPDRAWER_POS_X/SCREEN_WIDTH)*ad->root_w;
460                 wwidth = ad->root_h;
461                 wposx = CLIPDRAWER_WIDTH-CLIPDRAWER_HEIGHT_LANDSCAPE;
462         }
463         else if (angle == -90) // left rotate
464         {
465                 wh = (1.0*CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w;
466                 wy = (1.0*CLIPDRAWER_POS_X/SCREEN_WIDTH)*ad->root_w;
467                 wwidth = ad->root_h;
468                 wposx = CLIPDRAWER_POS_X;
469         }
470         else // angle == 0
471         {
472                 wh = (1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h;
473                 wy = (1.0*CLIPDRAWER_POS_Y/SCREEN_HEIGHT)*ad->root_h;
474                 wwidth = ad->root_w;
475                 wposx = CLIPDRAWER_POS_X;
476         }
477
478         evas_object_resize(ad->win_main, wwidth, (int)wh);
479         evas_object_move(ad->win_main, wposx, (int)wy);
480         evas_object_resize(ad->ly_main, wwidth, (int)wh);
481         evas_object_move(ad->ly_main, wposx, (int)wy);
482 }
483
484 int clipdrawer_init(void *data)
485 {
486         struct appdata *ad = data;
487         double cdy, cdw;
488
489         ad->windowshow = EINA_FALSE;
490         ad->hicount = 0;
491         ad->pastetextonly = EINA_TRUE;
492         ad->anim_status = STATUS_NONE;
493
494         // for elm_check
495         elm_theme_extension_add(NULL, APP_EDJ_FILE);
496
497         set_rotation_to_clipdrawer(ad, get_rotation_degree());
498
499         edje_object_signal_callback_add(elm_layout_edje_get(ad->ly_main), 
500                                                                         "mouse,up,1", "*", clipdrawer_ly_clicked, ad);
501
502         ad->hig = NULL;
503         ad->hig = elm_gengrid_add(ad->win_main);
504         elm_layout_content_set(ad->ly_main, "historyitems", ad->hig);
505         elm_gengrid_item_size_set(ad->hig, GRID_ITEM_W+2, GRID_ITEM_H);
506         elm_gengrid_align_set(ad->hig, 0.5, 0.5);
507         elm_gengrid_horizontal_set(ad->hig, EINA_TRUE);
508         elm_gengrid_bounce_set(ad->hig, EINA_TRUE, EINA_FALSE);
509         elm_gengrid_multi_select_set(ad->hig, EINA_FALSE);
510         evas_object_smart_callback_add(ad->hig, "selected", _grid_click_paste, ad);
511 //      evas_object_smart_callback_add(ad->hig, "longpressed", _grid_longpress, ad);
512         evas_object_size_hint_weight_set(ad->hig, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
513
514         elm_gengrid_clear(ad->hig);
515
516         gic.item_style = "default_grid";
517         gic.func.label_get = NULL;
518         gic.func.icon_get = _grid_icon_get;
519         gic.func.state_get = NULL;
520         gic.func.del = _grid_del;
521
522         int i;
523         griditem_t *newgi;
524
525         for (i = 0; i < N_IMAGES; i++)
526         {
527                 clipdrawer_add_item(g_images_path[0], GI_IMAGE);
528         }
529
530         clipdrawer_add_item("clipboard history", GI_TEXT);
531
532         evas_object_show (ad->hig);
533
534 // for debugging, calc history pos
535 /*
536    Evas_Coord x, y, w, h;
537    Evas_Coord vx, vy, vw, vh;
538
539    edje_object_part_geometry_get(elm_layout_edje_get(ad->ly_main),"imagehistory/list",&x,&y,&w,&h);
540    evas_object_geometry_get (ad->hig, &vx,&vy,&vw,&vh);
541    fprintf(stderr, "## x = %d, y = %d, w = %d, h = %d\n", x, y, w, h);
542    fprintf(stderr, "## vx = %d, vy = %d, vw = %d, vh = %d\n", vx, vy, vw, vh);
543 */
544
545 //      if (get_item_counts() != 0)
546 //              clipdrawer_update_contents(ad);
547
548         return 0;
549 }
550
551 int clipdrawer_create_view(void *data)
552 {
553         struct appdata *ad = data;
554
555         clipdrawer_init(ad);
556
557         // for debug
558         // at starting, showing app view
559         //clipdrawer_activate_view(ad);
560
561         return 0;
562 }
563
564 Eina_Bool _get_anim_pos(void *data, int *sp, int *ep)
565 {
566         if (!sp || !ep)
567                 return EINA_FALSE;
568
569         struct appdata *ad = data;
570         int angle = get_rotation_degree();
571         int anim_start, anim_end, delta;
572
573         switch (ad->anim_status)
574         {
575                 case HIDE_ANIM:
576                         if (angle == 180) // reverse
577                         {
578                                 anim_start = 0;
579                                 anim_end = (int)(((double)CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h);
580                                 anim_end = ad->root_h-anim_end;
581                                 anim_end = -anim_end;
582                         }
583                         else if (angle == 90) // right rotate
584                         {
585                                 anim_end = ad->root_w;
586                                 anim_start = (int)(((double)CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w);
587                                 anim_start = ad->root_w-anim_start;
588                         }
589                         else if (angle == -90) // left rotate
590                         {
591                                 anim_start = 0;
592                                 anim_end = (int)(((double)CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w);
593                                 anim_end = ad->root_w-anim_end;
594                                 anim_end = -anim_end;
595                         }
596                         else // angle == 0
597                         {
598                                 anim_start = (int)((1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h);
599                                 anim_end = ad->root_h;
600                                 anim_start = anim_end-anim_start;
601                         }
602                         break;
603                 case SHOW_ANIM:
604                         if (angle == 180) // reverse
605                         {
606                                 anim_start = (int)(((double)CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h);
607                                 anim_start = ad->root_h - anim_start;
608                                 anim_start = -anim_start;
609                                 anim_end = 0;
610                         }
611                         else if (angle == 90) // right rotate
612                         {
613                                 anim_start = ad->root_w;
614                                 anim_end = (int)(((double)CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w);
615                                 anim_end = anim_start-anim_end;
616                         }
617                         else if (angle == -90) // left rotate
618                         {
619                                 anim_start = (int)(((double)CLIPDRAWER_HEIGHT_LANDSCAPE/SCREEN_WIDTH)*ad->root_w);
620                                 anim_start = ad->root_w-anim_start;
621                                 anim_start = -anim_start;
622                                 anim_end = 0;
623                         }
624                         else // angle == 0
625                         {
626                                 anim_start = ad->root_h;
627                                 anim_end = (int)(((double)CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h);
628                                 anim_end = anim_start-anim_end;
629                         }
630                         break;
631         }
632         *sp = anim_start;
633         *ep = anim_end;
634         return EINA_TRUE;
635 }
636
637 Eina_Bool _do_anim_delta_pos(void *data, int sp, int ep, int ac, int *dp)
638 {
639         if (!dp)
640                 return EINA_FALSE;
641
642         struct appdata *ad = data;
643         int angle = get_rotation_degree();
644         int delta;
645         double posprop;
646         posprop = 1.0*ac/ANIM_DURATION;
647
648         switch (ad->anim_status)
649         {
650                 case HIDE_ANIM:
651                         if (angle == 180) // reverse
652                         {
653                                 delta = (int)((sp-ep)*posprop);
654                                 evas_object_move(ad->win_main, 0, sp-delta);
655                         }
656                         else if (angle == 90) // right rotate
657                         {
658                                 delta = (int)((sp-ep)*posprop);
659                                 evas_object_move(ad->win_main, sp-delta, 0);
660                         }
661                         else if (angle == -90) // left rotate
662                         {
663                                 delta = (int)((sp-ep)*posprop);
664                                 evas_object_move(ad->win_main, sp-delta, 0);
665                         }
666                         else // angle == 0
667                         {
668                                 delta = (int)((ep-sp)*posprop);
669                                 evas_object_move(ad->win_main, 0, sp+delta);
670                         }
671                         break;
672                 case SHOW_ANIM:
673                         if (angle == 180) // reverse
674                         {
675                                 delta = (int)((ep-sp)*posprop);
676                                 evas_object_move(ad->win_main, 0, sp+delta);
677                         }
678                         else if (angle == 90) // right rotate
679                         {
680                                 delta = (int)((ep-sp)*posprop);
681                                 evas_object_move(ad->win_main, sp+delta, 0);
682                         }
683                         else if (angle == -90) // left rotate
684                         {
685                                 delta = (int)((ep-sp)*posprop);
686                                 evas_object_move(ad->win_main, sp+delta, 0);
687                         }
688                         else // angle == 0
689                         {
690                                 delta = (int)((sp-ep)*posprop);
691                                 evas_object_move(ad->win_main, 0, sp-delta);
692                         }
693                         break;
694         }
695         
696         *dp = delta;
697
698         return EINA_TRUE;
699 }
700
701 Eina_Bool anim_pos_calc_cb(void *data)
702 {
703         struct appdata *ad = data;
704
705         static int anim_count = 0;
706         int anim_start, anim_end, delta;
707
708         _get_anim_pos(ad, &anim_start, &anim_end);
709
710         if (anim_count > ANIM_DURATION)
711         {
712                 anim_count = 0;
713                 if (ad->anim_status == HIDE_ANIM)
714                 {
715                         evas_object_hide(ad->win_main);
716                         elm_win_lower(ad->win_main);
717                         unset_transient_for(ad);
718                 }
719                 ad->anim_status = STATUS_NONE;
720                 set_focus_for_app_window(ad->win_main, EINA_FALSE);
721                 return EINA_FALSE;
722         }
723
724         _do_anim_delta_pos(ad, anim_start, anim_end, anim_count, &delta);
725
726         anim_count++;
727         return EINA_TRUE;
728 }
729
730 void clipdrawer_anim_effect(void *data, anim_status_t atype)
731 {
732         struct appdata *ad = data;
733
734         if (ad->anim_status != STATUS_NONE)
735         {
736                 DTRACE("ERR: another animation is showing\n");
737                 return;
738         }
739
740         ad->anim_status = atype;
741         ecore_timer_add(ANIM_FLOPS, anim_pos_calc_cb, ad);
742 }
743
744 void clipdrawer_activate_view(void *data)
745 {
746         struct appdata *ad = data;
747
748         set_focus_for_app_window(ad->win_main, EINA_TRUE);
749         if (ad->win_main)
750         {
751                 set_transient_for(ad);
752                 evas_object_show(ad->win_main);
753                 elm_win_activate(ad->win_main);
754 //              elm_win_raise(ad->win_main);
755                 clipdrawer_anim_effect(ad, SHOW_ANIM);
756                 ad->windowshow = EINA_TRUE;
757         }
758 }
759
760 void clipdrawer_lower_view(void *data)
761 {
762         struct appdata *ad = data;
763         
764         if (ad->win_main && ad->windowshow)
765         {
766                 clipdrawer_anim_effect(ad, HIDE_ANIM);
767                 ad->windowshow = EINA_FALSE;
768         }
769 }
770
771 void _change_gengrid_paste_textonly_mode(void *data)
772 {
773         struct appdata *ad = data;
774
775         Elm_Gengrid_Item *item;
776         griditem_t *ti = NULL;
777
778         if (clipdrawer_paste_textonly_get(ad))
779         { // textonly paste mode
780                 Elm_Gengrid_Item *item = elm_gengrid_first_item_get(ad->hig);
781
782                 while (item)    
783                 {
784                         ti = elm_gengrid_item_data_get(item);
785                         if ((ti->itype == GI_IMAGE) && (ti->ilayout))
786                         {
787                                 edje_object_signal_emit(elm_layout_edje_get(ti->ilayout), "elm,state,hide,delbtn", "elm");
788                                 Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(ad->hig));
789                                 evas_object_color_set(rect, 0, 0, 0, 200);
790                                 evas_object_show(rect);
791                                 elm_layout_content_set(ti->ilayout, "elm.swallow.cover", rect);
792                         }
793                         item = elm_gengrid_item_next_get(item);
794                 }
795         }
796         else
797         { // text+image paste mode
798                 Elm_Gengrid_Item *item = elm_gengrid_first_item_get(ad->hig);
799
800                 while (item)    
801                 {
802                         ti = elm_gengrid_item_data_get(item);
803                         if ((ti->itype == GI_IMAGE) && (ti->ilayout))
804                         {
805                                 edje_object_signal_emit(elm_layout_edje_get(ti->ilayout), "elm,state,show,delbtn", "elm");
806                                 Evas_Object *rect = elm_layout_content_unset(ti->ilayout, "elm.swallow.cover");
807                                 evas_object_hide(rect);
808                                 evas_object_del(rect);
809                         }
810                         item = elm_gengrid_item_next_get(item);      
811                 }
812         }
813 }
814
815 void clipdrawer_paste_textonly_set(void *data, Eina_Bool textonly)
816 {
817         struct appdata *ad = data;
818         textonly = !!textonly;
819         if (ad->pastetextonly != textonly)
820                 ad->pastetextonly = textonly;
821         DTRACE("paste textonly mode = %d\n", textonly);
822
823         _change_gengrid_paste_textonly_mode(ad);
824 }
825
826 Eina_Bool clipdrawer_paste_textonly_get(void *data)
827 {
828         struct appdata *ad = data;
829         return ad->pastetextonly;
830 }