xref: /aoo41x/main/sd/source/ui/func/fusumry.cxx (revision cdf0e10c)
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 
32 #include "fusumry.hxx"
33 #include <editeng/eeitem.hxx>
34 #include <svx/svdotext.hxx>
35 #include <svx/svdundo.hxx>
36 #include <sfx2/printer.hxx>
37 #include <editeng/outlobj.hxx>
38 
39 #include "strings.hrc"
40 
41 #include "pres.hxx"
42 #include "View.hxx"
43 #include "sdpage.hxx"
44 #include "Outliner.hxx"
45 #include "drawview.hxx"
46 #include "drawdoc.hxx"
47 #include "ViewShell.hxx"
48 #include "DrawDocShell.hxx"
49 #include "sdresid.hxx"
50 #include "optsitem.hxx"
51 #include "DrawViewShell.hxx"
52 
53 namespace sd {
54 
55 TYPEINIT1( FuSummaryPage, FuPoor );
56 
57 /*************************************************************************
58 |*
59 |* Konstruktor
60 |*
61 \************************************************************************/
62 FuSummaryPage::FuSummaryPage (
63     ViewShell* pViewSh,
64     ::sd::Window* pWin,
65     ::sd::View* pView,
66     SdDrawDocument* pDoc,
67     SfxRequest& rReq)
68     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
69 {
70 }
71 
72 FunctionReference FuSummaryPage::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
73 {
74 	FunctionReference xFunc( new FuSummaryPage( pViewSh, pWin, pView, pDoc, rReq ) );
75 	xFunc->DoExecute(rReq);
76 	return xFunc;
77 }
78 
79 void FuSummaryPage::DoExecute( SfxRequest& )
80 {
81 	::sd::Outliner* pOutl = NULL;
82 	SdPage* pSummaryPage = NULL;
83 	sal_uInt16 i = 0;
84 	sal_uInt16 nFirstPage = SDRPAGE_NOTFOUND;
85 	sal_uInt16 nSelectedPages = 0;
86 	sal_uInt16 nCount = mpDoc->GetSdPageCount(PK_STANDARD);
87 
88 	while (i < nCount && nSelectedPages <= 1)
89 	{
90 		/**********************************************************************
91 		* Wieviele Seiten sind selektiert?
92 		* Genau eine Seite selektiert: Ab dieser Seite alles zusammenfassen
93 		* sonst: Nur die selektierten Seiten zusammenfassen
94 		**********************************************************************/
95 		SdPage* pActualPage = mpDoc->GetSdPage(i, PK_STANDARD);
96 
97 		if (pActualPage->IsSelected())
98 		{
99 			if (nFirstPage == SDRPAGE_NOTFOUND)
100 			{
101 				nFirstPage = i;
102 			}
103 
104 			nSelectedPages++;
105 		}
106 
107 		i++;
108 	}
109 
110 	bool bBegUndo = false;
111 
112 	SfxStyleSheet* pStyle = NULL;
113 
114 	for (i = nFirstPage; i < nCount; i++)
115 	{
116 		SdPage* pActualPage = mpDoc->GetSdPage(i, PK_STANDARD);
117 
118 		if (nSelectedPages <= 1 || pActualPage->IsSelected())
119 		{
120 			SdPage* pActualNotesPage = mpDoc->GetSdPage(i, PK_NOTES);
121 			SdrTextObj* pTextObj = (SdrTextObj*) pActualPage->GetPresObj(PRESOBJ_TITLE);
122 
123 			if (pTextObj && !pTextObj->IsEmptyPresObj())
124 			{
125 				if (!pSummaryPage)
126 				{
127 					/**********************************************************
128 					* Inhaltsverzeichnis-Seite einfuegen und Outliner anlegen
129 					**********************************************************/
130 					const bool bUndo = mpView->IsUndoEnabled();
131 
132 					if( bUndo )
133 					{
134 						mpView->BegUndo(String(SdResId(STR_UNDO_SUMMARY_PAGE)));
135 						bBegUndo = true;
136 					}
137 
138 					SetOfByte aVisibleLayers = pActualPage->TRG_GetMasterPageVisibleLayers();
139 
140 					// Seite mit Titel & Gliederung!
141 					pSummaryPage = (SdPage*) mpDoc->AllocPage(sal_False);
142 					pSummaryPage->SetSize(pActualPage->GetSize() );
143 					pSummaryPage->SetBorder(pActualPage->GetLftBorder(),
144 									 pActualPage->GetUppBorder(),
145 									 pActualPage->GetRgtBorder(),
146 									 pActualPage->GetLwrBorder() );
147 
148 					// Seite hinten einfuegen
149 					mpDoc->InsertPage(pSummaryPage, nCount * 2 + 1);
150 					if( bUndo )
151 						mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pSummaryPage));
152 
153 					// MasterPage der aktuellen Seite verwenden
154 					pSummaryPage->TRG_SetMasterPage(pActualPage->TRG_GetMasterPage());
155 					pSummaryPage->SetLayoutName(pActualPage->GetLayoutName());
156 					pSummaryPage->SetAutoLayout(AUTOLAYOUT_ENUM, sal_True);
157 					pSummaryPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
158 					pSummaryPage->setHeaderFooterSettings(pActualPage->getHeaderFooterSettings());
159 
160 					// Notiz-Seite
161 					SdPage* pNotesPage = (SdPage*) mpDoc->AllocPage(sal_False);
162 					pNotesPage->SetSize(pActualNotesPage->GetSize());
163 					pNotesPage->SetBorder(pActualNotesPage->GetLftBorder(),
164 										  pActualNotesPage->GetUppBorder(),
165 										  pActualNotesPage->GetRgtBorder(),
166 										  pActualNotesPage->GetLwrBorder() );
167 					pNotesPage->SetPageKind(PK_NOTES);
168 
169 					// Seite hinten einfuegen
170 					mpDoc->InsertPage(pNotesPage, nCount * 2 + 2);
171 
172 					if( bUndo )
173 						mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage));
174 
175 					// MasterPage der aktuellen Seite verwenden
176 					pNotesPage->TRG_SetMasterPage(pActualNotesPage->TRG_GetMasterPage());
177 					pNotesPage->SetLayoutName(pActualNotesPage->GetLayoutName());
178 					pNotesPage->SetAutoLayout(pActualNotesPage->GetAutoLayout(), sal_True);
179 					pNotesPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
180 					pNotesPage->setHeaderFooterSettings(pActualNotesPage->getHeaderFooterSettings());
181 
182 					pOutl = new ::sd::Outliner( mpDoc, OUTLINERMODE_OUTLINEOBJECT );
183 					pOutl->SetUpdateMode(sal_False);
184 					pOutl->EnableUndo(sal_False);
185 
186 					if (mpDocSh)
187 						pOutl->SetRefDevice(SD_MOD()->GetRefDevice( *mpDocSh ));
188 
189 					pOutl->SetDefTab( mpDoc->GetDefaultTabulator() );
190 					pOutl->SetStyleSheetPool((SfxStyleSheetPool*) mpDoc->GetStyleSheetPool());
191 					pStyle = pSummaryPage->GetStyleSheetForPresObj( PRESOBJ_OUTLINE );
192 					pOutl->SetStyleSheet( 0, pStyle );
193 				}
194 
195 				/**************************************************************
196 				* Text hinzufuegen
197 				**************************************************************/
198 				OutlinerParaObject* pParaObj = pTextObj->GetOutlinerParaObject();
199 				pParaObj->SetOutlinerMode( OUTLINERMODE_OUTLINEOBJECT );
200 				pOutl->AddText(*pParaObj);
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