1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unocrsr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <unocrsr.hxx>
37 #include <swtable.hxx>
39 #include <rootfrm.hxx>
41 SV_IMPL_PTRARR( SwUnoCrsrTbl
, SwUnoCrsrPtr
)
43 IMPL_FIXEDMEMPOOL_NEWDEL( SwUnoCrsr
, 10, 10 )
45 SwUnoCrsr::SwUnoCrsr( const SwPosition
&rPos
, SwPaM
* pRing
)
46 : SwCursor( rPos
, pRing
, false ), SwModify( 0 ),
47 bRemainInSection( TRUE
),
48 bSkipOverHiddenSections( FALSE
),
49 bSkipOverProtectSections( FALSE
)
53 // @@@ semantic: no copy ctor.
54 SwUnoCrsr::SwUnoCrsr( SwUnoCrsr
& rICrsr
)
55 : SwCursor( rICrsr
), SwModify( 0 ),
56 bRemainInSection( rICrsr
.bRemainInSection
),
57 bSkipOverHiddenSections( rICrsr
.bSkipOverHiddenSections
),
58 bSkipOverProtectSections( rICrsr
.bSkipOverProtectSections
)
61 SwUnoCrsr::~SwUnoCrsr()
63 SwDoc
* pDoc
= GetDoc();
64 if( !pDoc
->IsInDtor() )
66 // dann muss der Cursor aus dem Array ausgetragen werden
67 SwUnoCrsrTbl
& rTbl
= (SwUnoCrsrTbl
&)pDoc
->GetUnoCrsrTbl();
68 USHORT nDelPos
= rTbl
.GetPos( this );
70 if( USHRT_MAX
!= nDelPos
)
71 rTbl
.Remove( nDelPos
);
73 ASSERT( !this, "UNO Cursor nicht mehr im Array" );
77 // den gesamten Ring loeschen!
78 while( GetNext() != this )
80 Ring
* pNxt
= GetNext();
81 pNxt
->MoveTo( 0 ); // ausketten
82 delete pNxt
; // und loeschen
86 SwUnoCrsr
* SwUnoCrsr::Clone() const
88 SwUnoCrsr
* pNewCrsr
= GetDoc()->CreateUnoCrsr( *GetPoint() );
92 *pNewCrsr
->GetMark() = *GetMark();
97 SwUnoTableCrsr
* SwUnoTableCrsr::Clone() const
99 SwUnoTableCrsr
* pNewCrsr
= dynamic_cast<SwUnoTableCrsr
*>(
100 GetDoc()->CreateUnoCrsr(
101 *GetPoint(), sal_True
/* create SwUnoTableCrsr */ ) );
102 OSL_ENSURE(pNewCrsr
, "Clone: cannot create SwUnoTableCrsr?");
106 *pNewCrsr
->GetMark() = *GetMark();
112 bool SwUnoCrsr::IsReadOnlyAvailable() const
118 SwUnoCrsr::DoSetBidiLevelLeftRight( BOOL
&, BOOL
, BOOL
)
120 return 0; // not for uno cursor
123 void SwUnoCrsr::DoSetBidiLevelUpDown()
125 return; // not for uno cursor
128 BOOL
SwUnoCrsr::IsSelOvr( int eFlags
)
130 if( bRemainInSection
)
132 SwDoc
* pDoc
= GetDoc();
133 SwNodeIndex
aOldIdx( *pDoc
->GetNodes()[ GetSavePos()->nNode
] );
134 SwNodeIndex
& rPtIdx
= GetPoint()->nNode
;
135 SwStartNode
*pOldSttNd
= aOldIdx
.GetNode().StartOfSectionNode(),
136 *pNewSttNd
= rPtIdx
.GetNode().StartOfSectionNode();
137 if( pOldSttNd
!= pNewSttNd
)
139 BOOL bMoveDown
= GetSavePos()->nNode
< rPtIdx
.GetIndex();
140 BOOL bValidPos
= FALSE
;
142 // search the correct surrounded start node - which the index
144 while( pOldSttNd
->IsSectionNode() )
145 pOldSttNd
= pOldSttNd
->StartOfSectionNode();
147 // is the new index inside this surrounded section?
148 if( rPtIdx
> *pOldSttNd
&&
149 rPtIdx
< pOldSttNd
->EndOfSectionIndex() )
151 // check if it a valid move inside this section
152 // (only over SwSection's !)
153 const SwStartNode
* pInvalidNode
;
156 pNewSttNd
= rPtIdx
.GetNode().StartOfSectionNode();
158 const SwStartNode
*pSttNd
= pNewSttNd
, *pEndNd
= pOldSttNd
;
159 if( pSttNd
->EndOfSectionIndex() >
160 pEndNd
->EndOfSectionIndex() )
166 while( pSttNd
->GetIndex() > pEndNd
->GetIndex() )
168 if( !pSttNd
->IsSectionNode() )
169 pInvalidNode
= pSttNd
;
170 pSttNd
= pSttNd
->StartOfSectionNode();
176 rPtIdx
.Assign( *pInvalidNode
->EndOfSectionNode(), 1 );
178 if( !rPtIdx
.GetNode().IsCntntNode() &&
179 ( !pDoc
->GetNodes().GoNextSection( &rPtIdx
) ||
180 rPtIdx
> pOldSttNd
->EndOfSectionIndex() ) )
185 rPtIdx
.Assign( *pInvalidNode
, -1 );
187 if( !rPtIdx
.GetNode().IsCntntNode() &&
188 ( !pDoc
->GetNodes().GoPrevSection( &rPtIdx
) ||
189 rPtIdx
< *pOldSttNd
) )
195 } while ( pInvalidNode
);
200 SwCntntNode
* pCNd
= GetCntntNode();
202 if( pCNd
&& !bMoveDown
)
204 GetPoint()->nContent
.Assign( pCNd
, nCnt
);
208 rPtIdx
= GetSavePos()->nNode
;
209 GetPoint()->nContent
.Assign( GetCntntNode(), GetSavePos()->nCntnt
);
214 return SwCursor::IsSelOvr( eFlags
);
220 SwUnoTableCrsr::SwUnoTableCrsr(const SwPosition
& rPos
)
221 : SwCursor(rPos
,0,false), SwUnoCrsr(rPos
), SwTableCursor(rPos
), aTblSel(rPos
,0,false)
223 SetRemainInSection(FALSE
);
226 SwUnoTableCrsr::~SwUnoTableCrsr()
228 while( aTblSel
.GetNext() != &aTblSel
)
229 delete aTblSel
.GetNext(); // und loeschen
234 SwCursor* SwUnoTableCrsr::Create( SwPaM* pRing ) const
236 return SwUnoCrsr::Create( pRing );
240 BOOL
SwUnoTableCrsr::IsSelOvr( int eFlags
)
242 BOOL bRet
= SwUnoCrsr::IsSelOvr( eFlags
);
245 const SwTableNode
* pTNd
= GetPoint()->nNode
.GetNode().FindTableNode();
246 bRet
= !(pTNd
== GetDoc()->GetNodes()[ GetSavePos()->nNode
]->
247 FindTableNode() && (!HasMark() ||
248 pTNd
== GetMark()->nNode
.GetNode().FindTableNode() ));
253 void SwUnoTableCrsr::MakeBoxSels()
255 const SwCntntNode
* pCNd
;
256 bool bMakeTblCrsrs
= true;
257 if( GetPoint()->nNode
.GetIndex() && GetMark()->nNode
.GetIndex() &&
258 0 != ( pCNd
= GetCntntNode() ) && pCNd
->GetFrm() &&
259 0 != ( pCNd
= GetCntntNode(FALSE
) ) && pCNd
->GetFrm() )
260 bMakeTblCrsrs
= GetDoc()->GetRootFrm()->MakeTblCrsrs( *this );
262 if ( !bMakeTblCrsrs
)
264 SwSelBoxes
& rTmpBoxes
= (SwSelBoxes
&)GetBoxes();
266 while( nCount
< rTmpBoxes
.Count() )
272 SwTableCursor::MakeBoxSels( &aTblSel
);
273 if( !GetBoxesCount() )
275 const SwTableBox
* pBox
;
276 const SwNode
* pBoxNd
= GetPoint()->nNode
.GetNode().FindTableBoxStartNode();
277 const SwTableNode
* pTblNd
= pBoxNd
? pBoxNd
->FindTableNode() : 0;
278 if( pTblNd
&& 0 != ( pBox
= pTblNd
->GetTable().GetTblBox( pBoxNd
->GetIndex() )) )