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", "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 elm_layout_theme_set(item->bg_layout, "dialoguegroup", buf, elm_widget_style_get(item->parent));
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;
168 static void _change_item_bg(Dialogue_Item *item, const char *location)
172 eina_stringshare_replace(&item->location, location);
173 _set_item_theme(item, location);
174 elm_layout_content_set(item->bg_layout, "swallow", item->content);
175 if(item->press == EINA_TRUE)
176 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
178 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
180 /* if(item->line_show == EINA_FALSE)
181 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,line,hide", "elm");*/
185 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style, const char *location)
187 Widget_Data *wd = elm_widget_data_get(obj);
190 if (!wd) return NULL;
192 item = ELM_NEW(Dialogue_Item);
194 item->content = subobj;
195 item->press = EINA_TRUE;
197 // item->line_show = EINA_TRUE;
198 eina_stringshare_replace(&item->location, location);
200 item->bg_layout = elm_layout_add(wd->box);
201 _set_item_theme(item, location);
202 evas_object_size_hint_weight_set(item->bg_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
203 evas_object_size_hint_align_set(item->bg_layout, EVAS_HINT_FILL, 0.0);
204 evas_object_show(item->bg_layout);
206 elm_layout_content_set(item->bg_layout, "swallow", item->content);
211 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
217 * Add a new dialoguegroup to the parent.
219 * @param parent The parent object
220 * @return The new object or NULL if it cannot be created
222 * @ingroup DialogueGroup
224 EAPI Evas_Object *elm_dialoguegroup_add(Evas_Object *parent)
226 Evas_Object *obj = NULL;
227 Widget_Data *wd = NULL;
229 wd = ELM_NEW(Widget_Data);
230 wd->e = evas_object_evas_get(parent);
231 if (wd->e == NULL) return NULL;
232 obj = elm_widget_add(wd->e);
233 ELM_SET_WIDTYPE(widtype, "dialoguegroup");
234 elm_widget_type_set(obj, "dialoguegroup");
235 elm_widget_sub_object_add(parent, obj);
236 elm_widget_data_set(obj, wd);
237 elm_widget_del_hook_set(obj, _del_hook);
238 elm_widget_theme_hook_set(obj, _theme_hook);
243 wd->box = elm_box_add(obj);
244 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
245 evas_object_show(wd->box);
246 elm_widget_resize_object_set(obj, wd->box);
253 * Append an item to the dialogue group.
255 * @param obj dialoguegroup object
257 * @return Dialogue_Item pointer, just made by this function
259 * @ingroup DialogueGroup
262 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
264 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
265 Widget_Data *wd = elm_widget_data_get(obj);
266 Dialogue_Item *item = NULL, *new_item = NULL;
268 if (!wd || !subobj) return NULL;
271 new_item = _create_item(obj, subobj, style, "default");
274 item = eina_list_data_get(wd->items);
275 _change_item_bg(item, "top");
278 item = eina_list_data_get( eina_list_last(wd->items) );
279 _change_item_bg(item, "middle");
281 new_item = _create_item(obj, subobj, style, "bottom");
282 // _set_line_show(item, new_item);
284 elm_box_pack_end(wd->box, new_item->bg_layout);
285 wd->items = eina_list_append(wd->items, new_item);
293 * Prepend an item to the dialogue group.
295 * @param obj dialoguegroup object
297 * @return Dialogue_Item pointer, just made by this function
299 * @ingroup DialogueGroup
302 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
304 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
305 Widget_Data *wd = elm_widget_data_get(obj);
306 Dialogue_Item *item = NULL, *new_item = NULL;
308 if (!wd || !subobj) return NULL;
311 new_item = _create_item(obj, subobj, style, "default");
314 item = eina_list_data_get(wd->items);
315 _change_item_bg(item, "bottom");
318 item = eina_list_data_get(wd->items);
319 _change_item_bg(item, "middle");
321 new_item = _create_item(obj, subobj, style, "top");
322 // _set_line_show(new_item, item);
325 elm_box_pack_after(wd->box, new_item->bg_layout, wd->title_layout);
327 elm_box_pack_start(wd->box, new_item->bg_layout);
328 wd->items = eina_list_prepend(wd->items, new_item);
335 * Insert an item to the dialogue group just after the specified item.
337 * @param obj dialoguegroup object
339 * @param after specified item existing in the dialogue group
340 * @return Dialogue_Item pointer, just made by this function
342 * @ingroup DialogueGroup
345 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *after, Elm_Dialoguegroup_Item_Style style)
347 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
348 Widget_Data *wd = elm_widget_data_get(obj);
349 Dialogue_Item *after_item = NULL, *item = NULL;
352 if (!wd || !subobj || !after || !wd->items) return NULL;
354 EINA_LIST_FOREACH(wd->items, l, after_item) {
355 if(after == after_item) {
356 if( !strcmp(after_item->location, "default") ) {
357 _change_item_bg(after_item, "top");
358 item = _create_item(obj, subobj, style, "bottom");
360 else if( !strcmp(after_item->location, "top") || !strcmp(after_item->location, "middle") )
361 item = _create_item(obj, subobj, style, "middle");
362 else if( !strcmp(after_item->location, "bottom") ) {
363 _change_item_bg(after_item, "middle");
364 item = _create_item(obj, subobj, style, "bottom");
367 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
368 wd->items = eina_list_append_relative(wd->items, item, after_item);
369 // _set_line_show(after, item);
379 * Insert an item to the dialogue group just before the specified item.
381 * @param obj dialoguegroup object
383 * @param before specified item existing in the dialogue group
384 * @return Dialogue_Item pointer, just made by this function
386 * @ingroup DialogueGroup
389 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *before, Elm_Dialoguegroup_Item_Style style)
391 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
392 Widget_Data *wd = elm_widget_data_get(obj);
393 Dialogue_Item *before_item = NULL, *item = NULL;
397 if (!wd || !subobj || !before || !wd->items) return NULL;
399 EINA_LIST_FOREACH(wd->items, l, before_item) {
400 if(before == before_item) {
401 if( !strcmp(before_item->location, "default") ) {
402 _change_item_bg(before_item, "bottom");
403 item = _create_item(obj, subobj, style, "top");
406 else if( !strcmp(before_item->location, "top") ) {
407 _change_item_bg(before_item, "middle");
408 item = _create_item(obj, subobj, style, "top");
411 else if( !strcmp(before_item->location, "middle") || !strcmp(before_item->location, "bottom") ) {
412 item = _create_item(obj, subobj, style, "middle");
413 prev = eina_list_prev(l);
414 // _set_line_show(prev->data, item);
416 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
417 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
427 * Remove an item from the dialogue group.
429 * @param obj dialoguegroup object
432 * @ingroup DialogueGroup
435 elm_dialoguegroup_remove(Dialogue_Item *item)
437 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
438 Dialogue_Item *current_item;
439 Widget_Data *wd = elm_widget_data_get(item->parent);
442 if (!wd || !wd->items || !item) return ;
444 EINA_LIST_FOREACH(wd->items, l, current_item) {
445 if (current_item == item) {
446 if (current_item->content){
447 evas_object_del(current_item->content);
448 current_item->content = NULL;
450 if (current_item->bg_layout){
451 evas_object_del(current_item->bg_layout);
452 current_item->bg_layout = NULL;
454 elm_box_unpack(wd->box, current_item->bg_layout);
455 wd->items = eina_list_remove(wd->items, current_item);
461 if (wd->num == 0) return;
464 current_item = eina_list_data_get(wd->items);
465 _change_item_bg(current_item, "default");
469 current_item = eina_list_data_get(wd->items);
470 _change_item_bg(current_item, "top");
471 current_item = eina_list_data_get( eina_list_last(wd->items) );
472 _change_item_bg(current_item, "bottom");
475 _sizing_eval(item->parent);
479 * Remove all items from the dialogue group.
481 * @param obj dialoguegroup object
483 * @ingroup DialogueGroup
486 elm_dialoguegroup_remove_all(Evas_Object *obj)
488 ELM_CHECK_WIDTYPE(obj, widtype);
495 * Set the title text of the dialogue group.
497 * @param obj dialoguegroup object
498 * @param title title text, if NULL title space will be disappeared
500 * @ingroup DialogueGroup
503 elm_dialoguegroup_title_set(Evas_Object *obj, const char *title)
505 ELM_CHECK_WIDTYPE(obj, widtype);
506 Widget_Data *wd = elm_widget_data_get(obj);
509 eina_stringshare_replace(&wd->title, title);
512 elm_box_unpack(wd->box, wd->title_layout);
514 if (!wd->title_layout) {
515 wd->title_layout = elm_layout_add(wd->box);
516 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "title", elm_widget_style_get(obj));
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;