2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUiCtrl_Panel.cpp
20 * @brief This is the implementation file for the %_Panel class.
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"
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Ui;
37 namespace Tizen { namespace Ui { namespace Controls
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)
51 GetAccessibilityContainer()->Activate(true);
56 delete __pBackgroundBitmap;
57 __pBackgroundBitmap = null;
59 delete __pGroupStyleBackgroundBitmap;
60 __pGroupStyleBackgroundBitmap = null;
62 delete __pGroupStyleBitmap;
63 __pGroupStyleBitmap = null;
65 delete __pPanelPresenter;
66 __pPanelPresenter = null;
70 _Panel::CreatePanelN(const FloatRectangle& rect, GroupStyle groupStyle)
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));
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));
81 r = pPresenter->Initialize(*pPanel);
82 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
84 r = pPanel->Initialize(*pPresenter);
85 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
87 pPanel->SetGroupStyle(groupStyle);
89 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
91 if (groupStyle != GROUP_STYLE_NONE)
93 Color defaultGroupStyleBackgroundColor = 0x00000000;
94 GET_COLOR_CONFIG(PANEL::GROUPED_STYLE_BG_NORMAL, defaultGroupStyleBackgroundColor);
95 pPanel->SetBackgroundColor(defaultGroupStyleBackgroundColor);
98 pPanel->AcquireHandle();
100 r = pPanel->SetBounds(rect);
101 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
107 pPanel->__pPanelPresenter = null;
116 _Panel::Initialize(const _PanelPresenter& presenter)
120 SetPanelPresenter(&presenter);
122 result r = GetVisualElement()->SetSurfaceOpaque(false);
123 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
125 SetBackgroundColor(Color(0, 0, 0, 0));
127 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
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));
133 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
135 SetDataBindingContext(pContext);
146 _Panel::SetPanelPresenter(const _PanelPresenter* panelPresenter)
150 __pPanelPresenter = const_cast <_PanelPresenter*>(panelPresenter);
160 if (__pPanelPresenter != null)
162 result r = __pPanelPresenter->Draw();
163 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
168 _Panel::SetBackgroundColor(const Color& color)
172 if (_Control::GetBackgroundColor() == color)
177 _Control::SetBackgroundColor(color);
179 if (__groupStyle != GROUP_STYLE_NONE)
186 _Panel::GetGroupStyle(void) const
194 _Panel::SetGroupStyle(GroupStyle groupStyle)
198 if (__groupStyle == groupStyle)
202 __groupStyle = groupStyle;
204 delete __pGroupStyleBackgroundBitmap;
205 __pGroupStyleBackgroundBitmap = null;
207 delete __pGroupStyleBitmap;
208 __pGroupStyleBitmap = null;
210 result r = E_SUCCESS;
211 switch (__groupStyle)
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));
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));
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));
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));
237 case GROUP_STYLE_NONE:
245 delete __pGroupStyleBackgroundBitmap;
246 __pGroupStyleBackgroundBitmap = null;
247 delete __pGroupStyleBitmap;
248 __pGroupStyleBitmap = null;
254 _Panel::GetGroupStyleBitmap(void) const
258 return __pGroupStyleBitmap;
262 _Panel::GetGroupStyleBackgroundBitmap(void) const
266 return __pGroupStyleBackgroundBitmap;
270 _Panel::IsBackgroundBitmapStretch(void) const
274 return __backgroundBitmapStretch;
278 _Panel::SetBackgroundBitmapStretch(bool stretch)
282 __backgroundBitmapStretch = stretch;
285 _PanelBackgroundBitmapHorizontalAlign
286 _Panel::GetBackgroundBitmapHorizontalAlign(void) const
290 return __backgroundBitmapHorizontalAlign;
294 _Panel::SetBackgroundBitmapHorizontalAlign(_PanelBackgroundBitmapHorizontalAlign align)
298 __backgroundBitmapHorizontalAlign = align;
301 _PanelBackgroundBitmapVerticalAlign
302 _Panel::GetBackgroundBitmapVerticalAlign(void) const
306 return __backgroundBitmapVerticalAlign;
310 _Panel::SetBackgroundBitmapVerticalAlign(_PanelBackgroundBitmapVerticalAlign align)
314 __backgroundBitmapVerticalAlign = align;
318 _Panel::SetBackgroundBitmapAlign(_PanelBackgroundBitmapHorizontalAlign horizontalAlign, _PanelBackgroundBitmapVerticalAlign verticalAlign)
322 SetBackgroundBitmapHorizontalAlign(horizontalAlign);
323 SetBackgroundBitmapVerticalAlign(verticalAlign);
327 _Panel::GetBackgroundBitmap(void) const
331 return __pBackgroundBitmap;
335 _Panel::SetBackgroundBitmap(Bitmap* bitmap)
339 if (__pBackgroundBitmap != bitmap)
341 delete __pBackgroundBitmap;
342 __pBackgroundBitmap = null;
350 __pBackgroundBitmap = _BitmapImpl::CloneN(*bitmap);
351 result r = GetLastResult();
352 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
358 }}} //Tizen::Ui::Controls