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