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_AuthConfirmPopup.cpp
20 * @brief The file contains the definition of _AuthConfirmPopup class.
22 #include <FGrpDimension.h>
23 #include <FGrpRectangle.h>
24 #include <FUiCtrlButton.h>
25 #include <FUiCtrlEditField.h>
26 #include <FUiCtrlLabel.h>
27 #include <FUiCtrlPanel.h>
28 #include <FUiLayout.h>
29 #include <FUiVerticalBoxLayout.h>
30 #include <FWebCtrlAuthenticationChallenge.h>
31 #include <FBaseSysLog.h>
32 #include <FUiCtrl_PopupImpl.h>
33 #include <FUi_ControlManager.h>
34 #include <FUi_ResourceManager.h>
35 #include <FGrpColor.h>
36 #include <FUiCtrlTextBox.h>
37 #include <FUiCtrl_TextBoxImpl.h>
38 #include <FSys_SystemResource.h>
39 #include "FWebCtrl_WebImpl.h"
40 #include "FWebCtrl_PromptPopup.h"
42 using namespace Tizen::Base;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Web::Controls;
45 using namespace Tizen::Ui::Controls;
46 using namespace Tizen::Ui;
48 static const int LABEL_HEIGHT = 10;
50 namespace Tizen { namespace Web { namespace Controls
54 _PromptPopup::_PromptPopup(void)
60 _PromptPopup::~_PromptPopup(void)
67 _PromptPopup::Construct(const Tizen::Base::String& message, const Tizen::Base::String& defaultVale)
73 Rectangle rect(0, 0, 0, 0);
81 int gapForControls = 0;
83 _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
85 GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, popupWidth);
86 GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, popupHeight);
87 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, buttonHeight);
88 GET_SHAPE_CONFIG(POPUP::SIDE_BORDER, orientation, sideMargin);
89 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_02, orientation, spacePad);
90 r = GET_DIMENSION_CONFIG(EDIT::MIN_SIZE, orientation, editDim);
91 GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_TOP_MARGIN, orientation, gapForControls);
93 VerticalBoxLayout layout;
94 r = layout.Construct(VERTICAL_DIRECTION_DOWNWARD);
96 Tizen::System::_SystemResource* pSysResource = Tizen::System::_SystemResource::GetInstance();
97 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
99 std::unique_ptr<Popup> pPopup(new (std::nothrow) Popup());
100 SysTryReturnResult(NID_WEB_CTRL, pPopup.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
102 popupHeight = LABEL_HEIGHT + (2 * editDim.height + gapForControls) + buttonHeight + (4 * spacePad) ;
104 r = pPopup->Construct(layout, layout, true, Tizen::Graphics::Dimension(popupWidth, popupHeight));
105 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
107 pPopup->SetTitleText("Prompt Dialog");
109 //Temp Label for Y position adjustment using Vertical layout.
112 rect.height = LABEL_HEIGHT;
113 rect.width = popupWidth - 2*sideMargin;;
115 std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
116 SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
118 r = pLabel->Construct(rect, L"");
119 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
121 r = pPopup->AddControl(*pLabel);
122 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
124 Label* pTmpLabel = pLabel.release();
127 rect = pPopup->GetClientAreaBounds();
128 rect.width = popupWidth - 2*sideMargin;
130 rect.height = editDim.height;
132 std::unique_ptr<TextBox> pTextBox(new (std::nothrow) TextBox());
133 SysTryReturnResult(NID_WEB_CTRL, pTextBox.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
135 r = pTextBox->Construct(rect, TEXT_BOX_BORDER_ROUNDED);
136 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
138 pTextBox->SetText(message);
139 pTextBox->SetColor(TEXT_BOX_STATUS_NORMAL, pPopup->GetColor());
140 pTextBox->SetColor(TEXT_BOX_STATUS_HIGHLIGHTED, pPopup->GetColor());
142 r = pPopup->AddControl(*pTextBox);
143 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
145 TextBox* pTmpTextBox = pTextBox.release();
150 rect.height = editDim.height;
152 std::unique_ptr<EditField> pEditField(new (std::nothrow) EditField());
153 SysTryReturnResult(NID_WEB_CTRL, pEditField.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
155 r = pEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
156 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
158 pEditField->SetText(defaultVale);
160 r = pPopup->AddControl(*pEditField);
161 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
163 __pEditField = pEditField.release();
166 buttonWidth = (popupWidth / 2) - (spacePad) - (sideMargin * 2);
168 std::unique_ptr<Panel> pPanel(new Panel());
169 SysTryReturnResult(NID_WEB_CTRL, pPanel.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
171 r = pPanel->Construct(Rectangle(0, 0, rect.width, buttonHeight + gapForControls));
172 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
174 r = pPopup->AddControl(*pPanel);
175 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
177 Panel* pTempPanel = pPanel.release();
180 buttonStr = pSysResource->GetString("sys_string", "IDS_COM_SK_OK");
181 std::unique_ptr<Button> pBtnOk(new (std::nothrow) Button());
182 SysTryReturnResult(NID_WEB_CTRL, pBtnOk.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
184 r = pBtnOk->Construct(Rectangle(sideMargin, gapForControls, buttonWidth, buttonHeight), buttonStr);
185 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
187 pBtnOk->SetActionId(ID_BUTTON_PROMPT_OK);
189 r = pTempPanel->AddControl(*pBtnOk);
190 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
192 pBtnOk->AddActionEventListener(*this);
196 buttonStr = pSysResource->GetString("sys_string", "IDS_COM_POP_CANCEL");
197 std::unique_ptr<Button> pBtnCancel(new (std::nothrow) Button());
198 SysTryReturnResult(NID_WEB_CTRL, pBtnCancel.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
200 r = pBtnCancel->Construct(Rectangle(buttonWidth + spacePad + sideMargin, gapForControls, buttonWidth, buttonHeight), buttonStr);
201 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
203 pBtnCancel->SetActionId(ID_BUTTON_PROMPT_CANCEL);
205 r = pTempPanel->AddControl(*pBtnCancel);
206 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
208 pBtnCancel->AddActionEventListener(*this);
209 pBtnCancel.release();
211 __pEditField->SetFocus();
213 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(pPopup->GetLayoutN()));
214 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
216 pLayout->SetHorizontalFitPolicy(*pTmpLabel, FIT_POLICY_PARENT);
217 pLayout->SetHorizontalFitPolicy(*pTempPanel, FIT_POLICY_PARENT);
218 pLayout->SetHorizontalFitPolicy(*__pEditField, FIT_POLICY_PARENT);
220 pLayout->SetHorizontalAlignment(*pTmpTextBox, LAYOUT_HORIZONTAL_ALIGN_LEFT);
221 pLayout->SetHorizontalAlignment(*__pEditField, LAYOUT_HORIZONTAL_ALIGN_LEFT);
222 pLayout->SetHorizontalAlignment(*pTempPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
224 pLayout->SetSpacing(*pTmpTextBox, gapForControls);
225 pLayout->SetSpacing(*__pEditField, gapForControls);
226 pLayout->SetSpacing(*pTempPanel, gapForControls);
228 __pPopup = std::move(pPopup);
234 _PromptPopup::GetPromptText()
236 return __pEditField->GetText();
241 _PromptPopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
245 case ID_BUTTON_PROMPT_OK:
247 __pPopup->SetShowState(false);
248 EndModal(ID_BUTTON_PROMPT_OK);
252 case ID_BUTTON_PROMPT_CANCEL:
253 __pPopup->SetShowState(false);
254 EndModal(ID_BUTTON_PROMPT_CANCEL);
263 _PromptPopup::ShowAndWait(int& modalResult)
265 return __pPopup->DoModal(modalResult);
270 _PromptPopup::EndModal(int modalResult)
272 return __pPopup->EndModal(modalResult);
275 }}} // Tizen::Web::Controls