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>
31 #include "strings.hrc"
35 #include "Outliner.hxx"
36 #include "drawview.hxx"
37 #include "drawdoc.hxx"
38 #include "ViewShell.hxx"
39 #include "DrawDocShell.hxx"
40 #include "sdresid.hxx"
41 #include "optsitem.hxx"
43 #include <sfx2/dispatch.hxx>
44 #include <editeng/eeitem.hxx>
48 TYPEINIT1( FuExpandPage
, FuPoor
);
51 FuExpandPage::FuExpandPage (
57 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
61 FunctionReference
FuExpandPage::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
63 FunctionReference
xFunc( new FuExpandPage( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
64 xFunc
->DoExecute(rReq
);
68 void FuExpandPage::DoExecute( SfxRequest
& )
70 if ( mpView
&& mpView
->IsTextEdit() )
71 mpView
->SdrEndTextEdit();
73 // find selected page (only standard pages)
74 SdPage
* pActualPage
= NULL
;
76 sal_uInt16 nCount
= mpDoc
->GetSdPageCount(PK_STANDARD
);
78 while (!pActualPage
&& i
< nCount
)
80 if (mpDoc
->GetSdPage(i
, PK_STANDARD
)->IsSelected())
82 pActualPage
= mpDoc
->GetSdPage(i
, PK_STANDARD
);
90 ::sd::Outliner
* pOutl
=
91 new ::sd::Outliner( mpDoc
, OUTLINERMODE_OUTLINEOBJECT
);
92 pOutl
->SetUpdateMode(sal_False
);
93 pOutl
->EnableUndo(sal_False
);
96 pOutl
->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh
) );
98 pOutl
->SetDefTab( mpDoc
->GetDefaultTabulator() );
99 pOutl
->SetStyleSheetPool((SfxStyleSheetPool
*) mpDoc
->GetStyleSheetPool());
101 SetOfByte aVisibleLayers
= pActualPage
->TRG_GetMasterPageVisibleLayers();
102 sal_uInt16 nActualPageNum
= pActualPage
->GetPageNum();
103 SdPage
* pActualNotesPage
= (SdPage
*) mpDoc
->GetPage(nActualPageNum
+ 1);
104 SdrTextObj
* pActualOutline
= (SdrTextObj
*) pActualPage
->GetPresObj(PRESOBJ_OUTLINE
);
108 const bool bUndo
= mpView
->IsUndoEnabled();
111 mpView
->BegUndo(String(SdResId(STR_UNDO_EXPAND_PAGE
)));
113 // set current structuring-object into outliner
114 OutlinerParaObject
* pParaObj
= pActualOutline
->GetOutlinerParaObject();
115 pOutl
->SetText(*pParaObj
);
117 // remove hard paragraph- and character attributes
118 SfxItemSet
aEmptyEEAttr(mpDoc
->GetPool(), EE_ITEMS_START
, EE_ITEMS_END
);
119 sal_Int32 nParaCount1
= pOutl
->GetParagraphCount();
121 for (sal_Int32 nPara
= 0; nPara
< nParaCount1
; nPara
++)
123 pOutl
->QuickRemoveCharAttribs(nPara
);
124 pOutl
->SetParaAttribs(nPara
, aEmptyEEAttr
);
128 Paragraph
* pPara
= pOutl
->GetParagraph( 0 );
132 sal_Int32 nParaPos
= pOutl
->GetAbsPos( pPara
);
133 sal_Int16 nDepth
= pOutl
->GetDepth( nParaPos
);
136 // page with title & structuring!
137 SdPage
* pPage
= (SdPage
*) mpDoc
->AllocPage(sal_False
);
138 pPage
->SetSize(pActualPage
->GetSize() );
139 pPage
->SetBorder(pActualPage
->GetLftBorder(),
140 pActualPage
->GetUppBorder(),
141 pActualPage
->GetRgtBorder(),
142 pActualPage
->GetLwrBorder() );
143 pPage
->SetName(String());
145 // insert page after current page
146 mpDoc
->InsertPage(pPage
, nActualPageNum
+ nPos
);
150 mpView
->AddUndo(mpDoc
->GetSdrUndoFactory().CreateUndoNewPage(*pPage
));
152 // use MasterPage of the current page
153 pPage
->TRG_SetMasterPage(pActualPage
->TRG_GetMasterPage());
154 pPage
->SetLayoutName(pActualPage
->GetLayoutName());
155 pPage
->SetAutoLayout(AUTOLAYOUT_ENUM
, sal_True
);
156 pPage
->TRG_SetMasterPageVisibleLayers(aVisibleLayers
);
159 SdPage
* pNotesPage
= (SdPage
*) mpDoc
->AllocPage(sal_False
);
160 pNotesPage
->SetSize(pActualNotesPage
->GetSize());
161 pNotesPage
->SetBorder(pActualNotesPage
->GetLftBorder(),
162 pActualNotesPage
->GetUppBorder(),
163 pActualNotesPage
->GetRgtBorder(),
164 pActualNotesPage
->GetLwrBorder() );
165 pNotesPage
->SetPageKind(PK_NOTES
);
166 pNotesPage
->SetName(String());
168 // insert page after current page
169 mpDoc
->InsertPage(pNotesPage
, nActualPageNum
+ nPos
);
173 mpView
->AddUndo(mpDoc
->GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage
));
175 // use MasterPage of the current page
176 pNotesPage
->TRG_SetMasterPage(pActualNotesPage
->TRG_GetMasterPage());
177 pNotesPage
->SetLayoutName(pActualNotesPage
->GetLayoutName());
178 pNotesPage
->SetAutoLayout(pActualNotesPage
->GetAutoLayout(), sal_True
);
179 pNotesPage
->TRG_SetMasterPageVisibleLayers(aVisibleLayers
);
181 // create title text objects
182 SdrTextObj
* pTextObj
= (SdrTextObj
*) pPage
->GetPresObj(PRESOBJ_TITLE
);
184 OutlinerParaObject
* pOutlinerParaObject
= pOutl
->CreateParaObject( nParaPos
, 1);
185 pOutlinerParaObject
->SetOutlinerMode(OUTLINERMODE_TITLEOBJECT
);
187 if( pOutlinerParaObject
->GetDepth(0) != -1 )
189 SdrOutliner
* pTempOutl
= SdrMakeOutliner( OUTLINERMODE_TITLEOBJECT
, mpDoc
);
191 pTempOutl
->SetText( *pOutlinerParaObject
);
193 delete pOutlinerParaObject
;
195 pTempOutl
->SetDepth( pTempOutl
->GetParagraph( 0 ), -1 );
197 pOutlinerParaObject
= pTempOutl
->CreateParaObject();
201 pTextObj
->SetOutlinerParaObject(pOutlinerParaObject
);
203 pTextObj
->SetEmptyPresObj(sal_False
);
205 SfxStyleSheet
* pSheet
= pPage
->GetStyleSheetForPresObj(PRESOBJ_TITLE
);
206 pTextObj
->NbcSetStyleSheet(pSheet
, sal_False
);
208 sal_Int32 nChildCount
= pOutl
->GetChildCount(pPara
);
212 // create structuring text objects
213 SdrTextObj
* pOutlineObj
= (SdrTextObj
*) pPage
->GetPresObj(PRESOBJ_OUTLINE
);
214 pPara
= pOutl
->GetParagraph( ++nParaPos
);
216 OutlinerParaObject
* pOPO
= pOutl
->CreateParaObject( nParaPos
, nChildCount
);
218 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);
231 pOPO
= pTempOutl
->CreateParaObject();
234 pOutlineObj
->SetOutlinerParaObject( pOPO
);
235 pOutlineObj
->SetEmptyPresObj(sal_False
);
237 // remove hard attributes (Flag to sal_True)
238 SfxItemSet
aAttr(mpDoc
->GetPool());
239 aAttr
.Put(XLineStyleItem(XLINE_NONE
));
240 aAttr
.Put(XFillStyleItem(XFILL_NONE
));
241 pOutlineObj
->SetMergedItemSet(aAttr
);
245 pPara
= pOutl
->GetParagraph( ++nParaPos
);
254 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE_PAGE
, SFX_CALLMODE_SYNCHRON
| SFX_CALLMODE_RECORD
);
258 } // end of namespace sd
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */