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;
30 Evas_Object *title_layout;
36 static const char*widtype = NULL;
38 static void _del_hook(Evas_Object *obj);
39 static void _theme_hook(Evas_Object *obj);
40 static void _sizing_eval(Evas_Object *obj);
42 static void _remove_all(Evas_Object *obj);
43 static void _set_item_theme(Dialogue_Item *item, const char *location);
44 static void _change_item_bg(Dialogue_Item *item, const char *location);
45 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style, const char *location);
49 _del_hook(Evas_Object *obj)
51 Widget_Data *wd = elm_widget_data_get(obj);
54 if (wd->title) eina_stringshare_del(wd->title);
59 evas_object_del(wd->box);
68 _theme_hook(Evas_Object *obj)
70 Widget_Data *wd = elm_widget_data_get(obj);
76 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "title", elm_widget_style_get(obj));
77 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", wd->title);
79 EINA_LIST_FOREACH(wd->items, l, item)
80 _change_item_bg( item, item->location );
85 _sizing_eval(Evas_Object *obj)
87 Widget_Data *wd = elm_widget_data_get(obj);
88 Evas_Coord minw, minh, maxw, maxh;
91 evas_object_size_hint_min_get(wd->box, &minw, &minh);
92 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
93 evas_object_size_hint_min_set(obj, minw, minh);
94 evas_object_size_hint_max_set(obj, maxw, maxh);
98 _remove_all(Evas_Object *obj)
100 Widget_Data *wd = elm_widget_data_get(obj);
108 EINA_LIST_FREE(wd->items, item) {
110 evas_object_del(item->content);
111 item->content = NULL;
113 if (item->bg_layout){
114 evas_object_del(item->bg_layout);
115 item->bg_layout = NULL;
118 eina_stringshare_del(item->location);
125 _set_item_theme(Dialogue_Item *item, const char *location)
130 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT)
131 snprintf(buf, sizeof(buf), "bg_%s", location);
132 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD)
133 snprintf(buf, sizeof(buf), "editfield_%s", location);
134 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD_WITH_TITLE)
135 snprintf(buf, sizeof(buf), "editfield_with_title_%s", location);
136 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDIT_TITLE)
137 snprintf(buf, sizeof(buf), "edit_title_%s", location);
138 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_HIDDEN)
139 snprintf(buf, sizeof(buf), "hidden_%s", location);
140 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DATAVIEW)
141 snprintf(buf, sizeof(buf), "dataview_%s", location);
142 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_NO_BG)
143 snprintf(buf, sizeof(buf), "no_bg_%s", location);
144 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
145 snprintf(buf, sizeof(buf), "sub_%s", location);
146 elm_layout_theme_set(item->bg_layout, "dialoguegroup", buf, elm_widget_style_get(item->parent));
150 static void _set_line_show(Dialogue_Item *item, Dialogue_Item *after)
152 if(!item || !after) return;
154 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT) {
155 if (after->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT) {
156 item->line_show = EINA_TRUE;
157 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,show", "elm");
159 else if (after->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD) {
160 item->line_show = EINA_FALSE;
161 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");
164 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD)
165 item->line_show = EINA_TRUE;
170 _change_item_bg(Dialogue_Item *item, const char *location)
174 eina_stringshare_replace(&item->location, location);
175 _set_item_theme(item, location);
176 elm_layout_content_set(item->bg_layout, "swallow", item->content);
177 if ((item->press == EINA_TRUE) && (item->disabled == EINA_FALSE))
178 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
180 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
181 if (item->disabled == EINA_TRUE)
182 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,disabled", "elm");
184 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,enabled", "elm");
186 /* if(item->line_show == EINA_FALSE)
187 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");*/
191 static Dialogue_Item*
192 _create_item(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style, const char *location)
194 Widget_Data *wd = elm_widget_data_get(obj);
197 if (!wd) return NULL;
199 item = ELM_NEW(Dialogue_Item);
201 item->content = subobj;
202 item->press = EINA_TRUE;
203 item->disabled = EINA_FALSE;
205 // item->line_show = EINA_TRUE;
206 eina_stringshare_replace(&item->location, location);
208 item->bg_layout = elm_layout_add(wd->box);
209 _set_item_theme(item, location);
210 evas_object_size_hint_weight_set(item->bg_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
211 evas_object_size_hint_align_set(item->bg_layout, EVAS_HINT_FILL, 0.0);
212 evas_object_show(item->bg_layout);
214 elm_layout_content_set(item->bg_layout, "swallow", item->content);
220 _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
226 * Add a new dialoguegroup to the parent.
228 * @param parent The parent object
229 * @return The new object or NULL if it cannot be created
231 * @ingroup DialogueGroup
234 elm_dialoguegroup_add(Evas_Object *parent)
236 Evas_Object *obj = NULL;
237 Widget_Data *wd = NULL;
240 e = evas_object_evas_get(parent);
241 if (e == NULL) return NULL;
242 wd = ELM_NEW(Widget_Data);
243 obj = elm_widget_add(e);
244 ELM_SET_WIDTYPE(widtype, "dialoguegroup");
245 elm_widget_type_set(obj, "dialoguegroup");
246 elm_widget_sub_object_add(parent, obj);
247 elm_widget_data_set(obj, wd);
248 elm_widget_del_hook_set(obj, _del_hook);
249 elm_widget_theme_hook_set(obj, _theme_hook);
254 wd->box = elm_box_add(obj);
255 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
256 evas_object_show(wd->box);
257 elm_widget_resize_object_set(obj, wd->box);
264 * Append an item to the dialogue group.
266 * @param obj dialoguegroup object
268 * @param style sytle of the item
269 * @return Dialogue_Item pointer, just made by this function
271 * @ingroup DialogueGroup
274 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
276 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
277 Widget_Data *wd = elm_widget_data_get(obj);
278 Dialogue_Item *item = NULL, *new_item = NULL;
280 if (!wd || !subobj) return NULL;
283 new_item = _create_item(obj, subobj, style, "default");
286 item = eina_list_data_get(wd->items);
287 _change_item_bg(item, "top");
290 item = eina_list_data_get( eina_list_last(wd->items) );
291 _change_item_bg(item, "middle");
293 new_item = _create_item(obj, subobj, style, "bottom");
294 // _set_line_show(item, new_item);
296 elm_box_pack_end(wd->box, new_item->bg_layout);
297 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
298 edje_object_signal_emit(elm_layout_edje_get(new_item->bg_layout), "flip_item", "");
299 wd->items = eina_list_append(wd->items, new_item);
307 * Prepend an item to the dialogue group.
309 * @param obj dialoguegroup object
311 * @param style sytle of the item
312 * @return Dialogue_Item pointer, just made by this function
314 * @ingroup DialogueGroup
317 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
319 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
320 Widget_Data *wd = elm_widget_data_get(obj);
321 Dialogue_Item *item = NULL, *new_item = NULL;
323 if (!wd || !subobj) return NULL;
326 new_item = _create_item(obj, subobj, style, "default");
329 item = eina_list_data_get(wd->items);
330 _change_item_bg(item, "bottom");
333 item = eina_list_data_get(wd->items);
334 _change_item_bg(item, "middle");
336 new_item = _create_item(obj, subobj, style, "top");
337 // _set_line_show(new_item, item);
339 if (wd->title_layout)
340 elm_box_pack_after(wd->box, new_item->bg_layout, wd->title_layout);
342 elm_box_pack_start(wd->box, new_item->bg_layout);
343 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
344 edje_object_signal_emit(elm_layout_edje_get(new_item->bg_layout), "flip_item", "");
345 wd->items = eina_list_prepend(wd->items, new_item);
352 * Insert an item to the dialogue group just after the specified item.
354 * @param obj dialoguegroup object
356 * @param after specified item existing in the dialogue group
357 * @param style sytle of the item
358 * @return Dialogue_Item pointer, just made by this function
360 * @ingroup DialogueGroup
363 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *after, Elm_Dialoguegroup_Item_Style style)
365 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
366 Widget_Data *wd = elm_widget_data_get(obj);
367 Dialogue_Item *after_item = NULL, *item = NULL;
370 if (!wd || !subobj || !after || !wd->items) return NULL;
372 EINA_LIST_FOREACH(wd->items, l, after_item) {
373 if (after == after_item) {
374 if ( !strcmp(after_item->location, "default") ) {
375 _change_item_bg(after_item, "top");
376 item = _create_item(obj, subobj, style, "bottom");
378 else if ( !strcmp(after_item->location, "top") || !strcmp(after_item->location, "middle") )
379 item = _create_item(obj, subobj, style, "middle");
380 else if ( !strcmp(after_item->location, "bottom") ) {
381 _change_item_bg(after_item, "middle");
382 item = _create_item(obj, subobj, style, "bottom");
384 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
385 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
386 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "flip_item", "");
387 wd->items = eina_list_append_relative(wd->items, item, after_item);
388 // _set_line_show(after, item);
398 * Insert an item to the dialogue group just before the specified item.
400 * @param obj dialoguegroup object
402 * @param before specified item existing in the dialogue group
403 * @param style sytle of the item
404 * @return Dialogue_Item pointer, just made by this function
406 * @ingroup DialogueGroup
409 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *before, Elm_Dialoguegroup_Item_Style style)
411 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
412 Widget_Data *wd = elm_widget_data_get(obj);
413 Dialogue_Item *before_item = NULL, *item = NULL;
417 if (!wd || !subobj || !before || !wd->items) return NULL;
419 EINA_LIST_FOREACH(wd->items, l, before_item) {
420 if (before == before_item) {
421 if ( !strcmp(before_item->location, "default") ) {
422 _change_item_bg(before_item, "bottom");
423 item = _create_item(obj, subobj, style, "top");
426 else if ( !strcmp(before_item->location, "top") ) {
427 _change_item_bg(before_item, "middle");
428 item = _create_item(obj, subobj, style, "top");
431 else if ( !strcmp(before_item->location, "middle") || !strcmp(before_item->location, "bottom") ) {
432 item = _create_item(obj, subobj, style, "middle");
433 prev = eina_list_prev(l);
434 // _set_line_show(prev->data, item);
436 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
437 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
438 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "flip_item", "");
439 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
449 * Remove an item from the dialogue group.
451 * @param obj dialoguegroup object
454 * @ingroup DialogueGroup
457 elm_dialoguegroup_remove(Dialogue_Item *item)
460 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
461 Dialogue_Item *current_item;
462 Widget_Data *wd = elm_widget_data_get(item->parent);
465 if (!wd || !wd->items || !item) return ;
467 EINA_LIST_FOREACH(wd->items, l, current_item) {
468 if (current_item == item) {
469 if (current_item->content){
470 evas_object_del(current_item->content);
471 current_item->content = NULL;
473 if (current_item->bg_layout){
474 evas_object_del(current_item->bg_layout);
475 current_item->bg_layout = NULL;
477 elm_box_unpack(wd->box, current_item->bg_layout);
478 wd->items = eina_list_remove(wd->items, current_item);
484 if (wd->num == 0) return;
487 current_item = eina_list_data_get(wd->items);
488 _change_item_bg(current_item, "default");
492 current_item = eina_list_data_get(wd->items);
493 _change_item_bg(current_item, "top");
494 current_item = eina_list_data_get( eina_list_last(wd->items) );
495 _change_item_bg(current_item, "bottom");
498 _sizing_eval(item->parent);
502 * Remove all items from the dialogue group.
504 * @param obj dialoguegroup object
506 * @ingroup DialogueGroup
509 elm_dialoguegroup_remove_all(Evas_Object *obj)
511 ELM_CHECK_WIDTYPE(obj, widtype);
518 * Set the title text of the dialogue group.
520 * @param obj dialoguegroup object
521 * @param title title text, if NULL title space will be disappeared
523 * @ingroup DialogueGroup
526 elm_dialoguegroup_title_set(Evas_Object *obj, const char *title)
528 ELM_CHECK_WIDTYPE(obj, widtype);
529 Widget_Data *wd = elm_widget_data_get(obj);
532 eina_stringshare_replace(&wd->title, title);
535 elm_box_unpack(wd->box, wd->title_layout);
537 if (!wd->title_layout) {
538 wd->title_layout = elm_layout_add(wd->box);
539 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "title", elm_widget_style_get(obj));
540 evas_object_size_hint_weight_set(wd->title_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
541 evas_object_size_hint_align_set(wd->title_layout, EVAS_HINT_FILL, 0.0);
542 evas_object_show(wd->title_layout);
543 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
544 elm_box_pack_start(wd->box, wd->title_layout);
546 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
550 * Get the title text of the dialogue group
552 * @param obj The dialoguegroup object
553 * @return The text title string in UTF-8
555 * @ingroup DialogueGroup
558 elm_dialoguegroup_title_get(Evas_Object *obj)
560 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
561 Widget_Data *wd = elm_widget_data_get(obj);
562 if (!wd) return NULL;
567 * Set whether the press effect will be shown or not
569 * @param obj The dialoguegroup object
570 * @param item Dialogue_Item pointer
571 * @param press If set as 1, press effect will be shown
573 * @ingroup DialogueGroup
576 elm_dialoguegroup_press_effect_set(Dialogue_Item *item, Eina_Bool press)
579 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
582 if ((press == EINA_TRUE) && (item->disabled == EINA_FALSE))
583 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
585 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
589 * Get the press effect state
591 * @param obj The dialoguegroup object
592 * @param item Dialogue_Item pointer
593 * @return 1 if press effect on, 0 if press effect off
595 * @ingroup DialogueGroup
598 elm_dialoguegroup_press_effect_get(Dialogue_Item *item)
600 if (!item) return EINA_FALSE;
601 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
607 * Get the conetent object from the specified dialogue item
609 * @param obj The dialoguegroup object
610 * @param item Dialogue_Item pointer
611 * @return content object
613 * @ingroup DialogueGroup
616 elm_dialoguegroup_item_content_get(Dialogue_Item *item)
618 if (!item) return NULL;
619 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
621 return item->content;
625 * Set the style of the item.
627 * @param item dialoguegroup item
628 * @param style sytle of the item
630 * @ingroup DialogueGroup
633 elm_dialoguegroup_item_style_set(Dialogue_Item *item, Elm_Dialoguegroup_Item_Style style)
636 ELM_CHECK_WIDTYPE(item->parent, widtype);
637 Widget_Data *wd = elm_widget_data_get(item->parent);
640 _change_item_bg(item, item->location);
646 * Get the style of the item.
648 * @param item dialoguegroup item
649 * @return dialoguegroup item style
651 * @ingroup DialogueGroup
654 EAPI Elm_Dialoguegroup_Item_Style
655 elm_dialoguegroup_item_style_get(Dialogue_Item *item)
657 if (!item) return ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
658 ELM_CHECK_WIDTYPE(item->parent, widtype) ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
659 Widget_Data *wd = elm_widget_data_get(item->parent);
661 if (!wd) return ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
667 * Set item state as disable or not.
669 * @param item dialoguegroup item.
670 * @param disabled if EINA_TRUE disabled, else abled.
672 * @ingroup DialogueGroup
675 elm_dialoguegroup_item_disabled_set(Dialogue_Item *item, Eina_Bool disabled)
678 ELM_CHECK_WIDTYPE(item->parent, widtype);
680 item->disabled = disabled;
682 if (disabled == EINA_TRUE)
684 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,disabled", "elm");
685 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
689 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,enabled", "elm");
690 if (item->press == EINA_TRUE)
691 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
696 * Get item state whether disabled or not.
698 * @param item dialoguegroup item.
699 * @return if EINA_TRUE, then disabled else abled.
701 * @ingroup DialogueGroup
705 elm_dialoguegroup_item_disabled_get(Dialogue_Item *item)
707 if (!item) return EINA_FALSE;
708 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
710 return item->disabled;
713 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/