381f7118d1096c5add2f6bc73655f09297cfe372
[framework/uifw/elementary.git] / src / modules / popup_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 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
7 struct _Elm_Entry_Context_Menu_Item
8 {
9    Evas_Object *obj;
10    const char *label;
11    const char *icon_file;
12    const char *icon_group;
13    Elm_Icon_Type icon_type;
14    Evas_Smart_Cb func;
15    void *data;
16 };
17
18
19 static void
20 _select(void *data, Evas_Object *obj, void *event_info)
21 {
22    ext_mod->select(data,obj,event_info);
23    evas_object_hide(ext_mod->popup);
24 }
25
26 static void
27 _paste(void *data, Evas_Object *obj, void *event_info)
28 {
29         ext_mod->paste(data,obj,event_info);
30    evas_object_hide(ext_mod->popup);
31 }
32
33 static void
34 _cut(void *data, Evas_Object *obj, void *event_info)
35 {
36         ext_mod->cut(data,obj,event_info);
37         evas_object_hide(ext_mod->popup);
38 }
39
40 static void
41 _copy(void *data, Evas_Object *obj, void *event_info)
42 {
43         ext_mod->copy(data,obj,event_info);
44         evas_object_hide(ext_mod->popup);
45 }
46
47 static void
48 _cancel(void *data, Evas_Object *obj, void *event_info)
49 {
50         ext_mod->cancel(data,obj,event_info);
51    evas_object_hide(ext_mod->popup);
52 }
53
54 static void
55 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
56 {
57    // start for cbhm
58 #ifdef HAVE_ELEMENTARY_X
59    ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
60 #endif
61    ext_mod->cnpinit(data,obj,event_info);
62    elm_cbhm_helper_init(obj);
63    if (ext_mod->cnp_mode != ELM_CNP_MODE_MARKUP)
64      elm_cbhm_send_raw_data("show0");
65    else
66      elm_cbhm_send_raw_data("show1");
67    evas_object_hide(ext_mod->popup);
68    // end for cbhm
69 }
70
71 static void
72 _item_clicked(void *data, Evas_Object *obj, void *event_info)
73 {
74    Elm_Entry_Context_Menu_Item *it = data;
75    Evas_Object *obj2 = it->obj;
76
77         if (it->func) it->func(it->data, obj2, NULL);
78         evas_object_hide(ext_mod->popup);
79 }
80
81 // module api funcs needed
82 EAPI int
83 elm_modapi_init(void *m)
84 {
85    return 1; // succeed always
86 }
87
88 EAPI int
89 elm_modapi_shutdown(void *m)
90 {
91    return 1; // succeed always
92 }
93
94 // module fucns for the specific module type
95 EAPI void
96 obj_hook(Evas_Object *obj)
97 {
98         if(!ext_mod)
99                 {
100                         ext_mod = ELM_NEW(Elm_Entry_Extension_data);
101                 elm_entry_extension_module_data_get(obj,ext_mod);
102                 }
103 }
104
105 EAPI void
106 obj_unhook(Evas_Object *obj)
107 {
108    if(ext_mod)
109         {
110                         free(ext_mod);
111                         ext_mod = NULL;
112         }
113 }
114
115 EAPI void
116 obj_longpress(Evas_Object *obj)
117 {
118         if(!ext_mod) return;
119         Evas_Object *top;
120         Evas_Object *list;
121
122         const Eina_List *l;
123         const Elm_Entry_Context_Menu_Item *it;
124         /*update*/
125         elm_entry_extension_module_data_get(obj,ext_mod);
126         if (ext_mod->context_menu)
127         {
128                 if (ext_mod->popup) evas_object_del(ext_mod->popup);
129         else elm_widget_scroll_freeze_push(obj);
130                 top = elm_widget_top_get(obj);
131                 if(top)
132                 ext_mod->popup = elm_popup_add(top);
133                 elm_object_style_set(ext_mod->popup,"menustyle");
134                 elm_popup_mode_set(ext_mod->popup, ELM_POPUP_TYPE_ALERT);
135                 elm_popup_title_label_set(ext_mod->popup,"CopyPaste");
136                 list = elm_list_add(ext_mod->popup);
137                 elm_object_style_set(list,"popup");
138                 elm_list_mode_set(list, ELM_LIST_COMPRESS);
139                 elm_widget_sub_object_add(obj, ext_mod->popup);
140                 if (!ext_mod->selmode)
141                 {
142                         if (!ext_mod->password)
143                                 elm_list_item_append(list, "Select", NULL, NULL,_select, obj);
144                         if (1) // need way to detect if someone has a selection
145                                 {
146                                         if (ext_mod->editable)
147                                                 elm_list_item_append(list, "Paste", NULL, NULL,_paste, obj);
148                                 }
149         //              elm_ctxpopup_item_add(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
150         // start for cbhm
151                         if ((!ext_mod->password) && (ext_mod->editable))
152                                 elm_list_item_append(list, "More", NULL, NULL,_clipboard_menu, obj);
153         // end for cbhm
154                 }
155                 else
156                 {
157                           if (!ext_mod->password)
158                                 {
159                                         if (ext_mod->have_selection)
160                                                 {
161                                                         elm_list_item_append(list, "Copy", NULL, NULL,_copy, obj);
162                                                         if (ext_mod->editable)
163                                                                 elm_list_item_append(list, "Cut", NULL, NULL,_cut, obj);
164                                                 }
165                                         else
166                                                 {
167                                                         _cancel(obj,ext_mod->popup,NULL);
168                                                         elm_list_item_append(list, "Select", NULL, NULL,_select, obj);
169                                                         if (1) // need way to detect if someone has a selection
170                                                                 {
171                                                                         if (ext_mod->editable)
172                                                                                 elm_list_item_append(list, "Paste", NULL, NULL,_paste, obj);
173                                                                 }
174                                                 }
175         // start for cbhm
176                                         if (ext_mod->editable)
177                                                 elm_list_item_append(list, "More", NULL, NULL,_clipboard_menu, obj);
178         // end for cbhm
179                                 }
180                 }
181                 EINA_LIST_FOREACH(ext_mod->items, l, it)
182                 {
183                         elm_list_item_append(list, it->label,NULL,NULL, _item_clicked, it);
184                 }
185                 if (ext_mod->popup)
186                 {
187                         elm_list_go(list);
188                         elm_popup_content_set(ext_mod->popup, list);
189                         evas_object_show(ext_mod->popup);
190                         evas_render( evas_object_evas_get( ext_mod->popup ) );
191                 }
192         }
193 }
194
195 EAPI void
196 obj_mouseup(Evas_Object *obj)
197 {
198 /*update*/
199         elm_entry_extension_module_data_get(obj,ext_mod);
200 }
201