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/xlineit0.hxx>
25 #include <svx/svdundo.hxx>
26 #include <editeng/outlobj.hxx>
27 #include <svx/svdetc.hxx>
28 #include <xmloff/autolayout.hxx>
29 #include <sal/log.hxx>
32 #include <strings.hrc>
36 #include <Outliner.hxx>
37 #include <drawdoc.hxx>
38 #include <ViewShell.hxx>
39 #include <sdresid.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <editeng/eeitem.hxx>
44 using namespace com::sun::star
;
49 FuExpandPage::FuExpandPage (
55 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
59 rtl::Reference
<FuPoor
> FuExpandPage::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
61 rtl::Reference
<FuPoor
> xFunc( new FuExpandPage( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
62 xFunc
->DoExecute(rReq
);
66 void FuExpandPage::DoExecute( SfxRequest
& )
68 if ( mpView
&& mpView
->IsTextEdit() )
69 mpView
->SdrEndTextEdit();
71 // find selected page (only standard pages)
72 SdPage
* pActualPage
= nullptr;
74 sal_uInt16 nCount
= mpDoc
->GetSdPageCount(PageKind::Standard
);
76 while (!pActualPage
&& i
< nCount
)
78 if (mpDoc
->GetSdPage(i
, PageKind::Standard
)->IsSelected())
80 pActualPage
= mpDoc
->GetSdPage(i
, PageKind::Standard
);
89 SdOutliner
aOutliner( mpDoc
, OutlinerMode::OutlineObject
);
90 aOutliner
.SetUpdateMode(false);
91 aOutliner
.EnableUndo(false);
94 aOutliner
.SetRefDevice( SD_MOD()->GetVirtualRefDevice() );
96 aOutliner
.SetDefTab( mpDoc
->GetDefaultTabulator() );
97 aOutliner
.SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(mpDoc
->GetStyleSheetPool()));
99 SdrLayerIDSet aVisibleLayers
= pActualPage
->TRG_GetMasterPageVisibleLayers();
100 sal_uInt16 nActualPageNum
= pActualPage
->GetPageNum();
101 SdPage
* pActualNotesPage
= static_cast<SdPage
*>(mpDoc
->GetPage(nActualPageNum
+ 1));
102 SdrTextObj
* pActualOutline
= static_cast<SdrTextObj
*>(pActualPage
->GetPresObj(PRESOBJ_OUTLINE
));
106 const bool bUndo
= mpView
->IsUndoEnabled();
109 mpView
->BegUndo(SdResId(STR_UNDO_EXPAND_PAGE
));
111 // set current structuring-object into outliner
112 OutlinerParaObject
* pParaObj
= pActualOutline
->GetOutlinerParaObject();
113 aOutliner
.SetText(*pParaObj
);
115 // remove hard paragraph- and character attributes
116 SfxItemSet
aEmptyEEAttr(mpDoc
->GetPool(), svl::Items
<EE_ITEMS_START
, EE_ITEMS_END
>{});
117 sal_Int32 nParaCount1
= aOutliner
.GetParagraphCount();
119 for (sal_Int32 nPara
= 0; nPara
< nParaCount1
; nPara
++)
121 aOutliner
.RemoveCharAttribs(nPara
);
122 aOutliner
.SetParaAttribs(nPara
, aEmptyEEAttr
);
126 Paragraph
* pPara
= aOutliner
.GetParagraph( 0 );
130 sal_Int32 nParaPos
= aOutliner
.GetAbsPos( pPara
);
131 sal_Int16 nDepth
= aOutliner
.GetDepth( nParaPos
);
134 // page with title & structuring!
135 SdPage
* pPage
= mpDoc
->AllocSdPage(false);
136 pPage
->SetSize(pActualPage
->GetSize() );
137 pPage
->SetBorder(pActualPage
->GetLeftBorder(),
138 pActualPage
->GetUpperBorder(),
139 pActualPage
->GetRightBorder(),
140 pActualPage
->GetLowerBorder() );
141 pPage
->SetName(OUString());
143 // insert page after current page
144 mpDoc
->InsertPage(pPage
, nActualPageNum
+ nPos
);
148 mpView
->AddUndo(mpDoc
->GetSdrUndoFactory().CreateUndoNewPage(*pPage
));
150 // use MasterPage of the current page
151 pPage
->TRG_SetMasterPage(pActualPage
->TRG_GetMasterPage());
152 pPage
->SetLayoutName(pActualPage
->GetLayoutName());
153 pPage
->SetAutoLayout(AUTOLAYOUT_TITLE_CONTENT
, true);
154 pPage
->TRG_SetMasterPageVisibleLayers(aVisibleLayers
);
157 SdPage
* pNotesPage
= mpDoc
->AllocSdPage(false);
158 pNotesPage
->SetSize(pActualNotesPage
->GetSize());
159 pNotesPage
->SetBorder(pActualNotesPage
->GetLeftBorder(),
160 pActualNotesPage
->GetUpperBorder(),
161 pActualNotesPage
->GetRightBorder(),
162 pActualNotesPage
->GetLowerBorder() );
163 pNotesPage
->SetPageKind(PageKind::Notes
);
164 pNotesPage
->SetName(OUString());
166 // insert page after current page
167 mpDoc
->InsertPage(pNotesPage
, nActualPageNum
+ nPos
);
171 mpView
->AddUndo(mpDoc
->GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage
));
173 // use MasterPage of the current page
174 pNotesPage
->TRG_SetMasterPage(pActualNotesPage
->TRG_GetMasterPage());
175 pNotesPage
->SetLayoutName(pActualNotesPage
->GetLayoutName());
176 pNotesPage
->SetAutoLayout(pActualNotesPage
->GetAutoLayout(), true);
177 pNotesPage
->TRG_SetMasterPageVisibleLayers(aVisibleLayers
);
179 // create title text objects
180 SdrTextObj
* pTextObj
= static_cast<SdrTextObj
*>(pPage
->GetPresObj(PRESOBJ_TITLE
));
181 SAL_WARN_IF(!pTextObj
, "sd.core", "worrying lack of PRESOBJ_TITLE object");
185 std::unique_ptr
<OutlinerParaObject
> pOutlinerParaObject
= aOutliner
.CreateParaObject( nParaPos
, 1);
186 pOutlinerParaObject
->SetOutlinerMode(OutlinerMode::TitleObject
);
188 if( pOutlinerParaObject
->GetDepth(0) != -1 )
190 std::unique_ptr
<SdrOutliner
> pTempOutl
= SdrMakeOutliner(OutlinerMode::TitleObject
, *mpDoc
);
192 pTempOutl
->SetText( *pOutlinerParaObject
);
194 pOutlinerParaObject
.reset();
196 pTempOutl
->SetDepth( pTempOutl
->GetParagraph( 0 ), -1 );
198 pOutlinerParaObject
= pTempOutl
->CreateParaObject();
201 pTextObj
->SetOutlinerParaObject(std::move(pOutlinerParaObject
));
203 pTextObj
->SetEmptyPresObj(false);
205 SfxStyleSheet
* pSheet
= pPage
->GetStyleSheetForPresObj(PRESOBJ_TITLE
);
206 pTextObj
->NbcSetStyleSheet(pSheet
, false);
208 SdrTextObj
* pOutlineObj
= nullptr;
209 sal_Int32 nChildCount
= aOutliner
.GetChildCount(pPara
);
211 pOutlineObj
= static_cast<SdrTextObj
*>( pPage
->GetPresObj(PRESOBJ_OUTLINE
) );
214 // create structuring text objects
215 std::unique_ptr
<OutlinerParaObject
> pOPO
= aOutliner
.CreateParaObject(++nParaPos
, nChildCount
);
217 std::unique_ptr
<SdrOutliner
> pTempOutl
= SdrMakeOutliner(OutlinerMode::OutlineObject
, *mpDoc
);
218 pTempOutl
->SetText( *pOPO
);
220 sal_Int32 nParaCount2
= pTempOutl
->GetParagraphCount();
222 for( nPara
= 0; nPara
< nParaCount2
; nPara
++ )
224 pTempOutl
->SetDepth (
225 pTempOutl
->GetParagraph( nPara
),
226 pTempOutl
->GetDepth( nPara
) - 1);
229 pOPO
= pTempOutl
->CreateParaObject();
232 pOutlineObj
->SetOutlinerParaObject( std::move(pOPO
) );
233 pOutlineObj
->SetEmptyPresObj(false);
235 // remove hard attributes (Flag to sal_True)
236 SfxItemSet
aAttr(mpDoc
->GetPool());
237 aAttr
.Put(XLineStyleItem(drawing::LineStyle_NONE
));
238 aAttr
.Put(XFillStyleItem(drawing::FillStyle_NONE
));
239 pOutlineObj
->SetMergedItemSet(aAttr
);
243 pPara
= aOutliner
.GetParagraph( ++nParaPos
);
250 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE_PAGE
, SfxCallMode::SYNCHRON
| SfxCallMode::RECORD
);
253 } // end of namespace sd
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */