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)
209 Widget_Data *wd = elm_widget_data_get(obj);
212 const Elm_Entry_Context_Menu_Item *it;
213 const char *context_menu_orientation;
215 if (wd->ctxpopup) evas_object_del(wd->ctxpopup);
216 else elm_widget_scroll_freeze_push(obj);
217 top = elm_widget_top_get(obj);
219 wd->ctxpopup = elm_ctxpopup_add(top);
220 elm_object_style_set(wd->ctxpopup,"entry");
221 elm_ctxpopup_scroller_disabled_set(wd->ctxpopup, EINA_TRUE);
222 context_menu_orientation = edje_object_data_get
223 (wd->ent, "context_menu_orientation");
224 if ((context_menu_orientation) &&
225 (!strcmp(context_menu_orientation, "horizontal")))
226 elm_ctxpopup_horizontal_set(wd->ctxpopup, EINA_TRUE);
228 elm_widget_sub_object_add(obj, wd->ctxpopup);
232 elm_ctxpopup_label_add(wd->ctxpopup, "Select",_select, obj );
233 if (1) // need way to detect if someone has a selection
236 elm_ctxpopup_label_add(wd->ctxpopup, "Paste", _paste, obj );
238 // elm_ctxpopup_label_add(wd->ctxpopup, "Selectall",_select_all, obj );
244 if (wd->have_selection)
246 elm_ctxpopup_label_add(wd->ctxpopup, "Copy",_copy, obj );
248 elm_ctxpopup_label_add(wd->ctxpopup, "Cut",_cut, obj );
252 _cancel(obj,wd->ctxpopup,NULL);
253 if (1) // need way to detect if someone has a selection
256 elm_ctxpopup_label_add(wd->ctxpopup, "Paste", _paste, obj );
258 elm_ctxpopup_label_add(wd->ctxpopup, "Select",_select, obj );
262 EINA_LIST_FOREACH(wd->items, l, it)
264 elm_ctxpopup_label_add(wd->ctxpopup, it->label,_item_clicked, it );
268 _ctxpopup_position(obj);
269 evas_object_show(wd->ctxpopup);
271 wd->longpress_timer = NULL;
275 obj_mouseup(Evas_Object *obj)
277 Widget_Data *wd = elm_widget_data_get(obj);
278 if (wd->longpress_timer)
280 ecore_timer_del(wd->longpress_timer);
281 wd->longpress_timer = NULL;
282 if (wd->have_selection )
284 _cancel(obj,wd->ctxpopup,NULL);
289 if (wd->have_selection )
291 obj_longpress( obj );