1 #include <Elementary.h>
2 #include "elm_module_priv.h"
4 #include <appsvc/appsvc.h>
6 Elm_Entry_Extension_data *ext_mod;
7 static int _mod_hook_count = 0;
9 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
10 struct _Elm_Entry_Context_Menu_Item
14 const char *icon_file;
15 const char *icon_group;
16 Elm_Icon_Type icon_type;
21 static void _ctxpopup_hide(Evas_Object *popup);
23 _entry_move(void *data, Evas *e, Evas_Object *obj, void *event_info)
25 _ctxpopup_hide(ext_mod->popup);
29 _ctxpopup_hide(Evas_Object *popup)
31 evas_object_hide(popup);
32 evas_object_event_callback_del(ext_mod->caller, EVAS_CALLBACK_MOVE, _entry_move);
33 ext_mod->caller = NULL;
37 _ctxpopup_position(Evas_Object *obj)
41 Evas_Coord cx, cy, cw, ch, x, y, w, h;
42 if (!edje_object_part_text_selection_geometry_get(ext_mod->ent, "elm.text", &x, &y, &w, &h))
44 evas_object_geometry_get(ext_mod->ent, &x, &y, NULL, NULL);
45 edje_object_part_text_cursor_geometry_get(ext_mod->ent, "elm.text",
47 evas_object_size_hint_min_get(ext_mod->popup, &w, &h);
58 evas_object_move(ext_mod->popup, x + cx, y + cy);
59 evas_object_resize(ext_mod->popup, cw, ch);
63 if (ext_mod->viewport_rect.x != -1 || ext_mod->viewport_rect.y != -1
64 || ext_mod->viewport_rect.w != -1 || ext_mod->viewport_rect.h != -1)
66 Evas_Coord vx, vy, vw, vh, x2, y2;
69 vx = ext_mod->viewport_rect.x;
70 vy = ext_mod->viewport_rect.y;
71 vw = ext_mod->viewport_rect.w;
72 vh = ext_mod->viewport_rect.h;
76 if (x2 > vx + vw) x2 = vx + vw;
77 if (y2 > vy + vh) y2 = vy + vh;
83 Evas_Coord sw, sh, x2, y2;
86 ecore_x_window_size_get(ecore_x_window_root_first_get(), &sw, &sh);
97 evas_object_move(ext_mod->popup, cx, cy);
102 _select_all(void *data, Evas_Object *obj, void *event_info)
106 ext_mod->selectall(data,obj,event_info);
111 _select(void *data, Evas_Object *obj, void *event_info)
115 ext_mod->select(data,obj,event_info);
120 _paste(void *data, Evas_Object *obj, void *event_info)
124 ext_mod->paste(data,obj,event_info);
129 _cut(void *data, Evas_Object *obj, void *event_info)
133 ext_mod->cut(data,obj,event_info);
135 elm_object_scroll_freeze_pop(ext_mod->popup);
139 _copy(void *data, Evas_Object *obj, void *event_info)
143 ext_mod->copy(data,obj,event_info);
145 elm_object_scroll_freeze_pop(ext_mod->popup);
149 _cancel(void *data, Evas_Object *obj, void *event_info)
153 ext_mod->cancel(data,obj,event_info);
155 elm_object_scroll_freeze_pop(ext_mod->popup);
159 _search_menu(void *data, Evas_Object *obj, void *event_info)
164 bundle *b = bundle_create();
167 //printf("bundle_create() failed\n");
171 appsvc_set_operation(b, APPSVC_OPERATION_SEARCH);
172 if (ext_mod->selmode)
174 char *selection = elm_entry_selection_get(ext_mod->caller);
176 appsvc_add_data(b, APPSVC_DATA_KEYWORD, selection);
178 appsvc_run_service(b, 0, NULL, NULL);
184 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
189 #ifdef HAVE_ELEMENTARY_X
190 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
192 ext_mod->cnpinit(data,obj,event_info);
193 elm_cbhm_helper_init(obj);
194 if (ext_mod->cnp_mode != ELM_CNP_MODE_MARKUP)
195 elm_cbhm_send_raw_data("show0");
197 elm_cbhm_send_raw_data("show1");
203 _item_clicked(void *data, Evas_Object *obj, void *event_info)
205 Elm_Entry_Context_Menu_Item *it = data;
206 Evas_Object *obj2 = it->obj;
208 if (it->func) it->func(it->data, obj2, NULL);
213 _ctxpopup_dismissed_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
215 if (!ext_mod) return;
217 elm_object_scroll_freeze_pop(ext_mod->popup);
220 // module api funcs needed
222 elm_modapi_init(void *m)
224 return 1; // succeed always
228 elm_modapi_shutdown(void *m)
230 return 1; // succeed always
233 // module funcs for the specific module type
235 obj_hook(Evas_Object *obj)
238 //if(_mod_hook_count > 1) return;
242 ext_mod = ELM_NEW(Elm_Entry_Extension_data);
243 elm_entry_extension_module_data_get(obj,ext_mod);
248 obj_unhook(Evas_Object *obj)
251 if(_mod_hook_count > 0) return;
261 obj_longpress(Evas_Object *obj)
267 const Elm_Entry_Context_Menu_Item *it;
268 const char *context_menu_orientation;
271 Elm_Object_Item *added_item = NULL;
274 elm_entry_extension_module_data_get(obj,ext_mod);
275 if (ext_mod->context_menu)
277 #ifdef HAVE_ELEMENTARY_X
279 if (elm_cbhm_helper_init(obj))
280 cbhm_count = elm_cbhm_get_count();
282 if (ext_mod->popup) evas_object_del(ext_mod->popup);
283 //else elm_widget_scroll_freeze_push(obj);
284 top = elm_widget_top_get(obj);
287 ext_mod->popup = elm_ctxpopup_add(top);
288 elm_object_tree_unfocusable_set(ext_mod->popup, EINA_TRUE);
289 evas_object_smart_callback_add(ext_mod->popup, "dismissed", _ctxpopup_dismissed_cb, NULL);
291 /*currently below theme not used,when guideline comes a new theme can be created if required*/
292 elm_object_style_set(ext_mod->popup,"extended/entry");
293 context_menu_orientation = edje_object_data_get
294 (ext_mod->ent, "context_menu_orientation");
295 if ((context_menu_orientation) &&
296 (!strcmp(context_menu_orientation, "horizontal")))
297 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
299 elm_widget_sub_object_add(obj, ext_mod->popup);
300 if (!ext_mod->selmode)
302 if (!ext_mod->password)
304 if (!elm_entry_is_empty(obj))
306 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
307 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
311 #ifdef HAVE_ELEMENTARY_X
314 if (1) // need way to detect if someone has a selection
317 if (ext_mod->editable)
318 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
320 //elm_ctxpopup_item_append(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
322 #ifdef HAVE_ELEMENTARY_X
323 if ((!ext_mod->password) && (ext_mod->editable) && (cbhm_count))
325 if ((!ext_mod->password) && (ext_mod->editable))
328 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Clipboard", NULL, _clipboard_menu, obj); // Clipboard
329 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
332 icon = elm_icon_add(ext_mod->popup);
333 snprintf(buf, sizeof(buf), "%s/images/copy&paste_icon_search.png", PACKAGE_DATA_DIR);
334 elm_icon_file_set(icon, buf, NULL);
335 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _search_menu, obj); // Search
339 if (!ext_mod->password)
341 if (ext_mod->have_selection)
343 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Copy", NULL, _copy, obj );
344 if (ext_mod->editable)
345 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Cut", NULL, _cut, obj );
346 #ifdef HAVE_ELEMENTARY_X
347 if (ext_mod->editable && cbhm_count)
349 if (ext_mod->editable)
351 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
355 _cancel(obj,ext_mod->popup,NULL);
356 if (!elm_entry_is_empty(obj))
358 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
359 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
361 #ifdef HAVE_ELEMENTARY_X
364 if (1) // need way to detect if someone has a selection
367 if (ext_mod->editable)
368 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
372 #ifdef HAVE_ELEMENTARY_X
373 if (ext_mod->editable && cbhm_count)
375 if (ext_mod->editable)
378 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Clipboard", NULL, _clipboard_menu, obj); // Clipboard
379 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
382 icon = elm_icon_add(ext_mod->popup);
383 snprintf(buf, sizeof(buf), "%s/images/copy&paste_icon_search.png", PACKAGE_DATA_DIR);
384 elm_icon_file_set(icon, buf, NULL);
385 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _search_menu, obj); // Search
388 EINA_LIST_FOREACH(ext_mod->items, l, it)
390 added_item = elm_ctxpopup_item_append(ext_mod->popup, it->label, NULL, _item_clicked, it );
392 if (ext_mod->popup && added_item)
394 elm_object_scroll_freeze_push(ext_mod->popup);
395 _ctxpopup_position(obj);
396 evas_object_show(ext_mod->popup);
397 ext_mod->caller = obj;
398 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _entry_move, ext_mod->popup);
401 ext_mod->caller = NULL;
406 obj_mouseup(Evas_Object *obj)
408 if (!obj || !ext_mod)
414 obj_hidemenu(Evas_Object *obj)
416 if (!obj || !ext_mod || obj != ext_mod->caller)
419 _ctxpopup_hide(ext_mod->popup);
420 // if (ext_mod->popup) evas_object_del(ext_mod->popup);