bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fuprobjs.cxx
blob81e3d588b7a7c6b90ee7afb8b11663dc4f84dae3
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 .
21 #include "fuprobjs.hxx"
23 #include <vcl/msgbox.hxx>
24 #include <svl/style.hxx>
25 #include <editeng/outliner.hxx>
26 #include <svl/smplhint.hxx>
29 #include "app.hrc"
30 #include "res_bmp.hrc"
31 #include "strings.hrc"
32 #include "glob.hrc"
33 #include "prltempl.hrc"
35 #include "sdresid.hxx"
36 #include "drawdoc.hxx"
37 #include "OutlineViewShell.hxx"
38 #include "ViewShell.hxx"
39 #include "Window.hxx"
40 #include "glob.hxx"
41 #include "prlayout.hxx"
42 #include "unchss.hxx"
43 #include "sdabstdlg.hxx"
44 namespace sd {
46 TYPEINIT1( FuPresentationObjects, FuPoor );
49 FuPresentationObjects::FuPresentationObjects (
50 ViewShell* pViewSh,
51 ::sd::Window* pWin,
52 ::sd::View* pView,
53 SdDrawDocument* pDoc,
54 SfxRequest& rReq)
55 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
59 FunctionReference FuPresentationObjects::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
61 FunctionReference xFunc( new FuPresentationObjects( pViewSh, pWin, pView, pDoc, rReq ) );
62 xFunc->DoExecute(rReq);
63 return xFunc;
66 void FuPresentationObjects::DoExecute( SfxRequest& )
68 OutlineViewShell* pOutlineViewShell = dynamic_cast< OutlineViewShell* >( mpViewShell );
69 DBG_ASSERT( pOutlineViewShell, "sd::FuPresentationObjects::DoExecute(), does not work without an OutlineViewShell!");
70 if( !pOutlineViewShell )
71 return;
73 /* does the selections end in a unique presentation layout?
74 if not, it is not allowed to edit the templates */
75 SfxItemSet aSet(mpDoc->GetItemPool(), SID_STATUS_LAYOUT, SID_STATUS_LAYOUT);
76 pOutlineViewShell->GetStatusBarState( aSet );
77 String aLayoutName = (((SfxStringItem&)aSet.Get(SID_STATUS_LAYOUT)).GetValue());
78 DBG_ASSERT(aLayoutName.Len(), "Layout not defined");
80 sal_Bool bUnique = sal_False;
81 sal_Int16 nDepth, nTmp;
82 OutlineView* pOlView = static_cast<OutlineView*>(pOutlineViewShell->GetView());
83 OutlinerView* pOutlinerView = pOlView->GetViewByWindow( (Window*) mpWindow );
84 ::Outliner* pOutl = pOutlinerView->GetOutliner();
86 std::vector<Paragraph*> aSelList;
87 pOutlinerView->CreateSelectionList(aSelList);
89 std::vector<Paragraph*>::const_iterator iter = aSelList.begin();
90 Paragraph* pPara = aSelList.empty() ? NULL : *iter;
92 nDepth = pOutl->GetDepth(pOutl->GetAbsPos( pPara ) );
93 bool bPage = pOutl->HasParaFlag( pPara, PARAFLAG_ISPAGE );
95 while( iter != aSelList.end() )
97 pPara = *iter;
99 nTmp = pOutl->GetDepth( pOutl->GetAbsPos( pPara ) );
101 if( nDepth != nTmp )
103 bUnique = sal_False;
104 break;
107 if( pOutl->HasParaFlag( pPara, PARAFLAG_ISPAGE ) != bPage )
109 bUnique = sal_False;
110 break;
112 bUnique = sal_True;
113 ++iter;
116 if( bUnique )
118 OUString aStyleName = aLayoutName;
119 aStyleName += SD_LT_SEPARATOR ;
120 sal_uInt16 nDlgId = TAB_PRES_LAYOUT_TEMPLATE;
121 PresentationObjects ePO;
123 if( bPage )
125 ePO = PO_TITLE;
126 String aStr(SdResId( STR_LAYOUT_TITLE ));
127 aStyleName += aStr ;
129 else
131 ePO = (PresentationObjects) ( PO_OUTLINE_1 + nDepth - 1 );
132 String aStr(SdResId( STR_LAYOUT_OUTLINE ));
133 aStyleName += aStr ;
134 aStyleName += OUString(' ') ;
135 aStyleName += OUString::number( nDepth ) ;
138 SfxStyleSheetBasePool* pStyleSheetPool = mpDocSh->GetStyleSheetPool();
139 SfxStyleSheetBase* pStyleSheet = pStyleSheetPool->Find( aStyleName, SD_STYLE_FAMILY_MASTERPAGE );
140 DBG_ASSERT(pStyleSheet, "StyleSheet missing");
142 if( pStyleSheet )
144 SfxStyleSheetBase& rStyleSheet = *pStyleSheet;
146 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
147 SfxAbstractTabDialog* pDlg = pFact ? pFact->CreateSdPresLayoutTemplateDlg( mpDocSh, NULL, SdResId( nDlgId ), rStyleSheet, ePO, pStyleSheetPool ) : 0;
148 if( pDlg && (pDlg->Execute() == RET_OK) )
150 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
151 // Undo-Action
152 StyleSheetUndoAction* pAction = new StyleSheetUndoAction
153 (mpDoc, (SfxStyleSheet*)pStyleSheet,
154 pOutSet);
155 mpDocSh->GetUndoManager()->AddUndoAction(pAction);
157 pStyleSheet->GetItemSet().Put( *pOutSet );
158 ( (SfxStyleSheet*) pStyleSheet )->Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
160 delete( pDlg );
165 } // end of namespace sd
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */