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