xref: /AOO41X/main/sd/source/core/undo/undoobjects.cxx (revision 79aad27f7f29270c03e208e3d687e8e3850af11d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "undo/undoobjects.hxx"
28 #include "sdpage.hxx"
29 #include "CustomAnimationEffect.hxx"
30 #include "drawdoc.hxx"
31 #include "undoanim.hxx"
32 
33 using namespace sd;
34 
35 ///////////////////////////////////////////////////////////////////////
36 
UndoRemovePresObjectImpl(SdrObject & rObject)37 UndoRemovePresObjectImpl::UndoRemovePresObjectImpl( SdrObject& rObject )
38 : mpUndoUsercall(0)
39 , mpUndoAnimation(0)
40 , mpUndoPresObj(0)
41 {
42     SdPage* pPage = dynamic_cast< SdPage* >( rObject.GetPage() );
43     if( pPage )
44     {
45         if( pPage->IsPresObj(&rObject) )
46             mpUndoPresObj = new UndoObjectPresentationKind( rObject );
47         if( rObject.GetUserCall() )
48             mpUndoUsercall = new UndoObjectUserCall(rObject);
49 
50         if( pPage->hasAnimationNode() )
51         {
52             com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape( rObject.getUnoShape(), com::sun::star::uno::UNO_QUERY );
53             if( pPage->getMainSequence()->hasEffect( xShape ) )
54             {
55                 mpUndoAnimation = new UndoAnimation( static_cast< SdDrawDocument* >( pPage->GetModel() ), pPage );
56             }
57         }
58     }
59 }
60 
61 //---------------------------------------------------------------------
62 
~UndoRemovePresObjectImpl()63 UndoRemovePresObjectImpl::~UndoRemovePresObjectImpl()
64 {
65     delete mpUndoAnimation;
66     delete mpUndoPresObj;
67     delete mpUndoUsercall;
68 }
69 
70 //---------------------------------------------------------------------
71 
Undo()72 void UndoRemovePresObjectImpl::Undo()
73 {
74     if( mpUndoUsercall )
75         mpUndoUsercall->Undo();
76     if( mpUndoPresObj )
77         mpUndoPresObj->Undo();
78     if( mpUndoAnimation )
79         mpUndoAnimation->Undo();
80 }
81 
82 //---------------------------------------------------------------------
83 
Redo()84 void UndoRemovePresObjectImpl::Redo()
85 {
86     if( mpUndoAnimation )
87         mpUndoAnimation->Redo();
88     if( mpUndoPresObj )
89         mpUndoPresObj->Redo();
90     if( mpUndoUsercall )
91         mpUndoUsercall->Redo();
92 }
93 
94 ///////////////////////////////////////////////////////////////////////
95 
96 
UndoRemoveObject(SdrObject & rObject,bool bOrdNumDirect)97 UndoRemoveObject::UndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect )
98 : SdrUndoRemoveObj( rObject, bOrdNumDirect ), UndoRemovePresObjectImpl( rObject )
99 , mxSdrObject(&rObject)
100 {
101 }
102 
103 //---------------------------------------------------------------------
104 
Undo()105 void UndoRemoveObject::Undo()
106 {
107     DBG_ASSERT( mxSdrObject.is(), "sd::UndoRemoveObject::Undo(), object already dead!" );
108     if( mxSdrObject.is() )
109     {
110         SdrUndoRemoveObj::Undo();
111         UndoRemovePresObjectImpl::Undo();
112     }
113 }
114 
115 //---------------------------------------------------------------------
116 
Redo()117 void UndoRemoveObject::Redo()
118 {
119     DBG_ASSERT( mxSdrObject.is(), "sd::UndoRemoveObject::Redo(), object already dead!" );
120     if( mxSdrObject.is() )
121     {
122         UndoRemovePresObjectImpl::Redo();
123         SdrUndoRemoveObj::Redo();
124     }
125 }
126 
127 ///////////////////////////////////////////////////////////////////////
128 
UndoDeleteObject(SdrObject & rObject,bool bOrdNumDirect)129 UndoDeleteObject::UndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect )
130 : SdrUndoDelObj( rObject, bOrdNumDirect )
131 , UndoRemovePresObjectImpl( rObject )
132 , mxSdrObject(&rObject)
133 {
134 }
135 
136 //---------------------------------------------------------------------
137 
Undo()138 void UndoDeleteObject::Undo()
139 {
140     DBG_ASSERT( mxSdrObject.is(), "sd::UndoDeleteObject::Undo(), object already dead!" );
141     if( mxSdrObject.is() )
142     {
143         SdrUndoDelObj::Undo();
144         UndoRemovePresObjectImpl::Undo();
145     }
146 }
147 
148 //---------------------------------------------------------------------
149 
Redo()150 void UndoDeleteObject::Redo()
151 {
152     DBG_ASSERT( mxSdrObject.is(), "sd::UndoDeleteObject::Redo(), object already dead!" );
153     if( mxSdrObject.is() )
154     {
155         UndoRemovePresObjectImpl::Redo();
156         SdrUndoDelObj::Redo();
157     }
158 }
159 
160 ///////////////////////////////////////////////////////////////////////
161 
UndoReplaceObject(SdrObject & rOldObject,SdrObject & rNewObject,bool bOrdNumDirect)162 UndoReplaceObject::UndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect )
163 : SdrUndoReplaceObj( rOldObject, rNewObject, bOrdNumDirect )
164 , UndoRemovePresObjectImpl( rOldObject )
165 , mxSdrObject( &rOldObject )
166 {
167 }
168 
169 //---------------------------------------------------------------------
170 
Undo()171 void UndoReplaceObject::Undo()
172 {
173     DBG_ASSERT( mxSdrObject.is(), "sd::UndoReplaceObject::Undo(), object already dead!" );
174     if( mxSdrObject.is() )
175     {
176         SdrUndoReplaceObj::Undo();
177         UndoRemovePresObjectImpl::Undo();
178     }
179 }
180 
181 //---------------------------------------------------------------------
182 
Redo()183 void UndoReplaceObject::Redo()
184 {
185     DBG_ASSERT( mxSdrObject.is(), "sd::UndoReplaceObject::Redo(), object already dead!" );
186     if( mxSdrObject.is() )
187     {
188         UndoRemovePresObjectImpl::Redo();
189         SdrUndoReplaceObj::Redo();
190     }
191 }
192 
193 ///////////////////////////////////////////////////////////////////////
194 
UndoObjectSetText(SdrObject & rObject,sal_Int32 nText)195 UndoObjectSetText::UndoObjectSetText( SdrObject& rObject, sal_Int32 nText )
196 : SdrUndoObjSetText( rObject, nText )
197 , mpUndoAnimation(0)
198 , mbNewEmptyPresObj(false)
199 , mxSdrObject( &rObject )
200 {
201     SdPage* pPage = dynamic_cast< SdPage* >( rObject.GetPage() );
202     if( pPage && pPage->hasAnimationNode() )
203     {
204         com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape( rObject.getUnoShape(), com::sun::star::uno::UNO_QUERY );
205         if( pPage->getMainSequence()->hasEffect( xShape ) )
206         {
207             mpUndoAnimation = new UndoAnimation( static_cast< SdDrawDocument* >( pPage->GetModel() ), pPage );
208         }
209     }
210 }
211 
212 //---------------------------------------------------------------------
213 
~UndoObjectSetText()214 UndoObjectSetText::~UndoObjectSetText()
215 {
216     delete mpUndoAnimation;
217 }
218 
219 //---------------------------------------------------------------------
220 
Undo()221 void UndoObjectSetText::Undo()
222 {
223     DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectSetText::Undo(), object already dead!" );
224     if( mxSdrObject.is() )
225     {
226         mbNewEmptyPresObj = mxSdrObject->IsEmptyPresObj() ? true : false;
227         SdrUndoObjSetText::Undo();
228         if( mpUndoAnimation )
229             mpUndoAnimation->Undo();
230     }
231 }
232 
233 //---------------------------------------------------------------------
234 
Redo()235 void UndoObjectSetText::Redo()
236 {
237     DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectSetText::Redo(), object already dead!" );
238     if( mxSdrObject.is() )
239     {
240         if( mpUndoAnimation )
241             mpUndoAnimation->Redo();
242         SdrUndoObjSetText::Redo();
243         mxSdrObject->SetEmptyPresObj(mbNewEmptyPresObj ? sal_True : sal_False );
244     }
245 }
246 
247 //////////////////////////////////////////////////////////////////////////////
248 // Undo for SdrObject::SetUserCall()
249 
UndoObjectUserCall(SdrObject & rObject)250 UndoObjectUserCall::UndoObjectUserCall(SdrObject& rObject)
251 :   SdrUndoObj(rObject)
252 ,   mpOldUserCall((SdPage*)rObject.GetUserCall())
253 ,   mpNewUserCall(0)
254 ,   mxSdrObject( &rObject )
255 {
256 }
257 
258 //---------------------------------------------------------------------
259 
Undo()260 void UndoObjectUserCall::Undo()
261 {
262     DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectUserCall::Undo(), object already dead!" );
263     if( mxSdrObject.is() )
264     {
265         mpNewUserCall = mxSdrObject->GetUserCall();
266         mxSdrObject->SetUserCall(mpOldUserCall);
267     }
268 }
269 
270 //---------------------------------------------------------------------
271 
Redo()272 void UndoObjectUserCall::Redo()
273 {
274     DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectUserCall::Redo(), object already dead!" );
275     if( mxSdrObject.is() )
276     {
277         mxSdrObject->SetUserCall(mpNewUserCall);
278     }
279 }
280 
281 //////////////////////////////////////////////////////////////////////////////
282 // Undo for SdPage::InsertPresObj() and SdPage::RemovePresObj()
283 
UndoObjectPresentationKind(SdrObject & rObject)284 UndoObjectPresentationKind::UndoObjectPresentationKind(SdrObject& rObject)
285 :   SdrUndoObj(rObject)
286 ,   meOldKind(PRESOBJ_NONE)
287 ,   meNewKind(PRESOBJ_NONE)
288 ,   mxPage( rObject.GetPage() )
289 ,   mxSdrObject( &rObject )
290 {
291     DBG_ASSERT( mxPage.is(), "sd::UndoObjectPresentationKind::UndoObjectPresentationKind(), does not work for shapes without a slide!" );
292 
293     if( mxPage.is() )
294         meOldKind = static_cast< SdPage* >( mxPage.get() )->GetPresObjKind( &rObject );
295 }
296 
297 //---------------------------------------------------------------------
298 
Undo()299 void UndoObjectPresentationKind::Undo()
300 {
301     if( mxPage.is() && mxSdrObject.is() )
302     {
303         SdPage* pPage = static_cast< SdPage* >( mxPage.get() );
304         meNewKind =  pPage->GetPresObjKind( mxSdrObject.get() );
305         if( meNewKind != PRESOBJ_NONE )
306             pPage->RemovePresObj( mxSdrObject.get() );
307         if( meOldKind != PRESOBJ_NONE )
308             pPage->InsertPresObj( mxSdrObject.get(), meOldKind );
309     }
310 }
311 
312 //---------------------------------------------------------------------
313 
Redo()314 void UndoObjectPresentationKind::Redo()
315 {
316     if( mxPage.is() && mxSdrObject.is() )
317     {
318         SdPage* pPage = static_cast< SdPage* >( mxPage.get() );
319         if( meOldKind != PRESOBJ_NONE )
320             pPage->RemovePresObj( mxSdrObject.get() );
321         if( meNewKind != PRESOBJ_NONE )
322             pPage->InsertPresObj( mxSdrObject.get(), meNewKind );
323     }
324 }
325 
326 //////////////////////////////////////////////////////////////////////////////
327 
UndoAutoLayoutPosAndSize(SdPage & rPage)328 UndoAutoLayoutPosAndSize::UndoAutoLayoutPosAndSize( SdPage& rPage )
329 : mxPage( &rPage )
330 {
331 }
332 
333 //---------------------------------------------------------------------
334 
Undo()335 void UndoAutoLayoutPosAndSize::Undo()
336 {
337     // do nothing
338 }
339 
340 //---------------------------------------------------------------------
341 
Redo()342 void UndoAutoLayoutPosAndSize::Redo()
343 {
344     SdPage* pPage = static_cast< SdPage* >( mxPage.get() );
345     if( pPage )
346         pPage->SetAutoLayout( pPage->GetAutoLayout(), sal_False, sal_False );
347 }
348 
349 //////////////////////////////////////////////////////////////////////////////
350 
UndoGeoObject(SdrObject & rNewObj)351 UndoGeoObject::UndoGeoObject( SdrObject& rNewObj )
352 : SdrUndoGeoObj( rNewObj )
353 , mxPage( rNewObj.GetPage() )
354 , mxSdrObject( &rNewObj )
355 {
356 }
357 
358 //---------------------------------------------------------------------
359 
Undo()360 void UndoGeoObject::Undo()
361 {
362     DBG_ASSERT( mxSdrObject.is(), "sd::UndoGeoObject::Undo(), object already dead!" );
363     if( mxSdrObject.is() )
364     {
365         if( mxPage.is() )
366         {
367             ScopeLockGuard aGuard( static_cast< SdPage* >( mxPage.get() )->maLockAutoLayoutArrangement );
368             SdrUndoGeoObj::Undo();
369         }
370         else
371         {
372             SdrUndoGeoObj::Undo();
373         }
374     }
375 }
376 
377 //---------------------------------------------------------------------
378 
Redo()379 void UndoGeoObject::Redo()
380 {
381     DBG_ASSERT( mxSdrObject.is(), "sd::UndoGeoObject::Redo(), object already dead!" );
382     if( mxSdrObject.is() )
383     {
384         if( mxPage.is() )
385         {
386             ScopeLockGuard aGuard( static_cast< SdPage* >(mxPage.get())->maLockAutoLayoutArrangement );
387             SdrUndoGeoObj::Redo();
388         }
389         else
390         {
391             SdrUndoGeoObj::Redo();
392         }
393     }
394 }
395 
396 //---------------------------------------------------------------------
397 
398 //////////////////////////////////////////////////////////////////////////////
399 
UndoAttrObject(SdrObject & rObject,bool bStyleSheet1,bool bSaveText)400 UndoAttrObject::UndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText )
401 : SdrUndoAttrObj( rObject, bStyleSheet1 ? sal_True : sal_False, bSaveText ? sal_True : sal_False )
402 , mxPage( rObject.GetPage() )
403 , mxSdrObject( &rObject )
404 {
405 }
406 
407 //---------------------------------------------------------------------
408 
Undo()409 void UndoAttrObject::Undo()
410 {
411     DBG_ASSERT( mxSdrObject.is(), "sd::UndoAttrObject::Undo(), object already dead!" );
412     if( mxSdrObject.is() )
413     {
414         if( mxPage.is() )
415         {
416             ScopeLockGuard aGuard( static_cast< SdPage* >( mxPage.get() )->maLockAutoLayoutArrangement );
417             SdrUndoAttrObj::Undo();
418         }
419         else
420         {
421             SdrUndoAttrObj::Undo();
422         }
423     }
424 }
425 
426 //---------------------------------------------------------------------
427 
Redo()428 void UndoAttrObject::Redo()
429 {
430     DBG_ASSERT( mxSdrObject.is(), "sd::UndoAttrObject::Redo(), object already dead!" );
431     if( mxSdrObject.is() )
432     {
433         if( mxPage.is() )
434         {
435             ScopeLockGuard aGuard( static_cast< SdPage* >( mxPage.get() )->maLockAutoLayoutArrangement );
436             SdrUndoAttrObj::Redo();
437         }
438         else
439         {
440             SdrUndoAttrObj::Redo();
441         }
442     }
443 }
444