win: Simplify modal legacy API and add test case

This fixes the modality of windows shown after setting
the flag.
This commit is contained in:
Jean-Philippe Andre 2016-11-22 17:59:33 +09:00
parent 0de72b44c1
commit 29e7d477b1
4 changed files with 90 additions and 27 deletions

View File

@ -836,6 +836,7 @@ bin/elementary/test_win_plug.c \
bin/elementary/test_win_state.c \
bin/elementary/test_win_wm_rotation.c \
bin/elementary/test_win_dialog.c \
bin/elementary/test_win_modal.c \
bin/elementary/test.h
bin_elementary_elementary_test_LDADD = @USE_ELEMENTARY_LIBS@

View File

@ -283,6 +283,7 @@ void test_dnd_multi_features(void *data, Evas_Object *obj, void *event_info);
void test_dnd_types(void *data, Evas_Object *obj, void *event_info);
void test_task_switcher(void *data, Evas_Object *obj, void *event_info);
void test_win_dialog(void *data, Evas_Object *obj, void *event_info);
void test_win_modal(void *data, Evas_Object *obj, void *event_info);
void test_box_disable(void *data, Evas_Object *obj, void *event_info);
void test_layout_disable(void *data, Evas_Object *obj, void *event_info);
@ -642,6 +643,7 @@ add_tests:
ADD_TEST(NULL, "Window / Background", "Window WM Rotation", test_win_wm_rotation);
ADD_TEST(NULL, "Window / Background", "Window Standard/Dialog", test_win_dialog);
ADD_TEST(NULL, "Window / Background", "Window Keygrab Set", test_win_keygrab);
ADD_TEST(NULL, "Window / Background", "Window Modal", test_win_modal);
//------------------------------//
ADD_TEST(NULL, "Images", "Icon", test_icon);

View File

@ -0,0 +1,78 @@
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#include <Elementary.h>
static Evas_Object *
_parent_win_get(Evas_Object *obj)
{
Evas_Object *parent = obj;
while ((parent = elm_object_parent_widget_get(obj)) != NULL)
obj = parent;
return obj;
}
static void
_close(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
evas_object_del(win);
}
void
test_win_modal(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
Evas_Object *parent_win, *win, *bg, *txt, *bx, *bt;
parent_win = _parent_win_get(obj);
win = elm_win_add(parent_win, "modal", ELM_WIN_BASIC);
elm_win_title_set(win, "Window Modal");
elm_win_autodel_set(win, EINA_TRUE);
bg = elm_bg_add(win);
elm_win_resize_object_add(win, bg);
evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(bg);
bx = elm_box_add(win);
elm_win_resize_object_add(win, bx);
evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(bx);
txt = elm_label_add(win);
elm_object_text_set(txt, "This is a modal window.<br>"
"It will block all inputs on all the other opened windows.");
evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_label_line_wrap_set(txt, ELM_WRAP_WORD);
elm_box_pack_end(bx, txt);
evas_object_show(txt);
bt = elm_button_add(win);
elm_object_text_set(bt, "Open another modal window");
evas_object_size_hint_align_set(bt, 0.5, 0.5);
evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
evas_object_smart_callback_add(bt, "clicked", test_win_modal, NULL);
elm_box_pack_end(bx, bt);
evas_object_show(bt);
bt = elm_button_add(win);
elm_object_text_set(bt, "Close");
evas_object_size_hint_align_set(bt, 0.5, 0.5);
evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
evas_object_smart_callback_add(bt, "clicked", _close, win);
elm_box_pack_end(bx, bt);
evas_object_show(bt);
/* make the window modal */
elm_win_modal_set(win, EINA_TRUE);
evas_object_resize(win, 250, 150);
evas_object_show(win);
}

View File

@ -2155,9 +2155,6 @@ _efl_ui_win_show(Eo *obj, Efl_Ui_Win_Data *sd)
return;
}
if (!evas_object_visible_get(obj)) do_eval = EINA_TRUE;
efl_gfx_visible_set(efl_super(obj, MY_CLASS), EINA_TRUE);
if ((sd->modal) && (!evas_object_visible_get(obj)))
{
const Eina_List *l;
@ -2165,6 +2162,9 @@ _efl_ui_win_show(Eo *obj, Efl_Ui_Win_Data *sd)
INCREMENT_MODALITY()
}
if (!evas_object_visible_get(obj)) do_eval = EINA_TRUE;
efl_gfx_visible_set(efl_super(obj, MY_CLASS), EINA_TRUE);
if (sd->deferred_resize_job)
_elm_win_resize_job(sd->obj);
evas_smart_objects_calculate(evas_object_evas_get(obj));
@ -7268,37 +7268,19 @@ elm_win_demand_attention_get(const Evas_Object *obj)
EAPI void
elm_win_modal_set(Evas_Object *obj, Eina_Bool modal)
{
ELM_WIN_CHECK(obj);
ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
Efl_Ui_Win_Modal_Mode modality;
if (sd->modal_count) return;
const Eina_List *l;
Evas_Object *current;
if ((modal) && (!sd->modal) && (evas_object_visible_get(obj)))
{
INCREMENT_MODALITY()
}
else if ((!modal) && (sd->modal) && (evas_object_visible_get(obj)))
{
DECREMENT_MODALITY()
}
sd->modal = modal;
TRAP(sd, modal_set, modal);
#ifdef HAVE_ELEMENTARY_X
_elm_win_xwin_update(sd);
#endif
modality = modal ? EFL_UI_WIN_MODAL_MODAL : EFL_UI_WIN_MODAL_NONE;
efl_ui_win_modal_set(obj, modality);
}
EAPI Eina_Bool
elm_win_modal_get(const Evas_Object *obj)
{
ELM_WIN_CHECK(obj) EINA_FALSE;
ELM_WIN_DATA_GET_OR_RETURN(obj, sd, EINA_FALSE);
Efl_Ui_Win_Modal_Mode modality;
return sd->modal;
modality = efl_ui_win_modal_get(obj);
return (modality != EFL_UI_WIN_MODAL_NONE);
}
EAPI void