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 <FBaseColIList.h>
23 #include <FBaseSysLog.h>
24 #include <FGrpColor.h>
25 #include <FGrpDimension.h>
26 #include <FGrpRectangle.h>
27 #include <FUiCtrlButton.h>
28 #include <FUiCtrlEditField.h>
29 #include <FUiCtrlLabel.h>
30 #include <FUiCtrlPanel.h>
31 #include <FUiCtrlTextBox.h>
32 #include <FUiLayout.h>
33 #include <FUiVerticalBoxLayout.h>
34 #include <FWebCtrlAuthenticationChallenge.h>
35 #include <FSys_SystemResource.h>
36 #include <FUi_ControlManager.h>
37 #include <FUi_ResourceManager.h>
38 #include <FUiCtrl_TextBoxImpl.h>
39 #include "FWebCtrl_WebImpl.h"
40 #include "FWebCtrl_PromptPopup.h"
43 using namespace Tizen::Base;
44 using namespace Tizen::Base::Collection;
45 using namespace Tizen::Graphics;
46 using namespace Tizen::System;
47 using namespace Tizen::Ui;
48 using namespace Tizen::Ui::Controls;
51 static const int LABEL_HEIGHT = 10;
54 namespace Tizen { namespace Web { namespace Controls
58 _PromptPopup::_PromptPopup(void)
63 _PromptPopup::~_PromptPopup(void)
70 _PromptPopup::Construct(const String& message, const String& defaultVale)
73 Rectangle rect(0, 0, 0, 0);
77 _WebPopupData* pPopupData = _WebPopup::GetPopupData();
78 SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
80 popupHeight = LABEL_HEIGHT + (2 * pPopupData->editDim.height + pPopupData->spacePad) + pPopupData->btnDim.height + (4 * pPopupData->spacePad) ;
82 r = _WebPopup::Construct(true, Dimension(pPopupData->popupDim.width, popupHeight));
83 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
84 SetTitleText("Prompt Dialog");
87 rect = GetClientAreaBounds();
88 rect.width = pPopupData->popupDim.width - 2 * pPopupData->sideMargin;
90 rect.height = pPopupData->editDim.height + 10;
92 std::unique_ptr<TextBox> pTextBox(new (std::nothrow) TextBox());
93 SysTryReturnResult(NID_WEB_CTRL, pTextBox.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
95 r = pTextBox->Construct(rect, TEXT_BOX_BORDER_ROUNDED);
96 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
98 pTextBox->SetText(message);
99 pTextBox->SetColor(TEXT_BOX_STATUS_NORMAL, GetColor());
100 pTextBox->SetColor(TEXT_BOX_STATUS_HIGHLIGHTED, GetColor());
102 r = AddControl(*pTextBox);
103 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
105 TextBox* pTmpTextBox = pTextBox.release();
110 rect.height = pPopupData->editDim.height + 10;
112 std::unique_ptr<EditField> pEditField(new (std::nothrow) EditField());
113 SysTryReturnResult(NID_WEB_CTRL, pEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
115 r = pEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
116 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
118 pEditField->SetText(defaultVale);
120 r = AddControl(*pEditField);
121 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
123 __pEditField = pEditField.release();
124 __pEditField->SetFocus();
127 Panel* pButtonPanel = CreateAndAddPanel();
128 SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
130 _SystemResource* pSysResource = _SystemResource::GetInstance();
131 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
134 r = idList.Construct();
135 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
136 idList.Add(*(new Integer(ID_BUTTON_PROMPT_OK)));
137 idList.Add(*(new Integer(ID_BUTTON_PROMPT_CANCEL)));
140 r = titleList.Construct();
141 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
142 titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_SK_OK"))));
143 titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_POP_CANCEL"))));
145 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
146 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
148 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
149 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
151 pLayout->SetHorizontalAlignment(*pTmpTextBox, LAYOUT_HORIZONTAL_ALIGN_CENTER);
152 pLayout->SetHorizontalAlignment(*__pEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
153 pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
155 pLayout->SetSpacing(*pTmpTextBox, pPopupData->spacePad);
156 pLayout->SetSpacing(*__pEditField, pPopupData->spacePad);
157 pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
163 _PromptPopup::GetPromptText()
165 return __pEditField->GetText();
170 _PromptPopup::OnActionPerformed(const Control& source, int actionId)
174 case ID_BUTTON_PROMPT_OK:
176 HidePopup(ID_BUTTON_PROMPT_OK);
179 case ID_BUTTON_PROMPT_CANCEL:
181 HidePopup(ID_BUTTON_PROMPT_CANCEL);
190 }}} // Tizen::Web::Controls