bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fusumry.cxx
blob4009e31c7099265d4193e958e95d8a5fcf5cf1b0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "fusumry.hxx"
21 #include <editeng/eeitem.hxx>
22 #include <svx/svdotext.hxx>
23 #include <svx/svdundo.hxx>
24 #include <sfx2/printer.hxx>
25 #include <editeng/outlobj.hxx>
27 #include "strings.hrc"
29 #include "pres.hxx"
30 #include "View.hxx"
31 #include "sdpage.hxx"
32 #include "Outliner.hxx"
33 #include "drawview.hxx"
34 #include "drawdoc.hxx"
35 #include "ViewShell.hxx"
36 #include "DrawDocShell.hxx"
37 #include "sdresid.hxx"
38 #include "optsitem.hxx"
39 #include "DrawViewShell.hxx"
41 namespace sd {
43 TYPEINIT1( FuSummaryPage, FuPoor );
45 FuSummaryPage::FuSummaryPage (
46 ViewShell* pViewSh,
47 ::sd::Window* pWin,
48 ::sd::View* pView,
49 SdDrawDocument* pDoc,
50 SfxRequest& rReq)
51 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
55 FunctionReference FuSummaryPage::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
57 FunctionReference xFunc( new FuSummaryPage( pViewSh, pWin, pView, pDoc, rReq ) );
58 xFunc->DoExecute(rReq);
59 return xFunc;
62 void FuSummaryPage::DoExecute( SfxRequest& )
64 ::sd::Outliner* pOutl = NULL;
65 SdPage* pSummaryPage = NULL;
66 sal_uInt16 i = 0;
67 sal_uInt16 nFirstPage = SDRPAGE_NOTFOUND;
68 sal_uInt16 nSelectedPages = 0;
69 sal_uInt16 nCount = mpDoc->GetSdPageCount(PK_STANDARD);
71 while (i < nCount && nSelectedPages <= 1)
73 /* How many pages are selected?
74 exactly one: pool everything from this page
75 otherwise: only pool the selected pages */
76 SdPage* pActualPage = mpDoc->GetSdPage(i, PK_STANDARD);
78 if (pActualPage->IsSelected())
80 if (nFirstPage == SDRPAGE_NOTFOUND)
82 nFirstPage = i;
85 nSelectedPages++;
88 i++;
91 bool bBegUndo = false;
93 SfxStyleSheet* pStyle = NULL;
95 for (i = nFirstPage; i < nCount; i++)
97 SdPage* pActualPage = mpDoc->GetSdPage(i, PK_STANDARD);
99 if (nSelectedPages <= 1 || pActualPage->IsSelected())
101 SdPage* pActualNotesPage = mpDoc->GetSdPage(i, PK_NOTES);
102 SdrTextObj* pTextObj = (SdrTextObj*) pActualPage->GetPresObj(PRESOBJ_TITLE);
104 if (pTextObj && !pTextObj->IsEmptyPresObj())
106 if (!pSummaryPage)
108 // insert "table of content"-page and create outliner
109 const bool bUndo = mpView->IsUndoEnabled();
111 if( bUndo )
113 mpView->BegUndo(String(SdResId(STR_UNDO_SUMMARY_PAGE)));
114 bBegUndo = true;
117 SetOfByte aVisibleLayers = pActualPage->TRG_GetMasterPageVisibleLayers();
119 // page with title & structuring!
120 pSummaryPage = (SdPage*) mpDoc->AllocPage(sal_False);
121 pSummaryPage->SetSize(pActualPage->GetSize() );
122 pSummaryPage->SetBorder(pActualPage->GetLftBorder(),
123 pActualPage->GetUppBorder(),
124 pActualPage->GetRgtBorder(),
125 pActualPage->GetLwrBorder() );
127 // insert page at the back
128 mpDoc->InsertPage(pSummaryPage, nCount * 2 + 1);
129 if( bUndo )
130 mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pSummaryPage));
132 // use MasterPage of the current page
133 pSummaryPage->TRG_SetMasterPage(pActualPage->TRG_GetMasterPage());
134 pSummaryPage->SetLayoutName(pActualPage->GetLayoutName());
135 pSummaryPage->SetAutoLayout(AUTOLAYOUT_ENUM, sal_True);
136 pSummaryPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
137 pSummaryPage->setHeaderFooterSettings(pActualPage->getHeaderFooterSettings());
139 // notes-page
140 SdPage* pNotesPage = (SdPage*) mpDoc->AllocPage(sal_False);
141 pNotesPage->SetSize(pActualNotesPage->GetSize());
142 pNotesPage->SetBorder(pActualNotesPage->GetLftBorder(),
143 pActualNotesPage->GetUppBorder(),
144 pActualNotesPage->GetRgtBorder(),
145 pActualNotesPage->GetLwrBorder() );
146 pNotesPage->SetPageKind(PK_NOTES);
148 // insert page at the back
149 mpDoc->InsertPage(pNotesPage, nCount * 2 + 2);
151 if( bUndo )
152 mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage));
154 // use MasterPage of the current page
155 pNotesPage->TRG_SetMasterPage(pActualNotesPage->TRG_GetMasterPage());
156 pNotesPage->SetLayoutName(pActualNotesPage->GetLayoutName());
157 pNotesPage->SetAutoLayout(pActualNotesPage->GetAutoLayout(), sal_True);
158 pNotesPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
159 pNotesPage->setHeaderFooterSettings(pActualNotesPage->getHeaderFooterSettings());
161 pOutl = new ::sd::Outliner( mpDoc, OUTLINERMODE_OUTLINEOBJECT );
162 pOutl->SetUpdateMode(sal_False);
163 pOutl->EnableUndo(sal_False);
165 if (mpDocSh)
166 pOutl->SetRefDevice(SD_MOD()->GetRefDevice( *mpDocSh ));
168 pOutl->SetDefTab( mpDoc->GetDefaultTabulator() );
169 pOutl->SetStyleSheetPool((SfxStyleSheetPool*) mpDoc->GetStyleSheetPool());
170 pStyle = pSummaryPage->GetStyleSheetForPresObj( PRESOBJ_OUTLINE );
171 pOutl->SetStyleSheet( 0, pStyle );
174 // add text
175 OutlinerParaObject* pParaObj = pTextObj->GetOutlinerParaObject();
176 // #118876#, check if the OutlinerParaObject is created successfully
177 if( pParaObj )
179 pParaObj->SetOutlinerMode( OUTLINERMODE_OUTLINEOBJECT );
180 pOutl->AddText(*pParaObj);
186 if (pSummaryPage)
188 SdrTextObj* pTextObj = (SdrTextObj*) pSummaryPage->GetPresObj(PRESOBJ_OUTLINE);
190 // remove hard break- and character attributes
191 SfxItemSet aEmptyEEAttr(mpDoc->GetPool(), EE_ITEMS_START, EE_ITEMS_END);
192 sal_Int32 nParaCount = pOutl->GetParagraphCount();
194 for (sal_Int32 nPara = 0; nPara < nParaCount; nPara++)
196 pOutl->SetStyleSheet( nPara, pStyle );
197 pOutl->QuickRemoveCharAttribs(nPara);
198 pOutl->SetParaAttribs(nPara, aEmptyEEAttr);
199 pOutl->SetDepth(pOutl->GetParagraph(nPara), 0);
202 pTextObj->SetOutlinerParaObject( pOutl->CreateParaObject() );
203 pTextObj->SetEmptyPresObj(sal_False);
205 // remove hard attributes (Flag to sal_True)
206 SfxItemSet aAttr(mpDoc->GetPool());
207 aAttr.Put(XLineStyleItem(XLINE_NONE));
208 aAttr.Put(XFillStyleItem(XFILL_NONE));
209 pTextObj->SetMergedItemSet(aAttr);
211 if( bBegUndo )
212 mpView->EndUndo();
213 delete pOutl;
215 DrawViewShell* pDrawViewShell= dynamic_cast< DrawViewShell* >( mpViewShell );
216 if(pDrawViewShell)
218 pDrawViewShell->SwitchPage( (pSummaryPage->GetPageNum() - 1) / 2);
224 } // end of namespace sd
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */