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-text-updater.cpp;h=672fd8a51390a8c19fc5bf33bac0004f5e5284b0;hp=cd3f75585256f153fc2b33f728d7750aefe902b3;hb=6864703aa51cfa5aee093145833566ddf91dd910;hpb=8ca4aa19ff1c7282e1a724d4660bf34e5a4b77fa diff --git a/dali-toolkit/internal/text/text-controller-text-updater.cpp b/dali-toolkit/internal/text/text-controller-text-updater.cpp index cd3f755..672fd8a 100644 --- a/dali-toolkit/internal/text/text-controller-text-updater.cpp +++ b/dali-toolkit/internal/text/text-controller-text-updater.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -19,8 +19,8 @@ #include // EXTERNAL INCLUDES -#include #include +#include // INTERNAL INCLUDES #include @@ -30,7 +30,6 @@ namespace { - #if defined(DEBUG_ENABLED) Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS"); #endif @@ -39,16 +38,13 @@ Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT namespace Dali { - namespace Toolkit { - namespace Text { - void Controller::TextUpdater::SetText(Controller& controller, const std::string& text) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" ); + DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::SetText\n"); Controller::Impl& impl = *controller.mImpl; @@ -65,57 +61,57 @@ void Controller::TextUpdater::SetText(Controller& controller, const std::string& EventData*& eventData = impl.mEventData; - if( nullptr != eventData ) + if(nullptr != eventData) { // If popup shown then hide it by switching to Editing state - if( ( EventData::SELECTING == eventData->mState ) || - ( EventData::EDITING_WITH_POPUP == eventData->mState ) || - ( EventData::EDITING_WITH_GRAB_HANDLE == eventData->mState ) || - ( EventData::EDITING_WITH_PASTE_POPUP == eventData->mState ) ) + if((EventData::SELECTING == eventData->mState) || + (EventData::EDITING_WITH_POPUP == eventData->mState) || + (EventData::EDITING_WITH_GRAB_HANDLE == eventData->mState) || + (EventData::EDITING_WITH_PASTE_POPUP == eventData->mState)) { - impl.ChangeState( EventData::EDITING ); + impl.ChangeState(EventData::EDITING); } } - if( !text.empty() ) + if(!text.empty()) { - ModelPtr& model = impl.mModel; + ModelPtr& model = impl.mModel; LogicalModelPtr& logicalModel = model->mLogicalModel; - model->mVisualModel->SetTextColor( impl.mTextColor ); + model->mVisualModel->SetTextColor(impl.mTextColor); - MarkupProcessData markupProcessData( logicalModel->mColorRuns, - logicalModel->mFontDescriptionRuns, - logicalModel->mEmbeddedItems ); + MarkupProcessData markupProcessData(logicalModel->mColorRuns, + logicalModel->mFontDescriptionRuns, + logicalModel->mEmbeddedItems); - Length textSize = 0u; - const uint8_t* utf8 = NULL; - if( impl.mMarkupProcessorEnabled ) + Length textSize = 0u; + const uint8_t* utf8 = NULL; + if(impl.mMarkupProcessorEnabled) { - ProcessMarkupString( text, markupProcessData ); + ProcessMarkupString(text, markupProcessData); textSize = markupProcessData.markupProcessedText.size(); // This is a bit horrible but std::string returns a (signed) char* - utf8 = reinterpret_cast( markupProcessData.markupProcessedText.c_str() ); + utf8 = reinterpret_cast(markupProcessData.markupProcessedText.c_str()); } else { textSize = text.size(); // This is a bit horrible but std::string returns a (signed) char* - utf8 = reinterpret_cast( text.c_str() ); + utf8 = reinterpret_cast(text.c_str()); } // Convert text into UTF-32 Vector& utf32Characters = logicalModel->mText; - utf32Characters.Resize( textSize ); + utf32Characters.Resize(textSize); // Transform a text array encoded in utf8 into an array encoded in utf32. // It returns the actual number of characters. - Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() ); - utf32Characters.Resize( characterCount ); + Length characterCount = Utf8ToUtf32(utf8, textSize, utf32Characters.Begin()); + utf32Characters.Resize(characterCount); - DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" ); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", &controller, textSize, logicalModel->mText.Count() ); + DALI_ASSERT_DEBUG(textSize >= characterCount && "Invalid UTF32 conversion length"); + DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", &controller, textSize, logicalModel->mText.Count()); // The characters to be added. impl.mTextUpdateInfo.mNumberOfCharactersToAdd = logicalModel->mText.Count(); @@ -124,7 +120,7 @@ void Controller::TextUpdater::SetText(Controller& controller, const std::string& lastCursorIndex = characterCount; // Update the rest of the model during size negotiation - impl.QueueModifyEvent( ModifyEvent::TEXT_REPLACED ); + impl.QueueModifyEvent(ModifyEvent::TEXT_REPLACED); // The natural size needs to be re-calculated. impl.mRecalculateNaturalSize = true; @@ -141,127 +137,125 @@ void Controller::TextUpdater::SetText(Controller& controller, const std::string& } // Resets the cursor position. - controller.ResetCursorPosition( lastCursorIndex ); + controller.ResetCursorPosition(lastCursorIndex); // Scrolls the text to make the cursor visible. controller.ResetScrollPosition(); impl.RequestRelayout(); - if( nullptr != eventData ) + if(nullptr != eventData) { // Cancel previously queued events eventData->mEventQueue.clear(); } // Do this last since it provides callbacks into application code. - if( NULL != impl.mEditableControlInterface ) + if(NULL != impl.mEditableControlInterface) { - impl.mEditableControlInterface->TextChanged(); + impl.mEditableControlInterface->TextChanged(true); } } void Controller::TextUpdater::InsertText(Controller& controller, const std::string& text, Controller::InsertType type) { - Controller::Impl& impl = *controller.mImpl; - EventData*& eventData = impl.mEventData; + Controller::Impl& impl = *controller.mImpl; + EventData*& eventData = impl.mEventData; - DALI_ASSERT_DEBUG( nullptr != eventData && "Unexpected InsertText" ) + DALI_ASSERT_DEBUG(nullptr != eventData && "Unexpected InsertText") - if( NULL == eventData ) + if(NULL == eventData) { return; } - bool removedPrevious = false; - bool removedSelected = false; + bool removedPrevious = false; + bool removedSelected = false; bool maxLengthReached = false; - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n", - &controller, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"), - eventData->mPrimaryCursorPosition, eventData->mPreEditFlag, eventData->mPreEditStartPosition, eventData->mPreEditLength ); + DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n", &controller, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"), eventData->mPrimaryCursorPosition, eventData->mPreEditFlag, eventData->mPreEditStartPosition, eventData->mPreEditLength); - ModelPtr& model = impl.mModel; + ModelPtr& model = impl.mModel; LogicalModelPtr& logicalModel = model->mLogicalModel; // TODO: At the moment the underline runs are only for pre-edit. model->mVisualModel->mUnderlineRuns.Clear(); // Remove the previous InputMethodContext pre-edit. - if( eventData->mPreEditFlag && ( 0u != eventData->mPreEditLength ) ) + if(eventData->mPreEditFlag && (0u != eventData->mPreEditLength)) { - removedPrevious = RemoveText( controller, - -static_cast( eventData->mPrimaryCursorPosition - eventData->mPreEditStartPosition ), - eventData->mPreEditLength, - DONT_UPDATE_INPUT_STYLE ); + removedPrevious = RemoveText(controller, + -static_cast(eventData->mPrimaryCursorPosition - eventData->mPreEditStartPosition), + eventData->mPreEditLength, + DONT_UPDATE_INPUT_STYLE); eventData->mPrimaryCursorPosition = eventData->mPreEditStartPosition; - eventData->mPreEditLength = 0u; + eventData->mPreEditLength = 0u; } else { // Remove the previous Selection. removedSelected = RemoveSelectedText(controller); - } Vector utf32Characters; - Length characterCount = 0u; + Length characterCount = 0u; - if( !text.empty() ) + if(!text.empty()) { // Convert text into UTF-32 - utf32Characters.Resize( text.size() ); + utf32Characters.Resize(text.size()); // This is a bit horrible but std::string returns a (signed) char* - const uint8_t* utf8 = reinterpret_cast( text.c_str() ); + const uint8_t* utf8 = reinterpret_cast(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 ); + 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() ); + 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 + if(0u != utf32Characters.Count()) // Check if Utf8ToUtf32 conversion succeeded { // The placeholder text is no longer needed - if( impl.IsShowingPlaceholderText() ) + if(impl.IsShowingPlaceholderText()) { ResetText(controller); } - impl.ChangeState( EventData::EDITING ); + impl.ChangeState(EventData::EDITING); // Handle the InputMethodContext (predicitive text) state changes - if( COMMIT == type ) + if(COMMIT == type) { // InputMethodContext is no longer handling key-events impl.ClearPreEditFlag(); } else // PRE_EDIT { - if( !eventData->mPreEditFlag ) + if(!eventData->mPreEditFlag) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" ); + DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Entered PreEdit state\n"); // Record the start of the pre-edit text eventData->mPreEditStartPosition = eventData->mPrimaryCursorPosition; } eventData->mPreEditLength = utf32Characters.Count(); - eventData->mPreEditFlag = true; + eventData->mPreEditFlag = true; - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", eventData->mPreEditStartPosition, eventData->mPreEditLength ); + DALI_LOG_INFO(gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", eventData->mPreEditStartPosition, eventData->mPreEditLength); } const Length numberOfCharactersInModel = logicalModel->mText.Count(); // Restrict new text to fit within Maximum characters setting. - Length maxSizeOfNewText = std::min( ( impl.mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount ); - maxLengthReached = ( characterCount > maxSizeOfNewText ); + Length temp_length = (impl.mMaximumNumberOfCharacters > numberOfCharactersInModel ? impl.mMaximumNumberOfCharacters - numberOfCharactersInModel : 0); + Length maxSizeOfNewText = std::min(temp_length, characterCount); + maxLengthReached = (characterCount > maxSizeOfNewText); // The cursor position. CharacterIndex& cursorIndex = eventData->mPrimaryCursorPosition; @@ -269,86 +263,86 @@ void Controller::TextUpdater::InsertText(Controller& controller, const std::stri // Update the text's style. // Updates the text style runs by adding characters. - logicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText ); + logicalModel->UpdateTextStyleRuns(cursorIndex, maxSizeOfNewText); // Get the character index from the cursor index. - const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u; + const CharacterIndex styleIndex = (cursorIndex > 0u) ? cursorIndex - 1u : 0u; // Retrieve the text's style for the given index. InputStyle style; - impl.RetrieveDefaultInputStyle( style ); - logicalModel->RetrieveStyle( styleIndex, style ); + impl.RetrieveDefaultInputStyle(style); + logicalModel->RetrieveStyle(styleIndex, style); InputStyle& inputStyle = eventData->mInputStyle; // Whether to add a new text color run. - const bool addColorRun = ( style.textColor != inputStyle.textColor ) && !inputStyle.isDefaultColor; + const bool addColorRun = (style.textColor != inputStyle.textColor) && !inputStyle.isDefaultColor; // Whether to add a new font run. - const bool addFontNameRun = ( style.familyName != inputStyle.familyName ) && inputStyle.isFamilyDefined; - const bool addFontWeightRun = ( style.weight != inputStyle.weight ) && inputStyle.isWeightDefined; - const bool addFontWidthRun = ( style.width != inputStyle.width ) && inputStyle.isWidthDefined; - const bool addFontSlantRun = ( style.slant != inputStyle.slant ) && inputStyle.isSlantDefined; - const bool addFontSizeRun = ( style.size != inputStyle.size ) && inputStyle.isSizeDefined ; + const bool addFontNameRun = (style.familyName != inputStyle.familyName) && inputStyle.isFamilyDefined; + const bool addFontWeightRun = (style.weight != inputStyle.weight) && inputStyle.isWeightDefined; + const bool addFontWidthRun = (style.width != inputStyle.width) && inputStyle.isWidthDefined; + const bool addFontSlantRun = (style.slant != inputStyle.slant) && inputStyle.isSlantDefined; + const bool addFontSizeRun = (style.size != inputStyle.size) && inputStyle.isSizeDefined; // Add style runs. - if( addColorRun ) + if(addColorRun) { const VectorBase::SizeType numberOfRuns = logicalModel->mColorRuns.Count(); - logicalModel->mColorRuns.Resize( numberOfRuns + 1u ); + logicalModel->mColorRuns.Resize(numberOfRuns + 1u); - ColorRun& colorRun = *( logicalModel->mColorRuns.Begin() + numberOfRuns ); - colorRun.color = inputStyle.textColor; - colorRun.characterRun.characterIndex = cursorIndex; + ColorRun& colorRun = *(logicalModel->mColorRuns.Begin() + numberOfRuns); + colorRun.color = inputStyle.textColor; + colorRun.characterRun.characterIndex = cursorIndex; colorRun.characterRun.numberOfCharacters = maxSizeOfNewText; } - if( addFontNameRun || - addFontWeightRun || - addFontWidthRun || - addFontSlantRun || - addFontSizeRun ) + if(addFontNameRun || + addFontWeightRun || + addFontWidthRun || + addFontSlantRun || + addFontSizeRun) { const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count(); - logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u ); + logicalModel->mFontDescriptionRuns.Resize(numberOfRuns + 1u); - FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns ); + FontDescriptionRun& fontDescriptionRun = *(logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns); - if( addFontNameRun ) + if(addFontNameRun) { fontDescriptionRun.familyLength = inputStyle.familyName.size(); - fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength]; - memcpy( fontDescriptionRun.familyName, inputStyle.familyName.c_str(), fontDescriptionRun.familyLength ); + fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength]; + memcpy(fontDescriptionRun.familyName, inputStyle.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 ) + if(addFontWeightRun) { - fontDescriptionRun.weight = inputStyle.weight; + fontDescriptionRun.weight = inputStyle.weight; fontDescriptionRun.weightDefined = true; } - if( addFontWidthRun ) + if(addFontWidthRun) { - fontDescriptionRun.width = inputStyle.width; + fontDescriptionRun.width = inputStyle.width; fontDescriptionRun.widthDefined = true; } - if( addFontSlantRun ) + if(addFontSlantRun) { - fontDescriptionRun.slant = inputStyle.slant; + fontDescriptionRun.slant = inputStyle.slant; fontDescriptionRun.slantDefined = true; } - if( addFontSizeRun ) + if(addFontSizeRun) { - fontDescriptionRun.size = static_cast( inputStyle.size * impl.mFontSizeScale * 64.f ); + fontDescriptionRun.size = static_cast(inputStyle.size * impl.mFontSizeScale * 64.f); fontDescriptionRun.sizeDefined = true; } - fontDescriptionRun.characterRun.characterIndex = cursorIndex; + fontDescriptionRun.characterRun.characterIndex = cursorIndex; fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText; } @@ -356,57 +350,57 @@ void Controller::TextUpdater::InsertText(Controller& controller, const std::stri Vector& modifyText = logicalModel->mText; auto pos = modifyText.End(); - if( cursorIndex < numberOfCharactersInModel ) + if(cursorIndex < numberOfCharactersInModel) { pos = modifyText.Begin() + cursorIndex; } unsigned int realPos = pos - modifyText.Begin(); - modifyText.Insert( pos, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText ); + modifyText.Insert(pos, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText); - if( NULL != impl.mEditableControlInterface ) + if(NULL != impl.mEditableControlInterface) { - impl.mEditableControlInterface->TextInserted( realPos, maxSizeOfNewText, text ); + impl.mEditableControlInterface->TextInserted(realPos, maxSizeOfNewText, text); } TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo; // Mark the first paragraph to be updated. - if( Layout::Engine::SINGLE_LINE_BOX == impl.mLayoutEngine.GetLayout() ) + if(Layout::Engine::SINGLE_LINE_BOX == impl.mLayoutEngine.GetLayout()) { - textUpdateInfo.mCharacterIndex = 0; + textUpdateInfo.mCharacterIndex = 0; textUpdateInfo.mNumberOfCharactersToRemove = textUpdateInfo.mPreviousNumberOfCharacters; - textUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText; - textUpdateInfo.mClearAll = true; + textUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText; + textUpdateInfo.mClearAll = true; } else { - textUpdateInfo.mCharacterIndex = std::min( cursorIndex, textUpdateInfo.mCharacterIndex ); + textUpdateInfo.mCharacterIndex = std::min(cursorIndex, textUpdateInfo.mCharacterIndex); textUpdateInfo.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, logicalModel->mText.Count(), eventData->mPrimaryCursorPosition ); + DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Inserted %d characters, new size %d new cursor %d\n", maxSizeOfNewText, logicalModel->mText.Count(), eventData->mPrimaryCursorPosition); } - if( ( 0u == logicalModel->mText.Count() ) && - impl.IsPlaceholderAvailable() ) + if((0u == logicalModel->mText.Count()) && + impl.IsPlaceholderAvailable()) { // Show place-holder if empty after removing the pre-edit text controller.ShowPlaceholderText(); eventData->mUpdateCursorPosition = true; impl.ClearPreEditFlag(); } - else if( removedPrevious || - removedSelected || - ( 0 != utf32Characters.Count() ) ) + else if(removedPrevious || + removedSelected || + (0 != utf32Characters.Count())) { // Queue an inserted event - impl.QueueModifyEvent( ModifyEvent::TEXT_INSERTED ); + impl.QueueModifyEvent(ModifyEvent::TEXT_INSERTED); eventData->mUpdateCursorPosition = true; - if( removedSelected ) + if(removedSelected) { eventData->mScrollAfterDelete = true; } @@ -416,13 +410,13 @@ void Controller::TextUpdater::InsertText(Controller& controller, const std::stri } } - if( maxLengthReached ) + if(maxLengthReached) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", logicalModel->mText.Count() ); + DALI_LOG_INFO(gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", logicalModel->mText.Count()); impl.ResetInputMethodContext(); - if( NULL != impl.mEditableControlInterface ) + if(NULL != impl.mEditableControlInterface) { // Do this last since it provides callbacks into application code impl.mEditableControlInterface->MaxLengthReached(); @@ -432,140 +426,139 @@ void Controller::TextUpdater::InsertText(Controller& controller, const std::stri void Controller::TextUpdater::PasteText(Controller& controller, const std::string& stringToPaste) { - InsertText( controller, stringToPaste, Text::Controller::COMMIT ); + InsertText(controller, stringToPaste, Text::Controller::COMMIT); Controller::Impl& impl = *controller.mImpl; - impl.ChangeState( EventData::EDITING ); + impl.ChangeState(EventData::EDITING); impl.RequestRelayout(); - if( NULL != impl.mEditableControlInterface ) + if(NULL != impl.mEditableControlInterface) { // Do this last since it provides callbacks into application code - impl.mEditableControlInterface->TextChanged(); + impl.mEditableControlInterface->TextChanged(true); } } bool Controller::TextUpdater::RemoveText( - Controller& controller, - int cursorOffset, - int numberOfCharacters, - UpdateInputStyleType type ) + Controller& controller, + int cursorOffset, + int numberOfCharacters, + UpdateInputStyleType type) { bool removed = false; - Controller::Impl& impl = *controller.mImpl; - EventData*& eventData = impl.mEventData; + Controller::Impl& impl = *controller.mImpl; + EventData*& eventData = impl.mEventData; - if( nullptr == eventData ) + if(nullptr == eventData) { return removed; } - ModelPtr& model = impl.mModel; + ModelPtr& model = impl.mModel; LogicalModelPtr& logicalModel = model->mLogicalModel; - DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n", - &controller, logicalModel->mText.Count(), eventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters ); + DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n", &controller, logicalModel->mText.Count(), eventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters); - if( !impl.IsShowingPlaceholderText() ) + if(!impl.IsShowingPlaceholderText()) { // Delete at current cursor position - Vector& currentText = logicalModel->mText; - CharacterIndex& oldCursorIndex = eventData->mPrimaryCursorPosition; + Vector& currentText = logicalModel->mText; + CharacterIndex& oldCursorIndex = eventData->mPrimaryCursorPosition; CharacterIndex cursorIndex = 0; // Validate the cursor position & number of characters - if( ( static_cast< int >( eventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 ) + if((static_cast(eventData->mPrimaryCursorPosition) + cursorOffset) >= 0) { cursorIndex = eventData->mPrimaryCursorPosition + cursorOffset; } - if( ( cursorIndex + numberOfCharacters ) > currentText.Count() ) + if((cursorIndex + numberOfCharacters) > currentText.Count()) { numberOfCharacters = currentText.Count() - cursorIndex; } TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo; - if( eventData->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 ) <= textUpdateInfo.mPreviousNumberOfCharacters ) ) + if(eventData->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) <= textUpdateInfo.mPreviousNumberOfCharacters)) { // Mark the paragraphs to be updated. - if( Layout::Engine::SINGLE_LINE_BOX == impl.mLayoutEngine.GetLayout() ) + if(Layout::Engine::SINGLE_LINE_BOX == impl.mLayoutEngine.GetLayout()) { - textUpdateInfo.mCharacterIndex = 0; + textUpdateInfo.mCharacterIndex = 0; textUpdateInfo.mNumberOfCharactersToRemove = textUpdateInfo.mPreviousNumberOfCharacters; - textUpdateInfo.mNumberOfCharactersToAdd = textUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters; - textUpdateInfo.mClearAll = true; + textUpdateInfo.mNumberOfCharactersToAdd = textUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters; + textUpdateInfo.mClearAll = true; } else { - textUpdateInfo.mCharacterIndex = std::min( cursorIndex, textUpdateInfo.mCharacterIndex ); + textUpdateInfo.mCharacterIndex = std::min(cursorIndex, textUpdateInfo.mCharacterIndex); textUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters; } // Update the input style and remove the text's style before removing the text. - if( UPDATE_INPUT_STYLE == type ) + if(UPDATE_INPUT_STYLE == type) { InputStyle& eventDataInputStyle = eventData->mInputStyle; // Keep a copy of the current input style. InputStyle currentInputStyle; - currentInputStyle.Copy( eventDataInputStyle ); + currentInputStyle.Copy(eventDataInputStyle); // Set first the default input style. - impl.RetrieveDefaultInputStyle( eventDataInputStyle ); + impl.RetrieveDefaultInputStyle(eventDataInputStyle); // Update the input style. - logicalModel->RetrieveStyle( cursorIndex, eventDataInputStyle ); + logicalModel->RetrieveStyle(cursorIndex, eventDataInputStyle); // Compare if the input style has changed. - const bool hasInputStyleChanged = !currentInputStyle.Equal( eventDataInputStyle ); + const bool hasInputStyleChanged = !currentInputStyle.Equal(eventDataInputStyle); - if( hasInputStyleChanged ) + if(hasInputStyleChanged) { - const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( eventDataInputStyle ); + const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask(eventDataInputStyle); // Queue the input style changed signal. - eventData->mInputStyleChangedQueue.PushBack( styleChangedMask ); + eventData->mInputStyleChangedQueue.PushBack(styleChangedMask); } } // If the number of current text and the number of characters to be deleted are same, // it means all texts should be removed and all Preedit variables should be initialized. - if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) ) + if((currentText.Count() - numberOfCharacters == 0) && (cursorIndex == 0)) { impl.ClearPreEditFlag(); textUpdateInfo.mNumberOfCharactersToAdd = 0; } // Updates the text style runs by removing characters. Runs with no characters are removed. - logicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters ); + logicalModel->UpdateTextStyleRuns(cursorIndex, -numberOfCharacters); // Remove the characters. Vector::Iterator first = currentText.Begin() + cursorIndex; Vector::Iterator last = first + numberOfCharacters; - if( NULL != impl.mEditableControlInterface ) + if(NULL != impl.mEditableControlInterface) { std::string utf8; - Utf32ToUtf8( first, numberOfCharacters, utf8 ); - impl.mEditableControlInterface->TextDeleted( cursorIndex, numberOfCharacters, utf8 ); + Utf32ToUtf8(first, numberOfCharacters, utf8); + impl.mEditableControlInterface->TextDeleted(cursorIndex, numberOfCharacters, utf8); } - currentText.Erase( first, last ); + currentText.Erase(first, last); // Cursor position retreat oldCursorIndex = cursorIndex; eventData->mScrollAfterDelete = true; - if( EventData::INACTIVE == eventData->mState ) + if(EventData::INACTIVE == eventData->mState) { - impl.ChangeState( EventData::EDITING ); + impl.ChangeState(EventData::EDITING); } - DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", &controller, numberOfCharacters ); + DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", &controller, numberOfCharacters); removed = true; } } @@ -575,19 +568,19 @@ bool Controller::TextUpdater::RemoveText( bool Controller::TextUpdater::RemoveSelectedText(Controller& controller) { - bool textRemoved( false ); + bool textRemoved(false); Controller::Impl& impl = *controller.mImpl; - if( EventData::SELECTING == impl.mEventData->mState ) + if(EventData::SELECTING == impl.mEventData->mState) { std::string removedString; - impl.RetrieveSelection( removedString, true ); + impl.RetrieveSelection(removedString, true); - if( !removedString.empty() ) + if(!removedString.empty()) { textRemoved = true; - impl.ChangeState( EventData::EDITING ); + impl.ChangeState(EventData::EDITING); } } @@ -596,8 +589,8 @@ bool Controller::TextUpdater::RemoveSelectedText(Controller& controller) void Controller::TextUpdater::ResetText(Controller& controller) { - Controller::Impl& impl = *controller.mImpl; - LogicalModelPtr& logicalModel = impl.mModel->mLogicalModel; + Controller::Impl& impl = *controller.mImpl; + LogicalModelPtr& logicalModel = impl.mModel->mLogicalModel; // Reset buffers. logicalModel->mText.Clear(); @@ -608,9 +601,9 @@ void Controller::TextUpdater::ResetText(Controller& controller) // We have cleared everything including the placeholder-text impl.PlaceholderCleared(); - impl.mTextUpdateInfo.mCharacterIndex = 0u; + impl.mTextUpdateInfo.mCharacterIndex = 0u; impl.mTextUpdateInfo.mNumberOfCharactersToRemove = impl.mTextUpdateInfo.mPreviousNumberOfCharacters; - impl.mTextUpdateInfo.mNumberOfCharactersToAdd = 0u; + impl.mTextUpdateInfo.mNumberOfCharactersToAdd = 0u; // Clear any previous text. impl.mTextUpdateInfo.mClearAll = true;