merge the formfield patch from ooo-build
[ooovba.git] / sd / source / core / undo / undoobjects.cxx
blob7d4c8b66003fb5ea7dc9890c2ce75e0bdea1ca6f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: undoobjects.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "undo/undoobjects.hxx"
35 #include "sdpage.hxx"
36 #include "CustomAnimationEffect.hxx"
37 #include "drawdoc.hxx"
38 #include "undoanim.hxx"
40 using namespace sd;
42 ///////////////////////////////////////////////////////////////////////
44 UndoRemovePresObjectImpl::UndoRemovePresObjectImpl( SdrObject& rObject )
45 : mpUndoUsercall(0)
46 , mpUndoAnimation(0)
47 , mpUndoPresObj(0)
49 SdPage* pPage = dynamic_cast< SdPage* >( rObject.GetPage() );
50 if( pPage )
52 if( pPage->IsPresObj(&rObject) )
53 mpUndoPresObj = new UndoObjectPresentationKind( rObject );
54 if( rObject.GetUserCall() )
55 mpUndoUsercall = new UndoObjectUserCall(rObject);
57 if( pPage->hasAnimationNode() )
59 com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape( rObject.getUnoShape(), com::sun::star::uno::UNO_QUERY );
60 if( pPage->getMainSequence()->hasEffect( xShape ) )
62 mpUndoAnimation = new UndoAnimation( static_cast< SdDrawDocument* >( pPage->GetModel() ), pPage );
68 //---------------------------------------------------------------------
70 UndoRemovePresObjectImpl::~UndoRemovePresObjectImpl()
72 delete mpUndoAnimation;
73 delete mpUndoPresObj;
74 delete mpUndoUsercall;
77 //---------------------------------------------------------------------
79 void UndoRemovePresObjectImpl::Undo()
81 if( mpUndoUsercall )
82 mpUndoUsercall->Undo();
83 if( mpUndoPresObj )
84 mpUndoPresObj->Undo();
85 if( mpUndoAnimation )
86 mpUndoAnimation->Undo();
89 //---------------------------------------------------------------------
91 void UndoRemovePresObjectImpl::Redo()
93 if( mpUndoAnimation )
94 mpUndoAnimation->Redo();
95 if( mpUndoPresObj )
96 mpUndoPresObj->Redo();
97 if( mpUndoUsercall )
98 mpUndoUsercall->Redo();
101 ///////////////////////////////////////////////////////////////////////
104 UndoRemoveObject::UndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect )
105 : SdrUndoRemoveObj( rObject, bOrdNumDirect ), UndoRemovePresObjectImpl( rObject )
106 , mxSdrObject(&rObject)
110 //---------------------------------------------------------------------
112 void UndoRemoveObject::Undo()
114 DBG_ASSERT( mxSdrObject.is(), "sd::UndoRemoveObject::Undo(), object already dead!" );
115 if( mxSdrObject.is() )
117 SdrUndoRemoveObj::Undo();
118 UndoRemovePresObjectImpl::Undo();
122 //---------------------------------------------------------------------
124 void UndoRemoveObject::Redo()
126 DBG_ASSERT( mxSdrObject.is(), "sd::UndoRemoveObject::Redo(), object already dead!" );
127 if( mxSdrObject.is() )
129 UndoRemovePresObjectImpl::Redo();
130 SdrUndoRemoveObj::Redo();
134 ///////////////////////////////////////////////////////////////////////
136 UndoDeleteObject::UndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect )
137 : SdrUndoDelObj( rObject, bOrdNumDirect )
138 , UndoRemovePresObjectImpl( rObject )
139 , mxSdrObject(&rObject)
143 //---------------------------------------------------------------------
145 void UndoDeleteObject::Undo()
147 DBG_ASSERT( mxSdrObject.is(), "sd::UndoDeleteObject::Undo(), object already dead!" );
148 if( mxSdrObject.is() )
150 SdrUndoDelObj::Undo();
151 UndoRemovePresObjectImpl::Undo();
155 //---------------------------------------------------------------------
157 void UndoDeleteObject::Redo()
159 DBG_ASSERT( mxSdrObject.is(), "sd::UndoDeleteObject::Redo(), object already dead!" );
160 if( mxSdrObject.is() )
162 UndoRemovePresObjectImpl::Redo();
163 SdrUndoDelObj::Redo();
167 ///////////////////////////////////////////////////////////////////////
169 UndoReplaceObject::UndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect )
170 : SdrUndoReplaceObj( rOldObject, rNewObject, bOrdNumDirect )
171 , UndoRemovePresObjectImpl( rOldObject )
172 , mxSdrObject( &rOldObject )
176 //---------------------------------------------------------------------
178 void UndoReplaceObject::Undo()
180 DBG_ASSERT( mxSdrObject.is(), "sd::UndoReplaceObject::Undo(), object already dead!" );
181 if( mxSdrObject.is() )
183 SdrUndoReplaceObj::Undo();
184 UndoRemovePresObjectImpl::Undo();
188 //---------------------------------------------------------------------
190 void UndoReplaceObject::Redo()
192 DBG_ASSERT( mxSdrObject.is(), "sd::UndoReplaceObject::Redo(), object already dead!" );
193 if( mxSdrObject.is() )
195 UndoRemovePresObjectImpl::Redo();
196 SdrUndoReplaceObj::Redo();
200 ///////////////////////////////////////////////////////////////////////
202 UndoObjectSetText::UndoObjectSetText( SdrObject& rObject, sal_Int32 nText )
203 : SdrUndoObjSetText( rObject, nText )
204 , mpUndoAnimation(0)
205 , mbNewEmptyPresObj(false)
206 , mxSdrObject( &rObject )
208 SdPage* pPage = dynamic_cast< SdPage* >( rObject.GetPage() );
209 if( pPage && pPage->hasAnimationNode() )
211 com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape( rObject.getUnoShape(), com::sun::star::uno::UNO_QUERY );
212 if( pPage->getMainSequence()->hasEffect( xShape ) )
214 mpUndoAnimation = new UndoAnimation( static_cast< SdDrawDocument* >( pPage->GetModel() ), pPage );
219 //---------------------------------------------------------------------
221 UndoObjectSetText::~UndoObjectSetText()
223 delete mpUndoAnimation;
226 //---------------------------------------------------------------------
228 void UndoObjectSetText::Undo()
230 DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectSetText::Undo(), object already dead!" );
231 if( mxSdrObject.is() )
233 mbNewEmptyPresObj = mxSdrObject->IsEmptyPresObj() ? true : false;
234 SdrUndoObjSetText::Undo();
235 if( mpUndoAnimation )
236 mpUndoAnimation->Undo();
240 //---------------------------------------------------------------------
242 void UndoObjectSetText::Redo()
244 DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectSetText::Redo(), object already dead!" );
245 if( mxSdrObject.is() )
247 if( mpUndoAnimation )
248 mpUndoAnimation->Redo();
249 SdrUndoObjSetText::Redo();
250 mxSdrObject->SetEmptyPresObj(mbNewEmptyPresObj ? TRUE : FALSE );
254 //////////////////////////////////////////////////////////////////////////////
255 // Undo for SdrObject::SetUserCall()
257 UndoObjectUserCall::UndoObjectUserCall(SdrObject& rObject)
258 : SdrUndoObj(rObject)
259 , mpOldUserCall((SdPage*)rObject.GetUserCall())
260 , mpNewUserCall(0)
261 , mxSdrObject( &rObject )
265 //---------------------------------------------------------------------
267 void UndoObjectUserCall::Undo()
269 DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectUserCall::Undo(), object already dead!" );
270 if( mxSdrObject.is() )
272 mpNewUserCall = mxSdrObject->GetUserCall();
273 mxSdrObject->SetUserCall(mpOldUserCall);
277 //---------------------------------------------------------------------
279 void UndoObjectUserCall::Redo()
281 DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectUserCall::Redo(), object already dead!" );
282 if( mxSdrObject.is() )
284 mxSdrObject->SetUserCall(mpNewUserCall);
288 //////////////////////////////////////////////////////////////////////////////
289 // Undo for SdPage::InsertPresObj() and SdPage::RemovePresObj()
291 UndoObjectPresentationKind::UndoObjectPresentationKind(SdrObject& rObject)
292 : SdrUndoObj(rObject)
293 , meOldKind(PRESOBJ_NONE)
294 , meNewKind(PRESOBJ_NONE)
295 , mxPage( rObject.GetPage() )
296 , mxSdrObject( &rObject )
298 DBG_ASSERT( mxPage.is(), "sd::UndoObjectPresentationKind::UndoObjectPresentationKind(), does not work for shapes without a slide!" );
300 if( mxPage.is() )
301 meOldKind = static_cast< SdPage* >( mxPage.get() )->GetPresObjKind( &rObject );
304 //---------------------------------------------------------------------
306 void UndoObjectPresentationKind::Undo()
308 if( mxPage.is() && mxSdrObject.is() )
310 SdPage* pPage = static_cast< SdPage* >( mxPage.get() );
311 meNewKind = pPage->GetPresObjKind( mxSdrObject.get() );
312 if( meNewKind != PRESOBJ_NONE )
313 pPage->RemovePresObj( mxSdrObject.get() );
314 if( meOldKind != PRESOBJ_NONE )
315 pPage->InsertPresObj( mxSdrObject.get(), meOldKind );
319 //---------------------------------------------------------------------
321 void UndoObjectPresentationKind::Redo()
323 if( mxPage.is() && mxSdrObject.is() )
325 SdPage* pPage = static_cast< SdPage* >( mxPage.get() );
326 if( meOldKind != PRESOBJ_NONE )
327 pPage->RemovePresObj( mxSdrObject.get() );
328 if( meNewKind != PRESOBJ_NONE )
329 pPage->InsertPresObj( mxSdrObject.get(), meNewKind );
333 //////////////////////////////////////////////////////////////////////////////
335 UndoAutoLayoutPosAndSize::UndoAutoLayoutPosAndSize( SdPage& rPage )
336 : mxPage( &rPage )
340 //---------------------------------------------------------------------
342 void UndoAutoLayoutPosAndSize::Undo()
344 // do nothing
347 //---------------------------------------------------------------------
349 void UndoAutoLayoutPosAndSize::Redo()
351 SdPage* pPage = static_cast< SdPage* >( mxPage.get() );
352 if( pPage )
353 pPage->SetAutoLayout( pPage->GetAutoLayout(), FALSE, FALSE );
356 //////////////////////////////////////////////////////////////////////////////
358 UndoGeoObject::UndoGeoObject( SdrObject& rNewObj )
359 : SdrUndoGeoObj( rNewObj )
360 , mxPage( rNewObj.GetPage() )
361 , mxSdrObject( &rNewObj )
365 //---------------------------------------------------------------------
367 void UndoGeoObject::Undo()
369 DBG_ASSERT( mxSdrObject.is(), "sd::UndoGeoObject::Undo(), object already dead!" );
370 if( mxSdrObject.is() )
372 if( mxPage.is() )
374 ScopeLockGuard aGuard( static_cast< SdPage* >( mxPage.get() )->maLockAutoLayoutArrangement );
375 SdrUndoGeoObj::Undo();
377 else
379 SdrUndoGeoObj::Undo();
384 //---------------------------------------------------------------------
386 void UndoGeoObject::Redo()
388 DBG_ASSERT( mxSdrObject.is(), "sd::UndoGeoObject::Redo(), object already dead!" );
389 if( mxSdrObject.is() )
391 if( mxPage.is() )
393 ScopeLockGuard aGuard( static_cast< SdPage* >(mxPage.get())->maLockAutoLayoutArrangement );
394 SdrUndoGeoObj::Redo();
396 else
398 SdrUndoGeoObj::Redo();
403 //---------------------------------------------------------------------
405 //////////////////////////////////////////////////////////////////////////////
407 UndoAttrObject::UndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText )
408 : SdrUndoAttrObj( rObject, bStyleSheet1 ? TRUE : FALSE, bSaveText ? TRUE : FALSE )
409 , mxPage( rObject.GetPage() )
410 , mxSdrObject( &rObject )
414 //---------------------------------------------------------------------
416 void UndoAttrObject::Undo()
418 DBG_ASSERT( mxSdrObject.is(), "sd::UndoAttrObject::Undo(), object already dead!" );
419 if( mxSdrObject.is() )
421 if( mxPage.is() )
423 ScopeLockGuard aGuard( static_cast< SdPage* >( mxPage.get() )->maLockAutoLayoutArrangement );
424 SdrUndoAttrObj::Undo();
426 else
428 SdrUndoAttrObj::Undo();
433 //---------------------------------------------------------------------
435 void UndoAttrObject::Redo()
437 DBG_ASSERT( mxSdrObject.is(), "sd::UndoAttrObject::Redo(), object already dead!" );
438 if( mxSdrObject.is() )
440 if( mxPage.is() )
442 ScopeLockGuard aGuard( static_cast< SdPage* >( mxPage.get() )->maLockAutoLayoutArrangement );
443 SdrUndoAttrObj::Redo();
445 else
447 SdrUndoAttrObj::Redo();