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_object_part_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_object_part_content_set(item->bg_layout, "swallow", item->content);
226 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
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);
256 elm_widget_can_focus_set(obj, EINA_FALSE);
260 wd->box = elm_box_add(obj);
261 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
262 evas_object_show(wd->box);
263 elm_widget_resize_object_set(obj, wd->box);
270 * Append an item to the dialogue group.
272 * @param obj dialoguegroup object
274 * @param style sytle of the item
275 * @return Dialogue_Item pointer, just made by this function
277 * @ingroup DialogueGroup
280 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
282 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
283 Widget_Data *wd = elm_widget_data_get(obj);
284 Dialogue_Item *item = NULL, *new_item = NULL;
286 if (!wd || !subobj) return NULL;
289 new_item = _create_item(obj, subobj, style, "default");
292 item = eina_list_data_get(wd->items);
293 _change_item_bg(item, "top");
296 item = eina_list_data_get( eina_list_last(wd->items) );
297 _change_item_bg(item, "middle");
299 new_item = _create_item(obj, subobj, style, "bottom");
300 // _set_line_show(item, new_item);
302 elm_box_pack_end(wd->box, new_item->bg_layout);
303 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
304 edje_object_signal_emit(elm_layout_edje_get(new_item->bg_layout), "flip_item", "");
305 wd->items = eina_list_append(wd->items, new_item);
313 * Prepend an item to the dialogue group.
315 * @param obj dialoguegroup object
317 * @param style sytle of the item
318 * @return Dialogue_Item pointer, just made by this function
320 * @ingroup DialogueGroup
323 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
325 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
326 Widget_Data *wd = elm_widget_data_get(obj);
327 Dialogue_Item *item = NULL, *new_item = NULL;
329 if (!wd || !subobj) return NULL;
332 new_item = _create_item(obj, subobj, style, "default");
335 item = eina_list_data_get(wd->items);
336 _change_item_bg(item, "bottom");
339 item = eina_list_data_get(wd->items);
340 _change_item_bg(item, "middle");
342 new_item = _create_item(obj, subobj, style, "top");
343 // _set_line_show(new_item, item);
345 if (wd->title_layout)
346 elm_box_pack_after(wd->box, new_item->bg_layout, wd->title_layout);
348 elm_box_pack_start(wd->box, new_item->bg_layout);
349 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
350 edje_object_signal_emit(elm_layout_edje_get(new_item->bg_layout), "flip_item", "");
351 wd->items = eina_list_prepend(wd->items, new_item);
358 * Insert an item to the dialogue group just after the specified item.
360 * @param obj dialoguegroup object
362 * @param after specified item existing in the dialogue group
363 * @param style sytle of the item
364 * @return Dialogue_Item pointer, just made by this function
366 * @ingroup DialogueGroup
369 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *after, Elm_Dialoguegroup_Item_Style style)
371 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
372 Widget_Data *wd = elm_widget_data_get(obj);
373 Dialogue_Item *after_item = NULL, *item = NULL;
376 if (!wd || !subobj || !after || !wd->items) return NULL;
378 EINA_LIST_FOREACH(wd->items, l, after_item) {
379 if (after == after_item) {
380 if ( !strcmp(after_item->location, "default") ) {
381 _change_item_bg(after_item, "top");
382 item = _create_item(obj, subobj, style, "bottom");
384 else if ( !strcmp(after_item->location, "top") || !strcmp(after_item->location, "middle") )
385 item = _create_item(obj, subobj, style, "middle");
386 else if ( !strcmp(after_item->location, "bottom") ) {
387 _change_item_bg(after_item, "middle");
388 item = _create_item(obj, subobj, style, "bottom");
392 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
393 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
394 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "flip_item", "");
395 wd->items = eina_list_append_relative(wd->items, item, after_item);
396 // _set_line_show(after, item);
406 * Insert an item to the dialogue group just before the specified item.
408 * @param obj dialoguegroup object
410 * @param before specified item existing in the dialogue group
411 * @param style sytle of the item
412 * @return Dialogue_Item pointer, just made by this function
414 * @ingroup DialogueGroup
417 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *before, Elm_Dialoguegroup_Item_Style style)
419 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
420 Widget_Data *wd = elm_widget_data_get(obj);
421 Dialogue_Item *before_item = NULL, *item = NULL;
425 if (!wd || !subobj || !before || !wd->items) return NULL;
427 EINA_LIST_FOREACH(wd->items, l, before_item) {
428 if (before == before_item) {
429 if ( !strcmp(before_item->location, "default") ) {
430 _change_item_bg(before_item, "bottom");
431 item = _create_item(obj, subobj, style, "top");
434 else if ( !strcmp(before_item->location, "top") ) {
435 _change_item_bg(before_item, "middle");
436 item = _create_item(obj, subobj, style, "top");
439 else if ( !strcmp(before_item->location, "middle") || !strcmp(before_item->location, "bottom") ) {
440 item = _create_item(obj, subobj, style, "middle");
441 prev = eina_list_prev(l);
442 // _set_line_show(prev->data, item);
446 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
447 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
448 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "flip_item", "");
449 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
459 * Remove an item from the dialogue group.
461 * @param obj dialoguegroup object
464 * @ingroup DialogueGroup
467 elm_dialoguegroup_remove(Dialogue_Item *item)
470 ELM_CHECK_WIDTYPE(item->obj, widtype) ;
471 Dialogue_Item *current_item;
472 Widget_Data *wd = elm_widget_data_get(item->obj);
475 if (!wd || !wd->items || !item) return ;
477 EINA_LIST_FOREACH(wd->items, l, current_item) {
478 if (current_item == item) {
479 if (current_item->content){
480 evas_object_del(current_item->content);
481 current_item->content = NULL;
483 if (current_item->bg_layout){
484 evas_object_del(current_item->bg_layout);
485 current_item->bg_layout = NULL;
487 elm_box_unpack(wd->box, current_item->bg_layout);
488 wd->items = eina_list_remove(wd->items, current_item);
494 if (wd->num == 0) return;
497 current_item = eina_list_data_get(wd->items);
498 _change_item_bg(current_item, "default");
502 current_item = eina_list_data_get(wd->items);
503 _change_item_bg(current_item, "top");
504 current_item = eina_list_data_get( eina_list_last(wd->items) );
505 _change_item_bg(current_item, "bottom");
508 _sizing_eval(item->obj);
512 * Remove all items from the dialogue group.
514 * @param obj dialoguegroup object
516 * @ingroup DialogueGroup
519 elm_dialoguegroup_remove_all(Evas_Object *obj)
521 ELM_CHECK_WIDTYPE(obj, widtype);
528 * Set the title text of the dialogue group.
530 * @param obj dialoguegroup object
531 * @param title title text, if NULL title space will be disappeared
533 * @ingroup DialogueGroup
536 elm_dialoguegroup_title_set(Evas_Object *obj, const char *title)
538 ELM_CHECK_WIDTYPE(obj, widtype);
539 Widget_Data *wd = elm_widget_data_get(obj);
542 eina_stringshare_replace(&wd->title, title);
545 elm_box_unpack(wd->box, wd->title_layout);
547 if (!wd->title_layout) {
548 wd->title_layout = elm_layout_add(wd->box);
549 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "title", elm_widget_style_get(obj));
550 evas_object_size_hint_weight_set(wd->title_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
551 evas_object_size_hint_align_set(wd->title_layout, EVAS_HINT_FILL, 0.0);
552 evas_object_show(wd->title_layout);
553 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
554 elm_box_pack_start(wd->box, wd->title_layout);
556 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
560 * Get the title text of the dialogue group
562 * @param obj The dialoguegroup object
563 * @return The text title string in UTF-8
565 * @ingroup DialogueGroup
568 elm_dialoguegroup_title_get(Evas_Object *obj)
570 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
571 Widget_Data *wd = elm_widget_data_get(obj);
572 if (!wd) return NULL;
577 * Set whether the press effect will be shown or not
579 * @param obj The dialoguegroup object
580 * @param item Dialogue_Item pointer
581 * @param press If set as 1, press effect will be shown
583 * @ingroup DialogueGroup
586 elm_dialoguegroup_press_effect_set(Dialogue_Item *item, Eina_Bool press)
589 ELM_CHECK_WIDTYPE(item->obj, widtype) ;
592 if ((press == EINA_TRUE) && (item->disabled == EINA_FALSE))
593 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
595 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
599 * Get the press effect state
601 * @param obj The dialoguegroup object
602 * @param item Dialogue_Item pointer
603 * @return 1 if press effect on, 0 if press effect off
605 * @ingroup DialogueGroup
608 elm_dialoguegroup_press_effect_get(Dialogue_Item *item)
610 if (!item) return EINA_FALSE;
611 ELM_CHECK_WIDTYPE(item->obj, widtype) EINA_FALSE;
617 * Get the conetent object from the specified dialogue item
619 * @param obj The dialoguegroup object
620 * @param item Dialogue_Item pointer
621 * @return content object
623 * @ingroup DialogueGroup
626 elm_dialoguegroup_item_content_get(Dialogue_Item *item)
628 if (!item) return NULL;
629 ELM_CHECK_WIDTYPE(item->obj, widtype) EINA_FALSE;
631 return item->content;
635 * Set the style of the item.
637 * @param item dialoguegroup item
638 * @param style sytle of the item
640 * @ingroup DialogueGroup
643 elm_dialoguegroup_item_style_set(Dialogue_Item *item, Elm_Dialoguegroup_Item_Style style)
646 ELM_CHECK_WIDTYPE(item->obj, widtype);
647 Widget_Data *wd = elm_widget_data_get(item->obj);
650 _change_item_bg(item, item->location);
656 * Get the style of the item.
658 * @param item dialoguegroup item
659 * @return dialoguegroup item style
661 * @ingroup DialogueGroup
664 EAPI Elm_Dialoguegroup_Item_Style
665 elm_dialoguegroup_item_style_get(Dialogue_Item *item)
667 if (!item) return ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
668 ELM_CHECK_WIDTYPE(item->obj, widtype) ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
669 Widget_Data *wd = elm_widget_data_get(item->obj);
671 if (!wd) return ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
677 * Set item state as disable or not.
679 * @param item dialoguegroup item.
680 * @param disabled if EINA_TRUE disabled, else abled.
682 * @ingroup DialogueGroup
685 elm_dialoguegroup_item_disabled_set(Dialogue_Item *item, Eina_Bool disabled)
688 ELM_CHECK_WIDTYPE(item->obj, widtype);
690 item->disabled = disabled;
692 if (disabled == EINA_TRUE)
694 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,disabled", "elm");
695 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
699 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,enabled", "elm");
700 if (item->press == EINA_TRUE)
701 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
706 * Get item state whether disabled or not.
708 * @param item dialoguegroup item.
709 * @return if EINA_TRUE, then disabled else abled.
711 * @ingroup DialogueGroup
715 elm_dialoguegroup_item_disabled_get(Dialogue_Item *item)
717 if (!item) return EINA_FALSE;
718 ELM_CHECK_WIDTYPE(item->obj, widtype) EINA_FALSE;
720 return item->disabled;
723 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/