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;
23 typedef struct _Widget_Data Widget_Data;
29 Evas_Object *title_layout;
35 static const char*widtype = NULL;
37 static void _del_hook(Evas_Object *obj);
38 static void _theme_hook(Evas_Object *obj);
39 static void _sizing_eval(Evas_Object *obj);
40 static void _disable_hook(Evas_Object *obj);
42 static void _remove_all(Evas_Object *obj);
43 static void _change_item_bg(Dialogue_Item *item, const char *location);
44 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style, const char *location);
48 _del_hook(Evas_Object *obj)
50 Widget_Data *wd = elm_widget_data_get(obj);
53 if (wd->title) eina_stringshare_del(wd->title);
58 evas_object_del(wd->box);
67 _theme_hook(Evas_Object *obj)
69 Widget_Data *wd = elm_widget_data_get(obj);
75 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "base", "title");
76 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", wd->title);
78 EINA_LIST_FOREACH(wd->items, l, item)
79 _change_item_bg( item, item->location );
84 _disable_hook(Evas_Object *obj)
90 _sizing_eval(Evas_Object *obj)
92 Widget_Data *wd = elm_widget_data_get(obj);
93 Evas_Coord minw, minh, maxw, maxh;
96 evas_object_size_hint_min_get(wd->box, &minw, &minh);
97 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
98 evas_object_size_hint_min_set(obj, minw, minh);
99 evas_object_size_hint_max_set(obj, maxw, maxh);
102 static void _remove_all(Evas_Object *obj)
104 Widget_Data *wd = elm_widget_data_get(obj);
112 EINA_LIST_FREE(wd->items, item) {
114 evas_object_del(item->content);
115 item->content = NULL;
117 if (item->bg_layout){
118 evas_object_del(item->bg_layout);
119 item->bg_layout = NULL;
122 eina_stringshare_del(item->location);
127 static void _set_item_theme(Dialogue_Item *item, const char *location)
131 if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_DEFAULT)
132 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "bg", location);
133 else if (item->style == ELM_DIALOGUEGROUP_ITEM_STYLE_EDITFIELD)
134 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "editfield", location);
137 static void _change_item_bg(Dialogue_Item *item, const char *location)
141 eina_stringshare_replace(&item->location, location);
142 _set_item_theme(item, location);
143 elm_layout_content_set(item->bg_layout, "swallow", item->content);
144 if(item->press == EINA_TRUE)
145 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
147 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
150 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style, const char *location)
152 Widget_Data *wd = elm_widget_data_get(obj);
155 if (!wd) return NULL;
157 item = ELM_NEW(Dialogue_Item);
159 item->content = subobj;
160 item->press = EINA_TRUE;
162 eina_stringshare_replace(&item->location, location);
164 item->bg_layout = elm_layout_add(wd->parent);
165 _set_item_theme(item, location);
166 evas_object_size_hint_weight_set(item->bg_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
167 evas_object_size_hint_align_set(item->bg_layout, EVAS_HINT_FILL, 0.0);
168 evas_object_show(item->bg_layout);
170 elm_layout_content_set(item->bg_layout, "swallow", item->content);
175 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
181 * Add a new dialoguegroup to the parent.
183 * @param parent The parent object
184 * @return The new object or NULL if it cannot be created
186 * @ingroup DialogueGroup
188 EAPI Evas_Object *elm_dialoguegroup_add(Evas_Object *parent)
190 Evas_Object *obj = NULL;
191 Widget_Data *wd = NULL;
193 wd = ELM_NEW(Widget_Data);
194 wd->e = evas_object_evas_get(parent);
195 if (wd->e == NULL) return NULL;
196 obj = elm_widget_add(wd->e);
197 ELM_SET_WIDTYPE(widtype, "dialoguegroup");
198 elm_widget_type_set(obj, "dialoguegroup");
199 elm_widget_sub_object_add(parent, obj);
200 elm_widget_data_set(obj, wd);
201 elm_widget_del_hook_set(obj, _del_hook);
202 elm_widget_theme_hook_set(obj, _theme_hook);
207 wd->box = elm_box_add(parent);
208 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
209 evas_object_show(wd->box);
210 elm_widget_resize_object_set(obj, wd->box);
217 * Append an item to the dialogue group.
219 * @param obj dialoguegroup object
221 * @return Dialogue_Item pointer, just made by this function
223 * @ingroup DialogueGroup
226 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
228 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
229 Widget_Data *wd = elm_widget_data_get(obj);
232 if (!wd || !subobj) return NULL;
235 item = _create_item(obj, subobj, style, "default");
236 elm_box_pack_end(wd->box, item->bg_layout);
237 wd->items = eina_list_append(wd->items, item);
242 item = eina_list_data_get(wd->items);
243 _change_item_bg(item, "top");
246 item = eina_list_data_get( eina_list_last(wd->items) );
247 _change_item_bg(item, "middle");
249 item = _create_item(obj, subobj, style, "bottom");
250 elm_box_pack_end(wd->box, item->bg_layout);
251 wd->items = eina_list_append(wd->items, item);
261 * Prepend an item to the dialogue group.
263 * @param obj dialoguegroup object
265 * @return Dialogue_Item pointer, just made by this function
267 * @ingroup DialogueGroup
270 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj, Elm_Dialoguegroup_Item_Style style)
272 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
273 Widget_Data *wd = elm_widget_data_get(obj);
276 if (!wd || !subobj) return NULL;
279 item = _create_item(obj, subobj, style, "default");
281 elm_box_pack_after(wd->box, item->bg_layout, wd->title_layout);
283 elm_box_pack_start(wd->box, item->bg_layout);
284 wd->items = eina_list_prepend(wd->items, item);
289 item = eina_list_data_get(wd->items);
290 _change_item_bg(item, "bottom");
293 item = eina_list_data_get(wd->items);
294 _change_item_bg(item, "middle");
296 item = _create_item(obj, subobj, style, "top");
298 elm_box_pack_after(wd->box, item->bg_layout, wd->title_layout);
300 elm_box_pack_start(wd->box, item->bg_layout);
301 wd->items = eina_list_prepend(wd->items, item);
310 * Insert an item to the dialogue group just after the specified item.
312 * @param obj dialoguegroup object
314 * @param after specified item existing in the dialogue group
315 * @return Dialogue_Item pointer, just made by this function
317 * @ingroup DialogueGroup
320 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *after, Elm_Dialoguegroup_Item_Style style)
322 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
323 Widget_Data *wd = elm_widget_data_get(obj);
324 Dialogue_Item *after_item, *item;
327 if (!wd || !subobj || !after || !wd->items) return NULL;
329 EINA_LIST_FOREACH(wd->items, l, after_item) {
330 if(after == after_item) {
331 if( !strcmp(item->location, "default") ) {
332 _change_item_bg(after_item, "top");
333 item = _create_item(obj, subobj, style, "bottom");
335 else if( !strcmp(item->location, "top") || !strcmp(item->location, "middle") )
336 item = _create_item(obj, subobj, style, "middle");
337 else if( !strcmp(item->location, "bottom") ) {
338 _change_item_bg(after_item, "middle");
339 item = _create_item(obj, subobj, style, "bottom");
342 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
343 wd->items = eina_list_append_relative(wd->items, item, after_item);
353 * Insert an item to the dialogue group just before the specified item.
355 * @param obj dialoguegroup object
357 * @param before specified item existing in the dialogue group
358 * @return Dialogue_Item pointer, just made by this function
360 * @ingroup DialogueGroup
363 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *before, Elm_Dialoguegroup_Item_Style style)
365 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
366 Widget_Data *wd = elm_widget_data_get(obj);
367 Dialogue_Item *before_item, *item;
370 if (!wd || !subobj || !before || !wd->items) return NULL;
372 EINA_LIST_FOREACH(wd->items, l, before_item) {
373 if(before == before_item) {
374 if( !strcmp(item->location, "default") ) {
375 _change_item_bg(before_item, "bottom");
376 item = _create_item(obj, subobj, style, "top");
379 else if( !strcmp(item->location, "top") ) {
380 _change_item_bg(before_item, "middle");
381 item = _create_item(obj, subobj, style, "top");
384 else if( !strcmp(item->location, "middle") || !strcmp(item->location, "bottom") )
385 item = _create_item(obj, subobj, style, "middle");
387 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
388 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
398 * Remove an item from the dialogue group.
400 * @param obj dialoguegroup object
403 * @ingroup DialogueGroup
406 elm_dialoguegroup_remove(Dialogue_Item *item)
408 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
409 Dialogue_Item *current_item;
410 Widget_Data *wd = elm_widget_data_get(item->parent);
413 if (!wd || !wd->items || !item) return ;
415 EINA_LIST_FOREACH(wd->items, l, current_item) {
416 if (current_item == item) {
417 if (current_item->content){
418 evas_object_del(current_item->content);
419 current_item->content = NULL;
421 if (current_item->bg_layout){
422 evas_object_del(current_item->bg_layout);
423 current_item->bg_layout = NULL;
425 elm_box_unpack(wd->box, current_item->bg_layout);
426 wd->items = eina_list_remove(wd->items, current_item);
432 if (wd->num == 0) return;
435 current_item = eina_list_data_get(wd->items);
436 _change_item_bg(current_item, "default");
440 current_item = eina_list_data_get(wd->items);
441 _change_item_bg(current_item, "top");
442 current_item = eina_list_data_get( eina_list_last(wd->items) );
443 _change_item_bg(current_item, "bottom");
446 _sizing_eval(item->parent);
450 * Remove all items from the dialogue group.
452 * @param obj dialoguegroup object
454 * @ingroup DialogueGroup
457 elm_dialoguegroup_remove_all(Evas_Object *obj)
459 ELM_CHECK_WIDTYPE(obj, widtype);
466 * Set the title text of the dialogue group.
468 * @param obj dialoguegroup object
469 * @param title title text, if NULL title space will be disappeared
471 * @ingroup DialogueGroup
474 elm_dialoguegroup_title_set(Evas_Object *obj, const char *title)
476 ELM_CHECK_WIDTYPE(obj, widtype);
477 Widget_Data *wd = elm_widget_data_get(obj);
480 eina_stringshare_replace(&wd->title, title);
483 elm_box_unpack(wd->box, wd->title_layout);
485 if (!wd->title_layout) {
486 wd->title_layout = elm_layout_add(wd->parent);
487 elm_widget_sub_object_add(obj, wd->title_layout);
488 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "base", "title");
489 evas_object_size_hint_weight_set(wd->title_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
490 evas_object_size_hint_align_set(wd->title_layout, EVAS_HINT_FILL, 0.0);
491 evas_object_show(wd->title_layout);
493 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
494 elm_box_pack_start(wd->box, wd->title_layout);
498 * Get the title text of the dialogue group
500 * @param obj The dialoguegroup object
501 * @return The text title string in UTF-8
503 * @ingroup DialogueGroup
506 elm_dialoguegroup_title_get(Evas_Object *obj)
508 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
509 Widget_Data *wd = elm_widget_data_get(obj);
510 if (!wd) return NULL;
515 * Set whether the press effect will be shown or not
517 * @param obj The dialoguegroup object
518 * @param item Dialogue_Item pointer
519 * @param press If set as 1, press effect will be shown
521 * @ingroup DialogueGroup
524 elm_dialoguegroup_press_effect_set(Dialogue_Item *item, Eina_Bool press)
526 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
530 if(press == EINA_TRUE)
531 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
533 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
537 * Get the press effect state
539 * @param obj The dialoguegroup object
540 * @param item Dialogue_Item pointer
541 * @return 1 if press effect on, 0 if press effect off
543 * @ingroup DialogueGroup
546 elm_dialoguegroup_press_effect_get(Dialogue_Item *item)
548 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
549 if(!item) return EINA_FALSE;
555 * Get the conetent object from the specified dialogue item
557 * @param obj The dialoguegroup object
558 * @param item Dialogue_Item pointer
559 * @return content object
561 * @ingroup DialogueGroup
564 elm_dialoguegroup_item_content_get(Dialogue_Item *item)
566 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
567 if(!item) return EINA_FALSE;
569 return item->content;