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