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);
31 static void _ctxpopup_position(Evas_Object *obj);
33 _entry_move(void *data, Evas *e, Evas_Object *obj, void *event_info)
35 if (evas_pointer_button_down_mask_get(e))
36 _ctxpopup_hide(ext_mod->popup);
38 _ctxpopup_position(data);
42 _ctxpopup_hide(Evas_Object *popup)
44 evas_object_hide(popup);
45 evas_object_event_callback_del(ext_mod->caller, EVAS_CALLBACK_MOVE, _entry_move);
46 ext_mod->caller = NULL;
50 _ctxpopup_position(Evas_Object *obj)
54 Evas_Coord cx, cy, cw, ch, x, y, w, h;
55 if (!edje_object_part_text_selection_geometry_get(ext_mod->ent, "elm.text", &x, &y, &w, &h))
57 evas_object_geometry_get(ext_mod->ent, &x, &y, NULL, NULL);
58 edje_object_part_text_cursor_geometry_get(ext_mod->ent, "elm.text",
60 evas_object_size_hint_min_get(ext_mod->popup, &w, &h);
71 evas_object_move(ext_mod->popup, x + cx, y + cy);
72 evas_object_resize(ext_mod->popup, cw, ch);
76 if (ext_mod->viewport_rect.x != -1 || ext_mod->viewport_rect.y != -1
77 || ext_mod->viewport_rect.w != -1 || ext_mod->viewport_rect.h != -1)
79 Evas_Coord vx, vy, vw, vh, x2, y2;
82 vx = ext_mod->viewport_rect.x;
83 vy = ext_mod->viewport_rect.y;
84 vw = ext_mod->viewport_rect.w;
85 vh = ext_mod->viewport_rect.h;
89 if (x2 > vx + vw) x2 = vx + vw;
90 if (y2 > vy + vh) y2 = vy + vh;
96 Evas_Coord sw, sh, x2, y2;
99 ecore_x_window_size_get(ecore_x_window_root_first_get(), &sw, &sh);
103 if (x2 > sw) x2 = sw;
104 if (y2 > sh) y2 = sh;
110 evas_object_move(ext_mod->popup, cx, cy);
115 _select_all(void *data, Evas_Object *obj, void *event_info)
119 ext_mod->selectall(data,obj,event_info);
124 _select(void *data, Evas_Object *obj, void *event_info)
128 ext_mod->select(data,obj,event_info);
133 _paste(void *data, Evas_Object *obj, void *event_info)
137 ext_mod->paste(data,obj,event_info);
142 _cut(void *data, Evas_Object *obj, void *event_info)
146 ext_mod->cut(data,obj,event_info);
148 elm_object_scroll_freeze_pop(ext_mod->popup);
152 _copy(void *data, Evas_Object *obj, void *event_info)
156 ext_mod->copy(data,obj,event_info);
158 elm_object_scroll_freeze_pop(ext_mod->popup);
162 _cancel(void *data, Evas_Object *obj, void *event_info)
166 ext_mod->cancel(data,obj,event_info);
168 elm_object_scroll_freeze_pop(ext_mod->popup);
172 _search_menu(void *data, Evas_Object *obj, void *event_info)
177 bundle *b = bundle_create();
180 //printf("bundle_create() failed\n");
184 appsvc_set_operation(b, APPSVC_OPERATION_SEARCH);
185 if (ext_mod->selmode)
187 char *selection = elm_entry_selection_get(ext_mod->caller);
189 appsvc_add_data(b, APPSVC_DATA_KEYWORD, selection);
191 appsvc_run_service(b, 0, NULL, NULL);
197 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
202 #ifdef HAVE_ELEMENTARY_X
203 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
205 ext_mod->cnpinit(data,obj,event_info);
206 elm_cbhm_helper_init(obj);
207 if (ext_mod->cnp_mode != ELM_CNP_MODE_MARKUP)
208 elm_cbhm_send_raw_data("show0");
210 elm_cbhm_send_raw_data("show1");
216 _item_clicked(void *data, Evas_Object *obj, void *event_info)
218 Elm_Entry_Context_Menu_Item *it = data;
219 Evas_Object *obj2 = it->obj;
221 if (it->func) it->func(it->data, obj2, NULL);
226 _ctxpopup_dismissed_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
228 if (!ext_mod) return;
230 elm_object_scroll_freeze_pop(ext_mod->popup);
233 // module api funcs needed
235 elm_modapi_init(void *m)
237 return 1; // succeed always
241 elm_modapi_shutdown(void *m)
243 return 1; // succeed always
246 // module funcs for the specific module type
248 obj_hook(Evas_Object *obj)
251 //if(_mod_hook_count > 1) return;
255 ext_mod = ELM_NEW(Elm_Entry_Extension_data);
256 elm_entry_extension_module_data_get(obj,ext_mod);
261 obj_unhook(Evas_Object *obj)
264 if(_mod_hook_count > 0) return;
274 obj_longpress(Evas_Object *obj)
280 const Elm_Entry_Context_Menu_Item *it;
281 const char *context_menu_orientation;
284 Elm_Object_Item *added_item = NULL;
287 elm_entry_extension_module_data_get(obj,ext_mod);
288 if (ext_mod->context_menu)
290 #ifdef HAVE_ELEMENTARY_X
292 if (elm_cbhm_helper_init(obj))
293 cbhm_count = elm_cbhm_get_count();
295 if (ext_mod->popup) evas_object_del(ext_mod->popup);
296 //else elm_widget_scroll_freeze_push(obj);
297 top = elm_widget_top_get(obj);
300 ext_mod->popup = elm_ctxpopup_add(top);
301 elm_object_tree_unfocusable_set(ext_mod->popup, EINA_TRUE);
302 evas_object_smart_callback_add(ext_mod->popup, "dismissed", _ctxpopup_dismissed_cb, NULL);
304 /*currently below theme not used,when guideline comes a new theme can be created if required*/
305 elm_object_style_set(ext_mod->popup,"extended/entry");
306 context_menu_orientation = edje_object_data_get
307 (ext_mod->ent, "context_menu_orientation");
308 if ((context_menu_orientation) &&
309 (!strcmp(context_menu_orientation, "horizontal")))
310 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
312 elm_widget_sub_object_add(obj, ext_mod->popup);
313 if (!ext_mod->selmode)
315 if (!ext_mod->password)
317 if (!elm_entry_is_empty(obj))
319 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_SELECT, NULL, _select, obj );
320 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_SELECT_ALL, NULL, _select_all, obj );
324 #ifdef HAVE_ELEMENTARY_X
327 if (1) // need way to detect if someone has a selection
330 if (ext_mod->editable)
331 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_PASTE, NULL, _paste, obj );
333 //elm_ctxpopup_item_append(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
335 #ifdef HAVE_ELEMENTARY_X
336 if ((!ext_mod->password) && (ext_mod->editable) && (cbhm_count))
338 if ((!ext_mod->password) && (ext_mod->editable))
341 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_CLIPBOARD, NULL, _clipboard_menu, obj); // Clipboard
342 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
345 icon = elm_icon_add(ext_mod->popup);
346 snprintf(buf, sizeof(buf), "%s/images/copy&paste_icon_search.png", PACKAGE_DATA_DIR);
347 elm_icon_file_set(icon, buf, NULL);
348 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _search_menu, obj); // Search
352 if (!ext_mod->password)
354 if (ext_mod->have_selection)
356 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_COPY, NULL, _copy, obj );
357 if (ext_mod->editable)
358 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_CUT, NULL, _cut, obj );
359 #ifdef HAVE_ELEMENTARY_X
360 if (ext_mod->editable && cbhm_count)
362 if (ext_mod->editable)
364 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_PASTE, NULL, _paste, obj );
368 _cancel(obj,ext_mod->popup,NULL);
369 if (!elm_entry_is_empty(obj))
371 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_SELECT, NULL, _select, obj );
372 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_SELECT_ALL, NULL, _select_all, obj );
374 #ifdef HAVE_ELEMENTARY_X
377 if (1) // need way to detect if someone has a selection
380 if (ext_mod->editable)
381 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_PASTE, NULL, _paste, obj );
385 #ifdef HAVE_ELEMENTARY_X
386 if (ext_mod->editable && cbhm_count)
388 if (ext_mod->editable)
391 added_item = elm_ctxpopup_item_append(ext_mod->popup, S_CLIPBOARD, NULL, _clipboard_menu, obj); // Clipboard
392 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
395 icon = elm_icon_add(ext_mod->popup);
396 snprintf(buf, sizeof(buf), "%s/images/copy&paste_icon_search.png", PACKAGE_DATA_DIR);
397 elm_icon_file_set(icon, buf, NULL);
398 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _search_menu, obj); // Search
401 EINA_LIST_FOREACH(ext_mod->items, l, it)
403 added_item = elm_ctxpopup_item_append(ext_mod->popup, it->label, NULL, _item_clicked, it );
405 if (ext_mod->popup && added_item)
407 elm_object_scroll_freeze_push(ext_mod->popup);
408 _ctxpopup_position(obj);
409 evas_object_show(ext_mod->popup);
410 ext_mod->caller = obj;
411 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _entry_move, ext_mod->popup);
414 ext_mod->caller = NULL;
419 obj_mouseup(Evas_Object *obj)
421 if (!obj || !ext_mod)
427 obj_hidemenu(Evas_Object *obj)
429 if (!obj || !ext_mod || obj != ext_mod->caller)
432 _ctxpopup_hide(ext_mod->popup);
433 // if (ext_mod->popup) evas_object_del(ext_mod->popup);