Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "fuprobjs.hxx"
21 :
22 : #include <vcl/msgbox.hxx>
23 : #include <svl/style.hxx>
24 : #include <editeng/outliner.hxx>
25 : #include <svl/smplhint.hxx>
26 :
27 : #include "app.hrc"
28 : #include "res_bmp.hrc"
29 : #include "strings.hrc"
30 : #include "glob.hrc"
31 : #include "prltempl.hrc"
32 :
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>
43 :
44 : namespace sd {
45 :
46 0 : TYPEINIT1( FuPresentationObjects, FuPoor );
47 :
48 0 : FuPresentationObjects::FuPresentationObjects (
49 : ViewShell* pViewSh,
50 : ::sd::Window* pWin,
51 : ::sd::View* pView,
52 : SdDrawDocument* pDoc,
53 : SfxRequest& rReq)
54 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
55 : {
56 0 : }
57 :
58 0 : rtl::Reference<FuPoor> FuPresentationObjects::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
59 : {
60 0 : rtl::Reference<FuPoor> xFunc( new FuPresentationObjects( pViewSh, pWin, pView, pDoc, rReq ) );
61 0 : xFunc->DoExecute(rReq);
62 0 : return xFunc;
63 : }
64 :
65 0 : void FuPresentationObjects::DoExecute( SfxRequest& )
66 : {
67 0 : OutlineViewShell* pOutlineViewShell = dynamic_cast< OutlineViewShell* >( mpViewShell );
68 : DBG_ASSERT( pOutlineViewShell, "sd::FuPresentationObjects::DoExecute(), does not work without an OutlineViewShell!");
69 0 : if( !pOutlineViewShell )
70 0 : return;
71 :
72 : /* does the selections end in a unique presentation layout?
73 : if not, it is not allowed to edit the templates */
74 0 : SfxItemSet aSet(mpDoc->GetItemPool(), SID_STATUS_LAYOUT, SID_STATUS_LAYOUT);
75 0 : pOutlineViewShell->GetStatusBarState( aSet );
76 0 : OUString aLayoutName = static_cast<const SfxStringItem&>(aSet.Get(SID_STATUS_LAYOUT)).GetValue();
77 : DBG_ASSERT(!aLayoutName.isEmpty(), "Layout not defined");
78 :
79 0 : bool bUnique = false;
80 : sal_Int16 nDepth, nTmp;
81 0 : OutlineView* pOlView = static_cast<OutlineView*>(pOutlineViewShell->GetView());
82 0 : OutlinerView* pOutlinerView = pOlView->GetViewByWindow( static_cast<Window*>(mpWindow) );
83 0 : ::Outliner* pOutl = pOutlinerView->GetOutliner();
84 :
85 0 : std::vector<Paragraph*> aSelList;
86 0 : pOutlinerView->CreateSelectionList(aSelList);
87 :
88 0 : std::vector<Paragraph*>::const_iterator iter = aSelList.begin();
89 0 : Paragraph* pPara = aSelList.empty() ? NULL : *iter;
90 :
91 0 : nDepth = pOutl->GetDepth(pOutl->GetAbsPos( pPara ) );
92 0 : bool bPage = ::Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE );
93 :
94 0 : while( iter != aSelList.end() )
95 : {
96 0 : pPara = *iter;
97 :
98 0 : nTmp = pOutl->GetDepth( pOutl->GetAbsPos( pPara ) );
99 :
100 0 : if( nDepth != nTmp )
101 : {
102 0 : bUnique = false;
103 0 : break;
104 : }
105 :
106 0 : if( ::Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) != bPage )
107 : {
108 0 : bUnique = false;
109 0 : break;
110 : }
111 0 : bUnique = true;
112 0 : ++iter;
113 : }
114 :
115 0 : if( bUnique )
116 : {
117 0 : OUString aStyleName = aLayoutName;
118 0 : aStyleName += SD_LT_SEPARATOR ;
119 0 : sal_uInt16 nDlgId = TAB_PRES_LAYOUT_TEMPLATE;
120 : PresentationObjects ePO;
121 :
122 0 : if( bPage )
123 : {
124 0 : ePO = PO_TITLE;
125 0 : aStyleName += SD_RESSTR(STR_LAYOUT_TITLE);
126 : }
127 : else
128 : {
129 0 : ePO = (PresentationObjects) ( PO_OUTLINE_1 + nDepth - 1 );
130 0 : aStyleName += SD_RESSTR(STR_LAYOUT_OUTLINE);
131 0 : aStyleName += OUString(' ') ;
132 0 : aStyleName += OUString::number( nDepth ) ;
133 : }
134 :
135 0 : SfxStyleSheetBasePool* pStyleSheetPool = mpDocSh->GetStyleSheetPool();
136 0 : SfxStyleSheetBase* pStyleSheet = pStyleSheetPool->Find( aStyleName, SD_STYLE_FAMILY_MASTERPAGE );
137 : DBG_ASSERT(pStyleSheet, "StyleSheet missing");
138 :
139 0 : if( pStyleSheet )
140 : {
141 0 : SfxStyleSheetBase& rStyleSheet = *pStyleSheet;
142 :
143 0 : SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
144 0 : boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact ? pFact->CreateSdPresLayoutTemplateDlg( mpDocSh, NULL, SdResId( nDlgId ), rStyleSheet, ePO, pStyleSheetPool ) : 0);
145 0 : if( pDlg && (pDlg->Execute() == RET_OK) )
146 : {
147 0 : const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
148 : // Undo-Action
149 : StyleSheetUndoAction* pAction = new StyleSheetUndoAction
150 0 : (mpDoc, static_cast<SfxStyleSheet*>(pStyleSheet), pOutSet);
151 0 : mpDocSh->GetUndoManager()->AddUndoAction(pAction);
152 :
153 0 : pStyleSheet->GetItemSet().Put( *pOutSet );
154 0 : static_cast<SfxStyleSheet*>( pStyleSheet )->Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
155 0 : }
156 0 : }
157 0 : }
158 : }
159 :
160 66 : } // end of namespace sd
161 :
162 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|