[cbhm] fixed N_SE-326 issue
[framework/uifw/cbhm.git] / src / clipdrawer.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17
18 #include <utilX.h>
19 #include "clipdrawer.h"
20 #include "item_manager.h"
21 #include "xconverter.h"
22
23 #define EDJ_PATH "/usr/share/edje"
24 #define APP_EDJ_FILE EDJ_PATH"/cbhmdrawer.edj"
25 #define GRP_MAIN "cbhmdrawer"
26
27 #define ANIM_DURATION 30 // 1 seconds
28 #define ANIM_FLOPS (0.5/30)
29 #define CLIPDRAWER_HEIGHT 360
30 #define CLIPDRAWER_HEIGHT_LANDSCAPE 228
31 #define DEFAULT_WIDTH 720
32 #define GRID_ITEM_SPACE_W 6
33 #define GRID_ITEM_SINGLE_W 185
34 #define GRID_ITEM_SINGLE_H 161
35 #define GRID_ITEM_W (GRID_ITEM_SINGLE_W+(GRID_ITEM_SPACE_W*2))
36 #define GRID_ITEM_H (GRID_ITEM_SINGLE_H)
37 #define GRID_IMAGE_LIMIT_W 91
38 #define GRID_IMAGE_LIMIT_H 113
39 #define GRID_IMAGE_INNER 10
40 #define GRID_IMAGE_REAL_W (GRID_ITEM_SINGLE_W - (2*GRID_IMAGE_INNER))
41 #define GRID_IMAGE_REAL_H (GRID_ITEM_SINGLE_H - (2*GRID_IMAGE_INNER))
42
43 static Evas_Object *create_win(ClipdrawerData *cd, const char *name);
44 static Evas_Object *_grid_content_get(void *data, Evas_Object *obj, const char *part);
45 static void _grid_del(void *data, Evas_Object *obj);
46 static Eina_Bool clipdrawer_add_item(AppData *ad, CNP_ITEM *item);
47 static Eina_Bool clipdrawer_del_item(AppData *ad, CNP_ITEM *item);
48 static void clipdrawer_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
49 static void _grid_item_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
50 static void setting_win(Ecore_X_Display *x_disp, Ecore_X_Window x_main_win);
51 static void set_transient_for(Ecore_X_Window x_main_win, Ecore_X_Window x_active_win);
52 static void unset_transient_for(Ecore_X_Window x_main_win, Ecore_X_Window x_active_win);
53
54 static void _change_gengrid_paste_textonly_mode(ClipdrawerData *cd)
55 {
56         CNP_ITEM *item = NULL;
57
58         Elm_Object_Item *gitem = elm_gengrid_first_item_get(cd->gengrid);
59
60         while (gitem)
61         {
62                 item = elm_object_item_data_get(gitem);
63                 if ((item->type_index == ATOM_INDEX_IMAGE) && (item->layout))
64                 {
65                         if (cd->paste_text_only)
66                                 edje_object_signal_emit(elm_layout_edje_get(item->layout), "elm,state,show,dim", "elm");
67                         else
68                                 edje_object_signal_emit(elm_layout_edje_get(item->layout), "elm,state,hide,dim", "elm");
69                 }
70                 gitem = elm_gengrid_item_next_get(gitem);
71         }
72 }
73
74 void clipdrawer_paste_textonly_set(AppData *ad, Eina_Bool textonly)
75 {
76         ClipdrawerData *cd = ad->clipdrawer;
77         if (cd->paste_text_only != textonly)
78                 cd->paste_text_only = textonly;
79         DTRACE("paste textonly mode = %d\n", textonly);
80
81         _change_gengrid_paste_textonly_mode(cd);
82 }
83
84 Eina_Bool clipdrawer_paste_textonly_get(AppData *ad)
85 {
86         ClipdrawerData *cd = ad->clipdrawer;
87         return cd->paste_text_only;
88 }
89
90 static Evas_Object *_load_edj(Evas_Object* win, const char *file, const char *group)
91 {
92         Evas_Object *layout = elm_layout_add(win);
93         if (!layout)
94         {
95                 DMSG("ERROR: elm_layout_add return NULL\n");
96                 return NULL;
97         }
98
99         if (!elm_layout_file_set(layout, file, group))
100         {
101                 DMSG("ERROR: elm_layout_file_set return FALSE\n");
102                 evas_object_del(layout);
103                 return NULL;
104         }
105
106         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
107         elm_win_resize_object_add(win, layout);
108
109         evas_object_show(layout);
110         return layout;
111 }
112
113 static Eina_Bool keydown_cb(void *data, int type, void *event)
114 {
115         AppData *ad = data;
116         Ecore_Event_Key *ev = event;
117         if (!strcmp(ev->keyname, KEY_END))
118                 clipdrawer_lower_view(ad);
119
120         return ECORE_CALLBACK_PASS_ON;
121 }
122
123 ClipdrawerData* init_clipdrawer(AppData *ad)
124 {
125         ClipdrawerData *cd = calloc(1, sizeof(ClipdrawerData));
126
127         /* create and setting window */
128         if (!cd)
129                 return NULL;
130         if (!(cd->main_win = create_win(cd, APPNAME)))
131         {
132                 free(cd);
133                 return NULL;
134         }
135         cd->x_main_win = elm_win_xwindow_get(cd->main_win);
136         setting_win(ad->x_disp, cd->x_main_win);
137
138         /* edj setting */
139         if (!(cd->main_layout = _load_edj(cd->main_win, APP_EDJ_FILE, GRP_MAIN)))
140         {
141                 evas_object_del(cd->main_win);
142                 free(cd);
143                 return NULL;
144         }
145
146         /* create and setting gengrid */
147         elm_theme_extension_add(NULL, APP_EDJ_FILE);
148         edje_object_signal_callback_add(elm_layout_edje_get(cd->main_layout),
149                         "mouse,up,1", "*", clipdrawer_ly_clicked, ad);
150
151         cd->gengrid = elm_gengrid_add(cd->main_win);
152         elm_object_part_content_set(cd->main_layout, "historyitems", cd->gengrid);
153         elm_gengrid_item_size_set(cd->gengrid, GRID_ITEM_W+2, GRID_ITEM_H);
154         elm_gengrid_align_set(cd->gengrid, 0.5, 0.0);
155         elm_gengrid_horizontal_set(cd->gengrid, EINA_TRUE);
156         elm_gengrid_bounce_set(cd->gengrid, EINA_TRUE, EINA_FALSE);
157         elm_gengrid_multi_select_set(cd->gengrid, EINA_FALSE);
158 //      evas_object_smart_callback_add(cd->gengrid, "selected", _grid_click_paste, ad);
159         evas_object_size_hint_weight_set(cd->gengrid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
160
161         elm_gengrid_clear(cd->gengrid);
162
163         cd->gic.item_style = "default_grid";
164         cd->gic.func.text_get = NULL;
165         cd->gic.func.content_get = _grid_content_get;
166         cd->gic.func.state_get = NULL;
167         cd->gic.func.del = _grid_del;
168
169         evas_object_show(cd->gengrid);
170
171         ad->draw_item_add = clipdrawer_add_item;
172         ad->draw_item_del = clipdrawer_del_item;
173 //      ad->x_main_win = cd->x_main_win;
174
175         cd->keydown_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, keydown_cb, ad);
176         cd->evas = evas_object_evas_get(cd->main_win);
177
178         return cd;
179 }
180
181 void depose_clipdrawer(ClipdrawerData *cd)
182 {
183         evas_object_del(cd->main_win);
184         if (cd->anim_timer)
185                 ecore_timer_del(cd->anim_timer);
186         if (cd->keydown_handler)
187                 ecore_event_handler_del(cd->keydown_handler);
188         free(cd);
189 }
190
191 static Eina_Bool clipdrawer_add_item(AppData *ad, CNP_ITEM *item)
192 {
193         ClipdrawerData *cd = ad->clipdrawer;
194         if (item->type_index == ATOM_INDEX_IMAGE)
195         {
196                 Elm_Object_Item *gitem = elm_gengrid_first_item_get(cd->gengrid);
197                 while (gitem)
198                 {
199                         CNP_ITEM *gitem_data = elm_object_item_data_get(gitem);
200                         gitem = elm_gengrid_item_next_get(gitem);
201                         if ((gitem_data->type_index == item->type_index) && (!strcmp(item->data, gitem_data->data)))
202                         {
203                                 DMSG("duplicated file path = %s\n", item->data);
204                                 item_delete_by_CNP_ITEM(ad, gitem_data);
205                         }
206                 }
207                 cd->gic.item_style = "clipboard_photo_style";
208         }
209         else
210         {
211                 cd->gic.item_style = "default_grid";
212         }
213
214         item->gitem = elm_gengrid_item_prepend(cd->gengrid, &cd->gic, item, NULL, NULL);
215
216         return EINA_TRUE;
217 }
218
219 static Eina_Bool clipdrawer_del_item(AppData *ad, CNP_ITEM *item)
220 {
221         if (item->gitem)
222                 elm_object_item_del(item->gitem);
223         return EINA_TRUE;
224 }
225
226 static void _grid_del(void *data, Evas_Object *obj)
227 {
228         CNP_ITEM *item = data;
229         item->gitem = NULL;
230         item->layout = NULL;
231 }
232
233 static Evas_Object *_grid_content_get(void *data, Evas_Object *obj, const char *part)
234 {
235         CNP_ITEM *item = data;
236         AppData *ad = item->ad;
237         ClipdrawerData *cd = ad->clipdrawer;
238
239         if (strcmp(part, "elm.swallow.icon"))
240                 return NULL;
241         if (item->type_index == ATOM_INDEX_IMAGE) /* text/uri */
242         {
243                 int w, h, iw, ih;
244
245                 Evas_Object *layout = elm_layout_add(obj);
246                 elm_layout_theme_set(layout, "gengrid", "item", "clipboard_style");
247                 edje_object_signal_callback_add(elm_layout_edje_get(layout),
248                                 "mouse,up,1", "*", _grid_item_ly_clicked, data);
249
250
251                 Evas_Object *sicon;
252                 sicon = evas_object_image_add(evas_object_evas_get(obj));
253                 evas_object_image_load_size_set(sicon, GRID_IMAGE_REAL_W, GRID_IMAGE_REAL_H);
254                 evas_object_image_file_set(sicon, item->data, NULL);
255                 evas_object_image_size_get(sicon, &w, &h);
256
257                 if (w > GRID_IMAGE_REAL_W || h > GRID_IMAGE_REAL_H)
258                 {
259                         if (w >= h)
260                         {
261                                 iw = GRID_IMAGE_REAL_W;
262                                 ih = (float)GRID_IMAGE_REAL_W / w * h;
263                         }
264                         else
265                         {
266                                 iw = (float)GRID_IMAGE_REAL_H / h * w;
267                                 ih = GRID_IMAGE_REAL_H;
268                         }
269                 }
270                 else
271                 {
272                         iw = w;
273                         ih = h;
274                 }
275
276                 evas_object_image_fill_set(sicon, 0, 0, iw, ih);
277                 evas_object_resize(sicon, iw, ih);
278                 evas_object_size_hint_min_set(sicon, iw, ih);
279                 elm_object_part_content_set(layout, "elm.swallow.icon", sicon);
280
281                 if (cd->paste_text_only)
282                         edje_object_signal_emit(elm_layout_edje_get(layout), "elm,state,show,dim", "elm");
283                 else
284                         edje_object_signal_emit(elm_layout_edje_get(layout), "elm,state,hide,dim", "elm");
285
286                 item->layout = layout;
287         }
288         else
289         {
290                 Evas_Object *layout = elm_layout_add(obj);
291                 elm_layout_theme_set(layout, "gengrid", "widestyle", "horizontal_layout");
292                 edje_object_signal_callback_add(elm_layout_edje_get(layout), 
293                                 "mouse,up,1", "*", _grid_item_ly_clicked, data);
294                 Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(obj));
295                 evas_object_resize(rect, GRID_ITEM_W, GRID_ITEM_H);
296                 evas_object_color_set(rect, 242, 233, 183, 255);
297                 evas_object_show(rect);
298                 elm_object_part_content_set(layout, "elm.swallow.icon", rect);
299
300                 Evas_Object *ientry = elm_entry_add(obj);
301                 evas_object_size_hint_weight_set(ientry, 0, 0);
302                 elm_entry_scrollable_set(ientry, EINA_TRUE);
303
304                 char *entry_text = string_for_entry_get(ad, item->type_index, item->data);
305                 if (entry_text)
306                 {
307                         elm_object_part_text_set(ientry, NULL, entry_text);
308                         free(entry_text);
309                 }
310                 else
311                 {
312                         elm_object_part_text_set(ientry, NULL, item->data);
313                 }
314                 elm_entry_editable_set(ientry, EINA_FALSE);
315                 elm_entry_context_menu_disabled_set(ientry, EINA_TRUE);
316                 evas_object_show(ientry);
317                 elm_object_part_content_set(layout, "elm.swallow.inner", ientry);
318
319                 item->layout = layout;
320         }
321
322         return item->layout;
323 }
324
325 static void clipdrawer_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
326 {
327         AppData *ad = data;
328
329         if (ad->clipdrawer->anim_status != STATUS_NONE)
330                 return;
331
332 #define EDJE_CLOSE_PART_PREFIX "background/close"
333         if (!strncmp(source, EDJE_CLOSE_PART_PREFIX, strlen(EDJE_CLOSE_PART_PREFIX)))
334         {
335                 clipdrawer_lower_view(ad);
336         }
337 }
338
339 static void _grid_del_response_cb(void *data, Evas_Object *obj, void *event_info)
340 {
341         CNP_ITEM *item = data;
342         AppData *ad = item->ad;
343         ClipdrawerData *cd = ad->clipdrawer;
344         const char *label = elm_object_item_text_get(event_info);
345
346         /* delete popup */
347         evas_object_del(obj);
348
349         if (!strcmp(label, "Yes"))
350         {
351                 item_delete_by_CNP_ITEM(ad, item);
352         }
353 }
354
355 static void _grid_item_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
356 {
357         CNP_ITEM *item = data;
358         AppData *ad = item->ad;
359         ClipdrawerData *cd = ad->clipdrawer;
360
361         if (cd->anim_status != STATUS_NONE)
362                 return;
363
364         Elm_Object_Item *sgobj = NULL;
365         sgobj = elm_gengrid_selected_item_get(cd->gengrid);
366         item = elm_object_item_data_get(sgobj);
367
368         if (!sgobj || !item)
369         {
370                 DTRACE("ERR: cbhm can't get the selected item\n");
371                 return;
372         }
373
374         #define EDJE_DELBTN_PART_PREFIX "delbtn"
375         if (strncmp(source, EDJE_DELBTN_PART_PREFIX, strlen(EDJE_DELBTN_PART_PREFIX)))
376         {
377                 elm_gengrid_item_selected_set(sgobj, EINA_FALSE);
378
379                 if (item->type_index != ATOM_INDEX_IMAGE || !cd->paste_text_only)
380                 {
381                         set_selection_owner(ad, ECORE_X_SELECTION_SECONDARY, item);
382                 }
383         }
384         else
385         {
386                 elm_gengrid_item_selected_set(sgobj, EINA_FALSE);
387
388                 Evas_Object *popup = elm_popup_add(cd->main_win);
389                 elm_popup_timeout_set(popup, 5);
390                 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
391                 elm_object_text_set(popup, "Are you sure delete this?");
392                 elm_popup_item_append(popup, "Yes", NULL, _grid_del_response_cb, item);
393                 elm_popup_item_append(popup, "No", NULL, _grid_del_response_cb, item);
394                 evas_object_show(popup);
395         }
396 }
397
398 void set_transient_for(Ecore_X_Window x_main_win, Ecore_X_Window x_active_win)
399 {
400         ecore_x_icccm_transient_for_set(x_main_win, x_active_win);
401         ecore_x_event_mask_set(x_active_win,
402                                 ECORE_X_EVENT_MASK_WINDOW_PROPERTY | ECORE_X_EVENT_MASK_WINDOW_CONFIGURE);
403 }
404
405 void unset_transient_for(Ecore_X_Window x_main_win, Ecore_X_Window x_active_win)
406 {
407         ecore_x_event_mask_unset(x_active_win,
408                         ECORE_X_EVENT_MASK_WINDOW_PROPERTY | ECORE_X_EVENT_MASK_WINDOW_CONFIGURE);
409         ecore_x_icccm_transient_for_unset(x_main_win);
410 }
411
412 static void set_focus_for_app_window(Ecore_X_Window x_main_win, Eina_Bool enable)
413 {
414         CALLED();
415         Eina_Bool accepts_focus;
416         Ecore_X_Window_State_Hint initial_state;
417         Ecore_X_Pixmap icon_pixmap;
418         Ecore_X_Pixmap icon_mask;
419         Ecore_X_Window icon_window;
420         Ecore_X_Window window_group;
421         Eina_Bool is_urgent;
422
423         ecore_x_icccm_hints_get (x_main_win,
424                         &accepts_focus, &initial_state, &icon_pixmap, &icon_mask, &icon_window, &window_group, &is_urgent);
425         ecore_x_icccm_hints_set (x_main_win,
426                         enable, initial_state, icon_pixmap, icon_mask, icon_window, window_group, is_urgent);
427         DMSG("set focus mode = %d\n", enable);
428 }
429
430 void setting_win(Ecore_X_Display *x_disp, Ecore_X_Window x_main_win)
431 {
432         CALLED();
433         // disable window effect
434         utilx_set_window_effect_state(x_disp, x_main_win, 0);
435
436         ecore_x_icccm_name_class_set(x_main_win, "NORMAL_WINDOW", "NORMAL_WINDOW");
437
438         set_focus_for_app_window(x_main_win, EINA_FALSE);
439
440 }
441
442 Evas_Object *create_win(ClipdrawerData *cd, const char *name)
443 {
444         CALLED();
445
446         Evas_Object *win = elm_win_add(NULL, name, ELM_WIN_BASIC);
447         if (!win)
448         {
449                 DMSG("ERROR: elm_win_add return NULL\n");
450                 return NULL;
451         }
452         elm_win_title_set(win, name);
453         elm_win_borderless_set(win, EINA_TRUE);
454         ecore_x_window_size_get(ecore_x_window_root_first_get(), &cd->root_w, &cd->root_h);
455         DMSG("root_w: %d, root_h: %d\n", cd->root_w, cd->root_h);
456         evas_object_resize(win, cd->root_w, cd->root_h);
457
458         elm_scale_set((double)cd->root_w/DEFAULT_WIDTH);
459         return win;
460 }
461
462 static void set_sliding_win_geometry(ClipdrawerData *cd)
463 {
464         CALLED();
465         Ecore_X_Window zone;
466         Evas_Coord x, y, w, h;
467         zone = ecore_x_e_illume_zone_get(cd->x_main_win);
468         DTRACE(" zone:%x\n", zone);
469
470         if (cd->o_degree == 90 || cd->o_degree == 270)
471         {
472                 h = cd->anim_count * CLIPDRAWER_HEIGHT_LANDSCAPE / ANIM_DURATION;
473                 x = 0;
474                 y = cd->root_w - h;
475                 w = cd->root_h;
476         }
477         else
478         {
479                 h = cd->anim_count * CLIPDRAWER_HEIGHT / ANIM_DURATION;
480                 x = 0;
481                 y = cd->root_h - h;
482                 w = cd->root_w;
483         }
484
485         if (!h)
486                 w = 0;
487
488         DTRACE("[CBHM] change degree geometry... (%d, %d, %d x %d)\n", x, y, w, h);
489         ecore_x_e_illume_sliding_win_geometry_set(zone, x, y, w, h);
490         ecore_x_e_illume_sliding_win_state_set(zone, cd->anim_count != 0);
491 }
492
493 void set_rotation_to_clipdrawer(ClipdrawerData *cd)
494 {
495         CALLED();
496         int angle = cd->o_degree;
497         int x, y, w, h;
498
499         if (angle == 180) // reverse
500         {
501                 h = CLIPDRAWER_HEIGHT;
502                 x = 0;
503                 y = 0;
504                 w = cd->root_w;
505         }
506         else if (angle == 90) // right rotate
507         {
508                 h = CLIPDRAWER_HEIGHT_LANDSCAPE;
509                 x = cd->root_w - h;
510                 y = 0;
511                 w = cd->root_h;
512         }
513         else if (angle == 270) // left rotate
514         {
515                 h = CLIPDRAWER_HEIGHT_LANDSCAPE;
516                 x = 0;
517                 y = 0;
518                 w = cd->root_h;
519         }
520         else // angle == 0
521         {
522                 h = CLIPDRAWER_HEIGHT;
523                 x = 0;
524                 y = cd->root_h - h;
525                 w = cd->root_w;
526         }
527
528         evas_object_resize(cd->main_win, w, h);
529         evas_object_move(cd->main_win, x, y);
530         if (cd->anim_count == ANIM_DURATION)
531                 set_sliding_win_geometry(cd);
532 }
533
534 static Eina_Bool _get_anim_pos(ClipdrawerData *cd, int *sp, int *ep)
535 {
536         if (!sp || !ep)
537                 return EINA_FALSE;
538
539         int angle = cd->o_degree;
540         int anim_start, anim_end;
541
542         if (angle == 180) // reverse
543         {
544                 anim_start = -(cd->root_h - CLIPDRAWER_HEIGHT);
545                 anim_end = 0;
546         }
547         else if (angle == 90) // right rotate
548         {
549                 anim_start = cd->root_w;
550                 anim_end = anim_start - CLIPDRAWER_HEIGHT_LANDSCAPE;
551         }
552         else if (angle == 270) // left rotate
553         {
554                 anim_start = -(cd->root_w - CLIPDRAWER_HEIGHT_LANDSCAPE);
555                 anim_end = 0;
556         }
557         else // angle == 0
558         {
559                 anim_start = cd->root_h;
560                 anim_end = anim_start - CLIPDRAWER_HEIGHT;
561         }
562
563         *sp = anim_start;
564         *ep = anim_end;
565         return EINA_TRUE;
566 }
567
568 static Eina_Bool _do_anim_delta_pos(ClipdrawerData *cd, int sp, int ep, int ac, int *dp)
569 {
570         if (!dp)
571                 return EINA_FALSE;
572
573         int angle = cd->o_degree;
574         int delta;
575         double posprop;
576         posprop = 1.0*ac/ANIM_DURATION;
577
578         if (angle == 180) // reverse
579         {
580                 delta = (int)((ep-sp)*posprop);
581                 evas_object_move(cd->main_win, 0, sp+delta);
582         }
583         else if (angle == 90) // right rotate
584         {
585                 delta = (int)((ep-sp)*posprop);
586                 evas_object_move(cd->main_win, sp+delta, 0);
587         }
588         else if (angle == 270) // left rotate
589         {
590                 delta = (int)((ep-sp)*posprop);
591                 evas_object_move(cd->main_win, sp+delta, 0);
592         }
593         else // angle == 0
594         {
595                 delta = (int)((sp-ep)*posprop);
596                 evas_object_move(cd->main_win, 0, sp-delta);
597         }
598         
599         *dp = delta;
600
601         return EINA_TRUE;
602 }
603
604 static void stop_animation(AppData *ad)
605 {
606         CALLED();
607         ClipdrawerData *cd = ad->clipdrawer;
608         cd->anim_status = STATUS_NONE;
609         if (cd->anim_timer)
610         {
611                 ecore_timer_del(cd->anim_timer);
612                 cd->anim_timer = NULL;
613         }
614
615         set_sliding_win_geometry(cd);
616 }
617
618 static Eina_Bool anim_pos_calc_cb(void *data)
619 {
620         AppData *ad = data;
621         ClipdrawerData *cd = ad->clipdrawer;
622         int anim_start, anim_end, delta;
623
624         _get_anim_pos(cd, &anim_start, &anim_end);
625
626         if (cd->anim_status == SHOW_ANIM)
627         {
628                 if (cd->anim_count > ANIM_DURATION)
629                 {
630                         cd->anim_count = ANIM_DURATION;
631                         stop_animation(ad);
632                         return EINA_FALSE;
633                 }
634                 _do_anim_delta_pos(cd, anim_start, anim_end, cd->anim_count, &delta);
635                 if (cd->anim_count == 1)
636                         evas_object_show(cd->main_win);
637                 cd->anim_count++;
638         }
639         else if (cd->anim_status == HIDE_ANIM)
640         {
641                 if (cd->anim_count < 0)
642                 {
643                         cd->anim_count = 0;
644                         evas_object_hide(cd->main_win);
645                         elm_win_lower(cd->main_win);
646                         unset_transient_for(cd->x_main_win, ad->x_active_win);
647                         stop_animation(ad);
648                         return EINA_FALSE;
649                 }
650                 _do_anim_delta_pos(cd, anim_start, anim_end, cd->anim_count, &delta);
651                 cd->anim_count--;
652         }
653         else
654         {
655                 stop_animation(ad);
656                 return EINA_FALSE;
657         }
658
659         return EINA_TRUE;
660 }
661
662 static Eina_Bool clipdrawer_anim_effect(AppData *ad, AnimStatus atype)
663 {
664         CALLED();
665         ClipdrawerData *cd = ad->clipdrawer;
666         if (atype == cd->anim_status)
667         {
668                 DTRACE("Warning: Animation effect is already in progress. \n");
669                 return EINA_FALSE;
670         }
671
672         cd->anim_status = atype;
673
674         if (cd->anim_timer)
675                 ecore_timer_del(cd->anim_timer);
676         cd->anim_timer = ecore_timer_add(ANIM_FLOPS, anim_pos_calc_cb, ad);
677
678         return EINA_TRUE;
679 }
680
681 void clipdrawer_activate_view(AppData* ad)
682 {
683         CALLED();
684         ClipdrawerData *cd = ad->clipdrawer;
685         if (cd->main_win)
686         {
687                 set_focus_for_app_window(cd->x_main_win, EINA_TRUE);
688                 set_transient_for(cd->x_main_win, ad->x_active_win);
689                 cd->o_degree = get_active_window_degree(ad->x_active_win);
690                 elm_win_rotation_set(cd->main_win, cd->o_degree);
691                 set_rotation_to_clipdrawer(cd);
692         //      evas_object_show(cd->main_win);
693                 elm_win_activate(cd->main_win);
694         //      if (clipdrawer_anim_effect(ad, SHOW_ANIM))
695                 clipdrawer_anim_effect(ad, SHOW_ANIM);
696         }
697 }
698
699 void clipdrawer_lower_view(AppData* ad)
700 {
701         CALLED();
702         ClipdrawerData *cd = ad->clipdrawer;
703         if (cd->main_win && cd->anim_count)
704         {
705                 set_focus_for_app_window(cd->x_main_win, EINA_FALSE);
706         //      if (clipdrawer_anim_effect(ad, HIDE_ANIM))
707         //              ad->windowshow = EINA_FALSE;
708                 clipdrawer_anim_effect(ad, HIDE_ANIM);
709         }
710 }