xref: /aoo42x/main/sd/source/ui/func/fuprlout.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 
32 #include "fuprlout.hxx"
33 #include <vcl/wrkwin.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <svl/smplhint.hxx>
36 #include <svl/itempool.hxx>
37 #include <sot/storage.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <svx/svdundo.hxx>
40 
41 #include <sfx2/viewfrm.hxx>
42 #include <sfx2/request.hxx>
43 
44 #include "drawdoc.hxx"
45 #include "sdpage.hxx"
46 #include "pres.hxx"
47 #include "DrawViewShell.hxx"
48 #ifndef SD_FRAMW_VIEW_HXX
49 #include "FrameView.hxx"
50 #endif
51 #include "stlpool.hxx"
52 #include "View.hxx"
53 #include "glob.hrc"
54 #include "glob.hxx"
55 #include "strings.hrc"
56 #include "strmname.h"
57 #include "app.hrc"
58 #include "DrawDocShell.hxx"
59 #include "unprlout.hxx"
60 #include "unchss.hxx"
61 #include "unmovss.hxx"
62 #include "sdattr.hxx"
63 #include "sdresid.hxx"
64 #include "drawview.hxx"
65 #include "eetext.hxx"
66 #include <editeng/editdata.hxx>
67 #include "sdabstdlg.hxx"
68 
69 namespace sd
70 {
71 
72 #ifndef SO2_DECL_SVSTORAGE_DEFINED
73 #define SO2_DECL_SVSTORAGE_DEFINED
74 SO2_DECL_REF(SvStorage)
75 #endif
76 
77 TYPEINIT1( FuPresentationLayout, FuPoor );
78 
79 #define POOL_BUFFER_SIZE		(sal_uInt16)32768
80 #define DOCUMENT_BUFFER_SIZE	(sal_uInt16)32768
81 #define DOCUMENT_TOKEN (sal_Unicode('#'))
82 
83 /*************************************************************************
84 |*
85 |* Konstruktor
86 |*
87 \************************************************************************/
88 
89 FuPresentationLayout::FuPresentationLayout (
90     ViewShell* pViewSh,
91     ::sd::Window* pWin,
92     ::sd::View* pView,
93     SdDrawDocument* pDoc,
94     SfxRequest& rReq)
95     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
96 {
97 }
98 
99 FunctionReference FuPresentationLayout::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
100 {
101 	FunctionReference xFunc( new FuPresentationLayout( pViewSh, pWin, pView, pDoc, rReq ) );
102 	xFunc->DoExecute(rReq);
103 	return xFunc;
104 }
105 
106 void FuPresentationLayout::DoExecute( SfxRequest& rReq )
107 {
108 	// damit nicht Objekte, die gerade editiert werden oder selektiert
109 	// sind , verschwinden
110 	mpView->SdrEndTextEdit();
111 
112 	if(mpView->GetSdrPageView())
113 	{
114 		mpView->UnmarkAll();
115 	}
116 
117 	sal_Bool bError = sal_False;
118 
119 	// die aktive Seite ermitteln
120 	sal_uInt16 nSelectedPage = SDRPAGE_NOTFOUND;
121 	for (sal_uInt16 nPage = 0; nPage < mpDoc->GetSdPageCount(PK_STANDARD); nPage++)
122 	{
123 		if (mpDoc->GetSdPage(nPage, PK_STANDARD)->IsSelected())
124 		{
125 			nSelectedPage = nPage;
126 			break;
127 		}
128 	}
129 
130 	DBG_ASSERT(nSelectedPage != SDRPAGE_NOTFOUND, "keine selektierte Seite");
131 	SdPage* pSelectedPage = mpDoc->GetSdPage(nSelectedPage, PK_STANDARD);
132 	String aOldPageLayoutName(pSelectedPage->GetLayoutName());
133 	String aOldLayoutName(aOldPageLayoutName);
134 	aOldLayoutName.Erase(aOldLayoutName.SearchAscii(SD_LT_SEPARATOR));
135 
136 	// wenn wir auf einer Masterpage sind, gelten die Aenderungen fuer alle
137 	// Seiten und Notizseiten, die das betreffende Layout benutzen
138 	sal_Bool bOnMaster = sal_False;
139 	if( mpViewShell && mpViewShell->ISA(DrawViewShell))
140 	{
141 		EditMode eEditMode =
142             static_cast<DrawViewShell*>(mpViewShell)->GetEditMode();
143 		if (eEditMode == EM_MASTERPAGE)
144 			bOnMaster = sal_True;
145 	}
146 	sal_Bool bMasterPage = bOnMaster;
147 	sal_Bool bCheckMasters = sal_False;
148 
149 	// Dialog aufrufen
150 	sal_Bool   bLoad = sal_False;			// tauchen neue Masterpages auf?
151 	String aFile;
152 
153 	SfxItemSet aSet(mpDoc->GetPool(), ATTR_PRESLAYOUT_START, ATTR_PRESLAYOUT_END);
154 
155 	aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad));
156 	aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, bMasterPage ) );
157 	aSet.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, bCheckMasters ) );
158 	aSet.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aOldLayoutName));
159 
160 
161 
162 	const SfxItemSet *pArgs = rReq.GetArgs ();
163 
164 	if (pArgs)
165 	{
166 		if (pArgs->GetItemState(ATTR_PRESLAYOUT_LOAD) == SFX_ITEM_SET)
167 			bLoad = ((SfxBoolItem&)pArgs->Get(ATTR_PRESLAYOUT_LOAD)).GetValue();
168 		if( pArgs->GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE ) == SFX_ITEM_SET )
169 			bMasterPage = ( (SfxBoolItem&) pArgs->Get( ATTR_PRESLAYOUT_MASTER_PAGE ) ).GetValue();
170 		if( pArgs->GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS ) == SFX_ITEM_SET )
171 			bCheckMasters = ( (SfxBoolItem&) pArgs->Get( ATTR_PRESLAYOUT_CHECK_MASTERS ) ).GetValue();
172 		if (pArgs->GetItemState(ATTR_PRESLAYOUT_NAME) == SFX_ITEM_SET)
173 			aFile = ((SfxStringItem&)pArgs->Get(ATTR_PRESLAYOUT_NAME)).GetValue();
174 	}
175 	else
176 	{
177 		SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
178 		AbstractSdPresLayoutDlg* pDlg = pFact ? pFact->CreateSdPresLayoutDlg(mpDocSh, mpViewShell, NULL, aSet ) : 0;
179 
180 		sal_uInt16 nResult = pDlg ? pDlg->Execute() : RET_CANCEL;
181 
182 		switch (nResult)
183 		{
184 			case RET_OK:
185 			{
186 				pDlg->GetAttr(aSet);
187 				if (aSet.GetItemState(ATTR_PRESLAYOUT_LOAD) == SFX_ITEM_SET)
188 					bLoad = ((SfxBoolItem&)aSet.Get(ATTR_PRESLAYOUT_LOAD)).GetValue();
189 				if( aSet.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE ) == SFX_ITEM_SET )
190 					bMasterPage = ( (SfxBoolItem&) aSet.Get( ATTR_PRESLAYOUT_MASTER_PAGE ) ).GetValue();
191 				if( aSet.GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS ) == SFX_ITEM_SET )
192 					bCheckMasters = ( (SfxBoolItem&) aSet.Get( ATTR_PRESLAYOUT_CHECK_MASTERS ) ).GetValue();
193 				if (aSet.GetItemState(ATTR_PRESLAYOUT_NAME) == SFX_ITEM_SET)
194 					aFile = ((SfxStringItem&)aSet.Get(ATTR_PRESLAYOUT_NAME)).GetValue();
195 			}
196 			break;
197 
198 			default:
199 				bError = sal_True;
200 		}
201 		delete pDlg;
202 	}
203 
204 	if (!bError)
205 	{
206 		mpDocSh->SetWaitCursor( sal_True );
207 
208 		// Hier werden nur Masterpages ausgewechselt, d.h. die aktuelle Seite
209 		// bleibt aktuell. Damit beim Ein- und Ausfuegen der Masterpages nicht
210 		// dauernd via PageOrderChangedHint die Methode ResetActualPage gerufen
211 		// wird, wird jetzt blockiert.
212 		// That isn't quitely right. If the masterpageview is active and you are
213 		// removing a masterpage, it's possible that you are removing the
214 		// current masterpage. So you have to call ResetActualPage !
215 		if( mpViewShell->ISA(DrawViewShell) && !bCheckMasters )
216 			static_cast<DrawView*>(mpView)->BlockPageOrderChangedHint(sal_True);
217 
218 		if (bLoad)
219 		{
220 			String aFileName = aFile.GetToken( 0, DOCUMENT_TOKEN );
221 			SdDrawDocument* pTempDoc = mpDoc->OpenBookmarkDoc( aFileName );
222 
223 			// #69581: If I chosed the standard-template I got no filename and so I get no
224 			//         SdDrawDocument-Pointer. But the method SetMasterPage is able to handle
225 			//         a NULL-pointer as a Standard-template ( look at SdDrawDocument::SetMasterPage )
226 			String aLayoutName;
227 			if( pTempDoc )
228 				aLayoutName = aFile.GetToken( 1, DOCUMENT_TOKEN );
229 
230 			mpDoc->SetMasterPage(nSelectedPage, aLayoutName, pTempDoc, bMasterPage, bCheckMasters);
231 			mpDoc->CloseBookmarkDoc();
232 		}
233 		else
234 		{
235 			// MasterPage mit dem LayoutNamen aFile aus aktuellem Doc verwenden
236 			mpDoc->SetMasterPage(nSelectedPage, aFile, mpDoc, bMasterPage, bCheckMasters);
237 		}
238 
239 		// Blockade wieder aufheben
240 		if (mpViewShell->ISA(DrawViewShell) && !bCheckMasters )
241 			static_cast<DrawView*>(mpView)->BlockPageOrderChangedHint(sal_False);
242 
243 		/*************************************************************************
244 		|* Falls dargestellte Masterpage sichtbar war, neu darstellen
245 		\************************************************************************/
246 		if (!bError && nSelectedPage != SDRPAGE_NOTFOUND)
247 		{
248 			if (bOnMaster)
249 			{
250 				if (mpViewShell->ISA(DrawViewShell))
251 				{
252 					::sd::View* pView =
253                           static_cast<DrawViewShell*>(mpViewShell)->GetView();
254 					sal_uInt16 nPgNum = pSelectedPage->TRG_GetMasterPage().GetPageNum();
255 
256 					if (static_cast<DrawViewShell*>(mpViewShell)->GetPageKind() == PK_NOTES)
257 						nPgNum++;
258 
259 					pView->HideSdrPage();
260 					pView->ShowSdrPage(pView->GetModel()->GetMasterPage(nPgNum));
261 				}
262 
263 				// damit TabBar aktualisiert wird
264 				mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_MASTERPAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
265 			}
266 			else
267 			{
268 				pSelectedPage->SetAutoLayout(pSelectedPage->GetAutoLayout());
269 			}
270 		}
271 
272 		// fake a mode change to repaint the page tab bar
273 		if( mpViewShell && mpViewShell->ISA( DrawViewShell ) )
274 		{
275 			DrawViewShell* pDrawViewSh =
276                 static_cast<DrawViewShell*>(mpViewShell);
277 			EditMode eMode = pDrawViewSh->GetEditMode();
278 			sal_Bool bLayer = pDrawViewSh->IsLayerModeActive();
279 			pDrawViewSh->ChangeEditMode( eMode, !bLayer );
280 			pDrawViewSh->ChangeEditMode( eMode, bLayer );
281 		}
282 
283 		mpDocSh->SetWaitCursor( sal_False );
284 	}
285 }
286 
287 } // end of namespace sd
288