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=19cae29c9ebeefe7a797c76041ff742418dec2f9;hp=cfac37f676421921790938a42ef725a245149154;hb=56f99f9b480bb1ea79d9da328fac95e993bde606;hpb=dd0935960c1acaf63d2b4f560b39236b871135b7 diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index cfac37f..19cae29 100755 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -835,6 +835,16 @@ void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily ) DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str()); mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty(); + if( mImpl->mEventData ) + { + // Update the cursor position if it's in editing mode + if( EventData::IsEditingState( mImpl->mEventData->mState ) ) + { + mImpl->mEventData->mDecoratorUpdated = true; + mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font family is updated. + } + } + // Clear the font-specific data ClearFontData(); @@ -888,6 +898,16 @@ void Controller::SetDefaultFontWeight( FontWeight weight ) mImpl->mFontDefaults->mFontDescription.weight = weight; mImpl->mFontDefaults->weightDefined = true; + if( mImpl->mEventData ) + { + // Update the cursor position if it's in editing mode + if( EventData::IsEditingState( mImpl->mEventData->mState ) ) + { + mImpl->mEventData->mDecoratorUpdated = true; + mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font weight is updated. + } + } + // Clear the font-specific data ClearFontData(); @@ -959,6 +979,16 @@ void Controller::SetDefaultFontWidth( FontWidth width ) mImpl->mFontDefaults->mFontDescription.width = width; mImpl->mFontDefaults->widthDefined = true; + if( mImpl->mEventData ) + { + // Update the cursor position if it's in editing mode + if( EventData::IsEditingState( mImpl->mEventData->mState ) ) + { + mImpl->mEventData->mDecoratorUpdated = true; + mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font width is updated. + } + } + // Clear the font-specific data ClearFontData(); @@ -1030,6 +1060,16 @@ void Controller::SetDefaultFontSlant( FontSlant slant ) mImpl->mFontDefaults->mFontDescription.slant = slant; mImpl->mFontDefaults->slantDefined = true; + if( mImpl->mEventData ) + { + // Update the cursor position if it's in editing mode + if( EventData::IsEditingState( mImpl->mEventData->mState ) ) + { + mImpl->mEventData->mDecoratorUpdated = true; + mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font slant is updated. + } + } + // Clear the font-specific data ClearFontData(); @@ -1119,6 +1159,16 @@ void Controller::SetDefaultFontSize( float fontSize, FontSizeType type ) } } + if( mImpl->mEventData ) + { + // Update the cursor position if it's in editing mode + if( EventData::IsEditingState( mImpl->mEventData->mState ) ) + { + mImpl->mEventData->mDecoratorUpdated = true; + mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated. + } + } + // Clear the font-specific data ClearFontData(); @@ -1536,17 +1586,32 @@ void Controller::SetInputFontFamily( const std::string& fontFamily ) { CharacterIndex startOfSelectedText = 0u; Length lengthOfSelectedText = 0u; - FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData, - mImpl->mModel->mLogicalModel, - startOfSelectedText, - lengthOfSelectedText ); - fontDescriptionRun.familyLength = fontFamily.size(); - fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength]; - memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength ); - fontDescriptionRun.familyDefined = true; + if( EventData::SELECTING == mImpl->mEventData->mState ) + { + // Update a font description run for the selecting state. + FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData, + mImpl->mModel->mLogicalModel, + startOfSelectedText, + lengthOfSelectedText ); + + fontDescriptionRun.familyLength = fontFamily.size(); + fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength]; + memcpy( fontDescriptionRun.familyName, fontFamily.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. - // The memory allocated for the font family name is freed when the font description is removed from the logical model. + mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText; + mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText; + mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText; + } + else + { + mImpl->mTextUpdateInfo.mCharacterIndex = 0; + mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters; + mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count(); + } // Request to relayout. mImpl->mOperationsPending = static_cast( mImpl->mOperationsPending | @@ -1560,10 +1625,6 @@ void Controller::SetInputFontFamily( const std::string& fontFamily ) mImpl->mRecalculateNaturalSize = true; mImpl->RequestRelayout(); - mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText; - mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText; - mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText; - // As the font changes, recalculate the handle positions is needed. mImpl->mEventData->mUpdateLeftSelectionPosition = true; mImpl->mEventData->mUpdateRightSelectionPosition = true; @@ -1595,13 +1656,28 @@ void Controller::SetInputFontWeight( FontWeight weight ) { CharacterIndex startOfSelectedText = 0u; Length lengthOfSelectedText = 0u; - FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData, - mImpl->mModel->mLogicalModel, - startOfSelectedText, - lengthOfSelectedText ); - fontDescriptionRun.weight = weight; - fontDescriptionRun.weightDefined = true; + if( EventData::SELECTING == mImpl->mEventData->mState ) + { + // Update a font description run for the selecting state. + FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData, + mImpl->mModel->mLogicalModel, + startOfSelectedText, + lengthOfSelectedText ); + + fontDescriptionRun.weight = weight; + fontDescriptionRun.weightDefined = true; + + mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText; + mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText; + mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText; + } + else + { + mImpl->mTextUpdateInfo.mCharacterIndex = 0; + mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters; + mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count(); + } // Request to relayout. mImpl->mOperationsPending = static_cast( mImpl->mOperationsPending | @@ -1615,10 +1691,6 @@ void Controller::SetInputFontWeight( FontWeight weight ) mImpl->mRecalculateNaturalSize = true; mImpl->RequestRelayout(); - mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText; - mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText; - mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText; - // As the font might change, recalculate the handle positions is needed. mImpl->mEventData->mUpdateLeftSelectionPosition = true; mImpl->mEventData->mUpdateRightSelectionPosition = true; @@ -1661,13 +1733,28 @@ void Controller::SetInputFontWidth( FontWidth width ) { CharacterIndex startOfSelectedText = 0u; Length lengthOfSelectedText = 0u; - FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData, - mImpl->mModel->mLogicalModel, - startOfSelectedText, - lengthOfSelectedText ); - fontDescriptionRun.width = width; - fontDescriptionRun.widthDefined = true; + if( EventData::SELECTING == mImpl->mEventData->mState ) + { + // Update a font description run for the selecting state. + FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData, + mImpl->mModel->mLogicalModel, + startOfSelectedText, + lengthOfSelectedText ); + + fontDescriptionRun.width = width; + fontDescriptionRun.widthDefined = true; + + mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText; + mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText; + mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText; + } + else + { + mImpl->mTextUpdateInfo.mCharacterIndex = 0; + mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters; + mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count(); + } // Request to relayout. mImpl->mOperationsPending = static_cast( mImpl->mOperationsPending | @@ -1681,10 +1768,6 @@ void Controller::SetInputFontWidth( FontWidth width ) mImpl->mRecalculateNaturalSize = true; mImpl->RequestRelayout(); - mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText; - mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText; - mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText; - // As the font might change, recalculate the handle positions is needed. mImpl->mEventData->mUpdateLeftSelectionPosition = true; mImpl->mEventData->mUpdateRightSelectionPosition = true; @@ -1727,13 +1810,28 @@ void Controller::SetInputFontSlant( FontSlant slant ) { CharacterIndex startOfSelectedText = 0u; Length lengthOfSelectedText = 0u; - FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData, - mImpl->mModel->mLogicalModel, - startOfSelectedText, - lengthOfSelectedText ); - fontDescriptionRun.slant = slant; - fontDescriptionRun.slantDefined = true; + if( EventData::SELECTING == mImpl->mEventData->mState ) + { + // Update a font description run for the selecting state. + FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData, + mImpl->mModel->mLogicalModel, + startOfSelectedText, + lengthOfSelectedText ); + + fontDescriptionRun.slant = slant; + fontDescriptionRun.slantDefined = true; + + mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText; + mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText; + mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText; + } + else + { + mImpl->mTextUpdateInfo.mCharacterIndex = 0; + mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters; + mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count(); + } // Request to relayout. mImpl->mOperationsPending = static_cast( mImpl->mOperationsPending | @@ -1747,10 +1845,6 @@ void Controller::SetInputFontSlant( FontSlant slant ) mImpl->mRecalculateNaturalSize = true; mImpl->RequestRelayout(); - mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText; - mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText; - mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText; - // As the font might change, recalculate the handle positions is needed. mImpl->mEventData->mUpdateLeftSelectionPosition = true; mImpl->mEventData->mUpdateRightSelectionPosition = true; @@ -1793,13 +1887,28 @@ void Controller::SetInputFontPointSize( float size ) { CharacterIndex startOfSelectedText = 0u; Length lengthOfSelectedText = 0u; - FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData, - mImpl->mModel->mLogicalModel, - startOfSelectedText, - lengthOfSelectedText ); - fontDescriptionRun.size = static_cast( size * 64.f ); - fontDescriptionRun.sizeDefined = true; + if( EventData::SELECTING == mImpl->mEventData->mState ) + { + // Update a font description run for the selecting state. + FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData, + mImpl->mModel->mLogicalModel, + startOfSelectedText, + lengthOfSelectedText ); + + fontDescriptionRun.size = static_cast( size * 64.f ); + fontDescriptionRun.sizeDefined = true; + + mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText; + mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText; + mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText; + } + else + { + mImpl->mTextUpdateInfo.mCharacterIndex = 0; + mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters; + mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count(); + } // Request to relayout. mImpl->mOperationsPending = static_cast( mImpl->mOperationsPending | @@ -1813,10 +1922,6 @@ void Controller::SetInputFontPointSize( float size ) mImpl->mRecalculateNaturalSize = true; mImpl->RequestRelayout(); - mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText; - mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText; - mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText; - // As the font might change, recalculate the handle positions is needed. mImpl->mEventData->mUpdateLeftSelectionPosition = true; mImpl->mEventData->mUpdateRightSelectionPosition = true; @@ -3728,6 +3833,7 @@ bool Controller::RemoveText( int cursorOffset, if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) ) { mImpl->ClearPreEditFlag(); + mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0; } // Updates the text style runs by removing characters. Runs with no characters are removed.