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 "undo/undoobjects.hxx"
22 #include "CustomAnimationEffect.hxx"
23 #include "drawdoc.hxx"
24 #include "undoanim.hxx"
28 UndoRemovePresObjectImpl::UndoRemovePresObjectImpl( SdrObject
& rObject
)
33 SdPage
* pPage
= dynamic_cast< SdPage
* >( rObject
.GetPage() );
36 if( pPage
->IsPresObj(&rObject
) )
37 mpUndoPresObj
= new UndoObjectPresentationKind( rObject
);
38 if( rObject
.GetUserCall() )
39 mpUndoUsercall
= new UndoObjectUserCall(rObject
);
41 if( pPage
->hasAnimationNode() )
43 com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
> xShape( rObject
.getUnoShape(), com::sun::star::uno::UNO_QUERY
);
44 if( pPage
->getMainSequence()->hasEffect( xShape
) )
46 mpUndoAnimation
= new UndoAnimation( static_cast< SdDrawDocument
* >( pPage
->GetModel() ), pPage
);
52 UndoRemovePresObjectImpl::~UndoRemovePresObjectImpl()
54 delete mpUndoAnimation
;
56 delete mpUndoUsercall
;
59 void UndoRemovePresObjectImpl::Undo()
62 mpUndoUsercall
->Undo();
64 mpUndoPresObj
->Undo();
66 mpUndoAnimation
->Undo();
69 void UndoRemovePresObjectImpl::Redo()
72 mpUndoAnimation
->Redo();
74 mpUndoPresObj
->Redo();
76 mpUndoUsercall
->Redo();
79 UndoRemoveObject::UndoRemoveObject( SdrObject
& rObject
, bool bOrdNumDirect
)
80 : SdrUndoRemoveObj( rObject
, bOrdNumDirect
), UndoRemovePresObjectImpl( rObject
)
81 , mxSdrObject(&rObject
)
85 void UndoRemoveObject::Undo()
87 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoRemoveObject::Undo(), object already dead!" );
88 if( mxSdrObject
.is() )
90 SdrUndoRemoveObj::Undo();
91 UndoRemovePresObjectImpl::Undo();
95 void UndoRemoveObject::Redo()
97 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoRemoveObject::Redo(), object already dead!" );
98 if( mxSdrObject
.is() )
100 UndoRemovePresObjectImpl::Redo();
101 SdrUndoRemoveObj::Redo();
105 UndoDeleteObject::UndoDeleteObject( SdrObject
& rObject
, bool bOrdNumDirect
)
106 : SdrUndoDelObj( rObject
, bOrdNumDirect
)
107 , UndoRemovePresObjectImpl( rObject
)
108 , mxSdrObject(&rObject
)
112 void UndoDeleteObject::Undo()
114 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoDeleteObject::Undo(), object already dead!" );
115 if( mxSdrObject
.is() )
117 SdrUndoDelObj::Undo();
118 UndoRemovePresObjectImpl::Undo();
122 void UndoDeleteObject::Redo()
124 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoDeleteObject::Redo(), object already dead!" );
125 if( mxSdrObject
.is() )
127 UndoRemovePresObjectImpl::Redo();
128 SdrUndoDelObj::Redo();
132 UndoReplaceObject::UndoReplaceObject( SdrObject
& rOldObject
, SdrObject
& rNewObject
, bool bOrdNumDirect
)
133 : SdrUndoReplaceObj( rOldObject
, rNewObject
, bOrdNumDirect
)
134 , UndoRemovePresObjectImpl( rOldObject
)
135 , mxSdrObject( &rOldObject
)
139 void UndoReplaceObject::Undo()
141 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoReplaceObject::Undo(), object already dead!" );
142 if( mxSdrObject
.is() )
144 SdrUndoReplaceObj::Undo();
145 UndoRemovePresObjectImpl::Undo();
149 void UndoReplaceObject::Redo()
151 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoReplaceObject::Redo(), object already dead!" );
152 if( mxSdrObject
.is() )
154 UndoRemovePresObjectImpl::Redo();
155 SdrUndoReplaceObj::Redo();
159 UndoObjectSetText::UndoObjectSetText( SdrObject
& rObject
, sal_Int32 nText
)
160 : SdrUndoObjSetText( rObject
, nText
)
162 , mbNewEmptyPresObj(false)
163 , mxSdrObject( &rObject
)
165 SdPage
* pPage
= dynamic_cast< SdPage
* >( rObject
.GetPage() );
166 if( pPage
&& pPage
->hasAnimationNode() )
168 com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
> xShape( rObject
.getUnoShape(), com::sun::star::uno::UNO_QUERY
);
169 if( pPage
->getMainSequence()->hasEffect( xShape
) )
171 mpUndoAnimation
= new UndoAnimation( static_cast< SdDrawDocument
* >( pPage
->GetModel() ), pPage
);
176 UndoObjectSetText::~UndoObjectSetText()
178 delete mpUndoAnimation
;
181 void UndoObjectSetText::Undo()
183 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoObjectSetText::Undo(), object already dead!" );
184 if( mxSdrObject
.is() )
186 mbNewEmptyPresObj
= mxSdrObject
->IsEmptyPresObj();
187 SdrUndoObjSetText::Undo();
188 if( mpUndoAnimation
)
189 mpUndoAnimation
->Undo();
193 void UndoObjectSetText::Redo()
195 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoObjectSetText::Redo(), object already dead!" );
196 if( mxSdrObject
.is() )
198 if( mpUndoAnimation
)
199 mpUndoAnimation
->Redo();
200 SdrUndoObjSetText::Redo();
201 mxSdrObject
->SetEmptyPresObj(mbNewEmptyPresObj
);
205 // Undo for SdrObject::SetUserCall()
207 UndoObjectUserCall::UndoObjectUserCall(SdrObject
& rObject
)
208 : SdrUndoObj(rObject
)
209 , mpOldUserCall(static_cast<SdPage
*>(rObject
.GetUserCall()))
211 , mxSdrObject( &rObject
)
215 void UndoObjectUserCall::Undo()
217 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoObjectUserCall::Undo(), object already dead!" );
218 if( mxSdrObject
.is() )
220 mpNewUserCall
= mxSdrObject
->GetUserCall();
221 mxSdrObject
->SetUserCall(mpOldUserCall
);
225 void UndoObjectUserCall::Redo()
227 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoObjectUserCall::Redo(), object already dead!" );
228 if( mxSdrObject
.is() )
230 mxSdrObject
->SetUserCall(mpNewUserCall
);
234 // Undo for SdPage::InsertPresObj() and SdPage::RemovePresObj()
236 UndoObjectPresentationKind::UndoObjectPresentationKind(SdrObject
& rObject
)
237 : SdrUndoObj(rObject
)
238 , meOldKind(PRESOBJ_NONE
)
239 , meNewKind(PRESOBJ_NONE
)
240 , mxPage( rObject
.GetPage() )
241 , mxSdrObject( &rObject
)
243 DBG_ASSERT( mxPage
.is(), "sd::UndoObjectPresentationKind::UndoObjectPresentationKind(), does not work for shapes without a slide!" );
246 meOldKind
= static_cast< SdPage
* >( mxPage
.get() )->GetPresObjKind( &rObject
);
249 void UndoObjectPresentationKind::Undo()
251 if( mxPage
.is() && mxSdrObject
.is() )
253 SdPage
* pPage
= static_cast< SdPage
* >( mxPage
.get() );
254 meNewKind
= pPage
->GetPresObjKind( mxSdrObject
.get() );
255 if( meNewKind
!= PRESOBJ_NONE
)
256 pPage
->RemovePresObj( mxSdrObject
.get() );
257 if( meOldKind
!= PRESOBJ_NONE
)
258 pPage
->InsertPresObj( mxSdrObject
.get(), meOldKind
);
262 void UndoObjectPresentationKind::Redo()
264 if( mxPage
.is() && mxSdrObject
.is() )
266 SdPage
* pPage
= static_cast< SdPage
* >( mxPage
.get() );
267 if( meOldKind
!= PRESOBJ_NONE
)
268 pPage
->RemovePresObj( mxSdrObject
.get() );
269 if( meNewKind
!= PRESOBJ_NONE
)
270 pPage
->InsertPresObj( mxSdrObject
.get(), meNewKind
);
274 UndoAutoLayoutPosAndSize::UndoAutoLayoutPosAndSize( SdPage
& rPage
)
279 void UndoAutoLayoutPosAndSize::Undo()
284 void UndoAutoLayoutPosAndSize::Redo()
286 SdPage
* pPage
= static_cast< SdPage
* >( mxPage
.get() );
288 pPage
->SetAutoLayout( pPage
->GetAutoLayout(), false, false );
291 UndoGeoObject::UndoGeoObject( SdrObject
& rNewObj
)
292 : SdrUndoGeoObj( rNewObj
)
293 , mxPage( rNewObj
.GetPage() )
294 , mxSdrObject( &rNewObj
)
298 void UndoGeoObject::Undo()
300 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoGeoObject::Undo(), object already dead!" );
301 if( mxSdrObject
.is() )
305 ScopeLockGuard
aGuard( static_cast< SdPage
* >( mxPage
.get() )->maLockAutoLayoutArrangement
);
306 SdrUndoGeoObj::Undo();
310 SdrUndoGeoObj::Undo();
315 void UndoGeoObject::Redo()
317 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoGeoObject::Redo(), object already dead!" );
318 if( mxSdrObject
.is() )
322 ScopeLockGuard
aGuard( static_cast< SdPage
* >(mxPage
.get())->maLockAutoLayoutArrangement
);
323 SdrUndoGeoObj::Redo();
327 SdrUndoGeoObj::Redo();
332 UndoAttrObject::UndoAttrObject( SdrObject
& rObject
, bool bStyleSheet1
, bool bSaveText
)
333 : SdrUndoAttrObj( rObject
, bStyleSheet1
, bSaveText
)
334 , mxPage( rObject
.GetPage() )
335 , mxSdrObject( &rObject
)
339 void UndoAttrObject::Undo()
341 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoAttrObject::Undo(), object already dead!" );
342 if( mxSdrObject
.is() )
346 ScopeLockGuard
aGuard( static_cast< SdPage
* >( mxPage
.get() )->maLockAutoLayoutArrangement
);
347 SdrUndoAttrObj::Undo();
351 SdrUndoAttrObj::Undo();
356 void UndoAttrObject::Redo()
358 DBG_ASSERT( mxSdrObject
.is(), "sd::UndoAttrObject::Redo(), object already dead!" );
359 if( mxSdrObject
.is() )
363 ScopeLockGuard
aGuard( static_cast< SdPage
* >( mxPage
.get() )->maLockAutoLayoutArrangement
);
364 SdrUndoAttrObj::Redo();
368 SdrUndoAttrObj::Redo();
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */