diff options
Diffstat (limited to 'libraries/elementary/src/lib/elc_multibuttonentry.c')
-rw-r--r-- | libraries/elementary/src/lib/elc_multibuttonentry.c | 1742 |
1 files changed, 1742 insertions, 0 deletions
diff --git a/libraries/elementary/src/lib/elc_multibuttonentry.c b/libraries/elementary/src/lib/elc_multibuttonentry.c new file mode 100644 index 0000000..c9ab83c --- /dev/null +++ b/libraries/elementary/src/lib/elc_multibuttonentry.c | |||
@@ -0,0 +1,1742 @@ | |||
1 | #include <Elementary.h> | ||
2 | #include "elm_priv.h" | ||
3 | |||
4 | #define MAX_STR 256 | ||
5 | #define MIN_W_ENTRY 10 | ||
6 | |||
7 | typedef enum _Multibuttonentry_Pos | ||
8 | { | ||
9 | MULTIBUTTONENTRY_POS_START, | ||
10 | MULTIBUTTONENTRY_POS_END, | ||
11 | MULTIBUTTONENTRY_POS_BEFORE, | ||
12 | MULTIBUTTONENTRY_POS_AFTER, | ||
13 | } Multibuttonentry_Pos; | ||
14 | |||
15 | typedef enum _Multibuttonentry_Button_State | ||
16 | { | ||
17 | MULTIBUTTONENTRY_BUTTON_STATE_DEFAULT, | ||
18 | MULTIBUTTONENTRY_BUTTON_STATE_SELECTED, | ||
19 | } Multibuttonentry_Button_State; | ||
20 | |||
21 | |||
22 | typedef enum _MultiButtonEntry_Closed_Button_Type | ||
23 | { | ||
24 | MULTIBUTTONENTRY_CLOSED_IMAGE, | ||
25 | MULTIBUTTONENTRY_CLOSED_LABEL | ||
26 | } MultiButtonEntry_Closed_Button_Type; | ||
27 | |||
28 | typedef enum _Multibuttonentry_View_State | ||
29 | { | ||
30 | MULTIBUTTONENTRY_VIEW_NONE, | ||
31 | MULTIBUTTONENTRY_VIEW_GUIDETEXT, | ||
32 | MULTIBUTTONENTRY_VIEW_ENTRY, | ||
33 | MULTIBUTTONENTRY_VIEW_SHRINK | ||
34 | } Multibuttonentry_View_State; | ||
35 | |||
36 | typedef struct _Widget_Data Widget_Data; | ||
37 | typedef struct _Multibuttonentry_Item Elm_Multibuttonentry_Item; | ||
38 | |||
39 | struct _Multibuttonentry_Item | ||
40 | { | ||
41 | ELM_WIDGET_ITEM; | ||
42 | Evas_Object *button; | ||
43 | Evas_Coord vw, rw; // vw: visual width, real width | ||
44 | Eina_Bool visible: 1; | ||
45 | Evas_Smart_Cb func; | ||
46 | }; | ||
47 | |||
48 | typedef struct _Elm_Multibuttonentry_Item_Filter | ||
49 | { | ||
50 | Elm_Multibuttonentry_Item_Filter_Cb callback_func; | ||
51 | void *data; | ||
52 | } Elm_Multibuttonentry_Item_Filter; | ||
53 | |||
54 | struct _Widget_Data | ||
55 | { | ||
56 | Evas_Object *base; | ||
57 | Evas_Object *box; | ||
58 | Evas_Object *entry; | ||
59 | Evas_Object *label; | ||
60 | Evas_Object *guidetext; | ||
61 | Evas_Object *end; // used to represent the total number of invisible buttons | ||
62 | |||
63 | Evas_Object *rect_for_end; | ||
64 | MultiButtonEntry_Closed_Button_Type end_type; | ||
65 | |||
66 | Eina_List *items; | ||
67 | Eina_List *filter_list; | ||
68 | Elm_Object_Item *selected_it; /* selected item */ | ||
69 | |||
70 | const char *labeltxt, *guidetexttxt; | ||
71 | |||
72 | int n_str; | ||
73 | Multibuttonentry_View_State view_state; | ||
74 | |||
75 | Evas_Coord w_box, h_box; | ||
76 | int shrink; | ||
77 | Eina_Bool focused: 1; | ||
78 | Eina_Bool last_btn_select: 1; | ||
79 | Elm_Multibuttonentry_Item_Filter_Cb add_callback; | ||
80 | void *add_callback_data; | ||
81 | }; | ||
82 | |||
83 | static void _del_hook(Evas_Object *obj); | ||
84 | static void _theme_hook(Evas_Object *obj); | ||
85 | static void _on_focus_hook(void *data __UNUSED__, Evas_Object *obj); | ||
86 | static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info); | ||
87 | static void _sizing_eval(Evas_Object *obj); | ||
88 | static void _changed_size_hint_cb(void *data, Evas *evas, Evas_Object *obj, void *event); | ||
89 | static void _resize_cb(void *data, Evas *evas, Evas_Object *obj, void *event); | ||
90 | static void _event_init(Evas_Object *obj); | ||
91 | static void _shrink_mode_set(Evas_Object *obj, Eina_Bool shrink); | ||
92 | static void _view_update(Evas_Object *obj); | ||
93 | static void _set_label(Evas_Object *obj, const char *str); | ||
94 | static void _change_current_button_state(Evas_Object *obj, Multibuttonentry_Button_State state); | ||
95 | static void _change_current_button(Evas_Object *obj, Evas_Object *btn); | ||
96 | static void _button_clicked(void *data, Evas_Object *obj, const char *emission, const char *source); | ||
97 | static void _del_button_obj(Evas_Object *obj, Evas_Object *btn); | ||
98 | static void _del_button_item(Elm_Multibuttonentry_Item *item); | ||
99 | static void _select_button(Evas_Object *obj, Evas_Object *btn); | ||
100 | static Elm_Object_Item *_add_button_item(Evas_Object *obj, const char *str, Multibuttonentry_Pos pos, const void *ref, Evas_Smart_Cb func, void *data); | ||
101 | static void _evas_mbe_key_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info); | ||
102 | static void _entry_changed_cb(void *data, Evas_Object *obj, void *event_info); | ||
103 | static void _entry_key_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info); | ||
104 | static void _entry_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info); | ||
105 | static void _entry_resized_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info); | ||
106 | static void _entry_focus_in_cb(void *data, Evas_Object *obj, void *event_info); | ||
107 | static void _entry_focus_out_cb(void *data, Evas_Object *obj, void *event_info); | ||
108 | static void _entry_clicked_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__); | ||
109 | static void _view_init(Evas_Object *obj); | ||
110 | static void _set_vis_guidetext(Evas_Object *obj); | ||
111 | static void _calculate_box_min_size(Evas_Object *box, Evas_Object_Box_Data *priv); | ||
112 | static Evas_Coord _calculate_item_max_height(Evas_Object *box, Evas_Object_Box_Data *priv, int obj_index); | ||
113 | static void _box_layout_cb(Evas_Object *o, Evas_Object_Box_Data *priv, void *data); | ||
114 | static void _item_text_set_hook(Elm_Object_Item *it, | ||
115 | const char *part, | ||
116 | const char *label); | ||
117 | static const char *_item_text_get_hook(const Elm_Object_Item *it, | ||
118 | const char *part); | ||
119 | |||
120 | static const char *widtype = NULL; | ||
121 | |||
122 | //widget signals | ||
123 | static const char SIG_ITEM_SELECTED[] = "item,selected"; | ||
124 | static const char SIG_ITEM_ADDED[] = "item,added"; | ||
125 | static const char SIG_ITEM_DELETED[] = "item,deleted"; | ||
126 | static const char SIG_ITEM_CLICKED[] = "item,clicked"; | ||
127 | static const char SIG_CLICKED[] = "clicked"; | ||
128 | static const char SIG_FOCUSED[] = "focused"; | ||
129 | static const char SIG_UNFOCUSED[] = "unfocused"; | ||
130 | static const char SIG_EXPANDED[] = "expanded"; | ||
131 | static const char SIG_CONTRACTED[] = "contracted"; | ||
132 | static const char SIG_EXPAND_STATE_CHANGED[] = "expand,state,changed"; | ||
133 | |||
134 | static const Evas_Smart_Cb_Description _signals[] = { | ||
135 | {SIG_ITEM_SELECTED, ""}, | ||
136 | {SIG_ITEM_ADDED, ""}, | ||
137 | {SIG_ITEM_DELETED, ""}, | ||
138 | {SIG_ITEM_CLICKED, ""}, | ||
139 | {SIG_CLICKED, ""}, | ||
140 | {SIG_FOCUSED, ""}, | ||
141 | {SIG_UNFOCUSED, ""}, | ||
142 | {SIG_EXPANDED, ""}, | ||
143 | {SIG_CONTRACTED, ""}, | ||
144 | {SIG_EXPAND_STATE_CHANGED, ""}, | ||
145 | {NULL, NULL} | ||
146 | }; | ||
147 | |||
148 | static void | ||
149 | _del_hook(Evas_Object *obj) | ||
150 | { | ||
151 | Widget_Data *wd = elm_widget_data_get(obj); | ||
152 | |||
153 | if (!wd) return; | ||
154 | if (wd->items) | ||
155 | { | ||
156 | Elm_Multibuttonentry_Item *item; | ||
157 | EINA_LIST_FREE(wd->items, item) | ||
158 | { | ||
159 | _del_button_obj(obj, item->button); | ||
160 | free(item); | ||
161 | } | ||
162 | wd->items = NULL; | ||
163 | } | ||
164 | wd->selected_it = NULL; | ||
165 | |||
166 | if (wd->labeltxt) eina_stringshare_del(wd->labeltxt); | ||
167 | if (wd->guidetexttxt) eina_stringshare_del(wd->guidetexttxt); | ||
168 | if (wd->entry) evas_object_del(wd->entry); | ||
169 | if (wd->label) evas_object_del(wd->label); | ||
170 | if (wd->guidetext) evas_object_del(wd->guidetext); | ||
171 | if (wd->end) evas_object_del(wd->end); | ||
172 | if (wd->rect_for_end) evas_object_del(wd->rect_for_end); | ||
173 | } | ||
174 | |||
175 | static void | ||
176 | _theme_hook(Evas_Object *obj) | ||
177 | { | ||
178 | Widget_Data *wd = elm_widget_data_get(obj); | ||
179 | Eina_List *l; | ||
180 | Elm_Multibuttonentry_Item *item; | ||
181 | |||
182 | if (!wd) return; | ||
183 | |||
184 | _elm_theme_object_set(obj, wd->base, "multibuttonentry", "base", elm_widget_style_get(obj)); | ||
185 | if (wd->box) edje_object_part_swallow(wd->base, "box.swallow", wd->box); | ||
186 | edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale); | ||
187 | |||
188 | EINA_LIST_FOREACH(wd->items, l, item) | ||
189 | { | ||
190 | if (item->button) | ||
191 | _elm_theme_object_set(obj, item->button, "multibuttonentry", "btn", elm_widget_style_get(obj)); | ||
192 | edje_object_scale_set(item->button, elm_widget_scale_get(obj) * _elm_config->scale); | ||
193 | } | ||
194 | |||
195 | _sizing_eval(obj); | ||
196 | } | ||
197 | |||
198 | static void | ||
199 | _on_focus_hook(void *data __UNUSED__, Evas_Object *obj) | ||
200 | { | ||
201 | Widget_Data *wd = elm_widget_data_get(obj); | ||
202 | |||
203 | if (!wd) return; | ||
204 | |||
205 | if (elm_widget_focus_get(obj)) | ||
206 | { | ||
207 | if ((wd->selected_it)) | ||
208 | { | ||
209 | elm_entry_input_panel_show(wd->entry); | ||
210 | } | ||
211 | else if (((!wd->selected_it) || (!eina_list_count(wd->items)))) | ||
212 | { | ||
213 | if (wd->entry) elm_entry_cursor_end_set(wd->entry); | ||
214 | _view_update(obj); | ||
215 | elm_entry_input_panel_show(wd->entry); | ||
216 | } | ||
217 | wd->focused = EINA_TRUE; | ||
218 | evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL); | ||
219 | } | ||
220 | else | ||
221 | { | ||
222 | wd->focused = EINA_FALSE; | ||
223 | _view_update(obj); | ||
224 | |||
225 | elm_entry_input_panel_hide(wd->entry); | ||
226 | evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | static Eina_Bool | ||
231 | _event_hook(Evas_Object *obj __UNUSED__, Evas_Object *src __UNUSED__, Evas_Callback_Type type __UNUSED__, void *event_info __UNUSED__) | ||
232 | { | ||
233 | return EINA_TRUE; | ||
234 | } | ||
235 | |||
236 | static void | ||
237 | _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source) | ||
238 | { | ||
239 | Widget_Data *wd = elm_widget_data_get(obj); | ||
240 | |||
241 | if (!wd) return; | ||
242 | edje_object_signal_emit(wd->base, emission, source); | ||
243 | } | ||
244 | |||
245 | static void | ||
246 | _sizing_eval(Evas_Object *obj) | ||
247 | { | ||
248 | Widget_Data *wd = elm_widget_data_get(obj); | ||
249 | Evas_Coord minw = -1, minh = -1; | ||
250 | Evas_Coord left, right, top, bottom; | ||
251 | |||
252 | if (!wd) return; | ||
253 | evas_object_size_hint_min_get(wd->box, &minw, &minh); | ||
254 | edje_object_part_geometry_get(wd->base, "top.left.pad", NULL, NULL, &left, &top); | ||
255 | edje_object_part_geometry_get(wd->base, "bottom.right.pad", NULL, NULL, &right, &bottom); | ||
256 | |||
257 | minw += (left + right); | ||
258 | minh += (top + bottom); | ||
259 | |||
260 | evas_object_size_hint_min_set(obj, minw, minh); | ||
261 | } | ||
262 | |||
263 | static void | ||
264 | _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) | ||
265 | { | ||
266 | Widget_Data *wd = elm_widget_data_get(data); | ||
267 | |||
268 | if (!wd || !wd->base) return; | ||
269 | wd->focused = EINA_TRUE; | ||
270 | _view_update(data); | ||
271 | |||
272 | elm_entry_input_panel_show(wd->entry); | ||
273 | |||
274 | evas_object_smart_callback_call(data, SIG_CLICKED, NULL); | ||
275 | } | ||
276 | |||
277 | static void | ||
278 | _changed_size_hint_cb(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__) | ||
279 | { | ||
280 | Evas_Object *eo = (Evas_Object *)data; | ||
281 | Widget_Data *wd = elm_widget_data_get(data); | ||
282 | |||
283 | if (!wd) return; | ||
284 | _sizing_eval(eo); | ||
285 | } | ||
286 | |||
287 | static void | ||
288 | _resize_cb(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__) | ||
289 | { | ||
290 | Widget_Data *wd = elm_widget_data_get(data); | ||
291 | Evas_Coord w, h; | ||
292 | |||
293 | if (!wd) return; | ||
294 | evas_object_geometry_get(wd->box, NULL, NULL, &w, &h); | ||
295 | |||
296 | if (wd->h_box < h) evas_object_smart_callback_call(data, SIG_EXPANDED, NULL); | ||
297 | else if (wd->h_box > h) | ||
298 | evas_object_smart_callback_call(data, SIG_CONTRACTED, NULL); | ||
299 | |||
300 | wd->w_box = w; | ||
301 | wd->h_box = h; | ||
302 | |||
303 | _view_update(data); | ||
304 | } | ||
305 | |||
306 | static void | ||
307 | _event_init(Evas_Object *obj) | ||
308 | { | ||
309 | Widget_Data *wd = elm_widget_data_get(obj); | ||
310 | |||
311 | if (!wd || !wd->base) return; | ||
312 | if (wd->base) | ||
313 | { | ||
314 | edje_object_signal_callback_add(wd->base, "mouse,clicked,1", "*", _signal_mouse_clicked, obj); | ||
315 | evas_object_event_callback_add(wd->base, EVAS_CALLBACK_KEY_UP, _evas_mbe_key_up_cb, obj); | ||
316 | } | ||
317 | |||
318 | if (wd->box) | ||
319 | { | ||
320 | evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE, _resize_cb, obj); | ||
321 | evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hint_cb, obj); | ||
322 | } | ||
323 | |||
324 | if (wd->entry) | ||
325 | { | ||
326 | evas_object_event_callback_add(wd->entry, EVAS_CALLBACK_KEY_UP, _entry_key_up_cb, obj); | ||
327 | evas_object_event_callback_add(wd->entry, EVAS_CALLBACK_KEY_DOWN, _entry_key_down_cb, obj); | ||
328 | evas_object_event_callback_add(wd->entry, EVAS_CALLBACK_RESIZE, _entry_resized_cb, obj); | ||
329 | evas_object_smart_callback_add(wd->entry, "changed", _entry_changed_cb, obj); | ||
330 | evas_object_smart_callback_add(wd->entry, "focused", _entry_focus_in_cb, obj); | ||
331 | evas_object_smart_callback_add(wd->entry, "unfocused", _entry_focus_out_cb, obj); | ||
332 | evas_object_smart_callback_add(wd->entry, "clicked", _entry_clicked_cb, obj); | ||
333 | } | ||
334 | } | ||
335 | |||
336 | static void | ||
337 | _set_vis_guidetext(Evas_Object *obj) | ||
338 | { | ||
339 | Widget_Data *wd = elm_widget_data_get(obj); | ||
340 | |||
341 | if (!wd) return; | ||
342 | elm_box_unpack(wd->box, wd->guidetext); | ||
343 | elm_box_unpack(wd->box, wd->entry); | ||
344 | if (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) return; | ||
345 | |||
346 | if (!wd->focused) | ||
347 | elm_object_focus_set(wd->entry, EINA_FALSE); | ||
348 | |||
349 | if (wd && (!eina_list_count(wd->items)) && wd->guidetext | ||
350 | && (!elm_widget_focus_get(obj)) && (!wd->focused) && (!wd->n_str)) | ||
351 | { | ||
352 | evas_object_hide(wd->entry); | ||
353 | elm_box_pack_end(wd->box, wd->guidetext); | ||
354 | evas_object_show(wd->guidetext); | ||
355 | wd->view_state = MULTIBUTTONENTRY_VIEW_GUIDETEXT; | ||
356 | } | ||
357 | else | ||
358 | { | ||
359 | evas_object_hide(wd->guidetext); | ||
360 | elm_box_pack_end(wd->box, wd->entry); | ||
361 | evas_object_show(wd->entry); | ||
362 | if (elm_widget_focus_get(obj) || wd->focused) | ||
363 | if (!wd->selected_it) | ||
364 | elm_object_focus_set(wd->entry, EINA_TRUE); | ||
365 | wd->view_state = MULTIBUTTONENTRY_VIEW_ENTRY; | ||
366 | } | ||
367 | } | ||
368 | |||
369 | static void | ||
370 | _shrink_mode_set(Evas_Object *obj, Eina_Bool shrink) | ||
371 | { | ||
372 | Widget_Data *wd = elm_widget_data_get(obj); | ||
373 | Eina_List *l; | ||
374 | Elm_Multibuttonentry_Item *item; | ||
375 | |||
376 | if (!wd || !wd->box) return; | ||
377 | if (wd->view_state == MULTIBUTTONENTRY_VIEW_ENTRY) | ||
378 | evas_object_hide(wd->entry); | ||
379 | else if (wd->view_state == MULTIBUTTONENTRY_VIEW_GUIDETEXT) | ||
380 | evas_object_hide(wd->guidetext); | ||
381 | else if (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) | ||
382 | { | ||
383 | evas_object_hide(wd->rect_for_end); | ||
384 | evas_object_hide(wd->end); | ||
385 | wd->view_state = MULTIBUTTONENTRY_VIEW_NONE; | ||
386 | } | ||
387 | |||
388 | if (shrink == EINA_TRUE) | ||
389 | { | ||
390 | Evas_Coord w = 0, w_tmp = 0; | ||
391 | Evas_Coord box_inner_item_width_padding = 0; | ||
392 | |||
393 | elm_box_padding_get(wd->box, &box_inner_item_width_padding, NULL); | ||
394 | // unpack all items and entry | ||
395 | elm_box_unpack_all(wd->box); | ||
396 | EINA_LIST_FOREACH(wd->items, l, item) | ||
397 | { | ||
398 | if (item) | ||
399 | { | ||
400 | evas_object_hide(item->button); | ||
401 | item->visible = EINA_FALSE; | ||
402 | } | ||
403 | } | ||
404 | // pack buttons only 1line | ||
405 | w = wd->w_box; | ||
406 | |||
407 | if (wd->label) | ||
408 | { | ||
409 | elm_box_pack_end(wd->box, wd->label); | ||
410 | evas_object_size_hint_min_get(wd->label, &w_tmp, NULL); | ||
411 | w -= w_tmp; | ||
412 | w -= box_inner_item_width_padding; | ||
413 | } | ||
414 | |||
415 | item = NULL; | ||
416 | int count = eina_list_count(wd->items); | ||
417 | Evas_Coord button_min_width = 0; | ||
418 | /* Evas_Coord button_min_height = 0; */ | ||
419 | if (wd->end_type == MULTIBUTTONENTRY_CLOSED_IMAGE) | ||
420 | { | ||
421 | const char *size_str; | ||
422 | size_str = edje_object_data_get(wd->end, "closed_button_width"); | ||
423 | if (size_str) button_min_width = (Evas_Coord)atoi(size_str); | ||
424 | /* it use for later | ||
425 | size_str = edje_object_data_get(wd->end, "closed_button_height"); | ||
426 | if (size_str) button_min_width = (Evas_Coord)atoi(size_str); | ||
427 | */ | ||
428 | } | ||
429 | |||
430 | EINA_LIST_FOREACH(wd->items, l, item) | ||
431 | { | ||
432 | if (item) | ||
433 | { | ||
434 | int w_label_count = 0; | ||
435 | char buf[MAX_STR]; | ||
436 | |||
437 | elm_box_pack_end(wd->box, item->button); | ||
438 | evas_object_show(item->button); | ||
439 | item->visible = EINA_TRUE; | ||
440 | |||
441 | w -= item->vw; | ||
442 | w -= box_inner_item_width_padding; | ||
443 | count--; | ||
444 | |||
445 | if (wd->end_type == MULTIBUTTONENTRY_CLOSED_LABEL) | ||
446 | { | ||
447 | if (count > 0) | ||
448 | { | ||
449 | snprintf(buf, sizeof(buf), "... + %d", count); | ||
450 | elm_object_text_set(wd->end, buf); | ||
451 | evas_object_size_hint_min_get(wd->end, &w_label_count, NULL); | ||
452 | } | ||
453 | |||
454 | if (w < 0 || w < w_label_count) | ||
455 | { | ||
456 | elm_box_unpack(wd->box, item->button); | ||
457 | evas_object_hide(item->button); | ||
458 | item->visible = EINA_FALSE; | ||
459 | |||
460 | count++; | ||
461 | snprintf(buf, sizeof(buf), "... + %d", count); | ||
462 | elm_object_text_set(wd->end, buf); | ||
463 | evas_object_size_hint_min_get(wd->end, &w_label_count, NULL); | ||
464 | |||
465 | elm_box_pack_end(wd->box, wd->end); | ||
466 | evas_object_show(wd->end); | ||
467 | |||
468 | wd->view_state = MULTIBUTTONENTRY_VIEW_SHRINK; | ||
469 | evas_object_smart_callback_call(obj, SIG_EXPAND_STATE_CHANGED, (void *)1); | ||
470 | break; | ||
471 | } | ||
472 | } | ||
473 | else if (wd->end_type == MULTIBUTTONENTRY_CLOSED_IMAGE) | ||
474 | { | ||
475 | if (w < button_min_width) | ||
476 | { | ||
477 | Evas_Coord rectSize; | ||
478 | Evas_Coord closed_height = 0; | ||
479 | const char *height_str = edje_object_data_get(wd->base, "closed_height"); | ||
480 | |||
481 | if (height_str) closed_height = (Evas_Coord)atoi(height_str); | ||
482 | elm_box_unpack(wd->box, item->button); | ||
483 | evas_object_hide(item->button); | ||
484 | item->visible = EINA_FALSE; | ||
485 | |||
486 | w += item->vw; | ||
487 | rectSize = w - button_min_width; | ||
488 | if (!wd->rect_for_end) | ||
489 | { | ||
490 | Evas *e = evas_object_evas_get(obj); | ||
491 | wd->rect_for_end = evas_object_rectangle_add(e); | ||
492 | evas_object_color_set(wd->rect_for_end, 0, 0, 0, 0); | ||
493 | } | ||
494 | evas_object_size_hint_min_set(wd->rect_for_end, rectSize, closed_height * _elm_config->scale); | ||
495 | elm_box_pack_end(wd->box, wd->rect_for_end); | ||
496 | evas_object_show(wd->rect_for_end); | ||
497 | |||
498 | elm_box_pack_end(wd->box, wd->end); | ||
499 | evas_object_show(wd->end); | ||
500 | |||
501 | wd->view_state = MULTIBUTTONENTRY_VIEW_SHRINK; | ||
502 | evas_object_smart_callback_call(obj, SIG_EXPAND_STATE_CHANGED, (void *)0); | ||
503 | break; | ||
504 | } | ||
505 | } | ||
506 | } | ||
507 | } | ||
508 | } | ||
509 | else | ||
510 | { | ||
511 | // unpack all items and entry | ||
512 | elm_box_unpack_all(wd->box); | ||
513 | EINA_LIST_FOREACH(wd->items, l, item) | ||
514 | { | ||
515 | if (item) | ||
516 | { | ||
517 | evas_object_hide(item->button); | ||
518 | item->visible = EINA_FALSE; | ||
519 | } | ||
520 | } | ||
521 | evas_object_hide(wd->end); | ||
522 | |||
523 | if (wd->rect_for_end) evas_object_hide(wd->rect_for_end); | ||
524 | |||
525 | // pack buttons only 1line | ||
526 | |||
527 | if (wd->label) elm_box_pack_end(wd->box, wd->label); | ||
528 | |||
529 | // pack remain btns | ||
530 | item = NULL; | ||
531 | EINA_LIST_FOREACH(wd->items, l, item) | ||
532 | { | ||
533 | if (item) | ||
534 | { | ||
535 | elm_box_pack_end(wd->box, item->button); | ||
536 | evas_object_show(item->button); | ||
537 | item->visible = EINA_TRUE; | ||
538 | } | ||
539 | } | ||
540 | |||
541 | wd->view_state = MULTIBUTTONENTRY_VIEW_NONE; | ||
542 | evas_object_smart_callback_call(obj, SIG_EXPAND_STATE_CHANGED, | ||
543 | (void *)(long)wd->shrink); | ||
544 | } | ||
545 | if (wd->view_state != MULTIBUTTONENTRY_VIEW_SHRINK) | ||
546 | { | ||
547 | _set_vis_guidetext(obj); | ||
548 | } | ||
549 | } | ||
550 | |||
551 | static void | ||
552 | _view_update(Evas_Object *obj) | ||
553 | { | ||
554 | Evas_Coord width = 1, height = 1; | ||
555 | Widget_Data *wd = elm_widget_data_get(obj); | ||
556 | |||
557 | if (!wd || !wd->box || !wd->entry || !(wd->w_box > 0)) return; | ||
558 | |||
559 | // update label | ||
560 | if (wd->label) | ||
561 | { | ||
562 | elm_box_unpack(wd->box, wd->label); | ||
563 | elm_box_pack_start(wd->box, wd->label); | ||
564 | evas_object_size_hint_min_get(wd->label, &width, &height); | ||
565 | } | ||
566 | |||
567 | if (wd->guidetext) | ||
568 | { | ||
569 | Evas_Coord guide_text_width = wd->w_box - width; | ||
570 | evas_object_size_hint_min_set(wd->guidetext, guide_text_width, height); | ||
571 | } | ||
572 | |||
573 | // update buttons in shrink mode | ||
574 | if (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) | ||
575 | _shrink_mode_set(obj, EINA_TRUE); | ||
576 | |||
577 | // update guidetext | ||
578 | _set_vis_guidetext(obj); | ||
579 | } | ||
580 | |||
581 | static void | ||
582 | _set_label(Evas_Object *obj, const char *str) | ||
583 | { | ||
584 | Widget_Data *wd = elm_widget_data_get(obj); | ||
585 | |||
586 | if (!wd || !str) return; | ||
587 | eina_stringshare_replace(&wd->labeltxt, str); | ||
588 | if (wd->label) | ||
589 | { | ||
590 | Evas_Coord width, height, sum_width = 0; | ||
591 | evas_object_size_hint_min_set(wd->label, 0, 0); | ||
592 | evas_object_resize(wd->label, 0, 0); | ||
593 | edje_object_part_text_escaped_set(wd->label, "mbe.label", str); | ||
594 | |||
595 | if (!strcmp(str, "")) | ||
596 | { | ||
597 | /* FIXME: not work yet */ | ||
598 | edje_object_signal_emit(wd->label, "elm,mbe,clear_text", ""); | ||
599 | edje_object_part_geometry_get(wd->label, "mbe.label", NULL, NULL, &width, &height); | ||
600 | sum_width += width; | ||
601 | } | ||
602 | else | ||
603 | { | ||
604 | edje_object_signal_emit(wd->label, "elm,mbe,set_text", ""); | ||
605 | edje_object_part_geometry_get(wd->label, "mbe.label", NULL, NULL, &width, &height); | ||
606 | |||
607 | sum_width += width; | ||
608 | |||
609 | edje_object_part_geometry_get(wd->label, "mbe.label.left.padding", NULL, NULL, &width, NULL); | ||
610 | sum_width += width; | ||
611 | |||
612 | edje_object_part_geometry_get(wd->label, "mbe.label.right.padding", NULL, NULL, &width, NULL); | ||
613 | sum_width += width; | ||
614 | } | ||
615 | evas_object_size_hint_min_set(wd->label, sum_width, height); | ||
616 | } | ||
617 | evas_object_show(wd->label); | ||
618 | _view_update(obj); | ||
619 | } | ||
620 | |||
621 | static void | ||
622 | _set_guidetext(Evas_Object *obj, const char *str) | ||
623 | { | ||
624 | Widget_Data *wd = elm_widget_data_get(obj); | ||
625 | |||
626 | if (!wd || !str) return; | ||
627 | |||
628 | eina_stringshare_replace(&wd->guidetexttxt, str); | ||
629 | if (wd->guidetext == NULL) | ||
630 | wd->guidetext = edje_object_add(evas_object_evas_get(obj)); | ||
631 | |||
632 | if (wd->guidetext) | ||
633 | { | ||
634 | _elm_theme_object_set(obj, wd->guidetext, "multibuttonentry", | ||
635 | "guidetext", elm_widget_style_get(obj)); | ||
636 | evas_object_size_hint_weight_set(wd->guidetext, 0.0, EVAS_HINT_EXPAND); | ||
637 | evas_object_size_hint_align_set(wd->guidetext, EVAS_HINT_FILL, | ||
638 | EVAS_HINT_FILL); | ||
639 | edje_object_part_text_escaped_set(wd->guidetext, "elm.text", str); | ||
640 | _view_update(obj); | ||
641 | } | ||
642 | } | ||
643 | |||
644 | static void | ||
645 | _change_current_button_state(Evas_Object *obj, Multibuttonentry_Button_State state) | ||
646 | { | ||
647 | Widget_Data *wd = elm_widget_data_get(obj); | ||
648 | Elm_Multibuttonentry_Item *item = NULL; | ||
649 | |||
650 | if (!wd) return; | ||
651 | item = (Elm_Multibuttonentry_Item *)wd->selected_it; | ||
652 | |||
653 | if (item && item->button) | ||
654 | { | ||
655 | switch (state) | ||
656 | { | ||
657 | case MULTIBUTTONENTRY_BUTTON_STATE_DEFAULT: | ||
658 | edje_object_signal_emit(item->button, "default", ""); | ||
659 | wd->selected_it = NULL; | ||
660 | break; | ||
661 | case MULTIBUTTONENTRY_BUTTON_STATE_SELECTED: | ||
662 | edje_object_signal_emit(item->button, "focused", ""); | ||
663 | evas_object_smart_callback_call(obj, SIG_ITEM_SELECTED, item); | ||
664 | break; | ||
665 | default: | ||
666 | edje_object_signal_emit(item->button, "default", ""); | ||
667 | wd->selected_it = NULL; | ||
668 | break; | ||
669 | } | ||
670 | } | ||
671 | } | ||
672 | |||
673 | static void | ||
674 | _change_current_button(Evas_Object *obj, Evas_Object *btn) | ||
675 | { | ||
676 | Widget_Data *wd = elm_widget_data_get(obj); | ||
677 | Eina_List *l; | ||
678 | Elm_Multibuttonentry_Item *item; | ||
679 | |||
680 | if (!wd) return; | ||
681 | |||
682 | // change the state of previous button to "default" | ||
683 | _change_current_button_state(obj, MULTIBUTTONENTRY_BUTTON_STATE_DEFAULT); | ||
684 | |||
685 | // change the current | ||
686 | EINA_LIST_FOREACH(wd->items, l, item) | ||
687 | { | ||
688 | if (item->button == btn) | ||
689 | { | ||
690 | wd->selected_it = (Elm_Object_Item *)item; | ||
691 | break; | ||
692 | } | ||
693 | } | ||
694 | // change the state of current button to "focused" | ||
695 | _change_current_button_state(obj, MULTIBUTTONENTRY_BUTTON_STATE_SELECTED); | ||
696 | } | ||
697 | |||
698 | static void | ||
699 | _button_clicked(void *data, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__) | ||
700 | { | ||
701 | Widget_Data *wd = elm_widget_data_get(data); | ||
702 | |||
703 | Elm_Multibuttonentry_Item *item = NULL; | ||
704 | if (!wd || wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) return; | ||
705 | |||
706 | _change_current_button(data, obj); | ||
707 | |||
708 | if (wd->selected_it) | ||
709 | if ((item = (Elm_Multibuttonentry_Item *)wd->selected_it) != NULL) | ||
710 | { | ||
711 | evas_object_smart_callback_call(data, SIG_ITEM_CLICKED, item); | ||
712 | _select_button(data, item->button); | ||
713 | } | ||
714 | } | ||
715 | |||
716 | static void | ||
717 | _del_button_obj(Evas_Object *obj, Evas_Object *btn) | ||
718 | { | ||
719 | Widget_Data *wd = elm_widget_data_get(obj); | ||
720 | |||
721 | if (!wd || !btn) return; | ||
722 | if (btn) | ||
723 | evas_object_del(btn); | ||
724 | } | ||
725 | |||
726 | static void | ||
727 | _del_button_item(Elm_Multibuttonentry_Item *item) | ||
728 | { | ||
729 | Eina_List *l; | ||
730 | Elm_Multibuttonentry_Item *_item; | ||
731 | if (!item) return; | ||
732 | Widget_Data *wd; | ||
733 | |||
734 | Evas_Object *obj = WIDGET(item); | ||
735 | wd = elm_widget_data_get(obj); | ||
736 | if (!wd) return; | ||
737 | EINA_LIST_FOREACH(wd->items, l, _item) | ||
738 | { | ||
739 | if (_item == item) | ||
740 | { | ||
741 | wd->items = eina_list_remove(wd->items, _item); | ||
742 | elm_box_unpack(wd->box, _item->button); | ||
743 | |||
744 | evas_object_smart_callback_call(obj, SIG_ITEM_DELETED, _item); | ||
745 | |||
746 | _del_button_obj(obj, _item->button); | ||
747 | |||
748 | if (wd->selected_it == (Elm_Object_Item *)_item) | ||
749 | wd->selected_it = NULL; | ||
750 | break; | ||
751 | } | ||
752 | } | ||
753 | if (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) | ||
754 | _shrink_mode_set(obj, EINA_TRUE); | ||
755 | |||
756 | if (!eina_list_count(wd->items)) | ||
757 | _set_vis_guidetext(obj); | ||
758 | } | ||
759 | |||
760 | static void | ||
761 | _select_button(Evas_Object *obj, Evas_Object *btn) | ||
762 | { | ||
763 | Widget_Data *wd = elm_widget_data_get(obj); | ||
764 | |||
765 | if (!wd) return; | ||
766 | if (btn) | ||
767 | { | ||
768 | _change_current_button(obj, btn); | ||
769 | if (elm_widget_focus_get(obj)) | ||
770 | { | ||
771 | elm_object_focus_set(wd->entry, EINA_FALSE); | ||
772 | evas_object_focus_set(btn, EINA_TRUE); | ||
773 | } | ||
774 | } | ||
775 | else | ||
776 | { | ||
777 | _change_current_button_state(obj, MULTIBUTTONENTRY_BUTTON_STATE_DEFAULT); | ||
778 | if (elm_widget_focus_get(obj)) | ||
779 | elm_object_focus_set(wd->entry, EINA_TRUE); | ||
780 | } | ||
781 | } | ||
782 | |||
783 | static void | ||
784 | _resize_button(Evas_Object *btn, Evas_Coord *realw, Evas_Coord *vieww) | ||
785 | { | ||
786 | Evas_Coord rw, vw; | ||
787 | Evas_Coord w_text, h_btn, padding_outer = 0; | ||
788 | Evas_Coord w_btn = 0, button_max_width = 0; | ||
789 | const char *size_str; | ||
790 | |||
791 | size_str = edje_object_data_get(btn, "button_max_size"); | ||
792 | if (size_str) button_max_width = (Evas_Coord)atoi(size_str); | ||
793 | |||
794 | // decide the size of button | ||
795 | edje_object_part_geometry_get(btn, "elm.base", NULL, NULL, NULL, &h_btn); | ||
796 | edje_object_part_geometry_get(btn, "elm.btn.text", NULL, NULL, &w_text, NULL); | ||
797 | edje_object_part_geometry_get(btn, "right.padding", NULL, NULL, &padding_outer, NULL); | ||
798 | w_btn = w_text + (2 * padding_outer); | ||
799 | |||
800 | rw = w_btn; | ||
801 | |||
802 | if (button_max_width < w_btn) | ||
803 | vw = button_max_width; | ||
804 | else | ||
805 | vw = w_btn; | ||
806 | |||
807 | //resize btn | ||
808 | evas_object_resize(btn, vw, h_btn); | ||
809 | evas_object_size_hint_min_set(btn, vw, h_btn); | ||
810 | |||
811 | if (realw) *realw = rw; | ||
812 | if (vieww) *vieww = vw; | ||
813 | } | ||
814 | |||
815 | static Eina_Bool | ||
816 | _item_del_pre_hook(Elm_Object_Item *it) | ||
817 | { | ||
818 | _del_button_item((Elm_Multibuttonentry_Item *)it); | ||
819 | return EINA_TRUE; | ||
820 | } | ||
821 | |||
822 | static Elm_Object_Item* | ||
823 | _add_button_item(Evas_Object *obj, const char *str, Multibuttonentry_Pos pos, const void *ref, Evas_Smart_Cb func, void *data) | ||
824 | { | ||
825 | Elm_Multibuttonentry_Item *item; | ||
826 | Elm_Multibuttonentry_Item_Filter *item_filter; | ||
827 | Elm_Multibuttonentry_Item *reference = (Elm_Multibuttonentry_Item *)ref; | ||
828 | Eina_List *l; | ||
829 | Evas_Object *btn; | ||
830 | Evas_Coord width = -1, height = -1; | ||
831 | char *str_utf8 = NULL; | ||
832 | Widget_Data *wd = elm_widget_data_get(obj); | ||
833 | |||
834 | if (!wd || !wd->box || !wd->entry) return NULL; | ||
835 | ELM_CHECK_WIDTYPE(obj, widtype) NULL; | ||
836 | if (!str) return NULL; | ||
837 | |||
838 | EINA_LIST_FOREACH(wd->filter_list, l, item_filter) | ||
839 | { | ||
840 | if (!(item_filter->callback_func(obj, str, data, item_filter->data))) | ||
841 | return NULL; | ||
842 | } | ||
843 | // add button | ||
844 | btn = edje_object_add(evas_object_evas_get(obj)); | ||
845 | str_utf8 = elm_entry_markup_to_utf8(str); | ||
846 | |||
847 | //entry is cleared when text is made to button | ||
848 | elm_object_text_set(wd->entry, ""); | ||
849 | |||
850 | _elm_theme_object_set(obj, btn, "multibuttonentry", "btn", elm_widget_style_get(obj)); | ||
851 | edje_object_part_text_escaped_set(btn, "elm.btn.text", str_utf8); | ||
852 | edje_object_part_geometry_get(btn, "elm.btn.text", NULL, NULL, &width, &height); | ||
853 | |||
854 | evas_object_size_hint_min_set(btn, width, height); | ||
855 | |||
856 | edje_object_signal_callback_add(btn, "mouse,clicked,1", "*", _button_clicked, obj); | ||
857 | evas_object_size_hint_weight_set(btn, 0.0, 0.0); | ||
858 | evas_object_show(btn); | ||
859 | |||
860 | // append item list | ||
861 | item = elm_widget_item_new(obj, Elm_Multibuttonentry_Item); | ||
862 | if (item) | ||
863 | { | ||
864 | elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook); | ||
865 | elm_widget_item_text_set_hook_set(item, _item_text_set_hook); | ||
866 | elm_widget_item_text_get_hook_set(item, _item_text_get_hook); | ||
867 | elm_widget_item_data_set(item, data); | ||
868 | Evas_Coord rw, vw; | ||
869 | _resize_button(btn, &rw, &vw); | ||
870 | item->button = btn; | ||
871 | item->rw = rw; | ||
872 | item->vw = vw; | ||
873 | item->visible = EINA_TRUE; | ||
874 | |||
875 | if (func) | ||
876 | { | ||
877 | item->func = func; | ||
878 | } | ||
879 | |||
880 | switch (pos) | ||
881 | { | ||
882 | case MULTIBUTTONENTRY_POS_START: | ||
883 | wd->items = eina_list_prepend(wd->items, item); | ||
884 | if (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) | ||
885 | { | ||
886 | elm_widget_sub_object_add(obj, btn); | ||
887 | _shrink_mode_set(obj, EINA_TRUE); | ||
888 | } | ||
889 | else | ||
890 | { | ||
891 | if (wd->label) | ||
892 | elm_box_pack_after(wd->box, btn, wd->label); | ||
893 | else | ||
894 | elm_box_pack_start(wd->box, btn); | ||
895 | if (wd->view_state == MULTIBUTTONENTRY_VIEW_GUIDETEXT) | ||
896 | _set_vis_guidetext(obj); | ||
897 | } | ||
898 | break; | ||
899 | case MULTIBUTTONENTRY_POS_END: | ||
900 | wd->items = eina_list_append(wd->items, item); | ||
901 | if (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) | ||
902 | { | ||
903 | elm_widget_sub_object_add(obj, btn); | ||
904 | evas_object_hide(btn); | ||
905 | } | ||
906 | else | ||
907 | { | ||
908 | if (wd->view_state == MULTIBUTTONENTRY_VIEW_GUIDETEXT) | ||
909 | _set_vis_guidetext(obj); | ||
910 | if (wd->entry) | ||
911 | elm_box_pack_before(wd->box, btn, wd->entry); | ||
912 | else | ||
913 | elm_box_pack_end(wd->box, btn); | ||
914 | } | ||
915 | break; | ||
916 | case MULTIBUTTONENTRY_POS_BEFORE: | ||
917 | if (reference) | ||
918 | wd->items = eina_list_prepend_relative(wd->items, item, reference); | ||
919 | else | ||
920 | wd->items = eina_list_append(wd->items, item); | ||
921 | if (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) | ||
922 | { | ||
923 | elm_widget_sub_object_add(obj, btn); | ||
924 | evas_object_hide(btn); | ||
925 | _shrink_mode_set(obj, EINA_TRUE); | ||
926 | } | ||
927 | else | ||
928 | { | ||
929 | if (reference) | ||
930 | elm_box_pack_before(wd->box, btn, reference->button); | ||
931 | else | ||
932 | { | ||
933 | if (wd->view_state == MULTIBUTTONENTRY_VIEW_GUIDETEXT) | ||
934 | _set_vis_guidetext(obj); | ||
935 | if (wd->entry) | ||
936 | elm_box_pack_before(wd->box, btn, wd->entry); | ||
937 | else | ||
938 | elm_box_pack_end(wd->box, btn); | ||
939 | } | ||
940 | } | ||
941 | break; | ||
942 | case MULTIBUTTONENTRY_POS_AFTER: | ||
943 | if (reference) | ||
944 | wd->items = eina_list_append_relative(wd->items, item, reference); | ||
945 | else | ||
946 | wd->items = eina_list_append(wd->items, item); | ||
947 | if (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) | ||
948 | { | ||
949 | elm_widget_sub_object_add(obj, btn); | ||
950 | _shrink_mode_set(obj, EINA_TRUE); | ||
951 | } | ||
952 | else | ||
953 | { | ||
954 | if (reference) | ||
955 | elm_box_pack_after(wd->box, btn, reference->button); | ||
956 | else | ||
957 | { | ||
958 | if (wd->view_state == MULTIBUTTONENTRY_VIEW_GUIDETEXT) | ||
959 | _set_vis_guidetext(obj); | ||
960 | if (wd->entry) | ||
961 | elm_box_pack_before(wd->box, btn, wd->entry); | ||
962 | else | ||
963 | elm_box_pack_end(wd->box, btn); | ||
964 | } | ||
965 | } | ||
966 | break; | ||
967 | default: | ||
968 | break; | ||
969 | } | ||
970 | } | ||
971 | evas_object_smart_callback_call(obj, SIG_ITEM_ADDED, item); | ||
972 | |||
973 | free(str_utf8); | ||
974 | |||
975 | return (Elm_Object_Item *)item; | ||
976 | } | ||
977 | |||
978 | static Elm_Multibuttonentry_Item_Filter* | ||
979 | _filter_new(Elm_Multibuttonentry_Item_Filter_Cb func, void *data) | ||
980 | { | ||
981 | Elm_Multibuttonentry_Item_Filter *item_filter = ELM_NEW(Elm_Multibuttonentry_Item_Filter); | ||
982 | if (!item_filter) return NULL; | ||
983 | |||
984 | item_filter->callback_func= func; | ||
985 | item_filter->data = data; | ||
986 | |||
987 | return item_filter; | ||
988 | } | ||
989 | |||
990 | static void | ||
991 | _filter_free(Elm_Multibuttonentry_Item_Filter *item_filter) | ||
992 | { | ||
993 | free(item_filter); | ||
994 | } | ||
995 | |||
996 | static void | ||
997 | _evas_mbe_key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info) | ||
998 | { | ||
999 | Widget_Data *wd = elm_widget_data_get(data); | ||
1000 | Elm_Multibuttonentry_Item *item = NULL; | ||
1001 | |||
1002 | if (!wd || !wd->base || !wd->box) return; | ||
1003 | |||
1004 | Evas_Event_Key_Up *ev = (Evas_Event_Key_Up*)event_info; | ||
1005 | |||
1006 | if (wd->last_btn_select) | ||
1007 | { | ||
1008 | if (wd->selected_it && | ||
1009 | ((strcmp(ev->keyname, "BackSpace") == 0) || | ||
1010 | (strcmp(ev->keyname, "Delete") == 0))) | ||
1011 | { | ||
1012 | item = (Elm_Multibuttonentry_Item *)wd->selected_it; | ||
1013 | if (item) | ||
1014 | { | ||
1015 | _del_button_item(item); | ||
1016 | elm_widget_item_free(item); | ||
1017 | elm_object_focus_set(wd->entry, EINA_TRUE); | ||
1018 | } | ||
1019 | } | ||
1020 | else if (((!wd->selected_it && (wd->n_str == 0) && | ||
1021 | (strcmp(ev->keyname, "BackSpace") == 0)) || | ||
1022 | (strcmp(ev->keyname, "Delete") == 0))) | ||
1023 | { | ||
1024 | item = eina_list_data_get(eina_list_last(wd->items)); | ||
1025 | if (item) | ||
1026 | _select_button(data, item->button); | ||
1027 | } | ||
1028 | } | ||
1029 | else | ||
1030 | wd->last_btn_select = EINA_TRUE; | ||
1031 | } | ||
1032 | |||
1033 | static void | ||
1034 | _entry_key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info) | ||
1035 | { | ||
1036 | Widget_Data *wd = elm_widget_data_get(data); | ||
1037 | Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *)event_info; | ||
1038 | |||
1039 | if (!wd) return; | ||
1040 | |||
1041 | if ((wd->n_str == 1) && (strcmp(ev->keyname, "BackSpace") == 0 || (strcmp(ev->keyname, "Delete") == 0 ))) | ||
1042 | wd->last_btn_select = EINA_FALSE; | ||
1043 | } | ||
1044 | |||
1045 | static void | ||
1046 | _entry_key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info) | ||
1047 | { | ||
1048 | Widget_Data *wd = elm_widget_data_get(data); | ||
1049 | Evas_Event_Key_Up *ev = (Evas_Event_Key_Up *) event_info; | ||
1050 | const char *str; | ||
1051 | |||
1052 | if (!wd || !wd->base || !wd->box) return; | ||
1053 | |||
1054 | str = elm_object_text_get(wd->entry); | ||
1055 | |||
1056 | if ((strcmp(str, "") != 0) && (strcmp(ev->keyname, "KP_Enter") == 0 || strcmp(ev->keyname, "Return") == 0 )) | ||
1057 | { | ||
1058 | _add_button_item(data, str, MULTIBUTTONENTRY_POS_END, NULL, NULL, NULL); | ||
1059 | wd->n_str = 0; | ||
1060 | } | ||
1061 | } | ||
1062 | |||
1063 | static void | ||
1064 | _entry_clicked_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
1065 | { | ||
1066 | Widget_Data *wd = elm_widget_data_get(data); | ||
1067 | if (!wd) return; | ||
1068 | |||
1069 | _change_current_button_state(data, MULTIBUTTONENTRY_BUTTON_STATE_DEFAULT); | ||
1070 | elm_object_focus_set(wd->entry, EINA_TRUE); | ||
1071 | } | ||
1072 | |||
1073 | static void | ||
1074 | _entry_focus_in_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
1075 | { | ||
1076 | Widget_Data *wd = elm_widget_data_get(data); | ||
1077 | Elm_Multibuttonentry_Item *item = NULL; | ||
1078 | |||
1079 | if (!wd) return; | ||
1080 | |||
1081 | if (wd->selected_it) | ||
1082 | { | ||
1083 | item = (Elm_Multibuttonentry_Item *)wd->selected_it; | ||
1084 | elm_object_focus_set(wd->entry, EINA_FALSE); | ||
1085 | evas_object_focus_set(item->button, EINA_TRUE); | ||
1086 | } | ||
1087 | } | ||
1088 | |||
1089 | static void | ||
1090 | _entry_focus_out_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
1091 | { | ||
1092 | Widget_Data *wd = elm_widget_data_get(data); | ||
1093 | const char *str; | ||
1094 | |||
1095 | if (!wd) return; | ||
1096 | |||
1097 | str = elm_object_text_get(wd->entry); | ||
1098 | if (strlen(str)) | ||
1099 | _add_button_item(data, str, MULTIBUTTONENTRY_POS_END, NULL, NULL, NULL); | ||
1100 | } | ||
1101 | |||
1102 | static void | ||
1103 | _entry_changed_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
1104 | { | ||
1105 | Widget_Data *wd = elm_widget_data_get(data); | ||
1106 | const char *str; | ||
1107 | |||
1108 | if (!wd) return; | ||
1109 | |||
1110 | str = elm_object_text_get(wd->entry); | ||
1111 | wd->n_str = strlen(str); | ||
1112 | } | ||
1113 | |||
1114 | static void | ||
1115 | _entry_resized_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
1116 | { | ||
1117 | Evas_Coord en_x, en_y, en_w, en_h; | ||
1118 | Evas_Coord bx_x, bx_y; | ||
1119 | |||
1120 | Widget_Data *wd = elm_widget_data_get(data); | ||
1121 | if (!wd) return; | ||
1122 | |||
1123 | evas_object_geometry_get(wd->entry, &en_x, &en_y, &en_w, &en_h); | ||
1124 | evas_object_geometry_get(wd->box, &bx_x, &bx_y, NULL, NULL); | ||
1125 | |||
1126 | if (wd->focused) | ||
1127 | elm_widget_show_region_set(wd->box, en_x - bx_x, en_y - bx_y, en_w, | ||
1128 | en_h, EINA_TRUE); | ||
1129 | } | ||
1130 | |||
1131 | static void | ||
1132 | _view_init(Evas_Object *obj) | ||
1133 | { | ||
1134 | Widget_Data *wd = elm_widget_data_get(obj); | ||
1135 | |||
1136 | if (!wd) return; | ||
1137 | |||
1138 | if (!wd->box) | ||
1139 | { | ||
1140 | wd->box = elm_box_add(obj); | ||
1141 | if (!wd->box) return; | ||
1142 | elm_widget_sub_object_add(obj, wd->box); | ||
1143 | elm_box_layout_set(wd->box, _box_layout_cb, NULL, NULL); | ||
1144 | elm_box_homogeneous_set(wd->box, EINA_FALSE); | ||
1145 | edje_object_part_swallow(wd->base, "box.swallow", wd->box); | ||
1146 | } | ||
1147 | if (!wd->label) | ||
1148 | { | ||
1149 | wd->label = edje_object_add(evas_object_evas_get(obj)); | ||
1150 | if (!wd->label) return; | ||
1151 | _elm_theme_object_set(obj, wd->label, "multibuttonentry", "label", elm_widget_style_get(obj)); | ||
1152 | _set_label(obj, ""); | ||
1153 | elm_widget_sub_object_add(obj, wd->label); | ||
1154 | } | ||
1155 | |||
1156 | if (!wd->entry) | ||
1157 | { | ||
1158 | wd->entry = elm_entry_add(obj); | ||
1159 | if (!wd->entry) return; | ||
1160 | elm_entry_single_line_set(wd->entry, EINA_TRUE); | ||
1161 | elm_object_text_set(wd->entry, ""); | ||
1162 | elm_entry_input_panel_enabled_set(wd->entry, EINA_FALSE); | ||
1163 | evas_object_size_hint_min_set(wd->entry, MIN_W_ENTRY, 0); | ||
1164 | evas_object_size_hint_weight_set(wd->entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
1165 | evas_object_size_hint_align_set(wd->entry, EVAS_HINT_FILL, EVAS_HINT_FILL); | ||
1166 | if (wd->box) elm_box_pack_end(wd->box, wd->entry); | ||
1167 | evas_object_show(wd->entry); | ||
1168 | wd->view_state = MULTIBUTTONENTRY_VIEW_ENTRY; | ||
1169 | } | ||
1170 | |||
1171 | if (!wd->end) | ||
1172 | { | ||
1173 | const char *end_type; | ||
1174 | |||
1175 | end_type = edje_object_data_get(wd->base, "closed_button_type"); | ||
1176 | if (!end_type || !strcmp(end_type, "label")) | ||
1177 | { | ||
1178 | wd->end = elm_label_add(obj); | ||
1179 | if (!wd->end) return; | ||
1180 | elm_object_style_set(wd->end, "extended/multibuttonentry_default"); | ||
1181 | wd->end_type = MULTIBUTTONENTRY_CLOSED_LABEL; | ||
1182 | } | ||
1183 | else | ||
1184 | { | ||
1185 | const char *size_str; | ||
1186 | wd->end = edje_object_add(evas_object_evas_get(obj)); | ||
1187 | if (!wd->end) return; | ||
1188 | _elm_theme_object_set(obj, wd->end, "multibuttonentry", "closedbutton", elm_widget_style_get(obj)); | ||
1189 | Evas_Coord button_min_width = 0; | ||
1190 | Evas_Coord button_min_height = 0; | ||
1191 | |||
1192 | size_str = edje_object_data_get(wd->end, "closed_button_width"); | ||
1193 | if (size_str) button_min_width = (Evas_Coord)atoi(size_str); | ||
1194 | size_str = edje_object_data_get(wd->end, "closed_button_height"); | ||
1195 | if (size_str) button_min_height = (Evas_Coord)atoi(size_str); | ||
1196 | |||
1197 | wd->end_type = MULTIBUTTONENTRY_CLOSED_IMAGE; | ||
1198 | evas_object_size_hint_min_set(wd->end, | ||
1199 | button_min_width * _elm_config->scale, | ||
1200 | button_min_height * _elm_config->scale); | ||
1201 | elm_widget_sub_object_add(obj, wd->end); | ||
1202 | } | ||
1203 | } | ||
1204 | } | ||
1205 | |||
1206 | static void | ||
1207 | _calculate_box_min_size(Evas_Object *box, Evas_Object_Box_Data *priv) | ||
1208 | { | ||
1209 | Evas_Coord minw, minh, mnw, mnh, ww; | ||
1210 | Evas_Coord w, cw = 0, cmaxh = 0; | ||
1211 | const Eina_List *l; | ||
1212 | Evas_Object_Box_Option *opt; | ||
1213 | double wx; | ||
1214 | |||
1215 | /* FIXME: need to calc max */ | ||
1216 | minw = 0; | ||
1217 | minh = 0; | ||
1218 | |||
1219 | evas_object_geometry_get(box, NULL, NULL, &w, NULL); | ||
1220 | evas_object_size_hint_min_get(box, &minw, NULL); | ||
1221 | |||
1222 | EINA_LIST_FOREACH(priv->children, l, opt) | ||
1223 | { | ||
1224 | evas_object_size_hint_min_get(opt->obj, &mnw, &mnh); | ||
1225 | evas_object_size_hint_weight_get(opt->obj, &wx, NULL); | ||
1226 | |||
1227 | if (wx) | ||
1228 | { | ||
1229 | if (mnw != -1 && (w - cw) >= mnw) | ||
1230 | ww = w - cw; | ||
1231 | else | ||
1232 | ww = w; | ||
1233 | } | ||
1234 | else | ||
1235 | ww = mnw; | ||
1236 | |||
1237 | if ((cw + mnw) > w) | ||
1238 | { | ||
1239 | minh += cmaxh; | ||
1240 | cw = 0; | ||
1241 | cmaxh = 0; | ||
1242 | } | ||
1243 | cw += ww; | ||
1244 | if (cmaxh < mnh) cmaxh = mnh; | ||
1245 | } | ||
1246 | |||
1247 | minh += cmaxh; | ||
1248 | |||
1249 | evas_object_size_hint_min_set(box, minw, minh); | ||
1250 | } | ||
1251 | |||
1252 | static Evas_Coord | ||
1253 | _calculate_item_max_height(Evas_Object *box, Evas_Object_Box_Data *priv, int obj_index) | ||
1254 | { | ||
1255 | Evas_Coord mnw, mnh, cw = 0, cmaxh = 0, w, ww; | ||
1256 | const Eina_List *l; | ||
1257 | Evas_Object_Box_Option *opt; | ||
1258 | int local_index = 0; | ||
1259 | double wx; | ||
1260 | |||
1261 | evas_object_geometry_get(box, NULL, NULL, &w, NULL); | ||
1262 | |||
1263 | EINA_LIST_FOREACH(priv->children, l, opt) | ||
1264 | { | ||
1265 | evas_object_size_hint_min_get(opt->obj, &mnw, &mnh); | ||
1266 | evas_object_size_hint_weight_get(opt->obj, &wx, NULL); | ||
1267 | |||
1268 | if (wx) | ||
1269 | { | ||
1270 | if (mnw != -1 && (w - cw) >= mnw) | ||
1271 | ww = w - cw; | ||
1272 | else | ||
1273 | ww = w; | ||
1274 | } | ||
1275 | else | ||
1276 | ww = mnw; | ||
1277 | |||
1278 | if ((cw + ww) > w) | ||
1279 | { | ||
1280 | if (local_index > obj_index) return cmaxh; | ||
1281 | cw = 0; | ||
1282 | cmaxh = 0; | ||
1283 | } | ||
1284 | |||
1285 | cw += ww; | ||
1286 | if (cmaxh < mnh) cmaxh = mnh; | ||
1287 | |||
1288 | local_index++; | ||
1289 | } | ||
1290 | |||
1291 | return cmaxh; | ||
1292 | } | ||
1293 | |||
1294 | static void | ||
1295 | _box_layout_cb(Evas_Object *o, Evas_Object_Box_Data *priv, void *data __UNUSED__) | ||
1296 | { | ||
1297 | Evas_Coord x, y, w, h, xx, yy; | ||
1298 | const Eina_List *l; | ||
1299 | Evas_Object *obj; | ||
1300 | Evas_Coord minw, minh; | ||
1301 | double ax, ay; | ||
1302 | Evas_Object_Box_Option *opt; | ||
1303 | |||
1304 | _calculate_box_min_size(o, priv); | ||
1305 | |||
1306 | evas_object_geometry_get(o, &x, &y, &w, &h); | ||
1307 | |||
1308 | evas_object_size_hint_min_get(o, &minw, &minh); | ||
1309 | evas_object_size_hint_align_get(o, &ax, &ay); | ||
1310 | if (w < minw) | ||
1311 | { | ||
1312 | x = x + ((w - minw) * (1.0 - ax)); | ||
1313 | w = minw; | ||
1314 | } | ||
1315 | if (h < minh) | ||
1316 | { | ||
1317 | y = y + ((h - minh) * (1.0 - ay)); | ||
1318 | h = minh; | ||
1319 | } | ||
1320 | |||
1321 | xx = x; | ||
1322 | yy = y; | ||
1323 | |||
1324 | Evas_Coord cw = 0, ch = 0, cmaxh = 0, obj_index = 0; | ||
1325 | |||
1326 | EINA_LIST_FOREACH(priv->children, l, opt) | ||
1327 | { | ||
1328 | Evas_Coord mnw, mnh, mxw, mxh; | ||
1329 | double wx, wy; | ||
1330 | int fw, fh; | ||
1331 | |||
1332 | obj = opt->obj; | ||
1333 | evas_object_size_hint_align_get(obj, &ax, &ay); | ||
1334 | evas_object_size_hint_weight_get(obj, &wx, &wy); | ||
1335 | evas_object_size_hint_min_get(obj, &mnw, &mnh); | ||
1336 | evas_object_size_hint_max_get(obj, &mxw, &mxh); | ||
1337 | fw = fh = 0; | ||
1338 | if (ax == -1.0) {fw = 1; ax = 0.5;} | ||
1339 | if (ay == -1.0) {fh = 1; ay = 0.5;} | ||
1340 | Evas_Coord ww, hh, ow, oh; | ||
1341 | |||
1342 | if (wx) | ||
1343 | { | ||
1344 | if (mnw != -1 && (w - cw) >= mnw) | ||
1345 | ww = w - cw; | ||
1346 | else | ||
1347 | ww = w; | ||
1348 | } | ||
1349 | else | ||
1350 | ww = mnw; | ||
1351 | hh = _calculate_item_max_height(o, priv, obj_index); | ||
1352 | |||
1353 | ow = mnw; | ||
1354 | if (fw) ow = ww; | ||
1355 | if ((mxw >= 0) && (mxw < ow)) ow = mxw; | ||
1356 | oh = mnh; | ||
1357 | if (fh) oh = hh; | ||
1358 | if ((mxh >= 0) && (mxh < oh)) oh = mxh; | ||
1359 | |||
1360 | if ((cw + ww) > w) | ||
1361 | { | ||
1362 | ch += cmaxh; | ||
1363 | cw = 0; | ||
1364 | cmaxh = 0; | ||
1365 | } | ||
1366 | |||
1367 | evas_object_move(obj, | ||
1368 | xx + cw + (Evas_Coord)(((double)(ww - ow)) * ax), | ||
1369 | yy + ch + (Evas_Coord)(((double)(hh - oh)) * ay)); | ||
1370 | evas_object_resize(obj, ow, oh); | ||
1371 | |||
1372 | cw += ww; | ||
1373 | if (cmaxh < hh) cmaxh = hh; | ||
1374 | |||
1375 | obj_index++; | ||
1376 | } | ||
1377 | } | ||
1378 | |||
1379 | static void | ||
1380 | _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label) | ||
1381 | { | ||
1382 | Elm_Multibuttonentry_Item *item; | ||
1383 | if (part && strcmp(part, "default")) return; | ||
1384 | if (!label) return; | ||
1385 | item = (Elm_Multibuttonentry_Item *)it; | ||
1386 | edje_object_part_text_escaped_set(item->button, "elm.btn.text", label); | ||
1387 | _resize_button(item->button, &item->rw, &item->vw); | ||
1388 | } | ||
1389 | |||
1390 | static const char * | ||
1391 | _item_text_get_hook(const Elm_Object_Item *it, const char *part) | ||
1392 | { | ||
1393 | Elm_Multibuttonentry_Item *item; | ||
1394 | if (part && strcmp(part, "default")) return NULL; | ||
1395 | item = (Elm_Multibuttonentry_Item *)it; | ||
1396 | return edje_object_part_text_get(item->button, "elm.btn.text"); | ||
1397 | } | ||
1398 | |||
1399 | static void | ||
1400 | _text_set_hook(Evas_Object *obj, const char *part, const char *label) | ||
1401 | { | ||
1402 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
1403 | if (!part || !strcmp(part, "default")) | ||
1404 | { | ||
1405 | if (label) _set_label(obj, label); | ||
1406 | else _set_label(obj, ""); | ||
1407 | } | ||
1408 | else if (!strcmp(part, "guide")) | ||
1409 | { | ||
1410 | if (label) _set_guidetext(obj, label); | ||
1411 | else _set_guidetext(obj, ""); | ||
1412 | } | ||
1413 | } | ||
1414 | |||
1415 | static const char * | ||
1416 | _text_get_hook(const Evas_Object *obj, const char *part) | ||
1417 | { | ||
1418 | ELM_CHECK_WIDTYPE(obj, widtype) NULL; | ||
1419 | Widget_Data *wd = elm_widget_data_get(obj); | ||
1420 | if (!wd) return NULL; | ||
1421 | |||
1422 | if (!part || !strcmp(part, "default")) | ||
1423 | { | ||
1424 | return wd->labeltxt; | ||
1425 | } | ||
1426 | else if (!strcmp(part, "guide")) | ||
1427 | { | ||
1428 | return wd->guidetexttxt; | ||
1429 | } | ||
1430 | return NULL; | ||
1431 | } | ||
1432 | |||
1433 | EAPI Evas_Object * | ||
1434 | elm_multibuttonentry_add(Evas_Object *parent) | ||
1435 | { | ||
1436 | Evas_Object *obj; | ||
1437 | Evas *e; | ||
1438 | Widget_Data *wd; | ||
1439 | |||
1440 | ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL); | ||
1441 | |||
1442 | ELM_SET_WIDTYPE(widtype, "multibuttonentry"); | ||
1443 | elm_widget_type_set(obj, "multibuttonentry"); | ||
1444 | elm_widget_sub_object_add(parent, obj); | ||
1445 | elm_widget_data_set(obj, wd); | ||
1446 | |||
1447 | elm_widget_del_hook_set(obj, _del_hook); | ||
1448 | elm_widget_theme_hook_set(obj, _theme_hook); | ||
1449 | elm_widget_event_hook_set(obj, _event_hook); | ||
1450 | elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL); | ||
1451 | elm_widget_signal_emit_hook_set(obj, _signal_emit_hook); | ||
1452 | elm_widget_text_set_hook_set(obj, _text_set_hook); | ||
1453 | elm_widget_text_get_hook_set(obj, _text_get_hook); | ||
1454 | |||
1455 | wd->base = edje_object_add(e); | ||
1456 | _elm_theme_object_set(obj, wd->base, "multibuttonentry", "base", "default"); | ||
1457 | elm_widget_resize_object_set(obj, wd->base); | ||
1458 | elm_widget_can_focus_set(obj, EINA_TRUE); | ||
1459 | |||
1460 | wd->view_state = MULTIBUTTONENTRY_VIEW_NONE; | ||
1461 | wd->focused = EINA_FALSE; | ||
1462 | wd->last_btn_select = EINA_TRUE; | ||
1463 | wd->n_str = 0; | ||
1464 | wd->rect_for_end = NULL; | ||
1465 | wd->add_callback = NULL; | ||
1466 | wd->add_callback_data = NULL; | ||
1467 | |||
1468 | evas_object_smart_callbacks_descriptions_set(obj, _signals); | ||
1469 | |||
1470 | _view_init(obj); | ||
1471 | _event_init(obj); | ||
1472 | |||
1473 | return obj; | ||
1474 | } | ||
1475 | |||
1476 | EAPI Evas_Object * | ||
1477 | elm_multibuttonentry_entry_get(const Evas_Object *obj) | ||
1478 | { | ||
1479 | ELM_CHECK_WIDTYPE(obj, widtype) NULL; | ||
1480 | Widget_Data *wd = elm_widget_data_get(obj); | ||
1481 | |||
1482 | if (!wd) return NULL; | ||
1483 | |||
1484 | return wd->entry; | ||
1485 | } | ||
1486 | |||
1487 | EAPI Eina_Bool | ||
1488 | elm_multibuttonentry_expanded_get(const Evas_Object *obj) | ||
1489 | { | ||
1490 | ELM_CHECK_WIDTYPE(obj, widtype) -1; | ||
1491 | Widget_Data *wd = elm_widget_data_get(obj); | ||
1492 | |||
1493 | if (!wd) return -1; | ||
1494 | return (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK ? EINA_FALSE : EINA_TRUE); | ||
1495 | } | ||
1496 | |||
1497 | EAPI void | ||
1498 | elm_multibuttonentry_expanded_set(Evas_Object *obj, Eina_Bool expanded) | ||
1499 | { | ||
1500 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
1501 | Widget_Data *wd = elm_widget_data_get(obj); | ||
1502 | |||
1503 | if (!wd || !wd->box || | ||
1504 | ((wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) ? EINA_FALSE : EINA_TRUE) == expanded) return; | ||
1505 | |||
1506 | if (expanded) | ||
1507 | _shrink_mode_set(obj, EINA_FALSE); | ||
1508 | else | ||
1509 | _shrink_mode_set(obj, EINA_TRUE); | ||
1510 | |||
1511 | } | ||
1512 | |||
1513 | EAPI Elm_Object_Item * | ||
1514 | elm_multibuttonentry_item_prepend(Evas_Object *obj, const char *label, Evas_Smart_Cb func, void *data) | ||
1515 | { | ||
1516 | return _add_button_item(obj, label, MULTIBUTTONENTRY_POS_START, NULL, func, data); | ||
1517 | } | ||
1518 | |||
1519 | EAPI Elm_Object_Item * | ||
1520 | elm_multibuttonentry_item_append(Evas_Object *obj, const char *label, Evas_Smart_Cb func, void *data) | ||
1521 | { | ||
1522 | return _add_button_item(obj, label, MULTIBUTTONENTRY_POS_END, NULL, func, data); | ||
1523 | } | ||
1524 | |||
1525 | EAPI Elm_Object_Item * | ||
1526 | elm_multibuttonentry_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *label, Evas_Smart_Cb func, void *data) | ||
1527 | { | ||
1528 | return _add_button_item(obj, label, MULTIBUTTONENTRY_POS_BEFORE, before, func, data); | ||
1529 | } | ||
1530 | |||
1531 | EAPI Elm_Object_Item * | ||
1532 | elm_multibuttonentry_item_insert_after(Evas_Object *obj, Elm_Object_Item *after, const char *label, Evas_Smart_Cb func, void *data) | ||
1533 | { | ||
1534 | return _add_button_item(obj, label, MULTIBUTTONENTRY_POS_AFTER, after, func, data); | ||
1535 | } | ||
1536 | |||
1537 | EAPI const Eina_List * | ||
1538 | elm_multibuttonentry_items_get(const Evas_Object *obj) | ||
1539 | { | ||
1540 | ELM_CHECK_WIDTYPE(obj, widtype) NULL; | ||
1541 | Widget_Data *wd = elm_widget_data_get(obj); | ||
1542 | if (!wd) return NULL; | ||
1543 | return wd->items; | ||
1544 | } | ||
1545 | |||
1546 | EAPI Elm_Object_Item * | ||
1547 | elm_multibuttonentry_first_item_get(const Evas_Object *obj) | ||
1548 | { | ||
1549 | ELM_CHECK_WIDTYPE(obj, widtype) NULL; | ||
1550 | Widget_Data *wd = elm_widget_data_get(obj); | ||
1551 | if (!wd) return NULL; | ||
1552 | return eina_list_data_get(wd->items); | ||
1553 | } | ||
1554 | |||
1555 | EAPI Elm_Object_Item * | ||
1556 | elm_multibuttonentry_last_item_get(const Evas_Object *obj) | ||
1557 | { | ||
1558 | ELM_CHECK_WIDTYPE(obj, widtype) NULL; | ||
1559 | Widget_Data *wd = elm_widget_data_get(obj); | ||
1560 | if (!wd) return NULL; | ||
1561 | return eina_list_data_get(eina_list_last(wd->items)); | ||
1562 | } | ||
1563 | |||
1564 | EAPI Elm_Object_Item * | ||
1565 | elm_multibuttonentry_selected_item_get(const Evas_Object *obj) | ||
1566 | { | ||
1567 | ELM_CHECK_WIDTYPE(obj, widtype) NULL; | ||
1568 | Widget_Data *wd = elm_widget_data_get(obj); | ||
1569 | if (!wd) return NULL; | ||
1570 | return wd->selected_it; | ||
1571 | } | ||
1572 | |||
1573 | EAPI void | ||
1574 | elm_multibuttonentry_item_selected_set(Elm_Object_Item *it, Eina_Bool selected) | ||
1575 | { | ||
1576 | ELM_OBJ_ITEM_CHECK_OR_RETURN(it); | ||
1577 | Elm_Multibuttonentry_Item *item = (Elm_Multibuttonentry_Item *)it; | ||
1578 | if (selected) _select_button(WIDGET(item), item->button); | ||
1579 | else _select_button(WIDGET(item), NULL); | ||
1580 | } | ||
1581 | |||
1582 | EAPI Eina_Bool | ||
1583 | elm_multibuttonentry_item_selected_get(const Elm_Object_Item *it) | ||
1584 | { | ||
1585 | //TODO : To be implemented. | ||
1586 | if (!it) return EINA_FALSE; | ||
1587 | return EINA_TRUE; | ||
1588 | } | ||
1589 | |||
1590 | EAPI void | ||
1591 | elm_multibuttonentry_clear(Evas_Object *obj) | ||
1592 | { | ||
1593 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
1594 | Elm_Multibuttonentry_Item *item; | ||
1595 | Widget_Data *wd = elm_widget_data_get(obj); | ||
1596 | if (!wd) return; | ||
1597 | |||
1598 | if (wd->items) | ||
1599 | { | ||
1600 | EINA_LIST_FREE(wd->items, item) | ||
1601 | { | ||
1602 | elm_box_unpack(wd->box, item->button); | ||
1603 | _del_button_obj(obj, item->button); | ||
1604 | free(item); | ||
1605 | } | ||
1606 | wd->items = NULL; | ||
1607 | } | ||
1608 | wd->selected_it = NULL; | ||
1609 | _view_update(obj); | ||
1610 | } | ||
1611 | |||
1612 | EAPI Elm_Object_Item * | ||
1613 | elm_multibuttonentry_item_prev_get(const Elm_Object_Item *it) | ||
1614 | { | ||
1615 | ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL); | ||
1616 | Widget_Data *wd; | ||
1617 | Eina_List *l; | ||
1618 | Elm_Multibuttonentry_Item *_item; | ||
1619 | |||
1620 | wd = elm_widget_data_get(WIDGET(it)); | ||
1621 | if (!wd) return NULL; | ||
1622 | |||
1623 | EINA_LIST_FOREACH(wd->items, l, _item) | ||
1624 | { | ||
1625 | if (_item == (Elm_Multibuttonentry_Item *)it) | ||
1626 | { | ||
1627 | l = eina_list_prev(l); | ||
1628 | if (!l) return NULL; | ||
1629 | return eina_list_data_get(l); | ||
1630 | } | ||
1631 | } | ||
1632 | return NULL; | ||
1633 | } | ||
1634 | |||
1635 | EAPI Elm_Object_Item * | ||
1636 | elm_multibuttonentry_item_next_get(const Elm_Object_Item *it) | ||
1637 | { | ||
1638 | ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL); | ||
1639 | Widget_Data *wd; | ||
1640 | Eina_List *l; | ||
1641 | Elm_Multibuttonentry_Item *_item; | ||
1642 | wd = elm_widget_data_get(WIDGET(it)); | ||
1643 | if (!wd) return NULL; | ||
1644 | |||
1645 | EINA_LIST_FOREACH(wd->items, l, _item) | ||
1646 | { | ||
1647 | if (_item == (Elm_Multibuttonentry_Item *)it) | ||
1648 | { | ||
1649 | l = eina_list_next(l); | ||
1650 | if (!l) return NULL; | ||
1651 | return eina_list_data_get(l); | ||
1652 | } | ||
1653 | } | ||
1654 | return NULL; | ||
1655 | } | ||
1656 | |||
1657 | EINA_DEPRECATED EAPI void * | ||
1658 | elm_multibuttonentry_item_data_get(const Elm_Object_Item *it) | ||
1659 | { | ||
1660 | return elm_widget_item_data_get(it); | ||
1661 | } | ||
1662 | |||
1663 | EINA_DEPRECATED EAPI void | ||
1664 | elm_multibuttonentry_item_data_set(Elm_Object_Item *it, void *data) | ||
1665 | { | ||
1666 | return elm_widget_item_data_set(it, data); | ||
1667 | } | ||
1668 | |||
1669 | EAPI void | ||
1670 | elm_multibuttonentry_item_filter_append(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_Cb func, void *data) | ||
1671 | { | ||
1672 | Elm_Multibuttonentry_Item_Filter *new_item_filter = NULL; | ||
1673 | Elm_Multibuttonentry_Item_Filter *_item_filter = NULL; | ||
1674 | Eina_List *l; | ||
1675 | |||
1676 | Widget_Data *wd = elm_widget_data_get(obj); | ||
1677 | if (!wd) return; | ||
1678 | |||
1679 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
1680 | EINA_SAFETY_ON_NULL_RETURN(func); | ||
1681 | |||
1682 | new_item_filter= _filter_new(func, data); | ||
1683 | if (!new_item_filter) return; | ||
1684 | |||
1685 | EINA_LIST_FOREACH(wd->filter_list, l, _item_filter) | ||
1686 | { | ||
1687 | if (_item_filter && ((_item_filter->callback_func == func) && (_item_filter->data == data))) | ||
1688 | { | ||
1689 | printf("Already Registered this item filter!!!!\n"); | ||
1690 | return; | ||
1691 | } | ||
1692 | } | ||
1693 | wd->filter_list = eina_list_append(wd->filter_list, new_item_filter); | ||
1694 | } | ||
1695 | |||
1696 | EAPI void | ||
1697 | elm_multibuttonentry_item_filter_prepend(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_Cb func, void *data) | ||
1698 | { | ||
1699 | Elm_Multibuttonentry_Item_Filter *new_item_filter = NULL; | ||
1700 | Elm_Multibuttonentry_Item_Filter *_item_filter = NULL; | ||
1701 | Eina_List *l; | ||
1702 | Widget_Data *wd = elm_widget_data_get(obj); | ||
1703 | if (!wd) return; | ||
1704 | |||
1705 | ELM_CHECK_WIDTYPE(obj, widtype); | ||
1706 | EINA_SAFETY_ON_NULL_RETURN(func); | ||
1707 | |||
1708 | new_item_filter = _filter_new(func, data); | ||
1709 | if (!new_item_filter) return; | ||
1710 | |||
1711 | EINA_LIST_FOREACH(wd->filter_list, l, _item_filter) | ||
1712 | { | ||
1713 | if (_item_filter && ((_item_filter->callback_func == func) && (_item_filter->data == data))) | ||
1714 | { | ||
1715 | printf("Already Registered this item filter!!!!\n"); | ||
1716 | return; | ||
1717 | } | ||
1718 | } | ||
1719 | wd->filter_list = eina_list_prepend(wd->filter_list, new_item_filter); | ||
1720 | } | ||
1721 | |||
1722 | EAPI void | ||
1723 | elm_multibuttonentry_item_filter_remove(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_Cb func, void *data) | ||
1724 | { | ||
1725 | Widget_Data *wd; | ||
1726 | Eina_List *l; | ||
1727 | Elm_Multibuttonentry_Item_Filter *item_filter; | ||
1728 | |||
1729 | wd = elm_widget_data_get(obj); | ||
1730 | |||
1731 | EINA_SAFETY_ON_NULL_RETURN(func); | ||
1732 | |||
1733 | EINA_LIST_FOREACH(wd->filter_list, l, item_filter) | ||
1734 | { | ||
1735 | if ((item_filter->callback_func == func) && ((!data) || (item_filter->data == data))) | ||
1736 | { | ||
1737 | wd->filter_list = eina_list_remove_list(wd->filter_list, l); | ||
1738 | _filter_free(item_filter); | ||
1739 | return; | ||
1740 | } | ||
1741 | } | ||
1742 | } | ||