1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <unocrsr.hxx>
29cdf0e10cSrcweir #include <doc.hxx>
30cdf0e10cSrcweir #include <swtable.hxx>
31cdf0e10cSrcweir #include <docary.hxx>
32cdf0e10cSrcweir #include <rootfrm.hxx>
33cdf0e10cSrcweir
SV_IMPL_PTRARR(SwUnoCrsrTbl,SwUnoCrsrPtr)34cdf0e10cSrcweir SV_IMPL_PTRARR( SwUnoCrsrTbl, SwUnoCrsrPtr )
35cdf0e10cSrcweir
36cdf0e10cSrcweir IMPL_FIXEDMEMPOOL_NEWDEL( SwUnoCrsr, 10, 10 )
37cdf0e10cSrcweir
38cdf0e10cSrcweir SwUnoCrsr::SwUnoCrsr( const SwPosition &rPos, SwPaM* pRing )
39cdf0e10cSrcweir : SwCursor( rPos, pRing, false ), SwModify( 0 ),
40cdf0e10cSrcweir bRemainInSection( sal_True ),
41cdf0e10cSrcweir bSkipOverHiddenSections( sal_False ),
42cdf0e10cSrcweir bSkipOverProtectSections( sal_False )
43cdf0e10cSrcweir
44cdf0e10cSrcweir {}
45cdf0e10cSrcweir
~SwUnoCrsr()46cdf0e10cSrcweir SwUnoCrsr::~SwUnoCrsr()
47cdf0e10cSrcweir {
48cdf0e10cSrcweir SwDoc* pDoc = GetDoc();
49cdf0e10cSrcweir if( !pDoc->IsInDtor() )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir // dann muss der Cursor aus dem Array ausgetragen werden
52cdf0e10cSrcweir SwUnoCrsrTbl& rTbl = (SwUnoCrsrTbl&)pDoc->GetUnoCrsrTbl();
53cdf0e10cSrcweir sal_uInt16 nDelPos = rTbl.GetPos( this );
54cdf0e10cSrcweir
55cdf0e10cSrcweir if( USHRT_MAX != nDelPos )
56cdf0e10cSrcweir rTbl.Remove( nDelPos );
57cdf0e10cSrcweir else {
58cdf0e10cSrcweir ASSERT( !this, "UNO Cursor nicht mehr im Array" );
59cdf0e10cSrcweir }
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
62cdf0e10cSrcweir // den gesamten Ring loeschen!
63cdf0e10cSrcweir while( GetNext() != this )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir Ring* pNxt = GetNext();
66cdf0e10cSrcweir pNxt->MoveTo( 0 ); // ausketten
67cdf0e10cSrcweir delete pNxt; // und loeschen
68cdf0e10cSrcweir }
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
Clone() const71cdf0e10cSrcweir SwUnoCrsr * SwUnoCrsr::Clone() const
72cdf0e10cSrcweir {
73cdf0e10cSrcweir SwUnoCrsr * pNewCrsr = GetDoc()->CreateUnoCrsr( *GetPoint() );
74cdf0e10cSrcweir if (HasMark())
75cdf0e10cSrcweir {
76cdf0e10cSrcweir pNewCrsr->SetMark();
77cdf0e10cSrcweir *pNewCrsr->GetMark() = *GetMark();
78cdf0e10cSrcweir }
79cdf0e10cSrcweir return pNewCrsr;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
Clone() const82cdf0e10cSrcweir SwUnoTableCrsr * SwUnoTableCrsr::Clone() const
83cdf0e10cSrcweir {
84cdf0e10cSrcweir SwUnoTableCrsr * pNewCrsr = dynamic_cast<SwUnoTableCrsr*>(
85cdf0e10cSrcweir GetDoc()->CreateUnoCrsr(
86cdf0e10cSrcweir *GetPoint(), sal_True /* create SwUnoTableCrsr */ ) );
87cdf0e10cSrcweir OSL_ENSURE(pNewCrsr, "Clone: cannot create SwUnoTableCrsr?");
88cdf0e10cSrcweir if (HasMark())
89cdf0e10cSrcweir {
90cdf0e10cSrcweir pNewCrsr->SetMark();
91cdf0e10cSrcweir *pNewCrsr->GetMark() = *GetMark();
92cdf0e10cSrcweir }
93cdf0e10cSrcweir return pNewCrsr;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
96cdf0e10cSrcweir
IsReadOnlyAvailable() const97cdf0e10cSrcweir bool SwUnoCrsr::IsReadOnlyAvailable() const
98cdf0e10cSrcweir {
99cdf0e10cSrcweir return true;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir const SwCntntFrm*
DoSetBidiLevelLeftRight(sal_Bool &,sal_Bool,sal_Bool)103cdf0e10cSrcweir SwUnoCrsr::DoSetBidiLevelLeftRight( sal_Bool &, sal_Bool, sal_Bool )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir return 0; // not for uno cursor
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
DoSetBidiLevelUpDown()108cdf0e10cSrcweir void SwUnoCrsr::DoSetBidiLevelUpDown()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir return; // not for uno cursor
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
IsSelOvr(int eFlags)113cdf0e10cSrcweir sal_Bool SwUnoCrsr::IsSelOvr( int eFlags )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir if( bRemainInSection )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir SwDoc* pDoc = GetDoc();
118cdf0e10cSrcweir SwNodeIndex aOldIdx( *pDoc->GetNodes()[ GetSavePos()->nNode ] );
119cdf0e10cSrcweir SwNodeIndex& rPtIdx = GetPoint()->nNode;
120cdf0e10cSrcweir SwStartNode *pOldSttNd = aOldIdx.GetNode().StartOfSectionNode(),
121cdf0e10cSrcweir *pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
122cdf0e10cSrcweir if( pOldSttNd != pNewSttNd )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir sal_Bool bMoveDown = GetSavePos()->nNode < rPtIdx.GetIndex();
125cdf0e10cSrcweir sal_Bool bValidPos = sal_False;
126cdf0e10cSrcweir
127cdf0e10cSrcweir // search the correct surrounded start node - which the index
128cdf0e10cSrcweir // can't leave.
129cdf0e10cSrcweir while( pOldSttNd->IsSectionNode() )
130cdf0e10cSrcweir pOldSttNd = pOldSttNd->StartOfSectionNode();
131cdf0e10cSrcweir
132cdf0e10cSrcweir // is the new index inside this surrounded section?
133cdf0e10cSrcweir if( rPtIdx > *pOldSttNd &&
134cdf0e10cSrcweir rPtIdx < pOldSttNd->EndOfSectionIndex() )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir // check if it a valid move inside this section
137cdf0e10cSrcweir // (only over SwSection's !)
138cdf0e10cSrcweir const SwStartNode* pInvalidNode;
139cdf0e10cSrcweir do {
140cdf0e10cSrcweir pInvalidNode = 0;
141cdf0e10cSrcweir pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
142cdf0e10cSrcweir
143cdf0e10cSrcweir const SwStartNode *pSttNd = pNewSttNd, *pEndNd = pOldSttNd;
144cdf0e10cSrcweir if( pSttNd->EndOfSectionIndex() >
145cdf0e10cSrcweir pEndNd->EndOfSectionIndex() )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir pEndNd = pNewSttNd;
148cdf0e10cSrcweir pSttNd = pOldSttNd;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
151cdf0e10cSrcweir while( pSttNd->GetIndex() > pEndNd->GetIndex() )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir if( !pSttNd->IsSectionNode() )
154cdf0e10cSrcweir pInvalidNode = pSttNd;
155cdf0e10cSrcweir pSttNd = pSttNd->StartOfSectionNode();
156cdf0e10cSrcweir }
157cdf0e10cSrcweir if( pInvalidNode )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir if( bMoveDown )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir rPtIdx.Assign( *pInvalidNode->EndOfSectionNode(), 1 );
162cdf0e10cSrcweir
163cdf0e10cSrcweir if( !rPtIdx.GetNode().IsCntntNode() &&
164cdf0e10cSrcweir ( !pDoc->GetNodes().GoNextSection( &rPtIdx ) ||
165cdf0e10cSrcweir rPtIdx > pOldSttNd->EndOfSectionIndex() ) )
166cdf0e10cSrcweir break;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir else
169cdf0e10cSrcweir {
170cdf0e10cSrcweir rPtIdx.Assign( *pInvalidNode, -1 );
171cdf0e10cSrcweir
172cdf0e10cSrcweir if( !rPtIdx.GetNode().IsCntntNode() &&
173cdf0e10cSrcweir ( !pDoc->GetNodes().GoPrevSection( &rPtIdx ) ||
174cdf0e10cSrcweir rPtIdx < *pOldSttNd ) )
175cdf0e10cSrcweir break;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir }
178cdf0e10cSrcweir else
179cdf0e10cSrcweir bValidPos = sal_True;
180cdf0e10cSrcweir } while ( pInvalidNode );
181cdf0e10cSrcweir }
182cdf0e10cSrcweir
183cdf0e10cSrcweir if( bValidPos )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir SwCntntNode* pCNd = GetCntntNode();
186cdf0e10cSrcweir sal_uInt16 nCnt = 0;
187cdf0e10cSrcweir if( pCNd && !bMoveDown )
188cdf0e10cSrcweir nCnt = pCNd->Len();
189cdf0e10cSrcweir GetPoint()->nContent.Assign( pCNd, nCnt );
190cdf0e10cSrcweir }
191cdf0e10cSrcweir else
192cdf0e10cSrcweir {
193cdf0e10cSrcweir rPtIdx = GetSavePos()->nNode;
194cdf0e10cSrcweir GetPoint()->nContent.Assign( GetCntntNode(), GetSavePos()->nCntnt );
195cdf0e10cSrcweir return sal_True;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir }
198cdf0e10cSrcweir }
199cdf0e10cSrcweir return SwCursor::IsSelOvr( eFlags );
200cdf0e10cSrcweir }
201cdf0e10cSrcweir
202cdf0e10cSrcweir
203cdf0e10cSrcweir /* */
204cdf0e10cSrcweir
SwUnoTableCrsr(const SwPosition & rPos)205cdf0e10cSrcweir SwUnoTableCrsr::SwUnoTableCrsr(const SwPosition& rPos)
206cdf0e10cSrcweir : SwCursor(rPos,0,false), SwUnoCrsr(rPos), SwTableCursor(rPos), aTblSel(rPos,0,false)
207cdf0e10cSrcweir {
208cdf0e10cSrcweir SetRemainInSection(sal_False);
209cdf0e10cSrcweir }
210cdf0e10cSrcweir
~SwUnoTableCrsr()211cdf0e10cSrcweir SwUnoTableCrsr::~SwUnoTableCrsr()
212cdf0e10cSrcweir {
213cdf0e10cSrcweir while( aTblSel.GetNext() != &aTblSel )
214cdf0e10cSrcweir delete aTblSel.GetNext(); // und loeschen
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
217cdf0e10cSrcweir
218cdf0e10cSrcweir /*
219cdf0e10cSrcweir SwCursor* SwUnoTableCrsr::Create( SwPaM* pRing ) const
220cdf0e10cSrcweir {
221cdf0e10cSrcweir return SwUnoCrsr::Create( pRing );
222cdf0e10cSrcweir }
223cdf0e10cSrcweir */
224cdf0e10cSrcweir
IsSelOvr(int eFlags)225cdf0e10cSrcweir sal_Bool SwUnoTableCrsr::IsSelOvr( int eFlags )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir sal_Bool bRet = SwUnoCrsr::IsSelOvr( eFlags );
228cdf0e10cSrcweir if( !bRet )
229cdf0e10cSrcweir {
230cdf0e10cSrcweir const SwTableNode* pTNd = GetPoint()->nNode.GetNode().FindTableNode();
231cdf0e10cSrcweir bRet = !(pTNd == GetDoc()->GetNodes()[ GetSavePos()->nNode ]->
232cdf0e10cSrcweir FindTableNode() && (!HasMark() ||
233cdf0e10cSrcweir pTNd == GetMark()->nNode.GetNode().FindTableNode() ));
234cdf0e10cSrcweir }
235cdf0e10cSrcweir return bRet;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir
MakeBoxSels()238cdf0e10cSrcweir void SwUnoTableCrsr::MakeBoxSels()
239cdf0e10cSrcweir {
240cdf0e10cSrcweir const SwCntntNode* pCNd;
241cdf0e10cSrcweir bool bMakeTblCrsrs = true;
242cdf0e10cSrcweir if( GetPoint()->nNode.GetIndex() && GetMark()->nNode.GetIndex() &&
243cdf0e10cSrcweir 0 != ( pCNd = GetCntntNode() ) && pCNd->getLayoutFrm( pCNd->GetDoc()->GetCurrentLayout() ) &&
244cdf0e10cSrcweir 0 != ( pCNd = GetCntntNode(sal_False) ) && pCNd->getLayoutFrm( pCNd->GetDoc()->GetCurrentLayout() ) )
245cdf0e10cSrcweir bMakeTblCrsrs = GetDoc()->GetCurrentLayout()->MakeTblCrsrs( *this );
246cdf0e10cSrcweir
247cdf0e10cSrcweir if ( !bMakeTblCrsrs )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir SwSelBoxes& rTmpBoxes = (SwSelBoxes&)GetBoxes();
250cdf0e10cSrcweir sal_uInt16 nCount = 0;
251cdf0e10cSrcweir while( nCount < rTmpBoxes.Count() )
252cdf0e10cSrcweir DeleteBox( nCount );
253cdf0e10cSrcweir }
254cdf0e10cSrcweir
255cdf0e10cSrcweir if( IsChgd() )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir SwTableCursor::MakeBoxSels( &aTblSel );
258cdf0e10cSrcweir if( !GetBoxesCount() )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir const SwTableBox* pBox;
261cdf0e10cSrcweir const SwNode* pBoxNd = GetPoint()->nNode.GetNode().FindTableBoxStartNode();
262cdf0e10cSrcweir const SwTableNode* pTblNd = pBoxNd ? pBoxNd->FindTableNode() : 0;
263cdf0e10cSrcweir if( pTblNd && 0 != ( pBox = pTblNd->GetTable().GetTblBox( pBoxNd->GetIndex() )) )
264cdf0e10cSrcweir InsertBox( *pBox );
265cdf0e10cSrcweir }
266cdf0e10cSrcweir }
267cdf0e10cSrcweir }
268cdf0e10cSrcweir
269