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 <vcl/wrkwin.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <svl/itempool.hxx>
24 #include <sot/storage.hxx>
25 #include <svx/svdundo.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <sfx2/request.hxx>
30 #include <drawdoc.hxx>
33 #include <DrawViewShell.hxx>
34 #include <FrameView.hxx>
35 #include <stlpool.hxx>
40 #include <DrawDocShell.hxx>
41 #include <SlideSorterViewShell.hxx>
42 #include <unprlout.hxx>
44 #include <unmovss.hxx>
46 #include <drawview.hxx>
47 #include <editeng/outliner.hxx>
48 #include <editeng/editdata.hxx>
49 #include <sdabstdlg.hxx>
56 #define DOCUMENT_TOKEN '#'
58 FuPresentationLayout::FuPresentationLayout (
64 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
68 rtl::Reference
<FuPoor
> FuPresentationLayout::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
70 rtl::Reference
<FuPoor
> xFunc( new FuPresentationLayout( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
71 xFunc
->DoExecute(rReq
);
75 void FuPresentationLayout::DoExecute( SfxRequest
& rReq
)
77 // prevent selected objects or objects which are under editing from disappearing
78 mpView
->SdrEndTextEdit();
80 if(mpView
->GetSdrPageView())
87 /* if we are on a master page, the changes apply for all pages and notes-
88 pages who are using the relevant layout */
89 bool bOnMaster
= false;
90 if (DrawViewShell
*pShell
= dynamic_cast<DrawViewShell
*>(mpViewShell
))
92 EditMode eEditMode
= pShell
->GetEditMode();
93 if (eEditMode
== EditMode::MasterPage
)
97 std::vector
<SdPage
*> aUnselect
;
100 //We later rely on IsSelected, so transfer the selection here
102 slidesorter::SlideSorterViewShell
* pSlideSorterViewShell
103 = slidesorter::SlideSorterViewShell::GetSlideSorter(mpViewShell
->GetViewShellBase());
104 if (pSlideSorterViewShell
)
106 std::shared_ptr
<slidesorter::SlideSorterViewShell::PageSelection
> xSelection(
107 pSlideSorterViewShell
->GetPageSelection());
110 for (auto it
= xSelection
->begin(); it
!= xSelection
->end(); ++it
)
113 if (pPage
->IsSelected() || pPage
->GetPageKind() != PageKind::Standard
)
115 mpDoc
->SetSelected(pPage
, true);
116 aUnselect
.push_back(pPage
);
122 std::vector
<SdPage
*> aSelectedPages
;
123 std::vector
<sal_uInt16
> aSelectedPageNums
;
124 // determine the active pages
125 for (sal_uInt16 nPage
= 0; nPage
< mpDoc
->GetSdPageCount(PageKind::Standard
); nPage
++)
127 SdPage
* pPage
= mpDoc
->GetSdPage(nPage
, PageKind::Standard
);
128 if (pPage
->IsSelected())
130 aSelectedPages
.push_back(pPage
);
131 aSelectedPageNums
.push_back(nPage
);
135 bool bMasterPage
= bOnMaster
;
136 bool bCheckMasters
= false;
139 bool bLoad
= false; // appear the new master pages?
142 SfxItemSet
aSet(mpDoc
->GetPool(), svl::Items
<ATTR_PRESLAYOUT_START
, ATTR_PRESLAYOUT_END
>{});
144 aSet
.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD
, bLoad
));
145 aSet
.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE
, bMasterPage
) );
146 aSet
.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS
, bCheckMasters
) );
148 if (!aSelectedPages
.empty())
150 OUString
aOldLayoutName(aSelectedPages
.back()->GetLayoutName());
151 sal_Int32 nPos
= aOldLayoutName
.indexOf(SD_LT_SEPARATOR
);
153 aOldLayoutName
= aOldLayoutName
.copy(0, nPos
);
154 aSet
.Put(SfxStringItem(ATTR_PRESLAYOUT_NAME
, aOldLayoutName
));
157 const SfxItemSet
*pArgs
= rReq
.GetArgs ();
161 if (pArgs
->GetItemState(ATTR_PRESLAYOUT_LOAD
) == SfxItemState::SET
)
162 bLoad
= static_cast<const SfxBoolItem
&>(pArgs
->Get(ATTR_PRESLAYOUT_LOAD
)).GetValue();
163 if( pArgs
->GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE
) == SfxItemState::SET
)
164 bMasterPage
= static_cast<const SfxBoolItem
&>( pArgs
->Get( ATTR_PRESLAYOUT_MASTER_PAGE
) ).GetValue();
165 if( pArgs
->GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS
) == SfxItemState::SET
)
166 bCheckMasters
= static_cast<const SfxBoolItem
&>( pArgs
->Get( ATTR_PRESLAYOUT_CHECK_MASTERS
) ).GetValue();
167 if (pArgs
->GetItemState(ATTR_PRESLAYOUT_NAME
) == SfxItemState::SET
)
168 aFile
= static_cast<const SfxStringItem
&>(pArgs
->Get(ATTR_PRESLAYOUT_NAME
)).GetValue();
172 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
173 ScopedVclPtr
<AbstractSdPresLayoutDlg
> pDlg(pFact
? pFact
->CreateSdPresLayoutDlg(mpDocSh
, aSet
) : nullptr);
175 sal_uInt16 nResult
= pDlg
? pDlg
->Execute() : static_cast<short>(RET_CANCEL
);
182 if (aSet
.GetItemState(ATTR_PRESLAYOUT_LOAD
) == SfxItemState::SET
)
183 bLoad
= static_cast<const SfxBoolItem
&>(aSet
.Get(ATTR_PRESLAYOUT_LOAD
)).GetValue();
184 if( aSet
.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE
) == SfxItemState::SET
)
185 bMasterPage
= static_cast<const SfxBoolItem
&>(aSet
.Get( ATTR_PRESLAYOUT_MASTER_PAGE
) ).GetValue();
186 if( aSet
.GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS
) == SfxItemState::SET
)
187 bCheckMasters
= static_cast<const SfxBoolItem
&>(aSet
.Get( ATTR_PRESLAYOUT_CHECK_MASTERS
) ).GetValue();
188 if (aSet
.GetItemState(ATTR_PRESLAYOUT_NAME
) == SfxItemState::SET
)
189 aFile
= static_cast<const SfxStringItem
&>(aSet
.Get(ATTR_PRESLAYOUT_NAME
)).GetValue();
200 mpDocSh
->SetWaitCursor( true );
202 /* Here, we only exchange masterpages, therefore the current page
203 remains the current page. To prevent calling PageOrderChangedHint
204 during insertion and extraction of the masterpages, we block. */
205 /* That isn't quite right. If the masterpageview is active and you are
206 removing a masterpage, it's possible that you are removing the
207 current masterpage. So you have to call ResetActualPage ! */
208 if( dynamic_cast< const DrawViewShell
*>( mpViewShell
) != nullptr && !bCheckMasters
)
209 static_cast<DrawView
*>(mpView
)->BlockPageOrderChangedHint(true);
213 OUString aFileName
= aFile
.getToken(0, DOCUMENT_TOKEN
);
214 SdDrawDocument
* pTempDoc
= mpDoc
->OpenBookmarkDoc( aFileName
);
216 // #69581: If I chose the standard-template I got no filename and so I get no
217 // SdDrawDocument-Pointer. But the method SetMasterPage is able to handle
218 // a NULL-pointer as a Standard-template ( look at SdDrawDocument::SetMasterPage )
219 OUString aLayoutName
;
221 aLayoutName
= aFile
.getToken(1, DOCUMENT_TOKEN
);
222 for (auto nSelectedPage
: aSelectedPageNums
)
223 mpDoc
->SetMasterPage(nSelectedPage
, aLayoutName
, pTempDoc
, bMasterPage
, bCheckMasters
);
224 mpDoc
->CloseBookmarkDoc();
228 // use master page with the layout name aFile from current Doc
229 for (auto nSelectedPage
: aSelectedPageNums
)
230 mpDoc
->SetMasterPage(nSelectedPage
, aFile
, mpDoc
, bMasterPage
, bCheckMasters
);
234 if( dynamic_cast< const DrawViewShell
*>( mpViewShell
) != nullptr && !bCheckMasters
)
235 static_cast<DrawView
*>(mpView
)->BlockPageOrderChangedHint(false);
237 // if the master page was visible, show it again
238 if (!aSelectedPages
.empty())
242 if( dynamic_cast< const DrawViewShell
*>( mpViewShell
) != nullptr)
245 static_cast<DrawViewShell
*>(mpViewShell
)->GetView();
246 for (auto pSelectedPage
: aSelectedPages
)
248 sal_uInt16 nPgNum
= pSelectedPage
->TRG_GetMasterPage().GetPageNum();
250 if (static_cast<DrawViewShell
*>(mpViewShell
)->GetPageKind() == PageKind::Notes
)
253 pView
->HideSdrPage();
254 pView
->ShowSdrPage(pView
->GetModel()->GetMasterPage(nPgNum
));
258 // force update of TabBar
259 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_MASTERPAGE
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
263 for (auto pSelectedPage
: aSelectedPages
)
264 pSelectedPage
->SetAutoLayout(pSelectedPage
->GetAutoLayout());
268 //Undo transfer to document selection
269 for (auto pPage
: aUnselect
)
270 mpDoc
->SetSelected(pPage
, false);
273 // fake a mode change to repaint the page tab bar
274 if( mpViewShell
&& dynamic_cast< const DrawViewShell
*>( mpViewShell
) != nullptr )
276 DrawViewShell
* pDrawViewSh
=
277 static_cast<DrawViewShell
*>(mpViewShell
);
278 EditMode eMode
= pDrawViewSh
->GetEditMode();
279 bool bLayer
= pDrawViewSh
->IsLayerModeActive();
280 pDrawViewSh
->ChangeEditMode( eMode
, !bLayer
);
281 pDrawViewSh
->ChangeEditMode( eMode
, bLayer
);
284 mpDocSh
->SetWaitCursor( false );
288 } // end of namespace sd
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */