Task TT-75 Implement "Main page loading UI" view
[profile/tv/apps/web/browser.git] / services / SimpleUI / SimplePopup.cpp
1 #include "SimplePopup.h"
2 #include "ServiceManager.h"
3 #include "AbstractMainWindow.h"
4 namespace tizen_browser
5 {
6
7 namespace base_ui
8 {
9     SimplePopup* SimplePopup::createPopup()
10     {
11         SimplePopup *raw_popup = new SimplePopup();
12         return raw_popup;
13     }
14
15     SimplePopup* SimplePopup::createPopup(const std::string &title, const std::string &message)
16     {
17         SimplePopup *raw_popup = new SimplePopup(title, message);
18         return raw_popup;
19     }
20
21     SimplePopup::~SimplePopup()
22     {
23         evas_object_del(popup);
24     }
25
26     SimplePopup::SimplePopup() : content(nullptr) { }
27
28     SimplePopup::SimplePopup(const std::string &title, const std::string &message)
29         : content(nullptr)
30         , title(title)
31         , message(message)
32     { }
33     void SimplePopup::show()
34     {
35        std::shared_ptr<tizen_browser::base_ui::AbstractMainWindow<Evas_Object>> mainUi =
36         std::dynamic_pointer_cast
37         <
38             tizen_browser::base_ui::AbstractMainWindow<Evas_Object>,
39             tizen_browser::core::AbstractService
40         >
41         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui"));
42
43         popup = elm_popup_add(mainUi->getMainWindow().get());
44         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
45
46         if(content != nullptr)
47             elm_object_content_set(popup, content);
48         else
49             elm_object_text_set(popup, message.c_str());
50
51         elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_WORD);
52 #if MERGE_ME
53         elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_CHAR);
54 #endif
55         elm_object_part_text_set(popup, "title,text", title.c_str());
56
57         int buttonsCounter = 1;
58         for(std::list<PopupButtons>::iterator it = buttons.begin(); it != buttons.end(); ++it)
59         {
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);
67             ++buttonsCounter;
68         }
69
70         evas_object_show(popup);
71     }
72
73     void SimplePopup::_response_cb(void *data, Evas_Object *obj, void */*event_info*/)
74     {
75         SimplePopup *self = static_cast<SimplePopup*>(data);
76         self->buttonClicked(self->addedButtons[obj], self->popupData);
77         delete self;
78     }
79
80     void SimplePopup::setTitle(const std::string &title)
81     {
82         this->title = title;
83     }
84
85     void SimplePopup::setMessage(const std::string &message)
86     {
87         this->message = message;
88     }
89
90     void SimplePopup::setContent(Evas_Object* content)
91     {
92         this->content = content;
93     }
94
95     void SimplePopup::setData(std::shared_ptr< PopupData > popupData)
96     {
97         this->popupData = popupData;
98     }
99
100     void SimplePopup::addButton(PopupButtons buttonId)
101     {
102         buttons.push_back(buttonId);
103     }
104 }
105
106 }