Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / FUi_CustomControlBaseImpl.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  * @file        FUi_CustomControlBaseImpl.cpp
19  * @brief       This is the implementation for the _CustomControlBaseImpl class and default transformer.
20  */
21
22 #include <FBaseSysLog.h>
23 #include "FUi_LayoutImpl.h"
24 #include "FUi_CustomControlBaseImpl.h"
25 #include "FUi_Control.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Ui;
29 using namespace Tizen::Graphics;
30
31 namespace Tizen { namespace Ui
32 {
33
34 _CustomControlBaseImpl::~_CustomControlBaseImpl(void)
35 {
36 }
37
38 _CustomControlBaseImpl*
39 _CustomControlBaseImpl::CreateCustomControlBaseImplN(CustomControlBase* pPublic, const Rectangle& bounds,
40                                                                                 const Layout* pPublicPortraitLayout, const Layout* pPublicLandscapeLayout,
41                                                                                 bool resizable, bool movable)
42 {
43         result r = E_SUCCESS;
44
45         _Control* pCore = _Control::CreateControlN();
46         SysTryReturn(NID_UI, pCore, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
47
48         _CustomControlBaseImpl* pImpl =
49                 new (std::nothrow) _CustomControlBaseImpl(pPublic, pCore, bounds,
50                                                                                                   pPublicPortraitLayout, pPublicLandscapeLayout,
51                                                                                                   resizable, movable);
52         r = CheckConstruction(pCore, pImpl);
53         SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
54
55         ClearLastResult();
56
57         return pImpl;
58 }
59
60 _CustomControlBaseImpl::_CustomControlBaseImpl(CustomControlBase* pCustomControlBase, _Control* pCore, const Rectangle& bounds, const Layout* pPublicPortraitLayout, const Layout* pPublicLandscapeLayout, bool resizable, bool movable)
61         : _ContainerImpl(pCustomControlBase, pCore, pPublicPortraitLayout, pPublicLandscapeLayout)
62 {
63         result r = E_SUCCESS;
64
65         r = GetLastResult();
66         if (IsFailed(r))
67         {
68                 return;
69         }
70
71         bool allOrNone = (pPublicPortraitLayout && pPublicLandscapeLayout) || (!pPublicPortraitLayout && !pPublicLandscapeLayout);
72         SysAssert(allOrNone);
73
74         r = SetBounds(bounds);
75         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
76
77         pCore->SetResizable(resizable);
78         pCore->SetMovable(movable);
79 }
80
81 const char*
82 _CustomControlBaseImpl::GetPublicClassName(void) const
83 {
84         return "Tizen::Ui::CustomControlBase";
85 }
86
87 const CustomControlBase&
88 _CustomControlBaseImpl::GetPublic(void) const
89 {
90         return static_cast <const CustomControlBase&>(_ControlImpl::GetPublic());
91 }
92
93 CustomControlBase&
94 _CustomControlBaseImpl::GetPublic(void)
95 {
96         return static_cast <CustomControlBase&>(_ControlImpl::GetPublic());
97 }
98
99 _CustomControlBaseImpl*
100 _CustomControlBaseImpl::GetInstance(CustomControlBase& pCustomControlBase)
101 {
102         return static_cast<_CustomControlBaseImpl*>(pCustomControlBase._pControlImpl);
103 }
104
105 const _CustomControlBaseImpl*
106 _CustomControlBaseImpl::GetInstance(const CustomControlBase& pCustomControlBase)
107 {
108         return static_cast<const _CustomControlBaseImpl*>(pCustomControlBase._pControlImpl);
109
110 }
111
112
113 result
114 _CustomControlBaseImpl::OnBoundsChanging(const Rectangle& bounds)
115 {
116         __oldBounds = GetBounds();
117         return GetPublic().PrepareBoundsChange(__oldBounds, bounds);
118 }
119
120 void
121 _CustomControlBaseImpl::OnBoundsChanged(void)
122 {
123         GetPublic().OnBoundsChanged(__oldBounds, GetBounds());
124 }
125
126 void
127 _CustomControlBaseImpl::OnEvaluateSize(Dimension& evaluatedSize)
128 {
129         GetPublic().EvaluateSize(evaluatedSize.width, evaluatedSize.height);
130 }
131
132 }} // Tizen::Ui