Fixed clipboard disappearing issue on selection
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller-impl.cpp
index 95266cd..e77f00d 100644 (file)
@@ -300,17 +300,17 @@ void Controller::Impl::CalculateTextUpdateIndices( Length& numberOfCharacters )
   }
   else
   {
-    CharacterIndex lastIndex = 0u;
+    Length numberOfCharactersToUpdate = 0u;
     if( mTextUpdateInfo.mFullRelayoutNeeded )
     {
-      lastIndex = mTextUpdateInfo.mPreviousNumberOfCharacters;
+      numberOfCharactersToUpdate = mTextUpdateInfo.mPreviousNumberOfCharacters;
     }
     else
     {
-      lastIndex = ( mTextUpdateInfo.mNumberOfCharactersToRemove > 0u ) ? mTextUpdateInfo.mNumberOfCharactersToRemove : 1u;
+      numberOfCharactersToUpdate = ( mTextUpdateInfo.mNumberOfCharactersToRemove > 0u ) ? mTextUpdateInfo.mNumberOfCharactersToRemove : 1u;
     }
     mLogicalModel->FindParagraphs( mTextUpdateInfo.mCharacterIndex,
-                                   lastIndex,
+                                   numberOfCharactersToUpdate,
                                    paragraphsToBeUpdated );
   }
 
@@ -345,36 +345,36 @@ void Controller::Impl::CalculateTextUpdateIndices( Length& numberOfCharacters )
 
 void Controller::Impl::ClearFullModelData( OperationsMask operations )
 {
-  if( GET_LINE_BREAKS & operations )
+  if( NO_OPERATION != ( GET_LINE_BREAKS & operations ) )
   {
     mLogicalModel->mLineBreakInfo.Clear();
     mLogicalModel->mParagraphInfo.Clear();
   }
 
-  if( GET_WORD_BREAKS & operations )
+  if( NO_OPERATION != ( GET_WORD_BREAKS & operations ) )
   {
     mLogicalModel->mLineBreakInfo.Clear();
   }
 
-  if( GET_SCRIPTS & operations )
+  if( NO_OPERATION != ( GET_SCRIPTS & operations ) )
   {
     mLogicalModel->mScriptRuns.Clear();
   }
 
-  if( VALIDATE_FONTS & operations )
+  if( NO_OPERATION != ( VALIDATE_FONTS & operations ) )
   {
     mLogicalModel->mFontRuns.Clear();
   }
 
   if( 0u != mLogicalModel->mBidirectionalParagraphInfo.Count() )
   {
-    if( BIDI_INFO & operations )
+    if( NO_OPERATION != ( BIDI_INFO & operations ) )
     {
       mLogicalModel->mBidirectionalParagraphInfo.Clear();
       mLogicalModel->mCharacterDirections.Clear();
     }
 
-    if( REORDER & operations )
+    if( NO_OPERATION != ( REORDER & operations ) )
     {
       // Free the allocated memory used to store the conversion table in the bidirectional line info run.
       for( Vector<BidirectionalLineInfoRun>::Iterator it = mLogicalModel->mBidirectionalLineInfo.Begin(),
@@ -388,13 +388,10 @@ void Controller::Impl::ClearFullModelData( OperationsMask operations )
         bidiLineInfo.visualToLogicalMap = NULL;
       }
       mLogicalModel->mBidirectionalLineInfo.Clear();
-
-      mLogicalModel->mLogicalToVisualMap.Clear();
-      mLogicalModel->mVisualToLogicalMap.Clear();
     }
   }
 
-  if( SHAPE_TEXT & operations )
+  if( NO_OPERATION != ( SHAPE_TEXT & operations ) )
   {
     mVisualModel->mGlyphs.Clear();
     mVisualModel->mGlyphsToCharacters.Clear();
@@ -404,12 +401,12 @@ void Controller::Impl::ClearFullModelData( OperationsMask operations )
     mVisualModel->mGlyphPositions.Clear();
   }
 
-  if( LAYOUT & operations )
+  if( NO_OPERATION != ( LAYOUT & operations ) )
   {
     mVisualModel->mLines.Clear();
   }
 
-  if( COLOR & operations )
+  if( NO_OPERATION != ( COLOR & operations ) )
   {
     mVisualModel->mColorIndices.Clear();
   }
@@ -419,7 +416,7 @@ void Controller::Impl::ClearCharacterModelData( CharacterIndex startIndex, Chara
 {
   const CharacterIndex endIndexPlusOne = endIndex + 1u;
 
-  if( GET_LINE_BREAKS & operations )
+  if( NO_OPERATION != ( GET_LINE_BREAKS & operations ) )
   {
     // Clear the line break info.
     LineBreakInfo* lineBreakInfoBuffer = mLogicalModel->mLineBreakInfo.Begin();
@@ -433,7 +430,7 @@ void Controller::Impl::ClearCharacterModelData( CharacterIndex startIndex, Chara
                         mLogicalModel->mParagraphInfo );
   }
 
-  if( GET_WORD_BREAKS & operations )
+  if( NO_OPERATION != ( GET_WORD_BREAKS & operations ) )
   {
     // Clear the word break info.
     WordBreakInfo* wordBreakInfoBuffer = mLogicalModel->mWordBreakInfo.Begin();
@@ -442,7 +439,7 @@ void Controller::Impl::ClearCharacterModelData( CharacterIndex startIndex, Chara
                                          wordBreakInfoBuffer + endIndexPlusOne );
   }
 
-  if( GET_SCRIPTS & operations )
+  if( NO_OPERATION != ( GET_SCRIPTS & operations ) )
   {
     // Clear the scripts.
     ClearCharacterRuns( startIndex,
@@ -450,7 +447,7 @@ void Controller::Impl::ClearCharacterModelData( CharacterIndex startIndex, Chara
                         mLogicalModel->mScriptRuns );
   }
 
-  if( VALIDATE_FONTS & operations )
+  if( NO_OPERATION != ( VALIDATE_FONTS & operations ) )
   {
     // Clear the fonts.
     ClearCharacterRuns( startIndex,
@@ -460,7 +457,7 @@ void Controller::Impl::ClearCharacterModelData( CharacterIndex startIndex, Chara
 
   if( 0u != mLogicalModel->mBidirectionalParagraphInfo.Count() )
   {
-    if( BIDI_INFO & operations )
+    if( NO_OPERATION != ( BIDI_INFO & operations ) )
     {
       // Clear the bidirectional paragraph info.
       ClearCharacterRuns( startIndex,
@@ -474,7 +471,7 @@ void Controller::Impl::ClearCharacterModelData( CharacterIndex startIndex, Chara
                                                  characterDirectionsBuffer + endIndexPlusOne );
     }
 
-    if( REORDER & operations )
+    if( NO_OPERATION != ( REORDER & operations ) )
     {
       uint32_t startRemoveIndex = mLogicalModel->mBidirectionalLineInfo.Count();
       uint32_t endRemoveIndex = startRemoveIndex;
@@ -500,15 +497,6 @@ void Controller::Impl::ClearCharacterModelData( CharacterIndex startIndex, Chara
 
       mLogicalModel->mBidirectionalLineInfo.Erase( bidirectionalLineInfoBuffer + startRemoveIndex,
                                                    bidirectionalLineInfoBuffer + endRemoveIndex );
-
-      // Clear the logical to visual and the visual to logical conversion tables.
-      CharacterIndex* logicalToVisualMapBuffer = mLogicalModel->mLogicalToVisualMap.Begin();
-      mLogicalModel->mLogicalToVisualMap.Erase( logicalToVisualMapBuffer + startIndex,
-                                                logicalToVisualMapBuffer + endIndexPlusOne );
-
-      CharacterIndex* visualToLogicalMapBuffer = mLogicalModel->mVisualToLogicalMap.Begin();
-      mLogicalModel->mVisualToLogicalMap.Erase( visualToLogicalMapBuffer + startIndex,
-                                                visualToLogicalMapBuffer + endIndexPlusOne );
     }
   }
 }
@@ -525,7 +513,7 @@ void Controller::Impl::ClearGlyphModelData( CharacterIndex startIndex, Character
   const GlyphIndex endGlyphIndexPlusOne = *( charactersToGlyphBuffer + endIndex ) + *( glyphsPerCharacterBuffer + endIndex );
   const Length numberOfGlyphsRemoved = endGlyphIndexPlusOne - mTextUpdateInfo.mStartGlyphIndex;
 
-  if( SHAPE_TEXT & operations )
+  if( NO_OPERATION != ( SHAPE_TEXT & operations ) )
   {
     // Update the character to glyph indices.
     for( Vector<GlyphIndex>::Iterator it =  charactersToGlyphBuffer + endIndexPlusOne,
@@ -577,7 +565,7 @@ void Controller::Impl::ClearGlyphModelData( CharacterIndex startIndex, Character
                                          positionsBuffer + endGlyphIndexPlusOne );
   }
 
-  if( LAYOUT & operations )
+  if( NO_OPERATION != ( LAYOUT & operations ) )
   {
     // Clear the lines.
     uint32_t startRemoveIndex = mVisualModel->mLines.Count();
@@ -605,7 +593,7 @@ void Controller::Impl::ClearGlyphModelData( CharacterIndex startIndex, Character
                                 linesBuffer + endRemoveIndex );
   }
 
-  if( COLOR & operations )
+  if( NO_OPERATION != ( COLOR & operations ) )
   {
     if( 0u != mVisualModel->mColorIndices.Count() )
     {
@@ -667,7 +655,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
   if( mTextUpdateInfo.mClearAll ||
       ( 0u != paragraphCharacters ) )
   {
-    ClearModelData( startIndex, startIndex + ( ( paragraphCharacters > 0u ) ? paragraphCharacters - 1u : 0u ), operationsRequired );
+    ClearModelData( startIndex, startIndex + ( ( paragraphCharacters > 0u ) ? paragraphCharacters - 1u : 0u ), operations );
   }
 
   mTextUpdateInfo.mClearAll = false;
@@ -678,7 +666,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
   Vector<LineBreakInfo>& lineBreakInfo = mLogicalModel->mLineBreakInfo;
   const Length requestedNumberOfCharacters = mTextUpdateInfo.mRequestedNumberOfCharacters;
 
-  if( GET_LINE_BREAKS & operations )
+  if( NO_OPERATION != ( GET_LINE_BREAKS & operations ) )
   {
     // Retrieves the line break info. The line break info is used to split the text in 'paragraphs' to
     // calculate the bidirectional info for each 'paragraph'.
@@ -698,7 +686,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
   }
 
   Vector<WordBreakInfo>& wordBreakInfo = mLogicalModel->mWordBreakInfo;
-  if( GET_WORD_BREAKS & operations )
+  if( NO_OPERATION != ( GET_WORD_BREAKS & operations ) )
   {
     // Retrieves the word break info. The word break info is used to layout the text (where to wrap the text in lines).
     wordBreakInfo.Resize( numberOfCharacters, TextAbstraction::WORD_NO_BREAK );
@@ -710,8 +698,8 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
     updated = true;
   }
 
-  const bool getScripts = GET_SCRIPTS & operations;
-  const bool validateFonts = VALIDATE_FONTS & operations;
+  const bool getScripts = NO_OPERATION != ( GET_SCRIPTS & operations );
+  const bool validateFonts = NO_OPERATION != ( VALIDATE_FONTS & operations );
 
   Vector<ScriptRun>& scripts = mLogicalModel->mScriptRuns;
   Vector<FontRun>& validFonts = mLogicalModel->mFontRuns;
@@ -755,7 +743,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
   Vector<Character> mirroredUtf32Characters;
   bool textMirrored = false;
   const Length numberOfParagraphs = mLogicalModel->mParagraphInfo.Count();
-  if( BIDI_INFO & operations )
+  if( NO_OPERATION != ( BIDI_INFO & operations ) )
   {
     Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mLogicalModel->mBidirectionalParagraphInfo;
     bidirectionalInfo.Reserve( numberOfParagraphs );
@@ -803,7 +791,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
   newParagraphGlyphs.Reserve( numberOfParagraphs );
 
   const Length currentNumberOfGlyphs = glyphs.Count();
-  if( SHAPE_TEXT & operations )
+  if( NO_OPERATION != ( SHAPE_TEXT & operations ) )
   {
     const Vector<Character>& textToShape = textMirrored ? mirroredUtf32Characters : utf32Characters;
     // Shapes the text.
@@ -827,7 +815,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
 
   const Length numberOfGlyphs = glyphs.Count() - currentNumberOfGlyphs;
 
-  if( GET_GLYPH_METRICS & operations )
+  if( NO_OPERATION != ( GET_GLYPH_METRICS & operations ) )
   {
     GlyphInfo* glyphsBuffer = glyphs.Begin();
     mMetrics->GetGlyphMetrics( glyphsBuffer + mTextUpdateInfo.mStartGlyphIndex, numberOfGlyphs );
@@ -845,7 +833,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
     updated = true;
   }
 
-  if( COLOR & operationsRequired )
+  if( NO_OPERATION != ( COLOR & operations ) )
   {
     // Set the color runs in glyphs.
     SetColorSegmentationInfo( mLogicalModel->mColorRuns,
@@ -896,34 +884,50 @@ void Controller::Impl::RetrieveDefaultInputStyle( InputStyle& inputStyle )
   inputStyle.textColor = mTextColor;
   inputStyle.isDefaultColor = true;
 
+  inputStyle.familyName.clear();
+  inputStyle.weight = TextAbstraction::FontWeight::NORMAL;
+  inputStyle.width = TextAbstraction::FontWidth::NORMAL;
+  inputStyle.slant = TextAbstraction::FontSlant::NORMAL;
+  inputStyle.size = 0.f;
+
+  inputStyle.familyDefined = false;
+  inputStyle.weightDefined = false;
+  inputStyle.widthDefined = false;
+  inputStyle.slantDefined = false;
+  inputStyle.sizeDefined = false;
+
   // Sets the default font's family name, weight, width, slant and size.
   if( mFontDefaults )
   {
-    inputStyle.familyName = mFontDefaults->mFontDescription.family;
-    inputStyle.weight = mFontDefaults->mFontDescription.weight;
-    inputStyle.width = mFontDefaults->mFontDescription.width;
-    inputStyle.slant = mFontDefaults->mFontDescription.slant;
-    inputStyle.size = mFontDefaults->mDefaultPointSize;
+    if( mFontDefaults->familyDefined )
+    {
+      inputStyle.familyName = mFontDefaults->mFontDescription.family;
+      inputStyle.familyDefined = true;
+    }
 
-    inputStyle.familyDefined = mFontDefaults->familyDefined;
-    inputStyle.weightDefined = mFontDefaults->weightDefined;
-    inputStyle.widthDefined = mFontDefaults->widthDefined;
-    inputStyle.slantDefined = mFontDefaults->slantDefined;
-    inputStyle.sizeDefined = mFontDefaults->sizeDefined;
-  }
-  else
-  {
-    inputStyle.familyName.clear();
-    inputStyle.weight = TextAbstraction::FontWeight::NORMAL;
-    inputStyle.width = TextAbstraction::FontWidth::NORMAL;
-    inputStyle.slant = TextAbstraction::FontSlant::NORMAL;
-    inputStyle.size = 0.f;
+    if( mFontDefaults->weightDefined )
+    {
+      inputStyle.weight = mFontDefaults->mFontDescription.weight;
+      inputStyle.weightDefined = true;
+    }
 
-    inputStyle.familyDefined = false;
-    inputStyle.weightDefined = false;
-    inputStyle.widthDefined = false;
-    inputStyle.slantDefined = false;
-    inputStyle.sizeDefined = false;
+    if( mFontDefaults->widthDefined )
+    {
+      inputStyle.width = mFontDefaults->mFontDescription.width;
+      inputStyle.widthDefined = true;
+    }
+
+    if( mFontDefaults->slantDefined )
+    {
+      inputStyle.slant = mFontDefaults->mFontDescription.slant;
+      inputStyle.slantDefined = true;
+    }
+
+    if( mFontDefaults->sizeDefined )
+    {
+      inputStyle.size = mFontDefaults->mDefaultPointSize;
+      inputStyle.sizeDefined = true;
+    }
   }
 }
 
@@ -1386,12 +1390,17 @@ void Controller::Impl::ShowClipboard()
 
 void Controller::Impl::HideClipboard()
 {
-  if( mClipboard )
+  if( mClipboard && mClipboardHideEnabled )
   {
     mClipboard.HideClipboard();
   }
 }
 
+void Controller::Impl::SetClipboardHideEnable(bool enable)
+{
+  mClipboardHideEnabled = enable;
+}
+
 bool Controller::Impl::CopyStringToClipboard( std::string& source )
 {
   //Send string to clipboard
@@ -1929,10 +1938,6 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX,
   const Vector<Vector2>& positions = mVisualModel->mGlyphPositions;
   const Vector2* const positionsBuffer = positions.Begin();
 
-  // Get the visual to logical conversion tables.
-  const CharacterIndex* const visualToLogicalBuffer = ( 0u != mLogicalModel->mVisualToLogicalMap.Count() ) ? mLogicalModel->mVisualToLogicalMap.Begin() : NULL;
-  const CharacterIndex* const visualToLogicalCursorBuffer = mLogicalModel->mVisualToLogicalCursorMap.Begin();
-
   // Get the character to glyph conversion table.
   const GlyphIndex* const charactersToGlyphBuffer = mVisualModel->mCharactersToGlyph.Begin();
 
@@ -1942,9 +1947,6 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX,
   // Get the glyph's info buffer.
   const GlyphInfo* const glyphInfoBuffer = mVisualModel->mGlyphs.Begin();
 
-  // If the vector is void, there is no right to left characters.
-  const bool hasRightToLeftCharacters = NULL != visualToLogicalBuffer;
-
   const CharacterIndex startCharacter = line.characterRun.characterIndex;
   const CharacterIndex endCharacter   = line.characterRun.characterIndex + line.characterRun.numberOfCharacters;
   DALI_ASSERT_DEBUG( endCharacter <= mLogicalModel->mText.Count() && "Invalid line info" );
@@ -1958,7 +1960,7 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX,
   for( ; !matched && ( visualIndex < endCharacter ); ++visualIndex )
   {
     // The character in logical order.
-    const CharacterIndex characterLogicalOrderIndex = hasRightToLeftCharacters ? *( visualToLogicalBuffer + visualIndex ) : visualIndex;
+    const CharacterIndex characterLogicalOrderIndex = mLogicalModel->GetLogicalCharacterIndex( visualIndex );
 
     // Get the script of the character.
     const Script script = mLogicalModel->GetScript( characterLogicalOrderIndex );
@@ -1972,7 +1974,7 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX,
     {
       // Get the first character/glyph of the group of glyphs.
       const CharacterIndex firstVisualCharacterIndex = 1u + visualIndex - numberOfCharacters;
-      const CharacterIndex firstLogicalCharacterIndex = hasRightToLeftCharacters ? *( visualToLogicalBuffer + firstVisualCharacterIndex ) : firstVisualCharacterIndex;
+      const CharacterIndex firstLogicalCharacterIndex = mLogicalModel->GetLogicalCharacterIndex( firstVisualCharacterIndex );
       const GlyphIndex firstLogicalGlyphIndex = *( charactersToGlyphBuffer + firstLogicalCharacterIndex );
 
       // Get the metrics for the group of glyphs.
@@ -2015,7 +2017,6 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX,
 
   }
 
-
   // Return the logical position of the cursor in characters.
 
   if( !matched )
@@ -2023,7 +2024,7 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX,
     visualIndex = endCharacter;
   }
 
-  logicalIndex = hasRightToLeftCharacters ? *( visualToLogicalCursorBuffer + visualIndex ) : visualIndex;
+  logicalIndex = mLogicalModel->GetLogicalCursorIndex( visualIndex );
   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "%p closest visualIndex %d logicalIndex %d\n", this, visualIndex, logicalIndex );
 
   DALI_ASSERT_DEBUG( ( logicalIndex <= mLogicalModel->mText.Count() && logicalIndex >= 0 ) && "GetClosestCursorIndex - Out of bounds index" );