xref: /aoo41x/main/sd/source/ui/func/fuexpand.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 "fuexpand.hxx"
33 
34 #include <sfx2/viewfrm.hxx>
35 #include <svx/svdotext.hxx>
36 #include <svx/xlineit0.hxx>
37 #include <svx/svdundo.hxx>
38 #include <sfx2/printer.hxx>
39 #include <editeng/outlobj.hxx>
40 #include <svx/svdetc.hxx>
41 
42 #include "app.hrc"
43 #include "strings.hrc"
44 #include "pres.hxx"
45 #include "View.hxx"
46 #include "sdpage.hxx"
47 #include "Outliner.hxx"
48 #include "drawview.hxx"
49 #include "drawdoc.hxx"
50 #include "ViewShell.hxx"
51 #include "DrawDocShell.hxx"
52 #include "sdresid.hxx"
53 #include "optsitem.hxx"
54 #include "sdmod.hxx"
55 #include <sfx2/dispatch.hxx>
56 #include <editeng/eeitem.hxx>
57 
58 namespace sd {
59 
60 TYPEINIT1( FuExpandPage, FuPoor );
61 
62 /*************************************************************************
63 |*
64 |* Konstruktor
65 |*
66 \************************************************************************/
67 
68 FuExpandPage::FuExpandPage (
69     ViewShell* pViewSh,
70     ::sd::Window* pWin,
71     ::sd::View* pView,
72     SdDrawDocument* pDoc,
73     SfxRequest& rReq)
74     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
75 {
76 }
77 
78 FunctionReference FuExpandPage::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
79 {
80 	FunctionReference xFunc( new FuExpandPage( pViewSh, pWin, pView, pDoc, rReq ) );
81 	xFunc->DoExecute(rReq);
82 	return xFunc;
83 }
84 
85 void FuExpandPage::DoExecute( SfxRequest& )
86 {
87 	if ( mpView && mpView->IsTextEdit() )
88 		mpView->SdrEndTextEdit();
89 
90 	// Selektierte Seite finden (nur Standard-Seiten)
91 	SdPage* pActualPage = NULL;
92 	sal_uInt16 i = 0;
93 	sal_uInt16 nCount = mpDoc->GetSdPageCount(PK_STANDARD);
94 
95 	while (!pActualPage && i < nCount)
96 	{
97 		if (mpDoc->GetSdPage(i, PK_STANDARD)->IsSelected())
98 		{
99 			pActualPage = mpDoc->GetSdPage(i, PK_STANDARD);
100 		}
101 
102 		i++;
103 	}
104 
105 	if (pActualPage)
106 	{
107 		::sd::Outliner* pOutl =
108               new ::sd::Outliner( mpDoc, OUTLINERMODE_OUTLINEOBJECT );
109 		pOutl->SetUpdateMode(sal_False);
110 		pOutl->EnableUndo(sal_False);
111 
112 		if (mpDocSh)
113 			pOutl->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
114 
115 		pOutl->SetDefTab( mpDoc->GetDefaultTabulator() );
116 		pOutl->SetStyleSheetPool((SfxStyleSheetPool*) mpDoc->GetStyleSheetPool());
117 
118 		SetOfByte aVisibleLayers = pActualPage->TRG_GetMasterPageVisibleLayers();
119 		sal_uInt16 nActualPageNum = pActualPage->GetPageNum();
120 		SdPage* pActualNotesPage = (SdPage*) mpDoc->GetPage(nActualPageNum + 1);
121 		SdrTextObj* pActualOutline = (SdrTextObj*) pActualPage->GetPresObj(PRESOBJ_OUTLINE);
122 
123 		if (pActualOutline)
124 		{
125 			const bool bUndo = mpView->IsUndoEnabled();
126 
127 			if( bUndo )
128 				mpView->BegUndo(String(SdResId(STR_UNDO_EXPAND_PAGE)));
129 
130 			// Aktuelles Gliederungsobjekt in Outliner setzen
131 			OutlinerParaObject* pParaObj = pActualOutline->GetOutlinerParaObject();
132 			pOutl->SetText(*pParaObj);
133 
134 			// Harte Absatz- und Zeichenattribute entfernen
135 			SfxItemSet aEmptyEEAttr(mpDoc->GetPool(), EE_ITEMS_START, EE_ITEMS_END);
136 			sal_uLong nParaCount1 = pOutl->GetParagraphCount();
137 
138 			for (sal_uInt16 nPara = 0; nPara < nParaCount1; nPara++)
139 			{
140 				pOutl->QuickRemoveCharAttribs(nPara);
141 				pOutl->SetParaAttribs(nPara, aEmptyEEAttr);
142 			}
143 
144 			sal_uInt16 nPos = 2;
145 			Paragraph* pPara = pOutl->GetParagraph( 0 );
146 
147 			while (pPara)
148 			{
149 				sal_uLong nParaPos = pOutl->GetAbsPos( pPara );
150 				sal_Int16 nDepth = pOutl->GetDepth( (sal_uInt16) nParaPos );
151 				if ( nDepth == 0 )
152 				{
153 					// Seite mit Titel & Gliederung!
154 					SdPage* pPage = (SdPage*) mpDoc->AllocPage(sal_False);
155 					pPage->SetSize(pActualPage->GetSize() );
156 					pPage->SetBorder(pActualPage->GetLftBorder(),
157 									 pActualPage->GetUppBorder(),
158 									 pActualPage->GetRgtBorder(),
159 									 pActualPage->GetLwrBorder() );
160 					pPage->SetName(String());
161 
162 					// Seite hinter aktueller Seite einfuegen
163 					mpDoc->InsertPage(pPage, nActualPageNum + nPos);
164 					nPos++;
165 
166 					if( bUndo )
167 						mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pPage));
168 
169 					// MasterPage der aktuellen Seite verwenden
170 					pPage->TRG_SetMasterPage(pActualPage->TRG_GetMasterPage());
171 					pPage->SetLayoutName(pActualPage->GetLayoutName());
172 					pPage->SetAutoLayout(AUTOLAYOUT_ENUM, sal_True);
173 					pPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
174 
175 					// Notiz-Seite
176 					SdPage* pNotesPage = (SdPage*) mpDoc->AllocPage(sal_False);
177 					pNotesPage->SetSize(pActualNotesPage->GetSize());
178 					pNotesPage->SetBorder(pActualNotesPage->GetLftBorder(),
179 										  pActualNotesPage->GetUppBorder(),
180 										  pActualNotesPage->GetRgtBorder(),
181 										  pActualNotesPage->GetLwrBorder() );
182 					pNotesPage->SetPageKind(PK_NOTES);
183 					pNotesPage->SetName(String());
184 
185 					// Seite hinter aktueller Seite einfuegen
186 					mpDoc->InsertPage(pNotesPage, nActualPageNum + nPos);
187 					nPos++;
188 
189 					if( bUndo )
190 						mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage));
191 
192 					// MasterPage der aktuellen Seite verwenden
193 					pNotesPage->TRG_SetMasterPage(pActualNotesPage->TRG_GetMasterPage());
194 					pNotesPage->SetLayoutName(pActualNotesPage->GetLayoutName());
195 					pNotesPage->SetAutoLayout(pActualNotesPage->GetAutoLayout(), sal_True);
196 					pNotesPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
197 
198 					// Title-Textobjekt erstellen
199 					SdrTextObj* pTextObj = (SdrTextObj*) pPage->GetPresObj(PRESOBJ_TITLE);
200 
201 //
202 					OutlinerParaObject* pOutlinerParaObject = pOutl->CreateParaObject( (sal_uInt16) nParaPos, 1);
203 					pOutlinerParaObject->SetOutlinerMode(OUTLINERMODE_TITLEOBJECT);
204 
205 					if( pOutlinerParaObject->GetDepth(0) != -1 )
206 					{
207 						SdrOutliner* pTempOutl = SdrMakeOutliner( OUTLINERMODE_TITLEOBJECT, mpDoc );
208 
209 						pTempOutl->SetText( *pOutlinerParaObject );
210 
211 						delete pOutlinerParaObject;
212 
213 						pTempOutl->SetDepth( pTempOutl->GetParagraph( 0 ), -1 );
214 
215 						pOutlinerParaObject = pTempOutl->CreateParaObject();
216 						delete pTempOutl;
217 					}
218 
219 					pTextObj->SetOutlinerParaObject(pOutlinerParaObject);
220 
221 					pTextObj->SetEmptyPresObj(sal_False);
222 
223 					SfxStyleSheet* pSheet = pPage->GetStyleSheetForPresObj(PRESOBJ_TITLE);
224 					pTextObj->NbcSetStyleSheet(pSheet, sal_False);
225 
226 					sal_uLong nChildCount = pOutl->GetChildCount(pPara);
227 
228 					if (nChildCount > 0)
229 					{
230 						// Gliederungs-Textobjekt erstellen
231 						SdrTextObj* pOutlineObj = (SdrTextObj*) pPage->GetPresObj(PRESOBJ_OUTLINE);
232 						pPara = pOutl->GetParagraph( ++nParaPos );
233 
234 						OutlinerParaObject* pOPO = pOutl->CreateParaObject( (sal_uInt16) nParaPos, (sal_uInt16) nChildCount);
235 
236 // --
237 						SdrOutliner* pTempOutl = SdrMakeOutliner( OUTLINERMODE_OUTLINEOBJECT, mpDoc );
238 						pTempOutl->SetText( *pOPO );
239 
240 						sal_uLong nParaCount2 = pTempOutl->GetParagraphCount();
241 						sal_uLong nPara;
242 						for( nPara = 0; nPara < nParaCount2; nPara++ )
243 						{
244 							pTempOutl->SetDepth (
245                                 pTempOutl->GetParagraph( nPara ),
246                                 pTempOutl->GetDepth((sal_uInt16) nPara ) - 1);
247 						}
248 
249 						delete pOPO;
250 						pOPO = pTempOutl->CreateParaObject();
251 						delete pTempOutl;
252 
253 // --
254 						pOutlineObj->SetOutlinerParaObject( pOPO );
255 						pOutlineObj->SetEmptyPresObj(sal_False);
256 
257 						// Harte Attribute entfernen (Flag auf sal_True)
258 						SfxItemSet aAttr(mpDoc->GetPool());
259 						aAttr.Put(XLineStyleItem(XLINE_NONE));
260 						aAttr.Put(XFillStyleItem(XFILL_NONE));
261 						pOutlineObj->SetMergedItemSet(aAttr);
262 					}
263 				}
264 
265 				pPara = pOutl->GetParagraph( ++nParaPos );
266 			}
267 
268 			if( bUndo )
269 				mpView->EndUndo();
270 		}
271 
272 		delete pOutl;
273 
274 		mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE_PAGE, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
275 	}
276 }
277 
278 } // end of namespace sd
279