2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FWebCtrl_WebPopup.cpp
20 * @brief The file contains the definition of _WebPopup class.
22 #include <FBaseColIList.h>
23 #include <FBaseSysLog.h>
24 #include <FUiCtrlButton.h>
25 #include <FUiCtrlPanel.h>
26 #include <FUiVerticalBoxLayout.h>
27 #include <FUi_ResourceManager.h>
28 #include "FWebCtrl_WebManager.h"
29 #include "FWebCtrl_WebPopup.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Io;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
40 namespace Tizen { namespace Web { namespace Controls
43 std::unique_ptr<_WebPopupData> _WebPopup::__pWebPopupData(null);
45 _WebPopup::_WebPopup(void)
52 _WebPopup::~_WebPopup(void)
58 __pWebPopupData.reset();
63 _WebPopup::Construct(bool hasTitle, const Dimension& popupDim)
65 VerticalBoxLayout layout;
67 Dimension dim(popupDim);
68 dim.height += __pWebPopupData->bottomMargin;
72 dim.height += __pWebPopupData->titleHeight;
75 result r = layout.Construct(VERTICAL_DIRECTION_DOWNWARD);
76 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
78 r = Popup::Construct(layout, layout, hasTitle, dim);
79 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
86 _WebPopup::OnActionPerformed(const Control& source, int actionId)
90 case ID_BUTTON_COMMON_CLOSE:
94 SysAssertf(false, "unknown action ID used");
103 _WebPopup::ShowPopup(void)
105 result r = E_SUCCESS;
107 _WebManager* pWebManager = _WebManager::GetInstance();
108 pWebManager->SetActivePopup(this);
110 r = SetShowState(true);
111 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
114 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
121 _WebPopup::HidePopup(int modalResult)
123 result r = E_SUCCESS;
125 r = SetShowState(false);
126 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
128 _WebManager* pWebManager = _WebManager::GetInstance();
129 pWebManager->RemoveActivePopup(this);
133 __modal = modalResult;
136 return EndModal(__modal);
144 _WebPopup::ShowAndWait(int& modalResult)
146 _WebManager* pWebManager = _WebManager::GetInstance();
147 pWebManager->SetActivePopup(this);
151 return DoModal(modalResult);
156 _WebPopup::CreateAndAddPanel(void)
158 std::unique_ptr<Panel> pPanel(new (std::nothrow) Panel());
159 SysTryReturn(NID_WEB_CTRL, pPanel.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
161 Rectangle panelRect(0, 0, __pWebPopupData->popupDim.width, __pWebPopupData->btnDim.height);
163 result r = pPanel->Construct(panelRect);
164 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
166 r = AddControl(*pPanel);
167 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
169 return pPanel.release();
174 _WebPopup::CreateAndAddButtons(const IList& buttonIds, const IList& buttonTitles, Panel* pPanel)
176 SysTryReturnResult(NID_WEB_CTRL, pPanel, E_INVALID_ARG, "[%s] Panel Pointer is null.", GetErrorMessage(E_INVALID_ARG));
178 _WebPopup* pParent = dynamic_cast<_WebPopup*>(pPanel->GetParent());
179 SysTryReturnResult(NID_WEB_CTRL, pParent == this, E_INVALID_ARG, "[E_INVALID_ARG] Panel not attached to popup.");
181 int idCount = buttonIds.GetCount();
182 int titleCount = buttonTitles.GetCount();
183 SysTryReturnResult(NID_WEB_CTRL, idCount > 0 && titleCount > 0 && idCount == titleCount, E_INVALID_DATA, "[E_INVALID_DATA] mismatch in count of Ids and Ttitles.");
185 int buttonMargin = __pWebPopupData->spacePad/2;
186 int buttonWidth = (__pWebPopupData->popupDim.width - buttonMargin*(idCount+1)) / idCount;
188 result r = E_SUCCESS;
189 for (int i = 0; i < idCount; i++)
191 const Integer* pButtonId = static_cast<const Integer*>(buttonIds.GetAt(i));
192 const String* pButtonTitle = static_cast<const String*>(buttonTitles.GetAt(i));
193 SysTryReturn(NID_WEB_CTRL, pButtonId && pButtonTitle, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
196 std::unique_ptr<Button> pButton(new (std::nothrow) Button());
197 SysTryReturnResult(NID_WEB_CTRL, pButton.get(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory Allocation failed.");
199 r = pButton->Construct(Rectangle((buttonMargin*(i+1))+(buttonWidth*i), 0, buttonWidth, __pWebPopupData->btnDim.height), *pButtonTitle);
200 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
202 pButton->SetActionId(pButtonId->ToInt());
204 //Add button to panel
205 r = pPanel->AddControl(*pButton);
206 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
208 pButton->AddActionEventListener(*this);
217 _WebPopup::IsModalPopup(void)
224 _WebPopup::GetPopupData(bool refresh)
226 if (!refresh && __pWebPopupData.get())
228 return __pWebPopupData.get();
231 __pWebPopupData.reset();
233 __pWebPopupData = std::unique_ptr<_WebPopupData> (new (std::nothrow) _WebPopupData());
234 SysTryReturn(NID_WEB_CTRL, __pWebPopupData.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
236 _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
238 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, __pWebPopupData->popupDim.width);
239 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, __pWebPopupData->popupDim.height);
240 GET_SHAPE_CONFIG(POPUP::SIDE_BORDER, orientation, __pWebPopupData->sideMargin);
241 GET_SHAPE_CONFIG(POPUP::BOTTOM_BORDER, orientation, __pWebPopupData->bottomMargin);
242 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, orientation, __pWebPopupData->titleHeight);
244 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, __pWebPopupData->btnDim.height);
245 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_02, orientation, __pWebPopupData->spacePad);
247 GET_SHAPE_CONFIG(LABEL::TEXT_FONT_SIZE, orientation, __pWebPopupData->labelFontSize);
248 GET_DIMENSION_CONFIG(CHECKBUTTON::MIN_DIMENSION, orientation, __pWebPopupData->checkDim);
250 GET_DIMENSION_CONFIG(EDIT::MIN_SIZE, orientation, __pWebPopupData->editDim);
252 __pWebPopupData->labelDim.width = __pWebPopupData->popupDim.width - 2*__pWebPopupData->sideMargin;
253 __pWebPopupData->labelDim.height = 3*__pWebPopupData->labelFontSize;
255 return __pWebPopupData.get();
260 _WebPopup::OnTerminating(void)
266 }}} // Tizen::Web::Controls