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