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 <fuprobjs.hxx>
22 #include <svl/style.hxx>
23 #include <editeng/outliner.hxx>
24 #include <svl/hint.hxx>
28 #include <strings.hxx>
30 #include <drawdoc.hxx>
31 #include <OutlineViewShell.hxx>
32 #include <ViewShell.hxx>
35 #include <prlayout.hxx>
37 #include <sdabstdlg.hxx>
43 FuPresentationObjects::FuPresentationObjects (
49 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
53 rtl::Reference
<FuPoor
> FuPresentationObjects::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
55 rtl::Reference
<FuPoor
> xFunc( new FuPresentationObjects( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
56 xFunc
->DoExecute(rReq
);
60 void FuPresentationObjects::DoExecute( SfxRequest
& )
62 OutlineViewShell
* pOutlineViewShell
= dynamic_cast< OutlineViewShell
* >( mpViewShell
);
63 DBG_ASSERT( pOutlineViewShell
, "sd::FuPresentationObjects::DoExecute(), does not work without an OutlineViewShell!");
64 if( !pOutlineViewShell
)
67 /* does the selections end in a unique presentation layout?
68 if not, it is not allowed to edit the templates */
69 SfxItemSet
aSet(mpDoc
->GetItemPool(), svl::Items
<SID_STATUS_LAYOUT
, SID_STATUS_LAYOUT
>{});
70 pOutlineViewShell
->GetStatusBarState( aSet
);
71 OUString aLayoutName
= static_cast<const SfxStringItem
&>(aSet
.Get(SID_STATUS_LAYOUT
)).GetValue();
72 DBG_ASSERT(!aLayoutName
.isEmpty(), "Layout not defined");
75 sal_Int16 nDepth
, nTmp
;
76 OutlineView
* pOlView
= static_cast<OutlineView
*>(pOutlineViewShell
->GetView());
77 OutlinerView
* pOutlinerView
= pOlView
->GetViewByWindow( static_cast<Window
*>(mpWindow
) );
78 ::Outliner
* pOutl
= pOutlinerView
->GetOutliner();
80 std::vector
<Paragraph
*> aSelList
;
81 pOutlinerView
->CreateSelectionList(aSelList
);
83 std::vector
<Paragraph
*>::const_iterator iter
= aSelList
.begin();
84 Paragraph
* pPara
= aSelList
.empty() ? nullptr : *iter
;
86 nDepth
= pOutl
->GetDepth(pOutl
->GetAbsPos( pPara
) );
87 bool bPage
= ::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
);
89 while( iter
!= aSelList
.end() )
93 nTmp
= pOutl
->GetDepth( pOutl
->GetAbsPos( pPara
) );
101 if( ::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
) != bPage
)
112 OUString aStyleName
= aLayoutName
+ SD_LT_SEPARATOR
;
113 PresentationObjects ePO
;
118 aStyleName
+= STR_LAYOUT_TITLE
;
122 ePO
= static_cast<PresentationObjects
>( PO_OUTLINE_1
+ nDepth
- 1 );
123 aStyleName
+= STR_LAYOUT_OUTLINE
" "
124 + OUString::number(nDepth
);
127 SfxStyleSheetBasePool
* pStyleSheetPool
= mpDocSh
->GetStyleSheetPool();
128 SfxStyleSheetBase
* pStyleSheet
= pStyleSheetPool
->Find( aStyleName
, SfxStyleFamily::Page
);
129 DBG_ASSERT(pStyleSheet
, "StyleSheet missing");
133 SfxStyleSheetBase
& rStyleSheet
= *pStyleSheet
;
135 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
138 ScopedVclPtr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateSdPresLayoutTemplateDlg( mpDocSh
, mpViewShell
->GetActiveWindow(),
139 false, rStyleSheet
, ePO
, pStyleSheetPool
));
140 if( pDlg
->Execute() == RET_OK
)
142 const SfxItemSet
* pOutSet
= pDlg
->GetOutputItemSet();
144 StyleSheetUndoAction
* pAction
= new StyleSheetUndoAction
145 (mpDoc
, static_cast<SfxStyleSheet
*>(pStyleSheet
), pOutSet
);
146 mpDocSh
->GetUndoManager()->AddUndoAction(pAction
);
148 pStyleSheet
->GetItemSet().Put( *pOutSet
);
149 static_cast<SfxStyleSheet
*>( pStyleSheet
)->Broadcast( SfxHint( SfxHintId::DataChanged
) );
156 } // end of namespace sd
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */