[Libreoffice-commits] core.git: editeng/source include/editeng
Varun Dhall
varun.dhall at studentpartner.com
Fri Jun 30 17:39:40 UTC 2017
editeng/source/uno/unotext.cxx | 19 +++--
editeng/source/uno/unotext2.cxx | 149 ++++++++++++++++++++++------------------
include/editeng/unotext.hxx | 45 ++++++------
3 files changed, 118 insertions(+), 95 deletions(-)
New commits:
commit 3c1fc723ff622d8a541fa26a3397ca4258332e4a
Author: Varun Dhall <varun.dhall at studentpartner.com>
Date: Thu Jun 22 11:24:10 2017 +0530
EditEngine: Changing export selection for copy/paste
Change-Id: I6f52f30eff76de5f0d641271ce3ea36ced572cc4
Reviewed-on: https://gerrit.libreoffice.org/39083
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Michael Stahl <mstahl at redhat.com>
diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx
index 058e56ad7d9f..dcfdd72eace9 100644
--- a/editeng/source/uno/unotext.cxx
+++ b/editeng/source/uno/unotext.cxx
@@ -1955,13 +1955,18 @@ void SAL_CALL SvxUnoTextBase::setString( const OUString& aString )
uno::Reference< container::XEnumeration > SAL_CALL SvxUnoTextBase::createEnumeration()
{
SolarMutexGuard aGuard;
-
- ESelection aSelection;
- ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
- SetSelection( aSelection );
-
- uno::Reference< container::XEnumeration > xEnum( static_cast<container::XEnumeration*>(new SvxUnoTextContentEnumeration( *this )) );
- return xEnum;
+ if( maSelection.IsEqual(ESelection(0,0,0,0)) || maSelection.IsEqual(ESelection(EE_PARA_MAX_COUNT,0,0,0)) )
+ {
+ ESelection aSelection;
+ ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
+ uno::Reference< container::XEnumeration > xEnum( static_cast<container::XEnumeration*>( new SvxUnoTextContentEnumeration( *this, aSelection ) ) );
+ return xEnum;
+ }
+ else
+ {
+ uno::Reference< container::XEnumeration > xEnum( static_cast<container::XEnumeration*>( new SvxUnoTextContentEnumeration( *this, maSelection ) ) );
+ return xEnum;
+ }
}
// XElementAccess ( container::XEnumerationAccess )
diff --git a/editeng/source/uno/unotext2.cxx b/editeng/source/uno/unotext2.cxx
index 5f012775bfde..6f16b855e751 100644
--- a/editeng/source/uno/unotext2.cxx
+++ b/editeng/source/uno/unotext2.cxx
@@ -39,13 +39,48 @@ using namespace ::com::sun::star;
// SvxUnoTextContentEnumeration
-SvxUnoTextContentEnumeration::SvxUnoTextContentEnumeration( const SvxUnoTextBase& _rText ) throw()
-: mrText( _rText )
+SvxUnoTextContentEnumeration::SvxUnoTextContentEnumeration( const SvxUnoTextBase& _rText, const ESelection& rSel ) throw()
+: mrText( _rText ),
+ maSelection( rSel )
{
mxParentText = const_cast<SvxUnoTextBase*>(&_rText);
if( mrText.GetEditSource() )
mpEditSource.reset( mrText.GetEditSource()->Clone() );
mnNextParagraph = 0;
+ for( sal_Int32 currentPara = 0; currentPara < mrText.GetEditSource()->GetTextForwarder()->GetParagraphCount(); currentPara++ )
+ {
+ if( currentPara>=maSelection.nStartPara && currentPara<=maSelection.nEndPara )
+ {
+ const SvxUnoTextRangeBaseList& rRanges( mpEditSource->getRanges() );
+ SvxUnoTextContent* pContent = nullptr;
+ sal_Int32 nStartPos = 0;
+ sal_Int32 nEndPos = mrText.GetEditSource()->GetTextForwarder()->GetTextLen( currentPara );
+ if( currentPara == maSelection.nStartPara )
+ nStartPos = nStartPos>maSelection.nStartPos ? nStartPos : maSelection.nStartPos;
+ if( currentPara == maSelection.nEndPara )
+ nEndPos = nEndPos<maSelection.nEndPos ? nEndPos : maSelection.nEndPos;
+ ESelection aCurrentParaSel = ESelection( currentPara, nStartPos, currentPara, nEndPos );
+ for( auto aIter = rRanges.begin(); (aIter != rRanges.end()) && (pContent == nullptr); ++aIter )
+ {
+ SvxUnoTextContent* pIterContent = dynamic_cast< SvxUnoTextContent* >( ( *aIter ) );
+ if( pIterContent && (pIterContent->mnParagraph == currentPara) )
+ {
+ ESelection aIterSel = pIterContent->GetSelection();
+ if( aIterSel.IsEqual( aCurrentParaSel ) )
+ {
+ pContent = pIterContent;
+ maContents.push_back( pContent );
+ }
+ }
+ }
+ if( pContent == nullptr )
+ {
+ pContent = new SvxUnoTextContent( mrText, currentPara );
+ pContent->SetSelection( aCurrentParaSel );
+ maContents.push_back( pContent );
+ }
+ }
+ }
}
SvxUnoTextContentEnumeration::~SvxUnoTextContentEnumeration() throw()
@@ -56,8 +91,8 @@ SvxUnoTextContentEnumeration::~SvxUnoTextContentEnumeration() throw()
sal_Bool SAL_CALL SvxUnoTextContentEnumeration::hasMoreElements()
{
SolarMutexGuard aGuard;
- if( mpEditSource && mpEditSource->GetTextForwarder() )
- return mnNextParagraph < mpEditSource->GetTextForwarder()->GetParagraphCount();
+ if( mpEditSource && !maContents.empty() )
+ return (unsigned)mnNextParagraph < maContents.size();
else
return false;
}
@@ -69,23 +104,8 @@ uno::Any SvxUnoTextContentEnumeration::nextElement()
if(!hasMoreElements())
throw container::NoSuchElementException();
- SvxUnoTextContent* pContent = nullptr;
-
- const SvxUnoTextRangeBaseList& rRanges( mpEditSource->getRanges() );
- SvxUnoTextRangeBaseList::const_iterator aIter;
- for( aIter = rRanges.begin(); (aIter != rRanges.end()) && (pContent == nullptr); ++aIter )
- {
- SvxUnoTextContent* pIterContent = dynamic_cast< SvxUnoTextContent* >( (*aIter ) );
- if( pIterContent && (pIterContent->mnParagraph == mnNextParagraph) )
- pContent = pIterContent;
- }
-
- if( pContent == nullptr )
- pContent = new SvxUnoTextContent( mrText, mnNextParagraph );
-
+ uno::Reference< text::XTextContent > xRef( maContents.at(mnNextParagraph).get() );
mnNextParagraph++;
-
- uno::Reference< text::XTextContent > xRef( pContent );
return uno::makeAny( xRef );
}
@@ -101,8 +121,6 @@ SvxUnoTextContent::SvxUnoTextContent( const SvxUnoTextBase& rText, sal_Int32 nPa
, mbDisposing( false )
{
mxParentText = const_cast<SvxUnoTextBase*>(&rText);
- if( GetEditSource() && GetEditSource()->GetTextForwarder() )
- SetSelection( ESelection( mnParagraph,0, mnParagraph, GetEditSource()->GetTextForwarder()->GetTextLen( mnParagraph ) ) );
}
SvxUnoTextContent::SvxUnoTextContent( const SvxUnoTextContent& rContent ) throw()
@@ -248,11 +266,11 @@ void SAL_CALL SvxUnoTextContent::removeEventListener( const uno::Reference< lang
// XEnumerationAccess
-uno::Reference< container::XEnumeration > SAL_CALL SvxUnoTextContent::createEnumeration( )
+uno::Reference< container::XEnumeration > SAL_CALL SvxUnoTextContent::createEnumeration()
{
SolarMutexGuard aGuard;
- return new SvxUnoTextRangeEnumeration( mrParentText, mnParagraph );
+ return new SvxUnoTextRangeEnumeration( mrParentText, mnParagraph, maSelection );
}
// XElementAccess ( container::XEnumerationAccess )
@@ -357,29 +375,54 @@ uno::Sequence< OUString > SAL_CALL SvxUnoTextContent::getSupportedServiceNames()
// class SvxUnoTextRangeEnumeration
-SvxUnoTextRangeEnumeration::SvxUnoTextRangeEnumeration( const SvxUnoTextBase& rText, sal_Int32 nPara ) throw()
+SvxUnoTextRangeEnumeration::SvxUnoTextRangeEnumeration( const SvxUnoTextBase& rText, sal_Int32 nPara, const ESelection& rSel ) throw()
: mxParentText( const_cast<SvxUnoTextBase*>(&rText) ),
mrParentText( rText ),
mnParagraph( nPara ),
- mnNextPortion( 0 )
+ mnNextPortion( 0 ),
+ mnSel( rSel )
{
- mpEditSource = rText.GetEditSource() ? rText.GetEditSource()->Clone() : nullptr;
+ mpEditSource.reset( rText.GetEditSource() ? rText.GetEditSource()->Clone() : nullptr );
- if( mpEditSource && mpEditSource->GetTextForwarder() )
+ if( mpEditSource && mpEditSource->GetTextForwarder() && (mnParagraph == mnSel.nStartPara && mnParagraph == mnSel.nEndPara) )
{
- mpPortions = new std::vector<sal_Int32>;
- mpEditSource->GetTextForwarder()->GetPortions( nPara, *mpPortions );
- }
- else
- {
- mpPortions = nullptr;
+ std::vector<sal_Int32> aPortions;
+ mpEditSource->GetTextForwarder()->GetPortions( nPara, aPortions );
+ for( size_t aPortionIndex = 0; aPortionIndex < aPortions.size(); aPortionIndex++ )
+ {
+ sal_uInt16 nStartPos = 0;
+ if ( aPortionIndex > 0 )
+ nStartPos = aPortions.at( aPortionIndex - 1 );
+ if( nStartPos > mnSel.nEndPos )
+ continue;
+ sal_uInt16 nEndPos = aPortions.at( aPortionIndex );
+ if( nEndPos < mnSel.nStartPos )
+ continue;
+
+ nStartPos = nStartPos>mnSel.nStartPos ? nStartPos : mnSel.nStartPos;
+ nEndPos = nEndPos<mnSel.nEndPos ? nEndPos : mnSel.nEndPos;
+ ESelection aSel( mnParagraph, nStartPos, mnParagraph, nEndPos );
+
+ const SvxUnoTextRangeBaseList& rRanges( mpEditSource->getRanges() );
+ SvxUnoTextRange* pRange = nullptr;
+ for( auto aIter = rRanges.begin(); (aIter != rRanges.end()) && (pRange == nullptr); ++aIter )
+ {
+ SvxUnoTextRange* pIterRange = dynamic_cast< SvxUnoTextRange* >( ( *aIter ) );
+ if( pIterRange && pIterRange->mbPortion && ( aSel.IsEqual( pIterRange->maSelection ) ) )
+ pRange = pIterRange;
+ }
+ if( pRange == nullptr )
+ {
+ pRange = new SvxUnoTextRange( mrParentText, true );
+ pRange->SetSelection( aSel );
+ }
+ maPortions.push_back( pRange );
+ }
}
}
SvxUnoTextRangeEnumeration::~SvxUnoTextRangeEnumeration() throw()
{
- delete mpEditSource;
- delete mpPortions;
}
// container::XEnumeration
@@ -388,46 +431,18 @@ sal_Bool SAL_CALL SvxUnoTextRangeEnumeration::hasMoreElements()
{
SolarMutexGuard aGuard;
- return mpPortions && mnNextPortion < mpPortions->size();
+ return !maPortions.empty() && mnNextPortion < maPortions.size();
}
uno::Any SAL_CALL SvxUnoTextRangeEnumeration::nextElement()
{
SolarMutexGuard aGuard;
- if( mpPortions == nullptr || mnNextPortion >= mpPortions->size() )
+ if( maPortions.empty() || mnNextPortion >= maPortions.size() )
throw container::NoSuchElementException();
- sal_uInt16 nStartPos = 0;
- if (mnNextPortion > 0)
- nStartPos = mpPortions->at(mnNextPortion-1);
- sal_uInt16 nEndPos = mpPortions->at(mnNextPortion);
- ESelection aSel( mnParagraph, nStartPos, mnParagraph, nEndPos );
-
- uno::Reference< text::XTextRange > xRange;
-
- const SvxUnoTextRangeBaseList& rRanges( mpEditSource->getRanges() );
-
- SvxUnoTextRange* pRange = nullptr;
-
- SvxUnoTextRangeBaseList::const_iterator aIter;
- for( aIter = rRanges.begin(); (aIter != rRanges.end()) && (pRange == nullptr); ++aIter )
- {
- SvxUnoTextRange* pIterRange = dynamic_cast< SvxUnoTextRange* >( (*aIter ) );
- if( pIterRange && pIterRange->mbPortion && (aSel.IsEqual( pIterRange->maSelection ) ) )
- pRange = pIterRange;
- }
-
- if( pRange == nullptr )
- {
- pRange = new SvxUnoTextRange( mrParentText, true );
- pRange->SetSelection(aSel);
- }
-
- xRange = pRange;
-
+ uno::Reference< text::XTextRange > xRange = ( maPortions.at(mnNextPortion) ).get();
mnNextPortion++;
-
return uno::makeAny( xRange );
}
diff --git a/include/editeng/unotext.hxx b/include/editeng/unotext.hxx
index 70be94f6965d..3cc7932d25b6 100644
--- a/include/editeng/unotext.hxx
+++ b/include/editeng/unotext.hxx
@@ -507,24 +507,6 @@ public:
};
-class SvxUnoTextContentEnumeration : public ::cppu::WeakAggImplHelper1< css::container::XEnumeration >
-{
-private:
- css::uno::Reference< css::text::XText > mxParentText;
- std::unique_ptr<SvxEditSource> mpEditSource;
- sal_Int32 mnNextParagraph;
- const SvxUnoTextBase& mrText;
-
-public:
- SvxUnoTextContentEnumeration( const SvxUnoTextBase& _rText ) throw();
- virtual ~SvxUnoTextContentEnumeration() throw() override;
-
- // css::container::XEnumeration
- virtual sal_Bool SAL_CALL hasMoreElements( ) override;
- virtual css::uno::Any SAL_CALL nextElement( ) override;
-};
-
-
class SvxUnoTextContent : public SvxUnoTextRangeBase,
public css::text::XTextContent,
public css::container::XEnumerationAccess,
@@ -599,18 +581,39 @@ public:
};
+class SvxUnoTextContentEnumeration : public ::cppu::WeakAggImplHelper1< css::container::XEnumeration >
+{
+private:
+ css::uno::Reference< css::text::XText > mxParentText;
+ std::unique_ptr<SvxEditSource> mpEditSource;
+ sal_Int32 mnNextParagraph;
+ const SvxUnoTextBase& mrText;
+ const ESelection maSelection;
+ std::vector< rtl::Reference<SvxUnoTextContent> > maContents;
+
+public:
+ SvxUnoTextContentEnumeration( const SvxUnoTextBase& _rText, const ESelection& rSel ) throw();
+ virtual ~SvxUnoTextContentEnumeration() throw() override;
+
+ // css::container::XEnumeration
+ virtual sal_Bool SAL_CALL hasMoreElements( ) override;
+ virtual css::uno::Any SAL_CALL nextElement( ) override;
+};
+
+
class SvxUnoTextRangeEnumeration : public ::cppu::WeakAggImplHelper1< css::container::XEnumeration >
{
private:
- SvxEditSource* mpEditSource;
+ std::unique_ptr<SvxEditSource> mpEditSource;
css::uno::Reference< css::text::XText > mxParentText;
const SvxUnoTextBase& mrParentText;
sal_Int32 mnParagraph;
- std::vector<sal_Int32>* mpPortions;
+ std::vector< rtl::Reference<SvxUnoTextRange> > maPortions;
sal_uInt16 mnNextPortion;
+ const ESelection mnSel;
public:
- SvxUnoTextRangeEnumeration( const SvxUnoTextBase& rText, sal_Int32 nPara ) throw();
+ SvxUnoTextRangeEnumeration( const SvxUnoTextBase& rText, sal_Int32 nPara, const ESelection& rSel ) throw();
virtual ~SvxUnoTextRangeEnumeration() throw() override;
// css::container::XEnumeration
More information about the Libreoffice-commits
mailing list