xref: /aoo41x/main/sd/source/ui/func/fuexpand.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "fuexpand.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
35*cdf0e10cSrcweir #include <svx/svdotext.hxx>
36*cdf0e10cSrcweir #include <svx/xlineit0.hxx>
37*cdf0e10cSrcweir #include <svx/svdundo.hxx>
38*cdf0e10cSrcweir #include <sfx2/printer.hxx>
39*cdf0e10cSrcweir #include <editeng/outlobj.hxx>
40*cdf0e10cSrcweir #include <svx/svdetc.hxx>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include "app.hrc"
43*cdf0e10cSrcweir #include "strings.hrc"
44*cdf0e10cSrcweir #include "pres.hxx"
45*cdf0e10cSrcweir #include "View.hxx"
46*cdf0e10cSrcweir #include "sdpage.hxx"
47*cdf0e10cSrcweir #include "Outliner.hxx"
48*cdf0e10cSrcweir #include "drawview.hxx"
49*cdf0e10cSrcweir #include "drawdoc.hxx"
50*cdf0e10cSrcweir #include "ViewShell.hxx"
51*cdf0e10cSrcweir #include "DrawDocShell.hxx"
52*cdf0e10cSrcweir #include "sdresid.hxx"
53*cdf0e10cSrcweir #include "optsitem.hxx"
54*cdf0e10cSrcweir #include "sdmod.hxx"
55*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
56*cdf0e10cSrcweir #include <editeng/eeitem.hxx>
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir namespace sd {
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir TYPEINIT1( FuExpandPage, FuPoor );
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir /*************************************************************************
63*cdf0e10cSrcweir |*
64*cdf0e10cSrcweir |* Konstruktor
65*cdf0e10cSrcweir |*
66*cdf0e10cSrcweir \************************************************************************/
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir FuExpandPage::FuExpandPage (
69*cdf0e10cSrcweir     ViewShell* pViewSh,
70*cdf0e10cSrcweir     ::sd::Window* pWin,
71*cdf0e10cSrcweir     ::sd::View* pView,
72*cdf0e10cSrcweir     SdDrawDocument* pDoc,
73*cdf0e10cSrcweir     SfxRequest& rReq)
74*cdf0e10cSrcweir     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir FunctionReference FuExpandPage::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	FunctionReference xFunc( new FuExpandPage( pViewSh, pWin, pView, pDoc, rReq ) );
81*cdf0e10cSrcweir 	xFunc->DoExecute(rReq);
82*cdf0e10cSrcweir 	return xFunc;
83*cdf0e10cSrcweir }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir void FuExpandPage::DoExecute( SfxRequest& )
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir 	if ( mpView && mpView->IsTextEdit() )
88*cdf0e10cSrcweir 		mpView->SdrEndTextEdit();
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	// Selektierte Seite finden (nur Standard-Seiten)
91*cdf0e10cSrcweir 	SdPage* pActualPage = NULL;
92*cdf0e10cSrcweir 	sal_uInt16 i = 0;
93*cdf0e10cSrcweir 	sal_uInt16 nCount = mpDoc->GetSdPageCount(PK_STANDARD);
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	while (!pActualPage && i < nCount)
96*cdf0e10cSrcweir 	{
97*cdf0e10cSrcweir 		if (mpDoc->GetSdPage(i, PK_STANDARD)->IsSelected())
98*cdf0e10cSrcweir 		{
99*cdf0e10cSrcweir 			pActualPage = mpDoc->GetSdPage(i, PK_STANDARD);
100*cdf0e10cSrcweir 		}
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 		i++;
103*cdf0e10cSrcweir 	}
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	if (pActualPage)
106*cdf0e10cSrcweir 	{
107*cdf0e10cSrcweir 		::sd::Outliner* pOutl =
108*cdf0e10cSrcweir               new ::sd::Outliner( mpDoc, OUTLINERMODE_OUTLINEOBJECT );
109*cdf0e10cSrcweir 		pOutl->SetUpdateMode(sal_False);
110*cdf0e10cSrcweir 		pOutl->EnableUndo(sal_False);
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 		if (mpDocSh)
113*cdf0e10cSrcweir 			pOutl->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 		pOutl->SetDefTab( mpDoc->GetDefaultTabulator() );
116*cdf0e10cSrcweir 		pOutl->SetStyleSheetPool((SfxStyleSheetPool*) mpDoc->GetStyleSheetPool());
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 		SetOfByte aVisibleLayers = pActualPage->TRG_GetMasterPageVisibleLayers();
119*cdf0e10cSrcweir 		sal_uInt16 nActualPageNum = pActualPage->GetPageNum();
120*cdf0e10cSrcweir 		SdPage* pActualNotesPage = (SdPage*) mpDoc->GetPage(nActualPageNum + 1);
121*cdf0e10cSrcweir 		SdrTextObj* pActualOutline = (SdrTextObj*) pActualPage->GetPresObj(PRESOBJ_OUTLINE);
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 		if (pActualOutline)
124*cdf0e10cSrcweir 		{
125*cdf0e10cSrcweir 			const bool bUndo = mpView->IsUndoEnabled();
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 			if( bUndo )
128*cdf0e10cSrcweir 				mpView->BegUndo(String(SdResId(STR_UNDO_EXPAND_PAGE)));
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 			// Aktuelles Gliederungsobjekt in Outliner setzen
131*cdf0e10cSrcweir 			OutlinerParaObject* pParaObj = pActualOutline->GetOutlinerParaObject();
132*cdf0e10cSrcweir 			pOutl->SetText(*pParaObj);
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 			// Harte Absatz- und Zeichenattribute entfernen
135*cdf0e10cSrcweir 			SfxItemSet aEmptyEEAttr(mpDoc->GetPool(), EE_ITEMS_START, EE_ITEMS_END);
136*cdf0e10cSrcweir 			sal_uLong nParaCount1 = pOutl->GetParagraphCount();
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 			for (sal_uInt16 nPara = 0; nPara < nParaCount1; nPara++)
139*cdf0e10cSrcweir 			{
140*cdf0e10cSrcweir 				pOutl->QuickRemoveCharAttribs(nPara);
141*cdf0e10cSrcweir 				pOutl->SetParaAttribs(nPara, aEmptyEEAttr);
142*cdf0e10cSrcweir 			}
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 			sal_uInt16 nPos = 2;
145*cdf0e10cSrcweir 			Paragraph* pPara = pOutl->GetParagraph( 0 );
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 			while (pPara)
148*cdf0e10cSrcweir 			{
149*cdf0e10cSrcweir 				sal_uLong nParaPos = pOutl->GetAbsPos( pPara );
150*cdf0e10cSrcweir 				sal_Int16 nDepth = pOutl->GetDepth( (sal_uInt16) nParaPos );
151*cdf0e10cSrcweir 				if ( nDepth == 0 )
152*cdf0e10cSrcweir 				{
153*cdf0e10cSrcweir 					// Seite mit Titel & Gliederung!
154*cdf0e10cSrcweir 					SdPage* pPage = (SdPage*) mpDoc->AllocPage(sal_False);
155*cdf0e10cSrcweir 					pPage->SetSize(pActualPage->GetSize() );
156*cdf0e10cSrcweir 					pPage->SetBorder(pActualPage->GetLftBorder(),
157*cdf0e10cSrcweir 									 pActualPage->GetUppBorder(),
158*cdf0e10cSrcweir 									 pActualPage->GetRgtBorder(),
159*cdf0e10cSrcweir 									 pActualPage->GetLwrBorder() );
160*cdf0e10cSrcweir 					pPage->SetName(String());
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 					// Seite hinter aktueller Seite einfuegen
163*cdf0e10cSrcweir 					mpDoc->InsertPage(pPage, nActualPageNum + nPos);
164*cdf0e10cSrcweir 					nPos++;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 					if( bUndo )
167*cdf0e10cSrcweir 						mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pPage));
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 					// MasterPage der aktuellen Seite verwenden
170*cdf0e10cSrcweir 					pPage->TRG_SetMasterPage(pActualPage->TRG_GetMasterPage());
171*cdf0e10cSrcweir 					pPage->SetLayoutName(pActualPage->GetLayoutName());
172*cdf0e10cSrcweir 					pPage->SetAutoLayout(AUTOLAYOUT_ENUM, sal_True);
173*cdf0e10cSrcweir 					pPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 					// Notiz-Seite
176*cdf0e10cSrcweir 					SdPage* pNotesPage = (SdPage*) mpDoc->AllocPage(sal_False);
177*cdf0e10cSrcweir 					pNotesPage->SetSize(pActualNotesPage->GetSize());
178*cdf0e10cSrcweir 					pNotesPage->SetBorder(pActualNotesPage->GetLftBorder(),
179*cdf0e10cSrcweir 										  pActualNotesPage->GetUppBorder(),
180*cdf0e10cSrcweir 										  pActualNotesPage->GetRgtBorder(),
181*cdf0e10cSrcweir 										  pActualNotesPage->GetLwrBorder() );
182*cdf0e10cSrcweir 					pNotesPage->SetPageKind(PK_NOTES);
183*cdf0e10cSrcweir 					pNotesPage->SetName(String());
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 					// Seite hinter aktueller Seite einfuegen
186*cdf0e10cSrcweir 					mpDoc->InsertPage(pNotesPage, nActualPageNum + nPos);
187*cdf0e10cSrcweir 					nPos++;
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 					if( bUndo )
190*cdf0e10cSrcweir 						mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage));
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 					// MasterPage der aktuellen Seite verwenden
193*cdf0e10cSrcweir 					pNotesPage->TRG_SetMasterPage(pActualNotesPage->TRG_GetMasterPage());
194*cdf0e10cSrcweir 					pNotesPage->SetLayoutName(pActualNotesPage->GetLayoutName());
195*cdf0e10cSrcweir 					pNotesPage->SetAutoLayout(pActualNotesPage->GetAutoLayout(), sal_True);
196*cdf0e10cSrcweir 					pNotesPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 					// Title-Textobjekt erstellen
199*cdf0e10cSrcweir 					SdrTextObj* pTextObj = (SdrTextObj*) pPage->GetPresObj(PRESOBJ_TITLE);
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir //
202*cdf0e10cSrcweir 					OutlinerParaObject* pOutlinerParaObject = pOutl->CreateParaObject( (sal_uInt16) nParaPos, 1);
203*cdf0e10cSrcweir 					pOutlinerParaObject->SetOutlinerMode(OUTLINERMODE_TITLEOBJECT);
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 					if( pOutlinerParaObject->GetDepth(0) != -1 )
206*cdf0e10cSrcweir 					{
207*cdf0e10cSrcweir 						SdrOutliner* pTempOutl = SdrMakeOutliner( OUTLINERMODE_TITLEOBJECT, mpDoc );
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 						pTempOutl->SetText( *pOutlinerParaObject );
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 						delete pOutlinerParaObject;
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 						pTempOutl->SetDepth( pTempOutl->GetParagraph( 0 ), -1 );
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 						pOutlinerParaObject = pTempOutl->CreateParaObject();
216*cdf0e10cSrcweir 						delete pTempOutl;
217*cdf0e10cSrcweir 					}
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 					pTextObj->SetOutlinerParaObject(pOutlinerParaObject);
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 					pTextObj->SetEmptyPresObj(sal_False);
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 					SfxStyleSheet* pSheet = pPage->GetStyleSheetForPresObj(PRESOBJ_TITLE);
224*cdf0e10cSrcweir 					pTextObj->NbcSetStyleSheet(pSheet, sal_False);
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 					sal_uLong nChildCount = pOutl->GetChildCount(pPara);
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 					if (nChildCount > 0)
229*cdf0e10cSrcweir 					{
230*cdf0e10cSrcweir 						// Gliederungs-Textobjekt erstellen
231*cdf0e10cSrcweir 						SdrTextObj* pOutlineObj = (SdrTextObj*) pPage->GetPresObj(PRESOBJ_OUTLINE);
232*cdf0e10cSrcweir 						pPara = pOutl->GetParagraph( ++nParaPos );
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 						OutlinerParaObject* pOPO = pOutl->CreateParaObject( (sal_uInt16) nParaPos, (sal_uInt16) nChildCount);
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir // --
237*cdf0e10cSrcweir 						SdrOutliner* pTempOutl = SdrMakeOutliner( OUTLINERMODE_OUTLINEOBJECT, mpDoc );
238*cdf0e10cSrcweir 						pTempOutl->SetText( *pOPO );
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 						sal_uLong nParaCount2 = pTempOutl->GetParagraphCount();
241*cdf0e10cSrcweir 						sal_uLong nPara;
242*cdf0e10cSrcweir 						for( nPara = 0; nPara < nParaCount2; nPara++ )
243*cdf0e10cSrcweir 						{
244*cdf0e10cSrcweir 							pTempOutl->SetDepth (
245*cdf0e10cSrcweir                                 pTempOutl->GetParagraph( nPara ),
246*cdf0e10cSrcweir                                 pTempOutl->GetDepth((sal_uInt16) nPara ) - 1);
247*cdf0e10cSrcweir 						}
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 						delete pOPO;
250*cdf0e10cSrcweir 						pOPO = pTempOutl->CreateParaObject();
251*cdf0e10cSrcweir 						delete pTempOutl;
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir // --
254*cdf0e10cSrcweir 						pOutlineObj->SetOutlinerParaObject( pOPO );
255*cdf0e10cSrcweir 						pOutlineObj->SetEmptyPresObj(sal_False);
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 						// Harte Attribute entfernen (Flag auf sal_True)
258*cdf0e10cSrcweir 						SfxItemSet aAttr(mpDoc->GetPool());
259*cdf0e10cSrcweir 						aAttr.Put(XLineStyleItem(XLINE_NONE));
260*cdf0e10cSrcweir 						aAttr.Put(XFillStyleItem(XFILL_NONE));
261*cdf0e10cSrcweir 						pOutlineObj->SetMergedItemSet(aAttr);
262*cdf0e10cSrcweir 					}
263*cdf0e10cSrcweir 				}
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 				pPara = pOutl->GetParagraph( ++nParaPos );
266*cdf0e10cSrcweir 			}
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 			if( bUndo )
269*cdf0e10cSrcweir 				mpView->EndUndo();
270*cdf0e10cSrcweir 		}
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 		delete pOutl;
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 		mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE_PAGE, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
275*cdf0e10cSrcweir 	}
276*cdf0e10cSrcweir }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir } // end of namespace sd
279