1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/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>
33 #include <strings.hrc>
37 #include <Outliner.hxx>
38 #include <drawdoc.hxx>
39 #include <ViewShell.hxx>
40 #include <sdresid.hxx>
42 #include <sfx2/dispatch.hxx>
43 #include <editeng/eeitem.hxx>
45 using namespace com::sun::star
;
50 FuExpandPage::FuExpandPage (
56 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
60 rtl::Reference
<FuPoor
> FuExpandPage::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
62 rtl::Reference
<FuPoor
> xFunc( new FuExpandPage( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
63 xFunc
->DoExecute(rReq
);
67 void FuExpandPage::DoExecute( SfxRequest
& )
69 if ( mpView
&& mpView
->IsTextEdit() )
70 mpView
->SdrEndTextEdit();
72 // find selected page (only standard pages)
73 SdPage
* pActualPage
= nullptr;
75 sal_uInt16 nCount
= mpDoc
->GetSdPageCount(PageKind::Standard
);
77 while (!pActualPage
&& i
< nCount
)
79 if (mpDoc
->GetSdPage(i
, PageKind::Standard
)->IsSelected())
81 pActualPage
= mpDoc
->GetSdPage(i
, PageKind::Standard
);
90 SdOutliner
aOutliner( mpDoc
, OutlinerMode::OutlineObject
);
91 aOutliner
.SetUpdateLayout(false);
92 aOutliner
.EnableUndo(false);
95 aOutliner
.SetRefDevice( SD_MOD()->GetVirtualRefDevice() );
97 aOutliner
.SetDefTab( mpDoc
->GetDefaultTabulator() );
98 aOutliner
.SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(mpDoc
->GetStyleSheetPool()));
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
));
107 const bool bUndo
= mpView
->IsUndoEnabled();
110 mpView
->BegUndo(SdResId(STR_UNDO_EXPAND_PAGE
));
112 // set current structuring-object into outliner
113 OutlinerParaObject
* pParaObj
= pActualOutline
->GetOutlinerParaObject();
114 aOutliner
.SetText(*pParaObj
);
116 // remove hard paragraph- and character attributes
117 SfxItemSetFixed
<EE_ITEMS_START
, EE_ITEMS_END
> aEmptyEEAttr(mpDoc
->GetPool());
118 sal_Int32 nParaCount1
= aOutliner
.GetParagraphCount();
120 for (sal_Int32 nPara
= 0; nPara
< nParaCount1
; nPara
++)
122 aOutliner
.RemoveCharAttribs(nPara
);
123 aOutliner
.SetParaAttribs(nPara
, aEmptyEEAttr
);
127 Paragraph
* pPara
= aOutliner
.GetParagraph( 0 );
131 sal_Int32 nParaPos
= aOutliner
.GetAbsPos( pPara
);
132 sal_Int16 nDepth
= aOutliner
.GetDepth( nParaPos
);
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());
144 // insert page after current page
145 mpDoc
->InsertPage(pPage
.get(), nActualPageNum
+ nPos
);
149 mpView
->AddUndo(mpDoc
->GetSdrUndoFactory().CreateUndoNewPage(*pPage
));
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
);
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());
167 // insert page after current page
168 mpDoc
->InsertPage(pNotesPage
.get(), nActualPageNum
+ nPos
);
172 mpView
->AddUndo(mpDoc
->GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage
));
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
);
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");
186 std::optional
<OutlinerParaObject
> pOutlinerParaObject
= aOutliner
.CreateParaObject( nParaPos
, 1);
187 pOutlinerParaObject
->SetOutlinerMode(OutlinerMode::TitleObject
);
189 if( pOutlinerParaObject
->GetDepth(0) != -1 )
191 std::unique_ptr
<SdrOutliner
> pTempOutl
= SdrMakeOutliner(OutlinerMode::TitleObject
, *mpDoc
);
193 pTempOutl
->SetText( *pOutlinerParaObject
);
195 pOutlinerParaObject
.reset();
197 pTempOutl
->SetDepth( pTempOutl
->GetParagraph( 0 ), -1 );
199 pOutlinerParaObject
= pTempOutl
->CreateParaObject();
202 pTextObj
->SetOutlinerParaObject(std::move(pOutlinerParaObject
));
204 pTextObj
->SetEmptyPresObj(false);
206 SfxStyleSheet
* pSheet
= pPage
->GetStyleSheetForPresObj(PresObjKind::Title
);
207 pTextObj
->NbcSetStyleSheet(pSheet
, false);
209 SdrTextObj
* pOutlineObj
= nullptr;
210 sal_Int32 nChildCount
= aOutliner
.GetChildCount(pPara
);
212 pOutlineObj
= static_cast<SdrTextObj
*>( pPage
->GetPresObj(PresObjKind::Outline
) );
215 // create structuring text objects
216 std::optional
<OutlinerParaObject
> pOPO
= aOutliner
.CreateParaObject(++nParaPos
, nChildCount
);
218 std::unique_ptr
<SdrOutliner
> pTempOutl
= SdrMakeOutliner(OutlinerMode::OutlineObject
, *mpDoc
);
219 pTempOutl
->SetText( *pOPO
);
221 sal_Int32 nParaCount2
= pTempOutl
->GetParagraphCount();
223 for( nPara
= 0; nPara
< nParaCount2
; nPara
++ )
225 pTempOutl
->SetDepth (
226 pTempOutl
->GetParagraph( nPara
),
227 pTempOutl
->GetDepth( nPara
) - 1);
230 pOPO
= pTempOutl
->CreateParaObject();
233 pOutlineObj
->SetOutlinerParaObject( std::move(pOPO
) );
234 pOutlineObj
->SetEmptyPresObj(false);
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
);
244 pPara
= aOutliner
.GetParagraph( ++nParaPos
);
251 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE_PAGE
, SfxCallMode::SYNCHRON
| SfxCallMode::RECORD
);
254 } // end of namespace sd
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */