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 <fuprlout.hxx>
21 #include <sfx2/dispatch.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include <sfx2/request.hxx>
25 #include <svl/stritem.hxx>
28 #include <drawdoc.hxx>
31 #include <DrawViewShell.hxx>
35 #include <DrawDocShell.hxx>
36 #include <SlideSorterViewShell.hxx>
38 #include <drawview.hxx>
39 #include <sdabstdlg.hxx>
46 #define DOCUMENT_TOKEN '#'
48 FuPresentationLayout::FuPresentationLayout (
54 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
58 rtl::Reference
<FuPoor
> FuPresentationLayout::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
60 rtl::Reference
<FuPoor
> xFunc( new FuPresentationLayout( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
61 xFunc
->DoExecute(rReq
);
65 void FuPresentationLayout::DoExecute( SfxRequest
& rReq
)
67 // prevent selected objects or objects which are under editing from disappearing
68 mpView
->SdrEndTextEdit();
70 if(mpView
->GetSdrPageView())
77 /* if we are on a master page, the changes apply for all pages and notes-
78 pages who are using the relevant layout */
79 bool bOnMaster
= false;
80 if (DrawViewShell
*pShell
= dynamic_cast<DrawViewShell
*>(mpViewShell
))
82 EditMode eEditMode
= pShell
->GetEditMode();
83 if (eEditMode
== EditMode::MasterPage
)
87 std::vector
<SdPage
*> aUnselect
;
90 //We later rely on IsSelected, so transfer the selection here
92 slidesorter::SlideSorterViewShell
* pSlideSorterViewShell
93 = slidesorter::SlideSorterViewShell::GetSlideSorter(mpViewShell
->GetViewShellBase());
94 if (pSlideSorterViewShell
)
96 std::shared_ptr
<slidesorter::SlideSorterViewShell::PageSelection
> xSelection(
97 pSlideSorterViewShell
->GetPageSelection());
100 for (SdPage
*pPage
: *xSelection
)
102 if (pPage
->IsSelected() || pPage
->GetPageKind() != PageKind::Standard
)
104 mpDoc
->SetSelected(pPage
, true);
105 aUnselect
.push_back(pPage
);
111 std::vector
<SdPage
*> aSelectedPages
;
112 std::vector
<sal_uInt16
> aSelectedPageNums
;
113 // determine the active pages
114 for (sal_uInt16 nPage
= 0; nPage
< mpDoc
->GetSdPageCount(PageKind::Standard
); nPage
++)
116 SdPage
* pPage
= mpDoc
->GetSdPage(nPage
, PageKind::Standard
);
117 if (pPage
->IsSelected())
119 aSelectedPages
.push_back(pPage
);
120 aSelectedPageNums
.push_back(nPage
);
124 bool bMasterPage
= bOnMaster
;
125 bool bCheckMasters
= false;
128 bool bLoad
= false; // appear the new master pages?
131 SfxItemSetFixed
<ATTR_PRESLAYOUT_START
, ATTR_PRESLAYOUT_END
> aSet(mpDoc
->GetPool() );
133 aSet
.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD
, bLoad
));
134 aSet
.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE
, bMasterPage
) );
135 aSet
.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS
, bCheckMasters
) );
137 if (!aSelectedPages
.empty())
139 OUString
aOldLayoutName(aSelectedPages
.back()->GetLayoutName());
140 sal_Int32 nPos
= aOldLayoutName
.indexOf(SD_LT_SEPARATOR
);
142 aOldLayoutName
= aOldLayoutName
.copy(0, nPos
);
143 aSet
.Put(SfxStringItem(ATTR_PRESLAYOUT_NAME
, aOldLayoutName
));
146 const SfxItemSet
*pArgs
= rReq
.GetArgs ();
150 if (pArgs
->GetItemState(ATTR_PRESLAYOUT_LOAD
) == SfxItemState::SET
)
151 bLoad
= static_cast<const SfxBoolItem
&>(pArgs
->Get(ATTR_PRESLAYOUT_LOAD
)).GetValue();
152 if( pArgs
->GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE
) == SfxItemState::SET
)
153 bMasterPage
= pArgs
->Get( ATTR_PRESLAYOUT_MASTER_PAGE
).GetValue();
154 if( pArgs
->GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS
) == SfxItemState::SET
)
155 bCheckMasters
= static_cast<const SfxBoolItem
&>( pArgs
->Get( ATTR_PRESLAYOUT_CHECK_MASTERS
) ).GetValue();
156 if (pArgs
->GetItemState(ATTR_PRESLAYOUT_NAME
) == SfxItemState::SET
)
157 aFile
= pArgs
->Get(ATTR_PRESLAYOUT_NAME
).GetValue();
161 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
162 ScopedVclPtr
<AbstractSdPresLayoutDlg
> pDlg(pFact
->CreateSdPresLayoutDlg(mpWindow
? mpWindow
->GetFrameWeld() : nullptr, mpDocSh
, aSet
));
164 sal_uInt16 nResult
= pDlg
->Execute();
171 if (aSet
.GetItemState(ATTR_PRESLAYOUT_LOAD
) == SfxItemState::SET
)
172 bLoad
= static_cast<const SfxBoolItem
&>(aSet
.Get(ATTR_PRESLAYOUT_LOAD
)).GetValue();
173 if( aSet
.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE
) == SfxItemState::SET
)
174 bMasterPage
= aSet
.Get( ATTR_PRESLAYOUT_MASTER_PAGE
).GetValue();
175 if( aSet
.GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS
) == SfxItemState::SET
)
176 bCheckMasters
= static_cast<const SfxBoolItem
&>(aSet
.Get( ATTR_PRESLAYOUT_CHECK_MASTERS
) ).GetValue();
177 if (aSet
.GetItemState(ATTR_PRESLAYOUT_NAME
) == SfxItemState::SET
)
178 aFile
= aSet
.Get(ATTR_PRESLAYOUT_NAME
).GetValue();
190 mpDocSh
->SetWaitCursor( true );
192 /* Here, we only exchange masterpages, therefore the current page
193 remains the current page. To prevent calling PageOrderChangedHint
194 during insertion and extraction of the masterpages, we block. */
195 /* That isn't quite right. If the masterpageview is active and you are
196 removing a masterpage, it's possible that you are removing the
197 current masterpage. So you have to call ResetActualPage ! */
198 if( dynamic_cast< const DrawViewShell
*>( mpViewShell
) != nullptr && !bCheckMasters
)
199 static_cast<DrawView
*>(mpView
)->BlockPageOrderChangedHint(true);
204 OUString aFileName
= aFile
.getToken(0, DOCUMENT_TOKEN
, nIdx
);
205 SdDrawDocument
* pTempDoc
= mpDoc
->OpenBookmarkDoc( aFileName
);
207 // #69581: If I chose the standard-template I got no filename and so I get no
208 // SdDrawDocument-Pointer. But the method SetMasterPage is able to handle
209 // a NULL-pointer as a Standard-template ( look at SdDrawDocument::SetMasterPage )
210 OUString aLayoutName
;
212 aLayoutName
= aFile
.getToken(0, DOCUMENT_TOKEN
, nIdx
);
213 for (auto nSelectedPage
: aSelectedPageNums
)
214 mpDoc
->SetMasterPage(nSelectedPage
, aLayoutName
, pTempDoc
, bMasterPage
, bCheckMasters
);
215 mpDoc
->CloseBookmarkDoc();
219 // use master page with the layout name aFile from current Doc
220 for (auto nSelectedPage
: aSelectedPageNums
)
221 mpDoc
->SetMasterPage(nSelectedPage
, aFile
, mpDoc
, bMasterPage
, bCheckMasters
);
225 if( dynamic_cast< const DrawViewShell
*>( mpViewShell
) != nullptr && !bCheckMasters
)
226 static_cast<DrawView
*>(mpView
)->BlockPageOrderChangedHint(false);
228 // if the master page was visible, show it again
229 if (!aSelectedPages
.empty())
233 if( auto pDrawViewShell
= dynamic_cast<DrawViewShell
*>( mpViewShell
))
235 ::sd::View
* pView
= pDrawViewShell
->GetView();
236 for (auto pSelectedPage
: aSelectedPages
)
238 sal_uInt16 nPgNum
= pSelectedPage
->TRG_GetMasterPage().GetPageNum();
240 if (static_cast<DrawViewShell
*>(mpViewShell
)->GetPageKind() == PageKind::Notes
)
243 pView
->HideSdrPage();
244 pView
->ShowSdrPage(pView
->GetModel().GetMasterPage(nPgNum
));
248 // force update of TabBar
249 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_MASTERPAGE
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
253 for (auto pSelectedPage
: aSelectedPages
)
254 pSelectedPage
->SetAutoLayout(pSelectedPage
->GetAutoLayout());
258 //Undo transfer to document selection
259 for (auto pPage
: aUnselect
)
260 mpDoc
->SetSelected(pPage
, false);
263 // fake a mode change to repaint the page tab bar
264 if( auto pDrawViewSh
= dynamic_cast<DrawViewShell
*>( mpViewShell
) )
266 EditMode eMode
= pDrawViewSh
->GetEditMode();
267 bool bLayer
= pDrawViewSh
->IsLayerModeActive();
268 pDrawViewSh
->ChangeEditMode( eMode
, !bLayer
);
269 pDrawViewSh
->ChangeEditMode( eMode
, bLayer
);
272 mpDocSh
->SetWaitCursor( false );
275 } // end of namespace sd
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */