X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Fpublic-api%2Fcontrols%2Fcontrol-impl.cpp;h=8355fc65f78573e2b0b8687bb8c1116f93108133;hb=refs%2Fchanges%2F28%2F38928%2F2;hp=4cea531bd0006007568426a0476c31a386bd0784;hpb=402784aceba9171e57ffca8769ca46ef8aebcd2f;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index 4cea531..8355fc6 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,12 +19,12 @@ #include // EXTERNAL INCLUDES +#include // for strcmp +#include #include #include -#include #include #include -#include #include #include #include @@ -47,9 +47,9 @@ namespace Toolkit namespace { -#if defined(DEBUG_ENABLED) -Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL"); -#endif +//#if defined(DEBUG_ENABLED) +//Integration::Log::Filter* gLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL"); +//#endif const float MAX_FLOAT_VALUE( std::numeric_limits::max() ); const Vector3 MAX_SIZE( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE ); @@ -63,15 +63,17 @@ BaseHandle Create() // Setup signals and actions using the type-registry. DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create ); -// Note: Properties are registered separately below, +// Note: Properties are registered separately below. -DALI_SIGNAL_REGISTRATION( Control, "key-event", SIGNAL_KEY_EVENT ) -DALI_SIGNAL_REGISTRATION( Control, "tapped", SIGNAL_TAPPED ) -DALI_SIGNAL_REGISTRATION( Control, "panned", SIGNAL_PANNED ) -DALI_SIGNAL_REGISTRATION( Control, "pinched", SIGNAL_PINCHED ) -DALI_SIGNAL_REGISTRATION( Control, "long-pressed", SIGNAL_LONG_PRESSED ) +DALI_SIGNAL_REGISTRATION( Toolkit, Control, "key-event", SIGNAL_KEY_EVENT ) +DALI_SIGNAL_REGISTRATION( Toolkit, Control, "key-input-focus-gained", SIGNAL_KEY_INPUT_FOCUS_GAINED ) +DALI_SIGNAL_REGISTRATION( Toolkit, Control, "key-input-focus-lost", SIGNAL_KEY_INPUT_FOCUS_LOST ) +DALI_SIGNAL_REGISTRATION( Toolkit, Control, "tapped", SIGNAL_TAPPED ) +DALI_SIGNAL_REGISTRATION( Toolkit, Control, "panned", SIGNAL_PANNED ) +DALI_SIGNAL_REGISTRATION( Toolkit, Control, "pinched", SIGNAL_PINCHED ) +DALI_SIGNAL_REGISTRATION( Toolkit, Control, "long-pressed", SIGNAL_LONG_PRESSED ) -DALI_ACTION_REGISTRATION( Control, "control-activated", ACTION_CONTROL_ACTIVATED ) +DALI_ACTION_REGISTRATION( Toolkit, Control, "control-activated", ACTION_CONTROL_ACTIVATED ) DALI_TYPE_REGISTRATION_END() @@ -96,10 +98,10 @@ struct Background /** * Creates a white coloured Mesh. */ -Mesh CreateMesh() +Vector3 CreateMesh() { Vector3 white( Color::WHITE ); - + /* MeshData meshData; // Create vertices with a white color (actual color is set by actor color) @@ -120,8 +122,24 @@ Mesh CreateMesh() meshData.SetVertices( vertices ); meshData.SetFaceIndices( faces ); meshData.SetHasColor( true ); + */ + return white; + //return Mesh::New( meshData ); +} - return Mesh::New( meshData ); +/** + * Sets all the required properties for the background actor. + * + * @param[in] actor The actor to set the properties on. + * @param[in] color The required color of the actor. + */ +void SetupBackgroundActor( Actor actor, const Vector4& color ) +{ + actor.SetColor( color ); + actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION ); + actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); + actor.SetZ( BACKGROUND_ACTOR_Z_POSITION ); + actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); } /** @@ -131,13 +149,12 @@ Mesh CreateMesh() * @param[in] constrainingIndex The property index to constrain the parent's size on. * @param[in] color The required color of the actor. */ -void SetupBackgroundActor( Actor actor, Property::Index constrainingIndex, const Vector4& color ) +void SetupBackgroundActorConstrained( Actor actor, Property::Index constrainingIndex, const Vector4& color ) { actor.SetColor( color ); actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION ); actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); actor.SetZ( BACKGROUND_ACTOR_Z_POSITION ); - actor.SetRelayoutEnabled( false ); Constraint constraint = Constraint::New( actor, constrainingIndex, @@ -168,6 +185,7 @@ public: // Construction & Destruction Impl(Control& controlImpl) : mControlImpl( controlImpl ), + mStyleName(""), mBackground( NULL ), mStartingPinchScale( NULL ), mKeyEventSignal(), @@ -177,7 +195,7 @@ public: mLongPressGestureDetector(), mCurrentSize(), mNaturalSize(), - mFlags( Control::CONTROL_BEHAVIOUR_NONE ), + mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ), mIsKeyboardNavigationSupported( false ), mIsKeyboardFocusGroup( false ), mInitialized( false ) @@ -246,6 +264,12 @@ public: switch ( index ) { + case Toolkit::Control::Property::STYLE_NAME: + { + controlImpl.SetStyleName( value.Get< std::string >() ); + break; + } + case Toolkit::Control::Property::BACKGROUND_COLOR: { controlImpl.SetBackgroundColor( value.Get< Vector4 >() ); @@ -306,6 +330,12 @@ public: switch ( index ) { + case Toolkit::Control::Property::STYLE_NAME: + { + value = controlImpl.GetStyleName(); + break; + } + case Toolkit::Control::Property::BACKGROUND_COLOR: { value = controlImpl.GetBackgroundColor(); @@ -347,9 +377,12 @@ public: // Data Control& mControlImpl; + std::string mStyleName; Background* mBackground; ///< Only create the background if we use it Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this Toolkit::Control::KeyEventSignalType mKeyEventSignal; + Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal; + Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal; // Gesture Detection PinchGestureDetector mPinchGestureDetector; @@ -360,7 +393,7 @@ public: Vector3 mCurrentSize; ///< Stores the current control's size, this is the negotiated size Vector3 mNaturalSize; ///< Stores the size set through the Actor's API. This is size the actor wants to be. Useful when reset to the initial size is needed. - ControlBehaviour mFlags :6; ///< Flags passed in from constructor. Need to increase this size when new enums are added + ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor. bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control. bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group. bool mInitialized :1; @@ -369,17 +402,19 @@ public: static PropertyRegistration PROPERTY_1; static PropertyRegistration PROPERTY_2; static PropertyRegistration PROPERTY_3; + static PropertyRegistration PROPERTY_4; }; // Properties registered without macro to use specific member variables. -PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); -PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); -PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); +PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "style-name", Toolkit::Control::Property::STYLE_NAME, Property::STRING, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); +PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "background-color", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); +PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "background-image", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); +PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "key-input-focus", Toolkit::Control::Property::KEY_INPUT_FOCUS, Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty ); Toolkit::Control Control::New() { // Create the implementation, temporarily owned on stack - IntrusivePtr controlImpl = new Control( CONTROL_BEHAVIOUR_NONE ); + IntrusivePtr controlImpl = new Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ); // Pass ownership to handle Toolkit::Control handle( *controlImpl ); @@ -402,13 +437,13 @@ Vector3 Control::GetNaturalSize() return mImpl->mNaturalSize; } -float Control::CalculateChildSize( const Dali::Actor& child, Dimension dimension ) +float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension ) { // Could be overridden in derived classes. return CalculateChildSizeBase( child, dimension ); } -bool Control::RelayoutDependentOnChildren( Dimension dimension ) +bool Control::RelayoutDependentOnChildren( Dimension::Type dimension ) { return RelayoutDependentOnChildrenBase( dimension ); } @@ -491,6 +526,23 @@ LongPressGestureDetector Control::GetLongPressGestureDetector() const return mImpl->mLongPressGestureDetector; } +void Control::SetStyleName( const std::string& styleName ) +{ + if( styleName != mImpl->mStyleName ) + { + mImpl->mStyleName = styleName; + + // Apply new style + Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get(); + GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) ); + } +} + +const std::string& Control::GetStyleName() const +{ + return mImpl->mStyleName; +} + void Control::SetBackgroundColor( const Vector4& color ) { Background& background( mImpl->GetBackground() ); @@ -500,17 +552,19 @@ void Control::SetBackgroundColor( const Vector4& color ) // Just set the actor color background.actor.SetColor( color ); } + /* else { // Create Mesh Actor MeshActor meshActor = MeshActor::New( CreateMesh() ); - SetupBackgroundActor( meshActor, Actor::Property::SCALE, color ); + SetupBackgroundActorConstrained( meshActor, Actor::Property::SCALE, color ); // Set the background actor before adding so that we do not inform deriving classes background.actor = meshActor; Self().Add( meshActor ); } + */ background.color = color; } @@ -535,12 +589,14 @@ void Control::SetBackgroundImage( Image image ) background.actor.Reset(); } + /* ImageActor imageActor = ImageActor::New( image ); SetupBackgroundActor( imageActor, Actor::Property::SIZE, background.color ); // Set the background actor before adding so that we do not inform derived classes background.actor = imageActor; Self().Add( imageActor ); + */ } void Control::ClearBackground() @@ -650,6 +706,14 @@ bool Control::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* t { controlImpl.KeyEventSignal().Connect( tracker, functor ); } + else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) ) + { + controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor ); + } + else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) ) + { + controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor ); + } else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) ) { controlImpl.EnableGestureDetection( Gesture::Tap ); @@ -684,6 +748,16 @@ Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal() return mImpl->mKeyEventSignal; } +Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal() +{ + return mImpl->mKeyInputFocusGainedSignal; +} + +Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal() +{ + return mImpl->mKeyInputFocusLostSignal; +} + bool Control::EmitKeyEventSignal( const KeyEvent& event ) { // Guard against destruction during signal emission @@ -707,7 +781,7 @@ bool Control::EmitKeyEventSignal( const KeyEvent& event ) } Control::Control( ControlBehaviour behaviourFlags ) -: CustomActorImpl( behaviourFlags & REQUIRES_TOUCH_EVENTS ), +: CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ), mImpl(new Impl(*this)) { mImpl->mFlags = behaviourFlags; @@ -718,26 +792,21 @@ void Control::Initialize() // Calling deriving classes OnInitialize(); - // Test if the no size negotiation flag is not set - if( ( mImpl->mFlags & NO_SIZE_NEGOTIATION ) == 0 ) - { - // Size negotiate disabled by default, so turn it on for this actor - Self().SetRelayoutEnabled( true ); - } - if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS ) { Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get(); // Register for style changes - styleManager.StyleChangeSignal().Connect( this, &Control::DoStyleChange ); + styleManager.StyleChangeSignal().Connect( this, &Control::OnStyleChange ); // SetTheme GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) ); } - SetRequiresHoverEvents(mImpl->mFlags & REQUIRES_HOVER_EVENTS); - SetRequiresMouseWheelEvents(mImpl->mFlags & REQUIRES_MOUSE_WHEEL_EVENTS); + if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT ) + { + SetKeyboardNavigationSupport( true ); + } mImpl->mInitialized = true; } @@ -808,13 +877,13 @@ void Control::OnActivated() { } -void Control::OnThemeChange( Toolkit::StyleManager styleManager ) -{ - GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) ); -} - -void Control::OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ) +void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change ) { + // By default the control is only interested in theme (not font) changes + if( change.themeChange ) + { + GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) ); + } } void Control::OnPinch(const PinchGesture& pinch) @@ -865,11 +934,11 @@ void Control::OnControlSizeSet( const Vector3& size ) { } -void Control::OnCalculateRelayoutSize( Dimension dimension ) +void Control::OnCalculateRelayoutSize( Dimension::Type dimension ) { } -void Control::OnLayoutNegotiated( float size, Dimension dimension ) +void Control::OnLayoutNegotiated( float size, Dimension::Type dimension ) { } @@ -881,18 +950,40 @@ void Control::OnRelayout( const Vector2& size, RelayoutContainer& container ) } } -void Control::OnSetResizePolicy( ResizePolicy policy, Dimension dimension ) +void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) { } +void Control::EmitKeyInputFocusSignal( bool focusGained ) +{ + Dali::Toolkit::Control handle( GetOwner() ); + + if ( focusGained ) + { + // signals are allocated dynamically when someone connects + if ( !mImpl->mKeyInputFocusGainedSignal.Empty() ) + { + mImpl->mKeyInputFocusGainedSignal.Emit( handle ); + } + } + else + { + // signals are allocated dynamically when someone connects + if ( !mImpl->mKeyInputFocusLostSignal.Empty() ) + { + mImpl->mKeyInputFocusLostSignal.Emit( handle ); + } + } +} + void Control::OnKeyInputFocusGained() { - // Do Nothing + EmitKeyInputFocusSignal( true ); } void Control::OnKeyInputFocusLost() { - // Do Nothing + EmitKeyInputFocusSignal( false ); } void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize) @@ -984,18 +1075,6 @@ void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* call mImpl->SignalDisconnected( slotObserver, callback ); } -void Control::DoStyleChange( Toolkit::StyleManager styleManager, StyleChange change ) -{ - if( change.themeChange ) - { - OnThemeChange( styleManager ); - } - else if( change.defaultFontChange || change.defaultFontSizeChange ) - { - OnFontChange( change.defaultFontChange, change.defaultFontSizeChange ); - } -} - } // namespace Internal } // namespace Toolkit