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"
54 #include <boost/scoped_ptr.hpp>
59 TYPEINIT1( FuPresentationLayout
, FuPoor
);
61 #define DOCUMENT_TOKEN '#'
63 FuPresentationLayout::FuPresentationLayout (
69 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
73 rtl::Reference
<FuPoor
> FuPresentationLayout::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
75 rtl::Reference
<FuPoor
> xFunc( new FuPresentationLayout( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
76 xFunc
->DoExecute(rReq
);
80 void FuPresentationLayout::DoExecute( SfxRequest
& rReq
)
82 // prevent selected objects or objects which are under editing from disappearing
83 mpView
->SdrEndTextEdit();
85 if(mpView
->GetSdrPageView())
92 // determine the active page
93 sal_uInt16 nSelectedPage
= SDRPAGE_NOTFOUND
;
94 for (sal_uInt16 nPage
= 0; nPage
< mpDoc
->GetSdPageCount(PK_STANDARD
); nPage
++)
96 if (mpDoc
->GetSdPage(nPage
, PK_STANDARD
)->IsSelected())
98 nSelectedPage
= nPage
;
103 DBG_ASSERT(nSelectedPage
!= SDRPAGE_NOTFOUND
, "no selected page");
104 SdPage
* pSelectedPage
= mpDoc
->GetSdPage(nSelectedPage
, PK_STANDARD
);
105 OUString
aOldLayoutName(pSelectedPage
->GetLayoutName());
106 sal_Int32 nPos
= aOldLayoutName
.indexOf(SD_LT_SEPARATOR
);
108 aOldLayoutName
= aOldLayoutName
.copy(0, nPos
);
110 /* if we are on a master page, the changes apply for all pages and notes-
111 pages who are using the relevant layout */
112 bool bOnMaster
= false;
113 if( mpViewShell
&& mpViewShell
->ISA(DrawViewShell
))
116 static_cast<DrawViewShell
*>(mpViewShell
)->GetEditMode();
117 if (eEditMode
== EM_MASTERPAGE
)
120 bool bMasterPage
= bOnMaster
;
121 bool bCheckMasters
= false;
124 bool bLoad
= false; // appear the new master pages?
127 SfxItemSet
aSet(mpDoc
->GetPool(), ATTR_PRESLAYOUT_START
, ATTR_PRESLAYOUT_END
);
129 aSet
.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD
, bLoad
));
130 aSet
.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE
, bMasterPage
) );
131 aSet
.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS
, bCheckMasters
) );
132 aSet
.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME
, aOldLayoutName
));
134 const SfxItemSet
*pArgs
= rReq
.GetArgs ();
138 if (pArgs
->GetItemState(ATTR_PRESLAYOUT_LOAD
) == SfxItemState::SET
)
139 bLoad
= static_cast<const SfxBoolItem
&>(pArgs
->Get(ATTR_PRESLAYOUT_LOAD
)).GetValue();
140 if( pArgs
->GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE
) == SfxItemState::SET
)
141 bMasterPage
= static_cast<const SfxBoolItem
&>( pArgs
->Get( ATTR_PRESLAYOUT_MASTER_PAGE
) ).GetValue();
142 if( pArgs
->GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS
) == SfxItemState::SET
)
143 bCheckMasters
= static_cast<const SfxBoolItem
&>( pArgs
->Get( ATTR_PRESLAYOUT_CHECK_MASTERS
) ).GetValue();
144 if (pArgs
->GetItemState(ATTR_PRESLAYOUT_NAME
) == SfxItemState::SET
)
145 aFile
= static_cast<const SfxStringItem
&>(pArgs
->Get(ATTR_PRESLAYOUT_NAME
)).GetValue();
149 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
150 boost::scoped_ptr
<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
) == SfxItemState::SET
)
160 bLoad
= static_cast<const SfxBoolItem
&>(aSet
.Get(ATTR_PRESLAYOUT_LOAD
)).GetValue();
161 if( aSet
.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE
) == SfxItemState::SET
)
162 bMasterPage
= static_cast<const SfxBoolItem
&>(aSet
.Get( ATTR_PRESLAYOUT_MASTER_PAGE
) ).GetValue();
163 if( aSet
.GetItemState( ATTR_PRESLAYOUT_CHECK_MASTERS
) == SfxItemState::SET
)
164 bCheckMasters
= static_cast<const SfxBoolItem
&>(aSet
.Get( ATTR_PRESLAYOUT_CHECK_MASTERS
) ).GetValue();
165 if (aSet
.GetItemState(ATTR_PRESLAYOUT_NAME
) == SfxItemState::SET
)
166 aFile
= static_cast<const SfxStringItem
&>(aSet
.Get(ATTR_PRESLAYOUT_NAME
)).GetValue();
177 mpDocSh
->SetWaitCursor( true );
179 /* Here, we only exchange masterpages, therefore the current page
180 remains the current page. To prevent calling PageOrderChangedHint
181 during insertion and extraction of the masterpages, we block. */
182 /* That isn't quitely right. If the masterpageview is active and you are
183 removing a masterpage, it's possible that you are removing the
184 current masterpage. So you have to call ResetActualPage ! */
185 if( mpViewShell
->ISA(DrawViewShell
) && !bCheckMasters
)
186 static_cast<DrawView
*>(mpView
)->BlockPageOrderChangedHint(true);
190 OUString aFileName
= aFile
.getToken(0, DOCUMENT_TOKEN
);
191 SdDrawDocument
* pTempDoc
= mpDoc
->OpenBookmarkDoc( aFileName
);
193 // #69581: If I chosed the standard-template I got no filename and so I get no
194 // SdDrawDocument-Pointer. But the method SetMasterPage is able to handle
195 // a NULL-pointer as a Standard-template ( look at SdDrawDocument::SetMasterPage )
196 OUString aLayoutName
;
198 aLayoutName
= aFile
.getToken(1, DOCUMENT_TOKEN
);
200 mpDoc
->SetMasterPage(nSelectedPage
, aLayoutName
, pTempDoc
, bMasterPage
, bCheckMasters
);
201 mpDoc
->CloseBookmarkDoc();
205 // use master page with the layout name aFile from current Doc
206 mpDoc
->SetMasterPage(nSelectedPage
, aFile
, mpDoc
, bMasterPage
, bCheckMasters
);
210 if (mpViewShell
->ISA(DrawViewShell
) && !bCheckMasters
)
211 static_cast<DrawView
*>(mpView
)->BlockPageOrderChangedHint(false);
213 // if the master page was visible, show it again
214 if (!bError
&& nSelectedPage
!= SDRPAGE_NOTFOUND
)
218 if (mpViewShell
->ISA(DrawViewShell
))
221 static_cast<DrawViewShell
*>(mpViewShell
)->GetView();
222 sal_uInt16 nPgNum
= pSelectedPage
->TRG_GetMasterPage().GetPageNum();
224 if (static_cast<DrawViewShell
*>(mpViewShell
)->GetPageKind() == PK_NOTES
)
227 pView
->HideSdrPage();
228 pView
->ShowSdrPage(pView
->GetModel()->GetMasterPage(nPgNum
));
231 // force update of TabBar
232 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_MASTERPAGE
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
236 pSelectedPage
->SetAutoLayout(pSelectedPage
->GetAutoLayout());
240 // fake a mode change to repaint the page tab bar
241 if( mpViewShell
&& mpViewShell
->ISA( DrawViewShell
) )
243 DrawViewShell
* pDrawViewSh
=
244 static_cast<DrawViewShell
*>(mpViewShell
);
245 EditMode eMode
= pDrawViewSh
->GetEditMode();
246 bool bLayer
= pDrawViewSh
->IsLayerModeActive();
247 pDrawViewSh
->ChangeEditMode( eMode
, !bLayer
);
248 pDrawViewSh
->ChangeEditMode( eMode
, bLayer
);
251 mpDocSh
->SetWaitCursor( false );
255 } // end of namespace sd
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */