Merge "[TickerNoti] Modified to remove signal6 error. Review comments are taken...
[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 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
8 struct _Elm_Entry_Context_Menu_Item
9 {
10    Evas_Object *obj;
11    const char *label;
12    const char *icon_file;
13    const char *icon_group;
14    Elm_Icon_Type icon_type;
15    Evas_Smart_Cb func;
16    void *data;
17 };
18
19 static void
20 _ctxpopup_position(Evas_Object *obj)
21 {
22    Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
23    evas_object_geometry_get(ext_mod->ent, &x, &y, NULL, NULL);
24    edje_object_part_text_cursor_geometry_get(ext_mod->ent, "elm.text",
25                                              &cx, &cy, &cw, &ch);
26    evas_object_size_hint_min_get(ext_mod->popup, &mw, &mh);
27    if (cw < mw)
28      {
29         cx += (cw - mw) / 2;
30         cw = mw;
31      }
32    if (ch < mh)
33      {
34         cy += (ch - mh) / 2;
35         ch = mh;
36      }
37    evas_object_move(ext_mod->popup, x + cx, y + cy);
38    evas_object_resize(ext_mod->popup, cw, ch);
39 }
40
41 static void
42 _select_all(void *data, Evas_Object *obj, void *event_info)
43 {
44    ext_mod->selectall(data,obj,event_info);
45    evas_object_hide(obj);
46 }
47
48 static void
49 _select(void *data, Evas_Object *obj, void *event_info)
50 {
51    ext_mod->select(data,obj,event_info);
52    evas_object_hide(obj);
53 }
54
55 static void
56 _paste(void *data, Evas_Object *obj, void *event_info)
57 {
58         ext_mod->paste(data,obj,event_info);
59         evas_object_hide(obj);
60 }
61
62 static void
63 _cut(void *data, Evas_Object *obj, void *event_info)
64 {
65         ext_mod->cut(data,obj,event_info);
66         evas_object_hide(obj);
67         elm_object_scroll_freeze_pop(ext_mod->popup);
68 }
69
70 static void
71 _copy(void *data, Evas_Object *obj, void *event_info)
72 {
73         ext_mod->copy(data,obj,event_info);
74         evas_object_hide(obj);
75         elm_object_scroll_freeze_pop(ext_mod->popup);
76 }
77
78 static void
79 _cancel(void *data, Evas_Object *obj, void *event_info)
80 {
81         ext_mod->cancel(data,obj,event_info);
82         evas_object_hide(obj);
83         elm_object_scroll_freeze_pop(ext_mod->popup);
84 }
85
86 static void
87 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
88 {
89         // start for cbhm
90         ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
91         ext_mod->cnpinit(data,obj,event_info);
92         elm_cbhm_helper_init(obj);
93         if (ext_mod->textonly)
94                 elm_cbhm_send_raw_data("show0");
95         else
96                 elm_cbhm_send_raw_data("show1");
97         evas_object_hide(obj);
98         // end for cbhm
99 }
100
101 static void
102 _item_clicked(void *data, Evas_Object *obj, void *event_info)
103 {
104    Elm_Entry_Context_Menu_Item *it = data;
105    Evas_Object *obj2 = it->obj;
106
107         if (it->func) it->func(it->data, obj2, NULL);
108         evas_object_hide(obj);
109 }
110
111 // module api funcs needed
112 EAPI int
113 elm_modapi_init(void *m)
114 {
115    return 1; // succeed always
116 }
117
118 EAPI int
119 elm_modapi_shutdown(void *m)
120 {
121    return 1; // succeed always
122 }
123
124 // module fucns for the specific module type
125 EAPI void
126 obj_hook(Evas_Object *obj)
127 {
128         if(!ext_mod)
129                 {
130                         ext_mod = ELM_NEW(Elm_Entry_Extension_data);
131                 elm_entry_extension_module_data_get(obj,ext_mod);
132                 }
133 }
134
135 EAPI void
136 obj_unhook(Evas_Object *obj)
137 {
138    if(ext_mod)
139                 {
140                         free(ext_mod);
141                         ext_mod = NULL;
142         }
143 }
144
145 EAPI void
146 obj_longpress(Evas_Object *obj)
147 {       
148         if(!ext_mod) return;
149         Evas_Object *top;
150         const Eina_List *l;
151         const Elm_Entry_Context_Menu_Item *it;
152         const char *context_menu_orientation;
153         char buf[255];
154         Evas_Object* icon;
155
156         /*update*/
157         elm_entry_extension_module_data_get(obj,ext_mod);
158         if (ext_mod->context_menu)
159         {
160                 if (ext_mod->popup) evas_object_del(ext_mod->popup);
161 //              else elm_widget_scroll_freeze_push(obj);
162                 top = elm_widget_top_get(obj);
163                 if(top)
164                         ext_mod->popup = elm_ctxpopup_add(top);
165                 /*currently below theme not used,when guideline comes a new theme can be created if required*/
166                 elm_object_style_set(ext_mod->popup,"extended/entry");
167                 context_menu_orientation = edje_object_data_get
168                 (ext_mod->ent, "context_menu_orientation");
169                 if ((context_menu_orientation) &&
170                 (!strcmp(context_menu_orientation, "horizontal")))
171                 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
172
173                 elm_widget_sub_object_add(obj, ext_mod->popup);
174                 if (!ext_mod->selmode)
175                 {       
176                         if (!ext_mod->password)
177                         {
178                                 elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
179                                 elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
180                         }
181                         if (1) // need way to detect if someone has a selection
182                                 {
183                                         if (ext_mod->editable)
184                                                 elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
185                                 }
186         //              elm_ctxpopup_item_append(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
187         // start for cbhm
188                         if (!ext_mod->password)
189                         {
190                                 icon = elm_icon_add(ext_mod->popup);
191                                 snprintf(buf, sizeof(buf), "%s/images/copypaste_icon_clipboard.png", PACKAGE_DATA_DIR);
192                                 elm_icon_file_set(icon, buf, NULL);
193                                 elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _clipboard_menu, obj);
194                                 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
195                         }
196         // end for cbhm
197                 }
198                 else
199                 {
200                           if (!ext_mod->password)
201                                 {
202                                         if (ext_mod->have_selection)
203                                                 {
204                                                         elm_ctxpopup_item_append(ext_mod->popup, "Copy", NULL, _copy, obj );
205                                                         if (ext_mod->editable)
206                                                                 elm_ctxpopup_item_append(ext_mod->popup, "Cut", NULL, _cut, obj );                                                      
207                                                         if (ext_mod->editable)
208                                                                 elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
209                                                 }
210                                         else
211                                                 {
212                                                         _cancel(obj,ext_mod->popup,NULL);               
213                                                         elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
214                                                         elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
215                                                         if (1) // need way to detect if someone has a selection
216                                                                 {
217                                                                         if (ext_mod->editable)
218                                                                                 elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
219                                                                 }
220                                                 }
221         // start for cbhm
222                                         icon = elm_icon_add(ext_mod->popup);
223                                         snprintf(buf, sizeof(buf), "%s/images/copypaste_icon_clipboard.png", PACKAGE_DATA_DIR);
224                                         elm_icon_file_set(icon, buf, NULL);
225                                         elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _clipboard_menu, obj);
226                                         //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
227         // end for cbhm
228                                 }
229                 }
230                 EINA_LIST_FOREACH(ext_mod->items, l, it)
231                 {
232                         elm_ctxpopup_item_append(ext_mod->popup, it->label, NULL, _item_clicked, it );
233                 }
234                 if (ext_mod->popup)
235                         {
236                                 elm_object_scroll_freeze_push(ext_mod->popup);
237                                 _ctxpopup_position(obj);
238                                 evas_object_show(ext_mod->popup);                 
239                         }
240                 }
241         ext_mod->longpress_timer = NULL;
242         }
243
244 EAPI void
245 obj_mouseup(Evas_Object *obj)
246 {
247         if (!obj || !ext_mod) {
248                 return;
249         }
250
251 /*update*/
252         elm_entry_extension_module_data_get(obj,ext_mod);
253    if (ext_mod->longpress_timer)
254      {    
255                 if (ext_mod->have_selection )
256                         {                               
257                                 _cancel(obj,ext_mod->popup,NULL);
258                         }
259      }     
260 }
261
262
263 EAPI void
264 obj_hidemenu(Evas_Object *obj)
265 {
266         if (!obj || !ext_mod) {
267                 return;
268         }
269
270         evas_object_hide(ext_mod->popup);
271 //      if (ext_mod->popup) evas_object_del(ext_mod->popup);
272 }
273
274