1 #include <Elementary.h>
2 #include "elm_module_priv.h"
4 #include <appsvc/appsvc.h>
5 #include "cbhm_helper.h"
7 #define MULTI_(id) dgettext("sys_string", #id)
8 #define S_SELECT MULTI_(IDS_COM_SK_SELECT)
9 #define S_SELECT_ALL MULTI_(IDS_COM_BODY_SELECT_ALL)
10 #define S_COPY MULTI_(IDS_COM_BODY_COPY)
11 #define S_CUT MULTI_(IDS_COM_BODY_CUT)
12 #define S_PASTE MULTI_(IDS_COM_BODY_PASTE)
13 #define S_CLIPBOARD MULTI_(IDS_COM_BODY_CLIPBOARD)
16 Elm_Entry_Extension_data *ext_mod;
17 static int _mod_hook_count = 0;
19 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
20 struct _Elm_Entry_Context_Menu_Item
24 const char *icon_file;
25 const char *icon_group;
26 Elm_Icon_Type icon_type;
31 static void _ctxpopup_hide(Evas_Object *popup);
32 static void _ctxpopup_position(Evas_Object *obj);
35 _remove_tags(const char *str)
41 Eina_Strbuf *buf = eina_strbuf_new();
45 if (!eina_strbuf_append(buf, str))
48 eina_strbuf_replace_all(buf, "<br>", " ");
49 eina_strbuf_replace_all(buf, "<br/>", " ");
50 eina_strbuf_replace_all(buf, "<ps>", " ");
51 eina_strbuf_replace_all(buf, "<ps/>", " ");
55 const char *temp = eina_strbuf_string_get(buf);
57 char *startTag = NULL;
60 startTag = strstr(temp, "<");
62 endTag = strstr(startTag, ">");
65 if (!endTag || startTag > endTag)
68 size_t sindex = startTag - temp;
69 size_t eindex = endTag - temp + 1;
70 if (!eina_strbuf_remove(buf, sindex, eindex))
73 ret = eina_strbuf_string_steal(buf);
74 eina_strbuf_free(buf);
79 _entry_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
81 evas_object_del(data);
85 _entry_hide_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
87 evas_object_hide(data);
91 _entry_move_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
93 if (evas_pointer_button_down_mask_get(e))
96 _ctxpopup_position(data);
100 _entry_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
102 _ctxpopup_hide(data);
106 _ctxpopup_hide(Evas_Object *popup)
108 evas_object_hide(popup);
109 evas_object_event_callback_del(ext_mod->caller, EVAS_CALLBACK_DEL, _entry_del_cb);
110 evas_object_event_callback_del(ext_mod->caller, EVAS_CALLBACK_HIDE, _entry_hide_cb);
111 evas_object_event_callback_del(ext_mod->caller, EVAS_CALLBACK_MOVE, _entry_move_cb);
112 evas_object_event_callback_del(ext_mod->caller, EVAS_CALLBACK_RESIZE, _entry_resize_cb);
113 ext_mod->caller = NULL;
117 _ctxpopup_position(Evas_Object *obj)
121 Evas_Coord cx, cy, cw, ch, x, y, w, h;
122 if (!edje_object_part_text_selection_geometry_get(ext_mod->ent, "elm.text", &x, &y, &w, &h))
124 evas_object_geometry_get(ext_mod->ent, &x, &y, NULL, NULL);
125 edje_object_part_text_cursor_geometry_get(ext_mod->ent, "elm.text",
127 evas_object_size_hint_min_get(ext_mod->popup, &w, &h);
138 evas_object_move(ext_mod->popup, x + cx, y + cy);
139 evas_object_resize(ext_mod->popup, cw, ch);
143 if (ext_mod->viewport_rect.x != -1 || ext_mod->viewport_rect.y != -1
144 || ext_mod->viewport_rect.w != -1 || ext_mod->viewport_rect.h != -1)
146 Evas_Coord vx, vy, vw, vh, x2, y2;
149 vx = ext_mod->viewport_rect.x;
150 vy = ext_mod->viewport_rect.y;
151 vw = ext_mod->viewport_rect.w;
152 vh = ext_mod->viewport_rect.h;
156 if (x2 > vx + vw) x2 = vx + vw;
157 if (y2 > vy + vh) y2 = vy + vh;
163 Evas_Coord sw, sh, x2, y2;
166 ecore_x_window_size_get(ecore_x_window_root_first_get(), &sw, &sh);
170 if (x2 > sw) x2 = sw;
171 if (y2 > sh) y2 = sh;
177 evas_object_move(ext_mod->popup, cx, cy);
182 _select_all(void *data, Evas_Object *obj, void *event_info)
186 ext_mod->selectall(data,obj,event_info);
191 _select(void *data, Evas_Object *obj, void *event_info)
195 ext_mod->select(data,obj,event_info);
200 _paste(void *data, Evas_Object *obj, void *event_info)
204 ext_mod->paste(data,obj,event_info);
209 _cut(void *data, Evas_Object *obj, void *event_info)
213 ext_mod->cut(data,obj,event_info);
215 elm_object_scroll_freeze_pop(ext_mod->popup);
219 _copy(void *data, Evas_Object *obj, void *event_info)
223 ext_mod->copy(data,obj,event_info);
225 elm_object_scroll_freeze_pop(ext_mod->popup);
229 _cancel(void *data, Evas_Object *obj, void *event_info)
233 ext_mod->cancel(data,obj,event_info);
235 elm_object_scroll_freeze_pop(ext_mod->popup);
239 _search_menu(void *data, Evas_Object *obj, void *event_info)
244 bundle *b = bundle_create();
247 //printf("bundle_create() failed\n");
251 appsvc_set_operation(b, APPSVC_OPERATION_SEARCH);
252 if (ext_mod->selmode)
254 const char *selection = elm_entry_selection_get(ext_mod->caller);
257 char *str = _remove_tags(selection);
260 appsvc_add_data(b, APPSVC_DATA_KEYWORD, str);
264 appsvc_add_data(b, APPSVC_DATA_KEYWORD, selection);
267 appsvc_run_service(b, 0, NULL, NULL);
273 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
278 #ifdef HAVE_ELEMENTARY_X
279 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
281 ext_mod->cnpinit(data,obj,event_info);
282 if (ext_mod->cnp_mode != ELM_CNP_MODE_MARKUP)
283 _cbhm_msg_send(obj, "show0");
285 _cbhm_msg_send(obj, "show1");
291 _item_clicked(void *data, Evas_Object *obj, void *event_info)
293 Elm_Entry_Context_Menu_Item *it = data;
294 Evas_Object *obj2 = it->obj;
296 if (it->func) it->func(it->data, obj2, NULL);
301 _ctxpopup_dismissed_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
303 if (!ext_mod) return;
305 elm_object_scroll_freeze_pop(ext_mod->popup);
308 // module api funcs needed
310 elm_modapi_init(void *m)
312 return 1; // succeed always
316 elm_modapi_shutdown(void *m)
318 return 1; // succeed always
321 // module funcs for the specific module type
323 obj_hook(Evas_Object *obj)
326 //if(_mod_hook_count > 1) return;
330 ext_mod = ELM_NEW(Elm_Entry_Extension_data);
331 elm_entry_extension_module_data_get(obj,ext_mod);
336 obj_unhook(Evas_Object *obj)
339 if(_mod_hook_count > 0) return;
349 obj_longpress(Evas_Object *obj)
355 const Elm_Entry_Context_Menu_Item *it;
356 const char *context_menu_orientation;
359 Elm_Object_Item *added_item = NULL;
362 elm_entry_extension_module_data_get(obj,ext_mod);
363 if (ext_mod->context_menu)
365 #ifdef HAVE_ELEMENTARY_X
366 int cbhm_count = _cbhm_item_count_get(obj);
368 if (ext_mod->popup) evas_object_del(ext_mod->popup);
369 //else elm_widget_scroll_freeze_push(obj);
370 top = elm_widget_top_get(obj);
373 ext_mod->popup = elm_ctxpopup_add(top);
374 elm_object_focus_allow_set(ext_mod->popup, EINA_FALSE);
375 evas_object_smart_callback_add(ext_mod->popup, "dismissed", _ctxpopup_dismissed_cb, NULL);
376 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _entry_del_cb, ext_mod->popup);
377 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _entry_hide_cb, ext_mod->popup);
379 /*currently below theme not used,when guideline comes a new theme can be created if required*/
380 elm_object_style_set(ext_mod->popup,"extended/entry");
381 context_menu_orientation = edje_object_data_get
382 (ext_mod->ent, "context_menu_orientation");
383 if ((context_menu_orientation) &&
384 (!strcmp(context_menu_orientation, "horizontal")))
385 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
387 if (!ext_mod->selmode)
389 if (!ext_mod->password)
391 if (!elm_entry_is_empty(obj))
393 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_SELECT, NULL, _select, obj );
394 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_SELECT_ALL, NULL, _select_all, obj );
398 #ifdef HAVE_ELEMENTARY_X
401 if (1) // need way to detect if someone has a selection
404 if (ext_mod->editable)
405 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_PASTE, NULL, _paste, obj );
407 //elm_ctxpopup_item_append(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
409 #ifdef HAVE_ELEMENTARY_X
410 if ((!ext_mod->password) && (ext_mod->editable) && (cbhm_count))
412 if ((!ext_mod->password) && (ext_mod->editable))
415 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_CLIPBOARD, NULL, _clipboard_menu, obj); // Clipboard
416 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
419 icon = elm_icon_add(ext_mod->popup);
420 snprintf(buf, sizeof(buf), "%s/images/copy&paste_icon_search.png", PACKAGE_DATA_DIR);
421 elm_icon_file_set(icon, buf, NULL);
422 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _search_menu, obj); // Search
426 if (!ext_mod->password)
428 if (ext_mod->have_selection)
430 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_COPY, NULL, _copy, obj );
431 if (ext_mod->editable)
432 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_CUT, NULL, _cut, obj );
433 #ifdef HAVE_ELEMENTARY_X
434 if (ext_mod->editable && cbhm_count)
436 if (ext_mod->editable)
438 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_PASTE, NULL, _paste, obj );
442 _cancel(obj,ext_mod->popup,NULL);
443 if (!elm_entry_is_empty(obj))
445 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_SELECT, NULL, _select, obj );
446 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_SELECT_ALL, NULL, _select_all, obj );
448 #ifdef HAVE_ELEMENTARY_X
451 if (1) // need way to detect if someone has a selection
454 if (ext_mod->editable)
455 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_PASTE, NULL, _paste, obj );
459 #ifdef HAVE_ELEMENTARY_X
460 if (ext_mod->editable && cbhm_count)
462 if (ext_mod->editable)
465 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_CLIPBOARD, NULL, _clipboard_menu, obj); // Clipboard
466 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
469 icon = elm_icon_add(ext_mod->popup);
470 snprintf(buf, sizeof(buf), "%s/images/copy&paste_icon_search.png", PACKAGE_DATA_DIR);
471 elm_icon_file_set(icon, buf, NULL);
472 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _search_menu, obj); // Search
475 EINA_LIST_FOREACH(ext_mod->items, l, it)
477 added_item = elm_ctxpopup_item_append(ext_mod->popup, it->label, NULL, _item_clicked, it );
479 if (ext_mod->popup && added_item)
481 elm_object_scroll_freeze_push(ext_mod->popup);
482 _ctxpopup_position(obj);
483 evas_object_show(ext_mod->popup);
484 ext_mod->caller = obj;
485 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _entry_move_cb, ext_mod->popup);
486 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _entry_resize_cb, ext_mod->popup);
489 ext_mod->caller = NULL;
494 obj_mouseup(Evas_Object *obj)
496 if (!obj || !ext_mod)
502 obj_hidemenu(Evas_Object *obj)
504 if (!obj || !ext_mod || obj != ext_mod->caller)
507 _ctxpopup_hide(ext_mod->popup);
508 // if (ext_mod->popup) evas_object_del(ext_mod->popup);