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*/
12 Evas_Object *hoversel;
13 Ecore_Job *deferred_recalc_job;
14 Ecore_Event_Handler *sel_notify_handler;
15 Ecore_Event_Handler *sel_clear_handler;
16 Ecore_Timer *longpress_timer;
20 Evas_Coord downx, downy;
21 Evas_Coord cx, cy, cw, ch;
23 Eina_List *item_providers;
24 Mod_Api *api; // module api if supplied
26 Eina_Bool changed : 1;
27 Eina_Bool linewrap : 1;
28 Eina_Bool char_linewrap : 1;
29 Eina_Bool single_line : 1;
30 Eina_Bool password : 1;
31 Eina_Bool show_last_character : 1;
32 Eina_Bool editable : 1;
33 Eina_Bool selection_asked : 1;
34 Eina_Bool have_selection : 1;
35 Eina_Bool selmode : 1;
36 Eina_Bool deferred_cur : 1;
37 Eina_Bool disabled : 1;
38 Eina_Bool context_menu : 1;
39 Eina_Bool autoreturnkey : 1;
42 struct _Elm_Entry_Context_Menu_Item
46 const char *icon_file;
47 const char *icon_group;
48 Elm_Icon_Type icon_type;
55 _store_selection(Evas_Object *obj)
57 Widget_Data *wd = elm_widget_data_get(obj);
58 const char *sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
60 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
61 wd->cut_sel = eina_stringshare_add(sel);
65 _ctxpopup_position(Evas_Object *obj)
67 Widget_Data *wd = elm_widget_data_get(obj);
68 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
70 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
71 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
73 evas_object_size_hint_min_get(wd->ctxpopup, &mw, &mh);
84 evas_object_move(wd->ctxpopup, x + cx, y + cy);
85 evas_object_resize(wd->ctxpopup, cw, ch);
89 _select(void *data, Evas_Object *obj, void *event_info)
91 Widget_Data *wd = elm_widget_data_get(data);
92 wd->selmode = EINA_TRUE;
93 edje_object_part_text_select_none(wd->ent, "elm.text");
94 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
96 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
97 elm_ctxpopup_scroller_disabled_set(obj, EINA_FALSE);
98 elm_widget_scroll_hold_push(data);
99 evas_object_hide(obj);
103 _paste(void *data, Evas_Object *obj, void *event_info)
105 Widget_Data *wd = elm_widget_data_get(data);
107 evas_object_smart_callback_call(data, "selection,paste", NULL);
108 if (wd->sel_notify_handler)
110 #ifdef HAVE_ELEMENTARY_X
113 top = elm_widget_top_get(data);
114 if ((top) && (elm_win_xwindow_get(top)))
116 ecore_x_selection_primary_request
117 (elm_win_xwindow_get(top),
118 ECORE_X_SELECTION_TARGET_UTF8_STRING);
119 wd->selection_asked = EINA_TRUE;
123 elm_ctxpopup_scroller_disabled_set(obj, EINA_FALSE);
124 evas_object_hide(obj);
128 _cut(void *data, Evas_Object *obj, void *event_info)
130 Widget_Data *wd = elm_widget_data_get(data);
131 wd->selmode = EINA_FALSE;
132 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
133 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
134 elm_ctxpopup_scroller_disabled_set(obj, EINA_FALSE);
135 elm_widget_scroll_hold_pop(data);
136 _store_selection(data);
137 edje_object_part_text_insert(wd->ent, "elm.text", "");
138 edje_object_part_text_select_none(wd->ent, "elm.text");
139 evas_object_hide(obj);
143 _copy(void *data, Evas_Object *obj, void *event_info)
145 Widget_Data *wd = elm_widget_data_get(data);
147 wd->selmode = EINA_FALSE;
148 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
149 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
150 elm_ctxpopup_scroller_disabled_set(obj, EINA_FALSE);
151 elm_widget_scroll_hold_pop(data);
152 _store_selection(data);
153 edje_object_part_text_select_none(wd->ent, "elm.text");
154 evas_object_hide(obj);
158 _cancel(void *data, Evas_Object *obj, void *event_info)
160 Widget_Data *wd = elm_widget_data_get(data);
162 wd->selmode = EINA_FALSE;
163 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
164 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
165 elm_ctxpopup_scroller_disabled_set(obj, EINA_FALSE);
166 elm_widget_scroll_hold_pop(data);
167 edje_object_part_text_select_none(wd->ent, "elm.text");
168 evas_object_hide(obj);
172 _item_clicked(void *data, Evas_Object *obj, void *event_info)
174 Elm_Entry_Context_Menu_Item *it = data;
175 Evas_Object *obj2 = it->obj;
177 if (it->func) it->func(it->data, obj2, NULL);
180 // module api funcs needed
182 elm_modapi_init(void *m)
184 return 1; // succeed always
188 elm_modapi_shutdown(void *m)
190 return 1; // succeed always
193 // module fucns for the specific module type
195 obj_hook(Evas_Object *obj)
201 obj_unhook(Evas_Object *obj)
207 obj_longpress(Evas_Object *obj)
210 Widget_Data *wd = elm_widget_data_get(obj);
213 const Elm_Entry_Context_Menu_Item *it;
214 const char *context_menu_orientation;
216 if (wd->ctxpopup) evas_object_del(wd->ctxpopup);
217 else elm_widget_scroll_freeze_push(obj);
218 top = elm_widget_top_get(obj);
220 wd->ctxpopup = elm_ctxpopup_add(top);
221 elm_object_style_set(wd->ctxpopup,"entry");
222 elm_ctxpopup_scroller_disabled_set(wd->ctxpopup, EINA_TRUE);
223 context_menu_orientation = edje_object_data_get
224 (wd->ent, "context_menu_orientation");
225 if ((context_menu_orientation) &&
226 (!strcmp(context_menu_orientation, "horizontal")))
227 elm_ctxpopup_horizontal_set(wd->ctxpopup, EINA_TRUE);
229 elm_widget_sub_object_add(obj, wd->ctxpopup);
233 elm_ctxpopup_label_add(wd->ctxpopup, "Select",_select, obj );
234 if (1) // need way to detect if someone has a selection
237 elm_ctxpopup_label_add(wd->ctxpopup, "Paste", _paste, obj );
239 // elm_ctxpopup_label_add(wd->ctxpopup, "Selectall",_select_all, obj );
245 if (wd->have_selection)
247 elm_ctxpopup_label_add(wd->ctxpopup, "Copy",_copy, obj );
249 elm_ctxpopup_label_add(wd->ctxpopup, "Cut",_cut, obj );
253 _cancel(obj,wd->ctxpopup,NULL);
254 if (1) // need way to detect if someone has a selection
257 elm_ctxpopup_label_add(wd->ctxpopup, "Paste", _paste, obj );
259 elm_ctxpopup_label_add(wd->ctxpopup, "Select",_select, obj );
263 EINA_LIST_FOREACH(wd->items, l, it)
265 elm_ctxpopup_label_add(wd->ctxpopup, it->label,_item_clicked, it );
269 _ctxpopup_position(obj);
270 evas_object_show(wd->ctxpopup);
272 wd->longpress_timer = NULL;
276 obj_mouseup(Evas_Object *obj)
278 Widget_Data *wd = elm_widget_data_get(obj);
279 if (wd->longpress_timer)
281 ecore_timer_del(wd->longpress_timer);
282 wd->longpress_timer = NULL;
283 if (wd->have_selection )
285 _cancel(obj,wd->ctxpopup,NULL);
290 if (wd->have_selection )
292 obj_longpress( obj );