Update ooo320-m1
[ooovba.git] / sw / source / ui / wrtsh / delete.cxx
blobba283bf95a893fc917e9f7b36da6dd3e8c977259
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 $
10 * $Revision: 1.22 $
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"
35 #include <wrtsh.hxx>
36 #include <crsskip.hxx>
37 #include <swcrsr.hxx>
38 #include <svx/lrspitem.hxx> // #i23725#
39 // --> OD 2006-07-10 #134369#
40 #ifndef _VIEW_HXX
41 #include <view.hxx>
42 #endif
43 #ifndef _DRAWBASE_HXX
44 #include <drawbase.hxx>
45 #endif
46 // <--
48 inline void SwWrtShell::OpenMark()
50 StartAllAction();
51 ResetCursorStack();
52 KillPams();
53 SetMark();
56 inline void SwWrtShell::CloseMark( BOOL bOkFlag )
58 if( bOkFlag )
59 UpdateAttr();
60 else
61 SwapPam();
63 ClearMark();
64 EndAllAction();
67 // #i23725#
68 BOOL SwWrtShell::TryRemoveIndent()
70 BOOL bResult = FALSE;
72 SfxItemSet aAttrSet(GetAttrPool(), RES_LR_SPACE, RES_LR_SPACE);
73 GetCurAttr(aAttrSet);
75 SvxLRSpaceItem aItem = (const SvxLRSpaceItem &)aAttrSet.Get(RES_LR_SPACE);
76 short aOldFirstLineOfst = aItem.GetTxtFirstLineOfst();
78 if (aOldFirstLineOfst > 0)
80 aItem.SetTxtFirstLineOfst(0);
81 bResult = TRUE;
83 else if (aOldFirstLineOfst < 0)
85 aItem.SetTxtFirstLineOfst(0);
86 aItem.SetLeft(aItem.GetLeft() + aOldFirstLineOfst);
88 bResult = TRUE;
90 else if (aItem.GetLeft() != 0)
92 aItem.SetLeft(0);
93 bResult = TRUE;
96 if (bResult)
98 aAttrSet.Put(aItem);
99 SetAttr(aAttrSet);
102 return bResult;
105 /*------------------------------------------------------------------------
106 Beschreibung: Zeile loeschen
107 ------------------------------------------------------------------------*/
111 long SwWrtShell::DelLine()
113 ACT_KONTEXT(this);
114 ResetCursorStack();
115 // alten Cursor merken
116 Push();
117 ClearMark();
118 SwCrsrShell::LeftMargin();
119 SetMark();
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();
125 Pop(FALSE);
126 if( nRet )
127 UpdateAttr();
128 return nRet;
133 long SwWrtShell::DelToStartOfLine()
135 OpenMark();
136 SwCrsrShell::LeftMargin();
137 long nRet = Delete();
138 CloseMark( 0 != nRet );
139 return nRet;
144 long SwWrtShell::DelToEndOfLine()
146 OpenMark();
147 SwCrsrShell::RightMargin();
148 long nRet = Delete();
149 CloseMark( 0 != nRet );
150 return 1;
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();
163 DelSelectedObj();
165 /* #108205# Set cursor to remembered position. */
166 SetCrsr(&aTmpPt);
168 LeaveSelFrmMode();
169 UnSelectFrm();
171 nSelType = GetSelectionType();
172 if ( nCmp & nSelType )
174 EnterSelFrmMode();
175 GotoNextFly();
178 return 1L;
181 // wenn eine Selektion existiert, diese loeschen.
182 if ( IsSelection() )
184 if( !IsBlockMode() || HasSelection() )
186 //OS: wieder einmal Basic: ACT_KONTEXT muss vor
187 //EnterStdMode verlassen werden!
189 ACT_KONTEXT(this);
190 ResetCursorStack();
191 Delete();
192 UpdateAttr();
194 if( IsBlockMode() )
196 NormalizePam();
197 ClearMark();
198 EnterBlockMode();
200 else
201 EnterStdMode();
202 return 1L;
204 else
205 EnterStdMode();
208 // JP 29.06.95: nie eine davor stehende Tabelle loeschen.
209 BOOL bSwap = FALSE;
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() :
219 // <--
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) )
224 return 0;
226 /* If the cursor entered or left a table (or both) we are done. No step
227 back. */
228 const SwTableNode* pIsInTblNd = SwCrsrShell::IsCrsrInTbl();
229 if( pIsInTblNd != pWasInTblNd )
230 return 0;
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 )
239 return 0;
240 // <--
242 OpenMark();
243 SwCrsrShell::Right(1,CRSR_SKIP_CHARS);
244 SwCrsrShell::SwapPam();
245 bSwap = TRUE;
247 else
249 OpenMark();
250 SwCrsrShell::Left(1,CRSR_SKIP_CHARS);
252 long nRet = Delete();
253 if( !nRet && bSwap )
254 SwCrsrShell::SwapPam();
255 CloseMark( 0 != nRet );
256 return nRet;
259 long SwWrtShell::DelRight()
261 // werden verodert, wenn Tabellenselektion vorliegt;
262 // wird hier auf nsSelectionType::SEL_TBL umgesetzt.
263 long nRet = 0;
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.
279 if( IsSelection() )
281 if( !IsBlockMode() || HasSelection() )
283 //OS: wieder einmal Basic: ACT_KONTEXT muss vor
284 //EnterStdMode verlassen werden!
286 ACT_KONTEXT(this);
287 ResetCursorStack();
288 Delete();
289 UpdateAttr();
291 if( IsBlockMode() )
293 NormalizePam();
294 ClearMark();
295 EnterBlockMode();
297 else
298 EnterStdMode();
299 nRet = 1L;
300 break;
302 else
303 EnterStdMode();
306 pWasInTblNd = IsCrsrInTbl();
308 if( nsSelectionType::SEL_TXT & nSelection && SwCrsrShell::IsSttPara() &&
309 SwCrsrShell::IsEndPara() )
311 // save cursor
312 SwCrsrShell::Push();
314 bool bDelFull = false;
315 if ( SwCrsrShell::Right(1,CRSR_SKIP_CHARS) )
317 const SwTableNode * pCurrTblNd = IsCrsrInTbl();
318 bDelFull = pCurrTblNd && pCurrTblNd != pWasInTblNd;
321 // restore cursor
322 SwCrsrShell::Pop( FALSE );
324 if( bDelFull )
326 DelFullPara();
327 UpdateAttr();
328 break;
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.
345 SwCrsrShell::Push();
346 // <--
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
354 moved. */
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 );
363 break;
368 // restore cursor
369 SwCrsrShell::Pop( FALSE );
373 OpenMark();
374 SwCrsrShell::Right(1,CRSR_SKIP_CELLS);
375 nRet = Delete();
376 CloseMark( 0 != nRet );
377 break;
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();
389 DelSelectedObj();
391 /* #108205# Set cursor to remembered position. */
392 SetCrsr(&aTmpPt);
394 LeaveSelFrmMode();
395 UnSelectFrm();
396 // --> OD 2006-07-06 #134369#
397 ASSERT( !IsFrmSelected(),
398 "<SwWrtShell::DelRight(..)> - <SwWrtShell::UnSelectFrm()> should unmark all objects" )
399 // <--
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();
413 // <--
416 // --> OD 2006-07-07 #134369#
417 // <IsFrmSelected()> can't be true - see above.
418 // <--
420 nSelection = GetSelectionType();
421 if ( nsSelectionType::SEL_FRM & nSelection ||
422 nsSelectionType::SEL_GRF & nSelection ||
423 nsSelectionType::SEL_OLE & nSelection ||
424 nsSelectionType::SEL_DRW & nSelection )
426 EnterSelFrmMode();
427 GotoNextFly();
430 nRet = 1;
431 break;
433 return nRet;
438 long SwWrtShell::DelToEndOfPara()
440 ACT_KONTEXT(this);
441 ResetCursorStack();
442 Push();
443 SetMark();
444 if( !MovePara(fnParaCurr,fnParaEnd))
446 Pop(FALSE);
447 return 0;
449 long nRet = Delete();
450 Pop(FALSE);
451 if( nRet )
452 UpdateAttr();
453 return nRet;
458 long SwWrtShell::DelToStartOfPara()
460 ACT_KONTEXT(this);
461 ResetCursorStack();
462 Push();
463 SetMark();
464 if( !MovePara(fnParaCurr,fnParaStart))
466 Pop(FALSE);
467 return 0;
469 long nRet = Delete();
470 Pop(FALSE);
471 if( nRet )
472 UpdateAttr();
473 return nRet;
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()
485 if(IsStartOfDoc())
486 return 0;
487 OpenMark();
488 long nRet = _BwdSentence() ? Delete() : 0;
489 CloseMark( 0 != nRet );
490 return nRet;
495 long SwWrtShell::DelToEndOfSentence()
497 if(IsEndOfDoc())
498 return 0;
499 OpenMark();
500 long nRet = _FwdSentence() ? Delete() : 0;
501 CloseMark( 0 != nRet );
502 return nRet;
507 long SwWrtShell::DelNxtWord()
509 if(IsEndOfDoc())
510 return 0;
511 ACT_KONTEXT(this);
512 ResetCursorStack();
513 EnterStdMode();
514 SetMark();
515 if(IsEndWrd() && !IsSttWrd())
516 _NxtWrdForDelete(); // --> OD 2008-08-06 #i92468#
517 if(IsSttWrd() || IsEndPara())
518 _NxtWrdForDelete(); // --> OD 2008-08-06 #i92468#
519 else
520 _EndWrd();
522 long nRet = Delete();
523 if( nRet )
524 UpdateAttr();
525 else
526 SwapPam();
527 ClearMark();
528 return nRet;
533 long SwWrtShell::DelPrvWord()
535 if(IsStartOfDoc())
536 return 0;
537 ACT_KONTEXT(this);
538 ResetCursorStack();
539 EnterStdMode();
540 SetMark();
541 if ( !IsSttWrd() ||
542 !_PrvWrdForDelete() ) // --> OD 2008-08-06 #i92468#
544 if( IsEndWrd() )
546 if ( _PrvWrdForDelete() ) // --> OD 2008-08-06 #i92468#
548 // skip over all-1 spaces
549 short n = -1;
550 while( ' ' == GetChar( FALSE, n ))
551 --n;
553 if( ++n )
554 ExtendSelection( FALSE, -n );
557 else if( IsSttPara())
558 _PrvWrdForDelete(); // --> OD 2008-08-06 #i92468#
559 else
560 _SttWrd();
562 long nRet = Delete();
563 if( nRet )
564 UpdateAttr();
565 else
566 SwapPam();
567 ClearMark();
568 return nRet;