summaryrefslogtreecommitdiff
path: root/sc/source/ui/undo/undocell.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source/ui/undo/undocell.cxx')
-rw-r--r--sc/source/ui/undo/undocell.cxx185
1 files changed, 175 insertions, 10 deletions
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index fc9015daff20..04048d8ef96e 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -25,6 +25,12 @@
#include <editeng/justifyitem.hxx>
#include <svl/zforlist.hxx>
#include <svl/sharedstringpool.hxx>
+#include <svx/dialmgr.hxx>
+#include <svx/e3dsceneupdater.hxx>
+#include <svx/svdocapt.hxx>
+#include <svx/svdogrp.hxx>
+#include <svx/svdviter.hxx>
+#include <svx/strings.hrc>
#include <sfx2/app.hxx>
#include <attrib.hxx>
@@ -715,22 +721,183 @@ bool ScUndoThesaurus::CanRepeat(SfxRepeatTarget& rTarget) const
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
+
+ScUndoSdrCaptionObj::ScUndoSdrCaptionObj(const std::shared_ptr< SdrCaptionObj >& pCaptionObj)
+ : SdrUndoAction(pCaptionObj->getSdrModelFromSdrObject())
+ , m_pObjList(pCaptionObj->getParentSdrObjListFromSdrObject())
+ , m_nOrdNum(pCaptionObj->GetOrdNum())
+ , m_pCaptionObj(pCaptionObj)
+{
+}
+
+ScUndoSdrCaptionObj::~ScUndoSdrCaptionObj()
+{
+}
+
+void ScUndoSdrCaptionObj::BroadcastSwitchToPage()
+{
+ if (m_pCaptionObj && m_pCaptionObj->IsInserted() && m_pCaptionObj->getSdrPageFromSdrObject())
+ {
+ SdrHint aHint(SdrHintKind::SwitchToPage, *m_pCaptionObj, m_pCaptionObj->getSdrPageFromSdrObject());
+ rMod.Broadcast(aHint);
+ }
+}
+
+void ScUndoSdrCaptionObj::UnmarkObject()
+{
+ SdrViewIter aIter( m_pCaptionObj.get() );
+ for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() )
+ {
+ pView->MarkObj( m_pCaptionObj.get(), pView->GetSdrPageView(), true );
+ }
+}
+
+OUString ScUndoSdrCaptionObj::GetDescriptionString(const char* pStrCacheID, bool bRepeat ) const
+{
+ const OUString rStr {SvxResId(pStrCacheID)};
+
+ const sal_Int32 nPos = rStr.indexOf("%1");
+ if (nPos < 0)
+ return rStr;
+
+ if (bRepeat)
+ return rStr.replaceAt(nPos, 2, SvxResId(STR_ObjNameSingulPlural));
+
+ return rStr.replaceAt(nPos, 2, m_pCaptionObj->TakeObjNameSingul());
+}
+
+ScUndoDelSdrCaptionObj::ScUndoDelSdrCaptionObj(const std::shared_ptr< SdrCaptionObj >& pCaptionObj)
+ : ScUndoSdrCaptionObj(pCaptionObj)
+{
+}
+
+ScUndoDelSdrCaptionObj::~ScUndoDelSdrCaptionObj()
+{
+
+}
+
+void ScUndoDelSdrCaptionObj::Undo()
+{
+ // Trigger PageChangeCall
+ BroadcastSwitchToPage();
+
+ if (!m_pCaptionObj->IsInserted())
+ {
+ Point aOwnerAnchorPos(0, 0);
+
+ if (dynamic_cast< const SdrObjGroup* >(m_pObjList->getSdrObjectFromSdrObjList()) != nullptr)
+ {
+ aOwnerAnchorPos = m_pObjList->getSdrObjectFromSdrObjList()->GetAnchorPos();
+ }
+
+ E3DModifySceneSnapRectUpdater aUpdater(m_pObjList->getSdrObjectFromSdrObjList());
+ m_pObjList->InsertObject(m_pCaptionObj.get(), m_nOrdNum);
+
+ if(aOwnerAnchorPos.X() || aOwnerAnchorPos.Y())
+ {
+ m_pCaptionObj->NbcSetAnchorPos(aOwnerAnchorPos);
+ }
+ }
+
+}
+
+void ScUndoDelSdrCaptionObj::Redo()
+{
+ if (m_pCaptionObj->IsInserted())
+ {
+ UnmarkObject();
+ E3DModifySceneSnapRectUpdater aUpdater(m_pCaptionObj.get());
+ m_pObjList->RemoveObject(m_nOrdNum);
+ }
+
+ // Trigger PageChangeCall
+ BroadcastSwitchToPage();
+}
+
+OUString ScUndoDelSdrCaptionObj::GetComment() const
+{
+ return GetDescriptionString(STR_EditDelete);
+}
+
+void ScUndoDelSdrCaptionObj::SdrRepeat(SdrView& rView)
+{
+ rView.DeleteMarked();
+}
+
+bool ScUndoDelSdrCaptionObj::CanSdrRepeat(SdrView& rView) const
+{
+ return rView.AreObjectsMarked();
+}
+
+OUString ScUndoDelSdrCaptionObj::GetSdrRepeatComment(SdrView& /*rView*/) const
+{
+ return GetDescriptionString(STR_EditDelete, true);
+}
+
+ScUndoNewSdrCaptionObj::ScUndoNewSdrCaptionObj(const std::shared_ptr< SdrCaptionObj >& pCaptionObj)
+ : ScUndoSdrCaptionObj(pCaptionObj)
+{
+}
+
+ScUndoNewSdrCaptionObj::~ScUndoNewSdrCaptionObj()
+{
+}
+
+void ScUndoNewSdrCaptionObj::Undo()
+{
+ // Trigger PageChangeCall
+ BroadcastSwitchToPage();
+
+ if (m_pCaptionObj->IsInserted())
+ {
+ UnmarkObject();
+ m_pObjList->RemoveObject(m_nOrdNum);
+ }
+}
+
+void ScUndoNewSdrCaptionObj::Redo()
+{
+ if (!m_pCaptionObj->IsInserted())
+ {
+ Point aAnchorPos( 0, 0 );
+
+ if (dynamic_cast<const SdrObjGroup*>(m_pObjList->getSdrObjectFromSdrObjList()) != nullptr)
+ {
+ aAnchorPos = m_pCaptionObj->GetAnchorPos();
+ }
+
+ m_pObjList->InsertObject(m_pCaptionObj.get(), m_nOrdNum);
+
+ // Arcs lose position when grouped (#i45952#)
+ if ( aAnchorPos.X() || aAnchorPos.Y() )
+ {
+ m_pCaptionObj->NbcSetAnchorPos( aAnchorPos );
+ }
+ }
+
+ // Trigger PageChangeCall
+ BroadcastSwitchToPage();
+}
+
+OUString ScUndoNewSdrCaptionObj::GetComment() const
+{
+ return GetDescriptionString(STR_UndoInsertObj);
+}
+
ScUndoReplaceNote::ScUndoReplaceNote( ScDocShell& rDocShell, const ScAddress& rPos,
const ScNoteData& rNoteData, bool bInsert, SdrUndoAction* pDrawUndo ) :
ScSimpleUndo( &rDocShell ),
maPos( rPos ),
mpDrawUndo( pDrawUndo )
{
- OSL_ENSURE( rNoteData.mxCaption, "ScUndoReplaceNote::ScUndoReplaceNote - missing note caption" );
+ OSL_ENSURE( rNoteData.m_pCaption, "ScUndoReplaceNote::ScUndoReplaceNote - missing note caption" );
if (bInsert)
{
maNewData = rNoteData;
- maNewData.mxCaption.setNotOwner();
}
else
{
maOldData = rNoteData;
- maOldData.mxCaption.setNotOwner();
}
}
@@ -742,10 +909,8 @@ ScUndoReplaceNote::ScUndoReplaceNote( ScDocShell& rDocShell, const ScAddress& rP
maNewData( rNewData ),
mpDrawUndo( pDrawUndo )
{
- OSL_ENSURE( maOldData.mxCaption || maNewData.mxCaption, "ScUndoReplaceNote::ScUndoReplaceNote - missing note captions" );
+ OSL_ENSURE( maOldData.m_pCaption || maNewData.m_pCaption, "ScUndoReplaceNote::ScUndoReplaceNote - missing note captions" );
OSL_ENSURE( !maOldData.mxInitData.get() && !maNewData.mxInitData.get(), "ScUndoReplaceNote::ScUndoReplaceNote - unexpected uninitialized note" );
- maOldData.mxCaption.setNotOwner();
- maNewData.mxCaption.setNotOwner();
}
ScUndoReplaceNote::~ScUndoReplaceNote()
@@ -790,13 +955,13 @@ bool ScUndoReplaceNote::CanRepeat( SfxRepeatTarget& /*rTarget*/ ) const
OUString ScUndoReplaceNote::GetComment() const
{
- return ScResId( maNewData.mxCaption ?
- (maOldData.mxCaption ? STR_UNDO_EDITNOTE : STR_UNDO_INSERTNOTE) : STR_UNDO_DELETENOTE );
+ return ScResId( maNewData.m_pCaption ?
+ (maOldData.m_pCaption ? STR_UNDO_EDITNOTE : STR_UNDO_INSERTNOTE) : STR_UNDO_DELETENOTE );
}
void ScUndoReplaceNote::DoInsertNote( const ScNoteData& rNoteData )
{
- if( rNoteData.mxCaption )
+ if( rNoteData.m_pCaption )
{
ScDocument& rDoc = pDocShell->GetDocument();
OSL_ENSURE( !rDoc.GetNote(maPos), "ScUndoReplaceNote::DoInsertNote - unexpected cell note" );
@@ -808,7 +973,7 @@ void ScUndoReplaceNote::DoInsertNote( const ScNoteData& rNoteData )
void ScUndoReplaceNote::DoRemoveNote( const ScNoteData& rNoteData )
{
- if( rNoteData.mxCaption )
+ if( rNoteData.m_pCaption )
{
ScDocument& rDoc = pDocShell->GetDocument();
OSL_ENSURE( rDoc.GetNote(maPos), "ScUndoReplaceNote::DoRemoveNote - missing cell note" );