[entry]: 2 or more entry, on entry deletion crash issue resolved.
[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 }
49
50 static void
51 _copy(void *data, Evas_Object *obj, void *event_info)
52 {
53         ext_mod->copy(data,obj,event_info);
54         evas_object_hide(obj);
55 }
56
57 static void
58 _cancel(void *data, Evas_Object *obj, void *event_info)
59 {
60         ext_mod->cancel(data,obj,event_info);
61    evas_object_hide(obj);
62 }
63
64 static void
65 _item_clicked(void *data, Evas_Object *obj, void *event_info)
66 {
67    Elm_Entry_Context_Menu_Item *it = data;
68    Evas_Object *obj2 = it->obj;
69
70         if (it->func) it->func(it->data, obj2, NULL);
71         evas_object_hide(obj);
72 }
73
74 // module api funcs needed
75 EAPI int
76 elm_modapi_init(void *m)
77 {
78    return 1; // succeed always
79 }
80
81 EAPI int
82 elm_modapi_shutdown(void *m)
83 {
84    return 1; // succeed always
85 }
86
87 // module fucns for the specific module type
88 EAPI void
89 obj_hook(Evas_Object *obj)
90 {
91         if(!ext_mod)
92                 {
93                         ext_mod = ELM_NEW(Elm_Entry_Extension_data);
94                 elm_entry_extension_module_data_get(obj,ext_mod);
95                 }
96 }
97
98 EAPI void
99 obj_unhook(Evas_Object *obj)
100 {
101    if(ext_mod)
102                 {
103                         free(ext_mod);
104                         ext_mod = NULL;
105         }
106 }
107
108 EAPI void
109 obj_longpress(Evas_Object *obj)
110 {               
111         if(!ext_mod) return;
112         Evas_Object *top;
113         const Eina_List *l;
114         const Elm_Entry_Context_Menu_Item *it;
115         const char *context_menu_orientation;
116
117         /*update*/
118         elm_entry_extension_module_data_get(obj,ext_mod);
119
120         if (ext_mod->popup) evas_object_del(ext_mod->popup);
121        else elm_widget_scroll_freeze_push(obj);
122         top = elm_widget_top_get(obj);
123         if(top)
124                 ext_mod->popup = elm_ctxpopup_add(top);
125         elm_object_style_set(ext_mod->popup,"entry");
126         elm_ctxpopup_scroller_disabled_set(ext_mod->popup, EINA_TRUE);
127         context_menu_orientation = edje_object_data_get
128         (ext_mod->ent, "context_menu_orientation");
129         if ((context_menu_orientation) &&
130         (!strcmp(context_menu_orientation, "horizontal")))
131                 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
132
133         elm_widget_sub_object_add(obj, ext_mod->popup);
134         if (!ext_mod->selmode)
135                 {       
136                         if (!ext_mod->password)
137                                 elm_ctxpopup_label_add(ext_mod->popup, "Select",_select, obj );
138                         if (1) // need way to detect if someone has a selection
139                                 {
140                                         if (ext_mod->editable)
141                                                 elm_ctxpopup_label_add(ext_mod->popup, "Paste", _paste, obj );
142                                 }
143         //              elm_ctxpopup_label_add(wd->ctxpopup, "Selectall",_select_all, obj );
144                 }
145         else
146                 {
147                           if (!ext_mod->password)
148                                 {
149                                         if (ext_mod->have_selection)
150                                                 {
151                                                         elm_ctxpopup_label_add(ext_mod->popup, "Copy",_copy, obj );
152                                                         if (ext_mod->editable)
153                                                                 elm_ctxpopup_label_add(ext_mod->popup, "Cut",_cut, obj );                                                       
154                                                 }
155                                         else
156                                                 {
157                                                         _cancel(obj,ext_mod->popup,NULL);               
158                                                         elm_ctxpopup_label_add(ext_mod->popup, "Select",_select, obj );
159                                                         if (1) // need way to detect if someone has a selection
160                                                                 {
161                                                                         if (ext_mod->editable)
162                                                                                 elm_ctxpopup_label_add(ext_mod->popup, "Paste", _paste, obj );
163                                                                 }
164                                                 }
165                                 }
166                 }
167                 EINA_LIST_FOREACH(ext_mod->items, l, it)
168                 {
169                         elm_ctxpopup_label_add(ext_mod->popup, it->label,_item_clicked, it );
170                 }
171         if (ext_mod->popup)
172                 {
173                         _ctxpopup_position(obj);
174                         evas_object_show(ext_mod->popup);                 
175                 }
176                 ext_mod->longpress_timer = NULL;
177         }
178
179 EAPI void
180 obj_mouseup(Evas_Object *obj)
181 {
182 /*update*/
183         elm_entry_extension_module_data_get(obj,ext_mod);
184    if (ext_mod->longpress_timer)
185      {    
186                 if (ext_mod->have_selection )
187                         {                               
188                                 _cancel(obj,ext_mod->popup,NULL);
189                         }
190      }     
191   else
192    {
193                 if (ext_mod->have_selection )
194                         {
195                                 obj_longpress( obj );
196                         }
197    }
198 }
199
200