1 #include <Elementary.h>
3 #include "elm_widget_multibuttonentry.h"
8 #define TRANSIT_DURATION 0.167
9 #define ANIMATE_FRAME 10
12 EAPI const char ELM_MULTIBUTTONENTRY_SMART_NAME[] = "elm_multibuttonentry";
15 static const char SIG_ITEM_SELECTED[] = "item,selected";
16 static const char SIG_ITEM_ADDED[] = "item,added";
17 static const char SIG_ITEM_DELETED[] = "item,deleted";
18 static const char SIG_ITEM_CLICKED[] = "item,clicked";
19 static const char SIG_CLICKED[] = "clicked";
20 static const char SIG_FOCUSED[] = "focused";
21 static const char SIG_UNFOCUSED[] = "unfocused";
22 static const char SIG_EXPANDED[] = "expanded";
23 static const char SIG_CONTRACTED[] = "contracted";
24 static const char SIG_EXPAND_STATE_CHANGED[] = "expand,state,changed";
25 static const char SIG_LONGPRESSED[] = "longpressed";
27 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
28 {SIG_ITEM_SELECTED, ""},
30 {SIG_ITEM_DELETED, ""},
31 {SIG_ITEM_CLICKED, ""},
37 {SIG_EXPAND_STATE_CHANGED, ""},
38 {SIG_LONGPRESSED, ""},
42 EVAS_SMART_SUBCLASS_NEW
43 (ELM_MULTIBUTTONENTRY_SMART_NAME, _elm_multibuttonentry,
44 Elm_Multibuttonentry_Smart_Class, Elm_Layout_Smart_Class,
45 elm_layout_smart_class_get, _smart_callbacks);
48 _elm_multibuttonentry_smart_focus_next(const Evas_Object *obj,
49 Elm_Focus_Direction dir,
52 Eina_List *items = NULL;
53 Eina_List *elist = NULL;
54 Elm_Multibuttonentry_Item *it;
56 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
61 if (!elm_widget_focus_next_get(sd->box, dir, next))
63 elm_widget_focused_object_clear(sd->box);
64 elm_widget_focus_next_get(sd->box, dir, next);
67 EINA_LIST_FOREACH(sd->items, elist, it)
68 items = eina_list_append(items, it->base.access_obj);
70 return elm_widget_focus_list_next_get
71 (obj, items, eina_list_data_get, dir, next);
75 _access_label_info_cb(void *data, Evas_Object *obj __UNUSED__)
77 Evas_Object *mbe = (Evas_Object *)data;
78 const char *txt = NULL;
80 ELM_MULTIBUTTONENTRY_DATA_GET(mbe, sd);
82 if (!mbe) return NULL;
86 txt = elm_object_part_text_get(sd->label, "mbe.label");
89 else return strdup(txt);
95 _access_shrink_info_cb(void *data, Evas_Object *obj __UNUSED__)
97 Evas_Object *mbe = (Evas_Object *)data;
98 const char *txt = NULL;
99 Eina_Strbuf *buf = NULL;
102 ELM_MULTIBUTTONENTRY_DATA_GET(mbe, sd);
104 if (!mbe) return NULL;
106 if (!txt) txt = elm_object_text_get(sd->end);
109 buf = eina_strbuf_new();
110 eina_strbuf_append(buf, E_("And "));
111 eina_strbuf_append(buf, txt);
112 eina_strbuf_append(buf, E_(" more"));
113 str = eina_strbuf_string_steal(buf);
114 eina_strbuf_free(buf);
121 _guide_packed(Evas_Object *obj)
125 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
127 if (!sd->guide) return EINA_FALSE;
129 children = elm_box_children_get(sd->box);
130 if (sd->guide == eina_list_data_get(eina_list_last(children)))
132 eina_list_free(children);
137 eina_list_free(children);
143 _label_packed(Evas_Object *obj)
147 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
149 if (!sd->label) return EINA_FALSE;
151 children = elm_box_children_get(sd->box);
152 if (sd->label == eina_list_data_get(children))
154 eina_list_free(children);
159 eina_list_free(children);
165 _guide_set(Evas_Object *obj,
168 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
170 if (!sd->guide && !strlen(text)) return;
174 sd->guide = elm_layout_add(obj);
176 (sd->guide, "multibuttonentry", "guidetext", elm_widget_style_get(obj));
177 evas_object_size_hint_weight_set
178 (sd->guide, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
179 evas_object_size_hint_align_set
180 (sd->guide, EVAS_HINT_FILL, EVAS_HINT_FILL);
182 elm_object_text_set(sd->guide, text);
184 if (!sd->items && !elm_object_focus_get(obj) && !_guide_packed(obj))
188 elm_box_unpack(sd->box, sd->entry);
189 evas_object_hide(sd->entry);
192 elm_box_pack_end(sd->box, sd->guide);
193 evas_object_show(sd->guide);
198 _label_set(Evas_Object *obj,
201 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
203 if (!sd->label && !strlen(text)) return;
207 sd->label = elm_layout_add(obj);
209 (sd->label, "multibuttonentry", "label", elm_widget_style_get(obj));
211 elm_object_part_text_set(sd->label, "mbe.label", text);
213 if (strlen(text) && !_label_packed(obj))
215 elm_box_pack_start(sd->box, sd->label);
216 evas_object_show(sd->label);
218 else if (!strlen(text) && _label_packed(obj))
220 elm_box_unpack(sd->box, sd->label);
221 evas_object_hide(sd->label);
225 if (_elm_config->access_mode)
227 _elm_access_object_register(obj, ELM_WIDGET_DATA(sd)->resize_obj);
228 _elm_access_callback_set(_elm_access_object_get(obj), ELM_ACCESS_INFO, _access_label_info_cb, obj);
234 _box_layout_pre_calculate(Evas_Object *obj,
235 Elm_Multibuttonentry_Item *except_it,
236 Evas_Coord *minh_wo_entry,
239 Evas_Coord mnw, mnh, x, w, hpad = 0, vpad = 0;
240 Evas_Coord linew = 0, lineh = 0;
243 Elm_Multibuttonentry_Item *it;
245 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
247 evas_object_geometry_get(sd->box, &x, NULL, &w, NULL);
248 elm_box_padding_get(sd->box, &hpad, &vpad);
252 if (sd->label && _label_packed(obj))
254 evas_object_size_hint_min_get(sd->label, &mnw, &mnh);
261 EINA_LIST_FOREACH(sd->items, l, it)
263 if (it == except_it) continue;
265 evas_object_size_hint_min_get(VIEW(it), &mnw, &mnh);
268 if (lineh < mnh) lineh = mnh;
281 *minh_wo_entry = lineh * line_num + (line_num - 1) * vpad;
285 // get entry size after text is reset
286 elm_object_text_set(sd->entry, "");
287 elm_layout_sizing_eval(sd->entry);
288 evas_object_size_hint_min_get(sd->entry, &mnw, &mnh);
291 if (lineh < mnh) lineh = mnh;
293 if (linew > w) line_num++;
297 *minh = lineh * line_num + (line_num - 1) * vpad;
301 _on_item_expanding_transit_del(void *data,
302 Elm_Transit *transit __UNUSED__)
304 Elm_Multibuttonentry_Item *it = data;
306 evas_object_data_set(VIEW(it), "transit", NULL);
307 evas_object_smart_callback_call(WIDGET(it), SIG_ITEM_ADDED, it);
311 _rect_expanding_animate(void *data)
315 Elm_Multibuttonentry_Item *it = data;
317 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
319 rect = (Evas_Object *)evas_object_data_get(VIEW(it), "effect_rect");
320 if (!rect) return ECORE_CALLBACK_CANCEL;
322 evas_object_geometry_get(sd->entry, NULL, NULL, NULL, &eh);
323 evas_object_size_hint_min_get(rect, &w, &h);
328 Elm_Multibuttonentry_Item *last_it;
330 evas_object_del(rect);
331 evas_object_data_set(VIEW(it), "effect_rect", NULL);
333 // if last item is unpacked, add it
334 children = elm_box_children_get(sd->box);
335 last_it = eina_list_data_get(eina_list_last(sd->items));
336 if (VIEW(last_it) != eina_list_data_get(eina_list_last(children)))
338 elm_box_pack_end(sd->box, VIEW(last_it));
339 evas_object_show(VIEW(last_it));
341 eina_list_free(children);
345 elm_box_pack_end(sd->box, sd->entry);
346 evas_object_show(sd->entry);
347 if (elm_object_focus_get(WIDGET(it)))
348 elm_object_focus_set(sd->entry, EINA_TRUE);
351 return ECORE_CALLBACK_CANCEL;
354 evas_object_size_hint_min_set(rect, w, h + eh / ANIMATE_FRAME);
356 return ECORE_CALLBACK_RENEW;
360 _item_adding_effect_add(Evas_Object *obj,
361 Elm_Multibuttonentry_Item *it)
364 Evas_Coord minh_wo_entry, minh;
365 Eina_Bool floating = EINA_FALSE;;
367 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
369 _box_layout_pre_calculate(obj, NULL, &minh_wo_entry, &minh);
371 // if box will be expanded, add resizing effect
374 Evas_Coord bx, by, bw, bh;
376 Ecore_Animator *anim;
378 evas_object_geometry_get(sd->box, &bx, &by, &bw, &bh);
380 // if box will be expanded with item and entry
381 if (minh_wo_entry == minh)
383 Elm_Multibuttonentry_Item *last_it;
385 last_it = eina_list_data_get(eina_list_last(sd->items));
388 Evas_Coord iw, ih, vpad;
390 evas_object_size_hint_min_get(VIEW(it), &iw, &ih);
391 elm_box_padding_get(sd->box, NULL, &vpad);
393 evas_object_move(VIEW(it), bx, by + bh + vpad);
394 evas_object_resize(VIEW(it), iw, ih);
395 evas_object_show(VIEW(it));
397 floating = EINA_TRUE;
401 elm_box_unpack(sd->box, VIEW(last_it));
402 evas_object_hide(VIEW(last_it));
408 if (elm_object_focus_get(sd->entry))
409 elm_object_focus_set(sd->entry, EINA_FALSE);
410 elm_box_unpack(sd->box, sd->entry);
411 evas_object_hide(sd->entry);
412 elm_entry_input_panel_show(sd->entry);
415 rect = evas_object_rectangle_add(evas_object_evas_get(obj));
416 evas_object_color_set(rect, 0, 0, 0, 0);
417 evas_object_size_hint_min_set(rect, bw, 0);
418 evas_object_data_set(VIEW(it), "effect_rect", rect);
419 elm_box_pack_end(sd->box, rect);
420 evas_object_show(rect);
422 anim = ecore_animator_add(_rect_expanding_animate, it);
423 evas_object_data_set(rect, "animator", anim);
429 cur = eina_list_data_find_list(sd->items, it);
430 if (cur == sd->items)
432 if (sd->label && _label_packed(obj))
433 elm_box_pack_after(sd->box, VIEW(it), sd->label);
435 elm_box_pack_start(sd->box, VIEW(it));
439 Elm_Multibuttonentry_Item *prev_it;
440 prev_it = eina_list_data_get(eina_list_prev(cur));
441 elm_box_pack_after(sd->box, VIEW(it), VIEW(prev_it));
443 evas_object_show(VIEW(it));
446 trans = elm_transit_add();
447 elm_transit_object_add(trans, VIEW(it));
448 elm_transit_effect_zoom_add(trans, 0.9, 1.0);
449 elm_transit_effect_color_add(trans, 0, 0, 0, 0, 255, 255, 255, 255);
450 elm_transit_del_cb_set(trans, _on_item_expanding_transit_del, it);
451 elm_transit_duration_set(trans, TRANSIT_DURATION);
452 evas_object_data_set(VIEW(it), "transit", trans);
453 elm_transit_go(trans);
457 _on_item_contracting_transit_del(void *data,
458 Elm_Transit *transit __UNUSED__)
461 Elm_Multibuttonentry_Item *it = data;
463 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
465 evas_object_data_set(VIEW(it), "transit", NULL);
467 rect = (Evas_Object *)evas_object_data_get(VIEW(it), "effect_rect");
470 evas_object_hide(VIEW(it));
474 // delete item and set focus to entry
475 if (sd->editable && elm_object_focus_get(WIDGET(it)))
476 elm_object_focus_set(sd->entry, EINA_TRUE);
478 elm_object_item_del((Elm_Object_Item *)it);
482 _rect_contracting_animate(void *data)
486 Elm_Multibuttonentry_Item *it = data;
488 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
490 rect = (Evas_Object *)evas_object_data_get(VIEW(it), "effect_rect");
491 if (!rect) return ECORE_CALLBACK_CANCEL;
493 evas_object_geometry_get(sd->entry, NULL, NULL, NULL, &eh);
494 evas_object_size_hint_min_get(rect, &w, &h);
499 Elm_Multibuttonentry_Item *last_it;
501 evas_object_del(rect);
502 evas_object_data_set(VIEW(it), "effect_rect", NULL);
504 // if last item is unpacked, add it
505 last_it = eina_list_data_get(eina_list_last(sd->items));
508 if (!evas_object_visible_get(VIEW(last_it)))
510 elm_box_pack_end(sd->box, VIEW(last_it));
511 evas_object_show(VIEW(last_it));
517 elm_box_pack_end(sd->box, sd->entry);
518 evas_object_show(sd->entry);
519 if (elm_object_focus_get(WIDGET(it)))
520 elm_object_focus_set(sd->entry, EINA_TRUE);
524 trans = (Elm_Transit *)evas_object_data_get(VIEW(it), "transit");
526 _on_item_contracting_transit_del(it, NULL);
528 return ECORE_CALLBACK_CANCEL;
531 evas_object_size_hint_min_set(rect, w, h - eh / ANIMATE_FRAME);
533 return ECORE_CALLBACK_RENEW;
537 _item_deleting_effect_add(Evas_Object *obj,
538 Elm_Multibuttonentry_Item *it)
543 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
545 _box_layout_pre_calculate(obj, it, NULL, &minh);
547 // if box will be contracted, add resizing effect
550 Evas_Coord bx, bw, ix, eh;
551 Ecore_Animator *anim;
553 Elm_Multibuttonentry_Item *last_it;
555 last_it = eina_list_data_get(eina_list_last(sd->items));
556 evas_object_geometry_get(sd->box, &bx, NULL, &bw, NULL);
557 evas_object_geometry_get(VIEW(last_it), &ix, NULL, NULL, NULL);
559 // if box will be contracted with item and entry
563 elm_box_unpack(sd->box, VIEW(it));
566 elm_box_unpack(sd->box, VIEW(last_it));
567 evas_object_hide(VIEW(last_it));
573 if (elm_object_focus_get(sd->entry))
574 elm_object_focus_set(sd->entry, EINA_FALSE);
575 elm_box_unpack(sd->box, sd->entry);
576 evas_object_hide(sd->entry);
577 elm_entry_input_panel_show(sd->entry);
580 rect = evas_object_rectangle_add(evas_object_evas_get(obj));
581 evas_object_color_set(rect, 0, 0, 0, 0);
582 evas_object_geometry_get(sd->entry, NULL, NULL, NULL, &eh);
583 evas_object_size_hint_min_set(rect, bw, eh);
584 evas_object_data_set(VIEW(it), "effect_rect", rect);
585 elm_box_pack_end(sd->box, rect);
586 evas_object_show(rect);
588 anim = ecore_animator_add(_rect_contracting_animate, it);
589 evas_object_data_set(rect, "animator", anim);
592 trans = elm_transit_add();
593 elm_transit_object_add(trans, VIEW(it));
594 elm_transit_effect_zoom_add(trans, 1.0, 0.9);
595 elm_transit_effect_color_add(trans, 255, 255, 255, 255, 0, 0, 0, 0);
596 elm_transit_del_cb_set(trans, _on_item_contracting_transit_del, it);
597 elm_transit_duration_set(trans, TRANSIT_DURATION);
598 evas_object_data_set(VIEW(it), "transit", trans);
599 elm_transit_go(trans);
605 _layout_expand(Evas_Object *obj)
607 int count, items_count, i;
609 Elm_Multibuttonentry_Item *it;
611 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
613 if (!sd->items) return;
614 if (sd->expanded_state) return;
616 children = elm_box_children_get(sd->box);
617 count = eina_list_count(children);
620 evas_object_del(sd->end);
624 if (sd->label && _label_packed(obj)) count--;
625 eina_list_free(children);
627 items_count = eina_list_count(sd->items);
628 for (i = count; i < items_count; i++)
630 it = eina_list_nth(sd->items, i);
631 elm_box_pack_end(sd->box, VIEW(it));
632 evas_object_show(VIEW(it));
637 elm_box_pack_end(sd->box, sd->entry);
638 evas_object_show(sd->entry);
641 sd->expanded_state = EINA_TRUE;
642 evas_object_smart_callback_call(obj, SIG_EXPAND_STATE_CHANGED, NULL);
646 _layout_shrink(Evas_Object *obj,
649 Evas_Coord w, mnw, linew = 0, hpad = 0;
650 int count = 0, items_count, i;
651 Eina_List *l, *children;
653 Elm_Multibuttonentry_Item *it;
657 Ecore_Animator *anim;
660 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
662 if (!sd->items) return;
663 if (!sd->expanded_state && !force) return;
665 evas_object_geometry_get(sd->box, NULL, NULL, &w, NULL);
666 elm_box_padding_get(sd->box, &hpad, NULL);
668 if (sd->label && _label_packed(obj))
670 evas_object_size_hint_min_get(sd->label, &mnw, NULL);
675 EINA_LIST_FOREACH(sd->items, l, it)
677 evas_object_size_hint_min_get(VIEW(it), &mnw, NULL);
692 items_count = eina_list_count(sd->items);
693 if (count < items_count)
695 const char *str = NULL;
698 str = elm_layout_data_get(obj, "closed_button_type");
701 sd->end = elm_layout_add(obj);
702 if (str && !strcmp(str, "image"))
703 elm_layout_theme_set(sd->end, "multibuttonentry",
704 "closedbutton", elm_widget_style_get(obj));
706 elm_layout_theme_set(sd->end, "multibuttonentry",
707 "number", elm_widget_style_get(obj));
709 if (!str || strcmp(str, "image"))
711 snprintf(buf, sizeof(buf), "+%d", items_count - count);
712 elm_object_text_set(sd->end, buf);
715 if (_elm_config->access_mode && sd->end)
717 _elm_access_object_register(obj, ELM_WIDGET_DATA(sd)->resize_obj);
718 _elm_access_callback_set(_elm_access_object_get(obj), ELM_ACCESS_INFO, _access_shrink_info_cb, obj);
721 evas_object_smart_calculate(sd->end);
722 evas_object_size_hint_min_get(sd->end, &mnw, NULL);
728 if (!str || strcmp(str, "image"))
730 snprintf(buf, sizeof(buf), "+%d", items_count - count);
731 elm_object_text_set(sd->end, buf);
734 if (_elm_config->access_mode && sd->end)
736 _elm_access_object_register(obj, ELM_WIDGET_DATA(sd)->resize_obj);
737 _elm_access_callback_set(_elm_access_object_get(obj), ELM_ACCESS_INFO, _access_shrink_info_cb, obj);
745 // reset last inserted item's effect_rect
746 it = eina_list_nth(sd->items, count - 1);
747 rect = (Evas_Object *)evas_object_data_get(VIEW(it), "effect_rect");
750 anim = (Ecore_Animator*)evas_object_data_get(rect, "animator");
751 if (anim) ecore_animator_del(anim);
753 evas_object_del(rect);
754 evas_object_data_set(VIEW(it), "effect_rect", NULL);
758 for (i = count; i < items_count; i++)
760 it = eina_list_nth(sd->items, i);
763 trans = (Elm_Transit *)evas_object_data_get(VIEW(it), "transit");
764 if (trans) elm_transit_del(trans);
766 rect = (Evas_Object *)evas_object_data_get(VIEW(it), "effect_rect");
769 anim = (Ecore_Animator*)evas_object_data_get(rect, "animator");
770 if (anim) ecore_animator_del(anim);
772 evas_object_del(rect);
773 evas_object_data_set(VIEW(it), "effect_rect", NULL);
776 elm_box_unpack(sd->box, VIEW(it));
777 evas_object_hide(VIEW(it));
782 elm_box_unpack(sd->box, sd->entry);
783 evas_object_hide(sd->entry);
788 // if it is called from item_append_xxx, item_del functions,
789 // all items are unpacked and packed again
791 // reset last inserted item's effect_rect
792 it = eina_list_nth(sd->items, count - 1);
793 rect = (Evas_Object *)evas_object_data_get(VIEW(it), "effect_rect");
796 anim = (Ecore_Animator*)evas_object_data_get(rect, "animator");
797 if (anim) ecore_animator_del(anim);
799 evas_object_del(rect);
800 evas_object_data_set(VIEW(it), "effect_rect", NULL);
803 for (i = count; i < items_count; i++)
805 it = eina_list_nth(sd->items, i);
807 trans = (Elm_Transit *)evas_object_data_get(VIEW(it), "transit");
808 if (trans) elm_transit_del(trans);
810 rect = (Evas_Object *)evas_object_data_get(VIEW(it), "effect_rect");
813 anim = (Ecore_Animator*)evas_object_data_get(rect, "animator");
814 if (anim) ecore_animator_del(anim);
816 evas_object_del(rect);
817 evas_object_data_set(VIEW(it), "effect_rect", NULL);
822 children = elm_box_children_get(sd->box);
823 EINA_LIST_FREE(children, child)
825 if (child != sd->label)
827 elm_box_unpack(sd->box, child);
828 evas_object_hide(child);
832 for (i = 0; i < count; i++)
834 it = eina_list_nth(sd->items, i);
835 elm_box_pack_end(sd->box, VIEW(it));
836 evas_object_show(VIEW(it));
840 elm_box_pack_end(sd->box, sd->end);
841 evas_object_show(sd->end);
843 sd->expanded_state = EINA_FALSE;
850 // reset last inserted item's effect_rect
851 it = eina_list_nth(sd->items, count - 1);
852 rect = (Evas_Object *)evas_object_data_get(VIEW(it), "effect_rect");
855 anim = (Ecore_Animator*)evas_object_data_get(rect, "animator");
856 if (anim) ecore_animator_del(anim);
858 evas_object_del(rect);
859 evas_object_data_set(VIEW(it), "effect_rect", NULL);
863 elm_box_pack_end(sd->box, sd->entry);
864 evas_object_show(sd->entry);
865 if (elm_object_focus_get(WIDGET(it)))
866 elm_object_focus_set(sd->entry, EINA_TRUE);
872 evas_object_size_hint_min_get(sd->entry, &mnw, NULL);
876 elm_box_unpack(sd->box, sd->entry);
877 evas_object_hide(sd->entry);
878 sd->expanded_state = EINA_FALSE;
886 evas_object_del(sd->end);
890 // if it is called from item_append_xxx, item_del functions,
891 // all items are unpacked and packed again
893 // reset last inserted item's effect_rect
894 it = eina_list_nth(sd->items, count - 1);
895 rect = (Evas_Object *)evas_object_data_get(VIEW(it), "effect_rect");
898 anim = (Ecore_Animator*)evas_object_data_get(rect, "animator");
899 if (anim) ecore_animator_del(anim);
901 evas_object_del(rect);
902 evas_object_data_set(VIEW(it), "effect_rect", NULL);
906 children = elm_box_children_get(sd->box);
907 EINA_LIST_FREE(children, child)
909 if (child != sd->label)
911 elm_box_unpack(sd->box, child);
912 evas_object_hide(child);
916 for (i = 0; i < count; i++)
918 it = eina_list_nth(sd->items, i);
919 elm_box_pack_end(sd->box, VIEW(it));
920 evas_object_show(VIEW(it));
923 sd->expanded_state = EINA_TRUE;
927 evas_object_size_hint_min_get(sd->entry, &mnw, NULL);
930 sd->expanded_state = EINA_FALSE;
933 elm_box_pack_end(sd->box, sd->entry);
934 evas_object_show(sd->entry);
940 if (!sd->expanded_state && !force)
941 evas_object_smart_callback_call(obj, SIG_EXPAND_STATE_CHANGED, NULL);
945 _box_min_size_calculate(Evas_Object *box,
946 Evas_Object_Box_Data *priv,
949 Evas_Coord mnw, mnh, w, minw, minh = 0, linew = 0, lineh = 0;
952 Evas_Object_Box_Option *opt;
954 evas_object_geometry_get(box, NULL, NULL, &w, NULL);
955 evas_object_size_hint_min_get(box, &minw, NULL);
956 if (!w) return EINA_FALSE;
959 EINA_LIST_FOREACH(priv->children, l, opt)
961 evas_object_size_hint_min_get(opt->obj, &mnw, &mnh);
965 !strcmp(evas_object_type_get(opt->obj), "rectangle"))
970 if (lineh < mnh) lineh = mnh;
978 if (l != eina_list_last(priv->children))
979 linew += priv->pad.h;
982 minh = lineh * line_num + (line_num - 1) * priv->pad.v;
985 // if last item is effect_rect
986 if (opt && opt->obj && mnw == w &&
987 !strcmp(evas_object_type_get(opt->obj), "rectangle"))
994 evas_object_size_hint_min_set(box, minw, minh);
995 *line_height = lineh;
1001 _box_layout(Evas_Object *o,
1002 Evas_Object_Box_Data *priv,
1005 Evas_Coord x, y, w, h, xx, yy, minw, minh, linew = 0, lineh = 0;
1010 Evas_Object_Box_Option *opt;
1012 if (!_box_min_size_calculate(o, priv, &lineh)) return;
1014 evas_object_geometry_get(o, &x, &y, &w, &h);
1015 evas_object_size_hint_min_get(o, &minw, &minh);
1016 evas_object_size_hint_align_get(o, &ax, &ay);
1018 rtl = elm_widget_mirrored_get(data);
1019 if (rtl) ax = 1.0 - ax;
1023 x = x + ((w - minw) * (1.0 - ax));
1028 y = y + ((h - minh) * (1.0 - ay));
1034 EINA_LIST_FOREACH(priv->children, l, opt)
1036 Evas_Coord mnw, mnh, ww, hh, ow, oh;
1038 Eina_Bool fw, fh, xw, xh;
1041 evas_object_size_hint_align_get(obj, &ax, &ay);
1042 evas_object_size_hint_weight_get(obj, &wx, &wy);
1043 evas_object_size_hint_min_get(obj, &mnw, &mnh);
1045 fw = fh = EINA_FALSE;
1046 xw = xh = EINA_FALSE;
1047 if (ax == -1.0) {fw = EINA_TRUE; ax = 0.5;}
1048 if (ay == -1.0) {fh = EINA_TRUE; ay = 0.5;}
1049 if (rtl) ax = 1.0 - ax;
1050 if (wx > 0.0) xw = EINA_TRUE;
1051 if (wy > 0.0) xh = EINA_TRUE;
1056 if (ww <= w - linew) ww = w - linew;
1067 if (linew > w && l != priv->children)
1074 linew += priv->pad.h;
1076 evas_object_move(obj,
1077 ((!rtl) ? (xx) : (x + (w - (xx - x) - ww)))
1078 + (Evas_Coord)(((double)(ww - ow)) * ax),
1079 yy + (Evas_Coord)(((double)(hh - oh)) * ay));
1080 evas_object_resize(obj, ow, oh);
1088 _on_box_resize(void *data,
1091 void *event_info __UNUSED__)
1095 ELM_MULTIBUTTONENTRY_DATA_GET(data, sd);
1097 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
1100 evas_object_smart_callback_call(data, SIG_EXPANDED, NULL);
1101 else if (sd->boxh > h)
1102 evas_object_smart_callback_call(data, SIG_CONTRACTED, NULL);
1104 // on rotation, items should be packed again in the shrinked layout
1105 if (sd->boxw && sd->boxw != w)
1107 if (!elm_object_focus_get(data) && !sd->expanded)
1108 _layout_shrink(data, EINA_TRUE);
1115 static Elm_Multibuttonentry_Item_Filter *
1116 _filter_new(Elm_Multibuttonentry_Item_Filter_Cb func,
1119 Elm_Multibuttonentry_Item_Filter *ft;
1121 ft = ELM_NEW(Elm_Multibuttonentry_Item_Filter);
1122 if (!ft) return NULL;
1131 _on_item_clicked(void *data,
1132 Evas_Object *obj __UNUSED__,
1133 const char *emission __UNUSED__,
1134 const char *source __UNUSED__)
1136 Elm_Multibuttonentry_Item *it = data;
1138 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
1140 evas_object_focus_set(elm_layout_edje_get(VIEW(it)), EINA_TRUE);
1142 // handles input panel because it can be hidden by user
1144 elm_entry_input_panel_show(sd->entry);
1146 evas_object_smart_callback_call(WIDGET(it), SIG_ITEM_CLICKED, it);
1150 _on_item_selected(void *data,
1151 Evas_Object *obj __UNUSED__,
1152 const char *emission __UNUSED__,
1153 const char *source __UNUSED__)
1155 Elm_Multibuttonentry_Item *it = data;
1157 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
1159 evas_object_smart_callback_call(WIDGET(it), SIG_ITEM_SELECTED, it);
1163 _on_item_focus(void *data,
1166 void *event_info __UNUSED__)
1168 Elm_Multibuttonentry_Item *it = data;
1170 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
1172 if (evas_object_focus_get(obj))
1174 if (elm_object_focus_get(sd->entry))
1175 elm_object_focus_set(sd->entry, EINA_FALSE);
1177 sd->selected_item = (Elm_Object_Item *)it;
1178 elm_layout_signal_emit(VIEW(it), "focused", "");
1181 elm_entry_input_panel_show(sd->entry);
1185 sd->selected_item = NULL;
1186 elm_layout_signal_emit(VIEW(it), "default", "");
1189 elm_entry_input_panel_hide(sd->entry);
1194 _long_press_cb(void *data)
1196 Elm_Multibuttonentry_Item *it = data;
1198 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
1200 sd->longpress_timer = NULL;
1201 sd->long_pressed = EINA_TRUE;
1203 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
1205 return ECORE_CALLBACK_CANCEL;
1209 _mouse_down_cb(Elm_Multibuttonentry_Item *it,
1210 Evas *evas __UNUSED__,
1211 Evas_Object *obj __UNUSED__,
1212 Evas_Event_Mouse_Down *ev)
1214 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
1216 if (ev->button != 1) return;
1218 sd->long_pressed = EINA_FALSE;
1220 if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer);
1221 sd->longpress_timer = ecore_timer_add
1222 (_elm_config->longpress_timeout, _long_press_cb, it);
1226 _mouse_up_cb(Elm_Multibuttonentry_Item *it,
1227 Evas *evas __UNUSED__,
1228 Evas_Object *obj __UNUSED__,
1229 Evas_Event_Mouse_Down *ev)
1231 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
1233 if (sd->longpress_timer)
1235 ecore_timer_del(sd->longpress_timer);
1236 sd->longpress_timer = NULL;
1241 _item_text_set_hook(Elm_Object_Item *it,
1245 if (part && strcmp(part, "elm.btn.text")) return;
1248 elm_object_part_text_set(VIEW(it), "elm.btn.text", text);
1252 _item_text_get_hook(const Elm_Object_Item *it,
1255 if (part && strcmp(part, "elm.btn.text")) return NULL;
1257 return elm_object_part_text_get(VIEW(it), "elm.btn.text");
1261 _item_del_pre_hook(Elm_Object_Item *it)
1263 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
1265 sd->items = eina_list_remove(sd->items, it);
1267 if (!elm_object_focus_get(WIDGET(it)) && !sd->expanded)
1268 _layout_shrink(WIDGET(it), EINA_TRUE);
1274 trans = (Elm_Transit *)evas_object_data_get(VIEW(it), "transit");
1277 elm_transit_del_cb_set(trans, NULL, NULL);
1278 elm_transit_del(trans);
1281 rect = (Evas_Object *)evas_object_data_get(VIEW(it), "effect_rect");
1284 Ecore_Animator *anim;
1285 anim = (Ecore_Animator*)evas_object_data_get(rect, "animator");
1286 if (anim) ecore_animator_del(anim);
1288 evas_object_del(rect);
1289 evas_object_data_set(VIEW(it), "effect_rect", NULL);
1293 elm_box_pack_end(sd->box, sd->entry);
1294 evas_object_show(sd->entry);
1295 if (elm_object_focus_get(WIDGET(it)))
1296 elm_object_focus_set(sd->entry, EINA_TRUE);
1301 if (!sd->items && !elm_object_focus_get(WIDGET(it)) &&
1302 sd->guide && !_guide_packed(WIDGET(it)))
1306 elm_box_unpack(sd->box, sd->entry);
1307 evas_object_hide(sd->entry);
1310 elm_box_pack_end(sd->box, sd->guide);
1311 evas_object_show(sd->guide);
1314 evas_object_smart_callback_call(WIDGET(it), SIG_ITEM_DELETED, it);
1320 _access_info_cb(void *data, Evas_Object *obj __UNUSED__)
1322 Elm_Multibuttonentry_Item *it = (Elm_Multibuttonentry_Item *)data;
1323 const char *txt = NULL;
1324 Eina_Strbuf *buf = NULL;
1327 if (!it) return NULL;
1329 if (!txt)txt = elm_object_item_text_get(it);
1332 buf = eina_strbuf_new();
1333 eina_strbuf_append(buf, E_(" double tap to edit"));
1334 eina_strbuf_prepend(buf, txt);
1335 str = eina_strbuf_string_steal(buf);
1336 eina_strbuf_free(buf);
1344 _access_state_cb(void *data, Evas_Object *obj __UNUSED__)
1346 Elm_Multibuttonentry_Item *it = (Elm_Multibuttonentry_Item *)data;
1347 if (!it) return NULL;
1349 if (it->base.disabled)
1350 return strdup(E_("State: Disabled"));
1356 _access_activate_cb(void *data __UNUSED__,
1357 Evas_Object *part_obj __UNUSED__,
1358 Elm_Object_Item *item)
1360 _on_item_selected(item, NULL, NULL, NULL);
1364 _access_widget_item_register(Elm_Multibuttonentry_Item *it, Eina_Bool is_access)
1366 Elm_Access_Info *ai;
1368 if (!is_access) _elm_access_widget_item_unregister((Elm_Widget_Item *)it);
1371 _elm_access_widget_item_register((Elm_Widget_Item *)it);
1373 ai = _elm_access_object_get(it->base.access_obj);
1375 _elm_access_callback_set(ai, ELM_ACCESS_INFO, _access_info_cb, it);
1376 _elm_access_callback_set(ai, ELM_ACCESS_STATE, _access_state_cb, it);
1377 _elm_access_activate_callback_set(ai, _access_activate_cb, it);
1381 static Elm_Multibuttonentry_Item *
1382 _item_new(Evas_Object *obj,
1387 Elm_Multibuttonentry_Item *it;
1388 Elm_Multibuttonentry_Item_Filter *ft;
1391 Evas_Coord minw, minh, maxw = 0;
1393 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
1395 EINA_LIST_FOREACH(sd->filters, l, ft)
1397 if (!ft->func(obj, text, data, ft->data))
1401 it = elm_widget_item_new(obj, Elm_Multibuttonentry_Item);
1402 if (!it) return NULL;
1404 VIEW(it) = elm_layout_add(obj);
1405 elm_layout_theme_set
1406 (VIEW(it), "multibuttonentry", "btn", elm_widget_style_get(obj));
1407 elm_layout_signal_callback_add
1408 (VIEW(it), "elm,action,clicked", "", _on_item_clicked, it);
1409 elm_layout_signal_callback_add
1410 (VIEW(it), "elm,action,selected", "", _on_item_selected, it);
1411 evas_object_event_callback_add
1412 (elm_layout_edje_get(VIEW(it)),
1413 EVAS_CALLBACK_FOCUS_IN, _on_item_focus, it);
1414 evas_object_event_callback_add
1415 (elm_layout_edje_get(VIEW(it)),
1416 EVAS_CALLBACK_FOCUS_OUT, _on_item_focus, it);
1417 evas_object_event_callback_add
1418 (elm_layout_edje_get(VIEW(it)),
1419 EVAS_CALLBACK_MOUSE_DOWN, (Evas_Object_Event_Cb)_mouse_down_cb, it);
1420 evas_object_event_callback_add
1421 (elm_layout_edje_get(VIEW(it)),
1422 EVAS_CALLBACK_MOUSE_UP, (Evas_Object_Event_Cb)_mouse_up_cb, it);
1423 elm_object_part_text_set(VIEW(it), "elm.btn.text", text);
1426 it->base.data = data;
1428 // adjust item size if item is longer than maximum size
1429 evas_object_smart_calculate(VIEW(it));
1430 evas_object_size_hint_min_get(VIEW(it), &minw, &minh);
1431 str = elm_layout_data_get(VIEW(it), "button_max_size");
1432 if (str) maxw = atoi(str);
1433 maxw = maxw * elm_widget_scale_get(obj) * elm_config_scale_get();
1436 elm_layout_signal_emit(VIEW(it), "elm,state,text,ellipsis", "");
1437 elm_layout_sizing_eval(VIEW(it));
1440 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
1441 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
1442 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
1444 sd->item_be_selected = EINA_TRUE;
1447 if (_elm_config->access_mode) _access_widget_item_register(it, EINA_TRUE);
1453 _on_entry_unfocused(void *data,
1455 void *event_info __UNUSED__)
1459 ELM_MULTIBUTTONENTRY_DATA_GET(data, sd);
1461 str = elm_entry_markup_to_utf8(elm_object_text_get(obj));
1464 Elm_Multibuttonentry_Item *it;
1466 it = _item_new(data, str, NULL, NULL);
1469 sd->items = eina_list_append(sd->items, it);
1471 _item_adding_effect_add(data, it);
1473 elm_box_pack_before(sd->box, VIEW(it), obj);
1474 evas_object_show(VIEW(it));
1475 evas_object_smart_callback_call(data, SIG_ITEM_ADDED, it);
1478 elm_object_text_set(obj, "");
1483 // handles semicolon, comma (before inserting them to the entry)
1485 _entry_filter(void *data,
1491 ELM_MULTIBUTTONENTRY_DATA_GET(data, sd);
1493 if (!*text || !strlen(*text)) return;
1495 // cancels item_be_selected when text inserting is started
1496 if (strcmp(*text, ";") && strcmp(*text, ","))
1498 sd->item_be_selected = EINA_FALSE;
1502 str = elm_entry_markup_to_utf8(elm_object_text_get(entry));
1505 Elm_Multibuttonentry_Item *it;
1507 it = _item_new(data, str, NULL, NULL);
1510 sd->items = eina_list_append(sd->items, it);
1512 _item_adding_effect_add(data, it);
1514 elm_box_pack_before(sd->box, VIEW(it), entry);
1515 evas_object_show(VIEW(it));
1516 evas_object_smart_callback_call(data, SIG_ITEM_ADDED, it);
1519 elm_object_text_set(entry, "");
1527 // handles enter key
1529 _on_entry_key_down(void *data,
1535 Evas_Event_Key_Up *ev = (Evas_Event_Key_Up *)event_info;
1537 ELM_MULTIBUTTONENTRY_DATA_GET(data, sd);
1539 // cancels item_be_selected when text inserting is started
1540 if (strcmp(ev->keyname, "KP_Enter") && strcmp(ev->keyname, "Return") &&
1541 strcmp(ev->keyname, "BackSpace") && strcmp(ev->keyname, "Delete") &&
1542 strcmp(ev->keyname, "semicolon") && strcmp(ev->keyname, "comma"))
1544 sd->item_be_selected = EINA_FALSE;
1548 if (!strcmp(ev->keyname, "KP_Enter") || !strcmp(ev->keyname, "Return"))
1550 str = elm_entry_markup_to_utf8(elm_object_text_get(obj));
1553 Elm_Multibuttonentry_Item *it;
1555 it = _item_new(data, str, NULL, NULL);
1558 sd->items = eina_list_append(sd->items, it);
1560 _item_adding_effect_add(data, it);
1562 elm_box_pack_before(sd->box, VIEW(it), obj);
1563 evas_object_show(VIEW(it));
1564 evas_object_smart_callback_call(data, SIG_ITEM_ADDED, it);
1567 elm_object_text_set(obj, "");
1573 // handles delete key
1574 // it can be pressed when button is selected, so it is handled on layout_key_down
1576 _on_layout_key_down(void *data __UNUSED__,
1582 Evas_Event_Key_Up *ev = (Evas_Event_Key_Up *)event_info;
1584 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
1586 if (strcmp(ev->keyname, "BackSpace") && strcmp(ev->keyname, "Delete"))
1589 str = elm_entry_markup_to_utf8(elm_object_text_get(sd->entry));
1597 if (!sd->items) return;
1599 if (!sd->selected_item)
1601 if (sd->item_be_selected) // 2nd delete
1603 Elm_Multibuttonentry_Item *it;
1605 it = eina_list_data_get(eina_list_last(sd->items));
1606 evas_object_focus_set(elm_layout_edje_get(VIEW(it)), EINA_TRUE);
1609 sd->item_be_selected = EINA_TRUE;
1617 trans = (Elm_Transit *)evas_object_data_get(VIEW(sd->selected_item), "transit");
1618 rect = (Evas_Object *)evas_object_data_get(VIEW(sd->selected_item), "effect_rect");
1620 if (!trans && !rect)
1621 _item_deleting_effect_add
1622 (obj, (Elm_Multibuttonentry_Item *)sd->selected_item);
1624 elm_object_item_del(sd->selected_item);
1627 elm_object_focus_set(sd->entry, EINA_TRUE);
1633 _on_layout_clicked(void *data __UNUSED__,
1635 const char *emission __UNUSED__,
1636 const char *source __UNUSED__)
1638 evas_object_smart_callback_call(obj, SIG_CLICKED, NULL);
1642 _elm_multibuttonentry_smart_on_focus(Evas_Object *obj)
1644 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
1646 if (!ELM_WIDGET_CLASS(_elm_multibuttonentry_parent_sc)->on_focus(obj))
1649 if (elm_object_focus_get(obj))
1652 //if ((_elm_config->access_mode == ELM_ACCESS_MODE_ON)) return EINA_TRUE;
1654 if (sd->guide && _guide_packed(obj))
1656 elm_box_unpack(sd->box, sd->guide);
1657 evas_object_hide(sd->guide);
1661 elm_box_pack_end(sd->box, sd->entry);
1662 evas_object_show(sd->entry);
1665 // when object gets focused, it should be expanded layout
1666 else if (!sd->expanded)
1667 _layout_expand(obj);
1671 elm_layout_signal_emit(obj, "elm,state,event,allow", "");
1672 elm_object_focus_set(sd->entry, EINA_TRUE);
1675 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
1679 if (!sd->items && sd->guide)
1683 elm_box_unpack(sd->box, sd->entry);
1684 evas_object_hide(sd->entry);
1687 elm_box_pack_end(sd->box, sd->guide);
1688 evas_object_show(sd->guide);
1690 // if shrinked mode was set, it goes back to shrinked layout
1691 else if (!sd->expanded)
1692 _layout_shrink(obj, EINA_FALSE);
1695 elm_layout_signal_emit(obj, "elm,state,event,block", "");
1697 if (sd->selected_item)
1698 evas_object_focus_set
1699 (elm_layout_edje_get(VIEW(sd->selected_item)), EINA_FALSE);
1701 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
1708 _elm_multibuttonentry_smart_text_set(Evas_Object *obj,
1712 if (!part || (part && !strcmp(part, "label")))
1714 if (text) _label_set(obj, text);
1717 else if (part && !strcmp(part, "guide"))
1719 if (text) _guide_set(obj, text);
1722 else return _elm_multibuttonentry_parent_sc->text_set(obj, part, text);
1726 _elm_multibuttonentry_smart_text_get(const Evas_Object *obj,
1729 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
1731 if (!part || !strcmp(part, "label"))
1732 return elm_object_part_text_get(sd->label, "mbe.label");
1733 else if (!strcmp(part, "guide"))
1734 return elm_object_text_get(sd->guide);
1735 else return _elm_multibuttonentry_parent_sc->text_get(obj, part);
1739 _elm_multibuttonentry_smart_sizing_eval(Evas_Object *obj)
1741 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
1743 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
1745 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
1746 edje_object_size_min_restricted_calc
1747 (ELM_WIDGET_DATA(sd)->resize_obj, &minw, &minh, minw, minh);
1748 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
1749 evas_object_size_hint_min_set(obj, minw, minh);
1750 evas_object_size_hint_max_set(obj, maxw, maxh);
1754 _elm_multibuttonentry_smart_theme(Evas_Object *obj)
1757 int hpad = 0, vpad = 0;
1759 Elm_Multibuttonentry_Item *it;
1761 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
1763 if (!ELM_WIDGET_CLASS(_elm_multibuttonentry_parent_sc)->theme(obj))
1766 str = elm_layout_data_get(obj, "horizontal_pad");
1767 if (str) hpad = atoi(str);
1768 str = elm_layout_data_get(obj, "vertical_pad");
1769 if (str) vpad = atoi(str);
1772 hpad * elm_widget_scale_get(obj) * elm_config_scale_get(),
1773 vpad * elm_widget_scale_get(obj) * elm_config_scale_get());
1775 elm_layout_theme_set
1776 (sd->label, "multibuttonentry", "label", elm_widget_style_get(obj));
1777 elm_layout_theme_set
1778 (sd->guide, "multibuttonentry", "guidetext", elm_widget_style_get(obj));
1779 elm_layout_theme_set
1780 (sd->end, "multibuttonentry", "number", elm_widget_style_get(obj));
1781 EINA_LIST_FOREACH(sd->items, l, it)
1782 elm_layout_theme_set
1783 (VIEW(it), "multibuttonentry", "btn", elm_widget_style_get(obj));
1785 elm_layout_sizing_eval(obj);
1791 _elm_multibuttonentry_smart_add(Evas_Object *obj)
1794 int hpad = 0, vpad = 0;
1796 EVAS_SMART_DATA_ALLOC(obj, Elm_Multibuttonentry_Smart_Data);
1798 ELM_WIDGET_CLASS(_elm_multibuttonentry_parent_sc)->base.add(obj);
1799 elm_layout_theme_set
1800 (obj, "multibuttonentry", "base", elm_widget_style_get(obj));
1801 elm_layout_signal_callback_add
1802 (obj, "elm,action,clicked", "", _on_layout_clicked, NULL);
1803 evas_object_event_callback_add
1804 (obj, EVAS_CALLBACK_KEY_DOWN, _on_layout_key_down, NULL);
1806 priv->box = elm_box_add(obj);
1807 str = elm_layout_data_get(obj, "horizontal_pad");
1808 if (str) hpad = atoi(str);
1809 str = elm_layout_data_get(obj, "vertical_pad");
1810 if (str) vpad = atoi(str);
1813 hpad * elm_widget_scale_get(obj) * elm_config_scale_get(),
1814 vpad * elm_widget_scale_get(obj) * elm_config_scale_get());
1815 elm_box_layout_set(priv->box, _box_layout, NULL, NULL);
1816 elm_layout_content_set(obj, "box.swallow", priv->box);
1817 evas_object_event_callback_add
1818 (priv->box, EVAS_CALLBACK_RESIZE, _on_box_resize, obj);
1820 priv->entry = elm_entry_add(obj);
1821 elm_entry_single_line_set(priv->entry, EINA_TRUE);
1822 elm_entry_cnp_mode_set(priv->entry, ELM_CNP_MODE_PLAINTEXT);
1823 evas_object_size_hint_weight_set
1824 (priv->entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1825 evas_object_size_hint_align_set
1826 (priv->entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
1827 evas_object_event_callback_add
1828 (priv->entry, EVAS_CALLBACK_KEY_DOWN, _on_entry_key_down, obj);
1829 evas_object_smart_callback_add
1830 (priv->entry, "unfocused", _on_entry_unfocused, obj);
1831 elm_entry_markup_filter_append(priv->entry, _entry_filter, obj);
1832 elm_box_pack_end(priv->box, priv->entry);
1833 evas_object_show(priv->entry);
1835 elm_widget_can_focus_set(obj, EINA_TRUE);
1837 priv->editable = EINA_TRUE;
1838 priv->expanded = EINA_TRUE;
1839 priv->expanded_state = EINA_TRUE;
1843 _elm_access_object_register(obj, ELM_WIDGET_DATA(priv)->resize_obj);
1844 _elm_access_text_set
1845 (_elm_access_object_get(obj), ELM_ACCESS_TYPE, E_("multi button entry"));
1846 _elm_access_callback_set
1847 (_elm_access_object_get(obj), ELM_ACCESS_INFO, _access_info_cb, NULL);
1852 _elm_multibuttonentry_smart_del(Evas_Object *obj)
1854 Elm_Multibuttonentry_Item *it;
1855 Elm_Multibuttonentry_Item_Filter *ft;
1857 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
1860 EINA_LIST_FREE(sd->items, it)
1865 trans = (Elm_Transit *)evas_object_data_get(VIEW(it), "transit");
1868 elm_transit_del_cb_set(trans, NULL, NULL);
1869 elm_transit_del(trans);
1872 rect = (Evas_Object *)evas_object_data_get(VIEW(it), "effect_rect");
1875 Ecore_Animator *anim;
1876 anim = (Ecore_Animator*)evas_object_data_get(rect, "animator");
1877 if (anim) ecore_animator_del(anim);
1879 evas_object_del(rect);
1880 evas_object_data_set(VIEW(it), "effect_rect", NULL);
1882 elm_widget_item_free(it);
1885 EINA_LIST_FREE(sd->items, it)
1886 elm_widget_item_free(it);
1889 EINA_LIST_FREE(sd->filters, ft)
1892 if (sd->end) evas_object_del(sd->end);
1893 if (sd->guide) evas_object_del(sd->guide);
1894 if (sd->label) evas_object_del(sd->label);
1895 if (sd->entry) evas_object_del(sd->entry);
1896 if (sd->box) evas_object_del(sd->box);
1897 if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer);
1899 ELM_WIDGET_CLASS(_elm_multibuttonentry_parent_sc)->base.del(obj);
1903 _elm_multibuttonentry_smart_access(Evas_Object *obj, Eina_Bool is_access)
1905 Eina_List *elist = NULL;
1906 Elm_Multibuttonentry_Item *it;
1908 ELM_MULTIBUTTONENTRY_CHECK(obj);
1909 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
1911 EINA_LIST_FOREACH(sd->items, elist, it)
1912 _access_widget_item_register(it, is_access);
1916 _elm_multibuttonentry_smart_set_user(Elm_Multibuttonentry_Smart_Class *sc)
1918 ELM_WIDGET_CLASS(sc)->base.add = _elm_multibuttonentry_smart_add;
1919 ELM_WIDGET_CLASS(sc)->base.del = _elm_multibuttonentry_smart_del;
1921 ELM_WIDGET_CLASS(sc)->theme = _elm_multibuttonentry_smart_theme;
1922 ELM_WIDGET_CLASS(sc)->on_focus = _elm_multibuttonentry_smart_on_focus;
1924 /* not a 'focus chain manager' */
1925 ELM_WIDGET_CLASS(sc)->focus_next = NULL;
1926 ELM_WIDGET_CLASS(sc)->focus_direction = NULL;
1928 ELM_LAYOUT_CLASS(sc)->text_set = _elm_multibuttonentry_smart_text_set;
1929 ELM_LAYOUT_CLASS(sc)->text_get = _elm_multibuttonentry_smart_text_get;
1931 ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_multibuttonentry_smart_sizing_eval;
1934 if (_elm_config->access_mode)
1935 ELM_WIDGET_CLASS(sc)->focus_next = _elm_multibuttonentry_smart_focus_next;
1937 ELM_WIDGET_CLASS(sc)->access = _elm_multibuttonentry_smart_access;
1940 EAPI const Elm_Multibuttonentry_Smart_Class *
1941 elm_multibuttonentry_smart_class_get(void)
1943 static Elm_Multibuttonentry_Smart_Class _sc =
1944 ELM_MULTIBUTTONENTRY_SMART_CLASS_INIT_NAME_VERSION
1945 (ELM_MULTIBUTTONENTRY_SMART_NAME);
1946 static const Elm_Multibuttonentry_Smart_Class *class = NULL;
1947 Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
1949 if (class) return class;
1951 _elm_multibuttonentry_smart_set(&_sc);
1952 esc->callbacks = _smart_callbacks;
1959 elm_multibuttonentry_add(Evas_Object *parent)
1963 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1965 obj = elm_widget_add(_elm_multibuttonentry_smart_class_new(), parent);
1966 if (!obj) return NULL;
1968 if (!elm_widget_sub_object_add(parent, obj))
1969 ERR("could not add %p as sub object of %p", obj, parent);
1975 elm_multibuttonentry_entry_get(const Evas_Object *obj)
1977 ELM_MULTIBUTTONENTRY_CHECK(obj) NULL;
1978 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
1984 elm_multibuttonentry_expanded_set(Evas_Object *obj,
1987 ELM_MULTIBUTTONENTRY_CHECK(obj);
1988 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
1990 expanded = !!expanded;
1991 if (sd->expanded == expanded) return;
1992 sd->expanded = expanded;
1994 if (elm_object_focus_get(obj)) return;
1997 _layout_expand(obj);
1999 _layout_shrink(obj, EINA_FALSE);
2003 elm_multibuttonentry_expanded_get(const Evas_Object *obj)
2005 ELM_MULTIBUTTONENTRY_CHECK(obj) EINA_FALSE;
2006 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2008 return (elm_object_focus_get(obj) || sd->expanded);
2012 elm_multibuttonentry_editable_set(Evas_Object *obj,
2015 ELM_MULTIBUTTONENTRY_CHECK(obj);
2016 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2018 editable = !!editable;
2019 if (sd->editable == editable) return;
2020 sd->editable = editable;
2024 if (!(sd->guide && _guide_packed(obj)))
2026 elm_box_pack_end(sd->box, sd->entry);
2027 evas_object_show(sd->entry);
2030 if (!elm_object_focus_get(obj))
2031 elm_layout_signal_emit(obj, "elm,state,event,block", "");
2035 if (!(sd->guide && _guide_packed(obj)))
2037 elm_box_unpack(sd->box, sd->entry);
2038 evas_object_hide(sd->entry);
2041 if (!elm_object_focus_get(obj))
2042 elm_layout_signal_emit(obj, "elm,state,event,allow", "");
2047 elm_multibuttonentry_editable_get(const Evas_Object *obj)
2049 ELM_MULTIBUTTONENTRY_CHECK(obj) EINA_FALSE;
2050 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2052 return sd->editable;
2055 EAPI Elm_Object_Item *
2056 elm_multibuttonentry_item_prepend(Evas_Object *obj,
2061 Elm_Multibuttonentry_Item *it;
2063 ELM_MULTIBUTTONENTRY_CHECK(obj) NULL;
2064 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2066 if (!label) return NULL;
2068 // if guide text was shown, hide it
2069 if (sd->guide && _guide_packed(obj))
2071 elm_box_unpack(sd->box, sd->guide);
2072 evas_object_hide(sd->guide);
2076 elm_box_pack_end(sd->box, sd->entry);
2077 evas_object_show(sd->entry);
2081 it = _item_new(obj, label, func, data);
2082 if (!it) return NULL;
2084 sd->items = eina_list_prepend(sd->items, it);
2086 if (!elm_object_focus_get(obj) && !sd->expanded && sd->boxw)
2089 _item_adding_effect_add(obj, it);
2091 _layout_shrink(obj, EINA_TRUE);
2096 if (sd->boxh && sd->boxw)
2097 _item_adding_effect_add(obj, it);
2100 if (sd->label && _label_packed(obj))
2101 elm_box_pack_after(sd->box, VIEW(it), sd->label);
2103 elm_box_pack_start(sd->box, VIEW(it));
2104 evas_object_show(VIEW(it));
2107 if (sd->label && _label_packed(obj))
2108 elm_box_pack_after(sd->box, VIEW(it), sd->label);
2110 elm_box_pack_start(sd->box, VIEW(it));
2111 evas_object_show(VIEW(it));
2116 if (!sd->boxh || !sd->boxw)
2117 evas_object_smart_callback_call(obj, SIG_ITEM_ADDED, it);
2119 evas_object_smart_callback_call(obj, SIG_ITEM_ADDED, it);
2122 return (Elm_Object_Item *)it;
2125 EAPI Elm_Object_Item *
2126 elm_multibuttonentry_item_append(Evas_Object *obj,
2131 Elm_Multibuttonentry_Item *it;
2133 ELM_MULTIBUTTONENTRY_CHECK(obj) NULL;
2134 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2136 if (!label) return NULL;
2138 // if guide text was shown, hide it
2139 if (sd->guide && _guide_packed(obj))
2141 elm_box_unpack(sd->box, sd->guide);
2142 evas_object_hide(sd->guide);
2146 elm_box_pack_end(sd->box, sd->entry);
2147 evas_object_show(sd->entry);
2151 it = _item_new(obj, label, func, data);
2152 if (!it) return NULL;
2154 sd->items = eina_list_append(sd->items, it);
2156 if (!elm_object_focus_get(obj) && !sd->expanded && sd->boxw)
2159 _item_adding_effect_add(obj, it);
2161 _layout_shrink(obj, EINA_TRUE);
2166 if (sd->boxh && sd->boxw)
2167 _item_adding_effect_add(obj, it);
2171 elm_box_pack_before(sd->box, VIEW(it), sd->entry);
2173 elm_box_pack_end(sd->box, VIEW(it));
2174 evas_object_show(VIEW(it));
2178 elm_box_pack_before(sd->box, VIEW(it), sd->entry);
2180 elm_box_pack_end(sd->box, VIEW(it));
2181 evas_object_show(VIEW(it));
2186 if (!sd->boxh || !sd->boxw)
2187 evas_object_smart_callback_call(obj, SIG_ITEM_ADDED, it);
2189 evas_object_smart_callback_call(obj, SIG_ITEM_ADDED, it);
2192 return (Elm_Object_Item *)it;
2195 EAPI Elm_Object_Item *
2196 elm_multibuttonentry_item_insert_before(Evas_Object *obj,
2197 Elm_Object_Item *before,
2202 Elm_Multibuttonentry_Item *it;
2204 ELM_MULTIBUTTONENTRY_CHECK(obj) NULL;
2205 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2207 if (!label) return NULL;
2208 if (!before) return NULL;
2210 it = _item_new(obj, label, func, data);
2211 if (!it) return NULL;
2213 sd->items = eina_list_prepend_relative(sd->items, it, before);
2215 if (!elm_object_focus_get(obj) && !sd->expanded && sd->boxw)
2218 _item_adding_effect_add(obj, it);
2220 _layout_shrink(obj, EINA_TRUE);
2225 if (sd->boxh && sd->boxw)
2226 _item_adding_effect_add(obj, it);
2229 elm_box_pack_before(sd->box, VIEW(it), VIEW(before));
2230 evas_object_show(VIEW(it));
2233 elm_box_pack_before(sd->box, VIEW(it), VIEW(before));
2234 evas_object_show(VIEW(it));
2239 if (!sd->boxh || !sd->boxw)
2240 evas_object_smart_callback_call(obj, SIG_ITEM_ADDED, it);
2242 evas_object_smart_callback_call(obj, SIG_ITEM_ADDED, it);
2245 return (Elm_Object_Item *)it;
2248 EAPI Elm_Object_Item *
2249 elm_multibuttonentry_item_insert_after(Evas_Object *obj,
2250 Elm_Object_Item *after,
2255 Elm_Multibuttonentry_Item *it;
2257 ELM_MULTIBUTTONENTRY_CHECK(obj) NULL;
2258 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2260 if (!label) return NULL;
2261 if (!after) return NULL;
2263 it = _item_new(obj, label, func, data);
2264 if (!it) return NULL;
2266 sd->items = eina_list_append_relative(sd->items, it, after);
2268 if (!elm_object_focus_get(obj) && !sd->expanded && sd->boxw)
2271 _item_adding_effect_add(obj, it);
2273 _layout_shrink(obj, EINA_TRUE);
2278 if (sd->boxw && sd->boxh)
2279 _item_adding_effect_add(obj, it);
2282 elm_box_pack_after(sd->box, VIEW(it), VIEW(after));
2283 evas_object_show(VIEW(it));
2286 elm_box_pack_after(sd->box, VIEW(it), VIEW(after));
2287 evas_object_show(VIEW(it));
2292 if (!sd->boxh || !sd->boxw)
2293 evas_object_smart_callback_call(obj, SIG_ITEM_ADDED, it);
2295 evas_object_smart_callback_call(obj, SIG_ITEM_ADDED, it);
2298 return (Elm_Object_Item *)it;
2301 EAPI const Eina_List *
2302 elm_multibuttonentry_items_get(const Evas_Object *obj)
2304 ELM_MULTIBUTTONENTRY_CHECK(obj) NULL;
2305 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2311 elm_multibuttonentry_item_object_get(const Elm_Object_Item *it)
2313 ELM_MULTIBUTTONENTRY_ITEM_CHECK_OR_RETURN(it);
2318 EAPI Elm_Object_Item *
2319 elm_multibuttonentry_first_item_get(const Evas_Object *obj)
2321 ELM_MULTIBUTTONENTRY_CHECK(obj) NULL;
2322 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2324 return eina_list_data_get(sd->items);
2327 EAPI Elm_Object_Item *
2328 elm_multibuttonentry_last_item_get(const Evas_Object *obj)
2330 ELM_MULTIBUTTONENTRY_CHECK(obj) NULL;
2331 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2333 return eina_list_data_get(eina_list_last(sd->items));
2336 EAPI Elm_Object_Item *
2337 elm_multibuttonentry_selected_item_get(const Evas_Object *obj)
2339 ELM_MULTIBUTTONENTRY_CHECK(obj) NULL;
2340 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2342 return sd->selected_item;
2346 elm_multibuttonentry_item_selected_set(Elm_Object_Item *it,
2349 ELM_MULTIBUTTONENTRY_ITEM_CHECK_OR_RETURN(it);
2350 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
2352 if (!elm_object_focus_get(WIDGET(it))) return;
2354 if (selected && it != sd->selected_item)
2356 evas_object_focus_set(elm_layout_edje_get(VIEW(it)), EINA_TRUE);
2358 else if (!selected && it == sd->selected_item)
2360 evas_object_focus_set(elm_layout_edje_get(VIEW(it)), EINA_FALSE);
2363 elm_object_focus_set(sd->entry, EINA_TRUE);
2368 elm_multibuttonentry_item_selected_get(const Elm_Object_Item *it)
2370 ELM_MULTIBUTTONENTRY_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2371 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
2373 if (!elm_object_focus_get(WIDGET(it))) return EINA_FALSE;
2375 if (it == sd->selected_item)
2382 elm_multibuttonentry_clear(Evas_Object *obj)
2384 Elm_Multibuttonentry_Item *it;
2386 ELM_MULTIBUTTONENTRY_CHECK(obj);
2387 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2390 EINA_LIST_FREE(sd->items, it)
2395 trans = (Elm_Transit *)evas_object_data_get(VIEW(it), "transit");
2398 elm_transit_del_cb_set(trans, NULL, NULL);
2399 elm_transit_del(trans);
2402 rect = (Evas_Object *)evas_object_data_get(VIEW(it), "effect_rect");
2405 Ecore_Animator *anim;
2407 anim = (Ecore_Animator*)evas_object_data_get(rect, "animator");
2408 if (anim) ecore_animator_del(anim);
2410 evas_object_del(rect);
2411 evas_object_data_set(VIEW(it), "effect_rect", NULL);
2415 elm_box_pack_end(sd->box, sd->entry);
2416 evas_object_show(sd->entry);
2417 if (elm_object_focus_get(WIDGET(it)))
2418 elm_object_focus_set(sd->entry, EINA_TRUE);
2421 elm_widget_item_free(it);
2424 EINA_LIST_FREE(sd->items, it)
2425 elm_widget_item_free(it);
2429 sd->item_be_selected = EINA_FALSE;
2430 sd->expanded_state = EINA_TRUE;
2434 evas_object_del(sd->end);
2438 if (!sd->items && !elm_object_focus_get(obj) &&
2439 sd->guide && !_guide_packed(obj))
2443 elm_box_unpack(sd->box, sd->entry);
2444 evas_object_hide(sd->entry);
2447 elm_box_pack_end(sd->box, sd->guide);
2448 evas_object_show(sd->guide);
2452 EAPI Elm_Object_Item *
2453 elm_multibuttonentry_item_prev_get(const Elm_Object_Item *it)
2456 Elm_Multibuttonentry_Item *item;
2458 ELM_MULTIBUTTONENTRY_ITEM_CHECK_OR_RETURN(it, NULL);
2459 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
2461 EINA_LIST_FOREACH(sd->items, l, item)
2463 if (item == (Elm_Multibuttonentry_Item *)it)
2465 l = eina_list_prev(l);
2466 if (!l) return NULL;
2467 return eina_list_data_get(l);
2473 EAPI Elm_Object_Item *
2474 elm_multibuttonentry_item_next_get(const Elm_Object_Item *it)
2477 Elm_Multibuttonentry_Item *item;
2479 ELM_MULTIBUTTONENTRY_ITEM_CHECK_OR_RETURN(it, NULL);
2480 ELM_MULTIBUTTONENTRY_DATA_GET(WIDGET(it), sd);
2482 EINA_LIST_FOREACH(sd->items, l, item)
2484 if (item == (Elm_Multibuttonentry_Item *)it)
2486 l = eina_list_next(l);
2487 if (!l) return NULL;
2488 return eina_list_data_get(l);
2495 elm_multibuttonentry_item_filter_append(Evas_Object *obj,
2496 Elm_Multibuttonentry_Item_Filter_Cb func,
2499 Elm_Multibuttonentry_Item_Filter *ft = NULL;
2501 ELM_MULTIBUTTONENTRY_CHECK(obj);
2502 EINA_SAFETY_ON_NULL_RETURN(func);
2503 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2505 ft = _filter_new(func, data);
2508 sd->filters = eina_list_append(sd->filters, ft);
2512 elm_multibuttonentry_item_filter_prepend(Evas_Object *obj,
2513 Elm_Multibuttonentry_Item_Filter_Cb func,
2516 Elm_Multibuttonentry_Item_Filter *ft = NULL;
2518 ELM_MULTIBUTTONENTRY_CHECK(obj);
2519 EINA_SAFETY_ON_NULL_RETURN(func);
2520 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2522 ft = _filter_new(func, data);
2525 sd->filters = eina_list_prepend(sd->filters, ft);
2529 elm_multibuttonentry_item_filter_remove(Evas_Object *obj,
2530 Elm_Multibuttonentry_Item_Filter_Cb func,
2533 Elm_Multibuttonentry_Item_Filter *ft;
2536 ELM_MULTIBUTTONENTRY_CHECK(obj);
2537 EINA_SAFETY_ON_NULL_RETURN(func);
2538 ELM_MULTIBUTTONENTRY_DATA_GET(obj, sd);
2540 EINA_LIST_FOREACH(sd->filters, l, ft)
2542 if ((ft->func == func) && (!data || ft->data == data))
2544 sd->filters = eina_list_remove_list(sd->filters, l);