tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / sd / source / ui / func / fuprobjs.cxx
blobedba20f8829cb8522f418813f98ab1169146a9f4
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 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");
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 = PresentationObjects::Title;
120 aStyleName += STR_LAYOUT_TITLE;
122 else
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");
132 if( !pStyleSheet )
133 return;
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();
143 // Undo-Action
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: */