Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / fuprobjs.cxx
blob3e4b1af411c840904d5c3d105a25ab5b1bbf4275
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/style.hxx>
23 #include <editeng/outliner.hxx>
24 #include <svl/hint.hxx>
26 #include <app.hrc>
28 #include <strings.hxx>
30 #include <drawdoc.hxx>
31 #include <OutlineViewShell.hxx>
32 #include <ViewShell.hxx>
33 #include <Window.hxx>
34 #include <glob.hxx>
35 #include <prlayout.hxx>
36 #include <unchss.hxx>
37 #include <sdabstdlg.hxx>
38 #include <memory>
40 namespace sd {
43 FuPresentationObjects::FuPresentationObjects (
44 ViewShell* pViewSh,
45 ::sd::Window* pWin,
46 ::sd::View* pView,
47 SdDrawDocument* pDoc,
48 SfxRequest& rReq)
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);
57 return xFunc;
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 )
65 return;
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");
74 bool bUnique = false;
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() )
91 pPara = *iter;
93 nTmp = pOutl->GetDepth( pOutl->GetAbsPos( pPara ) );
95 if( nDepth != nTmp )
97 bUnique = false;
98 break;
101 if( ::Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) != bPage )
103 bUnique = false;
104 break;
106 bUnique = true;
107 ++iter;
110 if( bUnique )
112 OUString aStyleName = aLayoutName + SD_LT_SEPARATOR;
113 PresentationObjects ePO;
115 if( bPage )
117 ePO = PO_TITLE;
118 aStyleName += STR_LAYOUT_TITLE;
120 else
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");
131 if( pStyleSheet )
133 SfxStyleSheetBase& rStyleSheet = *pStyleSheet;
135 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
136 if (pFact)
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();
143 // Undo-Action
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: */