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);
141 static void _set_line_show(Dialogue_Item *item, Dialogue_Item *after)
143 if(!item || !after) return;
145 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT) {
146 if (after->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT) {
147 item->line_show = EINA_TRUE;
148 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,show", "elm");
150 else if (after->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD) {
151 item->line_show = EINA_FALSE;
152 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");
155 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD)
156 item->line_show = EINA_TRUE;
160 static void _change_item_bg(Dialogue_Item *item, const char *location)
164 eina_stringshare_replace(&item->location, location);
165 _set_item_theme(item, location);
166 elm_layout_content_set(item->bg_layout, "swallow", item->content);
167 if(item->press == EINA_TRUE)
168 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
170 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
172 /* if(item->line_show == EINA_FALSE)
173 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");*/
177 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style, const char *location)
179 Widget_Data *wd = elm_widget_data_get(obj);
182 if (!wd) return NULL;
184 item = ELM_NEW(Dialogue_Item);
186 item->content = subobj;
187 item->press = EINA_TRUE;
189 // item->line_show = EINA_TRUE;
190 eina_stringshare_replace(&item->location, location);
192 item->bg_layout = elm_layout_add(wd->parent);
193 _set_item_theme(item, location);
194 evas_object_size_hint_weight_set(item->bg_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
195 evas_object_size_hint_align_set(item->bg_layout, EVAS_HINT_FILL, 0.0);
196 evas_object_show(item->bg_layout);
198 elm_layout_content_set(item->bg_layout, "swallow", item->content);
203 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
209 * Add a new dialoguegroup to the parent.
211 * @param parent The parent object
212 * @return The new object or NULL if it cannot be created
214 * @ingroup DialogueGroup
216 EAPI Evas_Object *elm_dialoguegroup_add(Evas_Object *parent)
218 Evas_Object *obj = NULL;
219 Widget_Data *wd = NULL;
221 wd = ELM_NEW(Widget_Data);
222 wd->e = evas_object_evas_get(parent);
223 if (wd->e == NULL) return NULL;
224 obj = elm_widget_add(wd->e);
225 ELM_SET_WIDTYPE(widtype, "dialoguegroup");
226 elm_widget_type_set(obj, "dialoguegroup");
227 elm_widget_sub_object_add(parent, obj);
228 elm_widget_data_set(obj, wd);
229 elm_widget_del_hook_set(obj, _del_hook);
230 elm_widget_theme_hook_set(obj, _theme_hook);
235 wd->box = elm_box_add(parent);
236 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
237 evas_object_show(wd->box);
238 elm_widget_resize_object_set(obj, wd->box);
245 * Append an item to the dialogue group.
247 * @param obj dialoguegroup object
249 * @return Dialogue_Item pointer, just made by this function
251 * @ingroup DialogueGroup
254 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
256 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
257 Widget_Data *wd = elm_widget_data_get(obj);
258 Dialogue_Item *item = NULL, *new_item = NULL;
260 if (!wd || !subobj) return NULL;
263 new_item = _create_item(obj, subobj, style, "default");
266 item = eina_list_data_get(wd->items);
267 _change_item_bg(item, "top");
270 item = eina_list_data_get( eina_list_last(wd->items) );
271 _change_item_bg(item, "middle");
273 new_item = _create_item(obj, subobj, style, "bottom");
274 // _set_line_show(item, new_item);
276 elm_box_pack_end(wd->box, new_item->bg_layout);
277 wd->items = eina_list_append(wd->items, new_item);
285 * Prepend an item to the dialogue group.
287 * @param obj dialoguegroup object
289 * @return Dialogue_Item pointer, just made by this function
291 * @ingroup DialogueGroup
294 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
296 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
297 Widget_Data *wd = elm_widget_data_get(obj);
298 Dialogue_Item *item = NULL, *new_item = NULL;
300 if (!wd || !subobj) return NULL;
303 new_item = _create_item(obj, subobj, style, "default");
306 item = eina_list_data_get(wd->items);
307 _change_item_bg(item, "bottom");
310 item = eina_list_data_get(wd->items);
311 _change_item_bg(item, "middle");
313 new_item = _create_item(obj, subobj, style, "top");
314 // _set_line_show(new_item, item);
317 elm_box_pack_after(wd->box, new_item->bg_layout, wd->title_layout);
319 elm_box_pack_start(wd->box, new_item->bg_layout);
320 wd->items = eina_list_prepend(wd->items, new_item);
327 * Insert an item to the dialogue group just after the specified item.
329 * @param obj dialoguegroup object
331 * @param after specified item existing in the dialogue group
332 * @return Dialogue_Item pointer, just made by this function
334 * @ingroup DialogueGroup
337 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *after, Elm_Dialoguegroup_Item_Style style)
339 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
340 Widget_Data *wd = elm_widget_data_get(obj);
341 Dialogue_Item *after_item = NULL, *item = NULL;
344 if (!wd || !subobj || !after || !wd->items) return NULL;
346 EINA_LIST_FOREACH(wd->items, l, after_item) {
347 if(after == after_item) {
348 if( !strcmp(after_item->location, "default") ) {
349 _change_item_bg(after_item, "top");
350 item = _create_item(obj, subobj, style, "bottom");
352 else if( !strcmp(after_item->location, "top") || !strcmp(after_item->location, "middle") )
353 item = _create_item(obj, subobj, style, "middle");
354 else if( !strcmp(after_item->location, "bottom") ) {
355 _change_item_bg(after_item, "middle");
356 item = _create_item(obj, subobj, style, "bottom");
359 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
360 wd->items = eina_list_append_relative(wd->items, item, after_item);
361 // _set_line_show(after, item);
371 * Insert an item to the dialogue group just before the specified item.
373 * @param obj dialoguegroup object
375 * @param before specified item existing in the dialogue group
376 * @return Dialogue_Item pointer, just made by this function
378 * @ingroup DialogueGroup
381 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *before, Elm_Dialoguegroup_Item_Style style)
383 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
384 Widget_Data *wd = elm_widget_data_get(obj);
385 Dialogue_Item *before_item = NULL, *item = NULL;
389 if (!wd || !subobj || !before || !wd->items) return NULL;
391 EINA_LIST_FOREACH(wd->items, l, before_item) {
392 if(before == before_item) {
393 if( !strcmp(before_item->location, "default") ) {
394 _change_item_bg(before_item, "bottom");
395 item = _create_item(obj, subobj, style, "top");
398 else if( !strcmp(before_item->location, "top") ) {
399 _change_item_bg(before_item, "middle");
400 item = _create_item(obj, subobj, style, "top");
403 else if( !strcmp(before_item->location, "middle") || !strcmp(before_item->location, "bottom") ) {
404 item = _create_item(obj, subobj, style, "middle");
405 prev = eina_list_prev(l);
406 // _set_line_show(prev->data, item);
408 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
409 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
419 * Remove an item from the dialogue group.
421 * @param obj dialoguegroup object
424 * @ingroup DialogueGroup
427 elm_dialoguegroup_remove(Dialogue_Item *item)
429 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
430 Dialogue_Item *current_item;
431 Widget_Data *wd = elm_widget_data_get(item->parent);
434 if (!wd || !wd->items || !item) return ;
436 EINA_LIST_FOREACH(wd->items, l, current_item) {
437 if (current_item == item) {
438 if (current_item->content){
439 evas_object_del(current_item->content);
440 current_item->content = NULL;
442 if (current_item->bg_layout){
443 evas_object_del(current_item->bg_layout);
444 current_item->bg_layout = NULL;
446 elm_box_unpack(wd->box, current_item->bg_layout);
447 wd->items = eina_list_remove(wd->items, current_item);
453 if (wd->num == 0) return;
456 current_item = eina_list_data_get(wd->items);
457 _change_item_bg(current_item, "default");
461 current_item = eina_list_data_get(wd->items);
462 _change_item_bg(current_item, "top");
463 current_item = eina_list_data_get( eina_list_last(wd->items) );
464 _change_item_bg(current_item, "bottom");
467 _sizing_eval(item->parent);
471 * Remove all items from the dialogue group.
473 * @param obj dialoguegroup object
475 * @ingroup DialogueGroup
478 elm_dialoguegroup_remove_all(Evas_Object *obj)
480 ELM_CHECK_WIDTYPE(obj, widtype);
487 * Set the title text of the dialogue group.
489 * @param obj dialoguegroup object
490 * @param title title text, if NULL title space will be disappeared
492 * @ingroup DialogueGroup
495 elm_dialoguegroup_title_set(Evas_Object *obj, const char *title)
497 ELM_CHECK_WIDTYPE(obj, widtype);
498 Widget_Data *wd = elm_widget_data_get(obj);
501 eina_stringshare_replace(&wd->title, title);
504 elm_box_unpack(wd->box, wd->title_layout);
506 if (!wd->title_layout) {
507 wd->title_layout = elm_layout_add(wd->parent);
508 elm_widget_sub_object_add(obj, wd->title_layout);
509 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "base", "title");
510 evas_object_size_hint_weight_set(wd->title_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
511 evas_object_size_hint_align_set(wd->title_layout, EVAS_HINT_FILL, 0.0);
512 evas_object_show(wd->title_layout);
514 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
515 elm_box_pack_start(wd->box, wd->title_layout);
519 * Get the title text of the dialogue group
521 * @param obj The dialoguegroup object
522 * @return The text title string in UTF-8
524 * @ingroup DialogueGroup
527 elm_dialoguegroup_title_get(Evas_Object *obj)
529 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
530 Widget_Data *wd = elm_widget_data_get(obj);
531 if (!wd) return NULL;
536 * Set whether the press effect will be shown or not
538 * @param obj The dialoguegroup object
539 * @param item Dialogue_Item pointer
540 * @param press If set as 1, press effect will be shown
542 * @ingroup DialogueGroup
545 elm_dialoguegroup_press_effect_set(Dialogue_Item *item, Eina_Bool press)
547 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
551 if(press == EINA_TRUE)
552 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
554 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
558 * Get the press effect state
560 * @param obj The dialoguegroup object
561 * @param item Dialogue_Item pointer
562 * @return 1 if press effect on, 0 if press effect off
564 * @ingroup DialogueGroup
567 elm_dialoguegroup_press_effect_get(Dialogue_Item *item)
569 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
570 if(!item) return EINA_FALSE;
576 * Get the conetent object from the specified dialogue item
578 * @param obj The dialoguegroup object
579 * @param item Dialogue_Item pointer
580 * @return content object
582 * @ingroup DialogueGroup
585 elm_dialoguegroup_item_content_get(Dialogue_Item *item)
587 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
588 if(!item) return EINA_FALSE;
590 return item->content;