xref: /trunk/main/sd/source/ui/view/unmodpg.cxx (revision 5b190011)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #ifndef _SVDLAYER
28 #include <svx/svdlayer.hxx>
29 #endif
30 #include <sfx2/dispatch.hxx>
31 #include <sfx2/viewfrm.hxx>
32 
33 
34 #include "strings.hrc"
35 #include "glob.hxx"
36 #include "glob.hrc"         // STR_BCKGRND, STR_BCKGRNDOBJ
37 #include "app.hrc"          // SID_SWITCHPAGE
38 
39 #include "unmodpg.hxx"
40 #include "sdpage.hxx"
41 #include "sdresid.hxx"
42 #include "drawdoc.hxx"
43 
44 
45 TYPEINIT1(ModifyPageUndoAction, SdUndoAction);
46 
47 
48 /*************************************************************************
49 |*
50 |* Konstruktor
51 |*
52 \************************************************************************/
53 
54 ModifyPageUndoAction::ModifyPageUndoAction(
55 	SdDrawDocument* pTheDoc,
56 	SdPage* pThePage,
57 	String aTheNewName,
58 	AutoLayout	eTheNewAutoLayout,
59 	sal_Bool bTheNewBckgrndVisible,
60 	sal_Bool bTheNewBckgrndObjsVisible)
61 :	SdUndoAction(pTheDoc)
62 {
63 	DBG_ASSERT(pThePage, "Undo ohne Seite ???");
64 
65 	mpPage					= pThePage;
66 	maNewName				= aTheNewName;
67 	meNewAutoLayout			= eTheNewAutoLayout;
68 	mbNewBckgrndVisible		= bTheNewBckgrndVisible;
69 	mbNewBckgrndObjsVisible	= bTheNewBckgrndObjsVisible;
70 
71 	meOldAutoLayout			= mpPage->GetAutoLayout();
72 
73 	if (!mpPage->IsMasterPage())
74 	{
75 		maOldName = mpPage->GetName();
76 		SdrLayerAdmin& rLayerAdmin = mpDoc->GetLayerAdmin();
77 		sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), sal_False);
78 		sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False);
79 		SetOfByte aVisibleLayers = mpPage->TRG_GetMasterPageVisibleLayers();
80 
81 		mbOldBckgrndVisible = aVisibleLayers.IsSet(aBckgrnd);
82 		mbOldBckgrndObjsVisible = aVisibleLayers.IsSet(aBckgrndObj);
83 	}
84 
85 	maComment = String(SdResId(STR_UNDO_MODIFY_PAGE));
86 }
87 
88 /*************************************************************************
89 |*
90 |* Undo()
91 |*
92 \************************************************************************/
93 #include <svx/svdviter.hxx>
94 #include <svx/svdview.hxx>
95 void ModifyPageUndoAction::Undo()
96 {
97 	// #94637# invalidate Selection, there could be objects deleted in tis UNDO
98 	// which are no longer allowed to be selected then.
99   	SdrViewIter aIter(mpPage);
100     SdrView* pView = aIter.FirstView();
101 
102 	while(pView)
103 	{
104 		if(pView->AreObjectsMarked())
105 			pView->UnmarkAll();
106 		pView = aIter.NextView();
107     }
108 
109 	mpPage->SetAutoLayout( meOldAutoLayout );
110 
111 	if (!mpPage->IsMasterPage())
112 	{
113 		if (mpPage->GetName() != maOldName)
114 		{
115 			mpPage->SetName(maOldName);
116 
117 			if (mpPage->GetPageKind() == PK_STANDARD)
118 			{
119 				SdPage* pNotesPage = (SdPage*)mpDoc->GetPage(mpPage->GetPageNum() + 1);
120 				pNotesPage->SetName(maOldName);
121 			}
122 		}
123 
124 		SdrLayerAdmin& rLayerAdmin = mpDoc->GetLayerAdmin();
125 		sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), sal_False);
126 		sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False);
127 		SetOfByte aVisibleLayers;
128 		aVisibleLayers.Set(aBckgrnd, mbOldBckgrndVisible);
129 		aVisibleLayers.Set(aBckgrndObj, mbOldBckgrndObjsVisible);
130 		mpPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
131 	}
132 
133 	// Redisplay
134 	SfxViewFrame::Current()->GetDispatcher()->Execute(
135 		SID_SWITCHPAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
136 }
137 
138 /*************************************************************************
139 |*
140 |* Redo()
141 |*
142 \************************************************************************/
143 
144 void ModifyPageUndoAction::Redo()
145 {
146 	// #94637# invalidate Selection, there could be objects deleted in tis UNDO
147 	// which are no longer allowed to be selected then.
148   	SdrViewIter aIter(mpPage);
149     SdrView* pView = aIter.FirstView();
150 
151 	while(pView)
152 	{
153 		if(pView->AreObjectsMarked())
154 			pView->UnmarkAll();
155 		pView = aIter.NextView();
156     }
157 
158 	mpPage->meAutoLayout = meNewAutoLayout;
159 
160 	if (!mpPage->IsMasterPage())
161 	{
162 		if (mpPage->GetName() != maNewName)
163 		{
164 			mpPage->SetName(maNewName);
165 
166 			if (mpPage->GetPageKind() == PK_STANDARD)
167 			{
168 				SdPage* pNotesPage = (SdPage*)mpDoc->GetPage(mpPage->GetPageNum() + 1);
169 				pNotesPage->SetName(maNewName);
170 			}
171 		}
172 
173 		SdrLayerAdmin& rLayerAdmin = mpDoc->GetLayerAdmin();
174 		sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), sal_False);
175 		sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False);
176 		SetOfByte aVisibleLayers;
177 		aVisibleLayers.Set(aBckgrnd, mbNewBckgrndVisible);
178 		aVisibleLayers.Set(aBckgrndObj, mbNewBckgrndObjsVisible);
179 		mpPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
180 	}
181 
182 	// Redisplay
183 	SfxViewFrame::Current()->GetDispatcher()->Execute(
184 		SID_SWITCHPAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
185 }
186 
187 /*************************************************************************
188 |*
189 |* Destruktor
190 |*
191 \************************************************************************/
192 
193 ModifyPageUndoAction::~ModifyPageUndoAction()
194 {
195 }
196 
197 /*************************************************************************
198 |*
199 |* Kommentar liefern
200 |*
201 \************************************************************************/
202 
203 String ModifyPageUndoAction::GetComment() const
204 {
205 	return maComment;
206 }
207 
208 // --------------------------------------------------------------------
209 
210 RenameLayoutTemplateUndoAction::RenameLayoutTemplateUndoAction( SdDrawDocument* pDocument, const String& rOldLayoutName, const String& rNewLayoutName )
211 : SdUndoAction(pDocument)
212 , maOldName( rOldLayoutName )
213 , maNewName( rNewLayoutName )
214 , maComment(SdResId(STR_TITLE_RENAMESLIDE))
215 {
216 	sal_uInt16 nPos = maOldName.SearchAscii( SD_LT_SEPARATOR );
217 	if( nPos != (sal_uInt16)-1 )
218 		maOldName.Erase(nPos);
219 }
220 
221 void RenameLayoutTemplateUndoAction::Undo()
222 {
223 	String aLayoutName( maNewName );
224 	aLayoutName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR ));
225 	aLayoutName.Append( String(SdResId(STR_LAYOUT_OUTLINE))) ;
226 
227 	mpDoc->RenameLayoutTemplate( aLayoutName, maOldName );
228 }
229 
230 void RenameLayoutTemplateUndoAction::Redo()
231 {
232 	String aLayoutName( maOldName );
233 	aLayoutName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR ));
234 	aLayoutName.Append( String(SdResId(STR_LAYOUT_OUTLINE))) ;
235 
236 	mpDoc->RenameLayoutTemplate( aLayoutName, maNewName );
237 }
238 
239 String RenameLayoutTemplateUndoAction::GetComment() const
240 {
241 	return 	maComment;
242 }
243 
244