2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "radio-button-impl.h"
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/object/type-registry.h>
25 #if defined(DEBUG_ENABLED)
26 extern Debug::Filter* gLogButtonFilter;
39 return Toolkit::RadioButton::New();
42 TypeRegistration typeRegistration(typeid(Toolkit::RadioButton), typeid(Toolkit::Button), Create);
46 Dali::Toolkit::RadioButton RadioButton::New()
48 // Create the implementation, temporarily owned on stack
49 IntrusivePtr<RadioButton> internalRadioButton = new RadioButton();
51 // Pass ownership to CustomActor
52 Dali::Toolkit::RadioButton radioButton(*internalRadioButton);
54 // Second-phase init of the implementation
55 // This can only be done after the CustomActor connection has been made...
56 internalRadioButton->Initialize();
61 RadioButton::RadioButton()
63 SetTogglableButton(true);
66 RadioButton::~RadioButton()
70 void RadioButton::OnInitialize()
72 Button::OnInitialize();
74 Self().SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::RADIO_BUTTON);
77 DevelControl::ControlAccessible* RadioButton::CreateAccessibleObject()
79 return new RadioButtonAccessible(Self());
82 bool RadioButton::OnToggleReleased()
84 // Radio button overrides toggle release (button up) as doesn't allow un-selection to be performed on it directly.
88 void RadioButton::OnStateChange(State newState)
90 // Radio button can be part of a group, if a button in the group is selected then all others should be unselected
91 DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "RadioButton::OnStateChange state(%d)\n", newState);
93 if(SELECTED_STATE == newState)
95 Actor parent = Self().GetParent();
98 for(unsigned int i = 0; i < parent.GetChildCount(); ++i)
100 Dali::Toolkit::RadioButton radioButtonChild = Dali::Toolkit::RadioButton::DownCast(parent.GetChildAt(i));
101 if(radioButtonChild && radioButtonChild != Self())
103 radioButtonChild.SetProperty(Toolkit::Button::Property::SELECTED, false);
109 // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used
110 if((Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor() == Self()) && (newState == SELECTED_STATE || newState == UNSELECTED_STATE))
112 GetAccessibleObject()->EmitStateChanged(Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0);
116 Dali::Accessibility::States RadioButton::RadioButtonAccessible::CalculateStates()
118 auto state = Button::ButtonAccessible::CalculateStates();
119 auto self = Toolkit::Button::DownCast(Self());
121 if(self.GetProperty<bool>(Toolkit::Button::Property::SELECTED))
123 state[Dali::Accessibility::State::CHECKED] = true;
126 state[Dali::Accessibility::State::SELECTABLE] = true;
130 } // namespace Internal
132 } // namespace Toolkit