xref: /trunk/main/sd/source/ui/func/fuprobjs.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "fuprobjs.hxx"
32 
33 #ifndef _MSGBOX_HXX //autogen
34 #include <vcl/msgbox.hxx>
35 #endif
36 #include <svl/style.hxx>
37 #include <editeng/outliner.hxx>
38 #include <svl/smplhint.hxx>
39 
40 
41 #include "app.hrc"
42 #include "res_bmp.hrc"
43 #include "strings.hrc"
44 #include "glob.hrc"
45 #include "prltempl.hrc"
46 
47 #include "sdresid.hxx"
48 #include "drawdoc.hxx"
49 #ifndef SD_OUTLINE_VIEW_SHELL_HX
50 #include "OutlineViewShell.hxx"
51 #endif
52 #include "ViewShell.hxx"
53 #include "Window.hxx"
54 #include "glob.hxx"
55 #include "prlayout.hxx"
56 #include "unchss.hxx"
57 #include "sdabstdlg.hxx"
58 namespace sd {
59 
60 TYPEINIT1( FuPresentationObjects, FuPoor );
61 
62 
63 /*************************************************************************
64 |*
65 |* Konstruktor
66 |*
67 \************************************************************************/
68 
69 FuPresentationObjects::FuPresentationObjects (
70     ViewShell* pViewSh,
71     ::sd::Window* pWin,
72     ::sd::View* pView,
73     SdDrawDocument* pDoc,
74     SfxRequest& rReq)
75      : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
76 {
77 }
78 
79 FunctionReference FuPresentationObjects::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
80 {
81     FunctionReference xFunc( new FuPresentationObjects( pViewSh, pWin, pView, pDoc, rReq ) );
82     xFunc->DoExecute(rReq);
83     return xFunc;
84 }
85 
86 void FuPresentationObjects::DoExecute( SfxRequest& )
87 {
88     OutlineViewShell* pOutlineViewShell = dynamic_cast< OutlineViewShell* >( mpViewShell );
89     DBG_ASSERT( pOutlineViewShell, "sd::FuPresentationObjects::DoExecute(), does not work without an OutlineViewShell!");
90     if( !pOutlineViewShell )
91         return;
92 
93     // ergibt die Selektion ein eindeutiges Praesentationslayout?
94     // wenn nicht, duerfen die Vorlagen nicht bearbeitet werden
95     SfxItemSet aSet(mpDoc->GetItemPool(), SID_STATUS_LAYOUT, SID_STATUS_LAYOUT);
96     pOutlineViewShell->GetStatusBarState( aSet );
97     String aLayoutName = (((SfxStringItem&)aSet.Get(SID_STATUS_LAYOUT)).GetValue());
98     DBG_ASSERT(aLayoutName.Len(), "Layout unbestimmt");
99 
100     sal_Bool    bUnique = sal_False;
101     sal_Int16   nDepth, nTmp;
102     OutlineView* pOlView = static_cast<OutlineView*>(pOutlineViewShell->GetView());
103     OutlinerView* pOutlinerView = pOlView->GetViewByWindow( (Window*) mpWindow );
104     ::Outliner* pOutl = pOutlinerView->GetOutliner();
105     List* pList = pOutlinerView->CreateSelectionList();
106     Paragraph* pPara = (Paragraph*)pList->First();
107     nDepth = pOutl->GetDepth((sal_uInt16)pOutl->GetAbsPos( pPara ) );
108     bool bPage = pOutl->HasParaFlag( pPara, PARAFLAG_ISPAGE );
109 
110     while( pPara )
111     {
112         nTmp = pOutl->GetDepth((sal_uInt16) pOutl->GetAbsPos( pPara ) );
113 
114         if( nDepth != nTmp )
115         {
116             bUnique = sal_False;
117             break;
118         }
119 
120         if( pOutl->HasParaFlag( pPara, PARAFLAG_ISPAGE ) != bPage )
121         {
122             bUnique = sal_False;
123             break;
124         }
125         bUnique = sal_True;
126 
127         pPara = (Paragraph*) pList->Next();
128     }
129 
130     if( bUnique )
131     {
132         String aStyleName = aLayoutName;
133         aStyleName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR ) );
134         sal_uInt16 nDlgId = TAB_PRES_LAYOUT_TEMPLATE;
135         PresentationObjects ePO;
136 
137         if( bPage )
138         {
139             ePO = PO_TITLE;
140             String aStr(SdResId( STR_LAYOUT_TITLE ));
141             aStyleName.Append( aStr );
142         }
143         else
144         {
145             ePO = (PresentationObjects) ( PO_OUTLINE_1 + nDepth - 1 );
146             String aStr(SdResId( STR_LAYOUT_OUTLINE ));
147             aStyleName.Append( aStr );
148             aStyleName.Append( sal_Unicode(' ') );
149             aStyleName.Append( UniString::CreateFromInt32( nDepth ) );
150         }
151 
152         SfxStyleSheetBasePool* pStyleSheetPool = mpDocSh->GetStyleSheetPool();
153         SfxStyleSheetBase* pStyleSheet = pStyleSheetPool->Find( aStyleName, SD_STYLE_FAMILY_MASTERPAGE );
154         DBG_ASSERT(pStyleSheet, "StyleSheet nicht gefunden");
155 
156         if( pStyleSheet )
157         {
158             SfxStyleSheetBase& rStyleSheet = *pStyleSheet;
159 
160             SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
161             SfxAbstractTabDialog* pDlg = pFact ? pFact->CreateSdPresLayoutTemplateDlg( mpDocSh, NULL, SdResId( nDlgId ), rStyleSheet, ePO, pStyleSheetPool ) : 0;
162             if( pDlg && (pDlg->Execute() == RET_OK) )
163             {
164                 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
165                 // Undo-Action
166                 StyleSheetUndoAction* pAction = new StyleSheetUndoAction
167                                                 (mpDoc, (SfxStyleSheet*)pStyleSheet,
168                                                     pOutSet);
169                 mpDocSh->GetUndoManager()->AddUndoAction(pAction);
170 
171                 pStyleSheet->GetItemSet().Put( *pOutSet );
172                 ( (SfxStyleSheet*) pStyleSheet )->Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
173             }
174             delete( pDlg );
175         }
176     }
177 }
178 
179 } // end of namespace sd
180