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 .
20 #include <svx/svdlayer.hxx>
21 #include <sfx2/dispatch.hxx>
22 #include <sfx2/viewfrm.hxx>
24 #include "strings.hrc"
29 #include "unmodpg.hxx"
31 #include "sdresid.hxx"
32 #include "drawdoc.hxx"
34 TYPEINIT1(ModifyPageUndoAction
, SdUndoAction
);
36 ModifyPageUndoAction::ModifyPageUndoAction(
37 SdDrawDocument
* pTheDoc
,
39 const OUString
& aTheNewName
,
40 AutoLayout eTheNewAutoLayout
,
41 bool bTheNewBckgrndVisible
,
42 bool bTheNewBckgrndObjsVisible
)
43 : SdUndoAction(pTheDoc
)
45 DBG_ASSERT(pThePage
, "Undo without a page???");
48 maNewName
= aTheNewName
;
49 meNewAutoLayout
= eTheNewAutoLayout
;
50 mbNewBckgrndVisible
= bTheNewBckgrndVisible
;
51 mbNewBckgrndObjsVisible
= bTheNewBckgrndObjsVisible
;
53 meOldAutoLayout
= mpPage
->GetAutoLayout();
55 if (!mpPage
->IsMasterPage())
57 maOldName
= mpPage
->GetName();
58 SdrLayerAdmin
& rLayerAdmin
= mpDoc
->GetLayerAdmin();
59 sal_uInt8 aBckgrnd
= rLayerAdmin
.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND
), false);
60 sal_uInt8 aBckgrndObj
= rLayerAdmin
.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ
), false);
61 SetOfByte aVisibleLayers
= mpPage
->TRG_GetMasterPageVisibleLayers();
63 mbOldBckgrndVisible
= aVisibleLayers
.IsSet(aBckgrnd
);
64 mbOldBckgrndObjsVisible
= aVisibleLayers
.IsSet(aBckgrndObj
);
68 mbOldBckgrndVisible
= false;
69 mbOldBckgrndObjsVisible
= false;
72 maComment
= SD_RESSTR(STR_UNDO_MODIFY_PAGE
);
75 #include <svx/svdviter.hxx>
76 #include <svx/svdview.hxx>
77 void ModifyPageUndoAction::Undo()
79 // invalidate Selection, there could be objects deleted in this UNDO
80 // which are no longer allowed to be selected then.
81 SdrViewIter
aIter(mpPage
);
82 SdrView
* pView
= aIter
.FirstView();
86 if(pView
->AreObjectsMarked())
88 pView
= aIter
.NextView();
91 mpPage
->SetAutoLayout( meOldAutoLayout
);
93 if (!mpPage
->IsMasterPage())
95 if (mpPage
->GetName() != maOldName
)
97 mpPage
->SetName(maOldName
);
99 if (mpPage
->GetPageKind() == PK_STANDARD
)
101 SdPage
* pNotesPage
= static_cast<SdPage
*>(mpDoc
->GetPage(mpPage
->GetPageNum() + 1));
102 pNotesPage
->SetName(maOldName
);
106 SdrLayerAdmin
& rLayerAdmin
= mpDoc
->GetLayerAdmin();
107 sal_uInt8 aBckgrnd
= rLayerAdmin
.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND
), false);
108 sal_uInt8 aBckgrndObj
= rLayerAdmin
.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ
), false);
109 SetOfByte aVisibleLayers
;
110 aVisibleLayers
.Set(aBckgrnd
, mbOldBckgrndVisible
);
111 aVisibleLayers
.Set(aBckgrndObj
, mbOldBckgrndObjsVisible
);
112 mpPage
->TRG_SetMasterPageVisibleLayers(aVisibleLayers
);
116 SfxViewFrame::Current()->GetDispatcher()->Execute(
117 SID_SWITCHPAGE
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
120 void ModifyPageUndoAction::Redo()
122 // invalidate Selection, there could be objects deleted in this UNDO
123 // which are no longer allowed to be selected then.
124 SdrViewIter
aIter(mpPage
);
125 SdrView
* pView
= aIter
.FirstView();
129 if(pView
->AreObjectsMarked())
131 pView
= aIter
.NextView();
134 mpPage
->meAutoLayout
= meNewAutoLayout
;
136 if (!mpPage
->IsMasterPage())
138 if (mpPage
->GetName() != maNewName
)
140 mpPage
->SetName(maNewName
);
142 if (mpPage
->GetPageKind() == PK_STANDARD
)
144 SdPage
* pNotesPage
= static_cast<SdPage
*>(mpDoc
->GetPage(mpPage
->GetPageNum() + 1));
145 pNotesPage
->SetName(maNewName
);
149 SdrLayerAdmin
& rLayerAdmin
= mpDoc
->GetLayerAdmin();
150 sal_uInt8 aBckgrnd
= rLayerAdmin
.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND
), false);
151 sal_uInt8 aBckgrndObj
= rLayerAdmin
.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ
), false);
152 SetOfByte aVisibleLayers
;
153 aVisibleLayers
.Set(aBckgrnd
, mbNewBckgrndVisible
);
154 aVisibleLayers
.Set(aBckgrndObj
, mbNewBckgrndObjsVisible
);
155 mpPage
->TRG_SetMasterPageVisibleLayers(aVisibleLayers
);
159 SfxViewFrame::Current()->GetDispatcher()->Execute(
160 SID_SWITCHPAGE
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
163 ModifyPageUndoAction::~ModifyPageUndoAction()
167 OUString
ModifyPageUndoAction::GetComment() const
172 RenameLayoutTemplateUndoAction::RenameLayoutTemplateUndoAction(
173 SdDrawDocument
* pDocument
,
174 const OUString
& rOldLayoutName
,
175 const OUString
& rNewLayoutName
)
176 : SdUndoAction(pDocument
)
177 , maOldName(rOldLayoutName
)
178 , maNewName(rNewLayoutName
)
179 , maComment(SD_RESSTR(STR_TITLE_RENAMESLIDE
))
181 sal_Int32 nPos
= maOldName
.indexOf(SD_LT_SEPARATOR
);
183 maOldName
= maOldName
.copy(0, nPos
);
186 void RenameLayoutTemplateUndoAction::Undo()
188 OUString
aLayoutName(maNewName
+ SD_LT_SEPARATOR
+ SD_RESSTR(STR_LAYOUT_OUTLINE
));
189 mpDoc
->RenameLayoutTemplate( aLayoutName
, maOldName
);
192 void RenameLayoutTemplateUndoAction::Redo()
194 OUString
aLayoutName(maOldName
+ SD_LT_SEPARATOR
+ SD_RESSTR(STR_LAYOUT_OUTLINE
));
195 mpDoc
->RenameLayoutTemplate( aLayoutName
, maNewName
);
198 OUString
RenameLayoutTemplateUndoAction::GetComment() const
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */