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
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 );
53 : ControlImpl( true ),
64 void Button::SetDimmed( bool dimmed )
68 // Notifies the painter.
69 Toolkit::Button handle( GetOwner() );
72 mPainter->SetDimmed( handle, mDimmed );
76 bool Button::IsDimmed() const
81 void Button::SetAnimationTime( float animationTime )
83 OnAnimationTimeSet( animationTime );
86 float Button::GetAnimationTime() const
88 return OnAnimationTimeRequested();
91 void Button::OnAnimationTimeSet( float animationTime )
96 float Button::OnAnimationTimeRequested() const
101 Toolkit::Button::ClickedSignalV2& Button::ClickedSignal()
103 return mClickedSignalV2;
106 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
108 Dali::BaseHandle handle( object );
110 bool connected( true );
111 Toolkit::Button button = Toolkit::Button::DownCast(handle);
113 if( Dali::Toolkit::Button::SIGNAL_CLICKED == signalName )
115 button.ClickedSignal().Connect( tracker, functor );
119 // signalName does not match any signal
126 bool Button::OnTouchEvent(const TouchEvent& event)
128 // Only events are processed when the button is not dimmed and the touch event has only
130 if( ( !mDimmed ) && ( 1 == event.GetPointCount() ) )
132 switch( event.GetPoint(0).state )
134 case TouchPoint::Down:
136 OnButtonDown(); // Notification for derived classes.
138 // Sets the button state to ButtonDown.
144 OnButtonUp(); // Notification for derived classes.
146 // Sets the button state to ButtonUp.
150 case TouchPoint::Interrupted:
152 OnTouchPointInterrupted(); // Notification for derived classes.
154 // Sets the button state to the default (ButtonUp).
158 case TouchPoint::Leave:
160 OnTouchPointLeave(); // Notification for derived classes.
162 // Sets the button state to the default (ButtonUp).
166 case TouchPoint::Motion:
167 case TouchPoint::Stationary: // FALLTHROUGH
174 DALI_ASSERT_ALWAYS( !"Point status unhandled." );
179 else if( 1 < event.GetPointCount() )
181 OnTouchPointLeave(); // Notification for derived classes.
183 // Sets the button state to the default (ButtonUp).
190 void Button::OnInitialize()
192 // Initialize the painter and notifies subclasses.
193 Toolkit::Button handle( GetOwner() );
196 mPainter->Initialize( handle );
199 mTapDetector = TapGestureDetector::New();
200 mTapDetector.Attach(Self());
201 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
203 OnButtonInitialize();
206 mPropertyDimmed = self.RegisterProperty( PROPERTY_DIMMED, false, Property::READ_WRITE );
208 self.SetKeyboardFocusable( true );
211 void Button::OnControlSizeSet(const Vector3& targetSize)
213 Toolkit::Button handle( GetOwner() );
216 mPainter->SetSize( handle, targetSize );
220 void Button::OnPropertySet( Property::Index index, Property::Value propertyValue )
222 if( index == mPropertyDimmed )
224 SetDimmed(propertyValue.Get<bool>());
228 void Button::OnTap(Actor actor, TapGesture tap)
233 void Button::OnStageDisconnection()
235 if( ButtonUp != mState )
237 OnTouchPointLeave(); // Notification for derived classes.
242 } // namespace Internal
244 } // namespace Toolkit