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, w, h;
26 if (!edje_object_part_text_selection_geometry_get(ext_mod->ent, "elm.text", &x, &y, &w, &h))
28 evas_object_geometry_get(ext_mod->ent, &x, &y, NULL, NULL);
29 edje_object_part_text_cursor_geometry_get(ext_mod->ent, "elm.text",
31 evas_object_size_hint_min_get(ext_mod->popup, &w, &h);
42 evas_object_move(ext_mod->popup, x + cx, y + cy);
43 evas_object_resize(ext_mod->popup, cw, ch);
47 if (ext_mod->viewport_obj)
49 Evas_Coord vx, vy, vw, vh, x2, y2;
52 evas_object_geometry_get(ext_mod->viewport_obj, &vx, &vy, &vw, &vh);
55 if (x2 > vx + vw) x2 = vx + vw;
56 if (y2 > vy + vh) y2 = vy + vh;
62 evas_object_move(ext_mod->popup, cx, cy);
67 _select_all(void *data, Evas_Object *obj, void *event_info)
71 ext_mod->selectall(data,obj,event_info);
72 evas_object_hide(obj);
76 _select(void *data, Evas_Object *obj, void *event_info)
80 ext_mod->select(data,obj,event_info);
81 evas_object_hide(obj);
85 _paste(void *data, Evas_Object *obj, void *event_info)
89 ext_mod->paste(data,obj,event_info);
90 evas_object_hide(obj);
94 _cut(void *data, Evas_Object *obj, void *event_info)
98 ext_mod->cut(data,obj,event_info);
99 evas_object_hide(obj);
100 elm_object_scroll_freeze_pop(ext_mod->popup);
104 _copy(void *data, Evas_Object *obj, void *event_info)
108 ext_mod->copy(data,obj,event_info);
109 evas_object_hide(obj);
110 elm_object_scroll_freeze_pop(ext_mod->popup);
114 _cancel(void *data, Evas_Object *obj, void *event_info)
118 ext_mod->cancel(data,obj,event_info);
119 evas_object_hide(obj);
120 elm_object_scroll_freeze_pop(ext_mod->popup);
124 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
129 #ifdef HAVE_ELEMENTARY_X
130 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
132 ext_mod->cnpinit(data,obj,event_info);
133 elm_cbhm_helper_init(obj);
134 if (ext_mod->textonly)
135 elm_cbhm_send_raw_data("show0");
137 elm_cbhm_send_raw_data("show1");
138 evas_object_hide(obj);
143 _item_clicked(void *data, Evas_Object *obj, void *event_info)
145 Elm_Entry_Context_Menu_Item *it = data;
146 Evas_Object *obj2 = it->obj;
148 if (it->func) it->func(it->data, obj2, NULL);
149 evas_object_hide(obj);
153 _ctxpopup_dismissed_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
155 if (!ext_mod) return;
157 elm_object_scroll_freeze_pop(ext_mod->popup);
160 // module api funcs needed
162 elm_modapi_init(void *m)
164 return 1; // succeed always
168 elm_modapi_shutdown(void *m)
170 return 1; // succeed always
173 // module funcs for the specific module type
175 obj_hook(Evas_Object *obj)
178 //if(_mod_hook_count > 1) return;
182 ext_mod = ELM_NEW(Elm_Entry_Extension_data);
183 elm_entry_extension_module_data_get(obj,ext_mod);
188 obj_unhook(Evas_Object *obj)
191 if(_mod_hook_count > 0) return;
201 obj_longpress(Evas_Object *obj)
207 const Elm_Entry_Context_Menu_Item *it;
208 const char *context_menu_orientation;
213 elm_entry_extension_module_data_get(obj,ext_mod);
214 if (ext_mod->context_menu)
216 #ifdef HAVE_ELEMENTARY_X
218 if (elm_cbhm_helper_init(obj))
219 cbhm_count = elm_cbhm_get_count();
221 if (ext_mod->popup) evas_object_del(ext_mod->popup);
222 //else elm_widget_scroll_freeze_push(obj);
223 top = elm_widget_top_get(obj);
226 ext_mod->popup = elm_ctxpopup_add(top);
227 elm_object_tree_unfocusable_set(ext_mod->popup, EINA_TRUE);
228 evas_object_smart_callback_add(ext_mod->popup, "dismissed", _ctxpopup_dismissed_cb, NULL);
230 /*currently below theme not used,when guideline comes a new theme can be created if required*/
231 elm_object_style_set(ext_mod->popup,"extended/entry");
232 context_menu_orientation = edje_object_data_get
233 (ext_mod->ent, "context_menu_orientation");
234 if ((context_menu_orientation) &&
235 (!strcmp(context_menu_orientation, "horizontal")))
236 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
238 elm_widget_sub_object_add(obj, ext_mod->popup);
239 if (!ext_mod->selmode)
241 if (!ext_mod->password)
243 if (!elm_entry_is_empty(obj))
245 elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
246 elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
249 if (1) // need way to detect if someone has a selection
251 if (ext_mod->editable)
252 elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
254 //elm_ctxpopup_item_append(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
256 #ifdef HAVE_ELEMENTARY_X
257 if ((!ext_mod->password) && (ext_mod->editable) && (cbhm_count))
259 if ((!ext_mod->password) && (ext_mod->editable))
262 icon = elm_icon_add(ext_mod->popup);
263 snprintf(buf, sizeof(buf), "%s/images/copypaste_icon_clipboard.png", PACKAGE_DATA_DIR);
264 elm_icon_file_set(icon, buf, NULL);
265 elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _clipboard_menu, obj);
266 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
272 if (!ext_mod->password)
274 if (ext_mod->have_selection)
276 elm_ctxpopup_item_append(ext_mod->popup, "Copy", NULL, _copy, obj );
277 if (ext_mod->editable)
278 elm_ctxpopup_item_append(ext_mod->popup, "Cut", NULL, _cut, obj );
279 if (ext_mod->editable)
280 elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
284 _cancel(obj,ext_mod->popup,NULL);
285 if (!elm_entry_is_empty(obj))
287 elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
288 elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
290 if (1) // need way to detect if someone has a selection
292 if (ext_mod->editable)
293 elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
297 #ifdef HAVE_ELEMENTARY_X
298 if (ext_mod->editable && cbhm_count)
300 if (ext_mod->editable)
303 icon = elm_icon_add(ext_mod->popup);
304 snprintf(buf, sizeof(buf), "%s/images/copypaste_icon_clipboard.png", PACKAGE_DATA_DIR);
305 elm_icon_file_set(icon, buf, NULL);
306 elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _clipboard_menu, obj);
307 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
312 EINA_LIST_FOREACH(ext_mod->items, l, it)
314 elm_ctxpopup_item_append(ext_mod->popup, it->label, NULL, _item_clicked, it );
318 elm_object_scroll_freeze_push(ext_mod->popup);
319 _ctxpopup_position(obj);
320 evas_object_show(ext_mod->popup);
326 obj_mouseup(Evas_Object *obj)
328 if (!obj || !ext_mod)
334 obj_hidemenu(Evas_Object *obj)
336 if (!obj || !ext_mod)
339 evas_object_hide(ext_mod->popup);
340 // if (ext_mod->popup) evas_object_del(ext_mod->popup);