1 #include "SimplePopup.h"
2 #include "ServiceManager.h"
3 #include "AbstractMainWindow.h"
4 namespace tizen_browser
9 SimplePopup* SimplePopup::createPopup()
11 SimplePopup *raw_popup = new SimplePopup();
15 SimplePopup* SimplePopup::createPopup(const std::string &title, const std::string &message)
17 SimplePopup *raw_popup = new SimplePopup(title, message);
21 SimplePopup::~SimplePopup()
23 evas_object_del(popup);
26 SimplePopup::SimplePopup() : content(nullptr) { }
28 SimplePopup::SimplePopup(const std::string &title, const std::string &message)
33 void SimplePopup::show()
35 std::shared_ptr<tizen_browser::base_ui::AbstractMainWindow<Evas_Object>> mainUi =
36 std::dynamic_pointer_cast
38 tizen_browser::base_ui::AbstractMainWindow<Evas_Object>,
39 tizen_browser::core::AbstractService
41 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui"));
43 popup = elm_popup_add(mainUi->getMainWindow().get());
44 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
46 if(content != nullptr)
47 elm_object_content_set(popup, content);
49 elm_object_text_set(popup, message.c_str());
51 elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_WORD);
53 elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_CHAR);
55 elm_object_part_text_set(popup, "title,text", title.c_str());
57 int buttonsCounter = 1;
58 for(std::list<PopupButtons>::iterator it = buttons.begin(); it != buttons.end(); ++it)
60 Evas_Object *btn1 = elm_button_add(popup);
61 elm_object_text_set(btn1, buttonsTranslations[*it].c_str());
62 std::string buttonName = "button";
63 buttonName.append(std::to_string(buttonsCounter));
64 elm_object_part_content_set(popup, buttonName.c_str(), btn1);
65 addedButtons[btn1] = *it;
66 evas_object_smart_callback_add(btn1, "clicked", _response_cb, this);
70 evas_object_show(popup);
73 void SimplePopup::_response_cb(void *data, Evas_Object *obj, void */*event_info*/)
75 SimplePopup *self = static_cast<SimplePopup*>(data);
76 self->buttonClicked(self->addedButtons[obj], self->popupData);
80 void SimplePopup::setTitle(const std::string &title)
85 void SimplePopup::setMessage(const std::string &message)
87 this->message = message;
90 void SimplePopup::setContent(Evas_Object* content)
92 this->content = content;
95 void SimplePopup::setData(std::shared_ptr< PopupData > popupData)
97 this->popupData = popupData;
100 void SimplePopup::addButton(PopupButtons buttonId)
102 buttons.push_back(buttonId);