2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file popup_renderer.cpp
18 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
20 * @brief This is efl specific implementation for PopupRenderer
23 #include <dpl/popup/popup_manager.h>
24 #include <dpl/popup/popup_renderer.h>
25 #include <dpl/popup/popup_manager.h>
26 #include <dpl/popup/evas_object.h>
27 #include <dpl/shared_ptr.h>
28 #include <dpl/scoped_array.h>
29 #include <dpl/assert.h>
30 #include <dpl/log/log.h>
31 #include <dpl/foreach.h>
32 #include <dpl/framework_efl.h>
33 #include <dpl/lexical_cast.h>
39 using namespace Popup;
40 const char* EDJ_NAME = "/usr/share/edje/ace/generic_popup.edj";
41 const char* POPUP_LAYOUT1 = "popup_layout1";
42 const char* POPUP_LAYOUT2 = "popup_layout2";
43 const char* POPUP_PART_TITLE = "title,text";
44 const char* POPUP_PART_BUTTON1 = "button1";
45 const char* POPUP_PART_BUTTON2 = "button2";
46 const char* POPUP_PART_BUTTON3 = "button3";
47 const char* BUTTON_CLICKED_CALLBACK_NAME = "clicked";
48 const char* CHANGED_CALLBACK_NAME = "changed";
49 const unsigned int MAX_NUMBER_OF_VERTICAL = 2;
51 Evas_Object* create_layout_main(Evas_Object* parent, int totalV)
53 Evas_Object *layout = elm_layout_add(parent);
56 elm_layout_file_set(layout, EDJ_NAME, POPUP_LAYOUT1);
57 } else if (totalV == 2) {
58 elm_layout_file_set(layout, EDJ_NAME, POPUP_LAYOUT2);
60 Assert("popup needs define new group in the edc");
63 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
70 class PopupRenderer::Impl
83 LogError("Destroyed without Deinitialize");
89 Assert(!m_initialized);
95 Assert(m_initialized);
96 m_current.Reset(NULL);
97 while (!m_popupsToRender.empty()) {
98 m_popupsToRender.pop();
100 m_initialized = false;
103 void ButtonCallback(EvasObject::IConnection* /*connection*/,
104 void* /*event_info*/,
107 LogInfo("ButtonCallback");
108 Assert(m_initialized);
109 AnswerCallbackData answerData;
111 answerData.buttonAnswer = reinterpret_cast<int>(data);
112 answerData.chackState = m_checkState;
113 answerData.password = m_password;
114 m_current->ForwardAnswer(answerData);
117 FOREACH(it, m_createdObjects)
120 evas_object_del(*it);
123 m_createdObjects.clear();
124 m_checkState = false;
128 void CheckCallback(EvasObject::IConnection* connection,
129 void* /*event_info*/,
133 elm_check_state_get(connection->GetEvasObject());
136 void Render (PopupPtr popup)
138 Assert(m_initialized);
139 m_popupsToRender.push(popup);
143 void DoRender(const PopupObject::Label& object,
148 EvasObject label(elm_label_add(parent));
150 elm_object_style_set(label, "popup_description/default");
151 elm_label_line_wrap_set(label, ELM_WRAP_WORD);
152 elm_object_text_set(label, object.getLabel().c_str());
153 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
154 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
155 evas_object_show(label);
157 elm_object_part_content_set(
159 DPL::lexical_cast<std::string>(themeIndex).c_str(),
161 m_createdObjects.push_back(label);
164 void DoRender(const PopupObject::Check& object,
169 EvasObject check(elm_check_add(parent));
171 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
172 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, 0.0);
173 elm_object_text_set(check,
174 object.getCheckLabel().c_str());
175 elm_object_part_content_set(
177 DPL::lexical_cast<std::string>(themeIndex).c_str(),
180 check.ConnectMemberSmartCallback(CHANGED_CALLBACK_NAME,
181 &Impl::CheckCallback,
183 static_cast<void*>(NULL));
184 evas_object_show(check);
185 m_createdObjects.push_back(check);
188 void DoRender(const PopupObject::Button& object,
191 EvasObject btn(elm_button_add(parent));
193 elm_object_text_set(btn, object.getLabel().c_str());
194 elm_object_part_content_set(parent, POPUP_PART_BUTTON1, btn);
195 btn.ConnectMemberSmartCallback(BUTTON_CLICKED_CALLBACK_NAME,
196 &Impl::ButtonCallback,
198 reinterpret_cast<void*>(object.getLabelId()));
199 m_createdObjects.push_back(btn);
202 void DoRender(const PopupObject::Button& object1,
203 const PopupObject::Button& object2,
206 EvasObject btn1(elm_button_add(parent));
207 EvasObject btn2(elm_button_add(parent));
209 elm_object_text_set(btn1, object1.getLabel().c_str());
210 elm_object_part_content_set(parent, POPUP_PART_BUTTON1, btn1);
211 btn1.ConnectMemberSmartCallback(BUTTON_CLICKED_CALLBACK_NAME,
212 &Impl::ButtonCallback,
214 reinterpret_cast<void*>(object1.getLabelId()));
216 elm_object_text_set(btn2, object2.getLabel().c_str());
217 elm_object_part_content_set(parent, POPUP_PART_BUTTON2, btn2);
218 btn2.ConnectMemberSmartCallback(BUTTON_CLICKED_CALLBACK_NAME,
219 &Impl::ButtonCallback,
221 reinterpret_cast<void*>(object2.getLabelId()));
222 m_createdObjects.push_back(btn1);
223 m_createdObjects.push_back(btn2);
226 void DoRender(const PopupObject::Button& object1,
227 const PopupObject::Button& object2,
228 const PopupObject::Button& object3,
231 EvasObject btn1(elm_button_add(parent));
232 EvasObject btn2(elm_button_add(parent));
233 EvasObject btn3(elm_button_add(parent));
235 elm_object_text_set(btn1, object1.getLabel().c_str());
236 elm_object_part_content_set(parent, POPUP_PART_BUTTON1, btn1);
237 btn1.ConnectMemberSmartCallback(BUTTON_CLICKED_CALLBACK_NAME,
238 &Impl::ButtonCallback,
240 reinterpret_cast<void*>(object1.getLabelId()));
242 elm_object_text_set(btn2, object2.getLabel().c_str());
243 elm_object_part_content_set(parent, POPUP_PART_BUTTON2, btn2);
244 btn2.ConnectMemberSmartCallback(BUTTON_CLICKED_CALLBACK_NAME,
245 &Impl::ButtonCallback,
247 reinterpret_cast<void*>(object2.getLabelId()));
249 elm_object_text_set(btn3, object3.getLabel().c_str());
250 elm_object_part_content_set(parent, POPUP_PART_BUTTON3, btn3);
251 btn3.ConnectMemberSmartCallback(BUTTON_CLICKED_CALLBACK_NAME,
252 &Impl::ButtonCallback,
254 reinterpret_cast<void*>(object3.getLabelId()));
255 m_createdObjects.push_back(btn1);
256 m_createdObjects.push_back(btn2);
257 m_createdObjects.push_back(btn3);
260 EvasObject getBaseObject()
262 if (getExternalCanvas() == NULL) {
263 LogInfo("Create old style popup");
264 EvasObject win(elm_win_add(NULL, "Popup", ELM_WIN_DIALOG_BASIC));
265 elm_win_borderless_set(win, EINA_TRUE);
266 elm_win_alpha_set(win, EINA_TRUE);
270 ecore_x_window_geometry_get(ecore_x_window_root_first_get(),
275 evas_object_resize(win, w, h);
276 evas_object_move(win, x, y);
278 m_createdObjects.push_back(win);
279 evas_object_show(win);
282 LogInfo("Create new style popup");
283 EvasObject win(getExternalCanvas());
284 evas_object_show(win);
291 if (!m_current && !m_popupsToRender.empty()) {
292 m_current = m_popupsToRender.front();
293 m_popupsToRender.pop();
298 std::vector<int> countPopupObjects = {0 /* PopupObject::BUTTON */,
299 0 /* PopupObject::LABEL */,
300 0 /* PopupObject::CHECK */};
301 FOREACH(it, m_current->GetPopupObjects()) {
302 Assert((*it)->getType() < countPopupObjects.size() &&
303 "Wrong PopupObject assigned");
304 countPopupObjects[(*it)->getType()]++;
306 int needsIndexV = countPopupObjects[PopupObject::LABEL] +
307 countPopupObjects[PopupObject::CHECK];
309 EvasObject win = getBaseObject();
310 EvasObject main(elm_popup_add(win));
312 evas_object_size_hint_weight_set(main,
315 elm_object_part_text_set(main,
317 m_current->GetTitle().c_str());
319 m_createdObjects.push_back(main);
320 std::vector<PopupObject::Button> buttonObjectList;
321 EvasObject layout(create_layout_main(main, needsIndexV));
322 m_createdObjects.push_back(layout);
324 FOREACH(it, m_current->GetPopupObjects()) {
325 switch ((*it)->getType()) {
326 case PopupObject::BUTTON:
327 buttonObjectList.push_back(*(*it)->asButton());
329 case PopupObject::LABEL:
330 DoRender(*(*it)->asLabel(),
335 case PopupObject::CHECK:
336 DoRender(*(*it)->asCheck(),
342 Assert("incorrect type");
344 Assert(m_themeIndexV <= MAX_NUMBER_OF_VERTICAL);
346 elm_object_content_set(main,
350 switch(buttonObjectList.size()) {
352 LogInfo("no button");
355 DoRender(buttonObjectList.at(0),
359 DoRender(buttonObjectList.at(0),
360 buttonObjectList.at(1),
364 DoRender(buttonObjectList.at(0),
365 buttonObjectList.at(1),
366 buttonObjectList.at(2),
370 Assert("incorrect button number");
374 evas_object_show(main);
378 void setExternalCanvas(void* externalCanvas)
380 m_externalCanvas = static_cast<Evas_Object*>(externalCanvas);
383 Evas_Object* getExternalCanvas() const
385 return m_externalCanvas;
388 std::queue<PopupPtr> m_popupsToRender;
389 std::list<EvasObject> m_createdObjects;
393 DPL::Optional<std::string> m_password;
394 unsigned int m_themeIndexV;
397 Evas_Object* m_externalCanvas;
400 PopupRenderer::PopupRenderer()
402 m_impl = new PopupRenderer::Impl();
405 PopupRenderer::~PopupRenderer()
410 void PopupRenderer::Initialize()
413 m_impl->Initialize();
416 void PopupRenderer::Deinitialize()
419 m_impl->Deinitialize();
422 IPopupPtr PopupRenderer::CreatePopup()
424 return DPL::StaticPointerCast<IPopup>(IPopupPtr
425 (new Popup(SharedFromThis())));
428 void PopupRenderer::Render(PopupPtr popup)
430 m_impl->Render(popup);
433 void PopupRenderer::setExternalCanvas(void* externalCanvas)
435 m_impl->setExternalCanvas(externalCanvas);