1 #include <Elementary.h>
4 typedef struct _Mod_Api Mod_Api;
5 typedef struct _Widget_Data Widget_Data;
6 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
10 Evas_Object *popup;/*copy paste UI - elm_popup*/
11 Evas_Object *ctxpopup;/*copy paste UI - elm_ctxpopup*/
13 Evas_Object *hoversel;
14 Ecore_Job *deferred_recalc_job;
15 Ecore_Event_Handler *sel_notify_handler;
16 Ecore_Event_Handler *sel_clear_handler;
17 Ecore_Timer *longpress_timer;
22 Evas_Coord downx, downy;
23 Evas_Coord cx, cy, cw, ch;
25 Eina_List *item_providers;
26 Mod_Api *api; // module api if supplied
28 Eina_Bool changed : 1;
29 Eina_Bool linewrap : 1;
30 Eina_Bool char_linewrap : 1;
31 Eina_Bool single_line : 1;
32 Eina_Bool password : 1;
33 Eina_Bool show_last_character : 1;
34 Eina_Bool editable : 1;
35 Eina_Bool selection_asked : 1;
36 Eina_Bool have_selection : 1;
37 Eina_Bool selmode : 1;
38 Eina_Bool deferred_cur : 1;
39 Eina_Bool disabled : 1;
40 Eina_Bool context_menu : 1;
41 Eina_Bool bgcolor : 1;
42 Eina_Bool ellipsis : 1;
43 Eina_Bool autoreturnkey : 1;
46 struct _Elm_Entry_Context_Menu_Item
50 const char *icon_file;
51 const char *icon_group;
52 Elm_Icon_Type icon_type;
59 _store_selection(Evas_Object *obj)
61 Widget_Data *wd = elm_widget_data_get(obj);
62 const char *sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
64 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
65 wd->cut_sel = eina_stringshare_add(sel);
69 _ctxpopup_position(Evas_Object *obj)
71 Widget_Data *wd = elm_widget_data_get(obj);
72 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
74 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
75 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
77 evas_object_size_hint_min_get(wd->ctxpopup, &mw, &mh);
88 evas_object_move(wd->ctxpopup, x + cx, y + cy);
89 evas_object_resize(wd->ctxpopup, cw, ch);
93 _select(void *data, Evas_Object *obj, void *event_info)
95 Widget_Data *wd = elm_widget_data_get(data);
96 wd->selmode = EINA_TRUE;
97 edje_object_part_text_select_none(wd->ent, "elm.text");
98 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
100 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
101 elm_ctxpopup_scroller_disabled_set(obj, EINA_FALSE);
102 elm_widget_scroll_hold_push(data);
103 evas_object_hide(obj);
107 _paste(void *data, Evas_Object *obj, void *event_info)
109 Widget_Data *wd = elm_widget_data_get(data);
111 evas_object_smart_callback_call(data, "selection,paste", NULL);
112 if (wd->sel_notify_handler)
114 #ifdef HAVE_ELEMENTARY_X
117 top = elm_widget_top_get(data);
118 if ((top) && (elm_win_xwindow_get(top)))
120 ecore_x_selection_primary_request
121 (elm_win_xwindow_get(top),
122 ECORE_X_SELECTION_TARGET_UTF8_STRING);
123 wd->selection_asked = EINA_TRUE;
127 elm_ctxpopup_scroller_disabled_set(obj, EINA_FALSE);
128 evas_object_hide(obj);
132 _cut(void *data, Evas_Object *obj, void *event_info)
134 Widget_Data *wd = elm_widget_data_get(data);
135 wd->selmode = EINA_FALSE;
136 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
137 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
138 elm_ctxpopup_scroller_disabled_set(obj, EINA_FALSE);
139 elm_widget_scroll_hold_pop(data);
140 _store_selection(data);
141 edje_object_part_text_insert(wd->ent, "elm.text", "");
142 edje_object_part_text_select_none(wd->ent, "elm.text");
143 evas_object_hide(obj);
147 _copy(void *data, Evas_Object *obj, void *event_info)
149 Widget_Data *wd = elm_widget_data_get(data);
151 wd->selmode = EINA_FALSE;
152 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
153 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
154 elm_ctxpopup_scroller_disabled_set(obj, EINA_FALSE);
155 elm_widget_scroll_hold_pop(data);
156 _store_selection(data);
157 edje_object_part_text_select_none(wd->ent, "elm.text");
158 evas_object_hide(obj);
162 _cancel(void *data, Evas_Object *obj, void *event_info)
164 Widget_Data *wd = elm_widget_data_get(data);
166 wd->selmode = EINA_FALSE;
167 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
168 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
169 elm_ctxpopup_scroller_disabled_set(obj, EINA_FALSE);
170 elm_widget_scroll_hold_pop(data);
171 edje_object_part_text_select_none(wd->ent, "elm.text");
172 evas_object_hide(obj);
176 _item_clicked(void *data, Evas_Object *obj, void *event_info)
178 Elm_Entry_Context_Menu_Item *it = data;
179 Evas_Object *obj2 = it->obj;
181 if (it->func) it->func(it->data, obj2, NULL);
184 // module api funcs needed
186 elm_modapi_init(void *m)
188 return 1; // succeed always
192 elm_modapi_shutdown(void *m)
194 return 1; // succeed always
197 // module fucns for the specific module type
199 obj_hook(Evas_Object *obj)
205 obj_unhook(Evas_Object *obj)
211 obj_longpress(Evas_Object *obj)
214 Widget_Data *wd = elm_widget_data_get(obj);
217 const Elm_Entry_Context_Menu_Item *it;
218 const char *context_menu_orientation;
220 if (wd->ctxpopup) evas_object_del(wd->ctxpopup);
221 else elm_widget_scroll_freeze_push(obj);
222 top = elm_widget_top_get(obj);
224 wd->ctxpopup = elm_ctxpopup_add(top);
225 elm_object_style_set(wd->ctxpopup,"entry");
226 elm_ctxpopup_scroller_disabled_set(wd->ctxpopup, EINA_TRUE);
227 context_menu_orientation = edje_object_data_get
228 (wd->ent, "context_menu_orientation");
229 if ((context_menu_orientation) &&
230 (!strcmp(context_menu_orientation, "horizontal")))
231 elm_ctxpopup_horizontal_set(wd->ctxpopup, EINA_TRUE);
233 elm_widget_sub_object_add(obj, wd->ctxpopup);
237 elm_ctxpopup_label_add(wd->ctxpopup, "Select",_select, obj );
238 if (1) // need way to detect if someone has a selection
241 elm_ctxpopup_label_add(wd->ctxpopup, "Paste", _paste, obj );
243 // elm_ctxpopup_label_add(wd->ctxpopup, "Selectall",_select_all, obj );
249 if (wd->have_selection)
251 elm_ctxpopup_label_add(wd->ctxpopup, "Copy",_copy, obj );
253 elm_ctxpopup_label_add(wd->ctxpopup, "Cut",_cut, obj );
257 _cancel(obj,wd->ctxpopup,NULL);
258 if (1) // need way to detect if someone has a selection
261 elm_ctxpopup_label_add(wd->ctxpopup, "Paste", _paste, obj );
263 elm_ctxpopup_label_add(wd->ctxpopup, "Select",_select, obj );
267 EINA_LIST_FOREACH(wd->items, l, it)
269 elm_ctxpopup_label_add(wd->ctxpopup, it->label,_item_clicked, it );
273 _ctxpopup_position(obj);
274 evas_object_show(wd->ctxpopup);
276 wd->longpress_timer = NULL;
280 obj_mouseup(Evas_Object *obj)
282 Widget_Data *wd = elm_widget_data_get(obj);
283 if (wd->longpress_timer)
285 ecore_timer_del(wd->longpress_timer);
286 wd->longpress_timer = NULL;
287 if (wd->have_selection )
289 _cancel(obj,wd->ctxpopup,NULL);
294 if (wd->have_selection )
296 obj_longpress( obj );