Files
libreoffice/sw/source/core/crsr/unocrsr.cxx

266 lines
8.5 KiB
C++
Raw Normal View History

2000-09-18 23:08:29 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 23:08:29 +00:00
*
* Copyright 2008 by Sun Microsystems, Inc.
2000-09-18 23:08:29 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 23:08:29 +00:00
*
* $RCSfile: unocrsr.cxx,v $
* $Revision: 1.18 $
2000-09-18 23:08:29 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 23:08:29 +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 23:08:29 +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 23:08:29 +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 23:08:29 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
2000-09-18 23:08:29 +00:00
#include <unocrsr.hxx>
#include <doc.hxx>
#include <swtable.hxx>
#include <docary.hxx>
#include <rootfrm.hxx>
SV_IMPL_PTRARR( SwUnoCrsrTbl, SwUnoCrsrPtr )
IMPL_FIXEDMEMPOOL_NEWDEL( SwUnoCrsr, 10, 10 )
SwUnoCrsr::SwUnoCrsr( const SwPosition &rPos, SwPaM* pRing )
: SwCursor( rPos, pRing, false ), SwModify( 0 ),
bRemainInSection( TRUE ),
bSkipOverHiddenSections( FALSE ),
bSkipOverProtectSections( FALSE )
2000-09-18 23:08:29 +00:00
{}
// @@@ semantic: no copy ctor.
2000-09-18 23:08:29 +00:00
SwUnoCrsr::SwUnoCrsr( SwUnoCrsr& rICrsr )
: SwCursor( rICrsr ), SwModify( 0 ),
bRemainInSection( rICrsr.bRemainInSection ),
bSkipOverHiddenSections( rICrsr.bSkipOverHiddenSections ),
bSkipOverProtectSections( rICrsr.bSkipOverProtectSections )
2000-09-18 23:08:29 +00:00
{}
SwUnoCrsr::~SwUnoCrsr()
{
SwDoc* pDoc = GetDoc();
if( !pDoc->IsInDtor() )
{
// dann muss der Cursor aus dem Array ausgetragen werden
SwUnoCrsrTbl& rTbl = (SwUnoCrsrTbl&)pDoc->GetUnoCrsrTbl();
USHORT nDelPos = rTbl.GetPos( this );
if( USHRT_MAX != nDelPos )
rTbl.Remove( nDelPos );
else {
2000-09-18 23:08:29 +00:00
ASSERT( !this, "UNO Cursor nicht mehr im Array" );
}
2000-09-18 23:08:29 +00:00
}
// den gesamten Ring loeschen!
while( GetNext() != this )
{
Ring* pNxt = GetNext();
pNxt->MoveTo( 0 ); // ausketten
delete pNxt; // und loeschen
}
}
SwUnoCrsr * SwUnoCrsr::Clone() const
{
SwUnoCrsr * pNewCrsr = 0;
// check if the cursor is a SwUnoTableCrsr, if so clone that type
const SwUnoTableCrsr * pUnoTableCrsr = *this;
if (pUnoTableCrsr)
pNewCrsr = GetDoc()->CreateUnoCrsr( *GetPoint(), sal_True /* create SwUnoTableCrsr */ );
else
pNewCrsr = GetDoc()->CreateUnoCrsr( *GetPoint() );
if (HasMark())
{
pNewCrsr->SetMark();
*pNewCrsr->GetMark() = *GetMark();
}
return pNewCrsr;
}
2000-09-18 23:08:29 +00:00
SwUnoCrsr::operator SwUnoCrsr* () { return this; }
BOOL SwUnoCrsr::IsSelOvr( int eFlags )
2000-09-18 23:08:29 +00:00
{
if( bRemainInSection )
{
SwDoc* pDoc = GetDoc();
SwNodeIndex aOldIdx( *pDoc->GetNodes()[ GetSavePos()->nNode ] );
SwNodeIndex& rPtIdx = GetPoint()->nNode;
SwStartNode *pOldSttNd = aOldIdx.GetNode().StartOfSectionNode(),
*pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
2000-09-18 23:08:29 +00:00
if( pOldSttNd != pNewSttNd )
{
BOOL bMoveDown = GetSavePos()->nNode < rPtIdx.GetIndex();
BOOL bValidPos = FALSE;
// search the correct surrounded start node - which the index
// can't leave.
while( pOldSttNd->IsSectionNode() )
pOldSttNd = pOldSttNd->StartOfSectionNode();
// is the new index inside this surrounded section?
if( rPtIdx > *pOldSttNd &&
rPtIdx < pOldSttNd->EndOfSectionIndex() )
2000-09-18 23:08:29 +00:00
{
// check if it a valid move inside this section
// (only over SwSection's !)
const SwStartNode* pInvalidNode;
do {
pInvalidNode = 0;
pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
const SwStartNode *pSttNd = pNewSttNd, *pEndNd = pOldSttNd;
if( pSttNd->EndOfSectionIndex() >
pEndNd->EndOfSectionIndex() )
2000-09-18 23:08:29 +00:00
{
pEndNd = pNewSttNd;
pSttNd = pOldSttNd;
2000-09-18 23:08:29 +00:00
}
while( pSttNd->GetIndex() > pEndNd->GetIndex() )
2000-09-18 23:08:29 +00:00
{
if( !pSttNd->IsSectionNode() )
pInvalidNode = pSttNd;
pSttNd = pSttNd->StartOfSectionNode();
2000-09-18 23:08:29 +00:00
}
if( pInvalidNode )
{
if( bMoveDown )
{
rPtIdx.Assign( *pInvalidNode->EndOfSectionNode(), 1 );
if( !rPtIdx.GetNode().IsCntntNode() &&
( !pDoc->GetNodes().GoNextSection( &rPtIdx ) ||
rPtIdx > pOldSttNd->EndOfSectionIndex() ) )
break;
}
else
{
rPtIdx.Assign( *pInvalidNode, -1 );
if( !rPtIdx.GetNode().IsCntntNode() &&
( !pDoc->GetNodes().GoPrevSection( &rPtIdx ) ||
rPtIdx < *pOldSttNd ) )
break;
}
}
else
bValidPos = TRUE;
} while ( pInvalidNode );
2000-09-18 23:08:29 +00:00
}
if( bValidPos )
{
SwCntntNode* pCNd = GetCntntNode();
USHORT nCnt = 0;
if( pCNd && !bMoveDown )
nCnt = pCNd->Len();
GetPoint()->nContent.Assign( pCNd, nCnt );
}
else
{
rPtIdx = GetSavePos()->nNode;
GetPoint()->nContent.Assign( GetCntntNode(), GetSavePos()->nCntnt );
return TRUE;
}
}
}
return SwCursor::IsSelOvr( eFlags );
}
/* */
SwUnoTableCrsr::SwUnoTableCrsr(const SwPosition& rPos)
: SwCursor(rPos,0,false), SwUnoCrsr(rPos), SwTableCursor(rPos), aTblSel(rPos,0,false)
2000-09-18 23:08:29 +00:00
{
SetRemainInSection(FALSE);
2000-09-18 23:08:29 +00:00
}
SwUnoTableCrsr::~SwUnoTableCrsr()
{
while( aTblSel.GetNext() != &aTblSel )
delete aTblSel.GetNext(); // und loeschen
}
SwUnoTableCrsr::operator SwUnoCrsr* () { return this; }
SwUnoTableCrsr::operator SwTableCursor* () { return this; }
SwUnoTableCrsr::operator SwUnoTableCrsr* () { return this; }
/*
SwCursor* SwUnoTableCrsr::Create( SwPaM* pRing ) const
{
return SwUnoCrsr::Create( pRing );
}
*/
BOOL SwUnoTableCrsr::IsSelOvr( int eFlags )
2000-09-18 23:08:29 +00:00
{
BOOL bRet = SwUnoCrsr::IsSelOvr( eFlags );
2000-09-18 23:08:29 +00:00
if( !bRet )
{
const SwTableNode* pTNd = GetPoint()->nNode.GetNode().FindTableNode();
bRet = !(pTNd == GetDoc()->GetNodes()[ GetSavePos()->nNode ]->
FindTableNode() && (!HasMark() ||
pTNd == GetMark()->nNode.GetNode().FindTableNode() ));
}
return bRet;
}
void SwUnoTableCrsr::MakeBoxSels()
{
const SwCntntNode* pCNd;
bool bMakeTblCrsrs = true;
2000-09-18 23:08:29 +00:00
if( GetPoint()->nNode.GetIndex() && GetMark()->nNode.GetIndex() &&
0 != ( pCNd = GetCntntNode() ) && pCNd->GetFrm() &&
0 != ( pCNd = GetCntntNode(FALSE) ) && pCNd->GetFrm() )
bMakeTblCrsrs = GetDoc()->GetRootFrm()->MakeTblCrsrs( *this );
if ( !bMakeTblCrsrs )
{
SwSelBoxes& rTmpBoxes = (SwSelBoxes&)GetBoxes();
USHORT nCount = 0;
while( nCount < rTmpBoxes.Count() )
DeleteBox( nCount );
}
2000-09-18 23:08:29 +00:00
if( IsChgd() )
{
SwTableCursor::MakeBoxSels( &aTblSel );
if( !GetBoxesCount() )
{
const SwTableBox* pBox;
const SwNode* pBoxNd = GetPoint()->nNode.GetNode().FindTableBoxStartNode();
const SwTableNode* pTblNd = pBoxNd ? pBoxNd->FindTableNode() : 0;
if( pTblNd && 0 != ( pBox = pTblNd->GetTable().GetTblBox( pBoxNd->GetIndex() )) )
InsertBox( *pBox );
}
}
}