bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / core / undo / undoobjects.cxx
blob66ad69902c9f2ebb1b931a79768aed92592e6888
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include "undo/undoobjects.hxx"
22 #include "sdpage.hxx"
23 #include "CustomAnimationEffect.hxx"
24 #include "drawdoc.hxx"
25 #include "undoanim.hxx"
27 using namespace sd;
29 ///////////////////////////////////////////////////////////////////////
31 UndoRemovePresObjectImpl::UndoRemovePresObjectImpl( SdrObject& rObject )
32 : mpUndoUsercall(0)
33 , mpUndoAnimation(0)
34 , mpUndoPresObj(0)
36 SdPage* pPage = dynamic_cast< SdPage* >( rObject.GetPage() );
37 if( pPage )
39 if( pPage->IsPresObj(&rObject) )
40 mpUndoPresObj = new UndoObjectPresentationKind( rObject );
41 if( rObject.GetUserCall() )
42 mpUndoUsercall = new UndoObjectUserCall(rObject);
44 if( pPage->hasAnimationNode() )
46 com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape( rObject.getUnoShape(), com::sun::star::uno::UNO_QUERY );
47 if( pPage->getMainSequence()->hasEffect( xShape ) )
49 mpUndoAnimation = new UndoAnimation( static_cast< SdDrawDocument* >( pPage->GetModel() ), pPage );
55 //---------------------------------------------------------------------
57 UndoRemovePresObjectImpl::~UndoRemovePresObjectImpl()
59 delete mpUndoAnimation;
60 delete mpUndoPresObj;
61 delete mpUndoUsercall;
64 //---------------------------------------------------------------------
66 void UndoRemovePresObjectImpl::Undo()
68 if( mpUndoUsercall )
69 mpUndoUsercall->Undo();
70 if( mpUndoPresObj )
71 mpUndoPresObj->Undo();
72 if( mpUndoAnimation )
73 mpUndoAnimation->Undo();
76 //---------------------------------------------------------------------
78 void UndoRemovePresObjectImpl::Redo()
80 if( mpUndoAnimation )
81 mpUndoAnimation->Redo();
82 if( mpUndoPresObj )
83 mpUndoPresObj->Redo();
84 if( mpUndoUsercall )
85 mpUndoUsercall->Redo();
88 ///////////////////////////////////////////////////////////////////////
91 UndoRemoveObject::UndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect )
92 : SdrUndoRemoveObj( rObject, bOrdNumDirect ), UndoRemovePresObjectImpl( rObject )
93 , mxSdrObject(&rObject)
97 //---------------------------------------------------------------------
99 void UndoRemoveObject::Undo()
101 DBG_ASSERT( mxSdrObject.is(), "sd::UndoRemoveObject::Undo(), object already dead!" );
102 if( mxSdrObject.is() )
104 SdrUndoRemoveObj::Undo();
105 UndoRemovePresObjectImpl::Undo();
109 //---------------------------------------------------------------------
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 ///////////////////////////////////////////////////////////////////////
123 UndoDeleteObject::UndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect )
124 : SdrUndoDelObj( rObject, bOrdNumDirect )
125 , UndoRemovePresObjectImpl( rObject )
126 , mxSdrObject(&rObject)
130 //---------------------------------------------------------------------
132 void UndoDeleteObject::Undo()
134 DBG_ASSERT( mxSdrObject.is(), "sd::UndoDeleteObject::Undo(), object already dead!" );
135 if( mxSdrObject.is() )
137 SdrUndoDelObj::Undo();
138 UndoRemovePresObjectImpl::Undo();
142 //---------------------------------------------------------------------
144 void UndoDeleteObject::Redo()
146 DBG_ASSERT( mxSdrObject.is(), "sd::UndoDeleteObject::Redo(), object already dead!" );
147 if( mxSdrObject.is() )
149 UndoRemovePresObjectImpl::Redo();
150 SdrUndoDelObj::Redo();
154 ///////////////////////////////////////////////////////////////////////
156 UndoReplaceObject::UndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect )
157 : SdrUndoReplaceObj( rOldObject, rNewObject, bOrdNumDirect )
158 , UndoRemovePresObjectImpl( rOldObject )
159 , mxSdrObject( &rOldObject )
163 //---------------------------------------------------------------------
165 void UndoReplaceObject::Undo()
167 DBG_ASSERT( mxSdrObject.is(), "sd::UndoReplaceObject::Undo(), object already dead!" );
168 if( mxSdrObject.is() )
170 SdrUndoReplaceObj::Undo();
171 UndoRemovePresObjectImpl::Undo();
175 //---------------------------------------------------------------------
177 void UndoReplaceObject::Redo()
179 DBG_ASSERT( mxSdrObject.is(), "sd::UndoReplaceObject::Redo(), object already dead!" );
180 if( mxSdrObject.is() )
182 UndoRemovePresObjectImpl::Redo();
183 SdrUndoReplaceObj::Redo();
187 ///////////////////////////////////////////////////////////////////////
189 UndoObjectSetText::UndoObjectSetText( SdrObject& rObject, sal_Int32 nText )
190 : SdrUndoObjSetText( rObject, nText )
191 , mpUndoAnimation(0)
192 , mbNewEmptyPresObj(false)
193 , mxSdrObject( &rObject )
195 SdPage* pPage = dynamic_cast< SdPage* >( rObject.GetPage() );
196 if( pPage && pPage->hasAnimationNode() )
198 com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape( rObject.getUnoShape(), com::sun::star::uno::UNO_QUERY );
199 if( pPage->getMainSequence()->hasEffect( xShape ) )
201 mpUndoAnimation = new UndoAnimation( static_cast< SdDrawDocument* >( pPage->GetModel() ), pPage );
206 //---------------------------------------------------------------------
208 UndoObjectSetText::~UndoObjectSetText()
210 delete mpUndoAnimation;
213 //---------------------------------------------------------------------
215 void UndoObjectSetText::Undo()
217 DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectSetText::Undo(), object already dead!" );
218 if( mxSdrObject.is() )
220 mbNewEmptyPresObj = mxSdrObject->IsEmptyPresObj() ? true : false;
221 SdrUndoObjSetText::Undo();
222 if( mpUndoAnimation )
223 mpUndoAnimation->Undo();
227 //---------------------------------------------------------------------
229 void UndoObjectSetText::Redo()
231 DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectSetText::Redo(), object already dead!" );
232 if( mxSdrObject.is() )
234 if( mpUndoAnimation )
235 mpUndoAnimation->Redo();
236 SdrUndoObjSetText::Redo();
237 mxSdrObject->SetEmptyPresObj(mbNewEmptyPresObj ? sal_True : sal_False );
241 //////////////////////////////////////////////////////////////////////////////
242 // Undo for SdrObject::SetUserCall()
244 UndoObjectUserCall::UndoObjectUserCall(SdrObject& rObject)
245 : SdrUndoObj(rObject)
246 , mpOldUserCall((SdPage*)rObject.GetUserCall())
247 , mpNewUserCall(0)
248 , mxSdrObject( &rObject )
252 //---------------------------------------------------------------------
254 void UndoObjectUserCall::Undo()
256 DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectUserCall::Undo(), object already dead!" );
257 if( mxSdrObject.is() )
259 mpNewUserCall = mxSdrObject->GetUserCall();
260 mxSdrObject->SetUserCall(mpOldUserCall);
264 //---------------------------------------------------------------------
266 void UndoObjectUserCall::Redo()
268 DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectUserCall::Redo(), object already dead!" );
269 if( mxSdrObject.is() )
271 mxSdrObject->SetUserCall(mpNewUserCall);
275 //////////////////////////////////////////////////////////////////////////////
276 // Undo for SdPage::InsertPresObj() and SdPage::RemovePresObj()
278 UndoObjectPresentationKind::UndoObjectPresentationKind(SdrObject& rObject)
279 : SdrUndoObj(rObject)
280 , meOldKind(PRESOBJ_NONE)
281 , meNewKind(PRESOBJ_NONE)
282 , mxPage( rObject.GetPage() )
283 , mxSdrObject( &rObject )
285 DBG_ASSERT( mxPage.is(), "sd::UndoObjectPresentationKind::UndoObjectPresentationKind(), does not work for shapes without a slide!" );
287 if( mxPage.is() )
288 meOldKind = static_cast< SdPage* >( mxPage.get() )->GetPresObjKind( &rObject );
291 //---------------------------------------------------------------------
293 void UndoObjectPresentationKind::Undo()
295 if( mxPage.is() && mxSdrObject.is() )
297 SdPage* pPage = static_cast< SdPage* >( mxPage.get() );
298 meNewKind = pPage->GetPresObjKind( mxSdrObject.get() );
299 if( meNewKind != PRESOBJ_NONE )
300 pPage->RemovePresObj( mxSdrObject.get() );
301 if( meOldKind != PRESOBJ_NONE )
302 pPage->InsertPresObj( mxSdrObject.get(), meOldKind );
306 //---------------------------------------------------------------------
308 void UndoObjectPresentationKind::Redo()
310 if( mxPage.is() && mxSdrObject.is() )
312 SdPage* pPage = static_cast< SdPage* >( mxPage.get() );
313 if( meOldKind != PRESOBJ_NONE )
314 pPage->RemovePresObj( mxSdrObject.get() );
315 if( meNewKind != PRESOBJ_NONE )
316 pPage->InsertPresObj( mxSdrObject.get(), meNewKind );
320 //////////////////////////////////////////////////////////////////////////////
322 UndoAutoLayoutPosAndSize::UndoAutoLayoutPosAndSize( SdPage& rPage )
323 : mxPage( &rPage )
327 //---------------------------------------------------------------------
329 void UndoAutoLayoutPosAndSize::Undo()
331 // do nothing
334 //---------------------------------------------------------------------
336 void UndoAutoLayoutPosAndSize::Redo()
338 SdPage* pPage = static_cast< SdPage* >( mxPage.get() );
339 if( pPage )
340 pPage->SetAutoLayout( pPage->GetAutoLayout(), sal_False, sal_False );
343 //////////////////////////////////////////////////////////////////////////////
345 UndoGeoObject::UndoGeoObject( SdrObject& rNewObj )
346 : SdrUndoGeoObj( rNewObj )
347 , mxPage( rNewObj.GetPage() )
348 , mxSdrObject( &rNewObj )
352 //---------------------------------------------------------------------
354 void UndoGeoObject::Undo()
356 DBG_ASSERT( mxSdrObject.is(), "sd::UndoGeoObject::Undo(), object already dead!" );
357 if( mxSdrObject.is() )
359 if( mxPage.is() )
361 ScopeLockGuard aGuard( static_cast< SdPage* >( mxPage.get() )->maLockAutoLayoutArrangement );
362 SdrUndoGeoObj::Undo();
364 else
366 SdrUndoGeoObj::Undo();
371 //---------------------------------------------------------------------
373 void UndoGeoObject::Redo()
375 DBG_ASSERT( mxSdrObject.is(), "sd::UndoGeoObject::Redo(), object already dead!" );
376 if( mxSdrObject.is() )
378 if( mxPage.is() )
380 ScopeLockGuard aGuard( static_cast< SdPage* >(mxPage.get())->maLockAutoLayoutArrangement );
381 SdrUndoGeoObj::Redo();
383 else
385 SdrUndoGeoObj::Redo();
390 //---------------------------------------------------------------------
392 //////////////////////////////////////////////////////////////////////////////
394 UndoAttrObject::UndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText )
395 : SdrUndoAttrObj( rObject, bStyleSheet1 ? sal_True : sal_False, bSaveText ? sal_True : sal_False )
396 , mxPage( rObject.GetPage() )
397 , mxSdrObject( &rObject )
401 //---------------------------------------------------------------------
403 void UndoAttrObject::Undo()
405 DBG_ASSERT( mxSdrObject.is(), "sd::UndoAttrObject::Undo(), object already dead!" );
406 if( mxSdrObject.is() )
408 if( mxPage.is() )
410 ScopeLockGuard aGuard( static_cast< SdPage* >( mxPage.get() )->maLockAutoLayoutArrangement );
411 SdrUndoAttrObj::Undo();
413 else
415 SdrUndoAttrObj::Undo();
420 //---------------------------------------------------------------------
422 void UndoAttrObject::Redo()
424 DBG_ASSERT( mxSdrObject.is(), "sd::UndoAttrObject::Redo(), object already dead!" );
425 if( mxSdrObject.is() )
427 if( mxPage.is() )
429 ScopeLockGuard aGuard( static_cast< SdPage* >( mxPage.get() )->maLockAutoLayoutArrangement );
430 SdrUndoAttrObj::Redo();
432 else
434 SdrUndoAttrObj::Redo();
439 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */