bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / func / fuprobjs.cxx
blobcabd3cff40fc5b5370e3ddb8023f51d62d8b57f0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
28 #include <app.hrc>
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>
38 #include <Window.hxx>
39 #include <glob.hxx>
40 #include <prlayout.hxx>
41 #include <unchss.hxx>
42 #include <sdabstdlg.hxx>
43 #include <memory>
45 namespace sd {
48 FuPresentationObjects::FuPresentationObjects (
49 ViewShell* pViewSh,
50 ::sd::Window* pWin,
51 ::sd::View* pView,
52 SdDrawDocument* pDoc,
53 SfxRequest& rReq)
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);
62 return xFunc;
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 )
70 return;
72 /* does the selections end in a unique presentation layout?
73 if not, it is not allowed to edit the templates */
74 SfxItemSet aSet(mpDoc->GetItemPool(), svl::Items<SID_STATUS_LAYOUT, SID_STATUS_LAYOUT>{});
75 pOutlineViewShell->GetStatusBarState( aSet );
76 OUString aLayoutName = static_cast<const SfxStringItem&>(aSet.Get(SID_STATUS_LAYOUT)).GetValue();
77 DBG_ASSERT(!aLayoutName.isEmpty(), "Layout not defined");
79 bool bUnique = false;
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 ) );
97 if( nDepth != nTmp )
99 bUnique = false;
100 break;
103 if( ::Outliner::HasParaFlag( rpPara, ParaFlag::ISPAGE ) != bPage )
105 bUnique = false;
106 break;
108 bUnique = true;
111 if( !bUnique )
112 return;
114 OUString aStyleName = aLayoutName + SD_LT_SEPARATOR;
115 PresentationObjects ePO;
117 if( bPage )
119 ePO = PO_TITLE;
120 aStyleName += STR_LAYOUT_TITLE;
122 else
124 ePO = static_cast<PresentationObjects>( PO_OUTLINE_1 + nDepth - 1 );
125 aStyleName += STR_LAYOUT_OUTLINE " "
126 + OUString::number(nDepth);
129 SfxStyleSheetBasePool* pStyleSheetPool = mpDocSh->GetStyleSheetPool();
130 SfxStyleSheetBase* pStyleSheet = pStyleSheetPool->Find( aStyleName, SfxStyleFamily::Page );
131 DBG_ASSERT(pStyleSheet, "StyleSheet missing");
133 if( !pStyleSheet )
134 return;
136 SfxStyleSheetBase& rStyleSheet = *pStyleSheet;
138 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
139 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSdPresLayoutTemplateDlg(mpDocSh, mpViewShell->GetFrameWeld(),
140 false, rStyleSheet, ePO, pStyleSheetPool));
141 if( pDlg->Execute() == RET_OK )
143 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
144 // Undo-Action
145 mpDocSh->GetUndoManager()->AddUndoAction(
146 std::make_unique<StyleSheetUndoAction>(mpDoc, static_cast<SfxStyleSheet*>(pStyleSheet), pOutSet));
148 pStyleSheet->GetItemSet().Put( *pOutSet );
149 static_cast<SfxStyleSheet*>( pStyleSheet )->Broadcast( SfxHint( SfxHintId::DataChanged ) );
153 } // end of namespace sd
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */