1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
35 #include "DrawViewShell.hxx"
36 #include "FrameView.hxx"
37 #include "stlpool.hxx"
41 #include "strings.hrc"
44 #include "DrawDocShell.hxx"
45 #include "unprlout.hxx"
47 #include "unmovss.hxx"
49 #include "sdresid.hxx"
50 #include "drawview.hxx"
51 #include <editeng/outliner.hxx>
52 #include <editeng/editdata.hxx>
53 #include "sdabstdlg.hxx"
58 TYPEINIT1( FuPresentationLayout
, FuPoor
);
60 #define DOCUMENT_TOKEN (sal_Unicode('#'))
62 FuPresentationLayout::FuPresentationLayout (
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
);
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())
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
;
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
))
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
;
122 sal_Bool bLoad
= sal_False
; // appear the new master pages?
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 ();
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();
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
);
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();
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
);
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 )
199 aLayoutName
= aFile
.GetToken( 1, DOCUMENT_TOKEN
);
201 mpDoc
->SetMasterPage(nSelectedPage
, aLayoutName
, pTempDoc
, bMasterPage
, bCheckMasters
);
202 mpDoc
->CloseBookmarkDoc();
206 // use master page with the layout name aFile from current Doc
207 mpDoc
->SetMasterPage(nSelectedPage
, aFile
, mpDoc
, bMasterPage
, bCheckMasters
);
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
)
219 if (mpViewShell
->ISA(DrawViewShell
))
222 static_cast<DrawViewShell
*>(mpViewShell
)->GetView();
223 sal_uInt16 nPgNum
= pSelectedPage
->TRG_GetMasterPage().GetPageNum();
225 if (static_cast<DrawViewShell
*>(mpViewShell
)->GetPageKind() == PK_NOTES
)
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
);
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: */