Update a font description run only in Selecting state for input font
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
index b4624dc..9a46e8b 100755 (executable)
@@ -1520,17 +1520,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 );
 
-      // The memory allocated for the font family name is freed when the font description is removed from the logical model.
+        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.
+
+        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<OperationsMask>( mImpl->mOperationsPending |
@@ -1544,10 +1559,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;
@@ -1579,13 +1590,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<OperationsMask>( mImpl->mOperationsPending |
@@ -1599,10 +1625,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;
@@ -1645,13 +1667,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<OperationsMask>( mImpl->mOperationsPending |
@@ -1665,10 +1702,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;
@@ -1711,13 +1744,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<OperationsMask>( mImpl->mOperationsPending |
@@ -1731,10 +1779,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;
@@ -1777,13 +1821,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<PointSize26Dot6>( 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<PointSize26Dot6>( 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<OperationsMask>( mImpl->mOperationsPending |
@@ -1797,10 +1856,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;