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;
32 static void _del_hook(Evas_Object *obj);
33 static void _theme_hook(Evas_Object *obj);
34 static void _sizing_eval(Evas_Object *obj);
35 static void _disable_hook(Evas_Object *obj);
37 static void _remove_all(Evas_Object *obj);
38 static void _change_item_bg(Dialogue_Item *item, const char *style);
39 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, const char *style);
43 _del_hook(Evas_Object *obj)
45 Widget_Data *wd = elm_widget_data_get(obj);
53 evas_object_del(wd->box);
62 _theme_hook(Evas_Object *obj)
64 Widget_Data *wd = elm_widget_data_get(obj);
70 EINA_LIST_FOREACH(wd->items, l, item)
71 _change_item_bg( item, elm_widget_style_get(item->bg_layout) );
77 _disable_hook(Evas_Object *obj)
83 _sizing_eval(Evas_Object *obj)
85 Widget_Data *wd = elm_widget_data_get(obj);
88 Evas_Coord minw, minh, maxw, maxh;
91 evas_object_size_hint_min_get(wd->box, &minw, &minh);
92 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
93 evas_object_size_hint_min_set(obj, minw, minh);
94 evas_object_size_hint_max_set(obj, maxw, maxh);
97 static void _remove_all(Evas_Object *obj)
99 Widget_Data *wd = elm_widget_data_get(obj);
107 EINA_LIST_FREE(wd->items, item) {
108 if (item->content_layout){
109 evas_object_del(item->content_layout);
110 item->content_layout = NULL;
112 if (item->bg_layout){
113 evas_object_del(item->bg_layout);
114 item->bg_layout = NULL;
121 static void _change_item_bg(Dialogue_Item *item, const char *style)
123 if ( ! item ) return;
125 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "bg", style);
126 elm_object_style_set(item->bg_layout, style);
127 elm_layout_content_set(item->bg_layout, "swallow", item->content_layout);
130 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, const char *style)
132 Widget_Data *wd = elm_widget_data_get(obj);
135 if ( ! wd ) return NULL;
137 item = ELM_NEW(Dialogue_Item);
139 item->content_layout = subobj;
141 item->bg_layout = elm_layout_add(wd->parent);
142 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "bg", style );
143 elm_object_style_set(item->bg_layout, style);
144 evas_object_size_hint_weight_set(item->bg_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
145 evas_object_size_hint_align_set(item->bg_layout, EVAS_HINT_FILL, 0.0);
146 evas_object_show(item->bg_layout);
148 elm_layout_content_set(item->bg_layout, "swallow", item->content_layout);
153 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
159 * Add a new dialoguegroup to the parent.
161 * @param parent The parent object
162 * @return The new object or NULL if it cannot be created
164 * @ingroup DialogueGroup
166 EAPI Evas_Object *elm_dialoguegroup_add(Evas_Object *parent)
168 Evas_Object *obj = NULL;
169 Widget_Data *wd = NULL;
171 wd = ELM_NEW(Widget_Data);
172 wd->e = evas_object_evas_get(parent);
173 if (wd->e == NULL) return NULL;
174 obj = elm_widget_add(wd->e);
175 elm_widget_type_set(obj, "dialoguegroup");
176 elm_widget_sub_object_add(parent, obj);
177 elm_widget_data_set(obj, wd);
178 elm_widget_del_hook_set(obj, _del_hook);
179 elm_widget_theme_hook_set(obj, _theme_hook);
184 wd->box = elm_box_add(parent);
185 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
186 evas_object_show(wd->box);
187 elm_widget_resize_object_set(obj, wd->box);
194 * Append an item to the dialogue group.
196 * @param obj dialoguegroup object
199 * @ingroup DialogueGroup
202 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj)
204 Widget_Data *wd = elm_widget_data_get(obj);
207 if ( ! wd || ! subobj ) return;
210 item = _create_item(obj, subobj, "default");
211 elm_box_pack_end(wd->box, item->bg_layout);
212 wd->items = eina_list_append(wd->items, item);
216 if ( wd->num == 1 ) {
217 item = eina_list_data_get(wd->items);
218 _change_item_bg(item, "top");
221 item = eina_list_data_get( eina_list_last(wd->items) );
222 _change_item_bg(item, "middle");
224 item = _create_item(obj, subobj, "bottom");
225 elm_box_pack_end(wd->box, item->bg_layout);
226 wd->items = eina_list_append(wd->items, item);
235 * Prepend an item to the dialogue group.
237 * @param obj dialoguegroup object
240 * @ingroup DialogueGroup
243 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj)
245 Widget_Data *wd = elm_widget_data_get(obj);
248 if ( ! wd || ! subobj ) return;
251 item = _create_item(obj, subobj, "default");
252 elm_box_pack_start(wd->box, item->bg_layout);
253 wd->items = eina_list_prepend(wd->items, item);
257 if ( wd->num == 1 ) {
258 item = eina_list_data_get(wd->items);
259 _change_item_bg(item, "bottom");
262 item = eina_list_data_get( wd->items );
263 _change_item_bg(item, "middle");
265 item = _create_item(obj, subobj, "top");
266 elm_box_pack_start(wd->box, item->bg_layout);
267 wd->items = eina_list_prepend(wd->items, item);
275 * Insert an item to the dialogue group just after the specified item.
277 * @param obj dialoguegroup object
279 * @param after specified item existing in the dialogue group
281 * @ingroup DialogueGroup
284 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Evas_Object *after)
286 Widget_Data *wd = elm_widget_data_get(obj);
287 Dialogue_Item *after_item, *item;
291 if ( !wd || !subobj || !after || !wd->items)
294 EINA_LIST_FOREACH(wd->items, l, after_item) {
295 if( after == after_item->content_layout ) {
296 style = elm_object_style_get(after_item->bg_layout);
298 if( !strcmp(style, "default") ) {
299 _change_item_bg(after_item, "top");
300 item = _create_item(obj, subobj, "bottom");
303 else if( !strcmp(style, "top") || !strcmp(style, "middle") )
304 item = _create_item(obj, subobj, "middle");
306 else if( !strcmp(style, "bottom") ) {
307 _change_item_bg(after_item, "middle");
308 item = _create_item(obj, subobj, "bottom");
311 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
312 wd->items = eina_list_append_relative(wd->items, item, after_item);
322 * Insert an item to the dialogue group just before the specified item.
324 * @param obj dialoguegroup object
326 * @param before specified item existing in the dialogue group
328 * @ingroup DialogueGroup
331 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Evas_Object *before)
333 Widget_Data *wd = elm_widget_data_get(obj);
334 Dialogue_Item *before_item, *item;
338 if ( !wd || !subobj || !before || !wd->items)
341 EINA_LIST_FOREACH(wd->items, l, before_item) {
342 if( before == before_item->content_layout ) {
343 style = elm_object_style_get(before_item->bg_layout);
345 if( !strcmp(style, "default") ) {
346 _change_item_bg(before_item, "bottom");
347 item = _create_item(obj, subobj, "top");
350 else if( !strcmp(style, "top") ) {
351 _change_item_bg(before_item, "middle");
352 item = _create_item(obj, subobj, "top");
355 else if( !strcmp(style, "middle") || !strcmp(style, "bottom") )
356 item = _create_item(obj, subobj, "middle");
358 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
359 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
369 * Remove an item from the dialogue group.
371 * @param obj dialoguegroup object
374 * @ingroup DialogueGroup
377 elm_dialoguegroup_remove(Evas_Object *obj, Evas_Object *subobj)
379 Widget_Data *wd = elm_widget_data_get(obj);
383 if ( !wd || !subobj || !wd->items)
386 EINA_LIST_FOREACH(wd->items, l, item) {
387 if (subobj == item->content_layout) {
388 if (item->content_layout){
389 evas_object_del(item->content_layout);
390 item->content_layout = NULL;
392 if (item->bg_layout){
393 evas_object_del(item->bg_layout);
394 item->bg_layout = NULL;
396 elm_box_unpack(wd->box, item->bg_layout);
397 wd->items = eina_list_remove(wd->items, item);
406 if ( wd->num == 1 ) {
407 item = eina_list_data_get(wd->items);
408 _change_item_bg(item, "default");
412 item = eina_list_data_get(wd->items);
413 _change_item_bg(item, "top");
414 item = eina_list_data_get( eina_list_last(wd->items) );
415 _change_item_bg(item, "bottom");
422 * Remove all items from the dialogue group.
424 * @param obj dialoguegroup object
426 * @ingroup DialogueGroup
429 elm_dialoguegroup_remove_all(Evas_Object *obj)