LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sd / source / core / undo / undoobjects.cxx
blobf586dac21f64be8682567ba047f1729e1b15c0a4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/debug.hxx>
21 #include <undo/undoobjects.hxx>
22 #include <sdpage.hxx>
23 #include <CustomAnimationEffect.hxx>
24 #include <drawdoc.hxx>
25 #include <undoanim.hxx>
26 #include <ViewShell.hxx>
27 #include <ViewShellBase.hxx>
28 #include <DrawDocShell.hxx>
30 using namespace sd;
32 SdUndoAction::SdUndoAction(SdDrawDocument* pSdDrawDocument)
33 : mpDoc(pSdDrawDocument),
34 mnViewShellId(-1)
36 sd::DrawDocShell* pDocShell = pSdDrawDocument ? pSdDrawDocument->GetDocSh() : nullptr;
37 sd::ViewShell* pViewShell = pDocShell ? pDocShell->GetViewShell() : nullptr;
38 if (pViewShell)
39 mnViewShellId = pViewShell->GetViewShellBase().GetViewShellId();
42 ViewShellId SdUndoAction::GetViewShellId() const
44 return mnViewShellId;
47 UndoRemovePresObjectImpl::UndoRemovePresObjectImpl( SdrObject& rObject )
49 SdPage* pPage = dynamic_cast< SdPage* >( rObject.getSdrPageFromSdrObject() );
50 if( !pPage )
51 return;
53 if( pPage->IsPresObj(&rObject) )
54 mpUndoPresObj.reset( new UndoObjectPresentationKind( rObject ) );
55 if( rObject.GetUserCall() )
56 mpUndoUsercall.reset( new UndoObjectUserCall(rObject) );
58 if( pPage->hasAnimationNode() )
60 css::uno::Reference< css::drawing::XShape > xShape( rObject.getUnoShape(), css::uno::UNO_QUERY );
61 if( pPage->getMainSequence()->hasEffect( xShape ) )
63 mpUndoAnimation.reset(
64 new UndoAnimation( // TTTT may use ref? Or just *SdrPage?
65 static_cast< SdDrawDocument* >(&pPage->getSdrModelFromSdrPage()),
66 pPage));
71 UndoRemovePresObjectImpl::~UndoRemovePresObjectImpl()
75 void UndoRemovePresObjectImpl::Undo()
77 if( mpUndoUsercall )
78 mpUndoUsercall->Undo();
79 if( mpUndoPresObj )
80 mpUndoPresObj->Undo();
81 if( mpUndoAnimation )
82 mpUndoAnimation->Undo();
85 void UndoRemovePresObjectImpl::Redo()
87 if( mpUndoAnimation )
88 mpUndoAnimation->Redo();
89 if( mpUndoPresObj )
90 mpUndoPresObj->Redo();
91 if( mpUndoUsercall )
92 mpUndoUsercall->Redo();
95 UndoRemoveObject::UndoRemoveObject( SdrObject& rObject )
96 : SdrUndoRemoveObj( rObject ), UndoRemovePresObjectImpl( rObject )
97 , mxSdrObject(&rObject)
101 void UndoRemoveObject::Undo()
103 DBG_ASSERT( mxSdrObject.is(), "sd::UndoRemoveObject::Undo(), object already dead!" );
104 if( mxSdrObject.is() )
106 SdrUndoRemoveObj::Undo();
107 UndoRemovePresObjectImpl::Undo();
111 void UndoRemoveObject::Redo()
113 DBG_ASSERT( mxSdrObject.is(), "sd::UndoRemoveObject::Redo(), object already dead!" );
114 if( mxSdrObject.is() )
116 UndoRemovePresObjectImpl::Redo();
117 SdrUndoRemoveObj::Redo();
121 UndoDeleteObject::UndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect )
122 : SdrUndoDelObj( rObject, bOrdNumDirect )
123 , UndoRemovePresObjectImpl( rObject )
124 , mxSdrObject(&rObject)
128 void UndoDeleteObject::Undo()
130 DBG_ASSERT( mxSdrObject.is(), "sd::UndoDeleteObject::Undo(), object already dead!" );
131 if( mxSdrObject.is() )
133 SdrUndoDelObj::Undo();
134 UndoRemovePresObjectImpl::Undo();
138 void UndoDeleteObject::Redo()
140 DBG_ASSERT( mxSdrObject.is(), "sd::UndoDeleteObject::Redo(), object already dead!" );
141 if( mxSdrObject.is() )
143 UndoRemovePresObjectImpl::Redo();
144 SdrUndoDelObj::Redo();
148 UndoReplaceObject::UndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject )
149 : SdrUndoReplaceObj( rOldObject, rNewObject )
150 , UndoRemovePresObjectImpl( rOldObject )
151 , mxSdrObject( &rOldObject )
155 void UndoReplaceObject::Undo()
157 DBG_ASSERT( mxSdrObject.is(), "sd::UndoReplaceObject::Undo(), object already dead!" );
158 if( mxSdrObject.is() )
160 SdrUndoReplaceObj::Undo();
161 UndoRemovePresObjectImpl::Undo();
165 void UndoReplaceObject::Redo()
167 DBG_ASSERT( mxSdrObject.is(), "sd::UndoReplaceObject::Redo(), object already dead!" );
168 if( mxSdrObject.is() )
170 UndoRemovePresObjectImpl::Redo();
171 SdrUndoReplaceObj::Redo();
175 UndoObjectSetText::UndoObjectSetText( SdrObject& rObject, sal_Int32 nText )
176 : SdrUndoObjSetText( rObject, nText )
177 , mbNewEmptyPresObj(false)
178 , mxSdrObject( &rObject )
180 SdPage* pPage = dynamic_cast< SdPage* >( rObject.getSdrPageFromSdrObject() );
181 if( pPage && pPage->hasAnimationNode() )
183 css::uno::Reference< css::drawing::XShape > xShape( rObject.getUnoShape(), css::uno::UNO_QUERY );
184 if( pPage->getMainSequence()->hasEffect( xShape ) )
186 mpUndoAnimation.reset(
187 new UndoAnimation(
188 static_cast< SdDrawDocument* >(&pPage->getSdrModelFromSdrPage()),
189 pPage));
194 UndoObjectSetText::~UndoObjectSetText()
198 void UndoObjectSetText::Undo()
200 DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectSetText::Undo(), object already dead!" );
201 if( mxSdrObject.is() )
203 mbNewEmptyPresObj = mxSdrObject->IsEmptyPresObj();
204 SdrUndoObjSetText::Undo();
205 if( mpUndoAnimation )
206 mpUndoAnimation->Undo();
210 void UndoObjectSetText::Redo()
212 DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectSetText::Redo(), object already dead!" );
213 if( mxSdrObject.is() )
215 if( mpUndoAnimation )
216 mpUndoAnimation->Redo();
217 SdrUndoObjSetText::Redo();
218 mxSdrObject->SetEmptyPresObj(mbNewEmptyPresObj);
222 // Undo for SdrObject::SetUserCall()
224 UndoObjectUserCall::UndoObjectUserCall(SdrObject& rObject)
225 : SdrUndoObj(rObject)
226 , mpOldUserCall(static_cast<SdPage*>(rObject.GetUserCall()))
227 , mpNewUserCall(nullptr)
228 , mxSdrObject( &rObject )
232 void UndoObjectUserCall::Undo()
234 DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectUserCall::Undo(), object already dead!" );
235 if( mxSdrObject.is() )
237 mpNewUserCall = mxSdrObject->GetUserCall();
238 mxSdrObject->SetUserCall(mpOldUserCall);
242 void UndoObjectUserCall::Redo()
244 DBG_ASSERT( mxSdrObject.is(), "sd::UndoObjectUserCall::Redo(), object already dead!" );
245 if( mxSdrObject.is() )
247 mxSdrObject->SetUserCall(mpNewUserCall);
251 // Undo for SdPage::InsertPresObj() and SdPage::RemovePresObj()
253 UndoObjectPresentationKind::UndoObjectPresentationKind(SdrObject& rObject)
254 : SdrUndoObj(rObject)
255 , meOldKind(PresObjKind::NONE)
256 , meNewKind(PresObjKind::NONE)
257 , mxPage( static_cast<SdPage*>(rObject.getSdrPageFromSdrObject()) )
258 , mxSdrObject( &rObject )
260 DBG_ASSERT( mxPage.get(), "sd::UndoObjectPresentationKind::UndoObjectPresentationKind(), does not work for shapes without a slide!" );
262 if( auto pPage = mxPage.get() )
263 meOldKind = pPage->GetPresObjKind( &rObject );
266 void UndoObjectPresentationKind::Undo()
268 if( !mxSdrObject.is() )
269 return;
270 if( rtl::Reference<SdPage> pPage = mxPage.get() )
272 meNewKind = pPage->GetPresObjKind( mxSdrObject.get() );
273 if( meNewKind != PresObjKind::NONE )
274 pPage->RemovePresObj( mxSdrObject.get() );
275 if( meOldKind != PresObjKind::NONE )
276 pPage->InsertPresObj( mxSdrObject.get(), meOldKind );
280 void UndoObjectPresentationKind::Redo()
282 if( !mxSdrObject.is() )
283 return;
284 if( rtl::Reference<SdPage> pPage = mxPage.get() )
286 if( meOldKind != PresObjKind::NONE )
287 pPage->RemovePresObj( mxSdrObject.get() );
288 if( meNewKind != PresObjKind::NONE )
289 pPage->InsertPresObj( mxSdrObject.get(), meNewKind );
293 UndoAutoLayoutPosAndSize::UndoAutoLayoutPosAndSize( SdPage& rPage )
294 : mxPage( &rPage )
298 void UndoAutoLayoutPosAndSize::Undo()
300 // do nothing
303 void UndoAutoLayoutPosAndSize::Redo()
305 rtl::Reference<SdPage> pPage = mxPage.get();
306 if( pPage )
307 pPage->SetAutoLayout( pPage->GetAutoLayout() );
310 UndoGeoObject::UndoGeoObject( SdrObject& rNewObj )
311 : SdrUndoGeoObj( rNewObj )
312 , mxPage( static_cast<SdPage*>(rNewObj.getSdrPageFromSdrObject()) )
313 , mxSdrObject( &rNewObj )
317 void UndoGeoObject::Undo()
319 DBG_ASSERT( mxSdrObject.is(), "sd::UndoGeoObject::Undo(), object already dead!" );
320 if( mxSdrObject.is() )
322 if( auto pPage = mxPage.get() )
324 ScopeLockGuard aGuard( pPage->maLockAutoLayoutArrangement );
325 SdrUndoGeoObj::Undo();
327 else
329 SdrUndoGeoObj::Undo();
334 void UndoGeoObject::Redo()
336 DBG_ASSERT( mxSdrObject.is(), "sd::UndoGeoObject::Redo(), object already dead!" );
337 if( mxSdrObject.is() )
339 if( auto pPage = mxPage.get() )
341 ScopeLockGuard aGuard( pPage->maLockAutoLayoutArrangement );
342 SdrUndoGeoObj::Redo();
344 else
346 SdrUndoGeoObj::Redo();
351 UndoAttrObject::UndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText )
352 : SdrUndoAttrObj( rObject, bStyleSheet1, bSaveText )
353 , mxPage( static_cast<SdPage*>(rObject.getSdrPageFromSdrObject()) )
354 , mxSdrObject( &rObject )
358 void UndoAttrObject::Undo()
360 DBG_ASSERT( mxSdrObject.is(), "sd::UndoAttrObject::Undo(), object already dead!" );
361 if( mxSdrObject.is() )
363 if( auto pPage = mxPage.get() )
365 ScopeLockGuard aGuard( pPage->maLockAutoLayoutArrangement );
366 SdrUndoAttrObj::Undo();
368 else
370 SdrUndoAttrObj::Undo();
375 void UndoAttrObject::Redo()
377 DBG_ASSERT( mxSdrObject.is(), "sd::UndoAttrObject::Redo(), object already dead!" );
378 if( mxSdrObject.is() )
380 if( auto pPage = mxPage.get() )
382 ScopeLockGuard aGuard( pPage->maLockAutoLayoutArrangement );
383 SdrUndoAttrObj::Redo();
385 else
387 SdrUndoAttrObj::Redo();
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */