2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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::AddActionEventListener(IActionEventListener& listener)
66 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
67 SysAssertf(pButtonImpl != null,
68 "Not yet constructed. Construct() should be called before use.");
70 result r = pButtonImpl->AddActionEventListener(listener);
71 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
77 Button::RemoveActionEventListener(IActionEventListener& listener)
79 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
80 SysAssertf(pButtonImpl != null,
81 "Not yet constructed. Construct() should be called before use.");
83 result r = pButtonImpl->RemoveActionEventListener(listener);
84 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
90 Button::SetActionId(int actionId)
92 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
93 SysAssertf(pButtonImpl != null,
94 "Not yet constructed. Construct() should be called before use.");
96 pButtonImpl->SetActionId(actionId);
102 Button::GetActionId(void) const
104 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
105 SysAssertf(pButtonImpl != null,
106 "Not yet constructed. Construct() should be called before use.");
108 return pButtonImpl->GetActionId();
112 Button::SetText(const String& text)
114 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
115 SysAssertf(pButtonImpl != null,
116 "Not yet constructed. Construct() should be called before use.");
118 pButtonImpl->SetText(text);
124 Button::SetTextHorizontalAlignment(HorizontalAlignment alignment)
126 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
127 SysAssertf(pButtonImpl != null,
128 "Not yet constructed. Construct() should be called before use.");
130 pButtonImpl->SetTextHorizontalAlignment(alignment);
136 Button::SetTextVerticalAlignment(VerticalAlignment alignment)
138 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
139 SysAssertf(pButtonImpl != null,
140 "Not yet constructed. Construct() should be called before use.");
142 pButtonImpl->SetTextVerticalAlignment(alignment);
148 Button::GetText(void) const
150 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
151 SysAssertf(pButtonImpl != null,
152 "Not yet constructed. Construct() should be called before use.");
154 return pButtonImpl->GetText();
158 Button::GetTextHorizontalAlignment(void) const
160 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
161 SysAssertf(pButtonImpl != null,
162 "Not yet constructed. Construct() should be called before use.");
164 return pButtonImpl->GetTextHorizontalAlignment();
168 Button::GetTextVerticalAlignment(void) const
170 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
171 SysAssertf(pButtonImpl != null,
172 "Not yet constructed. Construct() should be called before use.");
174 return pButtonImpl->GetTextVerticalAlignment();
178 Button::SetTextColor(const Color& color)
180 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
181 SysAssertf(pButtonImpl != null,
182 "Not yet constructed. Construct() should be called before use.");
184 pButtonImpl->SetTextColor(color);
190 Button::GetTextColor(void) const
192 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
193 SysAssertf(pButtonImpl != null,
194 "Not yet constructed. Construct() should be called before use.");
196 return pButtonImpl->GetTextColor();
200 Button::SetPressedTextColor(const Color& color)
202 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
203 SysAssertf(pButtonImpl != null,
204 "Not yet constructed. Construct() should be called before use.");
206 pButtonImpl->SetPressedTextColor(color);
212 Button::GetPressedTextColor(void) const
214 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
215 SysAssertf(pButtonImpl != null,
216 "Not yet constructed. Construct() should be called before use.");
218 return pButtonImpl->GetPressedTextColor();
222 Button::SetDisabledTextColor(const Color& color)
224 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
225 SysAssertf(pButtonImpl != null,
226 "Not yet constructed. Construct() should be called before use.");
228 pButtonImpl->SetDisabledTextColor(color);
234 Button::GetDisabledTextColor(void) const
236 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
237 SysAssertf(pButtonImpl != null,
238 "Not yet constructed. Construct() should be called before use.");
240 return pButtonImpl->GetDisabledTextColor();
244 Button::SetHighlightedTextColor(const Color& color)
246 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
247 SysAssertf(pButtonImpl != null,
248 "Not yet constructed. Construct() should be called before use.");
250 pButtonImpl->SetHighlightedTextColor(color);
256 Button::GetHighlightedTextColor(void) const
258 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
259 SysAssertf(pButtonImpl != null,
260 "Not yet constructed. Construct() should be called before use.");
262 return pButtonImpl->GetHighlightedTextColor();
266 Button::SetNormalBitmap(const Point& position, const Bitmap& bitmap)
268 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
269 SysAssertf(pButtonImpl != null,
270 "Not yet constructed. Construct() should be called before use.");
272 pButtonImpl->SetNormalBitmap(position, bitmap);
278 Button::SetPressedBitmap(const Point& position, const Bitmap& bitmap)
280 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
281 SysAssertf(pButtonImpl != null,
282 "Not yet constructed. Construct() should be called before use.");
284 pButtonImpl->SetPressedBitmap(position, bitmap);
290 Button::SetDisabledBitmap(const Point& position, const Bitmap& bitmap)
292 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
293 SysAssertf(pButtonImpl != null,
294 "Not yet constructed. Construct() should be called before use.");
296 pButtonImpl->SetDisabledBitmap(position, bitmap);
302 Button::SetNormalBackgroundBitmap(const Bitmap& bitmap)
304 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
305 SysAssertf(pButtonImpl != null,
306 "Not yet constructed. Construct() should be called before use.");
308 pButtonImpl->SetNormalBackgroundBitmap(bitmap);
314 Button::SetPressedBackgroundBitmap(const Bitmap& bitmap)
316 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
317 SysAssertf(pButtonImpl != null,
318 "Not yet constructed. Construct() should be called before use.");
320 pButtonImpl->SetPressedBackgroundBitmap(bitmap);
326 Button::SetHighlightedBackgroundBitmap(const Bitmap& bitmap)
328 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
329 SysAssertf(pButtonImpl != null,
330 "Not yet constructed. Construct() should be called before use.");
332 pButtonImpl->SetHighlightedBackgroundBitmap(bitmap);
338 Button::GetColor(ButtonStatus status) const
340 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
341 SysAssertf(pButtonImpl != null,
342 "Not yet constructed. Construct() should be called before use.");
344 return pButtonImpl->GetColor(status);
348 Button::SetColor(ButtonStatus status, const Color& color)
350 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
351 SysAssertf(pButtonImpl != null,
352 "Not yet constructed. Construct() should be called before use.");
354 result r = pButtonImpl->SetColor(status, color);
355 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
361 Button::GetTextSize(void) const
363 const _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
364 SysAssertf(pButtonImpl != null,
365 "Not yet constructed. Construct() should be called before use.");
367 return pButtonImpl->GetTextSize();
371 Button::SetTextSize(int size)
373 _ButtonImpl* pButtonImpl = _ButtonImpl::GetInstance(*this);
374 SysAssertf(pButtonImpl != null,
375 "Not yet constructed. Construct() should be called before use.");
377 result r = pButtonImpl->SetTextSize(size);
378 SysTryLog(NID_UI_CTRL, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
382 }}} // Tizen::Ui::Controls