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;
20 // Eina_Bool line_show;
24 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", "base", "title");
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)
134 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT)
135 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "bg", location);
136 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD)
137 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "editfield", location);
138 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD_WITH_TITLE)
139 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "editfield_with_title", location);
140 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDIT_TITLE)
141 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "title", location);
142 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_HIDDEN)
143 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "hidden", location);
147 static void _set_line_show(Dialogue_Item *item, Dialogue_Item *after)
149 if(!item || !after) return;
151 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT) {
152 if (after->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT) {
153 item->line_show = EINA_TRUE;
154 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,show", "elm");
156 else if (after->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD) {
157 item->line_show = EINA_FALSE;
158 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");
161 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD)
162 item->line_show = EINA_TRUE;
166 static void _change_item_bg(Dialogue_Item *item, const char *location)
170 eina_stringshare_replace(&item->location, location);
171 _set_item_theme(item, location);
172 elm_layout_content_set(item->bg_layout, "swallow", item->content);
173 if(item->press == EINA_TRUE)
174 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
176 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
178 /* if(item->line_show == EINA_FALSE)
179 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");*/
183 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style, const char *location)
185 Widget_Data *wd = elm_widget_data_get(obj);
188 if (!wd) return NULL;
190 item = ELM_NEW(Dialogue_Item);
192 item->content = subobj;
193 item->press = EINA_TRUE;
195 // item->line_show = EINA_TRUE;
196 eina_stringshare_replace(&item->location, location);
198 item->bg_layout = elm_layout_add(wd->box);
199 _set_item_theme(item, location);
200 evas_object_size_hint_weight_set(item->bg_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
201 evas_object_size_hint_align_set(item->bg_layout, EVAS_HINT_FILL, 0.0);
202 evas_object_show(item->bg_layout);
204 elm_layout_content_set(item->bg_layout, "swallow", item->content);
209 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
215 * Add a new dialoguegroup to the parent.
217 * @param parent The parent object
218 * @return The new object or NULL if it cannot be created
220 * @ingroup DialogueGroup
222 EAPI Evas_Object *elm_dialoguegroup_add(Evas_Object *parent)
224 Evas_Object *obj = NULL;
225 Widget_Data *wd = NULL;
227 wd = ELM_NEW(Widget_Data);
228 wd->e = evas_object_evas_get(parent);
229 if (wd->e == NULL) return NULL;
230 obj = elm_widget_add(wd->e);
231 ELM_SET_WIDTYPE(widtype, "dialoguegroup");
232 elm_widget_type_set(obj, "dialoguegroup");
233 elm_widget_sub_object_add(parent, obj);
234 elm_widget_data_set(obj, wd);
235 elm_widget_del_hook_set(obj, _del_hook);
236 elm_widget_theme_hook_set(obj, _theme_hook);
241 wd->box = elm_box_add(obj);
242 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
243 evas_object_show(wd->box);
244 elm_widget_resize_object_set(obj, wd->box);
251 * Append an item to the dialogue group.
253 * @param obj dialoguegroup object
255 * @return Dialogue_Item pointer, just made by this function
257 * @ingroup DialogueGroup
260 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
262 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
263 Widget_Data *wd = elm_widget_data_get(obj);
264 Dialogue_Item *item = NULL, *new_item = NULL;
266 if (!wd || !subobj) return NULL;
269 new_item = _create_item(obj, subobj, style, "default");
272 item = eina_list_data_get(wd->items);
273 _change_item_bg(item, "top");
276 item = eina_list_data_get( eina_list_last(wd->items) );
277 _change_item_bg(item, "middle");
279 new_item = _create_item(obj, subobj, style, "bottom");
280 // _set_line_show(item, new_item);
282 elm_box_pack_end(wd->box, new_item->bg_layout);
283 wd->items = eina_list_append(wd->items, new_item);
291 * Prepend an item to the dialogue group.
293 * @param obj dialoguegroup object
295 * @return Dialogue_Item pointer, just made by this function
297 * @ingroup DialogueGroup
300 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
302 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
303 Widget_Data *wd = elm_widget_data_get(obj);
304 Dialogue_Item *item = NULL, *new_item = NULL;
306 if (!wd || !subobj) return NULL;
309 new_item = _create_item(obj, subobj, style, "default");
312 item = eina_list_data_get(wd->items);
313 _change_item_bg(item, "bottom");
316 item = eina_list_data_get(wd->items);
317 _change_item_bg(item, "middle");
319 new_item = _create_item(obj, subobj, style, "top");
320 // _set_line_show(new_item, item);
323 elm_box_pack_after(wd->box, new_item->bg_layout, wd->title_layout);
325 elm_box_pack_start(wd->box, new_item->bg_layout);
326 wd->items = eina_list_prepend(wd->items, new_item);
333 * Insert an item to the dialogue group just after the specified item.
335 * @param obj dialoguegroup object
337 * @param after specified item existing in the dialogue group
338 * @return Dialogue_Item pointer, just made by this function
340 * @ingroup DialogueGroup
343 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *after, Elm_Dialoguegroup_Item_Style style)
345 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
346 Widget_Data *wd = elm_widget_data_get(obj);
347 Dialogue_Item *after_item = NULL, *item = NULL;
350 if (!wd || !subobj || !after || !wd->items) return NULL;
352 EINA_LIST_FOREACH(wd->items, l, after_item) {
353 if(after == after_item) {
354 if( !strcmp(after_item->location, "default") ) {
355 _change_item_bg(after_item, "top");
356 item = _create_item(obj, subobj, style, "bottom");
358 else if( !strcmp(after_item->location, "top") || !strcmp(after_item->location, "middle") )
359 item = _create_item(obj, subobj, style, "middle");
360 else if( !strcmp(after_item->location, "bottom") ) {
361 _change_item_bg(after_item, "middle");
362 item = _create_item(obj, subobj, style, "bottom");
365 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
366 wd->items = eina_list_append_relative(wd->items, item, after_item);
367 // _set_line_show(after, item);
377 * Insert an item to the dialogue group just before the specified item.
379 * @param obj dialoguegroup object
381 * @param before specified item existing in the dialogue group
382 * @return Dialogue_Item pointer, just made by this function
384 * @ingroup DialogueGroup
387 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *before, Elm_Dialoguegroup_Item_Style style)
389 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
390 Widget_Data *wd = elm_widget_data_get(obj);
391 Dialogue_Item *before_item = NULL, *item = NULL;
395 if (!wd || !subobj || !before || !wd->items) return NULL;
397 EINA_LIST_FOREACH(wd->items, l, before_item) {
398 if(before == before_item) {
399 if( !strcmp(before_item->location, "default") ) {
400 _change_item_bg(before_item, "bottom");
401 item = _create_item(obj, subobj, style, "top");
404 else if( !strcmp(before_item->location, "top") ) {
405 _change_item_bg(before_item, "middle");
406 item = _create_item(obj, subobj, style, "top");
409 else if( !strcmp(before_item->location, "middle") || !strcmp(before_item->location, "bottom") ) {
410 item = _create_item(obj, subobj, style, "middle");
411 prev = eina_list_prev(l);
412 // _set_line_show(prev->data, item);
414 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
415 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
425 * Remove an item from the dialogue group.
427 * @param obj dialoguegroup object
430 * @ingroup DialogueGroup
433 elm_dialoguegroup_remove(Dialogue_Item *item)
435 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
436 Dialogue_Item *current_item;
437 Widget_Data *wd = elm_widget_data_get(item->parent);
440 if (!wd || !wd->items || !item) return ;
442 EINA_LIST_FOREACH(wd->items, l, current_item) {
443 if (current_item == item) {
444 if (current_item->content){
445 evas_object_del(current_item->content);
446 current_item->content = NULL;
448 if (current_item->bg_layout){
449 evas_object_del(current_item->bg_layout);
450 current_item->bg_layout = NULL;
452 elm_box_unpack(wd->box, current_item->bg_layout);
453 wd->items = eina_list_remove(wd->items, current_item);
459 if (wd->num == 0) return;
462 current_item = eina_list_data_get(wd->items);
463 _change_item_bg(current_item, "default");
467 current_item = eina_list_data_get(wd->items);
468 _change_item_bg(current_item, "top");
469 current_item = eina_list_data_get( eina_list_last(wd->items) );
470 _change_item_bg(current_item, "bottom");
473 _sizing_eval(item->parent);
477 * Remove all items from the dialogue group.
479 * @param obj dialoguegroup object
481 * @ingroup DialogueGroup
484 elm_dialoguegroup_remove_all(Evas_Object *obj)
486 ELM_CHECK_WIDTYPE(obj, widtype);
493 * Set the title text of the dialogue group.
495 * @param obj dialoguegroup object
496 * @param title title text, if NULL title space will be disappeared
498 * @ingroup DialogueGroup
501 elm_dialoguegroup_title_set(Evas_Object *obj, const char *title)
503 ELM_CHECK_WIDTYPE(obj, widtype);
504 Widget_Data *wd = elm_widget_data_get(obj);
507 eina_stringshare_replace(&wd->title, title);
510 elm_box_unpack(wd->box, wd->title_layout);
512 if (!wd->title_layout) {
513 wd->title_layout = elm_layout_add(wd->box);
514 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "base", "title");
515 evas_object_size_hint_weight_set(wd->title_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
516 evas_object_size_hint_align_set(wd->title_layout, EVAS_HINT_FILL, 0.0);
517 evas_object_show(wd->title_layout);
519 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
520 elm_box_pack_start(wd->box, wd->title_layout);
524 * Get the title text of the dialogue group
526 * @param obj The dialoguegroup object
527 * @return The text title string in UTF-8
529 * @ingroup DialogueGroup
532 elm_dialoguegroup_title_get(Evas_Object *obj)
534 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
535 Widget_Data *wd = elm_widget_data_get(obj);
536 if (!wd) return NULL;
541 * Set whether the press effect will be shown or not
543 * @param obj The dialoguegroup object
544 * @param item Dialogue_Item pointer
545 * @param press If set as 1, press effect will be shown
547 * @ingroup DialogueGroup
550 elm_dialoguegroup_press_effect_set(Dialogue_Item *item, Eina_Bool press)
552 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
556 if(press == EINA_TRUE)
557 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
559 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
563 * Get the press effect state
565 * @param obj The dialoguegroup object
566 * @param item Dialogue_Item pointer
567 * @return 1 if press effect on, 0 if press effect off
569 * @ingroup DialogueGroup
572 elm_dialoguegroup_press_effect_get(Dialogue_Item *item)
574 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
575 if(!item) return EINA_FALSE;
581 * Get the conetent object from the specified dialogue item
583 * @param obj The dialoguegroup object
584 * @param item Dialogue_Item pointer
585 * @return content object
587 * @ingroup DialogueGroup
590 elm_dialoguegroup_item_content_get(Dialogue_Item *item)
592 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
593 if(!item) return EINA_FALSE;
595 return item->content;