bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / func / fuprobjs.cxx
blob6578b585d64328678a31c5b10dc6d3802d2bd275
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 <vcl/msgbox.hxx>
23 #include <svl/style.hxx>
24 #include <editeng/outliner.hxx>
25 #include <svl/smplhint.hxx>
27 #include "app.hrc"
28 #include "res_bmp.hrc"
29 #include "strings.hrc"
30 #include "glob.hrc"
31 #include "prltempl.hrc"
33 #include "sdresid.hxx"
34 #include "drawdoc.hxx"
35 #include "OutlineViewShell.hxx"
36 #include "ViewShell.hxx"
37 #include "Window.hxx"
38 #include "glob.hxx"
39 #include "prlayout.hxx"
40 #include "unchss.hxx"
41 #include "sdabstdlg.hxx"
42 #include <boost/scoped_ptr.hpp>
44 namespace sd {
46 TYPEINIT1( FuPresentationObjects, FuPoor );
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(), 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( (Window*) mpWindow );
83 ::Outliner* pOutl = pOutlinerView->GetOutliner();
85 std::vector<Paragraph*> aSelList;
86 pOutlinerView->CreateSelectionList(aSelList);
88 std::vector<Paragraph*>::const_iterator iter = aSelList.begin();
89 Paragraph* pPara = aSelList.empty() ? NULL : *iter;
91 nDepth = pOutl->GetDepth(pOutl->GetAbsPos( pPara ) );
92 bool bPage = ::Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE );
94 while( iter != aSelList.end() )
96 pPara = *iter;
98 nTmp = pOutl->GetDepth( pOutl->GetAbsPos( pPara ) );
100 if( nDepth != nTmp )
102 bUnique = false;
103 break;
106 if( ::Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) != bPage )
108 bUnique = false;
109 break;
111 bUnique = true;
112 ++iter;
115 if( bUnique )
117 OUString aStyleName = aLayoutName;
118 aStyleName += SD_LT_SEPARATOR ;
119 sal_uInt16 nDlgId = TAB_PRES_LAYOUT_TEMPLATE;
120 PresentationObjects ePO;
122 if( bPage )
124 ePO = PO_TITLE;
125 aStyleName += SD_RESSTR(STR_LAYOUT_TITLE);
127 else
129 ePO = (PresentationObjects) ( PO_OUTLINE_1 + nDepth - 1 );
130 aStyleName += SD_RESSTR(STR_LAYOUT_OUTLINE);
131 aStyleName += OUString(' ') ;
132 aStyleName += OUString::number( nDepth ) ;
135 SfxStyleSheetBasePool* pStyleSheetPool = mpDocSh->GetStyleSheetPool();
136 SfxStyleSheetBase* pStyleSheet = pStyleSheetPool->Find( aStyleName, SD_STYLE_FAMILY_MASTERPAGE );
137 DBG_ASSERT(pStyleSheet, "StyleSheet missing");
139 if( pStyleSheet )
141 SfxStyleSheetBase& rStyleSheet = *pStyleSheet;
143 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
144 boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact ? pFact->CreateSdPresLayoutTemplateDlg( mpDocSh, NULL, SdResId( nDlgId ), rStyleSheet, ePO, pStyleSheetPool ) : 0);
145 if( pDlg && (pDlg->Execute() == RET_OK) )
147 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
148 // Undo-Action
149 StyleSheetUndoAction* pAction = new StyleSheetUndoAction
150 (mpDoc, static_cast<SfxStyleSheet*>(pStyleSheet), pOutSet);
151 mpDocSh->GetUndoManager()->AddUndoAction(pAction);
153 pStyleSheet->GetItemSet().Put( *pOutSet );
154 static_cast<SfxStyleSheet*>( pStyleSheet )->Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
160 } // end of namespace sd
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */