Line data Source code
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/smplhint.hxx>
23 : #include <svx/svdobj.hxx>
24 :
25 : #include "unchss.hxx"
26 :
27 : #include "strings.hrc"
28 : #include "glob.hxx"
29 : #include "sdresid.hxx"
30 : #include "drawdoc.hxx"
31 : #include "stlsheet.hxx"
32 : #include "glob.hrc"
33 :
34 :
35 0 : TYPEINIT1(StyleSheetUndoAction, SdUndoAction);
36 :
37 :
38 0 : StyleSheetUndoAction::StyleSheetUndoAction(SdDrawDocument* pTheDoc,
39 : SfxStyleSheet* pTheStyleSheet,
40 : const SfxItemSet* pTheNewItemSet) :
41 0 : SdUndoAction(pTheDoc)
42 : {
43 : DBG_ASSERT(pTheStyleSheet, "Undo without StyleSheet ???");
44 0 : pStyleSheet = pTheStyleSheet;
45 :
46 : // Create ItemSets; Attention, it is possible that the new one is from a,
47 : // different pool. Therefore we clone it with its items.
48 0 : pNewSet = new SfxItemSet((SfxItemPool&)SdrObject::GetGlobalDrawObjectItemPool(), pTheNewItemSet->GetRanges());
49 0 : pTheDoc->MigrateItemSet( pTheNewItemSet, pNewSet, pTheDoc );
50 :
51 0 : pOldSet = new SfxItemSet((SfxItemPool&)SdrObject::GetGlobalDrawObjectItemPool(),pStyleSheet->GetItemSet().GetRanges());
52 0 : pTheDoc->MigrateItemSet( &pStyleSheet->GetItemSet(), pOldSet, pTheDoc );
53 :
54 0 : aComment = String(SdResId(STR_UNDO_CHANGE_PRES_OBJECT));
55 0 : String aName(pStyleSheet->GetName());
56 :
57 : // delete layout name and separator
58 0 : String aSep( SD_LT_SEPARATOR );
59 0 : sal_uInt16 nPos = aName.Search(aSep);
60 0 : if( nPos != STRING_NOTFOUND )
61 0 : aName.Erase(0, nPos + aSep.Len());
62 :
63 0 : if (aName == String(SdResId(STR_LAYOUT_TITLE)))
64 : {
65 0 : aName = String(SdResId(STR_PSEUDOSHEET_TITLE));
66 : }
67 0 : else if (aName == String(SdResId(STR_LAYOUT_SUBTITLE)))
68 : {
69 0 : aName = String(SdResId(STR_PSEUDOSHEET_SUBTITLE));
70 : }
71 0 : else if (aName == String(SdResId(STR_LAYOUT_BACKGROUND)))
72 : {
73 0 : aName = String(SdResId(STR_PSEUDOSHEET_BACKGROUND));
74 : }
75 0 : else if (aName == String(SdResId(STR_LAYOUT_BACKGROUNDOBJECTS)))
76 : {
77 0 : aName = String(SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS));
78 : }
79 0 : else if (aName == String(SdResId(STR_LAYOUT_NOTES)))
80 : {
81 0 : aName = String(SdResId(STR_PSEUDOSHEET_NOTES));
82 : }
83 : else
84 : {
85 0 : String aOutlineStr(SdResId(STR_PSEUDOSHEET_OUTLINE));
86 0 : nPos = aName.Search(aOutlineStr);
87 0 : if (nPos != STRING_NOTFOUND)
88 : {
89 0 : String aNumStr(aName.Copy(aOutlineStr.Len()));
90 0 : aName = String(SdResId(STR_LAYOUT_OUTLINE));
91 0 : aName += aNumStr;
92 0 : }
93 : }
94 :
95 : // replace placeholder with template name
96 0 : nPos = aComment.Search(sal_Unicode('$'));
97 0 : aComment.Erase(nPos, 1);
98 0 : aComment.Insert(aName, nPos);
99 0 : }
100 :
101 :
102 0 : void StyleSheetUndoAction::Undo()
103 : {
104 0 : SfxItemSet aNewSet( mpDoc->GetItemPool(), pOldSet->GetRanges() );
105 0 : mpDoc->MigrateItemSet( pOldSet, &aNewSet, mpDoc );
106 :
107 0 : pStyleSheet->GetItemSet().Set(aNewSet);
108 0 : if( pStyleSheet->GetFamily() == SD_STYLE_FAMILY_PSEUDO )
109 0 : ( (SdStyleSheet*)pStyleSheet )->GetRealStyleSheet()->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
110 : else
111 0 : pStyleSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
112 0 : }
113 :
114 :
115 0 : void StyleSheetUndoAction::Redo()
116 : {
117 0 : SfxItemSet aNewSet( mpDoc->GetItemPool(), pOldSet->GetRanges() );
118 0 : mpDoc->MigrateItemSet( pNewSet, &aNewSet, mpDoc );
119 :
120 0 : pStyleSheet->GetItemSet().Set(aNewSet);
121 0 : if( pStyleSheet->GetFamily() == SD_STYLE_FAMILY_PSEUDO )
122 0 : ( (SdStyleSheet*)pStyleSheet )->GetRealStyleSheet()->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
123 : else
124 0 : pStyleSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
125 0 : }
126 :
127 :
128 0 : StyleSheetUndoAction::~StyleSheetUndoAction()
129 : {
130 0 : delete pNewSet;
131 0 : delete pOldSet;
132 0 : }
133 :
134 :
135 0 : OUString StyleSheetUndoAction::GetComment() const
136 : {
137 0 : return aComment;
138 33 : }
139 :
140 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|