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
.is(), "sd::UndoRemoveObject::Undo(), object already dead!" );
104 if( mxSdrObject
.is() )
106 SdrUndoRemoveObj::Undo();
107 UndoRemovePresObjectImpl::Undo();
111 void UndoRemoveObject::Redo()
113 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoRemoveObject::Redo(), object already dead!" );
114 if( mxSdrObject
.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
.is(), "sd::UndoDeleteObject::Undo(), object already dead!" );
131 if( mxSdrObject
.is() )
133 SdrUndoDelObj::Undo();
134 UndoRemovePresObjectImpl::Undo();
138 void UndoDeleteObject::Redo()
140 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoDeleteObject::Redo(), object already dead!" );
141 if( mxSdrObject
.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
.is(), "sd::UndoReplaceObject::Undo(), object already dead!" );
158 if( mxSdrObject
.is() )
160 SdrUndoReplaceObj::Undo();
161 UndoRemovePresObjectImpl::Undo();
165 void UndoReplaceObject::Redo()
167 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoReplaceObject::Redo(), object already dead!" );
168 if( mxSdrObject
.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
.is(), "sd::UndoObjectSetText::Undo(), object already dead!" );
201 if( mxSdrObject
.is() )
203 mbNewEmptyPresObj
= mxSdrObject
->IsEmptyPresObj();
204 SdrUndoObjSetText::Undo();
205 if( mpUndoAnimation
)
206 mpUndoAnimation
->Undo();
210 void UndoObjectSetText::Redo()
212 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoObjectSetText::Redo(), object already dead!" );
213 if( mxSdrObject
.is() )
215 if( mpUndoAnimation
)
216 mpUndoAnimation
->Redo();
217 SdrUndoObjSetText::Redo();
218 mxSdrObject
->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
.is(), "sd::UndoObjectUserCall::Undo(), object already dead!" );
235 if( mxSdrObject
.is() )
237 mpNewUserCall
= mxSdrObject
->GetUserCall();
238 mxSdrObject
->SetUserCall(mpOldUserCall
);
242 void UndoObjectUserCall::Redo()
244 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoObjectUserCall::Redo(), object already dead!" );
245 if( mxSdrObject
.is() )
247 mxSdrObject
->SetUserCall(mpNewUserCall
);
251 // Undo for SdPage::InsertPresObj() and SdPage::RemovePresObj()
253 UndoObjectPresentationKind::UndoObjectPresentationKind(SdrObject
& rObject
)
254 : SdrUndoObj(rObject
)
255 , meOldKind(PRESOBJ_NONE
)
256 , meNewKind(PRESOBJ_NONE
)
257 , mxPage( static_cast<SdPage
*>(rObject
.getSdrPageFromSdrObject()) )
258 , mxSdrObject( &rObject
)
260 DBG_ASSERT( mxPage
.is(), "sd::UndoObjectPresentationKind::UndoObjectPresentationKind(), does not work for shapes without a slide!" );
263 meOldKind
= mxPage
->GetPresObjKind( &rObject
);
266 void UndoObjectPresentationKind::Undo()
268 if( mxPage
.is() && mxSdrObject
.is() )
270 SdPage
* pPage
= mxPage
.get();
271 meNewKind
= pPage
->GetPresObjKind( mxSdrObject
.get() );
272 if( meNewKind
!= PRESOBJ_NONE
)
273 pPage
->RemovePresObj( mxSdrObject
.get() );
274 if( meOldKind
!= PRESOBJ_NONE
)
275 pPage
->InsertPresObj( mxSdrObject
.get(), meOldKind
);
279 void UndoObjectPresentationKind::Redo()
281 if( mxPage
.is() && mxSdrObject
.is() )
283 SdPage
* pPage
= mxPage
.get();
284 if( meOldKind
!= PRESOBJ_NONE
)
285 pPage
->RemovePresObj( mxSdrObject
.get() );
286 if( meNewKind
!= PRESOBJ_NONE
)
287 pPage
->InsertPresObj( mxSdrObject
.get(), meNewKind
);
291 UndoAutoLayoutPosAndSize::UndoAutoLayoutPosAndSize( SdPage
& rPage
)
296 void UndoAutoLayoutPosAndSize::Undo()
301 void UndoAutoLayoutPosAndSize::Redo()
303 SdPage
* pPage
= mxPage
.get();
305 pPage
->SetAutoLayout( pPage
->GetAutoLayout() );
308 UndoGeoObject::UndoGeoObject( SdrObject
& rNewObj
)
309 : SdrUndoGeoObj( rNewObj
)
310 , mxPage( static_cast<SdPage
*>(rNewObj
.getSdrPageFromSdrObject()) )
311 , mxSdrObject( &rNewObj
)
315 void UndoGeoObject::Undo()
317 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoGeoObject::Undo(), object already dead!" );
318 if( mxSdrObject
.is() )
322 ScopeLockGuard
aGuard( mxPage
->maLockAutoLayoutArrangement
);
323 SdrUndoGeoObj::Undo();
327 SdrUndoGeoObj::Undo();
332 void UndoGeoObject::Redo()
334 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoGeoObject::Redo(), object already dead!" );
335 if( mxSdrObject
.is() )
339 ScopeLockGuard
aGuard( mxPage
->maLockAutoLayoutArrangement
);
340 SdrUndoGeoObj::Redo();
344 SdrUndoGeoObj::Redo();
349 UndoAttrObject::UndoAttrObject( SdrObject
& rObject
, bool bStyleSheet1
, bool bSaveText
)
350 : SdrUndoAttrObj( rObject
, bStyleSheet1
, bSaveText
)
351 , mxPage( static_cast<SdPage
*>(rObject
.getSdrPageFromSdrObject()) )
352 , mxSdrObject( &rObject
)
356 void UndoAttrObject::Undo()
358 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoAttrObject::Undo(), object already dead!" );
359 if( mxSdrObject
.is() )
363 ScopeLockGuard
aGuard( mxPage
->maLockAutoLayoutArrangement
);
364 SdrUndoAttrObj::Undo();
368 SdrUndoAttrObj::Undo();
373 void UndoAttrObject::Redo()
375 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoAttrObject::Redo(), object already dead!" );
376 if( mxSdrObject
.is() )
380 ScopeLockGuard
aGuard( mxPage
->maLockAutoLayoutArrangement
);
381 SdrUndoAttrObj::Redo();
385 SdrUndoAttrObj::Redo();
390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */