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