1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <crsskip.hxx>
23 #include <editeng/lrspitem.hxx> // #i23725#
26 #include <drawbase.hxx>
28 inline void SwWrtShell::OpenMark()
36 inline void SwWrtShell::CloseMark( bool bOkFlag
)
48 bool SwWrtShell::TryRemoveIndent()
52 SfxItemSet
aAttrSet(GetAttrPool(), RES_LR_SPACE
, RES_LR_SPACE
);
55 SvxLRSpaceItem aItem
= (const SvxLRSpaceItem
&)aAttrSet
.Get(RES_LR_SPACE
);
56 short aOldFirstLineOfst
= aItem
.GetTxtFirstLineOfst();
58 if (aOldFirstLineOfst
> 0)
60 aItem
.SetTxtFirstLineOfst(0);
63 else if (aOldFirstLineOfst
< 0)
65 aItem
.SetTxtFirstLineOfst(0);
66 aItem
.SetLeft(aItem
.GetLeft() + aOldFirstLineOfst
);
70 else if (aItem
.GetLeft() != 0)
85 /** Description: Erase the line. */
87 long SwWrtShell::DelLine()
89 SwActContext
aActContext(this);
91 // remember the old cursor
94 SwCrsrShell::LeftMargin();
96 SwCrsrShell::RightMargin();
107 long SwWrtShell::DelToStartOfLine()
110 SwCrsrShell::LeftMargin();
111 long nRet
= Delete();
112 CloseMark( 0 != nRet
);
118 long SwWrtShell::DelToEndOfLine()
121 SwCrsrShell::RightMargin();
122 long nRet
= Delete();
123 CloseMark( 0 != nRet
);
127 long SwWrtShell::DelLeft()
129 // If it's a Fly, throw it away
130 int nSelType
= GetSelectionType();
131 const int nCmp
= nsSelectionType::SEL_FRM
| nsSelectionType::SEL_GRF
| nsSelectionType::SEL_OLE
| nsSelectionType::SEL_DRW
;
132 if( nCmp
& nSelType
)
134 // #108205# Remember object's position.
135 Point aTmpPt
= GetObjRect().TopLeft();
139 // #108205# Set cursor to remembered position.
145 nSelType
= GetSelectionType();
146 if ( nCmp
& nSelType
)
155 // If a selection exists, erase this
158 if( !IsBlockMode() || HasSelection() )
160 //OS: Once again Basic: SwActContext must be leaved
161 //before EnterStdMode!
163 SwActContext
aActContext(this);
182 // JP 29.06.95: never erase a table standing in front of it.
184 const SwTableNode
* pWasInTblNd
= SwCrsrShell::IsCrsrInTbl();
186 if( SwCrsrShell::IsSttPara())
188 // #i4032# Don't actually call a 'delete' if we
189 // changed the table cell, compare DelRight().
190 const SwStartNode
* pSNdOld
= pWasInTblNd
?
191 GetSwCrsr()->GetNode()->FindTableBoxStartNode() :
194 // If the cursor is at the beginning of a paragraph, try to step
195 // backwards. On failure we are done.
196 if( !SwCrsrShell::Left(1,CRSR_SKIP_CHARS
) )
199 // If the cursor entered or left a table (or both) we are done. No step
201 const SwTableNode
* pIsInTblNd
= SwCrsrShell::IsCrsrInTbl();
202 if( pIsInTblNd
!= pWasInTblNd
)
205 const SwStartNode
* pSNdNew
= pIsInTblNd
?
206 GetSwCrsr()->GetNode()->FindTableBoxStartNode() :
209 // #i4032# Don't actually call a 'delete' if we
210 // changed the table cell, compare DelRight().
211 if ( pSNdOld
!= pSNdNew
)
215 SwCrsrShell::Right(1,CRSR_SKIP_CHARS
);
216 SwCrsrShell::SwapPam();
222 SwCrsrShell::Left(1,CRSR_SKIP_CHARS
);
224 long nRet
= Delete();
226 SwCrsrShell::SwapPam();
227 CloseMark( 0 != nRet
);
231 long SwWrtShell::DelRight()
233 // Will be or'ed, if a tableselection exists;
234 // will here be implemented on nsSelectionType::SEL_TBL
236 int nSelection
= GetSelectionType();
237 if(nSelection
& nsSelectionType::SEL_TBL_CELLS
)
238 nSelection
= nsSelectionType::SEL_TBL
;
239 if(nSelection
& nsSelectionType::SEL_TXT
)
240 nSelection
= nsSelectionType::SEL_TXT
;
242 const SwTableNode
* pWasInTblNd
= NULL
;
244 switch( nSelection
& ~(nsSelectionType::SEL_BEZ
) )
246 case nsSelectionType::SEL_POSTIT
:
247 case nsSelectionType::SEL_TXT
:
248 case nsSelectionType::SEL_TBL
:
249 case nsSelectionType::SEL_NUM
:
250 // If a selection exists, erase it.
253 if( !IsBlockMode() || HasSelection() )
255 //OS: And once again Basic: SwActContext must be
256 //leaved before EnterStdMode !
258 SwActContext
aActContext(this);
278 pWasInTblNd
= IsCrsrInTbl();
280 if( nsSelectionType::SEL_TXT
& nSelection
&& SwCrsrShell::IsSttPara() &&
281 SwCrsrShell::IsEndPara() )
286 bool bDelFull
= false;
287 if ( SwCrsrShell::Right(1,CRSR_SKIP_CHARS
) )
289 const SwTableNode
* pCurrTblNd
= IsCrsrInTbl();
290 bDelFull
= pCurrTblNd
&& pCurrTblNd
!= pWasInTblNd
;
294 SwCrsrShell::Pop( sal_False
);
305 // #108049# Save the startnode of the current cell
306 const SwStartNode
* pSNdOld
;
307 pSNdOld
= GetSwCrsr()->GetNode()->
308 FindTableBoxStartNode();
310 if ( SwCrsrShell::IsEndPara() )
312 // #i41424# Introduced a couple of
313 // Push()-Pop() pairs here. The reason for this is that a
314 // Right()-Left() combination does not make sure, that
315 // the cursor will be in its initial state, because there
316 // may be a numbering in front of the next paragraph.
319 if ( SwCrsrShell::Right(1, CRSR_SKIP_CHARS
) )
321 if (IsCrsrInTbl() || (pWasInTblNd
!= IsCrsrInTbl()))
323 /** #108049# Save the startnode of the current
324 cell. May be different to pSNdOld as we have
326 const SwStartNode
* pSNdNew
= GetSwCrsr()
327 ->GetNode()->FindTableBoxStartNode();
329 /** #108049# Only move instead of deleting if we
330 have moved to a different cell */
331 if (pSNdOld
!= pSNdNew
)
333 SwCrsrShell::Pop( sal_True
);
340 SwCrsrShell::Pop( sal_False
);
345 SwCrsrShell::Right(1,CRSR_SKIP_CELLS
);
347 CloseMark( 0 != nRet
);
350 case nsSelectionType::SEL_FRM
:
351 case nsSelectionType::SEL_GRF
:
352 case nsSelectionType::SEL_OLE
:
353 case nsSelectionType::SEL_DRW
:
354 case nsSelectionType::SEL_DRW_TXT
:
355 case nsSelectionType::SEL_DRW_FORM
:
357 // #108205# Remember object's position.
358 Point aTmpPt
= GetObjRect().TopLeft();
362 // #108205# Set cursor to remembered position.
368 OSL_ENSURE( !IsFrmSelected(),
369 "<SwWrtShell::DelRight(..)> - <SwWrtShell::UnSelectFrm()> should unmark all objects" );
371 // leave draw mode, if necessary.
373 if (GetView().GetDrawFuncPtr())
375 GetView().GetDrawFuncPtr()->Deactivate();
376 GetView().SetDrawFuncPtr(NULL
);
378 if ( GetView().IsDrawMode() )
380 GetView().LeaveDrawCreate();
386 // <IsFrmSelected()> can't be true - see above.
388 nSelection
= GetSelectionType();
389 if ( nsSelectionType::SEL_FRM
& nSelection
||
390 nsSelectionType::SEL_GRF
& nSelection
||
391 nsSelectionType::SEL_OLE
& nSelection
||
392 nsSelectionType::SEL_DRW
& nSelection
)
404 long SwWrtShell::DelToEndOfPara()
406 SwActContext
aActContext(this);
410 if( !MovePara(fnParaCurr
,fnParaEnd
))
415 long nRet
= Delete();
422 long SwWrtShell::DelToStartOfPara()
424 SwActContext
aActContext(this);
428 if( !MovePara(fnParaCurr
,fnParaStart
))
433 long nRet
= Delete();
440 // All erase operations should work with Find instead with
441 // Nxt-/PrvDelim, because the latter works with Wrap Around
442 // -- that's probably not wished.
444 long SwWrtShell::DelToStartOfSentence()
449 long nRet
= _BwdSentence() ? Delete() : 0;
450 CloseMark( 0 != nRet
);
454 long SwWrtShell::DelToEndOfSentence()
460 // fdo#60967: special case that is documented in help: delete
461 // paragraph following table if cursor is at end of last cell in table
466 if (SwCrsrShell::Right(1,CRSR_SKIP_CHARS
))
469 SwCrsrShell::MovePara(fnParaCurr
, fnParaEnd
);
470 if (!IsEndOfDoc()) // do not delete last paragraph in body text
472 nRet
= DelFullPara() ? 1 : 0;
479 nRet
= _FwdSentence() ? Delete() : 0;
481 CloseMark( 0 != nRet
);
485 long SwWrtShell::DelNxtWord()
489 SwActContext
aActContext(this);
493 if(IsEndWrd() && !IsSttWrd())
494 _NxtWrdForDelete(); // #i92468#
495 if(IsSttWrd() || IsEndPara())
496 _NxtWrdForDelete(); // #i92468#
500 long nRet
= Delete();
509 long SwWrtShell::DelPrvWord()
513 SwActContext
aActContext(this);
518 !_PrvWrdForDelete() ) // #i92468#
522 if ( _PrvWrdForDelete() ) // #i92468#
524 // skip over all-1 spaces
526 while( ' ' == GetChar( sal_False
, n
))
530 ExtendSelection( sal_False
, -n
);
533 else if( IsSttPara())
534 _PrvWrdForDelete(); // #i92468#
538 long nRet
= Delete();
550 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */