xref: /aoo41x/main/sd/source/ui/func/fuprobjs.cxx (revision 79aad27f)
1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "fuprobjs.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifndef _MSGBOX_HXX //autogen
30cdf0e10cSrcweir #include <vcl/msgbox.hxx>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #include <svl/style.hxx>
33cdf0e10cSrcweir #include <editeng/outliner.hxx>
34cdf0e10cSrcweir #include <svl/smplhint.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include "app.hrc"
38cdf0e10cSrcweir #include "res_bmp.hrc"
39cdf0e10cSrcweir #include "strings.hrc"
40cdf0e10cSrcweir #include "glob.hrc"
41cdf0e10cSrcweir #include "prltempl.hrc"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include "sdresid.hxx"
44cdf0e10cSrcweir #include "drawdoc.hxx"
45cdf0e10cSrcweir #ifndef SD_OUTLINE_VIEW_SHELL_HX
46cdf0e10cSrcweir #include "OutlineViewShell.hxx"
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #include "ViewShell.hxx"
49cdf0e10cSrcweir #include "Window.hxx"
50cdf0e10cSrcweir #include "glob.hxx"
51cdf0e10cSrcweir #include "prlayout.hxx"
52cdf0e10cSrcweir #include "unchss.hxx"
53cdf0e10cSrcweir #include "sdabstdlg.hxx"
54cdf0e10cSrcweir namespace sd {
55cdf0e10cSrcweir 
56cdf0e10cSrcweir TYPEINIT1( FuPresentationObjects, FuPoor );
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
59cdf0e10cSrcweir /*************************************************************************
60cdf0e10cSrcweir |*
61cdf0e10cSrcweir |* Konstruktor
62cdf0e10cSrcweir |*
63cdf0e10cSrcweir \************************************************************************/
64cdf0e10cSrcweir 
FuPresentationObjects(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)65cdf0e10cSrcweir FuPresentationObjects::FuPresentationObjects (
66cdf0e10cSrcweir     ViewShell* pViewSh,
67cdf0e10cSrcweir     ::sd::Window* pWin,
68cdf0e10cSrcweir     ::sd::View* pView,
69cdf0e10cSrcweir     SdDrawDocument* pDoc,
70cdf0e10cSrcweir     SfxRequest& rReq)
71cdf0e10cSrcweir 	 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
72cdf0e10cSrcweir {
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)75cdf0e10cSrcweir FunctionReference FuPresentationObjects::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	FunctionReference xFunc( new FuPresentationObjects( pViewSh, pWin, pView, pDoc, rReq ) );
78cdf0e10cSrcweir 	xFunc->DoExecute(rReq);
79cdf0e10cSrcweir 	return xFunc;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
DoExecute(SfxRequest &)82cdf0e10cSrcweir void FuPresentationObjects::DoExecute( SfxRequest& )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	OutlineViewShell* pOutlineViewShell = dynamic_cast< OutlineViewShell* >( mpViewShell );
85cdf0e10cSrcweir 	DBG_ASSERT( pOutlineViewShell, "sd::FuPresentationObjects::DoExecute(), does not work without an OutlineViewShell!");
86cdf0e10cSrcweir 	if( !pOutlineViewShell )
87cdf0e10cSrcweir 		return;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	// ergibt die Selektion ein eindeutiges Praesentationslayout?
90cdf0e10cSrcweir 	// wenn nicht, duerfen die Vorlagen nicht bearbeitet werden
91cdf0e10cSrcweir 	SfxItemSet aSet(mpDoc->GetItemPool(), SID_STATUS_LAYOUT, SID_STATUS_LAYOUT);
92cdf0e10cSrcweir 	pOutlineViewShell->GetStatusBarState( aSet );
93cdf0e10cSrcweir 	String aLayoutName = (((SfxStringItem&)aSet.Get(SID_STATUS_LAYOUT)).GetValue());
94cdf0e10cSrcweir 	DBG_ASSERT(aLayoutName.Len(), "Layout unbestimmt");
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	sal_Bool	bUnique = sal_False;
97cdf0e10cSrcweir 	sal_Int16	nDepth, nTmp;
98cdf0e10cSrcweir 	OutlineView* pOlView = static_cast<OutlineView*>(pOutlineViewShell->GetView());
99cdf0e10cSrcweir 	OutlinerView* pOutlinerView = pOlView->GetViewByWindow( (Window*) mpWindow );
100cdf0e10cSrcweir 	::Outliner* pOutl = pOutlinerView->GetOutliner();
101cdf0e10cSrcweir 	List* pList = pOutlinerView->CreateSelectionList();
102cdf0e10cSrcweir 	Paragraph* pPara = (Paragraph*)pList->First();
103cdf0e10cSrcweir 	nDepth = pOutl->GetDepth((sal_uInt16)pOutl->GetAbsPos( pPara ) );
104cdf0e10cSrcweir 	bool bPage = pOutl->HasParaFlag( pPara, PARAFLAG_ISPAGE );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	while( pPara )
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		nTmp = pOutl->GetDepth((sal_uInt16) pOutl->GetAbsPos( pPara ) );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 		if( nDepth != nTmp )
111cdf0e10cSrcweir 		{
112cdf0e10cSrcweir 			bUnique = sal_False;
113cdf0e10cSrcweir 			break;
114cdf0e10cSrcweir 		}
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		if( pOutl->HasParaFlag( pPara, PARAFLAG_ISPAGE ) != bPage )
117cdf0e10cSrcweir 		{
118cdf0e10cSrcweir 			bUnique = sal_False;
119cdf0e10cSrcweir 			break;
120cdf0e10cSrcweir 		}
121cdf0e10cSrcweir 		bUnique = sal_True;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 		pPara = (Paragraph*) pList->Next();
124cdf0e10cSrcweir 	}
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	if( bUnique )
127cdf0e10cSrcweir 	{
128cdf0e10cSrcweir 		String aStyleName = aLayoutName;
129cdf0e10cSrcweir 		aStyleName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR ) );
130cdf0e10cSrcweir 		sal_uInt16 nDlgId = TAB_PRES_LAYOUT_TEMPLATE;
131cdf0e10cSrcweir 		PresentationObjects	ePO;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 		if( bPage )
134cdf0e10cSrcweir 		{
135cdf0e10cSrcweir 			ePO = PO_TITLE;
136cdf0e10cSrcweir 			String aStr(SdResId( STR_LAYOUT_TITLE ));
137cdf0e10cSrcweir 			aStyleName.Append( aStr );
138cdf0e10cSrcweir 		}
139cdf0e10cSrcweir 		else
140cdf0e10cSrcweir 		{
141cdf0e10cSrcweir 			ePO = (PresentationObjects) ( PO_OUTLINE_1 + nDepth - 1 );
142cdf0e10cSrcweir 			String aStr(SdResId( STR_LAYOUT_OUTLINE ));
143cdf0e10cSrcweir 			aStyleName.Append( aStr );
144cdf0e10cSrcweir 			aStyleName.Append( sal_Unicode(' ') );
145cdf0e10cSrcweir 			aStyleName.Append( UniString::CreateFromInt32( nDepth ) );
146cdf0e10cSrcweir 		}
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 		SfxStyleSheetBasePool* pStyleSheetPool = mpDocSh->GetStyleSheetPool();
149cdf0e10cSrcweir 		SfxStyleSheetBase* pStyleSheet = pStyleSheetPool->Find( aStyleName, SD_STYLE_FAMILY_MASTERPAGE );
150cdf0e10cSrcweir 		DBG_ASSERT(pStyleSheet, "StyleSheet nicht gefunden");
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 		if( pStyleSheet )
153cdf0e10cSrcweir 		{
154cdf0e10cSrcweir 			SfxStyleSheetBase& rStyleSheet = *pStyleSheet;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 			SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
157cdf0e10cSrcweir 			SfxAbstractTabDialog* pDlg = pFact ? pFact->CreateSdPresLayoutTemplateDlg( mpDocSh, NULL, SdResId( nDlgId ), rStyleSheet, ePO, pStyleSheetPool ) : 0;
158cdf0e10cSrcweir 			if( pDlg && (pDlg->Execute() == RET_OK) )
159cdf0e10cSrcweir 			{
160cdf0e10cSrcweir 				const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
161cdf0e10cSrcweir 				// Undo-Action
162cdf0e10cSrcweir 				StyleSheetUndoAction* pAction = new StyleSheetUndoAction
163cdf0e10cSrcweir 												(mpDoc, (SfxStyleSheet*)pStyleSheet,
164cdf0e10cSrcweir 													pOutSet);
165cdf0e10cSrcweir 				mpDocSh->GetUndoManager()->AddUndoAction(pAction);
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 				pStyleSheet->GetItemSet().Put( *pOutSet );
168cdf0e10cSrcweir 				( (SfxStyleSheet*) pStyleSheet )->Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
169cdf0e10cSrcweir 			}
170cdf0e10cSrcweir 			delete( pDlg );
171cdf0e10cSrcweir 		}
172cdf0e10cSrcweir 	}
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir } // end of namespace sd
176