update dev300-m58
[ooovba.git] / sc / source / ui / view / pfuncache.cxx
blob1f18e374a9dcf1dc2c662aacaec0b5b896d10382
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pfuncache.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include <tools/multisel.hxx>
40 #include "pfuncache.hxx"
41 #include "printfun.hxx"
42 #include "docsh.hxx"
43 #include "markdata.hxx"
44 #include "prevloc.hxx"
46 //------------------------------------------------------------------------
48 ScPrintFuncCache::ScPrintFuncCache( ScDocShell* pD, const ScMarkData& rMark,
49 const ScPrintSelectionStatus& rStatus ) :
50 aSelection( rStatus ),
51 pDocSh( pD ),
52 nTotalPages( 0 ),
53 bLocInitialized( false )
55 // page count uses the stored cell widths for the printer anyway,
56 // so ScPrintFunc with the document's printer can be used to count
58 SfxPrinter* pPrinter = pDocSh->GetPrinter();
60 ScRange aRange;
61 const ScRange* pSelRange = NULL;
62 if ( rMark.IsMarked() )
64 rMark.GetMarkArea( aRange );
65 pSelRange = &aRange;
68 ScDocument* pDoc = pDocSh->GetDocument();
69 SCTAB nTabCount = pDoc->GetTableCount();
70 SCTAB nTab;
71 for ( nTab=0; nTab<nTabCount; nTab++ )
73 long nAttrPage = nTab > 0 ? nFirstAttr[nTab-1] : 1;
75 long nThisTab = 0;
76 if ( rMark.GetTableSelect( nTab ) )
78 ScPrintFunc aFunc( pDocSh, pPrinter, nTab, nAttrPage, 0, pSelRange );
79 nThisTab = aFunc.GetTotalPages();
80 nFirstAttr[nTab] = aFunc.GetFirstPageNo(); // from page style or previous sheet
82 else
83 nFirstAttr[nTab] = nAttrPage;
85 nPages[nTab] = nThisTab;
86 nTotalPages += nThisTab;
90 ScPrintFuncCache::~ScPrintFuncCache()
94 void ScPrintFuncCache::InitLocations( const ScMarkData& rMark, OutputDevice* pDev )
96 if ( bLocInitialized )
97 return; // initialize only once
99 ScRange aRange;
100 const ScRange* pSelRange = NULL;
101 if ( rMark.IsMarked() )
103 rMark.GetMarkArea( aRange );
104 pSelRange = &aRange;
107 long nRenderer = 0; // 0-based physical page number across sheets
108 long nTabStart = 0;
110 ScDocument* pDoc = pDocSh->GetDocument();
111 SCTAB nTabCount = pDoc->GetTableCount();
112 for ( SCTAB nTab=0; nTab<nTabCount; nTab++ )
114 if ( rMark.GetTableSelect( nTab ) )
116 ScPrintFunc aFunc( pDev, pDocSh, nTab, nFirstAttr[nTab], nTotalPages, pSelRange );
117 aFunc.SetRenderFlag( TRUE );
119 long nDisplayStart = GetDisplayStart( nTab );
121 for ( long nPage=0; nPage<nPages[nTab]; nPage++ )
123 Range aPageRange( nRenderer+1, nRenderer+1 );
124 MultiSelection aPage( aPageRange );
125 aPage.SetTotalRange( Range(0,RANGE_MAX) );
126 aPage.Select( aPageRange );
128 ScPreviewLocationData aLocData( pDoc, pDev );
129 aFunc.DoPrint( aPage, nTabStart, nDisplayStart, FALSE, NULL, &aLocData );
131 ScRange aCellRange;
132 Rectangle aPixRect;
133 if ( aLocData.GetMainCellRange( aCellRange, aPixRect ) )
134 aLocations.push_back( ScPrintPageLocation( nRenderer, aCellRange, aPixRect ) );
136 ++nRenderer;
139 nTabStart += nPages[nTab];
143 bLocInitialized = true;
146 bool ScPrintFuncCache::FindLocation( const ScAddress& rCell, ScPrintPageLocation& rLocation ) const
148 for ( std::vector<ScPrintPageLocation>::const_iterator aIter(aLocations.begin());
149 aIter != aLocations.end(); aIter++ )
151 if ( aIter->aCellRange.In( rCell ) )
153 rLocation = *aIter;
154 return true;
157 return false; // not found
160 BOOL ScPrintFuncCache::IsSameSelection( const ScPrintSelectionStatus& rStatus ) const
162 return aSelection == rStatus;
165 SCTAB ScPrintFuncCache::GetTabForPage( long nPage ) const
167 ScDocument* pDoc = pDocSh->GetDocument();
168 SCTAB nTabCount = pDoc->GetTableCount();
169 SCTAB nTab = 0;
170 while ( nTab < nTabCount && nPage >= nPages[nTab] )
171 nPage -= nPages[nTab++];
172 return nTab;
175 long ScPrintFuncCache::GetTabStart( SCTAB nTab ) const
177 long nRet = 0;
178 for ( SCTAB i=0; i<nTab; i++ )
179 nRet += nPages[i];
180 return nRet;
183 long ScPrintFuncCache::GetDisplayStart( SCTAB nTab ) const
185 //! merge with lcl_GetDisplayStart in preview?
187 long nDisplayStart = 0;
188 ScDocument* pDoc = pDocSh->GetDocument();
189 for (SCTAB i=0; i<nTab; i++)
191 if ( pDoc->NeedPageResetAfterTab(i) )
192 nDisplayStart = 0;
193 else
194 nDisplayStart += nPages[i];
196 return nDisplayStart;