xref: /aoo41x/main/sd/source/ui/dlg/unchss.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 
32 #include <svl/itemset.hxx>
33 #include <svl/style.hxx>
34 #include <svl/smplhint.hxx>
35 #include <svx/svdobj.hxx>
36 
37 #include "unchss.hxx"
38 
39 #include "strings.hrc"
40 #include "glob.hxx"
41 #include "sdresid.hxx"
42 #include "drawdoc.hxx"
43 #include "stlsheet.hxx"
44 #include "glob.hrc"
45 
46 
47 TYPEINIT1(StyleSheetUndoAction, SdUndoAction);
48 
49 
50 
51 /*************************************************************************
52 |*
53 |* Konstruktor
54 |*
55 \************************************************************************/
56 
57 StyleSheetUndoAction::StyleSheetUndoAction(SdDrawDocument* pTheDoc,
58 										   SfxStyleSheet* pTheStyleSheet,
59 										   const SfxItemSet* pTheNewItemSet) :
60 					  SdUndoAction(pTheDoc)
61 {
62 	DBG_ASSERT(pTheStyleSheet, "Undo ohne StyleSheet ???");
63 	pStyleSheet = pTheStyleSheet;
64 
65 	// ItemSets anlegen; Vorsicht, das neue koennte aus einem anderen Pool
66 	// stammen, also mitsamt seinen Items clonen
67 	pNewSet = new SfxItemSet((SfxItemPool&)SdrObject::GetGlobalDrawObjectItemPool(), pTheNewItemSet->GetRanges());
68 	pTheDoc->MigrateItemSet( pTheNewItemSet, pNewSet, pTheDoc );
69 
70 	pOldSet = new SfxItemSet((SfxItemPool&)SdrObject::GetGlobalDrawObjectItemPool(),pStyleSheet->GetItemSet().GetRanges());
71 	pTheDoc->MigrateItemSet( &pStyleSheet->GetItemSet(), pOldSet, pTheDoc );
72 
73 	aComment = String(SdResId(STR_UNDO_CHANGE_PRES_OBJECT));
74 	String aName(pStyleSheet->GetName());
75 
76 	// Layoutnamen und Separator loeschen
77 	String aSep( RTL_CONSTASCII_USTRINGPARAM( SD_LT_SEPARATOR ) );
78 	sal_uInt16 nPos = aName.Search(aSep);
79 	if( nPos != STRING_NOTFOUND )
80 		aName.Erase(0, nPos + aSep.Len());
81 
82 	if (aName == String(SdResId(STR_LAYOUT_TITLE)))
83 	{
84 		aName = String(SdResId(STR_PSEUDOSHEET_TITLE));
85 	}
86 	else if (aName == String(SdResId(STR_LAYOUT_SUBTITLE)))
87 	{
88 		aName = String(SdResId(STR_PSEUDOSHEET_SUBTITLE));
89 	}
90 	else if (aName == String(SdResId(STR_LAYOUT_BACKGROUND)))
91 	{
92 		aName = String(SdResId(STR_PSEUDOSHEET_BACKGROUND));
93 	}
94 	else if (aName == String(SdResId(STR_LAYOUT_BACKGROUNDOBJECTS)))
95 	{
96 		aName = String(SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS));
97 	}
98 	else if (aName == String(SdResId(STR_LAYOUT_NOTES)))
99 	{
100 		aName = String(SdResId(STR_PSEUDOSHEET_NOTES));
101 	}
102 	else
103 	{
104 		String aOutlineStr(SdResId(STR_PSEUDOSHEET_OUTLINE));
105 		nPos = aName.Search(aOutlineStr);
106 		if (nPos != STRING_NOTFOUND)
107 		{
108 			String aNumStr(aName.Copy(aOutlineStr.Len()));
109 			aName = String(SdResId(STR_LAYOUT_OUTLINE));
110 			aName += aNumStr;
111 		}
112 	}
113 
114 	// Platzhalter durch Vorlagennamen ersetzen
115 	nPos = aComment.Search(sal_Unicode('$'));
116 	aComment.Erase(nPos, 1);
117 	aComment.Insert(aName, nPos);
118 }
119 
120 
121 /*************************************************************************
122 |*
123 |* Undo()
124 |*
125 \************************************************************************/
126 
127 void StyleSheetUndoAction::Undo()
128 {
129 	SfxItemSet aNewSet( mpDoc->GetItemPool(), pOldSet->GetRanges() );
130 	mpDoc->MigrateItemSet( pOldSet, &aNewSet, mpDoc );
131 
132 	pStyleSheet->GetItemSet().Set(aNewSet);
133 	if( pStyleSheet->GetFamily() == SD_STYLE_FAMILY_PSEUDO )
134 		( (SdStyleSheet*)pStyleSheet )->GetRealStyleSheet()->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
135 	else
136 		pStyleSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
137 }
138 
139 /*************************************************************************
140 |*
141 |* Redo()
142 |*
143 \************************************************************************/
144 
145 void StyleSheetUndoAction::Redo()
146 {
147 	SfxItemSet aNewSet( mpDoc->GetItemPool(), pOldSet->GetRanges() );
148 	mpDoc->MigrateItemSet( pNewSet, &aNewSet, mpDoc );
149 
150 	pStyleSheet->GetItemSet().Set(aNewSet);
151 	if( pStyleSheet->GetFamily() == SD_STYLE_FAMILY_PSEUDO )
152 		( (SdStyleSheet*)pStyleSheet )->GetRealStyleSheet()->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
153 	else
154 		pStyleSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
155 }
156 
157 /*************************************************************************
158 |*
159 |* Destruktor
160 |*
161 \************************************************************************/
162 
163 StyleSheetUndoAction::~StyleSheetUndoAction()
164 {
165 	delete pNewSet;
166 	delete pOldSet;
167 }
168 
169 /*************************************************************************
170 |*
171 |* Kommentar liefern
172 |*
173 \************************************************************************/
174 
175 String StyleSheetUndoAction::GetComment() const
176 {
177 	return aComment;
178 }
179