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