LibreOffice Module sc (master) 1
pfuncache.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <tools/multisel.hxx>
21#include <osl/diagnose.h>
22
23#include <pfuncache.hxx>
24#include <printfun.hxx>
25#include <docsh.hxx>
26#include <markdata.hxx>
27#include <prevloc.hxx>
28#include <utility>
29
31 ScPrintSelectionStatus aStatus ) :
32 aSelection(std::move( aStatus )),
33 pDocSh( pD ),
34 nTotalPages( 0 ),
35 bLocInitialized( false )
36{
37 // page count uses the stored cell widths for the printer anyway,
38 // so ScPrintFunc with the document's printer can be used to count
39
40 SfxPrinter* pPrinter = pDocSh->GetPrinter();
41
42 ScRange aRange;
43 const ScRange* pSelRange = nullptr;
44 if ( rMark.IsMarked() )
45 {
46 aRange = rMark.GetMarkArea();
47 pSelRange = &aRange;
48 }
49
50 ScDocument& rDoc = pDocSh->GetDocument();
51 SCTAB nTabCount = rDoc.GetTableCount();
52
53 // avoid repeated progress bars if row heights for all sheets are needed
54 if ( nTabCount > 1 && rMark.GetSelectCount() == nTabCount )
55 pDocSh->UpdatePendingRowHeights( nTabCount-1, true );
56
57 SCTAB nTab;
58 for ( nTab=0; nTab<nTabCount; nTab++ )
59 {
60 tools::Long nAttrPage = nTab > 0 ? nFirstAttr[nTab-1] : 1;
61
62 tools::Long nThisTab = 0;
63 if ( rMark.GetTableSelect( nTab ) )
64 {
65 ScPrintFunc aFunc( pDocSh, pPrinter, nTab, nAttrPage, 0, pSelRange, &aSelection.GetOptions() );
66 nThisTab = aFunc.GetTotalPages();
67 nFirstAttr.push_back( aFunc.GetFirstPageNo() ); // from page style or previous sheet
68 }
69 else
70 nFirstAttr.push_back( nAttrPage );
71
72 nPages.push_back( nThisTab );
73 nTotalPages += nThisTab;
74 }
75}
76
78{
79}
80
82{
83 if ( bLocInitialized )
84 return; // initialize only once
85
86 ScRange aRange;
87 const ScRange* pSelRange = nullptr;
88 if ( rMark.IsMarked() )
89 {
90 aRange = rMark.GetMarkArea();
91 pSelRange = &aRange;
92 }
93
94 tools::Long nRenderer = 0; // 0-based physical page number across sheets
95 tools::Long nTabStart = 0;
96
97 ScDocument& rDoc = pDocSh->GetDocument();
98 SCTAB nTabCount = rDoc.GetTableCount();
99 for (SCTAB nTab : rMark)
100 {
101 if (nTab >= nTabCount)
102 break;
103 ScPrintFunc aFunc( pDev, pDocSh, nTab, nFirstAttr[nTab], nTotalPages, pSelRange, &aSelection.GetOptions() );
104 aFunc.SetRenderFlag( true );
105
106 tools::Long nDisplayStart = GetDisplayStart( nTab );
107
108 for ( tools::Long nPage=0; nPage<nPages[nTab]; nPage++ )
109 {
110 Range aPageRange( nRenderer+1, nRenderer+1 );
111 MultiSelection aPage( aPageRange );
112 aPage.SetTotalRange( Range(0,RANGE_MAX) );
113 aPage.Select( aPageRange );
114
115 ScPreviewLocationData aLocData( &rDoc, pDev );
116 aFunc.DoPrint( aPage, nTabStart, nDisplayStart, false, &aLocData );
117
118 ScRange aCellRange;
119 tools::Rectangle aPixRect;
120 if ( aLocData.GetMainCellRange( aCellRange, aPixRect ) )
121 aLocations.emplace_back( nRenderer, aCellRange, aPixRect );
122
123 ++nRenderer;
124 }
125
126 nTabStart += nPages[nTab];
127 }
128
129 bLocInitialized = true;
130}
131
133{
134 auto aIter = std::find_if(aLocations.begin(), aLocations.end(),
135 [&rCell](const ScPrintPageLocation& rLoc) { return rLoc.aCellRange.Contains(rCell); });
136 if (aIter != aLocations.end())
137 {
138 rLocation = *aIter;
139 return true;
140 }
141 return false; // not found
142}
143
145{
146 return aSelection == rStatus;
147}
148
150{
151 ScDocument& rDoc = pDocSh->GetDocument();
152 SCTAB nTabCount = rDoc.GetTableCount();
153 SCTAB nTab = 0;
154 while ( nTab < nTabCount && nPage >= nPages[nTab] )
155 nPage -= nPages[nTab++];
156 if (nTab >= nTabCount)
157 nTab = nTabCount - 1;
158 return nTab;
159}
160
162{
163 tools::Long nRet = 0;
164 const SCTAB maxIndex = std::min(nTab, static_cast<SCTAB>(nPages.size()));
165 for ( SCTAB i=0; i<maxIndex; i++ )
166 nRet += nPages[i];
167 return nRet;
168}
169
171{
173
174 tools::Long nDisplayStart = 0;
175 ScDocument& rDoc = pDocSh->GetDocument();
176 for (SCTAB i=0; i<nTab; i++)
177 {
178 if ( rDoc.NeedPageResetAfterTab(i) )
179 nDisplayStart = 0;
180 else
181 {
182 if ( i < static_cast<SCTAB>(nPages.size()) )
183 nDisplayStart += nPages[i];
184 else
185 OSL_FAIL("nPages out of bounds, FIX IT!");
186 }
187 }
188 return nDisplayStart;
189}
190
191/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool Select(sal_Int32 nIndex, bool bSelect=true)
void SetTotalRange(const Range &rTotRange)
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
void UpdatePendingRowHeights(SCTAB nUpdateTab, bool bBefore=false)
Definition: docsh5.cxx:442
SfxPrinter * GetPrinter(bool bCreateIfNotExist=true)
Definition: docsh3.cxx:451
SC_DLLPUBLIC bool NeedPageResetAfterTab(SCTAB nTab) const
Definition: document.cxx:6340
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:297
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
const ScRange & GetMarkArea() const
Definition: markdata.hxx:83
bool GetTableSelect(SCTAB nTab) const
Definition: markdata.cxx:169
SCTAB GetSelectCount() const
Definition: markdata.cxx:180
bool IsMarked() const
Definition: markdata.hxx:80
bool GetMainCellRange(ScRange &rRange, tools::Rectangle &rPixRect) const
Definition: prevloc.cxx:703
std::vector< ScPrintPageLocation > aLocations
Definition: pfuncache.hxx:91
tools::Long nTotalPages
Definition: pfuncache.hxx:88
tools::Long GetTabStart(SCTAB nTab) const
Definition: pfuncache.cxx:161
std::vector< tools::Long > nFirstAttr
Definition: pfuncache.hxx:90
std::vector< tools::Long > nPages
Definition: pfuncache.hxx:89
tools::Long GetDisplayStart(SCTAB nTab) const
Definition: pfuncache.cxx:170
ScPrintFuncCache(ScDocShell *pD, const ScMarkData &rMark, ScPrintSelectionStatus aStatus)
Definition: pfuncache.cxx:30
ScPrintSelectionStatus aSelection
Definition: pfuncache.hxx:86
bool FindLocation(const ScAddress &rCell, ScPrintPageLocation &rLocation) const
Definition: pfuncache.cxx:132
SCTAB GetTabForPage(tools::Long nPage) const
Definition: pfuncache.cxx:149
void InitLocations(const ScMarkData &rMark, OutputDevice *pDev)
Definition: pfuncache.cxx:81
bool IsSameSelection(const ScPrintSelectionStatus &rStatus) const
Definition: pfuncache.cxx:144
ScDocShell * pDocSh
Definition: pfuncache.hxx:87
void SetRenderFlag(bool bFlag)
Definition: printfun.cxx:2408
tools::Long GetFirstPageNo() const
Definition: printfun.hxx:365
tools::Long DoPrint(const MultiSelection &rPageRanges, tools::Long nStartPage, tools::Long nDisplayStart, bool bDoPrint, ScPreviewLocationData *pLocationData)
Definition: printfun.cxx:2657
tools::Long GetTotalPages() const
Definition: printfun.hxx:367
Stores the selection in the ScPrintFuncCache so it is only used for the same selection again.
Definition: pfuncache.hxx:46
const ScPrintOptions & GetOptions() const
Definition: pfuncache.hxx:62
#define RANGE_MAX
int i
long Long
The range that is printed on a page (excluding repeated columns/rows), and its position on the page,...
Definition: pfuncache.hxx:69
sal_Int16 SCTAB
Definition: types.hxx:22