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;
20 static void _ctxpopup_hide(Evas_Object *popup);
22 _entry_move(void *data, Evas *e, Evas_Object *obj, void *event_info)
24 _ctxpopup_hide(ext_mod->popup);
28 _ctxpopup_hide(Evas_Object *popup)
30 evas_object_hide(popup);
31 evas_object_event_callback_del(ext_mod->caller, EVAS_CALLBACK_MOVE, _entry_move);
32 ext_mod->caller = NULL;
36 _ctxpopup_position(Evas_Object *obj)
40 Evas_Coord cx, cy, cw, ch, x, y, w, h;
41 if (!edje_object_part_text_selection_geometry_get(ext_mod->ent, "elm.text", &x, &y, &w, &h))
43 evas_object_geometry_get(ext_mod->ent, &x, &y, NULL, NULL);
44 edje_object_part_text_cursor_geometry_get(ext_mod->ent, "elm.text",
46 evas_object_size_hint_min_get(ext_mod->popup, &w, &h);
57 evas_object_move(ext_mod->popup, x + cx, y + cy);
58 evas_object_resize(ext_mod->popup, cw, ch);
62 if (ext_mod->viewport_rect.x != -1 || ext_mod->viewport_rect.y != -1
63 || ext_mod->viewport_rect.w != -1 || ext_mod->viewport_rect.h != -1)
65 Evas_Coord vx, vy, vw, vh, x2, y2;
68 vx = ext_mod->viewport_rect.x;
69 vy = ext_mod->viewport_rect.y;
70 vw = ext_mod->viewport_rect.w;
71 vh = ext_mod->viewport_rect.h;
75 if (x2 > vx + vw) x2 = vx + vw;
76 if (y2 > vy + vh) y2 = vy + vh;
82 Evas_Coord sw, sh, x2, y2;
85 ecore_x_window_size_get(ecore_x_window_root_first_get(), &sw, &sh);
96 evas_object_move(ext_mod->popup, cx, cy);
101 _select_all(void *data, Evas_Object *obj, void *event_info)
105 ext_mod->selectall(data,obj,event_info);
110 _select(void *data, Evas_Object *obj, void *event_info)
114 ext_mod->select(data,obj,event_info);
119 _paste(void *data, Evas_Object *obj, void *event_info)
123 ext_mod->paste(data,obj,event_info);
128 _cut(void *data, Evas_Object *obj, void *event_info)
132 ext_mod->cut(data,obj,event_info);
134 elm_object_scroll_freeze_pop(ext_mod->popup);
138 _copy(void *data, Evas_Object *obj, void *event_info)
142 ext_mod->copy(data,obj,event_info);
144 elm_object_scroll_freeze_pop(ext_mod->popup);
148 _cancel(void *data, Evas_Object *obj, void *event_info)
152 ext_mod->cancel(data,obj,event_info);
154 elm_object_scroll_freeze_pop(ext_mod->popup);
158 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
163 #ifdef HAVE_ELEMENTARY_X
164 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
166 ext_mod->cnpinit(data,obj,event_info);
167 elm_cbhm_helper_init(obj);
168 if (ext_mod->cnp_mode != ELM_CNP_MODE_MARKUP)
169 elm_cbhm_send_raw_data("show0");
171 elm_cbhm_send_raw_data("show1");
177 _item_clicked(void *data, Evas_Object *obj, void *event_info)
179 Elm_Entry_Context_Menu_Item *it = data;
180 Evas_Object *obj2 = it->obj;
182 if (it->func) it->func(it->data, obj2, NULL);
187 _ctxpopup_dismissed_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
189 if (!ext_mod) return;
191 elm_object_scroll_freeze_pop(ext_mod->popup);
194 // module api funcs needed
196 elm_modapi_init(void *m)
198 return 1; // succeed always
202 elm_modapi_shutdown(void *m)
204 return 1; // succeed always
207 // module funcs for the specific module type
209 obj_hook(Evas_Object *obj)
212 //if(_mod_hook_count > 1) return;
216 ext_mod = ELM_NEW(Elm_Entry_Extension_data);
217 elm_entry_extension_module_data_get(obj,ext_mod);
222 obj_unhook(Evas_Object *obj)
225 if(_mod_hook_count > 0) return;
235 obj_longpress(Evas_Object *obj)
241 const Elm_Entry_Context_Menu_Item *it;
242 const char *context_menu_orientation;
245 Elm_Object_Item *added_item = NULL;
248 elm_entry_extension_module_data_get(obj,ext_mod);
249 if (ext_mod->context_menu)
251 #ifdef HAVE_ELEMENTARY_X
253 if (elm_cbhm_helper_init(obj))
254 cbhm_count = elm_cbhm_get_count();
256 if (ext_mod->popup) evas_object_del(ext_mod->popup);
257 //else elm_widget_scroll_freeze_push(obj);
258 top = elm_widget_top_get(obj);
261 ext_mod->popup = elm_ctxpopup_add(top);
262 elm_object_tree_unfocusable_set(ext_mod->popup, EINA_TRUE);
263 evas_object_smart_callback_add(ext_mod->popup, "dismissed", _ctxpopup_dismissed_cb, NULL);
265 /*currently below theme not used,when guideline comes a new theme can be created if required*/
266 elm_object_style_set(ext_mod->popup,"extended/entry");
267 context_menu_orientation = edje_object_data_get
268 (ext_mod->ent, "context_menu_orientation");
269 if ((context_menu_orientation) &&
270 (!strcmp(context_menu_orientation, "horizontal")))
271 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
273 elm_widget_sub_object_add(obj, ext_mod->popup);
274 if (!ext_mod->selmode)
276 if (!ext_mod->password)
278 if (!elm_entry_is_empty(obj))
280 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
281 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
285 #ifdef HAVE_ELEMENTARY_X
288 if (1) // need way to detect if someone has a selection
291 if (ext_mod->editable)
292 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
294 //elm_ctxpopup_item_append(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
296 #ifdef HAVE_ELEMENTARY_X
297 if ((!ext_mod->password) && (ext_mod->editable) && (cbhm_count))
299 if ((!ext_mod->password) && (ext_mod->editable))
302 icon = elm_icon_add(ext_mod->popup);
303 snprintf(buf, sizeof(buf), "%s/images/copypaste_icon_clipboard.png", PACKAGE_DATA_DIR);
304 elm_icon_file_set(icon, buf, NULL);
305 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _clipboard_menu, obj);
306 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
312 if (!ext_mod->password)
314 if (ext_mod->have_selection)
316 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Copy", NULL, _copy, obj );
317 if (ext_mod->editable)
318 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Cut", NULL, _cut, obj );
319 #ifdef HAVE_ELEMENTARY_X
320 if (ext_mod->editable && cbhm_count)
322 if (ext_mod->editable)
324 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
328 _cancel(obj,ext_mod->popup,NULL);
329 if (!elm_entry_is_empty(obj))
331 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
332 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
334 #ifdef HAVE_ELEMENTARY_X
337 if (1) // need way to detect if someone has a selection
340 if (ext_mod->editable)
341 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
345 #ifdef HAVE_ELEMENTARY_X
346 if (ext_mod->editable && cbhm_count)
348 if (ext_mod->editable)
351 icon = elm_icon_add(ext_mod->popup);
352 snprintf(buf, sizeof(buf), "%s/images/copypaste_icon_clipboard.png", PACKAGE_DATA_DIR);
353 elm_icon_file_set(icon, buf, NULL);
354 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _clipboard_menu, obj);
355 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
360 EINA_LIST_FOREACH(ext_mod->items, l, it)
362 added_item = elm_ctxpopup_item_append(ext_mod->popup, it->label, NULL, _item_clicked, it );
364 if (ext_mod->popup && added_item)
366 elm_object_scroll_freeze_push(ext_mod->popup);
367 _ctxpopup_position(obj);
368 evas_object_show(ext_mod->popup);
369 ext_mod->caller = obj;
370 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _entry_move, ext_mod->popup);
373 ext_mod->caller = NULL;
378 obj_mouseup(Evas_Object *obj)
380 if (!obj || !ext_mod)
386 obj_hidemenu(Evas_Object *obj)
388 if (!obj || !ext_mod || obj != ext_mod->caller)
391 _ctxpopup_hide(ext_mod->popup);
392 // if (ext_mod->popup) evas_object_del(ext_mod->popup);