LibreOffice Module sd (master) 1
fuexpand.cxx
Go to the documentation of this file.
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
45using namespace com::sun::star;
46
47namespace sd {
48
49
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
61{
62 rtl::Reference<FuPoor> xFunc( new FuExpandPage( pViewSh, pWin, pView, pDoc, rReq ) );
63 xFunc->DoExecute(rReq);
64 return xFunc;
65}
66
68{
69 if ( mpView && mpView->IsTextEdit() )
71
72 // find selected page (only standard pages)
73 SdPage* pActualPage = nullptr;
74 sal_uInt16 i = 0;
76
77 while (!pActualPage && i < nCount)
78 {
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.SetUpdateLayout(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
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!
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 )
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 )
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::optional<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::optional<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: */
AUTOLAYOUT_TITLE_CONTENT
void SetOutlinerMode(OutlinerMode nNew)
sal_Int16 GetDepth(sal_Int32 nPara) const
SAL_DLLPRIVATE SfxItemPool & GetPool()
Definition: drawdoc.hxx:237
SdPage * GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
Definition: drawdoc2.cxx:207
SAL_DLLPRIVATE void InsertPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF) override
Definition: drawdoc2.cxx:380
SAL_DLLPRIVATE rtl::Reference< SdPage > AllocSdPage(bool bMasterPage)
Definition: drawdoc.cxx:644
sal_uInt16 GetSdPageCount(PageKind ePgKind) const
Definition: drawdoc2.cxx:212
The main purpose of this class is searching and replacing as well as spelling of impress documents.
Definition: Outliner.hxx:123
SdrObject * GetPresObj(PresObjKind eObjKind, int nIndex=1, bool bFuzzySearch=false)
returns the nIndex'th object from the given PresObjKind, index starts with 1
Definition: sdpage.cxx:203
bool IsSelected() const
Definition: sdpage.hxx:208
virtual OUString GetLayoutName() const override
Definition: sdpage.hxx:255
AutoLayout GetAutoLayout() const
Definition: sdpage.hxx:190
bool IsUndoEnabled() const
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
void BegUndo()
void EndUndo()
sal_uInt16 GetDefaultTabulator() const
SfxStyleSheetBasePool * GetStyleSheetPool() const
SdrUndoFactory & GetSdrUndoFactory() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
virtual bool IsTextEdit() const final override
void SetOutlinerParaObject(std::optional< OutlinerParaObject > pTextObject)
void SetEmptyPresObj(bool bEpt)
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
void NbcSetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)
SdrPage & TRG_GetMasterPage() const
sal_uInt16 GetPageNum() const
Size GetSize() const
sal_Int32 GetUpperBorder() const
sal_Int32 GetRightBorder() const
sal_Int32 GetLeftBorder() const
const SdrLayerIDSet & TRG_GetMasterPageVisibleLayers() const
sal_Int32 GetLowerBorder() const
virtual OutlinerParaObject * GetOutlinerParaObject() const override
virtual std::unique_ptr< SdrUndoAction > CreateUndoNewPage(SdrPage &rPage)
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxDispatcher * GetDispatcher()
FuExpandPage(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuexpand.cxx:50
virtual void DoExecute(SfxRequest &rReq) override
Definition: fuexpand.cxx:67
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuexpand.cxx:60
Base class for all functions.
Definition: fupoor.hxx:48
SdDrawDocument * mpDoc
Definition: fupoor.hxx:148
ViewShell * mpViewShell
Definition: fupoor.hxx:145
DrawDocShell * mpDocSh
Definition: fupoor.hxx:147
::sd::View * mpView
Definition: fupoor.hxx:144
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
SD_DLLPUBLIC SfxViewFrame * GetViewFrame() const
Definition: viewshel.cxx:118
virtual SdrEndTextEditKind SdrEndTextEdit(bool bDontDeleteReally=false) override
ends current text editing
Definition: sdview.cxx:772
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
int nCount
sal_uInt16 nPos
#define SAL_WARN_IF(condition, area, stream)
int i
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
#define SD_MOD()
Definition: sdmod.hxx:184
SVXCORE_DLLPUBLIC std::unique_ptr< SdrOutliner > SdrMakeOutliner(OutlinerMode nOutlinerMode, SdrModel &rMod)