LibreOffice Module sd (master) 1
drviewsb.cxx
Go to the documentation of this file.
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 <svx/fmshell.hxx>
24#include <svx/svxdlg.hxx>
25#include <osl/diagnose.h>
26
27#include <app.hrc>
28
29#include <drawdoc.hxx>
30#include <DrawDocShell.hxx>
31#include <unokywds.hxx>
32#include <sdpage.hxx>
33#include <DrawViewShell.hxx>
34#include <drawview.hxx>
35#include <unmodpg.hxx>
36#include <ViewShellBase.hxx>
37#include <FormShellManager.hxx>
38#include <LayerTabBar.hxx>
40#include <SlideSorter.hxx>
42
43namespace sd {
44
45bool DrawViewShell::RenameSlide( sal_uInt16 nPageId, const OUString & rName )
46{
47 bool bOutDummy;
48 if( GetDoc()->GetPageByName( rName, bOutDummy ) != SDRPAGE_NOTFOUND )
49 return false;
50
51 SdPage* pPageToRename = nullptr;
52 PageKind ePageKind = GetPageKind();
53
55 {
56 pPageToRename = GetDoc()->GetSdPage( maTabControl->GetPagePos(nPageId), ePageKind );
57
58 // Undo
59 SdPage* pUndoPage = pPageToRename;
60 SdrLayerAdmin & rLayerAdmin = GetDoc()->GetLayerAdmin();
61 SdrLayerID nBackground = rLayerAdmin.GetLayerID(sUNO_LayerName_background);
64
65 SfxUndoManager* pManager = GetDoc()->GetDocSh()->GetUndoManager();
66 pManager->AddUndoAction(
67 std::make_unique<ModifyPageUndoAction>(
68 GetDoc(), pUndoPage, rName, pUndoPage->GetAutoLayout(),
69 aVisibleLayers.IsSet( nBackground ),
70 aVisibleLayers.IsSet( nBgObj )));
71
72 // rename
73 pPageToRename->SetName( rName );
74
75 if( ePageKind == PageKind::Standard )
76 {
77 // also rename notes-page
78 SdPage* pNotesPage = GetDoc()->GetSdPage( maTabControl->GetPagePos(nPageId), PageKind::Notes );
79 pNotesPage->SetName( rName );
80 }
81 }
82 else
83 {
84 // rename MasterPage -> rename LayoutTemplate
85 pPageToRename = GetDoc()->GetMasterSdPage( maTabControl->GetPagePos(nPageId), ePageKind );
86 GetDoc()->RenameLayoutTemplate( pPageToRename->GetLayoutName(), rName );
87 }
88
89 bool bSuccess = (rName == pPageToRename->GetName());
90
91 if( bSuccess )
92 {
93 // user edited page names may be changed by the page so update control
94 maTabControl->SetPageText( nPageId, rName );
95
96 // set document to modified state
97 GetDoc()->SetChanged();
98
99 // inform navigator about change
100 if (GetViewFrame())
101 {
102 SfxBindings& rBindings = GetViewFrame()->GetBindings();
103 rBindings.Invalidate(SID_NAVIGATOR_STATE, true);
104 }
105
106 // Tell the slide sorter about the name change (necessary for
107 // accessibility.)
108 slidesorter::SlideSorterViewShell* pSlideSorterViewShell
110 if (pSlideSorterViewShell != nullptr)
111 {
112 pSlideSorterViewShell->GetSlideSorter().GetController().PageNameHasChanged(
113 maTabControl->GetPagePos(nPageId), rName);
114 }
115 }
116
117 return bSuccess;
118}
119
120IMPL_LINK( DrawViewShell, RenameSlideHdl, AbstractSvxNameDialog&, rDialog, bool )
121{
122 OUString aNewName;
123 rDialog.GetName( aNewName );
124
125 SdPage* pCurrentPage = GetDoc()->GetSdPage( maTabControl->GetCurPagePos(), GetPageKind() );
126
127 return pCurrentPage && ( aNewName == pCurrentPage->GetName() || GetDocSh()->IsNewPageNameValid( aNewName ) );
128}
129
131 SdrLayer* pLayer,
132 const OUString& rLayerName,
133 const OUString& rLayerTitle,
134 const OUString& rLayerDesc,
135 bool bIsVisible,
136 bool bIsLocked,
137 bool bIsPrintable)
138{
139 if(!GetLayerTabControl()) // #i87182#
140 {
141 OSL_ENSURE(false, "No LayerTabBar (!)");
142 return;
143 }
144
145 if( !pLayer )
146 return;
147
148 const sal_uInt16 nPageCount = GetLayerTabControl()->GetPageCount();
149 sal_uInt16 nCurPage = 0;
150 sal_uInt16 nPos;
151 for( nPos = 0; nPos < nPageCount; nPos++ )
152 {
153 sal_uInt16 nId = GetLayerTabControl()->GetPageId( nPos );
154 if (GetLayerTabControl()->GetLayerName(nId) == pLayer->GetName())
155 {
156 nCurPage = nId;
157 break;
158 }
159 }
160
161 pLayer->SetName( rLayerName );
162 pLayer->SetTitle( rLayerTitle );
163 pLayer->SetDescription( rLayerDesc );
164 mpDrawView->SetLayerVisible( rLayerName, bIsVisible );
165 mpDrawView->SetLayerLocked( rLayerName, bIsLocked);
166 mpDrawView->SetLayerPrintable(rLayerName, bIsPrintable);
167
168 GetDoc()->SetChanged();
169
170 GetLayerTabControl()->SetPageText(nCurPage, rLayerName);
171
172 // Set page bits for modified tab name display
173
174 TabBarPageBits nBits = TabBarPageBits::NONE;
175
176 if (!bIsVisible)
177 {
178 nBits = TabBarPageBits::Blue;
179 }
180 if (bIsLocked)
181 {
182 nBits |= TabBarPageBits::Italic;
183 }
184 if (!bIsPrintable)
185 {
186 nBits |= TabBarPageBits::Underline;
187 }
188
189 // Save the bits
190
191 GetLayerTabControl()->SetPageBits(nCurPage, nBits);
192
194 SID_SWITCHLAYER,
195 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
196
197 // Call Invalidate at the form shell.
198 FmFormShell* pFormShell = GetViewShellBase().GetFormShellManager()->GetFormShell();
199 if (pFormShell != nullptr)
200 pFormShell->Invalidate();
201}
202
203} // end of namespace sd
204
205/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 nPageId
SdPage * GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
Definition: drawdoc2.cxx:207
SAL_DLLPRIVATE void RenameLayoutTemplate(const OUString &rOldLayoutName, const OUString &rNewName)
Definition: drawdoc4.cxx:1018
SdPage * GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
Definition: drawdoc2.cxx:217
virtual SAL_DLLPRIVATE void SetChanged(bool bFlag=true) override
Definition: drawdoc.cxx:658
SAL_DLLPRIVATE::sd::DrawDocShell * GetDocSh() const
Definition: drawdoc.hxx:242
virtual OUString GetLayoutName() const override
Definition: sdpage.hxx:255
const OUString & GetName() const
Definition: sdpage.cxx:2505
void SetName(const OUString &rName)
Set the name of the page and broadcast a model change.
Definition: sdpage.cxx:2703
AutoLayout GetAutoLayout() const
Definition: sdpage.hxx:190
SdrLayerID GetLayerID(const OUString &rName) const
bool IsSet(SdrLayerID a) const
const OUString & GetName() const
void SetDescription(const OUString &rDesc)
void SetTitle(const OUString &rTitle)
void SetName(const OUString &rNewName)
const SdrLayerAdmin & GetLayerAdmin() const
const SdrLayerIDSet & TRG_GetMasterPageVisibleLayers() const
void Invalidate(sal_uInt16 nId)
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
SfxBindings & GetBindings()
SfxDispatcher * GetDispatcher()
void SetPageBits(sal_uInt16 nPageId, TabBarPageBits nBits)
sal_uInt16 GetPageCount() const
sal_uInt16 GetPageId(sal_uInt16 nPos) const
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
void ModifyLayer(SdrLayer *pLayer, const OUString &rLayerName, const OUString &rLayerTitle, const OUString &rLayerDesc, bool bIsVisible, bool bIsLocked, bool bIsPrintable)
modifies the given layer with the given values
Definition: drviewsb.cxx:130
EditMode GetEditMode() const
std::unique_ptr< DrawView > mpDrawView
VclPtr< TabControl > maTabControl
SD_DLLPUBLIC LayerTabBar * GetLayerTabControl()
Return a pointer to the tab control for layers.
Definition: drviews5.cxx:636
bool RenameSlide(sal_uInt16 nPageId, const OUString &rName)
Renames the given slide using an SvxNameDialog.
Definition: drviewsb.cxx:45
PageKind GetPageKind() const
virtual void SetPageText(sal_uInt16 nPageId, const OUString &rText) override
std::shared_ptr< FormShellManager > const & GetFormShellManager() const
SdDrawDocument * GetDoc() const
Definition: viewshel.cxx:1412
SD_DLLPUBLIC ViewShellBase & GetViewShellBase() const
Definition: viewshel.cxx:1397
SD_DLLPUBLIC SfxViewFrame * GetViewFrame() const
Definition: viewshel.cxx:118
SD_DLLPUBLIC SlideSorter & GetSlideSorter() const
static SD_DLLPUBLIC SlideSorterViewShell * GetSlideSorter(ViewShellBase &rBase)
Return a slide sorter that is currently displayed in one of the panes that belong to the given ViewSh...
sal_uInt16 nPos
IMPL_LINK(SdCharHeightPropertyBox, implMenuSelectHdl, const OUString &, rIdent, void)
sal_Int16 nId
PageKind
Definition: pres.hxx:45
#define SDRPAGE_NOTFOUND
TabBarPageBits
constexpr OUStringLiteral sUNO_LayerName_background_objects
Definition: unokywds.hxx:30
constexpr OUStringLiteral sUNO_LayerName_background
Definition: unokywds.hxx:29