[WM_ROT] Fixed floating mode window rotation bug that window doesn't send ROTATION_DO...
[platform/core/uifw/e17.git] / src / bin / e_widget_entry.c
1 #include "e.h"
2
3 typedef struct _E_Widget_Data E_Widget_Data;
4 struct _E_Widget_Data
5 {
6    Evas_Object *o_entry;
7    char **text_location;
8    void (*func) (void *data, void *data2);
9    void *data;
10    void *data2;
11 };
12
13 /* local subsystem functions */
14 static void _e_wid_del_hook(Evas_Object *obj);
15 static void _e_wid_focus_hook(Evas_Object *obj);
16 static void _e_wid_disable_hook(Evas_Object *obj);
17 static void _e_wid_focus_steal(void *data, Evas *e, Evas_Object *obj, void *event_info);
18 static void _e_wid_in(void *data, Evas *e, Evas_Object *obj, void *event_info);
19 static void _e_wid_out(void *data, Evas *e, Evas_Object *obj, void *event_info);
20 static void _e_wid_changed_cb(void *data, Evas_Object *obj, void *event_info);
21 static void _e_wid_keydown(void *data, Evas *e, Evas_Object *obj, void *event_info);
22
23 /* externally accessible functions */
24
25 /**
26  * Creates a new entry widget
27  *
28  * @param evas the evas where to add the new entry widget
29  * @param text_location the location where to store the text of the entry.
30  * @param func DOCUMENT ME!
31  * @param data  DOCUMENT ME!
32  * @param data2 DOCUMENT ME!
33  * The current value will be used to initialize the entry
34  * @return Returns the new entry widget
35  */
36 EAPI Evas_Object
37 *e_widget_entry_add(Evas *evas, char **text_location, void (*func) (void *data, void *data2), void *data, void *data2)
38 {
39    Evas_Object *obj, *o;
40    E_Widget_Data *wd;
41    Evas_Coord minw, minh;
42
43    obj = e_widget_add(evas);
44
45    e_widget_del_hook_set(obj, _e_wid_del_hook);
46    e_widget_focus_hook_set(obj, _e_wid_focus_hook);
47    e_widget_disable_hook_set(obj, _e_wid_disable_hook);
48
49    wd = calloc(1, sizeof(E_Widget_Data));
50    e_widget_data_set(obj, wd);
51    wd->text_location = text_location;
52
53    o = e_entry_add(evas);
54    wd->o_entry = o;
55    evas_object_show(o);
56    e_widget_sub_object_add(obj, o);
57    e_widget_resize_object_set(obj, o);
58    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _e_wid_focus_steal, obj);
59    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_IN, _e_wid_in, obj);
60    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_OUT, _e_wid_out, obj);
61    evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN, _e_wid_keydown, obj);
62
63    if ((text_location) && (*text_location))
64      e_entry_text_set(o, *text_location);
65
66    e_entry_size_min_get(o, &minw, &minh);
67    e_widget_size_min_set(obj, minw, minh);
68
69    wd->func = func;
70    wd->data = data;
71    wd->data2 = data2;
72    evas_object_smart_callback_add(o, "changed", _e_wid_changed_cb, obj);
73
74    return obj;
75 }
76
77 /**
78  * Sets the text of the entry widget
79  *
80  * @param entry an entry widget
81  * @param text the text to set
82  */
83 EAPI void
84 e_widget_entry_text_set(Evas_Object *entry, const char *text)
85 {
86    E_Widget_Data *wd;
87
88    if (!(entry) || (!(wd = e_widget_data_get(entry))))
89       return;
90    e_entry_text_set(wd->o_entry, text);
91 }
92
93 /**
94  * Gets the text of the entry widget
95  *
96  * @param entry an entry widget
97  * @return Returns the text of the entry widget
98  */
99 EAPI const char *
100 e_widget_entry_text_get(Evas_Object *entry)
101 {
102    E_Widget_Data *wd;
103
104    if (!(entry) || (!(wd = e_widget_data_get(entry))))
105       return NULL;
106    return e_entry_text_get(wd->o_entry);
107 }
108
109 /**
110  * Clears the entry widget
111  *
112  * @param entry an entry widget
113  */
114 EAPI void
115 e_widget_entry_clear(Evas_Object *entry)
116 {
117    E_Widget_Data *wd;
118
119    if (!(entry) || (!(wd = e_widget_data_get(entry))))
120       return;
121    e_entry_clear(wd->o_entry);
122 }
123
124 /**
125  * Sets whether or not the entry widget is in password mode. In password mode,
126  * the entry displays '*' instead of the characters
127  *
128  * @param entry an entry widget
129  * @param password_mode 1 to turn on password mode, 0 to turn it off
130  */
131 EAPI void
132 e_widget_entry_password_set(Evas_Object *entry, int password_mode)
133 {
134    E_Widget_Data *wd;
135
136    if (!(entry) || (!(wd = e_widget_data_get(entry))))
137       return;
138    e_entry_password_set(wd->o_entry, password_mode);
139 }
140
141 /**
142  * Sets whether or not the entry widget is user-editable. This still
143  * allows copying and selecting, just no inserting or deleting of text.
144  *
145  * @param entry an entry widget
146  * @param readonly_mode 1 to enable read-only mode, 0 to turn it off
147  */
148 EAPI void
149 e_widget_entry_readonly_set(Evas_Object *entry, int readonly_mode)
150 {
151    E_Widget_Data *wd;
152
153    if (!(entry) || (!(wd = e_widget_data_get(entry))))
154       return;
155
156    if (readonly_mode)
157      e_entry_disable(wd->o_entry);
158    else
159      e_entry_enable(wd->o_entry);
160 }
161
162 /**
163  * Gets the editable object of the entry widget. It will allow you to have
164  * better control on the text, the cursor or the selection of the entry with
165  * the e_editable_*() functions.
166  *
167  * @param entry an entry widget
168  * @return Returns the editable object of the entry widget
169  */
170 EAPI Evas_Object *
171 e_widget_entry_editable_object_get(Evas_Object *entry)
172 {
173    E_Widget_Data *wd;
174
175    if (!(entry) || (!(wd = e_widget_data_get(entry))))
176       return NULL;
177    return e_entry_editable_object_get(wd->o_entry);
178 }
179
180
181 /* Private functions */
182
183 static void
184 _e_wid_del_hook(Evas_Object *obj)
185 {
186    E_Widget_Data *wd;
187
188    if (!(obj) || (!(wd = e_widget_data_get(obj))))
189       return;
190    free(wd);
191 }
192
193 static void
194 _e_wid_focus_hook(Evas_Object *obj)
195 {
196    E_Widget_Data *wd;
197
198    if (!(obj) || (!(wd = e_widget_data_get(obj))))
199       return;
200
201    if (e_widget_focus_get(obj))
202      e_entry_focus(wd->o_entry);
203    else
204      e_entry_unfocus(wd->o_entry);
205 }
206
207 static void
208 _e_wid_disable_hook(Evas_Object *obj)
209 {
210    E_Widget_Data *wd;
211
212    if (!(obj) || (!(wd = e_widget_data_get(obj))))
213       return;
214
215    if (e_widget_disabled_get(obj))
216      e_entry_disable(wd->o_entry);
217    else
218      e_entry_enable(wd->o_entry);
219 }
220
221 static void
222 _e_wid_focus_steal(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
223 {
224    e_widget_focus_steal(data);
225 }
226
227 static void
228 _e_wid_in(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
229 {
230    E_Pointer *p;
231
232    p = e_widget_pointer_get(data);
233    if (p) e_pointer_type_push(p, data, "entry");
234 }
235
236 static void
237 _e_wid_out(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
238 {
239    E_Pointer *p;
240
241    p = e_widget_pointer_get(data);
242    if (p) e_pointer_type_pop(p, data, "entry");
243 }
244
245 static void
246 _e_wid_changed_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
247 {
248    Evas_Object *entry;
249    E_Widget_Data *wd;
250    const char *text;
251
252    if (!(entry = data) || (!(wd = e_widget_data_get(entry))))
253       return;
254
255    if (wd->text_location)
256      {
257         text = e_entry_text_get(wd->o_entry);
258         free(*wd->text_location);
259         *wd->text_location = text ? strdup(text) : NULL;
260      }
261    e_widget_change(data);
262
263    if (wd->func) wd->func(wd->data, wd->data2);
264 }
265
266 static void
267 _e_wid_keydown(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
268 {
269    evas_object_smart_callback_call(data, "key_down", event_info);
270 }