Changed indicator bg color.
[platform/framework/native/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 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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
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 result
64 Button::Construct(const FloatRectangle& rect, const String& text)
65 {
66         result r = E_SUCCESS;
67         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
68
69         SysAssertf(pButtonImpl == null,
70                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
71
72         pButtonImpl = _ButtonImpl::CreateButtonImplN(this, rect);
73         r = GetLastResult();
74         SysTryReturn(NID_UI_CTRL, pButtonImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
75
76         r = pButtonImpl->SetText(text);
77         SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
78
79         _pControlImpl = pButtonImpl;
80
81         return E_SUCCESS;
82 }
83
84 void
85 Button::AddActionEventListener(IActionEventListener& listener)
86 {
87         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
88         SysAssertf(pButtonImpl != null,
89                                 "Not yet constructed. Construct() should be called before use.");
90
91         result r = pButtonImpl->AddActionEventListener(listener);
92         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
93
94         return;
95 }
96
97 void
98 Button::RemoveActionEventListener(IActionEventListener& listener)
99 {
100         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
101         SysAssertf(pButtonImpl != null,
102                                         "Not yet constructed. Construct() should be called before use.");
103
104         result r = pButtonImpl->RemoveActionEventListener(listener);
105         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
106
107         return;
108 }
109
110 void
111 Button::SetActionId(int actionId)
112 {
113         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
114         SysAssertf(pButtonImpl != null,
115                                         "Not yet constructed. Construct() should be called before use.");
116
117         pButtonImpl->SetActionId(actionId);
118
119         return;
120 }
121
122 int
123 Button::GetActionId(void) const
124 {
125         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
126         SysAssertf(pButtonImpl != null,
127                                         "Not yet constructed. Construct() should be called before use.");
128
129         return pButtonImpl->GetActionId();
130 }
131
132 void
133 Button::SetText(const String& text)
134 {
135         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
136         SysAssertf(pButtonImpl != null,
137                                         "Not yet constructed. Construct() should be called before use.");
138
139         pButtonImpl->SetText(text);
140
141         return;
142 }
143
144 void
145 Button::SetTextHorizontalAlignment(HorizontalAlignment alignment)
146 {
147         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
148         SysAssertf(pButtonImpl != null,
149                                         "Not yet constructed. Construct() should be called before use.");
150
151         pButtonImpl->SetTextHorizontalAlignment(alignment);
152
153         return;
154 }
155
156 void
157 Button::SetTextVerticalAlignment(VerticalAlignment alignment)
158 {
159         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
160         SysAssertf(pButtonImpl != null,
161                                         "Not yet constructed. Construct() should be called before use.");
162
163         pButtonImpl->SetTextVerticalAlignment(alignment);
164
165         return;
166 }
167
168 String
169 Button::GetText(void) const
170 {
171         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
172         SysAssertf(pButtonImpl != null,
173                                         "Not yet constructed. Construct() should be called before use.");
174
175         return pButtonImpl->GetText();
176 }
177
178 HorizontalAlignment
179 Button::GetTextHorizontalAlignment(void) const
180 {
181         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
182         SysAssertf(pButtonImpl != null,
183                                         "Not yet constructed. Construct() should be called before use.");
184
185         return pButtonImpl->GetTextHorizontalAlignment();
186 }
187
188 VerticalAlignment
189 Button::GetTextVerticalAlignment(void) const
190 {
191         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
192         SysAssertf(pButtonImpl != null,
193                                         "Not yet constructed. Construct() should be called before use.");
194
195         return pButtonImpl->GetTextVerticalAlignment();
196 }
197
198 void
199 Button::SetTextColor(const Color& color)
200 {
201         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
202         SysAssertf(pButtonImpl != null,
203                                         "Not yet constructed. Construct() should be called before use.");
204
205         pButtonImpl->SetTextColor(color);
206
207         return;
208 }
209
210 Color
211 Button::GetTextColor(void) const
212 {
213         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
214         SysAssertf(pButtonImpl != null,
215                                         "Not yet constructed. Construct() should be called before use.");
216
217         return pButtonImpl->GetTextColor();
218 }
219
220 void
221 Button::SetPressedTextColor(const Color& color)
222 {
223         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
224         SysAssertf(pButtonImpl != null,
225                                         "Not yet constructed. Construct() should be called before use.");
226
227         pButtonImpl->SetPressedTextColor(color);
228
229         return;
230 }
231
232 Color
233 Button::GetPressedTextColor(void) const
234 {
235         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
236         SysAssertf(pButtonImpl != null,
237                                         "Not yet constructed. Construct() should be called before use.");
238
239         return pButtonImpl->GetPressedTextColor();
240 }
241
242 void
243 Button::SetDisabledTextColor(const Color& color)
244 {
245         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
246         SysAssertf(pButtonImpl != null,
247                                         "Not yet constructed. Construct() should be called before use.");
248
249         pButtonImpl->SetDisabledTextColor(color);
250
251         return;
252 }
253
254 Color
255 Button::GetDisabledTextColor(void) const
256 {
257         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
258         SysAssertf(pButtonImpl != null,
259                                         "Not yet constructed. Construct() should be called before use.");
260
261         return pButtonImpl->GetDisabledTextColor();
262 }
263
264 void
265 Button::SetHighlightedTextColor(const Color& color)
266 {
267         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
268         SysAssertf(pButtonImpl != null,
269                                         "Not yet constructed. Construct() should be called before use.");
270
271         pButtonImpl->SetHighlightedTextColor(color);
272
273         return;
274 }
275
276 Color
277 Button::GetHighlightedTextColor(void) const
278 {
279         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
280         SysAssertf(pButtonImpl != null,
281                                         "Not yet constructed. Construct() should be called before use.");
282
283         return pButtonImpl->GetHighlightedTextColor();
284 }
285
286 void
287 Button::SetNormalBitmap(const Point& position, const Bitmap& bitmap)
288 {
289         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
290         SysAssertf(pButtonImpl != null,
291                                         "Not yet constructed. Construct() should be called before use.");
292
293         pButtonImpl->SetNormalBitmap(position, bitmap);
294
295         return;
296 }
297
298 void
299 Button::SetNormalBitmap(const FloatPoint& position, const Bitmap& bitmap)
300 {
301         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
302         SysAssertf(pButtonImpl != null,
303                                         "Not yet constructed. Construct() should be called before use.");
304
305         pButtonImpl->SetNormalBitmap(position, bitmap);
306
307         return;
308 }
309
310 void
311 Button::SetDisabledBitmap(const Point& position, const Bitmap& bitmap)
312 {
313         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
314         SysAssertf(pButtonImpl != null,
315                                         "Not yet constructed. Construct() should be called before use.");
316
317         pButtonImpl->SetDisabledBitmap(position, bitmap);
318
319         return;
320 }
321
322 void
323 Button::SetDisabledBitmap(const FloatPoint& position, const Bitmap& bitmap)
324 {
325         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
326         SysAssertf(pButtonImpl != null,
327                                         "Not yet constructed. Construct() should be called before use.");
328
329         pButtonImpl->SetDisabledBitmap(position, bitmap);
330
331         return;
332 }
333
334 void
335 Button::SetPressedBitmap(const Point& position, const Bitmap& bitmap)
336 {
337         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
338         SysAssertf(pButtonImpl != null,
339                                         "Not yet constructed. Construct() should be called before use.");
340
341         pButtonImpl->SetPressedBitmap(position, bitmap);
342
343         return;
344 }
345
346 void
347 Button::SetPressedBitmap(const FloatPoint& position, const Bitmap& bitmap)
348 {
349         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
350         SysAssertf(pButtonImpl != null,
351                                         "Not yet constructed. Construct() should be called before use.");
352
353         pButtonImpl->SetPressedBitmap(position, bitmap);
354
355         return;
356 }
357
358 void
359 Button::SetHighlightedBitmap(const Point& position, const Bitmap& bitmap)
360 {
361         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
362         SysAssertf(pButtonImpl != null,
363                                         "Not yet constructed. Construct() should be called before use.");
364
365         pButtonImpl->SetHighlightedBitmap(position, bitmap);
366
367         return;
368 }
369
370 void
371 Button::SetHighlightedBitmap(const FloatPoint& position, const Bitmap& bitmap)
372 {
373         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
374         SysAssertf(pButtonImpl != null,
375                                         "Not yet constructed. Construct() should be called before use.");
376
377         pButtonImpl->SetHighlightedBitmap(position, bitmap);
378
379         return;
380 }
381
382 void
383 Button::SetNormalBackgroundBitmap(const Bitmap& bitmap)
384 {
385         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
386         SysAssertf(pButtonImpl != null,
387                                         "Not yet constructed. Construct() should be called before use.");
388
389         pButtonImpl->SetNormalBackgroundBitmap(bitmap);
390
391         return;
392 }
393
394 void
395 Button::SetDisabledBackgroundBitmap(const Bitmap& bitmap)
396 {
397         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
398         SysAssertf(pButtonImpl != null,
399                                         "Not yet constructed. Construct() should be called before use.");
400
401         pButtonImpl->SetDisabledBackgroundBitmap(bitmap);
402
403         return;
404 }
405
406 void
407 Button::SetPressedBackgroundBitmap(const Bitmap& bitmap)
408 {
409         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
410         SysAssertf(pButtonImpl != null,
411                                         "Not yet constructed. Construct() should be called before use.");
412
413         pButtonImpl->SetPressedBackgroundBitmap(bitmap);
414
415         return;
416 }
417
418 void
419 Button::SetHighlightedBackgroundBitmap(const Bitmap& bitmap)
420 {
421         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
422         SysAssertf(pButtonImpl != null,
423                                         "Not yet constructed. Construct() should be called before use.");
424
425         pButtonImpl->SetHighlightedBackgroundBitmap(bitmap);
426
427         return;
428 }
429
430 Color
431 Button::GetColor(ButtonStatus status) const
432 {
433         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
434         SysAssertf(pButtonImpl != null,
435                                         "Not yet constructed. Construct() should be called before use.");
436
437         return pButtonImpl->GetColor(status);
438 }
439
440 result
441 Button::SetColor(ButtonStatus status, const Color& color)
442 {
443         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
444         SysAssertf(pButtonImpl != null,
445                                         "Not yet constructed. Construct() should be called before use.");
446
447         result r = pButtonImpl->SetColor(status, color);
448         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
449
450         return E_SUCCESS;
451 }
452
453 int
454 Button::GetTextSize(void) const
455 {
456         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
457         SysAssertf(pButtonImpl != null,
458                                         "Not yet constructed. Construct() should be called before use.");
459
460         return pButtonImpl->GetTextSize();
461 }
462
463 float
464 Button::GetTextSizeF(void) const
465 {
466         const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
467         SysAssertf(pButtonImpl != null,
468                                         "Not yet constructed. Construct() should be called before use.");
469
470         return pButtonImpl->GetTextSizeF();
471 }
472
473 result
474 Button::SetTextSize(int size)
475 {
476         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
477         SysAssertf(pButtonImpl != null,
478                                         "Not yet constructed. Construct() should be called before use.");
479
480         result r = pButtonImpl->SetTextSize(size);
481         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
482
483         return r;
484 }
485
486 result
487 Button::SetTextSize(float size)
488 {
489         _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
490         SysAssertf(pButtonImpl != null,
491                                         "Not yet constructed. Construct() should be called before use.");
492
493         result r = pButtonImpl->SetTextSize(size);
494         SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
495
496         return r;
497 }
498
499 }}} // Tizen::Ui::Controls