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 elm_layout_theme_set(item->bg_layout, "dialoguegroup", buf, elm_widget_style_get(item->obj));
149 static void _set_line_show(Dialogue_Item *item, Dialogue_Item *after)
151 if(!item || !after) return;
153 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT) {
154 if (after->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT) {
155 item->line_show = EINA_TRUE;
156 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,show", "elm");
158 else if (after->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD) {
159 item->line_show = EINA_FALSE;
160 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");
163 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD)
164 item->line_show = EINA_TRUE;
169 _change_item_bg(Dialogue_Item *item, const char *location)
173 eina_stringshare_replace(&item->location, location);
174 _set_item_theme(item, location);
175 elm_layout_content_set(item->bg_layout, "swallow", item->content);
176 if ((item->press == EINA_TRUE) && (item->disabled == EINA_FALSE))
177 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
179 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
180 if (item->disabled == EINA_TRUE)
181 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,disabled", "elm");
183 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,enabled", "elm");
185 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
186 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "flip_item", "");
188 /* if(item->line_show == EINA_FALSE)
189 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");*/
193 static Dialogue_Item*
194 _create_item(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style, const char *location)
196 Widget_Data *wd = elm_widget_data_get(obj);
199 if (!wd) return NULL;
201 item = ELM_NEW(Dialogue_Item);
203 item->content = subobj;
204 item->press = EINA_TRUE;
205 item->disabled = EINA_FALSE;
207 // item->line_show = EINA_TRUE;
208 eina_stringshare_replace(&item->location, location);
210 item->bg_layout = elm_layout_add(wd->box);
211 _set_item_theme(item, location);
212 evas_object_size_hint_weight_set(item->bg_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
213 evas_object_size_hint_align_set(item->bg_layout, EVAS_HINT_FILL, 0.0);
214 evas_object_show(item->bg_layout);
216 elm_layout_content_set(item->bg_layout, "swallow", item->content);
222 _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
228 * Add a new dialoguegroup to the parent.
230 * @param parent The parent object
231 * @return The new object or NULL if it cannot be created
233 * @ingroup DialogueGroup
236 elm_dialoguegroup_add(Evas_Object *parent)
238 Evas_Object *obj = NULL;
239 Widget_Data *wd = NULL;
242 e = evas_object_evas_get(parent);
243 if (e == NULL) return NULL;
244 wd = ELM_NEW(Widget_Data);
245 obj = elm_widget_add(e);
246 ELM_SET_WIDTYPE(widtype, "dialoguegroup");
247 elm_widget_type_set(obj, "dialoguegroup");
248 elm_widget_sub_object_add(parent, obj);
249 elm_widget_data_set(obj, wd);
250 elm_widget_del_hook_set(obj, _del_hook);
251 elm_widget_theme_hook_set(obj, _theme_hook);
255 wd->box = elm_box_add(obj);
256 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
257 evas_object_show(wd->box);
258 elm_widget_resize_object_set(obj, wd->box);
265 * Append an item to the dialogue group.
267 * @param obj dialoguegroup object
269 * @param style sytle of the item
270 * @return Dialogue_Item pointer, just made by this function
272 * @ingroup DialogueGroup
275 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
277 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
278 Widget_Data *wd = elm_widget_data_get(obj);
279 Dialogue_Item *item = NULL, *new_item = NULL;
281 if (!wd || !subobj) return NULL;
284 new_item = _create_item(obj, subobj, style, "default");
287 item = eina_list_data_get(wd->items);
288 _change_item_bg(item, "top");
291 item = eina_list_data_get( eina_list_last(wd->items) );
292 _change_item_bg(item, "middle");
294 new_item = _create_item(obj, subobj, style, "bottom");
295 // _set_line_show(item, new_item);
297 elm_box_pack_end(wd->box, new_item->bg_layout);
298 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
299 edje_object_signal_emit(elm_layout_edje_get(new_item->bg_layout), "flip_item", "");
300 wd->items = eina_list_append(wd->items, new_item);
308 * Prepend an item to the dialogue group.
310 * @param obj dialoguegroup object
312 * @param style sytle of the item
313 * @return Dialogue_Item pointer, just made by this function
315 * @ingroup DialogueGroup
318 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
320 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
321 Widget_Data *wd = elm_widget_data_get(obj);
322 Dialogue_Item *item = NULL, *new_item = NULL;
324 if (!wd || !subobj) return NULL;
327 new_item = _create_item(obj, subobj, style, "default");
330 item = eina_list_data_get(wd->items);
331 _change_item_bg(item, "bottom");
334 item = eina_list_data_get(wd->items);
335 _change_item_bg(item, "middle");
337 new_item = _create_item(obj, subobj, style, "top");
338 // _set_line_show(new_item, item);
340 if (wd->title_layout)
341 elm_box_pack_after(wd->box, new_item->bg_layout, wd->title_layout);
343 elm_box_pack_start(wd->box, new_item->bg_layout);
344 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
345 edje_object_signal_emit(elm_layout_edje_get(new_item->bg_layout), "flip_item", "");
346 wd->items = eina_list_prepend(wd->items, new_item);
353 * Insert an item to the dialogue group just after the specified item.
355 * @param obj dialoguegroup object
357 * @param after specified item existing in the dialogue group
358 * @param style sytle of the item
359 * @return Dialogue_Item pointer, just made by this function
361 * @ingroup DialogueGroup
364 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *after, Elm_Dialoguegroup_Item_Style style)
366 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
367 Widget_Data *wd = elm_widget_data_get(obj);
368 Dialogue_Item *after_item = NULL, *item = NULL;
371 if (!wd || !subobj || !after || !wd->items) return NULL;
373 EINA_LIST_FOREACH(wd->items, l, after_item) {
374 if (after == after_item) {
375 if ( !strcmp(after_item->location, "default") ) {
376 _change_item_bg(after_item, "top");
377 item = _create_item(obj, subobj, style, "bottom");
379 else if ( !strcmp(after_item->location, "top") || !strcmp(after_item->location, "middle") )
380 item = _create_item(obj, subobj, style, "middle");
381 else if ( !strcmp(after_item->location, "bottom") ) {
382 _change_item_bg(after_item, "middle");
383 item = _create_item(obj, subobj, style, "bottom");
385 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
386 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
387 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "flip_item", "");
388 wd->items = eina_list_append_relative(wd->items, item, after_item);
389 // _set_line_show(after, item);
399 * Insert an item to the dialogue group just before the specified item.
401 * @param obj dialoguegroup object
403 * @param before specified item existing in the dialogue group
404 * @param style sytle of the item
405 * @return Dialogue_Item pointer, just made by this function
407 * @ingroup DialogueGroup
410 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *before, Elm_Dialoguegroup_Item_Style style)
412 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
413 Widget_Data *wd = elm_widget_data_get(obj);
414 Dialogue_Item *before_item = NULL, *item = NULL;
418 if (!wd || !subobj || !before || !wd->items) return NULL;
420 EINA_LIST_FOREACH(wd->items, l, before_item) {
421 if (before == before_item) {
422 if ( !strcmp(before_item->location, "default") ) {
423 _change_item_bg(before_item, "bottom");
424 item = _create_item(obj, subobj, style, "top");
427 else if ( !strcmp(before_item->location, "top") ) {
428 _change_item_bg(before_item, "middle");
429 item = _create_item(obj, subobj, style, "top");
432 else if ( !strcmp(before_item->location, "middle") || !strcmp(before_item->location, "bottom") ) {
433 item = _create_item(obj, subobj, style, "middle");
434 prev = eina_list_prev(l);
435 // _set_line_show(prev->data, item);
437 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
438 if (style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
439 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "flip_item", "");
440 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
450 * Remove an item from the dialogue group.
452 * @param obj dialoguegroup object
455 * @ingroup DialogueGroup
458 elm_dialoguegroup_remove(Dialogue_Item *item)
461 ELM_CHECK_WIDTYPE(item->obj, widtype) ;
462 Dialogue_Item *current_item;
463 Widget_Data *wd = elm_widget_data_get(item->obj);
466 if (!wd || !wd->items || !item) return ;
468 EINA_LIST_FOREACH(wd->items, l, current_item) {
469 if (current_item == item) {
470 if (current_item->content){
471 evas_object_del(current_item->content);
472 current_item->content = NULL;
474 if (current_item->bg_layout){
475 evas_object_del(current_item->bg_layout);
476 current_item->bg_layout = NULL;
478 elm_box_unpack(wd->box, current_item->bg_layout);
479 wd->items = eina_list_remove(wd->items, current_item);
485 if (wd->num == 0) return;
488 current_item = eina_list_data_get(wd->items);
489 _change_item_bg(current_item, "default");
493 current_item = eina_list_data_get(wd->items);
494 _change_item_bg(current_item, "top");
495 current_item = eina_list_data_get( eina_list_last(wd->items) );
496 _change_item_bg(current_item, "bottom");
499 _sizing_eval(item->obj);
503 * Remove all items from the dialogue group.
505 * @param obj dialoguegroup object
507 * @ingroup DialogueGroup
510 elm_dialoguegroup_remove_all(Evas_Object *obj)
512 ELM_CHECK_WIDTYPE(obj, widtype);
519 * Set the title text of the dialogue group.
521 * @param obj dialoguegroup object
522 * @param title title text, if NULL title space will be disappeared
524 * @ingroup DialogueGroup
527 elm_dialoguegroup_title_set(Evas_Object *obj, const char *title)
529 ELM_CHECK_WIDTYPE(obj, widtype);
530 Widget_Data *wd = elm_widget_data_get(obj);
533 eina_stringshare_replace(&wd->title, title);
536 elm_box_unpack(wd->box, wd->title_layout);
538 if (!wd->title_layout) {
539 wd->title_layout = elm_layout_add(wd->box);
540 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "title", elm_widget_style_get(obj));
541 evas_object_size_hint_weight_set(wd->title_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
542 evas_object_size_hint_align_set(wd->title_layout, EVAS_HINT_FILL, 0.0);
543 evas_object_show(wd->title_layout);
544 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
545 elm_box_pack_start(wd->box, wd->title_layout);
547 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
551 * Get the title text of the dialogue group
553 * @param obj The dialoguegroup object
554 * @return The text title string in UTF-8
556 * @ingroup DialogueGroup
559 elm_dialoguegroup_title_get(Evas_Object *obj)
561 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
562 Widget_Data *wd = elm_widget_data_get(obj);
563 if (!wd) return NULL;
568 * Set whether the press effect will be shown or not
570 * @param obj The dialoguegroup object
571 * @param item Dialogue_Item pointer
572 * @param press If set as 1, press effect will be shown
574 * @ingroup DialogueGroup
577 elm_dialoguegroup_press_effect_set(Dialogue_Item *item, Eina_Bool press)
580 ELM_CHECK_WIDTYPE(item->obj, widtype) ;
583 if ((press == EINA_TRUE) && (item->disabled == EINA_FALSE))
584 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
586 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
590 * Get the press effect state
592 * @param obj The dialoguegroup object
593 * @param item Dialogue_Item pointer
594 * @return 1 if press effect on, 0 if press effect off
596 * @ingroup DialogueGroup
599 elm_dialoguegroup_press_effect_get(Dialogue_Item *item)
601 if (!item) return EINA_FALSE;
602 ELM_CHECK_WIDTYPE(item->obj, widtype) EINA_FALSE;
608 * Get the conetent object from the specified dialogue item
610 * @param obj The dialoguegroup object
611 * @param item Dialogue_Item pointer
612 * @return content object
614 * @ingroup DialogueGroup
617 elm_dialoguegroup_item_content_get(Dialogue_Item *item)
619 if (!item) return NULL;
620 ELM_CHECK_WIDTYPE(item->obj, widtype) EINA_FALSE;
622 return item->content;
626 * Set the style of the item.
628 * @param item dialoguegroup item
629 * @param style sytle of the item
631 * @ingroup DialogueGroup
634 elm_dialoguegroup_item_style_set(Dialogue_Item *item, Elm_Dialoguegroup_Item_Style style)
637 ELM_CHECK_WIDTYPE(item->obj, widtype);
638 Widget_Data *wd = elm_widget_data_get(item->obj);
641 _change_item_bg(item, item->location);
647 * Get the style of the item.
649 * @param item dialoguegroup item
650 * @return dialoguegroup item style
652 * @ingroup DialogueGroup
655 EAPI Elm_Dialoguegroup_Item_Style
656 elm_dialoguegroup_item_style_get(Dialogue_Item *item)
658 if (!item) return ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
659 ELM_CHECK_WIDTYPE(item->obj, widtype) ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
660 Widget_Data *wd = elm_widget_data_get(item->obj);
662 if (!wd) return ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
668 * Set item state as disable or not.
670 * @param item dialoguegroup item.
671 * @param disabled if EINA_TRUE disabled, else abled.
673 * @ingroup DialogueGroup
676 elm_dialoguegroup_item_disabled_set(Dialogue_Item *item, Eina_Bool disabled)
679 ELM_CHECK_WIDTYPE(item->obj, widtype);
681 item->disabled = disabled;
683 if (disabled == EINA_TRUE)
685 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,disabled", "elm");
686 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
690 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,enabled", "elm");
691 if (item->press == EINA_TRUE)
692 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
697 * Get item state whether disabled or not.
699 * @param item dialoguegroup item.
700 * @return if EINA_TRUE, then disabled else abled.
702 * @ingroup DialogueGroup
706 elm_dialoguegroup_item_disabled_get(Dialogue_Item *item)
708 if (!item) return EINA_FALSE;
709 ELM_CHECK_WIDTYPE(item->obj, widtype) EINA_FALSE;
711 return item->disabled;
714 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/