-// private : Update.
-
-void Controller::InsertText( const std::string& text, Controller::InsertType type )
-{
- bool removedPrevious = false;
- bool removedSelected = false;
- bool maxLengthReached = false;
-
- DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
-
- if( NULL == mImpl->mEventData )
- {
- return;
- }
-
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
- this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
- mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
-
- // TODO: At the moment the underline runs are only for pre-edit.
- mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
-
- // Remove the previous InputMethodContext pre-edit.
- if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
- {
- removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
- mImpl->mEventData->mPreEditLength,
- DONT_UPDATE_INPUT_STYLE );
-
- mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
- mImpl->mEventData->mPreEditLength = 0u;
- }
- else
- {
- // Remove the previous Selection.
- removedSelected = RemoveSelectedText();
-
- }
-
- Vector<Character> utf32Characters;
- Length characterCount = 0u;
-
- if( !text.empty() )
- {
- // Convert text into UTF-32
- utf32Characters.Resize( text.size() );
-
- // This is a bit horrible but std::string returns a (signed) char*
- const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
-
- // Transform a text array encoded in utf8 into an array encoded in utf32.
- // It returns the actual number of characters.
- characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
- utf32Characters.Resize( characterCount );
-
- DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
- }
-
- if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
- {
- // The placeholder text is no longer needed
- if( mImpl->IsShowingPlaceholderText() )
- {
- ResetText();
- }
-
- mImpl->ChangeState( EventData::EDITING );
-
- // Handle the InputMethodContext (predicitive text) state changes
- if( COMMIT == type )
- {
- // InputMethodContext is no longer handling key-events
- mImpl->ClearPreEditFlag();
- }
- else // PRE_EDIT
- {
- if( !mImpl->mEventData->mPreEditFlag )
- {
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
-
- // Record the start of the pre-edit text
- mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
- }
-
- mImpl->mEventData->mPreEditLength = utf32Characters.Count();
- mImpl->mEventData->mPreEditFlag = true;
-
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
- }
-
- const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
-
- // Restrict new text to fit within Maximum characters setting.
- Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
- maxLengthReached = ( characterCount > maxSizeOfNewText );
-
- // The cursor position.
- CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
-
- // Update the text's style.
-
- // Updates the text style runs by adding characters.
- mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
-
- // Get the character index from the cursor index.
- const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
-
- // Retrieve the text's style for the given index.
- InputStyle style;
- mImpl->RetrieveDefaultInputStyle( style );
- mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
-
- // Whether to add a new text color run.
- const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor );
-
- // Whether to add a new font run.
- const bool addFontNameRun = style.familyName != mImpl->mEventData->mInputStyle.familyName;
- const bool addFontWeightRun = style.weight != mImpl->mEventData->mInputStyle.weight;
- const bool addFontWidthRun = style.width != mImpl->mEventData->mInputStyle.width;
- const bool addFontSlantRun = style.slant != mImpl->mEventData->mInputStyle.slant;
- const bool addFontSizeRun = style.size != mImpl->mEventData->mInputStyle.size;
-
- // Add style runs.
- if( addColorRun )
- {
- const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
- mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
-
- ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
- colorRun.color = mImpl->mEventData->mInputStyle.textColor;
- colorRun.characterRun.characterIndex = cursorIndex;
- colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
- }
-
- if( addFontNameRun ||
- addFontWeightRun ||
- addFontWidthRun ||
- addFontSlantRun ||
- addFontSizeRun )
- {
- const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
- mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
-
- FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
-
- if( addFontNameRun )
- {
- fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
- fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
- memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
- fontDescriptionRun.familyDefined = true;
-
- // The memory allocated for the font family name is freed when the font description is removed from the logical model.
- }
-
- if( addFontWeightRun )
- {
- fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
- fontDescriptionRun.weightDefined = true;
- }
-
- if( addFontWidthRun )
- {
- fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
- fontDescriptionRun.widthDefined = true;
- }
-
- if( addFontSlantRun )
- {
- fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
- fontDescriptionRun.slantDefined = true;
- }
-
- if( addFontSizeRun )
- {
- fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
- fontDescriptionRun.sizeDefined = true;
- }
-
- fontDescriptionRun.characterRun.characterIndex = cursorIndex;
- fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
- }
-
- // Insert at current cursor position.
- Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
-
- if( cursorIndex < numberOfCharactersInModel )
- {
- modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
- }
- else
- {
- modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
- }
-
- // Mark the first paragraph to be updated.
- if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
- {
- mImpl->mTextUpdateInfo.mCharacterIndex = 0;
- mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
- mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
- mImpl->mTextUpdateInfo.mClearAll = true;
- }
- else
- {
- mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
- mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
- }
-
- // Update the cursor index.
- cursorIndex += maxSizeOfNewText;
-
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Inserted %d characters, new size %d new cursor %d\n", maxSizeOfNewText, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition );
- }
-
- if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
- mImpl->IsPlaceholderAvailable() )
- {
- // Show place-holder if empty after removing the pre-edit text
- ShowPlaceholderText();
- mImpl->mEventData->mUpdateCursorPosition = true;
- mImpl->ClearPreEditFlag();
- }
- else if( removedPrevious ||
- removedSelected ||
- ( 0 != utf32Characters.Count() ) )
- {
- // Queue an inserted event
- mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
-
- mImpl->mEventData->mUpdateCursorPosition = true;
- if( removedSelected )
- {
- mImpl->mEventData->mScrollAfterDelete = true;
- }
- else
- {
- mImpl->mEventData->mScrollAfterUpdatePosition = true;
- }
- }
-
- if( maxLengthReached )
- {
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
-
- mImpl->ResetInputMethodContext();
-
- if( NULL != mImpl->mEditableControlInterface )
- {
- // Do this last since it provides callbacks into application code
- mImpl->mEditableControlInterface->MaxLengthReached();
- }
- }
-}
-
-void Controller::PasteText( const std::string& stringToPaste )
-{
- InsertText( stringToPaste, Text::Controller::COMMIT );
- mImpl->ChangeState( EventData::EDITING );
- mImpl->RequestRelayout();
-
- if( NULL != mImpl->mEditableControlInterface )
- {
- // Do this last since it provides callbacks into application code
- mImpl->mEditableControlInterface->TextChanged();
- }
-}
-
-bool Controller::RemoveText( int cursorOffset,
- int numberOfCharacters,
- UpdateInputStyleType type )
-{
- bool removed = false;
-
- if( NULL == mImpl->mEventData )
- {
- return removed;
- }
-
- DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
- this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
-
- if( !mImpl->IsShowingPlaceholderText() )
- {
- // Delete at current cursor position
- Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
- CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
-
- CharacterIndex cursorIndex = 0;
-
- // Validate the cursor position & number of characters
- if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
- {
- cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
- }
-
- if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
- {
- numberOfCharacters = currentText.Count() - cursorIndex;
- }
-
- if( mImpl->mEventData->mPreEditFlag || // If the preedit flag is enabled, it means two (or more) of them came together i.e. when two keys have been pressed at the same time.
- ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
- {
- // Mark the paragraphs to be updated.
- if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
- {
- mImpl->mTextUpdateInfo.mCharacterIndex = 0;
- mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
- mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
- mImpl->mTextUpdateInfo.mClearAll = true;
- }
- else
- {
- mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
- mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
- }
-
- // Update the input style and remove the text's style before removing the text.
-
- if( UPDATE_INPUT_STYLE == type )
- {
- // Keep a copy of the current input style.
- InputStyle currentInputStyle;
- currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
-
- // Set first the default input style.
- mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
-
- // Update the input style.
- mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
-
- // Compare if the input style has changed.
- const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
-
- if( hasInputStyleChanged )
- {
- const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
- // Queue the input style changed signal.
- mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
- }
- }
-
- // Updates the text style runs by removing characters. Runs with no characters are removed.
- mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
-
- // Remove the characters.
- Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
- Vector<Character>::Iterator last = first + numberOfCharacters;
-
- currentText.Erase( first, last );
-
- // Cursor position retreat
- oldCursorIndex = cursorIndex;
-
- mImpl->mEventData->mScrollAfterDelete = true;
-
- DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
- removed = true;
- }
- }
-
- return removed;
-}
-
-bool Controller::RemoveSelectedText()
-{
- bool textRemoved( false );
-
- if( EventData::SELECTING == mImpl->mEventData->mState )
- {
- std::string removedString;
- mImpl->RetrieveSelection( removedString, true );
-
- if( !removedString.empty() )
- {
- textRemoved = true;
- mImpl->ChangeState( EventData::EDITING );
- }
- }
-
- return textRemoved;
-}
-
-// private : Relayout.
-
-bool Controller::DoRelayout( const Size& size,
- OperationsMask operationsRequired,
- Size& layoutSize )
-{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
- bool viewUpdated( false );
-
- // Calculate the operations to be done.
- const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
-
- const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
- const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
-
- // Get the current layout size.
- layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
-
- if( NO_OPERATION != ( LAYOUT & operations ) )
- {
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
-
- // Some vectors with data needed to layout and reorder may be void
- // after the first time the text has been laid out.
- // Fill the vectors again.
-
- // Calculate the number of glyphs to layout.
- const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
- const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
- const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
- const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
-
- const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
- const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
-
- // Make sure the index is not out of bound
- if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
- requestedNumberOfCharacters > charactersToGlyph.Count() ||
- ( lastIndex >= charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
- {
- std::string currentText;
- GetText( currentText );
-
- DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
- DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
- DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
-
- return false;
- }
-
- const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
- const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
-
- if( 0u == totalNumberOfGlyphs )
- {
- if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
- {
- mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
- }
-
- // Nothing else to do if there is no glyphs.
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
- return true;
- }
-
- const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
- const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
- const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
- const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
- const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
- const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
- const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
- const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
-
- // Set the layout parameters.
- const Vector2 sizeOffset = Vector2(outlineWidth * 2.0f, outlineWidth * 2.0f); // The outline should be fit into the bounding box
- Layout::Parameters layoutParameters( size - sizeOffset,
- textBuffer,
- lineBreakInfo.Begin(),
- wordBreakInfo.Begin(),
- ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
- glyphs.Begin(),
- glyphsToCharactersMap.Begin(),
- charactersPerGlyph.Begin(),
- charactersToGlyphBuffer,
- glyphsPerCharacterBuffer,
- totalNumberOfGlyphs,
- mImpl->mModel->mHorizontalAlignment,
- mImpl->mModel->mLineWrapMode,
- outlineWidth );
-
- // Resize the vector of positions to have the same size than the vector of glyphs.
- Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
- glyphPositions.Resize( totalNumberOfGlyphs );
-
- // Whether the last character is a new paragraph character.
- mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
- layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
-
- // The initial glyph and the number of glyphs to layout.
- layoutParameters.startGlyphIndex = startGlyphIndex;
- layoutParameters.numberOfGlyphs = numberOfGlyphs;
- layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
- layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
-
- // Update the ellipsis
- bool elideTextEnabled = mImpl->mModel->mElideEnabled;
-
- if( NULL != mImpl->mEventData )
- {
- if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
- {
- elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
- }
- else if( EventData::INACTIVE != mImpl->mEventData->mState )
- {
- // Disable ellipsis when editing
- elideTextEnabled = false;
- }
-
- // Reset the scroll position in inactive state
- if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
- {
- ResetScrollPosition();
- }
- }
-
- // Update the visual model.
- Size newLayoutSize;
- viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
- glyphPositions,
- mImpl->mModel->mVisualModel->mLines,
- newLayoutSize,
- elideTextEnabled );
-
- viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
-
- if( viewUpdated )
- {
- layoutSize = newLayoutSize;
-
- if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
- {
- mImpl->mIsTextDirectionRTL = false;
- }
-
- // Reorder the lines
- if( NO_OPERATION != ( REORDER & operations ) )
- {
- Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
- Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
-
- // Check first if there are paragraphs with bidirectional info.
- if( 0u != bidirectionalInfo.Count() )
- {
- // Get the lines
- const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
-
- // Reorder the lines.
- bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
- ReorderLines( bidirectionalInfo,
- startIndex,
- requestedNumberOfCharacters,
- mImpl->mModel->mVisualModel->mLines,
- bidirectionalLineInfo );
-
- // Set the bidirectional info per line into the layout parameters.
- layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
- layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
-
- // Re-layout the text. Reorder those lines with right to left characters.
- mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
- startIndex,
- requestedNumberOfCharacters,
- glyphPositions );
-
- if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
- {
- const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
- if ( firstline )
- {
- mImpl->mIsTextDirectionRTL = firstline->direction;
- }
- }
- }
- } // REORDER
-
- // Sets the layout size.
- if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
- {
- mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
- }
- } // view updated
- }
-
- if( NO_OPERATION != ( ALIGN & operations ) )
- {
- // The laid-out lines.
- Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
-
- // Need to align with the control's size as the text may contain lines
- // starting either with left to right text or right to left.
- mImpl->mLayoutEngine.Align( size,
- startIndex,
- requestedNumberOfCharacters,
- mImpl->mModel->mHorizontalAlignment,
- lines,
- mImpl->mModel->mAlignmentOffset );
-
- viewUpdated = true;
- }
-#if defined(DEBUG_ENABLED)
- std::string currentText;
- GetText( currentText );
- DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false", currentText.c_str() );
-#endif
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
- return viewUpdated;
-}
-
-void Controller::CalculateVerticalOffset( const Size& controlSize )
-{
- Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
-
- if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
- {
- // Get the line height of the default font.
- layoutSize.height = mImpl->GetDefaultFontLineHeight();
- }
-
- switch( mImpl->mModel->mVerticalAlignment )
- {
- case VerticalAlignment::TOP:
- {
- mImpl->mModel->mScrollPosition.y = 0.f;
- break;
- }
- case VerticalAlignment::CENTER:
- {
- mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
- break;
- }
- case VerticalAlignment::BOTTOM:
- {
- mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
- break;
- }
- }
-}
-
-// private : Events.
-
-void Controller::ProcessModifyEvents()
-{
- Vector<ModifyEvent>& events = mImpl->mModifyEvents;
-
- if( 0u == events.Count() )
- {
- // Nothing to do.
- return;
- }
-
- for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
- endIt = events.End();
- it != endIt;
- ++it )
- {
- const ModifyEvent& event = *it;
-
- if( ModifyEvent::TEXT_REPLACED == event.type )
- {
- // A (single) replace event should come first, otherwise we wasted time processing NOOP events
- DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
-
- TextReplacedEvent();
- }
- else if( ModifyEvent::TEXT_INSERTED == event.type )
- {
- TextInsertedEvent();
- }
- else if( ModifyEvent::TEXT_DELETED == event.type )
- {
- // Placeholder-text cannot be deleted
- if( !mImpl->IsShowingPlaceholderText() )
- {
- TextDeletedEvent();
- }
- }
- }
-
- if( NULL != mImpl->mEventData )
- {
- // When the text is being modified, delay cursor blinking
- mImpl->mEventData->mDecorator->DelayCursorBlink();
-
- // Update selection position after modifying the text
- mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
- mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
- }
-
- // Discard temporary text
- events.Clear();
-}
-
-void Controller::TextReplacedEvent()
-{
- // The natural size needs to be re-calculated.
- mImpl->mRecalculateNaturalSize = true;
-
- // The text direction needs to be updated.
- mImpl->mUpdateTextDirection = true;
-
- // Apply modifications to the model
- mImpl->mOperationsPending = ALL_OPERATIONS;
-}
-
-void Controller::TextInsertedEvent()
-{
- DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
-
- if( NULL == mImpl->mEventData )
- {
- return;
- }
-
- mImpl->mEventData->mCheckScrollAmount = true;
-
- // The natural size needs to be re-calculated.
- mImpl->mRecalculateNaturalSize = true;
-
- // The text direction needs to be updated.
- mImpl->mUpdateTextDirection = true;
-
- // Apply modifications to the model; TODO - Optimize this
- mImpl->mOperationsPending = ALL_OPERATIONS;
-}
-
-void Controller::TextDeletedEvent()
-{
- DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
-
- if( NULL == mImpl->mEventData )
- {
- return;
- }
-
- mImpl->mEventData->mCheckScrollAmount = true;
-
- // The natural size needs to be re-calculated.
- mImpl->mRecalculateNaturalSize = true;
-
- // The text direction needs to be updated.
- mImpl->mUpdateTextDirection = true;
-
- // Apply modifications to the model; TODO - Optimize this
- mImpl->mOperationsPending = ALL_OPERATIONS;
-}
-
-void Controller::SelectEvent( float x, float y, bool selectAll )
-{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
-
- if( NULL != mImpl->mEventData )
- {
- if( selectAll )
- {
- Event event( Event::SELECT_ALL );
- mImpl->mEventData->mEventQueue.push_back( event );
- }
- else
- {
- Event event( Event::SELECT );
- event.p2.mFloat = x;
- event.p3.mFloat = y;
- mImpl->mEventData->mEventQueue.push_back( event );
- }
-
- mImpl->mEventData->mCheckScrollAmount = true;
- mImpl->mEventData->mIsLeftHandleSelected = true;
- mImpl->mEventData->mIsRightHandleSelected = true;
- mImpl->RequestRelayout();
- }
-}
-
-bool Controller::DeleteEvent( int keyCode )
-{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
-
- bool removed = false;
-
- if( NULL == mImpl->mEventData )
- {
- return removed;
- }
-
- // InputMethodContext is no longer handling key-events
- mImpl->ClearPreEditFlag();
-
- if( EventData::SELECTING == mImpl->mEventData->mState )
- {
- removed = RemoveSelectedText();
- }
- else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
- {
- // Remove the character before the current cursor position
- removed = RemoveText( -1,
- 1,
- UPDATE_INPUT_STYLE );
- }
- else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
- {
- // Remove the character after the current cursor position
- removed = RemoveText( 0,
- 1,
- UPDATE_INPUT_STYLE );
- }
-
- if( removed )
- {
- if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
- !mImpl->IsPlaceholderAvailable() )
- {
- mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
- }
- else
- {
- ShowPlaceholderText();
- }
- mImpl->mEventData->mUpdateCursorPosition = true;
- mImpl->mEventData->mScrollAfterDelete = true;
- }
-
- return removed;
-}
-
-// private : Helpers.
-
-void Controller::ResetText()
-{
- // Reset buffers.
- mImpl->mModel->mLogicalModel->mText.Clear();
-
- // We have cleared everything including the placeholder-text
- mImpl->PlaceholderCleared();
-
- mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
- mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
- mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
-
- // Clear any previous text.
- mImpl->mTextUpdateInfo.mClearAll = true;
-
- // The natural size needs to be re-calculated.
- mImpl->mRecalculateNaturalSize = true;
-
- // The text direction needs to be updated.
- mImpl->mUpdateTextDirection = true;
-
- // Apply modifications to the model
- mImpl->mOperationsPending = ALL_OPERATIONS;
-}
-
-void Controller::ShowPlaceholderText()
-{
- if( mImpl->IsPlaceholderAvailable() )
- {
- DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
-
- if( NULL == mImpl->mEventData )
- {
- return;
- }
-
- mImpl->mEventData->mIsShowingPlaceholderText = true;
-
- // Disable handles when showing place-holder text
- mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
- mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
- mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
-
- const char* text( NULL );
- size_t size( 0 );
-
- // TODO - Switch Placeholder text when changing state
- if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
- ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
- {
- text = mImpl->mEventData->mPlaceholderTextActive.c_str();
- size = mImpl->mEventData->mPlaceholderTextActive.size();
- }
- else
- {
- text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
- size = mImpl->mEventData->mPlaceholderTextInactive.size();
- }
-
- mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
- mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
-
- // Reset model for showing placeholder.
- mImpl->mModel->mLogicalModel->mText.Clear();
- mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
-
- // Convert text into UTF-32
- Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
- utf32Characters.Resize( size );
-
- // This is a bit horrible but std::string returns a (signed) char*
- const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
-
- // Transform a text array encoded in utf8 into an array encoded in utf32.
- // It returns the actual number of characters.
- const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
- utf32Characters.Resize( characterCount );
-
- // The characters to be added.
- mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
-
- // Reset the cursor position
- mImpl->mEventData->mPrimaryCursorPosition = 0;
-
- // The natural size needs to be re-calculated.
- mImpl->mRecalculateNaturalSize = true;
-
- // The text direction needs to be updated.
- mImpl->mUpdateTextDirection = true;
-
- // Apply modifications to the model
- mImpl->mOperationsPending = ALL_OPERATIONS;
-
- // Update the rest of the model during size negotiation
- mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
- }
-}
-
-void Controller::ClearFontData()
-{
- if( mImpl->mFontDefaults )
- {
- mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
- }
-
- // Set flags to update the model.
- mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
- mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
- mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
-
- mImpl->mTextUpdateInfo.mClearAll = true;
- mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
- mImpl->mRecalculateNaturalSize = true;
-
- mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
- VALIDATE_FONTS |
- SHAPE_TEXT |
- BIDI_INFO |
- GET_GLYPH_METRICS |
- LAYOUT |
- UPDATE_LAYOUT_SIZE |
- REORDER |
- ALIGN );
-}
-
-void Controller::ClearStyleData()
-{
- mImpl->mModel->mLogicalModel->mColorRuns.Clear();
- mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
-}
-
-void Controller::ResetCursorPosition( CharacterIndex cursorIndex )