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 :
21 : #include "fuprobjs.hxx"
22 :
23 : #include <vcl/msgbox.hxx>
24 : #include <svl/style.hxx>
25 : #include <editeng/outliner.hxx>
26 : #include <svl/smplhint.hxx>
27 :
28 :
29 : #include "app.hrc"
30 : #include "res_bmp.hrc"
31 : #include "strings.hrc"
32 : #include "glob.hrc"
33 : #include "prltempl.hrc"
34 :
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 {
45 :
46 0 : TYPEINIT1( FuPresentationObjects, FuPoor );
47 :
48 :
49 : /*************************************************************************
50 : |*
51 : |* Konstruktor
52 : |*
53 : \************************************************************************/
54 :
55 0 : FuPresentationObjects::FuPresentationObjects (
56 : ViewShell* pViewSh,
57 : ::sd::Window* pWin,
58 : ::sd::View* pView,
59 : SdDrawDocument* pDoc,
60 : SfxRequest& rReq)
61 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
62 : {
63 0 : }
64 :
65 0 : FunctionReference FuPresentationObjects::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
66 : {
67 0 : FunctionReference xFunc( new FuPresentationObjects( pViewSh, pWin, pView, pDoc, rReq ) );
68 0 : xFunc->DoExecute(rReq);
69 0 : return xFunc;
70 : }
71 :
72 0 : void FuPresentationObjects::DoExecute( SfxRequest& )
73 : {
74 0 : OutlineViewShell* pOutlineViewShell = dynamic_cast< OutlineViewShell* >( mpViewShell );
75 : DBG_ASSERT( pOutlineViewShell, "sd::FuPresentationObjects::DoExecute(), does not work without an OutlineViewShell!");
76 0 : if( !pOutlineViewShell )
77 0 : return;
78 :
79 : // ergibt die Selektion ein eindeutiges Praesentationslayout?
80 : // wenn nicht, duerfen die Vorlagen nicht bearbeitet werden
81 0 : SfxItemSet aSet(mpDoc->GetItemPool(), SID_STATUS_LAYOUT, SID_STATUS_LAYOUT);
82 0 : pOutlineViewShell->GetStatusBarState( aSet );
83 0 : String aLayoutName = (((SfxStringItem&)aSet.Get(SID_STATUS_LAYOUT)).GetValue());
84 : DBG_ASSERT(aLayoutName.Len(), "Layout unbestimmt");
85 :
86 0 : sal_Bool bUnique = sal_False;
87 : sal_Int16 nDepth, nTmp;
88 0 : OutlineView* pOlView = static_cast<OutlineView*>(pOutlineViewShell->GetView());
89 0 : OutlinerView* pOutlinerView = pOlView->GetViewByWindow( (Window*) mpWindow );
90 0 : ::Outliner* pOutl = pOutlinerView->GetOutliner();
91 :
92 0 : std::vector<Paragraph*> aSelList;
93 0 : pOutlinerView->CreateSelectionList(aSelList);
94 :
95 0 : std::vector<Paragraph*>::const_iterator iter = aSelList.begin();
96 0 : Paragraph* pPara = aSelList.empty() ? NULL : *iter;
97 :
98 0 : nDepth = pOutl->GetDepth((sal_uInt16)pOutl->GetAbsPos( pPara ) );
99 0 : bool bPage = pOutl->HasParaFlag( pPara, PARAFLAG_ISPAGE );
100 :
101 0 : while( iter != aSelList.end() )
102 : {
103 0 : pPara = *iter;
104 :
105 0 : nTmp = pOutl->GetDepth((sal_uInt16) pOutl->GetAbsPos( pPara ) );
106 :
107 0 : if( nDepth != nTmp )
108 : {
109 0 : bUnique = sal_False;
110 0 : break;
111 : }
112 :
113 0 : if( pOutl->HasParaFlag( pPara, PARAFLAG_ISPAGE ) != bPage )
114 : {
115 0 : bUnique = sal_False;
116 0 : break;
117 : }
118 0 : bUnique = sal_True;
119 0 : ++iter;
120 : }
121 :
122 0 : if( bUnique )
123 : {
124 0 : String aStyleName = aLayoutName;
125 0 : aStyleName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR ) );
126 0 : sal_uInt16 nDlgId = TAB_PRES_LAYOUT_TEMPLATE;
127 : PresentationObjects ePO;
128 :
129 0 : if( bPage )
130 : {
131 0 : ePO = PO_TITLE;
132 0 : String aStr(SdResId( STR_LAYOUT_TITLE ));
133 0 : aStyleName.Append( aStr );
134 : }
135 : else
136 : {
137 0 : ePO = (PresentationObjects) ( PO_OUTLINE_1 + nDepth - 1 );
138 0 : String aStr(SdResId( STR_LAYOUT_OUTLINE ));
139 0 : aStyleName.Append( aStr );
140 0 : aStyleName.Append( sal_Unicode(' ') );
141 0 : aStyleName.Append( UniString::CreateFromInt32( nDepth ) );
142 : }
143 :
144 0 : SfxStyleSheetBasePool* pStyleSheetPool = mpDocSh->GetStyleSheetPool();
145 0 : SfxStyleSheetBase* pStyleSheet = pStyleSheetPool->Find( aStyleName, SD_STYLE_FAMILY_MASTERPAGE );
146 : DBG_ASSERT(pStyleSheet, "StyleSheet nicht gefunden");
147 :
148 0 : if( pStyleSheet )
149 : {
150 0 : SfxStyleSheetBase& rStyleSheet = *pStyleSheet;
151 :
152 0 : SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
153 0 : SfxAbstractTabDialog* pDlg = pFact ? pFact->CreateSdPresLayoutTemplateDlg( mpDocSh, NULL, SdResId( nDlgId ), rStyleSheet, ePO, pStyleSheetPool ) : 0;
154 0 : if( pDlg && (pDlg->Execute() == RET_OK) )
155 : {
156 0 : const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
157 : // Undo-Action
158 : StyleSheetUndoAction* pAction = new StyleSheetUndoAction
159 : (mpDoc, (SfxStyleSheet*)pStyleSheet,
160 0 : pOutSet);
161 0 : mpDocSh->GetUndoManager()->AddUndoAction(pAction);
162 :
163 0 : pStyleSheet->GetItemSet().Put( *pOutSet );
164 0 : ( (SfxStyleSheet*) pStyleSheet )->Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
165 : }
166 0 : delete( pDlg );
167 0 : }
168 0 : }
169 : }
170 :
171 9 : } // end of namespace sd
172 :
173 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|