bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / dlg / unchss.cxx
blob0d4fc949b4e7ee5b4086bd9030165d7ebc70915c
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 <svl/itemset.hxx>
21 #include <svl/style.hxx>
22 #include <svl/hint.hxx>
23 #include <svx/svdobj.hxx>
24 #include <svx/svdpool.hxx>
25 #include <tools/debug.hxx>
27 #include <unchss.hxx>
29 #include <strings.hrc>
30 #include <glob.hxx>
31 #include <sdresid.hxx>
32 #include <drawdoc.hxx>
33 #include <stlsheet.hxx>
34 #include <strings.hxx>
36 StyleSheetUndoAction::StyleSheetUndoAction(SdDrawDocument* pTheDoc,
37 SfxStyleSheet* pTheStyleSheet,
38 const SfxItemSet* pTheNewItemSet) :
39 SdUndoAction(pTheDoc)
41 DBG_ASSERT(pTheStyleSheet, "Undo without StyleSheet ???");
42 mpStyleSheet = pTheStyleSheet;
44 // Create ItemSets; Attention, it is possible that the new one is from a,
45 // different pool. Therefore we clone it with its items.
46 mpNewSet = std::make_unique<SfxItemSet>(static_cast<SfxItemPool&>(SdrObject::GetGlobalDrawObjectItemPool()), pTheNewItemSet->GetRanges());
47 SdrModel::MigrateItemSet( pTheNewItemSet, mpNewSet.get(), pTheDoc );
49 mpOldSet = std::make_unique<SfxItemSet>(static_cast<SfxItemPool&>(SdrObject::GetGlobalDrawObjectItemPool()), mpStyleSheet->GetItemSet().GetRanges());
50 SdrModel::MigrateItemSet( &mpStyleSheet->GetItemSet(), mpOldSet.get(), pTheDoc );
52 OUString aComment(SdResId(STR_UNDO_CHANGE_PRES_OBJECT));
53 OUString aName(mpStyleSheet->GetName());
55 // delete layout name and separator
56 sal_Int32 nPos = aName.indexOf(SD_LT_SEPARATOR);
57 if (nPos != -1)
58 aName = aName.copy(nPos + strlen(SD_LT_SEPARATOR));
60 if (aName == STR_LAYOUT_TITLE)
62 aName = SdResId(STR_PSEUDOSHEET_TITLE);
64 else if (aName == STR_LAYOUT_SUBTITLE)
66 aName = SdResId(STR_PSEUDOSHEET_SUBTITLE);
68 else if (aName == STR_LAYOUT_BACKGROUND)
70 aName = SdResId(STR_PSEUDOSHEET_BACKGROUND);
72 else if (aName == STR_LAYOUT_BACKGROUNDOBJECTS)
74 aName = SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS);
76 else if (aName == STR_LAYOUT_NOTES)
78 aName = SdResId(STR_PSEUDOSHEET_NOTES);
80 else
82 OUString aOutlineStr(SdResId(STR_PSEUDOSHEET_OUTLINE));
83 nPos = aName.indexOf(aOutlineStr);
84 if (nPos != -1)
86 OUString aNumStr(aName.copy(aOutlineStr.getLength()));
87 aName = STR_LAYOUT_OUTLINE + aNumStr;
91 // replace placeholder with template name
92 SetComment(aComment.replaceFirst("$", aName));
95 void StyleSheetUndoAction::Undo()
97 SfxItemSet aNewSet( mpDoc->GetItemPool(), mpOldSet->GetRanges() );
98 SdrModel::MigrateItemSet( mpOldSet.get(), &aNewSet, mpDoc );
100 mpStyleSheet->GetItemSet().Set(aNewSet);
101 if( mpStyleSheet->GetFamily() == SfxStyleFamily::Pseudo )
102 static_cast<SdStyleSheet*>(mpStyleSheet)->GetRealStyleSheet()->Broadcast(SfxHint(SfxHintId::DataChanged));
103 else
104 mpStyleSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
107 void StyleSheetUndoAction::Redo()
109 SfxItemSet aNewSet( mpDoc->GetItemPool(), mpOldSet->GetRanges() );
110 SdrModel::MigrateItemSet( mpNewSet.get(), &aNewSet, mpDoc );
112 mpStyleSheet->GetItemSet().Set(aNewSet);
113 if( mpStyleSheet->GetFamily() == SfxStyleFamily::Pseudo )
114 static_cast<SdStyleSheet*>(mpStyleSheet)->GetRealStyleSheet()->Broadcast(SfxHint(SfxHintId::DataChanged));
115 else
116 mpStyleSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */