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 _item_clicked(void *data, Evas_Object *obj, void *event_info)
69 {
70    Elm_Entry_Context_Menu_Item *it = data;
71    Evas_Object *obj2 = it->obj;
72
73         if (it->func) it->func(it->data, obj2, NULL);
74         // start for cbhm
75         if (!strcmp(it->label, "Menu"))
76         {
77                 elm_cbhm_helper_init(obj);
78                 elm_cbhm_send_raw_data("show");
79         }
80         // end for cbhm
81         evas_object_hide(obj);
82 }
83
84 // module api funcs needed
85 EAPI int
86 elm_modapi_init(void *m)
87 {
88    return 1; // succeed always
89 }
90
91 EAPI int
92 elm_modapi_shutdown(void *m)
93 {
94    return 1; // succeed always
95 }
96
97 // module fucns for the specific module type
98 EAPI void
99 obj_hook(Evas_Object *obj)
100 {
101         if(!ext_mod)
102                 {
103                         ext_mod = ELM_NEW(Elm_Entry_Extension_data);
104                 elm_entry_extension_module_data_get(obj,ext_mod);
105                 }
106 }
107
108 EAPI void
109 obj_unhook(Evas_Object *obj)
110 {
111    if(ext_mod)
112                 {
113                         free(ext_mod);
114                         ext_mod = NULL;
115         }
116 }
117
118 EAPI void
119 obj_longpress(Evas_Object *obj)
120 {               
121         if(!ext_mod) return;
122         Evas_Object *top;
123         const Eina_List *l;
124         const Elm_Entry_Context_Menu_Item *it;
125         const char *context_menu_orientation;
126
127         /*update*/
128         elm_entry_extension_module_data_get(obj,ext_mod);
129         if (ext_mod->context_menu)
130         {
131                 if (ext_mod->popup) evas_object_del(ext_mod->popup);
132         else elm_widget_scroll_freeze_push(obj);
133                 top = elm_widget_top_get(obj);
134                 if(top)
135                         ext_mod->popup = elm_ctxpopup_add(top);
136                 /*currently below theme not used,when guideline comes a new theme can be created if required*/
137                 //elm_object_style_set(ext_mod->popup,"entry");
138                 elm_ctxpopup_scroller_disabled_set(ext_mod->popup, EINA_TRUE);
139                 context_menu_orientation = edje_object_data_get
140                 (ext_mod->ent, "context_menu_orientation");
141                 if ((context_menu_orientation) &&
142                 (!strcmp(context_menu_orientation, "horizontal")))
143                 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
144
145                 elm_widget_sub_object_add(obj, ext_mod->popup);
146                 if (!ext_mod->selmode)
147                 {       
148                         if (!ext_mod->password)
149                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Select",_select, obj );
150                         if (1) // need way to detect if someone has a selection
151                                 {
152                                         if (ext_mod->editable)
153                                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Paste",    _paste, obj );
154                                 }
155         //              elm_ctxpopup_item_add(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
156                 }
157                 else
158                 {
159                           if (!ext_mod->password)
160                                 {
161                                         if (ext_mod->have_selection)
162                                                 {
163                                                         elm_ctxpopup_item_add(ext_mod->popup, NULL, "Copy",_copy, obj );
164                                                         if (ext_mod->editable)
165                                                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Cut",_cut, obj );                                                  
166                                                 }
167                                         else
168                                                 {
169                                                         _cancel(obj,ext_mod->popup,NULL);               
170                                                         elm_ctxpopup_item_add(ext_mod->popup, NULL, "Select",_select, obj );
171                                                         if (1) // need way to detect if someone has a selection
172                                                                 {
173                                                                         if (ext_mod->editable)
174                                                                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Paste",    _paste, obj );
175                                                                 }
176                                                 }
177                                 }
178                 }
179                 EINA_LIST_FOREACH(ext_mod->items, l, it)
180                 {
181                         elm_ctxpopup_item_add(ext_mod->popup, NULL, it->label,_item_clicked, it );
182                 }
183                 if (ext_mod->popup)
184                         {
185                                 _ctxpopup_position(obj);
186                                 evas_object_show(ext_mod->popup);                 
187                         }
188                 }
189         ext_mod->longpress_timer = NULL;
190         }
191
192 EAPI void
193 obj_mouseup(Evas_Object *obj)
194 {
195
196         if (!obj || !ext_mod) {
197                 return;
198         }
199
200 /*update*/
201         elm_entry_extension_module_data_get(obj,ext_mod);
202    if (ext_mod->longpress_timer)
203      {    
204                 if (ext_mod->have_selection )
205                         {                               
206                                 _cancel(obj,ext_mod->popup,NULL);
207                         }
208      }     
209   else
210    {
211                 if (ext_mod->have_selection )
212                         {
213                                 obj_longpress( obj );
214                         }
215    }
216 }
217
218