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.
19 #include "button-impl.h"
22 #include <dali/public-api/events/touch-event.h>
23 #include <dali/public-api/object/type-registry.h>
27 const char* const PROPERTY_DIMMED = "dimmed";
28 } // unnamed namespace
36 const Property::Index Button::PROPERTY_DIMMED( Internal::Button::BUTTON_PROPERTY_START_INDEX );
46 // empty handle as we cannot create button (but type registered for clicked signal)
50 TypeRegistration typeRegistration( typeid(Toolkit::Button), typeid(Toolkit::Control), Create );
52 SignalConnectorType signalConnector1( typeRegistration, Toolkit::Button::SIGNAL_CLICKED, &Button::DoConnectSignal );
53 SignalConnectorType signalConnector2( typeRegistration, Toolkit::Button::SIGNAL_TOGGLED, &Button::DoConnectSignal );
55 PropertyRegistration property1( typeRegistration, "dimmed", Toolkit::Button::PROPERTY_DIMMED, Property::BOOLEAN, &Button::SetProperty, &Button::GetProperty );
57 } // unnamed namespace
60 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
71 void Button::SetDimmed( bool dimmed )
75 // Notifies the painter.
76 Toolkit::Button handle( GetOwner() );
79 mPainter->SetDimmed( handle, mDimmed );
83 bool Button::IsDimmed() const
88 void Button::SetAnimationTime( float animationTime )
90 OnAnimationTimeSet( animationTime );
93 float Button::GetAnimationTime() const
95 return OnAnimationTimeRequested();
98 void Button::OnAnimationTimeSet( float animationTime )
103 float Button::OnAnimationTimeRequested() const
108 Toolkit::Button::ClickedSignalV2& Button::ClickedSignal()
110 return mClickedSignalV2;
113 Toolkit::Button::ToggledSignalV2& Button::ToggledSignal()
115 return mToggledSignalV2;
118 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
120 Dali::BaseHandle handle( object );
122 bool connected( true );
123 Toolkit::Button button = Toolkit::Button::DownCast(handle);
125 if( Dali::Toolkit::Button::SIGNAL_CLICKED == signalName )
127 button.ClickedSignal().Connect( tracker, functor );
129 else if( Dali::Toolkit::Button::SIGNAL_TOGGLED == signalName )
131 button.ToggledSignal().Connect( tracker, functor );
135 // signalName does not match any signal
142 bool Button::OnTouchEvent(const TouchEvent& event)
144 // Only events are processed when the button is not dimmed and the touch event has only
146 if( ( !mDimmed ) && ( 1 == event.GetPointCount() ) )
148 switch( event.GetPoint(0).state )
150 case TouchPoint::Down:
152 OnButtonDown(); // Notification for derived classes.
154 // Sets the button state to ButtonDown.
160 OnButtonUp(); // Notification for derived classes.
162 // Sets the button state to ButtonUp.
166 case TouchPoint::Interrupted:
168 OnTouchPointInterrupted(); // Notification for derived classes.
170 // Sets the button state to the default (ButtonUp).
174 case TouchPoint::Leave:
176 OnTouchPointLeave(); // Notification for derived classes.
178 // Sets the button state to the default (ButtonUp).
182 case TouchPoint::Motion:
183 case TouchPoint::Stationary: // FALLTHROUGH
190 DALI_ASSERT_ALWAYS( !"Point status unhandled." );
195 else if( 1 < event.GetPointCount() )
197 OnTouchPointLeave(); // Notification for derived classes.
199 // Sets the button state to the default (ButtonUp).
206 void Button::OnInitialize()
208 // Initialize the painter and notifies subclasses.
209 Toolkit::Button handle( GetOwner() );
212 mPainter->Initialize( handle );
217 mTapDetector = TapGestureDetector::New();
218 mTapDetector.Attach( self );
219 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
221 OnButtonInitialize();
223 self.SetKeyboardFocusable( true );
226 void Button::OnControlSizeSet(const Vector3& targetSize)
228 Toolkit::Button handle( GetOwner() );
231 mPainter->SetSize( handle, targetSize );
235 void Button::OnTap(Actor actor, const TapGesture& tap)
240 void Button::OnControlStageDisconnection()
242 OnButtonStageDisconnection(); // Notification for derived classes.
246 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
248 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
250 if ( button && ( index == Toolkit::Button::PROPERTY_DIMMED ) )
252 GetImplementation( button ).SetDimmed( value.Get<bool>() );
256 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
258 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
260 if ( button && ( propertyIndex == Toolkit::Button::PROPERTY_DIMMED ) )
262 return Property::Value( GetImplementation( button ).mDimmed );
265 return Property::Value();
268 } // namespace Internal
270 } // namespace Toolkit