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_position(Evas_Object *obj)
25 Evas_Coord cx, cy, cw, ch, x, y, w, h;
26 if (!edje_object_part_text_selection_geometry_get(ext_mod->ent, "elm.text", &x, &y, &w, &h))
28 evas_object_geometry_get(ext_mod->ent, &x, &y, NULL, NULL);
29 edje_object_part_text_cursor_geometry_get(ext_mod->ent, "elm.text",
31 evas_object_size_hint_min_get(ext_mod->popup, &w, &h);
42 evas_object_move(ext_mod->popup, x + cx, y + cy);
43 evas_object_resize(ext_mod->popup, cw, ch);
47 if (ext_mod->viewport_rect.x != -1 || ext_mod->viewport_rect.y != -1
48 || ext_mod->viewport_rect.w != -1 || ext_mod->viewport_rect.h != -1)
50 Evas_Coord vx, vy, vw, vh, x2, y2;
53 vx = ext_mod->viewport_rect.x;
54 vy = ext_mod->viewport_rect.y;
55 vw = ext_mod->viewport_rect.w;
56 vh = ext_mod->viewport_rect.h;
60 if (x2 > vx + vw) x2 = vx + vw;
61 if (y2 > vy + vh) y2 = vy + vh;
67 Evas_Coord sw, sh, x2, y2;
70 ecore_x_window_size_get(ecore_x_window_root_first_get(), &sw, &sh);
81 evas_object_move(ext_mod->popup, cx, cy);
86 _select_all(void *data, Evas_Object *obj, void *event_info)
90 ext_mod->selectall(data,obj,event_info);
91 evas_object_hide(obj);
95 _select(void *data, Evas_Object *obj, void *event_info)
99 ext_mod->select(data,obj,event_info);
100 evas_object_hide(obj);
104 _paste(void *data, Evas_Object *obj, void *event_info)
108 ext_mod->paste(data,obj,event_info);
109 evas_object_hide(obj);
113 _cut(void *data, Evas_Object *obj, void *event_info)
117 ext_mod->cut(data,obj,event_info);
118 evas_object_hide(obj);
119 elm_object_scroll_freeze_pop(ext_mod->popup);
123 _copy(void *data, Evas_Object *obj, void *event_info)
127 ext_mod->copy(data,obj,event_info);
128 evas_object_hide(obj);
129 elm_object_scroll_freeze_pop(ext_mod->popup);
133 _cancel(void *data, Evas_Object *obj, void *event_info)
137 ext_mod->cancel(data,obj,event_info);
138 evas_object_hide(obj);
139 elm_object_scroll_freeze_pop(ext_mod->popup);
143 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
148 #ifdef HAVE_ELEMENTARY_X
149 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
151 ext_mod->cnpinit(data,obj,event_info);
152 elm_cbhm_helper_init(obj);
153 if (ext_mod->cnp_mode != ELM_CNP_MODE_MARKUP)
154 elm_cbhm_send_raw_data("show0");
156 elm_cbhm_send_raw_data("show1");
157 evas_object_hide(obj);
162 _item_clicked(void *data, Evas_Object *obj, void *event_info)
164 Elm_Entry_Context_Menu_Item *it = data;
165 Evas_Object *obj2 = it->obj;
167 if (it->func) it->func(it->data, obj2, NULL);
168 evas_object_hide(obj);
172 _ctxpopup_dismissed_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
174 if (!ext_mod) return;
176 elm_object_scroll_freeze_pop(ext_mod->popup);
179 // module api funcs needed
181 elm_modapi_init(void *m)
183 return 1; // succeed always
187 elm_modapi_shutdown(void *m)
189 return 1; // succeed always
192 // module funcs for the specific module type
194 obj_hook(Evas_Object *obj)
197 //if(_mod_hook_count > 1) return;
201 ext_mod = ELM_NEW(Elm_Entry_Extension_data);
202 elm_entry_extension_module_data_get(obj,ext_mod);
207 obj_unhook(Evas_Object *obj)
210 if(_mod_hook_count > 0) return;
220 obj_longpress(Evas_Object *obj)
226 const Elm_Entry_Context_Menu_Item *it;
227 const char *context_menu_orientation;
230 Elm_Object_Item *added_item = NULL;
233 elm_entry_extension_module_data_get(obj,ext_mod);
234 if (ext_mod->context_menu)
236 #ifdef HAVE_ELEMENTARY_X
238 if (elm_cbhm_helper_init(obj))
239 cbhm_count = elm_cbhm_get_count();
241 if (ext_mod->popup) evas_object_del(ext_mod->popup);
242 //else elm_widget_scroll_freeze_push(obj);
243 top = elm_widget_top_get(obj);
246 ext_mod->popup = elm_ctxpopup_add(top);
247 elm_object_tree_unfocusable_set(ext_mod->popup, EINA_TRUE);
248 evas_object_smart_callback_add(ext_mod->popup, "dismissed", _ctxpopup_dismissed_cb, NULL);
250 /*currently below theme not used,when guideline comes a new theme can be created if required*/
251 elm_object_style_set(ext_mod->popup,"extended/entry");
252 context_menu_orientation = edje_object_data_get
253 (ext_mod->ent, "context_menu_orientation");
254 if ((context_menu_orientation) &&
255 (!strcmp(context_menu_orientation, "horizontal")))
256 elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
258 elm_widget_sub_object_add(obj, ext_mod->popup);
259 if (!ext_mod->selmode)
261 if (!ext_mod->password)
263 if (!elm_entry_is_empty(obj))
265 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
266 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
270 #ifdef HAVE_ELEMENTARY_X
273 if (1) // need way to detect if someone has a selection
276 if (ext_mod->editable)
277 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
279 //elm_ctxpopup_item_append(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
281 #ifdef HAVE_ELEMENTARY_X
282 if ((!ext_mod->password) && (ext_mod->editable) && (cbhm_count))
284 if ((!ext_mod->password) && (ext_mod->editable))
287 icon = elm_icon_add(ext_mod->popup);
288 snprintf(buf, sizeof(buf), "%s/images/copypaste_icon_clipboard.png", PACKAGE_DATA_DIR);
289 elm_icon_file_set(icon, buf, NULL);
290 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _clipboard_menu, obj);
291 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
297 if (!ext_mod->password)
299 if (ext_mod->have_selection)
301 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Copy", NULL, _copy, obj );
302 if (ext_mod->editable)
303 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Cut", NULL, _cut, obj );
304 #ifdef HAVE_ELEMENTARY_X
305 if (ext_mod->editable && cbhm_count)
307 if (ext_mod->editable)
309 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
313 _cancel(obj,ext_mod->popup,NULL);
314 if (!elm_entry_is_empty(obj))
316 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select", NULL, _select, obj );
317 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Select All", NULL, _select_all, obj );
319 #ifdef HAVE_ELEMENTARY_X
322 if (1) // need way to detect if someone has a selection
325 if (ext_mod->editable)
326 added_item = elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
330 #ifdef HAVE_ELEMENTARY_X
331 if (ext_mod->editable && cbhm_count)
333 if (ext_mod->editable)
336 icon = elm_icon_add(ext_mod->popup);
337 snprintf(buf, sizeof(buf), "%s/images/copypaste_icon_clipboard.png", PACKAGE_DATA_DIR);
338 elm_icon_file_set(icon, buf, NULL);
339 added_item = elm_ctxpopup_item_append(ext_mod->popup, NULL, icon, _clipboard_menu, obj);
340 //elm_ctxpopup_item_append(ext_mod->popup, "More", NULL, _clipboard_menu, obj );
345 EINA_LIST_FOREACH(ext_mod->items, l, it)
347 added_item = elm_ctxpopup_item_append(ext_mod->popup, it->label, NULL, _item_clicked, it );
349 if (ext_mod->popup && added_item)
351 elm_object_scroll_freeze_push(ext_mod->popup);
352 _ctxpopup_position(obj);
353 evas_object_show(ext_mod->popup);
359 obj_mouseup(Evas_Object *obj)
361 if (!obj || !ext_mod)
367 obj_hidemenu(Evas_Object *obj)
369 if (!obj || !ext_mod)
372 evas_object_hide(ext_mod->popup);
373 // if (ext_mod->popup) evas_object_del(ext_mod->popup);