1 #include <Elementary.h>
2 #include "elm_module_priv.h"
5 Elm_Entry_Extension_data *ext_mod;
6 static int _mod_hook_count = 0;
8 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
9 struct _Elm_Entry_Context_Menu_Item
13 const char *icon_file;
14 const char *icon_group;
15 Elm_Icon_Type icon_type;
21 _ctxpopup_position(Evas_Object *obj)
25 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
26 evas_object_geometry_get(ext_mod->ent, &x, &y, NULL, NULL);
27 edje_object_part_text_cursor_geometry_get(ext_mod->ent, "elm.text",
29 evas_object_size_hint_min_get(ext_mod->popup, &mw, &mh);
40 evas_object_move(ext_mod->popup, x + cx, y + cy);
41 evas_object_resize(ext_mod->popup, cw, ch);
45 _select_all(void *data, Evas_Object *obj, void *event_info)
49 ext_mod->selectall(data,obj,event_info);
50 evas_object_hide(obj);
54 _select(void *data, Evas_Object *obj, void *event_info)
58 ext_mod->select(data,obj,event_info);
59 evas_object_hide(obj);
63 _paste(void *data, Evas_Object *obj, void *event_info)
67 ext_mod->paste(data,obj,event_info);
68 evas_object_hide(obj);
72 _cut(void *data, Evas_Object *obj, void *event_info)
76 ext_mod->cut(data,obj,event_info);
77 evas_object_hide(obj);
78 elm_object_scroll_freeze_pop(ext_mod->popup);
82 _copy(void *data, Evas_Object *obj, void *event_info)
86 ext_mod->copy(data,obj,event_info);
87 evas_object_hide(obj);
88 elm_object_scroll_freeze_pop(ext_mod->popup);
92 _cancel(void *data, Evas_Object *obj, void *event_info)
96 ext_mod->cancel(data,obj,event_info);
97 evas_object_hide(obj);
98 elm_object_scroll_freeze_pop(ext_mod->popup);
102 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
107 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
108 ext_mod->cnpinit(data,obj,event_info);
109 elm_cbhm_helper_init(obj);
110 if (ext_mod->textonly)
111 elm_cbhm_send_raw_data("show0");
113 elm_cbhm_send_raw_data("show1");
114 evas_object_hide(obj);
119 _item_clicked(void *data, Evas_Object *obj, void *event_info)
121 Elm_Entry_Context_Menu_Item *it = data;
122 Evas_Object *obj2 = it->obj;
124 if (it->func) it->func(it->data, obj2, NULL);
125 evas_object_hide(obj);
129 _ctxpopup_dismissed_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
131 if (!ext_mod) return;
133 elm_object_scroll_freeze_pop(ext_mod->popup);
136 // module api funcs needed
138 elm_modapi_init(void *m)
140 return 1; // succeed always
144 elm_modapi_shutdown(void *m)
146 return 1; // succeed always
149 // module funcs for the specific module type
151 obj_hook(Evas_Object *obj)
154 //if(_mod_hook_count > 1) return;
158 ext_mod = ELM_NEW(Elm_Entry_Extension_data);
159 elm_entry_extension_module_data_get(obj,ext_mod);
164 obj_unhook(Evas_Object *obj)
167 if(_mod_hook_count > 0) return;
177 obj_longpress(Evas_Object *obj)
183 const Elm_Entry_Context_Menu_Item *it;
184 const char *context_menu_orientation;
189 elm_entry_extension_module_data_get(obj,ext_mod);
190 if (ext_mod->context_menu)
192 if (ext_mod->popup) evas_object_del(ext_mod->popup);
193 //else elm_widget_scroll_freeze_push(obj);
194 top = elm_widget_top_get(obj);
197 ext_mod->popup = elm_ctxpopup_add(top);
198 evas_object_smart_callback_add(ext_mod->popup, "dismissed", _ctxpopup_dismissed_cb, NULL);
200 /*currently below theme not used,when guideline comes a new theme can be created if required*/
201 elm_object_style_set(ext_mod->popup,"extended/entry");
202 context_menu_orientation = edje_object_data_get
203 (ext_mod->ent, "context_menu_orientation");
204 if ((context_menu_orientation) &&
205 (!strcmp(context_menu_orientation, "horizontal")))
206 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
208 elm_widget_sub_object_add(obj, ext_mod->popup);
209 if (!ext_mod->selmode)
211 if (!ext_mod->password)
213 if (!elm_entry_is_empty(obj))
215 elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
216 elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
219 if (1) // need way to detect if someone has a selection
221 if (ext_mod->editable)
222 elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
224 //elm_ctxpopup_item_append(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
226 if ((!ext_mod->password) && (ext_mod->editable))
228 icon = elm_icon_add(ext_mod->popup);
229 snprintf(buf, sizeof(buf), "%s/images/copypaste_icon_clipboard.png", PACKAGE_DATA_DIR);
230 elm_icon_file_set(icon, buf, NULL);
231 elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _clipboard_menu, obj);
232 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
238 if (!ext_mod->password)
240 if (ext_mod->have_selection)
242 elm_ctxpopup_item_append(ext_mod->popup, "Copy", NULL, _copy, obj );
243 if (ext_mod->editable)
244 elm_ctxpopup_item_append(ext_mod->popup, "Cut", NULL, _cut, obj );
245 if (ext_mod->editable)
246 elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
250 _cancel(obj,ext_mod->popup,NULL);
251 if (!elm_entry_is_empty(obj))
253 elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
254 elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
256 if (1) // need way to detect if someone has a selection
258 if (ext_mod->editable)
259 elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
263 if (ext_mod->editable)
265 icon = elm_icon_add(ext_mod->popup);
266 snprintf(buf, sizeof(buf), "%s/images/copypaste_icon_clipboard.png", PACKAGE_DATA_DIR);
267 elm_icon_file_set(icon, buf, NULL);
268 elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _clipboard_menu, obj);
269 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
274 EINA_LIST_FOREACH(ext_mod->items, l, it)
276 elm_ctxpopup_item_append(ext_mod->popup, it->label, NULL, _item_clicked, it );
280 elm_object_scroll_freeze_push(ext_mod->popup);
281 _ctxpopup_position(obj);
282 evas_object_show(ext_mod->popup);
285 ext_mod->longpress_timer = NULL;
289 obj_mouseup(Evas_Object *obj)
291 if (!obj || !ext_mod) {
296 elm_entry_extension_module_data_get(obj,ext_mod);
297 if (ext_mod->longpress_timer)
299 if (ext_mod->have_selection )
301 _cancel(obj,ext_mod->popup,NULL);
308 obj_hidemenu(Evas_Object *obj)
310 if (!obj || !ext_mod) {
314 evas_object_hide(ext_mod->popup);
315 // if (ext_mod->popup) evas_object_del(ext_mod->popup);