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