cid#1607171 Data race condition
[LibreOffice.git] / sc / source / ui / undo / UndoThemeChange.cxx
blobc83c9794714856ad3d6edff9740c8554088d7f26
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/.
8 */
10 #include <undo/UndoThemeChange.hxx>
11 #include <docmodel/theme/Theme.hxx>
12 #include <scresid.hxx>
13 #include <globstr.hrc>
15 namespace sc
17 UndoThemeChange::UndoThemeChange(ScDocShell& rDocShell,
18 std::shared_ptr<model::ColorSet> const& pOldColorSet,
19 std::shared_ptr<model::ColorSet> const& pNewColorSet)
20 : ScSimpleUndo(&rDocShell)
21 , mpOldColorSet(pOldColorSet)
22 , mpNewColorSet(pNewColorSet)
26 UndoThemeChange::~UndoThemeChange() = default;
28 namespace
30 std::shared_ptr<model::Theme> getTheme(ScDocShell& rDocShell)
32 ScDrawLayer* pModel = rDocShell.GetDocument().GetDrawLayer();
34 auto pTheme = pModel->getTheme();
35 if (!pTheme)
37 pTheme = std::make_shared<model::Theme>("Office");
38 pModel->setTheme(pTheme);
40 return pTheme;
44 void UndoThemeChange::Undo()
46 BeginUndo();
48 auto pTheme = getTheme(*pDocShell);
49 pTheme->setColorSet(mpOldColorSet);
51 EndUndo();
54 void UndoThemeChange::Redo()
56 BeginUndo();
58 auto pTheme = getTheme(*pDocShell);
59 pTheme->setColorSet(mpNewColorSet);
61 EndRedo();
64 void UndoThemeChange::Repeat(SfxRepeatTarget& /*rTarget*/) {}
66 bool UndoThemeChange::CanRepeat(SfxRepeatTarget& /*rTarget*/) const { return false; }
68 OUString UndoThemeChange::GetComment() const { return ScResId(STR_UNDO_THEME_CHANGE); }
70 } // end sc namespace
72 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */