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 = SD_RESSTR(STR_UNDO_CHANGE_PRES_OBJECT);
55 0 : OUString aName(pStyleSheet->GetName());
56 :
57 : // delete layout name and separator
58 0 : sal_Int32 nPos = aName.indexOf(SD_LT_SEPARATOR);
59 0 : if (nPos != -1)
60 0 : aName = aName.copy(nPos + strlen(SD_LT_SEPARATOR));
61 :
62 0 : if (aName == SD_RESSTR(STR_LAYOUT_TITLE))
63 : {
64 0 : aName = SD_RESSTR(STR_PSEUDOSHEET_TITLE);
65 : }
66 0 : else if (aName == SD_RESSTR(STR_LAYOUT_SUBTITLE))
67 : {
68 0 : aName = SD_RESSTR(STR_PSEUDOSHEET_SUBTITLE);
69 : }
70 0 : else if (aName == SD_RESSTR(STR_LAYOUT_BACKGROUND))
71 : {
72 0 : aName = SD_RESSTR(STR_PSEUDOSHEET_BACKGROUND);
73 : }
74 0 : else if (aName == SD_RESSTR(STR_LAYOUT_BACKGROUNDOBJECTS))
75 : {
76 0 : aName = SD_RESSTR(STR_PSEUDOSHEET_BACKGROUNDOBJECTS);
77 : }
78 0 : else if (aName == SD_RESSTR(STR_LAYOUT_NOTES))
79 : {
80 0 : aName = SD_RESSTR(STR_PSEUDOSHEET_NOTES);
81 : }
82 : else
83 : {
84 0 : OUString aOutlineStr(SD_RESSTR(STR_PSEUDOSHEET_OUTLINE));
85 0 : nPos = aName.indexOf(aOutlineStr);
86 0 : if (nPos != -1)
87 : {
88 0 : OUString aNumStr(aName.copy(aOutlineStr.getLength()));
89 0 : aName = SD_RESSTR(STR_LAYOUT_OUTLINE) + aNumStr;
90 0 : }
91 : }
92 :
93 : // replace placeholder with template name
94 0 : aComment = aComment.replaceFirst("$", aName);
95 0 : }
96 :
97 :
98 0 : void StyleSheetUndoAction::Undo()
99 : {
100 0 : SfxItemSet aNewSet( mpDoc->GetItemPool(), pOldSet->GetRanges() );
101 0 : mpDoc->MigrateItemSet( pOldSet, &aNewSet, mpDoc );
102 :
103 0 : pStyleSheet->GetItemSet().Set(aNewSet);
104 0 : if( pStyleSheet->GetFamily() == SD_STYLE_FAMILY_PSEUDO )
105 0 : ( (SdStyleSheet*)pStyleSheet )->GetRealStyleSheet()->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
106 : else
107 0 : pStyleSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
108 0 : }
109 :
110 :
111 0 : void StyleSheetUndoAction::Redo()
112 : {
113 0 : SfxItemSet aNewSet( mpDoc->GetItemPool(), pOldSet->GetRanges() );
114 0 : mpDoc->MigrateItemSet( pNewSet, &aNewSet, mpDoc );
115 :
116 0 : pStyleSheet->GetItemSet().Set(aNewSet);
117 0 : if( pStyleSheet->GetFamily() == SD_STYLE_FAMILY_PSEUDO )
118 0 : ( (SdStyleSheet*)pStyleSheet )->GetRealStyleSheet()->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
119 : else
120 0 : pStyleSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
121 0 : }
122 :
123 :
124 0 : StyleSheetUndoAction::~StyleSheetUndoAction()
125 : {
126 0 : delete pNewSet;
127 0 : delete pOldSet;
128 0 : }
129 :
130 :
131 0 : OUString StyleSheetUndoAction::GetComment() const
132 : {
133 0 : return aComment;
134 : }
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|