Revert " modify license, permission and remove ^M char"
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_MessageBoxImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /**
19  * @file                FUiCtrl_MessageBoxImpl.cpp
20  * @brief       This is the implementation file for the _MessageBoxImpl class.
21  */
22
23
24 // Includes
25 #include <FBaseSysLog.h>
26 #include "FUi_ControlImplManager.h"
27 #include "FUi_CoordinateSystemUtils.h"
28 #include "FUi_ResourceManager.h"
29 #include "FUiCtrl_FrameImpl.h"
30 #include "FUiCtrl_MessageBoxImpl.h"
31 #include "FUiCtrl_Form.h"
32
33
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Base;
36
37
38 namespace Tizen { namespace Ui { namespace Controls
39 {
40
41
42 _MessageBoxImpl*
43 _MessageBoxImpl::GetInstance(MessageBox& pMessageBox)
44 {
45         return static_cast <_MessageBoxImpl*>(pMessageBox._pControlImpl);
46 }
47
48 const _MessageBoxImpl*
49 _MessageBoxImpl::GetInstance(const MessageBox& pMessageBox)
50 {
51         return static_cast <const _MessageBoxImpl*>(pMessageBox._pControlImpl);
52 }
53
54 _MessageBoxImpl::_MessageBoxImpl(MessageBox* pPublic, _MessageBox* pCore)
55         : _WindowImpl(pPublic, pCore)
56 {
57         // empty statement
58 }
59
60 _MessageBoxImpl::~_MessageBoxImpl(void)
61 {
62         // empty statement
63 }
64
65 _MessageBoxImpl*
66 _MessageBoxImpl::CreateMessageBoxImplN(MessageBox* pControl)
67 {
68         result r = E_SUCCESS;
69
70         _MessageBox* pCore = null;
71         _MessageBoxImpl* pImpl = null;
72
73         pCore = _MessageBox::CreateMessageBoxN();
74         r = GetLastResult();
75         SysTryReturn(NID_UI_CTRL, pCore, null, r, "[%s] Propagating.", GetErrorMessage(r));
76
77         pImpl = new (std::nothrow) _MessageBoxImpl(pControl, pCore);
78         r = CheckConstruction(pCore, pImpl);
79         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
80
81         return pImpl;
82 }
83
84 result
85 _MessageBoxImpl::Initialize(const Tizen::Base::String& title, const Tizen::Base::String& text, MessageBoxStyle style, unsigned long timeout)
86 {
87         result r = E_SUCCESS;
88
89         FloatRectangle bounds;
90         float totalH = -1.0f;
91
92         float maxHeight = 0.0f;
93         float defaultWidth = 0.0f;
94
95         _ControlOrientation orientation;
96
97         r = GetCore().Initialize(title, text, style, timeout);
98         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
99
100         orientation = GetCore().GetOrientation();
101         GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, maxHeight);
102         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
103
104         totalH = GetCore().GetTotalHeight();
105
106         if (totalH > maxHeight)
107         {
108                 bounds = GetCenterAlignRect(defaultWidth, maxHeight);
109         }
110         else
111         {
112                 bounds = GetCenterAlignRect(defaultWidth, totalH);
113         }
114
115         r = SetBounds(bounds);
116         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
117
118         SetMovable(false);
119         SetResizable(false);
120
121         return r;
122 }
123
124 const char*
125 _MessageBoxImpl::GetPublicClassName(void) const
126 {
127         return "Tizen::Ui::Controls::MessageBox";
128 }
129
130 const MessageBox&
131 _MessageBoxImpl::GetPublic(void) const
132 {
133         return static_cast <const MessageBox&>(_ControlImpl::GetPublic());
134 }
135
136 MessageBox&
137 _MessageBoxImpl::GetPublic(void)
138 {
139         return static_cast <MessageBox&>(_ControlImpl::GetPublic());
140 }
141
142 const _MessageBox&
143 _MessageBoxImpl::GetCore(void) const
144 {
145         return static_cast <const _MessageBox&>(_ControlImpl::GetCore());
146 }
147
148 _MessageBox&
149 _MessageBoxImpl::GetCore(void)
150 {
151         return static_cast <_MessageBox&>(_ControlImpl::GetCore());
152 }
153
154 result
155 _MessageBoxImpl::ShowAndWait(int& modalResult)
156 {
157         SysTryReturn(NID_UI_CTRL, GetVisibleState() != false, E_SYSTEM,
158                                 E_SYSTEM, "[E_SYSTEM] This control is not visible");
159
160         return GetCore().ShowAndWait(modalResult);
161 }
162
163 void
164 _MessageBoxImpl::SetColor(const Color& color)
165 {
166         return GetCore().SetColor(color);
167 }
168
169 Color
170 _MessageBoxImpl::GetColor() const
171 {
172         return GetCore().GetColor();
173 }
174
175 void
176 _MessageBoxImpl::SetTitleTextColor(const Color& color)
177 {
178         return GetCore().SetTitleTextColor(color);
179 }
180
181 Color
182 _MessageBoxImpl::GetTitleTextColor() const
183 {
184         return GetCore().GetTitleTextColor();
185 }
186 void
187 _MessageBoxImpl::SetTextColor(const Color& color)
188 {
189         return GetCore().SetTextColor(color);
190 }
191
192 Color
193 _MessageBoxImpl::GetTextColor() const
194 {
195         return GetCore().GetTextColor();
196 }
197
198 MessageBoxStyle
199 _MessageBoxImpl::GetMessageBoxStyle(void) const
200 {
201         return GetCore().GetMsgBoxStyle();
202 }
203
204 String
205 _MessageBoxImpl::GetTitleText(void) const
206 {
207         return GetCore().GetTitleText();
208 }
209
210 String
211 _MessageBoxImpl::GetText(void) const
212 {
213         return GetCore().GetText();
214 }
215
216 unsigned long
217 _MessageBoxImpl::GetTimeout(void) const
218 {
219         return GetCore().GetTimeout();
220 }
221
222 int
223 _MessageBoxImpl::GetMaxTextLength(void) const
224 {
225         int maxLength = 0;
226         GET_FIXED_VALUE_CONFIG(MESSAGEBOX::TEXT_MAX_LENGTH, GetCore().GetOrientation(), maxLength);
227
228         return maxLength;
229 }
230
231 FloatRectangle
232 _MessageBoxImpl::GetCenterAlignRect(float width, float height) const
233 {
234         float x = 0.0f;
235         float y = 0.0f;
236
237         FloatDimension screenRect = _ControlManager::GetInstance()->GetScreenSizeF();
238
239         if (GetCore().GetOrientation() == _CONTROL_ORIENTATION_LANDSCAPE)
240         {
241                 float temp = screenRect.width;
242                 screenRect.width = screenRect.height;
243                 screenRect.height = temp;
244         }
245
246         x = (screenRect.width - width) / 2.0f;
247         y = (screenRect.height - height) / 2.0f;
248
249         return FloatRectangle(x, y, width, height);
250 }
251
252
253 void
254 _MessageBoxImpl::OnChangeLayout(_ControlOrientation orientation)
255 {
256         result r = E_SUCCESS;
257
258         float defaultWidth;
259         float maxHeight;
260         float totalH;
261         FloatRectangle bounds;
262
263         GetCore().OnChangeLayout(orientation);
264
265         r = GetLastResult();
266         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
267
268         SetResizable(true);
269         SetMovable(true);
270
271         GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, maxHeight);
272         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, defaultWidth);
273
274         totalH = GetCore().GetTotalHeight();
275
276         if (totalH > maxHeight)
277         {
278                 totalH = maxHeight;
279         }
280
281         bounds = GetCenterAlignRect(defaultWidth, totalH);
282
283         r = SetBounds(bounds);
284
285         SetMovable(false);
286         SetResizable(false);
287
288         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
289
290         return ;
291 }
292
293
294 }}} // Tizen::Ui::Controls