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;
21 _ctxpopup_hide(Evas_Object *popup)
23 evas_object_hide(popup);
24 ext_mod->caller = NULL;
28 _ctxpopup_position(Evas_Object *obj)
32 Evas_Coord cx, cy, cw, ch, x, y, w, h;
33 if (!edje_object_part_text_selection_geometry_get(ext_mod->ent, "elm.text", &x, &y, &w, &h))
35 evas_object_geometry_get(ext_mod->ent, &x, &y, NULL, NULL);
36 edje_object_part_text_cursor_geometry_get(ext_mod->ent, "elm.text",
38 evas_object_size_hint_min_get(ext_mod->popup, &w, &h);
49 evas_object_move(ext_mod->popup, x + cx, y + cy);
50 evas_object_resize(ext_mod->popup, cw, ch);
54 if (ext_mod->viewport_rect.x != -1 || ext_mod->viewport_rect.y != -1
55 || ext_mod->viewport_rect.w != -1 || ext_mod->viewport_rect.h != -1)
57 Evas_Coord vx, vy, vw, vh, x2, y2;
60 vx = ext_mod->viewport_rect.x;
61 vy = ext_mod->viewport_rect.y;
62 vw = ext_mod->viewport_rect.w;
63 vh = ext_mod->viewport_rect.h;
67 if (x2 > vx + vw) x2 = vx + vw;
68 if (y2 > vy + vh) y2 = vy + vh;
74 Evas_Coord sw, sh, x2, y2;
77 ecore_x_window_size_get(ecore_x_window_root_first_get(), &sw, &sh);
88 evas_object_move(ext_mod->popup, cx, cy);
93 _select_all(void *data, Evas_Object *obj, void *event_info)
97 ext_mod->selectall(data,obj,event_info);
102 _select(void *data, Evas_Object *obj, void *event_info)
106 ext_mod->select(data,obj,event_info);
111 _paste(void *data, Evas_Object *obj, void *event_info)
115 ext_mod->paste(data,obj,event_info);
120 _cut(void *data, Evas_Object *obj, void *event_info)
124 ext_mod->cut(data,obj,event_info);
126 elm_object_scroll_freeze_pop(ext_mod->popup);
130 _copy(void *data, Evas_Object *obj, void *event_info)
134 ext_mod->copy(data,obj,event_info);
136 elm_object_scroll_freeze_pop(ext_mod->popup);
140 _cancel(void *data, Evas_Object *obj, void *event_info)
144 ext_mod->cancel(data,obj,event_info);
146 elm_object_scroll_freeze_pop(ext_mod->popup);
150 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
155 #ifdef HAVE_ELEMENTARY_X
156 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
158 ext_mod->cnpinit(data,obj,event_info);
159 elm_cbhm_helper_init(obj);
160 if (ext_mod->cnp_mode != ELM_CNP_MODE_MARKUP)
161 elm_cbhm_send_raw_data("show0");
163 elm_cbhm_send_raw_data("show1");
169 _item_clicked(void *data, Evas_Object *obj, void *event_info)
171 Elm_Entry_Context_Menu_Item *it = data;
172 Evas_Object *obj2 = it->obj;
174 if (it->func) it->func(it->data, obj2, NULL);
179 _ctxpopup_dismissed_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
181 if (!ext_mod) return;
183 elm_object_scroll_freeze_pop(ext_mod->popup);
186 // module api funcs needed
188 elm_modapi_init(void *m)
190 return 1; // succeed always
194 elm_modapi_shutdown(void *m)
196 return 1; // succeed always
199 // module funcs for the specific module type
201 obj_hook(Evas_Object *obj)
204 //if(_mod_hook_count > 1) return;
208 ext_mod = ELM_NEW(Elm_Entry_Extension_data);
209 elm_entry_extension_module_data_get(obj,ext_mod);
214 obj_unhook(Evas_Object *obj)
217 if(_mod_hook_count > 0) return;
227 obj_longpress(Evas_Object *obj)
233 const Elm_Entry_Context_Menu_Item *it;
234 const char *context_menu_orientation;
237 Elm_Object_Item *added_item = NULL;
240 elm_entry_extension_module_data_get(obj,ext_mod);
241 if (ext_mod->context_menu)
243 #ifdef HAVE_ELEMENTARY_X
245 if (elm_cbhm_helper_init(obj))
246 cbhm_count = elm_cbhm_get_count();
248 if (ext_mod->popup) evas_object_del(ext_mod->popup);
249 //else elm_widget_scroll_freeze_push(obj);
250 top = elm_widget_top_get(obj);
253 ext_mod->popup = elm_ctxpopup_add(top);
254 elm_object_tree_unfocusable_set(ext_mod->popup, EINA_TRUE);
255 evas_object_smart_callback_add(ext_mod->popup, "dismissed", _ctxpopup_dismissed_cb, NULL);
257 /*currently below theme not used,when guideline comes a new theme can be created if required*/
258 elm_object_style_set(ext_mod->popup,"extended/entry");
259 context_menu_orientation = edje_object_data_get
260 (ext_mod->ent, "context_menu_orientation");
261 if ((context_menu_orientation) &&
262 (!strcmp(context_menu_orientation, "horizontal")))
263 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
265 elm_widget_sub_object_add(obj, ext_mod->popup);
266 if (!ext_mod->selmode)
268 if (!ext_mod->password)
270 if (!elm_entry_is_empty(obj))
272 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
273 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
277 #ifdef HAVE_ELEMENTARY_X
280 if (1) // need way to detect if someone has a selection
283 if (ext_mod->editable)
284 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
286 //elm_ctxpopup_item_append(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
288 #ifdef HAVE_ELEMENTARY_X
289 if ((!ext_mod->password) && (ext_mod->editable) && (cbhm_count))
291 if ((!ext_mod->password) && (ext_mod->editable))
294 icon = elm_icon_add(ext_mod->popup);
295 snprintf(buf, sizeof(buf), "%s/images/copypaste_icon_clipboard.png", PACKAGE_DATA_DIR);
296 elm_icon_file_set(icon, buf, NULL);
297 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _clipboard_menu, obj);
298 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
304 if (!ext_mod->password)
306 if (ext_mod->have_selection)
308 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Copy", NULL, _copy, obj );
309 if (ext_mod->editable)
310 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Cut", NULL, _cut, obj );
311 #ifdef HAVE_ELEMENTARY_X
312 if (ext_mod->editable && cbhm_count)
314 if (ext_mod->editable)
316 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
320 _cancel(obj,ext_mod->popup,NULL);
321 if (!elm_entry_is_empty(obj))
323 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
324 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
326 #ifdef HAVE_ELEMENTARY_X
329 if (1) // need way to detect if someone has a selection
332 if (ext_mod->editable)
333 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
337 #ifdef HAVE_ELEMENTARY_X
338 if (ext_mod->editable && cbhm_count)
340 if (ext_mod->editable)
343 icon = elm_icon_add(ext_mod->popup);
344 snprintf(buf, sizeof(buf), "%s/images/copypaste_icon_clipboard.png", PACKAGE_DATA_DIR);
345 elm_icon_file_set(icon, buf, NULL);
346 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _clipboard_menu, obj);
347 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
352 EINA_LIST_FOREACH(ext_mod->items, l, it)
354 added_item = elm_ctxpopup_item_append(ext_mod->popup, it->label, NULL, _item_clicked, it );
356 if (ext_mod->popup && added_item)
358 elm_object_scroll_freeze_push(ext_mod->popup);
359 _ctxpopup_position(obj);
360 evas_object_show(ext_mod->popup);
361 ext_mod->caller = obj;
364 ext_mod->caller = NULL;
369 obj_mouseup(Evas_Object *obj)
371 if (!obj || !ext_mod)
377 obj_hidemenu(Evas_Object *obj)
379 if (!obj || !ext_mod || obj != ext_mod->caller)
382 _ctxpopup_hide(ext_mod->popup);
383 // if (ext_mod->popup) evas_object_del(ext_mod->popup);