[entry] adding textonly mode to modules
[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         ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
59         ext_mod->cnpinit(data,obj,event_info);
60         elm_cbhm_helper_init(obj);
61         if (ext_mod->textonly)
62                 elm_cbhm_send_raw_data("show0");
63         else
64                 elm_cbhm_send_raw_data("show1");
65         evas_object_hide(ext_mod->popup);
66         // end for cbhm
67 }
68
69 static void
70 _item_clicked(void *data, Evas_Object *obj, void *event_info)
71 {
72    Elm_Entry_Context_Menu_Item *it = data;
73    Evas_Object *obj2 = it->obj;
74
75         if (it->func) it->func(it->data, obj2, NULL);
76         evas_object_hide(ext_mod->popup);
77 }
78
79 // module api funcs needed
80 EAPI int
81 elm_modapi_init(void *m)
82 {
83    return 1; // succeed always
84 }
85
86 EAPI int
87 elm_modapi_shutdown(void *m)
88 {
89    return 1; // succeed always
90 }
91
92 // module fucns for the specific module type
93 EAPI void
94 obj_hook(Evas_Object *obj)
95 {
96         if(!ext_mod)
97                 {
98                         ext_mod = ELM_NEW(Elm_Entry_Extension_data);
99                 elm_entry_extension_module_data_get(obj,ext_mod);
100                 }
101 }
102
103 EAPI void
104 obj_unhook(Evas_Object *obj)
105 {
106    if(ext_mod)
107         {
108                         free(ext_mod);
109                         ext_mod = NULL;
110         }
111 }
112
113 EAPI void
114 obj_longpress(Evas_Object *obj)
115 {               
116         if(!ext_mod) return;
117         Evas_Object *top;
118         Evas_Object *list;
119         
120         const Eina_List *l;
121         const Elm_Entry_Context_Menu_Item *it;
122         /*update*/
123         elm_entry_extension_module_data_get(obj,ext_mod);
124         if (ext_mod->context_menu)
125         {
126                 if (ext_mod->popup) evas_object_del(ext_mod->popup);
127         else elm_widget_scroll_freeze_push(obj);
128                 top = elm_widget_top_get(obj);
129                 if(top)
130                 ext_mod->popup = elm_popup_add(top);
131                 elm_object_style_set(ext_mod->popup,"menustyle");
132                 elm_popup_mode_set(ext_mod->popup, ELM_POPUP_TYPE_ALERT);
133                 elm_popup_title_label_set(ext_mod->popup,"CopyPaste");
134                 list = elm_list_add(ext_mod->popup);
135                 elm_object_style_set(list,"popup");
136                 elm_list_mode_set(list, ELM_LIST_COMPRESS);
137                 elm_widget_sub_object_add(obj, ext_mod->popup);
138                 if (!ext_mod->selmode)
139                 {       
140                         if (!ext_mod->password)
141                                 elm_list_item_append(list, "Select", NULL, NULL,_select, obj);
142                         if (1) // need way to detect if someone has a selection
143                                 {
144                                         if (ext_mod->editable)
145                                                 elm_list_item_append(list, "Paste", NULL, NULL,_paste, obj);
146                                 }
147         //              elm_ctxpopup_item_add(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
148         // start for cbhm
149                         if (!ext_mod->password)
150                                 elm_list_item_append(list, "More", NULL, NULL,_clipboard_menu, obj);
151         // end for cbhm
152                 }
153                 else
154                 {
155                           if (!ext_mod->password)
156                                 {
157                                         if (ext_mod->have_selection)
158                                                 {
159                                                         elm_list_item_append(list, "Copy", NULL, NULL,_copy, obj);
160                                                         if (ext_mod->editable)
161                                                                 elm_list_item_append(list, "Cut", NULL, NULL,_cut, obj);
162                                                 }
163                                         else
164                                                 {
165                                                         _cancel(obj,ext_mod->popup,NULL);               
166                                                         elm_list_item_append(list, "Select", NULL, NULL,_select, obj);
167                                                         if (1) // need way to detect if someone has a selection
168                                                                 {
169                                                                         if (ext_mod->editable)
170                                                                                 elm_list_item_append(list, "Paste", NULL, NULL,_paste, obj);
171                                                                 }
172                                                 }
173         // start for cbhm
174                                         elm_list_item_append(list, "More", NULL, NULL,_clipboard_menu, obj);
175         // end for cbhm
176                                 }
177                 }
178                 EINA_LIST_FOREACH(ext_mod->items, l, it)
179                 {
180                         elm_list_item_append(list, it->label,NULL,NULL, _item_clicked, it);
181                 }
182                 if (ext_mod->popup)
183                 {
184                         elm_list_go(list);
185                         elm_popup_content_set(ext_mod->popup, list);
186                         evas_object_show(ext_mod->popup);              
187                         evas_render( evas_object_evas_get( ext_mod->popup ) );
188                 }
189         }
190         ext_mod->longpress_timer = NULL;
191 }
192
193 EAPI void
194 obj_mouseup(Evas_Object *obj)
195 {
196 /*update*/
197         elm_entry_extension_module_data_get(obj,ext_mod);
198    if (ext_mod->longpress_timer)
199      {          
200                 if (ext_mod->have_selection )
201                         {                               
202                                 _cancel(obj,ext_mod->popup,NULL);
203                         }
204      }     
205 }
206