/src/libreoffice/sd/source/ui/dlg/unchss.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
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> |
26 | | |
27 | | #include <unchss.hxx> |
28 | | |
29 | | #include <strings.hrc> |
30 | | #include <glob.hxx> |
31 | | #include <sdresid.hxx> |
32 | | #include <drawdoc.hxx> |
33 | | #include <stlsheet.hxx> |
34 | | #include <strings.hxx> |
35 | | |
36 | | StyleSheetUndoAction::StyleSheetUndoAction(SdDrawDocument& rTheDoc, |
37 | | SfxStyleSheet& rTheStyleSheet, |
38 | | const SfxItemSet* pTheNewItemSet) |
39 | 0 | : SdUndoAction(rTheDoc), |
40 | 0 | mrStyleSheet(rTheStyleSheet) |
41 | 0 | { |
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 | 0 | mpNewSet = std::make_unique<SfxItemSet>(static_cast<SfxItemPool&>(SdrObject::GetGlobalDrawObjectItemPool()), pTheNewItemSet->GetRanges()); |
45 | 0 | SdrModel::MigrateItemSet( pTheNewItemSet, mpNewSet.get(), rTheDoc ); |
46 | |
|
47 | 0 | mpOldSet = std::make_unique<SfxItemSet>(static_cast<SfxItemPool&>(SdrObject::GetGlobalDrawObjectItemPool()), mrStyleSheet.GetItemSet().GetRanges()); |
48 | 0 | SdrModel::MigrateItemSet( &mrStyleSheet.GetItemSet(), mpOldSet.get(), rTheDoc ); |
49 | |
|
50 | 0 | OUString aComment(SdResId(STR_UNDO_CHANGE_PRES_OBJECT)); |
51 | 0 | OUString aName(mrStyleSheet.GetName()); |
52 | | |
53 | | // delete layout name and separator |
54 | 0 | sal_Int32 nPos = aName.indexOf(SD_LT_SEPARATOR); |
55 | 0 | if (nPos != -1) |
56 | 0 | aName = aName.copy(nPos + SD_LT_SEPARATOR.getLength()); |
57 | |
|
58 | 0 | if (aName == STR_LAYOUT_TITLE) |
59 | 0 | { |
60 | 0 | aName = SdResId(STR_PSEUDOSHEET_TITLE); |
61 | 0 | } |
62 | 0 | else if (aName == STR_LAYOUT_SUBTITLE) |
63 | 0 | { |
64 | 0 | aName = SdResId(STR_PSEUDOSHEET_SUBTITLE); |
65 | 0 | } |
66 | 0 | else if (aName == STR_LAYOUT_BACKGROUND) |
67 | 0 | { |
68 | 0 | aName = SdResId(STR_PSEUDOSHEET_BACKGROUND); |
69 | 0 | } |
70 | 0 | else if (aName == STR_LAYOUT_BACKGROUNDOBJECTS) |
71 | 0 | { |
72 | 0 | aName = SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS); |
73 | 0 | } |
74 | 0 | else if (aName == STR_LAYOUT_NOTES) |
75 | 0 | { |
76 | 0 | aName = SdResId(STR_PSEUDOSHEET_NOTES); |
77 | 0 | } |
78 | 0 | else |
79 | 0 | { |
80 | 0 | OUString aOutlineStr(SdResId(STR_PSEUDOSHEET_OUTLINE)); |
81 | 0 | nPos = aName.indexOf(aOutlineStr); |
82 | 0 | if (nPos != -1) |
83 | 0 | { |
84 | 0 | std::u16string_view aNumStr(aName.subView(aOutlineStr.getLength())); |
85 | 0 | aName = STR_LAYOUT_OUTLINE + aNumStr; |
86 | 0 | } |
87 | 0 | } |
88 | | |
89 | | // replace placeholder with template name |
90 | 0 | SetComment(aComment.replaceFirst("$", aName)); |
91 | 0 | } |
92 | | |
93 | | void StyleSheetUndoAction::Undo() |
94 | 0 | { |
95 | 0 | SfxItemSet aNewSet( mrDoc.GetItemPool(), mpOldSet->GetRanges() ); |
96 | 0 | SdrModel::MigrateItemSet( mpOldSet.get(), &aNewSet, mrDoc ); |
97 | |
|
98 | 0 | mrStyleSheet.GetItemSet().Set(aNewSet); |
99 | 0 | if( mrStyleSheet.GetFamily() == SfxStyleFamily::Pseudo ) |
100 | 0 | static_cast<SdStyleSheet&>(mrStyleSheet).GetRealStyleSheet()->Broadcast(SfxHint(SfxHintId::DataChanged)); |
101 | 0 | else |
102 | 0 | mrStyleSheet.Broadcast(SfxHint(SfxHintId::DataChanged)); |
103 | 0 | } |
104 | | |
105 | | void StyleSheetUndoAction::Redo() |
106 | 0 | { |
107 | 0 | SfxItemSet aNewSet( mrDoc.GetItemPool(), mpOldSet->GetRanges() ); |
108 | 0 | SdrModel::MigrateItemSet( mpNewSet.get(), &aNewSet, mrDoc ); |
109 | |
|
110 | 0 | mrStyleSheet.GetItemSet().Set(aNewSet); |
111 | 0 | if( mrStyleSheet.GetFamily() == SfxStyleFamily::Pseudo ) |
112 | 0 | static_cast<SdStyleSheet&>(mrStyleSheet).GetRealStyleSheet()->Broadcast(SfxHint(SfxHintId::DataChanged)); |
113 | 0 | else |
114 | 0 | mrStyleSheet.Broadcast(SfxHint(SfxHintId::DataChanged)); |
115 | 0 | } |
116 | | |
117 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |