bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fuexpand.cxx
blobce2e0ba33e91f0286af80c8cd6084dffaf5ee933
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "fuexpand.hxx"
22 #include <sfx2/viewfrm.hxx>
23 #include <svx/svdotext.hxx>
24 #include <svx/xlineit0.hxx>
25 #include <svx/svdundo.hxx>
26 #include <sfx2/printer.hxx>
27 #include <editeng/outlobj.hxx>
28 #include <svx/svdetc.hxx>
30 #include "app.hrc"
31 #include "strings.hrc"
32 #include "pres.hxx"
33 #include "View.hxx"
34 #include "sdpage.hxx"
35 #include "Outliner.hxx"
36 #include "drawview.hxx"
37 #include "drawdoc.hxx"
38 #include "ViewShell.hxx"
39 #include "DrawDocShell.hxx"
40 #include "sdresid.hxx"
41 #include "optsitem.hxx"
42 #include "sdmod.hxx"
43 #include <sfx2/dispatch.hxx>
44 #include <editeng/eeitem.hxx>
46 namespace sd {
48 TYPEINIT1( FuExpandPage, FuPoor );
51 FuExpandPage::FuExpandPage (
52 ViewShell* pViewSh,
53 ::sd::Window* pWin,
54 ::sd::View* pView,
55 SdDrawDocument* pDoc,
56 SfxRequest& rReq)
57 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
61 FunctionReference FuExpandPage::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
63 FunctionReference xFunc( new FuExpandPage( pViewSh, pWin, pView, pDoc, rReq ) );
64 xFunc->DoExecute(rReq);
65 return xFunc;
68 void FuExpandPage::DoExecute( SfxRequest& )
70 if ( mpView && mpView->IsTextEdit() )
71 mpView->SdrEndTextEdit();
73 // find selected page (only standard pages)
74 SdPage* pActualPage = NULL;
75 sal_uInt16 i = 0;
76 sal_uInt16 nCount = mpDoc->GetSdPageCount(PK_STANDARD);
78 while (!pActualPage && i < nCount)
80 if (mpDoc->GetSdPage(i, PK_STANDARD)->IsSelected())
82 pActualPage = mpDoc->GetSdPage(i, PK_STANDARD);
85 i++;
88 if (pActualPage)
90 ::sd::Outliner* pOutl =
91 new ::sd::Outliner( mpDoc, OUTLINERMODE_OUTLINEOBJECT );
92 pOutl->SetUpdateMode(sal_False);
93 pOutl->EnableUndo(sal_False);
95 if (mpDocSh)
96 pOutl->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
98 pOutl->SetDefTab( mpDoc->GetDefaultTabulator() );
99 pOutl->SetStyleSheetPool((SfxStyleSheetPool*) mpDoc->GetStyleSheetPool());
101 SetOfByte aVisibleLayers = pActualPage->TRG_GetMasterPageVisibleLayers();
102 sal_uInt16 nActualPageNum = pActualPage->GetPageNum();
103 SdPage* pActualNotesPage = (SdPage*) mpDoc->GetPage(nActualPageNum + 1);
104 SdrTextObj* pActualOutline = (SdrTextObj*) pActualPage->GetPresObj(PRESOBJ_OUTLINE);
106 if (pActualOutline)
108 const bool bUndo = mpView->IsUndoEnabled();
110 if( bUndo )
111 mpView->BegUndo(String(SdResId(STR_UNDO_EXPAND_PAGE)));
113 // set current structuring-object into outliner
114 OutlinerParaObject* pParaObj = pActualOutline->GetOutlinerParaObject();
115 pOutl->SetText(*pParaObj);
117 // remove hard paragraph- and character attributes
118 SfxItemSet aEmptyEEAttr(mpDoc->GetPool(), EE_ITEMS_START, EE_ITEMS_END);
119 sal_Int32 nParaCount1 = pOutl->GetParagraphCount();
121 for (sal_Int32 nPara = 0; nPara < nParaCount1; nPara++)
123 pOutl->QuickRemoveCharAttribs(nPara);
124 pOutl->SetParaAttribs(nPara, aEmptyEEAttr);
127 sal_uInt16 nPos = 2;
128 Paragraph* pPara = pOutl->GetParagraph( 0 );
130 while (pPara)
132 sal_Int32 nParaPos = pOutl->GetAbsPos( pPara );
133 sal_Int16 nDepth = pOutl->GetDepth( nParaPos );
134 if ( nDepth == 0 )
136 // page with title & structuring!
137 SdPage* pPage = (SdPage*) mpDoc->AllocPage(sal_False);
138 pPage->SetSize(pActualPage->GetSize() );
139 pPage->SetBorder(pActualPage->GetLftBorder(),
140 pActualPage->GetUppBorder(),
141 pActualPage->GetRgtBorder(),
142 pActualPage->GetLwrBorder() );
143 pPage->SetName(String());
145 // insert page after current page
146 mpDoc->InsertPage(pPage, nActualPageNum + nPos);
147 nPos++;
149 if( bUndo )
150 mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pPage));
152 // use MasterPage of the current page
153 pPage->TRG_SetMasterPage(pActualPage->TRG_GetMasterPage());
154 pPage->SetLayoutName(pActualPage->GetLayoutName());
155 pPage->SetAutoLayout(AUTOLAYOUT_ENUM, sal_True);
156 pPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
158 // notes-page
159 SdPage* pNotesPage = (SdPage*) mpDoc->AllocPage(sal_False);
160 pNotesPage->SetSize(pActualNotesPage->GetSize());
161 pNotesPage->SetBorder(pActualNotesPage->GetLftBorder(),
162 pActualNotesPage->GetUppBorder(),
163 pActualNotesPage->GetRgtBorder(),
164 pActualNotesPage->GetLwrBorder() );
165 pNotesPage->SetPageKind(PK_NOTES);
166 pNotesPage->SetName(String());
168 // insert page after current page
169 mpDoc->InsertPage(pNotesPage, nActualPageNum + nPos);
170 nPos++;
172 if( bUndo )
173 mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage));
175 // use MasterPage of the current page
176 pNotesPage->TRG_SetMasterPage(pActualNotesPage->TRG_GetMasterPage());
177 pNotesPage->SetLayoutName(pActualNotesPage->GetLayoutName());
178 pNotesPage->SetAutoLayout(pActualNotesPage->GetAutoLayout(), sal_True);
179 pNotesPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
181 // create title text objects
182 SdrTextObj* pTextObj = (SdrTextObj*) pPage->GetPresObj(PRESOBJ_TITLE);
184 OutlinerParaObject* pOutlinerParaObject = pOutl->CreateParaObject( nParaPos, 1);
185 pOutlinerParaObject->SetOutlinerMode(OUTLINERMODE_TITLEOBJECT);
187 if( pOutlinerParaObject->GetDepth(0) != -1 )
189 SdrOutliner* pTempOutl = SdrMakeOutliner( OUTLINERMODE_TITLEOBJECT, mpDoc );
191 pTempOutl->SetText( *pOutlinerParaObject );
193 delete pOutlinerParaObject;
195 pTempOutl->SetDepth( pTempOutl->GetParagraph( 0 ), -1 );
197 pOutlinerParaObject = pTempOutl->CreateParaObject();
198 delete pTempOutl;
201 pTextObj->SetOutlinerParaObject(pOutlinerParaObject);
203 pTextObj->SetEmptyPresObj(sal_False);
205 SfxStyleSheet* pSheet = pPage->GetStyleSheetForPresObj(PRESOBJ_TITLE);
206 pTextObj->NbcSetStyleSheet(pSheet, sal_False);
208 sal_Int32 nChildCount = pOutl->GetChildCount(pPara);
210 if (nChildCount > 0)
212 // create structuring text objects
213 SdrTextObj* pOutlineObj = (SdrTextObj*) pPage->GetPresObj(PRESOBJ_OUTLINE);
214 pPara = pOutl->GetParagraph( ++nParaPos );
216 OutlinerParaObject* pOPO = pOutl->CreateParaObject( nParaPos, nChildCount);
218 SdrOutliner* pTempOutl = SdrMakeOutliner( OUTLINERMODE_OUTLINEOBJECT, mpDoc );
219 pTempOutl->SetText( *pOPO );
221 sal_Int32 nParaCount2 = pTempOutl->GetParagraphCount();
222 sal_Int32 nPara;
223 for( nPara = 0; nPara < nParaCount2; nPara++ )
225 pTempOutl->SetDepth (
226 pTempOutl->GetParagraph( nPara ),
227 pTempOutl->GetDepth( nPara ) - 1);
230 delete pOPO;
231 pOPO = pTempOutl->CreateParaObject();
232 delete pTempOutl;
234 pOutlineObj->SetOutlinerParaObject( pOPO );
235 pOutlineObj->SetEmptyPresObj(sal_False);
237 // remove hard attributes (Flag to sal_True)
238 SfxItemSet aAttr(mpDoc->GetPool());
239 aAttr.Put(XLineStyleItem(XLINE_NONE));
240 aAttr.Put(XFillStyleItem(XFILL_NONE));
241 pOutlineObj->SetMergedItemSet(aAttr);
245 pPara = pOutl->GetParagraph( ++nParaPos );
248 if( bUndo )
249 mpView->EndUndo();
252 delete pOutl;
254 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE_PAGE, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
258 } // end of namespace sd
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */