deprecate guide text set api in multibutton as per xxx
[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_scale_get() );
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, button_min_width * elm_scale_get(), button_min_height * elm_scale_get());
1165              elm_widget_sub_object_add(obj, wd->end);
1166           }
1167      }
1168 }
1169
1170 static void
1171 _calculate_box_min_size(Evas_Object *box, Evas_Object_Box_Data *priv)
1172 {
1173    Evas_Coord minw, minh, mnw, mnh, ww;
1174    Evas_Coord w, cw = 0, cmaxh = 0;
1175    const Eina_List *l;
1176    Evas_Object_Box_Option *opt;
1177    double wx;
1178
1179    /* FIXME: need to calc max */
1180    minw = 0;
1181    minh = 0;
1182
1183    evas_object_geometry_get(box, NULL, NULL, &w, NULL);
1184    evas_object_size_hint_min_get(box, &minw, NULL);
1185
1186    EINA_LIST_FOREACH(priv->children, l, opt)
1187      {
1188         evas_object_size_hint_min_get(opt->obj, &mnw, &mnh);
1189         evas_object_size_hint_weight_get(opt->obj, &wx, NULL);
1190
1191         if (wx)
1192           {
1193              if (mnw != -1 && (w - cw) >= mnw)
1194                ww = w - cw;
1195              else
1196                ww = w;
1197           }
1198         else
1199            ww = mnw;
1200
1201         if ((cw + mnw) > w)
1202           {
1203              minh += cmaxh;
1204              cw = 0;
1205              cmaxh = 0;
1206           }
1207         cw += ww;
1208         if (cmaxh < mnh) cmaxh = mnh;
1209      }
1210
1211    minh += cmaxh;
1212
1213    evas_object_size_hint_min_set(box, minw, minh);
1214 }
1215
1216 static Evas_Coord
1217 _calculate_item_max_height(Evas_Object *box, Evas_Object_Box_Data *priv, int obj_index)
1218 {
1219    Evas_Coord mnw, mnh, cw = 0, cmaxh = 0, w, ww;
1220    const Eina_List *l;
1221    Evas_Object_Box_Option *opt;
1222    int index = 0;
1223    double wx;
1224
1225    evas_object_geometry_get(box, NULL, NULL, &w, NULL);
1226
1227    EINA_LIST_FOREACH(priv->children, l, opt)
1228      {
1229         evas_object_size_hint_min_get(opt->obj, &mnw, &mnh);
1230         evas_object_size_hint_weight_get(opt->obj, &wx, NULL);
1231
1232         if (wx)
1233           {
1234              if (mnw != -1 && (w - cw) >= mnw)
1235                 ww = w - cw;
1236              else
1237                 ww = w;
1238           }
1239         else
1240            ww = mnw;
1241
1242         if ((cw + ww) > w)
1243           {
1244              if (index > obj_index) return cmaxh;
1245              cw = 0;
1246              cmaxh = 0;
1247           }
1248
1249         cw += ww;
1250         if (cmaxh < mnh) cmaxh = mnh;
1251
1252         index++;
1253      }
1254
1255    return cmaxh;
1256 }
1257
1258 static void
1259 _box_layout_cb(Evas_Object *o, Evas_Object_Box_Data *priv, void *data __UNUSED__)
1260 {
1261    Evas_Coord x, y, w, h, xx, yy;
1262    const Eina_List *l;
1263    Evas_Object *obj;
1264    Evas_Coord minw, minh;
1265    double ax, ay;
1266    Evas_Object_Box_Option *opt;
1267
1268    _calculate_box_min_size(o, priv);
1269
1270    evas_object_geometry_get(o, &x, &y, &w, &h);
1271
1272    evas_object_size_hint_min_get(o, &minw, &minh);
1273    evas_object_size_hint_align_get(o, &ax, &ay);
1274    if (w < minw)
1275      {
1276         x = x + ((w - minw) * (1.0 - ax));
1277         w = minw;
1278      }
1279    if (h < minh)
1280      {
1281         y = y + ((h - minh) * (1.0 - ay));
1282         h = minh;
1283      }
1284
1285    xx = x;
1286    yy = y;
1287
1288    Evas_Coord cw = 0, ch = 0, cmaxh = 0, obj_index = 0;
1289
1290    EINA_LIST_FOREACH(priv->children, l, opt)
1291      {
1292         Evas_Coord mnw, mnh, mxw, mxh;
1293         double wx, wy;
1294         int fw, fh;
1295
1296         obj = opt->obj;
1297         evas_object_size_hint_align_get(obj, &ax, &ay);
1298         evas_object_size_hint_weight_get(obj, &wx, &wy);
1299         evas_object_size_hint_min_get(obj, &mnw, &mnh);
1300         evas_object_size_hint_max_get(obj, &mxw, &mxh);
1301         fw = fh = 0;
1302         if (ax == -1.0) {fw = 1; ax = 0.5;}
1303         if (ay == -1.0) {fh = 1; ay = 0.5;}
1304         Evas_Coord ww, hh, ow, oh;
1305
1306         if (wx)
1307           {
1308              if (mnw != -1 && (w - cw) >= mnw)
1309                 ww = w - cw;
1310              else
1311                 ww = w;
1312           }
1313         else
1314            ww = mnw;
1315         hh = _calculate_item_max_height(o, priv, obj_index);
1316
1317         ow = mnw;
1318         if (fw) ow = ww;
1319         if ((mxw >= 0) && (mxw < ow)) ow = mxw;
1320         oh = mnh;
1321         if (fh) oh = hh;
1322         if ((mxh >= 0) && (mxh < oh)) oh = mxh;
1323
1324         if ((cw + ww) > w)
1325           {
1326              ch += cmaxh;
1327              cw = 0;
1328              cmaxh = 0;
1329           }
1330
1331         evas_object_move(obj,
1332                          xx + cw + (Evas_Coord)(((double)(ww - ow)) * ax),
1333                          yy + ch + (Evas_Coord)(((double)(hh - oh)) * ay));
1334         evas_object_resize(obj, ow, oh);
1335
1336         cw += ww;
1337         if (cmaxh < hh) cmaxh = hh;
1338
1339         obj_index++;
1340      }
1341 }
1342
1343 static void
1344 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
1345 {
1346    Elm_Multibuttonentry_Item *item;
1347    if (part && strcmp(part, "default")) return;
1348    if (!label) return;
1349    item = (Elm_Multibuttonentry_Item *) it;
1350    edje_object_part_text_set(item->button, "elm.btn.text", label);
1351    _resize_button(item->button, &item->rw, &item->vw);
1352 }
1353
1354 static const char *
1355 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
1356 {
1357    Elm_Multibuttonentry_Item *item;
1358    if (part && strcmp(part, "default")) return NULL;
1359    item = (Elm_Multibuttonentry_Item *) it;
1360    return edje_object_part_text_get(item->button, "elm.btn.text");
1361 }
1362
1363 static void
1364 _text_set_hook(Evas_Object *obj, const char *part, const char *label)
1365 {
1366    ELM_CHECK_WIDTYPE(obj, widtype);
1367    if (!part || !strcmp(part, "default"))
1368      {
1369         if (label) _set_label(obj, label);
1370         else _set_label(obj, "");
1371      }
1372    else if (!strcmp(part, "guide"))
1373      {
1374         if (label) _set_guidetext(obj, label);
1375         else _set_guidetext(obj, "");
1376      }
1377 }
1378
1379 static const char *
1380 _text_get_hook(const Evas_Object *obj, const char *part)
1381 {
1382    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1383    Widget_Data *wd;
1384    if (!part || !strcmp(part, "default"))
1385      {
1386         return wd->labeltxt;
1387      }
1388    else if (!strcmp(part, "guide"))
1389      {
1390         return wd->guidetexttxt;
1391      }
1392    return NULL;
1393 }
1394
1395 EAPI Evas_Object *
1396 elm_multibuttonentry_add(Evas_Object *parent)
1397 {
1398    Evas_Object *obj;
1399    Evas *e;
1400    Widget_Data *wd;
1401
1402    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1403
1404    ELM_SET_WIDTYPE(widtype, "multibuttonentry");
1405    elm_widget_type_set(obj, "multibuttonentry");
1406    elm_widget_sub_object_add(parent, obj);
1407    elm_widget_data_set(obj, wd);
1408
1409    elm_widget_del_hook_set(obj, _del_hook);
1410    elm_widget_theme_hook_set(obj, _theme_hook);
1411    elm_widget_event_hook_set(obj, _event_hook);
1412    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1413    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1414    elm_widget_text_set_hook_set(obj, _text_set_hook);
1415    elm_widget_text_get_hook_set(obj, _text_get_hook);
1416
1417    wd->base = edje_object_add(e);
1418    _elm_theme_object_set(obj, wd->base, "multibuttonentry", "base", "default");
1419    elm_widget_resize_object_set(obj, wd->base);
1420    elm_widget_can_focus_set(obj, EINA_TRUE);
1421
1422    wd->view_state = MULTIBUTTONENTRY_VIEW_NONE;
1423    wd->focused = EINA_FALSE;
1424    wd->last_btn_select = EINA_TRUE;
1425    wd->n_str = 0;
1426    wd->rect_for_end= NULL;
1427    wd->add_callback = NULL;
1428    wd->add_callback_data = NULL;
1429
1430    _view_init(obj);
1431    _event_init(obj);
1432
1433    return obj;
1434 }
1435
1436 EAPI Evas_Object *
1437 elm_multibuttonentry_entry_get(const Evas_Object *obj)
1438 {
1439    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1440    Widget_Data *wd = elm_widget_data_get(obj);
1441
1442    if (!wd) return NULL;
1443
1444    return wd->entry;
1445 }
1446
1447 EINA_DEPRECATED EAPI const char *
1448 elm_multibuttonentry_label_get(const Evas_Object *obj)
1449 {
1450    return _text_get_hook(obj, NULL);
1451 }
1452
1453 EINA_DEPRECATED EAPI void
1454 elm_multibuttonentry_label_set(Evas_Object *obj, const char *label)
1455 {
1456    _text_set_hook(obj, NULL, label);
1457 }
1458
1459 EINA_DEPRECATED EAPI const char *
1460 elm_multibuttonentry_guide_text_get(const Evas_Object *obj)
1461 {
1462    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1463    Widget_Data *wd = elm_widget_data_get(obj);
1464
1465    if (!wd) return NULL;
1466    if (wd->guidetext) return edje_object_part_text_get(wd->guidetext, "elm.text");
1467    return NULL;
1468 }
1469
1470 EINA_DEPRECATED EAPI void
1471 elm_multibuttonentry_guide_text_set(Evas_Object *obj, const char *guidetext)
1472 {
1473    ELM_CHECK_WIDTYPE(obj, widtype);
1474    Widget_Data *wd = elm_widget_data_get(obj);
1475
1476    if (!wd) return;
1477
1478    _set_guidetext(obj, guidetext);
1479 }
1480
1481 EINA_DEPRECATED EAPI int
1482 elm_multibuttonentry_shrink_mode_get(const Evas_Object *obj)
1483 {
1484    if (elm_multibuttonentry_expanded_get(obj))
1485      return 0;
1486    else
1487      return 1;
1488 }
1489
1490 EAPI Eina_Bool
1491 elm_multibuttonentry_expanded_get(const Evas_Object *obj)
1492 {
1493    ELM_CHECK_WIDTYPE(obj, widtype) -1;
1494    Widget_Data *wd = elm_widget_data_get(obj);
1495
1496    if (!wd) return -1;
1497      return (wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK ? EINA_FALSE : EINA_TRUE);
1498
1499 }
1500
1501 EINA_DEPRECATED EAPI void
1502 elm_multibuttonentry_shrink_mode_set(Evas_Object *obj, int shrink)
1503 {
1504    if (shrink==0)
1505      elm_multibuttonentry_expanded_set(obj, EINA_TRUE);
1506
1507    if (shrink==1)
1508      elm_multibuttonentry_expanded_set(obj, EINA_FALSE);
1509 }
1510
1511 EAPI void
1512 elm_multibuttonentry_expanded_set(Evas_Object *obj, Eina_Bool expanded)
1513 {
1514    ELM_CHECK_WIDTYPE(obj, widtype);
1515    Widget_Data *wd = elm_widget_data_get(obj);
1516
1517    if (!wd || !wd->box ||
1518        ((wd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) ? EINA_FALSE : EINA_TRUE) == expanded) return;
1519
1520    if (expanded)
1521      _shrink_mode_set(obj, 0);
1522    else
1523      _shrink_mode_set(obj, 1);
1524
1525 }
1526
1527 EAPI Elm_Object_Item *
1528 elm_multibuttonentry_item_prepend(Evas_Object *obj, const char *label, Evas_Smart_Cb func, void *data)
1529 {
1530    return _add_button_item(obj, label, MULTIBUTTONENTRY_POS_START, NULL, data);
1531 }
1532
1533 EAPI Elm_Object_Item *
1534 elm_multibuttonentry_item_append(Evas_Object *obj, const char *label, Evas_Smart_Cb func, void *data)
1535 {
1536    return _add_button_item(obj, label, MULTIBUTTONENTRY_POS_END, NULL, data);
1537 }
1538
1539 EAPI Elm_Object_Item *
1540 elm_multibuttonentry_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *label, Evas_Smart_Cb func, void *data)
1541 {
1542    return _add_button_item(obj, label, MULTIBUTTONENTRY_POS_BEFORE, before, data);
1543 }
1544
1545 EAPI Elm_Object_Item *
1546 elm_multibuttonentry_item_insert_after(Evas_Object *obj, Elm_Object_Item *after, const char *label, Evas_Smart_Cb func, void *data)
1547 {
1548    return _add_button_item(obj, label, MULTIBUTTONENTRY_POS_AFTER, after, data);
1549 }
1550
1551 EAPI const Eina_List *
1552 elm_multibuttonentry_items_get(const Evas_Object *obj)
1553 {
1554    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1555    Widget_Data *wd = elm_widget_data_get(obj);
1556    if (!wd) return NULL;
1557    return wd->items;
1558 }
1559
1560 EAPI Elm_Object_Item *
1561 elm_multibuttonentry_first_item_get(const Evas_Object *obj)
1562 {
1563    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1564    Widget_Data *wd = elm_widget_data_get(obj);
1565    if (!wd) return NULL;
1566    return eina_list_data_get(wd->items);
1567 }
1568
1569 EAPI Elm_Object_Item *
1570 elm_multibuttonentry_last_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(eina_list_last(wd->items));
1576 }
1577
1578 EAPI Elm_Object_Item *
1579 elm_multibuttonentry_selected_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(wd->current);
1585 }
1586
1587 EAPI void
1588 elm_multibuttonentry_item_select(Elm_Object_Item *it, Eina_Bool selected)
1589 {
1590    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1591    Elm_Multibuttonentry_Item *item = (Elm_Multibuttonentry_Item *) it;
1592    if (selected) _select_button(WIDGET(item), item->button);
1593    else _select_button(WIDGET(item), NULL);
1594 }
1595
1596 EAPI void
1597 elm_multibuttonentry_item_unselect_all(Evas_Object *obj)
1598 {
1599    ELM_CHECK_WIDTYPE(obj, widtype);
1600    Widget_Data *wd = elm_widget_data_get(obj);
1601    if (!wd) return;
1602    _select_button(obj, NULL);
1603 }
1604
1605 EAPI void
1606 elm_multibuttonentry_clear(Evas_Object *obj)
1607 {
1608    ELM_CHECK_WIDTYPE(obj, widtype);
1609    Elm_Multibuttonentry_Item *item;
1610    Widget_Data *wd = elm_widget_data_get(obj);
1611    if (!wd) return;
1612
1613    if (wd->items)
1614      {
1615         EINA_LIST_FREE(wd->items, item)
1616           {
1617              elm_box_unpack(wd->box, item->button);
1618              _del_button_obj(obj, item->button);
1619              free(item);
1620           }
1621         wd->items = NULL;
1622      }
1623    wd->current = NULL;
1624    _view_update(obj);
1625 }
1626
1627 EAPI void
1628 elm_multibuttonentry_item_del(Elm_Object_Item *it)
1629 {
1630    elm_object_item_del(it);
1631 }
1632
1633 EAPI const char *
1634 elm_multibuttonentry_item_label_get(const Elm_Object_Item *it)
1635 {
1636    return _item_text_get_hook(it, NULL);
1637 }
1638
1639 EAPI void
1640 elm_multibuttonentry_item_label_set(Elm_Object_Item *it, const char *str)
1641 {
1642    _item_text_set_hook(it, NULL, str);
1643 }
1644
1645 EAPI Elm_Object_Item *
1646 elm_multibuttonentry_item_prev_get(const Elm_Object_Item *it)
1647 {
1648    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1649    Widget_Data *wd;
1650    Eina_List *l;
1651    Elm_Multibuttonentry_Item *_item;
1652
1653    wd = elm_widget_data_get(WIDGET(it));
1654    if (!wd) return NULL;
1655
1656    EINA_LIST_FOREACH(wd->items, l, _item)
1657      {
1658         if (_item == (Elm_Multibuttonentry_Item *) it)
1659           {
1660              l = eina_list_prev(l);
1661              if (!l) return NULL;
1662              return eina_list_data_get(l);
1663           }
1664      }
1665    return NULL;
1666 }
1667
1668 EAPI Elm_Object_Item *
1669 elm_multibuttonentry_item_next_get(const Elm_Object_Item *it)
1670 {
1671    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1672    Widget_Data *wd;
1673    Eina_List *l;
1674    Elm_Multibuttonentry_Item *_item;
1675    wd = elm_widget_data_get(WIDGET(it));
1676    if (!wd) return NULL;
1677
1678    EINA_LIST_FOREACH(wd->items, l, _item)
1679      {
1680         if (_item == (Elm_Multibuttonentry_Item *) it)
1681           {
1682              l = eina_list_next(l);
1683              if (!l) return NULL;
1684              return eina_list_data_get(l);
1685           }
1686      }
1687    return NULL;
1688 }
1689
1690 EAPI void *
1691 elm_multibuttonentry_item_data_get(const Elm_Object_Item *it)
1692 {
1693    return elm_widget_item_data_get(it);
1694 }
1695
1696 EAPI void
1697 elm_multibuttonentry_item_data_set(Elm_Object_Item *it, void *data)
1698 {
1699    return elm_widget_item_data_set(it, data);
1700 }
1701
1702 EAPI void
1703 elm_multibuttonentry_item_filter_append(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_callback func, void *data)
1704 {
1705    Elm_Multibuttonentry_Item_Filter *new_item_filter = NULL;
1706    Elm_Multibuttonentry_Item_Filter *_item_filter = NULL;
1707    Eina_List *l;
1708
1709    Widget_Data *wd = elm_widget_data_get(obj);
1710    if (!wd) return;
1711
1712    ELM_CHECK_WIDTYPE(obj, widtype);
1713    EINA_SAFETY_ON_NULL_RETURN(func);
1714
1715    new_item_filter= _filter_new(func, data);
1716    if (!new_item_filter) return;
1717
1718    EINA_LIST_FOREACH(wd->filter_list, l, _item_filter)
1719      {
1720         if (_item_filter && ((_item_filter->callback_func == func) && (_item_filter->data == data)))
1721           {
1722              printf("Already Registered this item filter!!!!\n");
1723              return;
1724           }
1725      }
1726    wd->filter_list = eina_list_append(wd->filter_list, new_item_filter);
1727 }
1728
1729 EAPI void
1730 elm_multibuttonentry_item_filter_prepend(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_callback func, void *data)
1731 {
1732    Elm_Multibuttonentry_Item_Filter *new_item_filter = NULL;
1733    Elm_Multibuttonentry_Item_Filter *_item_filter = NULL;
1734    Eina_List *l;
1735    Widget_Data *wd = elm_widget_data_get(obj);
1736    if (!wd) return;
1737
1738    ELM_CHECK_WIDTYPE(obj, widtype);
1739    EINA_SAFETY_ON_NULL_RETURN(func);
1740
1741    new_item_filter = _filter_new(func, data);
1742    if (!new_item_filter) return;
1743
1744    EINA_LIST_FOREACH(wd->filter_list, l, _item_filter)
1745      {
1746         if (_item_filter && ((_item_filter->callback_func == func) && (_item_filter->data == data)))
1747           {
1748              printf("Already Registered this item filter!!!!\n");
1749              return;
1750           }
1751      }
1752    wd->filter_list = eina_list_prepend(wd->filter_list, new_item_filter);
1753 }
1754
1755 EAPI void
1756 elm_multibuttonentry_item_filter_remove(Evas_Object *obj, Elm_Multibuttonentry_Item_Filter_callback func, void *data)
1757 {
1758    Widget_Data *wd;
1759    Eina_List *l;
1760    Elm_Multibuttonentry_Item_Filter *item_filter;
1761
1762    wd = elm_widget_data_get(obj);
1763
1764    EINA_SAFETY_ON_NULL_RETURN(func);
1765
1766    EINA_LIST_FOREACH(wd->filter_list, l, item_filter)
1767      {
1768         if ((item_filter->callback_func == func) && ((!data) || (item_filter->data == data)))
1769           {
1770              wd->filter_list = eina_list_remove_list(wd->filter_list, l);
1771              _filter_free(item_filter);
1772              return;
1773           }
1774      }
1775 }