From d3a888997fb0ab17fc994eed2854bcad8be32623 Mon Sep 17 00:00:00 2001 From: ali198724 Date: Wed, 9 Sep 2020 21:48:01 +0300 Subject: [PATCH] Text Editing (enable) property in text controls - Add support for enable/disable editing for TextField,TextEditor - this effect keyboard, clipboard - hide primary cursors and grap on non-edit mode - hide virtual keyboard on non-editable mode Change-Id: I4991e8bdffd0988e43c86d9be1b5b734e8e681cd --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 46 +++++++++++++++++++++- .../src/dali-toolkit/utc-Dali-TextField.cpp | 45 +++++++++++++++++++++ .../controls/text-controls/text-editor-devel.h | 6 +++ .../controls/text-controls/text-field-devel.h | 7 +++- .../controls/text-controls/text-editor-impl.cpp | 33 ++++++++++++++-- .../controls/text-controls/text-editor-impl.h | 11 +++++- .../controls/text-controls/text-field-impl.cpp | 33 ++++++++++++++-- .../controls/text-controls/text-field-impl.h | 11 +++++- .../internal/text/decorator/text-decorator.cpp | 13 ++++-- .../internal/text/decorator/text-decorator.h | 9 +++++ .../internal/text/text-controller-impl.cpp | 38 +++++++++++++++--- dali-toolkit/internal/text/text-controller-impl.h | 11 ++++++ dali-toolkit/internal/text/text-controller.cpp | 20 ++++++++++ dali-toolkit/internal/text/text-controller.h | 10 +++++ .../text/text-editable-control-interface.h | 14 +++++++ 15 files changed, 289 insertions(+), 18 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 6bf3ef9..574cbf9 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -2886,4 +2886,48 @@ int UtcDaliTextEditorSelectRange(void) DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 5, TEST_LOCATION ); END_TEST; -} \ No newline at end of file +} + +int UtcDaliTextEditorEnableEditing(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorEnableEditing "); + + TextEditor textEditor = TextEditor::New(); + + application.GetScene().Add( textEditor ); + + textEditor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + textEditor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + textEditor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + application.SendNotification(); + application.Render(); + + textEditor.SetKeyInputFocus(); + textEditor.SetProperty( DevelTextEditor::Property::ENABLE_EDITING, false ); + application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), "", TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::ENABLE_EDITING ).Get(), false, TEST_LOCATION ); + + textEditor.SetKeyInputFocus(); + textEditor.SetProperty( DevelTextEditor::Property::ENABLE_EDITING, true ); + application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), "D", TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::ENABLE_EDITING ).Get(), true, TEST_LOCATION ); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 7b68239..2dd61c2 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -3005,3 +3005,48 @@ int UtcDaliTextFieldSelectRange(void) END_TEST; } + +int UtcDaliTextFieldEnableEditing(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextFieldEnableEditing "); + + TextField textField = TextField::New(); + + application.GetScene().Add( textField ); + + textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + application.SendNotification(); + application.Render(); + + textField.SetKeyInputFocus(); + textField.SetProperty( DevelTextField::Property::ENABLE_EDITING, false ); + application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get(), "", TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::ENABLE_EDITING ).Get(), false, TEST_LOCATION ); + + + textField.SetKeyInputFocus(); + textField.SetProperty( DevelTextField::Property::ENABLE_EDITING, true ); + application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get(), "D", TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::ENABLE_EDITING ).Get(), true, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h index ac2bc6d..619f91a 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h @@ -138,6 +138,12 @@ enum Type * @details Name "selectedTextEnd", type Property::INTEGER. */ SELECTED_TEXT_END, + + /** + * @brief The Editable state of control. + * @details Name "editable", type Property::BOOL. + */ + ENABLE_EDITING, }; } // namespace Property diff --git a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h index 922632b..824d83c 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h @@ -143,8 +143,13 @@ enum */ SELECTED_TEXT_END, -}; + /** + * @brief The Editable state of control. + * @details Name "editable", type Property::BOOL. + */ + ENABLE_EDITING, +}; } // namespace Property /** diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index 5fac4ba..4224df2 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -142,6 +142,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "maxLength", INTEGER, MAX_LENGTH ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectedTextStart", INTEGER, SELECTED_TEXT_START ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectedTextEnd", INTEGER, SELECTED_TEXT_END ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableEditing", BOOLEAN, ENABLE_EDITING ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) @@ -718,6 +719,13 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } break; } + case Toolkit::DevelTextEditor::Property::ENABLE_EDITING: + { + const bool editable = value.Get< bool >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_EDITING %d\n", impl.mController.Get(), editable ); + impl.SetEditable( editable ); + break; + } } // switch } // texteditor } @@ -1044,6 +1052,11 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind value = static_cast(range.second); break; } + case Toolkit::DevelTextEditor::Property::ENABLE_EDITING: + { + value = impl.IsEditable(); + break; + } } //switch } @@ -1367,7 +1380,7 @@ void TextEditor::RenderText( Text::Controller::UpdateTextType updateTextType ) void TextEditor::OnKeyInputFocusGained() { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get() ); - if ( mInputMethodContext ) + if ( mInputMethodContext && IsEditable() ) { mInputMethodContext.StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged ); @@ -1421,7 +1434,7 @@ void TextEditor::OnKeyInputFocusLost() void TextEditor::OnTap( const TapGesture& gesture ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get() ); - if ( mInputMethodContext ) + if ( mInputMethodContext && IsEditable() ) { mInputMethodContext.Activate(); } @@ -1441,7 +1454,7 @@ void TextEditor::OnPan( const PanGesture& gesture ) void TextEditor::OnLongPress( const LongPressGesture& gesture ) { - if ( mInputMethodContext ) + if ( mInputMethodContext && IsEditable() ) { mInputMethodContext.Activate(); } @@ -1776,6 +1789,20 @@ void TextEditor::ApplyScrollPosition() } } +bool TextEditor::IsEditable() const +{ + return mController->IsEditable(); +} + +void TextEditor::SetEditable( bool editable ) +{ + mController->SetEditable(editable); + if ( mInputMethodContext && !editable ) + { + mInputMethodContext.Deactivate(); + } +} + TextEditor::TextEditor() : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), mAnimationPeriod( 0.0f, 0.0f ), diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h index 236cb7f..a149a79 100755 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -203,7 +203,6 @@ private: // From Control */ void AddDecoration( Actor& actor, bool needsClipping ) override; - // From SelectableControlInterface public: /** @@ -216,6 +215,16 @@ public: */ Uint32Pair GetTextSelectionRange() const override; + /** + * @copydoc Text::EditableControlInterface::IsEditable() + */ + bool IsEditable() const override; + + /** + * @copydoc Text::EditableControlInterface::SetEditable() + */ + void SetEditable( bool editable ) override; + private: // Implementation /** 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 0c1c13c..c038d08 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -137,6 +137,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextStart", INTEGER, SELECTED_TEXT_START ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableEditing", BOOLEAN, ENABLE_EDITING ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED ) @@ -731,6 +732,13 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } + case Toolkit::DevelTextField::Property::ENABLE_EDITING: + { + const bool editable = value.Get< bool >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_EDITING %d\n", impl.mController.Get(), editable ); + impl.SetEditable( editable ); + break; + } } // switch } // textfield } @@ -1066,6 +1074,11 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde value = static_cast(range.second); break; } + case Toolkit::DevelTextField::Property::ENABLE_EDITING: + { + value = impl.IsEditable(); + break; + } } //switch } @@ -1458,7 +1471,7 @@ void TextField::RenderText( Text::Controller::UpdateTextType updateTextType ) void TextField::OnKeyInputFocusGained() { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() ); - if ( mInputMethodContext ) + if ( mInputMethodContext && IsEditable() ) { mInputMethodContext.ApplyOptions( mInputMethodOptions ); @@ -1513,7 +1526,7 @@ void TextField::OnKeyInputFocusLost() void TextField::OnTap( const TapGesture& gesture ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() ); - if ( mInputMethodContext ) + if ( mInputMethodContext && IsEditable() ) { mInputMethodContext.Activate(); } @@ -1533,7 +1546,7 @@ void TextField::OnPan( const PanGesture& gesture ) void TextField::OnLongPress( const LongPressGesture& gesture ) { - if ( mInputMethodContext ) + if ( mInputMethodContext && IsEditable() ) { mInputMethodContext.Activate(); } @@ -1573,6 +1586,20 @@ void TextField::RequestTextRelayout() RelayoutRequest(); } +bool TextField::IsEditable() const +{ + return mController->IsEditable(); +} + +void TextField::SetEditable( bool editable ) +{ + mController->SetEditable(editable); + if ( mInputMethodContext && !editable ) + { + mInputMethodContext.Deactivate(); + } +} + void TextField::TextChanged() { Dali::Toolkit::TextField handle( GetOwner() ); diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.h b/dali-toolkit/internal/controls/text-controls/text-field-impl.h index c5723bd..aa5350d 100755 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -204,7 +204,6 @@ private: // From Control */ void AddDecoration( Actor& actor, bool needsClipping ) override; - // From SelectableControlInterface public: /** @@ -217,6 +216,16 @@ public: */ Uint32Pair GetTextSelectionRange() const override; + /** + * @copydoc Text::EditableControlInterface::IsEditable() + */ + bool IsEditable() const override; + + /** + * @copydoc Text::EditableControlInterface::SetEditable() + */ + void SetEditable( bool editable ) override; + private: // Implementation /** diff --git a/dali-toolkit/internal/text/decorator/text-decorator.cpp b/dali-toolkit/internal/text/decorator/text-decorator.cpp index 2a57d4d..7016759 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.cpp +++ b/dali-toolkit/internal/text/decorator/text-decorator.cpp @@ -266,7 +266,8 @@ struct Decorator::Impl : public ConnectionTracker mHorizontalScrollingEnabled( false ), mVerticalScrollingEnabled( false ), mSmoothHandlePanEnabled( false ), - mIsHighlightBoxActive( false ) + mIsHighlightBoxActive( false ), + mHidePrimaryCursorAndGrabHandle( false ) { mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2; mHighlightShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); @@ -290,7 +291,7 @@ struct Decorator::Impl : public ConnectionTracker if( mPrimaryCursor ) { const CursorImpl& cursor = mCursor[PRIMARY_CURSOR]; - mPrimaryCursorVisible = ( ( mControlSize.width - ( cursor.position.x + mCursorWidth ) > -Math::MACHINE_EPSILON_1000 ) && + mPrimaryCursorVisible = (!mHidePrimaryCursorAndGrabHandle) && ( ( mControlSize.width - ( cursor.position.x + mCursorWidth ) > -Math::MACHINE_EPSILON_1000 ) && ( cursor.position.x > -Math::MACHINE_EPSILON_1000 ) && ( mControlSize.height - ( cursor.position.y + cursor.cursorHeight ) > -Math::MACHINE_EPSILON_1000 ) && ( cursor.position.y > -Math::MACHINE_EPSILON_1000 ) ); @@ -330,7 +331,7 @@ struct Decorator::Impl : public ConnectionTracker grabHandle.verticallyVisible = ( ( ( mControlSize.height - grabHandle.lineHeight ) - grabHandle.position.y > -Math::MACHINE_EPSILON_1000 ) && ( grabHandle.position.y > -Math::MACHINE_EPSILON_1000 ) ); - const bool isVisible = grabHandle.horizontallyVisible && grabHandle.verticallyVisible; + const bool isVisible = grabHandle.horizontallyVisible && grabHandle.verticallyVisible && (!mHidePrimaryCursorAndGrabHandle); if( isVisible ) { CreateGrabHandle(); @@ -1945,6 +1946,7 @@ struct Decorator::Impl : public ConnectionTracker bool mVerticalScrollingEnabled : 1; ///< Whether the vertical scrolling is enabled. bool mSmoothHandlePanEnabled : 1; ///< Whether to pan smoothly the handles. bool mIsHighlightBoxActive : 1; ///< Whether the highlight box is active. + bool mHidePrimaryCursorAndGrabHandle : 1; ///< Whether the primary cursor and grab are hidden always. }; DecoratorPtr Decorator::New( ControllerInterface& controller, @@ -2093,6 +2095,11 @@ int Decorator::GetCursorWidth() const return static_cast( mImpl->mCursorWidth ); } +void Decorator::SetEditable( bool editable ) +{ + mImpl->mHidePrimaryCursorAndGrabHandle = !editable; + mImpl->Relayout( mImpl->mControlSize ); +} /** Handles **/ void Decorator::SetHandleActive( HandleType handleType, bool active ) diff --git a/dali-toolkit/internal/text/decorator/text-decorator.h b/dali-toolkit/internal/text/decorator/text-decorator.h index 8d0894f..0d0b25b 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.h +++ b/dali-toolkit/internal/text/decorator/text-decorator.h @@ -579,6 +579,15 @@ public: */ void SetScrollSpeed( float speed ); + /** + * @brief Sets Editable mode decoration. + * + * If this set to false, Primary cursor and grab will always be hidden. + * + * @param[in] isEditable enable or disable Editing. + */ + void SetEditable( bool isEditable ); + /** * @brief Retrieves the scroll speed. * diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 9144ae3..bfce755 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -159,7 +159,8 @@ EventData::EventData( DecoratorPtr decorator, InputMethodContext& inputMethodCon mIsPlaceholderElideEnabled( false ), mPlaceholderEllipsisFlag( false ), mShiftSelectionFlag( true ), - mUpdateAlignment( false ) + mUpdateAlignment( false ), + mEditingEnabled( true ) { } @@ -2088,6 +2089,19 @@ Uint32Pair Controller::Impl::GetTextSelectionRange() const return range; } +bool Controller::Impl::IsEditable() const +{ + return mEventData && mEventData->mEditingEnabled; +} + +void Controller::Impl::SetEditable( bool editable ) +{ + if( mEventData) + { + mEventData->mEditingEnabled = editable; + } +} + void Controller::Impl::RetrieveSelection( std::string& selectedText, bool deleteAfterRetrieval ) { if( mEventData->mLeftSelectionPosition == mEventData->mRightSelectionPosition ) @@ -2693,15 +2707,23 @@ void Controller::Impl::SetPopupButtons() * If EDITING_WITH_POPUP : SELECT & SELECT_ALL */ + bool isEditable = IsEditable(); TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::NONE; if( EventData::SELECTING == mEventData->mState ) { - buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::CUT | TextSelectionPopup::COPY ); + buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::COPY ); + if(isEditable) + { + buttonsToShow = TextSelectionPopup::Buttons( buttonsToShow | TextSelectionPopup::CUT ); + } if( !IsClipboardEmpty() ) { - buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); + if(isEditable) + { + buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); + } buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) ); } @@ -2719,7 +2741,10 @@ void Controller::Impl::SetPopupButtons() if( !IsClipboardEmpty() ) { - buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); + if(isEditable) + { + buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); + } buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) ); } } @@ -2727,7 +2752,10 @@ void Controller::Impl::SetPopupButtons() { if ( !IsClipboardEmpty() ) { - buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); + if(isEditable) + { + buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); + } buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) ); } } diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index bb03be4..3fc33b3 100755 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -172,6 +172,7 @@ struct EventData bool mPlaceholderEllipsisFlag : 1; ///< True if the text controller sets the placeholder ellipsis. bool mShiftSelectionFlag : 1; ///< True if the text selection using Shift key is enabled. bool mUpdateAlignment : 1; ///< True if the whole text needs to be full aligned.. + bool mEditingEnabled : 1; ///< True if the editing is enabled, false otherwise. }; struct ModifyEvent @@ -637,6 +638,16 @@ struct Controller::Impl Uint32Pair GetTextSelectionRange() const; /** + * @copydoc Text::EditableControlInterface::IsEditable() + */ + bool IsEditable() const; + + /** + * @copydoc Text::EditableControlInterface::SetEditable() + */ + void SetEditable( bool editable ); + + /** * @brief Retrieves the selected text. It removes the text if the @p deleteAfterRetrieval parameter is @e true. * * @param[out] selectedText The selected text encoded in utf8. diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 9b46fe2..ca02bac 100755 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -2975,6 +2975,7 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) else { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() ); + if (!IsEditable()) return false; if( !keyString.empty() ) { @@ -3368,6 +3369,20 @@ void Controller::AddDecoration( Actor& actor, bool needsClipping ) } } +bool Controller::IsEditable() const +{ + return mImpl->IsEditable(); +} + +void Controller::SetEditable( bool editable ) +{ + mImpl->SetEditable( editable ); + if(mImpl->mEventData && mImpl->mEventData->mDecorator) + { + mImpl->mEventData->mDecorator->SetEditable( editable ); + } +} + void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y ) { DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" ); @@ -3435,6 +3450,7 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt { case Toolkit::TextSelectionPopup::CUT: { + if (!IsEditable()) return; mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text mImpl->mOperationsPending = ALL_OPERATIONS; @@ -4224,6 +4240,8 @@ void Controller::TextDeletedEvent() return; } + if (!IsEditable()) return; + mImpl->mEventData->mCheckScrollAmount = true; // The natural size needs to be re-calculated. @@ -4247,6 +4265,8 @@ bool Controller::DeleteEvent( int keyCode ) return removed; } + if (!IsEditable()) return false; + // InputMethodContext is no longer handling key-events mImpl->ClearPreEditFlag(); diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 2661270..e523dd2 100755 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -1506,6 +1506,16 @@ public: // Text-input Event Queuing. Uint32Pair GetTextSelectionRange() const; /** + * @copydoc Text::EditableControlInterface::IsEditable() + */ + virtual bool IsEditable() const; + + /** + * @copydoc Text::EditableControlInterface::SetEditable() + */ + virtual void SetEditable( bool editable ); + + /** * @brief Event received from input method context * * @param[in] inputMethodContext The input method context. diff --git a/dali-toolkit/internal/text/text-editable-control-interface.h b/dali-toolkit/internal/text/text-editable-control-interface.h index e54704c..abfbb59 100644 --- a/dali-toolkit/internal/text/text-editable-control-interface.h +++ b/dali-toolkit/internal/text/text-editable-control-interface.h @@ -69,6 +69,20 @@ public: * @param[in] needsClipping Whether the actor needs clipping. */ virtual void AddDecoration( Actor& actor, bool needsClipping ) = 0; + + /** + * @brief Editable status (on/off). + * + * @return true if it can be edit, else false. + */ + virtual bool IsEditable() const = 0; + + /** + * @brief Change the editable status (on/off) . + * + * @param[in] editable The editable status. + */ + virtual void SetEditable( bool editable ) = 0; }; } // namespace Text -- 2.7.4