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