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.
18 * @file FUiCtrlButton.cpp
19 * @brief This file contains implementation of Button class
22 #include <FUiCtrlButton.h>
23 #include <FBaseSysLog.h>
24 #include "FUiCtrl_ButtonImpl.h"
26 using namespace Tizen::Base;
27 using namespace Tizen::Graphics;
29 namespace Tizen { namespace Ui { namespace Controls
43 Button::Construct(const Rectangle& rect, const String& text)
46 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
48 SysAssertf(pButtonImpl == null,
49 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
51 pButtonImpl = _ButtonImpl::CreateButtonImplN(this, rect);
53 SysTryReturn(NID_UI_CTRL, pButtonImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
55 r = pButtonImpl->SetText(text);
56 SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
58 _pControlImpl = pButtonImpl;
64 Button::Construct(const FloatRectangle& rect, const String& text)
67 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
69 SysAssertf(pButtonImpl == null,
70 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
72 pButtonImpl = _ButtonImpl::CreateButtonImplN(this, rect);
74 SysTryReturn(NID_UI_CTRL, pButtonImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
76 r = pButtonImpl->SetText(text);
77 SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
79 _pControlImpl = pButtonImpl;
85 Button::AddActionEventListener(IActionEventListener& listener)
87 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
88 SysAssertf(pButtonImpl != null,
89 "Not yet constructed. Construct() should be called before use.");
91 result r = pButtonImpl->AddActionEventListener(listener);
92 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
98 Button::RemoveActionEventListener(IActionEventListener& listener)
100 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
101 SysAssertf(pButtonImpl != null,
102 "Not yet constructed. Construct() should be called before use.");
104 result r = pButtonImpl->RemoveActionEventListener(listener);
105 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
111 Button::SetActionId(int actionId)
113 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
114 SysAssertf(pButtonImpl != null,
115 "Not yet constructed. Construct() should be called before use.");
117 pButtonImpl->SetActionId(actionId);
123 Button::GetActionId(void) const
125 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
126 SysAssertf(pButtonImpl != null,
127 "Not yet constructed. Construct() should be called before use.");
129 return pButtonImpl->GetActionId();
133 Button::SetText(const String& text)
135 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
136 SysAssertf(pButtonImpl != null,
137 "Not yet constructed. Construct() should be called before use.");
139 pButtonImpl->SetText(text);
145 Button::SetTextHorizontalAlignment(HorizontalAlignment alignment)
147 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
148 SysAssertf(pButtonImpl != null,
149 "Not yet constructed. Construct() should be called before use.");
151 pButtonImpl->SetTextHorizontalAlignment(alignment);
157 Button::SetTextVerticalAlignment(VerticalAlignment alignment)
159 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
160 SysAssertf(pButtonImpl != null,
161 "Not yet constructed. Construct() should be called before use.");
163 pButtonImpl->SetTextVerticalAlignment(alignment);
169 Button::GetText(void) const
171 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
172 SysAssertf(pButtonImpl != null,
173 "Not yet constructed. Construct() should be called before use.");
175 return pButtonImpl->GetText();
179 Button::GetTextHorizontalAlignment(void) const
181 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
182 SysAssertf(pButtonImpl != null,
183 "Not yet constructed. Construct() should be called before use.");
185 return pButtonImpl->GetTextHorizontalAlignment();
189 Button::GetTextVerticalAlignment(void) const
191 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
192 SysAssertf(pButtonImpl != null,
193 "Not yet constructed. Construct() should be called before use.");
195 return pButtonImpl->GetTextVerticalAlignment();
199 Button::SetTextColor(const Color& color)
201 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
202 SysAssertf(pButtonImpl != null,
203 "Not yet constructed. Construct() should be called before use.");
205 pButtonImpl->SetTextColor(color);
211 Button::GetTextColor(void) const
213 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
214 SysAssertf(pButtonImpl != null,
215 "Not yet constructed. Construct() should be called before use.");
217 return pButtonImpl->GetTextColor();
221 Button::SetPressedTextColor(const Color& color)
223 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
224 SysAssertf(pButtonImpl != null,
225 "Not yet constructed. Construct() should be called before use.");
227 pButtonImpl->SetPressedTextColor(color);
233 Button::GetPressedTextColor(void) const
235 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
236 SysAssertf(pButtonImpl != null,
237 "Not yet constructed. Construct() should be called before use.");
239 return pButtonImpl->GetPressedTextColor();
243 Button::SetDisabledTextColor(const Color& color)
245 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
246 SysAssertf(pButtonImpl != null,
247 "Not yet constructed. Construct() should be called before use.");
249 pButtonImpl->SetDisabledTextColor(color);
255 Button::GetDisabledTextColor(void) const
257 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
258 SysAssertf(pButtonImpl != null,
259 "Not yet constructed. Construct() should be called before use.");
261 return pButtonImpl->GetDisabledTextColor();
265 Button::SetHighlightedTextColor(const Color& color)
267 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
268 SysAssertf(pButtonImpl != null,
269 "Not yet constructed. Construct() should be called before use.");
271 pButtonImpl->SetHighlightedTextColor(color);
277 Button::GetHighlightedTextColor(void) const
279 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
280 SysAssertf(pButtonImpl != null,
281 "Not yet constructed. Construct() should be called before use.");
283 return pButtonImpl->GetHighlightedTextColor();
287 Button::SetNormalBitmap(const Point& position, const Bitmap& bitmap)
289 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
290 SysAssertf(pButtonImpl != null,
291 "Not yet constructed. Construct() should be called before use.");
293 pButtonImpl->SetNormalBitmap(position, bitmap);
299 Button::SetNormalBitmap(const FloatPoint& position, const Bitmap& bitmap)
301 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
302 SysAssertf(pButtonImpl != null,
303 "Not yet constructed. Construct() should be called before use.");
305 pButtonImpl->SetNormalBitmap(position, bitmap);
311 Button::SetDisabledBitmap(const Point& position, const Bitmap& bitmap)
313 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
314 SysAssertf(pButtonImpl != null,
315 "Not yet constructed. Construct() should be called before use.");
317 pButtonImpl->SetDisabledBitmap(position, bitmap);
323 Button::SetDisabledBitmap(const FloatPoint& position, const Bitmap& bitmap)
325 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
326 SysAssertf(pButtonImpl != null,
327 "Not yet constructed. Construct() should be called before use.");
329 pButtonImpl->SetDisabledBitmap(position, bitmap);
335 Button::SetPressedBitmap(const Point& position, const Bitmap& bitmap)
337 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
338 SysAssertf(pButtonImpl != null,
339 "Not yet constructed. Construct() should be called before use.");
341 pButtonImpl->SetPressedBitmap(position, bitmap);
347 Button::SetPressedBitmap(const FloatPoint& position, const Bitmap& bitmap)
349 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
350 SysAssertf(pButtonImpl != null,
351 "Not yet constructed. Construct() should be called before use.");
353 pButtonImpl->SetPressedBitmap(position, bitmap);
359 Button::SetHighlightedBitmap(const Point& position, const Bitmap& bitmap)
361 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
362 SysAssertf(pButtonImpl != null,
363 "Not yet constructed. Construct() should be called before use.");
365 pButtonImpl->SetHighlightedBitmap(position, bitmap);
371 Button::SetHighlightedBitmap(const FloatPoint& position, const Bitmap& bitmap)
373 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
374 SysAssertf(pButtonImpl != null,
375 "Not yet constructed. Construct() should be called before use.");
377 pButtonImpl->SetHighlightedBitmap(position, bitmap);
383 Button::SetNormalBackgroundBitmap(const Bitmap& bitmap)
385 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
386 SysAssertf(pButtonImpl != null,
387 "Not yet constructed. Construct() should be called before use.");
389 pButtonImpl->SetNormalBackgroundBitmap(bitmap);
395 Button::SetDisabledBackgroundBitmap(const Bitmap& bitmap)
397 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
398 SysAssertf(pButtonImpl != null,
399 "Not yet constructed. Construct() should be called before use.");
401 pButtonImpl->SetDisabledBackgroundBitmap(bitmap);
407 Button::SetPressedBackgroundBitmap(const Bitmap& bitmap)
409 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
410 SysAssertf(pButtonImpl != null,
411 "Not yet constructed. Construct() should be called before use.");
413 pButtonImpl->SetPressedBackgroundBitmap(bitmap);
419 Button::SetHighlightedBackgroundBitmap(const Bitmap& bitmap)
421 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
422 SysAssertf(pButtonImpl != null,
423 "Not yet constructed. Construct() should be called before use.");
425 pButtonImpl->SetHighlightedBackgroundBitmap(bitmap);
431 Button::GetColor(ButtonStatus status) const
433 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
434 SysAssertf(pButtonImpl != null,
435 "Not yet constructed. Construct() should be called before use.");
437 return pButtonImpl->GetColor(status);
441 Button::SetColor(ButtonStatus status, const Color& color)
443 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
444 SysAssertf(pButtonImpl != null,
445 "Not yet constructed. Construct() should be called before use.");
447 result r = pButtonImpl->SetColor(status, color);
448 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
454 Button::GetTextSize(void) const
456 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
457 SysAssertf(pButtonImpl != null,
458 "Not yet constructed. Construct() should be called before use.");
460 return pButtonImpl->GetTextSize();
464 Button::GetTextSizeF(void) const
466 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
467 SysAssertf(pButtonImpl != null,
468 "Not yet constructed. Construct() should be called before use.");
470 return pButtonImpl->GetTextSizeF();
474 Button::SetTextSize(int size)
476 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
477 SysAssertf(pButtonImpl != null,
478 "Not yet constructed. Construct() should be called before use.");
480 result r = pButtonImpl->SetTextSize(size);
481 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
487 Button::SetTextSize(float size)
489 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
490 SysAssertf(pButtonImpl != null,
491 "Not yet constructed. Construct() should be called before use.");
493 result r = pButtonImpl->SetTextSize(size);
494 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
499 }}} // Tizen::Ui::Controls