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->parent);
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);
203 elm_widget_sub_object_add(obj, item->bg_layout);
205 elm_layout_content_set(item->bg_layout, "swallow", item->content);
210 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
216 * Add a new dialoguegroup to the parent.
218 * @param parent The parent object
219 * @return The new object or NULL if it cannot be created
221 * @ingroup DialogueGroup
223 EAPI Evas_Object *elm_dialoguegroup_add(Evas_Object *parent)
225 Evas_Object *obj = NULL;
226 Widget_Data *wd = NULL;
228 wd = ELM_NEW(Widget_Data);
229 wd->e = evas_object_evas_get(parent);
230 if (wd->e == NULL) return NULL;
231 obj = elm_widget_add(wd->e);
232 ELM_SET_WIDTYPE(widtype, "dialoguegroup");
233 elm_widget_type_set(obj, "dialoguegroup");
234 elm_widget_sub_object_add(parent, obj);
235 elm_widget_data_set(obj, wd);
236 elm_widget_del_hook_set(obj, _del_hook);
237 elm_widget_theme_hook_set(obj, _theme_hook);
242 wd->box = elm_box_add(parent);
243 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
244 evas_object_show(wd->box);
245 elm_widget_resize_object_set(obj, wd->box);
252 * Append an item to the dialogue group.
254 * @param obj dialoguegroup object
256 * @return Dialogue_Item pointer, just made by this function
258 * @ingroup DialogueGroup
261 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
263 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
264 Widget_Data *wd = elm_widget_data_get(obj);
265 Dialogue_Item *item = NULL, *new_item = NULL;
267 if (!wd || !subobj) return NULL;
270 new_item = _create_item(obj, subobj, style, "default");
273 item = eina_list_data_get(wd->items);
274 _change_item_bg(item, "top");
277 item = eina_list_data_get( eina_list_last(wd->items) );
278 _change_item_bg(item, "middle");
280 new_item = _create_item(obj, subobj, style, "bottom");
281 // _set_line_show(item, new_item);
283 elm_box_pack_end(wd->box, new_item->bg_layout);
284 wd->items = eina_list_append(wd->items, new_item);
292 * Prepend an item to the dialogue group.
294 * @param obj dialoguegroup object
296 * @return Dialogue_Item pointer, just made by this function
298 * @ingroup DialogueGroup
301 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
303 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
304 Widget_Data *wd = elm_widget_data_get(obj);
305 Dialogue_Item *item = NULL, *new_item = NULL;
307 if (!wd || !subobj) return NULL;
310 new_item = _create_item(obj, subobj, style, "default");
313 item = eina_list_data_get(wd->items);
314 _change_item_bg(item, "bottom");
317 item = eina_list_data_get(wd->items);
318 _change_item_bg(item, "middle");
320 new_item = _create_item(obj, subobj, style, "top");
321 // _set_line_show(new_item, item);
324 elm_box_pack_after(wd->box, new_item->bg_layout, wd->title_layout);
326 elm_box_pack_start(wd->box, new_item->bg_layout);
327 wd->items = eina_list_prepend(wd->items, new_item);
334 * Insert an item to the dialogue group just after the specified item.
336 * @param obj dialoguegroup object
338 * @param after specified item existing in the dialogue group
339 * @return Dialogue_Item pointer, just made by this function
341 * @ingroup DialogueGroup
344 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *after, Elm_Dialoguegroup_Item_Style style)
346 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
347 Widget_Data *wd = elm_widget_data_get(obj);
348 Dialogue_Item *after_item = NULL, *item = NULL;
351 if (!wd || !subobj || !after || !wd->items) return NULL;
353 EINA_LIST_FOREACH(wd->items, l, after_item) {
354 if(after == after_item) {
355 if( !strcmp(after_item->location, "default") ) {
356 _change_item_bg(after_item, "top");
357 item = _create_item(obj, subobj, style, "bottom");
359 else if( !strcmp(after_item->location, "top") || !strcmp(after_item->location, "middle") )
360 item = _create_item(obj, subobj, style, "middle");
361 else if( !strcmp(after_item->location, "bottom") ) {
362 _change_item_bg(after_item, "middle");
363 item = _create_item(obj, subobj, style, "bottom");
366 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
367 wd->items = eina_list_append_relative(wd->items, item, after_item);
368 // _set_line_show(after, item);
378 * Insert an item to the dialogue group just before the specified item.
380 * @param obj dialoguegroup object
382 * @param before specified item existing in the dialogue group
383 * @return Dialogue_Item pointer, just made by this function
385 * @ingroup DialogueGroup
388 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *before, Elm_Dialoguegroup_Item_Style style)
390 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
391 Widget_Data *wd = elm_widget_data_get(obj);
392 Dialogue_Item *before_item = NULL, *item = NULL;
396 if (!wd || !subobj || !before || !wd->items) return NULL;
398 EINA_LIST_FOREACH(wd->items, l, before_item) {
399 if(before == before_item) {
400 if( !strcmp(before_item->location, "default") ) {
401 _change_item_bg(before_item, "bottom");
402 item = _create_item(obj, subobj, style, "top");
405 else if( !strcmp(before_item->location, "top") ) {
406 _change_item_bg(before_item, "middle");
407 item = _create_item(obj, subobj, style, "top");
410 else if( !strcmp(before_item->location, "middle") || !strcmp(before_item->location, "bottom") ) {
411 item = _create_item(obj, subobj, style, "middle");
412 prev = eina_list_prev(l);
413 // _set_line_show(prev->data, item);
415 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
416 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
426 * Remove an item from the dialogue group.
428 * @param obj dialoguegroup object
431 * @ingroup DialogueGroup
434 elm_dialoguegroup_remove(Dialogue_Item *item)
436 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
437 Dialogue_Item *current_item;
438 Widget_Data *wd = elm_widget_data_get(item->parent);
441 if (!wd || !wd->items || !item) return ;
443 EINA_LIST_FOREACH(wd->items, l, current_item) {
444 if (current_item == item) {
445 if (current_item->content){
446 evas_object_del(current_item->content);
447 current_item->content = NULL;
449 if (current_item->bg_layout){
450 evas_object_del(current_item->bg_layout);
451 current_item->bg_layout = NULL;
453 elm_box_unpack(wd->box, current_item->bg_layout);
454 wd->items = eina_list_remove(wd->items, current_item);
460 if (wd->num == 0) return;
463 current_item = eina_list_data_get(wd->items);
464 _change_item_bg(current_item, "default");
468 current_item = eina_list_data_get(wd->items);
469 _change_item_bg(current_item, "top");
470 current_item = eina_list_data_get( eina_list_last(wd->items) );
471 _change_item_bg(current_item, "bottom");
474 _sizing_eval(item->parent);
478 * Remove all items from the dialogue group.
480 * @param obj dialoguegroup object
482 * @ingroup DialogueGroup
485 elm_dialoguegroup_remove_all(Evas_Object *obj)
487 ELM_CHECK_WIDTYPE(obj, widtype);
494 * Set the title text of the dialogue group.
496 * @param obj dialoguegroup object
497 * @param title title text, if NULL title space will be disappeared
499 * @ingroup DialogueGroup
502 elm_dialoguegroup_title_set(Evas_Object *obj, const char *title)
504 ELM_CHECK_WIDTYPE(obj, widtype);
505 Widget_Data *wd = elm_widget_data_get(obj);
508 eina_stringshare_replace(&wd->title, title);
511 elm_box_unpack(wd->box, wd->title_layout);
513 if (!wd->title_layout) {
514 wd->title_layout = elm_layout_add(wd->parent);
515 elm_widget_sub_object_add(obj, wd->title_layout);
516 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "base", "title");
517 evas_object_size_hint_weight_set(wd->title_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
518 evas_object_size_hint_align_set(wd->title_layout, EVAS_HINT_FILL, 0.0);
519 evas_object_show(wd->title_layout);
521 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
522 elm_box_pack_start(wd->box, wd->title_layout);
526 * Get the title text of the dialogue group
528 * @param obj The dialoguegroup object
529 * @return The text title string in UTF-8
531 * @ingroup DialogueGroup
534 elm_dialoguegroup_title_get(Evas_Object *obj)
536 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
537 Widget_Data *wd = elm_widget_data_get(obj);
538 if (!wd) return NULL;
543 * Set whether the press effect will be shown or not
545 * @param obj The dialoguegroup object
546 * @param item Dialogue_Item pointer
547 * @param press If set as 1, press effect will be shown
549 * @ingroup DialogueGroup
552 elm_dialoguegroup_press_effect_set(Dialogue_Item *item, Eina_Bool press)
554 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
558 if(press == EINA_TRUE)
559 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
561 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
565 * Get the press effect state
567 * @param obj The dialoguegroup object
568 * @param item Dialogue_Item pointer
569 * @return 1 if press effect on, 0 if press effect off
571 * @ingroup DialogueGroup
574 elm_dialoguegroup_press_effect_get(Dialogue_Item *item)
576 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
577 if(!item) return EINA_FALSE;
583 * Get the conetent object from the specified dialogue item
585 * @param obj The dialoguegroup object
586 * @param item Dialogue_Item pointer
587 * @return content object
589 * @ingroup DialogueGroup
592 elm_dialoguegroup_item_content_get(Dialogue_Item *item)
594 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
595 if(!item) return EINA_FALSE;
597 return item->content;