1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <fuexpand.hxx>
21
22 #include <sfx2/viewfrm.hxx>
23 #include <svx/svdotext.hxx>
24 #include <svx/xfillit0.hxx>
25 #include <svx/xlineit0.hxx>
26 #include <svx/svdundo.hxx>
27 #include <editeng/outlobj.hxx>
28 #include <svx/svdetc.hxx>
29 #include <xmloff/autolayout.hxx>
30 #include <sal/log.hxx>
31
32 #include <app.hrc>
33 #include <strings.hrc>
34 #include <pres.hxx>
35 #include <View.hxx>
36 #include <sdpage.hxx>
37 #include <Outliner.hxx>
38 #include <drawdoc.hxx>
39 #include <ViewShell.hxx>
40 #include <sdresid.hxx>
41 #include <sdmod.hxx>
42 #include <sfx2/dispatch.hxx>
43 #include <editeng/eeitem.hxx>
44
45 using namespace com::sun::star;
46
47 namespace sd {
48
49
FuExpandPage(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)50 FuExpandPage::FuExpandPage (
51 ViewShell* pViewSh,
52 ::sd::Window* pWin,
53 ::sd::View* pView,
54 SdDrawDocument* pDoc,
55 SfxRequest& rReq)
56 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
57 {
58 }
59
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)60 rtl::Reference<FuPoor> FuExpandPage::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
61 {
62 rtl::Reference<FuPoor> xFunc( new FuExpandPage( pViewSh, pWin, pView, pDoc, rReq ) );
63 xFunc->DoExecute(rReq);
64 return xFunc;
65 }
66
DoExecute(SfxRequest &)67 void FuExpandPage::DoExecute( SfxRequest& )
68 {
69 if ( mpView && mpView->IsTextEdit() )
70 mpView->SdrEndTextEdit();
71
72 // find selected page (only standard pages)
73 SdPage* pActualPage = nullptr;
74 sal_uInt16 i = 0;
75 sal_uInt16 nCount = mpDoc->GetSdPageCount(PageKind::Standard);
76
77 while (!pActualPage && i < nCount)
78 {
79 if (mpDoc->GetSdPage(i, PageKind::Standard)->IsSelected())
80 {
81 pActualPage = mpDoc->GetSdPage(i, PageKind::Standard);
82 }
83
84 i++;
85 }
86
87 if (!pActualPage)
88 return;
89
90 SdOutliner aOutliner( mpDoc, OutlinerMode::OutlineObject );
91 aOutliner.SetUpdateMode(false);
92 aOutliner.EnableUndo(false);
93
94 if (mpDocSh)
95 aOutliner.SetRefDevice( SD_MOD()->GetVirtualRefDevice() );
96
97 aOutliner.SetDefTab( mpDoc->GetDefaultTabulator() );
98 aOutliner.SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(mpDoc->GetStyleSheetPool()));
99
100 SdrLayerIDSet aVisibleLayers = pActualPage->TRG_GetMasterPageVisibleLayers();
101 sal_uInt16 nActualPageNum = pActualPage->GetPageNum();
102 SdPage* pActualNotesPage = static_cast<SdPage*>(mpDoc->GetPage(nActualPageNum + 1));
103 SdrTextObj* pActualOutline = static_cast<SdrTextObj*>(pActualPage->GetPresObj(PresObjKind::Outline));
104
105 if (pActualOutline)
106 {
107 const bool bUndo = mpView->IsUndoEnabled();
108
109 if( bUndo )
110 mpView->BegUndo(SdResId(STR_UNDO_EXPAND_PAGE));
111
112 // set current structuring-object into outliner
113 OutlinerParaObject* pParaObj = pActualOutline->GetOutlinerParaObject();
114 aOutliner.SetText(*pParaObj);
115
116 // remove hard paragraph- and character attributes
117 SfxItemSet aEmptyEEAttr(mpDoc->GetPool(), svl::Items<EE_ITEMS_START, EE_ITEMS_END>{});
118 sal_Int32 nParaCount1 = aOutliner.GetParagraphCount();
119
120 for (sal_Int32 nPara = 0; nPara < nParaCount1; nPara++)
121 {
122 aOutliner.RemoveCharAttribs(nPara);
123 aOutliner.SetParaAttribs(nPara, aEmptyEEAttr);
124 }
125
126 sal_uInt16 nPos = 2;
127 Paragraph* pPara = aOutliner.GetParagraph( 0 );
128
129 while (pPara)
130 {
131 sal_Int32 nParaPos = aOutliner.GetAbsPos( pPara );
132 sal_Int16 nDepth = aOutliner.GetDepth( nParaPos );
133 if ( nDepth == 0 )
134 {
135 // page with title & structuring!
136 rtl::Reference<SdPage> pPage = mpDoc->AllocSdPage(false);
137 pPage->SetSize(pActualPage->GetSize() );
138 pPage->SetBorder(pActualPage->GetLeftBorder(),
139 pActualPage->GetUpperBorder(),
140 pActualPage->GetRightBorder(),
141 pActualPage->GetLowerBorder() );
142 pPage->SetName(OUString());
143
144 // insert page after current page
145 mpDoc->InsertPage(pPage.get(), nActualPageNum + nPos);
146 nPos++;
147
148 if( bUndo )
149 mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pPage));
150
151 // use MasterPage of the current page
152 pPage->TRG_SetMasterPage(pActualPage->TRG_GetMasterPage());
153 pPage->SetLayoutName(pActualPage->GetLayoutName());
154 pPage->SetAutoLayout(AUTOLAYOUT_TITLE_CONTENT, true);
155 pPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
156
157 // notes-page
158 rtl::Reference<SdPage> pNotesPage = mpDoc->AllocSdPage(false);
159 pNotesPage->SetSize(pActualNotesPage->GetSize());
160 pNotesPage->SetBorder(pActualNotesPage->GetLeftBorder(),
161 pActualNotesPage->GetUpperBorder(),
162 pActualNotesPage->GetRightBorder(),
163 pActualNotesPage->GetLowerBorder() );
164 pNotesPage->SetPageKind(PageKind::Notes);
165 pNotesPage->SetName(OUString());
166
167 // insert page after current page
168 mpDoc->InsertPage(pNotesPage.get(), nActualPageNum + nPos);
169 nPos++;
170
171 if( bUndo )
172 mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage));
173
174 // use MasterPage of the current page
175 pNotesPage->TRG_SetMasterPage(pActualNotesPage->TRG_GetMasterPage());
176 pNotesPage->SetLayoutName(pActualNotesPage->GetLayoutName());
177 pNotesPage->SetAutoLayout(pActualNotesPage->GetAutoLayout(), true);
178 pNotesPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
179
180 // create title text objects
181 SdrTextObj* pTextObj = static_cast<SdrTextObj*>(pPage->GetPresObj(PresObjKind::Title));
182 SAL_WARN_IF(!pTextObj, "sd.core", "worrying lack of PresObjKind::Title object");
183 if (!pTextObj)
184 continue;
185
186 std::unique_ptr<OutlinerParaObject> pOutlinerParaObject = aOutliner.CreateParaObject( nParaPos, 1);
187 pOutlinerParaObject->SetOutlinerMode(OutlinerMode::TitleObject);
188
189 if( pOutlinerParaObject->GetDepth(0) != -1 )
190 {
191 std::unique_ptr<SdrOutliner> pTempOutl = SdrMakeOutliner(OutlinerMode::TitleObject, *mpDoc);
192
193 pTempOutl->SetText( *pOutlinerParaObject );
194
195 pOutlinerParaObject.reset();
196
197 pTempOutl->SetDepth( pTempOutl->GetParagraph( 0 ), -1 );
198
199 pOutlinerParaObject = pTempOutl->CreateParaObject();
200 }
201
202 pTextObj->SetOutlinerParaObject(std::move(pOutlinerParaObject));
203
204 pTextObj->SetEmptyPresObj(false);
205
206 SfxStyleSheet* pSheet = pPage->GetStyleSheetForPresObj(PresObjKind::Title);
207 pTextObj->NbcSetStyleSheet(pSheet, false);
208
209 SdrTextObj* pOutlineObj = nullptr;
210 sal_Int32 nChildCount = aOutliner.GetChildCount(pPara);
211 if (nChildCount > 0)
212 pOutlineObj = static_cast<SdrTextObj*>( pPage->GetPresObj(PresObjKind::Outline) );
213 if (pOutlineObj)
214 {
215 // create structuring text objects
216 std::unique_ptr<OutlinerParaObject> pOPO = aOutliner.CreateParaObject(++nParaPos, nChildCount);
217
218 std::unique_ptr<SdrOutliner> pTempOutl = SdrMakeOutliner(OutlinerMode::OutlineObject, *mpDoc);
219 pTempOutl->SetText( *pOPO );
220
221 sal_Int32 nParaCount2 = pTempOutl->GetParagraphCount();
222 sal_Int32 nPara;
223 for( nPara = 0; nPara < nParaCount2; nPara++ )
224 {
225 pTempOutl->SetDepth (
226 pTempOutl->GetParagraph( nPara ),
227 pTempOutl->GetDepth( nPara ) - 1);
228 }
229
230 pOPO = pTempOutl->CreateParaObject();
231 pTempOutl.reset();
232
233 pOutlineObj->SetOutlinerParaObject( std::move(pOPO) );
234 pOutlineObj->SetEmptyPresObj(false);
235
236 // remove hard attributes (Flag to sal_True)
237 SfxItemSet aAttr(mpDoc->GetPool());
238 aAttr.Put(XLineStyleItem(drawing::LineStyle_NONE));
239 aAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
240 pOutlineObj->SetMergedItemSet(aAttr);
241 }
242 }
243
244 pPara = aOutliner.GetParagraph( ++nParaPos );
245 }
246
247 if( bUndo )
248 mpView->EndUndo();
249 }
250
251 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE_PAGE, SfxCallMode::SYNCHRON | SfxCallMode::RECORD);
252 }
253
254 } // end of namespace sd
255
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
257