tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / sd / source / ui / dlg / unchss.cxx
blob43ca8a85c66ced6fb16fdc2f1dffa741c0de19e5
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& rTheStyleSheet,
38 const SfxItemSet* pTheNewItemSet)
39 : SdUndoAction(pTheDoc),
40 mrStyleSheet(rTheStyleSheet)
42 // Create ItemSets; Attention, it is possible that the new one is from a,
43 // different pool. Therefore we clone it with its items.
44 mpNewSet = std::make_unique<SfxItemSet>(static_cast<SfxItemPool&>(SdrObject::GetGlobalDrawObjectItemPool()), pTheNewItemSet->GetRanges());
45 SdrModel::MigrateItemSet( pTheNewItemSet, mpNewSet.get(), *pTheDoc );
47 mpOldSet = std::make_unique<SfxItemSet>(static_cast<SfxItemPool&>(SdrObject::GetGlobalDrawObjectItemPool()), mrStyleSheet.GetItemSet().GetRanges());
48 SdrModel::MigrateItemSet( &mrStyleSheet.GetItemSet(), mpOldSet.get(), *pTheDoc );
50 OUString aComment(SdResId(STR_UNDO_CHANGE_PRES_OBJECT));
51 OUString aName(mrStyleSheet.GetName());
53 // delete layout name and separator
54 sal_Int32 nPos = aName.indexOf(SD_LT_SEPARATOR);
55 if (nPos != -1)
56 aName = aName.copy(nPos + SD_LT_SEPARATOR.getLength());
58 if (aName == STR_LAYOUT_TITLE)
60 aName = SdResId(STR_PSEUDOSHEET_TITLE);
62 else if (aName == STR_LAYOUT_SUBTITLE)
64 aName = SdResId(STR_PSEUDOSHEET_SUBTITLE);
66 else if (aName == STR_LAYOUT_BACKGROUND)
68 aName = SdResId(STR_PSEUDOSHEET_BACKGROUND);
70 else if (aName == STR_LAYOUT_BACKGROUNDOBJECTS)
72 aName = SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS);
74 else if (aName == STR_LAYOUT_NOTES)
76 aName = SdResId(STR_PSEUDOSHEET_NOTES);
78 else
80 OUString aOutlineStr(SdResId(STR_PSEUDOSHEET_OUTLINE));
81 nPos = aName.indexOf(aOutlineStr);
82 if (nPos != -1)
84 std::u16string_view aNumStr(aName.subView(aOutlineStr.getLength()));
85 aName = STR_LAYOUT_OUTLINE + aNumStr;
89 // replace placeholder with template name
90 SetComment(aComment.replaceFirst("$", aName));
93 void StyleSheetUndoAction::Undo()
95 SfxItemSet aNewSet( mpDoc->GetItemPool(), mpOldSet->GetRanges() );
96 SdrModel::MigrateItemSet( mpOldSet.get(), &aNewSet, *mpDoc );
98 mrStyleSheet.GetItemSet().Set(aNewSet);
99 if( mrStyleSheet.GetFamily() == SfxStyleFamily::Pseudo )
100 static_cast<SdStyleSheet&>(mrStyleSheet).GetRealStyleSheet()->Broadcast(SfxHint(SfxHintId::DataChanged));
101 else
102 mrStyleSheet.Broadcast(SfxHint(SfxHintId::DataChanged));
105 void StyleSheetUndoAction::Redo()
107 SfxItemSet aNewSet( mpDoc->GetItemPool(), mpOldSet->GetRanges() );
108 SdrModel::MigrateItemSet( mpNewSet.get(), &aNewSet, *mpDoc );
110 mrStyleSheet.GetItemSet().Set(aNewSet);
111 if( mrStyleSheet.GetFamily() == SfxStyleFamily::Pseudo )
112 static_cast<SdStyleSheet&>(mrStyleSheet).GetRealStyleSheet()->Broadcast(SfxHint(SfxHintId::DataChanged));
113 else
114 mrStyleSheet.Broadcast(SfxHint(SfxHintId::DataChanged));
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */