Files
libreoffice/sw/source/ui/wrtsh/delete.cxx

556 lines
14 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-09-18 16:15:01 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 16:15:01 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-09-18 16:15:01 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 16:15:01 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 16:15:01 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 16:15:01 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 16:15:01 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 16:15:01 +00:00
*
************************************************************************/
#include <wrtsh.hxx>
#include <crsskip.hxx>
#include <swcrsr.hxx>
#include <editeng/lrspitem.hxx> // #i23725#
2011-04-18 12:37:38 -03:00
// #134369#
#include <view.hxx>
#include <drawbase.hxx>
2000-09-18 16:15:01 +00:00
inline void SwWrtShell::OpenMark()
{
StartAllAction();
ResetCursorStack();
KillPams();
SetMark();
}
inline void SwWrtShell::CloseMark( sal_Bool bOkFlag )
2000-09-18 16:15:01 +00:00
{
if( bOkFlag )
UpdateAttr();
else
SwapPam();
ClearMark();
EndAllAction();
}
// #i23725#
sal_Bool SwWrtShell::TryRemoveIndent()
{
sal_Bool bResult = sal_False;
SfxItemSet aAttrSet(GetAttrPool(), RES_LR_SPACE, RES_LR_SPACE);
GetCurAttr(aAttrSet);
SvxLRSpaceItem aItem = (const SvxLRSpaceItem &)aAttrSet.Get(RES_LR_SPACE);
short aOldFirstLineOfst = aItem.GetTxtFirstLineOfst();
if (aOldFirstLineOfst > 0)
{
aItem.SetTxtFirstLineOfst(0);
bResult = sal_True;
}
else if (aOldFirstLineOfst < 0)
{
aItem.SetTxtFirstLineOfst(0);
aItem.SetLeft(aItem.GetLeft() + aOldFirstLineOfst);
bResult = sal_True;
}
else if (aItem.GetLeft() != 0)
{
aItem.SetLeft(0);
bResult = sal_True;
}
if (bResult)
{
aAttrSet.Put(aItem);
SetAttr(aAttrSet);
}
return bResult;
}
2000-09-18 16:15:01 +00:00
/*------------------------------------------------------------------------
Beschreibung: Zeile loeschen
------------------------------------------------------------------------*/
long SwWrtShell::DelLine()
{
SwActContext aActContext(this);
2000-09-18 16:15:01 +00:00
ResetCursorStack();
// alten Cursor merken
Push();
ClearMark();
SwCrsrShell::LeftMargin();
SetMark();
SwCrsrShell::RightMargin();
2010-11-30 16:44:46 +01:00
2000-09-18 16:15:01 +00:00
long nRet = Delete();
Pop(sal_False);
2000-09-18 16:15:01 +00:00
if( nRet )
UpdateAttr();
return nRet;
}
long SwWrtShell::DelToStartOfLine()
{
OpenMark();
SwCrsrShell::LeftMargin();
long nRet = Delete();
CloseMark( 0 != nRet );
return nRet;
}
long SwWrtShell::DelToEndOfLine()
{
OpenMark();
SwCrsrShell::RightMargin();
long nRet = Delete();
CloseMark( 0 != nRet );
return 1;
}
long SwWrtShell::DelLeft()
{
// wenns denn ein Fly ist, wech damit
int nSelType = GetSelectionType();
const int nCmp = nsSelectionType::SEL_FRM | nsSelectionType::SEL_GRF | nsSelectionType::SEL_OLE | nsSelectionType::SEL_DRW;
2000-09-18 16:15:01 +00:00
if( nCmp & nSelType )
{
/* #108205# Remember object's position. */
Point aTmpPt = GetObjRect().TopLeft();
2000-09-18 16:15:01 +00:00
DelSelectedObj();
/* #108205# Set cursor to remembered position. */
SetCrsr(&aTmpPt);
2000-09-18 16:15:01 +00:00
LeaveSelFrmMode();
UnSelectFrm();
2000-09-18 16:15:01 +00:00
nSelType = GetSelectionType();
if ( nCmp & nSelType )
{
EnterSelFrmMode();
GotoNextFly();
}
2000-09-18 16:15:01 +00:00
return 1L;
}
// wenn eine Selektion existiert, diese loeschen.
if ( IsSelection() )
{
if( !IsBlockMode() || HasSelection() )
2000-09-18 16:15:01 +00:00
{
//OS: wieder einmal Basic: SwActContext muss vor
//EnterStdMode verlassen werden!
{
SwActContext aActContext(this);
ResetCursorStack();
Delete();
UpdateAttr();
}
if( IsBlockMode() )
{
NormalizePam();
ClearMark();
EnterBlockMode();
}
else
EnterStdMode();
return 1L;
2000-09-18 16:15:01 +00:00
}
else
EnterStdMode();
2000-09-18 16:15:01 +00:00
}
// JP 29.06.95: nie eine davor stehende Tabelle loeschen.
sal_Bool bSwap = sal_False;
const SwTableNode * pWasInTblNd = SwCrsrShell::IsCrsrInTbl();
if( SwCrsrShell::IsSttPara())
2000-09-18 16:15:01 +00:00
{
// #i4032# Don't actually call a 'delete' if we
// changed the table cell, compare DelRight().
const SwStartNode * pSNdOld = pWasInTblNd ?
GetSwCrsr()->GetNode()->FindTableBoxStartNode() :
0;
/* If the cursor is at the beginning of a paragraph, try to step
backwards. On failure we are done. */
if( !SwCrsrShell::Left(1,CRSR_SKIP_CHARS) )
2000-09-18 16:15:01 +00:00
return 0;
/* If the cursor entered or left a table (or both) we are done. No step
back. */
const SwTableNode* pIsInTblNd = SwCrsrShell::IsCrsrInTbl();
if( pIsInTblNd != pWasInTblNd )
return 0;
const SwStartNode* pSNdNew = pIsInTblNd ?
GetSwCrsr()->GetNode()->FindTableBoxStartNode() :
0;
// #i4032# Don't actually call a 'delete' if we
// changed the table cell, compare DelRight().
if ( pSNdOld != pSNdNew )
2000-09-18 16:15:01 +00:00
return 0;
2000-09-18 16:15:01 +00:00
OpenMark();
SwCrsrShell::Right(1,CRSR_SKIP_CHARS);
2000-09-18 16:15:01 +00:00
SwCrsrShell::SwapPam();
bSwap = sal_True;
2000-09-18 16:15:01 +00:00
}
else
{
OpenMark();
SwCrsrShell::Left(1,CRSR_SKIP_CHARS);
2000-09-18 16:15:01 +00:00
}
long nRet = Delete();
if( !nRet && bSwap )
SwCrsrShell::SwapPam();
CloseMark( 0 != nRet );
return nRet;
}
long SwWrtShell::DelRight()
2000-09-18 16:15:01 +00:00
{
// werden verodert, wenn Tabellenselektion vorliegt;
// wird hier auf nsSelectionType::SEL_TBL umgesetzt.
2000-09-18 16:15:01 +00:00
long nRet = 0;
int nSelection = GetSelectionType();
if(nSelection & nsSelectionType::SEL_TBL_CELLS)
nSelection = nsSelectionType::SEL_TBL;
if(nSelection & nsSelectionType::SEL_TXT)
nSelection = nsSelectionType::SEL_TXT;
const SwTableNode * pWasInTblNd = NULL;
switch( nSelection & ~(nsSelectionType::SEL_BEZ) )
2000-09-18 16:15:01 +00:00
{
case nsSelectionType::SEL_POSTIT:
case nsSelectionType::SEL_TXT:
case nsSelectionType::SEL_TBL:
case nsSelectionType::SEL_NUM:
2000-09-18 16:15:01 +00:00
// wenn eine Selektion existiert, diese loeschen.
if( IsSelection() )
{
if( !IsBlockMode() || HasSelection() )
2000-09-18 16:15:01 +00:00
{
//OS: wieder einmal Basic: SwActContext muss vor
//EnterStdMode verlassen werden!
{
SwActContext aActContext(this);
ResetCursorStack();
Delete();
UpdateAttr();
}
if( IsBlockMode() )
{
NormalizePam();
ClearMark();
EnterBlockMode();
}
else
EnterStdMode();
nRet = 1L;
break;
2000-09-18 16:15:01 +00:00
}
else
EnterStdMode();
2000-09-18 16:15:01 +00:00
}
pWasInTblNd = IsCrsrInTbl();
if( nsSelectionType::SEL_TXT & nSelection && SwCrsrShell::IsSttPara() &&
SwCrsrShell::IsEndPara() )
2000-09-18 16:15:01 +00:00
{
// save cursor
SwCrsrShell::Push();
bool bDelFull = false;
if ( SwCrsrShell::Right(1,CRSR_SKIP_CHARS) )
{
const SwTableNode * pCurrTblNd = IsCrsrInTbl();
bDelFull = pCurrTblNd && pCurrTblNd != pWasInTblNd;
}
// restore cursor
SwCrsrShell::Pop( sal_False );
2000-09-18 16:15:01 +00:00
if( bDelFull )
{
DelFullPara();
UpdateAttr();
break;
}
}
{
/* #108049# Save the startnode of the current cell */
const SwStartNode * pSNdOld;
pSNdOld = GetSwCrsr()->GetNode()->
FindTableBoxStartNode();
if ( SwCrsrShell::IsEndPara() )
{
// #i41424# Introduced a couple of
// Push()-Pop() pairs here. The reason for this is that a
// Right()-Left() combination does not make sure, that
// the cursor will be in its initial state, because there
// may be a numbering in front of the next paragraph.
SwCrsrShell::Push();
if ( SwCrsrShell::Right(1, CRSR_SKIP_CHARS) )
{
if (IsCrsrInTbl() || (pWasInTblNd != IsCrsrInTbl()))
{
/* #108049# Save the startnode of the current
cell. May be different to pSNdOld as we have
moved. */
const SwStartNode * pSNdNew = GetSwCrsr()
->GetNode()->FindTableBoxStartNode();
/* #108049# Only move instead of deleting if we
have moved to a different cell */
if (pSNdOld != pSNdNew)
{
SwCrsrShell::Pop( sal_True );
break;
}
}
}
// restore cursor
SwCrsrShell::Pop( sal_False );
}
}
2000-09-18 16:15:01 +00:00
OpenMark();
SwCrsrShell::Right(1,CRSR_SKIP_CELLS);
2000-09-18 16:15:01 +00:00
nRet = Delete();
CloseMark( 0 != nRet );
break;
case nsSelectionType::SEL_FRM:
case nsSelectionType::SEL_GRF:
case nsSelectionType::SEL_OLE:
case nsSelectionType::SEL_DRW:
case nsSelectionType::SEL_DRW_TXT:
case nsSelectionType::SEL_DRW_FORM:
{
/* #108205# Remember object's position. */
Point aTmpPt = GetObjRect().TopLeft();
DelSelectedObj();
/* #108205# Set cursor to remembered position. */
SetCrsr(&aTmpPt);
LeaveSelFrmMode();
UnSelectFrm();
2011-04-18 12:37:38 -03:00
// #134369#
OSL_ENSURE( !IsFrmSelected(),
"<SwWrtShell::DelRight(..)> - <SwWrtShell::UnSelectFrm()> should unmark all objects" );
2011-04-18 12:37:38 -03:00
// #134369#
// leave draw mode, if necessary.
{
if (GetView().GetDrawFuncPtr())
{
GetView().GetDrawFuncPtr()->Deactivate();
GetView().SetDrawFuncPtr(NULL);
}
if ( GetView().IsDrawMode() )
{
GetView().LeaveDrawCreate();
}
}
}
2000-09-18 16:15:01 +00:00
2011-04-18 12:37:38 -03:00
// #134369#
// <IsFrmSelected()> can't be true - see above.
2000-09-18 16:15:01 +00:00
{
nSelection = GetSelectionType();
if ( nsSelectionType::SEL_FRM & nSelection ||
nsSelectionType::SEL_GRF & nSelection ||
nsSelectionType::SEL_OLE & nSelection ||
nsSelectionType::SEL_DRW & nSelection )
2000-09-18 16:15:01 +00:00
{
EnterSelFrmMode();
GotoNextFly();
}
}
nRet = 1;
break;
}
return nRet;
}
long SwWrtShell::DelToEndOfPara()
{
SwActContext aActContext(this);
2000-09-18 16:15:01 +00:00
ResetCursorStack();
Push();
SetMark();
if( !MovePara(fnParaCurr,fnParaEnd))
{
Pop(sal_False);
2000-09-18 16:15:01 +00:00
return 0;
}
long nRet = Delete();
Pop(sal_False);
2000-09-18 16:15:01 +00:00
if( nRet )
UpdateAttr();
return nRet;
}
long SwWrtShell::DelToStartOfPara()
{
SwActContext aActContext(this);
2000-09-18 16:15:01 +00:00
ResetCursorStack();
Push();
SetMark();
if( !MovePara(fnParaCurr,fnParaStart))
{
Pop(sal_False);
2000-09-18 16:15:01 +00:00
return 0;
}
long nRet = Delete();
Pop(sal_False);
2000-09-18 16:15:01 +00:00
if( nRet )
UpdateAttr();
return nRet;
}
/*
* alle Loeschoperationen sollten mit Find statt mit
* Nxt-/PrvDelim arbeiten, da letzteren mit Wrap Around arbeiten
* -- das ist wohl nicht gewuenscht.
*/
long SwWrtShell::DelToStartOfSentence()
{
if(IsStartOfDoc())
return 0;
OpenMark();
long nRet = _BwdSentence() ? Delete() : 0;
CloseMark( 0 != nRet );
return nRet;
}
long SwWrtShell::DelToEndOfSentence()
{
if(IsEndOfDoc())
return 0;
OpenMark();
long nRet = _FwdSentence() ? Delete() : 0;
CloseMark( 0 != nRet );
return nRet;
}
long SwWrtShell::DelNxtWord()
{
if(IsEndOfDoc())
return 0;
SwActContext aActContext(this);
2000-09-18 16:15:01 +00:00
ResetCursorStack();
EnterStdMode();
SetMark();
if(IsEndWrd() && !IsSttWrd())
_NxtWrdForDelete(); // #i92468#
2000-09-18 16:15:01 +00:00
if(IsSttWrd() || IsEndPara())
_NxtWrdForDelete(); // #i92468#
2000-09-18 16:15:01 +00:00
else
_EndWrd();
long nRet = Delete();
if( nRet )
UpdateAttr();
else
SwapPam();
ClearMark();
return nRet;
}
long SwWrtShell::DelPrvWord()
{
if(IsStartOfDoc())
return 0;
SwActContext aActContext(this);
2000-09-18 16:15:01 +00:00
ResetCursorStack();
EnterStdMode();
SetMark();
if ( !IsSttWrd() ||
!_PrvWrdForDelete() ) // #i92468#
2000-09-18 16:15:01 +00:00
{
if( IsEndWrd() )
{
if ( _PrvWrdForDelete() ) // #i92468#
2000-09-18 16:15:01 +00:00
{
// skip over all-1 spaces
short n = -1;
while( ' ' == GetChar( sal_False, n ))
2000-09-18 16:15:01 +00:00
--n;
if( ++n )
ExtendSelection( sal_False, -n );
2000-09-18 16:15:01 +00:00
}
}
else if( IsSttPara())
_PrvWrdForDelete(); // #i92468#
2000-09-18 16:15:01 +00:00
else
_SttWrd();
}
long nRet = Delete();
if( nRet )
UpdateAttr();
else
SwapPam();
ClearMark();
return nRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */