Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlColorPicker.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                FUiCtrlColorPicker.cpp
19  * @brief               This is the implementation file for the %ColorPicker class.
20  */
21
22 #include <FBaseSysLog.h>
23 #include <FUiCtrlColorPicker.h>
24 #include "FUiCtrl_ColorPickerImpl.h"
25
26 using namespace Tizen::Graphics;
27
28 namespace Tizen { namespace Ui { namespace Controls
29 {
30
31 ColorPicker::ColorPicker(void)
32 {
33 }
34
35 ColorPicker::~ColorPicker(void)
36 {
37 }
38
39 result
40 ColorPicker::Construct(const Point& point)
41 {
42         SysAssertf((_ColorPickerImpl::GetInstance(*this) == null),
43                         "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
44
45         _ColorPickerImpl* pImpl = _ColorPickerImpl::CreateColorPickerImplN(*this);
46         result r = GetLastResult();
47         SysTryReturn(NID_UI_CTRL, (pImpl != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
48
49         _pControlImpl = pImpl;
50         r = SetPosition(point);
51         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
52
53         return r;
54
55 CATCH:
56         delete pImpl;
57         pImpl = null;
58
59         return r;
60 }
61
62 Color
63 ColorPicker::GetColor(void) const
64 {
65         const _ColorPickerImpl* pImpl = _ColorPickerImpl::GetInstance(*this);
66         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
67
68         Color color = pImpl->GetColor();
69         result r = GetLastResult();
70         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), color, r, "[%s] Propagating.", GetErrorMessage(r));
71
72         return color;
73 }
74
75 int
76 ColorPicker::GetHue(void) const
77 {
78         const _ColorPickerImpl* pImpl = _ColorPickerImpl::GetInstance(*this);
79         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
80
81         int hue = pImpl->GetHue();
82         result r = GetLastResult();
83         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), hue, r, "[%s] Propagating.", GetErrorMessage(r));
84
85         return hue;
86 }
87
88 int
89 ColorPicker::GetSaturation(void) const
90 {
91         const _ColorPickerImpl* pImpl = _ColorPickerImpl::GetInstance(*this);
92         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
93
94         int sat = pImpl->GetSaturation();
95         result r = GetLastResult();
96         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), sat, r, "[%s] Propagating.", GetErrorMessage(r));
97
98         return sat;
99 }
100
101 int
102 ColorPicker::GetLuminance(void) const
103 {
104         const _ColorPickerImpl* pImpl = _ColorPickerImpl::GetInstance(*this);
105         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
106
107         int lum = pImpl->GetLuminance();
108         result r = GetLastResult();
109         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), lum, r, "[%s] Propagating.", GetErrorMessage(r));
110
111         return lum;
112 }
113
114 void
115 ColorPicker::SetColor(const Tizen::Graphics::Color& color)
116 {
117         _ColorPickerImpl* pImpl = _ColorPickerImpl::GetInstance(*this);
118         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
119
120         result r = pImpl->SetColor(color);
121         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
122 }
123
124 void
125 ColorPicker::SetHue(int hue)
126 {
127         _ColorPickerImpl* pImpl = _ColorPickerImpl::GetInstance(*this);
128         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
129
130         result r = pImpl->SetHue(hue);
131         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
132 }
133
134 void
135 ColorPicker::SetSaturation(int saturation)
136 {
137         _ColorPickerImpl* pImpl = _ColorPickerImpl::GetInstance(*this);
138         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
139
140         result r = pImpl->SetSaturation(saturation);
141         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
142 }
143
144 void
145 ColorPicker::SetLuminance(int luminance)
146 {
147         _ColorPickerImpl* pImpl = _ColorPickerImpl::GetInstance(*this);
148         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
149
150         result r = pImpl->SetLuminance(luminance);
151         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
152 }
153
154 void
155 ColorPicker::AddColorChangeEventListener(Tizen::Ui::IColorChangeEventListener& listener)
156 {
157         _ColorPickerImpl* pImpl = _ColorPickerImpl::GetInstance(*this);
158         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
159
160         result r = pImpl->AddColorChangeEventListener(listener);
161         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
162 }
163
164 void
165 ColorPicker::RemoveColorChangeEventListener(Tizen::Ui::IColorChangeEventListener& listener)
166 {
167         _ColorPickerImpl* pImpl = _ColorPickerImpl::GetInstance(*this);
168         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
169
170         result r = pImpl->RemoveColorChangeEventListener(listener);
171         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
172 }
173
174 }}} // Tizen::Ui::Controls