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>
25 #include <dali/public-api/images/resource-image.h>
27 #if defined(DEBUG_ENABLED)
28 extern Debug::Filter* gLogButtonFilter;
45 return Toolkit::RadioButton::New();
48 TypeRegistration typeRegistration( typeid( Toolkit::RadioButton ), typeid( Toolkit::Button ), Create);
52 Dali::Toolkit::RadioButton RadioButton::New()
54 // Create the implementation, temporarily owned on stack
55 IntrusivePtr< RadioButton > internalRadioButton = new RadioButton();
57 // Pass ownership to CustomActor
58 Dali::Toolkit::RadioButton radioButton(*internalRadioButton);
60 // Second-phase init of the implementation
61 // This can only be done after the CustomActor connection has been made...
62 internalRadioButton->Initialize();
67 RadioButton::RadioButton()
69 SetTogglableButton(true);
72 RadioButton::~RadioButton()
76 void RadioButton::OnInitialize()
78 Button::OnInitialize();
81 bool RadioButton::OnToggleReleased()
83 // Radio button overrides toggle release (button up) as doesn't allow un-selection to be performed on it directly.
84 bool stateChanged = false;
87 Button::SetSelected( true ); // Set button to selected as previously unselected
93 void RadioButton::OnStateChange( State newState )
95 // Radio button can be part of a group, if a button in the group is selected then all others should be unselected
96 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "RadioButton::OnStateChange state(%d)\n", newState );
102 Actor parent = Self().GetParent();
105 for( unsigned int i = 0; i < parent.GetChildCount(); ++i )
107 Dali::Toolkit::RadioButton radioButtonChild = Dali::Toolkit::RadioButton::DownCast( parent.GetChildAt( i ) );
108 if( radioButtonChild && radioButtonChild != Self() )
110 radioButtonChild.SetSelected( false );
123 } // namespace Internal
125 } // namespace Toolkit