cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / view / unmodpg.cxx
blob8ed7837b79ec31662ce04261e13e1b8d44e14bfb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
23 #include <svx/svdviter.hxx>
24 #include <svx/svdview.hxx>
25 #include <tools/debug.hxx>
27 #include <strings.hrc>
28 #include <strings.hxx>
29 #include <glob.hxx>
30 #include <app.hrc>
32 #include <unmodpg.hxx>
33 #include <sdpage.hxx>
34 #include <sdresid.hxx>
35 #include <unokywds.hxx>
36 #include <drawdoc.hxx>
37 #include <utility>
39 #include <ViewShell.hxx>
40 #include <ViewShellBase.hxx>
41 #include <DrawDocShell.hxx>
42 #include <SlideSorter.hxx>
43 #include <SlideSorterViewShell.hxx>
44 #include <view/SlideSorterView.hxx>
46 ModifyPageUndoAction::ModifyPageUndoAction(
47 SdDrawDocument* pTheDoc,
48 SdPage* pThePage,
49 const OUString& aTheNewName,
50 AutoLayout eTheNewAutoLayout,
51 bool bTheNewBckgrndVisible,
52 bool bTheNewBckgrndObjsVisible)
53 : SdUndoAction(pTheDoc)
55 DBG_ASSERT(pThePage, "Undo without a page???");
57 mpPage = pThePage;
58 maNewName = aTheNewName;
59 meNewAutoLayout = eTheNewAutoLayout;
60 mbNewBckgrndVisible = bTheNewBckgrndVisible;
61 mbNewBckgrndObjsVisible = bTheNewBckgrndObjsVisible;
63 meOldAutoLayout = mpPage->GetAutoLayout();
65 if (!mpPage->IsMasterPage())
67 maOldName = mpPage->GetName();
68 SdrLayerAdmin& rLayerAdmin = mpDoc->GetLayerAdmin();
69 SdrLayerID aBckgrnd = rLayerAdmin.GetLayerID(sUNO_LayerName_background);
70 SdrLayerID aBckgrndObj = rLayerAdmin.GetLayerID(sUNO_LayerName_background_objects);
71 SdrLayerIDSet aVisibleLayers = mpPage->TRG_GetMasterPageVisibleLayers();
73 mbOldBckgrndVisible = aVisibleLayers.IsSet(aBckgrnd);
74 mbOldBckgrndObjsVisible = aVisibleLayers.IsSet(aBckgrndObj);
76 else
78 mbOldBckgrndVisible = false;
79 mbOldBckgrndObjsVisible = false;
82 if (pTheDoc && pTheDoc->GetDocumentType() == DocumentType::Draw)
83 SetComment( SdResId(STR_UNDO_MODIFY_PAGE_DRAW) );
84 else
85 SetComment( SdResId(STR_UNDO_MODIFY_PAGE) );
88 void ModifyPageUndoAction::Undo()
90 // invalidate Selection, there could be objects deleted in this UNDO
91 // which are no longer allowed to be selected then.
92 SdrViewIter::ForAllViews(mpPage,
93 [] (SdrView* pView)
95 if(pView->GetMarkedObjectList().GetMarkCount() != 0)
96 pView->UnmarkAll();
97 });
99 mpPage->SetAutoLayout( meOldAutoLayout );
101 if (!mpPage->IsMasterPage())
103 if (mpPage->GetName() != maOldName)
105 mpPage->SetName(maOldName);
107 if (mpPage->GetPageKind() == PageKind::Standard)
109 SdPage* pNotesPage = static_cast<SdPage*>(mpDoc->GetPage(mpPage->GetPageNum() + 1));
110 pNotesPage->SetName(maOldName);
114 SdrLayerAdmin& rLayerAdmin = mpDoc->GetLayerAdmin();
115 SdrLayerID aBckgrnd = rLayerAdmin.GetLayerID(sUNO_LayerName_background);
116 SdrLayerID aBckgrndObj = rLayerAdmin.GetLayerID(sUNO_LayerName_background_objects);
117 SdrLayerIDSet aVisibleLayers;
118 aVisibleLayers.Set(aBckgrnd, mbOldBckgrndVisible);
119 aVisibleLayers.Set(aBckgrndObj, mbOldBckgrndObjsVisible);
120 mpPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
123 // Redisplay
124 SfxViewFrame* pCurrent = SfxViewFrame::Current();
125 if( pCurrent )
127 pCurrent->GetDispatcher()->Execute(
128 SID_SWITCHPAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
132 void ModifyPageUndoAction::Redo()
134 // invalidate Selection, there could be objects deleted in this UNDO
135 // which are no longer allowed to be selected then.
136 SdrViewIter::ForAllViews(mpPage,
137 [] (SdrView* pView)
139 if(pView->GetMarkedObjectList().GetMarkCount() != 0)
140 pView->UnmarkAll();
143 mpPage->meAutoLayout = meNewAutoLayout;
145 if (!mpPage->IsMasterPage())
147 if (mpPage->GetName() != maNewName)
149 mpPage->SetName(maNewName);
151 if (mpPage->GetPageKind() == PageKind::Standard)
153 SdPage* pNotesPage = static_cast<SdPage*>(mpDoc->GetPage(mpPage->GetPageNum() + 1));
154 pNotesPage->SetName(maNewName);
158 SdrLayerAdmin& rLayerAdmin = mpDoc->GetLayerAdmin();
159 SdrLayerID aBckgrnd = rLayerAdmin.GetLayerID(sUNO_LayerName_background);
160 SdrLayerID aBckgrndObj = rLayerAdmin.GetLayerID(sUNO_LayerName_background_objects);
161 SdrLayerIDSet aVisibleLayers;
162 aVisibleLayers.Set(aBckgrnd, mbNewBckgrndVisible);
163 aVisibleLayers.Set(aBckgrndObj, mbNewBckgrndObjsVisible);
164 mpPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
167 // Redisplay
168 SfxViewFrame* pCurrent = SfxViewFrame::Current();
169 if( pCurrent )
171 pCurrent->GetDispatcher()->Execute(
172 SID_SWITCHPAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
176 ModifyPageUndoAction::~ModifyPageUndoAction()
180 ChangeSlideExclusionStateUndoAction::ChangeSlideExclusionStateUndoAction(
181 SdDrawDocument* pDocument, const sd::slidesorter::model::PageDescriptor::State eState,
182 const bool bOldStateValue)
183 : SdUndoAction(pDocument)
184 , meState(eState)
185 , mbOldStateValue(bOldStateValue)
186 , maComment(bOldStateValue ? SdResId(STR_UNDO_SHOW_SLIDE) : SdResId(STR_UNDO_HIDE_SLIDE))
190 ChangeSlideExclusionStateUndoAction::ChangeSlideExclusionStateUndoAction(
191 SdDrawDocument* pDocument, const sd::slidesorter::model::SharedPageDescriptor& rpDescriptor,
192 const sd::slidesorter::model::PageDescriptor::State eState, const bool bOldStateValue)
193 : ChangeSlideExclusionStateUndoAction(pDocument, eState, bOldStateValue)
195 mrpDescriptors.push_back(rpDescriptor);
198 void ChangeSlideExclusionStateUndoAction::AddPageDescriptor(
199 const sd::slidesorter::model::SharedPageDescriptor& rpDescriptor)
201 mrpDescriptors.push_back(rpDescriptor);
204 void ChangeSlideExclusionStateUndoAction::Undo()
206 sd::DrawDocShell* pDocShell = mpDoc ? mpDoc->GetDocSh() : nullptr;
207 sd::ViewShell* pViewShell = pDocShell ? pDocShell->GetViewShell() : nullptr;
208 if (pViewShell)
210 sd::slidesorter::SlideSorterViewShell* pSlideSorterViewShell
211 = sd::slidesorter::SlideSorterViewShell::GetSlideSorter(pViewShell->GetViewShellBase());
212 if (pSlideSorterViewShell)
214 for (const sd::slidesorter::model::SharedPageDescriptor& rpDescriptor : mrpDescriptors)
215 pSlideSorterViewShell->GetSlideSorter().GetView().SetState(rpDescriptor, meState,
216 mbOldStateValue);
221 void ChangeSlideExclusionStateUndoAction::Redo()
223 sd::DrawDocShell* pDocShell = mpDoc ? mpDoc->GetDocSh() : nullptr;
224 sd::ViewShell* pViewShell = pDocShell ? pDocShell->GetViewShell() : nullptr;
225 if (pViewShell)
227 sd::slidesorter::SlideSorterViewShell* pSlideSorterViewShell
228 = sd::slidesorter::SlideSorterViewShell::GetSlideSorter(pViewShell->GetViewShellBase());
229 if (pSlideSorterViewShell)
231 for (const sd::slidesorter::model::SharedPageDescriptor& rpDescriptor : mrpDescriptors)
232 pSlideSorterViewShell->GetSlideSorter().GetView().SetState(rpDescriptor, meState,
233 !mbOldStateValue);
238 OUString ChangeSlideExclusionStateUndoAction::GetComment() const
240 return maComment;
243 RenameLayoutTemplateUndoAction::RenameLayoutTemplateUndoAction(
244 SdDrawDocument* pDocument,
245 OUString aOldLayoutName,
246 OUString aNewLayoutName)
247 : SdUndoAction(pDocument)
248 , maOldName(std::move(aOldLayoutName))
249 , maNewName(std::move(aNewLayoutName))
250 , maComment(SdResId(STR_TITLE_RENAMESLIDE))
252 sal_Int32 nPos = maOldName.indexOf(SD_LT_SEPARATOR);
253 if (nPos != -1)
254 maOldName = maOldName.copy(0, nPos);
257 void RenameLayoutTemplateUndoAction::Undo()
259 OUString aLayoutName(maNewName + SD_LT_SEPARATOR + STR_LAYOUT_OUTLINE);
260 mpDoc->RenameLayoutTemplate( aLayoutName, maOldName );
263 void RenameLayoutTemplateUndoAction::Redo()
265 OUString aLayoutName(maOldName + SD_LT_SEPARATOR + STR_LAYOUT_OUTLINE);
266 mpDoc->RenameLayoutTemplate( aLayoutName, maNewName );
269 OUString RenameLayoutTemplateUndoAction::GetComment() const
271 return maComment;
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */