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 <sfx2/printer.hxx>
27 #include <editeng/outlobj.hxx>
28 #include <svx/svdetc.hxx>
29 #include <xmloff/autolayout.hxx>
32 #include <strings.hrc>
36 #include <Outliner.hxx>
37 #include <drawview.hxx>
38 #include <drawdoc.hxx>
39 #include <ViewShell.hxx>
40 #include <DrawDocShell.hxx>
41 #include <sdresid.hxx>
42 #include <optsitem.hxx>
44 #include <sfx2/dispatch.hxx>
45 #include <editeng/eeitem.hxx>
47 using namespace com::sun::star
;
52 FuExpandPage::FuExpandPage (
58 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
62 rtl::Reference
<FuPoor
> FuExpandPage::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
64 rtl::Reference
<FuPoor
> xFunc( new FuExpandPage( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
65 xFunc
->DoExecute(rReq
);
69 void FuExpandPage::DoExecute( SfxRequest
& )
71 if ( mpView
&& mpView
->IsTextEdit() )
72 mpView
->SdrEndTextEdit();
74 // find selected page (only standard pages)
75 SdPage
* pActualPage
= nullptr;
77 sal_uInt16 nCount
= mpDoc
->GetSdPageCount(PageKind::Standard
);
79 while (!pActualPage
&& i
< nCount
)
81 if (mpDoc
->GetSdPage(i
, PageKind::Standard
)->IsSelected())
83 pActualPage
= mpDoc
->GetSdPage(i
, PageKind::Standard
);
92 new SdOutliner( mpDoc
, OutlinerMode::OutlineObject
);
93 pOutl
->SetUpdateMode(false);
94 pOutl
->EnableUndo(false);
97 pOutl
->SetRefDevice( SD_MOD()->GetVirtualRefDevice() );
99 pOutl
->SetDefTab( mpDoc
->GetDefaultTabulator() );
100 pOutl
->SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(mpDoc
->GetStyleSheetPool()));
102 SdrLayerIDSet aVisibleLayers
= pActualPage
->TRG_GetMasterPageVisibleLayers();
103 sal_uInt16 nActualPageNum
= pActualPage
->GetPageNum();
104 SdPage
* pActualNotesPage
= static_cast<SdPage
*>(mpDoc
->GetPage(nActualPageNum
+ 1));
105 SdrTextObj
* pActualOutline
= static_cast<SdrTextObj
*>(pActualPage
->GetPresObj(PRESOBJ_OUTLINE
));
109 const bool bUndo
= mpView
->IsUndoEnabled();
112 mpView
->BegUndo(SdResId(STR_UNDO_EXPAND_PAGE
));
114 // set current structuring-object into outliner
115 OutlinerParaObject
* pParaObj
= pActualOutline
->GetOutlinerParaObject();
116 pOutl
->SetText(*pParaObj
);
118 // remove hard paragraph- and character attributes
119 SfxItemSet
aEmptyEEAttr(mpDoc
->GetPool(), svl::Items
<EE_ITEMS_START
, EE_ITEMS_END
>{});
120 sal_Int32 nParaCount1
= pOutl
->GetParagraphCount();
122 for (sal_Int32 nPara
= 0; nPara
< nParaCount1
; nPara
++)
124 pOutl
->RemoveCharAttribs(nPara
);
125 pOutl
->SetParaAttribs(nPara
, aEmptyEEAttr
);
129 Paragraph
* pPara
= pOutl
->GetParagraph( 0 );
133 sal_Int32 nParaPos
= pOutl
->GetAbsPos( pPara
);
134 sal_Int16 nDepth
= pOutl
->GetDepth( nParaPos
);
137 // page with title & structuring!
138 SdPage
* pPage
= mpDoc
->AllocSdPage(false);
139 pPage
->SetSize(pActualPage
->GetSize() );
140 pPage
->SetBorder(pActualPage
->GetLeftBorder(),
141 pActualPage
->GetUpperBorder(),
142 pActualPage
->GetRightBorder(),
143 pActualPage
->GetLowerBorder() );
144 pPage
->SetName(OUString());
146 // insert page after current page
147 mpDoc
->InsertPage(pPage
, nActualPageNum
+ nPos
);
151 mpView
->AddUndo(mpDoc
->GetSdrUndoFactory().CreateUndoNewPage(*pPage
));
153 // use MasterPage of the current page
154 pPage
->TRG_SetMasterPage(pActualPage
->TRG_GetMasterPage());
155 pPage
->SetLayoutName(pActualPage
->GetLayoutName());
156 pPage
->SetAutoLayout(AUTOLAYOUT_TITLE_CONTENT
, true);
157 pPage
->TRG_SetMasterPageVisibleLayers(aVisibleLayers
);
160 SdPage
* pNotesPage
= mpDoc
->AllocSdPage(false);
161 pNotesPage
->SetSize(pActualNotesPage
->GetSize());
162 pNotesPage
->SetBorder(pActualNotesPage
->GetLeftBorder(),
163 pActualNotesPage
->GetUpperBorder(),
164 pActualNotesPage
->GetRightBorder(),
165 pActualNotesPage
->GetLowerBorder() );
166 pNotesPage
->SetPageKind(PageKind::Notes
);
167 pNotesPage
->SetName(OUString());
169 // insert page after current page
170 mpDoc
->InsertPage(pNotesPage
, nActualPageNum
+ nPos
);
174 mpView
->AddUndo(mpDoc
->GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage
));
176 // use MasterPage of the current page
177 pNotesPage
->TRG_SetMasterPage(pActualNotesPage
->TRG_GetMasterPage());
178 pNotesPage
->SetLayoutName(pActualNotesPage
->GetLayoutName());
179 pNotesPage
->SetAutoLayout(pActualNotesPage
->GetAutoLayout(), true);
180 pNotesPage
->TRG_SetMasterPageVisibleLayers(aVisibleLayers
);
182 // create title text objects
183 SdrTextObj
* pTextObj
= static_cast<SdrTextObj
*>(pPage
->GetPresObj(PRESOBJ_TITLE
));
184 SAL_WARN_IF(!pTextObj
, "sd.core", "worrying lack of PRESOBJ_TITLE object");
188 OutlinerParaObject
* pOutlinerParaObject
= pOutl
->CreateParaObject( nParaPos
, 1);
189 pOutlinerParaObject
->SetOutlinerMode(OutlinerMode::TitleObject
);
191 if( pOutlinerParaObject
->GetDepth(0) != -1 )
193 std::unique_ptr
<SdrOutliner
> pTempOutl
= SdrMakeOutliner(OutlinerMode::TitleObject
, *mpDoc
);
195 pTempOutl
->SetText( *pOutlinerParaObject
);
197 delete pOutlinerParaObject
;
199 pTempOutl
->SetDepth( pTempOutl
->GetParagraph( 0 ), -1 );
201 pOutlinerParaObject
= pTempOutl
->CreateParaObject();
204 pTextObj
->SetOutlinerParaObject(pOutlinerParaObject
);
206 pTextObj
->SetEmptyPresObj(false);
208 SfxStyleSheet
* pSheet
= pPage
->GetStyleSheetForPresObj(PRESOBJ_TITLE
);
209 pTextObj
->NbcSetStyleSheet(pSheet
, false);
211 SdrTextObj
* pOutlineObj
= nullptr;
212 sal_Int32 nChildCount
= pOutl
->GetChildCount(pPara
);
214 pOutlineObj
= static_cast<SdrTextObj
*>( pPage
->GetPresObj(PRESOBJ_OUTLINE
) );
217 // create structuring text objects
218 OutlinerParaObject
* pOPO
= pOutl
->CreateParaObject(++nParaPos
, nChildCount
);
220 std::unique_ptr
<SdrOutliner
> pTempOutl
= SdrMakeOutliner(OutlinerMode::OutlineObject
, *mpDoc
);
221 pTempOutl
->SetText( *pOPO
);
223 sal_Int32 nParaCount2
= pTempOutl
->GetParagraphCount();
225 for( nPara
= 0; nPara
< nParaCount2
; nPara
++ )
227 pTempOutl
->SetDepth (
228 pTempOutl
->GetParagraph( nPara
),
229 pTempOutl
->GetDepth( nPara
) - 1);
233 pOPO
= pTempOutl
->CreateParaObject();
236 pOutlineObj
->SetOutlinerParaObject( pOPO
);
237 pOutlineObj
->SetEmptyPresObj(false);
239 // remove hard attributes (Flag to sal_True)
240 SfxItemSet
aAttr(mpDoc
->GetPool());
241 aAttr
.Put(XLineStyleItem(drawing::LineStyle_NONE
));
242 aAttr
.Put(XFillStyleItem(drawing::FillStyle_NONE
));
243 pOutlineObj
->SetMergedItemSet(aAttr
);
247 pPara
= pOutl
->GetParagraph( ++nParaPos
);
256 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE_PAGE
, SfxCallMode::SYNCHRON
| SfxCallMode::RECORD
);
260 } // end of namespace sd
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */