1 #include <Elementary.h>
2 #include "elm_module_priv.h"
4 #include <appsvc/appsvc.h>
6 #define MULTI_(id) dgettext("sys_string", #id)
7 #define S_SELECT MULTI_(IDS_COM_SK_SELECT)
8 #define S_SELECT_ALL MULTI_(IDS_COM_BODY_SELECT_ALL)
9 #define S_COPY MULTI_(IDS_COM_BODY_COPY)
10 #define S_CUT MULTI_(IDS_COM_BODY_CUT)
11 #define S_PASTE MULTI_(IDS_COM_BODY_PASTE)
12 #define S_CLIPBOARD MULTI_(IDS_COM_BODY_CLIPBOARD)
15 Elm_Entry_Extension_data *ext_mod;
16 static int _mod_hook_count = 0;
18 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
19 struct _Elm_Entry_Context_Menu_Item
23 const char *icon_file;
24 const char *icon_group;
25 Elm_Icon_Type icon_type;
30 static void _ctxpopup_hide(Evas_Object *popup);
32 _entry_move(void *data, Evas *e, Evas_Object *obj, void *event_info)
34 _ctxpopup_hide(ext_mod->popup);
38 _ctxpopup_hide(Evas_Object *popup)
40 evas_object_hide(popup);
41 evas_object_event_callback_del(ext_mod->caller, EVAS_CALLBACK_MOVE, _entry_move);
42 ext_mod->caller = NULL;
46 _ctxpopup_position(Evas_Object *obj)
50 Evas_Coord cx, cy, cw, ch, x, y, w, h;
51 if (!edje_object_part_text_selection_geometry_get(ext_mod->ent, "elm.text", &x, &y, &w, &h))
53 evas_object_geometry_get(ext_mod->ent, &x, &y, NULL, NULL);
54 edje_object_part_text_cursor_geometry_get(ext_mod->ent, "elm.text",
56 evas_object_size_hint_min_get(ext_mod->popup, &w, &h);
67 evas_object_move(ext_mod->popup, x + cx, y + cy);
68 evas_object_resize(ext_mod->popup, cw, ch);
72 if (ext_mod->viewport_rect.x != -1 || ext_mod->viewport_rect.y != -1
73 || ext_mod->viewport_rect.w != -1 || ext_mod->viewport_rect.h != -1)
75 Evas_Coord vx, vy, vw, vh, x2, y2;
78 vx = ext_mod->viewport_rect.x;
79 vy = ext_mod->viewport_rect.y;
80 vw = ext_mod->viewport_rect.w;
81 vh = ext_mod->viewport_rect.h;
85 if (x2 > vx + vw) x2 = vx + vw;
86 if (y2 > vy + vh) y2 = vy + vh;
92 Evas_Coord sw, sh, x2, y2;
95 ecore_x_window_size_get(ecore_x_window_root_first_get(), &sw, &sh);
100 if (y2 > sh) y2 = sh;
106 evas_object_move(ext_mod->popup, cx, cy);
111 _select_all(void *data, Evas_Object *obj, void *event_info)
115 ext_mod->selectall(data,obj,event_info);
120 _select(void *data, Evas_Object *obj, void *event_info)
124 ext_mod->select(data,obj,event_info);
129 _paste(void *data, Evas_Object *obj, void *event_info)
133 ext_mod->paste(data,obj,event_info);
138 _cut(void *data, Evas_Object *obj, void *event_info)
142 ext_mod->cut(data,obj,event_info);
144 elm_object_scroll_freeze_pop(ext_mod->popup);
148 _copy(void *data, Evas_Object *obj, void *event_info)
152 ext_mod->copy(data,obj,event_info);
154 elm_object_scroll_freeze_pop(ext_mod->popup);
158 _cancel(void *data, Evas_Object *obj, void *event_info)
162 ext_mod->cancel(data,obj,event_info);
164 elm_object_scroll_freeze_pop(ext_mod->popup);
168 _search_menu(void *data, Evas_Object *obj, void *event_info)
173 bundle *b = bundle_create();
176 //printf("bundle_create() failed\n");
180 appsvc_set_operation(b, APPSVC_OPERATION_SEARCH);
181 if (ext_mod->selmode)
183 char *selection = elm_entry_selection_get(ext_mod->caller);
185 appsvc_add_data(b, APPSVC_DATA_KEYWORD, selection);
187 appsvc_run_service(b, 0, NULL, NULL);
193 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
198 #ifdef HAVE_ELEMENTARY_X
199 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
201 ext_mod->cnpinit(data,obj,event_info);
202 elm_cbhm_helper_init(obj);
203 if (ext_mod->cnp_mode != ELM_CNP_MODE_MARKUP)
204 elm_cbhm_send_raw_data("show0");
206 elm_cbhm_send_raw_data("show1");
212 _item_clicked(void *data, Evas_Object *obj, void *event_info)
214 Elm_Entry_Context_Menu_Item *it = data;
215 Evas_Object *obj2 = it->obj;
217 if (it->func) it->func(it->data, obj2, NULL);
222 _ctxpopup_dismissed_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
224 if (!ext_mod) return;
226 elm_object_scroll_freeze_pop(ext_mod->popup);
229 // module api funcs needed
231 elm_modapi_init(void *m)
233 return 1; // succeed always
237 elm_modapi_shutdown(void *m)
239 return 1; // succeed always
242 // module funcs for the specific module type
244 obj_hook(Evas_Object *obj)
247 //if(_mod_hook_count > 1) return;
251 ext_mod = ELM_NEW(Elm_Entry_Extension_data);
252 elm_entry_extension_module_data_get(obj,ext_mod);
257 obj_unhook(Evas_Object *obj)
260 if(_mod_hook_count > 0) return;
270 obj_longpress(Evas_Object *obj)
276 const Elm_Entry_Context_Menu_Item *it;
277 const char *context_menu_orientation;
280 Elm_Object_Item *added_item = NULL;
283 elm_entry_extension_module_data_get(obj,ext_mod);
284 if (ext_mod->context_menu)
286 #ifdef HAVE_ELEMENTARY_X
288 if (elm_cbhm_helper_init(obj))
289 cbhm_count = elm_cbhm_get_count();
291 if (ext_mod->popup) evas_object_del(ext_mod->popup);
292 //else elm_widget_scroll_freeze_push(obj);
293 top = elm_widget_top_get(obj);
296 ext_mod->popup = elm_ctxpopup_add(top);
297 elm_object_tree_unfocusable_set(ext_mod->popup, EINA_TRUE);
298 evas_object_smart_callback_add(ext_mod->popup, "dismissed", _ctxpopup_dismissed_cb, NULL);
300 /*currently below theme not used,when guideline comes a new theme can be created if required*/
301 elm_object_style_set(ext_mod->popup,"extended/entry");
302 context_menu_orientation = edje_object_data_get
303 (ext_mod->ent, "context_menu_orientation");
304 if ((context_menu_orientation) &&
305 (!strcmp(context_menu_orientation, "horizontal")))
306 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
308 elm_widget_sub_object_add(obj, ext_mod->popup);
309 if (!ext_mod->selmode)
311 if (!ext_mod->password)
313 if (!elm_entry_is_empty(obj))
315 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_SELECT, NULL, _select, obj );
316 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_SELECT_ALL, NULL, _select_all, obj );
320 #ifdef HAVE_ELEMENTARY_X
323 if (1) // need way to detect if someone has a selection
326 if (ext_mod->editable)
327 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_PASTE, NULL, _paste, obj );
329 //elm_ctxpopup_item_append(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
331 #ifdef HAVE_ELEMENTARY_X
332 if ((!ext_mod->password) && (ext_mod->editable) && (cbhm_count))
334 if ((!ext_mod->password) && (ext_mod->editable))
337 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_CLIPBOARD, NULL, _clipboard_menu, obj); // Clipboard
338 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
341 icon = elm_icon_add(ext_mod->popup);
342 snprintf(buf, sizeof(buf), "%s/images/copy&paste_icon_search.png", PACKAGE_DATA_DIR);
343 elm_icon_file_set(icon, buf, NULL);
344 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _search_menu, obj); // Search
348 if (!ext_mod->password)
350 if (ext_mod->have_selection)
352 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_COPY, NULL, _copy, obj );
353 if (ext_mod->editable)
354 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_CUT, NULL, _cut, obj );
355 #ifdef HAVE_ELEMENTARY_X
356 if (ext_mod->editable && cbhm_count)
358 if (ext_mod->editable)
360 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_PASTE, NULL, _paste, obj );
364 _cancel(obj,ext_mod->popup,NULL);
365 if (!elm_entry_is_empty(obj))
367 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_SELECT, NULL, _select, obj );
368 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_SELECT_ALL, NULL, _select_all, obj );
370 #ifdef HAVE_ELEMENTARY_X
373 if (1) // need way to detect if someone has a selection
376 if (ext_mod->editable)
377 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_PASTE, NULL, _paste, obj );
381 #ifdef HAVE_ELEMENTARY_X
382 if (ext_mod->editable && cbhm_count)
384 if (ext_mod->editable)
387 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_CLIPBOARD, NULL, _clipboard_menu, obj); // Clipboard
388 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
391 icon = elm_icon_add(ext_mod->popup);
392 snprintf(buf, sizeof(buf), "%s/images/copy&paste_icon_search.png", PACKAGE_DATA_DIR);
393 elm_icon_file_set(icon, buf, NULL);
394 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _search_menu, obj); // Search
397 EINA_LIST_FOREACH(ext_mod->items, l, it)
399 added_item = elm_ctxpopup_item_append(ext_mod->popup, it->label, NULL, _item_clicked, it );
401 if (ext_mod->popup && added_item)
403 elm_object_scroll_freeze_push(ext_mod->popup);
404 _ctxpopup_position(obj);
405 evas_object_show(ext_mod->popup);
406 ext_mod->caller = obj;
407 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _entry_move, ext_mod->popup);
410 ext_mod->caller = NULL;
415 obj_mouseup(Evas_Object *obj)
417 if (!obj || !ext_mod)
423 obj_hidemenu(Evas_Object *obj)
425 if (!obj || !ext_mod || obj != ext_mod->caller)
428 _ctxpopup_hide(ext_mod->popup);
429 // if (ext_mod->popup) evas_object_del(ext_mod->popup);