Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlButton.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         FUiCtrlButton.cpp
19 * @brief        This file contains implementation of Button class
20 */
21
22 #include <FUiCtrlButton.h>
23 #include <FBaseSysLog.h>
24 #include "FUiCtrl_ButtonImpl.h"
25
26 using namespace Tizen::Base;
27 using namespace Tizen::Graphics;
28
29 namespace Tizen { namespace Ui { namespace Controls
30 {
31
32 Button::Button(void)
33 {
34
35 }
36
37 Button::~Button(void)
38 {
39
40 }
41
42 result
43 Button::Construct(const Rectangle& rect, const String& text)
44 {
45         result r = E_SUCCESS;
46         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
47
48         SysAssertf(pButtonImpl == null,
49                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
50
51         pButtonImpl = _ButtonImpl::CreateButtonImplN(this, rect);
52         r = GetLastResult();
53         SysTryReturn(NID_UI_CTRL, pButtonImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
54
55         r = pButtonImpl->SetText(text);
56         SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
57
58         _pControlImpl = pButtonImpl;
59
60         return E_SUCCESS;
61 }
62
63 void
64 Button::AddActionEventListener(IActionEventListener& listener)
65 {
66         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
67         SysAssertf(pButtonImpl != null,
68                                 "Not yet constructed. Construct() should be called before use.");
69
70         result r = pButtonImpl->AddActionEventListener(listener);
71         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
72
73         return;
74 }
75
76 void
77 Button::RemoveActionEventListener(IActionEventListener& listener)
78 {
79         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
80         SysAssertf(pButtonImpl != null,
81                                         "Not yet constructed. Construct() should be called before use.");
82
83         result r = pButtonImpl->RemoveActionEventListener(listener);
84         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
85
86         return;
87 }
88
89 void
90 Button::SetActionId(int actionId)
91 {
92         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
93         SysAssertf(pButtonImpl != null,
94                                         "Not yet constructed. Construct() should be called before use.");
95
96         pButtonImpl->SetActionId(actionId);
97
98         return;
99 }
100
101 int
102 Button::GetActionId(void) const
103 {
104         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
105         SysAssertf(pButtonImpl != null,
106                                         "Not yet constructed. Construct() should be called before use.");
107
108         return pButtonImpl->GetActionId();
109 }
110
111 void
112 Button::SetText(const String& text)
113 {
114         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
115         SysAssertf(pButtonImpl != null,
116                                         "Not yet constructed. Construct() should be called before use.");
117
118         pButtonImpl->SetText(text);
119
120         return;
121 }
122
123 void
124 Button::SetTextHorizontalAlignment(HorizontalAlignment alignment)
125 {
126         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
127         SysAssertf(pButtonImpl != null,
128                                         "Not yet constructed. Construct() should be called before use.");
129
130         pButtonImpl->SetTextHorizontalAlignment(alignment);
131
132         return;
133 }
134
135 void
136 Button::SetTextVerticalAlignment(VerticalAlignment alignment)
137 {
138         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
139         SysAssertf(pButtonImpl != null,
140                                         "Not yet constructed. Construct() should be called before use.");
141
142         pButtonImpl->SetTextVerticalAlignment(alignment);
143
144         return;
145 }
146
147 String
148 Button::GetText(void) const
149 {
150         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
151         SysAssertf(pButtonImpl != null,
152                                         "Not yet constructed. Construct() should be called before use.");
153
154         return pButtonImpl->GetText();
155 }
156
157 HorizontalAlignment
158 Button::GetTextHorizontalAlignment(void) const
159 {
160         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
161         SysAssertf(pButtonImpl != null,
162                                         "Not yet constructed. Construct() should be called before use.");
163
164         return pButtonImpl->GetTextHorizontalAlignment();
165 }
166
167 VerticalAlignment
168 Button::GetTextVerticalAlignment(void) const
169 {
170         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
171         SysAssertf(pButtonImpl != null,
172                                         "Not yet constructed. Construct() should be called before use.");
173
174         return pButtonImpl->GetTextVerticalAlignment();
175 }
176
177 void
178 Button::SetTextColor(const Color& color)
179 {
180         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
181         SysAssertf(pButtonImpl != null,
182                                         "Not yet constructed. Construct() should be called before use.");
183
184         pButtonImpl->SetTextColor(color);
185
186         return;
187 }
188
189 Color
190 Button::GetTextColor(void) const
191 {
192         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
193         SysAssertf(pButtonImpl != null,
194                                         "Not yet constructed. Construct() should be called before use.");
195
196         return pButtonImpl->GetTextColor();
197 }
198
199 void
200 Button::SetPressedTextColor(const Color& color)
201 {
202         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
203         SysAssertf(pButtonImpl != null,
204                                         "Not yet constructed. Construct() should be called before use.");
205
206         pButtonImpl->SetPressedTextColor(color);
207
208         return;
209 }
210
211 Color
212 Button::GetPressedTextColor(void) const
213 {
214         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
215         SysAssertf(pButtonImpl != null,
216                                         "Not yet constructed. Construct() should be called before use.");
217
218         return pButtonImpl->GetPressedTextColor();
219 }
220
221 void
222 Button::SetDisabledTextColor(const Color& color)
223 {
224         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
225         SysAssertf(pButtonImpl != null,
226                                         "Not yet constructed. Construct() should be called before use.");
227
228         pButtonImpl->SetDisabledTextColor(color);
229
230         return;
231 }
232
233 Color
234 Button::GetDisabledTextColor(void) const
235 {
236         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
237         SysAssertf(pButtonImpl != null,
238                                         "Not yet constructed. Construct() should be called before use.");
239
240         return pButtonImpl->GetDisabledTextColor();
241 }
242
243 void
244 Button::SetHighlightedTextColor(const Color& color)
245 {
246         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
247         SysAssertf(pButtonImpl != null,
248                                         "Not yet constructed. Construct() should be called before use.");
249
250         pButtonImpl->SetHighlightedTextColor(color);
251
252         return;
253 }
254
255 Color
256 Button::GetHighlightedTextColor(void) const
257 {
258         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
259         SysAssertf(pButtonImpl != null,
260                                         "Not yet constructed. Construct() should be called before use.");
261
262         return pButtonImpl->GetHighlightedTextColor();
263 }
264
265 void
266 Button::SetNormalBitmap(const Point& position, const Bitmap& bitmap)
267 {
268         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
269         SysAssertf(pButtonImpl != null,
270                                         "Not yet constructed. Construct() should be called before use.");
271
272         pButtonImpl->SetNormalBitmap(position, bitmap);
273
274         return;
275 }
276
277 void
278 Button::SetPressedBitmap(const Point& position, const Bitmap& bitmap)
279 {
280         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
281         SysAssertf(pButtonImpl != null,
282                                         "Not yet constructed. Construct() should be called before use.");
283
284         pButtonImpl->SetPressedBitmap(position, bitmap);
285
286         return;
287 }
288
289 void
290 Button::SetDisabledBitmap(const Point& position, const Bitmap& bitmap)
291 {
292         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
293         SysAssertf(pButtonImpl != null,
294                                         "Not yet constructed. Construct() should be called before use.");
295
296         pButtonImpl->SetDisabledBitmap(position, bitmap);
297
298         return;
299 }
300
301 void
302 Button::SetNormalBackgroundBitmap(const Bitmap& bitmap)
303 {
304         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
305         SysAssertf(pButtonImpl != null,
306                                         "Not yet constructed. Construct() should be called before use.");
307
308         pButtonImpl->SetNormalBackgroundBitmap(bitmap);
309
310         return;
311 }
312
313 void
314 Button::SetPressedBackgroundBitmap(const Bitmap& bitmap)
315 {
316         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
317         SysAssertf(pButtonImpl != null,
318                                         "Not yet constructed. Construct() should be called before use.");
319
320         pButtonImpl->SetPressedBackgroundBitmap(bitmap);
321
322         return;
323 }
324
325 void
326 Button::SetHighlightedBackgroundBitmap(const Bitmap& bitmap)
327 {
328         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
329         SysAssertf(pButtonImpl != null,
330                                         "Not yet constructed. Construct() should be called before use.");
331
332         pButtonImpl->SetHighlightedBackgroundBitmap(bitmap);
333
334         return;
335 }
336
337 Color
338 Button::GetColor(ButtonStatus status) const
339 {
340         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
341         SysAssertf(pButtonImpl != null,
342                                         "Not yet constructed. Construct() should be called before use.");
343
344         return pButtonImpl->GetColor(status);
345 }
346
347 result
348 Button::SetColor(ButtonStatus status, const Color& color)
349 {
350         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
351         SysAssertf(pButtonImpl != null,
352                                         "Not yet constructed. Construct() should be called before use.");
353
354         result r = pButtonImpl->SetColor(status, color);
355         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
356
357         return E_SUCCESS;
358 }
359
360 int
361 Button::GetTextSize(void) const
362 {
363         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
364         SysAssertf(pButtonImpl != null,
365                                         "Not yet constructed. Construct() should be called before use.");
366
367         return pButtonImpl->GetTextSize();
368 }
369
370 result
371 Button::SetTextSize(int size)
372 {
373         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
374         SysAssertf(pButtonImpl != null,
375                                         "Not yet constructed. Construct() should be called before use.");
376
377         result r = pButtonImpl->SetTextSize(size);
378         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
379
380         return r;
381 }
382 }}} // Tizen::Ui::Controls