[entry] made copy paste ctx_popup not dimmed
[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_all(void *data, Evas_Object *obj, void *event_info)
31 {
32    ext_mod->selectall(data,obj,event_info);
33    evas_object_hide(obj);
34 }
35
36 static void
37 _select(void *data, Evas_Object *obj, void *event_info)
38 {
39    ext_mod->select(data,obj,event_info);
40    evas_object_hide(obj);
41 }
42
43 static void
44 _paste(void *data, Evas_Object *obj, void *event_info)
45 {
46         ext_mod->paste(data,obj,event_info);
47         evas_object_hide(obj);
48 }
49
50 static void
51 _cut(void *data, Evas_Object *obj, void *event_info)
52 {
53         ext_mod->cut(data,obj,event_info);
54         evas_object_hide(obj);
55         elm_ctxpopup_scroller_disabled_set(ext_mod->popup, EINA_FALSE);
56 }
57
58 static void
59 _copy(void *data, Evas_Object *obj, void *event_info)
60 {
61         ext_mod->copy(data,obj,event_info);
62         evas_object_hide(obj);
63         elm_ctxpopup_scroller_disabled_set(ext_mod->popup, EINA_FALSE);
64 }
65
66 static void
67 _cancel(void *data, Evas_Object *obj, void *event_info)
68 {
69         ext_mod->cancel(data,obj,event_info);
70         evas_object_hide(obj);
71         elm_ctxpopup_scroller_disabled_set(ext_mod->popup, EINA_FALSE);
72 }
73
74 static void
75 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
76 {
77         // start for cbhm
78         ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
79         ext_mod->cnpinit(data,obj,event_info);
80         elm_cbhm_helper_init(obj);
81         elm_cbhm_send_raw_data("show");
82         evas_object_hide(obj);
83         // end for cbhm
84 }
85
86 static void
87 _item_clicked(void *data, Evas_Object *obj, void *event_info)
88 {
89    Elm_Entry_Context_Menu_Item *it = data;
90    Evas_Object *obj2 = it->obj;
91
92         if (it->func) it->func(it->data, obj2, NULL);
93         evas_object_hide(obj);
94 }
95
96 // module api funcs needed
97 EAPI int
98 elm_modapi_init(void *m)
99 {
100    return 1; // succeed always
101 }
102
103 EAPI int
104 elm_modapi_shutdown(void *m)
105 {
106    return 1; // succeed always
107 }
108
109 // module fucns for the specific module type
110 EAPI void
111 obj_hook(Evas_Object *obj)
112 {
113         if(!ext_mod)
114                 {
115                         ext_mod = ELM_NEW(Elm_Entry_Extension_data);
116                 elm_entry_extension_module_data_get(obj,ext_mod);
117                 }
118 }
119
120 EAPI void
121 obj_unhook(Evas_Object *obj)
122 {
123    if(ext_mod)
124                 {
125                         free(ext_mod);
126                         ext_mod = NULL;
127         }
128 }
129
130 EAPI void
131 obj_longpress(Evas_Object *obj)
132 {       
133         if(!ext_mod) return;
134         Evas_Object *top;
135         const Eina_List *l;
136         const Elm_Entry_Context_Menu_Item *it;
137         const char *context_menu_orientation;
138
139         /*update*/
140         elm_entry_extension_module_data_get(obj,ext_mod);
141         if (ext_mod->context_menu)
142         {
143                 if (ext_mod->popup) evas_object_del(ext_mod->popup);
144 //              else elm_widget_scroll_freeze_push(obj);
145                 top = elm_widget_top_get(obj);
146                 if(top)
147                         ext_mod->popup = elm_ctxpopup_add(top);
148                 /*currently below theme not used,when guideline comes a new theme can be created if required*/
149                 elm_object_style_set(ext_mod->popup,"extended/entry");
150                 elm_ctxpopup_scroller_disabled_set(ext_mod->popup, EINA_TRUE);
151                 context_menu_orientation = edje_object_data_get
152                 (ext_mod->ent, "context_menu_orientation");
153                 if ((context_menu_orientation) &&
154                 (!strcmp(context_menu_orientation, "horizontal")))
155                 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
156                 elm_ctxpopup_screen_dimmed_disabled_set(ext_mod->popup, EINA_TRUE);
157
158                 elm_widget_sub_object_add(obj, ext_mod->popup);
159                 if (!ext_mod->selmode)
160                 {       
161                         if (!ext_mod->password)
162                         {
163                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Select",_select, obj );
164                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Select All",_select_all, obj );
165                         }
166                         if (1) // need way to detect if someone has a selection
167                                 {
168                                         if (ext_mod->editable)
169                                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Paste",_paste, obj );
170                                 }
171         //              elm_ctxpopup_item_add(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
172         // start for cbhm
173                         if (!ext_mod->password)
174                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "More", _clipboard_menu, obj );
175         // end for cbhm
176                 }
177                 else
178                 {
179                           if (!ext_mod->password)
180                                 {
181                                         if (ext_mod->have_selection)
182                                                 {
183                                                         elm_ctxpopup_item_add(ext_mod->popup, NULL, "Copy",_copy, obj );
184                                                         if (ext_mod->editable)
185                                                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Cut",_cut, obj );                                                  
186                                                         if (ext_mod->editable)
187                                                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Paste",_paste, obj );
188                                                 }
189                                         else
190                                                 {
191                                                         _cancel(obj,ext_mod->popup,NULL);               
192                                                         elm_ctxpopup_item_add(ext_mod->popup, NULL, "Select",_select, obj );
193                                                         elm_ctxpopup_item_add(ext_mod->popup, NULL, "Select All",_select_all, obj );
194                                                         if (1) // need way to detect if someone has a selection
195                                                                 {
196                                                                         if (ext_mod->editable)
197                                                                                 elm_ctxpopup_item_add(ext_mod->popup, NULL, "Paste",_paste, obj );
198                                                                 }
199                                                 }
200         // start for cbhm
201                                                         elm_ctxpopup_item_add(ext_mod->popup, NULL, "More",_clipboard_menu, obj );
202         // end for cbhm
203                                 }
204                 }
205                 EINA_LIST_FOREACH(ext_mod->items, l, it)
206                 {
207                         elm_ctxpopup_item_add(ext_mod->popup, NULL, it->label,_item_clicked, it );
208                 }
209                 if (ext_mod->popup)
210                         {
211                                 _ctxpopup_position(obj);
212                                 evas_object_show(ext_mod->popup);                 
213                         }
214                 }
215         ext_mod->longpress_timer = NULL;
216         }
217
218 EAPI void
219 obj_mouseup(Evas_Object *obj)
220 {
221         if (!obj || !ext_mod) {
222                 return;
223         }
224
225 /*update*/
226         elm_entry_extension_module_data_get(obj,ext_mod);
227    if (ext_mod->longpress_timer)
228      {    
229                 if (ext_mod->have_selection )
230                         {                               
231                                 _cancel(obj,ext_mod->popup,NULL);
232                         }
233      }     
234 }
235
236
237 EAPI void
238 obj_hidemenu(Evas_Object *obj)
239 {
240         if (!obj || !ext_mod) {
241                 return;
242         }
243
244         evas_object_hide(ext_mod->popup);
245 //      if (ext_mod->popup) evas_object_del(ext_mod->popup);
246 }
247
248