1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/debug.hxx>
21 #include <undo/undoobjects.hxx>
23 #include <CustomAnimationEffect.hxx>
24 #include <drawdoc.hxx>
25 #include <undoanim.hxx>
26 #include <ViewShell.hxx>
27 #include <ViewShellBase.hxx>
28 #include <DrawDocShell.hxx>
32 SdUndoAction::SdUndoAction(SdDrawDocument
* pSdDrawDocument
)
33 : mpDoc(pSdDrawDocument
),
36 sd::DrawDocShell
* pDocShell
= pSdDrawDocument
? pSdDrawDocument
->GetDocSh() : nullptr;
37 sd::ViewShell
* pViewShell
= pDocShell
? pDocShell
->GetViewShell() : nullptr;
39 mnViewShellId
= pViewShell
->GetViewShellBase().GetViewShellId();
42 ViewShellId
SdUndoAction::GetViewShellId() const
47 UndoRemovePresObjectImpl::UndoRemovePresObjectImpl( SdrObject
& rObject
)
49 SdPage
* pPage
= dynamic_cast< SdPage
* >( rObject
.getSdrPageFromSdrObject() );
53 if( pPage
->IsPresObj(&rObject
) )
54 mpUndoPresObj
.reset( new UndoObjectPresentationKind( rObject
) );
55 if( rObject
.GetUserCall() )
56 mpUndoUsercall
.reset( new UndoObjectUserCall(rObject
) );
58 if( pPage
->hasAnimationNode() )
60 css::uno::Reference
< css::drawing::XShape
> xShape( rObject
.getUnoShape(), css::uno::UNO_QUERY
);
61 if( pPage
->getMainSequence()->hasEffect( xShape
) )
63 mpUndoAnimation
.reset(
64 new UndoAnimation( // TTTT may use ref? Or just *SdrPage?
65 static_cast< SdDrawDocument
* >(&pPage
->getSdrModelFromSdrPage()),
71 UndoRemovePresObjectImpl::~UndoRemovePresObjectImpl()
75 void UndoRemovePresObjectImpl::Undo()
78 mpUndoUsercall
->Undo();
80 mpUndoPresObj
->Undo();
82 mpUndoAnimation
->Undo();
85 void UndoRemovePresObjectImpl::Redo()
88 mpUndoAnimation
->Redo();
90 mpUndoPresObj
->Redo();
92 mpUndoUsercall
->Redo();
95 UndoRemoveObject::UndoRemoveObject( SdrObject
& rObject
)
96 : SdrUndoRemoveObj( rObject
), UndoRemovePresObjectImpl( rObject
)
97 , mxSdrObject(&rObject
)
101 void UndoRemoveObject::Undo()
103 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoRemoveObject::Undo(), object already dead!" );
104 if( mxSdrObject
.get().is() )
106 SdrUndoRemoveObj::Undo();
107 UndoRemovePresObjectImpl::Undo();
111 void UndoRemoveObject::Redo()
113 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoRemoveObject::Redo(), object already dead!" );
114 if( mxSdrObject
.get().is() )
116 UndoRemovePresObjectImpl::Redo();
117 SdrUndoRemoveObj::Redo();
121 UndoDeleteObject::UndoDeleteObject( SdrObject
& rObject
, bool bOrdNumDirect
)
122 : SdrUndoDelObj( rObject
, bOrdNumDirect
)
123 , UndoRemovePresObjectImpl( rObject
)
124 , mxSdrObject(&rObject
)
128 void UndoDeleteObject::Undo()
130 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoDeleteObject::Undo(), object already dead!" );
131 if( mxSdrObject
.get().is() )
133 SdrUndoDelObj::Undo();
134 UndoRemovePresObjectImpl::Undo();
138 void UndoDeleteObject::Redo()
140 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoDeleteObject::Redo(), object already dead!" );
141 if( mxSdrObject
.get().is() )
143 UndoRemovePresObjectImpl::Redo();
144 SdrUndoDelObj::Redo();
148 UndoReplaceObject::UndoReplaceObject( SdrObject
& rOldObject
, SdrObject
& rNewObject
)
149 : SdrUndoReplaceObj( rOldObject
, rNewObject
)
150 , UndoRemovePresObjectImpl( rOldObject
)
151 , mxSdrObject( &rOldObject
)
155 void UndoReplaceObject::Undo()
157 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoReplaceObject::Undo(), object already dead!" );
158 if( mxSdrObject
.get().is() )
160 SdrUndoReplaceObj::Undo();
161 UndoRemovePresObjectImpl::Undo();
165 void UndoReplaceObject::Redo()
167 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoReplaceObject::Redo(), object already dead!" );
168 if( mxSdrObject
.get().is() )
170 UndoRemovePresObjectImpl::Redo();
171 SdrUndoReplaceObj::Redo();
175 UndoObjectSetText::UndoObjectSetText( SdrObject
& rObject
, sal_Int32 nText
)
176 : SdrUndoObjSetText( rObject
, nText
)
177 , mbNewEmptyPresObj(false)
178 , mxSdrObject( &rObject
)
180 SdPage
* pPage
= dynamic_cast< SdPage
* >( rObject
.getSdrPageFromSdrObject() );
181 if( pPage
&& pPage
->hasAnimationNode() )
183 css::uno::Reference
< css::drawing::XShape
> xShape( rObject
.getUnoShape(), css::uno::UNO_QUERY
);
184 if( pPage
->getMainSequence()->hasEffect( xShape
) )
186 mpUndoAnimation
.reset(
188 static_cast< SdDrawDocument
* >(&pPage
->getSdrModelFromSdrPage()),
194 UndoObjectSetText::~UndoObjectSetText()
198 void UndoObjectSetText::Undo()
200 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoObjectSetText::Undo(), object already dead!" );
201 if( auto pSdrObject
= mxSdrObject
.get() )
203 mbNewEmptyPresObj
= pSdrObject
->IsEmptyPresObj();
204 SdrUndoObjSetText::Undo();
205 if( mpUndoAnimation
)
206 mpUndoAnimation
->Undo();
210 void UndoObjectSetText::Redo()
212 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoObjectSetText::Redo(), object already dead!" );
213 if( auto pSdrObject
= mxSdrObject
.get() )
215 if( mpUndoAnimation
)
216 mpUndoAnimation
->Redo();
217 SdrUndoObjSetText::Redo();
218 pSdrObject
->SetEmptyPresObj(mbNewEmptyPresObj
);
222 // Undo for SdrObject::SetUserCall()
224 UndoObjectUserCall::UndoObjectUserCall(SdrObject
& rObject
)
225 : SdrUndoObj(rObject
)
226 , mpOldUserCall(static_cast<SdPage
*>(rObject
.GetUserCall()))
227 , mpNewUserCall(nullptr)
228 , mxSdrObject( &rObject
)
232 void UndoObjectUserCall::Undo()
234 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoObjectUserCall::Undo(), object already dead!" );
235 if( auto pSdrObject
= mxSdrObject
.get() )
237 mpNewUserCall
= pSdrObject
->GetUserCall();
238 pSdrObject
->SetUserCall(mpOldUserCall
);
242 void UndoObjectUserCall::Redo()
244 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoObjectUserCall::Redo(), object already dead!" );
245 if( auto pSdrObject
= mxSdrObject
.get() )
247 pSdrObject
->SetUserCall(mpNewUserCall
);
251 // Undo for SdPage::InsertPresObj() and SdPage::RemovePresObj()
253 UndoObjectPresentationKind::UndoObjectPresentationKind(SdrObject
& rObject
)
254 : SdrUndoObj(rObject
)
255 , meOldKind(PresObjKind::NONE
)
256 , meNewKind(PresObjKind::NONE
)
257 , mxPage( static_cast<SdPage
*>(rObject
.getSdrPageFromSdrObject()) )
258 , mxSdrObject( &rObject
)
260 DBG_ASSERT( mxPage
.get(), "sd::UndoObjectPresentationKind::UndoObjectPresentationKind(), does not work for shapes without a slide!" );
262 if( auto pPage
= mxPage
.get() )
263 meOldKind
= pPage
->GetPresObjKind( &rObject
);
266 void UndoObjectPresentationKind::Undo()
268 if( auto pSdrObject
= mxSdrObject
.get() )
270 if( rtl::Reference
<SdPage
> pPage
= mxPage
.get() )
272 meNewKind
= pPage
->GetPresObjKind( pSdrObject
.get() );
273 if( meNewKind
!= PresObjKind::NONE
)
274 pPage
->RemovePresObj( pSdrObject
.get() );
275 if( meOldKind
!= PresObjKind::NONE
)
276 pPage
->InsertPresObj( pSdrObject
.get(), meOldKind
);
281 void UndoObjectPresentationKind::Redo()
283 if( auto pSdrObject
= mxSdrObject
.get() )
285 if( rtl::Reference
<SdPage
> pPage
= mxPage
.get() )
287 if( meOldKind
!= PresObjKind::NONE
)
288 pPage
->RemovePresObj( pSdrObject
.get() );
289 if( meNewKind
!= PresObjKind::NONE
)
290 pPage
->InsertPresObj( pSdrObject
.get(), meNewKind
);
295 UndoAutoLayoutPosAndSize::UndoAutoLayoutPosAndSize( SdPage
& rPage
)
300 void UndoAutoLayoutPosAndSize::Undo()
305 void UndoAutoLayoutPosAndSize::Redo()
307 rtl::Reference
<SdPage
> pPage
= mxPage
.get();
309 pPage
->SetAutoLayout( pPage
->GetAutoLayout() );
312 UndoGeoObject::UndoGeoObject( SdrObject
& rNewObj
)
313 : SdrUndoGeoObj( rNewObj
)
314 , mxPage( static_cast<SdPage
*>(rNewObj
.getSdrPageFromSdrObject()) )
315 , mxSdrObject( &rNewObj
)
319 void UndoGeoObject::Undo()
321 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoGeoObject::Undo(), object already dead!" );
322 if( auto pSdrObject
= mxSdrObject
.get() )
324 if( auto pPage
= mxPage
.get() )
326 ScopeLockGuard
aGuard( pPage
->maLockAutoLayoutArrangement
);
327 SdrUndoGeoObj::Undo();
331 SdrUndoGeoObj::Undo();
336 void UndoGeoObject::Redo()
338 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoGeoObject::Redo(), object already dead!" );
339 if( auto pSdrObject
= mxSdrObject
.get() )
341 if( auto pPage
= mxPage
.get() )
343 ScopeLockGuard
aGuard( pPage
->maLockAutoLayoutArrangement
);
344 SdrUndoGeoObj::Redo();
348 SdrUndoGeoObj::Redo();
353 UndoAttrObject::UndoAttrObject( SdrObject
& rObject
, bool bStyleSheet1
, bool bSaveText
)
354 : SdrUndoAttrObj( rObject
, bStyleSheet1
, bSaveText
)
355 , mxPage( static_cast<SdPage
*>(rObject
.getSdrPageFromSdrObject()) )
356 , mxSdrObject( &rObject
)
360 void UndoAttrObject::Undo()
362 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoAttrObject::Undo(), object already dead!" );
363 if( auto pSdrObject
= mxSdrObject
.get() )
365 if( auto pPage
= mxPage
.get() )
367 ScopeLockGuard
aGuard( pPage
->maLockAutoLayoutArrangement
);
368 SdrUndoAttrObj::Undo();
372 SdrUndoAttrObj::Undo();
377 void UndoAttrObject::Redo()
379 DBG_ASSERT( mxSdrObject
.get().is(), "sd::UndoAttrObject::Redo(), object already dead!" );
380 if( auto pSdrObject
= mxSdrObject
.get() )
382 if( auto pPage
= mxPage
.get() )
384 ScopeLockGuard
aGuard( pPage
->maLockAutoLayoutArrangement
);
385 SdrUndoAttrObj::Redo();
389 SdrUndoAttrObj::Redo();
394 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */