xref: /aoo41x/main/sd/source/ui/func/fusumry.cxx (revision 79aad27f)
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 
28 #include "fusumry.hxx"
29 #include <editeng/eeitem.hxx>
30 #include <svx/svdotext.hxx>
31 #include <svx/svdundo.hxx>
32 #include <sfx2/printer.hxx>
33 #include <editeng/outlobj.hxx>
34 
35 #include "strings.hrc"
36 
37 #include "pres.hxx"
38 #include "View.hxx"
39 #include "sdpage.hxx"
40 #include "Outliner.hxx"
41 #include "drawview.hxx"
42 #include "drawdoc.hxx"
43 #include "ViewShell.hxx"
44 #include "DrawDocShell.hxx"
45 #include "sdresid.hxx"
46 #include "optsitem.hxx"
47 #include "DrawViewShell.hxx"
48 
49 namespace sd {
50 
51 TYPEINIT1( FuSummaryPage, FuPoor );
52 
53 /*************************************************************************
54 |*
55 |* Konstruktor
56 |*
57 \************************************************************************/
FuSummaryPage(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)58 FuSummaryPage::FuSummaryPage (
59     ViewShell* pViewSh,
60     ::sd::Window* pWin,
61     ::sd::View* pView,
62     SdDrawDocument* pDoc,
63     SfxRequest& rReq)
64     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
65 {
66 }
67 
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)68 FunctionReference FuSummaryPage::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
69 {
70 	FunctionReference xFunc( new FuSummaryPage( pViewSh, pWin, pView, pDoc, rReq ) );
71 	xFunc->DoExecute(rReq);
72 	return xFunc;
73 }
74 
DoExecute(SfxRequest &)75 void FuSummaryPage::DoExecute( SfxRequest& )
76 {
77 	::sd::Outliner* pOutl = NULL;
78 	SdPage* pSummaryPage = NULL;
79 	sal_uInt16 i = 0;
80 	sal_uInt16 nFirstPage = SDRPAGE_NOTFOUND;
81 	sal_uInt16 nSelectedPages = 0;
82 	sal_uInt16 nCount = mpDoc->GetSdPageCount(PK_STANDARD);
83 
84 	while (i < nCount && nSelectedPages <= 1)
85 	{
86 		/**********************************************************************
87 		* Wieviele Seiten sind selektiert?
88 		* Genau eine Seite selektiert: Ab dieser Seite alles zusammenfassen
89 		* sonst: Nur die selektierten Seiten zusammenfassen
90 		**********************************************************************/
91 		SdPage* pActualPage = mpDoc->GetSdPage(i, PK_STANDARD);
92 
93 		if (pActualPage->IsSelected())
94 		{
95 			if (nFirstPage == SDRPAGE_NOTFOUND)
96 			{
97 				nFirstPage = i;
98 			}
99 
100 			nSelectedPages++;
101 		}
102 
103 		i++;
104 	}
105 
106 	bool bBegUndo = false;
107 
108 	SfxStyleSheet* pStyle = NULL;
109 
110 	for (i = nFirstPage; i < nCount; i++)
111 	{
112 		SdPage* pActualPage = mpDoc->GetSdPage(i, PK_STANDARD);
113 
114 		if (nSelectedPages <= 1 || pActualPage->IsSelected())
115 		{
116 			SdPage* pActualNotesPage = mpDoc->GetSdPage(i, PK_NOTES);
117 			SdrTextObj* pTextObj = (SdrTextObj*) pActualPage->GetPresObj(PRESOBJ_TITLE);
118 
119 			if (pTextObj && !pTextObj->IsEmptyPresObj())
120 			{
121 				if (!pSummaryPage)
122 				{
123 					/**********************************************************
124 					* Inhaltsverzeichnis-Seite einfuegen und Outliner anlegen
125 					**********************************************************/
126 					const bool bUndo = mpView->IsUndoEnabled();
127 
128 					if( bUndo )
129 					{
130 						mpView->BegUndo(String(SdResId(STR_UNDO_SUMMARY_PAGE)));
131 						bBegUndo = true;
132 					}
133 
134 					SetOfByte aVisibleLayers = pActualPage->TRG_GetMasterPageVisibleLayers();
135 
136 					// Seite mit Titel & Gliederung!
137 					pSummaryPage = (SdPage*) mpDoc->AllocPage(sal_False);
138 					pSummaryPage->SetSize(pActualPage->GetSize() );
139 					pSummaryPage->SetBorder(pActualPage->GetLftBorder(),
140 									 pActualPage->GetUppBorder(),
141 									 pActualPage->GetRgtBorder(),
142 									 pActualPage->GetLwrBorder() );
143 
144 					// Seite hinten einfuegen
145 					mpDoc->InsertPage(pSummaryPage, nCount * 2 + 1);
146 					if( bUndo )
147 						mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pSummaryPage));
148 
149 					// MasterPage der aktuellen Seite verwenden
150 					pSummaryPage->TRG_SetMasterPage(pActualPage->TRG_GetMasterPage());
151 					pSummaryPage->SetLayoutName(pActualPage->GetLayoutName());
152 					pSummaryPage->SetAutoLayout(AUTOLAYOUT_ENUM, sal_True);
153 					pSummaryPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
154 					pSummaryPage->setHeaderFooterSettings(pActualPage->getHeaderFooterSettings());
155 
156 					// Notiz-Seite
157 					SdPage* pNotesPage = (SdPage*) mpDoc->AllocPage(sal_False);
158 					pNotesPage->SetSize(pActualNotesPage->GetSize());
159 					pNotesPage->SetBorder(pActualNotesPage->GetLftBorder(),
160 										  pActualNotesPage->GetUppBorder(),
161 										  pActualNotesPage->GetRgtBorder(),
162 										  pActualNotesPage->GetLwrBorder() );
163 					pNotesPage->SetPageKind(PK_NOTES);
164 
165 					// Seite hinten einfuegen
166 					mpDoc->InsertPage(pNotesPage, nCount * 2 + 2);
167 
168 					if( bUndo )
169 						mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage));
170 
171 					// MasterPage der aktuellen Seite verwenden
172 					pNotesPage->TRG_SetMasterPage(pActualNotesPage->TRG_GetMasterPage());
173 					pNotesPage->SetLayoutName(pActualNotesPage->GetLayoutName());
174 					pNotesPage->SetAutoLayout(pActualNotesPage->GetAutoLayout(), sal_True);
175 					pNotesPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
176 					pNotesPage->setHeaderFooterSettings(pActualNotesPage->getHeaderFooterSettings());
177 
178 					pOutl = new ::sd::Outliner( mpDoc, OUTLINERMODE_OUTLINEOBJECT );
179 					pOutl->SetUpdateMode(sal_False);
180 					pOutl->EnableUndo(sal_False);
181 
182 					if (mpDocSh)
183 						pOutl->SetRefDevice(SD_MOD()->GetRefDevice( *mpDocSh ));
184 
185 					pOutl->SetDefTab( mpDoc->GetDefaultTabulator() );
186 					pOutl->SetStyleSheetPool((SfxStyleSheetPool*) mpDoc->GetStyleSheetPool());
187 					pStyle = pSummaryPage->GetStyleSheetForPresObj( PRESOBJ_OUTLINE );
188 					pOutl->SetStyleSheet( 0, pStyle );
189 				}
190 
191 				/**************************************************************
192 				* Text hinzufuegen
193 				**************************************************************/
194 				OutlinerParaObject* pParaObj = pTextObj->GetOutlinerParaObject();
195 				// #118876#, check if the OutlinerParaObject is created successfully
196 				if( pParaObj )
197 				{
198 					pParaObj->SetOutlinerMode( OUTLINERMODE_OUTLINEOBJECT );
199 					pOutl->AddText(*pParaObj);
200 				}
201 			}
202 		}
203 	}
204 
205 	if (pSummaryPage)
206 	{
207 		SdrTextObj* pTextObj = (SdrTextObj*) pSummaryPage->GetPresObj(PRESOBJ_OUTLINE);
208 
209 		// Harte Absatz- und Zeichenattribute entfernen
210 		SfxItemSet aEmptyEEAttr(mpDoc->GetPool(), EE_ITEMS_START, EE_ITEMS_END);
211 		sal_uLong nParaCount = pOutl->GetParagraphCount();
212 
213 		for (sal_uInt16 nPara = 0; nPara < nParaCount; nPara++)
214 		{
215 			pOutl->SetStyleSheet( nPara, pStyle );
216 			pOutl->QuickRemoveCharAttribs(nPara);
217 			pOutl->SetParaAttribs(nPara, aEmptyEEAttr);
218 			pOutl->SetDepth(pOutl->GetParagraph(nPara), 0);
219 		}
220 
221 		pTextObj->SetOutlinerParaObject( pOutl->CreateParaObject() );
222 		pTextObj->SetEmptyPresObj(sal_False);
223 
224 		// Harte Attribute entfernen (Flag auf sal_True)
225 		SfxItemSet aAttr(mpDoc->GetPool());
226 		aAttr.Put(XLineStyleItem(XLINE_NONE));
227 		aAttr.Put(XFillStyleItem(XFILL_NONE));
228 		pTextObj->SetMergedItemSet(aAttr);
229 
230 		if( bBegUndo )
231 			mpView->EndUndo();
232 		delete pOutl;
233 
234 		DrawViewShell* pDrawViewShell= dynamic_cast< DrawViewShell* >( mpViewShell );
235 		if(pDrawViewShell)
236 		{
237 			pDrawViewShell->SwitchPage( (pSummaryPage->GetPageNum() - 1) / 2);
238 		}
239 	}
240 }
241 
242 
243 } // end of namespace sd
244