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