Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/view/unmodpg.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
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>
26
27
#include <strings.hrc>
28
#include <strings.hxx>
29
#include <glob.hxx>
30
#include <app.hrc>
31
32
#include <unmodpg.hxx>
33
#include <sdpage.hxx>
34
#include <sdresid.hxx>
35
#include <unokywds.hxx>
36
#include <drawdoc.hxx>
37
#include <utility>
38
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>
45
46
ModifyPageUndoAction::ModifyPageUndoAction(
47
    SdDrawDocument& rTheDoc,
48
    SdPage* pThePage,
49
    const OUString& aTheNewName,
50
    AutoLayout  eTheNewAutoLayout,
51
    bool bTheNewBckgrndVisible,
52
    bool bTheNewBckgrndObjsVisible)
53
0
:   SdUndoAction(rTheDoc)
54
0
{
55
0
    DBG_ASSERT(pThePage, "Undo without a page???");
56
57
0
    mpPage                  = pThePage;
58
0
    maNewName               = aTheNewName;
59
0
    meNewAutoLayout         = eTheNewAutoLayout;
60
0
    mbNewBckgrndVisible     = bTheNewBckgrndVisible;
61
0
    mbNewBckgrndObjsVisible = bTheNewBckgrndObjsVisible;
62
63
0
    meOldAutoLayout         = mpPage->GetAutoLayout();
64
65
0
    if (!mpPage->IsMasterPage())
66
0
    {
67
0
        maOldName = mpPage->GetName();
68
0
        SdrLayerAdmin& rLayerAdmin = mrDoc.GetLayerAdmin();
69
0
        SdrLayerID aBckgrnd = rLayerAdmin.GetLayerID(sUNO_LayerName_background);
70
0
        SdrLayerID aBckgrndObj = rLayerAdmin.GetLayerID(sUNO_LayerName_background_objects);
71
0
        SdrLayerIDSet aVisibleLayers = mpPage->TRG_GetMasterPageVisibleLayers();
72
73
0
        mbOldBckgrndVisible = aVisibleLayers.IsSet(aBckgrnd);
74
0
        mbOldBckgrndObjsVisible = aVisibleLayers.IsSet(aBckgrndObj);
75
0
    }
76
0
    else
77
0
    {
78
0
        mbOldBckgrndVisible = false;
79
0
        mbOldBckgrndObjsVisible = false;
80
0
    }
81
82
0
    if (rTheDoc.GetDocumentType() == DocumentType::Draw)
83
0
        SetComment( SdResId(STR_UNDO_MODIFY_PAGE_DRAW) );
84
0
    else
85
0
        SetComment( SdResId(STR_UNDO_MODIFY_PAGE) );
86
0
}
87
88
void ModifyPageUndoAction::Undo()
89
0
{
90
    // invalidate Selection, there could be objects deleted in this UNDO
91
    // which are no longer allowed to be selected then.
92
0
    SdrViewIter::ForAllViews(mpPage,
93
0
        [] (SdrView* pView)
94
0
        {
95
0
            if(pView->GetMarkedObjectList().GetMarkCount() != 0)
96
0
                pView->UnmarkAll();
97
0
        });
98
99
0
    mpPage->SetAutoLayout( meOldAutoLayout );
100
101
0
    if (!mpPage->IsMasterPage())
102
0
    {
103
0
        if (mpPage->GetName() != maOldName)
104
0
        {
105
0
            mpPage->SetName(maOldName);
106
107
0
            if (mpPage->GetPageKind() == PageKind::Standard)
108
0
            {
109
0
                SdPage* pNotesPage = static_cast<SdPage*>(mrDoc.GetPage(mpPage->GetPageNum() + 1));
110
0
                pNotesPage->SetName(maOldName);
111
0
            }
112
0
        }
113
114
0
        SdrLayerAdmin& rLayerAdmin = mrDoc.GetLayerAdmin();
115
0
        SdrLayerID aBckgrnd = rLayerAdmin.GetLayerID(sUNO_LayerName_background);
116
0
        SdrLayerID aBckgrndObj = rLayerAdmin.GetLayerID(sUNO_LayerName_background_objects);
117
0
        SdrLayerIDSet aVisibleLayers;
118
0
        aVisibleLayers.Set(aBckgrnd, mbOldBckgrndVisible);
119
0
        aVisibleLayers.Set(aBckgrndObj, mbOldBckgrndObjsVisible);
120
0
        mpPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
121
0
    }
122
123
    // Redisplay
124
0
    SfxViewFrame* pCurrent = SfxViewFrame::Current();
125
0
    if( pCurrent )
126
0
    {
127
0
        pCurrent->GetDispatcher()->Execute(
128
0
            SID_SWITCHPAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
129
0
    }
130
0
}
131
132
void ModifyPageUndoAction::Redo()
133
0
{
134
    // invalidate Selection, there could be objects deleted in this UNDO
135
    // which are no longer allowed to be selected then.
136
0
    SdrViewIter::ForAllViews(mpPage,
137
0
        [] (SdrView* pView)
138
0
        {
139
0
            if(pView->GetMarkedObjectList().GetMarkCount() != 0)
140
0
                pView->UnmarkAll();
141
0
        });
142
143
0
    mpPage->meAutoLayout = meNewAutoLayout;
144
145
0
    if (!mpPage->IsMasterPage())
146
0
    {
147
0
        if (mpPage->GetName() != maNewName)
148
0
        {
149
0
            mpPage->SetName(maNewName);
150
151
0
            if (mpPage->GetPageKind() == PageKind::Standard)
152
0
            {
153
0
                SdPage* pNotesPage = static_cast<SdPage*>(mrDoc.GetPage(mpPage->GetPageNum() + 1));
154
0
                pNotesPage->SetName(maNewName);
155
0
            }
156
0
        }
157
158
0
        SdrLayerAdmin& rLayerAdmin = mrDoc.GetLayerAdmin();
159
0
        SdrLayerID aBckgrnd = rLayerAdmin.GetLayerID(sUNO_LayerName_background);
160
0
        SdrLayerID aBckgrndObj = rLayerAdmin.GetLayerID(sUNO_LayerName_background_objects);
161
0
        SdrLayerIDSet aVisibleLayers;
162
0
        aVisibleLayers.Set(aBckgrnd, mbNewBckgrndVisible);
163
0
        aVisibleLayers.Set(aBckgrndObj, mbNewBckgrndObjsVisible);
164
0
        mpPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
165
0
    }
166
167
    // Redisplay
168
0
    SfxViewFrame* pCurrent = SfxViewFrame::Current();
169
0
    if( pCurrent )
170
0
    {
171
0
        pCurrent->GetDispatcher()->Execute(
172
0
            SID_SWITCHPAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
173
0
    }
174
0
}
175
176
ModifyPageUndoAction::~ModifyPageUndoAction()
177
0
{
178
0
}
179
180
ChangeSlideExclusionStateUndoAction::ChangeSlideExclusionStateUndoAction(
181
    SdDrawDocument& rDocument, const sd::slidesorter::model::PageDescriptor::State eState,
182
    const bool bOldStateValue)
183
0
    : SdUndoAction(rDocument)
184
0
    , meState(eState)
185
0
    , mbOldStateValue(bOldStateValue)
186
0
    , maComment(bOldStateValue ? SdResId(STR_UNDO_SHOW_SLIDE) : SdResId(STR_UNDO_HIDE_SLIDE))
187
0
{
188
0
}
189
190
ChangeSlideExclusionStateUndoAction::ChangeSlideExclusionStateUndoAction(
191
    SdDrawDocument& rDocument, const sd::slidesorter::model::SharedPageDescriptor& rpDescriptor,
192
    const sd::slidesorter::model::PageDescriptor::State eState, const bool bOldStateValue)
193
0
    : ChangeSlideExclusionStateUndoAction(rDocument, eState, bOldStateValue)
194
0
{
195
0
    mrpDescriptors.push_back(rpDescriptor);
196
0
}
197
198
void ChangeSlideExclusionStateUndoAction::AddPageDescriptor(
199
    const sd::slidesorter::model::SharedPageDescriptor& rpDescriptor)
200
0
{
201
0
    mrpDescriptors.push_back(rpDescriptor);
202
0
}
203
204
void ChangeSlideExclusionStateUndoAction::Undo()
205
0
{
206
0
    sd::DrawDocShell* pDocShell = mrDoc.GetDocSh();
207
0
    sd::ViewShell* pViewShell = pDocShell ? pDocShell->GetViewShell() : nullptr;
208
0
    if (pViewShell)
209
0
    {
210
0
        sd::slidesorter::SlideSorterViewShell* pSlideSorterViewShell
211
0
            = sd::slidesorter::SlideSorterViewShell::GetSlideSorter(pViewShell->GetViewShellBase());
212
0
        if (pSlideSorterViewShell)
213
0
        {
214
0
            for (const sd::slidesorter::model::SharedPageDescriptor& rpDescriptor : mrpDescriptors)
215
0
                pSlideSorterViewShell->GetSlideSorter().GetView().SetState(rpDescriptor, meState,
216
0
                                                                           mbOldStateValue);
217
0
        }
218
0
    }
219
0
}
220
221
void ChangeSlideExclusionStateUndoAction::Redo()
222
0
{
223
0
    sd::DrawDocShell* pDocShell = mrDoc.GetDocSh();
224
0
    sd::ViewShell* pViewShell = pDocShell ? pDocShell->GetViewShell() : nullptr;
225
0
    if (pViewShell)
226
0
    {
227
0
        sd::slidesorter::SlideSorterViewShell* pSlideSorterViewShell
228
0
            = sd::slidesorter::SlideSorterViewShell::GetSlideSorter(pViewShell->GetViewShellBase());
229
0
        if (pSlideSorterViewShell)
230
0
        {
231
0
            for (const sd::slidesorter::model::SharedPageDescriptor& rpDescriptor : mrpDescriptors)
232
0
                pSlideSorterViewShell->GetSlideSorter().GetView().SetState(rpDescriptor, meState,
233
0
                                                                           !mbOldStateValue);
234
0
        }
235
0
    }
236
0
}
237
238
OUString ChangeSlideExclusionStateUndoAction::GetComment() const
239
0
{
240
0
    return maComment;
241
0
}
242
243
RenameLayoutTemplateUndoAction::RenameLayoutTemplateUndoAction(
244
    SdDrawDocument& rDocument,
245
    OUString aOldLayoutName,
246
    OUString aNewLayoutName)
247
0
    : SdUndoAction(rDocument)
248
0
    , maOldName(std::move(aOldLayoutName))
249
0
    , maNewName(std::move(aNewLayoutName))
250
0
    , maComment(SdResId(STR_TITLE_RENAMESLIDE))
251
0
{
252
0
    sal_Int32 nPos = maOldName.indexOf(SD_LT_SEPARATOR);
253
0
    if (nPos != -1)
254
0
        maOldName = maOldName.copy(0, nPos);
255
0
}
256
257
void RenameLayoutTemplateUndoAction::Undo()
258
0
{
259
0
    OUString aLayoutName(maNewName + SD_LT_SEPARATOR + STR_LAYOUT_OUTLINE);
260
0
    mrDoc.RenameLayoutTemplate( aLayoutName, maOldName );
261
0
}
262
263
void RenameLayoutTemplateUndoAction::Redo()
264
0
{
265
0
    OUString aLayoutName(maOldName + SD_LT_SEPARATOR + STR_LAYOUT_OUTLINE);
266
0
    mrDoc.RenameLayoutTemplate( aLayoutName, maNewName );
267
0
}
268
269
OUString RenameLayoutTemplateUndoAction::GetComment() const
270
0
{
271
0
    return  maComment;
272
0
}
273
274
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */