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 FUiCtrlCheckButton.cpp
19 * @brief This file contains implementation of CheckButton class
22 #include <FUiCtrlCheckButton.h>
23 #include <FBaseSysLog.h>
24 #include "FUiCtrl_CheckButtonImpl.h"
26 #define CONTROL_MINIMUM_LENGTH_LIMIT 0
27 #define CONTROL_MAXIMUM_LENGTH_LIMIT 0xFFFF
28 #define CONTROL_MINIMUM_SIZE_LIMIT 0, 0
29 #define CONTROL_MAXIMUM_SIZE_LIMIT 0xFFFF, 0xFFFF
31 #define PROPERTY_CHECKBUTTON_MIN_WIDTH 0
32 #define PROPERTY_CHECKBUTTON_MIN_HEIGHT 0
33 #define PROPERTY_CHECKBUTTON_MIN_WIDTH_WITH_TITLE 0
34 #define PROPERTY_CHECKBUTTON_MIN_HEIGHT_WITH_TITLE 0
35 #define PROPERTY_CHECKBUTTON_MIN_WIDTH_WITH_DIVIDER 0
36 #define PROPERTY_CHECKBUTTON_MIN_WIDTH_ONOFF_SLIDING 0
37 #define PROPERTY_CHECKBUTTON_MIN_WIDTH_WITH_DETAILED 0
38 #define PROPERTY_CHECK_MARK_REGION_CONFIG 108
39 int checkMinWidth, checkMinHeight = 0;
41 using namespace Tizen::Base;
42 using namespace Tizen::Graphics;
44 namespace Tizen { namespace Ui { namespace Controls
47 CheckButton::CheckButton(void)
52 CheckButton::~CheckButton(void)
58 CheckButton::Construct(const Rectangle& rect, CheckButtonStyle style, BackgroundStyle backgroundStyle,
59 bool showTitle, const String& text, GroupStyle groupStyle)
63 case CHECK_BUTTON_STYLE_MARK_WITH_DIVIDER:
65 case CHECK_BUTTON_STYLE_ONOFF_WITH_DIVIDER:
67 case CHECK_BUTTON_STYLE_RADIO_WITH_DIVIDER:
68 checkMinWidth = PROPERTY_CHECKBUTTON_MIN_WIDTH_WITH_DIVIDER;
71 case CHECK_BUTTON_STYLE_MARK_WITH_DETAILED_BUTTON:
73 case CHECK_BUTTON_STYLE_RADIO_WITH_DETAILED_BUTTON:
74 checkMinWidth = PROPERTY_CHECKBUTTON_MIN_WIDTH_WITH_DETAILED;
77 case CHECK_BUTTON_STYLE_ONOFF_SLIDING:
78 checkMinWidth = PROPERTY_CHECKBUTTON_MIN_WIDTH_ONOFF_SLIDING;
81 default: //CHECK_BUTTON_STYLE_MARK , CHECK_BUTTON_STYLE_ONOFF, CHECK_BUTTON_STYLE_RADIO
82 checkMinWidth = showTitle ? PROPERTY_CHECKBUTTON_MIN_WIDTH_WITH_TITLE : PROPERTY_CHECKBUTTON_MIN_WIDTH;
85 checkMinHeight = showTitle ? PROPERTY_CHECKBUTTON_MIN_HEIGHT_WITH_TITLE : PROPERTY_CHECKBUTTON_MIN_HEIGHT;
87 SysTryReturn(NID_UI_CTRL, (rect.width >= checkMinWidth && rect.width <= CONTROL_MAXIMUM_LENGTH_LIMIT),
88 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The width error occurred");
90 SysTryReturn(NID_UI_CTRL, (rect.height >= checkMinHeight && rect.height <= CONTROL_MAXIMUM_LENGTH_LIMIT),
91 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The height error occurred");
93 SysTryReturn(NID_UI_CTRL, !(backgroundStyle == BACKGROUND_STYLE_NONE && groupStyle != GROUP_STYLE_NONE),
94 E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Unable to set group style.");
97 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
99 SysAssertf(pCheckButtonImpl == null,
100 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
102 pCheckButtonImpl = _CheckButtonImpl::CreateCheckButtonImplN(this, rect);
104 SysTryReturn(NID_UI_CTRL, pCheckButtonImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
107 r = pCheckButtonImpl->SetCheckButtonStyle(style);
108 SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
110 r = pCheckButtonImpl->SetBackgroundStyle(backgroundStyle);
111 SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
113 r = pCheckButtonImpl->SetShowTitle(showTitle);
114 SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
116 r = pCheckButtonImpl->SetText(text);
117 SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
119 r = pCheckButtonImpl->SetGroupStyle(groupStyle);
120 SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
122 r = pCheckButtonImpl->SetMinimumSize(Dimension(checkMinWidth, checkMinHeight));
123 SysAssert(r == E_SUCCESS); // [ToDo] Exception. Which exception can occur?
125 _pControlImpl = pCheckButtonImpl;
131 CheckButton::SetSelected(bool select)
133 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
134 SysAssertf(pCheckButtonImpl != null,
135 "Not yet constructed. Construct() should be called before use.");
137 pCheckButtonImpl->SetSelected(select);
143 CheckButton::IsSelected(void) const
145 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
146 SysAssertf(pCheckButtonImpl != null,
147 "Not yet constructed. Construct() should be called before use.");
149 return pCheckButtonImpl->IsSelected();
153 CheckButton::AddActionEventListener(IActionEventListener& listener)
155 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
156 SysAssertf(pCheckButtonImpl != null,
157 "Not yet constructed. Construct() should be called before use.");
159 result r = pCheckButtonImpl->AddActionEventListener(listener);
160 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
166 CheckButton::RemoveActionEventListener(IActionEventListener& listener)
168 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
169 SysAssertf(pCheckButtonImpl != null,
170 "Not yet constructed. Construct() should be called before use.");
172 result r = pCheckButtonImpl->RemoveActionEventListener(listener);
173 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
179 CheckButton::SetActionId(int checkedActionId, int uncheckedActionId, int selectedActionId)
181 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
182 SysAssertf(pCheckButtonImpl != null,
183 "Not yet constructed. Construct() should be called before use.");
185 pCheckButtonImpl->SetActionId(checkedActionId, uncheckedActionId, selectedActionId);
191 CheckButton::GetCheckedActionId(void) const
193 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
194 SysAssertf(pCheckButtonImpl != null,
195 "Not yet constructed. Construct() should be called before use.");
197 return pCheckButtonImpl->GetCheckedActionId();
201 CheckButton::GetUncheckedActionId(void) const
203 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
204 SysAssertf(pCheckButtonImpl != null,
205 "Not yet constructed. Construct() should be called before use.");
207 return pCheckButtonImpl->GetUncheckedActionId();
211 CheckButton::GetSelectedActionId(void) const
213 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
214 SysAssertf(pCheckButtonImpl != null,
215 "Not yet constructed. Construct() should be called before use.");
217 return pCheckButtonImpl->GetSelectedActionId();
221 CheckButton::SetText(const String& text)
223 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
224 SysAssertf(pCheckButtonImpl != null,
225 "Not yet constructed. Construct() should be called before use.");
227 pCheckButtonImpl->SetText(text);
233 CheckButton::GetText(void) const
235 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
236 SysAssertf(pCheckButtonImpl != null,
237 "Not yet constructed. Construct() should be called before use.");
239 return pCheckButtonImpl->GetText();
243 CheckButton::SetTitleText(const String& title)
245 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
246 SysAssertf(pCheckButtonImpl != null,
247 "Not yet constructed. Construct() should be called before use.");
249 result r = pCheckButtonImpl->SetTitleText(title);
250 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
256 CheckButton::GetTitleText(void) const
258 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
259 SysAssertf(pCheckButtonImpl != null,
260 "Not yet constructed. Construct() should be called before use.");
262 return pCheckButtonImpl->GetTitleText();
266 CheckButton::SetTextHorizontalAlignment(HorizontalAlignment alignment)
268 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
269 SysAssertf(pCheckButtonImpl != null,
270 "Not yet constructed. Construct() should be called before use.");
272 pCheckButtonImpl->SetTextHorizontalAlignment(alignment);
278 CheckButton::GetTextHorizontalAlignment(void) const
280 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
281 SysAssertf(pCheckButtonImpl != null,
282 "Not yet constructed. Construct() should be called before use.");
284 return pCheckButtonImpl->GetTextHorizontalAlignment();
288 CheckButton::SetTextVerticalAlignment(VerticalAlignment alignment)
290 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
291 SysAssertf(pCheckButtonImpl != null,
292 "Not yet constructed. Construct() should be called before use.");
294 pCheckButtonImpl->SetTextVerticalAlignment(alignment);
300 CheckButton::GetTextVerticalAlignment(void) const
302 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
303 SysAssertf(pCheckButtonImpl != null,
304 "Not yet constructed. Construct() should be called before use.");
306 return pCheckButtonImpl->GetTextVerticalAlignment();
310 CheckButton::SetTextColor(const Color& color)
312 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
313 SysAssertf(pCheckButtonImpl != null,
314 "Not yet constructed. Construct() should be called before use.");
316 pCheckButtonImpl->SetTextColor(color);
322 CheckButton::GetTextColor(void) const
324 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
325 SysAssertf(pCheckButtonImpl != null,
326 "Not yet constructed. Construct() should be called before use.");
328 return pCheckButtonImpl->GetTextColor();
332 CheckButton::SetDisabledTextColor(const Color& color)
334 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
335 SysAssertf(pCheckButtonImpl != null,
336 "Not yet constructed. Construct() should be called before use.");
338 result r = pCheckButtonImpl->SetDisabledTextColor(color);
339 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
345 CheckButton::GetDisabledTextColor(void) const
347 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
348 SysAssertf(pCheckButtonImpl != null,
349 "Not yet constructed. Construct() should be called before use.");
351 return pCheckButtonImpl->GetDisabledTextColor();
355 CheckButton::SetPressedTextColor(const Color& color)
357 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
358 SysAssertf(pCheckButtonImpl != null,
359 "Not yet constructed. Construct() should be called before use.");
361 result r = pCheckButtonImpl->SetPressedTextColor(color);
362 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
368 CheckButton::GetPressedTextColor(void) const
370 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
371 SysAssertf(pCheckButtonImpl != null,
372 "Not yet constructed. Construct() should be called before use.");
374 return pCheckButtonImpl->GetPressedTextColor();
378 CheckButton::SetHighlightedTextColor(const Color& color)
380 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
381 SysAssertf(pCheckButtonImpl != null,
382 "Not yet constructed. Construct() should be called before use.");
384 result r = pCheckButtonImpl->SetHighlightedTextColor(color);
385 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
391 CheckButton::GetHighlightedTextColor(void) const
393 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
394 SysAssertf(pCheckButtonImpl != null,
395 "Not yet constructed. Construct() should be called before use.");
397 return pCheckButtonImpl->GetHighlightedTextColor();
401 CheckButton::SetTitleTextColor(const Color& color)
403 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
404 SysAssertf(pCheckButtonImpl != null,
405 "Not yet constructed. Construct() should be called before use.");
407 pCheckButtonImpl->SetTitleTextColor(color);
413 CheckButton::GetTitleTextColor(void) const
415 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
416 SysAssertf(pCheckButtonImpl != null,
417 "Not yet constructed. Construct() should be called before use.");
419 return pCheckButtonImpl->GetTitleTextColor();
423 CheckButton::SetDisabledTitleTextColor(const Color& color)
425 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
426 SysAssertf(pCheckButtonImpl != null,
427 "Not yet constructed. Construct() should be called before use.");
429 result r = pCheckButtonImpl->SetDisabledTitleTextColor(color);
430 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
436 CheckButton::GetDisabledTitleTextColor(void) const
438 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
439 SysAssertf(pCheckButtonImpl != null,
440 "Not yet constructed. Construct() should be called before use.");
442 return pCheckButtonImpl->GetDisabledTitleTextColor();
446 CheckButton::SetPressedTitleTextColor(const Color& color)
448 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
449 SysAssertf(pCheckButtonImpl != null,
450 "Not yet constructed. Construct() should be called before use.");
452 result r = pCheckButtonImpl->SetPressedTitleTextColor(color);
453 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
459 CheckButton::GetPressedTitleTextColor(void) const
461 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
462 SysAssertf(pCheckButtonImpl != null,
463 "Not yet constructed. Construct() should be called before use.");
465 return pCheckButtonImpl->GetPressedTitleTextColor();
469 CheckButton::SetHighlightedTitleTextColor(const Color& color)
471 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
472 SysAssertf(pCheckButtonImpl != null,
473 "Not yet constructed. Construct() should be called before use.");
475 result r = pCheckButtonImpl->SetHighlightedTitleTextColor(color);
476 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
482 CheckButton::GetHighlightedTitleTextColor(void) const
484 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
485 SysAssertf(pCheckButtonImpl != null,
486 "Not yet constructed. Construct() should be called before use.");
488 return pCheckButtonImpl->GetHighlightedTitleTextColor();
492 CheckButton::SetColor(CheckButtonStatus status, const Color& color)
494 _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
495 SysAssertf(pCheckButtonImpl != null,
496 "Not yet constructed. Construct() should be called before use.");
498 result r = pCheckButtonImpl->SetColor(status, color);
499 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
505 CheckButton::GetColor(CheckButtonStatus status) const
507 const _CheckButtonImpl* pCheckButtonImpl = _CheckButtonImpl::GetInstance(*this);
508 SysAssertf(pCheckButtonImpl != null,
509 "Not yet constructed. Construct() should be called before use.");
511 return pCheckButtonImpl->GetColor(status);
514 }}} // Tizen::Ui::Controls