bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / func / fuprlout.cxx
blobc0fffc9721935c7cbc73def3be9268cccfa936a0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/smplhint.hxx>
24 #include <svl/itempool.hxx>
25 #include <sot/storage.hxx>
26 #include <vcl/msgbox.hxx>
27 #include <svx/svdundo.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <sfx2/request.hxx>
32 #include "drawdoc.hxx"
33 #include "sdpage.hxx"
34 #include "pres.hxx"
35 #include "DrawViewShell.hxx"
36 #include "FrameView.hxx"
37 #include "stlpool.hxx"
38 #include "View.hxx"
39 #include "glob.hrc"
40 #include "glob.hxx"
41 #include "strings.hrc"
42 #include "strmname.h"
43 #include "app.hrc"
44 #include "DrawDocShell.hxx"
45 #include "unprlout.hxx"
46 #include "unchss.hxx"
47 #include "unmovss.hxx"
48 #include "sdattr.hxx"
49 #include "sdresid.hxx"
50 #include "drawview.hxx"
51 #include <editeng/outliner.hxx>
52 #include <editeng/editdata.hxx>
53 #include "sdabstdlg.hxx"
54 #include <boost/scoped_ptr.hpp>
56 namespace sd
59 TYPEINIT1( FuPresentationLayout, FuPoor );
61 #define DOCUMENT_TOKEN '#'
63 FuPresentationLayout::FuPresentationLayout (
64 ViewShell* pViewSh,
65 ::sd::Window* pWin,
66 ::sd::View* pView,
67 SdDrawDocument* pDoc,
68 SfxRequest& rReq)
69 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
73 rtl::Reference<FuPoor> FuPresentationLayout::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
75 rtl::Reference<FuPoor> xFunc( new FuPresentationLayout( pViewSh, pWin, pView, pDoc, rReq ) );
76 xFunc->DoExecute(rReq);
77 return xFunc;
80 void FuPresentationLayout::DoExecute( SfxRequest& rReq )
82 // prevent selected objects or objects which are under editing from disappearing
83 mpView->SdrEndTextEdit();
85 if(mpView->GetSdrPageView())
87 mpView->UnmarkAll();
90 bool bError = false;
92 // determine the active page
93 sal_uInt16 nSelectedPage = SDRPAGE_NOTFOUND;
94 for (sal_uInt16 nPage = 0; nPage < mpDoc->GetSdPageCount(PK_STANDARD); nPage++)
96 if (mpDoc->GetSdPage(nPage, PK_STANDARD)->IsSelected())
98 nSelectedPage = nPage;
99 break;
103 DBG_ASSERT(nSelectedPage != SDRPAGE_NOTFOUND, "no selected page");
104 SdPage* pSelectedPage = mpDoc->GetSdPage(nSelectedPage, PK_STANDARD);
105 OUString aOldLayoutName(pSelectedPage->GetLayoutName());
106 sal_Int32 nPos = aOldLayoutName.indexOf(SD_LT_SEPARATOR);
107 if (nPos != -1)
108 aOldLayoutName = aOldLayoutName.copy(0, nPos);
110 /* if we are on a master page, the changes apply for all pages and notes-
111 pages who are using the relevant layout */
112 bool bOnMaster = false;
113 if( mpViewShell && mpViewShell->ISA(DrawViewShell))
115 EditMode eEditMode =
116 static_cast<DrawViewShell*>(mpViewShell)->GetEditMode();
117 if (eEditMode == EM_MASTERPAGE)
118 bOnMaster = true;
120 bool bMasterPage = bOnMaster;
121 bool bCheckMasters = false;
123 // call dialog
124 bool bLoad = false; // appear the new master pages?
125 OUString aFile;
127 SfxItemSet aSet(mpDoc->GetPool(), ATTR_PRESLAYOUT_START, ATTR_PRESLAYOUT_END);
129 aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad));
130 aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, bMasterPage ) );
131 aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, bCheckMasters ) );
132 aSet.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aOldLayoutName));
134 const SfxItemSet *pArgs = rReq.GetArgs ();
136 if (pArgs)
138 if (pArgs->GetItemState(ATTR_PRESLAYOUT_LOAD) == SfxItemState::SET)
139 bLoad = static_cast<const SfxBoolItem&>(pArgs->Get(ATTR_PRESLAYOUT_LOAD)).GetValue();
140 if( pArgs->GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE ) == SfxItemState::SET )
141 bMasterPage = static_cast<const SfxBoolItem&>( pArgs->Get( ATTR_PRESLAYOUT_MASTER_PAGE ) ).GetValue();
142 if( pArgs->GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS ) == SfxItemState::SET )
143 bCheckMasters = static_cast<const SfxBoolItem&>( pArgs->Get( ATTR_PRESLAYOUT_CHECK_MASTERS ) ).GetValue();
144 if (pArgs->GetItemState(ATTR_PRESLAYOUT_NAME) == SfxItemState::SET)
145 aFile = static_cast<const SfxStringItem&>(pArgs->Get(ATTR_PRESLAYOUT_NAME)).GetValue();
147 else
149 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
150 boost::scoped_ptr<AbstractSdPresLayoutDlg> pDlg(pFact ? pFact->CreateSdPresLayoutDlg(mpDocSh, NULL, aSet ) : 0);
152 sal_uInt16 nResult = pDlg ? pDlg->Execute() : static_cast<short>(RET_CANCEL);
154 switch (nResult)
156 case RET_OK:
158 pDlg->GetAttr(aSet);
159 if (aSet.GetItemState(ATTR_PRESLAYOUT_LOAD) == SfxItemState::SET)
160 bLoad = static_cast<const SfxBoolItem&>(aSet.Get(ATTR_PRESLAYOUT_LOAD)).GetValue();
161 if( aSet.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE ) == SfxItemState::SET )
162 bMasterPage = static_cast<const SfxBoolItem&>(aSet.Get( ATTR_PRESLAYOUT_MASTER_PAGE ) ).GetValue();
163 if( aSet.GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS ) == SfxItemState::SET )
164 bCheckMasters = static_cast<const SfxBoolItem&>(aSet.Get( ATTR_PRESLAYOUT_CHECK_MASTERS ) ).GetValue();
165 if (aSet.GetItemState(ATTR_PRESLAYOUT_NAME) == SfxItemState::SET)
166 aFile = static_cast<const SfxStringItem&>(aSet.Get(ATTR_PRESLAYOUT_NAME)).GetValue();
168 break;
170 default:
171 bError = true;
175 if (!bError)
177 mpDocSh->SetWaitCursor( true );
179 /* Here, we only exchange masterpages, therefore the current page
180 remains the current page. To prevent calling PageOrderChangedHint
181 during insertion and extraction of the masterpages, we block. */
182 /* That isn't quitely right. If the masterpageview is active and you are
183 removing a masterpage, it's possible that you are removing the
184 current masterpage. So you have to call ResetActualPage ! */
185 if( mpViewShell->ISA(DrawViewShell) && !bCheckMasters )
186 static_cast<DrawView*>(mpView)->BlockPageOrderChangedHint(true);
188 if (bLoad)
190 OUString aFileName = aFile.getToken(0, DOCUMENT_TOKEN);
191 SdDrawDocument* pTempDoc = mpDoc->OpenBookmarkDoc( aFileName );
193 // #69581: If I chosed the standard-template I got no filename and so I get no
194 // SdDrawDocument-Pointer. But the method SetMasterPage is able to handle
195 // a NULL-pointer as a Standard-template ( look at SdDrawDocument::SetMasterPage )
196 OUString aLayoutName;
197 if( pTempDoc )
198 aLayoutName = aFile.getToken(1, DOCUMENT_TOKEN);
200 mpDoc->SetMasterPage(nSelectedPage, aLayoutName, pTempDoc, bMasterPage, bCheckMasters);
201 mpDoc->CloseBookmarkDoc();
203 else
205 // use master page with the layout name aFile from current Doc
206 mpDoc->SetMasterPage(nSelectedPage, aFile, mpDoc, bMasterPage, bCheckMasters);
209 // remove blocking
210 if (mpViewShell->ISA(DrawViewShell) && !bCheckMasters )
211 static_cast<DrawView*>(mpView)->BlockPageOrderChangedHint(false);
213 // if the master page was visible, show it again
214 if (!bError && nSelectedPage != SDRPAGE_NOTFOUND)
216 if (bOnMaster)
218 if (mpViewShell->ISA(DrawViewShell))
220 ::sd::View* pView =
221 static_cast<DrawViewShell*>(mpViewShell)->GetView();
222 sal_uInt16 nPgNum = pSelectedPage->TRG_GetMasterPage().GetPageNum();
224 if (static_cast<DrawViewShell*>(mpViewShell)->GetPageKind() == PK_NOTES)
225 nPgNum++;
227 pView->HideSdrPage();
228 pView->ShowSdrPage(pView->GetModel()->GetMasterPage(nPgNum));
231 // force update of TabBar
232 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_MASTERPAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
234 else
236 pSelectedPage->SetAutoLayout(pSelectedPage->GetAutoLayout());
240 // fake a mode change to repaint the page tab bar
241 if( mpViewShell && mpViewShell->ISA( DrawViewShell ) )
243 DrawViewShell* pDrawViewSh =
244 static_cast<DrawViewShell*>(mpViewShell);
245 EditMode eMode = pDrawViewSh->GetEditMode();
246 bool bLayer = pDrawViewSh->IsLayerModeActive();
247 pDrawViewSh->ChangeEditMode( eMode, !bLayer );
248 pDrawViewSh->ChangeEditMode( eMode, bLayer );
251 mpDocSh->SetWaitCursor( false );
255 } // end of namespace sd
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */