1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
30 #include "res_bmp.hrc"
31 #include "strings.hrc"
33 #include "prltempl.hrc"
35 #include "sdresid.hxx"
36 #include "drawdoc.hxx"
37 #include "OutlineViewShell.hxx"
38 #include "ViewShell.hxx"
41 #include "prlayout.hxx"
43 #include "sdabstdlg.hxx"
46 TYPEINIT1( FuPresentationObjects
, FuPoor
);
49 FuPresentationObjects::FuPresentationObjects (
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
);
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
)
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() )
99 nTmp
= pOutl
->GetDepth( pOutl
->GetAbsPos( pPara
) );
107 if( pOutl
->HasParaFlag( pPara
, PARAFLAG_ISPAGE
) != bPage
)
118 OUString aStyleName
= aLayoutName
;
119 aStyleName
+= SD_LT_SEPARATOR
;
120 sal_uInt16 nDlgId
= TAB_PRES_LAYOUT_TEMPLATE
;
121 PresentationObjects ePO
;
126 String
aStr(SdResId( STR_LAYOUT_TITLE
));
131 ePO
= (PresentationObjects
) ( PO_OUTLINE_1
+ nDepth
- 1 );
132 String
aStr(SdResId( STR_LAYOUT_OUTLINE
));
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");
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();
152 StyleSheetUndoAction
* pAction
= new StyleSheetUndoAction
153 (mpDoc
, (SfxStyleSheet
*)pStyleSheet
,
155 mpDocSh
->GetUndoManager()->AddUndoAction(pAction
);
157 pStyleSheet
->GetItemSet().Put( *pOutSet
);
158 ( (SfxStyleSheet
*) pStyleSheet
)->Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED
) );
165 } // end of namespace sd
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */