Merge branch 'master' of 165.213.180.234:/git/slp/pkgs/elementary
[framework/uifw/elementary.git] / src / modules / ctxpopup_copypasteUI / copypaste.c
1 #include <Elementary.h>
2 #include "elm_module_priv.h"
3 #include "elm_priv.h"
4
5 Elm_Entry_Extension_data *ext_mod;
6
7 static void
8 _ctxpopup_position(Evas_Object *obj)
9 {
10    Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
11    evas_object_geometry_get(ext_mod->ent, &x, &y, NULL, NULL);
12    edje_object_part_text_cursor_geometry_get(ext_mod->ent, "elm.text",
13                                              &cx, &cy, &cw, &ch);
14    evas_object_size_hint_min_get(ext_mod->popup, &mw, &mh);
15    if (cw < mw)
16      {
17         cx += (cw - mw) / 2;
18         cw = mw;
19      }
20    if (ch < mh)
21      {
22         cy += (ch - mh) / 2;
23         ch = mh;
24      }
25    evas_object_move(ext_mod->popup, x + cx, y + cy);
26    evas_object_resize(ext_mod->popup, cw, ch);
27 }
28
29 static void
30 _select(void *data, Evas_Object *obj, void *event_info)
31 {
32    ext_mod->select(data,obj,event_info);
33    evas_object_hide(obj);
34 }
35
36 static void
37 _paste(void *data, Evas_Object *obj, void *event_info)
38 {
39         ext_mod->paste(data,obj,event_info);
40         evas_object_hide(obj);
41 }
42
43 static void
44 _cut(void *data, Evas_Object *obj, void *event_info)
45 {
46         ext_mod->cut(data,obj,event_info);
47         evas_object_hide(obj);
48         elm_ctxpopup_scroller_disabled_set(ext_mod->popup, EINA_FALSE);
49 }
50
51 static void
52 _copy(void *data, Evas_Object *obj, void *event_info)
53 {
54         ext_mod->copy(data,obj,event_info);
55         evas_object_hide(obj);
56         elm_ctxpopup_scroller_disabled_set(ext_mod->popup, EINA_FALSE);
57 }
58
59 static void
60 _cancel(void *data, Evas_Object *obj, void *event_info)
61 {
62         ext_mod->cancel(data,obj,event_info);
63         evas_object_hide(obj);
64         elm_ctxpopup_scroller_disabled_set(ext_mod->popup, EINA_FALSE);
65 }
66
67 static void
68 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
69 {
70         // start for cbhm
71         ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
72         elm_cbhm_helper_init(obj);
73         elm_cbhm_send_raw_data("show");
74         evas_object_hide(obj);
75         // end for cbhm
76 }
77
78 static void
79 _item_clicked(void *data, Evas_Object *obj, void *event_info)
80 {
81    Elm_Entry_Context_Menu_Item *it = data;
82    Evas_Object *obj2 = it->obj;
83
84         if (it->func) it->func(it->data, obj2, NULL);
85         evas_object_hide(obj);
86 }
87
88 // module api funcs needed
89 EAPI int
90 elm_modapi_init(void *m)
91 {
92    return 1; // succeed always
93 }
94
95 EAPI int
96 elm_modapi_shutdown(void *m)
97 {
98    return 1; // succeed always
99 }
100
101 // module fucns for the specific module type
102 EAPI void
103 obj_hook(Evas_Object *obj)
104 {
105         if(!ext_mod)
106                 {
107                         ext_mod = ELM_NEW(Elm_Entry_Extension_data);
108                 elm_entry_extension_module_data_get(obj,ext_mod);
109                 }
110 }
111
112 EAPI void
113 obj_unhook(Evas_Object *obj)
114 {
115    if(ext_mod)
116                 {
117                         free(ext_mod);
118                         ext_mod = NULL;
119         }
120 }
121
122 EAPI void
123 obj_longpress(Evas_Object *obj)
124 {               
125         if(!ext_mod) return;
126         Evas_Object *top;
127         const Eina_List *l;
128         const Elm_Entry_Context_Menu_Item *it;
129         const char *context_menu_orientation;
130
131         /*update*/
132         elm_entry_extension_module_data_get(obj,ext_mod);
133         if (ext_mod->context_menu)
134         {
135                 if (ext_mod->popup) evas_object_del(ext_mod->popup);
136         else elm_widget_scroll_freeze_push(obj);
137                 top = elm_widget_top_get(obj);
138                 if(top)
139                         ext_mod->popup = elm_ctxpopup_add(top);
140                 /*currently below theme not used,when guideline comes a new theme can be created if required*/
141                 //elm_object_style_set(ext_mod->popup,"entry");
142                 elm_ctxpopup_scroller_disabled_set(ext_mod->popup, EINA_TRUE);
143                 context_menu_orientation = edje_object_data_get
144                 (ext_mod->ent, "context_menu_orientation");
145                 if ((context_menu_orientation) &&
146                 (!strcmp(context_menu_orientation, "horizontal")))
147                 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
148
149                 elm_widget_sub_object_add(obj, ext_mod->popup);
150                 if (!ext_mod->selmode)
151                 {       
152                         if (!ext_mod->password)
153                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Select",_select, obj );
154                         if (1) // need way to detect if someone has a selection
155                                 {
156                                         if (ext_mod->editable)
157                                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Paste",    _paste, obj );
158                                 }
159         //              elm_ctxpopup_item_add(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
160         // start for cbhm
161                         if (!ext_mod->password)
162                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "More", _clipboard_menu, obj );
163         // end for cbhm
164                 }
165                 else
166                 {
167                           if (!ext_mod->password)
168                                 {
169                                         if (ext_mod->have_selection)
170                                                 {
171                                                         elm_ctxpopup_item_add(ext_mod->popup, NULL, "Copy",_copy, obj );
172                                                         if (ext_mod->editable)
173                                                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Cut",_cut, obj );                                                  
174                                                 }
175                                         else
176                                                 {
177                                                         _cancel(obj,ext_mod->popup,NULL);               
178                                                         elm_ctxpopup_item_add(ext_mod->popup, NULL, "Select",_select, obj );
179                                                         if (1) // need way to detect if someone has a selection
180                                                                 {
181                                                                         if (ext_mod->editable)
182                                                                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Paste",    _paste, obj );
183                                                                 }
184                                                 }
185         // start for cbhm
186                                                         elm_ctxpopup_item_add(ext_mod->popup, NULL, "More",_clipboard_menu, obj );
187         // end for cbhm
188                                 }
189                 }
190                 EINA_LIST_FOREACH(ext_mod->items, l, it)
191                 {
192                         elm_ctxpopup_item_add(ext_mod->popup, NULL, it->label,_item_clicked, it );
193                 }
194                 if (ext_mod->popup)
195                         {
196                                 _ctxpopup_position(obj);
197                                 evas_object_show(ext_mod->popup);                 
198                         }
199                 }
200         ext_mod->longpress_timer = NULL;
201         }
202
203 EAPI void
204 obj_mouseup(Evas_Object *obj)
205 {
206
207         if (!obj || !ext_mod) {
208                 return;
209         }
210
211 /*update*/
212         elm_entry_extension_module_data_get(obj,ext_mod);
213    if (ext_mod->longpress_timer)
214      {    
215                 if (ext_mod->have_selection )
216                         {                               
217                                 _cancel(obj,ext_mod->popup,NULL);
218                         }
219      }     
220   else
221    {
222                 if (ext_mod->have_selection )
223                         {
224                                 obj_longpress( obj );
225                         }
226    }
227 }
228
229