Popup in cpp style 05/196705/7
authorOskar Chodowicz <o.chodowicz@samsung.com>
Thu, 3 Jan 2019 11:24:10 +0000 (12:24 +0100)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Wed, 16 Jan 2019 10:35:38 +0000 (11:35 +0100)
Change-Id: I88f3eeaf4f0ac3dfc7b3ff9a119ea2895691cc1b

14 files changed:
src/AccessoriesSwitchesPage.cpp
src/MainData.cpp
src/MainData.hpp
src/RemoveSwitchPage.cpp
src/RemoveSwitchPage.hpp
src/ScreenReaderSettingsPage.cpp
src/ScreenReaderSettingsPage.hpp
src/SettingPopup.cpp
src/SettingPopup.hpp
src/UniversalSwitchPage.cpp
src/UniversalSwitchSettingsPage.cpp
src/Widget.cpp
src/Widget.hpp
src/setting-accessibility.cpp

index 9d0f331..c52398d 100644 (file)
@@ -99,11 +99,9 @@ void AccessoriesSwitchesPage::captureSwitchCb(void *user_data, const char *switc
        }
 
        self->context_->us_configuration.switch_id = switch_id;
-       self->settingPopup_ = std::make_unique<SettingPopup>(self, self->context_->md.getNaviframe()->getObject(),
+       self->settingPopup_ = std::make_unique<SettingPopup>(self, self->context_->md.getNaviframe(),
                                                  "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH", std::string{},
-                                                 popupResponseCb, 0,
-                                                 true,
-                                                 true,
+                                                 popupResponseCb,
                                                  std::vector<std::string> {"IDS_ACCS_UNIVERSAL_SWITCH_CANCEL", "IDS_ACCS_UNIVERSAL_SWITCH_SAVE"});
 
        Evas_Object *layout = createLayout(self->settingPopup_->getObject(), EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP);
@@ -116,11 +114,9 @@ void AccessoriesSwitchesPage::captureSwitchCb(void *user_data, const char *switc
 
 void AccessoriesSwitchesPage::alreadyMappedSwitchPopup()
 {
-       settingPopup_ = std::make_unique<SettingPopup>(this, context_->md.getNaviframe()->getObject(),
+       settingPopup_ = std::make_unique<SettingPopup>(this, context_->md.getNaviframe(),
                                        "IDS_ACCS_UNIVERSAL_SWITCH_UNABLE_TO_ADD", std::string{},
-                                       okResponseCb, 0,
-                                       true,
-                                       true,
+                                       okResponseCb,
                                        std::vector<std::string> {"IDS_ACCS_UNIVERSAL_SWITCH_OK"});
 
        Evas_Object *layout = createLayout(settingPopup_->getObject(), EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP);
index 83f3f60..d7944b5 100644 (file)
@@ -55,9 +55,9 @@ void MainData::initView(const std::string &name)
        evas_object_show(genlist);
 }
 
-Evas_Object *MainData::getWindow() const
+Window *MainData::getWindow() const
 {
-       return window->getObject();
+       return window.get();
 }
 
 Naviframe *MainData::getNaviframe() const
index bc203e6..1df2b02 100644 (file)
@@ -34,7 +34,7 @@ public:
        MainData() = default;
        int initApp(const std::string &name);
        void initView(const std::string &name);
-       Evas_Object *getWindow() const;
+       Window *getWindow() const;
        Naviframe *getNaviframe() const;
        Evas_Object *getGenlist() const;
        void addBackButton(Elm_Naviframe_Item_Pop_Cb view_pop_cb, void *ad) const;
index a8a1845..e385afa 100644 (file)
@@ -58,7 +58,7 @@ void RemoveSwitchPage::onDeleteButtonClicked(void *data, Evas_Object *obj, void
        auto self = static_cast<RemoveSwitchPage *>(data);
        retm_if(self->context_->set_value_layout.getGenlist() == NULL, "No genlist provided");
 
-       createPopupForSwitchesRemoving(self);
+       self->createPopupForSwitchesRemoving();
 }
 
 void RemoveSwitchPage::onAllButtonsClicked(void *data, Evas_Object *obj, void *event_info)
@@ -97,47 +97,43 @@ void RemoveSwitchPage::useNaviframeTitleAsCounter(RemoveSwitchPage *self)
        elm_layout_text_set(self->context_->md.getNaviframe()->getObject(), "default", title.c_str());
 }
 
-void RemoveSwitchPage::createPopupForSwitchesRemoving(RemoveSwitchPage *self)
+void RemoveSwitchPage::createPopupForSwitchesRemoving()
 {
-       self->popup = elm_popup_add(self->context_->md.getNaviframe()->getObject());
-       retm_if(!self->popup, "Popup creation failure");
-       elm_popup_orient_set(self->popup, ELM_POPUP_ORIENT_CENTER);
-       evas_object_size_hint_weight_set(self->popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       popup_ = Widget::make<Popup>(context_->md.getNaviframe());
+
+       popup_->setOrientation(ELM_POPUP_ORIENT_CENTER);
+       popup_->setWeightHint(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
        int vconf_val;
        int vconf_ret = vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, &vconf_val);
        retm_if(vconf_ret != 0,
                        "Failed to get vconf bool value VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE. Error: %d", vconf_ret);
 
-       elm_object_part_text_set(self->popup, "title,text", _("IDS_ACCS_UNIVERSAL_SWITCH_DELETE_SWITCHES"));
+       popup_->setPartText("title,text", TranslatedString{"IDS_ACCS_UNIVERSAL_SWITCH_DELETE_SWITCHES"});
+
 
-       if (vconf_val && self->context_->switches_to_remove_counter == (int)elm_genlist_items_count(self->context_->set_value_layout.getGenlist())) {
-               elm_object_text_set(self->popup, _("IDS_ACCS_UNIVERSAL_SWITCH_DELETE_ALL_SWITCHES_DESC"));
+       if (vconf_val && context_->switches_to_remove_counter == (int)elm_genlist_items_count(context_->set_value_layout.getGenlist())) {
+               popup_->setText(TranslatedString{"IDS_ACCS_UNIVERSAL_SWITCH_DELETE_ALL_SWITCHES_DESC"});
        } else {
-               auto s = std::to_string(self->context_->switches_to_remove_counter) + " " + TranslatedString{"IDS_ACCS_UNIVERSAL_SWITCH_DELETE_SWITCHES_DESC"} .str();
-               elm_object_text_set(self->popup, s.c_str());
+               auto s = std::to_string(context_->switches_to_remove_counter) + " " + TranslatedString{"IDS_ACCS_UNIVERSAL_SWITCH_DELETE_SWITCHES_DESC"} .str();
+               popup_->setText(s);
        }
+       auto removeCb = [p = popup_, nf = context_->md.getNaviframe()](){
+               nf->detachChild(p);
+               };
+       context_->md.getNaviframe()->setEextEventCallback(EEXT_CALLBACK_BACK, removeCb, popup_);
+       context_->md.getNaviframe()->setEvasSmartCallback("dismissed", removeCb, popup_);
+       context_->md.getNaviframe()->setEvasSmartCallback("block,clicked", removeCb ,popup_);
 
-       eext_object_event_callback_add(self->popup, EEXT_CALLBACK_BACK, onRemovePopup, NULL);
-       evas_object_smart_callback_add(self->popup, "dismissed", onRemovePopup, NULL);
-       evas_object_smart_callback_add(self->popup, "block,clicked", onRemovePopup, NULL);
+       auto btn = WidgetFactory::createButton(popup_->getObject(), "IDS_ST_BUTTON_CANCEL", "bottom", onCancelPopupButtonClicked, popup_->getObject());
 
-       auto btn = WidgetFactory::createButton(self->popup, "IDS_ST_BUTTON_CANCEL", "bottom", onCancelPopupButtonClicked, self->popup);
-       if (!btn) {
-               SETTING_TRACE_ERROR("Button creation failed");
-               evas_object_del(self->popup);
-               self->popup = NULL;
-       }
-       elm_object_part_content_set(self->popup, "button1", btn);
+       elm_object_part_content_set(popup_->getObject(), "button1", btn);
 
 
-       btn = WidgetFactory::createButton(self->popup, "IDS_ACCS_DELETE", "bottom", onRemoveSelectedSwitches, self);
-       if (!btn) {
-               SETTING_TRACE_ERROR("Button creation failed");
-               evas_object_del(self->popup);
-               self->popup = NULL;
-       }
-       elm_object_part_content_set(self->popup, "button2", btn);
-       evas_object_show(self->popup);
+       btn = WidgetFactory::createButton(popup_->getObject(), "IDS_ACCS_DELETE", "bottom", onRemoveSelectedSwitches, this);
+
+       elm_object_part_content_set(popup_->getObject(), "button2", btn);
+       popup_->show();
 }
 
 void RemoveSwitchPage::onRemoveSelectedSwitches(void *data, Evas_Object *obj, void *event_info)
@@ -153,8 +149,7 @@ void RemoveSwitchPage::onRemoveSelectedSwitches(void *data, Evas_Object *obj, vo
                        removeSwitch(self, list_item->chk_id);
        }
 
-       evas_object_del(self->popup);
-       self->popup = NULL;
+       evas_object_del(self->popup_->getObject());
        elm_naviframe_item_pop(self->context_->md.getNaviframe()->getObject());
 
        if (disable_universal_switch && vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, 0))
index fc6b353..9c14749 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "SettingAccessibility.hpp"
 #include "SetValuePage.hpp"
+#include "Popup.hpp"
 
 class SetValuePage;
 
@@ -43,7 +44,7 @@ public:
 private:
        static void onDeleteButtonClicked(void *data, Evas_Object *obj, void *event_info);
        static void onAllButtonsClicked(void *data, Evas_Object *obj, void *event_info);
-       static void createPopupForSwitchesRemoving(RemoveSwitchPage *self);
+       void createPopupForSwitchesRemoving();
        static void onRemoveSelectedSwitches(void *data, Evas_Object *obj, void *event_info);
        static void onCancelPopupButtonClicked(void *data, Evas_Object *obj, void *event_info);
        static void onRemovePopup(void *data, Evas_Object *obj, void *event_info);
@@ -55,7 +56,7 @@ private:
        void *switch_removed_cb_data = nullptr;
        Evas_Object *remove_switches_popup_button = nullptr;
        Evas_Object *all_checkbox = nullptr;
-       Evas_Object *popup;
+       Popup *popup_ = nullptr;
 };
 
 
index 1d148e8..8cf3b7a 100644 (file)
@@ -225,7 +225,7 @@ void ScreenReaderSettingsPage::mouseUpGendialListCb(void *data, Evas_Object *obj
        retm_if(event_info == NULL, "Invalid argument: event_info is NULL");
        Elm_Object_Item *item = (Elm_Object_Item *)event_info;
        auto ad = static_cast<SettingAccessibility *>(data);
-       Evas_Object *popup;
+
        Evas_Object *box;
        Evas_Object *genlist;
        GenGroupItemData *screenreader_checkbox = NULL;
@@ -234,17 +234,17 @@ void ScreenReaderSettingsPage::mouseUpGendialListCb(void *data, Evas_Object *obj
 
        elm_genlist_item_selected_set(item, EINA_FALSE);
 
-       popup = elm_popup_add(ad->md.getWindow());
-       elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+       auto popup = Widget::make<Popup>(ad->md.getWindow());
+       popup->setAlignment(ELM_NOTIFY_ALIGN_FILL, 1.0);
+
        /* eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
         *  eext_popup_back_cb, NULL); */
-       elm_object_part_text_set(popup, "title,text",
-                                                        _("IDS_ACCS_TMBODY_STATUS_BAR_INFORMATION"));
-       evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
-                                                                        EVAS_HINT_EXPAND);
+
+       popup->setPartText("title,text", "IDS_ACCS_TMBODY_STATUS_BAR_INFORMATION");
+       popup->setWeightHint(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
        /* box */
-       box = elm_box_add(popup);
+       box = elm_box_add(popup->getObject());
        evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND,
                                                                         EVAS_HINT_EXPAND);
 
@@ -280,21 +280,24 @@ void ScreenReaderSettingsPage::mouseUpGendialListCb(void *data, Evas_Object *obj
                                                                  ELM_SCALE_SIZE(POPUP_CONTENT_BASE_SIZE) * size);
        evas_object_size_hint_max_set(box, -1,
                                                                  ELM_SCALE_SIZE(POPUP_CONTENT_BASE_SIZE) * size);
-       elm_object_content_set(popup, box);
+       elm_object_content_set(popup->getObject(), box);
 
-       Evas_Object *btnCancel = WidgetFactory::createButton(popup, "IDS_MSG_ACBUTTON_CANCEL_ABB", {}, onCancelButtonClicked, popup);
+       Evas_Object *btnCancel = WidgetFactory::createButton(popup->getObject(), "IDS_MSG_ACBUTTON_CANCEL_ABB", {}, onCancelButtonClicked, popup->getObject());
        elm_object_style_set(btnCancel, "popup");
-       elm_object_part_content_set(popup, _("button1"), btnCancel);
-       evas_object_data_set(popup, "button1", "IDS_MSG_ACBUTTON_CANCEL_ABB");
+       elm_object_part_content_set(popup->getObject(), _("button1"), btnCancel);
+       evas_object_data_set(popup->getObject(), "button1", "IDS_MSG_ACBUTTON_CANCEL_ABB");
 
-       Evas_Object *btnDone = WidgetFactory::createButton(popup, "IDS_MSG_ACBUTTON_DONE_ABB", {}, onDoneButtonClicked, popup);
+       Evas_Object *btnDone = WidgetFactory::createButton(popup->getObject(), "IDS_MSG_ACBUTTON_DONE_ABB", {}, onDoneButtonClicked, popup->getObject());
        elm_object_style_set(btnDone, "popup");
-       elm_object_part_content_set(popup, _("button2"), btnDone);
-       evas_object_data_set(popup, "button2", "IDS_MSG_ACBUTTON_DONE_ABB");
+       elm_object_part_content_set(popup->getObject(), _("button2"), btnDone);
+       evas_object_data_set(popup->getObject(), "button2", "IDS_MSG_ACBUTTON_DONE_ABB");
 
-       eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, onCancelButtonClicked, popup);
+       auto removeCb = [p = popup, window = ad->md.getWindow()](){
+               window->detachChild(p);
+               };
 
-       evas_object_show(popup);
+       ad->md.getWindow()->setEextEventCallback(EEXT_CALLBACK_BACK, removeCb, popup);
+       popup->show();
 }
 
 void ScreenReaderSettingsPage::vibrationFeedbackCb(void *data, Evas_Object *obj, void *event_info)
@@ -427,29 +430,26 @@ void ScreenReaderSettingsPage::ttsSpeedChangedCb(int speed, void *user_data)
 void ScreenReaderSettingsPage::createSpeechRatePopup(void *data, void *item)
 {
        auto ad = static_cast<SettingAccessibility *>(data);
-       Evas_Object *popup;
        Evas_Object *layout;
        Evas_Object *slider;
        int val = -1;
 
-       popup = elm_popup_add(ad->md.getWindow());
-       elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+       auto popup = Widget::make<Popup>(ad->md.getWindow());
+       popup->setAlignment(ELM_NOTIFY_ALIGN_FILL, 1.0);
        /* eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
         *  eext_popup_back_cb, NULL); */
-       elm_object_part_text_set(popup, "title,text",
-                                                        _("IDS_ST_BODY_SPEECH_RATE"));
-       evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
-                                                                        EVAS_HINT_EXPAND);
+       popup->setPartText("title,text", "IDS_ST_BODY_SPEECH_RATE");
+       popup->setWeightHint(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
        /* layout */
-       layout = elm_layout_add(popup);
+       layout = elm_layout_add(popup->getObject());
        elm_layout_file_set(layout, SETTINGS_EDJ,
                                                "popup_text_slider_view_layout");
        elm_object_part_text_set(layout, "elm.text.description",
                                                         _("IDS_SCR_POP_DRAG_THE_SLIDER_TO_SET_THE_SPEECH_RATE"));
        evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
                                                                         EVAS_HINT_EXPAND);
-       elm_object_content_set(popup, layout);
+       elm_object_content_set(popup->getObject(), layout);
 
        /* slider */
        slider = elm_slider_add(layout);
@@ -467,16 +467,20 @@ void ScreenReaderSettingsPage::createSpeechRatePopup(void *data, void *item)
        elm_slider_value_set(slider, val);
        elm_object_part_content_set(layout, "slider", slider);
 
-       auto btn1 = WidgetFactory::createButton(popup, "IDS_ST_BUTTON_CANCEL_ABB", "bottom", onCancelButtonClicked, popup);
-       eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, onCancelButtonClicked, popup);
-       elm_object_part_content_set(popup, "button1", btn1);
+       auto btn1 = WidgetFactory::createButton(popup->getObject(), "IDS_ST_BUTTON_CANCEL_ABB", "bottom", onCancelButtonClicked, popup->getObject());
+       elm_object_part_content_set(popup->getObject(), "button1", btn1);
 
-       auto btn2 = WidgetFactory::createButton(popup, "IDS_ST_SK3_DONE", "bottom", onPopupDoneButtonClicked, popup);
-       elm_object_part_content_set(popup, "button2", btn2);
+       auto btn2 = WidgetFactory::createButton(popup->getObject(), "IDS_ST_SK3_DONE", "bottom", onPopupDoneButtonClicked, popup->getObject());
+       elm_object_part_content_set(popup->getObject(), "button2", btn2);
 
-       evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, onPopupDel, item);
+       auto removeCb = [p = popup, window = ad->md.getWindow()](){
+       window->detachChild(p);
+       };
+       ad->md.getWindow()->setEextEventCallback(EEXT_CALLBACK_BACK, removeCb, popup);
+       
+       evas_object_event_callback_add(popup->getObject(), EVAS_CALLBACK_DEL, onPopupDel, item);
 
-       evas_object_show(popup);
+       popup->show();
 }
 
 void ScreenReaderSettingsPage::onPopupDel(void *data, Evas *e, Evas_Object *obj, void *event_info)
index fa1ebc9..e7c438e 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "SettingAccessibility.hpp"
 #include "GenGroupItemData.hpp"
+#include "Popup.hpp"
 
 #include <Elementary.h>
 
index 3fb8256..e55689d 100644 (file)
 #include <efl_extension.h>
 #include <app.h>
 
-SettingPopup::SettingPopup(void *data, Evas_Object *parent,
+SettingPopup::SettingPopup(void *data, Widget *parent,
                                                   const std::string &title, const std::string &text,
-                                                  SettingCallback response_cb, int timeout,
-                                                  bool blocked_flag,
-                                                  bool keygrab_flag, std::vector<std::string> buttons)
+                                                  SettingCallback response_cb,
+                                                  std::vector<std::string> buttons)
 {
-       Evas_Object *popup = elm_popup_add(parent);
-       elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
-       evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       popup_ = Widget::make<Popup>(parent);
 
-       elm_object_text_set(popup, TranslatedString{text} .c_str());
+       popup_->setAlignment(ELM_NOTIFY_ALIGN_FILL, 1.0);
+       popup_->setWeightHint(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
-       elm_object_part_text_set(popup, "title,text", TranslatedString{title} .c_str());
-
-       if (timeout > 0)
-               elm_popup_timeout_set(popup, timeout);
-
-       setEvent(popup, data, response_cb, onTimeout, timeout, blocked_flag, keygrab_flag);
-
-       evas_object_data_set(popup, "title", TranslatedString{title} .c_str());
-       evas_object_data_set(popup, "text", TranslatedString{text} .c_str());
-       auto r = vconf_notify_key_changed(VCONFKEY_LANGSET, onLanguageChange, popup);
-       if (!r)
-               SETTING_TRACE_ERROR("Could not get value for key: %s", VCONFKEY_SETAPPL_ACCESSIBILITY_TTS);
-       evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, onPopupDel, NULL);
+       popup_->setText(TranslatedString{text});
+       popup_->setPartText("title,text", TranslatedString{title});
+       popup_->setEextEventCallback(EEXT_CALLBACK_BACK, [](){});
 
        if (buttons.size() <= 3) {
                std::vector<TranslatedString> buttons_parts = {"button1", "button2", "button3"};
                for (auto i = 0u; i < buttons.size(); ++i) {
-                       Evas_Object *btn = WidgetFactory::createButton(popup, buttons[i], {}, response_cb, data);
+                       Evas_Object *btn = WidgetFactory::createButton(popup_->getObject(), buttons[i], {}, response_cb, data);
                        elm_object_style_set(btn, "popup");
-                       elm_object_part_content_set(popup, buttons_parts[i].c_str(), btn);
-                       evas_object_data_set(popup, buttons_parts[i].c_str(), TranslatedString{buttons[i]} .c_str());
+                       elm_object_part_content_set(popup_->getObject(), buttons_parts[i].c_str(), btn);
+                       evas_object_data_set(popup_->getObject(), buttons_parts[i].c_str(), TranslatedString{buttons[i]} .c_str());
                }
        } else {
                SETTING_TRACE_ERROR("incorrect button number for popup");
        }
 
-       evas_object_show(popup);
-       obj = popup;
+       popup_->show();
 }
 
 Evas_Object *SettingPopup::getObject() const
 {
-       return obj;
+       return popup_->getObject();
 }
 
 SettingPopup::~SettingPopup()
 {
-       evas_object_del(obj);
-}
-
-void SettingPopup::setEvent(Evas_Object *popup, void *data,
-                                                       SettingCallback response_cb,
-                                                       SettingCallback back_cb, int timeout,
-                                                       bool blocked_flag,
-                                                       bool keygrab_flag)
-{
-       if (timeout > 0) {
-               if (response_cb)
-                       evas_object_smart_callback_add(popup, "timeout", response_cb, data);
-               else
-                       evas_object_smart_callback_add(popup, "timeout", onTimeout, data);
-       }
-
-       if (!blocked_flag) {
-               if (response_cb)
-                       evas_object_smart_callback_add(popup, "block,clicked", response_cb, data);
-               else
-                       evas_object_smart_callback_add(popup, "block,clicked", back_cb, data);
-       }
-
-       if (keygrab_flag) {
-#ifdef ECORE_X
-               Ecore_X_Window xwin = elm_win_xwindow_get(popup);
-
-               int ret = eext_win_keygrab_set(xwin, "XF86Home");
-               if (ret)
-                       SETTING_TRACE_ERROR("KEY_HOME grab error ret[%d]", ret);
-#endif
-               evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, onPopupKeygrabDel, NULL);
-               eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, ignoreBackKeyCb, NULL);
-       } else {
-               eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, back_cb, data);
-       }
-}
-
-void SettingPopup::onTimeout(void *data, Evas_Object *obj, void *event_info)
-{
-       evas_object_del(obj);
-}
-
-void SettingPopup::onLanguageChange(keynode_t *key, void *data)
-{
-       setting_retm_if(NULL == key, "key is NULL");
-       setting_retm_if(NULL == data, "data is NULL");
-       Evas_Object *popup = (Evas_Object *)data;
-       char *vconf_name = vconf_keynode_get_name(key);
-       if (!safeStrCmp(vconf_name, VCONFKEY_LANGSET))
-               updateLanguage(popup);
-}
-
-void SettingPopup::onPopupDel(void *data, Evas *e, Evas_Object *obj, void *event_info)
-{
-       ret_if(!obj);
-       (void)vconf_ignore_key_changed(VCONFKEY_LANGSET, onLanguageChange);
-       evas_object_data_set(obj, "title", NULL);
-       evas_object_data_set(obj, "text0", NULL);
-       evas_object_data_set(obj, "text", NULL);
-       evas_object_data_set(obj, "button1", NULL);
-       evas_object_data_set(obj, "button2", NULL);
-       evas_object_data_set(obj, "button3", NULL);
-       evas_object_data_set(obj, "check_str", NULL);
-}
-
-void SettingPopup::onPopupKeygrabDel(void *data, Evas *e, Evas_Object *obj, void *event_info)
-{
-#ifdef ECORE_X
-       Ecore_X_Window xwin = elm_win_xwindow_get(obj);
-
-       int ret = eext_win_keygrab_unset(xwin, "XF86Home");
-       if (ret)
-               SETTING_TRACE_ERROR("KEY_HOME ungrab error ret[%d]", ret);
-
-       ret = eext_win_keygrab_unset(xwin, "XF86Back");
-       if (ret)
-               SETTING_TRACE_ERROR("KEY_BACK ungrab error ret[%d]", ret);
-#endif
-}
-
-void SettingPopup::updateLanguage(Evas_Object *popup)
-{
-       setting_retm_if(NULL == popup, "data is NULL");
-       auto title = static_cast<char *>(evas_object_data_get(popup, "title"));
-       auto text1 = static_cast<char *>(evas_object_data_get(popup, "text"));
-       auto text0 = static_cast<char *>(evas_object_data_get(popup, "text0"));
-       std::string text; // TODO change this variable into TranslatedString
-
-       if (text0) {
-               text = TranslatedString{text0} .str() + "<br>" + TranslatedString{text1} .str();
-       } else {
-               text = TranslatedString{text1} .str();
-       }
-
-       if (title)
-               elm_object_part_text_set(popup, "title,text", _(title));
-
-       Evas_Object *layout = elm_object_content_get(popup);
-       if (layout) {
-               Evas_Object *eo_view = elm_object_part_content_get(layout, "elm.swallow.content");
-               if (eo_view) {
-                       const char *eo_view_t = evas_object_type_get(eo_view);
-                       if (!safeStrCmp("elm_genlist", eo_view_t))
-                               elm_genlist_realized_items_update(eo_view);
-                       else if (!safeStrCmp("elm_label", eo_view_t))
-                               if (!text.empty())
-                                       elm_object_text_set(eo_view, text.c_str());
-               }
-               eo_view = elm_object_part_content_get(layout, "elm.swallow.end");
-               if (eo_view) {
-                       const char *eo_view_t = evas_object_type_get(eo_view);
-                       if (!safeStrCmp("elm_check", eo_view_t)) {
-                               char *check_str = (char *)evas_object_data_get(popup, "check_str");
-                               if (check_str)
-                                       elm_object_text_set(eo_view, _(check_str));
-                       }
-               }
-       } else {
-               if (!text.empty())
-                       elm_object_text_set(popup, text.c_str());
-       }
-
-       char *btn_part_str[3] = { _("button1"), _("button2"), _("button3") };
-       int i = 0;
-
-       for (; i < 3; i++) {
-               auto btn = elm_object_part_content_get(popup, btn_part_str[i]);
-               if (btn) {
-                       char *btn_str = (char *)evas_object_data_get(popup, btn_part_str[i]);
-                       elm_object_text_set(btn, _(btn_str));
-               }
-       }
-
-}
-
-void SettingPopup::ignoreBackKeyCb(void *data, Evas_Object *obj, void *event_info)
-{
-       return;
+       evas_object_del(popup_->getObject());
+       //TODO find better way to remove popup object
 }
index 220f54e..775dc15 100644 (file)
@@ -18,6 +18,7 @@
 #define SETTING_POPUP_HPP
 
 #include "utils.hpp"
+#include "Popup.hpp"
 
 #include <Elementary.h>
 #include <vconf.h>
@@ -48,28 +49,18 @@ public:
        * @param keygrab_flag   to control whether to block key
        * @param buttons                buttons to show in the popup
        **********************************************************/
-       SettingPopup(void *data, Evas_Object *parent,
+       SettingPopup(void *data, Widget *parent,
                                 const std::string &title, const std::string &text,
-                                SettingCallback response_cb, int timeout,
-                                bool blocked_flag,
-                                bool keygrab_flag, std::vector<std::string> buttons);
+                                SettingCallback response_cb,
+                                std::vector<std::string> buttons);
        Evas_Object *getObject() const;
        ~SettingPopup();
 
 private:
-       void setEvent(Evas_Object *popup, void *data,
-                                 SettingCallback response_cb,
-                                 SettingCallback back_cb, int timeout,
-                                 bool blocked_flag,
-                                 bool keygrab_flag);
-       static void onTimeout(void *data, Evas_Object *obj, void *event_info);
-       static void onLanguageChange(keynode_t *key, void *data);
-       static void onPopupDel(void *data, Evas *e, Evas_Object *obj, void *event_info);
-       static void onPopupKeygrabDel(void *data, Evas *e, Evas_Object *obj, void *event_info);
-       static void updateLanguage(Evas_Object *popup);
+
        static void ignoreBackKeyCb(void *data, Evas_Object *obj, void *event_info);
 
-       Evas_Object *obj;
+       Popup *popup_;
 };
 
 #endif
index 92123b2..ce2d400 100644 (file)
@@ -130,9 +130,7 @@ void UniversalSwitchPage::updateVconfKey(int state)
                context_->md.naviframe_it = elm_naviframe_top_item_get(context_->md.getNaviframe()->getObject());
                noSwitchPopup_ = std::make_unique<SettingPopup>(this, context_->md.getWindow(),
                                                 std::string{}, "To turn on Universal switch, tap ADD SWITCH and add at least one switch",
-                                                popupResponseCb, 0,
-                                                true,
-                                                true,
+                                                popupResponseCb,
                                                 std::vector<std::string> {"IDS_ACCS_UNIVERSAL_SWITCH_POPUP_ADD", "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL"});
        } else {
                setState(state);
index d381aae..0e8a2a0 100644 (file)
@@ -302,7 +302,7 @@ void UniversalSwitchSettingsPage::setCtxPopupPosition(SettingAccessibility *ad,
        int y = 0;
        int h = 0;
 
-       evas_pointer_output_xy_get(evas_object_evas_get(ad->md.getWindow()), NULL, &y);
+       evas_pointer_output_xy_get(evas_object_evas_get(ad->md.getWindow()->getObject()), NULL, &y);
        evas_object_geometry_get(ctxpopup, NULL, NULL, NULL, &h);
        evas_object_move(ctxpopup, -1, y + h);
 }
index 34f90ed..2606465 100644 (file)
@@ -11,6 +11,11 @@ void Widget::setText(const TranslatedString &text)
        elm_object_text_set(obj_, text.c_str());
 }
 
+void Widget::setPartText(const std::string &partName, const TranslatedString &text)
+{
+       elm_object_part_text_set(obj_, partName.c_str(), text.c_str());
+}
+
 void Widget::setWeightHint(double x, double y)
 {
        evas_object_size_hint_weight_set(obj_, x, y);
@@ -21,11 +26,22 @@ void Widget::setAlignHint(double x, double y)
        evas_object_size_hint_align_set(obj_, x, y);
 }
 
-void Widget::setEventCallback(const std::string &eventName, std::function<void()> callback)
+void Widget::setEvasSmartCallback(const std::string &eventName, std::function<void()> callback, Widget *ptr)
 {
-       callbacks_.insert_or_assign(eventName, std::move(callback));
+       if ( ptr == nullptr)
+               ptr = this;
+       smartCallbacks_.insert_or_assign(eventName, std::move(callback));
        auto cbData = new CallbackData{this, eventName};
-       evas_object_smart_callback_add(obj_, eventName.c_str(), callbackMethod, cbData);
+       evas_object_smart_callback_add(ptr->getObject(), eventName.c_str(), smartCallbackMethod, cbData);
+}
+
+void Widget::setEextEventCallback(const Eext_Callback_Type type, std::function<void()> callback, Widget *ptr)
+{
+       if ( ptr == nullptr)
+               ptr = this;
+       eextEventCallbacks_[type] = std::move(callback);
+       auto cbData = new EextEventData{this, type};
+       eext_object_event_callback_add(ptr->getObject(), type, eextEventMethod, cbData);
 }
 
 void Widget::setStyle(const std::string &style)
@@ -58,6 +74,11 @@ Evas_Object *Widget::getObject()
        return obj_;
 }
 
+Widget *Widget::getParent()
+{
+       return parent_;
+}
+
 void Widget::addChild(std::unique_ptr<Widget> child)
 {
        child->parent_ = this;
@@ -73,6 +94,7 @@ std::unique_ptr<Widget> Widget::detachChild(Widget *child)
        for (auto it = children_.begin(); it != children_.end(); ++it) {
                if (it->get() == child) {
                        (*it)->parent_ = nullptr;
+                       (*it)->uniqueObj_.reset((*it)->obj_);
                        ret.swap(*it);
                        children_.erase(it);
                        break;
@@ -84,17 +106,30 @@ std::unique_ptr<Widget> Widget::detachChild(Widget *child)
 
 void Widget::onCallbackCall(const std::string &eventName)
 {
-       auto cb = callbacks_.find(eventName);
-       if (cb == callbacks_.end()) {
+       auto cb = smartCallbacks_.find(eventName);
+       if (cb == smartCallbacks_.end()) {
                SETTING_TRACE_ERROR("No callback registered for this event");
                return;
        }
        cb->second();
 }
 
-void Widget::callbackMethod(void *data, Evas_Object *obj, void *event_info)
+void Widget::onCallbackCall(const Eext_Callback_Type &type)
+{
+       auto cb = eextEventCallbacks_[type];
+       cb(); //TODO Check if cb is true
+}
+
+void Widget::smartCallbackMethod(void *data, Evas_Object *obj, void *event_info)
 {
        auto cbData = static_cast<CallbackData *>(data);
        cbData->first->onCallbackCall(cbData->second);
-       delete cbData;
+       //TODO add cbData deleting
+}
+
+void Widget::eextEventMethod(void *data, Evas_Object *obj, void *event_info)
+{
+       auto eextData = static_cast<EextEventData *>(data);
+       eextData->first->onCallbackCall(eextData->second);
+       //TODO add cbData deleting
 }
index 7b9c9f5..b105317 100644 (file)
@@ -2,6 +2,7 @@
 #define WIDGET_HPP
 
 #include <Elementary.h>
+#include <efl_extension.h>
 
 #include "TranslatedString.hpp"
 #include "utils.hpp"
@@ -32,15 +33,18 @@ public:
        }
 
        void setText(const TranslatedString &text);
+       void setPartText(const std::string &partName, const TranslatedString &text);
        void setWeightHint(double x, double y);
        void setAlignHint(double x, double y);
-       void setEventCallback(const std::string &eventName, std::function<void()> callback);
+       void setEvasSmartCallback(const std::string &eventName, std::function<void()> callback, Widget *ptr = nullptr);
+       void setEextEventCallback(const Eext_Callback_Type type, std::function<void()> callback, Widget *ptr = nullptr);
        void setStyle(const std::string &style);
        void setColor(int r, int g, int b, int a);
        void setContent(Widget *widget);
        void emitSignal(const std::string &signal);
        void show();
        Evas_Object *getObject();
+       Widget *getParent();
        void addChild(std::unique_ptr<Widget> child);
        std::unique_ptr<Widget> detachChild(Widget *child);
 
@@ -48,15 +52,19 @@ protected:
        Widget() = default;
        Widget(Widget *parent);
        void onCallbackCall(const std::string &eventName);
-       static void callbackMethod(void *data, Evas_Object *obj, void *event_info);
+       void onCallbackCall(const Eext_Callback_Type &type);
+       static void smartCallbackMethod(void *data, Evas_Object *obj, void *event_info);
+       static void eextEventMethod(void *data, Evas_Object *obj, void *event_info);
 
        using CallbackData = std::pair<Widget *, std::string>;
+       using EextEventData = std::pair<Widget *, Eext_Callback_Type>;
        Evas_Object *obj_ = nullptr;
        std::unique_ptr<Evas_Object, utils::EvasDeleter> uniqueObj_;
 
        Widget *parent_ = nullptr;
        std::vector<std::unique_ptr<Widget>> children_;
-       std::unordered_map<std::string, std::function<void()>> callbacks_;
+       std::unordered_map<std::string, std::function<void()>> smartCallbacks_;
+       std::vector<std::function<void()>> eextEventCallbacks_ { EEXT_CALLBACK_LAST };
 };
 
 #endif
index 69d6c11..4dd2054 100644 (file)
@@ -132,7 +132,7 @@ static bool on_app_create(void *priv)
        if (ret == -1) destroy_tts_handle(ad);
        ad->mainPage_ = std::make_unique<MainPage>(ad);
 
-       evas_object_show(ad->md.getWindow());
+       evas_object_show(ad->md.getWindow()->getObject());
 
        return true;
 }