LibreOffice Module sd (master) 1
undoobjects.cxx
Go to the documentation of this file.
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#include <tools/debug.hxx>
21#include <undo/undoobjects.hxx>
22#include <sdpage.hxx>
24#include <drawdoc.hxx>
25#include <undoanim.hxx>
26#include <ViewShell.hxx>
27#include <ViewShellBase.hxx>
28#include <DrawDocShell.hxx>
29
30using namespace sd;
31
33 : mpDoc(pSdDrawDocument),
34 mnViewShellId(-1)
35{
36 sd::DrawDocShell* pDocShell = pSdDrawDocument ? pSdDrawDocument->GetDocSh() : nullptr;
37 sd::ViewShell* pViewShell = pDocShell ? pDocShell->GetViewShell() : nullptr;
38 if (pViewShell)
40}
41
43{
44 return mnViewShellId;
45}
46
47UndoRemovePresObjectImpl::UndoRemovePresObjectImpl( SdrObject& rObject )
48{
49 SdPage* pPage = dynamic_cast< SdPage* >( rObject.getSdrPageFromSdrObject() );
50 if( !pPage )
51 return;
52
53 if( pPage->IsPresObj(&rObject) )
54 mpUndoPresObj.reset( new UndoObjectPresentationKind( rObject ) );
55 if( rObject.GetUserCall() )
56 mpUndoUsercall.reset( new UndoObjectUserCall(rObject) );
57
58 if( pPage->hasAnimationNode() )
59 {
60 css::uno::Reference< css::drawing::XShape > xShape( rObject.getUnoShape(), css::uno::UNO_QUERY );
61 if( pPage->getMainSequence()->hasEffect( xShape ) )
62 {
63 mpUndoAnimation.reset(
64 new UndoAnimation( // TTTT may use ref? Or just *SdrPage?
65 static_cast< SdDrawDocument* >(&pPage->getSdrModelFromSdrPage()),
66 pPage));
67 }
68 }
69}
70
72{
73}
74
76{
77 if( mpUndoUsercall )
78 mpUndoUsercall->Undo();
79 if( mpUndoPresObj )
80 mpUndoPresObj->Undo();
81 if( mpUndoAnimation )
82 mpUndoAnimation->Undo();
83}
84
86{
87 if( mpUndoAnimation )
88 mpUndoAnimation->Redo();
89 if( mpUndoPresObj )
90 mpUndoPresObj->Redo();
91 if( mpUndoUsercall )
92 mpUndoUsercall->Redo();
93}
94
96: SdrUndoRemoveObj( rObject ), UndoRemovePresObjectImpl( rObject )
97, mxSdrObject(&rObject)
98{
99}
100
102{
103 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoRemoveObject::Undo(), object already dead!" );
104 if( mxSdrObject.get().is() )
105 {
108 }
109}
110
112{
113 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoRemoveObject::Redo(), object already dead!" );
114 if( mxSdrObject.get().is() )
115 {
118 }
119}
120
121UndoDeleteObject::UndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect )
122: SdrUndoDelObj( rObject, bOrdNumDirect )
123, UndoRemovePresObjectImpl( rObject )
124, mxSdrObject(&rObject)
125{
126}
127
129{
130 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoDeleteObject::Undo(), object already dead!" );
131 if( mxSdrObject.get().is() )
132 {
135 }
136}
137
139{
140 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoDeleteObject::Redo(), object already dead!" );
141 if( mxSdrObject.get().is() )
142 {
145 }
146}
147
149: SdrUndoReplaceObj( rOldObject, rNewObject )
150, UndoRemovePresObjectImpl( rOldObject )
151, mxSdrObject( &rOldObject )
152{
153}
154
156{
157 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoReplaceObject::Undo(), object already dead!" );
158 if( mxSdrObject.get().is() )
159 {
162 }
163}
164
166{
167 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoReplaceObject::Redo(), object already dead!" );
168 if( mxSdrObject.get().is() )
169 {
172 }
173}
174
176: SdrUndoObjSetText( rObject, nText )
177, mbNewEmptyPresObj(false)
178, mxSdrObject( &rObject )
179{
180 SdPage* pPage = dynamic_cast< SdPage* >( rObject.getSdrPageFromSdrObject() );
181 if( pPage && pPage->hasAnimationNode() )
182 {
183 css::uno::Reference< css::drawing::XShape > xShape( rObject.getUnoShape(), css::uno::UNO_QUERY );
184 if( pPage->getMainSequence()->hasEffect( xShape ) )
185 {
186 mpUndoAnimation.reset(
187 new UndoAnimation(
188 static_cast< SdDrawDocument* >(&pPage->getSdrModelFromSdrPage()),
189 pPage));
190 }
191 }
192}
193
195{
196}
197
199{
200 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoObjectSetText::Undo(), object already dead!" );
201 if( auto pSdrObject = mxSdrObject.get() )
202 {
203 mbNewEmptyPresObj = pSdrObject->IsEmptyPresObj();
205 if( mpUndoAnimation )
206 mpUndoAnimation->Undo();
207 }
208}
209
211{
212 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoObjectSetText::Redo(), object already dead!" );
213 if( auto pSdrObject = mxSdrObject.get() )
214 {
215 if( mpUndoAnimation )
216 mpUndoAnimation->Redo();
218 pSdrObject->SetEmptyPresObj(mbNewEmptyPresObj);
219 }
220}
221
222// Undo for SdrObject::SetUserCall()
223
225: SdrUndoObj(rObject)
226, mpOldUserCall(static_cast<SdPage*>(rObject.GetUserCall()))
227, mpNewUserCall(nullptr)
228, mxSdrObject( &rObject )
229{
230}
231
233{
234 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoObjectUserCall::Undo(), object already dead!" );
235 if( auto pSdrObject = mxSdrObject.get() )
236 {
237 mpNewUserCall = pSdrObject->GetUserCall();
238 pSdrObject->SetUserCall(mpOldUserCall);
239 }
240}
241
243{
244 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoObjectUserCall::Redo(), object already dead!" );
245 if( auto pSdrObject = mxSdrObject.get() )
246 {
247 pSdrObject->SetUserCall(mpNewUserCall);
248 }
249}
250
251// Undo for SdPage::InsertPresObj() and SdPage::RemovePresObj()
252
254: SdrUndoObj(rObject)
255, meOldKind(PresObjKind::NONE)
256, meNewKind(PresObjKind::NONE)
257, mxPage( static_cast<SdPage*>(rObject.getSdrPageFromSdrObject()) )
258, mxSdrObject( &rObject )
259{
260 DBG_ASSERT( mxPage.get(), "sd::UndoObjectPresentationKind::UndoObjectPresentationKind(), does not work for shapes without a slide!" );
261
262 if( auto pPage = mxPage.get() )
263 meOldKind = pPage->GetPresObjKind( &rObject );
264}
265
267{
268 if( auto pSdrObject = mxSdrObject.get() )
269 {
270 if( rtl::Reference<SdPage> pPage = mxPage.get() )
271 {
272 meNewKind = pPage->GetPresObjKind( pSdrObject.get() );
274 pPage->RemovePresObj( pSdrObject.get() );
276 pPage->InsertPresObj( pSdrObject.get(), meOldKind );
277 }
278 }
279}
280
282{
283 if( auto pSdrObject = mxSdrObject.get() )
284 {
285 if( rtl::Reference<SdPage> pPage = mxPage.get() )
286 {
288 pPage->RemovePresObj( pSdrObject.get() );
290 pPage->InsertPresObj( pSdrObject.get(), meNewKind );
291 }
292 }
293}
294
296: mxPage( &rPage )
297{
298}
299
301{
302 // do nothing
303}
304
306{
308 if( pPage )
309 pPage->SetAutoLayout( pPage->GetAutoLayout() );
310}
311
313: SdrUndoGeoObj( rNewObj )
314, mxPage( static_cast<SdPage*>(rNewObj.getSdrPageFromSdrObject()) )
315, mxSdrObject( &rNewObj )
316{
317}
318
320{
321 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoGeoObject::Undo(), object already dead!" );
322 if( auto pSdrObject = mxSdrObject.get() )
323 {
324 if( auto pPage = mxPage.get() )
325 {
326 ScopeLockGuard aGuard( pPage->maLockAutoLayoutArrangement );
328 }
329 else
330 {
332 }
333 }
334}
335
337{
338 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoGeoObject::Redo(), object already dead!" );
339 if( auto pSdrObject = mxSdrObject.get() )
340 {
341 if( auto pPage = mxPage.get() )
342 {
343 ScopeLockGuard aGuard( pPage->maLockAutoLayoutArrangement );
345 }
346 else
347 {
349 }
350 }
351}
352
353UndoAttrObject::UndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText )
354: SdrUndoAttrObj( rObject, bStyleSheet1, bSaveText )
355, mxPage( static_cast<SdPage*>(rObject.getSdrPageFromSdrObject()) )
356, mxSdrObject( &rObject )
357{
358}
359
361{
362 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoAttrObject::Undo(), object already dead!" );
363 if( auto pSdrObject = mxSdrObject.get() )
364 {
365 if( auto pPage = mxPage.get() )
366 {
367 ScopeLockGuard aGuard( pPage->maLockAutoLayoutArrangement );
369 }
370 else
371 {
373 }
374 }
375}
376
378{
379 DBG_ASSERT( mxSdrObject.get().is(), "sd::UndoAttrObject::Redo(), object already dead!" );
380 if( auto pSdrObject = mxSdrObject.get() )
381 {
382 if( auto pPage = mxPage.get() )
383 {
384 ScopeLockGuard aGuard( pPage->maLockAutoLayoutArrangement );
386 }
387 else
388 {
390 }
391 }
392}
393
394/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPRIVATE::sd::DrawDocShell * GetDocSh() const
Definition: drawdoc.hxx:242
bool IsPresObj(const SdrObject *pObj)
Definition: sdpage.cxx:2322
std::shared_ptr< sd::MainSequence > const & getMainSequence()
returns a helper class to manipulate effects inside the main sequence
bool hasAnimationNode() const
quick check if this slide has an animation node.
ViewShellId GetViewShellId() const override
See SfxUndoAction::GetViewShellId().
Definition: undoobjects.cxx:42
ViewShellId mnViewShellId
Definition: sdundo.hxx:40
SdUndoAction(SdDrawDocument *pSdDrawDocument)
Definition: undoobjects.cxx:32
SdrObjUserCall * GetUserCall() const
virtual css::uno::Reference< css::drawing::XShape > getUnoShape()
SdrPage * getSdrPageFromSdrObject() const
SdrModel & getSdrModelFromSdrPage() const
virtual void Undo() override
virtual void Redo() override
virtual void Redo() override
virtual void Undo() override
virtual void Redo() override
virtual void Undo() override
virtual void Undo() override
virtual void Redo() override
virtual void Redo() override
virtual void Undo() override
virtual void Redo() override
virtual void Undo() override
ViewShellId GetViewShellId() const override
sd::ViewShell * GetViewShell()
::unotools::WeakReference< SdPage > mxPage
virtual void Undo() override
UndoAttrObject(SdrObject &rObject, bool bStyleSheet1, bool bSaveText)
virtual void Redo() override
::unotools::WeakReference< SdrObject > mxSdrObject
virtual void Redo() override
::unotools::WeakReference< SdPage > mxPage
virtual void Undo() override
UndoAutoLayoutPosAndSize(SdPage &rPage)
virtual void Redo() override
UndoDeleteObject(SdrObject &rObject, bool bOrdNumDirect)
::unotools::WeakReference< SdrObject > mxSdrObject
Definition: undoobjects.hxx:69
virtual void Undo() override
::unotools::WeakReference< SdPage > mxPage
::unotools::WeakReference< SdrObject > mxSdrObject
virtual void Undo() override
UndoGeoObject(SdrObject &rNewObj)
virtual void Redo() override
UndoObjectPresentationKind(SdrObject &rObject)
virtual void Undo() override
::unotools::WeakReference< SdPage > mxPage
virtual void Redo() override
::unotools::WeakReference< SdrObject > mxSdrObject
std::unique_ptr< SfxUndoAction > mpUndoAnimation
Definition: undoobjects.hxx:94
virtual void Undo() override
virtual void Redo() override
::unotools::WeakReference< SdrObject > mxSdrObject
Definition: undoobjects.hxx:96
UndoObjectSetText(SdrObject &rNewObj, sal_Int32 nText)
virtual ~UndoObjectSetText() override
UndoObjectUserCall(SdrObject &rNewObj)
virtual void Undo() override
SdrObjUserCall * mpOldUserCall
SdrObjUserCall * mpNewUserCall
virtual void Redo() override
::unotools::WeakReference< SdrObject > mxSdrObject
UndoRemoveObject(SdrObject &rObject)
Definition: undoobjects.cxx:95
virtual void Undo() override
::unotools::WeakReference< SdrObject > mxSdrObject
Definition: undoobjects.hxx:57
virtual void Redo() override
std::unique_ptr< SfxUndoAction > mpUndoUsercall
Definition: undoobjects.hxx:43
std::unique_ptr< SfxUndoAction > mpUndoAnimation
Definition: undoobjects.hxx:44
std::unique_ptr< SfxUndoAction > mpUndoPresObj
Definition: undoobjects.hxx:45
::unotools::WeakReference< SdrObject > mxSdrObject
Definition: undoobjects.hxx:81
virtual void Redo() override
UndoReplaceObject(SdrObject &rOldObject, SdrObject &rNewObject)
virtual void Undo() override
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
SD_DLLPUBLIC ViewShellBase & GetViewShellBase() const
Definition: viewshel.cxx:1397
rtl::Reference< interface_type > SAL_CALL get() const
SwContact * GetUserCall(const SdrObject *)
#define DBG_ASSERT(sCon, aError)
NONE
PresObjKind
Definition: pres.hxx:22