Files
libreoffice/svx/source/outliner/paralist.cxx

233 lines
6.1 KiB
C++
Raw Normal View History

2000-09-18 16:07:07 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 16:07:07 +00:00
*
* Copyright 2008 by Sun Microsystems, Inc.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 16:07:07 +00:00
*
* $RCSfile: paralist.cxx,v $
* $Revision: 1.9 $
2000-09-18 16:07:07 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 16:07:07 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 16:07:07 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"
2000-09-18 16:07:07 +00:00
#include <paralist.hxx>
#include <svx/outliner.hxx> // nur wegen Paragraph, muss geaendert werden!
#include <svx/numdef.hxx>
2000-09-18 16:07:07 +00:00
DBG_NAME(Paragraph)
2000-09-18 16:07:07 +00:00
Paragraph::Paragraph( USHORT nDDepth )
: aBulSize( -1, -1)
{
DBG_CTOR( Paragraph, 0 );
2001-06-21 12:03:30 +00:00
DBG_ASSERT( ( nDDepth < SVX_MAX_NUM ) || ( nDDepth == 0xFFFF ), "Paragraph-CTOR: nDepth invalid!" );
2001-05-30 16:23:37 +00:00
2000-09-18 16:07:07 +00:00
nDepth = nDDepth;
nFlags = 0;
bVisible = TRUE;
}
Paragraph::Paragraph( const Paragraph& rPara )
: aBulText( rPara.aBulText )
, aBulSize( rPara.aBulSize )
2000-09-18 16:07:07 +00:00
{
DBG_CTOR( Paragraph, 0 );
nDepth = rPara.nDepth;
nFlags = rPara.nFlags;
bVisible = rPara.bVisible;
}
Paragraph::~Paragraph()
{
DBG_DTOR( Paragraph, 0 );
}
void ParagraphList::Clear( BOOL bDestroyParagraphs )
{
if ( bDestroyParagraphs )
{
for ( ULONG n = GetParagraphCount(); n; )
{
Paragraph* pPara = GetParagraph( --n );
delete pPara;
}
}
List::Clear();
}
void ParagraphList::MoveParagraphs( ULONG nStart, ULONG nDest, ULONG _nCount )
2000-09-18 16:07:07 +00:00
{
if ( ( nDest < nStart ) || ( nDest >= ( nStart + _nCount ) ) )
2000-09-18 16:07:07 +00:00
{
ULONG n;
ParagraphList aParas;
for ( n = 0; n < _nCount; n++ )
2000-09-18 16:07:07 +00:00
{
Paragraph* pPara = GetParagraph( nStart );
aParas.Insert( pPara, LIST_APPEND );
Remove( nStart );
}
if ( nDest > nStart )
nDest -= _nCount;
2000-09-18 16:07:07 +00:00
for ( n = 0; n < _nCount; n++ )
2000-09-18 16:07:07 +00:00
{
Paragraph* pPara = aParas.GetParagraph( n );
Insert( pPara, nDest++ );
}
}
else
DBG_ERROR( "MoveParagraphs: Invalid Parameters" );
}
Paragraph* ParagraphList::NextVisible( Paragraph* pPara ) const
{
ULONG n = GetAbsPos( pPara );
Paragraph* p = GetParagraph( ++n );
while ( p && !p->IsVisible() )
p = GetParagraph( ++n );
return p;
}
Paragraph* ParagraphList::PrevVisible( Paragraph* pPara ) const
{
ULONG n = GetAbsPos( pPara );
Paragraph* p = n ? GetParagraph( --n ) : NULL;
while ( p && !p->IsVisible() )
p = n ? GetParagraph( --n ) : NULL;
return p;
}
Paragraph* ParagraphList::LastVisible() const
{
ULONG n = GetParagraphCount();
Paragraph* p = n ? GetParagraph( --n ) : NULL;
while ( p && !p->IsVisible() )
p = n ? GetParagraph( --n ) : NULL;
return p;
}
BOOL ParagraphList::HasChilds( Paragraph* pParagraph ) const
{
ULONG n = GetAbsPos( pParagraph );
Paragraph* pNext = GetParagraph( ++n );
return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) ) ? TRUE : FALSE;
}
BOOL ParagraphList::HasHiddenChilds( Paragraph* pParagraph ) const
{
ULONG n = GetAbsPos( pParagraph );
Paragraph* pNext = GetParagraph( ++n );
return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && !pNext->IsVisible() ) ? TRUE : FALSE;
}
BOOL ParagraphList::HasVisibleChilds( Paragraph* pParagraph ) const
{
ULONG n = GetAbsPos( pParagraph );
Paragraph* pNext = GetParagraph( ++n );
return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && pNext->IsVisible() ) ? TRUE : FALSE;
}
ULONG ParagraphList::GetChildCount( Paragraph* pParent ) const
{
ULONG nChildCount = 0;
ULONG n = GetAbsPos( pParent );
Paragraph* pPara = GetParagraph( ++n );
while ( pPara && ( pPara->GetDepth() > pParent->GetDepth() ) )
{
nChildCount++;
pPara = GetParagraph( ++n );
}
return nChildCount;
}
Paragraph* ParagraphList::GetParent( Paragraph* pParagraph, USHORT& rRelPos ) const
{
rRelPos = 0;
ULONG n = GetAbsPos( pParagraph );
Paragraph* pPrev = GetParagraph( --n );
while ( pPrev && ( pPrev->GetDepth() >= pParagraph->GetDepth() ) )
{
if ( pPrev->GetDepth() == pParagraph->GetDepth() )
rRelPos++;
pPrev = GetParagraph( --n );
}
return pPrev;
}
void ParagraphList::Expand( Paragraph* pParent )
{
ULONG nChildCount = GetChildCount( pParent );
ULONG nPos = GetAbsPos( pParent );
for ( ULONG n = 1; n <= nChildCount; n++ )
{
Paragraph* pPara = GetParagraph( nPos+n );
if ( !( pPara->IsVisible() ) )
{
pPara->bVisible = TRUE;
aVisibleStateChangedHdl.Call( pPara );
}
}
}
void ParagraphList::Collapse( Paragraph* pParent )
{
ULONG nChildCount = GetChildCount( pParent );
ULONG nPos = GetAbsPos( pParent );
for ( ULONG n = 1; n <= nChildCount; n++ )
{
Paragraph* pPara = GetParagraph( nPos+n );
if ( pPara->IsVisible() )
{
pPara->bVisible = FALSE;
aVisibleStateChangedHdl.Call( pPara );
}
}
}
ULONG ParagraphList::GetVisPos( Paragraph* pPara )
{
ULONG nVisPos = 0;
ULONG nPos = GetAbsPos( pPara );
for ( ULONG n = 0; n < nPos; n++ )
{
Paragraph* _pPara = GetParagraph( n );
if ( _pPara->IsVisible() )
2000-09-18 16:07:07 +00:00
nVisPos++;
}
return nVisPos;
}