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