From 0c142462a1b928f88589612333c695f80cc09a51 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Andre Date: Fri, 10 Nov 2017 16:50:01 +0900 Subject: [PATCH] win: Move autodel to C only Note: this is C only, not legacy only. The problem is that bindings will hold a strong reference to the window, which will then die "under the rug" if autodel is enabled. This then leads to at least ERR if not crashes. Note: elm_policy needs to support autodel and quit on last del only for C applications. Bindings will require some other mechanism that doesn't break all assumptions wrt. references. --- .../elementary/toolbar_cxx_example_01.cc | 2 - src/lib/elementary/efl_ui_win.c | 12 +++-- src/lib/elementary/efl_ui_win.eo | 51 +++++-------------- src/lib/elementary/elm_win.h | 2 +- src/lib/elementary/elm_win_eo.h | 48 +++++++++++++++++ src/lib/elementary/elm_win_legacy.h | 33 ++++++++++++ 6 files changed, 103 insertions(+), 45 deletions(-) diff --git a/src/examples/elementary/toolbar_cxx_example_01.cc b/src/examples/elementary/toolbar_cxx_example_01.cc index 12548e046d..f76f959589 100644 --- a/src/examples/elementary/toolbar_cxx_example_01.cc +++ b/src/examples/elementary/toolbar_cxx_example_01.cc @@ -25,8 +25,6 @@ elm_main(int argc, char* argv[]) win_1.type_set(EFL_UI_WIN_BASIC); }); - win_1.autodel_set(true); - #if 0 win_1.eo_cxx::efl::Gfx::size_set({320, 300}); diff --git a/src/lib/elementary/efl_ui_win.c b/src/lib/elementary/efl_ui_win.c index 812e1645d7..145dc027e1 100644 --- a/src/lib/elementary/efl_ui_win.c +++ b/src/lib/elementary/efl_ui_win.c @@ -5540,15 +5540,19 @@ _efl_ui_win_icon_object_get(Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *sd) return sd->icon; } -EOLIAN static void -_efl_ui_win_autodel_set(Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *sd, Eina_Bool autodel) +/* Only for C API */ +EAPI void +elm_win_autodel_set(Eo *obj, Eina_Bool autodel) { + ELM_WIN_DATA_GET_OR_RETURN(obj, sd); sd->autodel = autodel; } -EOLIAN static Eina_Bool -_efl_ui_win_autodel_get(Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *sd) +EAPI Eina_Bool +elm_win_autodel_get(const Eo *obj) { + Efl_Ui_Win_Data *sd = efl_data_scope_safe_get(obj, MY_CLASS); + if (!sd) return EINA_FALSE; return sd->autodel; } diff --git a/src/lib/elementary/efl_ui_win.eo b/src/lib/elementary/efl_ui_win.eo index 5ccf8240d1..8fb9bb4033 100644 --- a/src/lib/elementary/efl_ui_win.eo +++ b/src/lib/elementary/efl_ui_win.eo @@ -305,51 +305,26 @@ class Efl.Ui.Win (Elm.Widget, Efl.Canvas, Efl.Access.Window, skip: bool; [[The skip flag state ($true if it is to be skipped).]] } } - @property autodel { - set { - [[Set the window's autodel state. - - When closing the window in any way outside of the program - control, like pressing the X button in the titlebar or using - a command from the Window Manager, a "delete,request" signal - is emitted to indicate that this event occurred and the - developer can take any action, which may include, or not, - destroying the window object. - - When the $autodel parameter is set, the window will be - automatically destroyed when this event occurs, after the - signal is emitted. If $autodel is $false, then the window - will not be destroyed and is up to the program to do so - when it's required. - ]] - } - get { - [[Get the window's autodel state.]] - } - values { - autodel: bool; [[If $true, the window will automatically delete - itself when closed.]] - } - } @property autohide { [[Window's autohide state. - This property works similarly to @.autodel, automatically handling - "delete,request" signals when set to $trze, with the difference - that it will hide the window, instead of destroying it. + When closing the window in any way outside of the program control, + like pressing the X button in the titlebar or using a command from + the Window Manager, a "delete,request" signal is emitted to indicate + that this event occurred and the developer can take any action, which + may include, or not, destroying the window object. - It is specially designed to work together with $ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN - which allows exiting Elementary's main loop when all the windows - are hidden. + When this property is set to $true, the window will be automatically + hidden when this event occurs, after the signal is emitted. If this + property is $false, nothing will happen, beyond the event emission. - Note: @.autodel and $autohide are not mutually exclusive. The window + C applications can use this option along with the quit policy + $ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN which allows exiting EFL's main + loop when all the windows are hidden. + + Note: $autodel and $autohide are not mutually exclusive. The window will be deleted if both are set to $true. ]] - - set { - } - get { - } values { autohide: bool; [[If $true, the window will automatically hide itself when closed.]] diff --git a/src/lib/elementary/elm_win.h b/src/lib/elementary/elm_win.h index 467666ca3e..7720b980cb 100644 --- a/src/lib/elementary/elm_win.h +++ b/src/lib/elementary/elm_win.h @@ -105,7 +105,7 @@ #include #ifdef EFL_EO_API_SUPPORT -#include +#include #endif #ifndef EFL_NOLEGACY_API_SUPPORT #include diff --git a/src/lib/elementary/elm_win_eo.h b/src/lib/elementary/elm_win_eo.h index cdddf880f7..4d3daa8884 100644 --- a/src/lib/elementary/elm_win_eo.h +++ b/src/lib/elementary/elm_win_eo.h @@ -6,6 +6,54 @@ #include "efl_ui_win.eo.h" +EAPI void elm_win_autodel_set(Evas_Object *obj, Eina_Bool autodel); +EAPI Eina_Bool elm_win_autodel_get(const Evas_Object *obj); + +/** + * @brief Set the window's autodel state. + * + * When closing the window in any way outside of the program control, like + * pressing the X button in the titlebar or using a command from the Window + * Manager, a "delete,request" signal is emitted to indicate that this event + * occurred and the developer can take any action, which may include, or not, + * destroying the window object. + * + * When the @c autodel parameter is set, the window will be automatically + * destroyed when this event occurs, after the signal is emitted. If @c autodel + * is @c false, then the window will not be destroyed and is up to the program + * to do so when it's required. + * + * @param[in] obj The object. + * @param[in] autodel If @c true, the window will automatically delete itself + * when closed. + * + * Note: This function is only available in C. + * + * @ingroup Efl_Ui_Win + */ +static inline void +efl_ui_win_autodel_set(Efl_Ui_Win *obj, Eina_Bool autodel) +{ + elm_win_autodel_set(obj, autodel); +} + +/** + * @brief Get the window's autodel state. + * + * @param[in] obj The object. + * + * @return If @c true, the window will automatically delete itself when closed. + * + * Note: This function is only available in C. + * + * @ingroup Efl_Ui_Win + */ +static inline Eina_Bool +efl_ui_win_autodel_get(const Efl_Ui_Win *obj) +{ + return elm_win_autodel_get(obj); +} + /** * @} */ diff --git a/src/lib/elementary/elm_win_legacy.h b/src/lib/elementary/elm_win_legacy.h index 3abb242940..74774c7d19 100644 --- a/src/lib/elementary/elm_win_legacy.h +++ b/src/lib/elementary/elm_win_legacy.h @@ -179,6 +179,39 @@ EAPI Evas_Object *elm_win_util_standard_add(const char *name, const cha */ EAPI Evas_Object *elm_win_util_dialog_add(Evas_Object *parent, const char *name, const char *title); +/** + * @brief Set the window's autodel state. + * + * When closing the window in any way outside of the program control, like + * pressing the X button in the titlebar or using a command from the Window + * Manager, a "delete,request" signal is emitted to indicate that this event + * occurred and the developer can take any action, which may include, or not, + * destroying the window object. + * + * When the @c autodel parameter is set, the window will be automatically + * destroyed when this event occurs, after the signal is emitted. If @c autodel + * is @c false, then the window will not be destroyed and is up to the program + * to do so when it's required. + * + * @param[in] obj The object. + * @param[in] autodel If @c true, the window will automatically delete itself + * when closed. + * + * @ingroup Elm_Win + */ +EAPI void elm_win_autodel_set(Evas_Object *obj, Eina_Bool autodel); + +/** + * @brief Get the window's autodel state. + * + * @param[in] obj The object. + * + * @return If @c true, the window will automatically delete itself when closed. + * + * @ingroup Elm_Win + */ +EAPI Eina_Bool elm_win_autodel_get(const Evas_Object *obj); + /** * Set the floating mode of a window. *