X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=base%2Fdali-toolkit%2Finternal%2Fcontrols%2Ftext-view%2Ftext-view-impl.cpp;h=3e08d27161afbf81379048650639ad3855b36633;hp=ddf6cd718b5ce6e026a27f2c7bc793bf532c9d5e;hb=efc7867951058f01bbbf9694a24726e1dfaf5c16;hpb=0eed173d0b1a957811af9f0afa022f714bf2b5dc diff --git a/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp b/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp index ddf6cd7..3e08d27 100644 --- a/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/text-view/text-view-impl.cpp @@ -18,10 +18,16 @@ // CLASS HEADER #include +// EXTERNAL INCLUDES +#include +#include +#include + // INTERNAL INCLUDES #include #include #include +#include #include #include #include @@ -121,8 +127,8 @@ bool IsTextViewProcessorNewStyleOperation( const TextView::TextViewProcessorMeta TextView::TextViewProcessorMetadata::TextViewProcessorMetadata() : mType( TextView::TextSet ), - mPosition( 0 ), - mNumberOfCharacters( 0 ), + mPosition( 0u ), + mNumberOfCharacters( 0u ), mText() { } @@ -193,23 +199,38 @@ void TextView::InsertTextAt( std::size_t position, const std::string& text ) void TextView::InsertTextAt( std::size_t position, const MarkupProcessor::StyledTextArray& text ) { - // Creates metadata with the Insert operation. - TextViewProcessorMetadata metadata; - metadata.mType = TextView::TextInserted; - metadata.mPosition = position; - metadata.mText = text; + std::string textStr; + MarkupProcessor::GetPlainString( text, textStr ); - // Store metadata. - mTextViewProcessorOperations.push_back( metadata ); + if( TextProcessor::ContainsRightToLeftCharacter( Text( textStr ) ) || + TextProcessor::ContainsRightToLeftCharacter( Text( GetText() ) ) ) + { + // Temporary fix. Creates the whole layout if there is rtl text. - // Updates current styled text. - mCurrentStyledText.insert( mCurrentStyledText.begin() + position, text.begin(), text.end() ); + MarkupProcessor::StyledTextArray textToSet = mCurrentStyledText; + textToSet.insert( textToSet.begin() + position, text.begin(), text.end() ); + SetText( textToSet ); + } + else + { + // Creates metadata with the Insert operation. + TextViewProcessorMetadata metadata; + metadata.mType = TextView::TextInserted; + metadata.mPosition = position; + metadata.mText = text; - // Request to be relaid out - RelayoutRequest(); + // Store metadata. + mTextViewProcessorOperations.push_back( metadata ); - // If a GetTextLayoutInfo() or GetHeightForWidth() arrives, relayout the text synchronously is needed on order to retrieve the right values. - mRelayoutOperations = RELAYOUT_ALL; + // Updates current styled text. + mCurrentStyledText.insert( mCurrentStyledText.begin() + position, text.begin(), text.end() ); + + // Request to be relaid out + RelayoutRequest(); + + // If a GetTextLayoutInfo() or GetHeightForWidth() arrives, relayout the text synchronously is needed on order to retrieve the right values. + mRelayoutOperations = RELAYOUT_ALL; + } } void TextView::ReplaceTextFromTo( std::size_t position, std::size_t numberOfCharacters, const std::string& text ) @@ -224,49 +245,84 @@ void TextView::ReplaceTextFromTo( std::size_t position, std::size_t numberOfChar void TextView::ReplaceTextFromTo( std::size_t position, std::size_t numberOfCharacters, const MarkupProcessor::StyledTextArray& text ) { - // Creates metadata with the Insert operation. - TextViewProcessorMetadata metadata; - metadata.mType = TextView::TextReplaced; - metadata.mPosition = position; - metadata.mNumberOfCharacters = numberOfCharacters; - metadata.mText = text; + std::string textStr; + MarkupProcessor::GetPlainString( text, textStr ); - // Store metadata. - mTextViewProcessorOperations.push_back( metadata ); + if( TextProcessor::ContainsRightToLeftCharacter( Text( textStr ) ) || + TextProcessor::ContainsRightToLeftCharacter( Text( GetText() ) ) ) + { + // Temporary fix. Creates the whole layout if there is rtl text. - // Updates current styled text. - MarkupProcessor::StyledTextArray::iterator it = mCurrentStyledText.begin() + position; - mCurrentStyledText.erase( it, it + numberOfCharacters ); - it = mCurrentStyledText.begin() + position; - mCurrentStyledText.insert( it, text.begin(), text.end() ); + // Updates current styled text. + MarkupProcessor::StyledTextArray textToSet = mCurrentStyledText; - // Request to be relaid out - RelayoutRequest(); + MarkupProcessor::StyledTextArray::iterator it = textToSet.begin() + position; + textToSet.erase( it, it + numberOfCharacters ); + it = textToSet.begin() + position; + textToSet.insert( it, text.begin(), text.end() ); - // If a GetTextLayoutInfo() or GetHeightForWidth() arrives, relayout the text synchronously is needed on order to retrieve the right values. - mRelayoutOperations = RELAYOUT_ALL; + SetText( textToSet ); + } + else + { + // Creates metadata with the Insert operation. + TextViewProcessorMetadata metadata; + metadata.mType = TextView::TextReplaced; + metadata.mPosition = position; + metadata.mNumberOfCharacters = numberOfCharacters; + metadata.mText = text; + + // Store metadata. + mTextViewProcessorOperations.push_back( metadata ); + + // Updates current styled text. + MarkupProcessor::StyledTextArray::iterator it = mCurrentStyledText.begin() + position; + mCurrentStyledText.erase( it, it + numberOfCharacters ); + it = mCurrentStyledText.begin() + position; + mCurrentStyledText.insert( it, text.begin(), text.end() ); + + // Request to be relaid out + RelayoutRequest(); + + // If a GetTextLayoutInfo() or GetHeightForWidth() arrives, relayout the text synchronously is needed on order to retrieve the right values. + mRelayoutOperations = RELAYOUT_ALL; + } } void TextView::RemoveTextFrom( std::size_t position, std::size_t numberOfCharacters ) { - // Creates metadata with the Remove operation. - TextViewProcessorMetadata metadata; - metadata.mType = TextView::TextRemoved; - metadata.mPosition = position; - metadata.mNumberOfCharacters = numberOfCharacters; + if( TextProcessor::ContainsRightToLeftCharacter( Text( GetText() ) ) ) + { + // Temporary fix. Creates the whole layout if there is rtl text. - // Store metadata. - mTextViewProcessorOperations.push_back( metadata ); + // Updates current styled text. + MarkupProcessor::StyledTextArray textToSet = mCurrentStyledText; + MarkupProcessor::StyledTextArray::iterator it = textToSet.begin() + position; + textToSet.erase( it, it + numberOfCharacters ); - // Updates current styled text. - MarkupProcessor::StyledTextArray::iterator it = mCurrentStyledText.begin() + position; - mCurrentStyledText.erase( it, it + numberOfCharacters ); + SetText( textToSet ); + } + else + { + // Creates metadata with the Remove operation. + TextViewProcessorMetadata metadata; + metadata.mType = TextView::TextRemoved; + metadata.mPosition = position; + metadata.mNumberOfCharacters = numberOfCharacters; - // Request to be relaid out - RelayoutRequest(); + // Store metadata. + mTextViewProcessorOperations.push_back( metadata ); - // If a GetTextLayoutInfo() or GetHeightForWidth() arrives, relayout the text synchronously is needed on order to retrieve the right values. - mRelayoutOperations = RELAYOUT_ALL; + // Updates current styled text. + MarkupProcessor::StyledTextArray::iterator it = mCurrentStyledText.begin() + position; + mCurrentStyledText.erase( it, it + numberOfCharacters ); + + // Request to be relaid out + RelayoutRequest(); + + // If a GetTextLayoutInfo() or GetHeightForWidth() arrives, relayout the text synchronously is needed on order to retrieve the right values. + mRelayoutOperations = RELAYOUT_ALL; + } } std::string TextView::GetText() const @@ -311,8 +367,7 @@ void TextView::SetLineHeightOffset( PointSize offset ) RELAYOUT_ALIGNMENT | RELAYOUT_VISIBILITY | RELAYOUT_TEXT_ACTOR_UPDATE | - RELAYOUT_INSERT_TO_TEXT_VIEW | - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); + RELAYOUT_INSERT_TO_TEXT_VIEW ); } } } @@ -378,14 +433,18 @@ void TextView::SetStyleToCurrentText( const TextStyle& style, TextStyle::Mask ma } // Sets the new style to the ellipsize text - if( !mLayoutParameters.mEllipsizeText.empty() ) + // TODO: fix this as a call to SetEllipsizeText will trigger the creation of new text actors. + if( 0u < mRelayoutData.mTextLayoutInfo.mEllipsisTextStyles.Count() ) { - for( MarkupProcessor::StyledTextArray::iterator it = mLayoutParameters.mEllipsizeText.begin(), endIt = mLayoutParameters.mEllipsizeText.end(); it != endIt; ++it ) + for( Vector::Iterator it = mRelayoutData.mTextLayoutInfo.mEllipsisTextStyles.Begin(), + endIt = mRelayoutData.mTextLayoutInfo.mEllipsisTextStyles.End(); + it != endIt; + ++it ) { - (*it).mStyle.Copy( style, mask ); + (*it)->Copy( style, mask ); } - SetEllipsizeText( mLayoutParameters.mEllipsizeText ); + SetEllipsizeText( mRelayoutData.mTextLayoutInfo.mEllipsisText, mRelayoutData.mTextLayoutInfo.mEllipsisTextStyles ); } } @@ -477,8 +536,7 @@ void TextView::SetHeightExceedPolicy( Toolkit::TextView::ExceedPolicy policy ) RELAYOUT_ALIGNMENT | RELAYOUT_VISIBILITY | RELAYOUT_TEXT_ACTOR_UPDATE | - RELAYOUT_INSERT_TO_TEXT_VIEW | - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); + RELAYOUT_INSERT_TO_TEXT_VIEW ); } } } @@ -505,8 +563,7 @@ void TextView::SetLineJustification( Toolkit::TextView::LineJustification justif RELAYOUT_ALIGNMENT | RELAYOUT_VISIBILITY | RELAYOUT_TEXT_ACTOR_UPDATE | - RELAYOUT_INSERT_TO_TEXT_VIEW | - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); + RELAYOUT_INSERT_TO_TEXT_VIEW ); } } } @@ -534,8 +591,7 @@ void TextView::SetFadeBoundary( const Toolkit::TextView::FadeBoundary& fadeBound RELAYOUT_REMOVE_TEXT_ACTORS | RELAYOUT_VISIBILITY | RELAYOUT_TEXT_ACTOR_UPDATE | - RELAYOUT_INSERT_TO_TEXT_VIEW | - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); + RELAYOUT_INSERT_TO_TEXT_VIEW ); } } } @@ -551,17 +607,35 @@ void TextView::SetEllipsizeText( const std::string& ellipsizeText ) MarkupProcessor::StyledTextArray styledText; MarkupProcessor::GetStyledTextArray( ellipsizeText, styledText, IsMarkupProcessingEnabled() ); + // Creates the ellipsis layout info and sets the text and styles. SetEllipsizeText( styledText ); } void TextView::SetEllipsizeText( const MarkupProcessor::StyledTextArray& ellipsizeText ) { - mLayoutParameters.mEllipsizeText = ellipsizeText; + // Converts the styled text array into a Text and a vector of TextStyles. + Text text; + Vector styles; + for( MarkupProcessor::StyledTextArray::const_iterator it = ellipsizeText.begin(), endIt = ellipsizeText.end(); it != endIt; ++it ) + { + const MarkupProcessor::StyledText& styledText( *it ); - mRelayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo = TextViewProcessor::WordLayoutInfo(); + text.Append( styledText.mText ); + styles.PushBack( new TextStyle( styledText.mStyle ) ); + } - TextViewProcessor::CreateWordTextInfo( mLayoutParameters.mEllipsizeText, - mRelayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo ); + // Creates the ellipsis layout info and sets the text and styles. + SetEllipsizeText( text, styles ); +} + +void TextView::SetEllipsizeText( const Text& ellipsizeText, const Vector& ellipsizeStyles ) +{ + // Sets the text and styles for the ellipsis text. + mRelayoutData.mTextLayoutInfo.mEllipsisText = ellipsizeText; + mRelayoutData.mTextLayoutInfo.mEllipsisTextStyles = ellipsizeStyles; + + // Creates the ellipsis layout info. + CreateEllipsizeLayout(); // Request to be relaid out RelayoutRequest(); @@ -571,13 +645,7 @@ void TextView::SetEllipsizeText( const MarkupProcessor::StyledTextArray& ellipsi std::string TextView::GetEllipsizeText() const { - std::string text; - for( MarkupProcessor::StyledTextArray::const_iterator it = mLayoutParameters.mEllipsizeText.begin(), endIt = mLayoutParameters.mEllipsizeText.end(); it != endIt; ++it ) - { - text.append( (*it).mText.GetText() ); - } - - return text; + return mRelayoutData.mTextLayoutInfo.mEllipsisText.GetText(); } void TextView::GetTextLayoutInfo() @@ -635,9 +703,7 @@ void TextView::GetTextLayoutInfo() if( hasGlyphActors ) { mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_VIEW ); - mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); } - } } } @@ -741,8 +807,7 @@ void TextView::SetSnapshotModeEnabled( bool enable ) mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_REMOVE_TEXT_ACTORS | RELAYOUT_TEXT_ACTOR_UPDATE | - RELAYOUT_INSERT_TO_TEXT_VIEW | - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); + RELAYOUT_INSERT_TO_TEXT_VIEW ); } RelayoutRequest(); } @@ -867,12 +932,12 @@ TextView::LayoutParameters::LayoutParameters() mVerticalAlignment( Toolkit::Alignment::VerticalCenter ), mLineJustification( Toolkit::TextView::Left ), mLineHeightOffset( 0.f ), - mEllipsizeText(), mMarkUpEnabled( false ) { - // Sets ellipsize text - MarkupProcessor::StyledTextArray styledEllipsize; - MarkupProcessor::GetStyledTextArray( std::string( "..." ), mEllipsizeText, false ); +} + +TextView::LayoutParameters::~LayoutParameters() +{ } TextView::LayoutParameters::LayoutParameters( Toolkit::TextView::MultilinePolicy multilinePolicy, @@ -881,7 +946,6 @@ TextView::LayoutParameters::LayoutParameters( Toolkit::TextView::MultilinePolicy Toolkit::Alignment::Type alignmentType, Toolkit::TextView::LineJustification lineJustification, float lineHeightOffset, - const std::string& ellipsizeText, bool markUpEnabled ) : mMultilinePolicy( multilinePolicy ), mWidthExceedPolicy( widthExceedPolicy ), @@ -890,7 +954,6 @@ TextView::LayoutParameters::LayoutParameters( Toolkit::TextView::MultilinePolicy mVerticalAlignment(), mLineJustification( lineJustification ), mLineHeightOffset( lineHeightOffset ), - mEllipsizeText(), mMarkUpEnabled( markUpEnabled ) { // Sets alignment @@ -903,10 +966,6 @@ TextView::LayoutParameters::LayoutParameters( Toolkit::TextView::MultilinePolicy mHorizontalAlignment = horizontalAlignment; mVerticalAlignment = verticalAlignment; - - // Sets ellipsize text - MarkupProcessor::StyledTextArray styledEllipsize; - MarkupProcessor::GetStyledTextArray( ellipsizeText, mEllipsizeText, mMarkUpEnabled ); } TextView::LayoutParameters::LayoutParameters( const TextView::LayoutParameters& layoutParameters ) @@ -917,7 +976,6 @@ TextView::LayoutParameters::LayoutParameters( const TextView::LayoutParameters& mVerticalAlignment( layoutParameters.mVerticalAlignment ), mLineJustification( layoutParameters.mLineJustification ), mLineHeightOffset( layoutParameters.mLineHeightOffset ), - mEllipsizeText( layoutParameters.mEllipsizeText ), mMarkUpEnabled( layoutParameters.mMarkUpEnabled ) { } @@ -931,7 +989,6 @@ TextView::LayoutParameters& TextView::LayoutParameters::operator=( const TextVie mVerticalAlignment = layoutParameters.mVerticalAlignment; mLineJustification = layoutParameters.mLineJustification; mLineHeightOffset = layoutParameters.mLineHeightOffset; - mEllipsizeText = layoutParameters.mEllipsizeText; mMarkUpEnabled = layoutParameters.mMarkUpEnabled; return *this; @@ -1020,7 +1077,6 @@ TextView::TextView() static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), Toolkit::TextView::Left, PointSize( 0.f ), - std::string( "..." ), false ), mVisualParameters(), mRelayoutData(), @@ -1036,8 +1092,8 @@ TextView::TextView() mPreviousSnapshotModeEnabled( false ), mMarkUpEnabled( false ) { - TextViewProcessor::CreateWordTextInfo( mLayoutParameters.mEllipsizeText, - mRelayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo ); + // Creates the ellipsis layout info. + CreateEllipsizeLayout(); } TextView::~TextView() @@ -1066,7 +1122,6 @@ Vector3 TextView::GetNaturalSize() mRelayoutData.mGlyphActors.clear(); mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_VIEW ); - mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); } PerformTextViewProcessorOperations(); @@ -1127,7 +1182,6 @@ float TextView::GetHeightForWidth( float width ) if( hasGlyphActors ) { mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_VIEW ); - mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); } if( differentWidth || hasGlyphActors ) @@ -1153,9 +1207,8 @@ void TextView::OnInitialize() void TextView::OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ) { - mRelayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo = TextViewProcessor::WordLayoutInfo(); - TextViewProcessor::CreateWordTextInfo( mLayoutParameters.mEllipsizeText, - mRelayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo ); + // Creates the ellipsis layout info. + CreateEllipsizeLayout(); SetText( mCurrentStyledText ); } @@ -1191,8 +1244,18 @@ void TextView::OnRelaidOut( Vector2 size, ActorSizeContainer& container ) RELAYOUT_ALIGNMENT | RELAYOUT_VISIBILITY | RELAYOUT_TEXT_ACTOR_UPDATE | - RELAYOUT_INSERT_TO_TEXT_VIEW | - RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST ); + RELAYOUT_INSERT_TO_TEXT_VIEW ); + } + } + + if( ( Toolkit::TextView::Fade == mLayoutParameters.mWidthExceedPolicy ) || + ( Toolkit::TextView::Fade == mLayoutParameters.mHeightExceedPolicy ) ) + { + if( mRelayoutOperations & RELAYOUT_ALIGNMENT ) + { + // If the text of the alignment changes and a fade exceed policy is set, + // some characters may need new TextActor. + mRelayoutOperations = RELAYOUT_ALL; } } @@ -1300,9 +1363,9 @@ void TextView::OptimizeTextViewProcessorOperations() { bool optimizationDone = false; - if( it + 1 != endIt ) + if( it + 1u != endIt ) { - const TextViewProcessorMetadata& nextRelayoutMetadata( *( it + 1 ) ); + const TextViewProcessorMetadata& nextRelayoutMetadata( *( it + 1u ) ); if( TextView::TextInserted == nextRelayoutMetadata.mType ) { if( relayoutMetadata.mPosition == nextRelayoutMetadata.mPosition ) @@ -1885,6 +1948,16 @@ Actor TextView::GetRootActor() const return rootActor; } +void TextView::CreateEllipsizeLayout() +{ + // Creates the ellipsis layout info for the ellipsis text and styles. + mRelayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo = TextViewProcessor::WordLayoutInfo(); + mRelayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo.mCharactersLayoutInfo.resize( mRelayoutData.mTextLayoutInfo.mEllipsisText.GetLength(), TextViewProcessor::CharacterLayoutInfo() ); + TextViewProcessor::CreateWordTextInfo( mRelayoutData.mTextLayoutInfo.mEllipsisText, + mRelayoutData.mTextLayoutInfo.mEllipsisTextStyles, + mRelayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo ); +} + void TextView::OnMarkupEnabledPeopertySet( Property::Value propertyValue ) { bool newValue( propertyValue.Get() ); @@ -2006,7 +2079,7 @@ void TextView::OnLineJustificationPropertySet( Property::Value propertyValue ) void TextView::OnFadeBoundaryPropertySet( Property::Value propertyValue ) { Vector4 value( propertyValue.Get() ); - DALI_ASSERT_ALWAYS( value.x >= 0 && value.y >= 0 && value.z >= 0 && value.w >= 0 + DALI_ASSERT_ALWAYS( ( value.x >= 0.f ) && ( value.y >= 0.f ) && ( value.z >= 0.f ) && ( value.w >= 0.f ) && "TextView::OnFadeBoundaryPropertySet(). Negative value is invalid. " ); Toolkit::TextView::FadeBoundary fadeBoundary( PixelSize( static_cast( value.x ) ),