Line data Source code
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 "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>
28 :
29 : #include <sfx2/viewfrm.hxx>
30 : #include <sfx2/request.hxx>
31 :
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 :
55 : namespace sd
56 : {
57 :
58 0 : TYPEINIT1( FuPresentationLayout, FuPoor );
59 :
60 : #define DOCUMENT_TOKEN '#'
61 :
62 0 : FuPresentationLayout::FuPresentationLayout (
63 : ViewShell* pViewSh,
64 : ::sd::Window* pWin,
65 : ::sd::View* pView,
66 : SdDrawDocument* pDoc,
67 : SfxRequest& rReq)
68 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
69 : {
70 0 : }
71 :
72 0 : rtl::Reference<FuPoor> FuPresentationLayout::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
73 : {
74 0 : rtl::Reference<FuPoor> xFunc( new FuPresentationLayout( pViewSh, pWin, pView, pDoc, rReq ) );
75 0 : xFunc->DoExecute(rReq);
76 0 : return xFunc;
77 : }
78 :
79 0 : void FuPresentationLayout::DoExecute( SfxRequest& rReq )
80 : {
81 : // prevent selected objects or objects which are under editing from disappearing
82 0 : mpView->SdrEndTextEdit();
83 :
84 0 : if(mpView->GetSdrPageView())
85 : {
86 0 : mpView->UnmarkAll();
87 : }
88 :
89 0 : sal_Bool bError = sal_False;
90 :
91 : // determine the active page
92 0 : sal_uInt16 nSelectedPage = SDRPAGE_NOTFOUND;
93 0 : for (sal_uInt16 nPage = 0; nPage < mpDoc->GetSdPageCount(PK_STANDARD); nPage++)
94 : {
95 0 : if (mpDoc->GetSdPage(nPage, PK_STANDARD)->IsSelected())
96 : {
97 0 : nSelectedPage = nPage;
98 0 : break;
99 : }
100 : }
101 :
102 : DBG_ASSERT(nSelectedPage != SDRPAGE_NOTFOUND, "no selected page");
103 0 : SdPage* pSelectedPage = mpDoc->GetSdPage(nSelectedPage, PK_STANDARD);
104 0 : OUString aOldLayoutName(pSelectedPage->GetLayoutName());
105 0 : sal_Int32 nPos = aOldLayoutName.indexOf(SD_LT_SEPARATOR);
106 0 : if (nPos != -1)
107 0 : aOldLayoutName = aOldLayoutName.copy(0, nPos);
108 :
109 : /* if we are on a master page, the changes apply for all pages and notes-
110 : pages who are using the relevant layout */
111 0 : sal_Bool bOnMaster = sal_False;
112 0 : if( mpViewShell && mpViewShell->ISA(DrawViewShell))
113 : {
114 : EditMode eEditMode =
115 0 : static_cast<DrawViewShell*>(mpViewShell)->GetEditMode();
116 0 : if (eEditMode == EM_MASTERPAGE)
117 0 : bOnMaster = sal_True;
118 : }
119 0 : sal_Bool bMasterPage = bOnMaster;
120 0 : sal_Bool bCheckMasters = sal_False;
121 :
122 : // call dialog
123 0 : sal_Bool bLoad = sal_False; // appear the new master pages?
124 0 : OUString aFile;
125 :
126 0 : SfxItemSet aSet(mpDoc->GetPool(), ATTR_PRESLAYOUT_START, ATTR_PRESLAYOUT_END);
127 :
128 0 : aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad));
129 0 : aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, bMasterPage ) );
130 0 : aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, bCheckMasters ) );
131 0 : aSet.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aOldLayoutName));
132 :
133 :
134 :
135 0 : const SfxItemSet *pArgs = rReq.GetArgs ();
136 :
137 0 : if (pArgs)
138 : {
139 0 : if (pArgs->GetItemState(ATTR_PRESLAYOUT_LOAD) == SFX_ITEM_SET)
140 0 : bLoad = ((SfxBoolItem&)pArgs->Get(ATTR_PRESLAYOUT_LOAD)).GetValue();
141 0 : if( pArgs->GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE ) == SFX_ITEM_SET )
142 0 : bMasterPage = ( (SfxBoolItem&) pArgs->Get( ATTR_PRESLAYOUT_MASTER_PAGE ) ).GetValue();
143 0 : if( pArgs->GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS ) == SFX_ITEM_SET )
144 0 : bCheckMasters = ( (SfxBoolItem&) pArgs->Get( ATTR_PRESLAYOUT_CHECK_MASTERS ) ).GetValue();
145 0 : if (pArgs->GetItemState(ATTR_PRESLAYOUT_NAME) == SFX_ITEM_SET)
146 0 : aFile = ((SfxStringItem&)pArgs->Get(ATTR_PRESLAYOUT_NAME)).GetValue();
147 : }
148 : else
149 : {
150 0 : SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
151 0 : AbstractSdPresLayoutDlg* pDlg = pFact ? pFact->CreateSdPresLayoutDlg(mpDocSh, NULL, aSet ) : 0;
152 :
153 0 : sal_uInt16 nResult = pDlg ? pDlg->Execute() : static_cast<short>(RET_CANCEL);
154 :
155 0 : switch (nResult)
156 : {
157 : case RET_OK:
158 : {
159 0 : pDlg->GetAttr(aSet);
160 0 : if (aSet.GetItemState(ATTR_PRESLAYOUT_LOAD) == SFX_ITEM_SET)
161 0 : bLoad = ((SfxBoolItem&)aSet.Get(ATTR_PRESLAYOUT_LOAD)).GetValue();
162 0 : if( aSet.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE ) == SFX_ITEM_SET )
163 0 : bMasterPage = ( (SfxBoolItem&) aSet.Get( ATTR_PRESLAYOUT_MASTER_PAGE ) ).GetValue();
164 0 : if( aSet.GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS ) == SFX_ITEM_SET )
165 0 : bCheckMasters = ( (SfxBoolItem&) aSet.Get( ATTR_PRESLAYOUT_CHECK_MASTERS ) ).GetValue();
166 0 : if (aSet.GetItemState(ATTR_PRESLAYOUT_NAME) == SFX_ITEM_SET)
167 0 : aFile = ((SfxStringItem&)aSet.Get(ATTR_PRESLAYOUT_NAME)).GetValue();
168 : }
169 0 : break;
170 :
171 : default:
172 0 : bError = sal_True;
173 : }
174 0 : delete pDlg;
175 : }
176 :
177 0 : if (!bError)
178 : {
179 0 : mpDocSh->SetWaitCursor( true );
180 :
181 : /* Here, we only exchange masterpages, therefore the current page
182 : remains the current page. To prevent calling PageOrderChangedHint
183 : during insertion and extraction of the masterpages, we block. */
184 : /* That isn't quitely right. If the masterpageview is active and you are
185 : removing a masterpage, it's possible that you are removing the
186 : current masterpage. So you have to call ResetActualPage ! */
187 0 : if( mpViewShell->ISA(DrawViewShell) && !bCheckMasters )
188 0 : static_cast<DrawView*>(mpView)->BlockPageOrderChangedHint(sal_True);
189 :
190 0 : if (bLoad)
191 : {
192 0 : OUString aFileName = aFile.getToken(0, DOCUMENT_TOKEN);
193 0 : SdDrawDocument* pTempDoc = mpDoc->OpenBookmarkDoc( aFileName );
194 :
195 : // #69581: If I chosed the standard-template I got no filename and so I get no
196 : // SdDrawDocument-Pointer. But the method SetMasterPage is able to handle
197 : // a NULL-pointer as a Standard-template ( look at SdDrawDocument::SetMasterPage )
198 0 : OUString aLayoutName;
199 0 : if( pTempDoc )
200 0 : aLayoutName = aFile.getToken(1, DOCUMENT_TOKEN);
201 :
202 0 : mpDoc->SetMasterPage(nSelectedPage, aLayoutName, pTempDoc, bMasterPage, bCheckMasters);
203 0 : mpDoc->CloseBookmarkDoc();
204 : }
205 : else
206 : {
207 : // use master page with the layout name aFile from current Doc
208 0 : mpDoc->SetMasterPage(nSelectedPage, aFile, mpDoc, bMasterPage, bCheckMasters);
209 : }
210 :
211 : // remove blocking
212 0 : if (mpViewShell->ISA(DrawViewShell) && !bCheckMasters )
213 0 : static_cast<DrawView*>(mpView)->BlockPageOrderChangedHint(sal_False);
214 :
215 : // if the master page was visible, show it again
216 0 : if (!bError && nSelectedPage != SDRPAGE_NOTFOUND)
217 : {
218 0 : if (bOnMaster)
219 : {
220 0 : if (mpViewShell->ISA(DrawViewShell))
221 : {
222 : ::sd::View* pView =
223 0 : static_cast<DrawViewShell*>(mpViewShell)->GetView();
224 0 : sal_uInt16 nPgNum = pSelectedPage->TRG_GetMasterPage().GetPageNum();
225 :
226 0 : if (static_cast<DrawViewShell*>(mpViewShell)->GetPageKind() == PK_NOTES)
227 0 : nPgNum++;
228 :
229 0 : pView->HideSdrPage();
230 0 : pView->ShowSdrPage(pView->GetModel()->GetMasterPage(nPgNum));
231 : }
232 :
233 : // force update of TabBar
234 0 : mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_MASTERPAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
235 : }
236 : else
237 : {
238 0 : pSelectedPage->SetAutoLayout(pSelectedPage->GetAutoLayout());
239 : }
240 : }
241 :
242 : // fake a mode change to repaint the page tab bar
243 0 : if( mpViewShell && mpViewShell->ISA( DrawViewShell ) )
244 : {
245 : DrawViewShell* pDrawViewSh =
246 0 : static_cast<DrawViewShell*>(mpViewShell);
247 0 : EditMode eMode = pDrawViewSh->GetEditMode();
248 0 : sal_Bool bLayer = pDrawViewSh->IsLayerModeActive();
249 0 : pDrawViewSh->ChangeEditMode( eMode, !bLayer );
250 0 : pDrawViewSh->ChangeEditMode( eMode, bLayer );
251 : }
252 :
253 0 : mpDocSh->SetWaitCursor( false );
254 0 : }
255 0 : }
256 :
257 0 : } // end of namespace sd
258 :
259 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|