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 "button-impl.h"
22 #include <dali/public-api/events/touch-event.h>
23 #include <dali/public-api/object/type-registry.h>
31 const Property::Index Button::PROPERTY_DISABLED = Internal::Button::BUTTON_PROPERTY_START_INDEX;
32 const Property::Index Button::PROPERTY_AUTO_REPEATING = Internal::Button::BUTTON_PROPERTY_START_INDEX + 1;
33 const Property::Index Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY = Internal::Button::BUTTON_PROPERTY_START_INDEX + 2;
34 const Property::Index Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY = Internal::Button::BUTTON_PROPERTY_START_INDEX + 3;
35 const Property::Index Button::PROPERTY_TOGGLABLE = Internal::Button::BUTTON_PROPERTY_START_INDEX + 4;
36 const Property::Index Button::PROPERTY_TOGGLED = Internal::Button::BUTTON_PROPERTY_START_INDEX + 5;
37 const Property::Index Button::PROPERTY_NORMAL_STATE_ACTOR = Internal::Button::BUTTON_PROPERTY_START_INDEX + 6;
38 const Property::Index Button::PROPERTY_SELECTED_STATE_ACTOR = Internal::Button::BUTTON_PROPERTY_START_INDEX + 7;
39 const Property::Index Button::PROPERTY_DISABLED_STATE_ACTOR = Internal::Button::BUTTON_PROPERTY_START_INDEX + 8;
40 const Property::Index Button::PROPERTY_LABEL_ACTOR = Internal::Button::BUTTON_PROPERTY_START_INDEX + 9;
50 // empty handle as we cannot create button (but type registered for clicked signal)
54 TypeRegistration typeRegistration( typeid(Toolkit::Button), typeid(Toolkit::Control), Create );
56 SignalConnectorType signalConnector1( typeRegistration, Toolkit::Button::SIGNAL_CLICKED, &Button::DoConnectSignal );
57 SignalConnectorType signalConnector2( typeRegistration, Toolkit::Button::SIGNAL_STATE_CHANGED, &Button::DoConnectSignal );
59 PropertyRegistration property1( typeRegistration, "disabled", Toolkit::Button::PROPERTY_DISABLED, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
60 PropertyRegistration property2( typeRegistration, "auto-repeating", Toolkit::Button::PROPERTY_AUTO_REPEATING, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
61 PropertyRegistration property3( typeRegistration, "initial-auto-repeating-delay", Toolkit::Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, Property::FLOAT, &Button::SetProperty, &Button::GetProperty );
62 PropertyRegistration property4( typeRegistration, "next-auto-repeating-delay", Toolkit::Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY, Property::FLOAT, &Button::SetProperty, &Button::GetProperty );
63 PropertyRegistration property5( typeRegistration, "togglable", Toolkit::Button::PROPERTY_TOGGLABLE, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
64 PropertyRegistration property6( typeRegistration, "toggled", Toolkit::Button::PROPERTY_TOGGLED, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
65 PropertyRegistration property7( typeRegistration, "normal-state-actor", Toolkit::Button::PROPERTY_NORMAL_STATE_ACTOR, Property::MAP, &Button::SetProperty, &Button::GetProperty );
66 PropertyRegistration property8( typeRegistration, "selected-state-actor", Toolkit::Button::PROPERTY_SELECTED_STATE_ACTOR, Property::MAP, &Button::SetProperty, &Button::GetProperty );
67 PropertyRegistration property9( typeRegistration, "disabled-state-actor", Toolkit::Button::PROPERTY_DISABLED_STATE_ACTOR, Property::MAP, &Button::SetProperty, &Button::GetProperty );
68 PropertyRegistration property10( typeRegistration, "label-actor", Toolkit::Button::PROPERTY_LABEL_ACTOR, Property::MAP, &Button::SetProperty, &Button::GetProperty );
70 } // unnamed namespace
73 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
84 void Button::SetDisabled( bool disabled )
88 // Notifies the painter.
89 Toolkit::Button handle( GetOwner() );
92 mPainter->SetDisabled( handle, mDisabled );
96 bool Button::IsDisabled() const
101 void Button::SetAnimationTime( float animationTime )
103 OnAnimationTimeSet( animationTime );
106 float Button::GetAnimationTime() const
108 return OnAnimationTimeRequested();
111 void Button::OnAnimationTimeSet( float animationTime )
116 void Button::OnButtonDown()
121 void Button::OnButtonUp()
126 float Button::OnAnimationTimeRequested() const
131 Toolkit::Button::ClickedSignalType& Button::ClickedSignal()
133 return mClickedSignal;
136 Toolkit::Button::StateChangedSignalType& Button::StateChangedSignal()
138 return mStateChangedSignal;
141 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
143 Dali::BaseHandle handle( object );
145 bool connected( true );
146 Toolkit::Button button = Toolkit::Button::DownCast(handle);
148 if( Dali::Toolkit::Button::SIGNAL_CLICKED == signalName )
150 button.ClickedSignal().Connect( tracker, functor );
152 else if( Dali::Toolkit::Button::SIGNAL_STATE_CHANGED == signalName )
154 button.StateChangedSignal().Connect( tracker, functor );
158 // signalName does not match any signal
165 bool Button::OnTouchEvent(const TouchEvent& event)
167 // Only events are processed when the button is not disabled and the touch event has only
169 if( ( !mDisabled ) && ( 1 == event.GetPointCount() ) )
171 switch( event.GetPoint(0).state )
173 case TouchPoint::Down:
175 OnButtonDown(); // Notification for derived classes.
177 // Sets the button state to ButtonDown.
183 OnButtonUp(); // Notification for derived classes.
185 // Sets the button state to ButtonUp.
189 case TouchPoint::Interrupted:
191 OnTouchPointInterrupted(); // Notification for derived classes.
193 // Sets the button state to the default (ButtonUp).
197 case TouchPoint::Leave:
199 OnTouchPointLeave(); // Notification for derived classes.
201 // Sets the button state to the default (ButtonUp).
205 case TouchPoint::Motion:
206 case TouchPoint::Stationary: // FALLTHROUGH
213 DALI_ASSERT_ALWAYS( !"Point status unhandled." );
218 else if( 1 < event.GetPointCount() )
220 OnTouchPointLeave(); // Notification for derived classes.
222 // Sets the button state to the default (ButtonUp).
229 void Button::OnInitialize()
231 // Initialize the painter and notifies subclasses.
232 Toolkit::Button handle( GetOwner() );
235 mPainter->Initialize( handle );
240 mTapDetector = TapGestureDetector::New();
241 mTapDetector.Attach( self );
242 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
244 OnButtonInitialize();
246 self.SetKeyboardFocusable( true );
249 void Button::OnControlSizeSet(const Vector3& targetSize)
251 Toolkit::Button handle( GetOwner() );
254 mPainter->SetSize( handle, targetSize );
258 void Button::OnTap(Actor actor, const TapGesture& tap)
263 void Button::OnControlStageDisconnection()
265 OnButtonStageDisconnection(); // Notification for derived classes.
269 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
271 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
273 if ( button && ( index == Toolkit::Button::PROPERTY_DISABLED ) )
275 GetImplementation( button ).SetDisabled( value.Get<bool>() );
279 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
281 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
283 if ( button && ( propertyIndex == Toolkit::Button::PROPERTY_DISABLED ) )
285 return Property::Value( GetImplementation( button ).mDisabled );
288 return Property::Value();
291 } // namespace Internal
293 } // namespace Toolkit