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