/src/libreoffice/sd/source/ui/func/fuexpand.cxx
Line | Count | Source |
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 | | |
50 | | FuExpandPage::FuExpandPage ( |
51 | | ViewShell& rViewSh, |
52 | | ::sd::Window* pWin, |
53 | | ::sd::View* pView, |
54 | | SdDrawDocument& rDoc, |
55 | | SfxRequest& rReq) |
56 | 0 | : FuPoor(rViewSh, pWin, pView, rDoc, rReq) |
57 | 0 | { |
58 | 0 | } |
59 | | |
60 | | rtl::Reference<FuPoor> FuExpandPage::Create( ViewShell& rViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument& rDoc, SfxRequest& rReq ) |
61 | 0 | { |
62 | 0 | rtl::Reference<FuPoor> xFunc( new FuExpandPage( rViewSh, pWin, pView, rDoc, rReq ) ); |
63 | 0 | xFunc->DoExecute(rReq); |
64 | 0 | return xFunc; |
65 | 0 | } |
66 | | |
67 | | void FuExpandPage::DoExecute( SfxRequest& ) |
68 | 0 | { |
69 | 0 | if ( mpView && mpView->IsTextEdit() ) |
70 | 0 | mpView->SdrEndTextEdit(); |
71 | | |
72 | | // find selected page (only standard pages) |
73 | 0 | SdPage* pActualPage = nullptr; |
74 | 0 | sal_uInt16 i = 0; |
75 | 0 | sal_uInt16 nCount = mrDoc.GetSdPageCount(PageKind::Standard); |
76 | |
|
77 | 0 | while (!pActualPage && i < nCount) |
78 | 0 | { |
79 | 0 | if (mrDoc.GetSdPage(i, PageKind::Standard)->IsSelected()) |
80 | 0 | { |
81 | 0 | pActualPage = mrDoc.GetSdPage(i, PageKind::Standard); |
82 | 0 | } |
83 | |
|
84 | 0 | i++; |
85 | 0 | } |
86 | |
|
87 | 0 | if (!pActualPage) |
88 | 0 | return; |
89 | | |
90 | 0 | SdOutliner aOutliner( mrDoc, OutlinerMode::OutlineObject ); |
91 | 0 | aOutliner.SetUpdateLayout(false); |
92 | 0 | aOutliner.EnableUndo(false); |
93 | |
|
94 | 0 | if (mpDocSh) |
95 | 0 | aOutliner.SetRefDevice(SdModule::get()->GetVirtualRefDevice()); |
96 | |
|
97 | 0 | aOutliner.SetDefTab( mrDoc.GetDefaultTabulator() ); |
98 | 0 | aOutliner.SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(mrDoc.GetStyleSheetPool())); |
99 | |
|
100 | 0 | SdrLayerIDSet aVisibleLayers = pActualPage->TRG_GetMasterPageVisibleLayers(); |
101 | 0 | sal_uInt16 nActualPageNum = pActualPage->GetPageNum(); |
102 | 0 | SdPage* pActualNotesPage = static_cast<SdPage*>(mrDoc.GetPage(nActualPageNum + 1)); |
103 | 0 | SdrTextObj* pActualOutline = static_cast<SdrTextObj*>(pActualPage->GetPresObj(PresObjKind::Outline)); |
104 | |
|
105 | 0 | if (pActualOutline) |
106 | 0 | { |
107 | 0 | const bool bUndo = mpView && mpView->IsUndoEnabled(); |
108 | |
|
109 | 0 | if( bUndo ) |
110 | 0 | mpView->BegUndo(SdResId(STR_UNDO_EXPAND_PAGE)); |
111 | | |
112 | | // set current structuring-object into outliner |
113 | 0 | OutlinerParaObject* pParaObj = pActualOutline->GetOutlinerParaObject(); |
114 | 0 | aOutliner.SetText(*pParaObj); |
115 | | |
116 | | // remove hard paragraph- and character attributes |
117 | 0 | SfxItemSet aEmptyEEAttr(SfxItemSet::makeFixedSfxItemSet<EE_ITEMS_START, EE_ITEMS_END>(mrDoc.GetPool())); |
118 | 0 | sal_Int32 nParaCount1 = aOutliner.GetParagraphCount(); |
119 | |
|
120 | 0 | for (sal_Int32 nPara = 0; nPara < nParaCount1; nPara++) |
121 | 0 | { |
122 | 0 | aOutliner.RemoveCharAttribs(nPara); |
123 | 0 | aOutliner.SetParaAttribs(nPara, aEmptyEEAttr); |
124 | 0 | } |
125 | |
|
126 | 0 | sal_uInt16 nPos = 2; |
127 | 0 | Paragraph* pPara = aOutliner.GetParagraph( 0 ); |
128 | |
|
129 | 0 | while (pPara) |
130 | 0 | { |
131 | 0 | sal_Int32 nParaPos = aOutliner.GetAbsPos( pPara ); |
132 | 0 | sal_Int16 nDepth = aOutliner.GetDepth( nParaPos ); |
133 | 0 | if ( nDepth == 0 ) |
134 | 0 | { |
135 | | // page with title & structuring! |
136 | 0 | rtl::Reference<SdPage> pPage = mrDoc.AllocSdPage(false); |
137 | 0 | pPage->SetSize(pActualPage->GetSize() ); |
138 | 0 | pPage->SetBorder(pActualPage->GetLeftBorder(), |
139 | 0 | pActualPage->GetUpperBorder(), |
140 | 0 | pActualPage->GetRightBorder(), |
141 | 0 | pActualPage->GetLowerBorder() ); |
142 | 0 | pPage->SetName(OUString()); |
143 | | |
144 | | // insert page after current page |
145 | 0 | mrDoc.InsertPage(pPage.get(), nActualPageNum + nPos); |
146 | 0 | nPos++; |
147 | |
|
148 | 0 | if( bUndo ) |
149 | 0 | mpView->AddUndo(mrDoc.GetSdrUndoFactory().CreateUndoNewPage(*pPage)); |
150 | | |
151 | | // use MasterPage of the current page |
152 | 0 | pPage->TRG_SetMasterPage(pActualPage->TRG_GetMasterPage()); |
153 | 0 | pPage->SetLayoutName(pActualPage->GetLayoutName()); |
154 | 0 | pPage->SetAutoLayout(AUTOLAYOUT_TITLE_CONTENT, true); |
155 | 0 | pPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers); |
156 | | |
157 | | // notes-page |
158 | 0 | rtl::Reference<SdPage> pNotesPage = mrDoc.AllocSdPage(false); |
159 | 0 | pNotesPage->SetSize(pActualNotesPage->GetSize()); |
160 | 0 | pNotesPage->SetBorder(pActualNotesPage->GetLeftBorder(), |
161 | 0 | pActualNotesPage->GetUpperBorder(), |
162 | 0 | pActualNotesPage->GetRightBorder(), |
163 | 0 | pActualNotesPage->GetLowerBorder() ); |
164 | 0 | pNotesPage->SetPageKind(PageKind::Notes); |
165 | 0 | pNotesPage->SetName(OUString()); |
166 | | |
167 | | // insert page after current page |
168 | 0 | mrDoc.InsertPage(pNotesPage.get(), nActualPageNum + nPos); |
169 | 0 | nPos++; |
170 | |
|
171 | 0 | if( bUndo ) |
172 | 0 | mpView->AddUndo(mrDoc.GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage)); |
173 | | |
174 | | // use MasterPage of the current page |
175 | 0 | pNotesPage->TRG_SetMasterPage(pActualNotesPage->TRG_GetMasterPage()); |
176 | 0 | pNotesPage->SetLayoutName(pActualNotesPage->GetLayoutName()); |
177 | 0 | pNotesPage->SetAutoLayout(pActualNotesPage->GetAutoLayout(), true); |
178 | 0 | pNotesPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers); |
179 | | |
180 | | // create title text objects |
181 | 0 | SdrTextObj* pTextObj = static_cast<SdrTextObj*>(pPage->GetPresObj(PresObjKind::Title)); |
182 | 0 | SAL_WARN_IF(!pTextObj, "sd.core", "worrying lack of PresObjKind::Title object"); |
183 | 0 | if (!pTextObj) |
184 | 0 | continue; |
185 | | |
186 | 0 | std::optional<OutlinerParaObject> pOutlinerParaObject = aOutliner.CreateParaObject( nParaPos, 1); |
187 | 0 | pOutlinerParaObject->SetOutlinerMode(OutlinerMode::TitleObject); |
188 | |
|
189 | 0 | if( pOutlinerParaObject->GetNumberingDepth(0) != -1 ) |
190 | 0 | { |
191 | 0 | std::unique_ptr<SdrOutliner> pTempOutl = SdrMakeOutliner(OutlinerMode::TitleObject, mrDoc); |
192 | |
|
193 | 0 | pTempOutl->SetText( *pOutlinerParaObject ); |
194 | |
|
195 | 0 | pOutlinerParaObject.reset(); |
196 | |
|
197 | 0 | pTempOutl->SetDepth( pTempOutl->GetParagraph( 0 ), -1 ); |
198 | |
|
199 | 0 | pOutlinerParaObject = pTempOutl->CreateParaObject(); |
200 | 0 | } |
201 | |
|
202 | 0 | pTextObj->SetOutlinerParaObject(std::move(pOutlinerParaObject)); |
203 | |
|
204 | 0 | pTextObj->SetEmptyPresObj(false); |
205 | |
|
206 | 0 | SfxStyleSheet* pSheet = pPage->GetStyleSheetForPresObj(PresObjKind::Title); |
207 | 0 | pTextObj->NbcSetStyleSheet(pSheet, false); |
208 | |
|
209 | 0 | SdrTextObj* pOutlineObj = nullptr; |
210 | 0 | sal_Int32 nChildCount = aOutliner.GetChildCount(pPara); |
211 | 0 | if (nChildCount > 0) |
212 | 0 | pOutlineObj = static_cast<SdrTextObj*>( pPage->GetPresObj(PresObjKind::Outline) ); |
213 | 0 | if (pOutlineObj) |
214 | 0 | { |
215 | | // create structuring text objects |
216 | 0 | std::optional<OutlinerParaObject> pOPO = aOutliner.CreateParaObject(++nParaPos, nChildCount); |
217 | |
|
218 | 0 | std::unique_ptr<SdrOutliner> pTempOutl = SdrMakeOutliner(OutlinerMode::OutlineObject, mrDoc); |
219 | 0 | pTempOutl->SetText( *pOPO ); |
220 | |
|
221 | 0 | sal_Int32 nParaCount2 = pTempOutl->GetParagraphCount(); |
222 | 0 | sal_Int32 nPara; |
223 | 0 | for( nPara = 0; nPara < nParaCount2; nPara++ ) |
224 | 0 | { |
225 | 0 | pTempOutl->SetDepth ( |
226 | 0 | pTempOutl->GetParagraph( nPara ), |
227 | 0 | pTempOutl->GetDepth( nPara ) - 1); |
228 | 0 | } |
229 | |
|
230 | 0 | pOPO = pTempOutl->CreateParaObject(); |
231 | 0 | pTempOutl.reset(); |
232 | |
|
233 | 0 | pOutlineObj->SetOutlinerParaObject( std::move(pOPO) ); |
234 | 0 | pOutlineObj->SetEmptyPresObj(false); |
235 | | |
236 | | // remove hard attributes (Flag to sal_True) |
237 | 0 | SfxItemSet aAttr(mrDoc.GetPool()); |
238 | 0 | aAttr.Put(XLineStyleItem(drawing::LineStyle_NONE)); |
239 | 0 | aAttr.Put(XFillStyleItem(drawing::FillStyle_NONE)); |
240 | 0 | pOutlineObj->SetMergedItemSet(aAttr); |
241 | 0 | } |
242 | 0 | } |
243 | | |
244 | 0 | pPara = aOutliner.GetParagraph( ++nParaPos ); |
245 | 0 | } |
246 | | |
247 | 0 | if( bUndo ) |
248 | 0 | mpView->EndUndo(); |
249 | 0 | } |
250 | | |
251 | 0 | mrViewShell.GetViewFrame()->GetDispatcher()->Execute(SID_DELETE_PAGE, SfxCallMode::SYNCHRON | SfxCallMode::RECORD); |
252 | 0 | } |
253 | | |
254 | | } // end of namespace sd |
255 | | |
256 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |