Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / controls / FUiCtrl_MessageBox.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_MessageBox.cpp
20  * @brief       This is the implementation file for the _MessageBox class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FBaseErrorDefine.h>
25 #include <FGrp_BitmapImpl.h>
26 #include "FUi_AccessibilityContainer.h"
27 #include "FUi_AccessibilityElement.h"
28 #include "FUi_ResourceManager.h"
29 #include "FUiCtrl_Form.h"
30 #include "FUiCtrl_Frame.h"
31 #include "FUiCtrl_MessageBox.h"
32 #include "FUiCtrl_MessageBoxPresenter.h"
33
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Graphics;
37
38
39 namespace Tizen { namespace Ui { namespace Controls
40 {
41
42
43 _MessageBox::_MessageBox(void)
44         : __pMsgboxPresenter(null)
45         , __msgboxStyle(MSGBOX_STYLE_NONE)
46         , __textColor(Color(0xFFFFFFFF))
47         , __text(L"")
48         , __timeout(0)
49 {
50         //empty statement
51 }
52
53 _MessageBox::~_MessageBox(void)
54 {
55         delete __pMsgboxPresenter;
56         __pMsgboxPresenter = null;
57
58         delete _pBgBitmap;
59         _pBgBitmap = null;
60
61         delete _pComposedBgBitmap;
62         _pComposedBgBitmap = null;
63
64         delete _pOutlineBitmap;
65         _pOutlineBitmap = null;
66
67         delete _pDimmingLayer;
68         _pDimmingLayer = null;
69
70 }
71
72 _MessageBox*
73 _MessageBox::CreateMessageBoxN(void)
74 {
75         _MessageBox* pMsgbox = new (std::nothrow) _MessageBox();
76         SysTryReturn(NID_UI, pMsgbox != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
77
78 #if defined(MULTI_WINDOW)
79         result r = pMsgbox->CreateRootVisualElement();
80         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
81 #endif
82
83         // for taking touch event
84         pMsgbox->AcquireHandle();
85
86         return pMsgbox;
87
88 #if defined(MULTI_WINDOW)
89 CATCH:
90         delete pMsgbox;
91
92         return null;
93 #endif
94 }
95
96 result
97 _MessageBox::Initialize(const String& title, const String& text, MessageBoxStyle style, unsigned long timeout)
98 {
99         result r = E_SUCCESS;
100
101         int titleHeight = 0;
102
103         _titleText = title;
104         _titleState = !(title.Equals(L"", false));
105
106         __text = text;
107         __msgboxStyle = style;
108         __timeout = timeout;
109
110         _MessageBoxPresenter* pPresenter = new (std::nothrow) _MessageBoxPresenter();
111         SysTryReturn(NID_UI_CTRL, pPresenter != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
112
113         SetPresenter(*pPresenter);
114
115         r = pPresenter->Initialize(*this);
116         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
117
118         // for dim effect
119         _pDimmingLayer = new (std::nothrow) _DimmingLayer();
120         SysTryReturn(NID_UI_CTRL, _pDimmingLayer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
121
122         r = _pDimmingLayer->Construct(*this);
123         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
124
125         GET_COLOR_CONFIG(MESSAGEBOX::BG_NORMAL, _bgColor);
126         GET_COLOR_CONFIG(MESSAGEBOX::TITLE_TEXT_NORMAL, _titleTextColor);
127         GET_COLOR_CONFIG(MESSAGEBOX::TEXT_NORMAL, __textColor);
128
129         GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, GetOrientation(), titleHeight);
130
131         // MsgBox_Outline
132         GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_OUTLINE_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pOutlineBitmap);
133         r = GetLastResult();
134         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] failed to load MessageBox Outline Image.");
135
136         // MsgBox BG
137         GET_BITMAP_CONFIG_N(MESSAGEBOX::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, _pBgBitmap);
138         r = GetLastResult();
139         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] failed to load MessageBox BG Image.");
140
141         _pComposedBgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*_pBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), _bgColor);
142
143         // for clearing canvas
144         if (GetVisualElement() != null)
145         {
146                 GetVisualElement()->SetSurfaceOpaque(false);
147         }
148
149         _AccessibilityContainer* pContainer = null;
150
151         pContainer = GetAccessibilityContainer();
152         if(pContainer != null)
153         {
154                 pContainer->Activate(true);
155         }
156
157         SetTouchMoveAllowance(TOUCH_MOVE_ALLOWANCE_NORMAL);
158
159         return r;
160 }
161
162 result
163 _MessageBox::SetPresenter(const _MessageBoxPresenter& msgboxPresenter)
164 {
165         __pMsgboxPresenter = const_cast <_MessageBoxPresenter*>(&msgboxPresenter);
166
167         return E_SUCCESS;
168 }
169
170 void
171 _MessageBox::OnDraw()
172 {
173         __pMsgboxPresenter->Draw();
174
175         return;
176 }
177
178 void
179 _MessageBox::OnFontChanged(Font * pFont)
180 {
181         __pMsgboxPresenter->OnFontChanged(pFont);
182 }
183
184 void
185 _MessageBox::OnFontInfoRequested(unsigned long& style, int& size)
186 {
187         __pMsgboxPresenter->OnFontInfoRequested(style, size);
188 }
189
190 void
191 _MessageBox::OnActivated(void)
192 {
193         _Popup::OnActivated();
194 }
195
196 void
197 _MessageBox::OnDeactivated(void)
198 {
199         _Popup::OnDeactivated();
200 }
201
202 result
203 _MessageBox::OnAttachedToMainTree(void)
204 {
205         result r = E_SUCCESS;
206
207         SysTryReturn(NID_UI_CTRL, GetVisibleState() != false, E_INVALID_OPERATION,
208                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control is not 'displayable'");
209
210         r = __pMsgboxPresenter->OnAttachedToMainTree();
211         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
212
213         return r;
214 }
215
216 result
217 _MessageBox::ShowAndWait(int& modalResult)
218 {
219         __pMsgboxPresenter->ShowAndWait(modalResult);
220
221         return E_SUCCESS;
222 }
223
224 String
225 _MessageBox::GetText(void) const
226 {
227         return __text;
228 }
229
230 unsigned long
231 _MessageBox::GetTimeout(void) const
232 {
233         return __timeout;
234 }
235
236 void
237 _MessageBox::SetTextColor(const Color& color)
238 {
239         __textColor = color;
240 }
241
242 Color
243 _MessageBox::GetTextColor(void) const
244 {
245         return __textColor;
246 }
247
248 MessageBoxStyle
249 _MessageBox::GetMsgBoxStyle(void) const
250 {
251         return __msgboxStyle;
252 }
253
254 int
255 _MessageBox::GetTotalHeight(void) const
256 {
257         int titleHeight = 0;
258         int btnHeight = 0;
259
260         int textTopMargin = 0;
261         int textTopMarginNoButton = 0;
262
263         int btnGap = 0;
264         int btnTopMargin = 0;
265         int btnBottomMargin = 0;
266
267         int transTopMargin = 0;
268         int transBottomMargin = 0;
269
270         GET_SHAPE_CONFIG(MESSAGEBOX::TITLE_HEIGHT, GetOrientation(), titleHeight);
271         GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, GetOrientation(), btnHeight);
272
273         GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN, GetOrientation(), textTopMargin);
274         GET_SHAPE_CONFIG(MESSAGEBOX::TEXT_TOP_MRAGIN_NO_BUTTON, GetOrientation(), textTopMarginNoButton);
275
276         GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_INTERNAL_GAP, GetOrientation(), btnGap);
277         GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_TOP_MARGIN, GetOrientation(), btnTopMargin);
278         GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_BOTTOM_MARGIN, GetOrientation(), btnBottomMargin);
279
280         GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_TOP_MARGIN, GetOrientation(), transTopMargin);
281         GET_SHAPE_CONFIG(MESSAGEBOX::BG_IMAGE_TRANSPARENT_BOTTOM_MARGIN, GetOrientation(), transBottomMargin);
282
283         if (HasTitle() == false)
284         {
285                 titleHeight = 0;
286         }
287
288         int totalH = titleHeight
289                         + __pMsgboxPresenter->GetBodyTextHeight()
290                         + transTopMargin
291                         + transBottomMargin;
292
293         switch (__msgboxStyle)
294         {
295         case MSGBOX_STYLE_NONE:
296                 totalH += textTopMarginNoButton * 2;
297                 break;
298
299         case MSGBOX_STYLE_OK:
300                         // fall through
301         case MSGBOX_STYLE_CANCEL:
302                         // fall through
303         case MSGBOX_STYLE_OKCANCEL:
304                         // fall through
305         case MSGBOX_STYLE_YESNO:
306                         // fall through
307         case MSGBOX_STYLE_RETRYCANCEL:
308                         // fall through
309         case MSGBOX_STYLE_YESNOCANCEL:
310                         // fall through
311         case MSGBOX_STYLE_ABORTRETRYIGNORE:
312                         // fall through
313         case MSGBOX_STYLE_CANCELTRYCONTINUE:
314                 totalH += textTopMargin * 2
315                                 + btnHeight
316                                 + btnTopMargin
317                                 + btnBottomMargin;
318                 break;
319         }
320
321         return totalH;
322 }
323
324 void
325 _MessageBox::OnChangeLayout(_ControlOrientation orientation)
326 {
327         SysTryReturnVoidResult(NID_UI_CTRL, _pDimmingLayer != null, E_SYSTEM, "[E_SYSTEM] There is no Dimming Layer.");
328
329         result r = E_SUCCESS;
330
331         r = _pDimmingLayer->Rearrange();
332         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
333
334         return;
335 }
336
337 void
338 _MessageBox::OnBoundsChanged(void)
339 {
340         SetClientBounds(Rectangle(0, 0, GetBounds().width, GetBounds().height));
341
342         return;
343 }
344
345 bool
346 _MessageBox::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
347 {
348         if (&source != this)
349         {
350                 return false;
351         }
352
353         return __pMsgboxPresenter->OnTouchPressed(source, touchinfo);
354 }
355
356 bool
357 _MessageBox::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
358 {
359         if (&source != this)
360         {
361                 return false;
362         }
363
364         return __pMsgboxPresenter->OnTouchReleased(source, touchinfo);
365 }
366
367 bool
368 _MessageBox::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
369 {
370         if (&source != this)
371         {
372                 return false;
373         }
374
375         return __pMsgboxPresenter->OnTouchMoved(source, touchinfo);
376 }
377
378
379 }}} // Tizen::Ui::Controls
380