1 #include <Elementary.h>
6 * @defgroup DialogueGroup DialogueGroup
9 * Using dialoguegroup, you can make a dialogue group.
15 Evas_Object *bg_layout;
17 Elm_Dialoguegroup_Item_Style style;
21 // Eina_Bool line_show;
25 typedef struct _Widget_Data Widget_Data;
29 Evas_Object *title_layout;
35 static const char*widtype = NULL;
37 static void _del_hook(Evas_Object *obj);
38 static void _theme_hook(Evas_Object *obj);
39 static void _sizing_eval(Evas_Object *obj);
41 static void _remove_all(Evas_Object *obj);
42 static void _set_item_theme(Dialogue_Item *item, const char *location);
43 static void _change_item_bg(Dialogue_Item *item, const char *location);
44 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style, const char *location);
48 _del_hook(Evas_Object *obj)
50 Widget_Data *wd = elm_widget_data_get(obj);
53 if (wd->title) eina_stringshare_del(wd->title);
58 evas_object_del(wd->box);
67 _theme_hook(Evas_Object *obj)
69 Widget_Data *wd = elm_widget_data_get(obj);
75 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "title", elm_widget_style_get(obj));
76 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", wd->title);
78 EINA_LIST_FOREACH(wd->items, l, item)
79 _change_item_bg( item, item->location );
84 _sizing_eval(Evas_Object *obj)
86 Widget_Data *wd = elm_widget_data_get(obj);
87 Evas_Coord minw, minh, maxw, maxh;
90 evas_object_size_hint_min_get(wd->box, &minw, &minh);
91 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
92 evas_object_size_hint_min_set(obj, minw, minh);
93 evas_object_size_hint_max_set(obj, maxw, maxh);
97 _remove_all(Evas_Object *obj)
99 Widget_Data *wd = elm_widget_data_get(obj);
107 EINA_LIST_FREE(wd->items, item) {
109 evas_object_del(item->content);
110 item->content = NULL;
112 if (item->bg_layout){
113 evas_object_del(item->bg_layout);
114 item->bg_layout = NULL;
117 eina_stringshare_del(item->location);
124 _set_item_theme(Dialogue_Item *item, const char *location)
129 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT)
130 snprintf(buf, sizeof(buf), "bg_%s", location);
131 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD)
132 snprintf(buf, sizeof(buf), "editfield_%s", location);
133 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD_WITH_TITLE)
134 snprintf(buf, sizeof(buf), "editfield_with_title_%s", location);
135 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDIT_TITLE)
136 snprintf(buf, sizeof(buf), "edit_title_%s", location);
137 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_HIDDEN)
138 snprintf(buf, sizeof(buf), "hidden_%s", location);
139 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DATAVIEW)
140 snprintf(buf, sizeof(buf), "dataview_%s", location);
141 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_NO_BG)
142 snprintf(buf, sizeof(buf), "no_bg_%s", location);
143 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
144 snprintf(buf, sizeof(buf), "sub_%s", location);
145 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDIT)
146 snprintf(buf, sizeof(buf), "bg_edit_%s", location);
147 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDIT_MERGE)
148 snprintf(buf, sizeof(buf), "bg_edit_merge_%s", location);
149 elm_layout_theme_set(item->bg_layout, "dialoguegroup", buf, elm_widget_style_get(item->obj));
153 static void _set_line_show(Dialogue_Item *item, Dialogue_Item *after)
155 if(!item || !after) return;
157 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT) {
158 if (after->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT) {
159 item->line_show = EINA_TRUE;
160 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,show", "elm");
162 else if (after->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD) {
163 item->line_show = EINA_FALSE;
164 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");
167 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD)
168 item->line_show = EINA_TRUE;
173 _change_item_bg(Dialogue_Item *item, const char *location)
177 eina_stringshare_replace(&item->location, location);
178 _set_item_theme(item, location);
179 elm_layout_content_set(item->bg_layout, "swallow", item->content);
180 if ((item->press == EINA_TRUE) && (item->disabled == EINA_FALSE))
181 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
183 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
184 if (item->disabled == EINA_TRUE)
185 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,disabled", "elm");
187 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,enabled", "elm");
189 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
190 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "flip_item", "");
192 /* if(item->line_show == EINA_FALSE)
193 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");*/
197 static Dialogue_Item*
198 _create_item(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style, const char *location)
200 Widget_Data *wd = elm_widget_data_get(obj);
203 if (!wd) return NULL;
205 item = ELM_NEW(Dialogue_Item);
207 item->content = subobj;
208 item->press = EINA_TRUE;
209 item->disabled = EINA_FALSE;
211 // item->line_show = EINA_TRUE;
212 eina_stringshare_replace(&item->location, location);
214 item->bg_layout = elm_layout_add(wd->box);
215 _set_item_theme(item, location);
216 evas_object_size_hint_weight_set(item->bg_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
217 evas_object_size_hint_align_set(item->bg_layout, EVAS_HINT_FILL, 0.0);
218 evas_object_show(item->bg_layout);
220 elm_layout_content_set(item->bg_layout, "swallow", item->content);
226 _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
232 * Add a new dialoguegroup to the parent.
234 * @param parent The parent object
235 * @return The new object or NULL if it cannot be created
237 * @ingroup DialogueGroup
240 elm_dialoguegroup_add(Evas_Object *parent)
242 Evas_Object *obj = NULL;
243 Widget_Data *wd = NULL;
246 e = evas_object_evas_get(parent);
247 if (e == NULL) return NULL;
248 wd = ELM_NEW(Widget_Data);
249 obj = elm_widget_add(e);
250 ELM_SET_WIDTYPE(widtype, "dialoguegroup");
251 elm_widget_type_set(obj, "dialoguegroup");
252 elm_widget_sub_object_add(parent, obj);
253 elm_widget_data_set(obj, wd);
254 elm_widget_del_hook_set(obj, _del_hook);
255 elm_widget_theme_hook_set(obj, _theme_hook);
259 wd->box = elm_box_add(obj);
260 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
261 evas_object_show(wd->box);
262 elm_widget_resize_object_set(obj, wd->box);
269 * Append an item to the dialogue group.
271 * @param obj dialoguegroup object
273 * @param style sytle of the item
274 * @return Dialogue_Item pointer, just made by this function
276 * @ingroup DialogueGroup
279 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
281 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
282 Widget_Data *wd = elm_widget_data_get(obj);
283 Dialogue_Item *item = NULL, *new_item = NULL;
285 if (!wd || !subobj) return NULL;
288 new_item = _create_item(obj, subobj, style, "default");
291 item = eina_list_data_get(wd->items);
292 _change_item_bg(item, "top");
295 item = eina_list_data_get( eina_list_last(wd->items) );
296 _change_item_bg(item, "middle");
298 new_item = _create_item(obj, subobj, style, "bottom");
299 // _set_line_show(item, new_item);
301 elm_box_pack_end(wd->box, new_item->bg_layout);
302 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
303 edje_object_signal_emit(elm_layout_edje_get(new_item->bg_layout), "flip_item", "");
304 wd->items = eina_list_append(wd->items, new_item);
312 * Prepend an item to the dialogue group.
314 * @param obj dialoguegroup object
316 * @param style sytle of the item
317 * @return Dialogue_Item pointer, just made by this function
319 * @ingroup DialogueGroup
322 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
324 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
325 Widget_Data *wd = elm_widget_data_get(obj);
326 Dialogue_Item *item = NULL, *new_item = NULL;
328 if (!wd || !subobj) return NULL;
331 new_item = _create_item(obj, subobj, style, "default");
334 item = eina_list_data_get(wd->items);
335 _change_item_bg(item, "bottom");
338 item = eina_list_data_get(wd->items);
339 _change_item_bg(item, "middle");
341 new_item = _create_item(obj, subobj, style, "top");
342 // _set_line_show(new_item, item);
344 if (wd->title_layout)
345 elm_box_pack_after(wd->box, new_item->bg_layout, wd->title_layout);
347 elm_box_pack_start(wd->box, new_item->bg_layout);
348 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
349 edje_object_signal_emit(elm_layout_edje_get(new_item->bg_layout), "flip_item", "");
350 wd->items = eina_list_prepend(wd->items, new_item);
357 * Insert an item to the dialogue group just after the specified item.
359 * @param obj dialoguegroup object
361 * @param after specified item existing in the dialogue group
362 * @param style sytle of the item
363 * @return Dialogue_Item pointer, just made by this function
365 * @ingroup DialogueGroup
368 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *after, Elm_Dialoguegroup_Item_Style style)
370 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
371 Widget_Data *wd = elm_widget_data_get(obj);
372 Dialogue_Item *after_item = NULL, *item = NULL;
375 if (!wd || !subobj || !after || !wd->items) return NULL;
377 EINA_LIST_FOREACH(wd->items, l, after_item) {
378 if (after == after_item) {
379 if ( !strcmp(after_item->location, "default") ) {
380 _change_item_bg(after_item, "top");
381 item = _create_item(obj, subobj, style, "bottom");
383 else if ( !strcmp(after_item->location, "top") || !strcmp(after_item->location, "middle") )
384 item = _create_item(obj, subobj, style, "middle");
385 else if ( !strcmp(after_item->location, "bottom") ) {
386 _change_item_bg(after_item, "middle");
387 item = _create_item(obj, subobj, style, "bottom");
391 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
392 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
393 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "flip_item", "");
394 wd->items = eina_list_append_relative(wd->items, item, after_item);
395 // _set_line_show(after, item);
405 * Insert an item to the dialogue group just before the specified item.
407 * @param obj dialoguegroup object
409 * @param before specified item existing in the dialogue group
410 * @param style sytle of the item
411 * @return Dialogue_Item pointer, just made by this function
413 * @ingroup DialogueGroup
416 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *before, Elm_Dialoguegroup_Item_Style style)
418 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
419 Widget_Data *wd = elm_widget_data_get(obj);
420 Dialogue_Item *before_item = NULL, *item = NULL;
424 if (!wd || !subobj || !before || !wd->items) return NULL;
426 EINA_LIST_FOREACH(wd->items, l, before_item) {
427 if (before == before_item) {
428 if ( !strcmp(before_item->location, "default") ) {
429 _change_item_bg(before_item, "bottom");
430 item = _create_item(obj, subobj, style, "top");
433 else if ( !strcmp(before_item->location, "top") ) {
434 _change_item_bg(before_item, "middle");
435 item = _create_item(obj, subobj, style, "top");
438 else if ( !strcmp(before_item->location, "middle") || !strcmp(before_item->location, "bottom") ) {
439 item = _create_item(obj, subobj, style, "middle");
440 prev = eina_list_prev(l);
441 // _set_line_show(prev->data, item);
445 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
446 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
447 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "flip_item", "");
448 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
458 * Remove an item from the dialogue group.
460 * @param obj dialoguegroup object
463 * @ingroup DialogueGroup
466 elm_dialoguegroup_remove(Dialogue_Item *item)
469 ELM_CHECK_WIDTYPE(item->obj, widtype) ;
470 Dialogue_Item *current_item;
471 Widget_Data *wd = elm_widget_data_get(item->obj);
474 if (!wd || !wd->items || !item) return ;
476 EINA_LIST_FOREACH(wd->items, l, current_item) {
477 if (current_item == item) {
478 if (current_item->content){
479 evas_object_del(current_item->content);
480 current_item->content = NULL;
482 if (current_item->bg_layout){
483 evas_object_del(current_item->bg_layout);
484 current_item->bg_layout = NULL;
486 elm_box_unpack(wd->box, current_item->bg_layout);
487 wd->items = eina_list_remove(wd->items, current_item);
493 if (wd->num == 0) return;
496 current_item = eina_list_data_get(wd->items);
497 _change_item_bg(current_item, "default");
501 current_item = eina_list_data_get(wd->items);
502 _change_item_bg(current_item, "top");
503 current_item = eina_list_data_get( eina_list_last(wd->items) );
504 _change_item_bg(current_item, "bottom");
507 _sizing_eval(item->obj);
511 * Remove all items from the dialogue group.
513 * @param obj dialoguegroup object
515 * @ingroup DialogueGroup
518 elm_dialoguegroup_remove_all(Evas_Object *obj)
520 ELM_CHECK_WIDTYPE(obj, widtype);
527 * Set the title text of the dialogue group.
529 * @param obj dialoguegroup object
530 * @param title title text, if NULL title space will be disappeared
532 * @ingroup DialogueGroup
535 elm_dialoguegroup_title_set(Evas_Object *obj, const char *title)
537 ELM_CHECK_WIDTYPE(obj, widtype);
538 Widget_Data *wd = elm_widget_data_get(obj);
541 eina_stringshare_replace(&wd->title, title);
544 elm_box_unpack(wd->box, wd->title_layout);
546 if (!wd->title_layout) {
547 wd->title_layout = elm_layout_add(wd->box);
548 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "title", elm_widget_style_get(obj));
549 evas_object_size_hint_weight_set(wd->title_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
550 evas_object_size_hint_align_set(wd->title_layout, EVAS_HINT_FILL, 0.0);
551 evas_object_show(wd->title_layout);
552 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
553 elm_box_pack_start(wd->box, wd->title_layout);
555 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
559 * Get the title text of the dialogue group
561 * @param obj The dialoguegroup object
562 * @return The text title string in UTF-8
564 * @ingroup DialogueGroup
567 elm_dialoguegroup_title_get(Evas_Object *obj)
569 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
570 Widget_Data *wd = elm_widget_data_get(obj);
571 if (!wd) return NULL;
576 * Set whether the press effect will be shown or not
578 * @param obj The dialoguegroup object
579 * @param item Dialogue_Item pointer
580 * @param press If set as 1, press effect will be shown
582 * @ingroup DialogueGroup
585 elm_dialoguegroup_press_effect_set(Dialogue_Item *item, Eina_Bool press)
588 ELM_CHECK_WIDTYPE(item->obj, widtype) ;
591 if ((press == EINA_TRUE) && (item->disabled == EINA_FALSE))
592 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
594 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
598 * Get the press effect state
600 * @param obj The dialoguegroup object
601 * @param item Dialogue_Item pointer
602 * @return 1 if press effect on, 0 if press effect off
604 * @ingroup DialogueGroup
607 elm_dialoguegroup_press_effect_get(Dialogue_Item *item)
609 if (!item) return EINA_FALSE;
610 ELM_CHECK_WIDTYPE(item->obj, widtype) EINA_FALSE;
616 * Get the conetent object from the specified dialogue item
618 * @param obj The dialoguegroup object
619 * @param item Dialogue_Item pointer
620 * @return content object
622 * @ingroup DialogueGroup
625 elm_dialoguegroup_item_content_get(Dialogue_Item *item)
627 if (!item) return NULL;
628 ELM_CHECK_WIDTYPE(item->obj, widtype) EINA_FALSE;
630 return item->content;
634 * Set the style of the item.
636 * @param item dialoguegroup item
637 * @param style sytle of the item
639 * @ingroup DialogueGroup
642 elm_dialoguegroup_item_style_set(Dialogue_Item *item, Elm_Dialoguegroup_Item_Style style)
645 ELM_CHECK_WIDTYPE(item->obj, widtype);
646 Widget_Data *wd = elm_widget_data_get(item->obj);
649 _change_item_bg(item, item->location);
655 * Get the style of the item.
657 * @param item dialoguegroup item
658 * @return dialoguegroup item style
660 * @ingroup DialogueGroup
663 EAPI Elm_Dialoguegroup_Item_Style
664 elm_dialoguegroup_item_style_get(Dialogue_Item *item)
666 if (!item) return ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
667 ELM_CHECK_WIDTYPE(item->obj, widtype) ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
668 Widget_Data *wd = elm_widget_data_get(item->obj);
670 if (!wd) return ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
676 * Set item state as disable or not.
678 * @param item dialoguegroup item.
679 * @param disabled if EINA_TRUE disabled, else abled.
681 * @ingroup DialogueGroup
684 elm_dialoguegroup_item_disabled_set(Dialogue_Item *item, Eina_Bool disabled)
687 ELM_CHECK_WIDTYPE(item->obj, widtype);
689 item->disabled = disabled;
691 if (disabled == EINA_TRUE)
693 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,disabled", "elm");
694 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
698 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,enabled", "elm");
699 if (item->press == EINA_TRUE)
700 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
705 * Get item state whether disabled or not.
707 * @param item dialoguegroup item.
708 * @return if EINA_TRUE, then disabled else abled.
710 * @ingroup DialogueGroup
714 elm_dialoguegroup_item_disabled_get(Dialogue_Item *item)
716 if (!item) return EINA_FALSE;
717 ELM_CHECK_WIDTYPE(item->obj, widtype) EINA_FALSE;
719 return item->disabled;
722 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/