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.
20 #include "radio-button-impl.h"
23 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/object/type-registry.h>
26 #if defined(DEBUG_ENABLED)
27 extern Debug::Filter* gLogButtonFilter;
44 return Toolkit::RadioButton::New();
47 TypeRegistration typeRegistration( typeid( Toolkit::RadioButton ), typeid( Toolkit::Button ), Create);
51 Dali::Toolkit::RadioButton RadioButton::New()
53 // Create the implementation, temporarily owned on stack
54 IntrusivePtr< RadioButton > internalRadioButton = new RadioButton();
56 // Pass ownership to CustomActor
57 Dali::Toolkit::RadioButton radioButton(*internalRadioButton);
59 // Second-phase init of the implementation
60 // This can only be done after the CustomActor connection has been made...
61 internalRadioButton->Initialize();
66 RadioButton::RadioButton()
68 SetTogglableButton(true);
69 DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) {
70 return std::unique_ptr< Dali::Accessibility::Accessible >(
71 new AccessibleImpl( actor, Dali::Accessibility::Role::RADIO_BUTTON ) );
75 RadioButton::~RadioButton()
79 void RadioButton::OnInitialize()
81 Button::OnInitialize();
84 bool RadioButton::OnToggleReleased()
86 // Radio button overrides toggle release (button up) as doesn't allow un-selection to be performed on it directly.
90 void RadioButton::OnStateChange( State newState )
92 // Radio button can be part of a group, if a button in the group is selected then all others should be unselected
93 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "RadioButton::OnStateChange state(%d)\n", newState );
95 if ( SELECTED_STATE == newState )
97 Actor parent = Self().GetParent();
100 for( unsigned int i = 0; i < parent.GetChildCount(); ++i )
102 Dali::Toolkit::RadioButton radioButtonChild = Dali::Toolkit::RadioButton::DownCast( parent.GetChildAt( i ) );
103 if( radioButtonChild && radioButtonChild != Self() )
105 radioButtonChild.SetProperty( Toolkit::Button::Property::SELECTED, false );
110 // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used
111 if (Dali::Accessibility::IsUp() && (newState == SELECTED_STATE || newState == UNSELECTED_STATE))
113 Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged(
114 Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0
119 Dali::Accessibility::States RadioButton::AccessibleImpl::CalculateStates()
121 auto tmp = Button::AccessibleImpl::CalculateStates();
122 auto slf = Toolkit::Button::DownCast( self );
123 if( slf.GetProperty<bool>( Toolkit::Button::Property::SELECTED ) )
124 tmp[Dali::Accessibility::State::CHECKED] = true;
125 tmp[Dali::Accessibility::State::SELECTABLE] = true;
129 } // namespace Internal
131 } // namespace Toolkit