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