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