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