LibreOffice Module sd (master) 1
unchss.cxx
Go to the documentation of this file.
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
37 SfxStyleSheet* pTheStyleSheet,
38 const SfxItemSet* pTheNewItemSet) :
39 SdUndoAction(pTheDoc)
40{
41 DBG_ASSERT(pTheStyleSheet, "Undo without StyleSheet ???");
42 mpStyleSheet = pTheStyleSheet;
43
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 );
48
49 mpOldSet = std::make_unique<SfxItemSet>(static_cast<SfxItemPool&>(SdrObject::GetGlobalDrawObjectItemPool()), mpStyleSheet->GetItemSet().GetRanges());
51
52 OUString aComment(SdResId(STR_UNDO_CHANGE_PRES_OBJECT));
53 OUString aName(mpStyleSheet->GetName());
54
55 // delete layout name and separator
56 sal_Int32 nPos = aName.indexOf(SD_LT_SEPARATOR);
57 if (nPos != -1)
58 aName = aName.copy(nPos + SD_LT_SEPARATOR.getLength());
59
61 {
62 aName = SdResId(STR_PSEUDOSHEET_TITLE);
63 }
64 else if (aName == STR_LAYOUT_SUBTITLE)
65 {
66 aName = SdResId(STR_PSEUDOSHEET_SUBTITLE);
67 }
68 else if (aName == STR_LAYOUT_BACKGROUND)
69 {
70 aName = SdResId(STR_PSEUDOSHEET_BACKGROUND);
71 }
73 {
74 aName = SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS);
75 }
76 else if (aName == STR_LAYOUT_NOTES)
77 {
78 aName = SdResId(STR_PSEUDOSHEET_NOTES);
79 }
80 else
81 {
82 OUString aOutlineStr(SdResId(STR_PSEUDOSHEET_OUTLINE));
83 nPos = aName.indexOf(aOutlineStr);
84 if (nPos != -1)
85 {
86 std::u16string_view aNumStr(aName.subView(aOutlineStr.getLength()));
87 aName = STR_LAYOUT_OUTLINE + aNumStr;
88 }
89 }
90
91 // replace placeholder with template name
92 SetComment(aComment.replaceFirst("$", aName));
93}
94
96{
97 SfxItemSet aNewSet( mpDoc->GetItemPool(), mpOldSet->GetRanges() );
98 SdrModel::MigrateItemSet( mpOldSet.get(), &aNewSet, mpDoc );
99
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));
105}
106
108{
109 SfxItemSet aNewSet( mpDoc->GetItemPool(), mpOldSet->GetRanges() );
110 SdrModel::MigrateItemSet( mpNewSet.get(), &aNewSet, mpDoc );
111
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));
117}
118
119/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetComment(const OUString &rStr)
Definition: sdundo.hxx:32
SdDrawDocument * mpDoc
Definition: sdundo.hxx:39
const SfxItemPool & GetItemPool() const
static void MigrateItemSet(const SfxItemSet *pSourceSet, SfxItemSet *pDestSet, SdrModel *pNewModel)
static SdrItemPool & GetGlobalDrawObjectItemPool()
void Broadcast(const SfxHint &rHint)
const WhichRangesContainer & GetRanges() const
bool Set(const SfxItemSet &, bool bDeep=true)
const OUString & GetName() const
SfxStyleFamily GetFamily() const
virtual SfxItemSet & GetItemSet()
std::unique_ptr< SfxItemSet > mpNewSet
Definition: unchss.hxx:36
virtual void Undo() override
Definition: unchss.cxx:95
std::unique_ptr< SfxItemSet > mpOldSet
Definition: unchss.hxx:37
SfxStyleSheet * mpStyleSheet
Definition: unchss.hxx:34
virtual void Redo() override
Definition: unchss.cxx:107
StyleSheetUndoAction(SdDrawDocument *pTheDoc, SfxStyleSheet *pTheStyleSheet, const SfxItemSet *pTheNewItemSet)
Definition: unchss.cxx:36
#define DBG_ASSERT(sCon, aError)
constexpr OUStringLiteral SD_LT_SEPARATOR
Definition: glob.hxx:49
OUString aName
sal_uInt16 nPos
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
constexpr OUStringLiteral STR_LAYOUT_TITLE
Definition: strings.hxx:15
constexpr OUStringLiteral STR_LAYOUT_OUTLINE
Definition: strings.hxx:16
constexpr OUStringLiteral STR_LAYOUT_SUBTITLE
Definition: strings.hxx:20
constexpr OUStringLiteral STR_LAYOUT_BACKGROUNDOBJECTS
Definition: strings.hxx:18
constexpr OUStringLiteral STR_LAYOUT_NOTES
Definition: strings.hxx:19
constexpr OUStringLiteral STR_LAYOUT_BACKGROUND
Definition: strings.hxx:17