1 #include <Elementary.h>
6 * @addtogroup DialogueGroup DialogueGroup
8 * Using dialoguegroup, you can make a dialogue group.
11 typedef struct _Dialogue_Item Dialogue_Item;
15 Evas_Object *bg_layout;
16 Evas_Object *content_layout;
20 typedef struct _Widget_Data Widget_Data;
31 static void _del_hook(Evas_Object *obj);
32 static void _theme_hook(Evas_Object *obj);
33 static void _sizing_eval(Evas_Object *obj);
34 static void _disable_hook(Evas_Object *obj);
36 static void _remove_all(Evas_Object *obj);
37 static void _change_item_bg(Dialogue_Item *item, const char *style);
38 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, const char *style);
42 _del_hook(Evas_Object *obj)
44 Widget_Data *wd = elm_widget_data_get(obj);
52 evas_object_del(wd->box);
61 _theme_hook(Evas_Object *obj)
63 Widget_Data *wd = elm_widget_data_get(obj);
69 EINA_LIST_FOREACH(wd->items, l, item)
70 _change_item_bg( item, elm_widget_style_get(item->bg_layout) );
76 _disable_hook(Evas_Object *obj)
82 _sizing_eval(Evas_Object *obj)
84 Widget_Data *wd = elm_widget_data_get(obj);
87 Evas_Coord minw, minh, maxw, maxh;
90 evas_object_size_hint_min_get(wd->box, &minw, &minh);
91 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
92 evas_object_size_hint_min_set(obj, minw, minh);
93 evas_object_size_hint_max_set(obj, maxw, maxh);
96 static void _remove_all(Evas_Object *obj)
98 Widget_Data *wd = elm_widget_data_get(obj);
106 EINA_LIST_FREE(wd->items, item) {
107 if (item->content_layout){
108 evas_object_del(item->content_layout);
109 item->content_layout = NULL;
111 if (item->bg_layout){
112 evas_object_del(item->bg_layout);
113 item->bg_layout = NULL;
120 static void _change_item_bg(Dialogue_Item *item, const char *style)
122 if ( ! item ) return;
124 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "bg", style);
125 elm_object_style_set(item->bg_layout, style);
126 elm_layout_content_set(item->bg_layout, "swallow", item->content_layout);
129 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, const char *style)
131 Widget_Data *wd = elm_widget_data_get(obj);
134 if ( ! wd ) return NULL;
136 item = ELM_NEW(Dialogue_Item);
138 item->content_layout = subobj;
140 item->bg_layout = elm_layout_add(wd->parent);
141 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "bg", style );
142 elm_object_style_set(item->bg_layout, style);
143 evas_object_size_hint_weight_set(item->bg_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
144 evas_object_size_hint_align_set(item->bg_layout, EVAS_HINT_FILL, 0.0);
145 evas_object_show(item->bg_layout);
147 elm_layout_content_set(item->bg_layout, "swallow", item->content_layout);
152 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
158 * Add a new dialoguegroup to the parent.
160 * @param parent The parent object
161 * @return The new object or NULL if it cannot be created
163 * @ingroup DialogueGroup
165 EAPI Evas_Object *elm_dialoguegroup_add(Evas_Object *parent)
167 Evas_Object *obj = NULL;
168 Widget_Data *wd = NULL;
170 wd = ELM_NEW(Widget_Data);
171 wd->e = evas_object_evas_get(parent);
172 if (wd->e == NULL) return NULL;
173 obj = elm_widget_add(wd->e);
174 elm_widget_type_set(obj, "dialoguegroup");
175 elm_widget_sub_object_add(parent, obj);
176 elm_widget_data_set(obj, wd);
177 elm_widget_del_hook_set(obj, _del_hook);
178 elm_widget_theme_hook_set(obj, _theme_hook);
183 wd->box = elm_box_add(parent);
184 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
185 evas_object_show(wd->box);
186 elm_widget_resize_object_set(obj, wd->box);
193 * Append an item to the dialogue group.
195 * @param obj dialoguegroup object
198 * @ingroup DialogueGroup
201 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj)
203 Widget_Data *wd = elm_widget_data_get(obj);
206 if ( ! wd || ! subobj ) return;
209 item = _create_item(obj, subobj, "default");
210 elm_box_pack_end(wd->box, item->bg_layout);
211 wd->items = eina_list_append(wd->items, item);
215 if ( wd->num == 1 ) {
216 item = eina_list_data_get(wd->items);
217 _change_item_bg(item, "top");
220 item = eina_list_data_get( eina_list_last(wd->items) );
221 _change_item_bg(item, "middle");
223 item = _create_item(obj, subobj, "bottom");
224 elm_box_pack_end(wd->box, item->bg_layout);
225 wd->items = eina_list_append(wd->items, item);
234 * Prepend an item to the dialogue group.
236 * @param obj dialoguegroup object
239 * @ingroup DialogueGroup
242 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj)
244 Widget_Data *wd = elm_widget_data_get(obj);
247 if ( ! wd || ! subobj ) return;
250 item = _create_item(obj, subobj, "default");
251 elm_box_pack_start(wd->box, item->bg_layout);
252 wd->items = eina_list_prepend(wd->items, item);
256 if ( wd->num == 1 ) {
257 item = eina_list_data_get(wd->items);
258 _change_item_bg(item, "bottom");
261 item = eina_list_data_get( wd->items );
262 _change_item_bg(item, "middle");
264 item = _create_item(obj, subobj, "top");
265 elm_box_pack_start(wd->box, item->bg_layout);
266 wd->items = eina_list_prepend(wd->items, item);
274 * Insert an item to the dialogue group just after the specified item.
276 * @param obj dialoguegroup object
278 * @param after specified item existing in the dialogue group
280 * @ingroup DialogueGroup
283 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Evas_Object *after)
285 Widget_Data *wd = elm_widget_data_get(obj);
286 Dialogue_Item *after_item, *item;
290 if ( !wd || !subobj || !after || !wd->items)
293 EINA_LIST_FOREACH(wd->items, l, after_item) {
294 if( after == after_item->content_layout ) {
295 style = elm_object_style_get(after_item->bg_layout);
297 if( !strcmp(style, "default") ) {
298 _change_item_bg(after_item, "top");
299 item = _create_item(obj, subobj, "bottom");
302 else if( !strcmp(style, "top") || !strcmp(style, "middle") )
303 item = _create_item(obj, subobj, "middle");
305 else if( !strcmp(style, "bottom") ) {
306 _change_item_bg(after_item, "middle");
307 item = _create_item(obj, subobj, "bottom");
310 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
311 wd->items = eina_list_append_relative(wd->items, item, after_item);
321 * Insert an item to the dialogue group just before the specified item.
323 * @param obj dialoguegroup object
325 * @param before specified item existing in the dialogue group
327 * @ingroup DialogueGroup
330 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Evas_Object *before)
332 Widget_Data *wd = elm_widget_data_get(obj);
333 Dialogue_Item *before_item, *item;
337 if ( !wd || !subobj || !before || !wd->items)
340 EINA_LIST_FOREACH(wd->items, l, before_item) {
341 if( before == before_item->content_layout ) {
342 style = elm_object_style_get(before_item->bg_layout);
344 if( !strcmp(style, "default") ) {
345 _change_item_bg(before_item, "bottom");
346 item = _create_item(obj, subobj, "top");
349 else if( !strcmp(style, "top") ) {
350 _change_item_bg(before_item, "middle");
351 item = _create_item(obj, subobj, "top");
354 else if( !strcmp(style, "middle") || !strcmp(style, "bottom") )
355 item = _create_item(obj, subobj, "middle");
357 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
358 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
368 * Remove an item from the dialogue group.
370 * @param obj dialoguegroup object
373 * @ingroup DialogueGroup
376 elm_dialoguegroup_remove(Evas_Object *obj, Evas_Object *subobj)
378 Widget_Data *wd = elm_widget_data_get(obj);
382 if ( !wd || !subobj || !wd->items)
385 EINA_LIST_FOREACH(wd->items, l, item) {
386 if (subobj == item->content_layout) {
387 if (item->content_layout){
388 evas_object_del(item->content_layout);
389 item->content_layout = NULL;
391 if (item->bg_layout){
392 evas_object_del(item->bg_layout);
393 item->bg_layout = NULL;
395 elm_box_unpack(wd->box, item->bg_layout);
396 wd->items = eina_list_remove(wd->items, item);
405 if ( wd->num == 1 ) {
406 item = eina_list_data_get(wd->items);
407 _change_item_bg(item, "default");
411 item = eina_list_data_get(wd->items);
412 _change_item_bg(item, "top");
413 item = eina_list_data_get( eina_list_last(wd->items) );
414 _change_item_bg(item, "bottom");
421 * Remove all items from the dialogue group.
423 * @param obj dialoguegroup object
425 * @ingroup DialogueGroup
428 elm_dialoguegroup_remove_all(Evas_Object *obj)