X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftext-controls%2Ftext-field-impl.cpp;h=991848b450142f9b2b599f35524b2ae995db5b2b;hp=4eeab41ecbeed699ee5685fabc39b78f74532288;hb=4d45925a50b8a260f8e4e609d6309a8a0d2aada1;hpb=1c5674a11a51310ee689d6daf4e6b7d94dec607e diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index 4eeab41..991848b 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -62,7 +62,7 @@ namespace // unnamed namespace namespace { -const Scripting::StringEnum< Toolkit::Text::LayoutEngine::HorizontalAlignment > HORIZONTAL_ALIGNMENT_STRING_TABLE[] = +const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] = { { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN }, { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER }, @@ -70,7 +70,7 @@ const Scripting::StringEnum< Toolkit::Text::LayoutEngine::HorizontalAlignment > }; const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] ); -const Scripting::StringEnum< Toolkit::Text::LayoutEngine::VerticalAlignment > VERTICAL_ALIGNMENT_STRING_TABLE[] = +const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] = { { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP }, { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER }, @@ -108,7 +108,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enable-cursor-blink", DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-interval", FLOAT, CURSOR_BLINK_INTERVAL ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-duration", FLOAT, CURSOR_BLINK_DURATION ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-image", STRING, GRAB_HANDLE_IMAGE ) -DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-pressed-image", VECTOR4, GRAB_HANDLE_PRESSED_IMAGE ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-pressed-image", STRING, GRAB_HANDLE_PRESSED_IMAGE ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-threshold", FLOAT, SCROLL_THRESHOLD ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-speed", FLOAT, SCROLL_SPEED ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-left", STRING, SELECTION_HANDLE_IMAGE_LEFT ) @@ -251,11 +251,14 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr const std::string alignStr = value.Get< std::string >(); DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %f\n", impl.mController.Get(), alignStr.c_str() ); - const LayoutEngine::HorizontalAlignment alignment = Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(), - HORIZONTAL_ALIGNMENT_STRING_TABLE, - HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT ); - - impl.mController->SetHorizontalAlignment( alignment ); + LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN ); + if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(), + HORIZONTAL_ALIGNMENT_STRING_TABLE, + HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT, + alignment ) ) + { + impl.mController->SetHorizontalAlignment( alignment ); + } } break; } @@ -266,11 +269,14 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr const std::string alignStr = value.Get< std::string >(); DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %f\n", impl.mController.Get(), alignStr.c_str() ); - LayoutEngine::VerticalAlignment alignment = Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(), - VERTICAL_ALIGNMENT_STRING_TABLE, - VERTICAL_ALIGNMENT_STRING_TABLE_COUNT ); - - impl.mController->SetVerticalAlignment( alignment ); + LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM ); + if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(), + VERTICAL_ALIGNMENT_STRING_TABLE, + VERTICAL_ALIGNMENT_STRING_TABLE_COUNT, + alignment ) ) + { + impl.mController->SetVerticalAlignment( alignment ); + } } break; } @@ -341,7 +347,7 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr const Vector4 color = value.Get< Vector4 >(); DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_COLOR %f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a ); - impl.mDecorator->SetColor( PRIMARY_CURSOR, color ); + impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color ); impl.RequestTextRelayout(); } break; @@ -353,7 +359,7 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr const Vector4 color = value.Get< Vector4 >(); DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SECONDARY_CURSOR_COLOR %f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a ); - impl.mDecorator->SetColor( SECONDARY_CURSOR, color ); + impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color ); impl.RequestTextRelayout(); } break; @@ -612,9 +618,13 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde { if( impl.mController ) { - value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(), - HORIZONTAL_ALIGNMENT_STRING_TABLE, - HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT ) ); + const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(), + HORIZONTAL_ALIGNMENT_STRING_TABLE, + HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT ); + if( name ) + { + value = std::string( name ); + } } break; } @@ -622,9 +632,13 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde { if( impl.mController ) { - value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(), - VERTICAL_ALIGNMENT_STRING_TABLE, - VERTICAL_ALIGNMENT_STRING_TABLE_COUNT ) ); + const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(), + VERTICAL_ALIGNMENT_STRING_TABLE, + VERTICAL_ALIGNMENT_STRING_TABLE_COUNT ); + if( name ) + { + value = std::string( name ); + } } break; } @@ -859,16 +873,16 @@ void TextField::OnInitialize() mController = Text::Controller::New( *this ); - mDecorator = Text::Decorator::New( *this, *mController ); + mDecorator = Text::Decorator::New( *mController, + *mController ); mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX ); mController->EnableTextInput( mDecorator ); // Forward input events to controller - EnableGestureDetection(Gesture::Tap); + EnableGestureDetection( static_cast( Gesture::Tap | Gesture::Pan |Gesture::LongPress ) ); GetTapGestureDetector().SetMaximumTapsRequired( 2 ); - EnableGestureDetection(Gesture::Pan); self.TouchedSignal().Connect( this, &TextField::OnTouched ); @@ -882,6 +896,7 @@ void TextField::OnInitialize() // Fill-parent area by default self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); + self.OnStageSignal().Connect( this, &TextField::OnStageConnect ); } void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) @@ -916,36 +931,58 @@ void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container ) mRenderer = Backend::Get().NewRenderer( mRenderingBackend ); } - Actor renderableActor; - if( mRenderer ) - { - renderableActor = mRenderer->Render( mController->GetView() ); - } - + RenderText(); EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size ); + } +} - if( renderableActor != mRenderableActor ) +void TextField::RenderText() +{ + Actor renderableActor; + if( mRenderer ) + { + renderableActor = mRenderer->Render( mController->GetView(), mDepth ); + } + + if( renderableActor != mRenderableActor ) + { + UnparentAndReset( mRenderableActor ); + mRenderableActor = renderableActor; + } + + if( mRenderableActor ) + { + const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset(); + + mRenderableActor.SetPosition( offset.x, offset.y ); + + // Make sure the actor is parented correctly with/without clipping + if( mClipper ) { - UnparentAndReset( mRenderableActor ); - mRenderableActor = renderableActor; + mClipper->GetRootActor().Add( mRenderableActor ); } - - if( mRenderableActor ) + else { - const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset(); + Self().Add( mRenderableActor ); + } - mRenderableActor.SetPosition( offset.x, offset.y ); + for( std::vector::const_iterator it = mClippingDecorationActors.begin(), + endIt = mClippingDecorationActors.end(); + it != endIt; + ++it ) + { + Actor actor = *it; - // Make sure the actor is parented correctly with/without clipping if( mClipper ) { - mClipper->GetRootActor().Add( mRenderableActor ); + mClipper->GetRootActor().Add( actor ); } else { - Self().Add( mRenderableActor ); + Self().Add( actor ); } } + mClippingDecorationActors.clear(); } } @@ -968,7 +1005,14 @@ void TextField::OnKeyInputFocusGained() imfManager.SetRestoreAfterFocusLost( true ); } - mController->KeyboardFocusGainEvent(); + ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() ); + + if ( notifier ) + { + notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected ); + } + + mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last. } @@ -991,6 +1035,13 @@ void TextField::OnKeyInputFocusLost() imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent ); } + ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() ); + + if ( notifier ) + { + notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected ); + } + mController->KeyboardFocusLostEvent(); EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last. @@ -1017,6 +1068,11 @@ void TextField::OnPan( const PanGesture& gesture ) mController->PanEvent( gesture.state, gesture.displacement ); } +void TextField::OnLongPress( const LongPressGesture& gesture ) +{ + mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y ); +} + bool TextField::OnKeyEvent( const KeyEvent& event ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode ); @@ -1031,10 +1087,19 @@ bool TextField::OnKeyEvent( const KeyEvent& event ) return mController->KeyEvent( event ); } -ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent ) +void TextField::AddDecoration( Actor& actor, bool needsClipping ) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName ); - return mController->OnImfEvent( imfManager, imfEvent ); + if( actor ) + { + if( needsClipping ) + { + mClippingDecorationActors.push_back( actor ); + } + else + { + Self().Add( actor ); + } + } } void TextField::RequestTextRelayout() @@ -1048,12 +1113,30 @@ void TextField::TextChanged() mTextChangedSignal.Emit( handle ); } +void TextField::OnStageConnect( Dali::Actor actor ) +{ + if ( mHasBeenStaged ) + { + RenderText(); + } + else + { + mHasBeenStaged = true; + } +} + void TextField::MaxLengthReached() { Dali::Toolkit::TextField handle( GetOwner() ); mMaxLengthReachedSignal.Emit( handle ); } +ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent ) +{ + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName ); + return mController->OnImfEvent( imfManager, imfEvent ); +} + void TextField::EnableClipping( bool clipping, const Vector2& size ) { if( clipping ) @@ -1082,6 +1165,11 @@ void TextField::EnableClipping( bool clipping, const Vector2& size ) } } +void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard ) +{ + mController->PasteClipboardItemEvent(); +} + void TextField::KeyboardStatusChanged(bool keyboardShown) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown ); @@ -1091,6 +1179,15 @@ void TextField::KeyboardStatusChanged(bool keyboardShown) { mController->KeyboardFocusLostEvent(); } + else + { + mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained + } +} + +void TextField::OnStageConnection( int depth ) +{ + mDepth = depth; } bool TextField::OnTouched( Actor actor, const TouchEvent& event ) @@ -1101,7 +1198,9 @@ bool TextField::OnTouched( Actor actor, const TouchEvent& event ) TextField::TextField() : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ), mRenderingBackend( DEFAULT_RENDERING_BACKEND ), - mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ) + mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ), + mDepth( 0 ), + mHasBeenStaged( false ) { }