X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=base%2Fdali-toolkit%2Finternal%2Fcontrols%2Ftext-view%2Ftext-view-impl.cpp;h=3e08d27161afbf81379048650639ad3855b36633;hb=efc7867951058f01bbbf9694a24726e1dfaf5c16;hp=63b6191d3a8b8c36480bd02de06e7c8728031851;hpb=0f217b9896d284c667e1251ee617e4ddadd4c9e3;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git 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 63b6191..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 @@ -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 @@ -377,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 ); } } @@ -547,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(); @@ -567,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() @@ -632,7 +704,6 @@ void TextView::GetTextLayoutInfo() { mRelayoutOperations = static_cast( mRelayoutOperations | RELAYOUT_INSERT_TO_TEXT_VIEW ); } - } } } @@ -861,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, @@ -875,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 ), @@ -884,7 +954,6 @@ TextView::LayoutParameters::LayoutParameters( Toolkit::TextView::MultilinePolicy mVerticalAlignment(), mLineJustification( lineJustification ), mLineHeightOffset( lineHeightOffset ), - mEllipsizeText(), mMarkUpEnabled( markUpEnabled ) { // Sets alignment @@ -897,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 ) @@ -911,7 +976,6 @@ TextView::LayoutParameters::LayoutParameters( const TextView::LayoutParameters& mVerticalAlignment( layoutParameters.mVerticalAlignment ), mLineJustification( layoutParameters.mLineJustification ), mLineHeightOffset( layoutParameters.mLineHeightOffset ), - mEllipsizeText( layoutParameters.mEllipsizeText ), mMarkUpEnabled( layoutParameters.mMarkUpEnabled ) { } @@ -925,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; @@ -1014,7 +1077,6 @@ TextView::TextView() static_cast( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ), Toolkit::TextView::Left, PointSize( 0.f ), - std::string( "..." ), false ), mVisualParameters(), mRelayoutData(), @@ -1030,8 +1092,8 @@ TextView::TextView() mPreviousSnapshotModeEnabled( false ), mMarkUpEnabled( false ) { - TextViewProcessor::CreateWordTextInfo( mLayoutParameters.mEllipsizeText, - mRelayoutData.mTextLayoutInfo.mEllipsizeLayoutInfo ); + // Creates the ellipsis layout info. + CreateEllipsizeLayout(); } TextView::~TextView() @@ -1145,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 ); } @@ -1187,6 +1248,17 @@ void TextView::OnRelaidOut( Vector2 size, ActorSizeContainer& container ) } } + 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; + } + } + // Remove glyph-actors from text-view if( !mRelayoutData.mGlyphActors.empty() && ( mRelayoutOperations & RELAYOUT_REMOVE_TEXT_ACTORS ) ) { @@ -1876,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() );