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