diff options
Diffstat (limited to 'sw/source/core/edit/edundo.cxx')
-rw-r--r-- | sw/source/core/edit/edundo.cxx | 217 |
1 files changed, 98 insertions, 119 deletions
diff --git a/sw/source/core/edit/edundo.cxx b/sw/source/core/edit/edundo.cxx index 58bc6965c40b..f30db42a4460 100644 --- a/sw/source/core/edit/edundo.cxx +++ b/sw/source/core/edit/edundo.cxx @@ -28,18 +28,20 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sw.hxx" - #include <svx/svdview.hxx> + #include <editsh.hxx> #include <fesh.hxx> #include <doc.hxx> +#include <IDocumentUndoRedo.hxx> #include <pam.hxx> -#include <undobj.hxx> +#include <UndoCore.hxx> #include <swundo.hxx> #include <dcontact.hxx> #include <flyfrm.hxx> #include <frmfmt.hxx> #include <viewimp.hxx> +#include <docsh.hxx> /** helper function to select all objects in an SdrMarkList; @@ -47,16 +49,64 @@ void lcl_SelectSdrMarkList( SwEditShell* pShell, const SdrMarkList* pSdrMarkList ); +bool SwEditShell::CursorsLocked() const +{ + + return GetDoc()->GetDocShell()->GetModel()->hasControllersLocked(); +} + +void +SwEditShell::HandleUndoRedoContext(::sw::UndoRedoContext & rContext) +{ + // do nothing if somebody has locked controllers! + if (CursorsLocked()) + { + return; + } + + SwFrmFmt * pSelFmt(0); + SdrMarkList * pMarkList(0); + rContext.GetSelections(pSelFmt, pMarkList); + + if (pSelFmt) // select frame + { + if (RES_DRAWFRMFMT == pSelFmt->Which()) + { + SdrObject* pSObj = pSelFmt->FindSdrObject(); + static_cast<SwFEShell*>(this)->SelectObj( + pSObj->GetCurrentBoundRect().Center() ); + } + else + { + Point aPt; + SwFlyFrm *const pFly = + static_cast<SwFlyFrmFmt*>(pSelFmt)->GetFrm(& aPt, false); + if (pFly) + { + static_cast<SwFEShell*>(this)->SelectFlyFrm(*pFly, true); + } + } + } + else if (pMarkList) + { + lcl_SelectSdrMarkList( this, pMarkList ); + } + else if (GetCrsr()->GetNext() != GetCrsr()) + { + // current cursor is the last one: + // go around the ring, to the first cursor + GoNextCrsr(); + } +} -BOOL SwEditShell::Undo( SwUndoId nUndoId, USHORT nCnt ) +bool SwEditShell::Undo(sal_uInt16 const nCount) { SET_CURR_SHELL( this ); // #105332# current undo state was not saved - BOOL bRet = FALSE; - BOOL bSaveDoesUndo = GetDoc()->DoesUndo(); + ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo()); + sal_Bool bRet = sal_False; - GetDoc()->DoUndo( FALSE ); StartAllAction(); { // eigentlich muesste ja nur der aktuelle Cursor berarbeitet @@ -69,8 +119,9 @@ BOOL SwEditShell::Undo( SwUndoId nUndoId, USHORT nCnt ) // JP 02.04.98: Cursor merken - beim Auto-Format/-Korrektur // soll dieser wieder an die Position - SwUndoId nLastUndoId = GetDoc()->GetUndoIds(NULL, NULL); - BOOL bRestoreCrsr = 1 == nCnt && ( UNDO_AUTOFORMAT == nLastUndoId || + SwUndoId nLastUndoId(UNDO_EMPTY); + GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(0, & nLastUndoId); + bool bRestoreCrsr = 1 == nCount && (UNDO_AUTOFORMAT == nLastUndoId || UNDO_AUTOCORRECT == nLastUndoId ); Push(); @@ -80,51 +131,19 @@ BOOL SwEditShell::Undo( SwUndoId nUndoId, USHORT nCnt ) RedlineMode_t eOld = GetDoc()->GetRedlineMode(); - SwUndoIter aUndoIter( GetCrsr(), nUndoId ); - while( nCnt-- ) - { - do { - - bRet = GetDoc()->Undo( aUndoIter ) || bRet; - - if( !aUndoIter.IsNextUndo() ) - break; - - // es geht weiter, also erzeuge einen neuen Cursor wenn - // der alte schon eine Selection hat - // JP 02.04.98: aber nicht wenns ein Autoformat ist - if( !bRestoreCrsr && HasSelection() ) - { - CreateCrsr(); - aUndoIter.pAktPam = GetCrsr(); - } - } while( TRUE ); - } - - Pop( !bRestoreCrsr ); - - if( aUndoIter.pSelFmt ) // dann erzeuge eine Rahmen-Selection - { - if( RES_DRAWFRMFMT == aUndoIter.pSelFmt->Which() ) + try { + for (sal_uInt16 i = 0; i < nCount; ++i) { - SdrObject* pSObj = aUndoIter.pSelFmt->FindSdrObject(); - ((SwFEShell*)this)->SelectObj( pSObj->GetCurrentBoundRect().Center() ); + bRet = GetDoc()->GetIDocumentUndoRedo().Undo() + || bRet; } - else - { - Point aPt; - SwFlyFrm* pFly = ((SwFlyFrmFmt*)aUndoIter.pSelFmt)->GetFrm( - &aPt, FALSE ); - if( pFly ) - ((SwFEShell*)this)->SelectFlyFrm( *pFly, TRUE ); - } - } - else if( aUndoIter.pMarkList ) - { - lcl_SelectSdrMarkList( this, aUndoIter.pMarkList ); + } catch (::com::sun::star::uno::Exception & e) { + OSL_TRACE("SwEditShell::Undo(): exception caught:\n %s", + ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8) + .getStr()); } - else if( GetCrsr()->GetNext() != GetCrsr() ) // gehe nach einem - GoNextCrsr(); // Undo zur alten Undo-Position !! + + Pop( !bRestoreCrsr ); GetDoc()->SetRedlineMode( eOld ); GetDoc()->CompressRedlines(); @@ -134,21 +153,18 @@ BOOL SwEditShell::Undo( SwUndoId nUndoId, USHORT nCnt ) } EndAllAction(); - // #105332# undo state was not restored but set to FALSE everytime - GetDoc()->DoUndo( bSaveDoesUndo ); return bRet; } -USHORT SwEditShell::Redo( USHORT nCnt ) +bool SwEditShell::Redo(sal_uInt16 const nCount) { SET_CURR_SHELL( this ); - BOOL bRet = FALSE; + sal_Bool bRet = sal_False; // #105332# undo state was not saved - BOOL bSaveDoesUndo = GetDoc()->DoesUndo(); + ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo()); - GetDoc()->DoUndo( FALSE ); StartAllAction(); { @@ -166,51 +182,17 @@ USHORT SwEditShell::Redo( USHORT nCnt ) RedlineMode_t eOld = GetDoc()->GetRedlineMode(); - SwUndoIter aUndoIter( GetCrsr(), UNDO_EMPTY ); - while( nCnt-- ) - { - do { - - bRet = GetDoc()->Redo( aUndoIter ) || bRet; - - if( !aUndoIter.IsNextUndo() ) - break; - - // es geht weiter, also erzeugen einen neuen Cursor wenn - // der alte schon eine SSelection hat - if( HasSelection() ) - { - CreateCrsr(); - aUndoIter.pAktPam = GetCrsr(); - } - } while( TRUE ); - } - - if( aUndoIter.IsUpdateAttr() ) - UpdateAttr(); - - if( aUndoIter.pSelFmt ) // dann erzeuge eine Rahmen-Selection - { - if( RES_DRAWFRMFMT == aUndoIter.pSelFmt->Which() ) + try { + for (sal_uInt16 i = 0; i < nCount; ++i) { - SdrObject* pSObj = aUndoIter.pSelFmt->FindSdrObject(); - ((SwFEShell*)this)->SelectObj( pSObj->GetCurrentBoundRect().Center() ); + bRet = GetDoc()->GetIDocumentUndoRedo().Redo() + || bRet; } - else - { - Point aPt; - SwFlyFrm* pFly = ((SwFlyFrmFmt*)aUndoIter.pSelFmt)->GetFrm( - &aPt, FALSE ); - if( pFly ) - ((SwFEShell*)this)->SelectFlyFrm( *pFly, TRUE ); - } - } - else if( aUndoIter.pMarkList ) - { - lcl_SelectSdrMarkList( this, aUndoIter.pMarkList ); + } catch (::com::sun::star::uno::Exception & e) { + OSL_TRACE("SwEditShell::Redo(): exception caught:\n %s", + ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8) + .getStr()); } - else if( GetCrsr()->GetNext() != GetCrsr() ) // gehe nach einem - GoNextCrsr(); // Redo zur alten Undo-Position !! GetDoc()->SetRedlineMode( eOld ); GetDoc()->CompressRedlines(); @@ -221,41 +203,31 @@ USHORT SwEditShell::Redo( USHORT nCnt ) EndAllAction(); - // #105332# undo state was not restored but set FALSE everytime - GetDoc()->DoUndo( bSaveDoesUndo ); return bRet; } -USHORT SwEditShell::Repeat( USHORT nCount ) +bool SwEditShell::Repeat(sal_uInt16 const nCount) { SET_CURR_SHELL( this ); - BOOL bRet = FALSE; + sal_Bool bRet = sal_False; StartAllAction(); - SwUndoIter aUndoIter( GetCrsr(), UNDO_EMPTY ); - bRet = GetDoc()->Repeat( aUndoIter, nCount ) || bRet; + try { + ::sw::RepeatContext context(*GetDoc(), *GetCrsr()); + bRet = GetDoc()->GetIDocumentUndoRedo().Repeat( context, nCount ) + || bRet; + } catch (::com::sun::star::uno::Exception & e) { + OSL_TRACE("SwEditShell::Repeat(): exception caught:\n %s", + ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8) + .getStr()); + } EndAllAction(); return bRet; } - // abfragen/setzen der Anzahl von wiederherstellbaren Undo-Actions - -USHORT SwEditShell::GetUndoActionCount() -{ - return SwDoc::GetUndoActionCount(); -} - - -void SwEditShell::SetUndoActionCount( USHORT nNew ) -{ - SwDoc::SetUndoActionCount( nNew ); -} - - - void lcl_SelectSdrMarkList( SwEditShell* pShell, const SdrMarkList* pSdrMarkList ) @@ -266,6 +238,7 @@ void lcl_SelectSdrMarkList( SwEditShell* pShell, if( pShell->ISA( SwFEShell ) ) { SwFEShell* pFEShell = static_cast<SwFEShell*>( pShell ); +<<<<<<< local bool bFirst = true; for( USHORT i = 0; i < pSdrMarkList->GetMarkCount(); ++i ) { @@ -276,6 +249,12 @@ void lcl_SelectSdrMarkList( SwEditShell* pShell, bFirst = false; } } +======= + for( sal_uInt16 i = 0; i < pSdrMarkList->GetMarkCount(); ++i ) + pFEShell->SelectObj( Point(), + (i==0) ? 0 : SW_ADD_SELECT, + pSdrMarkList->GetMark( i )->GetMarkedSdrObj() ); +>>>>>>> other // the old implementation would always unselect // objects, even if no new ones were selected. If this |