basctl/source/basicide/basicrenderable.cxx | 30 +++++--- tools/inc/tools/multisel.hxx | 3 tools/source/memtools/multisel.cxx | 99 ++++++++++++++--------------- 3 files changed, 71 insertions(+), 61 deletions(-)
New commits: commit e0ffea7232fe4bd52424b321562baa809686fb09 Author: Ivan Timofeev <timofeev....@gmail.com> Date: Sat Oct 8 22:25:09 2011 +0400 migrate to StringRangeEnumerator in Basic diff --git a/basctl/source/basicide/basicrenderable.cxx b/basctl/source/basicide/basicrenderable.cxx index 1671238..b3e787d 100644 --- a/basctl/source/basicide/basicrenderable.cxx +++ b/basctl/source/basicide/basicrenderable.cxx @@ -121,10 +121,13 @@ sal_Int32 SAL_CALL BasicRenderable::getRendererCount ( if( nContent == 1 ) { rtl::OUString aPageRange( getStringValue( "PageRange" ) ); - MultiSelection aSel( aPageRange ); - long nSelCount = aSel.GetSelectCount(); - if( nSelCount >= 0 && nSelCount < nCount ) - nCount = nSelCount; + if( aPageRange.getLength() ) + { + StringRangeEnumerator aRangeEnum( aPageRange, 0, nCount-1 ); + sal_Int32 nSelCount = aRangeEnum.size(); + if( nSelCount >= 0 ) + nCount = nSelCount; + } } } else @@ -177,12 +180,19 @@ void SAL_CALL BasicRenderable::render ( if( nContent == 1 ) { rtl::OUString aPageRange( getStringValue( "PageRange" ) ); - MultiSelection aSel( aPageRange ); - long nSelect = aSel.FirstSelected(); - while( nSelect != long(SFX_ENDOFSELECTION) && nRenderer-- ) - nSelect = aSel.NextSelected(); - if( nSelect != long(SFX_ENDOFSELECTION) ) - mpWindow->printPage( sal_Int32(nSelect-1), pPrinter ); + if( aPageRange.getLength() ) + { + sal_Int32 nPageCount = mpWindow->countPages( pPrinter ); + StringRangeEnumerator aRangeEnum( aPageRange, 0, nPageCount-1 ); + StringRangeEnumerator::Iterator it = aRangeEnum.begin(); + for( ; it != aRangeEnum.end() && nRenderer; --nRenderer ) + ++it; + + sal_Int32 nPage = ( it != aRangeEnum.end() ) ? *it : nRenderer; + mpWindow->printPage( nPage, pPrinter ); + } + else + mpWindow->printPage( nRenderer, pPrinter ); } else mpWindow->printPage( nRenderer, pPrinter ); commit 9cbc1c3253f1c7ac7507ec89ed879d157c809bb6 Author: Ivan Timofeev <timofeev....@gmail.com> Date: Sat Oct 8 22:24:21 2011 +0400 no need to return size_t instead of sal_Int32 diff --git a/tools/inc/tools/multisel.hxx b/tools/inc/tools/multisel.hxx index 733682f..6d3c3de 100644 --- a/tools/inc/tools/multisel.hxx +++ b/tools/inc/tools/multisel.hxx @@ -162,7 +162,7 @@ public: sal_Int32 i_nLogicalOffset = -1 ); - size_t size() const { return size_t(mnCount); } + sal_Int32 size() const { return mnCount; } Iterator begin( const std::set< sal_Int32 >* i_pPossibleValues = NULL ) const; Iterator end( const std::set< sal_Int32 >* i_pPossibleValues = NULL ) const; diff --git a/tools/source/memtools/multisel.cxx b/tools/source/memtools/multisel.cxx index 395082e..bf504e5 100644 --- a/tools/source/memtools/multisel.cxx +++ b/tools/source/memtools/multisel.cxx @@ -1168,7 +1168,7 @@ bool StringRangeEnumerator::getRangesFromString( const OUString& i_rPageRange, //Even if the input range wasn't completely valid, return what ranges could //be extracted from the input. - o_rPageVector.reserve( aEnum.size() ); + o_rPageVector.reserve( static_cast< size_t >( aEnum.size() ) ); for( StringRangeEnumerator::Iterator it = aEnum.begin( i_pPossibleValues ); it != aEnum.end( i_pPossibleValues ); ++it ) { commit 6dcfa9d2aefc161ce61ea9b007d8997be3f31af9 Author: Ivan Timofeev <timofeev....@gmail.com> Date: Sat Oct 8 22:20:42 2011 +0400 allow parsing of joined ranges i.e. "1-4-2" means "1,2,3,4,3,2" now. This is for eliminating ambiguity, it is doubtful whether users will find this useful. diff --git a/tools/inc/tools/multisel.hxx b/tools/inc/tools/multisel.hxx index bb74783..733682f 100644 --- a/tools/inc/tools/multisel.hxx +++ b/tools/inc/tools/multisel.hxx @@ -127,6 +127,7 @@ class TOOLS_DLLPUBLIC StringRangeEnumerator sal_Int32 mnOffset; bool insertRange( sal_Int32 nFirst, sal_Int32 nLast, bool bSequence, bool bMayAdjust ); + bool insertJoinedRanges( const std::vector< sal_Int32 >& rNumbers, bool i_bStrict ); bool checkValue( sal_Int32, const std::set< sal_Int32 >* i_pPossibleValues = NULL ) const; public: class TOOLS_DLLPUBLIC Iterator diff --git a/tools/source/memtools/multisel.cxx b/tools/source/memtools/multisel.cxx index 9984b3a..395082e 100644 --- a/tools/source/memtools/multisel.cxx +++ b/tools/source/memtools/multisel.cxx @@ -972,6 +972,33 @@ bool StringRangeEnumerator::insertRange( sal_Int32 i_nFirst, sal_Int32 i_nLast, return bSuccess; } +bool StringRangeEnumerator::insertJoinedRanges( + const std::vector< sal_Int32 >& rNumbers, bool i_bStrict ) +{ + size_t nCount = rNumbers.size(); + if( nCount == 0 ) + return true; + + if( nCount == 1 ) + return insertRange( rNumbers[0], -1, false, ! i_bStrict ); + + for( size_t i = 0; i < nCount - 1; i++ ) + { + sal_Int32 nFirst = rNumbers[i]; + sal_Int32 nLast = rNumbers[i + 1]; + if( i > 0 ) + { + if ( nFirst > nLast ) nFirst--; + else if( nFirst < nLast ) nFirst++; + } + + if ( ! insertRange( nFirst, nLast, nFirst != nLast, ! i_bStrict ) && i_bStrict) + return false; + } + + return true; +} + bool StringRangeEnumerator::setRange( const rtl::OUString& i_rNewRange, bool i_bStrict ) { mnCount = 0; @@ -989,75 +1016,47 @@ bool StringRangeEnumerator::setRange( const rtl::OUString& i_rNewRange, bool i_b const sal_Unicode* pInput = i_rNewRange.getStr(); rtl::OUStringBuffer aNumberBuf( 16 ); - sal_Int32 nLastNumber = -1, nNumber = -1; + std::vector< sal_Int32 > aNumbers; bool bSequence = false; - bool bSuccess = true; while( *pInput ) { while( *pInput >= sal_Unicode('0') && *pInput <= sal_Unicode('9') ) aNumberBuf.append( *pInput++ ); if( aNumberBuf.getLength() ) { - if( nNumber != -1 ) - { - if( bSequence ) - { - if( ! insertRange( nLastNumber, nNumber, true, ! i_bStrict ) && i_bStrict ) - { - bSuccess = false; - break; - } - nLastNumber = -1; - bSequence = false; - } - else - { - if( ! insertRange( nNumber, nNumber, false, ! i_bStrict ) && i_bStrict ) - { - bSuccess = false; - break; - } - } - } - nNumber = aNumberBuf.makeStringAndClear().toInt32(); - nNumber += mnOffset; + if( bSequence && aNumbers.empty() ) + aNumbers.push_back( mnMin ); + + sal_Int32 nNumber = aNumberBuf.makeStringAndClear().toInt32() + mnOffset; + aNumbers.push_back( nNumber ); + bSequence = false; } - bool bInsertRange = false; + if( *pInput == sal_Unicode('-') ) - { - nLastNumber = nNumber; - nNumber = -1; bSequence = true; - } - else if( *pInput == ' ' ) - { - } else if( *pInput == sal_Unicode(',') || *pInput == sal_Unicode(';') ) - bInsertRange = true; - else if( *pInput ) { + if( bSequence && !aNumbers.empty() ) + aNumbers.push_back( mnMax ); + if( ! insertJoinedRanges( aNumbers, i_bStrict ) && i_bStrict ) + return false; - bSuccess = false; - break; // parse error - } - - if( bInsertRange ) - { - if( ! insertRange( nLastNumber, nNumber, bSequence, ! i_bStrict ) && i_bStrict ) - { - bSuccess = false; - break; - } - nNumber = nLastNumber = -1; + aNumbers.clear(); bSequence = false; } + else if( *pInput && *pInput != sal_Unicode(' ') ) + return false; // parse error + if( *pInput ) pInput++; } // insert last entries - insertRange( nLastNumber, nNumber, bSequence, ! i_bStrict ); + if( bSequence && !aNumbers.empty() ) + aNumbers.push_back( mnMax ); + if( ! insertJoinedRanges( aNumbers, i_bStrict ) && i_bStrict ) + return false; - return bSuccess; + return true; } bool StringRangeEnumerator::hasValue( sal_Int32 i_nValue, const std::set< sal_Int32 >* i_pPossibleValues ) const _______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits