1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <o3tl/make_unique.hxx>
22 #include <svl/itemset.hxx>
23 #include <svl/style.hxx>
24 #include <svl/hint.hxx>
25 #include <svx/svdobj.hxx>
26 #include <svx/svdpool.hxx>
30 #include <strings.hrc>
32 #include <sdresid.hxx>
33 #include <drawdoc.hxx>
34 #include <stlsheet.hxx>
35 #include <strings.hxx>
37 StyleSheetUndoAction::StyleSheetUndoAction(SdDrawDocument
* pTheDoc
,
38 SfxStyleSheet
* pTheStyleSheet
,
39 const SfxItemSet
* pTheNewItemSet
) :
42 DBG_ASSERT(pTheStyleSheet
, "Undo without StyleSheet ???");
43 mpStyleSheet
= pTheStyleSheet
;
45 // Create ItemSets; Attention, it is possible that the new one is from a,
46 // different pool. Therefore we clone it with its items.
47 mpNewSet
= o3tl::make_unique
<SfxItemSet
>(static_cast<SfxItemPool
&>(SdrObject::GetGlobalDrawObjectItemPool()), pTheNewItemSet
->GetRanges());
48 SdrModel::MigrateItemSet( pTheNewItemSet
, mpNewSet
.get(), pTheDoc
);
50 mpOldSet
= o3tl::make_unique
<SfxItemSet
>(static_cast<SfxItemPool
&>(SdrObject::GetGlobalDrawObjectItemPool()), mpStyleSheet
->GetItemSet().GetRanges());
51 SdrModel::MigrateItemSet( &mpStyleSheet
->GetItemSet(), mpOldSet
.get(), pTheDoc
);
53 OUString
aComment(SdResId(STR_UNDO_CHANGE_PRES_OBJECT
));
54 OUString
aName(mpStyleSheet
->GetName());
56 // delete layout name and separator
57 sal_Int32 nPos
= aName
.indexOf(SD_LT_SEPARATOR
);
59 aName
= aName
.copy(nPos
+ strlen(SD_LT_SEPARATOR
));
61 if (aName
== STR_LAYOUT_TITLE
)
63 aName
= SdResId(STR_PSEUDOSHEET_TITLE
);
65 else if (aName
== STR_LAYOUT_SUBTITLE
)
67 aName
= SdResId(STR_PSEUDOSHEET_SUBTITLE
);
69 else if (aName
== STR_LAYOUT_BACKGROUND
)
71 aName
= SdResId(STR_PSEUDOSHEET_BACKGROUND
);
73 else if (aName
== STR_LAYOUT_BACKGROUNDOBJECTS
)
75 aName
= SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS
);
77 else if (aName
== STR_LAYOUT_NOTES
)
79 aName
= SdResId(STR_PSEUDOSHEET_NOTES
);
83 OUString
aOutlineStr(SdResId(STR_PSEUDOSHEET_OUTLINE
));
84 nPos
= aName
.indexOf(aOutlineStr
);
87 OUString
aNumStr(aName
.copy(aOutlineStr
.getLength()));
88 aName
= STR_LAYOUT_OUTLINE
+ aNumStr
;
92 // replace placeholder with template name
93 SetComment(aComment
.replaceFirst("$", aName
));
96 void StyleSheetUndoAction::Undo()
98 SfxItemSet
aNewSet( mpDoc
->GetItemPool(), mpOldSet
->GetRanges() );
99 SdrModel::MigrateItemSet( mpOldSet
.get(), &aNewSet
, mpDoc
);
101 mpStyleSheet
->GetItemSet().Set(aNewSet
);
102 if( mpStyleSheet
->GetFamily() == SfxStyleFamily::Pseudo
)
103 static_cast<SdStyleSheet
*>(mpStyleSheet
)->GetRealStyleSheet()->Broadcast(SfxHint(SfxHintId::DataChanged
));
105 mpStyleSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
108 void StyleSheetUndoAction::Redo()
110 SfxItemSet
aNewSet( mpDoc
->GetItemPool(), mpOldSet
->GetRanges() );
111 SdrModel::MigrateItemSet( mpNewSet
.get(), &aNewSet
, mpDoc
);
113 mpStyleSheet
->GetItemSet().Set(aNewSet
);
114 if( mpStyleSheet
->GetFamily() == SfxStyleFamily::Pseudo
)
115 static_cast<SdStyleSheet
*>(mpStyleSheet
)->GetRealStyleSheet()->Broadcast(SfxHint(SfxHintId::DataChanged
));
117 mpStyleSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */