1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: delete.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
36 #include <crsskip.hxx>
38 #include <svx/lrspitem.hxx> // #i23725#
39 // --> OD 2006-07-10 #134369#
44 #include <drawbase.hxx>
48 inline void SwWrtShell::OpenMark()
56 inline void SwWrtShell::CloseMark( BOOL bOkFlag
)
68 BOOL
SwWrtShell::TryRemoveIndent()
72 SfxItemSet
aAttrSet(GetAttrPool(), RES_LR_SPACE
, RES_LR_SPACE
);
75 SvxLRSpaceItem aItem
= (const SvxLRSpaceItem
&)aAttrSet
.Get(RES_LR_SPACE
);
76 short aOldFirstLineOfst
= aItem
.GetTxtFirstLineOfst();
78 if (aOldFirstLineOfst
> 0)
80 aItem
.SetTxtFirstLineOfst(0);
83 else if (aOldFirstLineOfst
< 0)
85 aItem
.SetTxtFirstLineOfst(0);
86 aItem
.SetLeft(aItem
.GetLeft() + aOldFirstLineOfst
);
90 else if (aItem
.GetLeft() != 0)
105 /*------------------------------------------------------------------------
106 Beschreibung: Zeile loeschen
107 ------------------------------------------------------------------------*/
111 long SwWrtShell::DelLine()
115 // alten Cursor merken
118 SwCrsrShell::LeftMargin();
120 SwCrsrShell::RightMargin();
121 //Warum soll hier noch ein Zeichen in der naechsten Zeile geloescht werden?
122 // if(!IsEndOfPara())
123 // SwCrsrShell::Right();
124 long nRet
= Delete();
133 long SwWrtShell::DelToStartOfLine()
136 SwCrsrShell::LeftMargin();
137 long nRet
= Delete();
138 CloseMark( 0 != nRet
);
144 long SwWrtShell::DelToEndOfLine()
147 SwCrsrShell::RightMargin();
148 long nRet
= Delete();
149 CloseMark( 0 != nRet
);
153 long SwWrtShell::DelLeft()
155 // wenns denn ein Fly ist, wech damit
156 int nSelType
= GetSelectionType();
157 const int nCmp
= nsSelectionType::SEL_FRM
| nsSelectionType::SEL_GRF
| nsSelectionType::SEL_OLE
| nsSelectionType::SEL_DRW
;
158 if( nCmp
& nSelType
)
160 /* #108205# Remember object's position. */
161 Point aTmpPt
= GetObjRect().TopLeft();
165 /* #108205# Set cursor to remembered position. */
171 nSelType
= GetSelectionType();
172 if ( nCmp
& nSelType
)
181 // wenn eine Selektion existiert, diese loeschen.
184 if( !IsBlockMode() || HasSelection() )
186 //OS: wieder einmal Basic: ACT_KONTEXT muss vor
187 //EnterStdMode verlassen werden!
208 // JP 29.06.95: nie eine davor stehende Tabelle loeschen.
210 const SwTableNode
* pWasInTblNd
= SwCrsrShell::IsCrsrInTbl();
212 if( SwCrsrShell::IsSttPara())
214 // --> FME 2007-02-15 #i4032# Don't actually call a 'delete' if we
215 // changed the table cell, compare DelRight().
216 const SwStartNode
* pSNdOld
= pWasInTblNd
?
217 GetSwCrsr()->GetNode()->FindTableBoxStartNode() :
221 /* If the cursor is at the beginning of a paragraph, try to step
222 backwards. On failure we are done. */
223 if( !SwCrsrShell::Left(1,CRSR_SKIP_CHARS
) )
226 /* If the cursor entered or left a table (or both) we are done. No step
228 const SwTableNode
* pIsInTblNd
= SwCrsrShell::IsCrsrInTbl();
229 if( pIsInTblNd
!= pWasInTblNd
)
232 const SwStartNode
* pSNdNew
= pIsInTblNd
?
233 GetSwCrsr()->GetNode()->FindTableBoxStartNode() :
236 // --> FME 2007-02-15 #i4032# Don't actually call a 'delete' if we
237 // changed the table cell, compare DelRight().
238 if ( pSNdOld
!= pSNdNew
)
243 SwCrsrShell::Right(1,CRSR_SKIP_CHARS
);
244 SwCrsrShell::SwapPam();
250 SwCrsrShell::Left(1,CRSR_SKIP_CHARS
);
252 long nRet
= Delete();
254 SwCrsrShell::SwapPam();
255 CloseMark( 0 != nRet
);
259 long SwWrtShell::DelRight()
261 // werden verodert, wenn Tabellenselektion vorliegt;
262 // wird hier auf nsSelectionType::SEL_TBL umgesetzt.
264 int nSelection
= GetSelectionType();
265 if(nSelection
& nsSelectionType::SEL_TBL_CELLS
)
266 nSelection
= nsSelectionType::SEL_TBL
;
267 if(nSelection
& nsSelectionType::SEL_TXT
)
268 nSelection
= nsSelectionType::SEL_TXT
;
270 const SwTableNode
* pWasInTblNd
= NULL
;
272 switch( nSelection
& ~(nsSelectionType::SEL_BEZ
) )
274 case nsSelectionType::SEL_POSTIT
:
275 case nsSelectionType::SEL_TXT
:
276 case nsSelectionType::SEL_TBL
:
277 case nsSelectionType::SEL_NUM
:
278 // wenn eine Selektion existiert, diese loeschen.
281 if( !IsBlockMode() || HasSelection() )
283 //OS: wieder einmal Basic: ACT_KONTEXT muss vor
284 //EnterStdMode verlassen werden!
306 pWasInTblNd
= IsCrsrInTbl();
308 if( nsSelectionType::SEL_TXT
& nSelection
&& SwCrsrShell::IsSttPara() &&
309 SwCrsrShell::IsEndPara() )
314 bool bDelFull
= false;
315 if ( SwCrsrShell::Right(1,CRSR_SKIP_CHARS
) )
317 const SwTableNode
* pCurrTblNd
= IsCrsrInTbl();
318 bDelFull
= pCurrTblNd
&& pCurrTblNd
!= pWasInTblNd
;
322 SwCrsrShell::Pop( FALSE
);
333 /* #108049# Save the startnode of the current cell */
334 const SwStartNode
* pSNdOld
;
335 pSNdOld
= GetSwCrsr()->GetNode()->
336 FindTableBoxStartNode();
338 if ( SwCrsrShell::IsEndPara() )
340 // --> FME 2005-01-28 #i41424# Introduced a couple of
341 // Push()-Pop() pairs here. The reason for this is that a
342 // Right()-Left() combination does not make sure, that
343 // the cursor will be in its initial state, because there
344 // may be a numbering in front of the next paragraph.
348 if ( SwCrsrShell::Right(1, CRSR_SKIP_CHARS
) )
350 if (IsCrsrInTbl() || (pWasInTblNd
!= IsCrsrInTbl()))
352 /* #108049# Save the startnode of the current
353 cell. May be different to pSNdOld as we have
355 const SwStartNode
* pSNdNew
= GetSwCrsr()
356 ->GetNode()->FindTableBoxStartNode();
358 /* #108049# Only move instead of deleting if we
359 have moved to a different cell */
360 if (pSNdOld
!= pSNdNew
)
362 SwCrsrShell::Pop( TRUE
);
369 SwCrsrShell::Pop( FALSE
);
374 SwCrsrShell::Right(1,CRSR_SKIP_CELLS
);
376 CloseMark( 0 != nRet
);
379 case nsSelectionType::SEL_FRM
:
380 case nsSelectionType::SEL_GRF
:
381 case nsSelectionType::SEL_OLE
:
382 case nsSelectionType::SEL_DRW
:
383 case nsSelectionType::SEL_DRW_TXT
:
384 case nsSelectionType::SEL_DRW_FORM
:
386 /* #108205# Remember object's position. */
387 Point aTmpPt
= GetObjRect().TopLeft();
391 /* #108205# Set cursor to remembered position. */
396 // --> OD 2006-07-06 #134369#
397 ASSERT( !IsFrmSelected(),
398 "<SwWrtShell::DelRight(..)> - <SwWrtShell::UnSelectFrm()> should unmark all objects" )
400 // --> OD 2006-07-10 #134369#
401 // leave draw mode, if necessary.
403 if (GetView().GetDrawFuncPtr())
405 GetView().GetDrawFuncPtr()->Deactivate();
406 GetView().SetDrawFuncPtr(NULL
);
408 if ( GetView().IsDrawMode() )
410 GetView().LeaveDrawCreate();
416 // --> OD 2006-07-07 #134369#
417 // <IsFrmSelected()> can't be true - see above.
420 nSelection
= GetSelectionType();
421 if ( nsSelectionType::SEL_FRM
& nSelection
||
422 nsSelectionType::SEL_GRF
& nSelection
||
423 nsSelectionType::SEL_OLE
& nSelection
||
424 nsSelectionType::SEL_DRW
& nSelection
)
438 long SwWrtShell::DelToEndOfPara()
444 if( !MovePara(fnParaCurr
,fnParaEnd
))
449 long nRet
= Delete();
458 long SwWrtShell::DelToStartOfPara()
464 if( !MovePara(fnParaCurr
,fnParaStart
))
469 long nRet
= Delete();
476 * alle Loeschoperationen sollten mit Find statt mit
477 * Nxt-/PrvDelim arbeiten, da letzteren mit Wrap Around arbeiten
478 * -- das ist wohl nicht gewuenscht.
483 long SwWrtShell::DelToStartOfSentence()
488 long nRet
= _BwdSentence() ? Delete() : 0;
489 CloseMark( 0 != nRet
);
495 long SwWrtShell::DelToEndOfSentence()
500 long nRet
= _FwdSentence() ? Delete() : 0;
501 CloseMark( 0 != nRet
);
507 long SwWrtShell::DelNxtWord()
515 if(IsEndWrd() && !IsSttWrd())
516 _NxtWrdForDelete(); // --> OD 2008-08-06 #i92468#
517 if(IsSttWrd() || IsEndPara())
518 _NxtWrdForDelete(); // --> OD 2008-08-06 #i92468#
522 long nRet
= Delete();
533 long SwWrtShell::DelPrvWord()
542 !_PrvWrdForDelete() ) // --> OD 2008-08-06 #i92468#
546 if ( _PrvWrdForDelete() ) // --> OD 2008-08-06 #i92468#
548 // skip over all-1 spaces
550 while( ' ' == GetChar( FALSE
, n
))
554 ExtendSelection( FALSE
, -n
);
557 else if( IsSttPara())
558 _PrvWrdForDelete(); // --> OD 2008-08-06 #i92468#
562 long nRet
= Delete();