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"
37 // empty handle as we cannot create button (but type registered for clicked signal)
41 TypeRegistration typeRegistration( typeid(Toolkit::Button), typeid(Toolkit::Control), Create );
43 SignalConnectorType signalConnector1( typeRegistration, Toolkit::Button::SIGNAL_CLICKED, &Button::DoConnectSignal );
48 : ControlImpl( true ),
59 void Button::SetDimmed( bool dimmed )
63 // Notifies the painter.
64 Toolkit::Button handle( GetOwner() );
67 mPainter->SetDimmed( handle, mDimmed );
71 bool Button::IsDimmed() const
76 void Button::SetAnimationTime( float animationTime )
78 OnAnimationTimeSet( animationTime );
81 float Button::GetAnimationTime() const
83 return OnAnimationTimeRequested();
86 void Button::OnAnimationTimeSet( float animationTime )
91 float Button::OnAnimationTimeRequested() const
96 Toolkit::Button::ClickedSignalV2& Button::ClickedSignal()
98 return mClickedSignalV2;
101 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
103 Dali::BaseHandle handle( object );
105 bool connected( true );
106 Toolkit::Button button = Toolkit::Button::DownCast(handle);
108 if( Dali::Toolkit::Button::SIGNAL_CLICKED == signalName )
110 button.ClickedSignal().Connect( tracker, functor );
114 // signalName does not match any signal
121 bool Button::OnTouchEvent(const TouchEvent& event)
123 // Only events are processed when the button is not dimmed and the touch event has only
125 if( ( !mDimmed ) && ( 1 == event.GetPointCount() ) )
127 switch( event.GetPoint(0).state )
129 case TouchPoint::Down:
131 OnButtonDown(); // Notification for derived classes.
133 // Sets the button state to ButtonDown.
139 OnButtonUp(); // Notification for derived classes.
141 // Sets the button state to ButtonUp.
145 case TouchPoint::Interrupted:
147 OnTouchPointInterrupted(); // Notification for derived classes.
149 // Sets the button state to the default (ButtonUp).
153 case TouchPoint::Leave:
155 OnTouchPointLeave(); // Notification for derived classes.
157 // Sets the button state to the default (ButtonUp).
161 case TouchPoint::Motion:
162 case TouchPoint::Stationary: // FALLTHROUGH
169 DALI_ASSERT_ALWAYS( !"Point status unhandled." );
174 else if( 1 < event.GetPointCount() )
176 OnTouchPointLeave(); // Notification for derived classes.
178 // Sets the button state to the default (ButtonUp).
185 void Button::OnInitialize()
187 // Initialize the painter and notifies subclasses.
188 Toolkit::Button handle( GetOwner() );
191 mPainter->Initialize( handle );
194 mTapDetector = TapGestureDetector::New();
195 mTapDetector.Attach(Self());
196 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
198 OnButtonInitialize();
201 mPropertyDimmed = self.RegisterProperty( Dali::Toolkit::Button::PROPERTY_DIMMED, false, Property::READ_WRITE );
203 self.SetKeyboardFocusable( true );
206 void Button::OnControlSizeSet(const Vector3& targetSize)
208 Toolkit::Button handle( GetOwner() );
211 mPainter->SetSize( handle, targetSize );
215 void Button::OnPropertySet( Property::Index index, Property::Value propertyValue )
217 if( index == mPropertyDimmed )
219 SetDimmed(propertyValue.Get<bool>());
223 void Button::OnTap(Actor actor, TapGesture tap)
228 void Button::OnStageDisconnection()
230 if( ButtonUp != mState )
232 OnTouchPointLeave(); // Notification for derived classes.
237 } // namespace Internal
239 } // namespace Toolkit