Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <tools/multisel.hxx>
30 : :
31 : : #include "pfuncache.hxx"
32 : : #include "printfun.hxx"
33 : : #include "docsh.hxx"
34 : : #include "markdata.hxx"
35 : : #include "prevloc.hxx"
36 : :
37 : : //------------------------------------------------------------------------
38 : :
39 : 0 : ScPrintFuncCache::ScPrintFuncCache( ScDocShell* pD, const ScMarkData& rMark,
40 : : const ScPrintSelectionStatus& rStatus ) :
41 : : aSelection( rStatus ),
42 : : pDocSh( pD ),
43 : : nTotalPages( 0 ),
44 : : nPages(),
45 : : nFirstAttr(),
46 [ # # ][ # # ]: 0 : bLocInitialized( false )
[ # # ]
47 : : {
48 : : // page count uses the stored cell widths for the printer anyway,
49 : : // so ScPrintFunc with the document's printer can be used to count
50 : :
51 [ # # ]: 0 : SfxPrinter* pPrinter = pDocSh->GetPrinter();
52 : :
53 : 0 : ScRange aRange;
54 : 0 : const ScRange* pSelRange = NULL;
55 [ # # ]: 0 : if ( rMark.IsMarked() )
56 : : {
57 [ # # ]: 0 : rMark.GetMarkArea( aRange );
58 : 0 : pSelRange = &aRange;
59 : : }
60 : :
61 : 0 : ScDocument* pDoc = pDocSh->GetDocument();
62 [ # # ]: 0 : SCTAB nTabCount = pDoc->GetTableCount();
63 : :
64 : : // avoid repeated progress bars if row heights for all sheets are needed
65 [ # # ][ # # ]: 0 : if ( nTabCount > 1 && rMark.GetSelectCount() == nTabCount )
[ # # ][ # # ]
66 [ # # ]: 0 : pDocSh->UpdatePendingRowHeights( nTabCount-1, true );
67 : :
68 : : SCTAB nTab;
69 [ # # ]: 0 : for ( nTab=0; nTab<nTabCount; nTab++ )
70 : : {
71 [ # # ][ # # ]: 0 : long nAttrPage = nTab > 0 ? nFirstAttr[nTab-1] : 1;
72 : :
73 : 0 : long nThisTab = 0;
74 [ # # ][ # # ]: 0 : if ( rMark.GetTableSelect( nTab ) )
75 : : {
76 [ # # ]: 0 : ScPrintFunc aFunc( pDocSh, pPrinter, nTab, nAttrPage, 0, pSelRange, &aSelection.GetOptions() );
77 : 0 : nThisTab = aFunc.GetTotalPages();
78 [ # # ][ # # ]: 0 : nFirstAttr.push_back( aFunc.GetFirstPageNo() ); // from page style or previous sheet
79 : : }
80 : : else
81 [ # # ]: 0 : nFirstAttr.push_back( nAttrPage );
82 : :
83 [ # # ]: 0 : nPages.push_back( nThisTab );
84 : 0 : nTotalPages += nThisTab;
85 : : }
86 : 0 : }
87 : :
88 : 0 : ScPrintFuncCache::~ScPrintFuncCache()
89 : : {
90 : 0 : }
91 : :
92 : 0 : void ScPrintFuncCache::InitLocations( const ScMarkData& rMark, OutputDevice* pDev )
93 : : {
94 [ # # ]: 0 : if ( bLocInitialized )
95 : 0 : return; // initialize only once
96 : :
97 : 0 : ScRange aRange;
98 : 0 : const ScRange* pSelRange = NULL;
99 [ # # ]: 0 : if ( rMark.IsMarked() )
100 : : {
101 [ # # ]: 0 : rMark.GetMarkArea( aRange );
102 : 0 : pSelRange = &aRange;
103 : : }
104 : :
105 : 0 : long nRenderer = 0; // 0-based physical page number across sheets
106 : 0 : long nTabStart = 0;
107 : :
108 : 0 : ScDocument* pDoc = pDocSh->GetDocument();
109 [ # # ]: 0 : SCTAB nTabCount = pDoc->GetTableCount();
110 [ # # ][ # # ]: 0 : ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
111 [ # # ][ # # ]: 0 : for (; itr != itrEnd && (*itr) < nTabCount; ++itr)
[ # # ][ # # ]
[ # # ][ # # ]
112 : : {
113 [ # # ]: 0 : SCTAB nTab = *itr;
114 [ # # ][ # # ]: 0 : ScPrintFunc aFunc( pDev, pDocSh, nTab, nFirstAttr[nTab], nTotalPages, pSelRange, &aSelection.GetOptions() );
115 [ # # ]: 0 : aFunc.SetRenderFlag( sal_True );
116 : :
117 [ # # ]: 0 : long nDisplayStart = GetDisplayStart( nTab );
118 : :
119 [ # # ][ # # ]: 0 : for ( long nPage=0; nPage<nPages[nTab]; nPage++ )
120 : : {
121 : 0 : Range aPageRange( nRenderer+1, nRenderer+1 );
122 [ # # ]: 0 : MultiSelection aPage( aPageRange );
123 [ # # ]: 0 : aPage.SetTotalRange( Range(0,RANGE_MAX) );
124 [ # # ]: 0 : aPage.Select( aPageRange );
125 : :
126 [ # # ]: 0 : ScPreviewLocationData aLocData( pDoc, pDev );
127 [ # # ]: 0 : aFunc.DoPrint( aPage, nTabStart, nDisplayStart, false, &aLocData );
128 : :
129 : 0 : ScRange aCellRange;
130 [ # # ]: 0 : Rectangle aPixRect;
131 [ # # ][ # # ]: 0 : if ( aLocData.GetMainCellRange( aCellRange, aPixRect ) )
132 [ # # ]: 0 : aLocations.push_back( ScPrintPageLocation( nRenderer, aCellRange, aPixRect ) );
133 : :
134 : 0 : ++nRenderer;
135 [ # # ][ # # ]: 0 : }
136 : :
137 [ # # ]: 0 : nTabStart += nPages[nTab];
138 [ # # ]: 0 : }
139 : :
140 : 0 : bLocInitialized = true;
141 : : }
142 : :
143 : 0 : bool ScPrintFuncCache::FindLocation( const ScAddress& rCell, ScPrintPageLocation& rLocation ) const
144 : : {
145 [ # # ][ # # ]: 0 : for ( std::vector<ScPrintPageLocation>::const_iterator aIter(aLocations.begin());
[ # # ]
146 : 0 : aIter != aLocations.end(); aIter++ )
147 : : {
148 [ # # ]: 0 : if ( aIter->aCellRange.In( rCell ) )
149 : : {
150 : 0 : rLocation = *aIter;
151 : 0 : return true;
152 : : }
153 : : }
154 : 0 : return false; // not found
155 : : }
156 : :
157 : 0 : sal_Bool ScPrintFuncCache::IsSameSelection( const ScPrintSelectionStatus& rStatus ) const
158 : : {
159 : 0 : return aSelection == rStatus;
160 : : }
161 : :
162 : 0 : SCTAB ScPrintFuncCache::GetTabForPage( long nPage ) const
163 : : {
164 : 0 : ScDocument* pDoc = pDocSh->GetDocument();
165 : 0 : SCTAB nTabCount = pDoc->GetTableCount();
166 : 0 : SCTAB nTab = 0;
167 [ # # ][ # # ]: 0 : while ( nTab < nTabCount && nPage >= nPages[nTab] )
[ # # ]
168 : 0 : nPage -= nPages[nTab++];
169 [ # # ]: 0 : if (nTab >= nTabCount)
170 : 0 : nTab = nTabCount - 1;
171 : 0 : return nTab;
172 : : }
173 : :
174 : 0 : long ScPrintFuncCache::GetTabStart( SCTAB nTab ) const
175 : : {
176 : 0 : long nRet = 0;
177 [ # # ][ # # ]: 0 : for ( SCTAB i=0; i<nTab&& i < static_cast<SCTAB>(nPages.size()); i++ )
[ # # ]
178 : 0 : nRet += nPages[i];
179 : 0 : return nRet;
180 : : }
181 : :
182 : 0 : long ScPrintFuncCache::GetDisplayStart( SCTAB nTab ) const
183 : : {
184 : : //! merge with lcl_GetDisplayStart in preview?
185 : :
186 : 0 : long nDisplayStart = 0;
187 : 0 : ScDocument* pDoc = pDocSh->GetDocument();
188 [ # # ]: 0 : for (SCTAB i=0; i<nTab; i++)
189 : : {
190 [ # # ]: 0 : if ( pDoc->NeedPageResetAfterTab(i) )
191 : 0 : nDisplayStart = 0;
192 : : else
193 : : {
194 [ # # ]: 0 : if ( i < static_cast<SCTAB>(nPages.size()) )
195 : 0 : nDisplayStart += nPages[i];
196 : : else
197 : : OSL_FAIL("nPages out of bounds, FIX IT!");
198 : : }
199 : : }
200 : 0 : return nDisplayStart;
201 : : }
202 : :
203 : :
204 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|