1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <svx/svdlayer.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <sfx2/viewfrm.hxx>
28 #include "strings.hrc"
30 #include "glob.hrc" // STR_BCKGRND, STR_BCKGRNDOBJ
31 #include "app.hrc" // SID_SWITCHPAGE
33 #include "unmodpg.hxx"
35 #include "sdresid.hxx"
36 #include "drawdoc.hxx"
39 TYPEINIT1(ModifyPageUndoAction
, SdUndoAction
);
43 ModifyPageUndoAction::ModifyPageUndoAction(
44 SdDrawDocument
* pTheDoc
,
47 AutoLayout eTheNewAutoLayout
,
48 sal_Bool bTheNewBckgrndVisible
,
49 sal_Bool bTheNewBckgrndObjsVisible
)
50 : SdUndoAction(pTheDoc
)
52 DBG_ASSERT(pThePage
, "Undo without a page???");
55 maNewName
= aTheNewName
;
56 meNewAutoLayout
= eTheNewAutoLayout
;
57 mbNewBckgrndVisible
= bTheNewBckgrndVisible
;
58 mbNewBckgrndObjsVisible
= bTheNewBckgrndObjsVisible
;
60 meOldAutoLayout
= mpPage
->GetAutoLayout();
62 if (!mpPage
->IsMasterPage())
64 maOldName
= mpPage
->GetName();
65 SdrLayerAdmin
& rLayerAdmin
= mpDoc
->GetLayerAdmin();
66 sal_uInt8 aBckgrnd
= rLayerAdmin
.GetLayerID(String(SdResId(STR_LAYER_BCKGRND
)), sal_False
);
67 sal_uInt8 aBckgrndObj
= rLayerAdmin
.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ
)), sal_False
);
68 SetOfByte aVisibleLayers
= mpPage
->TRG_GetMasterPageVisibleLayers();
70 mbOldBckgrndVisible
= aVisibleLayers
.IsSet(aBckgrnd
);
71 mbOldBckgrndObjsVisible
= aVisibleLayers
.IsSet(aBckgrndObj
);
74 maComment
= String(SdResId(STR_UNDO_MODIFY_PAGE
));
77 #include <svx/svdviter.hxx>
78 #include <svx/svdview.hxx>
79 void ModifyPageUndoAction::Undo()
81 // invalidate Selection, there could be objects deleted in this UNDO
82 // which are no longer allowed to be selected then.
83 SdrViewIter
aIter(mpPage
);
84 SdrView
* pView
= aIter
.FirstView();
88 if(pView
->AreObjectsMarked())
90 pView
= aIter
.NextView();
93 mpPage
->SetAutoLayout( meOldAutoLayout
);
95 if (!mpPage
->IsMasterPage())
97 if (mpPage
->GetName() != maOldName
)
99 mpPage
->SetName(maOldName
);
101 if (mpPage
->GetPageKind() == PK_STANDARD
)
103 SdPage
* pNotesPage
= (SdPage
*)mpDoc
->GetPage(mpPage
->GetPageNum() + 1);
104 pNotesPage
->SetName(maOldName
);
108 SdrLayerAdmin
& rLayerAdmin
= mpDoc
->GetLayerAdmin();
109 sal_uInt8 aBckgrnd
= rLayerAdmin
.GetLayerID(String(SdResId(STR_LAYER_BCKGRND
)), sal_False
);
110 sal_uInt8 aBckgrndObj
= rLayerAdmin
.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ
)), sal_False
);
111 SetOfByte aVisibleLayers
;
112 aVisibleLayers
.Set(aBckgrnd
, mbOldBckgrndVisible
);
113 aVisibleLayers
.Set(aBckgrndObj
, mbOldBckgrndObjsVisible
);
114 mpPage
->TRG_SetMasterPageVisibleLayers(aVisibleLayers
);
118 SfxViewFrame::Current()->GetDispatcher()->Execute(
119 SID_SWITCHPAGE
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
);
123 void ModifyPageUndoAction::Redo()
125 // invalidate Selection, there could be objects deleted in this UNDO
126 // which are no longer allowed to be selected then.
127 SdrViewIter
aIter(mpPage
);
128 SdrView
* pView
= aIter
.FirstView();
132 if(pView
->AreObjectsMarked())
134 pView
= aIter
.NextView();
137 mpPage
->meAutoLayout
= meNewAutoLayout
;
139 if (!mpPage
->IsMasterPage())
141 if (mpPage
->GetName() != maNewName
)
143 mpPage
->SetName(maNewName
);
145 if (mpPage
->GetPageKind() == PK_STANDARD
)
147 SdPage
* pNotesPage
= (SdPage
*)mpDoc
->GetPage(mpPage
->GetPageNum() + 1);
148 pNotesPage
->SetName(maNewName
);
152 SdrLayerAdmin
& rLayerAdmin
= mpDoc
->GetLayerAdmin();
153 sal_uInt8 aBckgrnd
= rLayerAdmin
.GetLayerID(String(SdResId(STR_LAYER_BCKGRND
)), sal_False
);
154 sal_uInt8 aBckgrndObj
= rLayerAdmin
.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ
)), sal_False
);
155 SetOfByte aVisibleLayers
;
156 aVisibleLayers
.Set(aBckgrnd
, mbNewBckgrndVisible
);
157 aVisibleLayers
.Set(aBckgrndObj
, mbNewBckgrndObjsVisible
);
158 mpPage
->TRG_SetMasterPageVisibleLayers(aVisibleLayers
);
162 SfxViewFrame::Current()->GetDispatcher()->Execute(
163 SID_SWITCHPAGE
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
);
167 ModifyPageUndoAction::~ModifyPageUndoAction()
172 OUString
ModifyPageUndoAction::GetComment() const
177 // --------------------------------------------------------------------
179 RenameLayoutTemplateUndoAction::RenameLayoutTemplateUndoAction( SdDrawDocument
* pDocument
, const String
& rOldLayoutName
, const String
& rNewLayoutName
)
180 : SdUndoAction(pDocument
)
181 , maOldName( rOldLayoutName
)
182 , maNewName( rNewLayoutName
)
183 , maComment(SdResId(STR_TITLE_RENAMESLIDE
))
185 sal_uInt16 nPos
= maOldName
.SearchAscii( SD_LT_SEPARATOR
);
186 if( nPos
!= (sal_uInt16
)-1 )
187 maOldName
.Erase(nPos
);
190 void RenameLayoutTemplateUndoAction::Undo()
192 String
aLayoutName( maNewName
);
193 aLayoutName
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR
));
194 aLayoutName
.Append( String(SdResId(STR_LAYOUT_OUTLINE
))) ;
196 mpDoc
->RenameLayoutTemplate( aLayoutName
, maOldName
);
199 void RenameLayoutTemplateUndoAction::Redo()
201 String
aLayoutName( maOldName
);
202 aLayoutName
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR
));
203 aLayoutName
.Append( String(SdResId(STR_LAYOUT_OUTLINE
))) ;
205 mpDoc
->RenameLayoutTemplate( aLayoutName
, maNewName
);
208 OUString
RenameLayoutTemplateUndoAction::GetComment() const
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */