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 _select(void *data, Evas_Object *obj, void *event_info)
67 Widget_Data *wd = elm_widget_data_get(data);
68 wd->selmode = EINA_TRUE;
69 edje_object_part_text_select_none(wd->ent, "elm.text");
70 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
72 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
73 elm_widget_scroll_hold_push(data);
74 evas_object_hide(wd->popup);
78 _paste(void *data, Evas_Object *obj, void *event_info)
80 Widget_Data *wd = elm_widget_data_get(data);
82 evas_object_smart_callback_call(data, "selection,paste", NULL);
83 if (wd->sel_notify_handler)
85 #ifdef HAVE_ELEMENTARY_X
88 top = elm_widget_top_get(data);
89 if ((top) && (elm_win_xwindow_get(top)))
91 ecore_x_selection_primary_request
92 (elm_win_xwindow_get(top),
93 ECORE_X_SELECTION_TARGET_UTF8_STRING);
94 wd->selection_asked = EINA_TRUE;
98 evas_object_hide(wd->popup);
102 _cut(void *data, Evas_Object *obj, void *event_info)
104 Widget_Data *wd = elm_widget_data_get(data);
105 wd->selmode = EINA_FALSE;
106 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
107 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
108 elm_widget_scroll_hold_pop(data);
109 _store_selection(data);
110 edje_object_part_text_insert(wd->ent, "elm.text", "");
111 edje_object_part_text_select_none(wd->ent, "elm.text");
112 evas_object_hide(wd->popup);
116 _copy(void *data, Evas_Object *obj, void *event_info)
118 Widget_Data *wd = elm_widget_data_get(data);
120 wd->selmode = EINA_FALSE;
121 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
122 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
123 elm_widget_scroll_hold_pop(data);
124 _store_selection(data);
125 edje_object_part_text_select_none(wd->ent, "elm.text");
126 evas_object_hide(wd->popup);
130 _cancel(void *data, Evas_Object *obj, void *event_info)
132 Widget_Data *wd = elm_widget_data_get(data);
134 wd->selmode = EINA_FALSE;
135 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
136 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
137 elm_widget_scroll_hold_pop(data);
138 edje_object_part_text_select_none(wd->ent, "elm.text");
139 evas_object_hide(wd->popup);
143 _item_clicked(void *data, Evas_Object *obj, void *event_info)
145 Elm_Entry_Context_Menu_Item *it = data;
146 Evas_Object *obj2 = it->obj;
148 if (it->func) it->func(it->data, obj2, NULL);
151 // module api funcs needed
153 elm_modapi_init(void *m)
155 return 1; // succeed always
159 elm_modapi_shutdown(void *m)
161 return 1; // succeed always
164 // module fucns for the specific module type
166 obj_hook(Evas_Object *obj)
172 obj_unhook(Evas_Object *obj)
178 obj_longpress(Evas_Object *obj)
180 Widget_Data *wd = elm_widget_data_get(obj);
184 const Elm_Entry_Context_Menu_Item *it;
186 if (wd->popup) evas_object_del(wd->popup);
187 else elm_widget_scroll_freeze_push(obj);
188 top = elm_widget_top_get(obj);
190 wd->popup = elm_popup_add(top);
191 elm_object_style_set(wd->popup,"menustyle");
192 elm_popup_set_mode(wd->popup, ELM_POPUP_TYPE_ALERT);
193 elm_popup_title_label_set(wd->popup,"CopyPaste");
194 list = elm_list_add(wd->popup);
195 elm_object_style_set(list,"popup");
196 elm_list_horizontal_mode_set(list, ELM_LIST_COMPRESS);
197 elm_widget_sub_object_add(obj, wd->popup);
201 elm_list_item_append(list, "Select", NULL, NULL,_select, obj);
203 if (1) // need way to detect if someone has a selection
206 elm_list_item_append(list, "Paste", NULL, NULL,_paste, obj);
209 //elm_list_item_append(list, "Selectall", NULL, NULL,_select_all, data);
215 if (wd->have_selection)
217 elm_list_item_append(list, "Copy", NULL, NULL,_copy, obj);
219 elm_list_item_append(list, "Cut", NULL, NULL,_cut, obj);
223 _cancel(obj,wd->popup,NULL);
224 if (1) // need way to detect if someone has a selection
227 elm_list_item_append(list, "Paste", NULL, NULL,_paste, obj);
229 elm_list_item_append(list, "Select", NULL, NULL,_select, obj);
233 EINA_LIST_FOREACH(wd->items, l, it)
235 elm_list_item_append(list, it->label, NULL, NULL,_item_clicked, it);
240 elm_popup_content_set(wd->popup, list);
241 evas_object_show(wd->popup);
242 evas_render( evas_object_evas_get( wd->popup ) );
244 wd->longpress_timer = NULL;
248 obj_mouseup(Evas_Object *obj)
250 Widget_Data *wd = elm_widget_data_get(obj);
251 if (wd->longpress_timer)
253 ecore_timer_del(wd->longpress_timer);
254 wd->longpress_timer = NULL;
255 if (wd->have_selection )
257 _cancel(obj,wd->popup,NULL);