Elementary migration revision 69448
[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    _select_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 = 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;
797    rw = w_btn;
798
799    if (button_max_width < w_btn)
800      vw = button_max_width;
801    else
802      vw = w_btn;
803
804    //resize btn
805    evas_object_resize(btn, vw, h_btn);
806    evas_object_size_hint_min_set(btn, vw, h_btn);
807
808    if (realw) *realw = rw;
809    if (vieww) *vieww = vw;
810 }
811
812 static Eina_Bool
813 _item_del_pre_hook(Elm_Object_Item *it)
814 {
815    _del_button_item((Elm_Multibuttonentry_Item *)it);
816    return EINA_TRUE;
817 }
818
819 static Elm_Object_Item*
820 _add_button_item(Evas_Object *obj, const char *str, Multibuttonentry_Pos pos, const void *ref, Evas_Smart_Cb func, void *data)
821 {
822    Elm_Multibuttonentry_Item *item;
823    Elm_Multibuttonentry_Item_Filter *item_filter;
824    Elm_Multibuttonentry_Item *reference = (Elm_Multibuttonentry_Item *)ref;
825    Eina_List *l;
826    Evas_Object *btn;
827    Evas_Coord width = -1, height = -1;
828    char *str_utf8 = NULL;
829    Widget_Data *wd = elm_widget_data_get(obj);
830
831    if (!wd || !wd->box || !wd->entry) return NULL;
832    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
833    if (!str) return NULL;
834
835    EINA_LIST_FOREACH(wd->filter_list, l, item_filter)
836      {
837         if (!(item_filter->callback_func(obj, str, data, item_filter->data)))
838           return NULL;
839      }
840    // add button
841    btn = edje_object_add(evas_object_evas_get(obj));
842    str_utf8 = elm_entry_markup_to_utf8(str);
843
844    //entry is cleared when text is made to button
845    elm_object_text_set(wd->entry, "");
846
847    _elm_theme_object_set(obj, btn, "multibuttonentry", "btn", elm_widget_style_get(obj));
848    edje_object_part_text_set(btn, "elm.btn.text", str_utf8);
849    edje_object_part_geometry_get(btn, "elm.btn.text", NULL, NULL, &width, &height);
850
851    evas_object_size_hint_min_set(btn, width, height);
852
853    edje_object_signal_callback_add(btn, "mouse,clicked,1", "*", _button_clicked, obj);
854    evas_object_size_hint_weight_set(btn, 0.0, 0.0);
855    evas_object_show(btn);
856
857    // append item list
858    item = elm_widget_item_new(obj, Elm_Multibuttonentry_Item);
859    if (item)
860      {
861         elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
862         elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
863         elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
864         elm_widget_item_data_set(item, data);
865         Evas_Coord rw, vw;
866         _resize_button(btn, &rw, &vw);
867         item->button = btn;
868         item->rw = rw;
869         item->vw = vw;
870         item->visible = EINA_TRUE;
871
872         if (func)
873           {
874               item->func = func;
875           }
876
877         switch (pos)
878           {
879              case MULTIBUTTONENTRY_POS_START:
880                 wd->items = eina_list_prepend(wd->items, item);
881                 if (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK)
882                   {
883                      elm_widget_sub_object_add(obj, btn);
884                      _shrink_mode_set(obj, EINA_TRUE);
885                   }
886                 else
887                   {
888                      if (wd->label)
889                        elm_box_pack_after(wd->box, btn, wd->label);
890                      else
891                        elm_box_pack_start(wd->box, btn);
892                      if (wd->view_state == MULTIBUTTONENTRY_VIEW_GUIDETEXT)
893                        _set_vis_guidetext(obj);
894                   }
895                 break;
896              case MULTIBUTTONENTRY_POS_END:
897                 wd->items = eina_list_append(wd->items, item);
898                 if (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK)
899                   {
900                      elm_widget_sub_object_add(obj, btn);
901                      evas_object_hide(btn);
902                   }
903                 else
904                   {
905                      if (wd->view_state == MULTIBUTTONENTRY_VIEW_GUIDETEXT)
906                        _set_vis_guidetext(obj);
907                      if (wd->entry)
908                        elm_box_pack_before(wd->box, btn, wd->entry);
909                      else
910                        elm_box_pack_end(wd->box, btn);
911                   }
912                 break;
913              case MULTIBUTTONENTRY_POS_BEFORE:
914                 if (reference)
915                      wd->items = eina_list_prepend_relative(wd->items, item, reference);
916                 else
917                      wd->items = eina_list_append(wd->items, item);
918                 if (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK)
919                   {
920                      elm_widget_sub_object_add(obj, btn);
921                      evas_object_hide(btn);
922                      _shrink_mode_set(obj, EINA_TRUE);
923                   }
924                 else
925                   {
926                      if (reference)
927                        elm_box_pack_before(wd->box, btn, reference->button);
928                      else
929                        {
930                           if (wd->view_state == MULTIBUTTONENTRY_VIEW_GUIDETEXT)
931                             _set_vis_guidetext(obj);
932                           if (wd->entry)
933                             elm_box_pack_before(wd->box, btn, wd->entry);
934                           else
935                             elm_box_pack_end(wd->box, btn);
936                        }
937                   }
938                 break;
939              case MULTIBUTTONENTRY_POS_AFTER:
940                 if (reference)
941                      wd->items = eina_list_append_relative(wd->items, item, reference);
942                 else
943                      wd->items = eina_list_append(wd->items, item);
944                 if (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK)
945                   {
946                      elm_widget_sub_object_add(obj, btn);
947                      _shrink_mode_set(obj, EINA_TRUE);
948                   }
949                 else
950                   {
951                      if (reference)
952                        elm_box_pack_after(wd->box, btn, reference->button);
953                      else
954                        {
955                           if (wd->view_state == MULTIBUTTONENTRY_VIEW_GUIDETEXT)
956                             _set_vis_guidetext(obj);
957                           if (wd->entry)
958                             elm_box_pack_before(wd->box, btn, wd->entry);
959                           else
960                             elm_box_pack_end(wd->box, btn);
961                        }
962                   }
963                 break;
964              default:
965                 break;
966           }
967      }
968    evas_object_smart_callback_call(obj, SIG_ITEM_ADDED, item);
969
970    free(str_utf8);
971
972    return (Elm_Object_Item *)item;
973 }
974
975 static Elm_Multibuttonentry_Item_Filter*
976 _filter_new(Elm_Multibuttonentry_Item_Filter_Cb func, void *data)
977 {
978    Elm_Multibuttonentry_Item_Filter *item_filter = ELM_NEW(Elm_Multibuttonentry_Item_Filter);
979    if (!item_filter) return NULL;
980
981    item_filter->callback_func= func;
982    item_filter->data = data;
983
984    return item_filter;
985 }
986
987 static void
988 _filter_free(Elm_Multibuttonentry_Item_Filter *item_filter)
989 {
990    free(item_filter);
991 }
992
993 static void
994 _evas_mbe_key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
995 {
996    Widget_Data *wd = elm_widget_data_get(data);
997    Elm_Multibuttonentry_Item *item = NULL;
998
999    if (!wd || !wd->base || !wd->box) return;
1000
1001    Evas_Event_Key_Up *ev = (Evas_Event_Key_Up*)event_info;
1002
1003    if (wd->last_btn_select)
1004      {
1005         if (wd->current &&
1006             ((strcmp(ev->keyname, "BackSpace") == 0) ||
1007              (strcmp(ev->keyname, "Delete") == 0)))
1008           {
1009              item = eina_list_data_get(wd->current);
1010              if (item)
1011                {
1012                   _del_button_item(item);
1013                   elm_widget_item_free(item);
1014                   elm_object_focus_set(wd->entry, EINA_TRUE);
1015                }
1016           }
1017         else if (((!wd->current && (wd->n_str == 0) &&
1018                    (strcmp(ev->keyname, "BackSpace") == 0)) ||
1019                    (strcmp(ev->keyname, "Delete") == 0)))
1020           {
1021              item = eina_list_data_get(eina_list_last(wd->items));
1022              if (item)
1023                _select_button(data, item->button);
1024           }
1025      }
1026    else
1027      wd->last_btn_select = EINA_TRUE;
1028 }
1029
1030 static void
1031 _entry_key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1032 {
1033    Widget_Data *wd = elm_widget_data_get(data);
1034    Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *)event_info;
1035
1036    if (!wd) return;
1037
1038    if ((wd->n_str == 1) && (strcmp(ev->keyname, "BackSpace") == 0 || (strcmp(ev->keyname, "Delete") == 0 )))
1039      wd->last_btn_select = EINA_FALSE;
1040 }
1041
1042 static void
1043 _entry_key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1044 {
1045    Widget_Data *wd = elm_widget_data_get(data);
1046    Evas_Event_Key_Up *ev = (Evas_Event_Key_Up *) event_info;
1047    const char *str;
1048
1049    if (!wd || !wd->base || !wd->box) return;
1050
1051    str = elm_object_text_get(wd->entry);
1052
1053    if ((strcmp(str, "") != 0) && (strcmp(ev->keyname, "KP_Enter") == 0 || strcmp(ev->keyname, "Return") == 0 ))
1054      {
1055         _add_button_item(data, str, MULTIBUTTONENTRY_POS_END, NULL, NULL, NULL);
1056         wd->n_str = 0;
1057      }
1058 }
1059
1060 static void
1061 _entry_clicked_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1062 {
1063    Widget_Data *wd = elm_widget_data_get(data);
1064    if (!wd) return;
1065
1066    _change_current_button_state(data, MULTIBUTTONENTRY_BUTTON_STATE_DEFAULT);
1067    elm_object_focus_set(wd->entry, EINA_TRUE);
1068 }
1069
1070 static void
1071 _entry_focus_in_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1072 {
1073    Widget_Data *wd = elm_widget_data_get(data);
1074    Elm_Multibuttonentry_Item *item = NULL;
1075
1076    if (!wd) return;
1077
1078    if (wd->current)
1079      {
1080         item = eina_list_data_get(wd->current);
1081         elm_object_focus_set(wd->entry, EINA_FALSE);
1082         evas_object_focus_set(item->button, EINA_TRUE);
1083      }
1084 }
1085
1086 static void
1087 _entry_focus_out_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1088 {
1089    Widget_Data *wd = elm_widget_data_get(data);
1090    const char *str;
1091
1092    if (!wd) return;
1093
1094    str = elm_object_text_get(wd->entry);
1095    if (strlen(str))
1096      _add_button_item(data, str, MULTIBUTTONENTRY_POS_END, NULL, NULL, NULL);
1097 }
1098
1099 static void
1100 _entry_changed_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1101 {
1102    Widget_Data *wd = elm_widget_data_get(data);
1103    const char *str;
1104
1105    if (!wd) return;
1106
1107    str = elm_object_text_get(wd->entry);
1108    wd->n_str = strlen(str);
1109 }
1110
1111 static void
1112 _entry_resized_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1113 {
1114    Evas_Coord en_x, en_y, en_w, en_h;
1115
1116    Widget_Data *wd = elm_widget_data_get(data);
1117    if (!wd) return;
1118
1119    evas_object_geometry_get(wd->entry, &en_x, &en_y, &en_w, &en_h);
1120
1121    if (wd->focused)
1122      elm_widget_show_region_set(wd->entry, en_x, en_y, en_w, en_h, EINA_TRUE);
1123 }
1124
1125 static void
1126 _view_init(Evas_Object *obj)
1127 {
1128    Widget_Data *wd = elm_widget_data_get(obj);
1129
1130    if (!wd) return;
1131
1132    if (!wd->box)
1133      {
1134         wd->box = elm_box_add(obj);
1135         if (!wd->box) return;
1136         elm_widget_sub_object_add(obj, wd->box);
1137         elm_box_layout_set(wd->box, _box_layout_cb, NULL, NULL);
1138         elm_box_homogeneous_set(wd->box, EINA_FALSE);
1139         edje_object_part_swallow(wd->base, "box.swallow", wd->box);
1140      }
1141    if (!wd->label)
1142      {
1143         wd->label = edje_object_add(evas_object_evas_get(obj));
1144         if (!wd->label) return;
1145         _elm_theme_object_set(obj, wd->label, "multibuttonentry", "label", elm_widget_style_get(obj));
1146         _set_label(obj, "");
1147         elm_widget_sub_object_add(obj, wd->label);
1148      }
1149
1150    if (!wd->entry)
1151      {
1152         wd->entry = elm_entry_add(obj);
1153         if (!wd->entry) return;
1154         elm_entry_scrollable_set(wd->entry, EINA_TRUE);
1155         elm_entry_single_line_set(wd->entry, EINA_TRUE);
1156         elm_object_text_set(wd->entry, "");
1157         elm_entry_input_panel_enabled_set(wd->entry, EINA_FALSE);
1158         evas_object_size_hint_min_set(wd->entry, MIN_W_ENTRY, 0);
1159         evas_object_size_hint_weight_set(wd->entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1160         evas_object_size_hint_align_set(wd->entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
1161         if (wd->box) elm_box_pack_end(wd->box, wd->entry);
1162         evas_object_show(wd->entry);
1163         wd->view_state = MULTIBUTTONENTRY_VIEW_ENTRY;
1164      }
1165
1166    if (!wd->end)
1167      {
1168         const char *end_type;
1169
1170         end_type = edje_object_data_get(wd->base, "closed_button_type");
1171         if (!end_type || !strcmp(end_type, "label"))
1172           {
1173              wd->end = elm_label_add(obj);
1174              if (!wd->end) return;
1175              elm_object_style_set(wd->end, "extended/multibuttonentry_default");
1176              wd->end_type = MULTIBUTTONENTRY_CLOSED_LABEL;
1177           }
1178         else
1179           {
1180              const char *size_str;
1181              wd->end = edje_object_add(evas_object_evas_get(obj));
1182              if (!wd->end) return;
1183              _elm_theme_object_set(obj, wd->end, "multibuttonentry", "closedbutton", elm_widget_style_get(obj));
1184              Evas_Coord button_min_width = 0;
1185              Evas_Coord button_min_height = 0;
1186
1187              size_str = edje_object_data_get(wd->end, "closed_button_width");
1188              if (size_str) button_min_width = (Evas_Coord)atoi(size_str);
1189              size_str = edje_object_data_get(wd->end, "closed_button_height");
1190              if (size_str) button_min_height = (Evas_Coord)atoi(size_str);
1191
1192              wd->end_type = MULTIBUTTONENTRY_CLOSED_IMAGE;
1193              evas_object_size_hint_min_set(wd->end, 
1194                                            button_min_width * _elm_config->scale, 
1195                                            button_min_height * _elm_config->scale);
1196              elm_widget_sub_object_add(obj, wd->end);
1197           }
1198      }
1199 }
1200
1201 static void
1202 _calculate_box_min_size(Evas_Object *box, Evas_Object_Box_Data *priv)
1203 {
1204    Evas_Coord minw, minh, mnw, mnh, ww;
1205    Evas_Coord w, cw = 0, cmaxh = 0;
1206    const Eina_List *l;
1207    Evas_Object_Box_Option *opt;
1208    double wx;
1209
1210    /* FIXME: need to calc max */
1211    minw = 0;
1212    minh = 0;
1213
1214    evas_object_geometry_get(box, NULL, NULL, &w, NULL);
1215    evas_object_size_hint_min_get(box, &minw, NULL);
1216
1217    EINA_LIST_FOREACH(priv->children, l, opt)
1218      {
1219         evas_object_size_hint_min_get(opt->obj, &mnw, &mnh);
1220         evas_object_size_hint_weight_get(opt->obj, &wx, NULL);
1221
1222         if (wx)
1223           {
1224              if ((elm_widget_is(opt->obj)) && (!(strcmp(elm_widget_type_get(opt->obj), "entry"))) && (mnw == -1))
1225                mnw = MIN_W_ENTRY;
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 ((elm_widget_is(opt->obj)) && (!(strcmp(elm_widget_type_get(opt->obj), "entry"))) && (mnw == -1))
1269                mnw = MIN_W_ENTRY;
1270
1271              if (mnw != -1 && (w - cw) >= mnw)
1272                 ww = w - cw;
1273              else
1274                 ww = w;
1275           }
1276         else
1277            ww = mnw;
1278
1279         if ((cw + ww) > w)
1280           {
1281              if (local_index > obj_index) return cmaxh;
1282              cw = 0;
1283              cmaxh = 0;
1284           }
1285
1286         cw += ww;
1287         if (cmaxh < mnh) cmaxh = mnh;
1288
1289         local_index++;
1290      }
1291
1292    return cmaxh;
1293 }
1294
1295 static void
1296 _box_layout_cb(Evas_Object *o, Evas_Object_Box_Data *priv, void *data __UNUSED__)
1297 {
1298    Evas_Coord x, y, w, h, xx, yy;
1299    const Eina_List *l;
1300    Evas_Object *obj;
1301    Evas_Coord minw, minh;
1302    double ax, ay;
1303    Evas_Object_Box_Option *opt;
1304
1305    _calculate_box_min_size(o, priv);
1306
1307    evas_object_geometry_get(o, &x, &y, &w, &h);
1308
1309    evas_object_size_hint_min_get(o, &minw, &minh);
1310    evas_object_size_hint_align_get(o, &ax, &ay);
1311    if (w < minw)
1312      {
1313         x = x + ((w - minw) * (1.0 - ax));
1314         w = minw;
1315      }
1316    if (h < minh)
1317      {
1318         y = y + ((h - minh) * (1.0 - ay));
1319         h = minh;
1320      }
1321
1322    xx = x;
1323    yy = y;
1324
1325    Evas_Coord cw = 0, ch = 0, cmaxh = 0, obj_index = 0;
1326
1327    EINA_LIST_FOREACH(priv->children, l, opt)
1328      {
1329         Evas_Coord mnw, mnh, mxw, mxh;
1330         double wx, wy;
1331         int fw, fh;
1332
1333         obj = opt->obj;
1334         evas_object_size_hint_align_get(obj, &ax, &ay);
1335         evas_object_size_hint_weight_get(obj, &wx, &wy);
1336         evas_object_size_hint_min_get(obj, &mnw, &mnh);
1337         evas_object_size_hint_max_get(obj, &mxw, &mxh);
1338         fw = fh = 0;
1339         if (ax == -1.0) {fw = 1; ax = 0.5;}
1340         if (ay == -1.0) {fh = 1; ay = 0.5;}
1341         Evas_Coord ww, hh, ow, oh;
1342
1343         if (wx)
1344           {
1345              if ((elm_widget_is(obj)) && (!(strcmp(elm_widget_type_get(obj), "entry"))) && (mnw == -1))
1346                mnw = MIN_W_ENTRY;
1347
1348              if (mnw != -1 && (w - cw) >= mnw)
1349                 ww = w - cw;
1350              else
1351                 ww = w;
1352           }
1353         else
1354            ww = mnw;
1355         hh = _calculate_item_max_height(o, priv, obj_index);
1356
1357         ow = mnw;
1358         if (fw) ow = ww;
1359         if ((mxw >= 0) && (mxw < ow)) ow = mxw;
1360         oh = mnh;
1361         if (fh) oh = hh;
1362         if ((mxh >= 0) && (mxh < oh)) oh = mxh;
1363
1364         if ((cw + ww) > w)
1365           {
1366              ch += cmaxh;
1367              cw = 0;
1368              cmaxh = 0;
1369           }
1370
1371         evas_object_move(obj,
1372                          xx + cw + (Evas_Coord)(((double)(ww - ow)) * ax),
1373                          yy + ch + (Evas_Coord)(((double)(hh - oh)) * ay));
1374         evas_object_resize(obj, ow, oh);
1375
1376         cw += ww;
1377         if (cmaxh < hh) cmaxh = hh;
1378
1379         obj_index++;
1380      }
1381 }
1382
1383 static void
1384 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
1385 {
1386    Elm_Multibuttonentry_Item *item;
1387    if (part && strcmp(part, "default")) return;
1388    if (!label) return;
1389    item = (Elm_Multibuttonentry_Item *)it;
1390    edje_object_part_text_set(item->button, "elm.btn.text", label);
1391    _resize_button(item->button, &item->rw, &item->vw);
1392 }
1393
1394 static const char *
1395 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
1396 {
1397    Elm_Multibuttonentry_Item *item;
1398    if (part && strcmp(part, "default")) return NULL;
1399    item = (Elm_Multibuttonentry_Item *)it;
1400    return edje_object_part_text_get(item->button, "elm.btn.text");
1401 }
1402
1403 static void
1404 _text_set_hook(Evas_Object *obj, const char *part, const char *label)
1405 {
1406    ELM_CHECK_WIDTYPE(obj, widtype);
1407    if (!part || !strcmp(part, "default"))
1408      {
1409         if (label) _set_label(obj, label);
1410         else _set_label(obj, "");
1411      }
1412    else if (!strcmp(part, "guide"))
1413      {
1414         if (label) _set_guidetext(obj, label);
1415         else _set_guidetext(obj, "");
1416      }
1417 }
1418
1419 static const char *
1420 _text_get_hook(const Evas_Object *obj, const char *part)
1421 {
1422    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1423    Widget_Data *wd = elm_widget_data_get(obj);
1424    if (!wd) return NULL;
1425
1426    if (!part || !strcmp(part, "default"))
1427      {
1428         return wd->labeltxt;
1429      }
1430    else if (!strcmp(part, "guide"))
1431      {
1432         return wd->guidetexttxt;
1433      }
1434    return NULL;
1435 }
1436
1437 EAPI Evas_Object *
1438 elm_multibuttonentry_add(Evas_Object *parent)
1439 {
1440    Evas_Object *obj;
1441    Evas *e;
1442    Widget_Data *wd;
1443
1444    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1445
1446    ELM_SET_WIDTYPE(widtype, "multibuttonentry");
1447    elm_widget_type_set(obj, "multibuttonentry");
1448    elm_widget_sub_object_add(parent, obj);
1449    elm_widget_data_set(obj, wd);
1450
1451    elm_widget_del_hook_set(obj, _del_hook);
1452    elm_widget_theme_hook_set(obj, _theme_hook);
1453    elm_widget_event_hook_set(obj, _event_hook);
1454    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1455    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1456    elm_widget_text_set_hook_set(obj, _text_set_hook);
1457    elm_widget_text_get_hook_set(obj, _text_get_hook);
1458
1459    wd->base = edje_object_add(e);
1460    _elm_theme_object_set(obj, wd->base, "multibuttonentry", "base", "default");
1461    elm_widget_resize_object_set(obj, wd->base);
1462    elm_widget_can_focus_set(obj, EINA_TRUE);
1463
1464    wd->view_state = MULTIBUTTONENTRY_VIEW_NONE;
1465    wd->focused = EINA_FALSE;
1466    wd->last_btn_select = EINA_TRUE;
1467    wd->n_str = 0;
1468    wd->rect_for_end = NULL;
1469    wd->add_callback = NULL;
1470    wd->add_callback_data = NULL;
1471
1472    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1473
1474    _view_init(obj);
1475    _event_init(obj);
1476
1477    return obj;
1478 }
1479
1480 EAPI Evas_Object *
1481 elm_multibuttonentry_entry_get(const Evas_Object *obj)
1482 {
1483    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1484    Widget_Data *wd = elm_widget_data_get(obj);
1485
1486    if (!wd) return NULL;
1487
1488    return wd->entry;
1489 }
1490
1491 EAPI Eina_Bool
1492 elm_multibuttonentry_expanded_get(const Evas_Object *obj)
1493 {
1494    ELM_CHECK_WIDTYPE(obj, widtype) -1;
1495    Widget_Data *wd = elm_widget_data_get(obj);
1496
1497    if (!wd) return -1;
1498      return (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK ? EINA_FALSE : EINA_TRUE);
1499
1500 }
1501
1502 EAPI void
1503 elm_multibuttonentry_expanded_set(Evas_Object *obj, Eina_Bool expanded)
1504 {
1505    ELM_CHECK_WIDTYPE(obj, widtype);
1506    Widget_Data *wd = elm_widget_data_get(obj);
1507
1508    if (!wd || !wd->box ||
1509        ((wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) ? EINA_FALSE : EINA_TRUE) == expanded) return;
1510
1511    if (expanded)
1512      _shrink_mode_set(obj, EINA_FALSE);
1513    else
1514      _shrink_mode_set(obj, EINA_TRUE);
1515
1516 }
1517
1518 EAPI Elm_Object_Item *
1519 elm_multibuttonentry_item_prepend(Evas_Object *obj, const char *label, Evas_Smart_Cb func, void *data)
1520 {
1521    return _add_button_item(obj, label, MULTIBUTTONENTRY_POS_START, NULL, func, data);
1522 }
1523
1524 EAPI Elm_Object_Item *
1525 elm_multibuttonentry_item_append(Evas_Object *obj, const char *label, Evas_Smart_Cb func, void *data)
1526 {
1527    return _add_button_item(obj, label, MULTIBUTTONENTRY_POS_END, NULL, func, data);
1528 }
1529
1530 EAPI Elm_Object_Item *
1531 elm_multibuttonentry_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *label, Evas_Smart_Cb func, void *data)
1532 {
1533    return _add_button_item(obj, label, MULTIBUTTONENTRY_POS_BEFORE, before, func, data);
1534 }
1535
1536 EAPI Elm_Object_Item *
1537 elm_multibuttonentry_item_insert_after(Evas_Object *obj, Elm_Object_Item *after, const char *label, Evas_Smart_Cb func, void *data)
1538 {
1539    return _add_button_item(obj, label, MULTIBUTTONENTRY_POS_AFTER, after, func, data);
1540 }
1541
1542 EAPI const Eina_List *
1543 elm_multibuttonentry_items_get(const Evas_Object *obj)
1544 {
1545    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1546    Widget_Data *wd = elm_widget_data_get(obj);
1547    if (!wd) return NULL;
1548    return wd->items;
1549 }
1550
1551 EAPI Elm_Object_Item *
1552 elm_multibuttonentry_first_item_get(const Evas_Object *obj)
1553 {
1554    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1555    Widget_Data *wd = elm_widget_data_get(obj);
1556    if (!wd) return NULL;
1557    return eina_list_data_get(wd->items);
1558 }
1559
1560 EAPI Elm_Object_Item *
1561 elm_multibuttonentry_last_item_get(const Evas_Object *obj)
1562 {
1563    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1564    Widget_Data *wd = elm_widget_data_get(obj);
1565    if (!wd) return NULL;
1566    return eina_list_data_get(eina_list_last(wd->items));
1567 }
1568
1569 EAPI Elm_Object_Item *
1570 elm_multibuttonentry_selected_item_get(const Evas_Object *obj)
1571 {
1572    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1573    Widget_Data *wd = elm_widget_data_get(obj);
1574    if (!wd) return NULL;
1575    return eina_list_data_get(wd->current);
1576 }
1577
1578 EAPI void
1579 elm_multibuttonentry_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1580 {
1581    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1582    Elm_Multibuttonentry_Item *item = (Elm_Multibuttonentry_Item *)it;
1583    if (selected) _select_button(WIDGET(item), item->button);
1584    else _select_button(WIDGET(item), NULL);
1585 }
1586
1587 EAPI Eina_Bool
1588 elm_multibuttonentry_item_selected_get(const Elm_Object_Item *it)
1589 {
1590    //TODO : To be implemented.
1591    if (!it) return EINA_FALSE;
1592    return EINA_TRUE;
1593 }
1594
1595 EAPI void
1596 elm_multibuttonentry_clear(Evas_Object *obj)
1597 {
1598    ELM_CHECK_WIDTYPE(obj, widtype);
1599    Elm_Multibuttonentry_Item *item;
1600    Widget_Data *wd = elm_widget_data_get(obj);
1601    if (!wd) return;
1602
1603    if (wd->items)
1604      {
1605         EINA_LIST_FREE(wd->items, item)
1606           {
1607              elm_box_unpack(wd->box, item->button);
1608              _del_button_obj(obj, item->button);
1609              free(item);
1610           }
1611         wd->items = NULL;
1612      }
1613    wd->current = NULL;
1614    _view_update(obj);
1615 }
1616
1617 EAPI Elm_Object_Item *
1618 elm_multibuttonentry_item_prev_get(const Elm_Object_Item *it)
1619 {
1620    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1621    Widget_Data *wd;
1622    Eina_List *l;
1623    Elm_Multibuttonentry_Item *_item;
1624
1625    wd = elm_widget_data_get(WIDGET(it));
1626    if (!wd) return NULL;
1627
1628    EINA_LIST_FOREACH(wd->items, l, _item)
1629      {
1630         if (_item == (Elm_Multibuttonentry_Item *)it)
1631           {
1632              l = eina_list_prev(l);
1633              if (!l) return NULL;
1634              return eina_list_data_get(l);
1635           }
1636      }
1637    return NULL;
1638 }
1639
1640 EAPI Elm_Object_Item *
1641 elm_multibuttonentry_item_next_get(const Elm_Object_Item *it)
1642 {
1643    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1644    Widget_Data *wd;
1645    Eina_List *l;
1646    Elm_Multibuttonentry_Item *_item;
1647    wd = elm_widget_data_get(WIDGET(it));
1648    if (!wd) return NULL;
1649
1650    EINA_LIST_FOREACH(wd->items, l, _item)
1651      {
1652         if (_item == (Elm_Multibuttonentry_Item *)it)
1653           {
1654              l = eina_list_next(l);
1655              if (!l) return NULL;
1656              return eina_list_data_get(l);
1657           }
1658      }
1659    return NULL;
1660 }
1661
1662 EAPI void *
1663 elm_multibuttonentry_item_data_get(const Elm_Object_Item *it)
1664 {
1665    return elm_widget_item_data_get(it);
1666 }
1667
1668 EAPI void
1669 elm_multibuttonentry_item_data_set(Elm_Object_Item *it, void *data)
1670 {
1671    return elm_widget_item_data_set(it, data);
1672 }
1673
1674 EAPI void
1675 elm_multibuttonentry_item_filter_append(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_Cb func, void *data)
1676 {
1677    Elm_Multibuttonentry_Item_Filter *new_item_filter = NULL;
1678    Elm_Multibuttonentry_Item_Filter *_item_filter = NULL;
1679    Eina_List *l;
1680
1681    Widget_Data *wd = elm_widget_data_get(obj);
1682    if (!wd) return;
1683
1684    ELM_CHECK_WIDTYPE(obj, widtype);
1685    EINA_SAFETY_ON_NULL_RETURN(func);
1686
1687    new_item_filter= _filter_new(func, data);
1688    if (!new_item_filter) return;
1689
1690    EINA_LIST_FOREACH(wd->filter_list, l, _item_filter)
1691      {
1692         if (_item_filter && ((_item_filter->callback_func == func) && (_item_filter->data == data)))
1693           {
1694              printf("Already Registered this item filter!!!!\n");
1695              return;
1696           }
1697      }
1698    wd->filter_list = eina_list_append(wd->filter_list, new_item_filter);
1699 }
1700
1701 EAPI void
1702 elm_multibuttonentry_item_filter_prepend(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_Cb func, void *data)
1703 {
1704    Elm_Multibuttonentry_Item_Filter *new_item_filter = NULL;
1705    Elm_Multibuttonentry_Item_Filter *_item_filter = NULL;
1706    Eina_List *l;
1707    Widget_Data *wd = elm_widget_data_get(obj);
1708    if (!wd) return;
1709
1710    ELM_CHECK_WIDTYPE(obj, widtype);
1711    EINA_SAFETY_ON_NULL_RETURN(func);
1712
1713    new_item_filter = _filter_new(func, data);
1714    if (!new_item_filter) return;
1715
1716    EINA_LIST_FOREACH(wd->filter_list, l, _item_filter)
1717      {
1718         if (_item_filter && ((_item_filter->callback_func == func) && (_item_filter->data == data)))
1719           {
1720              printf("Already Registered this item filter!!!!\n");
1721              return;
1722           }
1723      }
1724    wd->filter_list = eina_list_prepend(wd->filter_list, new_item_filter);
1725 }
1726
1727 EAPI void
1728 elm_multibuttonentry_item_filter_remove(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_Cb func, void *data)
1729 {
1730    Widget_Data *wd;
1731    Eina_List *l;
1732    Elm_Multibuttonentry_Item_Filter *item_filter;
1733
1734    wd = elm_widget_data_get(obj);
1735
1736    EINA_SAFETY_ON_NULL_RETURN(func);
1737
1738    EINA_LIST_FOREACH(wd->filter_list, l, item_filter)
1739      {
1740         if ((item_filter->callback_func == func) && ((!data) || (item_filter->data == data)))
1741           {
1742              wd->filter_list = eina_list_remove_list(wd->filter_list, l);
1743              _filter_free(item_filter);
1744              return;
1745           }
1746      }
1747 }