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/stritem.hxx>
23 #include <svl/style.hxx>
24 #include <editeng/outliner.hxx>
25 #include <svl/hint.hxx>
26 #include <tools/debug.hxx>
30 #include <strings.hxx>
32 #include <drawdoc.hxx>
33 #include <sfx2/sfxdlg.hxx>
34 #include <DrawDocShell.hxx>
35 #include <OutlineView.hxx>
36 #include <OutlineViewShell.hxx>
37 #include <ViewShell.hxx>
40 #include <prlayout.hxx>
42 #include <sdabstdlg.hxx>
48 FuPresentationObjects::FuPresentationObjects (
54 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
58 rtl::Reference
<FuPoor
> FuPresentationObjects::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
60 rtl::Reference
<FuPoor
> xFunc( new FuPresentationObjects( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
61 xFunc
->DoExecute(rReq
);
65 void FuPresentationObjects::DoExecute( SfxRequest
& )
67 OutlineViewShell
* pOutlineViewShell
= dynamic_cast< OutlineViewShell
* >( mpViewShell
);
68 DBG_ASSERT( pOutlineViewShell
, "sd::FuPresentationObjects::DoExecute(), does not work without an OutlineViewShell!");
69 if( !pOutlineViewShell
)
72 /* does the selections end in a unique presentation layout?
73 if not, it is not allowed to edit the templates */
74 SfxItemSetFixed
<SID_STATUS_LAYOUT
, SID_STATUS_LAYOUT
> aSet(mpDoc
->GetItemPool() );
75 pOutlineViewShell
->GetStatusBarState( aSet
);
76 OUString aLayoutName
= aSet
.Get(SID_STATUS_LAYOUT
).GetValue();
77 DBG_ASSERT(!aLayoutName
.isEmpty(), "Layout not defined");
80 sal_Int16 nDepth
, nTmp
;
81 OutlineView
* pOlView
= static_cast<OutlineView
*>(pOutlineViewShell
->GetView());
82 OutlinerView
* pOutlinerView
= pOlView
->GetViewByWindow( static_cast<Window
*>(mpWindow
) );
83 ::Outliner
* pOutl
= pOutlinerView
->GetOutliner();
85 std::vector
<Paragraph
*> aSelList
;
86 pOutlinerView
->CreateSelectionList(aSelList
);
88 Paragraph
* pPara
= aSelList
.empty() ? nullptr : aSelList
.front();
90 nDepth
= pOutl
->GetDepth(pOutl
->GetAbsPos( pPara
) );
91 bool bPage
= ::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
);
93 for( const auto& rpPara
: aSelList
)
95 nTmp
= pOutl
->GetDepth( pOutl
->GetAbsPos( rpPara
) );
103 if( ::Outliner::HasParaFlag( rpPara
, ParaFlag::ISPAGE
) != bPage
)
114 OUString aStyleName
= aLayoutName
+ SD_LT_SEPARATOR
;
115 PresentationObjects ePO
;
119 ePO
= PresentationObjects::Title
;
120 aStyleName
+= STR_LAYOUT_TITLE
;
124 ePO
= static_cast<PresentationObjects
>( static_cast<int>(PresentationObjects::Outline_1
) + nDepth
- 1 );
125 aStyleName
+= STR_LAYOUT_OUTLINE
+ " " + OUString::number(nDepth
);
128 SfxStyleSheetBasePool
* pStyleSheetPool
= mpDocSh
->GetStyleSheetPool();
129 SfxStyleSheetBase
* pStyleSheet
= pStyleSheetPool
->Find( aStyleName
, SfxStyleFamily::Page
);
130 DBG_ASSERT(pStyleSheet
, "StyleSheet missing");
135 SfxStyleSheetBase
& rStyleSheet
= *pStyleSheet
;
137 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
138 ScopedVclPtr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateSdPresLayoutTemplateDlg(mpDocSh
, mpViewShell
->GetFrameWeld(),
139 false, rStyleSheet
, ePO
, pStyleSheetPool
));
140 if( pDlg
->Execute() == RET_OK
)
142 const SfxItemSet
* pOutSet
= pDlg
->GetOutputItemSet();
144 mpDocSh
->GetUndoManager()->AddUndoAction(
145 std::make_unique
<StyleSheetUndoAction
>(mpDoc
, static_cast<SfxStyleSheet
&>(rStyleSheet
), pOutSet
));
147 rStyleSheet
.GetItemSet().Put( *pOutSet
);
148 static_cast<SfxStyleSheet
&>( rStyleSheet
).Broadcast( SfxHint( SfxHintId::DataChanged
) );
152 } // end of namespace sd
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */