Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/view/drviewsb.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/viewfrm.hxx>
22
#include <sfx2/dispatch.hxx>
23
#include <svtools/dlgname.hxx>
24
#include <svx/fmshell.hxx>
25
#include <svx/svxdlg.hxx>
26
#include <osl/diagnose.h>
27
28
#include <app.hrc>
29
30
#include <drawdoc.hxx>
31
#include <DrawDocShell.hxx>
32
#include <unokywds.hxx>
33
#include <sdpage.hxx>
34
#include <DrawViewShell.hxx>
35
#include <drawview.hxx>
36
#include <unmodpg.hxx>
37
#include <ViewShellBase.hxx>
38
#include <FormShellManager.hxx>
39
#include <LayerTabBar.hxx>
40
#include <SlideSorterViewShell.hxx>
41
#include <SlideSorter.hxx>
42
#include <controller/SlideSorterController.hxx>
43
44
namespace sd {
45
46
bool DrawViewShell::RenameSlide( sal_uInt16 nPageId, const OUString & rName  )
47
0
{
48
0
    bool   bOutDummy;
49
0
    if( GetDoc()->GetPageByName( rName, bOutDummy ) != SDRPAGE_NOTFOUND )
50
0
        return false;
51
52
0
    SdPage* pPageToRename = nullptr;
53
0
    PageKind ePageKind = GetPageKind();
54
55
0
    if( GetEditMode() == EditMode::Page )
56
0
    {
57
0
        pPageToRename = GetDoc()->GetSdPage( maTabControl->GetPagePos(nPageId), ePageKind );
58
59
        // Undo
60
0
        SdPage* pUndoPage = pPageToRename;
61
0
        SdrLayerAdmin &  rLayerAdmin = GetDoc()->GetLayerAdmin();
62
0
        SdrLayerID nBackground = rLayerAdmin.GetLayerID(sUNO_LayerName_background);
63
0
        SdrLayerID nBgObj = rLayerAdmin.GetLayerID(sUNO_LayerName_background_objects);
64
0
        SdrLayerIDSet aVisibleLayers = mpActualPage->TRG_GetMasterPageVisibleLayers();
65
66
0
        SfxUndoManager* pManager = GetDoc()->GetDocSh()->GetUndoManager();
67
0
        pManager->AddUndoAction(
68
0
            std::make_unique<ModifyPageUndoAction>(
69
0
                *GetDoc(), pUndoPage, rName, pUndoPage->GetAutoLayout(),
70
0
                aVisibleLayers.IsSet( nBackground ),
71
0
                aVisibleLayers.IsSet( nBgObj )));
72
73
        // rename
74
0
        pPageToRename->SetName( rName );
75
76
0
        if( ePageKind == PageKind::Standard )
77
0
        {
78
            // also rename notes-page
79
0
            SdPage* pNotesPage = GetDoc()->GetSdPage( maTabControl->GetPagePos(nPageId), PageKind::Notes );
80
0
            pNotesPage->SetName( rName );
81
0
        }
82
0
    }
83
0
    else
84
0
    {
85
        // rename MasterPage -> rename LayoutTemplate
86
0
        pPageToRename = GetDoc()->GetMasterSdPage( maTabControl->GetPagePos(nPageId), ePageKind );
87
0
        OUString aOldPageLayoutName = pPageToRename->GetLayoutName();
88
0
        GetDoc()->RenameLayoutTemplate(aOldPageLayoutName, rName);
89
0
    }
90
91
0
    bool bSuccess = (rName == pPageToRename->GetName());
92
93
0
    if( bSuccess )
94
0
    {
95
        // user edited page names may be changed by the page so update control
96
0
        maTabControl->SetPageText( nPageId, rName );
97
98
        // set document to modified state
99
0
        GetDoc()->SetChanged();
100
101
        // inform navigator about change
102
0
        if (GetViewFrame())
103
0
        {
104
0
            SfxBindings& rBindings = GetViewFrame()->GetBindings();
105
0
            rBindings.Invalidate(SID_NAVIGATOR_STATE, true);
106
0
        }
107
108
        // Tell the slide sorter about the name change (necessary for
109
        // accessibility.)
110
0
        slidesorter::SlideSorterViewShell* pSlideSorterViewShell
111
0
            = slidesorter::SlideSorterViewShell::GetSlideSorter(GetViewShellBase());
112
0
        if (pSlideSorterViewShell != nullptr)
113
0
        {
114
0
            pSlideSorterViewShell->GetSlideSorter().GetController().PageNameHasChanged(
115
0
                maTabControl->GetPagePos(nPageId), rName);
116
0
        }
117
0
    }
118
119
0
    return bSuccess;
120
0
}
121
122
IMPL_LINK(DrawViewShell, RenameSlideHdl, SvxNameDialog&, rDialog, bool)
123
0
{
124
0
    OUString aNewName = rDialog.GetName();
125
126
0
    SdPage* pCurrentPage = GetDoc()->GetSdPage( maTabControl->GetCurPagePos(), GetPageKind() );
127
128
0
    return pCurrentPage && ( aNewName == pCurrentPage->GetName() || GetDocSh()->IsNewPageNameValid( aNewName ) );
129
0
}
130
131
void DrawViewShell::ModifyLayer (
132
    SdrLayer* pLayer,
133
    const OUString& rLayerName,
134
    const OUString& rLayerTitle,
135
    const OUString& rLayerDesc,
136
    bool bIsVisible,
137
    bool bIsLocked,
138
    bool bIsPrintable)
139
0
{
140
0
    if(!GetLayerTabControl()) // #i87182#
141
0
    {
142
0
        OSL_ENSURE(false, "No LayerTabBar (!)");
143
0
        return;
144
0
    }
145
146
0
    if( !pLayer )
147
0
        return;
148
149
0
    const sal_uInt16 nPageCount = GetLayerTabControl()->GetPageCount();
150
0
    sal_uInt16 nCurPage = 0;
151
0
    sal_uInt16 nPos;
152
0
    for( nPos = 0; nPos < nPageCount; nPos++ )
153
0
    {
154
0
        sal_uInt16 nId = GetLayerTabControl()->GetPageId( nPos );
155
0
        if (GetLayerTabControl()->GetLayerName(nId) == pLayer->GetName())
156
0
        {
157
0
            nCurPage = nId;
158
0
            break;
159
0
        }
160
0
    }
161
162
0
    pLayer->SetName( rLayerName );
163
0
    pLayer->SetTitle( rLayerTitle );
164
0
    pLayer->SetDescription( rLayerDesc );
165
0
    mpDrawView->SetLayerVisible( rLayerName, bIsVisible );
166
0
    mpDrawView->SetLayerLocked( rLayerName, bIsLocked);
167
0
    mpDrawView->SetLayerPrintable(rLayerName, bIsPrintable);
168
169
0
    GetDoc()->SetChanged();
170
171
0
    GetLayerTabControl()->SetPageText(nCurPage, rLayerName);
172
173
    // Set page bits for modified tab name display
174
175
0
    TabBarPageBits nBits = TabBarPageBits::NONE;
176
177
0
    if (!bIsVisible)
178
0
    {
179
0
        nBits = TabBarPageBits::Blue;
180
0
    }
181
0
    if (bIsLocked)
182
0
    {
183
0
        nBits |= TabBarPageBits::Italic;
184
0
    }
185
0
    if (!bIsPrintable)
186
0
    {
187
0
        nBits |= TabBarPageBits::Underline;
188
0
    }
189
190
    // Save the bits
191
192
0
    GetLayerTabControl()->SetPageBits(nCurPage, nBits);
193
194
0
    GetViewFrame()->GetDispatcher()->Execute(
195
0
        SID_SWITCHLAYER,
196
0
        SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
197
198
    // Call Invalidate at the form shell.
199
0
    FmFormShell* pFormShell = GetViewShellBase().GetFormShellManager()->GetFormShell();
200
0
    if (pFormShell != nullptr)
201
0
        pFormShell->Invalidate();
202
0
}
203
204
} // end of namespace sd
205
206
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */