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 "button-impl.h"
24 const char* const PROPERTY_DIMMED = "dimmed";
25 } // unnamed namespace
33 const Property::Index Button::PROPERTY_DIMMED( Internal::Button::BUTTON_PROPERTY_START_INDEX );
43 // empty handle as we cannot create button (but type registered for clicked signal)
47 TypeRegistration typeRegistration( typeid(Toolkit::Button), typeid(Toolkit::Control), Create );
49 SignalConnectorType signalConnector1( typeRegistration, Toolkit::Button::SIGNAL_CLICKED, &Button::DoConnectSignal );
50 SignalConnectorType signalConnector2( typeRegistration, Toolkit::Button::SIGNAL_TOGGLED, &Button::DoConnectSignal );
52 PropertyRegistration property1( typeRegistration, "dimmed", Toolkit::Button::PROPERTY_DIMMED, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
54 } // unnamed namespace
57 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
68 void Button::SetDimmed( bool dimmed )
72 // Notifies the painter.
73 Toolkit::Button handle( GetOwner() );
76 mPainter->SetDimmed( handle, mDimmed );
80 bool Button::IsDimmed() const
85 void Button::SetAnimationTime( float animationTime )
87 OnAnimationTimeSet( animationTime );
90 float Button::GetAnimationTime() const
92 return OnAnimationTimeRequested();
95 void Button::OnAnimationTimeSet( float animationTime )
100 float Button::OnAnimationTimeRequested() const
105 Toolkit::Button::ClickedSignalV2& Button::ClickedSignal()
107 return mClickedSignalV2;
110 Toolkit::Button::ToggledSignalV2& Button::ToggledSignal()
112 return mToggledSignalV2;
115 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
117 Dali::BaseHandle handle( object );
119 bool connected( true );
120 Toolkit::Button button = Toolkit::Button::DownCast(handle);
122 if( Dali::Toolkit::Button::SIGNAL_CLICKED == signalName )
124 button.ClickedSignal().Connect( tracker, functor );
126 else if( Dali::Toolkit::Button::SIGNAL_TOGGLED == signalName )
128 button.ToggledSignal().Connect( tracker, functor );
132 // signalName does not match any signal
139 bool Button::OnTouchEvent(const TouchEvent& event)
141 // Only events are processed when the button is not dimmed and the touch event has only
143 if( ( !mDimmed ) && ( 1 == event.GetPointCount() ) )
145 switch( event.GetPoint(0).state )
147 case TouchPoint::Down:
149 OnButtonDown(); // Notification for derived classes.
151 // Sets the button state to ButtonDown.
157 OnButtonUp(); // Notification for derived classes.
159 // Sets the button state to ButtonUp.
163 case TouchPoint::Interrupted:
165 OnTouchPointInterrupted(); // Notification for derived classes.
167 // Sets the button state to the default (ButtonUp).
171 case TouchPoint::Leave:
173 OnTouchPointLeave(); // Notification for derived classes.
175 // Sets the button state to the default (ButtonUp).
179 case TouchPoint::Motion:
180 case TouchPoint::Stationary: // FALLTHROUGH
187 DALI_ASSERT_ALWAYS( !"Point status unhandled." );
192 else if( 1 < event.GetPointCount() )
194 OnTouchPointLeave(); // Notification for derived classes.
196 // Sets the button state to the default (ButtonUp).
203 void Button::OnInitialize()
205 // Initialize the painter and notifies subclasses.
206 Toolkit::Button handle( GetOwner() );
209 mPainter->Initialize( handle );
214 mTapDetector = TapGestureDetector::New();
215 mTapDetector.Attach( self );
216 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
218 OnButtonInitialize();
220 self.SetKeyboardFocusable( true );
223 void Button::OnControlSizeSet(const Vector3& targetSize)
225 Toolkit::Button handle( GetOwner() );
228 mPainter->SetSize( handle, targetSize );
232 void Button::OnTap(Actor actor, TapGesture tap)
237 void Button::OnControlStageDisconnection()
239 OnButtonStageDisconnection(); // Notification for derived classes.
243 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
245 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
247 if ( button && ( index == Toolkit::Button::PROPERTY_DIMMED ) )
249 GetImplementation( button ).SetDimmed( value.Get<bool>() );
253 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
255 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
257 if ( button && ( propertyIndex == Toolkit::Button::PROPERTY_DIMMED ) )
259 return Property::Value( GetImplementation( button ).mDimmed );
262 return Property::Value();
265 } // namespace Internal
267 } // namespace Toolkit