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 FUiCtrl_RadioGroup.cpp
19 * @brief This is the implementation file for the _RadioGroup class.
22 #include <FBaseErrorDefine.h>
23 #include <FBaseSysLog.h>
24 #include "FUiCtrl_RadioGroup.h"
25 #include "FUiCtrl_RadioGroupPresenter.h"
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Graphics;
31 namespace Tizen { namespace Ui { namespace Controls
34 _RadioGroup::_RadioGroup(void)
35 : __pRadioGroupPresenter(null)
40 _RadioGroupPresenter* pPresenter = new (std::nothrow) _RadioGroupPresenter();
41 SysTryReturnVoidResult(NID_UI_CTRL, pPresenter, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
43 r = SetPresenter(*pPresenter);
44 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
46 r = pPresenter->Construct(*this);
47 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
49 r = pPresenter->Install();
50 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
65 _RadioGroup::CreateRadioGroupN(void)
67 _RadioGroup* pRadioGroup = new (std::nothrow) _RadioGroup();
68 SysTryReturn(NID_UI_CTRL, pRadioGroup, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
69 SysTryCatch(NID_UI_CTRL, GetLastResult() == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
71 pRadioGroup->AcquireHandle();
73 pRadioGroup->CreateCheckList();
82 _RadioGroup::~_RadioGroup(void)
84 if (__pRadioGroupPresenter)
86 delete __pRadioGroupPresenter;
87 __pRadioGroupPresenter = null;
100 _RadioGroup::SetPresenter(const _RadioGroupPresenter& radioGroupPresenter)
102 __pRadioGroupPresenter = const_cast <_RadioGroupPresenter*>(&radioGroupPresenter);
108 _RadioGroup::CreateCheckList(void)
110 result r = E_SUCCESS;
112 __checkList = new (std::nothrow) ArrayList();
113 SysTryReturn(NID_UI_CTRL, __checkList, E_INVALID_STATE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
115 r = __checkList->Construct();
116 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[E_SYSTEM] System error occurred.");
126 _RadioGroup::Add(_CheckButton& checkButton)
128 result r = E_SUCCESS;
130 if ((checkButton.__checkButtonStyle != CHECK_BUTTON_STYLE_RADIO) &&
131 (checkButton.__checkButtonStyle != CHECK_BUTTON_STYLE_RADIO_WITH_DIVIDER)
132 && (checkButton.__checkButtonStyle != CHECK_BUTTON_STYLE_RADIO_WITH_DETAILED_BUTTON))
134 SysTryReturn(NID_UI_CTRL, 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The CheckButton style is invalid.\n");
137 r = checkButton.AddRadioGroup(*this);
138 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_INVALID_ARG, E_INVALID_ARG,
139 "[E_INVALID_ARG] The CheckButton is already belonged to a RadioGroup.\n");
141 r = __checkList->Add(checkButton);
142 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_INVALID_ARG, E_INVALID_ARG,
143 "[E_INVALID_ARG] The CheckButton is already belonged to a RadioGroup.\n");
149 _RadioGroup::Remove(_CheckButton& checkButton)
151 result r = E_SUCCESS;
153 r = checkButton.RemoveRadioGroup();
154 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND,
155 "[E_OBJ_NOT_FOUND] Unable to find the CheckButton.\n");
157 r = __checkList->Remove(checkButton);
158 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND,
159 "[E_OBJ_NOT_FOUND] Unable to find the CheckButton.\n");
165 _RadioGroup::OnNotifiedN(const _Control& source, IList* pArgs)
167 SysTryReturn(NID_UI_CTRL, pArgs != null, false, E_SYSTEM, "[E_SYSTEM] The argument is invalid.");
169 String checkButtonReleasedEvent(L"CheckButtonReleasedEvent");
170 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
172 const _CheckButton* pSelectedCheckButton = dynamic_cast <const _CheckButton*>(pArgs->GetAt(1));
173 SysTryReturn(NID_UI_CTRL, pSelectedCheckButton, false, E_INVALID_STATE, "[E_INVALID_STATE] This instance is not constructed.");
177 if (*pType == checkButtonReleasedEvent)
179 SetSelectedItem(*pSelectedCheckButton);
188 _RadioGroup::SetSelectedItem(const _CheckButton& checkButton)
190 _CheckButton* pCurrentRB = null;
191 _CheckButton* pTarget = const_cast <_CheckButton*>(&checkButton);
193 int count = __checkList->GetCount();
195 for (int i = 0; i < count; i++)
197 pCurrentRB = dynamic_cast<_CheckButton*>(__checkList->GetAt(i));
201 if (pTarget == pCurrentRB)
203 pCurrentRB->SetSelected(true);
207 pCurrentRB->SetSelected(false);
217 _RadioGroup::GetItemCount(void) const
219 return __checkList->GetCount();
223 _RadioGroup::GetSelectedItem(void) const
225 const _CheckButton* pCurrentRB = null;
226 int count = __checkList->GetCount();
228 for (int i = 0; i < count; i++)
230 pCurrentRB = dynamic_cast<_CheckButton*>(__checkList->GetAt(i));
234 if (pCurrentRB->IsSelected() == true)
248 }}} // Tizen::Ui::Controls