Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <unocrsr.hxx>
21 : #include <doc.hxx>
22 : #include <swtable.hxx>
23 : #include <docary.hxx>
24 : #include <rootfrm.hxx>
25 :
26 10 : IMPL_FIXEDMEMPOOL_NEWDEL( SwUnoCrsr )
27 :
28 5050 : SwUnoCrsr::SwUnoCrsr( const SwPosition &rPos, SwPaM* pRing )
29 : : SwCursor( rPos, pRing, false ), SwModify( 0 ),
30 : bRemainInSection( sal_True ),
31 : bSkipOverHiddenSections( sal_False ),
32 5050 : bSkipOverProtectSections( sal_False )
33 :
34 5050 : {}
35 :
36 20180 : SwUnoCrsr::~SwUnoCrsr()
37 : {
38 5046 : SwDoc* pDoc = GetDoc();
39 5046 : if( !pDoc->IsInDtor() )
40 : {
41 : // then remove cursor from array
42 5046 : SwUnoCrsrTbl& rTbl = (SwUnoCrsrTbl&)pDoc->GetUnoCrsrTbl();
43 5046 : if( !rTbl.erase( this ) )
44 : {
45 : OSL_ENSURE( !this, "UNO Cursor nicht mehr im Array" );
46 : }
47 : }
48 :
49 : // delete the whole ring
50 10092 : while( GetNext() != this )
51 : {
52 0 : Ring* pNxt = GetNext();
53 0 : pNxt->MoveTo( 0 ); // remove from chain
54 0 : delete pNxt; // and delete
55 : }
56 15136 : }
57 :
58 0 : SwUnoCrsr * SwUnoCrsr::Clone() const
59 : {
60 0 : SwUnoCrsr * pNewCrsr = GetDoc()->CreateUnoCrsr( *GetPoint() );
61 0 : if (HasMark())
62 : {
63 0 : pNewCrsr->SetMark();
64 0 : *pNewCrsr->GetMark() = *GetMark();
65 : }
66 0 : return pNewCrsr;
67 : }
68 :
69 0 : SwUnoTableCrsr * SwUnoTableCrsr::Clone() const
70 : {
71 : SwUnoTableCrsr * pNewCrsr = dynamic_cast<SwUnoTableCrsr*>(
72 : GetDoc()->CreateUnoCrsr(
73 0 : *GetPoint(), true /* create SwUnoTableCrsr */ ) );
74 : OSL_ENSURE(pNewCrsr, "Clone: cannot create SwUnoTableCrsr?");
75 0 : if (HasMark())
76 : {
77 0 : pNewCrsr->SetMark();
78 0 : *pNewCrsr->GetMark() = *GetMark();
79 : }
80 0 : return pNewCrsr;
81 : }
82 :
83 :
84 0 : bool SwUnoCrsr::IsReadOnlyAvailable() const
85 : {
86 0 : return true;
87 : }
88 :
89 : const SwCntntFrm*
90 1416 : SwUnoCrsr::DoSetBidiLevelLeftRight( sal_Bool &, sal_Bool, sal_Bool )
91 : {
92 1416 : return 0; // not for uno cursor
93 : }
94 :
95 0 : void SwUnoCrsr::DoSetBidiLevelUpDown()
96 : {
97 0 : return; // not for uno cursor
98 : }
99 :
100 1799 : sal_Bool SwUnoCrsr::IsSelOvr( int eFlags )
101 : {
102 1799 : if( bRemainInSection )
103 : {
104 1650 : SwDoc* pDoc = GetDoc();
105 1650 : SwNodeIndex aOldIdx( *pDoc->GetNodes()[ GetSavePos()->nNode ] );
106 1650 : SwNodeIndex& rPtIdx = GetPoint()->nNode;
107 1650 : SwStartNode *pOldSttNd = aOldIdx.GetNode().StartOfSectionNode(),
108 1650 : *pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
109 1650 : if( pOldSttNd != pNewSttNd )
110 : {
111 122 : bool bMoveDown = GetSavePos()->nNode < rPtIdx.GetIndex();
112 122 : bool bValidPos = false;
113 :
114 : // search the correct surrounded start node - which the index
115 : // can't leave.
116 245 : while( pOldSttNd->IsSectionNode() )
117 1 : pOldSttNd = pOldSttNd->StartOfSectionNode();
118 :
119 : // is the new index inside this surrounded section?
120 244 : if( rPtIdx > *pOldSttNd &&
121 122 : rPtIdx < pOldSttNd->EndOfSectionIndex() )
122 : {
123 : // check if it a valid move inside this section
124 : // (only over SwSection's !)
125 : const SwStartNode* pInvalidNode;
126 5 : do {
127 7 : pInvalidNode = 0;
128 7 : pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
129 :
130 7 : const SwStartNode *pSttNd = pNewSttNd, *pEndNd = pOldSttNd;
131 14 : if( pSttNd->EndOfSectionIndex() >
132 7 : pEndNd->EndOfSectionIndex() )
133 : {
134 0 : pEndNd = pNewSttNd;
135 0 : pSttNd = pOldSttNd;
136 : }
137 :
138 22 : while( pSttNd->GetIndex() > pEndNd->GetIndex() )
139 : {
140 8 : if( !pSttNd->IsSectionNode() )
141 4 : pInvalidNode = pSttNd;
142 8 : pSttNd = pSttNd->StartOfSectionNode();
143 : }
144 7 : if( pInvalidNode )
145 : {
146 2 : if( bMoveDown )
147 : {
148 0 : rPtIdx.Assign( *pInvalidNode->EndOfSectionNode(), 1 );
149 :
150 0 : if( !rPtIdx.GetNode().IsCntntNode() &&
151 0 : ( !pDoc->GetNodes().GoNextSection( &rPtIdx ) ||
152 0 : rPtIdx > pOldSttNd->EndOfSectionIndex() ) )
153 0 : break;
154 : }
155 : else
156 : {
157 2 : rPtIdx.Assign( *pInvalidNode, -1 );
158 :
159 8 : if( !rPtIdx.GetNode().IsCntntNode() &&
160 2 : ( !pDoc->GetNodes().GoPrevSection( &rPtIdx ) ||
161 4 : rPtIdx < *pOldSttNd ) )
162 2 : break;
163 : }
164 : }
165 : else
166 5 : bValidPos = true;
167 : } while ( pInvalidNode );
168 : }
169 :
170 122 : if( bValidPos )
171 : {
172 5 : SwCntntNode* pCNd = GetCntntNode();
173 5 : sal_uInt16 nCnt = 0;
174 5 : if( pCNd && !bMoveDown )
175 4 : nCnt = pCNd->Len();
176 5 : GetPoint()->nContent.Assign( pCNd, nCnt );
177 : }
178 : else
179 : {
180 117 : rPtIdx = GetSavePos()->nNode;
181 117 : GetPoint()->nContent.Assign( GetCntntNode(), GetSavePos()->nCntnt );
182 117 : return sal_True;
183 : }
184 1650 : }
185 : }
186 1682 : return SwCursor::IsSelOvr( eFlags );
187 : }
188 :
189 :
190 :
191 2 : SwUnoTableCrsr::SwUnoTableCrsr(const SwPosition& rPos)
192 2 : : SwCursor(rPos,0,false), SwUnoCrsr(rPos), SwTableCursor(rPos), aTblSel(rPos,0,false)
193 : {
194 2 : SetRemainInSection(sal_False);
195 2 : }
196 :
197 12 : SwUnoTableCrsr::~SwUnoTableCrsr()
198 : {
199 7 : while( aTblSel.GetNext() != &aTblSel )
200 3 : delete aTblSel.GetNext();
201 10 : }
202 :
203 0 : sal_Bool SwUnoTableCrsr::IsSelOvr( int eFlags )
204 : {
205 0 : sal_Bool bRet = SwUnoCrsr::IsSelOvr( eFlags );
206 0 : if( !bRet )
207 : {
208 0 : const SwTableNode* pTNd = GetPoint()->nNode.GetNode().FindTableNode();
209 0 : bRet = !(pTNd == GetDoc()->GetNodes()[ GetSavePos()->nNode ]->
210 0 : FindTableNode() && (!HasMark() ||
211 0 : pTNd == GetMark()->nNode.GetNode().FindTableNode() ));
212 : }
213 0 : return bRet;
214 : }
215 :
216 2 : void SwUnoTableCrsr::MakeBoxSels()
217 : {
218 : const SwCntntNode* pCNd;
219 2 : bool bMakeTblCrsrs = true;
220 10 : if( GetPoint()->nNode.GetIndex() && GetMark()->nNode.GetIndex() &&
221 4 : 0 != ( pCNd = GetCntntNode() ) && pCNd->getLayoutFrm( pCNd->GetDoc()->GetCurrentLayout() ) &&
222 4 : 0 != ( pCNd = GetCntntNode(sal_False) ) && pCNd->getLayoutFrm( pCNd->GetDoc()->GetCurrentLayout() ) )
223 2 : bMakeTblCrsrs = GetDoc()->GetCurrentLayout()->MakeTblCrsrs( *this );
224 :
225 2 : if ( !bMakeTblCrsrs )
226 : {
227 0 : SwSelBoxes const& rTmpBoxes = GetSelectedBoxes();
228 0 : while (!rTmpBoxes.empty())
229 : {
230 0 : DeleteBox(0);
231 : }
232 : }
233 :
234 2 : if( IsChgd() )
235 : {
236 2 : SwTableCursor::MakeBoxSels( &aTblSel );
237 2 : if (!GetSelectedBoxesCount())
238 : {
239 : const SwTableBox* pBox;
240 0 : const SwNode* pBoxNd = GetPoint()->nNode.GetNode().FindTableBoxStartNode();
241 0 : const SwTableNode* pTblNd = pBoxNd ? pBoxNd->FindTableNode() : 0;
242 0 : if( pTblNd && 0 != ( pBox = pTblNd->GetTable().GetTblBox( pBoxNd->GetIndex() )) )
243 0 : InsertBox( *pBox );
244 : }
245 : }
246 2 : }
247 :
248 204 : SwUnoCrsrTbl::~SwUnoCrsrTbl()
249 : {
250 204 : while (!empty())
251 : {
252 0 : delete *begin();
253 0 : erase( begin() );
254 : }
255 132 : }
256 :
257 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|