1 #include <Elementary.h>
6 * @defgroup DialogueGroup DialogueGroup
9 * Using dialoguegroup, you can make a dialogue group.
12 typedef struct _Dialogue_Item Dialogue_Item;
16 Evas_Object *bg_layout;
17 Evas_Object *content_layout;
21 typedef struct _Widget_Data Widget_Data;
27 Evas_Object *title_layout;
33 static const char*widtype = NULL;
35 static void _del_hook(Evas_Object *obj);
36 static void _theme_hook(Evas_Object *obj);
37 static void _sizing_eval(Evas_Object *obj);
38 static void _disable_hook(Evas_Object *obj);
40 static void _remove_all(Evas_Object *obj);
41 static void _change_item_bg(Dialogue_Item *item, const char *style);
42 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, const char *style);
46 _del_hook(Evas_Object *obj)
48 Widget_Data *wd = elm_widget_data_get(obj);
51 if (wd->title) eina_stringshare_del(wd->title);
56 evas_object_del(wd->box);
65 _theme_hook(Evas_Object *obj)
67 Widget_Data *wd = elm_widget_data_get(obj);
73 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "base", "title");
74 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", wd->title);
76 EINA_LIST_FOREACH(wd->items, l, item)
77 _change_item_bg( item, elm_widget_style_get(item->bg_layout) );
82 _disable_hook(Evas_Object *obj)
88 _sizing_eval(Evas_Object *obj)
90 Widget_Data *wd = elm_widget_data_get(obj);
91 Evas_Coord minw, minh, maxw, maxh;
94 evas_object_size_hint_min_get(wd->box, &minw, &minh);
95 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
96 evas_object_size_hint_min_set(obj, minw, minh);
97 evas_object_size_hint_max_set(obj, maxw, maxh);
100 static void _remove_all(Evas_Object *obj)
102 Widget_Data *wd = elm_widget_data_get(obj);
110 EINA_LIST_FREE(wd->items, item) {
111 if (item->content_layout){
112 evas_object_del(item->content_layout);
113 item->content_layout = NULL;
115 if (item->bg_layout){
116 evas_object_del(item->bg_layout);
117 item->bg_layout = NULL;
124 static void _change_item_bg(Dialogue_Item *item, const char *style)
128 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "bg", style);
129 elm_object_style_set(item->bg_layout, style);
130 elm_layout_content_set(item->bg_layout, "swallow", item->content_layout);
133 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, const char *style)
135 Widget_Data *wd = elm_widget_data_get(obj);
138 if (!wd) return NULL;
140 item = ELM_NEW(Dialogue_Item);
142 item->content_layout = subobj;
144 item->bg_layout = elm_layout_add(wd->parent);
145 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "bg", style );
146 elm_object_style_set(item->bg_layout, style);
147 evas_object_size_hint_weight_set(item->bg_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
148 evas_object_size_hint_align_set(item->bg_layout, EVAS_HINT_FILL, 0.0);
149 evas_object_show(item->bg_layout);
151 elm_layout_content_set(item->bg_layout, "swallow", item->content_layout);
156 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
162 * Add a new dialoguegroup to the parent.
164 * @param parent The parent object
165 * @return The new object or NULL if it cannot be created
167 * @ingroup DialogueGroup
169 EAPI Evas_Object *elm_dialoguegroup_add(Evas_Object *parent)
171 Evas_Object *obj = NULL;
172 Widget_Data *wd = NULL;
174 wd = ELM_NEW(Widget_Data);
175 wd->e = evas_object_evas_get(parent);
176 if (wd->e == NULL) return NULL;
177 obj = elm_widget_add(wd->e);
178 ELM_SET_WIDTYPE(widtype, "dialoguegroup");
179 elm_widget_type_set(obj, "dialoguegroup");
180 elm_widget_sub_object_add(parent, obj);
181 elm_widget_data_set(obj, wd);
182 elm_widget_del_hook_set(obj, _del_hook);
183 elm_widget_theme_hook_set(obj, _theme_hook);
188 wd->box = elm_box_add(parent);
189 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
190 evas_object_show(wd->box);
191 elm_widget_resize_object_set(obj, wd->box);
198 * Append an item to the dialogue group.
200 * @param obj dialoguegroup object
203 * @ingroup DialogueGroup
206 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj)
208 ELM_CHECK_WIDTYPE(obj, widtype);
209 Widget_Data *wd = elm_widget_data_get(obj);
212 if (!wd || !subobj) return;
215 item = _create_item(obj, subobj, "default");
216 elm_box_pack_end(wd->box, item->bg_layout);
217 wd->items = eina_list_append(wd->items, item);
222 item = eina_list_data_get(wd->items);
223 _change_item_bg(item, "top");
226 item = eina_list_data_get( eina_list_last(wd->items) );
227 _change_item_bg(item, "middle");
229 item = _create_item(obj, subobj, "bottom");
230 elm_box_pack_end(wd->box, item->bg_layout);
231 wd->items = eina_list_append(wd->items, item);
240 * Prepend an item to the dialogue group.
242 * @param obj dialoguegroup object
245 * @ingroup DialogueGroup
248 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj)
250 ELM_CHECK_WIDTYPE(obj, widtype);
251 Widget_Data *wd = elm_widget_data_get(obj);
254 if (!wd || !subobj) return;
257 item = _create_item(obj, subobj, "default");
259 elm_box_pack_after(wd->box, item->bg_layout, wd->title_layout);
261 elm_box_pack_start(wd->box, item->bg_layout);
262 wd->items = eina_list_prepend(wd->items, item);
267 item = eina_list_data_get(wd->items);
268 _change_item_bg(item, "bottom");
271 item = eina_list_data_get(wd->items);
272 _change_item_bg(item, "middle");
274 item = _create_item(obj, subobj, "top");
276 elm_box_pack_after(wd->box, item->bg_layout, wd->title_layout);
278 elm_box_pack_start(wd->box, item->bg_layout);
279 wd->items = eina_list_prepend(wd->items, item);
287 * Insert an item to the dialogue group just after the specified item.
289 * @param obj dialoguegroup object
291 * @param after specified item existing in the dialogue group
293 * @ingroup DialogueGroup
296 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Evas_Object *after)
298 ELM_CHECK_WIDTYPE(obj, widtype);
299 Widget_Data *wd = elm_widget_data_get(obj);
300 Dialogue_Item *after_item, *item;
304 if (!wd || !subobj || !after || !wd->items) return ;
306 EINA_LIST_FOREACH(wd->items, l, after_item) {
307 if( after == after_item->content_layout ) {
308 style = elm_object_style_get(after_item->bg_layout);
310 if( !strcmp(style, "default") ) {
311 _change_item_bg(after_item, "top");
312 item = _create_item(obj, subobj, "bottom");
314 else if( !strcmp(style, "top") || !strcmp(style, "middle") )
315 item = _create_item(obj, subobj, "middle");
316 else if( !strcmp(style, "bottom") ) {
317 _change_item_bg(after_item, "middle");
318 item = _create_item(obj, subobj, "bottom");
321 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
322 wd->items = eina_list_append_relative(wd->items, item, after_item);
332 * Insert an item to the dialogue group just before the specified item.
334 * @param obj dialoguegroup object
336 * @param before specified item existing in the dialogue group
338 * @ingroup DialogueGroup
341 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Evas_Object *before)
343 ELM_CHECK_WIDTYPE(obj, widtype);
344 Widget_Data *wd = elm_widget_data_get(obj);
345 Dialogue_Item *before_item, *item;
349 if (!wd || !subobj || !before || !wd->items) return ;
351 EINA_LIST_FOREACH(wd->items, l, before_item) {
352 if( before == before_item->content_layout ) {
353 style = elm_object_style_get(before_item->bg_layout);
355 if( !strcmp(style, "default") ) {
356 _change_item_bg(before_item, "bottom");
357 item = _create_item(obj, subobj, "top");
360 else if( !strcmp(style, "top") ) {
361 _change_item_bg(before_item, "middle");
362 item = _create_item(obj, subobj, "top");
365 else if( !strcmp(style, "middle") || !strcmp(style, "bottom") )
366 item = _create_item(obj, subobj, "middle");
368 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
369 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
379 * Remove an item from the dialogue group.
381 * @param obj dialoguegroup object
384 * @ingroup DialogueGroup
387 elm_dialoguegroup_remove(Evas_Object *obj, Evas_Object *subobj)
389 ELM_CHECK_WIDTYPE(obj, widtype);
390 Widget_Data *wd = elm_widget_data_get(obj);
394 if (!wd || !subobj || !wd->items) return ;
396 EINA_LIST_FOREACH(wd->items, l, item) {
397 if (subobj == item->content_layout) {
398 if (item->content_layout){
399 evas_object_del(item->content_layout);
400 item->content_layout = NULL;
402 if (item->bg_layout){
403 evas_object_del(item->bg_layout);
404 item->bg_layout = NULL;
406 elm_box_unpack(wd->box, item->bg_layout);
407 wd->items = eina_list_remove(wd->items, item);
413 if (wd->num == 0) return;
416 item = eina_list_data_get(wd->items);
417 _change_item_bg(item, "default");
421 item = eina_list_data_get(wd->items);
422 _change_item_bg(item, "top");
423 item = eina_list_data_get( eina_list_last(wd->items) );
424 _change_item_bg(item, "bottom");
431 * Remove all items from the dialogue group.
433 * @param obj dialoguegroup object
435 * @ingroup DialogueGroup
438 elm_dialoguegroup_remove_all(Evas_Object *obj)
440 ELM_CHECK_WIDTYPE(obj, widtype);
447 * Set the title text of the dialogue group.
449 * @param obj dialoguegroup object
450 * @param title title text, if NULL title space will be disappeared
452 * @ingroup DialogueGroup
455 elm_dialoguegroup_title_set(Evas_Object *obj, const char *title)
457 ELM_CHECK_WIDTYPE(obj, widtype);
458 Widget_Data *wd = elm_widget_data_get(obj);
461 eina_stringshare_replace(&wd->title, title);
464 elm_box_unpack(wd->box, wd->title_layout);
466 if (!wd->title_layout) {
467 wd->title_layout = elm_layout_add(wd->parent);
468 elm_widget_sub_object_add(obj, wd->title_layout);
469 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "base", "title");
470 evas_object_size_hint_weight_set(wd->title_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
471 evas_object_size_hint_align_set(wd->title_layout, EVAS_HINT_FILL, 0.0);
472 evas_object_show(wd->title_layout);
474 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
475 elm_box_pack_start(wd->box, wd->title_layout);
479 * Get the title text of the dialogue group
481 * @param obj The dialoguegroup object
482 * @return The text title string in UTF-8
487 elm_dialoguegroup_title_get(Evas_Object *obj)
489 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
490 Widget_Data *wd = elm_widget_data_get(obj);
491 if (!wd) return NULL;