Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/util/SearchOptions.hpp>
30 : : #include <com/sun/star/text/XTextRange.hpp>
31 : : #include <hintids.hxx>
32 : : #include <svx/svdmodel.hxx>
33 : : #include <editeng/frmdiritem.hxx>
34 : :
35 : : #include <SwSmartTagMgr.hxx>
36 : : #include <doc.hxx>
37 : : #include <rootfrm.hxx>
38 : : #include <pagefrm.hxx>
39 : : #include <cntfrm.hxx>
40 : : #include <viewimp.hxx>
41 : : #include <pam.hxx>
42 : : #include <swselectionlist.hxx>
43 : : #include <IBlockCursor.hxx>
44 : : #include "BlockCursor.hxx"
45 : : #include <ndtxt.hxx>
46 : : #include <flyfrm.hxx>
47 : : #include <dview.hxx>
48 : : #include <viewopt.hxx>
49 : : #include <frmtool.hxx>
50 : : #include <crsrsh.hxx>
51 : : #include <tabfrm.hxx>
52 : : #include <txtfrm.hxx>
53 : : #include <sectfrm.hxx>
54 : : #include <swtable.hxx>
55 : : #include <callnk.hxx>
56 : : #include <viscrs.hxx>
57 : : #include <section.hxx>
58 : : #include <docsh.hxx>
59 : : #include <scriptinfo.hxx>
60 : : #include <globdoc.hxx>
61 : : #include <pamtyp.hxx>
62 : : #include <mdiexp.hxx>
63 : : #include <fmteiro.hxx>
64 : : #include <wrong.hxx>
65 : : #include <unotextrange.hxx>
66 : : #include <vcl/svapp.hxx>
67 : : #include <numrule.hxx>
68 : : #include <IGrammarContact.hxx>
69 : :
70 : : #include <globals.hrc>
71 : :
72 : : #include <comcore.hrc>
73 : :
74 : : using namespace com::sun::star;
75 : : using namespace util;
76 : :
77 [ + + ][ - + ]: 636013 : TYPEINIT2(SwCrsrShell,ViewShell,SwModify);
[ + + ]
78 : :
79 : :
80 : : /**
81 : : * Delete all overlapping Cursors from a Cursor ring.
82 : : * @param pointer to SwCursor (ring)
83 : : */
84 : : void CheckRange( SwCursor* );
85 : :
86 : :
87 : : /**
88 : : * Check if pCurCrsr points into already existing ranges and delete those.
89 : : * @param Pointer to SwCursor object
90 : : */
91 : 35547 : void CheckRange( SwCursor* pCurCrsr )
92 : : {
93 : 35547 : const SwPosition *pStt = pCurCrsr->Start(),
94 [ + + ]: 35547 : *pEnd = pCurCrsr->GetPoint() == pStt ? pCurCrsr->GetMark() : pCurCrsr->GetPoint();
95 : :
96 : 35547 : SwPaM *pTmpDel = 0,
97 : 35547 : *pTmp = (SwPaM*)pCurCrsr->GetNext();
98 : :
99 : : // Search the complete ring
100 [ + + ]: 35565 : while( pTmp != pCurCrsr )
101 : : {
102 : 18 : const SwPosition *pTmpStt = pTmp->Start(),
103 : 18 : *pTmpEnd = pTmp->GetPoint() == pTmpStt ?
104 [ + - ]: 18 : pTmp->GetMark() : pTmp->GetPoint();
105 [ + - ]: 18 : if( *pStt <= *pTmpStt )
106 : : {
107 [ + - - + : 36 : if( *pEnd > *pTmpStt ||
# # ][ - + ]
108 : 18 : ( *pEnd == *pTmpStt && *pEnd == *pTmpEnd ))
109 : 0 : pTmpDel = pTmp;
110 : : }
111 : : else
112 [ # # ]: 0 : if( *pStt < *pTmpEnd )
113 : 0 : pTmpDel = pTmp;
114 : :
115 : : // If Point or Mark is within the Crsr range, we need to remove the old
116 : : // range. Take note that Point does not belong to the range anymore.
117 : 18 : pTmp = (SwPaM*)pTmp->GetNext();
118 [ - + ]: 18 : delete pTmpDel; // Remove old range
119 : 18 : pTmpDel = 0;
120 : : }
121 : 35547 : }
122 : :
123 : : // -----------
124 : : // SwCrsrShell
125 : : // -----------
126 : :
127 : :
128 : :
129 : :
130 : 0 : SwPaM * SwCrsrShell::CreateCrsr()
131 : : {
132 : : // don't create Crsr in a table Selection (sic!)
133 : : OSL_ENSURE( !IsTableMode(), "in table Selection" );
134 : :
135 : : // New cursor as copy of current one. Add to the ring.
136 : : // Links point to previously created one, ie forward.
137 [ # # ]: 0 : SwShellCrsr* pNew = new SwShellCrsr( *pCurCrsr );
138 : :
139 : : // Hide PaM logically, to avoid undoing the inverting from
140 : : // copied PaM (#i75172#)
141 : 0 : pNew->swapContent(*pCurCrsr);
142 : :
143 : 0 : pCurCrsr->DeleteMark();
144 : :
145 : 0 : UpdateCrsr( SwCrsrShell::SCROLLWIN );
146 [ # # ]: 0 : return pNew;
147 : : }
148 : :
149 : :
150 : : /**
151 : : * Delete current Cursor, making the following one the current.
152 : : * Note, this function does not delete anything if there is no other cursor.
153 : : * @return - returns sal_True if there was another cursor and we deleted one.
154 : : */
155 : 0 : sal_Bool SwCrsrShell::DestroyCrsr()
156 : : {
157 : : // don't delete Crsr within table selection
158 : : OSL_ENSURE( !IsTableMode(), "in table Selection" );
159 : :
160 : : // Is there a next one? Don't do anything if not.
161 [ # # ][ # # ]: 0 : if(pCurCrsr->GetNext() == pCurCrsr)
162 : 0 : return sal_False;
163 : :
164 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves
165 : 0 : SwCursor* pNextCrsr = (SwCursor*)pCurCrsr->GetNext();
166 [ # # ][ # # ]: 0 : delete pCurCrsr;
167 [ # # ]: 0 : pCurCrsr = dynamic_cast<SwShellCrsr*>(pNextCrsr);
168 [ # # ]: 0 : UpdateCrsr();
169 [ # # ]: 0 : return sal_True;
170 : : }
171 : :
172 : :
173 : : /**
174 : : * Create and return a new shell cursor.
175 : : * Simply returns the current shell cursor if there is no selection
176 : : * (HasSelection()).
177 : : */
178 : 10 : SwPaM & SwCrsrShell::CreateNewShellCursor()
179 : : {
180 [ - + ]: 10 : if (HasSelection())
181 : : {
182 : 0 : (void) CreateCrsr(); // n.b. returns old cursor
183 : : }
184 : 10 : return *GetCrsr();
185 : : }
186 : :
187 : : /**
188 : : * Return the current shell cursor
189 : : * @return - returns current `SwPaM` shell cursor
190 : : */
191 : 0 : SwPaM & SwCrsrShell::GetCurrentShellCursor()
192 : : {
193 : 0 : return *GetCrsr();
194 : : }
195 : :
196 : : /**
197 : : * Return pointer to the current shell cursor
198 : : * @return - returns pointer to current `SwPaM` shell cursor
199 : : */
200 : 246029 : SwPaM* SwCrsrShell::GetCrsr( sal_Bool bMakeTblCrsr ) const
201 : : {
202 [ + + ]: 246029 : if( pTblCrsr )
203 : : {
204 [ + + ][ + + ]: 226 : if( bMakeTblCrsr && pTblCrsr->IsCrsrMovedUpdt() )
[ + + ]
205 : : {
206 : : //don't re-create 'parked' cursors
207 : : const SwCntntNode* pCNd;
208 [ + - + - ]: 32 : if( pTblCrsr->GetPoint()->nNode.GetIndex() &&
[ + - + - ]
[ + - + - ]
[ + - ]
209 : 8 : pTblCrsr->GetMark()->nNode.GetIndex() &&
210 : 8 : 0 != ( pCNd = pTblCrsr->GetCntntNode() ) && pCNd->getLayoutFrm( GetLayout() ) &&
211 : 8 : 0 != ( pCNd = pTblCrsr->GetCntntNode(sal_False) ) && pCNd->getLayoutFrm( GetLayout() ) )
212 : : {
213 : 8 : SwShellTableCrsr* pTC = (SwShellTableCrsr*)pTblCrsr;
214 : 8 : GetLayout()->MakeTblCrsrs( *pTC );
215 : : }
216 : : }
217 : :
218 [ + + ]: 226 : if( pTblCrsr->IsChgd() )
219 : : {
220 : : const_cast<SwCrsrShell*>(this)->pCurCrsr =
221 [ + - ][ - + ]: 12 : dynamic_cast<SwShellCrsr*>(pTblCrsr->MakeBoxSels( pCurCrsr ));
222 : : }
223 : : }
224 [ + - ]: 246029 : return pCurCrsr;
225 : : }
226 : :
227 : :
228 : 35539 : void SwCrsrShell::StartAction()
229 : : {
230 [ + + ]: 35539 : if( !ActionPend() )
231 : : {
232 : : // save for update of the ribbon bar
233 : 34859 : const SwNode& rNd = pCurCrsr->GetPoint()->nNode.GetNode();
234 : 34859 : nAktNode = rNd.GetIndex();
235 : 34859 : nAktCntnt = pCurCrsr->GetPoint()->nContent.GetIndex();
236 : 34859 : nAktNdTyp = rNd.GetNodeType();
237 : 34859 : bAktSelection = *pCurCrsr->GetPoint() != *pCurCrsr->GetMark();
238 [ + - ]: 34859 : if( rNd.IsTxtNode() )
239 : 34859 : nLeftFrmPos = SwCallLink::getLayoutFrm( GetLayout(), (SwTxtNode&)rNd, nAktCntnt, sal_True );
240 : : else
241 : 0 : nLeftFrmPos = 0;
242 : : }
243 : 35539 : ViewShell::StartAction(); // to the ViewShell
244 : 35539 : }
245 : :
246 : :
247 : 35539 : void SwCrsrShell::EndAction( const sal_Bool bIdleEnd )
248 : : {
249 : 35539 : sal_Bool bVis = bSVCrsrVis;
250 : :
251 : : // Idle-formatting?
252 [ + + ][ - + ]: 35539 : if( bIdleEnd && Imp()->GetRegion() )
[ - + ]
253 : : {
254 : 0 : pCurCrsr->Hide();
255 : : }
256 : :
257 : : // Update all invalid numberings before the last action
258 [ + + ]: 35539 : if( 1 == nStartAction )
259 : 34859 : GetDoc()->UpdateNumRule();
260 : :
261 : : // #i76923#: Don't show the cursor in the ViewShell::EndAction() - call.
262 : : // Only the UpdateCrsr shows the cursor.
263 : 35539 : sal_Bool bSavSVCrsrVis = bSVCrsrVis;
264 : 35539 : bSVCrsrVis = sal_False;
265 : :
266 : 35539 : ViewShell::EndAction( bIdleEnd ); // have ViewShell go first
267 : :
268 : 35539 : bSVCrsrVis = bSavSVCrsrVis;
269 : :
270 [ + + ]: 35539 : if( ActionPend() )
271 : : {
272 [ + + ]: 680 : if( bVis ) // display SV-Cursor again
273 : 641 : pVisCrsr->Show();
274 : :
275 : : // If there is still a ChgCall and just the "basic
276 : : // parenthiszing(?) (Basic-Klammerung)" exists, call it. This
277 : : // decouples the internal with the Basic-parenthising, the
278 : : // Shells are switched.
279 [ - + ]: 680 : if( !BasicActionPend() )
280 : : {
281 : : // Within a Basic action, one needs to update the cursor,
282 : : // to e.g. create the table cursos. This is being done in
283 : : // UpdateCrsr.
284 : 0 : UpdateCrsr( SwCrsrShell::CHKRANGE, bIdleEnd );
285 : :
286 : : {
287 : : // watch Crsr-Moves, call Link if needed, the DTOR is key here!
288 : : SwCallLink aLk( *this, nAktNode, nAktCntnt, (sal_uInt8)nAktNdTyp,
289 [ # # ][ # # ]: 0 : nLeftFrmPos, bAktSelection );
290 : :
291 : : }
292 [ # # ][ # # ]: 0 : if( bCallChgLnk && bChgCallFlag && aChgLnk.IsSet() )
[ # # ][ # # ]
293 : : {
294 : 0 : aChgLnk.Call( this );
295 : 0 : bChgCallFlag = sal_False; // reset flag
296 : : }
297 : : }
298 : 35539 : return;
299 : : }
300 : :
301 : 34859 : sal_uInt16 nParm = SwCrsrShell::CHKRANGE;
302 [ + + ]: 34859 : if ( !bIdleEnd )
303 : 33557 : nParm |= SwCrsrShell::SCROLLWIN;
304 : :
305 : 34859 : UpdateCrsr( nParm, bIdleEnd ); // Show Cursor changes
306 : :
307 : : {
308 [ + - ]: 34859 : SwCallLink aLk( *this ); // watch Crsr-Moves
309 : 34859 : aLk.nNode = nAktNode; // call Link if needed
310 : 34859 : aLk.nNdTyp = (sal_uInt8)nAktNdTyp;
311 : 34859 : aLk.nCntnt = nAktCntnt;
312 : 34859 : aLk.nLeftFrmPos = nLeftFrmPos;
313 : :
314 [ + + ][ + - ]: 34859 : if( !nCrsrMove ||
[ + + ]
315 : : ( 1 == nCrsrMove && bInCMvVisportChgd ) )
316 : : // display Cursor & Selektions again
317 [ + + ][ + - ]: 34859 : ShowCrsrs( bSVCrsrVis ? sal_True : sal_False );
[ + - ]
318 : : }
319 : : // call ChgCall if there is still one
320 [ + - ][ + + ]: 34859 : if( bCallChgLnk && bChgCallFlag && aChgLnk.IsSet() )
[ + - ][ + + ]
321 : : {
322 : 1010 : aChgLnk.Call( this );
323 : 1010 : bChgCallFlag = sal_False; // reset flag
324 : : }
325 : : }
326 : :
327 : :
328 : : #ifdef DBG_UTIL
329 : :
330 : : void SwCrsrShell::SttCrsrMove()
331 : : {
332 : : OSL_ENSURE( nCrsrMove < USHRT_MAX, "To many nested CrsrMoves." );
333 : : ++nCrsrMove;
334 : : StartAction();
335 : : }
336 : :
337 : : void SwCrsrShell::EndCrsrMove( const sal_Bool bIdleEnd )
338 : : {
339 : : OSL_ENSURE( nCrsrMove, "EndCrsrMove() without SttCrsrMove()." );
340 : : EndAction( bIdleEnd );
341 : : if( !--nCrsrMove )
342 : : bInCMvVisportChgd = sal_False;
343 : : }
344 : :
345 : : #endif
346 : :
347 : :
348 : 34 : sal_Bool SwCrsrShell::LeftRight( sal_Bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
349 : : sal_Bool bVisualAllowed )
350 : : {
351 [ - + ]: 34 : if( IsTableMode() )
352 [ # # ][ # # ]: 0 : return bLeft ? GoPrevCell() : GoNextCell();
[ # # ]
353 : :
354 [ + - ]: 34 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
355 : 34 : sal_Bool bRet = sal_False;
356 : :
357 : : // #i27615# Handle cursor in front of label.
358 : 34 : const SwTxtNode* pTxtNd = 0;
359 : :
360 [ - + ]: 34 : if( pBlockCrsr )
361 [ # # ]: 0 : pBlockCrsr->clearPoints();
362 : :
363 : : // 1. CASE: Cursor is in front of label. A move to the right
364 : : // will simply reset the bInFrontOfLabel flag:
365 [ + - ]: 34 : SwShellCrsr* pShellCrsr = getShellCrsr( true );
366 [ + + ][ - + ]: 34 : if ( !bLeft && pShellCrsr->IsInFrontOfLabel() )
[ - + ]
367 : : {
368 [ # # ]: 0 : SetInFrontOfLabel( sal_False );
369 : 0 : bRet = sal_True;
370 : : }
371 : : // 2. CASE: Cursor is at beginning of numbered paragraph. A move
372 : : // to the left will simply set the bInFrontOfLabel flag:
373 [ + + ][ + + : 42 : else if ( bLeft && 0 == pShellCrsr->GetPoint()->nContent.GetIndex() &&
+ - + - +
- ][ - + ]
[ - + ]
374 : 4 : !pShellCrsr->IsInFrontOfLabel() && !pShellCrsr->HasMark() &&
375 : 2 : 0 != ( pTxtNd = pShellCrsr->GetNode()->GetTxtNode() ) &&
376 [ + - ]: 2 : pTxtNd->HasVisibleNumberingOrBullet() )
377 : : {
378 [ # # ]: 0 : SetInFrontOfLabel( sal_True );
379 : 0 : bRet = sal_True;
380 : : }
381 : : // 3. CASE: Regular cursor move. Reset the bInFrontOfLabel flag:
382 : : else
383 : : {
384 : 34 : const sal_Bool bSkipHidden = !GetViewOptions()->IsShowHiddenChar();
385 : : // #i107447#
386 : : // To avoid loop the reset of <bInFrontOfLabel> flag is no longer
387 : : // reflected in the return value <bRet>.
388 [ + - ]: 34 : const bool bResetOfInFrontOfLabel = SetInFrontOfLabel( sal_False );
389 : : bRet = pShellCrsr->LeftRight( bLeft, nCnt, nMode, bVisualAllowed,
390 [ + - ]: 34 : bSkipHidden, !IsOverwriteCrsr() );
391 [ + + ][ + + ]: 34 : if ( !bRet && bLeft && bResetOfInFrontOfLabel )
[ - + ]
392 : : {
393 : : // undo reset of <bInFrontOfLabel> flag
394 [ # # ]: 0 : SetInFrontOfLabel( sal_True );
395 : : }
396 : : }
397 : :
398 [ + + ]: 34 : if( bRet )
399 : : {
400 [ + - ]: 30 : UpdateCrsr();
401 : : }
402 [ + - ]: 34 : return bRet;
403 : : }
404 : :
405 : 0 : void SwCrsrShell::MarkListLevel( const String& sListId,
406 : : const int nListLevel )
407 : : {
408 [ # # ][ # # ]: 0 : if ( sListId != sMarkedListId ||
[ # # ]
409 : : nListLevel != nMarkedListLevel)
410 : : {
411 [ # # ]: 0 : if ( sMarkedListId.Len() > 0 )
412 : 0 : pDoc->MarkListLevel( sMarkedListId, nMarkedListLevel, sal_False );
413 : :
414 [ # # ]: 0 : if ( sListId.Len() > 0 )
415 : : {
416 : 0 : pDoc->MarkListLevel( sListId, nListLevel, sal_True );
417 : : }
418 : :
419 : 0 : sMarkedListId = sListId;
420 : 0 : nMarkedListLevel = nListLevel;
421 : : }
422 : 0 : }
423 : :
424 : 0 : void SwCrsrShell::UpdateMarkedListLevel()
425 : : {
426 : 0 : SwTxtNode * pTxtNd = _GetCrsr()->GetNode()->GetTxtNode();
427 : :
428 [ # # ]: 0 : if ( pTxtNd )
429 : : {
430 [ # # ]: 0 : if ( !pTxtNd->IsNumbered() )
431 : : {
432 : 0 : pCurCrsr->_SetInFrontOfLabel( sal_False );
433 [ # # ]: 0 : MarkListLevel( String(), 0 );
434 : : }
435 [ # # ]: 0 : else if ( pCurCrsr->IsInFrontOfLabel() )
436 : : {
437 [ # # ]: 0 : if ( pTxtNd->IsInList() )
438 : : {
439 : : OSL_ENSURE( pTxtNd->GetActualListLevel() >= 0 &&
440 : : pTxtNd->GetActualListLevel() < MAXLEVEL, "Which level?");
441 : : MarkListLevel( pTxtNd->GetListId(),
442 [ # # ]: 0 : pTxtNd->GetActualListLevel() );
443 : : }
444 : : }
445 : : else
446 : : {
447 [ # # ]: 0 : MarkListLevel( String(), 0 );
448 : : }
449 : : }
450 : 0 : }
451 : :
452 : 0 : sal_Bool SwCrsrShell::UpDown( sal_Bool bUp, sal_uInt16 nCnt )
453 : : {
454 [ # # ]: 0 : SET_CURR_SHELL( this );
455 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
456 : :
457 : 0 : sal_Bool bTableMode = IsTableMode();
458 [ # # ]: 0 : SwShellCrsr* pTmpCrsr = getShellCrsr( true );
459 : :
460 [ # # ]: 0 : sal_Bool bRet = pTmpCrsr->UpDown( bUp, nCnt );
461 : : // #i40019# UpDown should always reset the bInFrontOfLabel flag:
462 [ # # ][ # # ]: 0 : bRet = SetInFrontOfLabel(sal_False) || bRet;
[ # # ]
463 : :
464 [ # # ]: 0 : if( pBlockCrsr )
465 [ # # ]: 0 : pBlockCrsr->clearPoints();
466 : :
467 [ # # ]: 0 : if( bRet )
468 : : {
469 : 0 : eMvState = MV_UPDOWN; // status for Crsr travelling - GetCrsrOfst
470 [ # # ]: 0 : if( !ActionPend() )
471 : : {
472 : 0 : CrsrFlag eUpdtMode = SwCrsrShell::SCROLLWIN;
473 [ # # ]: 0 : if( !bTableMode )
474 : : eUpdtMode = (CrsrFlag) (eUpdtMode
475 : 0 : | SwCrsrShell::UPDOWN | SwCrsrShell::CHKRANGE);
476 [ # # ]: 0 : UpdateCrsr( static_cast<sal_uInt16>(eUpdtMode) );
477 : : }
478 : : }
479 [ # # ][ # # ]: 0 : return bRet;
480 : : }
481 : :
482 : 0 : sal_Bool SwCrsrShell::LRMargin( sal_Bool bLeft, sal_Bool bAPI)
483 : : {
484 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
485 [ # # ]: 0 : SET_CURR_SHELL( this );
486 : 0 : eMvState = MV_LEFTMARGIN; // status for Crsr travelling - GetCrsrOfst
487 : :
488 : 0 : const sal_Bool bTableMode = IsTableMode();
489 [ # # ]: 0 : SwShellCrsr* pTmpCrsr = getShellCrsr( true );
490 : :
491 [ # # ]: 0 : if( pBlockCrsr )
492 [ # # ]: 0 : pBlockCrsr->clearPoints();
493 : :
494 : : const sal_Bool bWasAtLM =
495 : 0 : ( 0 == _GetCrsr()->GetPoint()->nContent.GetIndex() );
496 : :
497 [ # # ]: 0 : sal_Bool bRet = pTmpCrsr->LeftRightMargin( bLeft, bAPI );
498 : :
499 [ # # ][ # # ]: 0 : if ( bLeft && !bTableMode && bRet && bWasAtLM && !_GetCrsr()->HasMark() )
[ # # ][ # # ]
[ # # ][ # # ]
500 : : {
501 : 0 : const SwTxtNode * pTxtNd = _GetCrsr()->GetNode()->GetTxtNode();
502 [ # # ][ # # ]: 0 : if ( pTxtNd && pTxtNd->HasVisibleNumberingOrBullet() )
[ # # ][ # # ]
503 [ # # ]: 0 : SetInFrontOfLabel( sal_True );
504 : : }
505 [ # # ]: 0 : else if ( !bLeft )
506 : : {
507 [ # # ][ # # ]: 0 : bRet = SetInFrontOfLabel( sal_False ) || bRet;
[ # # ]
508 : : }
509 : :
510 [ # # ]: 0 : if( bRet )
511 : : {
512 [ # # ]: 0 : UpdateCrsr();
513 : : }
514 [ # # ][ # # ]: 0 : return bRet;
515 : : }
516 : :
517 : 0 : sal_Bool SwCrsrShell::IsAtLRMargin( sal_Bool bLeft, sal_Bool bAPI ) const
518 : : {
519 : 0 : const SwShellCrsr* pTmpCrsr = getShellCrsr( true );
520 : 0 : return pTmpCrsr->IsAtLeftRightMargin( bLeft, bAPI );
521 : : }
522 : :
523 : :
524 : 49 : sal_Bool SwCrsrShell::SttEndDoc( sal_Bool bStt )
525 : : {
526 [ + - ]: 49 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
527 : :
528 [ - + ][ # # ]: 49 : SwShellCrsr* pTmpCrsr = pBlockCrsr ? &pBlockCrsr->getShellCrsr() : pCurCrsr;
529 [ + - ]: 49 : sal_Bool bRet = pTmpCrsr->SttEndDoc( bStt );
530 [ + - ]: 49 : if( bRet )
531 : : {
532 [ + + ]: 49 : if( bStt )
533 : 20 : pTmpCrsr->GetPtPos().Y() = 0; // set to 0 explicitly (table header)
534 [ - + ]: 49 : if( pBlockCrsr )
535 : : {
536 [ # # ]: 0 : pBlockCrsr->clearPoints();
537 [ # # ]: 0 : RefreshBlockCursor();
538 : : }
539 : :
540 [ + - ]: 49 : UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
541 : : }
542 [ + - ]: 49 : return bRet;
543 : : }
544 : :
545 : 0 : void SwCrsrShell::ExtendedSelectAll()
546 : : {
547 : 0 : SwNodes& rNodes = GetDoc()->GetNodes();
548 : 0 : SwPosition* pPos = pCurCrsr->GetPoint();
549 : 0 : pPos->nNode = rNodes.GetEndOfPostIts();
550 [ # # ]: 0 : pPos->nContent.Assign( rNodes.GoNext( &pPos->nNode ), 0 );
551 : 0 : pPos = pCurCrsr->GetMark();
552 : 0 : pPos->nNode = rNodes.GetEndOfContent();
553 : 0 : SwCntntNode* pCNd = rNodes.GoPrevious( &pPos->nNode );
554 [ # # ][ # # ]: 0 : pPos->nContent.Assign( pCNd, pCNd ? pCNd->Len() : 0 );
555 : 0 : }
556 : :
557 : 21 : sal_Bool SwCrsrShell::MovePage( SwWhichPage fnWhichPage, SwPosPage fnPosPage )
558 : : {
559 : 21 : sal_Bool bRet = sal_False;
560 : :
561 : : // never jump of section borders at selection
562 [ - + ][ # # ]: 21 : if( !pCurCrsr->HasMark() || !pCurCrsr->IsNoCntnt() )
[ + - ]
563 : : {
564 [ + - ]: 21 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
565 [ + - ]: 21 : SET_CURR_SHELL( this );
566 : :
567 [ + - ]: 21 : SwCrsrSaveState aSaveState( *pCurCrsr );
568 : 21 : Point& rPt = pCurCrsr->GetPtPos();
569 : : SwCntntFrm * pFrm = pCurCrsr->GetCntntNode()->
570 [ + - ][ + - ]: 21 : getLayoutFrm( GetLayout(), &rPt, pCurCrsr->GetPoint(), sal_False );
571 [ + - ][ + - ]: 63 : if( pFrm && sal_True == ( bRet = GetFrmInPage( pFrm, fnWhichPage,
[ + - ][ + - ]
[ + - ]
572 [ + - ]: 21 : fnPosPage, pCurCrsr ) ) &&
573 : : !pCurCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
574 [ + - ]: 21 : nsSwCursorSelOverFlags::SELOVER_CHANGEPOS ))
575 [ + - ]: 21 : UpdateCrsr();
576 : : else
577 [ + - ][ + - ]: 21 : bRet = sal_False;
[ + - ]
578 : : }
579 : 21 : return bRet;
580 : : }
581 : :
582 : :
583 : 0 : sal_Bool SwCrsrShell::MovePara(SwWhichPara fnWhichPara, SwPosPara fnPosPara )
584 : : {
585 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
586 [ # # ][ # # ]: 0 : SwCursor* pTmpCrsr = getShellCrsr( true );
587 [ # # ]: 0 : sal_Bool bRet = pTmpCrsr->MovePara( fnWhichPara, fnPosPara );
588 [ # # ]: 0 : if( bRet )
589 [ # # ]: 0 : UpdateCrsr();
590 [ # # ]: 0 : return bRet;
591 : : }
592 : :
593 : :
594 : 0 : sal_Bool SwCrsrShell::MoveSection( SwWhichSection fnWhichSect,
595 : : SwPosSection fnPosSect)
596 : : {
597 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
598 [ # # ][ # # ]: 0 : SwCursor* pTmpCrsr = getShellCrsr( true );
599 [ # # ]: 0 : sal_Bool bRet = pTmpCrsr->MoveSection( fnWhichSect, fnPosSect );
600 [ # # ]: 0 : if( bRet )
601 [ # # ]: 0 : UpdateCrsr();
602 [ # # ]: 0 : return bRet;
603 : :
604 : : }
605 : :
606 : :
607 : : // position cursor
608 : :
609 : :
610 : 71106 : SwFrm* lcl_IsInHeaderFooter( const SwNodeIndex& rIdx, Point& rPt )
611 : : {
612 : 71106 : SwFrm* pFrm = 0;
613 : 71106 : SwCntntNode* pCNd = rIdx.GetNode().GetCntntNode();
614 [ + - ]: 71106 : if( pCNd )
615 : : {
616 : 71106 : SwCntntFrm *pCntFrm = pCNd->getLayoutFrm( pCNd->GetDoc()->GetCurrentLayout(), &rPt, 0, sal_False );
617 [ + - ]: 71106 : pFrm = pCntFrm ? pCntFrm->GetUpper() : NULL;
618 [ + + ][ + - ]: 285864 : while( pFrm && !pFrm->IsHeaderFrm() && !pFrm->IsFooterFrm() )
[ + - ][ + + ]
619 : 214758 : pFrm = pFrm->IsFlyFrm() ? ((SwFlyFrm*)pFrm)->AnchorFrm()
620 [ - + ]: 214758 : : pFrm->GetUpper();
621 : : }
622 : 71106 : return pFrm;
623 : : }
624 : :
625 : 71106 : bool SwCrsrShell::IsInHeaderFooter( sal_Bool* pbInHeader ) const
626 : : {
627 : 71106 : Point aPt;
628 [ + - ]: 71106 : SwFrm* pFrm = ::lcl_IsInHeaderFooter( pCurCrsr->GetPoint()->nNode, aPt );
629 [ - + ][ # # ]: 71106 : if( pFrm && pbInHeader )
630 : 0 : *pbInHeader = pFrm->IsHeaderFrm();
631 : 71106 : return 0 != pFrm;
632 : : }
633 : :
634 : 0 : int SwCrsrShell::SetCrsr( const Point &rLPt, sal_Bool bOnlyText, bool bBlock )
635 : : {
636 [ # # ]: 0 : SET_CURR_SHELL( this );
637 : :
638 [ # # ]: 0 : SwShellCrsr* pCrsr = getShellCrsr( bBlock );
639 [ # # ]: 0 : SwPosition aPos( *pCrsr->GetPoint() );
640 : 0 : Point aPt( rLPt );
641 : 0 : Point & rAktCrsrPt = pCrsr->GetPtPos();
642 : 0 : SwCrsrMoveState aTmpState( IsTableMode() ? MV_TBLSEL :
643 [ # # ][ # # ]: 0 : bOnlyText ? MV_SETONLYTEXT : MV_NONE );
644 : 0 : aTmpState.bSetInReadOnly = IsReadOnlyAvailable();
645 : :
646 : 0 : SwTxtNode * pTxtNd = pCrsr->GetNode()->GetTxtNode();
647 : :
648 [ # # # # ]: 0 : if ( pTxtNd && !IsTableMode() &&
[ # # ][ # # ]
[ # # ]
649 : : // #i37515# No bInFrontOfLabel during selection
650 : 0 : !pCrsr->HasMark() &&
651 [ # # ]: 0 : pTxtNd->HasVisibleNumberingOrBullet() )
652 : : {
653 : 0 : aTmpState.bInFrontOfLabel = sal_True; // #i27615#
654 : : }
655 : : else
656 : : {
657 : 0 : aTmpState.bInFrontOfLabel = sal_False;
658 : : }
659 : :
660 : : int bRet = CRSR_POSOLD |
661 [ # # ][ # # ]: 0 : ( GetLayout()->GetCrsrOfst( &aPos, aPt, &aTmpState )
662 [ # # ]: 0 : ? 0 : CRSR_POSCHG );
663 : :
664 [ # # ]: 0 : const bool bOldInFrontOfLabel = IsInFrontOfLabel();
665 : 0 : const bool bNewInFrontOfLabel = aTmpState.bInFrontOfLabel;
666 : :
667 : 0 : pCrsr->SetCrsrBidiLevel( aTmpState.nCursorBidiLevel );
668 : :
669 [ # # ]: 0 : if( MV_RIGHTMARGIN == aTmpState.eState )
670 : 0 : eMvState = MV_RIGHTMARGIN;
671 : : // is the new position in header or footer?
672 [ # # ]: 0 : SwFrm* pFrm = lcl_IsInHeaderFooter( aPos.nNode, aPt );
673 [ # # ][ # # ]: 0 : if( IsTableMode() && !pFrm && aPos.nNode.GetNode().StartOfSectionNode() ==
[ # # ][ # # ]
674 : 0 : pCrsr->GetPoint()->nNode.GetNode().StartOfSectionNode() )
675 : : // same table column and not in header/footer -> back
676 : 0 : return bRet;
677 : :
678 : : // toggle the header/footer mode if needed
679 [ # # ][ # # ]: 0 : bool bInHeaderFooter = pFrm && ( pFrm->IsHeaderFrm() || pFrm->IsFooterFrm() );
[ # # ]
680 [ # # ]: 0 : if ( bInHeaderFooter != IsHeaderFooterEdit() )
681 [ # # ]: 0 : ToggleHeaderFooterEdit();
682 : :
683 [ # # ][ # # ]: 0 : if( pBlockCrsr && bBlock )
684 : : {
685 [ # # ]: 0 : pBlockCrsr->setEndPoint( rLPt );
686 [ # # ]: 0 : if( !pCrsr->HasMark() )
687 [ # # ]: 0 : pBlockCrsr->setStartPoint( rLPt );
688 [ # # ][ # # ]: 0 : else if( !pBlockCrsr->getStartPoint() )
689 [ # # ]: 0 : pBlockCrsr->setStartPoint( pCrsr->GetMkPos() );
690 : : }
691 [ # # ]: 0 : if( !pCrsr->HasMark() )
692 : : {
693 : : // is at the same position and if in header/footer -> in the same
694 [ # # ][ # # ]: 0 : if( aPos == *pCrsr->GetPoint() &&
[ # # ][ # # ]
695 : : bOldInFrontOfLabel == bNewInFrontOfLabel )
696 : : {
697 [ # # ]: 0 : if( pFrm )
698 : : {
699 [ # # ][ # # ]: 0 : if( pFrm->Frm().IsInside( rAktCrsrPt ))
700 : 0 : return bRet;
701 : : }
702 [ # # ]: 0 : else if( aPos.nNode.GetNode().IsCntntNode() )
703 : : {
704 : : // in the same frame?
705 : 0 : SwFrm* pOld = ((SwCntntNode&)aPos.nNode.GetNode()).getLayoutFrm(
706 [ # # # # ]: 0 : GetLayout(), &aCharRect.Pos(), 0, sal_False );
[ # # ]
707 : 0 : SwFrm* pNew = ((SwCntntNode&)aPos.nNode.GetNode()).getLayoutFrm(
708 [ # # # # ]: 0 : GetLayout(), &aPt, 0, sal_False );
[ # # ]
709 [ # # ]: 0 : if( pNew == pOld )
710 : 0 : return bRet;
711 : : }
712 : : }
713 : : }
714 : : else
715 : : {
716 : : // SSelection over not allowed sections or if in header/footer -> different
717 [ # # ][ # # ]: 0 : if( !CheckNodesRange( aPos.nNode, pCrsr->GetMark()->nNode, sal_True )
[ # # ][ # # ]
[ # # ]
718 [ # # ]: 0 : || ( pFrm && !pFrm->Frm().IsInside( pCrsr->GetMkPos() ) ))
719 : 0 : return bRet;
720 : :
721 : : // is at same position but not in header/footer
722 [ # # ][ # # ]: 0 : if( aPos == *pCrsr->GetPoint() )
723 : 0 : return bRet;
724 : : }
725 : :
726 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
727 [ # # ]: 0 : SwCrsrSaveState aSaveState( *pCrsr );
728 : :
729 [ # # ]: 0 : *pCrsr->GetPoint() = aPos;
730 : 0 : rAktCrsrPt = aPt;
731 : :
732 : : // #i41424# Only update the marked number levels if necessary
733 : : // Force update of marked number levels if necessary.
734 [ # # ][ # # ]: 0 : if ( bNewInFrontOfLabel || bOldInFrontOfLabel )
735 : 0 : pCurCrsr->_SetInFrontOfLabel( !bNewInFrontOfLabel );
736 [ # # ]: 0 : SetInFrontOfLabel( bNewInFrontOfLabel );
737 : :
738 [ # # ][ # # ]: 0 : if( !pCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_CHANGEPOS ) )
739 : : {
740 : 0 : sal_uInt16 nFlag = SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE;
741 [ # # ]: 0 : UpdateCrsr( nFlag );
742 : 0 : bRet &= ~CRSR_POSOLD;
743 : : }
744 [ # # ][ # # ]: 0 : else if( bOnlyText && !pCurCrsr->HasMark() )
[ # # ]
745 : : {
746 [ # # ][ # # ]: 0 : if( FindValidCntntNode( bOnlyText ) )
747 : : {
748 : : // position cursor in a valid content
749 [ # # ][ # # ]: 0 : if( aPos == *pCrsr->GetPoint() )
750 : 0 : bRet = CRSR_POSOLD;
751 : : else
752 : : {
753 [ # # ]: 0 : UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE );
754 : 0 : bRet &= ~CRSR_POSOLD;
755 : : }
756 : : }
757 : : else
758 : : {
759 : : // there is no valid content -> hide cursor
760 [ # # ]: 0 : pVisCrsr->Hide(); // always hide visible cursor
761 : 0 : eMvState = MV_NONE; // status for Crsr travelling
762 : 0 : bAllProtect = sal_True;
763 [ # # ]: 0 : if( GetDoc()->GetDocShell() )
764 : : {
765 [ # # ]: 0 : GetDoc()->GetDocShell()->SetReadOnlyUI( sal_True );
766 [ # # ]: 0 : CallChgLnk(); // notify UI
767 : : }
768 : : }
769 : : }
770 : :
771 [ # # ][ # # ]: 0 : return bRet;
[ # # ][ # # ]
772 : : }
773 : :
774 : :
775 : 0 : void SwCrsrShell::TblCrsrToCursor()
776 : : {
777 : : OSL_ENSURE( pTblCrsr, "TblCrsrToCursor: Why?" );
778 [ # # ]: 0 : delete pTblCrsr, pTblCrsr = 0;
779 : 0 : }
780 : :
781 : 0 : void SwCrsrShell::BlockCrsrToCrsr()
782 : : {
783 : : OSL_ENSURE( pBlockCrsr, "BlockCrsrToCrsr: Why?" );
784 [ # # ][ # # ]: 0 : if( pBlockCrsr && !HasSelection() )
[ # # ]
785 : : {
786 : 0 : SwPaM& rPam = pBlockCrsr->getShellCrsr();
787 : 0 : pCurCrsr->SetMark();
788 : 0 : *pCurCrsr->GetPoint() = *rPam.GetPoint();
789 [ # # ]: 0 : if( rPam.HasMark() )
790 : 0 : *pCurCrsr->GetMark() = *rPam.GetMark();
791 : : else
792 : 0 : pCurCrsr->DeleteMark();
793 : : }
794 [ # # ]: 0 : delete pBlockCrsr, pBlockCrsr = 0;
795 : 0 : }
796 : :
797 : 0 : void SwCrsrShell::CrsrToBlockCrsr()
798 : : {
799 [ # # ]: 0 : if( !pBlockCrsr )
800 : : {
801 [ # # ]: 0 : SwPosition aPos( *pCurCrsr->GetPoint() );
802 [ # # ]: 0 : pBlockCrsr = createBlockCursor( *this, aPos );
803 [ # # ]: 0 : SwShellCrsr &rBlock = pBlockCrsr->getShellCrsr();
804 : 0 : rBlock.GetPtPos() = pCurCrsr->GetPtPos();
805 [ # # ]: 0 : if( pCurCrsr->HasMark() )
806 : : {
807 [ # # ]: 0 : rBlock.SetMark();
808 [ # # ]: 0 : *rBlock.GetMark() = *pCurCrsr->GetMark();
809 : 0 : rBlock.GetMkPos() = pCurCrsr->GetMkPos();
810 [ # # ]: 0 : }
811 : : }
812 : 0 : pBlockCrsr->clearPoints();
813 : 0 : RefreshBlockCursor();
814 : 0 : }
815 : :
816 : 148 : void SwCrsrShell::ClearMark()
817 : : {
818 : : // is there any GetMark?
819 [ + + ]: 148 : if( pTblCrsr )
820 : : {
821 [ + - ][ + + ]: 8 : while( pCurCrsr->GetNext() != pCurCrsr )
822 [ + - ]: 6 : delete pCurCrsr->GetNext();
823 : 2 : pTblCrsr->DeleteMark();
824 : :
825 [ + - ]: 2 : if( pCurCrsr->HasMark() )
826 : : {
827 : : // move content part from mark to nodes array if not all indices
828 : : // were moved correctly (e.g. when deleting header/footer)
829 : 2 : SwPosition& rPos = *pCurCrsr->GetMark();
830 : 2 : rPos.nNode.Assign( pDoc->GetNodes(), 0 );
831 : 2 : rPos.nContent.Assign( 0, 0 );
832 : 2 : pCurCrsr->DeleteMark();
833 : : }
834 : :
835 : 2 : *pCurCrsr->GetPoint() = *pTblCrsr->GetPoint();
836 : 2 : pCurCrsr->GetPtPos() = pTblCrsr->GetPtPos();
837 [ + - ]: 2 : delete pTblCrsr, pTblCrsr = 0;
838 : 2 : pCurCrsr->SwSelPaintRects::Show();
839 : : }
840 : : else
841 : : {
842 [ + + ]: 146 : if( !pCurCrsr->HasMark() )
843 : 148 : return;
844 : : // move content part from mark to nodes array if not all indices
845 : : // were moved correctly (e.g. when deleting header/footer)
846 : 78 : SwPosition& rPos = *pCurCrsr->GetMark();
847 : 78 : rPos.nNode.Assign( pDoc->GetNodes(), 0 );
848 : 78 : rPos.nContent.Assign( 0, 0 );
849 : 78 : pCurCrsr->DeleteMark();
850 [ + - ]: 78 : if( !nCrsrMove )
851 : 78 : pCurCrsr->SwSelPaintRects::Show();
852 : : }
853 : : }
854 : :
855 : :
856 : 0 : void SwCrsrShell::NormalizePam(sal_Bool bPointFirst)
857 : : {
858 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
859 [ # # ][ # # ]: 0 : pCurCrsr->Normalize(bPointFirst);
860 : 0 : }
861 : :
862 : 0 : void SwCrsrShell::SwapPam()
863 : : {
864 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
865 [ # # ]: 0 : pCurCrsr->Exchange();
866 : 0 : }
867 : :
868 : : //TODO: provide documentation
869 : : /** Search in the selected area for a Selection that covers the given point.
870 : :
871 : : If only a test run is made, then it checks if a SSelection exists but does
872 : : not move the current cursor. In a normal run the cursor will be moved to the
873 : : chosen SSelection.
874 : :
875 : : @param rPt The point to search at.
876 : : @param bTstOnly Should I only do a test run? If true so do not move cursor.
877 : : @param bTstHit ???
878 : : */
879 : 0 : sal_Bool SwCrsrShell::ChgCurrPam( const Point & rPt,
880 : : sal_Bool bTstOnly, sal_Bool bTstHit )
881 : : {
882 [ # # ]: 0 : SET_CURR_SHELL( this );
883 : :
884 : : // check if the SPoint is in a table selection
885 [ # # ][ # # ]: 0 : if( bTstOnly && pTblCrsr )
886 [ # # ]: 0 : return pTblCrsr->IsInside( rPt );
887 : :
888 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
889 : : // search position <rPt> in document
890 [ # # ]: 0 : SwPosition aPtPos( *pCurCrsr->GetPoint() );
891 : 0 : Point aPt( rPt );
892 : :
893 : 0 : SwCrsrMoveState aTmpState( MV_NONE );
894 : 0 : aTmpState.bSetInReadOnly = IsReadOnlyAvailable();
895 [ # # ][ # # ]: 0 : if ( !GetLayout()->GetCrsrOfst( &aPtPos, aPt, &aTmpState ) && bTstHit )
[ # # ][ # # ]
[ # # ]
896 : 0 : return sal_False;
897 : :
898 : : // search in all selections for this position
899 : 0 : SwShellCrsr* pCmp = (SwShellCrsr*)pCurCrsr; // keep the pointer on cursor
900 [ # # ][ # # ]: 0 : do {
901 [ # # ][ # # ]: 0 : if( pCmp->HasMark() &&
[ # # ][ # # ]
902 [ # # ][ # # ]: 0 : *pCmp->Start() <= aPtPos && *pCmp->End() > aPtPos )
[ # # ][ # # ]
903 : : {
904 [ # # ][ # # ]: 0 : if( bTstOnly || pCurCrsr == pCmp ) // is the current
905 : 0 : return sal_True; // return without update
906 : :
907 : 0 : pCurCrsr = pCmp;
908 [ # # ]: 0 : UpdateCrsr(); // cursor is already at the right position
909 : 0 : return sal_True;
910 : : }
911 : : } while( pCurCrsr !=
912 : 0 : ( pCmp = dynamic_cast<SwShellCrsr*>(pCmp->GetNext()) ) );
913 [ # # ][ # # ]: 0 : return sal_False;
[ # # ]
914 : : }
915 : :
916 : :
917 : 160 : void SwCrsrShell::KillPams()
918 : : {
919 : : // Does any exist for deletion?
920 [ + + ][ + - ]: 160 : if( !pTblCrsr && !pBlockCrsr && pCurCrsr->GetNext() == pCurCrsr )
[ + - ][ + - ]
[ + + ]
921 : 160 : return;
922 : :
923 [ + - ][ + + ]: 12 : while( pCurCrsr->GetNext() != pCurCrsr )
924 [ + - ]: 6 : delete pCurCrsr->GetNext();
925 : 6 : pCurCrsr->SetColumnSelection( false );
926 : :
927 [ + - ]: 6 : if( pTblCrsr )
928 : : {
929 : : // delete the ring of cursors
930 : 6 : pCurCrsr->DeleteMark();
931 : 6 : *pCurCrsr->GetPoint() = *pTblCrsr->GetPoint();
932 : 6 : pCurCrsr->GetPtPos() = pTblCrsr->GetPtPos();
933 [ + - ]: 6 : delete pTblCrsr;
934 : 6 : pTblCrsr = 0;
935 : : }
936 [ # # ]: 0 : else if( pBlockCrsr )
937 : : {
938 : : // delete the ring of cursors
939 : 0 : pCurCrsr->DeleteMark();
940 : 0 : SwShellCrsr &rBlock = pBlockCrsr->getShellCrsr();
941 : 0 : *pCurCrsr->GetPoint() = *rBlock.GetPoint();
942 : 0 : pCurCrsr->GetPtPos() = rBlock.GetPtPos();
943 : 0 : rBlock.DeleteMark();
944 : 0 : pBlockCrsr->clearPoints();
945 : : }
946 : 6 : UpdateCrsr( SwCrsrShell::SCROLLWIN );
947 : : }
948 : :
949 : :
950 : 0 : int SwCrsrShell::CompareCursor( CrsrCompareType eType ) const
951 : : {
952 : 0 : int nRet = 0;
953 : 0 : const SwPosition *pFirst = 0, *pSecond = 0;
954 [ # # ]: 0 : const SwPaM *pCur = GetCrsr(), *pStk = pCrsrStk;
955 [ # # ][ # # ]: 0 : if( CurrPtCurrMk != eType && pStk )
956 : : {
957 [ # # # # : 0 : switch ( eType)
# # # ]
958 : : {
959 : : case StackPtStackMk:
960 : 0 : pFirst = pStk->GetPoint();
961 : 0 : pSecond = pStk->GetMark();
962 : 0 : break;
963 : : case StackPtCurrPt:
964 : 0 : pFirst = pStk->GetPoint();
965 : 0 : pSecond = pCur->GetPoint();
966 : 0 : break;
967 : : case StackPtCurrMk:
968 : 0 : pFirst = pStk->GetPoint();
969 : 0 : pSecond = pCur->GetMark();
970 : 0 : break;
971 : : case StackMkCurrPt:
972 : 0 : pFirst = pStk->GetMark();
973 : 0 : pSecond = pCur->GetPoint();
974 : 0 : break;
975 : : case StackMkCurrMk:
976 : 0 : pFirst = pStk->GetMark();
977 : 0 : pSecond = pStk->GetMark();
978 : 0 : break;
979 : : case CurrPtCurrMk:
980 : 0 : pFirst = pCur->GetPoint();
981 : 0 : pSecond = pCur->GetMark();
982 : 0 : break;
983 : : }
984 : : }
985 [ # # ][ # # ]: 0 : if( !pFirst || !pSecond )
986 : 0 : nRet = INT_MAX;
987 [ # # ]: 0 : else if( *pFirst < *pSecond )
988 : 0 : nRet = -1;
989 [ # # ]: 0 : else if( *pFirst == *pSecond )
990 : 0 : nRet = 0;
991 : : else
992 : 0 : nRet = 1;
993 : 0 : return nRet;
994 : : }
995 : :
996 : :
997 : 0 : sal_Bool SwCrsrShell::IsSttPara() const
998 [ # # ]: 0 : { return( pCurCrsr->GetPoint()->nContent == 0 ? sal_True : sal_False ); }
999 : :
1000 : :
1001 : 0 : sal_Bool SwCrsrShell::IsEndPara() const
1002 [ # # ]: 0 : { return( pCurCrsr->GetPoint()->nContent == pCurCrsr->GetCntntNode()->Len() ? sal_True : sal_False ); }
1003 : :
1004 : :
1005 : 44 : sal_Bool SwCrsrShell::IsInFrontOfLabel() const
1006 : : {
1007 : 44 : return pCurCrsr->IsInFrontOfLabel();
1008 : : }
1009 : :
1010 : 44 : bool SwCrsrShell::SetInFrontOfLabel( sal_Bool bNew )
1011 : : {
1012 [ - + ]: 44 : if ( bNew != IsInFrontOfLabel() )
1013 : : {
1014 : 0 : pCurCrsr->_SetInFrontOfLabel( bNew );
1015 : 0 : UpdateMarkedListLevel();
1016 : 0 : return true;
1017 : : }
1018 : 44 : return false;
1019 : : }
1020 : :
1021 : 2 : sal_Bool SwCrsrShell::GotoPage( sal_uInt16 nPage )
1022 : : {
1023 [ + - ]: 2 : SET_CURR_SHELL( this );
1024 [ + - ]: 2 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
1025 [ + - ]: 2 : SwCrsrSaveState aSaveState( *pCurCrsr );
1026 [ + - ][ + - ]: 2 : sal_Bool bRet = GetLayout()->SetCurrPage( pCurCrsr, nPage ) &&
[ + - ]
1027 : : !pCurCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
1028 [ + - ][ + - ]: 2 : nsSwCursorSelOverFlags::SELOVER_CHANGEPOS );
[ + - ]
1029 [ + - ]: 2 : if( bRet )
1030 [ + - ]: 2 : UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
1031 [ + - ][ + - ]: 2 : return bRet;
[ + - ]
1032 : : }
1033 : :
1034 : :
1035 : 692 : void SwCrsrShell::GetPageNum( sal_uInt16 &rnPhyNum, sal_uInt16 &rnVirtNum,
1036 : : sal_Bool bAtCrsrPos, const sal_Bool bCalcFrm )
1037 : : {
1038 [ + - ]: 692 : SET_CURR_SHELL( this );
1039 : : // page number: first visible page or the one at the cursor
1040 : : const SwCntntFrm* pCFrm;
1041 : 692 : const SwPageFrm *pPg = 0;
1042 : :
1043 [ + - ][ + - ]: 692 : if( !bAtCrsrPos || 0 == (pCFrm = GetCurrFrm( bCalcFrm )) ||
[ + - ][ + - ]
[ - + ][ - + ]
1044 : 692 : 0 == (pPg = pCFrm->FindPageFrm()) )
1045 : : {
1046 [ # # ]: 0 : pPg = Imp()->GetFirstVisPage();
1047 [ # # ][ # # ]: 0 : while( pPg && pPg->IsEmptyPage() )
[ # # ]
1048 : 0 : pPg = (const SwPageFrm *)pPg->GetNext();
1049 : : }
1050 : : // pPg has to exist with a default of 1 for the special case "Writerstart"
1051 [ + - ]: 692 : rnPhyNum = pPg? pPg->GetPhyPageNum() : 1;
1052 [ + - ][ + - ]: 692 : rnVirtNum = pPg? pPg->GetVirtPageNum() : 1;
[ + - ]
1053 : 692 : }
1054 : :
1055 : :
1056 : 0 : sal_uInt16 SwCrsrShell::GetNextPrevPageNum( sal_Bool bNext )
1057 : : {
1058 [ # # ]: 0 : SET_CURR_SHELL( this );
1059 : :
1060 : : // page number: first visible page or the one at the cursor
1061 [ # # ]: 0 : const SwPageFrm *pPg = Imp()->GetFirstVisPage();
1062 [ # # ]: 0 : if( pPg )
1063 : : {
1064 : 0 : const SwTwips nPageTop = pPg->Frm().Top();
1065 : :
1066 [ # # ]: 0 : if( bNext )
1067 : : {
1068 : : // go to next view layout row:
1069 [ # # ]: 0 : do
[ # # # # ]
1070 : : {
1071 : 0 : pPg = (const SwPageFrm *)pPg->GetNext();
1072 : : }
1073 : 0 : while( pPg && pPg->Frm().Top() == nPageTop );
1074 : :
1075 [ # # ][ # # ]: 0 : while( pPg && pPg->IsEmptyPage() )
[ # # ]
1076 : 0 : pPg = (const SwPageFrm *)pPg->GetNext();
1077 : : }
1078 : : else
1079 : : {
1080 : : // go to previous view layout row:
1081 [ # # ]: 0 : do
[ # # # # ]
1082 : : {
1083 : 0 : pPg = (const SwPageFrm *)pPg->GetPrev();
1084 : : }
1085 : 0 : while( pPg && pPg->Frm().Top() == nPageTop );
1086 : :
1087 [ # # ][ # # ]: 0 : while( pPg && pPg->IsEmptyPage() )
[ # # ]
1088 : 0 : pPg = (const SwPageFrm *)pPg->GetPrev();
1089 : : }
1090 : : }
1091 : : // pPg has to exist with a default of 1 for the special case "Writerstart"
1092 [ # # ][ # # ]: 0 : return pPg ? pPg->GetPhyPageNum() : USHRT_MAX;
1093 : : }
1094 : :
1095 : :
1096 : 2865 : sal_uInt16 SwCrsrShell::GetPageCnt()
1097 : : {
1098 [ + - ]: 2865 : SET_CURR_SHELL( this );
1099 : : // return number of pages
1100 [ + - ][ + - ]: 2865 : return GetLayout()->GetPageNum();
1101 : : }
1102 : :
1103 : : /// go to the next SSelection
1104 : 0 : sal_Bool SwCrsrShell::GoNextCrsr()
1105 : : {
1106 : : // is there a ring of cursors?
1107 [ # # ][ # # ]: 0 : if( pCurCrsr->GetNext() == pCurCrsr )
1108 : 0 : return sal_False;
1109 : :
1110 [ # # ]: 0 : SET_CURR_SHELL( this );
1111 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
1112 [ # # ]: 0 : pCurCrsr = dynamic_cast<SwShellCrsr*>(pCurCrsr->GetNext());
1113 : :
1114 : : // #i24086#: show also all others
1115 [ # # ]: 0 : if( !ActionPend() )
1116 : : {
1117 [ # # ]: 0 : UpdateCrsr();
1118 [ # # ]: 0 : pCurCrsr->Show();
1119 : : }
1120 [ # # ][ # # ]: 0 : return sal_True;
1121 : : }
1122 : :
1123 : : /// go to the previous SSelection
1124 : 0 : sal_Bool SwCrsrShell::GoPrevCrsr()
1125 : : {
1126 : : // is there a ring of cursors?
1127 [ # # ][ # # ]: 0 : if( pCurCrsr->GetNext() == pCurCrsr )
1128 : 0 : return sal_False;
1129 : :
1130 [ # # ]: 0 : SET_CURR_SHELL( this );
1131 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
1132 [ # # ]: 0 : pCurCrsr = dynamic_cast<SwShellCrsr*>(pCurCrsr->GetPrev());
1133 : :
1134 : : // #i24086#: show also all others
1135 [ # # ]: 0 : if( !ActionPend() )
1136 : : {
1137 [ # # ]: 0 : UpdateCrsr();
1138 [ # # ]: 0 : pCurCrsr->Show();
1139 : : }
1140 : :
1141 [ # # ][ # # ]: 0 : return sal_True;
1142 : : }
1143 : :
1144 : :
1145 : 6681 : void SwCrsrShell::Paint( const Rectangle &rRect)
1146 : : {
1147 [ + - ]: 6681 : SET_CURR_SHELL( this );
1148 : :
1149 : : // always switch off all cursors when painting
1150 [ + - ]: 6681 : SwRect aRect( rRect );
1151 : :
1152 : 6681 : sal_Bool bVis = sal_False;
1153 : : // if a cursor is visible then hide the SV cursor
1154 [ + + ][ + - ]: 6681 : if( pVisCrsr->IsVisible() && !aRect.IsOver( aCharRect ) )
[ + + ][ + + ]
1155 : : {
1156 : 3375 : bVis = sal_True;
1157 [ + - ]: 3375 : pVisCrsr->Hide();
1158 : : }
1159 : :
1160 : : // re-paint area
1161 [ + - ]: 6681 : ViewShell::Paint( rRect );
1162 : :
1163 [ + + ][ + - ]: 6681 : if( bHasFocus && !bBasicHideCrsr )
1164 : : {
1165 [ + + ][ + - ]: 6591 : SwShellCrsr* pAktCrsr = pTblCrsr ? pTblCrsr : pCurCrsr;
1166 : :
1167 [ + + ]: 6591 : if( !ActionPend() )
1168 : : {
1169 : : // so that right/bottom borders will not be cropped
1170 [ + - ]: 4863 : pAktCrsr->Invalidate( VisArea() );
1171 [ + - ]: 4863 : pAktCrsr->Show();
1172 : : }
1173 : : else
1174 [ + - ]: 1728 : pAktCrsr->Invalidate( aRect );
1175 : :
1176 : : }
1177 [ + + ][ + + ]: 6681 : if( bSVCrsrVis && bVis ) // also show SV cursor again
1178 [ + - ][ + - ]: 6681 : pVisCrsr->Show();
1179 : 6681 : }
1180 : :
1181 : :
1182 : :
1183 : 2591 : void SwCrsrShell::VisPortChgd( const SwRect & rRect )
1184 : : {
1185 [ + - ]: 2591 : SET_CURR_SHELL( this );
1186 : : sal_Bool bVis; // switch off all cursors when scrolling
1187 : :
1188 : : // if a cursor is visible then hide the SV cursor
1189 [ + + ]: 2591 : if( sal_True == ( bVis = pVisCrsr->IsVisible() ))
1190 [ + - ]: 1837 : pVisCrsr->Hide();
1191 : :
1192 : 2591 : bVisPortChgd = sal_True;
1193 : 2591 : aOldRBPos.X() = VisArea().Right();
1194 : 2591 : aOldRBPos.Y() = VisArea().Bottom();
1195 : :
1196 : : // For not having problems with the SV cursor, Update() is called for the
1197 : : // Window in ViewShell::VisPo...
1198 : : // During painting no selections should be shown, thus the call is encapsulated. <- TODO: old artefact?
1199 [ + - ]: 2591 : ViewShell::VisPortChgd( rRect ); // move area
1200 : :
1201 [ + + ][ + + ]: 2591 : if( bSVCrsrVis && bVis ) // show SV cursor again
1202 [ + - ]: 1831 : pVisCrsr->Show();
1203 : :
1204 [ + + ]: 2591 : if( nCrsrMove )
1205 : 6 : bInCMvVisportChgd = sal_True;
1206 : :
1207 [ + - ]: 2591 : bVisPortChgd = sal_False;
1208 : 2591 : }
1209 : :
1210 : : /** Set the cursor back into content.
1211 : :
1212 : : This should only be called if the cursor was move somewhere else (e.g. when
1213 : : deleting a border). The new position is calculated from its current position
1214 : : in the layout.
1215 : : */
1216 : 35537 : void SwCrsrShell::UpdateCrsrPos()
1217 : : {
1218 [ + - ]: 35537 : SET_CURR_SHELL( this );
1219 : 35537 : ++nStartAction;
1220 [ + - ]: 35537 : SwShellCrsr* pShellCrsr = getShellCrsr( true );
1221 [ + - ]: 35537 : Size aOldSz( GetDocSize() );
1222 : 35537 : SwCntntNode *pCNode = pShellCrsr->GetCntntNode();
1223 : : SwCntntFrm *pFrm = pCNode ?
1224 [ + - ][ + - ]: 35537 : pCNode->getLayoutFrm( GetLayout(), &pShellCrsr->GetPtPos(), pShellCrsr->GetPoint(), sal_False ) :0;
[ + - ]
1225 [ + - ][ + - ]: 35537 : if( !pFrm || (pFrm->IsTxtFrm() && ((SwTxtFrm*)pFrm)->IsHiddenNow()) )
[ + - ][ + + ]
[ + + ]
1226 : : {
1227 : 20 : SwCrsrMoveState aTmpState( MV_NONE );
1228 : 20 : aTmpState.bSetInReadOnly = IsReadOnlyAvailable();
1229 [ + - ]: 20 : GetLayout()->GetCrsrOfst( pShellCrsr->GetPoint(), pShellCrsr->GetPtPos(),
1230 [ + - ]: 20 : &aTmpState );
1231 [ + + ]: 20 : if( pShellCrsr->HasMark())
1232 [ + - ]: 20 : pShellCrsr->DeleteMark();
1233 : : }
1234 [ + - ]: 35537 : IGrammarContact *pGrammarContact = GetDoc() ? GetDoc()->getGrammarContact() : 0;
1235 [ + - ]: 35537 : if( pGrammarContact )
1236 [ + - ]: 35537 : pGrammarContact->updateCursorPosition( *pCurCrsr->GetPoint() );
1237 : 35537 : --nStartAction;
1238 [ + - ][ - + ]: 35537 : if( aOldSz != GetDocSize() )
1239 [ # # ][ + - ]: 35537 : SizeChgNotify();
1240 : 35537 : }
1241 : :
1242 : : // #i65475# - if Point/Mark in hidden sections, move them out
1243 : 32 : static void lcl_CheckHiddenSection( SwNodeIndex& rIdx )
1244 : : {
1245 : 32 : const SwSectionNode* pSectNd = rIdx.GetNode().FindSectionNode();
1246 [ # # ][ - + ]: 32 : if( pSectNd && pSectNd->GetSection().IsHiddenFlag() )
[ - + ]
1247 : : {
1248 [ # # ]: 0 : SwNodeIndex aTmp( *pSectNd );
1249 : : const SwNode* pFrmNd =
1250 [ # # ]: 0 : rIdx.GetNodes().FindPrvNxtFrmNode( aTmp, pSectNd->EndOfSectionNode() );
1251 : : SAL_WARN_IF( !pFrmNd, "sw", "found no Node with Frames" );
1252 [ # # ][ # # ]: 0 : rIdx = aTmp;
1253 : : }
1254 : 32 : }
1255 : :
1256 : : /// Try to set the cursor to the next visible content node.
1257 : 32 : static void lcl_CheckHiddenPara( SwPosition& rPos )
1258 : : {
1259 [ + - ]: 32 : SwNodeIndex aTmp( rPos.nNode );
1260 : 32 : SwTxtNode* pTxtNd = aTmp.GetNode().GetTxtNode();
1261 [ + - ][ + - ]: 32 : while( pTxtNd && pTxtNd->HasHiddenCharAttribute( true ) )
[ - + ][ - + ]
1262 : : {
1263 [ # # ]: 0 : SwCntntNode* pCntnt = aTmp.GetNodes().GoNext( &aTmp );
1264 [ # # ][ # # ]: 0 : if ( pCntnt && pCntnt->IsTxtNode() )
[ # # ]
1265 : 0 : pTxtNd = (SwTxtNode*)pCntnt;
1266 : : else
1267 : 0 : pTxtNd = 0;
1268 : : }
1269 : :
1270 [ + - ]: 32 : if ( pTxtNd )
1271 [ + - ][ + - ]: 32 : rPos = SwPosition( aTmp, SwIndex( pTxtNd, 0 ) );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
1272 : 32 : }
1273 : :
1274 : : // #i27301# - helper class that notifies the accessibility about invalid text
1275 : : // selections in its destructor
1276 : : class SwNotifyAccAboutInvalidTextSelections
1277 : : {
1278 : : private:
1279 : : SwCrsrShell& mrCrsrSh;
1280 : :
1281 : : public:
1282 : 35553 : SwNotifyAccAboutInvalidTextSelections( SwCrsrShell& _rCrsrSh )
1283 : 35553 : : mrCrsrSh( _rCrsrSh )
1284 : 35553 : {}
1285 : :
1286 : 35553 : ~SwNotifyAccAboutInvalidTextSelections()
1287 : : {
1288 : 35553 : mrCrsrSh.InvalidateAccessibleParaTextSelection();
1289 : 35553 : }
1290 : : };
1291 : 35568 : void SwCrsrShell::UpdateCrsr( sal_uInt16 eFlags, sal_Bool bIdleEnd )
1292 : : {
1293 [ + - ]: 35568 : SET_CURR_SHELL( this );
1294 : :
1295 [ + - ]: 35568 : ClearUpCrsrs();
1296 : :
1297 : : // In a BasicAction the cursor must be updated, e.g. to create the
1298 : : // TableCursor. EndAction now calls UpdateCrsr!
1299 [ + + ][ + - ]: 35568 : if( ActionPend() && BasicActionPend() )
[ + + ]
1300 : : {
1301 [ + + ]: 15 : if ( eFlags & SwCrsrShell::READONLY )
1302 : 15 : bIgnoreReadonly = sal_True;
1303 : : return; // if not then no update
1304 : : }
1305 : :
1306 : 35553 : sal_Bool bInHeader= sal_True;
1307 [ + - ][ - + ]: 35553 : if ( IsInHeaderFooter( &bInHeader ) )
1308 : : {
1309 [ # # ]: 0 : if ( !bInHeader )
1310 : : {
1311 [ # # ]: 0 : SetShowHeaderFooterSeparator( Footer, true );
1312 [ # # ]: 0 : SetShowHeaderFooterSeparator( Header, false );
1313 : : }
1314 : : else
1315 : : {
1316 [ # # ]: 0 : SetShowHeaderFooterSeparator( Header, true );
1317 [ # # ]: 0 : SetShowHeaderFooterSeparator( Footer, false );
1318 : : }
1319 : : }
1320 [ + - ][ - + ]: 35553 : if ( IsInHeaderFooter() != IsHeaderFooterEdit() )
1321 [ # # ]: 0 : ToggleHeaderFooterEdit();
1322 : :
1323 : :
1324 : : // #i27301#
1325 : 35553 : SwNotifyAccAboutInvalidTextSelections aInvalidateTextSelections( *this );
1326 : :
1327 [ + + ]: 35553 : if ( bIgnoreReadonly )
1328 : : {
1329 : 4 : bIgnoreReadonly = sal_False;
1330 : 4 : eFlags |= SwCrsrShell::READONLY;
1331 : : }
1332 : :
1333 [ + + ]: 35553 : if( eFlags & SwCrsrShell::CHKRANGE ) // check all cursor moves for
1334 [ + - ][ + - ]: 35547 : CheckRange( pCurCrsr ); // overlapping ranges
1335 : :
1336 [ + + ]: 35553 : if( !bIdleEnd )
1337 [ + - ]: 34251 : CheckTblBoxCntnt();
1338 : :
1339 : : // If the current cursor is in a table and point/mark in different boxes,
1340 : : // then the table mode is active (also if it is already active: pTblCrsr)
1341 [ + - ][ + - ]: 35553 : SwPaM* pTstCrsr = getShellCrsr( true );
1342 [ + + ][ + - ]: 35763 : if( pTstCrsr->HasMark() && !pBlockCrsr &&
[ + + ]
[ + + + - ]
[ + + ]
1343 [ + - ]: 206 : pDoc->IsIdxInTbl( pTstCrsr->GetPoint()->nNode ) &&
1344 : : ( pTblCrsr ||
1345 : 4 : pTstCrsr->GetNode( sal_True )->StartOfSectionNode() !=
1346 : 4 : pTstCrsr->GetNode( sal_False )->StartOfSectionNode() ) )
1347 : : {
1348 [ + - ]: 16 : SwShellCrsr* pITmpCrsr = getShellCrsr( true );
1349 : 16 : Point aTmpPt( pITmpCrsr->GetPtPos() );
1350 : 16 : Point aTmpMk( pITmpCrsr->GetMkPos() );
1351 : 16 : SwPosition* pPos = pITmpCrsr->GetPoint();
1352 : :
1353 : : // Bug 65475 (1999) - if Point/Mark in hidden sections, move them out
1354 [ + - ]: 16 : lcl_CheckHiddenSection( pPos->nNode );
1355 [ + - ]: 16 : lcl_CheckHiddenSection( pITmpCrsr->GetMark()->nNode );
1356 : :
1357 : : // Move cursor out of hidden paragraphs
1358 [ + - ]: 16 : if ( !GetViewOptions()->IsShowHiddenChar() )
1359 : : {
1360 [ + - ]: 16 : lcl_CheckHiddenPara( *pPos );
1361 [ + - ]: 16 : lcl_CheckHiddenPara( *pITmpCrsr->GetMark() );
1362 : : }
1363 : :
1364 : 16 : SwCntntFrm *pTblFrm = pPos->nNode.GetNode().GetCntntNode()->
1365 [ + - + - ]: 32 : getLayoutFrm( GetLayout(), &aTmpPt, pPos, sal_False );
1366 : :
1367 : : OSL_ENSURE( pTblFrm, "Tabelle Crsr nicht im Content ??" );
1368 : :
1369 : : // --> Make code robust. The table cursor may point
1370 : : // to a table in a currently inactive header.
1371 [ + - ][ + - ]: 16 : SwTabFrm *pTab = pTblFrm ? pTblFrm->FindTabFrm() : 0;
1372 : :
1373 [ + - ][ + - ]: 16 : if ( pTab && pTab->GetTable()->GetRowsToRepeat() > 0 )
[ - + ][ - + ]
1374 : : {
1375 : : // First check if point is in repeated headline:
1376 [ # # ][ # # ]: 0 : bool bInRepeatedHeadline = pTab->IsFollow() && pTab->IsInHeadline( *pTblFrm );
[ # # ]
1377 : :
1378 : : // Second check if mark is in repeated headline:
1379 [ # # ]: 0 : if ( !bInRepeatedHeadline )
1380 : : {
1381 : : SwCntntFrm* pMarkTblFrm = pITmpCrsr->GetCntntNode( sal_False )->
1382 [ # # ][ # # ]: 0 : getLayoutFrm( GetLayout(), &aTmpMk, pITmpCrsr->GetMark(), sal_False );
1383 : : OSL_ENSURE( pMarkTblFrm, "Tabelle Crsr nicht im Content ??" );
1384 : :
1385 [ # # ]: 0 : if ( pMarkTblFrm )
1386 : : {
1387 [ # # ]: 0 : SwTabFrm* pMarkTab = pMarkTblFrm->FindTabFrm();
1388 : : OSL_ENSURE( pMarkTab, "Tabelle Crsr nicht im Content ??" );
1389 : :
1390 : : // Make code robust:
1391 [ # # ]: 0 : if ( pMarkTab )
1392 : : {
1393 [ # # ][ # # ]: 0 : bInRepeatedHeadline = pMarkTab->IsFollow() && pMarkTab->IsInHeadline( *pMarkTblFrm );
[ # # ]
1394 : : }
1395 : : }
1396 : : }
1397 : :
1398 : : // No table cursor in repeaded headlines:
1399 [ # # ]: 0 : if ( bInRepeatedHeadline )
1400 : : {
1401 : 0 : pTblFrm = 0;
1402 : :
1403 [ # # ]: 0 : SwPosSection fnPosSect = *pPos < *pITmpCrsr->GetMark()
1404 : : ? fnSectionStart
1405 [ # # ]: 0 : : fnSectionEnd;
1406 : :
1407 : : // then only select inside the Box
1408 [ # # ]: 0 : if( pTblCrsr )
1409 : : {
1410 [ # # ]: 0 : pCurCrsr->SetMark();
1411 [ # # ]: 0 : *pCurCrsr->GetMark() = *pTblCrsr->GetMark();
1412 : 0 : pCurCrsr->GetMkPos() = pTblCrsr->GetMkPos();
1413 [ # # ]: 0 : pTblCrsr->DeleteMark();
1414 [ # # ]: 0 : pTblCrsr->SwSelPaintRects::Hide();
1415 : : }
1416 : :
1417 [ # # ]: 0 : *pCurCrsr->GetPoint() = *pCurCrsr->GetMark();
1418 [ # # ]: 0 : (*fnSectionCurr)( *pCurCrsr, fnPosSect );
1419 : : }
1420 : : }
1421 : :
1422 : : // we really want a table selection
1423 [ + - ][ + - ]: 16 : if( pTab && pTblFrm )
1424 : : {
1425 [ + + ]: 16 : if( !pTblCrsr )
1426 : : {
1427 : : pTblCrsr = new SwShellTableCrsr( *this,
1428 : 8 : *pCurCrsr->GetMark(), pCurCrsr->GetMkPos(),
1429 [ + - ][ + - ]: 4 : *pPos, aTmpPt );
1430 [ + - ]: 4 : pCurCrsr->DeleteMark();
1431 [ + - ]: 4 : pCurCrsr->SwSelPaintRects::Hide();
1432 : :
1433 [ + - ]: 4 : CheckTblBoxCntnt();
1434 : : }
1435 : :
1436 : 16 : SwCrsrMoveState aTmpState( MV_NONE );
1437 : 16 : aTmpState.bRealHeight = sal_True;
1438 [ - + ][ + - ]: 16 : if( !pTblFrm->GetCharRect( aCharRect, *pTblCrsr->GetPoint(), &aTmpState ) )
1439 : : {
1440 [ # # ]: 0 : Point aCentrPt( aCharRect.Center() );
1441 : 0 : aTmpState.bSetInReadOnly = IsReadOnlyAvailable();
1442 [ # # ]: 0 : pTblFrm->GetCrsrOfst( pTblCrsr->GetPoint(), aCentrPt, &aTmpState );
1443 : : bool const bResult =
1444 [ # # ]: 0 : pTblFrm->GetCharRect( aCharRect, *pTblCrsr->GetPoint() );
1445 : : OSL_ENSURE( bResult, "GetCharRect failed." );
1446 : : (void) bResult; // non-debug: unused
1447 : : }
1448 : :
1449 [ + - ]: 16 : pVisCrsr->Hide(); // always hide visible Cursor
1450 : : // scroll Cursor to visible area
1451 [ + - ][ - + ]: 32 : if( (eFlags & SwCrsrShell::SCROLLWIN) &&
[ # # ][ # # ]
[ + - ]
1452 [ + - ]: 16 : (HasSelection() || eFlags & SwCrsrShell::READONLY ||
1453 [ # # ]: 0 : !IsCrsrReadonly()) )
1454 : : {
1455 : 16 : SwFrm* pBoxFrm = pTblFrm;
1456 [ + - ][ + + ]: 32 : while( pBoxFrm && !pBoxFrm->IsCellFrm() )
[ + + ]
1457 : 16 : pBoxFrm = pBoxFrm->GetUpper();
1458 [ + - ][ + - ]: 16 : if( pBoxFrm && pBoxFrm->Frm().HasArea() )
[ + - ][ + - ]
1459 [ + - ]: 16 : MakeVisible( pBoxFrm->Frm() );
1460 : : else
1461 [ # # ]: 0 : MakeVisible( aCharRect );
1462 : : }
1463 : :
1464 : : // let Layout create the Cursors in the Boxes
1465 [ + - ][ + + ]: 16 : if( pTblCrsr->IsCrsrMovedUpdt() )
1466 [ + - ][ + - ]: 4 : GetLayout()->MakeTblCrsrs( *pTblCrsr );
1467 [ + - ][ + - ]: 16 : if( bHasFocus && !bBasicHideCrsr )
1468 [ + - ]: 16 : pTblCrsr->Show();
1469 : :
1470 : : // set Cursor-Points to the new Positions
1471 : 16 : pTblCrsr->GetPtPos().X() = aCharRect.Left();
1472 : 16 : pTblCrsr->GetPtPos().Y() = aCharRect.Top();
1473 : :
1474 [ + - ]: 16 : if( bSVCrsrVis )
1475 : : {
1476 : 16 : aCrsrHeight.X() = 0;
1477 : 16 : aCrsrHeight.Y() = aTmpState.aRealHeight.Y() < 0 ?
1478 [ - + ]: 16 : -aCharRect.Width() : aCharRect.Height();
1479 [ + - ]: 16 : pVisCrsr->Show(); // show again
1480 : : }
1481 : 16 : eMvState = MV_NONE; // state for cursor travelling - GetCrsrOfst
1482 [ + - ][ + - ]: 16 : if( pTblFrm && Imp()->IsAccessible() )
[ + - ]
1483 [ + - ]: 16 : Imp()->InvalidateAccessibleCursorPosition( pTblFrm );
1484 : : return;
1485 : : }
1486 : : }
1487 : :
1488 [ - + ]: 35537 : if( pTblCrsr )
1489 : : {
1490 : : // delete Ring
1491 [ # # ][ # # ]: 0 : while( pCurCrsr->GetNext() != pCurCrsr )
1492 [ # # ][ # # ]: 0 : delete pCurCrsr->GetNext();
1493 [ # # ]: 0 : pCurCrsr->DeleteMark();
1494 [ # # ]: 0 : *pCurCrsr->GetPoint() = *pTblCrsr->GetPoint();
1495 : 0 : pCurCrsr->GetPtPos() = pTblCrsr->GetPtPos();
1496 [ # # ][ # # ]: 0 : delete pTblCrsr, pTblCrsr = 0;
1497 : : }
1498 : :
1499 [ + - ]: 35537 : pVisCrsr->Hide(); // always hide visible Cursor
1500 : :
1501 : : // are we perhaps in a protected / hidden Section ?
1502 : : {
1503 [ + - ]: 35537 : SwShellCrsr* pShellCrsr = getShellCrsr( true );
1504 : 35537 : sal_Bool bChgState = sal_True;
1505 [ + - ]: 35537 : const SwSectionNode* pSectNd = pShellCrsr->GetNode()->FindSectionNode();
1506 [ + + ][ + - : 35591 : if( pSectNd && ( pSectNd->GetSection().IsHiddenFlag() ||
- + # # #
# ][ # # ]
[ # # ][ - + ]
1507 : 54 : ( !IsReadOnlyAvailable() &&
1508 : 0 : pSectNd->GetSection().IsProtectFlag() &&
1509 : 0 : ( !pDoc->GetDocShell() ||
1510 [ # # ]: 0 : !pDoc->GetDocShell()->IsReadOnly() || bAllProtect )) ) )
1511 : : {
1512 [ # # ][ # # ]: 0 : if( !FindValidCntntNode( !HasDrawView() ||
1513 [ # # ][ # # ]: 0 : 0 == Imp()->GetDrawView()->GetMarkedObjectList().GetMarkCount()))
[ # # ]
1514 : : {
1515 : : // everything protected/hidden -> special mode
1516 [ # # ]: 0 : if( bAllProtect && !IsReadOnlyAvailable() &&
[ # # # # ]
[ # # ]
1517 : 0 : pSectNd->GetSection().IsProtectFlag() )
1518 : 0 : bChgState = sal_False;
1519 : : else
1520 : : {
1521 : 0 : eMvState = MV_NONE; // state for cursor travelling
1522 : 0 : bAllProtect = sal_True;
1523 [ # # ]: 0 : if( GetDoc()->GetDocShell() )
1524 : : {
1525 [ # # ]: 0 : GetDoc()->GetDocShell()->SetReadOnlyUI( sal_True );
1526 [ # # ]: 0 : CallChgLnk(); // notify UI!
1527 : : }
1528 : : return;
1529 : : }
1530 : : }
1531 : : }
1532 [ + - ]: 35537 : if( bChgState )
1533 : : {
1534 : 35537 : sal_Bool bWasAllProtect = bAllProtect;
1535 : 35537 : bAllProtect = sal_False;
1536 [ - + ][ # # ]: 35537 : if( bWasAllProtect && GetDoc()->GetDocShell() &&
[ # # ][ - + ]
1537 [ # # ]: 0 : GetDoc()->GetDocShell()->IsReadOnlyUI() )
1538 : : {
1539 [ # # ]: 0 : GetDoc()->GetDocShell()->SetReadOnlyUI( sal_False );
1540 [ # # ]: 0 : CallChgLnk(); // notify UI!
1541 : : }
1542 : : }
1543 : : }
1544 : :
1545 [ + - ]: 35537 : UpdateCrsrPos();
1546 : :
1547 : : // The cursor must always point into content; there's some code
1548 : : // that relies on this. (E.g. in SwEditShell::GetScriptType, which always
1549 : : // loops _behind_ the last node in the selection, which always works if you
1550 : : // are in content.) To achieve this, we'll force cursor(s) to point into
1551 : : // content, if UpdateCrsrPos() hasn't already done so.
1552 [ + - ]: 35537 : SwPaM* pCmp = pCurCrsr;
1553 [ - + ][ + - ]: 35537 : do
1554 : : {
1555 : : // start will move forwards, end will move backwards
1556 [ + - ]: 35537 : bool bPointIsStart = ( pCmp->Start() == pCmp->GetPoint() );
1557 : :
1558 : : // move point; forward if it's the start, backwards if it's the end
1559 [ - + ]: 35537 : if( ! pCmp->GetPoint()->nNode.GetNode().IsCntntNode() )
1560 : : pCmp->Move( bPointIsStart ? fnMoveForward : fnMoveBackward,
1561 [ # # ][ # # ]: 0 : fnGoCntnt );
1562 : :
1563 : : // move mark (if exists); forward if it's the start, else backwards
1564 [ + + ]: 35537 : if( pCmp->HasMark() )
1565 : : {
1566 [ - + ]: 188 : if( ! pCmp->GetMark()->nNode.GetNode().IsCntntNode() )
1567 : : {
1568 : 0 : pCmp->Exchange();
1569 : 0 : pCmp->Move( !bPointIsStart ? fnMoveForward : fnMoveBackward,
1570 [ # # ][ # # ]: 0 : fnGoCntnt );
1571 : 0 : pCmp->Exchange();
1572 : : }
1573 : : }
1574 : :
1575 : : // iterate to next PaM in ring
1576 : 35537 : pCmp = static_cast<SwPaM*>( pCmp->GetNext() );
1577 : : }
1578 : 35537 : while( pCmp != pCurCrsr );
1579 : :
1580 : :
1581 : 35537 : SwRect aOld( aCharRect );
1582 : 35537 : sal_Bool bFirst = sal_True;
1583 : : SwCntntFrm *pFrm;
1584 : 35537 : int nLoopCnt = 100;
1585 [ + - ]: 35537 : SwShellCrsr* pShellCrsr = getShellCrsr( true );
1586 : :
1587 [ + + ]: 35537 : do {
1588 : : sal_Bool bAgainst;
1589 [ - + ]: 69345 : do {
1590 : 69345 : bAgainst = sal_False;
1591 [ + - ]: 69345 : pFrm = pShellCrsr->GetCntntNode()->getLayoutFrm( GetLayout(),
1592 [ + - ]: 138690 : &pShellCrsr->GetPtPos(), pShellCrsr->GetPoint(), sal_False );
1593 : : // if the Frm doesn't exist anymore, the complete Layout has to be
1594 : : // created, because there used to be a Frm here!
1595 [ - + ]: 69345 : if ( !pFrm )
1596 : : {
1597 [ # # ]: 0 : do
1598 : : {
1599 [ # # ]: 0 : CalcLayout();
1600 [ # # ]: 0 : pFrm = pShellCrsr->GetCntntNode()->getLayoutFrm( GetLayout(),
1601 [ # # ]: 0 : &pShellCrsr->GetPtPos(), pShellCrsr->GetPoint(), sal_False );
1602 : 0 : } while( !pFrm );
1603 : : }
1604 [ + + ]: 69345 : else if ( Imp()->IsIdleAction() )
1605 : : // Guarantee everything's properly formatted
1606 [ + - ]: 174 : pFrm->PrepareCrsr();
1607 : :
1608 : : // In protected Fly? but ignore in case of frame selection
1609 [ - + ][ # # ]: 69345 : if( !IsReadOnlyAvailable() && pFrm->IsProtected() &&
[ # # # #
# # # # ]
[ # # ][ # # ]
[ - + ]
1610 : 0 : ( !Imp()->GetDrawView() ||
1611 : 0 : !Imp()->GetDrawView()->GetMarkedObjectList().GetMarkCount() ) &&
1612 : 0 : (!pDoc->GetDocShell() ||
1613 [ # # ]: 0 : !pDoc->GetDocShell()->IsReadOnly() || bAllProtect ) )
1614 : : {
1615 : : // look for a valid position
1616 : 0 : sal_Bool bChgState = sal_True;
1617 [ # # ][ # # ]: 0 : if( !FindValidCntntNode(!HasDrawView() ||
1618 [ # # ][ # # ]: 0 : 0 == Imp()->GetDrawView()->GetMarkedObjectList().GetMarkCount()))
[ # # ]
1619 : : {
1620 : : // everything is protected / hidden -> special Mode
1621 [ # # ]: 0 : if( bAllProtect )
1622 : 0 : bChgState = sal_False;
1623 : : else
1624 : : {
1625 : 0 : eMvState = MV_NONE; // state for crusor travelling
1626 : 0 : bAllProtect = sal_True;
1627 [ # # ]: 0 : if( GetDoc()->GetDocShell() )
1628 : : {
1629 [ # # ]: 0 : GetDoc()->GetDocShell()->SetReadOnlyUI( sal_True );
1630 [ # # ]: 0 : CallChgLnk(); // notify UI!
1631 : : }
1632 : : return;
1633 : : }
1634 : : }
1635 : :
1636 [ # # ]: 0 : if( bChgState )
1637 : : {
1638 : 0 : sal_Bool bWasAllProtect = bAllProtect;
1639 : 0 : bAllProtect = sal_False;
1640 [ # # ][ # # ]: 0 : if( bWasAllProtect && GetDoc()->GetDocShell() &&
[ # # ][ # # ]
1641 [ # # ]: 0 : GetDoc()->GetDocShell()->IsReadOnlyUI() )
1642 : : {
1643 [ # # ]: 0 : GetDoc()->GetDocShell()->SetReadOnlyUI( sal_False );
1644 [ # # ]: 0 : CallChgLnk(); // notify UI!
1645 : : }
1646 : 0 : bAllProtect = sal_False;
1647 : 0 : bAgainst = sal_True; // look for the right Frm again
1648 : : }
1649 : : }
1650 : : } while( bAgainst );
1651 : :
1652 [ + - ]: 69345 : if( !( eFlags & SwCrsrShell::NOCALRECT ))
1653 : : {
1654 : 69345 : SwCrsrMoveState aTmpState( eMvState );
1655 : 69345 : aTmpState.bSetInReadOnly = IsReadOnlyAvailable();
1656 : 69345 : aTmpState.bRealHeight = sal_True;
1657 : 69345 : aTmpState.bRealWidth = IsOverwriteCrsr();
1658 : 69345 : aTmpState.nCursorBidiLevel = pShellCrsr->GetCrsrBidiLevel();
1659 : :
1660 : : // #i27615#,#i30453#
1661 : 69345 : SwSpecialPos aSpecialPos;
1662 : 69345 : aSpecialPos.nExtendRange = SP_EXTEND_RANGE_BEFORE;
1663 [ - + ]: 69345 : if (pShellCrsr->IsInFrontOfLabel())
1664 : : {
1665 : 0 : aTmpState.pSpecialPos = &aSpecialPos;
1666 : : }
1667 : :
1668 [ + - ][ + + ]: 69345 : if( !pFrm->GetCharRect( aCharRect, *pShellCrsr->GetPoint(), &aTmpState ) )
1669 : : {
1670 : 160 : Point& rPt = pShellCrsr->GetPtPos();
1671 [ + - ]: 160 : rPt = aCharRect.Center();
1672 [ + - ]: 160 : pFrm->GetCrsrOfst( pShellCrsr->GetPoint(), rPt, &aTmpState );
1673 : : }
1674 : :
1675 [ + + ]: 69345 : if( !pShellCrsr->HasMark() )
1676 : 68969 : aCrsrHeight = aTmpState.aRealHeight;
1677 : : else
1678 : : {
1679 : 376 : aCrsrHeight.X() = 0;
1680 : 376 : aCrsrHeight.Y() = aTmpState.aRealHeight.Y() < 0 ?
1681 [ - + ]: 69345 : -aCharRect.Width() : aCharRect.Height();
1682 : : }
1683 : : }
1684 : : else
1685 : : {
1686 : 0 : aCrsrHeight.X() = 0;
1687 : 0 : aCrsrHeight.Y() = aCharRect.Height();
1688 : : }
1689 : :
1690 [ + + ][ + - ]: 69345 : if( !bFirst && aOld == aCharRect )
[ + + ]
1691 : 33808 : break;
1692 : :
1693 : : // if the layout says that we are after the 100th iteration still in
1694 : : // flow then we should always take the current position for granted.
1695 : : // (see bug: 29658)
1696 [ - + ]: 35537 : if( !--nLoopCnt )
1697 : : {
1698 : : OSL_ENSURE( !this, "endless loop? CharRect != OldCharRect ");
1699 : 0 : break;
1700 : : }
1701 : 35537 : aOld = aCharRect;
1702 : 35537 : bFirst = sal_False;
1703 : :
1704 : : // update cursor Points to the new Positions
1705 : 35537 : pShellCrsr->GetPtPos().X() = aCharRect.Left();
1706 : 35537 : pShellCrsr->GetPtPos().Y() = aCharRect.Top();
1707 : :
1708 [ + - ]: 35537 : if( !(eFlags & SwCrsrShell::UPDOWN )) // delete old Pos. of Up/Down
1709 : : {
1710 [ + - ]: 35537 : pFrm->Calc();
1711 [ + - ]: 35537 : nUpDownX = pFrm->IsVertical() ?
1712 : 2 : aCharRect.Top() - pFrm->Frm().Top() :
1713 [ + + ]: 35539 : aCharRect.Left() - pFrm->Frm().Left();
1714 : : }
1715 : :
1716 : : // scroll Cursor to visible area
1717 [ + + ][ + + ]: 102632 : if( bHasFocus && eFlags & SwCrsrShell::SCROLLWIN &&
[ + + ][ + + ]
[ + + - + ]
[ + + ]
1718 [ + - ]: 33652 : (HasSelection() || eFlags & SwCrsrShell::READONLY ||
1719 [ + - ]: 33443 : !IsCrsrReadonly() || GetViewOptions()->IsSelectionInReadonly()) )
1720 : : {
1721 : : // in case of scrolling this EndAction doesn't show the SV cursor
1722 : : // again, thus save and reset the flag here
1723 : 33638 : sal_Bool bSav = bSVCrsrVis; bSVCrsrVis = sal_False;
1724 [ + - ]: 33638 : MakeSelVisible();
1725 : 33638 : bSVCrsrVis = bSav;
1726 : : }
1727 : :
1728 : : } while( eFlags & SwCrsrShell::SCROLLWIN );
1729 : :
1730 [ - + ]: 35537 : if( pBlockCrsr )
1731 [ # # ]: 0 : RefreshBlockCursor();
1732 : :
1733 [ + + ][ + + ]: 35537 : if( !bIdleEnd && bHasFocus && !bBasicHideCrsr )
[ + - ]
1734 : : {
1735 [ - + ]: 34079 : if( pTblCrsr )
1736 [ # # ]: 0 : pTblCrsr->SwSelPaintRects::Show();
1737 : : else
1738 : : {
1739 [ + - ]: 34079 : pCurCrsr->SwSelPaintRects::Show();
1740 [ - + ]: 34079 : if( pBlockCrsr )
1741 : : {
1742 [ # # ]: 0 : SwShellCrsr* pNxt = dynamic_cast<SwShellCrsr*>(pCurCrsr->GetNext());
1743 [ # # ][ # # ]: 0 : while( pNxt && pNxt != pCurCrsr )
[ # # ]
1744 : : {
1745 [ # # ]: 0 : pNxt->SwSelPaintRects::Show();
1746 [ # # ]: 0 : pNxt = dynamic_cast<SwShellCrsr*>(pNxt->GetNext());
1747 : : }
1748 : : }
1749 : : }
1750 : : }
1751 : :
1752 : 35537 : eMvState = MV_NONE; // state for cursor tavelling - GetCrsrOfst
1753 : :
1754 [ + - ][ + + ]: 35537 : if( pFrm && Imp()->IsAccessible() )
[ + + ]
1755 [ + - ]: 126 : Imp()->InvalidateAccessibleCursorPosition( pFrm );
1756 : :
1757 : : // switch from blinking cursor to read-only-text-selection cursor
1758 : : static const long nNoBlinkTime = STYLE_CURSOR_NOBLINKTIME;
1759 : 35537 : const long nBlinkTime = GetOut()->GetSettings().GetStyleSettings().
1760 : 35537 : GetCursorBlinkTime();
1761 : :
1762 [ + + ][ - + ]: 35537 : if ( (IsCrsrReadonly() && GetViewOptions()->IsSelectionInReadonly()) ==
[ + - ][ + - ]
1763 : : ( nBlinkTime != nNoBlinkTime ) )
1764 : : {
1765 : : // non blinking cursor in read only - text selection mode
1766 [ + - ]: 35537 : AllSettings aSettings = GetOut()->GetSettings();
1767 [ + - ]: 35537 : StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1768 : : const long nNewBlinkTime = nBlinkTime == nNoBlinkTime ?
1769 [ + - ]: 35537 : Application::GetSettings().GetStyleSettings().GetCursorBlinkTime() :
1770 [ + - ]: 71074 : nNoBlinkTime;
1771 [ + - ]: 35537 : aStyleSettings.SetCursorBlinkTime( nNewBlinkTime );
1772 [ + - ]: 35537 : aSettings.SetStyleSettings( aStyleSettings );
1773 [ + - ][ + - ]: 35537 : GetOut()->SetSettings( aSettings );
[ + - ]
1774 : : }
1775 : :
1776 [ + + ]: 35537 : if( bSVCrsrVis )
1777 [ + - ][ + - ]: 35568 : pVisCrsr->Show(); // show again
[ + + ][ + - ]
[ + + ]
1778 : : }
1779 : :
1780 : 0 : void SwCrsrShell::RefreshBlockCursor()
1781 : : {
1782 : : OSL_ENSURE( pBlockCrsr, "Don't call me without a block cursor" );
1783 [ # # ]: 0 : SwShellCrsr &rBlock = pBlockCrsr->getShellCrsr();
1784 : 0 : Point aPt = rBlock.GetPtPos();
1785 [ # # ][ # # ]: 0 : SwCntntFrm* pFrm = rBlock.GetCntntNode()->getLayoutFrm( GetLayout(), &aPt, rBlock.GetPoint(), sal_False );
1786 : 0 : Point aMk;
1787 [ # # ][ # # ]: 0 : if( pBlockCrsr->getEndPoint() && pBlockCrsr->getStartPoint() )
[ # # ][ # # ]
[ # # ]
1788 : : {
1789 [ # # ]: 0 : aPt = *pBlockCrsr->getStartPoint();
1790 [ # # ]: 0 : aMk = *pBlockCrsr->getEndPoint();
1791 : : }
1792 : : else
1793 : : {
1794 : 0 : aPt = rBlock.GetPtPos();
1795 [ # # ]: 0 : if( pFrm )
1796 : : {
1797 [ # # ][ # # ]: 0 : if( pFrm->IsVertical() )
1798 : 0 : aPt.Y() = pFrm->Frm().Top() + GetUpDownX();
1799 : : else
1800 : 0 : aPt.X() = pFrm->Frm().Left() + GetUpDownX();
1801 : : }
1802 : 0 : aMk = rBlock.GetMkPos();
1803 : : }
1804 : 0 : SwRect aRect( aMk, aPt );
1805 [ # # ]: 0 : aRect.Justify();
1806 [ # # ]: 0 : SwSelectionList aSelList( pFrm );
1807 : :
1808 [ # # ][ # # ]: 0 : if( GetLayout()->FillSelection( aSelList, aRect ) )
[ # # ]
1809 : : {
1810 : 0 : SwCursor* pNxt = (SwCursor*)pCurCrsr->GetNext();
1811 [ # # ][ # # ]: 0 : while( pNxt != pCurCrsr )
1812 : : {
1813 [ # # ][ # # ]: 0 : delete pNxt;
1814 : 0 : pNxt = (SwCursor*)pCurCrsr->GetNext();
1815 : : }
1816 : :
1817 : 0 : std::list<SwPaM*>::iterator pStart = aSelList.getStart();
1818 : 0 : std::list<SwPaM*>::iterator pPam = aSelList.getEnd();
1819 : : OSL_ENSURE( pPam != pStart, "FillSelection should deliver at least one PaM" );
1820 [ # # ]: 0 : pCurCrsr->SetMark();
1821 [ # # ]: 0 : --pPam;
1822 : : // If there is only one text portion inside the rectangle, a simple
1823 : : // selection is created
1824 [ # # ][ # # ]: 0 : if( pPam == pStart )
1825 : : {
1826 [ # # ][ # # ]: 0 : *pCurCrsr->GetPoint() = *(*pPam)->GetPoint();
1827 [ # # ][ # # ]: 0 : if( (*pPam)->HasMark() )
1828 [ # # ][ # # ]: 0 : *pCurCrsr->GetMark() = *(*pPam)->GetMark();
1829 : : else
1830 [ # # ]: 0 : pCurCrsr->DeleteMark();
1831 [ # # ][ # # ]: 0 : delete *pPam;
[ # # ]
1832 : 0 : pCurCrsr->SetColumnSelection( false );
1833 : : }
1834 : : else
1835 : : {
1836 : : // The order of the SwSelectionList has to be preserved but
1837 : : // the order inside the ring created by CreateCrsr() is not like
1838 : : // exspected => First create the selections before the last one
1839 : : // downto the first selection.
1840 : : // At least create the cursor for the last selection
1841 [ # # ]: 0 : --pPam;
1842 [ # # ][ # # ]: 0 : *pCurCrsr->GetPoint() = *(*pPam)->GetPoint(); // n-1 (if n == number of selections)
1843 [ # # ][ # # ]: 0 : if( (*pPam)->HasMark() )
1844 [ # # ][ # # ]: 0 : *pCurCrsr->GetMark() = *(*pPam)->GetMark();
1845 : : else
1846 [ # # ]: 0 : pCurCrsr->DeleteMark();
1847 [ # # ][ # # ]: 0 : delete *pPam;
[ # # ]
1848 : 0 : pCurCrsr->SetColumnSelection( true );
1849 [ # # ][ # # ]: 0 : while( pPam != pStart )
1850 : : {
1851 [ # # ]: 0 : --pPam;
1852 : :
1853 [ # # ][ # # ]: 0 : SwShellCrsr* pNew = new SwShellCrsr( *pCurCrsr );
1854 [ # # ]: 0 : pNew->insert( pNew->begin(), pCurCrsr->begin(), pCurCrsr->end());
1855 : 0 : pCurCrsr->clear();
1856 [ # # ]: 0 : pCurCrsr->DeleteMark();
1857 : :
1858 [ # # ][ # # ]: 0 : *pCurCrsr->GetPoint() = *(*pPam)->GetPoint(); // n-2, n-3, .., 2, 1
1859 [ # # ][ # # ]: 0 : if( (*pPam)->HasMark() )
1860 : : {
1861 [ # # ]: 0 : pCurCrsr->SetMark();
1862 [ # # ][ # # ]: 0 : *pCurCrsr->GetMark() = *(*pPam)->GetMark();
1863 : : }
1864 : : else
1865 [ # # ]: 0 : pCurCrsr->DeleteMark();
1866 : 0 : pCurCrsr->SetColumnSelection( true );
1867 [ # # ][ # # ]: 0 : delete *pPam;
[ # # ]
1868 : : }
1869 : : {
1870 [ # # ][ # # ]: 0 : SwShellCrsr* pNew = new SwShellCrsr( *pCurCrsr );
1871 [ # # ]: 0 : pNew->insert( pNew->begin(), pCurCrsr->begin(), pCurCrsr->end() );
1872 : 0 : pCurCrsr->clear();
1873 [ # # ]: 0 : pCurCrsr->DeleteMark();
1874 : : }
1875 : 0 : pPam = aSelList.getEnd();
1876 [ # # ]: 0 : --pPam;
1877 [ # # ][ # # ]: 0 : *pCurCrsr->GetPoint() = *(*pPam)->GetPoint(); // n, the last selection
1878 [ # # ][ # # ]: 0 : if( (*pPam)->HasMark() )
1879 : : {
1880 [ # # ]: 0 : pCurCrsr->SetMark();
1881 [ # # ][ # # ]: 0 : *pCurCrsr->GetMark() = *(*pPam)->GetMark();
1882 : : }
1883 : : else
1884 [ # # ]: 0 : pCurCrsr->DeleteMark();
1885 : 0 : pCurCrsr->SetColumnSelection( true );
1886 [ # # ][ # # ]: 0 : delete *pPam;
[ # # ]
1887 : : }
1888 : 0 : }
1889 : 0 : }
1890 : :
1891 : : /// create a copy of the cursor and save it in the stack
1892 : 17 : void SwCrsrShell::Push()
1893 : : {
1894 : 17 : pCrsrStk = new SwShellCrsr( *this, *pCurCrsr->GetPoint(),
1895 [ - + ][ + - ]: 17 : pCurCrsr->GetPtPos(), pCrsrStk );
1896 : :
1897 [ - + ]: 17 : if( pCurCrsr->HasMark() )
1898 : : {
1899 : 0 : pCrsrStk->SetMark();
1900 : 0 : *pCrsrStk->GetMark() = *pCurCrsr->GetMark();
1901 : : }
1902 : 17 : }
1903 : :
1904 : : /** delete cursor
1905 : :
1906 : : @param bOldCrsr If <true> so delete from stack, if <false> delete current
1907 : : and assign the one from stack as the new current cursor.
1908 : : @return <true> if there was one on the stack, <false> otherwise
1909 : : */
1910 : 17 : sal_Bool SwCrsrShell::Pop( sal_Bool bOldCrsr )
1911 : : {
1912 [ + - ]: 17 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
1913 : :
1914 : : // are there any left?
1915 [ - + ]: 17 : if( 0 == pCrsrStk )
1916 : 0 : return sal_False;
1917 : :
1918 : 17 : SwShellCrsr *pTmp = 0, *pOldStk = pCrsrStk;
1919 : :
1920 : : // the successor becomes the current one
1921 [ + - ][ - + ]: 17 : if( pCrsrStk->GetNext() != pCrsrStk )
1922 : : {
1923 [ # # ]: 0 : pTmp = dynamic_cast<SwShellCrsr*>(pCrsrStk->GetNext());
1924 : : }
1925 : :
1926 [ + + ]: 17 : if( bOldCrsr ) // delete from stack
1927 [ + - ][ + - ]: 6 : delete pCrsrStk;
1928 : :
1929 : 17 : pCrsrStk = pTmp; // assign new one
1930 : :
1931 [ + + ]: 17 : if( !bOldCrsr )
1932 : : {
1933 [ + - ]: 11 : SwCrsrSaveState aSaveState( *pCurCrsr );
1934 : :
1935 : : // If the visible SSelection was not changed
1936 [ - + # # ]: 11 : if( pOldStk->GetPtPos() == pCurCrsr->GetPtPos() ||
[ + - ]
1937 : 0 : pOldStk->GetPtPos() == pCurCrsr->GetMkPos() )
1938 : : {
1939 : : // move "Selections Rectangles"
1940 [ + - ]: 11 : pCurCrsr->insert( pCurCrsr->begin(), pOldStk->begin(), pOldStk->end() );
1941 : 11 : pOldStk->clear();
1942 : : }
1943 : :
1944 [ - + ]: 11 : if( pOldStk->HasMark() )
1945 : : {
1946 [ # # ]: 0 : pCurCrsr->SetMark();
1947 [ # # ]: 0 : *pCurCrsr->GetMark() = *pOldStk->GetMark();
1948 : 0 : pCurCrsr->GetMkPos() = pOldStk->GetMkPos();
1949 : : }
1950 : : else
1951 : : // no selection so revoke old one and set to old position
1952 [ + - ]: 11 : pCurCrsr->DeleteMark();
1953 [ + - ]: 11 : *pCurCrsr->GetPoint() = *pOldStk->GetPoint();
1954 : 11 : pCurCrsr->GetPtPos() = pOldStk->GetPtPos();
1955 [ + - ][ + - ]: 11 : delete pOldStk;
1956 : :
1957 [ + - ][ + - ]: 22 : if( !pCurCrsr->IsInProtectTable( sal_True ) &&
[ + - ][ + - ]
1958 : : !pCurCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
1959 [ + - ]: 11 : nsSwCursorSelOverFlags::SELOVER_CHANGEPOS ) )
1960 [ + - ][ + - ]: 11 : UpdateCrsr(); // update current cursor
1961 : : }
1962 [ + - ]: 17 : return sal_True;
1963 : : }
1964 : :
1965 : : /** Combine two cursors
1966 : :
1967 : : Delete topmost from stack and use its GetMark in the current.
1968 : : */
1969 : 0 : void SwCrsrShell::Combine()
1970 : : {
1971 : : // any others left?
1972 [ # # ]: 0 : if( 0 == pCrsrStk )
1973 : 0 : return;
1974 : :
1975 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
1976 [ # # ]: 0 : SwCrsrSaveState aSaveState( *pCurCrsr );
1977 [ # # ]: 0 : if( pCrsrStk->HasMark() ) // only if GetMark was set
1978 : : {
1979 : : bool const bResult =
1980 [ # # ]: 0 : CheckNodesRange( pCrsrStk->GetMark()->nNode, pCurCrsr->GetPoint()->nNode, sal_True );
1981 : : OSL_ENSURE(bResult, "StackCrsr & current Crsr not in same Section.");
1982 : : (void) bResult; // non-debug: unused
1983 : : // copy GetMark
1984 [ # # ]: 0 : if( !pCurCrsr->HasMark() )
1985 [ # # ]: 0 : pCurCrsr->SetMark();
1986 [ # # ]: 0 : *pCurCrsr->GetMark() = *pCrsrStk->GetMark();
1987 : 0 : pCurCrsr->GetMkPos() = pCrsrStk->GetMkPos();
1988 : : }
1989 : :
1990 : 0 : SwShellCrsr * pTmp = 0;
1991 [ # # ][ # # ]: 0 : if( pCrsrStk->GetNext() != pCrsrStk )
1992 : : {
1993 [ # # ]: 0 : pTmp = dynamic_cast<SwShellCrsr*>(pCrsrStk->GetNext());
1994 : : }
1995 [ # # ][ # # ]: 0 : delete pCrsrStk;
1996 : 0 : pCrsrStk = pTmp;
1997 [ # # ][ # # ]: 0 : if( !pCurCrsr->IsInProtectTable( sal_True ) &&
[ # # ][ # # ]
1998 : : !pCurCrsr->IsSelOvr( nsSwCursorSelOverFlags::SELOVER_TOGGLE |
1999 [ # # ]: 0 : nsSwCursorSelOverFlags::SELOVER_CHANGEPOS ) )
2000 [ # # ][ # # ]: 0 : UpdateCrsr(); // update current cursor
[ # # ]
2001 : : }
2002 : :
2003 : :
2004 : 8183 : void SwCrsrShell::HideCrsrs()
2005 : : {
2006 [ + + ][ - + ]: 8183 : if( !bHasFocus || bBasicHideCrsr )
2007 : 8183 : return;
2008 : :
2009 : : // if cursor is visible then hide SV cursor
2010 [ + + ]: 8165 : if( pVisCrsr->IsVisible() )
2011 : : {
2012 [ + - ]: 7240 : SET_CURR_SHELL( this );
2013 [ + - ][ + - ]: 7240 : pVisCrsr->Hide();
2014 : : }
2015 : : // revoke inversion of SSelection
2016 [ - + ][ # # ]: 8165 : SwShellCrsr* pAktCrsr = pTblCrsr ? pTblCrsr : pCurCrsr;
2017 : 8165 : pAktCrsr->Hide();
2018 : : }
2019 : :
2020 : :
2021 : :
2022 : 42066 : void SwCrsrShell::ShowCrsrs( sal_Bool bCrsrVis )
2023 : : {
2024 [ + + ][ + - ]: 42066 : if( !bHasFocus || bAllProtect || bBasicHideCrsr )
[ + - ]
2025 : 42066 : return;
2026 : :
2027 [ + - ]: 41890 : SET_CURR_SHELL( this );
2028 [ + + ][ + - ]: 41890 : SwShellCrsr* pAktCrsr = pTblCrsr ? pTblCrsr : pCurCrsr;
2029 [ + - ]: 41890 : pAktCrsr->Show();
2030 : :
2031 [ + + ][ + - ]: 41890 : if( bSVCrsrVis && bCrsrVis ) // also show SV cursor again
2032 [ + - ][ + - ]: 42066 : pVisCrsr->Show();
2033 : : }
2034 : :
2035 : :
2036 : :
2037 : 157 : void SwCrsrShell::ShowCrsr()
2038 : : {
2039 [ + - ]: 157 : if( !bBasicHideCrsr )
2040 : : {
2041 : 157 : bSVCrsrVis = sal_True;
2042 : 157 : UpdateCrsr();
2043 : : }
2044 : 157 : }
2045 : :
2046 : :
2047 : 163 : void SwCrsrShell::HideCrsr()
2048 : : {
2049 [ + - ]: 163 : if( !bBasicHideCrsr )
2050 : : {
2051 : 163 : bSVCrsrVis = sal_False;
2052 : : // evt. die sel. Bereiche aufheben !!
2053 [ + - ]: 163 : SET_CURR_SHELL( this );
2054 [ + - ][ + - ]: 163 : pVisCrsr->Hide();
2055 : : }
2056 : 163 : }
2057 : :
2058 : :
2059 : 1360 : void SwCrsrShell::ShLooseFcs()
2060 : : {
2061 [ + - ]: 1360 : if( !bBasicHideCrsr )
2062 : 1360 : HideCrsrs();
2063 : 1360 : bHasFocus = sal_False;
2064 : 1360 : }
2065 : :
2066 : :
2067 : 1360 : void SwCrsrShell::ShGetFcs( sal_Bool bUpdate )
2068 : : {
2069 : 1360 : bHasFocus = sal_True;
2070 [ + - ][ + + ]: 1360 : if( !bBasicHideCrsr && VisArea().Width() )
[ + + ]
2071 : : {
2072 : : UpdateCrsr( static_cast<sal_uInt16>( bUpdate ?
2073 : : SwCrsrShell::CHKRANGE|SwCrsrShell::SCROLLWIN
2074 [ - + ]: 427 : : SwCrsrShell::CHKRANGE ) );
2075 [ + - ]: 427 : ShowCrsrs( bSVCrsrVis ? sal_True : sal_False );
2076 : : }
2077 : 1360 : }
2078 : :
2079 : : /** Get current frame in which the cursor is positioned. */
2080 : 19488 : SwCntntFrm *SwCrsrShell::GetCurrFrm( const sal_Bool bCalcFrm ) const
2081 : : {
2082 [ + - ]: 19488 : SET_CURR_SHELL( (ViewShell*)this );
2083 : 19488 : SwCntntFrm *pRet = 0;
2084 : 19488 : SwCntntNode *pNd = pCurCrsr->GetCntntNode();
2085 [ + - ]: 19488 : if ( pNd )
2086 : : {
2087 [ + + ]: 19488 : if ( bCalcFrm )
2088 : : {
2089 : 5689 : const sal_uInt16* pST = &nStartAction;
2090 : 5689 : ++(*((sal_uInt16*)pST));
2091 [ + - ]: 5689 : const Size aOldSz( GetDocSize() );
2092 [ + - ][ + - ]: 5689 : pRet = pNd->getLayoutFrm( GetLayout(), &pCurCrsr->GetPtPos(), pCurCrsr->GetPoint() );
2093 : 5689 : --(*((sal_uInt16*)pST));
2094 [ + - ][ + + ]: 5689 : if( aOldSz != GetDocSize() )
2095 [ + - ]: 5689 : ((SwCrsrShell*)this)->SizeChgNotify();
2096 : : }
2097 : : else
2098 [ + - ][ + - ]: 13799 : pRet = pNd->getLayoutFrm( GetLayout(), &pCurCrsr->GetPtPos(), pCurCrsr->GetPoint(), sal_False);
2099 : : }
2100 [ + - ]: 19488 : return pRet;
2101 : : }
2102 : :
2103 : : //TODO: provide documentation
2104 : : /** forward all attribute/format changes at the current node to the Link
2105 : :
2106 : : @param pOld ???
2107 : : @param pNew ???
2108 : : */
2109 : 6216 : void SwCrsrShell::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
2110 : : {
2111 : : const sal_uInt16 nWhich = pOld ?
2112 : : pOld->Which() :
2113 : : pNew ?
2114 : : pNew->Which() :
2115 [ + + ][ + - ]: 6216 : sal::static_int_cast<sal_uInt16>(RES_MSG_BEGIN);
2116 : :
2117 [ + - ][ + + ]: 6216 : if( bCallChgLnk &&
[ + - ][ + + ]
[ + + ][ + + ]
2118 : : ( nWhich < RES_MSG_BEGIN || nWhich >= RES_MSG_END ||
2119 : : nWhich == RES_FMT_CHG || nWhich == RES_UPDATE_ATTR ||
2120 : : nWhich == RES_ATTRSET_CHG ))
2121 : : // messages are not forwarded
2122 : : // #i6681#: RES_UPDATE_ATTR is implicitly unset in
2123 : : // SwTxtNode::Insert(SwTxtHint*, sal_uInt16); we react here and thus do
2124 : : // not need to send the expensive RES_FMT_CHG in Insert.
2125 : 1852 : CallChgLnk();
2126 : :
2127 [ + + ][ + - ]: 6216 : if( aGrfArrivedLnk.IsSet() &&
[ - + ][ - + ]
2128 : : ( RES_GRAPHIC_ARRIVED == nWhich || RES_GRAPHIC_SWAPIN == nWhich ))
2129 : 0 : aGrfArrivedLnk.Call( this );
2130 : 6216 : }
2131 : :
2132 : : /** Does the current cursor create a selection?
2133 : :
2134 : : This means checking if GetMark is set and if SPoint and GetMark differ.
2135 : : */
2136 : 43166 : sal_Bool SwCrsrShell::HasSelection() const
2137 : : {
2138 [ + - ]: 43166 : const SwPaM* pCrsr = getShellCrsr( true );
2139 : 86294 : return( IsTableMode() || ( pCrsr->HasMark() &&
2140 : 229 : *pCrsr->GetPoint() != *pCrsr->GetMark())
2141 [ + + + + : 86523 : ? sal_True : sal_False );
+ + ]
2142 : : }
2143 : :
2144 : :
2145 : 19000 : void SwCrsrShell::CallChgLnk()
2146 : : {
2147 : : // Do not make any call in start/end action but just remember the change.
2148 : : // This will be taken care of in the end action.
2149 [ + + ]: 19000 : if( BasicActionPend() )
2150 : 1772 : bChgCallFlag = sal_True; // remember change
2151 [ + - ]: 17228 : else if( aChgLnk.IsSet() )
2152 : : {
2153 [ + - ]: 17228 : if( bCallChgLnk )
2154 : 17228 : aChgLnk.Call( this );
2155 : 17228 : bChgCallFlag = sal_False; // reset flag
2156 : : }
2157 : 19000 : }
2158 : :
2159 : : /// get selected text of a node at current cursor
2160 : 0 : String SwCrsrShell::GetSelTxt() const
2161 : : {
2162 : 0 : String aTxt;
2163 [ # # ]: 0 : if( pCurCrsr->GetPoint()->nNode.GetIndex() ==
2164 : 0 : pCurCrsr->GetMark()->nNode.GetIndex() )
2165 : : {
2166 : 0 : SwTxtNode* pTxtNd = pCurCrsr->GetNode()->GetTxtNode();
2167 [ # # ]: 0 : if( pTxtNd )
2168 : : {
2169 [ # # ]: 0 : xub_StrLen nStt = pCurCrsr->Start()->nContent.GetIndex();
2170 : : aTxt = pTxtNd->GetExpandTxt( nStt,
2171 [ # # ][ # # ]: 0 : pCurCrsr->End()->nContent.GetIndex() - nStt );
[ # # ][ # # ]
2172 : : }
2173 : : }
2174 : 0 : return aTxt;
2175 : : }
2176 : :
2177 : : /// get text only from current cursor position (until end of node)
2178 : 0 : String SwCrsrShell::GetText() const
2179 : : {
2180 : 0 : String aTxt;
2181 [ # # ]: 0 : if( pCurCrsr->GetPoint()->nNode.GetIndex() ==
2182 : 0 : pCurCrsr->GetMark()->nNode.GetIndex() )
2183 : : {
2184 : 0 : SwTxtNode* pTxtNd = pCurCrsr->GetNode()->GetTxtNode();
2185 [ # # ]: 0 : if( pTxtNd )
2186 : 0 : aTxt = pTxtNd->GetTxt().Copy(
2187 [ # # ][ # # ]: 0 : pCurCrsr->GetPoint()->nContent.GetIndex() );
[ # # ]
2188 : : }
2189 : 0 : return aTxt;
2190 : : }
2191 : :
2192 : : /** get the nth character of the current SSelection
2193 : :
2194 : : @param bEnd Start counting from the end? From start otherwise.
2195 : : @param nOffset position of the character
2196 : : */
2197 : 0 : sal_Unicode SwCrsrShell::GetChar( sal_Bool bEnd, long nOffset )
2198 : : {
2199 [ # # ]: 0 : if( IsTableMode() ) // not possible in table mode
2200 : 0 : return 0;
2201 : :
2202 : 0 : const SwPosition* pPos = !pCurCrsr->HasMark() ? pCurCrsr->GetPoint()
2203 [ # # ][ # # ]: 0 : : bEnd ? pCurCrsr->End() : pCurCrsr->Start();
2204 : 0 : SwTxtNode* pTxtNd = pPos->nNode.GetNode().GetTxtNode();
2205 [ # # ]: 0 : if( !pTxtNd )
2206 : 0 : return 0;
2207 : :
2208 : 0 : xub_StrLen nPos = pPos->nContent.GetIndex();
2209 : 0 : const String& rStr = pTxtNd->GetTxt();
2210 : 0 : sal_Unicode cCh = 0;
2211 : :
2212 [ # # ][ # # ]: 0 : if( ((nPos+nOffset) >= 0 ) && (nPos+nOffset) < rStr.Len() )
[ # # ]
2213 : 0 : cCh = rStr.GetChar( static_cast<xub_StrLen>(nPos+nOffset) );
2214 : :
2215 : 0 : return cCh;
2216 : : }
2217 : :
2218 : : /** extend current SSelection by n characters
2219 : :
2220 : : @param bEnd Start counting from the end? From start otherwise.
2221 : : @param nCount Number of characters.
2222 : : */
2223 : 0 : sal_Bool SwCrsrShell::ExtendSelection( sal_Bool bEnd, xub_StrLen nCount )
2224 : : {
2225 [ # # ][ # # ]: 0 : if( !pCurCrsr->HasMark() || IsTableMode() )
[ # # ]
2226 : 0 : return sal_False; // no selection
2227 : :
2228 [ # # ][ # # ]: 0 : SwPosition* pPos = bEnd ? pCurCrsr->End() : pCurCrsr->Start();
[ # # ]
2229 : 0 : SwTxtNode* pTxtNd = pPos->nNode.GetNode().GetTxtNode();
2230 : : OSL_ENSURE( pTxtNd, "no text node; how should this then be extended?" );
2231 : :
2232 : 0 : xub_StrLen nPos = pPos->nContent.GetIndex();
2233 [ # # ]: 0 : if( bEnd )
2234 : : {
2235 [ # # ]: 0 : if( ( nPos + nCount ) <= pTxtNd->GetTxt().Len() )
2236 : 0 : nPos = nPos + nCount;
2237 : : else
2238 : 0 : return sal_False; // not possible
2239 : : }
2240 [ # # ]: 0 : else if( nPos >= nCount )
2241 : 0 : nPos = nPos - nCount;
2242 : : else
2243 : 0 : return sal_False; // not possible anymore
2244 : :
2245 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
2246 : :
2247 [ # # ]: 0 : pPos->nContent = nPos;
2248 [ # # ]: 0 : UpdateCrsr();
2249 : :
2250 [ # # ]: 0 : return sal_True;
2251 : : }
2252 : :
2253 : : /** Move visible cursor to given position in document.
2254 : :
2255 : : @param rPt The position to move the visible cursor to.
2256 : : @return <sal_False> if SPoint was corrected by the layout.
2257 : : */
2258 : 0 : sal_Bool SwCrsrShell::SetVisCrsr( const Point &rPt )
2259 : : {
2260 [ # # ]: 0 : SET_CURR_SHELL( this );
2261 : 0 : Point aPt( rPt );
2262 [ # # ]: 0 : SwPosition aPos( *pCurCrsr->GetPoint() );
2263 : 0 : SwCrsrMoveState aTmpState( MV_SETONLYTEXT );
2264 : 0 : aTmpState.bSetInReadOnly = IsReadOnlyAvailable();
2265 : 0 : aTmpState.bRealHeight = sal_True;
2266 : :
2267 [ # # ][ # # ]: 0 : sal_Bool bRet = GetLayout()->GetCrsrOfst( &aPos, aPt /*, &aTmpState*/ );
2268 : :
2269 [ # # ]: 0 : SetInFrontOfLabel( sal_False ); // #i27615#
2270 : :
2271 : : // show only in TextNodes
2272 : 0 : SwTxtNode* pTxtNd = aPos.nNode.GetNode().GetTxtNode();
2273 [ # # ]: 0 : if( !pTxtNd )
2274 : 0 : return sal_False;
2275 : :
2276 [ # # ]: 0 : const SwSectionNode* pSectNd = pTxtNd->FindSectionNode();
2277 [ # # ][ # # : 0 : if( pSectNd && (pSectNd->GetSection().IsHiddenFlag() ||
# # # # ]
[ # # ]
2278 : 0 : ( !IsReadOnlyAvailable() &&
2279 : 0 : pSectNd->GetSection().IsProtectFlag())) )
2280 : 0 : return sal_False;
2281 : :
2282 [ # # ][ # # ]: 0 : SwCntntFrm *pFrm = pTxtNd->getLayoutFrm( GetLayout(), &aPt, &aPos );
2283 [ # # ]: 0 : if ( Imp()->IsIdleAction() )
2284 [ # # ]: 0 : pFrm->PrepareCrsr();
2285 : 0 : SwRect aTmp( aCharRect );
2286 : :
2287 [ # # ]: 0 : pFrm->GetCharRect( aCharRect, aPos, &aTmpState );
2288 : :
2289 : : // #i10137#
2290 [ # # ][ # # ]: 0 : if( aTmp == aCharRect && pVisCrsr->IsVisible() )
[ # # ]
2291 : 0 : return sal_True;
2292 : :
2293 [ # # ]: 0 : pVisCrsr->Hide(); // always hide visible cursor
2294 [ # # ][ # # ]: 0 : if( IsScrollMDI( this, aCharRect ))
2295 : : {
2296 [ # # ]: 0 : MakeVisible( aCharRect );
2297 [ # # ]: 0 : pCurCrsr->Show();
2298 : : }
2299 : :
2300 : : {
2301 [ # # ]: 0 : if( aTmpState.bRealHeight )
2302 : 0 : aCrsrHeight = aTmpState.aRealHeight;
2303 : : else
2304 : : {
2305 : 0 : aCrsrHeight.X() = 0;
2306 : 0 : aCrsrHeight.Y() = aCharRect.Height();
2307 : : }
2308 : :
2309 : 0 : pVisCrsr->SetDragCrsr( sal_True );
2310 [ # # ]: 0 : pVisCrsr->Show(); // show again
2311 : : }
2312 [ # # ][ # # ]: 0 : return bRet;
2313 : : }
2314 : :
2315 : 0 : sal_Bool SwCrsrShell::IsOverReadOnlyPos( const Point& rPt ) const
2316 : : {
2317 : 0 : Point aPt( rPt );
2318 [ # # ]: 0 : SwPaM aPam( *pCurCrsr->GetPoint() );
2319 [ # # ][ # # ]: 0 : GetLayout()->GetCrsrOfst( aPam.GetPoint(), aPt );
2320 : : // Formular view
2321 [ # # ][ # # ]: 0 : return aPam.HasReadonlySel( GetViewOptions()->IsFormView() );
2322 : : }
2323 : :
2324 : 0 : sal_Bool SwCrsrShell::IsOverHeaderFooterPos( const Point& rPt ) const
2325 : : {
2326 : 0 : Point aPt( rPt );
2327 [ # # ]: 0 : SwPaM aPam( *pCurCrsr->GetPoint() );
2328 [ # # ][ # # ]: 0 : GetLayout()->GetCrsrOfst( aPam.GetPoint(), aPt );
2329 : :
2330 [ # # ][ # # ]: 0 : return GetDoc()->IsInHeaderFooter( aPam.GetPoint()->nNode );
2331 : : }
2332 : :
2333 : : /** Get the number of elements in the ring of cursors
2334 : :
2335 : : @param bAll If <false> get only spanned ones (= with selections) (Basic).
2336 : : */
2337 : 27390 : sal_uInt16 SwCrsrShell::GetCrsrCnt( sal_Bool bAll ) const
2338 : : {
2339 : 27390 : Ring* pTmp = GetCrsr()->GetNext();
2340 : 0 : sal_uInt16 n = (bAll || ( pCurCrsr->HasMark() &&
2341 [ # # ]: 27390 : *pCurCrsr->GetPoint() != *pCurCrsr->GetMark())) ? 1 : 0;
[ - + # # ]
2342 [ + - ][ + + ]: 27498 : while( pTmp != pCurCrsr )
2343 : : {
2344 [ - + ]: 108 : if( bAll || ( ((SwPaM*)pTmp)->HasMark() &&
[ # # # # ]
[ + - ]
2345 : 0 : *((SwPaM*)pTmp)->GetPoint() != *((SwPaM*)pTmp)->GetMark()))
2346 : 108 : ++n;
2347 : 108 : pTmp = pTmp->GetNext();
2348 : : }
2349 : 27390 : return n;
2350 : : }
2351 : :
2352 : :
2353 : 0 : sal_Bool SwCrsrShell::IsStartOfDoc() const
2354 : : {
2355 [ # # ]: 0 : if( pCurCrsr->GetPoint()->nContent.GetIndex() )
2356 : 0 : return sal_False;
2357 : :
2358 : : // after EndOfIcons comes the content selection (EndNd+StNd+CntntNd)
2359 [ # # ][ # # ]: 0 : SwNodeIndex aIdx( GetDoc()->GetNodes().GetEndOfExtras(), 2 );
2360 [ # # ]: 0 : if( !aIdx.GetNode().IsCntntNode() )
2361 [ # # ][ # # ]: 0 : GetDoc()->GetNodes().GoNext( &aIdx );
2362 [ # # ]: 0 : return aIdx == pCurCrsr->GetPoint()->nNode;
2363 : : }
2364 : :
2365 : :
2366 : 0 : sal_Bool SwCrsrShell::IsEndOfDoc() const
2367 : : {
2368 [ # # ][ # # ]: 0 : SwNodeIndex aIdx( GetDoc()->GetNodes().GetEndOfContent(), -1 );
2369 : 0 : SwCntntNode* pCNd = aIdx.GetNode().GetCntntNode();
2370 [ # # ]: 0 : if( !pCNd )
2371 [ # # ][ # # ]: 0 : pCNd = GetDoc()->GetNodes().GoPrevious( &aIdx );
2372 : :
2373 : 0 : return aIdx == pCurCrsr->GetPoint()->nNode &&
2374 [ # # ][ # # ]: 0 : pCNd->Len() == pCurCrsr->GetPoint()->nContent.GetIndex();
[ # # ][ # # ]
2375 : : }
2376 : :
2377 : : /** Invalidate cursors
2378 : :
2379 : : Delete all created cursors, set table crsr and last crsr to their TextNode
2380 : : (or StartNode?). They will then all re-created at the next ::GetCrsr() call.
2381 : :
2382 : : This is needed for Drag&Drop/ Clipboard-paste in tables.
2383 : : */
2384 : 0 : sal_Bool SwCrsrShell::ParkTblCrsr()
2385 : : {
2386 [ # # ]: 0 : if( !pTblCrsr )
2387 : 0 : return sal_False;
2388 : :
2389 : 0 : pTblCrsr->ParkCrsr();
2390 : :
2391 [ # # ][ # # ]: 0 : while( pCurCrsr->GetNext() != pCurCrsr )
2392 [ # # ]: 0 : delete pCurCrsr->GetNext();
2393 : :
2394 : : // *always* move cursor's SPoint and Mark
2395 : 0 : pCurCrsr->SetMark();
2396 : 0 : *pCurCrsr->GetMark() = *pCurCrsr->GetPoint() = *pTblCrsr->GetPoint();
2397 : 0 : pCurCrsr->DeleteMark();
2398 : :
2399 : 0 : return sal_True;
2400 : : }
2401 : :
2402 : 0 : void SwCrsrShell::_ParkPams( SwPaM* pDelRg, SwShellCrsr** ppDelRing )
2403 : : {
2404 : 0 : const SwPosition *pStt = pDelRg->Start(),
2405 [ # # ]: 0 : *pEnd = pDelRg->GetPoint() == pStt ? pDelRg->GetMark() : pDelRg->GetPoint();
2406 : :
2407 [ # # ]: 0 : SwPaM *pTmpDel = 0, *pTmp = *ppDelRing;
2408 : :
2409 : : // search over the whole ring
2410 : : sal_Bool bGoNext;
2411 [ # # ][ # # ]: 0 : do {
[ # # ][ # # ]
2412 : 0 : const SwPosition *pTmpStt = pTmp->Start(),
2413 : 0 : *pTmpEnd = pTmp->GetPoint() == pTmpStt ?
2414 [ # # ]: 0 : pTmp->GetMark() : pTmp->GetPoint();
2415 : : // If a SPoint or GetMark are in a cursor area than cancel the old area.
2416 : : // During comparison keep in mind that End() is outside the area.
2417 [ # # ]: 0 : if( *pStt <= *pTmpStt )
2418 : : {
2419 [ # # # # : 0 : if( *pEnd > *pTmpStt ||
# # ][ # # ]
2420 : 0 : ( *pEnd == *pTmpStt && *pEnd == *pTmpEnd ))
2421 : 0 : pTmpDel = pTmp;
2422 : : }
2423 : : else
2424 [ # # ]: 0 : if( *pStt < *pTmpEnd )
2425 : 0 : pTmpDel = pTmp;
2426 : :
2427 : 0 : bGoNext = sal_True;
2428 [ # # ]: 0 : if( pTmpDel ) // is the pam in area -> delete
2429 : : {
2430 : 0 : sal_Bool bDelete = sal_True;
2431 [ # # ][ # # ]: 0 : if( *ppDelRing == pTmpDel )
2432 : : {
2433 [ # # ]: 0 : if( *ppDelRing == pCurCrsr )
2434 : : {
2435 [ # # ]: 0 : if( sal_True == ( bDelete = GoNextCrsr() ))
2436 : : {
2437 : 0 : bGoNext = sal_False;
2438 : 0 : pTmp = (SwPaM*)pTmp->GetNext();
2439 : : }
2440 : : }
2441 : : else
2442 : 0 : bDelete = sal_False; // never delete the StackCrsr
2443 : : }
2444 : :
2445 [ # # ]: 0 : if( bDelete )
2446 [ # # ]: 0 : delete pTmpDel; // invalidate old area
2447 : : else
2448 : : {
2449 : 0 : pTmpDel->GetPoint()->nContent.Assign( 0, 0 );
2450 : 0 : pTmpDel->GetPoint()->nNode = 0;
2451 : 0 : pTmpDel->SetMark();
2452 : 0 : pTmpDel->DeleteMark();
2453 : : }
2454 : 0 : pTmpDel = 0;
2455 : : }
2456 [ # # ]: 0 : else if( !pTmp->HasMark() )
2457 : : {
2458 : : // Take care that not used indices are considered.
2459 : : // SPoint is not in area but maybe GetMark is, thus set it.
2460 : 0 : pTmp->SetMark();
2461 : 0 : pTmp->DeleteMark();
2462 : : }
2463 [ # # ]: 0 : if( bGoNext )
2464 : 0 : pTmp = (SwPaM*)pTmp->GetNext();
2465 : 0 : } while( !bGoNext || *ppDelRing != pTmp );
2466 : 0 : }
2467 : :
2468 : : //TODO: provide documentation
2469 : : /** Remove selections and additional cursors of all shells.
2470 : :
2471 : : The remaining cursor of the shell is parked.
2472 : :
2473 : : @param rIdx ???
2474 : : */
2475 : 0 : void SwCrsrShell::ParkCrsr( const SwNodeIndex &rIdx )
2476 : : {
2477 : 0 : SwNode *pNode = &rIdx.GetNode();
2478 : :
2479 : : // create a new PaM
2480 [ # # ]: 0 : SwPaM * pNew = new SwPaM( *GetCrsr()->GetPoint() );
2481 [ # # ]: 0 : if( pNode->GetStartNode() )
2482 : : {
2483 [ # # ]: 0 : if( ( pNode = pNode->StartOfSectionNode())->IsTableNode() )
2484 : : {
2485 : : // the given node is in a table, thus park cursor to table node
2486 : : // (outside of the table)
2487 : 0 : pNew->GetPoint()->nNode = *pNode->StartOfSectionNode();
2488 : : }
2489 : : else
2490 : : // Also on the start node itself. Then we need to request the start
2491 : : // node always via its end node! (StartOfSelection of StartNode is
2492 : : // the parent)
2493 : 0 : pNew->GetPoint()->nNode = *pNode->EndOfSectionNode()->StartOfSectionNode();
2494 : : }
2495 : : else
2496 : 0 : pNew->GetPoint()->nNode = *pNode->StartOfSectionNode();
2497 : 0 : pNew->SetMark();
2498 : 0 : pNew->GetPoint()->nNode = *pNode->EndOfSectionNode();
2499 : :
2500 : : // take care of all shells
2501 : 0 : ViewShell *pTmp = this;
2502 [ # # ]: 0 : do {
2503 [ # # ]: 0 : if( pTmp->IsA( TYPE( SwCrsrShell )))
2504 : : {
2505 : 0 : SwCrsrShell* pSh = (SwCrsrShell*)pTmp;
2506 [ # # ]: 0 : if( pSh->pCrsrStk )
2507 : 0 : pSh->_ParkPams( pNew, &pSh->pCrsrStk );
2508 : :
2509 : 0 : pSh->_ParkPams( pNew, &pSh->pCurCrsr );
2510 [ # # ]: 0 : if( pSh->pTblCrsr )
2511 : : {
2512 : : // set table cursor always to 0 and the current one always to
2513 : : // the beginning of the table
2514 : 0 : SwPaM* pTCrsr = pSh->GetTblCrs();
2515 : 0 : SwNode* pTblNd = pTCrsr->GetPoint()->nNode.GetNode().FindTableNode();
2516 [ # # ]: 0 : if ( pTblNd )
2517 : : {
2518 : 0 : pTCrsr->GetPoint()->nContent.Assign( 0, 0 );
2519 : 0 : pTCrsr->GetPoint()->nNode = 0;
2520 : 0 : pTCrsr->SetMark();
2521 : 0 : pTCrsr->DeleteMark();
2522 : 0 : pSh->pCurCrsr->GetPoint()->nNode = *pTblNd;
2523 : : }
2524 : : }
2525 : : }
2526 : 0 : } while ( this != (pTmp = (ViewShell*)pTmp->GetNext() ));
2527 [ # # ]: 0 : delete pNew;
2528 : 0 : }
2529 : :
2530 : :
2531 : : /** Copy constructor
2532 : :
2533 : : Copy cursor position and add it to the ring.
2534 : : All views of a document are in the ring of the shell.
2535 : : */
2536 : 0 : SwCrsrShell::SwCrsrShell( SwCrsrShell& rShell, Window *pInitWin )
2537 : : : ViewShell( rShell, pInitWin ),
2538 : : SwModify( 0 ), pCrsrStk( 0 ), pBlockCrsr( 0 ), pTblCrsr( 0 ),
2539 : : pBoxIdx( 0 ), pBoxPtr( 0 ), nCrsrMove( 0 ), nBasicActionCnt( 0 ),
2540 : : eMvState( MV_NONE ),
2541 : : sMarkedListId(),
2542 [ # # ][ # # ]: 0 : nMarkedListLevel( 0 )
[ # # ][ # # ]
[ # # ]
2543 : : {
2544 [ # # ]: 0 : SET_CURR_SHELL( this );
2545 : : // only keep the position of the current cursor of the copy shell
2546 [ # # ][ # # ]: 0 : pCurCrsr = new SwShellCrsr( *this, *(rShell.pCurCrsr->GetPoint()) );
2547 [ # # ]: 0 : pCurCrsr->GetCntntNode()->Add( this );
2548 : :
2549 : : bAllProtect = bVisPortChgd = bChgCallFlag = bInCMvVisportChgd =
2550 : : bGCAttr = bIgnoreReadonly = bSelTblCells = bBasicHideCrsr =
2551 : 0 : bOverwriteCrsr = sal_False;
2552 : 0 : bCallChgLnk = bHasFocus = bSVCrsrVis = bAutoUpdateCells = sal_True;
2553 : 0 : bSetCrsrInReadOnly = sal_True;
2554 [ # # ][ # # ]: 0 : pVisCrsr = new SwVisCrsr( this );
2555 [ # # ]: 0 : mbMacroExecAllowed = rShell.IsMacroExecAllowed();
2556 : 0 : }
2557 : :
2558 : : /// default constructor
2559 : 1318 : SwCrsrShell::SwCrsrShell( SwDoc& rDoc, Window *pInitWin,
2560 : : const SwViewOption *pInitOpt )
2561 : : : ViewShell( rDoc, pInitWin, pInitOpt ),
2562 : : SwModify( 0 ), pCrsrStk( 0 ), pBlockCrsr( 0 ), pTblCrsr( 0 ),
2563 : : pBoxIdx( 0 ), pBoxPtr( 0 ), nCrsrMove( 0 ), nBasicActionCnt( 0 ),
2564 : : eMvState( MV_NONE ), // state for crsr-travelling - GetCrsrOfst
2565 : : sMarkedListId(),
2566 [ + - ][ + - ]: 1318 : nMarkedListLevel( 0 )
[ + - ][ + - ]
[ + - ]
2567 : : {
2568 [ + - ]: 1318 : SET_CURR_SHELL( this );
2569 : : // create initial cursor and set it to first content position
2570 [ + - ]: 1318 : SwNodes& rNds = rDoc.GetNodes();
2571 : :
2572 [ + - ]: 1318 : SwNodeIndex aNodeIdx( *rNds.GetEndOfContent().StartOfSectionNode() );
2573 [ + - ]: 1318 : SwCntntNode* pCNd = rNds.GoNext( &aNodeIdx ); // gehe zum 1. ContentNode
2574 : :
2575 [ + - ][ + - ]: 1318 : pCurCrsr = new SwShellCrsr( *this, SwPosition( aNodeIdx, SwIndex( pCNd, 0 )));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
2576 : :
2577 : : // Register shell as dependent at current node. As a result all attribute
2578 : : // changes can be forwarded via the Link.
2579 [ + - ]: 1318 : pCNd->Add( this );
2580 : :
2581 : : bAllProtect = bVisPortChgd = bChgCallFlag = bInCMvVisportChgd =
2582 : : bGCAttr = bIgnoreReadonly = bSelTblCells = bBasicHideCrsr =
2583 : 1318 : bOverwriteCrsr = sal_False;
2584 : 1318 : bCallChgLnk = bHasFocus = bSVCrsrVis = bAutoUpdateCells = sal_True;
2585 : 1318 : bSetCrsrInReadOnly = sal_True;
2586 : :
2587 [ + - ][ + - ]: 1318 : pVisCrsr = new SwVisCrsr( this );
2588 [ + - ][ + - ]: 1318 : mbMacroExecAllowed = true;
2589 : 1318 : }
2590 : :
2591 : :
2592 : :
2593 [ + - ][ + - ]: 1231 : SwCrsrShell::~SwCrsrShell()
2594 : : {
2595 : : // if it is not the last view then at least the field should be updated
2596 [ - + ]: 1231 : if( GetNext() != this )
2597 [ # # ]: 0 : CheckTblBoxCntnt( pCurCrsr->GetPoint() );
2598 : : else
2599 [ + - ]: 1231 : ClearTblBoxCntnt();
2600 : :
2601 [ + - ][ + - ]: 1231 : delete pVisCrsr;
2602 [ - + ][ # # ]: 1231 : delete pBlockCrsr;
2603 [ - + ][ # # ]: 1231 : delete pTblCrsr;
2604 : :
2605 : : // release cursors
2606 [ + - ][ - + ]: 1231 : while(pCurCrsr->GetNext() != pCurCrsr)
2607 [ # # ][ # # ]: 0 : delete pCurCrsr->GetNext();
2608 [ + - ][ + - ]: 1231 : delete pCurCrsr;
2609 : :
2610 : : // free stack
2611 [ - + ]: 1231 : if( pCrsrStk )
2612 : : {
2613 [ # # ][ # # ]: 0 : while( pCrsrStk->GetNext() != pCrsrStk )
2614 [ # # ][ # # ]: 0 : delete pCrsrStk->GetNext();
2615 [ # # ][ # # ]: 0 : delete pCrsrStk;
2616 : : }
2617 : :
2618 : : // #i54025# - do not give a HTML parser that might potentially hang as
2619 : : // a client at the cursor shell the chance to hang itself on a TextNode
2620 [ + - ]: 1231 : if( GetRegisteredIn() )
2621 [ + - ]: 1231 : GetRegisteredInNonConst()->Remove( this );
2622 [ - + ]: 1231 : }
2623 : :
2624 : 185471 : SwShellCrsr* SwCrsrShell::getShellCrsr( bool bBlock )
2625 : : {
2626 [ + + ]: 185471 : if( pTblCrsr )
2627 [ + - ]: 116 : return pTblCrsr;
2628 [ - + ][ # # ]: 185355 : if( pBlockCrsr && bBlock )
2629 : 0 : return &pBlockCrsr->getShellCrsr();
2630 : 185471 : return pCurCrsr;
2631 : : }
2632 : :
2633 : : /** Should WaitPtr be switched on for the clipboard?
2634 : :
2635 : : Wait for TableMode, multiple selections and more than x selected paragraphs.
2636 : : */
2637 : 0 : sal_Bool SwCrsrShell::ShouldWait() const
2638 : : {
2639 [ # # ][ # # ]: 0 : if ( IsTableMode() || GetCrsrCnt() > 1 )
[ # # ]
2640 : 0 : return sal_True;
2641 : :
2642 [ # # ][ # # ]: 0 : if( HasDrawView() && GetDrawView()->GetMarkedObjectList().GetMarkCount() )
[ # # ]
2643 : 0 : return sal_True;
2644 : :
2645 : 0 : SwPaM* pPam = GetCrsr();
2646 : 0 : return pPam->Start()->nNode.GetIndex() + 10 <
2647 : 0 : pPam->End()->nNode.GetIndex();
2648 : : }
2649 : :
2650 : :
2651 : 0 : sal_uInt16 SwCrsrShell::UpdateTblSelBoxes()
2652 : : {
2653 [ # # ][ # # ]: 0 : if( pTblCrsr && ( pTblCrsr->IsChgd() || !pTblCrsr->GetBoxesCount() ))
[ # # ][ # # ]
2654 : 0 : GetLayout()->MakeTblCrsrs( *pTblCrsr );
2655 [ # # ]: 0 : return pTblCrsr ? pTblCrsr->GetBoxesCount() : 0;
2656 : : }
2657 : :
2658 : : /// show the current selected "object"
2659 : 33638 : void SwCrsrShell::MakeSelVisible()
2660 : : {
2661 : : OSL_ENSURE( bHasFocus, "no focus but cursor should be made visible?" );
2662 [ + + ][ + + ]: 33638 : if( aCrsrHeight.Y() < aCharRect.Height() && aCharRect.Height() > VisArea().Height() )
[ + + ]
2663 : : {
2664 : 30 : SwRect aTmp( aCharRect );
2665 : 30 : long nDiff = aCharRect.Height() - VisArea().Height();
2666 [ - + ]: 30 : if( nDiff < aCrsrHeight.X() )
2667 : 0 : aTmp.Top( nDiff + aCharRect.Top() );
2668 : : else
2669 : : {
2670 : 30 : aTmp.Top( aCrsrHeight.X() + aCharRect.Top() );
2671 : 30 : aTmp.Height( aCrsrHeight.Y() );
2672 : : }
2673 [ + - ][ - + ]: 30 : if( !aTmp.HasArea() )
2674 : : {
2675 : 0 : aTmp.SSize().Height() += 1;
2676 : 0 : aTmp.SSize().Width() += 1;
2677 : : }
2678 [ + - ]: 30 : MakeVisible( aTmp );
2679 : : }
2680 : : else
2681 : : {
2682 [ + + ]: 33608 : if( aCharRect.HasArea() )
2683 : 33548 : MakeVisible( aCharRect );
2684 : : else
2685 : : {
2686 : 60 : SwRect aTmp( aCharRect );
2687 : 60 : aTmp.SSize().Height() += 1; aTmp.SSize().Width() += 1;
2688 [ + - ]: 60 : MakeVisible( aTmp );
2689 : : }
2690 : : }
2691 : 33638 : }
2692 : :
2693 : : /// search a valid content position (not protected/hidden)
2694 : 0 : sal_Bool SwCrsrShell::FindValidCntntNode( sal_Bool bOnlyText )
2695 : : {
2696 [ # # ]: 0 : if( pTblCrsr )
2697 : : {
2698 : : OSL_ENSURE( !this, "Did not remove table selection!" );
2699 : 0 : return sal_False;
2700 : : }
2701 : :
2702 : : // #i45129# - everything is allowed in UI-readonly
2703 [ # # ]: 0 : if( !bAllProtect && GetDoc()->GetDocShell() &&
[ # # # # ]
[ # # ]
2704 : 0 : GetDoc()->GetDocShell()->IsReadOnlyUI() )
2705 : 0 : return sal_True;
2706 : :
2707 [ # # ]: 0 : if( pCurCrsr->HasMark() )
2708 : 0 : ClearMark();
2709 : :
2710 : : // first check for frames
2711 : 0 : SwNodeIndex& rNdIdx = pCurCrsr->GetPoint()->nNode;
2712 : 0 : sal_uLong nNdIdx = rNdIdx.GetIndex(); // keep backup
2713 : 0 : SwNodes& rNds = pDoc->GetNodes();
2714 : 0 : SwCntntNode* pCNd = rNdIdx.GetNode().GetCntntNode();
2715 : : const SwCntntFrm * pFrm;
2716 : :
2717 [ # # # # : 0 : if( pCNd && 0 != (pFrm = pCNd->getLayoutFrm( GetLayout(),0,pCurCrsr->GetPoint(),sal_False)) &&
# # # # ]
[ # # ][ # # ]
2718 : 0 : !IsReadOnlyAvailable() && pFrm->IsProtected() &&
2719 : 0 : nNdIdx < rNds.GetEndOfExtras().GetIndex() )
2720 : : {
2721 : : // skip protected frame
2722 [ # # ]: 0 : SwPaM aPam( *pCurCrsr->GetPoint() );
2723 [ # # ]: 0 : aPam.SetMark();
2724 [ # # ]: 0 : aPam.GetMark()->nNode = rNds.GetEndOfContent();
2725 [ # # ]: 0 : aPam.GetPoint()->nNode = *pCNd->EndOfSectionNode();
2726 : :
2727 : 0 : sal_Bool bFirst = sal_False;
2728 [ # # ][ # # ]: 0 : if( 0 == (pCNd = ::GetNode( aPam, bFirst, fnMoveForward, sal_False )))
2729 : : {
2730 [ # # ]: 0 : aPam.GetMark()->nNode = *rNds.GetEndOfPostIts().StartOfSectionNode();
2731 [ # # ]: 0 : pCNd = ::GetNode( aPam, bFirst, fnMoveBackward, sal_False );
2732 : : }
2733 : :
2734 [ # # ]: 0 : if( !pCNd ) // should *never* happen
2735 : : {
2736 [ # # ]: 0 : rNdIdx = nNdIdx; // back to old node
2737 : 0 : return sal_False;
2738 : : }
2739 [ # # ][ # # ]: 0 : *pCurCrsr->GetPoint() = *aPam.GetPoint();
[ # # ]
2740 : : }
2741 [ # # ][ # # ]: 0 : else if( bOnlyText && pCNd && pCNd->IsNoTxtNode() )
[ # # ][ # # ]
2742 : : {
2743 : : // set to beginning of document
2744 : 0 : rNdIdx = pDoc->GetNodes().GetEndOfExtras();
2745 : 0 : pCurCrsr->GetPoint()->nContent.Assign( pDoc->GetNodes().GoNext(
2746 [ # # ]: 0 : &rNdIdx ), 0 );
2747 : 0 : nNdIdx = rNdIdx.GetIndex();
2748 : : }
2749 : :
2750 : 0 : sal_Bool bOk = sal_True;
2751 : :
2752 : : // #i9059# cursor may not stand in protected cells
2753 : : // (unless cursor in protected areas is OK.)
2754 : 0 : const SwTableNode* pTableNode = rNdIdx.GetNode().FindTableNode();
2755 [ # # # # ]: 0 : if( !IsReadOnlyAvailable() &&
[ # # ][ # # ]
2756 : 0 : pTableNode != NULL && rNdIdx.GetNode().IsProtect() )
2757 : : {
2758 : : // we're in a table, and we're in a protected area, so we're
2759 : : // probably in a protected cell.
2760 : :
2761 : : // move forward into non-protected area.
2762 [ # # ]: 0 : SwPaM aPam( rNdIdx.GetNode(), 0 );
2763 [ # # ][ # # ]: 0 : while( aPam.GetNode()->IsProtect() &&
[ # # ][ # # ]
2764 [ # # ]: 0 : aPam.Move( fnMoveForward, fnGoCntnt ) )
2765 : : ; // nothing to do in the loop; the aPam.Move does the moving!
2766 : :
2767 : : // didn't work? then go backwards!
2768 [ # # ][ # # ]: 0 : if( aPam.GetNode()->IsProtect() )
2769 : : {
2770 [ # # ]: 0 : SwPaM aTmpPaM( rNdIdx.GetNode(), 0 );
2771 [ # # ]: 0 : aPam = aTmpPaM;
2772 [ # # ][ # # ]: 0 : while( aPam.GetNode()->IsProtect() &&
[ # # ][ # # ]
2773 [ # # ]: 0 : aPam.Move( fnMoveBackward, fnGoCntnt ) )
2774 [ # # ]: 0 : ; // nothing to do in the loop; the aPam.Move does the moving!
2775 : : }
2776 : :
2777 : : // if we're successful, set the new position
2778 [ # # ][ # # ]: 0 : if( ! aPam.GetNode()->IsProtect() )
2779 : : {
2780 [ # # ]: 0 : *pCurCrsr->GetPoint() = *aPam.GetPoint();
2781 [ # # ]: 0 : }
2782 : : }
2783 : :
2784 : : // in a protected frame
2785 : 0 : const SwSectionNode* pSectNd = rNdIdx.GetNode().FindSectionNode();
2786 [ # # # # : 0 : if( pSectNd && ( pSectNd->GetSection().IsHiddenFlag() ||
# # ][ # # ]
[ # # ]
2787 : 0 : ( !IsReadOnlyAvailable() &&
2788 : 0 : pSectNd->GetSection().IsProtectFlag() )) )
2789 : : {
2790 : : typedef SwCntntNode* (SwNodes:: *FNGoSection)( SwNodeIndex *, int, int ) const;
2791 : 0 : FNGoSection funcGoSection = &SwNodes::GoNextSection;
2792 : :
2793 : 0 : bOk = sal_False;
2794 : :
2795 [ # # ][ # # ]: 0 : for( int nLoopCnt = 0; !bOk && nLoopCnt < 2; ++nLoopCnt )
[ # # ]
2796 : : {
2797 : : bool bContinue;
2798 [ # # ]: 0 : do {
2799 : 0 : bContinue = false;
2800 [ # # ][ # # ]: 0 : while( 0 != ( pCNd = (rNds.*funcGoSection)( &rNdIdx,
2801 [ # # ]: 0 : sal_True, !IsReadOnlyAvailable() )) )
2802 : : {
2803 : : // moved inside a table -> check if it is protected
2804 [ # # ][ # # ]: 0 : if( pCNd->FindTableNode() )
2805 : : {
2806 [ # # ]: 0 : SwCallLink aTmp( *this );
2807 [ # # ]: 0 : SwCrsrSaveState aSaveState( *pCurCrsr );
2808 : 0 : aTmp.nNdTyp = 0; // don't do anything in DTOR
2809 [ # # ][ # # ]: 0 : if( !pCurCrsr->IsInProtectTable( sal_True, sal_True ) )
2810 : : {
2811 [ # # ]: 0 : const SwSectionNode* pSNd = pCNd->FindSectionNode();
2812 [ # # ][ # # : 0 : if( !pSNd || !pSNd->GetSection().IsHiddenFlag()
# # # # ]
[ # # ]
2813 : 0 : || (!IsReadOnlyAvailable() &&
2814 : 0 : pSNd->GetSection().IsProtectFlag() ))
2815 : : {
2816 : 0 : bOk = sal_True;
2817 : : break; // found non-protected cell
2818 : : }
2819 : 0 : continue; // continue search
2820 [ # # ]: 0 : }
[ # # # ]
[ # # ]
[ # # # ]
2821 : : }
2822 : : else
2823 : : {
2824 : 0 : bOk = sal_True;
2825 : 0 : break; // found non-protected cell
2826 : : }
2827 : : }
2828 : :
2829 [ # # ][ # # ]: 0 : if( bOk && rNdIdx.GetIndex() < rNds.GetEndOfExtras().GetIndex() )
[ # # ]
2830 : : {
2831 : : // also check for Fly - might be protected as well
2832 [ # # ][ # # ]: 0 : if( 0 == (pFrm = pCNd->getLayoutFrm( GetLayout(),0,0,sal_False)) ||
[ # # # # ]
[ # # ]
[ # # # # ]
[ # # ]
2833 [ # # ]: 0 : ( !IsReadOnlyAvailable() && pFrm->IsProtected() ) ||
2834 : 0 : ( bOnlyText && pCNd->IsNoTxtNode() ) )
2835 : : {
2836 : : // continue search
2837 : 0 : bOk = sal_False;
2838 : 0 : bContinue = true;
2839 : : }
2840 : : }
2841 : : } while( bContinue );
2842 : :
2843 [ # # ]: 0 : if( !bOk )
2844 : : {
2845 [ # # ]: 0 : if( !nLoopCnt )
2846 : 0 : funcGoSection = &SwNodes::GoPrevSection;
2847 [ # # ]: 0 : rNdIdx = nNdIdx;
2848 : : }
2849 : : }
2850 : : }
2851 [ # # ]: 0 : if( bOk )
2852 : : {
2853 : 0 : pCNd = rNdIdx.GetNode().GetCntntNode();
2854 [ # # ]: 0 : xub_StrLen nCntnt = rNdIdx.GetIndex() < nNdIdx ? pCNd->Len() : 0;
2855 [ # # ]: 0 : pCurCrsr->GetPoint()->nContent.Assign( pCNd, nCntnt );
2856 : : }
2857 : : else
2858 : : {
2859 : 0 : pCNd = rNdIdx.GetNode().GetCntntNode();
2860 : : // if cursor in hidden frame, always move it
2861 [ # # ][ # # ]: 0 : if( !pCNd || !pCNd->getLayoutFrm( GetLayout(),0,0,sal_False) )
[ # # ]
2862 : : {
2863 : 0 : SwCrsrMoveState aTmpState( MV_NONE );
2864 : 0 : aTmpState.bSetInReadOnly = IsReadOnlyAvailable();
2865 [ # # ]: 0 : GetLayout()->GetCrsrOfst( pCurCrsr->GetPoint(), pCurCrsr->GetPtPos(),
2866 [ # # ]: 0 : &aTmpState );
2867 : : }
2868 : : }
2869 : 0 : return bOk;
2870 : : }
2871 : :
2872 : :
2873 : 104928 : sal_Bool SwCrsrShell::IsCrsrReadonly() const
2874 : : {
2875 [ + + - + ]: 209776 : if ( GetViewOptions()->IsReadonly() ||
[ + + ]
2876 : 104848 : GetViewOptions()->IsFormView() /* Formular view */ )
2877 : : {
2878 : 80 : SwFrm *pFrm = GetCurrFrm( sal_False );
2879 : : const SwFlyFrm* pFly;
2880 : : const SwSection* pSection;
2881 : :
2882 [ - + ][ # # : 80 : if( pFrm && pFrm->IsInFly() &&
# # # # #
# ][ - + ]
[ + - ]
2883 : 0 : (pFly = pFrm->FindFlyFrm())->GetFmt()->GetEditInReadonly().GetValue() &&
2884 : 0 : pFly->Lower() &&
2885 : 0 : !pFly->Lower()->IsNoTxtFrm() &&
2886 : 0 : !GetDrawView()->GetMarkedObjectList().GetMarkCount() )
2887 : : {
2888 : 0 : return sal_False;
2889 : : }
2890 : : // edit in readonly sections
2891 [ + - ][ - + : 80 : else if ( pFrm && pFrm->IsInSct() &&
# # # # ]
[ - + ]
2892 : 0 : 0 != ( pSection = pFrm->FindSctFrm()->GetSection() ) &&
2893 : 0 : pSection->IsEditInReadonlyFlag() )
2894 : : {
2895 : 0 : return sal_False;
2896 : : }
2897 : :
2898 : 80 : return sal_True;
2899 : : }
2900 : 104928 : return sal_False;
2901 : : }
2902 : :
2903 : : /// is the cursor allowed to enter ReadOnly sections?
2904 : 1454 : void SwCrsrShell::SetReadOnlyAvailable( sal_Bool bFlag )
2905 : : {
2906 : : // *never* switch in GlobalDoc
2907 [ + - + - ]: 2908 : if( (!GetDoc()->GetDocShell() ||
[ - + ][ - + ]
2908 : 1454 : !GetDoc()->GetDocShell()->IsA( SwGlobalDocShell::StaticType() )) &&
2909 : : bFlag != bSetCrsrInReadOnly )
2910 : : {
2911 : : // If the flag is switched off then all selections need to be
2912 : : // invalidated. Otherwise we would trust that nothing protected is selected.
2913 [ # # ]: 0 : if( !bFlag )
2914 : : {
2915 : 0 : ClearMark();
2916 : : }
2917 : 0 : bSetCrsrInReadOnly = bFlag;
2918 : 0 : UpdateCrsr();
2919 : : }
2920 : 1454 : }
2921 : :
2922 : 23596 : sal_Bool SwCrsrShell::HasReadonlySel() const
2923 : : {
2924 : 23596 : sal_Bool bRet = sal_False;
2925 [ - + ][ # # ]: 23596 : if( IsReadOnlyAvailable() || GetViewOptions()->IsFormView() )
[ + - ]
2926 : : {
2927 [ + + ]: 23596 : if( pTblCrsr )
2928 : 28 : bRet = pTblCrsr->HasReadOnlyBoxSel() ||
2929 [ - + ][ + - ]: 28 : pTblCrsr->HasReadonlySel( GetViewOptions()->IsFormView() );
2930 : : else
2931 : : {
2932 [ + - ]: 23568 : const SwPaM* pCrsr = pCurCrsr;
2933 : :
2934 [ + + ][ + - ]: 23568 : do {
[ - + ][ - + ]
2935 [ + + ]: 23568 : if( pCrsr->HasReadonlySel( GetViewOptions()->IsFormView() ) )
2936 : 6 : bRet = sal_True;
2937 : 47124 : } while( !bRet && pCurCrsr != ( pCrsr = (SwPaM*)pCrsr->GetNext() ));
2938 : : }
2939 : : }
2940 : 23596 : return bRet;
2941 : : }
2942 : :
2943 : 0 : sal_Bool SwCrsrShell::IsSelFullPara() const
2944 : : {
2945 : 0 : sal_Bool bRet = sal_False;
2946 : :
2947 [ # # ][ # # ]: 0 : if( pCurCrsr->GetPoint()->nNode.GetIndex() ==
[ # # ][ # # ]
2948 : 0 : pCurCrsr->GetMark()->nNode.GetIndex() && pCurCrsr == pCurCrsr->GetNext() )
2949 : : {
2950 : 0 : xub_StrLen nStt = pCurCrsr->GetPoint()->nContent.GetIndex(),
2951 : 0 : nEnd = pCurCrsr->GetMark()->nContent.GetIndex();
2952 [ # # ]: 0 : if( nStt > nEnd )
2953 : : {
2954 : 0 : xub_StrLen nTmp = nStt;
2955 : 0 : nStt = nEnd;
2956 : 0 : nEnd = nTmp;
2957 : : }
2958 : 0 : const SwCntntNode* pCNd = pCurCrsr->GetCntntNode();
2959 [ # # ][ # # ]: 0 : bRet = pCNd && !nStt && nEnd == pCNd->Len();
[ # # ]
2960 : : }
2961 : 0 : return bRet;
2962 : : }
2963 : :
2964 : 13692 : short SwCrsrShell::GetTextDirection( const Point* pPt ) const
2965 : : {
2966 [ + - ]: 13692 : SwPosition aPos( *pCurCrsr->GetPoint() );
2967 [ + - ]: 13692 : Point aPt( pPt ? *pPt : pCurCrsr->GetPtPos() );
2968 [ - + ]: 13692 : if( pPt )
2969 : : {
2970 : 0 : SwCrsrMoveState aTmpState( MV_NONE );
2971 : 0 : aTmpState.bSetInReadOnly = IsReadOnlyAvailable();
2972 : :
2973 [ # # ][ # # ]: 0 : GetLayout()->GetCrsrOfst( &aPos, aPt, &aTmpState );
2974 : : }
2975 : :
2976 [ + - ][ + - ]: 13692 : return pDoc->GetTextDirection( aPos, &aPt );
2977 : : }
2978 : :
2979 : 7892 : sal_Bool SwCrsrShell::IsInVerticalText( const Point* pPt ) const
2980 : : {
2981 : 7892 : const short nDir = GetTextDirection( pPt );
2982 [ - + ][ + - ]: 7892 : return FRMDIR_VERT_TOP_RIGHT == nDir || FRMDIR_VERT_TOP_LEFT == nDir;
2983 : : }
2984 : :
2985 : 5800 : sal_Bool SwCrsrShell::IsInRightToLeftText( const Point* pPt ) const
2986 : : {
2987 : 5800 : const short nDir = GetTextDirection( pPt );
2988 : : // GetTextDirection uses FRMDIR_VERT_TOP_LEFT to indicate RTL in
2989 : : // vertical environment
2990 [ - + ][ + - ]: 5800 : return FRMDIR_VERT_TOP_LEFT == nDir || FRMDIR_HORI_RIGHT_TOP == nDir;
2991 : : }
2992 : :
2993 : : /// If the current cursor position is inside a hidden range, the hidden range
2994 : : /// is selected.
2995 : 0 : bool SwCrsrShell::SelectHiddenRange()
2996 : : {
2997 : 0 : bool bRet = false;
2998 [ # # ][ # # ]: 0 : if ( !GetViewOptions()->IsShowHiddenChar() && !pCurCrsr->HasMark() )
[ # # ]
2999 : : {
3000 : 0 : SwPosition& rPt = *(SwPosition*)pCurCrsr->GetPoint();
3001 : 0 : const SwTxtNode* pNode = rPt.nNode.GetNode().GetTxtNode();
3002 [ # # ]: 0 : if ( pNode )
3003 : : {
3004 : 0 : const xub_StrLen nPos = rPt.nContent.GetIndex();
3005 : :
3006 : : // check if nPos is in hidden range
3007 : : xub_StrLen nHiddenStart;
3008 : : xub_StrLen nHiddenEnd;
3009 [ # # ]: 0 : SwScriptInfo::GetBoundsOfHiddenRange( *pNode, nPos, nHiddenStart, nHiddenEnd );
3010 [ # # ]: 0 : if ( STRING_LEN != nHiddenStart )
3011 : : {
3012 : : // make selection:
3013 [ # # ]: 0 : pCurCrsr->SetMark();
3014 [ # # ]: 0 : pCurCrsr->GetMark()->nContent = nHiddenEnd;
3015 : 0 : bRet = true;
3016 : : }
3017 : : }
3018 : : }
3019 : :
3020 : 0 : return bRet;
3021 : : }
3022 : :
3023 : 0 : sal_uLong SwCrsrShell::Find( const SearchOptions& rSearchOpt,
3024 : : sal_Bool bSearchInNotes,
3025 : : SwDocPositions eStart, SwDocPositions eEnd,
3026 : : sal_Bool& bCancel,
3027 : : FindRanges eRng,
3028 : : int bReplace )
3029 : : {
3030 [ # # ]: 0 : if( pTblCrsr )
3031 [ # # ]: 0 : GetCrsr();
3032 [ # # ][ # # ]: 0 : delete pTblCrsr, pTblCrsr = 0;
3033 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
3034 : : sal_uLong nRet = pCurCrsr->Find( rSearchOpt, bSearchInNotes, eStart, eEnd,
3035 [ # # ]: 0 : bCancel, eRng, bReplace );
3036 [ # # ][ # # ]: 0 : if( nRet || bCancel )
3037 [ # # ]: 0 : UpdateCrsr();
3038 [ # # ]: 0 : return nRet;
3039 : : }
3040 : :
3041 : 0 : sal_uLong SwCrsrShell::Find( const SwTxtFmtColl& rFmtColl,
3042 : : SwDocPositions eStart, SwDocPositions eEnd,
3043 : : sal_Bool& bCancel,
3044 : : FindRanges eRng,
3045 : : const SwTxtFmtColl* pReplFmt )
3046 : : {
3047 [ # # ]: 0 : if( pTblCrsr )
3048 [ # # ]: 0 : GetCrsr();
3049 [ # # ][ # # ]: 0 : delete pTblCrsr, pTblCrsr = 0;
3050 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
3051 : : sal_uLong nRet = pCurCrsr->Find( rFmtColl, eStart, eEnd, bCancel, eRng,
3052 [ # # ]: 0 : pReplFmt );
3053 [ # # ]: 0 : if( nRet )
3054 [ # # ]: 0 : UpdateCrsr();
3055 [ # # ]: 0 : return nRet;
3056 : : }
3057 : :
3058 : 0 : sal_uLong SwCrsrShell::Find( const SfxItemSet& rSet,
3059 : : sal_Bool bNoCollections,
3060 : : SwDocPositions eStart, SwDocPositions eEnd,
3061 : : sal_Bool& bCancel,
3062 : : FindRanges eRng,
3063 : : const SearchOptions* pSearchOpt,
3064 : : const SfxItemSet* rReplSet )
3065 : : {
3066 [ # # ]: 0 : if( pTblCrsr )
3067 [ # # ]: 0 : GetCrsr();
3068 [ # # ][ # # ]: 0 : delete pTblCrsr, pTblCrsr = 0;
3069 [ # # ]: 0 : SwCallLink aLk( *this ); // watch Crsr-Moves; call Link if needed
3070 : : sal_uLong nRet = pCurCrsr->Find( rSet, bNoCollections, eStart, eEnd,
3071 [ # # ]: 0 : bCancel, eRng, pSearchOpt, rReplSet );
3072 [ # # ]: 0 : if( nRet )
3073 [ # # ]: 0 : UpdateCrsr();
3074 [ # # ]: 0 : return nRet;
3075 : : }
3076 : :
3077 : 18 : void SwCrsrShell::SetSelection( const SwPaM& rCrsr )
3078 : : {
3079 : 18 : StartAction();
3080 : 18 : SwPaM* pCrsr = GetCrsr();
3081 : 18 : *pCrsr->GetPoint() = *rCrsr.GetPoint();
3082 [ + + ]: 18 : if(rCrsr.HasMark())
3083 : : {
3084 : 4 : pCrsr->SetMark();
3085 : 4 : *pCrsr->GetMark() = *rCrsr.GetMark();
3086 : : }
3087 [ - + ]: 18 : if((SwPaM*)rCrsr.GetNext() != &rCrsr)
3088 : : {
3089 : 0 : const SwPaM *_pStartCrsr = (SwPaM*)rCrsr.GetNext();
3090 [ # # ]: 0 : do
3091 : : {
3092 : 0 : SwPaM* pCurrentCrsr = CreateCrsr();
3093 : 0 : *pCurrentCrsr->GetPoint() = *_pStartCrsr->GetPoint();
3094 [ # # ]: 0 : if(_pStartCrsr->HasMark())
3095 : : {
3096 : 0 : pCurrentCrsr->SetMark();
3097 : 0 : *pCurrentCrsr->GetMark() = *_pStartCrsr->GetMark();
3098 : : }
3099 : 0 : } while( (_pStartCrsr=(SwPaM *)_pStartCrsr->GetNext()) != &rCrsr );
3100 : : }
3101 : 18 : EndAction();
3102 : 18 : }
3103 : :
3104 : 0 : void lcl_RemoveMark( SwPaM* pPam )
3105 : : {
3106 : : OSL_ENSURE( pPam->HasMark(), "Don't remove pPoint!" );
3107 : 0 : pPam->GetMark()->nContent.Assign( 0, 0 );
3108 : 0 : pPam->GetMark()->nNode = 0;
3109 : 0 : pPam->DeleteMark();
3110 : 0 : }
3111 : :
3112 : 0 : const SwStartNode* lcl_NodeContext( const SwNode& rNode )
3113 : : {
3114 : 0 : const SwStartNode *pRet = rNode.StartOfSectionNode();
3115 [ # # ]: 0 : while( pRet->IsSectionNode() || pRet->IsTableNode() ||
[ # # # # ]
[ # # ]
3116 : 0 : pRet->GetStartNodeType() == SwTableBoxStartNode )
3117 : : {
3118 : 0 : pRet = pRet->StartOfSectionNode();
3119 : : }
3120 : 0 : return pRet;
3121 : : }
3122 : :
3123 : : /**
3124 : : Checks if a position is valid. To be valid the position's node must
3125 : : be a content node and the content must not be unregistered.
3126 : :
3127 : : @param aPos the position to check.
3128 : : */
3129 : 35838 : bool lcl_PosOk(const SwPosition & aPos)
3130 : : {
3131 : 35838 : return NULL != aPos.nNode.GetNode().GetCntntNode() &&
3132 [ + - ][ + - ]: 35838 : aPos.nContent.GetIdxReg();
3133 : : }
3134 : :
3135 : : /**
3136 : : Checks if a PaM is valid. For a PaM to be valid its point must be
3137 : : valid. Additionaly if the PaM has a mark this has to be valid, too.
3138 : :
3139 : : @param aPam the PaM to check
3140 : : */
3141 : 30 : static bool lcl_CrsrOk(SwPaM & aPam)
3142 : : {
3143 : 60 : return lcl_PosOk(*aPam.GetPoint()) && (! aPam.HasMark()
3144 [ + - ]: 60 : || lcl_PosOk(*aPam.GetMark()));
[ + - + - ]
3145 : : }
3146 : :
3147 : 35568 : void SwCrsrShell::ClearUpCrsrs()
3148 : : {
3149 : : // start of the ring
3150 : 35568 : SwPaM * pStartCrsr = GetCrsr();
3151 : : // start loop with second entry of the ring
3152 : 35568 : SwPaM * pCrsr = (SwPaM *) pStartCrsr->GetNext();
3153 : : SwPaM * pTmpCrsr;
3154 : 35568 : bool bChanged = false;
3155 : :
3156 : : // For all entries in the ring except the start entry delete the entry if
3157 : : // it is invalid.
3158 [ + + ]: 35598 : while (pCrsr != pStartCrsr)
3159 : : {
3160 : 30 : pTmpCrsr = (SwPaM *) pCrsr->GetNext();
3161 : :
3162 [ - + ]: 30 : if ( ! lcl_CrsrOk(*pCrsr))
3163 : : {
3164 [ # # ]: 0 : delete pCrsr;
3165 : :
3166 : 0 : bChanged = true;
3167 : : }
3168 : :
3169 : 30 : pCrsr = pTmpCrsr;
3170 : : }
3171 : :
3172 [ + + ][ - + ]: 35568 : if( pStartCrsr->HasMark() && !lcl_PosOk( *pStartCrsr->GetMark() ) )
[ - + ]
3173 : : {
3174 : 0 : lcl_RemoveMark( pStartCrsr );
3175 : 0 : bChanged = true;
3176 : : }
3177 [ - + ]: 35568 : if( !lcl_PosOk( *pStartCrsr->GetPoint() ) )
3178 : : {
3179 [ # # ]: 0 : SwNodes & aNodes = GetDoc()->GetNodes();
3180 : 0 : const SwNode* pStart = lcl_NodeContext( pStartCrsr->GetPoint()->nNode.GetNode() );
3181 [ # # ]: 0 : SwNodeIndex aIdx( pStartCrsr->GetPoint()->nNode );
3182 [ # # ][ # # ]: 0 : SwNode * pNode = aNodes.GoPrevious(&aIdx);
3183 [ # # ][ # # ]: 0 : if( pNode == NULL || lcl_NodeContext( *pNode ) != pStart )
[ # # ]
3184 [ # # ]: 0 : aNodes.GoNext( &aIdx );
3185 [ # # ][ # # ]: 0 : if( pNode == NULL || lcl_NodeContext( *pNode ) != pStart )
[ # # ]
3186 : : {
3187 : : // If the start entry of the ring is invalid replace it with a
3188 : : // cursor pointing to the beginning of the first content node in the
3189 : : // document.
3190 [ # # ]: 0 : aIdx = (*(aNodes.GetEndOfContent().StartOfSectionNode()));
3191 [ # # ][ # # ]: 0 : pNode = aNodes.GoNext( &aIdx );
3192 : : }
3193 : 0 : bool bFound = (pNode != NULL);
3194 : :
3195 : : OSL_ENSURE(bFound, "no content node found");
3196 : :
3197 [ # # ]: 0 : if (bFound)
3198 : : {
3199 [ # # ]: 0 : SwPaM aTmpPam(*pNode);
3200 [ # # ][ # # ]: 0 : *pStartCrsr = aTmpPam;
3201 : : }
3202 : :
3203 [ # # ]: 0 : bChanged = true;
3204 : : }
3205 : :
3206 : : // If at least one of the cursors in the ring have been deleted or replaced,
3207 : : // remove the table cursor.
3208 [ + + ][ - + ]: 35568 : if (pTblCrsr != NULL && bChanged)
3209 : 0 : TblCrsrToCursor();
3210 : 35568 : }
3211 : :
3212 : 0 : String SwCrsrShell::GetCrsrDescr() const
3213 : : {
3214 : 0 : String aResult;
3215 : :
3216 [ # # ]: 0 : if (IsMultiSelection())
3217 [ # # ][ # # ]: 0 : aResult += String(SW_RES(STR_MULTISEL));
[ # # ]
3218 : : else
3219 [ # # ][ # # ]: 0 : aResult = GetDoc()->GetPaMDescr(*GetCrsr());
[ # # ][ # # ]
3220 : :
3221 : 0 : return aResult;
3222 : : }
3223 : :
3224 : : // SMARTTAGS
3225 : :
3226 : 0 : void lcl_FillRecognizerData( uno::Sequence< rtl::OUString >& rSmartTagTypes,
3227 : : uno::Sequence< uno::Reference< container::XStringKeyMap > >& rStringKeyMaps,
3228 : : const SwWrongList& rSmartTagList, xub_StrLen nCurrent )
3229 : : {
3230 : : // Insert smart tag information
3231 [ # # ]: 0 : std::vector< rtl::OUString > aSmartTagTypes;
3232 [ # # ]: 0 : std::vector< uno::Reference< container::XStringKeyMap > > aStringKeyMaps;
3233 : :
3234 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < rSmartTagList.Count(); ++i )
3235 : : {
3236 [ # # ]: 0 : const xub_StrLen nSTPos = rSmartTagList.Pos( i );
3237 [ # # ]: 0 : const xub_StrLen nSTLen = rSmartTagList.Len( i );
3238 : :
3239 [ # # ][ # # ]: 0 : if ( nSTPos <= nCurrent && nCurrent < nSTPos + nSTLen )
3240 : : {
3241 [ # # ]: 0 : const SwWrongArea* pArea = rSmartTagList.GetElement( i );
3242 [ # # ]: 0 : if ( pArea )
3243 : : {
3244 [ # # ]: 0 : aSmartTagTypes.push_back( pArea->maType );
3245 [ # # ]: 0 : aStringKeyMaps.push_back( pArea->mxPropertyBag );
3246 : : }
3247 : : }
3248 : : }
3249 : :
3250 [ # # ]: 0 : if ( !aSmartTagTypes.empty() )
3251 : : {
3252 [ # # ]: 0 : rSmartTagTypes.realloc( aSmartTagTypes.size() );
3253 [ # # ]: 0 : rStringKeyMaps.realloc( aSmartTagTypes.size() );
3254 : :
3255 [ # # ]: 0 : std::vector< rtl::OUString >::const_iterator aTypesIter = aSmartTagTypes.begin();
3256 : 0 : sal_uInt16 i = 0;
3257 [ # # ][ # # ]: 0 : for ( aTypesIter = aSmartTagTypes.begin(); aTypesIter != aSmartTagTypes.end(); ++aTypesIter )
[ # # ]
3258 [ # # ]: 0 : rSmartTagTypes[i++] = *aTypesIter;
3259 : :
3260 [ # # ]: 0 : std::vector< uno::Reference< container::XStringKeyMap > >::const_iterator aMapsIter = aStringKeyMaps.begin();
3261 : 0 : i = 0;
3262 [ # # ][ # # ]: 0 : for ( aMapsIter = aStringKeyMaps.begin(); aMapsIter != aStringKeyMaps.end(); ++aMapsIter )
[ # # ]
3263 [ # # ][ # # ]: 0 : rStringKeyMaps[i++] = *aMapsIter;
3264 : 0 : }
3265 : 0 : }
3266 : :
3267 : 0 : void lcl_FillTextRange( uno::Reference<text::XTextRange>& rRange,
3268 : : SwTxtNode& rNode, xub_StrLen nBegin, xub_StrLen nLen )
3269 : : {
3270 : : // create SwPosition for nStartIndex
3271 [ # # ]: 0 : SwIndex aIndex( &rNode, nBegin );
3272 [ # # ][ # # ]: 0 : SwPosition aStartPos( rNode, aIndex );
[ # # ]
3273 : :
3274 : : // create SwPosition for nEndIndex
3275 [ # # ]: 0 : SwPosition aEndPos( aStartPos );
3276 [ # # ]: 0 : aEndPos.nContent = nBegin + nLen;
3277 : :
3278 : : const uno::Reference<text::XTextRange> xRange =
3279 [ # # ]: 0 : SwXTextRange::CreateXTextRange(*rNode.GetDoc(), aStartPos, &aEndPos);
3280 : :
3281 [ # # ][ # # ]: 0 : rRange = xRange;
[ # # ][ # # ]
3282 : 0 : }
3283 : :
3284 : 0 : void SwCrsrShell::GetSmartTagTerm( uno::Sequence< rtl::OUString >& rSmartTagTypes,
3285 : : uno::Sequence< uno::Reference< container::XStringKeyMap > >& rStringKeyMaps,
3286 : : uno::Reference< text::XTextRange>& rRange ) const
3287 : : {
3288 [ # # ][ # # ]: 0 : if ( !SwSmartTagMgr::Get().IsSmartTagsEnabled() )
3289 : 0 : return;
3290 : :
3291 [ # # ]: 0 : SwPaM* pCrsr = GetCrsr();
3292 [ # # ]: 0 : SwPosition aPos( *pCrsr->GetPoint() );
3293 : 0 : SwTxtNode *pNode = aPos.nNode.GetNode().GetTxtNode();
3294 [ # # ][ # # ]: 0 : if ( pNode && !pNode->IsInProtectSect() )
[ # # ][ # # ]
3295 : : {
3296 [ # # ]: 0 : const SwWrongList *pSmartTagList = pNode->GetSmartTags();
3297 [ # # ]: 0 : if ( pSmartTagList )
3298 : : {
3299 : 0 : xub_StrLen nCurrent = aPos.nContent.GetIndex();
3300 : 0 : xub_StrLen nBegin = nCurrent;
3301 : 0 : xub_StrLen nLen = 1;
3302 : :
3303 [ # # ][ # # ]: 0 : if( pSmartTagList->InWrongWord( nBegin, nLen ) && !pNode->IsSymbol(nBegin) )
[ # # ][ # # ]
[ # # ]
3304 : : {
3305 [ # # ]: 0 : const sal_uInt16 nIndex = pSmartTagList->GetWrongPos( nBegin );
3306 [ # # ]: 0 : const SwWrongList* pSubList = pSmartTagList->SubList( nIndex );
3307 [ # # ]: 0 : if ( pSubList )
3308 : : {
3309 : 0 : pSmartTagList = pSubList;
3310 : 0 : nCurrent = 0;
3311 : : }
3312 : :
3313 [ # # ]: 0 : lcl_FillRecognizerData( rSmartTagTypes, rStringKeyMaps, *pSmartTagList, nCurrent );
3314 [ # # ]: 0 : lcl_FillTextRange( rRange, *pNode, nBegin, nLen );
3315 : : }
3316 : : }
3317 [ # # ]: 0 : }
3318 : : }
3319 : :
3320 : : // see also SwEditShell::GetCorrection( const Point* pPt, SwRect& rSelectRect )
3321 : 0 : void SwCrsrShell::GetSmartTagTerm( const Point& rPt, SwRect& rSelectRect,
3322 : : uno::Sequence< rtl::OUString >& rSmartTagTypes,
3323 : : uno::Sequence< uno::Reference< container::XStringKeyMap > >& rStringKeyMaps,
3324 : : uno::Reference<text::XTextRange>& rRange )
3325 : : {
3326 [ # # ][ # # ]: 0 : if ( !SwSmartTagMgr::Get().IsSmartTagsEnabled() )
3327 : 0 : return;
3328 : :
3329 [ # # ]: 0 : SwPaM* pCrsr = GetCrsr();
3330 [ # # ]: 0 : SwPosition aPos( *pCrsr->GetPoint() );
3331 : 0 : Point aPt( rPt );
3332 : 0 : SwCrsrMoveState eTmpState( MV_SETONLYTEXT );
3333 : 0 : SwSpecialPos aSpecialPos;
3334 : 0 : eTmpState.pSpecialPos = &aSpecialPos;
3335 : : SwTxtNode *pNode;
3336 : : const SwWrongList *pSmartTagList;
3337 : :
3338 [ # # ]: 0 : if( GetLayout()->GetCrsrOfst( &aPos, aPt, &eTmpState ) &&
[ # # # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
3339 : 0 : 0 != (pNode = aPos.nNode.GetNode().GetTxtNode()) &&
3340 : : 0 != (pSmartTagList = pNode->GetSmartTags()) &&
3341 [ # # ]: 0 : !pNode->IsInProtectSect() )
3342 : : {
3343 : 0 : xub_StrLen nCurrent = aPos.nContent.GetIndex();
3344 : 0 : xub_StrLen nBegin = nCurrent;
3345 : 0 : xub_StrLen nLen = 1;
3346 : :
3347 [ # # ][ # # ]: 0 : if( pSmartTagList->InWrongWord( nBegin, nLen ) && !pNode->IsSymbol(nBegin) )
[ # # ][ # # ]
[ # # ]
3348 : : {
3349 [ # # ]: 0 : const sal_uInt16 nIndex = pSmartTagList->GetWrongPos( nBegin );
3350 [ # # ]: 0 : const SwWrongList* pSubList = pSmartTagList->SubList( nIndex );
3351 [ # # ]: 0 : if ( pSubList )
3352 : : {
3353 : 0 : pSmartTagList = pSubList;
3354 : 0 : nCurrent = eTmpState.pSpecialPos->nCharOfst;
3355 : : }
3356 : :
3357 [ # # ]: 0 : lcl_FillRecognizerData( rSmartTagTypes, rStringKeyMaps, *pSmartTagList, nCurrent );
3358 [ # # ]: 0 : lcl_FillTextRange( rRange, *pNode, nBegin, nLen );
3359 : :
3360 : : // get smarttag word
3361 [ # # ]: 0 : String aText( pNode->GetTxt().Copy( nBegin, nLen ) );
3362 : :
3363 : : //save the start and end positons of the line and the starting point
3364 [ # # ]: 0 : Push();
3365 [ # # ]: 0 : LeftMargin();
3366 [ # # ]: 0 : xub_StrLen nLineStart = GetCrsr()->GetPoint()->nContent.GetIndex();
3367 [ # # ]: 0 : RightMargin();
3368 [ # # ]: 0 : xub_StrLen nLineEnd = GetCrsr()->GetPoint()->nContent.GetIndex();
3369 [ # # ]: 0 : Pop(sal_False);
3370 : :
3371 : : // make sure the selection build later from the data below does not
3372 : : // include "in word" character to the left and right in order to
3373 : : // preserve those. Therefore count those "in words" in order to
3374 : : // modify the selection accordingly.
3375 : 0 : const sal_Unicode* pChar = aText.GetBuffer();
3376 : 0 : xub_StrLen nLeft = 0;
3377 [ # # ][ # # ]: 0 : while (pChar && *pChar++ == CH_TXTATR_INWORD)
[ # # ]
3378 : 0 : ++nLeft;
3379 [ # # ]: 0 : pChar = aText.Len() ? aText.GetBuffer() + aText.Len() - 1 : 0;
3380 : 0 : xub_StrLen nRight = 0;
3381 [ # # ][ # # ]: 0 : while (pChar && *pChar-- == CH_TXTATR_INWORD)
[ # # ]
3382 : 0 : ++nRight;
3383 : :
3384 [ # # ]: 0 : aPos.nContent = nBegin + nLeft;
3385 [ # # ]: 0 : pCrsr = GetCrsr();
3386 [ # # ]: 0 : *pCrsr->GetPoint() = aPos;
3387 [ # # ]: 0 : pCrsr->SetMark();
3388 [ # # ]: 0 : ExtendSelection( sal_True, nLen - nLeft - nRight );
3389 : : // do not determine the rectangle in the current line
3390 : 0 : xub_StrLen nWordStart = (nBegin + nLeft) < nLineStart ? nLineStart : nBegin + nLeft;
3391 : : // take one less than the line end - otherwise the next line would
3392 : : // be calculated
3393 : 0 : xub_StrLen nWordEnd = (nBegin + nLen - nLeft - nRight) > nLineEnd ? nLineEnd : (nBegin + nLen - nLeft - nRight);
3394 [ # # ]: 0 : Push();
3395 [ # # ]: 0 : pCrsr->DeleteMark();
3396 [ # # ]: 0 : SwIndex& rContent = GetCrsr()->GetPoint()->nContent;
3397 [ # # ]: 0 : rContent = nWordStart;
3398 : 0 : SwRect aStartRect;
3399 : 0 : SwCrsrMoveState aState;
3400 : 0 : aState.bRealWidth = sal_True;
3401 : 0 : SwCntntNode* pCntntNode = pCrsr->GetCntntNode();
3402 [ # # ][ # # ]: 0 : SwCntntFrm *pCntntFrame = pCntntNode->getLayoutFrm( GetLayout(), &rPt, pCrsr->GetPoint(), sal_False);
3403 : :
3404 [ # # ]: 0 : pCntntFrame->GetCharRect( aStartRect, *pCrsr->GetPoint(), &aState );
3405 [ # # ]: 0 : rContent = nWordEnd - 1;
3406 : 0 : SwRect aEndRect;
3407 [ # # ]: 0 : pCntntFrame->GetCharRect( aEndRect, *pCrsr->GetPoint(),&aState );
3408 [ # # ]: 0 : rSelectRect = aStartRect.Union( aEndRect );
3409 [ # # ][ # # ]: 0 : Pop(sal_False);
3410 : : }
3411 [ # # ]: 0 : }
3412 : : }
3413 : :
3414 : :
3415 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|