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 <FGrpColor.h>
25 #include <FUiCtrlButton.h>
26 #include <FUiCtrlPanel.h>
27 #include <FUiVerticalBoxLayout.h>
28 #include <FUi_ResourceManager.h>
29 #include "FWebCtrl_WebManager.h"
30 #include "FWebCtrl_WebPopup.h"
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Io;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
41 namespace Tizen { namespace Web { namespace Controls
44 std::unique_ptr<_WebPopupData> _WebPopup::__pWebPopupData(null);
46 _WebPopup::_WebPopup(void)
53 _WebPopup::~_WebPopup(void)
55 _WebManager* pWebManager = _WebManager::GetInstance();
56 pWebManager->RemoveActivePopup(this);
62 __pWebPopupData.reset();
67 _WebPopup::Construct(bool hasTitle, const Dimension& popupDim)
69 VerticalBoxLayout layout;
71 Dimension dim(popupDim);
75 dim.height += __pWebPopupData->titleHeight;
78 result r = layout.Construct(VERTICAL_DIRECTION_DOWNWARD);
79 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
81 r = Popup::Construct(layout, layout, hasTitle, dim);
82 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
89 _WebPopup::OnActionPerformed(const Control& source, int actionId)
93 case ID_BUTTON_COMMON_CLOSE:
97 SysAssertf(false, "unknown action ID used");
106 _WebPopup::ShowPopup(void)
108 result r = E_SUCCESS;
110 _WebManager* pWebManager = _WebManager::GetInstance();
111 pWebManager->SetActivePopup(this);
113 r = SetShowState(true);
114 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
117 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
124 _WebPopup::HidePopup(int modalResult)
126 result r = E_SUCCESS;
128 r = SetShowState(false);
129 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
133 __modal = modalResult;
136 r = EndModal(__modal);
137 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
145 _WebPopup::ShowAndWait(int& modalResult)
147 _WebManager* pWebManager = _WebManager::GetInstance();
148 pWebManager->SetActivePopup(this);
152 return DoModal(modalResult);
157 _WebPopup::CreateAndAddPanel(void)
159 std::unique_ptr<Panel> pPanel(new (std::nothrow) Panel());
160 SysTryReturn(NID_WEB_CTRL, pPanel.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
162 Rectangle panelRect(0, 0, GetSize().width, __pWebPopupData->panelHeight);
164 result r = pPanel->Construct(panelRect, GROUP_STYLE_BOTTOM);
165 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
167 Color buttonBgColor(0x00000000);
168 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BG_NORMAL, buttonBgColor);
169 pPanel->SetBackgroundColor(buttonBgColor);
171 r = AddControl(*pPanel);
172 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
174 return pPanel.release();
179 _WebPopup::CreateAndAddButtons(const IList& buttonIds, const IList& buttonTitles, Panel* pPanel)
181 SysTryReturnResult(NID_WEB_CTRL, pPanel, E_INVALID_ARG, "[%s] Panel Pointer is null.", GetErrorMessage(E_INVALID_ARG));
183 _WebPopup* pParent = dynamic_cast<_WebPopup*>(pPanel->GetParent());
184 SysTryReturnResult(NID_WEB_CTRL, pParent == this, E_INVALID_ARG, "[E_INVALID_ARG] Panel not attached to popup.");
186 int idCount = buttonIds.GetCount();
187 int titleCount = buttonTitles.GetCount();
188 SysTryReturnResult(NID_WEB_CTRL, idCount > 0 && titleCount > 0 && idCount == titleCount, E_INVALID_DATA, "[E_INVALID_DATA] mismatch in count of Ids and Ttitles.");
190 int buttonMargin = __pWebPopupData->spacePad/2;
193 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_01, _CONTROL_ORIENTATION_PORTRAIT, buttonMargin);
195 int buttonWidth = (GetSize().width - buttonMargin*(idCount+1)) / idCount;
196 int buttonTopMargin = (__pWebPopupData->panelHeight - __pWebPopupData->btnDim.height)/2;
198 result r = E_SUCCESS;
201 Color buttonColorNormal(0x00000000);
202 Color buttonColorPressed(0x00000000);
203 Color buttonColorDisabled(0x00000000);
204 Color buttonColorHighlighted(0x00000000);
205 Color buttonTextNormal(0x00000000);
206 Color buttonTextPressed(0x00000000);
207 Color buttonTextDisabled(0x00000000);
208 Color buttonTextHighlighted(0x00000000);
210 Bitmap* pComposedButtonBgNormal = null;
211 Bitmap* pComposedButtonBgPressed = null;
212 Bitmap* pComposedButtonBgDisabled = null;
213 Bitmap* pComposedButtonBgHighlighted = null;
215 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_BG_NORMAL, buttonColorNormal);
216 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_BG_PRESSED, buttonColorPressed);
217 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_BG_DISABLED, buttonColorDisabled);
218 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_BG_HIGHLIGHTED, buttonColorHighlighted);
220 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_TEXT_NORMAL, buttonTextNormal);
221 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_TEXT_PRESSED, buttonTextPressed);
222 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_TEXT_DISABLED, buttonTextDisabled);
223 GET_COLOR_CONFIG(MESSAGEBOX::BOTTOM_BUTTON_TEXT_HIGHLIGHTED, buttonTextHighlighted);
225 r = GET_REPLACED_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, buttonColorNormal, pComposedButtonBgNormal);
226 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
227 std::unique_ptr< Bitmap > pComposedBtnBgNormal(pComposedButtonBgNormal);
229 r = GET_REPLACED_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, buttonColorPressed, pComposedButtonBgPressed);
230 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
231 std::unique_ptr< Bitmap > pComposedBtnBgPressed(pComposedButtonBgPressed);
233 r = GET_REPLACED_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, buttonColorDisabled, pComposedButtonBgDisabled);
234 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
235 std::unique_ptr< Bitmap > pComposedBtnBgDisabled(pComposedButtonBgDisabled);
237 r = GET_REPLACED_BITMAP_CONFIG_N(MESSAGEBOX::BOTTOM_BUTTON_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, buttonColorHighlighted, pComposedButtonBgHighlighted);
238 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
239 std::unique_ptr< Bitmap > pComposedBtnBgHighlighted(pComposedButtonBgHighlighted);
241 for (int i = 0; i < idCount; i++)
243 const Integer* pButtonId = static_cast<const Integer*>(buttonIds.GetAt(i));
244 const String* pButtonTitle = static_cast<const String*>(buttonTitles.GetAt(i));
245 SysTryReturn(NID_WEB_CTRL, pButtonId && pButtonTitle, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
248 std::unique_ptr<Button> pButton(new (std::nothrow) Button());
249 SysTryReturnResult(NID_WEB_CTRL, pButton.get(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory Allocation failed.");
251 r = pButton->Construct(Rectangle((buttonMargin*(i+1))+(buttonWidth*i), buttonTopMargin, buttonWidth, __pWebPopupData->btnDim.height), *pButtonTitle);
252 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
254 pButton->SetActionId(pButtonId->ToInt());
256 pButton->SetNormalBackgroundBitmap(*pComposedBtnBgNormal);
257 pButton->SetPressedBackgroundBitmap(*pComposedBtnBgPressed);
258 pButton->SetDisabledBackgroundBitmap(*pComposedBtnBgDisabled);
259 pButton->SetHighlightedBackgroundBitmap(*pComposedBtnBgHighlighted);
260 pButton->SetTextColor(buttonTextNormal);
261 pButton->SetPressedTextColor(buttonTextPressed);
262 pButton->SetDisabledTextColor(buttonTextDisabled);
263 pButton->SetHighlightedTextColor(buttonTextHighlighted);
265 //Add button to panel
266 r = pPanel->AddControl(*pButton);
267 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
269 pButton->AddActionEventListener(*this);
278 _WebPopup::IsModalPopup(void)
285 _WebPopup::GetPopupData(bool refresh)
287 if (!refresh && __pWebPopupData.get())
289 return __pWebPopupData.get();
292 __pWebPopupData.reset();
294 __pWebPopupData = std::unique_ptr<_WebPopupData> (new (std::nothrow) _WebPopupData());
295 SysTryReturn(NID_WEB_CTRL, __pWebPopupData.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
297 _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
299 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, __pWebPopupData->popupDim.width);
300 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, __pWebPopupData->popupDim.height);
301 GET_SHAPE_CONFIG(POPUP::SIDE_BORDER, orientation, __pWebPopupData->sideMargin);
302 GET_SHAPE_CONFIG(POPUP::BOTTOM_BORDER, orientation, __pWebPopupData->bottomMargin);
303 GET_SHAPE_CONFIG(POPUP::TITLE_HEIGHT, orientation, __pWebPopupData->titleHeight);
305 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, __pWebPopupData->btnDim.height);
306 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_02, orientation, __pWebPopupData->spacePad);
307 GET_SHAPE_CONFIG(MESSAGEBOX::BOTTOM_HEIGHT, orientation, __pWebPopupData->panelHeight);
309 GET_SHAPE_CONFIG(LABEL::TEXT_FONT_SIZE, orientation, __pWebPopupData->labelFontSize);
310 GET_DIMENSION_CONFIG(CHECKBUTTON::MIN_DIMENSION, orientation, __pWebPopupData->checkDim);
312 GET_DIMENSION_CONFIG(EDIT::MIN_SIZE, orientation, __pWebPopupData->editDim);
314 __pWebPopupData->labelDim.width = __pWebPopupData->popupDim.width - 2*__pWebPopupData->sideMargin;
315 __pWebPopupData->labelDim.height = 3*__pWebPopupData->labelFontSize;
317 return __pWebPopupData.get();
322 _WebPopup::OnTerminating(void)
328 }}} // Tizen::Web::Controls