diff options
Diffstat (limited to 'editeng/source/editeng/editundo.cxx')
-rw-r--r-- | editeng/source/editeng/editundo.cxx | 156 |
1 files changed, 70 insertions, 86 deletions
diff --git a/editeng/source/editeng/editundo.cxx b/editeng/source/editeng/editundo.cxx index dc9c3a104b6c..e6678e78f681 100644 --- a/editeng/source/editeng/editundo.cxx +++ b/editeng/source/editeng/editundo.cxx @@ -22,16 +22,17 @@ #include "editundo.hxx" #include <editeng/editview.hxx> #include <editeng/editeng.hxx> +#include <utility> #include <osl/diagnose.h> static void lcl_DoSetSelection( EditView const * pView, sal_uInt16 nPara ) { EPaM aEPaM( nPara, 0 ); - EditPaM aPaM( pView->GetImpEditEngine()->CreateEditPaM( aEPaM ) ); + EditPaM aPaM = pView->getImpEditEngine().CreateEditPaM(aEPaM); aPaM.SetIndex( aPaM.GetNode()->Len() ); EditSelection aSel( aPaM, aPaM ); - pView->GetImpEditView()->SetEditSelection( aSel ); + pView->getImpl().SetEditSelection( aSel ); } EditUndoManager::EditUndoManager(sal_uInt16 nMaxUndoActionCount ) @@ -63,18 +64,18 @@ bool EditUndoManager::Undo() } } - mpEditEngine->GetActiveView()->GetImpEditView()->DrawSelectionXOR(); // Remove the old selection + mpEditEngine->GetActiveView()->getImpl().DrawSelectionXOR(); // Remove the old selection mpEditEngine->SetUndoMode( true ); bool bDone = SfxUndoManager::Undo(); mpEditEngine->SetUndoMode( false ); - EditSelection aNewSel( mpEditEngine->GetActiveView()->GetImpEditView()->GetEditSelection() ); + EditSelection aNewSel( mpEditEngine->GetActiveView()->getImpl().GetEditSelection() ); DBG_ASSERT( !aNewSel.IsInvalid(), "Invalid selection after Undo () "); DBG_ASSERT( !aNewSel.DbgIsBuggy( mpEditEngine->GetEditDoc() ), "Broken selection afte Undo () "); aNewSel.Min() = aNewSel.Max(); - mpEditEngine->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel ); + mpEditEngine->GetActiveView()->getImpl().SetEditSelection( aNewSel ); if (mpEditEngine->IsUpdateLayout()) mpEditEngine->FormatAndLayout( mpEditEngine->GetActiveView(), true ); @@ -99,18 +100,18 @@ bool EditUndoManager::Redo() } } - mpEditEngine->GetActiveView()->GetImpEditView()->DrawSelectionXOR(); // Remove the old selection + mpEditEngine->GetActiveView()->getImpl().DrawSelectionXOR(); // Remove the old selection mpEditEngine->SetUndoMode( true ); bool bDone = SfxUndoManager::Redo(); mpEditEngine->SetUndoMode( false ); - EditSelection aNewSel( mpEditEngine->GetActiveView()->GetImpEditView()->GetEditSelection() ); + EditSelection aNewSel( mpEditEngine->GetActiveView()->getImpl().GetEditSelection() ); DBG_ASSERT( !aNewSel.IsInvalid(), "Invalid selection after Undo () "); DBG_ASSERT( !aNewSel.DbgIsBuggy( mpEditEngine->GetEditDoc() ), "Broken selection afte Undo () "); aNewSel.Min() = aNewSel.Max(); - mpEditEngine->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel ); + mpEditEngine->GetActiveView()->getImpl().SetEditSelection( aNewSel ); if (mpEditEngine->IsUpdateLayout()) mpEditEngine->FormatAndLayout( mpEditEngine->GetActiveView() ); @@ -121,7 +122,7 @@ EditUndo::EditUndo(sal_uInt16 nI, EditEngine* pEE) : nId(nI), mnViewShellId(-1), mpEditEngine(pEE) { const EditView* pEditView = mpEditEngine ? mpEditEngine->GetActiveView() : nullptr; - const OutlinerViewShell* pViewShell = pEditView ? pEditView->GetImpEditView()->GetViewShell() : nullptr; + const OutlinerViewShell* pViewShell = pEditView ? pEditView->getImpl().GetViewShell() : nullptr; if (pViewShell) mnViewShellId = pViewShell->GetViewShellId(); } @@ -156,26 +157,23 @@ ViewShellId EditUndo::GetViewShellId() const return mnViewShellId; } -EditUndoDelContent::EditUndoDelContent( - EditEngine* pEE, ContentNode* pNode, sal_Int32 nPortion) : - EditUndo(EDITUNDO_DELCONTENT, pEE), - bDelObject(true), - nNode(nPortion), - pContentNode(pNode) {} +EditUndoDelContent::EditUndoDelContent(EditEngine* pEE, std::unique_ptr<ContentNode> pNode, sal_Int32 nPortion) + : EditUndo(EDITUNDO_DELCONTENT, pEE) + , nNode(nPortion) + , mpContentNode(std::move(pNode)) +{} EditUndoDelContent::~EditUndoDelContent() { - if ( bDelObject ) - delete pContentNode; } void EditUndoDelContent::Undo() { DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" ); - GetEditEngine()->InsertContent( pContentNode, nNode ); - bDelObject = false; // belongs to the Engine again - EditSelection aSel( EditPaM( pContentNode, 0 ), EditPaM( pContentNode, pContentNode->Len() ) ); - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aSel); + ContentNode* pNode = mpContentNode.get(); + GetEditEngine()->InsertContent(std::move(mpContentNode), nNode); + EditSelection aSel(EditPaM(pNode, 0), EditPaM(pNode, pNode->Len())); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection(aSel); } void EditUndoDelContent::Redo() @@ -186,40 +184,44 @@ void EditUndoDelContent::Redo() // pNode is no longer correct, if the paragraphs where merged // in between Undos - pContentNode = pEE->GetEditDoc().GetObject( nNode ); - DBG_ASSERT( pContentNode, "EditUndoDelContent::Redo(): Node?!" ); + ContentNode* pNode = pEE->GetEditDoc().GetObject(nNode); + DBG_ASSERT(pNode, "EditUndoDelContent::Redo(): Node?!"); pEE->RemoveParaPortion(nNode); // Do not delete node, depends on the undo! - pEE->GetEditDoc().Release( nNode ); + mpContentNode = pEE->GetEditDoc().Release(nNode); + assert(mpContentNode.get() == pNode); + if (pEE->IsCallParaInsertedOrDeleted()) - pEE->ParagraphDeleted( nNode ); + pEE->ParagraphDeleted(nNode); - DeletedNodeInfo* pInf = new DeletedNodeInfo( pContentNode, nNode ); - pEE->AppendDeletedNodeInfo(pInf); + DeletedNodeInfo* pDeletedNodeInfo = new DeletedNodeInfo(pNode, nNode); + pEE->AppendDeletedNodeInfo(pDeletedNodeInfo); pEE->UpdateSelections(); - ContentNode* pN = ( nNode < pEE->GetEditDoc().Count() ) - ? pEE->GetEditDoc().GetObject( nNode ) - : pEE->GetEditDoc().GetObject( nNode-1 ); - DBG_ASSERT( pN && ( pN != pContentNode ), "?! RemoveContent !? " ); - EditPaM aPaM( pN, pN->Len() ); + ContentNode* pCheckNode = (nNode < pEE->GetEditDoc().Count()) + ? pEE->GetEditDoc().GetObject(nNode) + : pEE->GetEditDoc().GetObject(nNode - 1); + + assert(pCheckNode); + + DBG_ASSERT(pCheckNode != mpContentNode.get(), "?! RemoveContent !? "); - bDelObject = true; // belongs to the Engine again + EditPaM aPaM(pCheckNode, pCheckNode->Len()); - pEE->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) ); + pEE->GetActiveView()->getImpl().SetEditSelection( EditSelection( aPaM, aPaM ) ); } EditUndoConnectParas::EditUndoConnectParas( EditEngine* pEE, sal_Int32 nN, sal_uInt16 nSP, - const SfxItemSet& rLeftParaAttribs, const SfxItemSet& rRightParaAttribs, + SfxItemSet _aLeftParaAttribs, SfxItemSet _aRightParaAttribs, const SfxStyleSheet* pLeftStyle, const SfxStyleSheet* pRightStyle, bool bBkwrd) : EditUndo(EDITUNDO_CONNECTPARAS, pEE), nNode(nN), nSepPos(nSP), - aLeftParaAttribs(rLeftParaAttribs), - aRightParaAttribs(rRightParaAttribs), + aLeftParaAttribs(std::move(_aLeftParaAttribs)), + aRightParaAttribs(std::move(_aRightParaAttribs)), eLeftStyleFamily(SfxStyleFamily::All), eRightStyleFamily(SfxStyleFamily::All), bBackward(bBkwrd) @@ -270,7 +272,7 @@ void EditUndoConnectParas::Undo() GetEditEngine()->SetStyleSheet( nNode+1, static_cast<SfxStyleSheet*>(GetEditEngine()->GetStyleSheetPool()->Find( aRightStyleName, eRightStyleFamily )) ); } - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) ); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection( EditSelection( aPaM, aPaM ) ); } void EditUndoConnectParas::Redo() @@ -278,7 +280,7 @@ void EditUndoConnectParas::Redo() DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: Np Active View!" ); EditPaM aPaM = GetEditEngine()->ConnectContents( nNode, bBackward ); - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) ); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection( EditSelection( aPaM, aPaM ) ); } EditUndoSplitPara::EditUndoSplitPara( @@ -292,21 +294,21 @@ void EditUndoSplitPara::Undo() { DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" ); EditPaM aPaM = GetEditEngine()->ConnectContents(nNode, false); - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) ); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection( EditSelection( aPaM, aPaM ) ); } void EditUndoSplitPara::Redo() { DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" ); EditPaM aPaM = GetEditEngine()->SplitContent(nNode, nSepPos); - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) ); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection( EditSelection( aPaM, aPaM ) ); } EditUndoInsertChars::EditUndoInsertChars( - EditEngine* pEE, const EPaM& rEPaM, const OUString& rStr) : + EditEngine* pEE, const EPaM& rEPaM, OUString aStr) : EditUndo(EDITUNDO_INSERTCHARS, pEE), aEPaM(rEPaM), - aText(rStr) {} + aText(std::move(aStr)) {} void EditUndoInsertChars::Undo() { @@ -315,7 +317,7 @@ void EditUndoInsertChars::Undo() EditSelection aSel( aPaM, aPaM ); aSel.Max().SetIndex( aSel.Max().GetIndex() + aText.getLength() ); EditPaM aNewPaM( GetEditEngine()->DeleteSelection(aSel) ); - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aNewPaM, aNewPaM ) ); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection( EditSelection( aNewPaM, aNewPaM ) ); } void EditUndoInsertChars::Redo() @@ -325,7 +327,7 @@ void EditUndoInsertChars::Redo() GetEditEngine()->InsertText(EditSelection(aPaM, aPaM), aText); EditPaM aNewPaM( aPaM ); aNewPaM.SetIndex( aNewPaM.GetIndex() + aText.getLength() ); - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aNewPaM ) ); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection( EditSelection( aPaM, aNewPaM ) ); } bool EditUndoInsertChars::Merge( SfxUndoAction* pNextAction ) @@ -346,9 +348,9 @@ bool EditUndoInsertChars::Merge( SfxUndoAction* pNextAction ) } EditUndoRemoveChars::EditUndoRemoveChars( - EditEngine* pEE, const EPaM& rEPaM, const OUString& rStr) : + EditEngine* pEE, const EPaM& rEPaM, OUString aStr) : EditUndo(EDITUNDO_REMOVECHARS, pEE), - aEPaM(rEPaM), aText(rStr) {} + aEPaM(rEPaM), aText(std::move(aStr)) {} void EditUndoRemoveChars::Undo() { @@ -357,7 +359,7 @@ void EditUndoRemoveChars::Undo() EditSelection aSel( aPaM, aPaM ); GetEditEngine()->InsertText(aSel, aText); aSel.Max().SetIndex( aSel.Max().GetIndex() + aText.getLength() ); - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aSel); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection(aSel); } void EditUndoRemoveChars::Redo() @@ -367,7 +369,7 @@ void EditUndoRemoveChars::Redo() EditSelection aSel( aPaM, aPaM ); aSel.Max().SetIndex( aSel.Max().GetIndex() + aText.getLength() ); EditPaM aNewPaM = GetEditEngine()->DeleteSelection(aSel); - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aNewPaM); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection(aNewPaM); } EditUndoInsertFeature::EditUndoInsertFeature( @@ -392,7 +394,7 @@ void EditUndoInsertFeature::Undo() aSel.Max().SetIndex( aSel.Max().GetIndex()+1 ); GetEditEngine()->DeleteSelection(aSel); aSel.Max().SetIndex( aSel.Max().GetIndex()-1 ); // For Selection - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aSel); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection(aSel); } void EditUndoInsertFeature::Redo() @@ -404,7 +406,7 @@ void EditUndoInsertFeature::Redo() if ( pFeature->Which() == EE_FEATURE_FIELD ) GetEditEngine()->UpdateFieldsOnly(); aSel.Max().SetIndex( aSel.Max().GetIndex()+1 ); - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aSel); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection(aSel); } EditUndoMoveParagraphs::EditUndoMoveParagraphs( @@ -433,26 +435,26 @@ void EditUndoMoveParagraphs::Undo() nTmpDest += aTmpRange.Len(); EditSelection aNewSel = GetEditEngine()->MoveParagraphs(aTmpRange, nTmpDest); - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel ); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection( aNewSel ); } void EditUndoMoveParagraphs::Redo() { DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" ); EditSelection aNewSel = GetEditEngine()->MoveParagraphs(nParagraphs, nDest); - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel ); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection( aNewSel ); } EditUndoSetStyleSheet::EditUndoSetStyleSheet( - EditEngine* pEE, sal_Int32 nP, const OUString& rPrevName, SfxStyleFamily ePrevFam, - const OUString& rNewName, SfxStyleFamily eNewFam, const SfxItemSet& rPrevParaAttribs) : + EditEngine* pEE, sal_Int32 nP, OUString _aPrevName, SfxStyleFamily ePrevFam, + OUString _aNewName, SfxStyleFamily eNewFam, SfxItemSet _aPrevParaAttribs) : EditUndo(EDITUNDO_STYLESHEET, pEE), nPara(nP), - aPrevName(rPrevName), - aNewName(rNewName), + aPrevName(std::move(_aPrevName)), + aNewName(std::move(_aNewName)), ePrevFamily(ePrevFam), eNewFamily(eNewFam), - aPrevParaAttribs(rPrevParaAttribs) + aPrevParaAttribs(std::move(_aPrevParaAttribs)) { } @@ -476,11 +478,11 @@ void EditUndoSetStyleSheet::Redo() } EditUndoSetParaAttribs::EditUndoSetParaAttribs( - EditEngine* pEE, sal_Int32 nP, const SfxItemSet& rPrevItems, const SfxItemSet& rNewItems) : + EditEngine* pEE, sal_Int32 nP, SfxItemSet _aPrevItems, SfxItemSet _aNewItems) : EditUndo(EDITUNDO_PARAATTRIBS, pEE), nPara(nP), - aPrevItems(rPrevItems), - aNewItems(rNewItems) {} + aPrevItems(std::move(_aPrevItems)), + aNewItems(std::move(_aNewItems)) {} EditUndoSetParaAttribs::~EditUndoSetParaAttribs() {} @@ -498,10 +500,10 @@ void EditUndoSetParaAttribs::Redo() lcl_DoSetSelection( GetEditEngine()->GetActiveView(), nPara ); } -EditUndoSetAttribs::EditUndoSetAttribs(EditEngine* pEE, const ESelection& rESel, const SfxItemSet& rNewItems) : +EditUndoSetAttribs::EditUndoSetAttribs(EditEngine* pEE, const ESelection& rESel, SfxItemSet aNewItems) : EditUndo(EDITUNDO_ATTRIBS, pEE), aESel(rESel), - aNewAttribs(rNewItems), + aNewAttribs(std::move(aNewItems)), nSpecial(SetAttribsMode::NONE), m_bSetSelection(true), // When EditUndoSetAttribs actually is a RemoveAttribs this could be @@ -513,26 +515,8 @@ EditUndoSetAttribs::EditUndoSetAttribs(EditEngine* pEE, const ESelection& rESel, { } -namespace { - -struct RemoveAttribsFromPool -{ - SfxItemPool& mrPool; -public: - explicit RemoveAttribsFromPool(SfxItemPool& rPool) : mrPool(rPool) {} - void operator() (std::unique_ptr<ContentAttribsInfo> const & rInfo) - { - rInfo->RemoveAllCharAttribsFromPool(mrPool); - } -}; - -} - EditUndoSetAttribs::~EditUndoSetAttribs() { - // Get Items from Pool... - SfxItemPool* pPool = aNewAttribs.GetPool(); - std::for_each(aPrevAttribs.begin(), aPrevAttribs.end(), RemoveAttribsFromPool(*pPool)); } void EditUndoSetAttribs::Undo() @@ -595,7 +579,7 @@ void EditUndoSetAttribs::ImpSetSelection() { EditEngine* pEE = GetEditEngine(); EditSelection aSel = pEE->CreateSelection(aESel); - pEE->GetActiveView()->GetImpEditView()->SetEditSelection(aSel); + pEE->GetActiveView()->getImpl().SetEditSelection(aSel); } EditUndoTransliteration::EditUndoTransliteration(EditEngine* pEE, const ESelection& rESel, TransliterationFlags nM) : @@ -619,7 +603,7 @@ void EditUndoTransliteration::Undo() EditSelection aDelSel( aSel ); aSel = pEE->InsertParaBreak( aSel ); aDelSel.Max() = aSel.Min(); - aDelSel.Max().GetNode()->GetCharAttribs().DeleteEmptyAttribs( pEE->GetEditDoc().GetItemPool() ); + aDelSel.Max().GetNode()->GetCharAttribs().DeleteEmptyAttribs(); EditSelection aNewSel; if ( pTxtObj ) { @@ -640,7 +624,7 @@ void EditUndoTransliteration::Undo() aNewSel.Max().SetIndex( aNewSel.Max().GetIndex() + aDelSel.Min().GetIndex() ); } pEE->DeleteSelected( aDelSel ); - pEE->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel ); + pEE->GetActiveView()->getImpl().SetEditSelection( aNewSel ); } void EditUndoTransliteration::Redo() @@ -650,7 +634,7 @@ void EditUndoTransliteration::Redo() EditSelection aSel = pEE->CreateSelection(aOldESel); EditSelection aNewSel = pEE->TransliterateText( aSel, nMode ); - pEE->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel ); + pEE->GetActiveView()->getImpl().SetEditSelection( aNewSel ); } EditUndoMarkSelection::EditUndoMarkSelection(EditEngine* pEE, const ESelection& rSel) : @@ -666,7 +650,7 @@ void EditUndoMarkSelection::Undo() if ( GetEditEngine()->IsFormatted() ) GetEditEngine()->GetActiveView()->SetSelection( aSelection ); else - GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( GetEditEngine()->CreateSelection(aSelection) ); + GetEditEngine()->GetActiveView()->getImpl().SetEditSelection(GetEditEngine()->CreateSelection(aSelection)); } } |