cid#1607171 Data race condition
[LibreOffice.git] / sc / source / ui / undo / undoolk.cxx
blob519ae20a77c376b0d91071822e14c676016f9a4a
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 <svx/svdundo.hxx>
22 #include <document.hxx>
23 #include <drwlayer.hxx>
24 #include <undoolk.hxx>
26 std::unique_ptr<SdrUndoAction> GetSdrUndoAction(ScDocument* pDoc)
28 ScDrawLayer* pLayer = pDoc->GetDrawLayer();
29 if (pLayer)
30 return pLayer->GetCalcUndo(); // must exist
31 else
32 return nullptr;
35 void DoSdrUndoAction(SdrUndoAction* pUndoAction, ScDocument* pDoc)
37 if (pUndoAction)
38 pUndoAction->Undo();
39 else
41 // if no drawing layer existed when the action was created,
42 // but it was created after that, there is no draw undo action,
43 // and after undo there might be a drawing layer with a wrong page count.
44 // The drawing layer must have been empty in that case, so any missing
45 // pages can just be created now.
47 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
48 if (pDrawLayer)
50 SCTAB nTabCount = pDoc->GetTableCount();
51 SCTAB nPages = static_cast<SCTAB>(pDrawLayer->GetPageCount());
52 while (nPages < nTabCount)
54 pDrawLayer->ScAddPage(nPages);
55 ++nPages;
61 void RedoSdrUndoAction(SdrUndoAction* pUndoAction)
63 // DoSdrUndoAction/RedoSdrUndoAction is called even if the pointer is null
64 if (pUndoAction)
65 pUndoAction->Redo();
68 void EnableDrawAdjust(ScDocument* pDoc, bool bEnable)
70 ScDrawLayer* pLayer = pDoc->GetDrawLayer();
71 if (pLayer)
72 pLayer->EnableAdjust(bEnable);
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */