Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_Panel.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
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_Panel.cpp
20  * @brief       This is the implementation file for the %_Panel class.
21  *
22  */
23
24 #include <FBaseErrorDefine.h>
25 #include <FBaseSysLog.h>
26 #include <FGrpBitmap.h>
27 #include <FGrp_BitmapImpl.h>
28 #include "FUi_AccessibilityContainer.h"
29 #include "FUi_DataBindingContext.h"
30 #include "FUi_ResourceManager.h"
31 #include "FUiAnim_VisualElement.h"
32 #include "FUiCtrl_Panel.h"
33
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Ui;
36
37 namespace Tizen { namespace Ui { namespace Controls
38 {
39
40 _Panel::_Panel(void)
41         : _Control()
42         , __pPanelPresenter(null)
43         , __groupStyle(GROUP_STYLE_NONE)
44         , __pGroupStyleBitmap(null)
45         , __pGroupStyleBackgroundBitmap(null)
46         , __backgroundBitmapStretch(false)
47         , __backgroundBitmapHorizontalAlign(PANEL_BACKGROUND_BITMAP_HORIZONTAL_ALIGN_CENTER)
48         , __backgroundBitmapVerticalAlign(PANEL_BACKGROUND_BITMAP_VERTICAL_ALIGN_MIDDLE)
49         , __pBackgroundBitmap(null)
50 {
51         GetAccessibilityContainer()->Activate(true);
52 }
53
54 _Panel::~_Panel(void)
55 {
56         delete __pBackgroundBitmap;
57         __pBackgroundBitmap = null;
58
59         delete __pGroupStyleBackgroundBitmap;
60         __pGroupStyleBackgroundBitmap = null;
61
62         delete __pGroupStyleBitmap;
63         __pGroupStyleBitmap = null;
64
65         delete __pPanelPresenter;
66         __pPanelPresenter = null;
67 }
68
69 _Panel*
70 _Panel::CreatePanelN(const FloatRectangle& rect, GroupStyle groupStyle)
71 {
72         ClearLastResult();
73         result r = E_SUCCESS;
74
75         _Panel* pPanel = new (std::nothrow) _Panel;
76         SysTryReturn(NID_UI_CTRL, pPanel != null, null, E_OUT_OF_MEMORY, "[%s] The memory is insufficient.", GetErrorMessage(E_OUT_OF_MEMORY));
77
78         _PanelPresenter* pPresenter = new (std::nothrow) _PanelPresenter;
79         SysTryCatch(NID_UI_CTRL, pPresenter != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] The memory is insufficient.", GetErrorMessage(E_OUT_OF_MEMORY));
80
81         r = pPresenter->Initialize(*pPanel);
82         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
83
84         r = pPanel->Initialize(*pPresenter);
85         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
86
87         pPanel->SetGroupStyle(groupStyle);
88         r = GetLastResult();
89         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
90
91         if (groupStyle != GROUP_STYLE_NONE)
92         {
93                 Color defaultGroupStyleBackgroundColor = 0x00000000;
94                 GET_COLOR_CONFIG(PANEL::GROUPED_STYLE_BG_NORMAL, defaultGroupStyleBackgroundColor);
95                 pPanel->SetBackgroundColor(defaultGroupStyleBackgroundColor);
96         }
97
98         pPanel->AcquireHandle();
99
100         r = pPanel->SetBounds(rect);
101         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
102
103         return pPanel;
104
105 CATCH:
106         delete pPresenter;
107         pPanel->__pPanelPresenter = null;
108
109         delete pPanel;
110
111         SetLastResult(r);
112         return null;
113 }
114
115 result
116 _Panel::Initialize(const _PanelPresenter& presenter)
117 {
118         ClearLastResult();
119
120         SetPanelPresenter(&presenter);
121
122         result r = GetVisualElement()->SetSurfaceOpaque(false);
123         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
124
125         SetBackgroundColor(Color(0, 0, 0, 0));
126         r = GetLastResult();
127         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
128
129         // create data binding context
130         _DataBindingContext* pContext = new (std::nothrow) _DataBindingContext(*this);
131         SysTryCatch(NID_UI_CTRL, pContext != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] The memory is insufficient.", GetErrorMessage(E_OUT_OF_MEMORY));
132         r = GetLastResult();
133         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
134
135         SetDataBindingContext(pContext);
136
137         return r;
138
139 CATCH:
140         delete pContext;
141
142         return r;
143 }
144
145 result
146 _Panel::SetPanelPresenter(const _PanelPresenter* panelPresenter)
147 {
148         ClearLastResult();
149
150         __pPanelPresenter = const_cast <_PanelPresenter*>(panelPresenter);
151
152         return E_SUCCESS;
153 }
154
155 void
156 _Panel::OnDraw(void)
157 {
158         ClearLastResult();
159
160         if (__pPanelPresenter != null)
161         {
162                 result r = __pPanelPresenter->Draw();
163                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
164         }
165 }
166
167 void
168 _Panel::SetBackgroundColor(const Color& color)
169 {
170         ClearLastResult();
171
172         if (_Control::GetBackgroundColor() == color)
173         {
174                 return;
175         }
176
177         _Control::SetBackgroundColor(color);
178
179         if (__groupStyle != GROUP_STYLE_NONE)
180         {
181                 Invalidate();
182         }
183 }
184
185 GroupStyle
186 _Panel::GetGroupStyle(void) const
187 {
188         ClearLastResult();
189
190         return __groupStyle;
191 }
192
193 void
194 _Panel::SetGroupStyle(GroupStyle groupStyle)
195 {
196         ClearLastResult();
197
198         if (__groupStyle == groupStyle)
199         {
200                 return;
201         }
202         __groupStyle = groupStyle;
203
204         delete __pGroupStyleBackgroundBitmap;
205         __pGroupStyleBackgroundBitmap = null;
206
207         delete __pGroupStyleBitmap;
208         __pGroupStyleBitmap = null;
209
210         result r = E_SUCCESS;
211         switch (__groupStyle)
212         {
213         case GROUP_STYLE_TOP:
214                 r = GET_BITMAP_CONFIG_N(PANEL::GROUPED_TOP_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pGroupStyleBitmap);
215                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
216                 r = GET_BITMAP_CONFIG_N(PANEL::GROUPED_TOP_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pGroupStyleBackgroundBitmap);
217                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
218                 break;
219         case GROUP_STYLE_MIDDLE:
220                 r = GET_BITMAP_CONFIG_N(PANEL::GROUPED_MIDDLE_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pGroupStyleBitmap);
221                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
222                 r = GET_BITMAP_CONFIG_N(PANEL::GROUPED_MIDDLE_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pGroupStyleBackgroundBitmap);
223                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
224                 break;
225         case GROUP_STYLE_BOTTOM:
226                 r = GET_BITMAP_CONFIG_N(PANEL::GROUPED_BOTTOM_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pGroupStyleBitmap);
227                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
228                 r = GET_BITMAP_CONFIG_N(PANEL::GROUPED_BOTTOM_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pGroupStyleBackgroundBitmap);
229                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
230                 break;
231         case GROUP_STYLE_SINGLE:
232                 r = GET_BITMAP_CONFIG_N(PANEL::GROUPED_SINGLE_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pGroupStyleBitmap);
233                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
234                 r = GET_BITMAP_CONFIG_N(PANEL::GROUPED_SINGLE_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pGroupStyleBackgroundBitmap);
235                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
236                 break;
237         case GROUP_STYLE_NONE:
238                 // fall through
239         default:
240                 break;
241         }
242
243         return;
244 CATCH:
245         delete __pGroupStyleBackgroundBitmap;
246         __pGroupStyleBackgroundBitmap = null;
247         delete __pGroupStyleBitmap;
248         __pGroupStyleBitmap = null;
249
250         SetLastResult(r);
251 }
252
253 Bitmap*
254 _Panel::GetGroupStyleBitmap(void) const
255 {
256         ClearLastResult();
257
258         return __pGroupStyleBitmap;
259 }
260
261 Bitmap*
262 _Panel::GetGroupStyleBackgroundBitmap(void) const
263 {
264         ClearLastResult();
265
266         return __pGroupStyleBackgroundBitmap;
267 }
268
269 bool
270 _Panel::IsBackgroundBitmapStretch(void) const
271 {
272         ClearLastResult();
273
274         return __backgroundBitmapStretch;
275 }
276
277 void
278 _Panel::SetBackgroundBitmapStretch(bool stretch)
279 {
280         ClearLastResult();
281
282         __backgroundBitmapStretch = stretch;
283 }
284
285 _PanelBackgroundBitmapHorizontalAlign
286 _Panel::GetBackgroundBitmapHorizontalAlign(void) const
287 {
288         ClearLastResult();
289
290         return __backgroundBitmapHorizontalAlign;
291 }
292
293 void
294 _Panel::SetBackgroundBitmapHorizontalAlign(_PanelBackgroundBitmapHorizontalAlign align)
295 {
296         ClearLastResult();
297
298         __backgroundBitmapHorizontalAlign = align;
299 }
300
301 _PanelBackgroundBitmapVerticalAlign
302 _Panel::GetBackgroundBitmapVerticalAlign(void) const
303 {
304         ClearLastResult();
305
306         return __backgroundBitmapVerticalAlign;
307 }
308
309 void
310 _Panel::SetBackgroundBitmapVerticalAlign(_PanelBackgroundBitmapVerticalAlign align)
311 {
312         ClearLastResult();
313
314         __backgroundBitmapVerticalAlign = align;
315 }
316
317 void
318 _Panel::SetBackgroundBitmapAlign(_PanelBackgroundBitmapHorizontalAlign horizontalAlign, _PanelBackgroundBitmapVerticalAlign verticalAlign)
319 {
320         ClearLastResult();
321
322         SetBackgroundBitmapHorizontalAlign(horizontalAlign);
323         SetBackgroundBitmapVerticalAlign(verticalAlign);
324 }
325
326 Bitmap*
327 _Panel::GetBackgroundBitmap(void) const
328 {
329         ClearLastResult();
330
331         return __pBackgroundBitmap;
332 }
333
334 void
335 _Panel::SetBackgroundBitmap(Bitmap* bitmap)
336 {
337         ClearLastResult();
338
339         if (__pBackgroundBitmap != bitmap)
340         {
341                 delete __pBackgroundBitmap;
342                 __pBackgroundBitmap = null;
343         }
344
345         if (bitmap == null)
346         {
347                 return;
348         }
349
350         __pBackgroundBitmap = _BitmapImpl::CloneN(*bitmap);
351         result r = GetLastResult();
352         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
353
354         Invalidate();
355 }
356
357
358 }}} //Tizen::Ui::Controls
359