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