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 );
51 PropertyRegistration property1( typeRegistration, "dimmed", Toolkit::Button::PROPERTY_DIMMED, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
53 } // unnamed namespace
56 : ControlImpl( true ),
67 void Button::SetDimmed( bool dimmed )
71 // Notifies the painter.
72 Toolkit::Button handle( GetOwner() );
75 mPainter->SetDimmed( handle, mDimmed );
79 bool Button::IsDimmed() const
84 void Button::SetAnimationTime( float animationTime )
86 OnAnimationTimeSet( animationTime );
89 float Button::GetAnimationTime() const
91 return OnAnimationTimeRequested();
94 void Button::OnAnimationTimeSet( float animationTime )
99 float Button::OnAnimationTimeRequested() const
104 Toolkit::Button::ClickedSignalV2& Button::ClickedSignal()
106 return mClickedSignalV2;
109 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
111 Dali::BaseHandle handle( object );
113 bool connected( true );
114 Toolkit::Button button = Toolkit::Button::DownCast(handle);
116 if( Dali::Toolkit::Button::SIGNAL_CLICKED == signalName )
118 button.ClickedSignal().Connect( tracker, functor );
122 // signalName does not match any signal
129 bool Button::OnTouchEvent(const TouchEvent& event)
131 // Only events are processed when the button is not dimmed and the touch event has only
133 if( ( !mDimmed ) && ( 1 == event.GetPointCount() ) )
135 switch( event.GetPoint(0).state )
137 case TouchPoint::Down:
139 OnButtonDown(); // Notification for derived classes.
141 // Sets the button state to ButtonDown.
147 OnButtonUp(); // Notification for derived classes.
149 // Sets the button state to ButtonUp.
153 case TouchPoint::Interrupted:
155 OnTouchPointInterrupted(); // Notification for derived classes.
157 // Sets the button state to the default (ButtonUp).
161 case TouchPoint::Leave:
163 OnTouchPointLeave(); // Notification for derived classes.
165 // Sets the button state to the default (ButtonUp).
169 case TouchPoint::Motion:
170 case TouchPoint::Stationary: // FALLTHROUGH
177 DALI_ASSERT_ALWAYS( !"Point status unhandled." );
182 else if( 1 < event.GetPointCount() )
184 OnTouchPointLeave(); // Notification for derived classes.
186 // Sets the button state to the default (ButtonUp).
193 void Button::OnInitialize()
195 // Initialize the painter and notifies subclasses.
196 Toolkit::Button handle( GetOwner() );
199 mPainter->Initialize( handle );
204 mTapDetector = TapGestureDetector::New();
205 mTapDetector.Attach( self );
206 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
208 OnButtonInitialize();
210 self.SetKeyboardFocusable( true );
213 void Button::OnControlSizeSet(const Vector3& targetSize)
215 Toolkit::Button handle( GetOwner() );
218 mPainter->SetSize( handle, targetSize );
222 void Button::OnTap(Actor actor, TapGesture tap)
227 void Button::OnStageDisconnection()
229 if( ButtonUp != mState )
231 OnTouchPointLeave(); // Notification for derived classes.
236 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
238 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
240 if ( button && ( index == Toolkit::Button::PROPERTY_DIMMED ) )
242 GetImplementation( button ).SetDimmed( value.Get<bool>() );
246 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
248 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
250 if ( button && ( propertyIndex == Toolkit::Button::PROPERTY_DIMMED ) )
252 return Property::Value( GetImplementation( button ).mDimmed );
255 return Property::Value();
258 } // namespace Internal
260 } // namespace Toolkit