bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fuprlout.cxx
blob67ae4cae1c7d5b20e49efd9f9d1d6050acd36f2d
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"
55 namespace sd
58 TYPEINIT1( FuPresentationLayout, FuPoor );
60 #define DOCUMENT_TOKEN (sal_Unicode('#'))
62 FuPresentationLayout::FuPresentationLayout (
63 ViewShell* pViewSh,
64 ::sd::Window* pWin,
65 ::sd::View* pView,
66 SdDrawDocument* pDoc,
67 SfxRequest& rReq)
68 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
72 FunctionReference FuPresentationLayout::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
74 FunctionReference xFunc( new FuPresentationLayout( pViewSh, pWin, pView, pDoc, rReq ) );
75 xFunc->DoExecute(rReq);
76 return xFunc;
79 void FuPresentationLayout::DoExecute( SfxRequest& rReq )
81 // prevent selected objects or objects which are under editing from disappearing
82 mpView->SdrEndTextEdit();
84 if(mpView->GetSdrPageView())
86 mpView->UnmarkAll();
89 sal_Bool bError = sal_False;
91 // determine the active page
92 sal_uInt16 nSelectedPage = SDRPAGE_NOTFOUND;
93 for (sal_uInt16 nPage = 0; nPage < mpDoc->GetSdPageCount(PK_STANDARD); nPage++)
95 if (mpDoc->GetSdPage(nPage, PK_STANDARD)->IsSelected())
97 nSelectedPage = nPage;
98 break;
102 DBG_ASSERT(nSelectedPage != SDRPAGE_NOTFOUND, "no selected page");
103 SdPage* pSelectedPage = mpDoc->GetSdPage(nSelectedPage, PK_STANDARD);
104 String aOldPageLayoutName(pSelectedPage->GetLayoutName());
105 String aOldLayoutName(aOldPageLayoutName);
106 aOldLayoutName.Erase(aOldLayoutName.SearchAscii(SD_LT_SEPARATOR));
108 /* if we are on a master page, the changes apply for all pages and notes-
109 pages who are using the relevant layout */
110 sal_Bool bOnMaster = sal_False;
111 if( mpViewShell && mpViewShell->ISA(DrawViewShell))
113 EditMode eEditMode =
114 static_cast<DrawViewShell*>(mpViewShell)->GetEditMode();
115 if (eEditMode == EM_MASTERPAGE)
116 bOnMaster = sal_True;
118 sal_Bool bMasterPage = bOnMaster;
119 sal_Bool bCheckMasters = sal_False;
121 // call dialog
122 sal_Bool bLoad = sal_False; // appear the new master pages?
123 String aFile;
125 SfxItemSet aSet(mpDoc->GetPool(), ATTR_PRESLAYOUT_START, ATTR_PRESLAYOUT_END);
127 aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad));
128 aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, bMasterPage ) );
129 aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, bCheckMasters ) );
130 aSet.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aOldLayoutName));
134 const SfxItemSet *pArgs = rReq.GetArgs ();
136 if (pArgs)
138 if (pArgs->GetItemState(ATTR_PRESLAYOUT_LOAD) == SFX_ITEM_SET)
139 bLoad = ((SfxBoolItem&)pArgs->Get(ATTR_PRESLAYOUT_LOAD)).GetValue();
140 if( pArgs->GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE ) == SFX_ITEM_SET )
141 bMasterPage = ( (SfxBoolItem&) pArgs->Get( ATTR_PRESLAYOUT_MASTER_PAGE ) ).GetValue();
142 if( pArgs->GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS ) == SFX_ITEM_SET )
143 bCheckMasters = ( (SfxBoolItem&) pArgs->Get( ATTR_PRESLAYOUT_CHECK_MASTERS ) ).GetValue();
144 if (pArgs->GetItemState(ATTR_PRESLAYOUT_NAME) == SFX_ITEM_SET)
145 aFile = ((SfxStringItem&)pArgs->Get(ATTR_PRESLAYOUT_NAME)).GetValue();
147 else
149 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
150 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) == SFX_ITEM_SET)
160 bLoad = ((SfxBoolItem&)aSet.Get(ATTR_PRESLAYOUT_LOAD)).GetValue();
161 if( aSet.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE ) == SFX_ITEM_SET )
162 bMasterPage = ( (SfxBoolItem&) aSet.Get( ATTR_PRESLAYOUT_MASTER_PAGE ) ).GetValue();
163 if( aSet.GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS ) == SFX_ITEM_SET )
164 bCheckMasters = ( (SfxBoolItem&) aSet.Get( ATTR_PRESLAYOUT_CHECK_MASTERS ) ).GetValue();
165 if (aSet.GetItemState(ATTR_PRESLAYOUT_NAME) == SFX_ITEM_SET)
166 aFile = ((SfxStringItem&)aSet.Get(ATTR_PRESLAYOUT_NAME)).GetValue();
168 break;
170 default:
171 bError = sal_True;
173 delete pDlg;
176 if (!bError)
178 mpDocSh->SetWaitCursor( sal_True );
180 /* Here, we only exchange masterpages, therefore the current page
181 remains the current page. To prevent calling PageOrderChangedHint
182 during insertion and extraction of the masterpages, we block. */
183 /* That isn't quitely right. If the masterpageview is active and you are
184 removing a masterpage, it's possible that you are removing the
185 current masterpage. So you have to call ResetActualPage ! */
186 if( mpViewShell->ISA(DrawViewShell) && !bCheckMasters )
187 static_cast<DrawView*>(mpView)->BlockPageOrderChangedHint(sal_True);
189 if (bLoad)
191 String aFileName = aFile.GetToken( 0, DOCUMENT_TOKEN );
192 SdDrawDocument* pTempDoc = mpDoc->OpenBookmarkDoc( aFileName );
194 // #69581: If I chosed the standard-template I got no filename and so I get no
195 // SdDrawDocument-Pointer. But the method SetMasterPage is able to handle
196 // a NULL-pointer as a Standard-template ( look at SdDrawDocument::SetMasterPage )
197 String aLayoutName;
198 if( pTempDoc )
199 aLayoutName = aFile.GetToken( 1, DOCUMENT_TOKEN );
201 mpDoc->SetMasterPage(nSelectedPage, aLayoutName, pTempDoc, bMasterPage, bCheckMasters);
202 mpDoc->CloseBookmarkDoc();
204 else
206 // use master page with the layout name aFile from current Doc
207 mpDoc->SetMasterPage(nSelectedPage, aFile, mpDoc, bMasterPage, bCheckMasters);
210 // remove blocking
211 if (mpViewShell->ISA(DrawViewShell) && !bCheckMasters )
212 static_cast<DrawView*>(mpView)->BlockPageOrderChangedHint(sal_False);
214 // if the master page was visible, show it again
215 if (!bError && nSelectedPage != SDRPAGE_NOTFOUND)
217 if (bOnMaster)
219 if (mpViewShell->ISA(DrawViewShell))
221 ::sd::View* pView =
222 static_cast<DrawViewShell*>(mpViewShell)->GetView();
223 sal_uInt16 nPgNum = pSelectedPage->TRG_GetMasterPage().GetPageNum();
225 if (static_cast<DrawViewShell*>(mpViewShell)->GetPageKind() == PK_NOTES)
226 nPgNum++;
228 pView->HideSdrPage();
229 pView->ShowSdrPage(pView->GetModel()->GetMasterPage(nPgNum));
232 // force update of TabBar
233 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_MASTERPAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
235 else
237 pSelectedPage->SetAutoLayout(pSelectedPage->GetAutoLayout());
241 // fake a mode change to repaint the page tab bar
242 if( mpViewShell && mpViewShell->ISA( DrawViewShell ) )
244 DrawViewShell* pDrawViewSh =
245 static_cast<DrawViewShell*>(mpViewShell);
246 EditMode eMode = pDrawViewSh->GetEditMode();
247 sal_Bool bLayer = pDrawViewSh->IsLayerModeActive();
248 pDrawViewSh->ChangeEditMode( eMode, !bLayer );
249 pDrawViewSh->ChangeEditMode( eMode, bLayer );
252 mpDocSh->SetWaitCursor( sal_False );
256 } // end of namespace sd
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */