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);
41 static void _disable_hook(Evas_Object *obj);
43 static void _remove_all(Evas_Object *obj);
44 static void _set_item_theme(Dialogue_Item *item, const char *location);
45 static void _change_item_bg(Dialogue_Item *item, const char *location);
46 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style, const char *location);
50 _del_hook(Evas_Object *obj)
52 Widget_Data *wd = elm_widget_data_get(obj);
55 if (wd->title) eina_stringshare_del(wd->title);
60 evas_object_del(wd->box);
69 _theme_hook(Evas_Object *obj)
71 Widget_Data *wd = elm_widget_data_get(obj);
77 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "title", elm_widget_style_get(obj));
78 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", wd->title);
80 EINA_LIST_FOREACH(wd->items, l, item)
81 _change_item_bg( item, item->location );
86 _disable_hook(Evas_Object *obj)
92 _sizing_eval(Evas_Object *obj)
94 Widget_Data *wd = elm_widget_data_get(obj);
95 Evas_Coord minw, minh, maxw, maxh;
98 evas_object_size_hint_min_get(wd->box, &minw, &minh);
99 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
100 evas_object_size_hint_min_set(obj, minw, minh);
101 evas_object_size_hint_max_set(obj, maxw, maxh);
104 static void _remove_all(Evas_Object *obj)
106 Widget_Data *wd = elm_widget_data_get(obj);
114 EINA_LIST_FREE(wd->items, item) {
116 evas_object_del(item->content);
117 item->content = NULL;
119 if (item->bg_layout){
120 evas_object_del(item->bg_layout);
121 item->bg_layout = NULL;
124 eina_stringshare_del(item->location);
130 static void _set_item_theme(Dialogue_Item *item, const char *location)
135 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT)
136 snprintf(buf, sizeof(buf), "bg_%s", location);
137 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD)
138 snprintf(buf, sizeof(buf), "editfield_%s", location);
139 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD_WITH_TITLE)
140 snprintf(buf, sizeof(buf), "editfield_with_title_%s", location);
141 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDIT_TITLE)
142 snprintf(buf, sizeof(buf), "edit_title_%s", location);
143 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_HIDDEN)
144 snprintf(buf, sizeof(buf), "hidden_%s", location);
145 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DATAVIEW)
146 snprintf(buf, sizeof(buf), "dataview_%s", location);
147 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_NO_BG)
148 snprintf(buf, sizeof(buf), "no_bg_%s", location);
149 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_SUB)
150 snprintf(buf, sizeof(buf), "sub_%s", location);
151 elm_layout_theme_set(item->bg_layout, "dialoguegroup", buf, elm_widget_style_get(item->parent));
155 static void _set_line_show(Dialogue_Item *item, Dialogue_Item *after)
157 if(!item || !after) return;
159 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT) {
160 if (after->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT) {
161 item->line_show = EINA_TRUE;
162 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,show", "elm");
164 else if (after->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD) {
165 item->line_show = EINA_FALSE;
166 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");
169 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD)
170 item->line_show = EINA_TRUE;
174 static void _change_item_bg(Dialogue_Item *item, const char *location)
178 eina_stringshare_replace(&item->location, location);
179 _set_item_theme(item, location);
180 elm_layout_content_set(item->bg_layout, "swallow", item->content);
181 if((item->press == EINA_TRUE) && (item->disabled == EINA_FALSE))
182 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
184 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
185 if(item->disabled == EINA_TRUE)
186 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,disabled", "elm");
188 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,enabled", "elm");
190 /* if(item->line_show == EINA_FALSE)
191 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");*/
195 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style, const char *location)
197 Widget_Data *wd = elm_widget_data_get(obj);
200 if (!wd) return NULL;
202 item = ELM_NEW(Dialogue_Item);
204 item->content = subobj;
205 item->press = EINA_TRUE;
206 item->disabled = EINA_FALSE;
208 // item->line_show = EINA_TRUE;
209 eina_stringshare_replace(&item->location, location);
211 item->bg_layout = elm_layout_add(wd->box);
212 _set_item_theme(item, location);
213 evas_object_size_hint_weight_set(item->bg_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
214 evas_object_size_hint_align_set(item->bg_layout, EVAS_HINT_FILL, 0.0);
215 evas_object_show(item->bg_layout);
217 elm_layout_content_set(item->bg_layout, "swallow", item->content);
222 static void _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
235 EAPI Evas_Object *elm_dialoguegroup_add(Evas_Object *parent)
237 Evas_Object *obj = NULL;
238 Widget_Data *wd = NULL;
241 e = evas_object_evas_get(parent);
242 if (e == NULL) return NULL;
243 wd = ELM_NEW(Widget_Data);
244 obj = elm_widget_add(e);
245 ELM_SET_WIDTYPE(widtype, "dialoguegroup");
246 elm_widget_type_set(obj, "dialoguegroup");
247 elm_widget_sub_object_add(parent, obj);
248 elm_widget_data_set(obj, wd);
249 elm_widget_del_hook_set(obj, _del_hook);
250 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 wd->items = eina_list_append(wd->items, new_item);
306 * Prepend an item to the dialogue group.
308 * @param obj dialoguegroup object
310 * @param style sytle of the item
311 * @return Dialogue_Item pointer, just made by this function
313 * @ingroup DialogueGroup
316 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
318 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
319 Widget_Data *wd = elm_widget_data_get(obj);
320 Dialogue_Item *item = NULL, *new_item = NULL;
322 if (!wd || !subobj) return NULL;
325 new_item = _create_item(obj, subobj, style, "default");
328 item = eina_list_data_get(wd->items);
329 _change_item_bg(item, "bottom");
332 item = eina_list_data_get(wd->items);
333 _change_item_bg(item, "middle");
335 new_item = _create_item(obj, subobj, style, "top");
336 // _set_line_show(new_item, item);
339 elm_box_pack_after(wd->box, new_item->bg_layout, wd->title_layout);
341 elm_box_pack_start(wd->box, new_item->bg_layout);
342 wd->items = eina_list_prepend(wd->items, new_item);
349 * Insert an item to the dialogue group just after the specified item.
351 * @param obj dialoguegroup object
353 * @param after specified item existing in the dialogue group
354 * @param style sytle of the item
355 * @return Dialogue_Item pointer, just made by this function
357 * @ingroup DialogueGroup
360 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *after, Elm_Dialoguegroup_Item_Style style)
362 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
363 Widget_Data *wd = elm_widget_data_get(obj);
364 Dialogue_Item *after_item = NULL, *item = NULL;
367 if (!wd || !subobj || !after || !wd->items) return NULL;
369 EINA_LIST_FOREACH(wd->items, l, after_item) {
370 if(after == after_item) {
371 if( !strcmp(after_item->location, "default") ) {
372 _change_item_bg(after_item, "top");
373 item = _create_item(obj, subobj, style, "bottom");
375 else if( !strcmp(after_item->location, "top") || !strcmp(after_item->location, "middle") )
376 item = _create_item(obj, subobj, style, "middle");
377 else if( !strcmp(after_item->location, "bottom") ) {
378 _change_item_bg(after_item, "middle");
379 item = _create_item(obj, subobj, style, "bottom");
382 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
383 wd->items = eina_list_append_relative(wd->items, item, after_item);
384 // _set_line_show(after, item);
394 * Insert an item to the dialogue group just before the specified item.
396 * @param obj dialoguegroup object
398 * @param before specified item existing in the dialogue group
399 * @param style sytle of the item
400 * @return Dialogue_Item pointer, just made by this function
402 * @ingroup DialogueGroup
405 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *before, Elm_Dialoguegroup_Item_Style style)
407 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
408 Widget_Data *wd = elm_widget_data_get(obj);
409 Dialogue_Item *before_item = NULL, *item = NULL;
413 if (!wd || !subobj || !before || !wd->items) return NULL;
415 EINA_LIST_FOREACH(wd->items, l, before_item) {
416 if(before == before_item) {
417 if( !strcmp(before_item->location, "default") ) {
418 _change_item_bg(before_item, "bottom");
419 item = _create_item(obj, subobj, style, "top");
422 else if( !strcmp(before_item->location, "top") ) {
423 _change_item_bg(before_item, "middle");
424 item = _create_item(obj, subobj, style, "top");
427 else if( !strcmp(before_item->location, "middle") || !strcmp(before_item->location, "bottom") ) {
428 item = _create_item(obj, subobj, style, "middle");
429 prev = eina_list_prev(l);
430 // _set_line_show(prev->data, item);
432 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
433 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
443 * Remove an item from the dialogue group.
445 * @param obj dialoguegroup object
448 * @ingroup DialogueGroup
451 elm_dialoguegroup_remove(Dialogue_Item *item)
454 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
455 Dialogue_Item *current_item;
456 Widget_Data *wd = elm_widget_data_get(item->parent);
459 if (!wd || !wd->items || !item) return ;
461 EINA_LIST_FOREACH(wd->items, l, current_item) {
462 if (current_item == item) {
463 if (current_item->content){
464 evas_object_del(current_item->content);
465 current_item->content = NULL;
467 if (current_item->bg_layout){
468 evas_object_del(current_item->bg_layout);
469 current_item->bg_layout = NULL;
471 elm_box_unpack(wd->box, current_item->bg_layout);
472 wd->items = eina_list_remove(wd->items, current_item);
478 if (wd->num == 0) return;
481 current_item = eina_list_data_get(wd->items);
482 _change_item_bg(current_item, "default");
486 current_item = eina_list_data_get(wd->items);
487 _change_item_bg(current_item, "top");
488 current_item = eina_list_data_get( eina_list_last(wd->items) );
489 _change_item_bg(current_item, "bottom");
492 _sizing_eval(item->parent);
496 * Remove all items from the dialogue group.
498 * @param obj dialoguegroup object
500 * @ingroup DialogueGroup
503 elm_dialoguegroup_remove_all(Evas_Object *obj)
505 ELM_CHECK_WIDTYPE(obj, widtype);
512 * Set the title text of the dialogue group.
514 * @param obj dialoguegroup object
515 * @param title title text, if NULL title space will be disappeared
517 * @ingroup DialogueGroup
520 elm_dialoguegroup_title_set(Evas_Object *obj, const char *title)
522 ELM_CHECK_WIDTYPE(obj, widtype);
523 Widget_Data *wd = elm_widget_data_get(obj);
526 eina_stringshare_replace(&wd->title, title);
529 elm_box_unpack(wd->box, wd->title_layout);
531 if (!wd->title_layout) {
532 wd->title_layout = elm_layout_add(wd->box);
533 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "title", elm_widget_style_get(obj));
534 evas_object_size_hint_weight_set(wd->title_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
535 evas_object_size_hint_align_set(wd->title_layout, EVAS_HINT_FILL, 0.0);
536 evas_object_show(wd->title_layout);
537 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
538 elm_box_pack_start(wd->box, wd->title_layout);
540 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
544 * Get the title text of the dialogue group
546 * @param obj The dialoguegroup object
547 * @return The text title string in UTF-8
549 * @ingroup DialogueGroup
552 elm_dialoguegroup_title_get(Evas_Object *obj)
554 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
555 Widget_Data *wd = elm_widget_data_get(obj);
556 if (!wd) return NULL;
561 * Set whether the press effect will be shown or not
563 * @param obj The dialoguegroup object
564 * @param item Dialogue_Item pointer
565 * @param press If set as 1, press effect will be shown
567 * @ingroup DialogueGroup
570 elm_dialoguegroup_press_effect_set(Dialogue_Item *item, Eina_Bool press)
573 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
576 if((press == EINA_TRUE) && (item->disabled == EINA_FALSE))
577 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
579 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
583 * Get the press effect state
585 * @param obj The dialoguegroup object
586 * @param item Dialogue_Item pointer
587 * @return 1 if press effect on, 0 if press effect off
589 * @ingroup DialogueGroup
592 elm_dialoguegroup_press_effect_get(Dialogue_Item *item)
594 if(!item) return EINA_FALSE;
595 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
601 * Get the conetent object from the specified dialogue item
603 * @param obj The dialoguegroup object
604 * @param item Dialogue_Item pointer
605 * @return content object
607 * @ingroup DialogueGroup
610 elm_dialoguegroup_item_content_get(Dialogue_Item *item)
612 if(!item) return NULL;
613 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
615 return item->content;
619 * Set the style of the item.
621 * @param item dialoguegroup item
622 * @param style sytle of the item
624 * @ingroup DialogueGroup
627 elm_dialoguegroup_item_style_set(Dialogue_Item *item, Elm_Dialoguegroup_Item_Style style)
630 ELM_CHECK_WIDTYPE(item->parent, widtype);
631 Widget_Data *wd = elm_widget_data_get(item->parent);
634 _change_item_bg(item, item->location);
640 * Get the style of the item.
642 * @param item dialoguegroup item
643 * @return dialoguegroup item style
645 * @ingroup DialogueGroup
648 EAPI Elm_Dialoguegroup_Item_Style
649 elm_dialoguegroup_item_style_get(Dialogue_Item *item)
651 if(!item) return ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
652 ELM_CHECK_WIDTYPE(item->parent, widtype) ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
653 Widget_Data *wd = elm_widget_data_get(item->parent);
655 if (!wd) return ELM_DIALOGUEGROUP_ITEM_STYLE_LAST;
661 * Set item state as disable or not.
663 * @param item dialoguegroup item.
664 * @param disabled if EINA_TRUE disabled, else abled.
666 * @ingroup DialogueGroup
669 elm_dialoguegroup_item_disabled_set(Dialogue_Item *item, Eina_Bool disabled)
672 ELM_CHECK_WIDTYPE(item->parent, widtype);
674 item->disabled = disabled;
676 if(disabled == EINA_TRUE)
678 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,disabled", "elm");
679 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
683 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,enabled", "elm");
684 if(item->press == EINA_TRUE)
685 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
690 * Get item state whether disabled or not.
692 * @param item dialoguegroup item.
693 * @return if EINA_TRUE, then disabled else abled.
695 * @ingroup DialogueGroup
699 elm_dialoguegroup_item_disabled_get(Dialogue_Item *item)
701 if(!item) return EINA_FALSE;
702 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
704 return item->disabled;
707 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/