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=f7958ffa40a063ca7f0d19ffabb4b644d0afc410;hp=6b1e31fabf0b4a807a5be21d826299edf7ec2aca;hb=4469fbe38e5ce460187346003a013552a9d393a5;hpb=669373aecf093fe345b679b0ebe1e8056b12af2c diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 6b1e31f..f7958ff 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -89,7 +89,6 @@ void Controller::SetText( const std::string& text ) { // If popup shown then hide it by switching to Editing state if( ( EventData::SELECTING == mImpl->mEventData->mState ) || - ( EventData::SELECTION_CHANGED == mImpl->mEventData->mState ) || ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) || ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ) { @@ -454,12 +453,12 @@ bool Controller::RemoveText( int cursorOffset, int numberOfChars ) cursorIndex = oldCursorIndex + cursorOffset; } - if( (cursorIndex + numberOfChars) > currentText.Count() ) + if( ( cursorIndex + numberOfChars ) > currentText.Count() ) { numberOfChars = currentText.Count() - cursorIndex; } - if( (cursorIndex + numberOfChars) <= currentText.Count() ) + if( ( cursorIndex + numberOfChars ) <= currentText.Count() ) { Vector::Iterator first = currentText.Begin() + cursorIndex; Vector::Iterator last = first + numberOfChars; @@ -668,7 +667,7 @@ float Controller::GetHeightForWidth( float width ) ProcessModifyEvents(); Size layoutSize; - if( width != mImpl->mVisualModel->mControlSize.width ) + if( fabsf( width - mImpl->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ) { // Operations that can be done only once until the text changes. const OperationsMask onlyOnceOperations = static_cast( CONVERT_TO_UTF32 | @@ -725,7 +724,9 @@ bool Controller::Relayout( const Size& size ) return glyphsRemoved; } - if( size != mImpl->mVisualModel->mControlSize ) + const bool newSize = ( size != mImpl->mVisualModel->mControlSize ); + + if( newSize ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mVisualModel->mControlSize.width, mImpl->mVisualModel->mControlSize.height ); @@ -751,9 +752,9 @@ bool Controller::Relayout( const Size& size ) // Do not re-do any operation until something changes. mImpl->mOperationsPending = NO_OPERATION; - // Keep the current offset and alignment as it will be used to update the decorator's positions. + // Keep the current offset and alignment as it will be used to update the decorator's positions (if the size changes). Vector2 offset; - if( mImpl->mEventData ) + if( newSize && mImpl->mEventData ) { offset = mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition; } @@ -763,11 +764,14 @@ bool Controller::Relayout( const Size& size ) if( mImpl->mEventData ) { - // If there is a nex size, the scroll position needs to be clamped. - mImpl->ClampHorizontalScroll( layoutSize ); + if( newSize ) + { + // If there is a new size, the scroll position needs to be clamped. + mImpl->ClampHorizontalScroll( layoutSize ); - // Update the decorator's positions. - mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition - offset ); + // Update the decorator's positions is needed if there is a new size. + mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition - offset ); + } // Move the cursor, grab handle etc. updated = mImpl->ProcessInputEvents() || updated; @@ -922,11 +926,8 @@ void Controller::TextDeletedEvent() REORDER ); // Queue a cursor reposition event; this must wait until after DoRelayout() - if( 0u == mImpl->mLogicalModel->mText.Count() ) - { - mImpl->mEventData->mUpdateCursorPosition = true; - } - else + mImpl->mEventData->mUpdateCursorPosition = true; + if( 0u != mImpl->mLogicalModel->mText.Count() ) { mImpl->mEventData->mScrollAfterDelete = true; } @@ -1179,8 +1180,7 @@ void Controller::CalculateTextAlignment( const Size& size ) } case LayoutEngine::HORIZONTAL_ALIGN_CENTER: { - const int intOffset = static_cast( 0.5f * ( size.width - actualSize.width ) ); // try to avoid pixel alignment. - mImpl->mAlignmentOffset.x = static_cast( intOffset ); + mImpl->mAlignmentOffset.x = floorf( 0.5f * ( size.width - actualSize.width ) ); // try to avoid pixel alignment. break; } case LayoutEngine::HORIZONTAL_ALIGN_END: @@ -1200,8 +1200,7 @@ void Controller::CalculateTextAlignment( const Size& size ) } case LayoutEngine::VERTICAL_ALIGN_CENTER: { - const int intOffset = static_cast( 0.5f * ( size.height - actualSize.height ) ); // try to avoid pixel alignment. - mImpl->mAlignmentOffset.y = static_cast( intOffset ); + mImpl->mAlignmentOffset.y = floorf( 0.5f * ( size.height - actualSize.height ) ); // try to avoid pixel alignment. break; } case LayoutEngine::VERTICAL_ALIGN_BOTTOM: @@ -1485,8 +1484,7 @@ bool Controller::RemoveSelectedText() { bool textRemoved( false ); - if ( EventData::SELECTING == mImpl->mEventData->mState || - EventData::SELECTION_CHANGED == mImpl->mEventData->mState ) + if( EventData::SELECTING == mImpl->mEventData->mState ) { std::string removedString; mImpl->RetrieveSelection( removedString, true ); @@ -1522,7 +1520,7 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y ) else if( EventData::EDITING != mImpl->mEventData->mState && EventData::EDITING_WITH_GRAB_HANDLE != mImpl->mEventData->mState ) { - if( mImpl->IsShowingPlaceholderText() && ! mImpl->IsFocusedPlaceholderAvailable() ) + if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() ) { // Hide placeholder text ResetText(); @@ -1623,14 +1621,7 @@ void Controller::SelectEvent( float x, float y, bool selectAll ) { if( mImpl->mEventData ) { - if ( mImpl->mEventData->mState == EventData::SELECTING ) - { - mImpl->ChangeState( EventData::SELECTION_CHANGED ); - } - else - { - mImpl->ChangeState( EventData::SELECTING ); - } + mImpl->ChangeState( EventData::SELECTING ); if( selectAll ) { @@ -1718,12 +1709,21 @@ void Controller::PasteText( const std::string& stringToPaste ) InsertText( stringToPaste, Text::Controller::COMMIT ); mImpl->ChangeState( EventData::EDITING ); mImpl->RequestRelayout(); + + // Do this last since it provides callbacks into application code + mImpl->mControlInterface.TextChanged(); } void Controller::PasteClipboardItemEvent() { + // Retrieve the clipboard contents first ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() ); std::string stringToPaste( notifier.GetContent() ); + + // Commit the current pre-edit text; the contents of the clipboard should be appended + mImpl->ResetImfManager(); + + // Paste PasteText( stringToPaste ); } @@ -1806,7 +1806,7 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent ) { - bool update( false ); + bool update = false; bool requestRelayout = false; std::string text; @@ -1898,8 +1898,7 @@ bool Controller::BackspaceKeyEvent() bool removed( false ); - if ( EventData::SELECTING == mImpl->mEventData->mState || - EventData::SELECTION_CHANGED == mImpl->mEventData->mState ) + if( EventData::SELECTING == mImpl->mEventData->mState ) { removed = RemoveSelectedText(); } @@ -1935,17 +1934,15 @@ void Controller::NotifyImfManager() { if( mImpl->mEventData ) { - ImfManager imfManager = ImfManager::Get(); - - if( imfManager ) + if( mImpl->mEventData->mImfManager ) { // Notifying IMF of a cursor change triggers a surrounding text request so updating it now. std::string text; GetText( text ); - imfManager.SetSurroundingText( text ); + mImpl->mEventData->mImfManager.SetSurroundingText( text ); - imfManager.SetCursorPosition( GetLogicalCursorPosition() ); - imfManager.NotifyCursorPosition(); + mImpl->mEventData->mImfManager.SetCursorPosition( GetLogicalCursorPosition() ); + mImpl->mEventData->mImfManager.NotifyCursorPosition(); } } }