2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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"
23 const char* const PROPERTY_DIMMED = "dimmed";
24 } // unnamed namespace
32 const Property::Index Button::PROPERTY_DIMMED( Internal::Button::BUTTON_PROPERTY_START_INDEX );
42 // empty handle as we cannot create button (but type registered for clicked signal)
46 TypeRegistration typeRegistration( typeid(Toolkit::Button), typeid(Toolkit::Control), Create );
48 SignalConnectorType signalConnector1( typeRegistration, Toolkit::Button::SIGNAL_CLICKED, &Button::DoConnectSignal );
50 PropertyRegistration property1( typeRegistration, "dimmed", Toolkit::Button::PROPERTY_DIMMED, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
52 } // unnamed namespace
66 void Button::SetDimmed( bool dimmed )
70 // Notifies the painter.
71 Toolkit::Button handle( GetOwner() );
74 mPainter->SetDimmed( handle, mDimmed );
78 bool Button::IsDimmed() const
83 void Button::SetAnimationTime( float animationTime )
85 OnAnimationTimeSet( animationTime );
88 float Button::GetAnimationTime() const
90 return OnAnimationTimeRequested();
93 void Button::OnAnimationTimeSet( float animationTime )
98 float Button::OnAnimationTimeRequested() const
103 Toolkit::Button::ClickedSignalV2& Button::ClickedSignal()
105 return mClickedSignalV2;
108 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
110 Dali::BaseHandle handle( object );
112 bool connected( true );
113 Toolkit::Button button = Toolkit::Button::DownCast(handle);
115 if( Dali::Toolkit::Button::SIGNAL_CLICKED == signalName )
117 button.ClickedSignal().Connect( tracker, functor );
121 // signalName does not match any signal
128 bool Button::OnTouchEvent(const TouchEvent& event)
130 // Only events are processed when the button is not dimmed and the touch event has only
132 if( ( !mDimmed ) && ( 1 == event.GetPointCount() ) )
134 switch( event.GetPoint(0).state )
136 case TouchPoint::Down:
138 OnButtonDown(); // Notification for derived classes.
140 // Sets the button state to ButtonDown.
146 OnButtonUp(); // Notification for derived classes.
148 // Sets the button state to ButtonUp.
152 case TouchPoint::Interrupted:
154 OnTouchPointInterrupted(); // Notification for derived classes.
156 // Sets the button state to the default (ButtonUp).
160 case TouchPoint::Leave:
162 OnTouchPointLeave(); // Notification for derived classes.
164 // Sets the button state to the default (ButtonUp).
168 case TouchPoint::Motion:
169 case TouchPoint::Stationary: // FALLTHROUGH
176 DALI_ASSERT_ALWAYS( !"Point status unhandled." );
181 else if( 1 < event.GetPointCount() )
183 OnTouchPointLeave(); // Notification for derived classes.
185 // Sets the button state to the default (ButtonUp).
192 void Button::OnInitialize()
194 // Initialize the painter and notifies subclasses.
195 Toolkit::Button handle( GetOwner() );
198 mPainter->Initialize( handle );
203 mTapDetector = TapGestureDetector::New();
204 mTapDetector.Attach( self );
205 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
207 OnButtonInitialize();
209 self.SetKeyboardFocusable( true );
212 void Button::OnControlSizeSet(const Vector3& targetSize)
214 Toolkit::Button handle( GetOwner() );
217 mPainter->SetSize( handle, targetSize );
221 void Button::OnTap(Actor actor, TapGesture tap)
226 void Button::OnStageDisconnection()
228 if( ButtonUp != mState )
230 OnTouchPointLeave(); // Notification for derived classes.
235 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
237 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
239 if ( button && ( index == Toolkit::Button::PROPERTY_DIMMED ) )
241 GetImplementation( button ).SetDimmed( value.Get<bool>() );
245 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
247 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
249 if ( button && ( propertyIndex == Toolkit::Button::PROPERTY_DIMMED ) )
251 return Property::Value( GetImplementation( button ).mDimmed );
254 return Property::Value();
257 } // namespace Internal
259 } // namespace Toolkit