1 #include <Elementary.h>
6 * @defgroup DialogueGroup DialogueGroup
9 * Using dialoguegroup, you can make a dialogue group.
15 Evas_Object *bg_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) {
112 evas_object_del(item->content);
113 item->content = 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);
131 if(item->press == EINA_TRUE)
132 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
134 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
137 static Dialogue_Item* _create_item(Evas_Object *obj, Evas_Object *subobj, const char *style)
139 Widget_Data *wd = elm_widget_data_get(obj);
142 if (!wd) return NULL;
144 item = ELM_NEW(Dialogue_Item);
146 item->content = subobj;
147 item->press = EINA_TRUE;
149 item->bg_layout = elm_layout_add(wd->parent);
150 elm_layout_theme_set(item->bg_layout, "dialoguegroup", "bg", style );
151 elm_object_style_set(item->bg_layout, style);
152 evas_object_size_hint_weight_set(item->bg_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
153 evas_object_size_hint_align_set(item->bg_layout, EVAS_HINT_FILL, 0.0);
154 evas_object_show(item->bg_layout);
156 elm_layout_content_set(item->bg_layout, "swallow", item->content);
161 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
167 * Add a new dialoguegroup to the parent.
169 * @param parent The parent object
170 * @return The new object or NULL if it cannot be created
172 * @ingroup DialogueGroup
174 EAPI Evas_Object *elm_dialoguegroup_add(Evas_Object *parent)
176 Evas_Object *obj = NULL;
177 Widget_Data *wd = NULL;
179 wd = ELM_NEW(Widget_Data);
180 wd->e = evas_object_evas_get(parent);
181 if (wd->e == NULL) return NULL;
182 obj = elm_widget_add(wd->e);
183 ELM_SET_WIDTYPE(widtype, "dialoguegroup");
184 elm_widget_type_set(obj, "dialoguegroup");
185 elm_widget_sub_object_add(parent, obj);
186 elm_widget_data_set(obj, wd);
187 elm_widget_del_hook_set(obj, _del_hook);
188 elm_widget_theme_hook_set(obj, _theme_hook);
193 wd->box = elm_box_add(parent);
194 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
195 evas_object_show(wd->box);
196 elm_widget_resize_object_set(obj, wd->box);
203 * Append an item to the dialogue group.
205 * @param obj dialoguegroup object
207 * @return Dialogue_Item pointer, just made by this function
209 * @ingroup DialogueGroup
212 elm_dialoguegroup_append(Evas_Object *obj, Evas_Object *subobj)
214 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
215 Widget_Data *wd = elm_widget_data_get(obj);
218 if (!wd || !subobj) return NULL;
221 item = _create_item(obj, subobj, "default");
222 elm_box_pack_end(wd->box, item->bg_layout);
223 wd->items = eina_list_append(wd->items, item);
228 item = eina_list_data_get(wd->items);
229 _change_item_bg(item, "top");
232 item = eina_list_data_get( eina_list_last(wd->items) );
233 _change_item_bg(item, "middle");
235 item = _create_item(obj, subobj, "bottom");
236 elm_box_pack_end(wd->box, item->bg_layout);
237 wd->items = eina_list_append(wd->items, item);
247 * Prepend an item to the dialogue group.
249 * @param obj dialoguegroup object
251 * @return Dialogue_Item pointer, just made by this function
253 * @ingroup DialogueGroup
256 elm_dialoguegroup_prepend(Evas_Object *obj, Evas_Object *subobj)
258 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
259 Widget_Data *wd = elm_widget_data_get(obj);
262 if (!wd || !subobj) return NULL;
265 item = _create_item(obj, subobj, "default");
267 elm_box_pack_after(wd->box, item->bg_layout, wd->title_layout);
269 elm_box_pack_start(wd->box, item->bg_layout);
270 wd->items = eina_list_prepend(wd->items, item);
275 item = eina_list_data_get(wd->items);
276 _change_item_bg(item, "bottom");
279 item = eina_list_data_get(wd->items);
280 _change_item_bg(item, "middle");
282 item = _create_item(obj, subobj, "top");
284 elm_box_pack_after(wd->box, item->bg_layout, wd->title_layout);
286 elm_box_pack_start(wd->box, item->bg_layout);
287 wd->items = eina_list_prepend(wd->items, item);
296 * Insert an item to the dialogue group just after the specified item.
298 * @param obj dialoguegroup object
300 * @param after specified item existing in the dialogue group
301 * @return Dialogue_Item pointer, just made by this function
303 * @ingroup DialogueGroup
306 elm_dialoguegroup_insert_after(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *after)
308 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
309 Widget_Data *wd = elm_widget_data_get(obj);
310 Dialogue_Item *after_item, *item;
314 if (!wd || !subobj || !after || !wd->items) return NULL;
316 EINA_LIST_FOREACH(wd->items, l, after_item) {
317 if(after == after_item) {
318 style = elm_object_style_get(after_item->bg_layout);
320 if( !strcmp(style, "default") ) {
321 _change_item_bg(after_item, "top");
322 item = _create_item(obj, subobj, "bottom");
324 else if( !strcmp(style, "top") || !strcmp(style, "middle") )
325 item = _create_item(obj, subobj, "middle");
326 else if( !strcmp(style, "bottom") ) {
327 _change_item_bg(after_item, "middle");
328 item = _create_item(obj, subobj, "bottom");
331 elm_box_pack_after(wd->box, item->bg_layout, after_item->bg_layout);
332 wd->items = eina_list_append_relative(wd->items, item, after_item);
342 * Insert an item to the dialogue group just before the specified item.
344 * @param obj dialoguegroup object
346 * @param before specified item existing in the dialogue group
347 * @return Dialogue_Item pointer, just made by this function
349 * @ingroup DialogueGroup
352 elm_dialoguegroup_insert_before(Evas_Object *obj, Evas_Object *subobj, Dialogue_Item *before)
354 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
355 Widget_Data *wd = elm_widget_data_get(obj);
356 Dialogue_Item *before_item, *item;
360 if (!wd || !subobj || !before || !wd->items) return NULL;
362 EINA_LIST_FOREACH(wd->items, l, before_item) {
363 if(before == before_item) {
364 style = elm_object_style_get(before_item->bg_layout);
366 if( !strcmp(style, "default") ) {
367 _change_item_bg(before_item, "bottom");
368 item = _create_item(obj, subobj, "top");
371 else if( !strcmp(style, "top") ) {
372 _change_item_bg(before_item, "middle");
373 item = _create_item(obj, subobj, "top");
376 else if( !strcmp(style, "middle") || !strcmp(style, "bottom") )
377 item = _create_item(obj, subobj, "middle");
379 elm_box_pack_before(wd->box, item->bg_layout, before_item->bg_layout);
380 wd->items = eina_list_prepend_relative(wd->items, item, before_item);
390 * Remove an item from the dialogue group.
392 * @param obj dialoguegroup object
395 * @ingroup DialogueGroup
398 elm_dialoguegroup_remove(Dialogue_Item *item)
400 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
401 Dialogue_Item *current_item;
402 Widget_Data *wd = elm_widget_data_get(item->parent);
405 if (!wd || !wd->items || !item) return ;
407 EINA_LIST_FOREACH(wd->items, l, current_item) {
408 if (current_item == item) {
409 if (current_item->content){
410 evas_object_del(current_item->content);
411 current_item->content = NULL;
413 if (current_item->bg_layout){
414 evas_object_del(current_item->bg_layout);
415 current_item->bg_layout = NULL;
417 elm_box_unpack(wd->box, current_item->bg_layout);
418 wd->items = eina_list_remove(wd->items, current_item);
424 if (wd->num == 0) return;
427 current_item = eina_list_data_get(wd->items);
428 _change_item_bg(current_item, "default");
432 current_item = eina_list_data_get(wd->items);
433 _change_item_bg(current_item, "top");
434 current_item = eina_list_data_get( eina_list_last(wd->items) );
435 _change_item_bg(current_item, "bottom");
438 _sizing_eval(item->parent);
442 * Remove all items from the dialogue group.
444 * @param obj dialoguegroup object
446 * @ingroup DialogueGroup
449 elm_dialoguegroup_remove_all(Evas_Object *obj)
451 ELM_CHECK_WIDTYPE(obj, widtype);
458 * Set the title text of the dialogue group.
460 * @param obj dialoguegroup object
461 * @param title title text, if NULL title space will be disappeared
463 * @ingroup DialogueGroup
466 elm_dialoguegroup_title_set(Evas_Object *obj, const char *title)
468 ELM_CHECK_WIDTYPE(obj, widtype);
469 Widget_Data *wd = elm_widget_data_get(obj);
472 eina_stringshare_replace(&wd->title, title);
475 elm_box_unpack(wd->box, wd->title_layout);
477 if (!wd->title_layout) {
478 wd->title_layout = elm_layout_add(wd->parent);
479 elm_widget_sub_object_add(obj, wd->title_layout);
480 elm_layout_theme_set(wd->title_layout, "dialoguegroup", "base", "title");
481 evas_object_size_hint_weight_set(wd->title_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
482 evas_object_size_hint_align_set(wd->title_layout, EVAS_HINT_FILL, 0.0);
483 evas_object_show(wd->title_layout);
485 edje_object_part_text_set(elm_layout_edje_get(wd->title_layout), "text", title);
486 elm_box_pack_start(wd->box, wd->title_layout);
490 * Get the title text of the dialogue group
492 * @param obj The dialoguegroup object
493 * @return The text title string in UTF-8
495 * @ingroup DialogueGroup
498 elm_dialoguegroup_title_get(Evas_Object *obj)
500 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
501 Widget_Data *wd = elm_widget_data_get(obj);
502 if (!wd) return NULL;
507 * Set whether the press effect will be shown or not
509 * @param obj The dialoguegroup object
510 * @param item Dialogue_Item pointer
511 * @param press If set as 1, press effect will be shown
513 * @ingroup DialogueGroup
516 elm_dialoguegroup_press_effect_set(Dialogue_Item *item, Eina_Bool press)
518 ELM_CHECK_WIDTYPE(item->parent, widtype) ;
522 if(press == EINA_TRUE)
523 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,on", "elm");
525 edje_object_signal_emit(elm_layout_edje_get(item->bg_layout), "elm,state,press,off", "elm");
529 * Get the press effect state
531 * @param obj The dialoguegroup object
532 * @param item Dialogue_Item pointer
533 * @return 1 if press effect on, 0 if press effect off
535 * @ingroup DialogueGroup
538 elm_dialoguegroup_press_effect_get(Dialogue_Item *item)
540 ELM_CHECK_WIDTYPE(item->parent, widtype) EINA_FALSE;
541 if(!item) return EINA_FALSE;