X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller.cpp;h=ca02bac96fcaa685955626e931ed1964a04de8cc;hp=19cae29c9ebeefe7a797c76041ff742418dec2f9;hb=d3a888997fb0ab17fc994eed2854bcad8be32623;hpb=56f99f9b480bb1ea79d9da328fac95e993bde606 diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 19cae29..ca02bac 100755 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -53,6 +53,8 @@ const std::string EMPTY_STRING(""); const std::string KEY_C_NAME = "c"; const std::string KEY_V_NAME = "v"; const std::string KEY_X_NAME = "x"; +const std::string KEY_A_NAME = "a"; +const std::string KEY_INSERT_NAME = "Insert"; const char * const PLACEHOLDER_TEXT = "text"; const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused"; @@ -141,10 +143,12 @@ ControllerPtr Controller::New( ControlInterface* controlInterface ) } ControllerPtr Controller::New( ControlInterface* controlInterface, - EditableControlInterface* editableControlInterface ) + EditableControlInterface* editableControlInterface, + SelectableControlInterface* selectableControlInterface ) { return ControllerPtr( new Controller( controlInterface, - editableControlInterface ) ); + editableControlInterface, + selectableControlInterface ) ); } // public : Configure the text controller. @@ -2830,11 +2834,11 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) bool relayoutNeeded = false; if( ( NULL != mImpl->mEventData ) && - ( keyEvent.state == KeyEvent::Down ) ) + ( keyEvent.GetState() == KeyEvent::DOWN ) ) { - int keyCode = keyEvent.keyCode; - const std::string& keyString = keyEvent.keyPressed; - const std::string keyName = keyEvent.keyPressedName; + int keyCode = keyEvent.GetKeyCode(); + const std::string& keyString = keyEvent.GetKeyString(); + const std::string keyName = keyEvent.GetKeyName(); const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() ); @@ -2905,12 +2909,12 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) // Do nothing return false; } - else if ( keyEvent.IsCtrlModifier() ) + else if ( keyEvent.IsCtrlModifier() && !keyEvent.IsShiftModifier()) { bool consumed = false; - if (keyName == KEY_C_NAME) + if (keyName == KEY_C_NAME || keyName == KEY_INSERT_NAME) { - // Ctrl-C to copy the selected text + // Ctrl-C or Ctrl+Insert to copy the selected text TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY ); consumed = true; } @@ -2926,6 +2930,12 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent ) TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT ); consumed = true; } + else if (keyName == KEY_A_NAME) + { + // Ctrl-A to select All the text + TextPopupButtonTouched( Toolkit::TextSelectionPopup::SELECT_ALL ); + consumed = true; + } return consumed; } else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) || @@ -2965,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() ) { @@ -3091,14 +3102,14 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y ) mImpl->ResetInputMethodContext(); } -void Controller::PanEvent( Gesture::State state, const Vector2& displacement ) +void Controller::PanEvent( GestureState state, const Vector2& displacement ) { DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" ); if( NULL != mImpl->mEventData ) { Event event( Event::PAN_EVENT ); - event.p1.mInt = state; + event.p1.mInt = static_cast( state ); event.p2.mFloat = displacement.x; event.p3.mFloat = displacement.y; mImpl->mEventData->mEventQueue.push_back( event ); @@ -3107,11 +3118,11 @@ void Controller::PanEvent( Gesture::State state, const Vector2& displacement ) } } -void Controller::LongPressEvent( Gesture::State state, float x, float y ) +void Controller::LongPressEvent( GestureState state, float x, float y ) { DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" ); - if( ( state == Gesture::Started ) && + if( ( state == GestureState::STARTED ) && ( NULL != mImpl->mEventData ) ) { // The 1st long-press on inactive text-field is treated as tap @@ -3130,7 +3141,7 @@ void Controller::LongPressEvent( Gesture::State state, float x, float y ) else if( !mImpl->IsShowingRealText() ) { Event event( Event::LONG_PRESS_EVENT ); - event.p1.mInt = state; + event.p1.mInt = static_cast( state ); event.p2.mFloat = x; event.p3.mFloat = y; mImpl->mEventData->mEventQueue.push_back( event ); @@ -3142,7 +3153,7 @@ void Controller::LongPressEvent( Gesture::State state, float x, float y ) mImpl->ResetInputMethodContext(); Event event( Event::LONG_PRESS_EVENT ); - event.p1.mInt = state; + event.p1.mInt = static_cast( state ); event.p2.mFloat = x; event.p3.mFloat = y; mImpl->mEventData->mEventQueue.push_back( event ); @@ -3185,6 +3196,24 @@ void Controller::SelectEvent( float x, float y, SelectionType selectType ) } } +void Controller::SetTextSelectionRange(const uint32_t *start, const uint32_t *end) +{ + if( mImpl->mEventData ) + { + mImpl->mEventData->mCheckScrollAmount = true; + mImpl->mEventData->mIsLeftHandleSelected = true; + mImpl->mEventData->mIsRightHandleSelected = true; + mImpl->SetTextSelectionRange(start, end); + mImpl->RequestRelayout(); + KeyboardFocusGainEvent(); + } +} + +Uint32Pair Controller::GetTextSelectionRange() const +{ + return mImpl->GetTextSelectionRange(); +} + InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent ) { // Whether the text needs to be relaid-out. @@ -3340,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" ); @@ -3407,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; @@ -4150,7 +4194,7 @@ void Controller::ProcessModifyEvents() mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition; } - // Discard temporary text + // DISCARD temporary text events.Clear(); } @@ -4196,6 +4240,8 @@ void Controller::TextDeletedEvent() return; } + if (!IsEditable()) return; + mImpl->mEventData->mCheckScrollAmount = true; // The natural size needs to be re-calculated. @@ -4219,6 +4265,8 @@ bool Controller::DeleteEvent( int keyCode ) return removed; } + if (!IsEditable()) return false; + // InputMethodContext is no longer handling key-events mImpl->ClearPreEditFlag(); @@ -4440,19 +4488,21 @@ Actor Controller::CreateBackgroundActor() Controller::Controller() : mImpl( NULL ) { - mImpl = new Controller::Impl( NULL, NULL ); + mImpl = new Controller::Impl( nullptr, nullptr, nullptr ); } Controller::Controller( ControlInterface* controlInterface ) { - mImpl = new Controller::Impl( controlInterface, NULL ); + mImpl = new Controller::Impl( controlInterface, NULL, NULL ); } Controller::Controller( ControlInterface* controlInterface, - EditableControlInterface* editableControlInterface ) + EditableControlInterface* editableControlInterface, + SelectableControlInterface* selectableControlInterface ) { mImpl = new Controller::Impl( controlInterface, - editableControlInterface ); + editableControlInterface, + selectableControlInterface ); } // The copy constructor and operator are left unimplemented.