/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// clear the old and copy the sub selections
ImplClear();
aSels.insert( aSels.end(), rOrig.aSels.begin(), rOrig.aSels.end() );
nSelCount = rOrig.nSelCount;
bool MultiSelection::Select( sal_Int32 nIndex, bool bSelect )
{
DBG_ASSERT( aTotRange.Contains(nIndex), "selected index out of range" );
// out of range? if ( !aTotRange.Contains(nIndex) ) returnfalse;
// find the virtual target position
std::size_t nSubSelPos = ImplFindSubSelection( nIndex );
if ( bSelect )
{ // is it included in the found sub selection? if ( nSubSelPos < aSels.size() && aSels[ nSubSelPos ].Contains( nIndex ) ) // already selected, nothing to do returnfalse;
// it will become selected
++nSelCount;
// is it at the end of the previous sub selection if ( nSubSelPos > 0 &&
aSels[ nSubSelPos-1 ].Max() == (nIndex-1) )
{ // expand the previous sub selection
aSels[ nSubSelPos-1 ].Max() = nIndex;
// try to merge the previous sub selection
ImplMergeSubSelections( nSubSelPos-1, nSubSelPos );
} // is it at the beginning of the found sub selection elseif ( nSubSelPos < aSels.size()
&& aSels[ nSubSelPos ].Min() == (nIndex+1)
) // expand the found sub selection
aSels[ nSubSelPos ].Min() = nIndex; else
{ // create a new sub selection if ( nSubSelPos < aSels.size() ) {
aSels.insert( aSels.begin() + nSubSelPos, Range( nIndex, nIndex ) );
} else {
aSels.push_back( Range( nIndex, nIndex ) );
} if ( bCurValid && nCurSubSel >= nSubSelPos )
++nCurSubSel;
}
} else
{ // is it excluded from the found sub selection? if ( nSubSelPos >= aSels.size()
|| !aSels[ nSubSelPos ].Contains( nIndex )
) { // not selected, nothing to do returnfalse;
}
// it will become deselected
--nSelCount;
// is it the only index in the found sub selection? if ( aSels[ nSubSelPos ].Len() == 1 )
{ // remove the complete sub selection
aSels.erase( aSels.begin() + nSubSelPos ); returntrue;
}
// is it at the beginning of the found sub selection? if ( aSels[ nSubSelPos ].Min() == nIndex )
++aSels[ nSubSelPos ].Min(); // is it at the end of the found sub selection? elseif ( aSels[ nSubSelPos ].Max() == nIndex )
--aSels[ nSubSelPos ].Max(); // it is in the middle of the found sub selection? else
{ // split the sub selection // we know nSubSelPos < aSels.size() since it's been tested some lines before
aSels.insert( aSels.begin() + nSubSelPos, Range( aSels[ nSubSelPos ].Min(), nIndex-1 ) );
aSels[ nSubSelPos+1 ].Min() = nIndex + 1;
}
}
sal_Int32 nTmpMin = rIndexRange.Min();
sal_Int32 nTmpMax = rIndexRange.Max();
sal_Int32 nCurMin = FirstSelected();
sal_Int32 nCurMax = LastSelected();
DBG_ASSERT(aTotRange.Contains(nTmpMax), "selected index out of range" );
DBG_ASSERT(aTotRange.Contains(nTmpMin), "selected index out of range" );
void MultiSelection::Insert( sal_Int32 nIndex, sal_Int32 nCount )
{ // find the virtual target position
std::size_t nSubSelPos = ImplFindSubSelection( nIndex );
// did we need to shift the sub selections? if ( nSubSelPos < aSels.size() )
{ // did we insert an unselected into an existing sub selection? if ( aSels[ nSubSelPos ].Min() != nIndex
&& aSels[ nSubSelPos ].Contains(nIndex)
) { // split the sub selection
aSels.insert( aSels.begin() + nSubSelPos, Range( aSels[ nSubSelPos ].Min(), nIndex-1 ) );
++nSubSelPos;
aSels[ nSubSelPos ].Min() = nIndex;
}
// shift the sub selections behind the inserting position for ( std::size_t nPos = nSubSelPos; nPos < aSels.size(); ++nPos )
{
aSels[ nPos ].Min() += nCount;
aSels[ nPos ].Max() += nCount;
}
}
bCurValid = false;
aTotRange.Max() += nCount;
}
void MultiSelection::Remove( sal_Int32 nIndex )
{ // find the virtual target position
std::size_t nSubSelPos = ImplFindSubSelection( nIndex );
// did we remove from an existing sub selection? if ( nSubSelPos < aSels.size()
&& aSels[ nSubSelPos ].Contains(nIndex)
) { // does this sub selection only contain the index to be deleted if ( aSels[ nSubSelPos ].Len() == 1 ) { // completely remove the sub selection
aSels.erase( aSels.begin() + nSubSelPos );
} else { // shorten this sub selection
--( aSels[ nSubSelPos++ ].Max() );
}
// adjust the selected counter
--nSelCount;
}
// shift the sub selections behind the removed index for ( std::size_t nPos = nSubSelPos; nPos < aSels.size(); ++nPos )
{
--( aSels[ nPos ].Min() );
--( aSels[ nPos ].Max() );
}
//Even if the input range wasn't completely valid, return what ranges could //be extracted from the input.
o_rPageVector.reserve( static_cast< size_t >( aEnum.size() ) ); for( StringRangeEnumerator::Iterator it = aEnum.begin( i_pPossibleValues );
it != aEnum.end( i_pPossibleValues ); ++it )
{
o_rPageVector.push_back( *it );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.