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