xref: /aoo41x/main/sc/source/core/data/table5.cxx (revision 3d762826)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19b3f79822SAndrew Rist  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "scitems.hxx"
30cdf0e10cSrcweir #include "collect.hxx"
31cdf0e10cSrcweir #include "attrib.hxx"
32cdf0e10cSrcweir #include "patattr.hxx"
33cdf0e10cSrcweir #include "docpool.hxx"
34cdf0e10cSrcweir #include "cell.hxx"
35cdf0e10cSrcweir #include "table.hxx"
36cdf0e10cSrcweir #include "column.hxx"
37cdf0e10cSrcweir #include "document.hxx"
38cdf0e10cSrcweir #include "drwlayer.hxx"
39cdf0e10cSrcweir #include "olinetab.hxx"
40cdf0e10cSrcweir #include "userlist.hxx"
41cdf0e10cSrcweir #include "stlsheet.hxx"
42cdf0e10cSrcweir #include "global.hxx"
43cdf0e10cSrcweir #include "rechead.hxx"
44cdf0e10cSrcweir #include "stlpool.hxx"
45cdf0e10cSrcweir #include "stlsheet.hxx"
46cdf0e10cSrcweir #include "brdcst.hxx"
47cdf0e10cSrcweir #include "tabprotection.hxx"
48cdf0e10cSrcweir #include "globstr.hrc"
49cdf0e10cSrcweir #include "segmenttree.hxx"
50cdf0e10cSrcweir #include <com/sun/star/sheet/TablePageBreakData.hpp>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #include <algorithm>
53cdf0e10cSrcweir #include <limits>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
56cdf0e10cSrcweir using ::com::sun::star::sheet::TablePageBreakData;
57cdf0e10cSrcweir using ::std::set;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
60cdf0e10cSrcweir 
61cdf0e10cSrcweir #define GET_SCALEVALUE(set,id) 	((const SfxUInt16Item&)(set.Get( id ))).GetValue()
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 
UpdatePageBreaks(const ScRange * pUserArea)64cdf0e10cSrcweir void ScTable::UpdatePageBreaks( const ScRange* pUserArea )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	if ( pDocument->IsImportingXML() )
67cdf0e10cSrcweir 		return;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     // pUserArea != NULL -> print area is specified.  We need to force-update
70cdf0e10cSrcweir     // the page breaks.
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     if (!pUserArea)
73cdf0e10cSrcweir     {
74cdf0e10cSrcweir         if (!bPageSizeValid)
75cdf0e10cSrcweir             return;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir         if (mbPageBreaksValid)
78cdf0e10cSrcweir             return;
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	SfxStyleSheetBase* pStyle = pDocument->GetStyleSheetPool()->
82cdf0e10cSrcweir 									Find( aPageStyle, SFX_STYLE_FAMILY_PAGE );
83cdf0e10cSrcweir 	if ( !pStyle )
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		DBG_ERROR("UpdatePageBreaks: Style nicht gefunden");
86cdf0e10cSrcweir 		return;
87cdf0e10cSrcweir 	}
88cdf0e10cSrcweir 	SfxItemSet* pStyleSet = &pStyle->GetItemSet();
89cdf0e10cSrcweir 	const SfxPoolItem* pItem;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	SCCOL nX;
92cdf0e10cSrcweir 	SCCOL nStartCol = 0;
93cdf0e10cSrcweir 	SCROW nStartRow = 0;
94cdf0e10cSrcweir 	SCCOL nEndCol = MAXCOL;
95cdf0e10cSrcweir 	SCROW nEndRow = MAXROW;
96cdf0e10cSrcweir 	if (pUserArea)
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 		nStartCol = pUserArea->aStart.Col();
99cdf0e10cSrcweir 		nStartRow = pUserArea->aStart.Row();
100cdf0e10cSrcweir 		nEndCol = pUserArea->aEnd.Col();
101cdf0e10cSrcweir 		nEndRow = pUserArea->aEnd.Row();
102cdf0e10cSrcweir 	}
103cdf0e10cSrcweir 	else
104cdf0e10cSrcweir 	{
105cdf0e10cSrcweir 		sal_uInt16 nAreaCount = GetPrintRangeCount();
106cdf0e10cSrcweir 		if ( nAreaCount > 1 )
107cdf0e10cSrcweir 		{
108cdf0e10cSrcweir 			//	bei mehreren Bereichen nichts anzeigen:
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 			for (nX=0; nX<MAXCOL; nX++)
111cdf0e10cSrcweir                 RemoveColBreak(nX, true, false);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir             RemoveRowPageBreaks(0, MAXROW-1);
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 			return;
116cdf0e10cSrcweir 		}
117cdf0e10cSrcweir 		else if ( nAreaCount == 1 )
118cdf0e10cSrcweir 		{
119cdf0e10cSrcweir 			const ScRange* pArea = GetPrintRange( 0 );
120cdf0e10cSrcweir 			if (pArea)
121cdf0e10cSrcweir 			{
122cdf0e10cSrcweir 				nStartCol = pArea->aStart.Col();
123cdf0e10cSrcweir 				nStartRow = pArea->aStart.Row();
124cdf0e10cSrcweir 				nEndCol = pArea->aEnd.Col();
125cdf0e10cSrcweir 				nEndRow = pArea->aEnd.Row();
126cdf0e10cSrcweir 			}
127cdf0e10cSrcweir 		}			// sonst alles
128cdf0e10cSrcweir 	}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     // get bSkipColBreaks/bSkipRowBreaks flags:
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     bool bSkipColBreaks = false;
133cdf0e10cSrcweir     bool bSkipRowBreaks = false;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	if ( pStyleSet->GetItemState( ATTR_PAGE_SCALETOPAGES, sal_False, &pItem ) == SFX_ITEM_SET )
136cdf0e10cSrcweir 	{
137cdf0e10cSrcweir 		DBG_ASSERT( pItem->ISA(SfxUInt16Item), "falsches Item" );
138cdf0e10cSrcweir         bSkipColBreaks = bSkipRowBreaks = ( ((const SfxUInt16Item*)pItem)->GetValue() > 0 );
139cdf0e10cSrcweir 	}
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     if ( !bSkipColBreaks && pStyleSet->GetItemState(ATTR_PAGE_SCALETO, sal_False, &pItem) == SFX_ITEM_SET )
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         // #i54993# when fitting to width or height, ignore only manual breaks in that direction
144cdf0e10cSrcweir         const ScPageScaleToItem* pScaleToItem = static_cast<const ScPageScaleToItem*>(pItem);
145cdf0e10cSrcweir         if ( pScaleToItem->GetWidth() > 0 )
146cdf0e10cSrcweir             bSkipColBreaks = true;
147cdf0e10cSrcweir         if ( pScaleToItem->GetHeight() > 0 )
148cdf0e10cSrcweir             bSkipRowBreaks = true;
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	//--------------------------------------------------------------------------
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	long nPageSizeX = aPageSizeTwips.Width();
154cdf0e10cSrcweir 	long nPageSizeY = aPageSizeTwips.Height();
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 		//	Anfang: Breaks loeschen
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	for (nX=0; nX<nStartCol; nX++)
159cdf0e10cSrcweir         RemoveColBreak(nX, true, false);
160cdf0e10cSrcweir     RemoveRowPageBreaks(0, nStartRow-1);
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	if (nStartCol > 0)
163cdf0e10cSrcweir         SetColBreak(nStartCol, true, false);  // AREABREAK
164cdf0e10cSrcweir 	if (nStartRow > 0)
165cdf0e10cSrcweir         SetRowBreak(nStartRow, true, false);  // AREABREAK
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 		//	Mittelteil: Breaks verteilen
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	sal_Bool bRepeatCol = ( nRepeatStartX != SCCOL_REPEAT_NONE );
170cdf0e10cSrcweir 	sal_Bool bColFound = sal_False;
171cdf0e10cSrcweir 	long nSizeX = 0;
172cdf0e10cSrcweir 	for (nX=nStartCol; nX<=nEndCol; nX++)
173cdf0e10cSrcweir 	{
174cdf0e10cSrcweir 		sal_Bool bStartOfPage = sal_False;
175cdf0e10cSrcweir 		long nThisX = ColHidden(nX) ? 0 : pColWidth[nX];
176cdf0e10cSrcweir         bool bManualBreak = HasColManualBreak(nX);
177cdf0e10cSrcweir         if ( (nSizeX+nThisX > nPageSizeX) || (bManualBreak && !bSkipColBreaks) )
178cdf0e10cSrcweir 		{
179cdf0e10cSrcweir             SetColBreak(nX, true, false);
180cdf0e10cSrcweir 			nSizeX = 0;
181cdf0e10cSrcweir 			bStartOfPage = sal_True;
182cdf0e10cSrcweir 		}
183cdf0e10cSrcweir 		else if (nX != nStartCol)
184cdf0e10cSrcweir             RemoveColBreak(nX, true, false);
185cdf0e10cSrcweir 		else
186cdf0e10cSrcweir 			bStartOfPage = sal_True;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 		if ( bStartOfPage && bRepeatCol && nX>nRepeatStartX && !bColFound )
189cdf0e10cSrcweir 		{
190cdf0e10cSrcweir 			// subtract size of repeat columns from page size
191cdf0e10cSrcweir 			for (SCCOL i=nRepeatStartX; i<=nRepeatEndX; i++)
192cdf0e10cSrcweir 				nPageSizeX -= ColHidden(i) ? 0 : pColWidth[i];
193cdf0e10cSrcweir 			while (nX<=nRepeatEndX)
194cdf0e10cSrcweir                 RemoveColBreak(++nX, true, false);
195cdf0e10cSrcweir 			bColFound = sal_True;
196cdf0e10cSrcweir 		}
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 		nSizeX += nThisX;
199cdf0e10cSrcweir 	}
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     // Remove all page breaks in range.
202cdf0e10cSrcweir     RemoveRowPageBreaks(nStartRow+1, nEndRow);
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     // And set new page breaks.
205cdf0e10cSrcweir 	sal_Bool bRepeatRow = ( nRepeatStartY != SCROW_REPEAT_NONE );
206cdf0e10cSrcweir 	sal_Bool bRowFound = sal_False;
207cdf0e10cSrcweir 	long nSizeY = 0;
208cdf0e10cSrcweir     ScFlatBoolRowSegments::ForwardIterator aIterHidden(*mpHiddenRows);
209cdf0e10cSrcweir     ScFlatUInt16RowSegments::ForwardIterator aIterHeights(*mpRowHeights);
210cdf0e10cSrcweir     SCROW nNextManualBreak = GetNextManualBreak(nStartRow); // -1 => no more manual breaks
211cdf0e10cSrcweir     for (SCROW nY = nStartRow; nY <= nEndRow; ++nY)
212cdf0e10cSrcweir     {
213cdf0e10cSrcweir 		sal_Bool bStartOfPage = sal_False;
214cdf0e10cSrcweir         bool bThisRowHidden = false;
215cdf0e10cSrcweir         aIterHidden.getValue(nY, bThisRowHidden);
216cdf0e10cSrcweir         long nThisY = 0;
217cdf0e10cSrcweir         if (!bThisRowHidden)
218cdf0e10cSrcweir         {
219cdf0e10cSrcweir             sal_uInt16 nTmp;
220cdf0e10cSrcweir             aIterHeights.getValue(nY, nTmp);
221cdf0e10cSrcweir             nThisY = static_cast<long>(nTmp);
222cdf0e10cSrcweir         }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir         bool bManualBreak = false;
225cdf0e10cSrcweir         if (nNextManualBreak >= 0)
226cdf0e10cSrcweir         {
227cdf0e10cSrcweir             bManualBreak = (nY == nNextManualBreak);
228cdf0e10cSrcweir             if (nY >= nNextManualBreak)
229cdf0e10cSrcweir                 // Query the next menual break position.
230cdf0e10cSrcweir                 nNextManualBreak = GetNextManualBreak(nY+1);
231cdf0e10cSrcweir         }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 		if ( (nSizeY+nThisY > nPageSizeY) || (bManualBreak && !bSkipRowBreaks) )
234cdf0e10cSrcweir 		{
235cdf0e10cSrcweir             SetRowBreak(nY, true, false);
236cdf0e10cSrcweir 			nSizeY = 0;
237cdf0e10cSrcweir 			bStartOfPage = sal_True;
238cdf0e10cSrcweir 		}
239cdf0e10cSrcweir 		else if (nY != nStartRow)
240cdf0e10cSrcweir 			; // page break already removed
241cdf0e10cSrcweir 		else
242cdf0e10cSrcweir 			bStartOfPage = sal_True;
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 		if ( bStartOfPage && bRepeatRow && nY>nRepeatStartY && !bRowFound )
245cdf0e10cSrcweir 		{
246cdf0e10cSrcweir 			// subtract size of repeat rows from page size
247cdf0e10cSrcweir             unsigned long nHeights = GetTotalRowHeight(nRepeatStartY, nRepeatEndY);
248cdf0e10cSrcweir #ifdef DBG_UTIL
249cdf0e10cSrcweir             if (nHeights == ::std::numeric_limits<unsigned long>::max())
250cdf0e10cSrcweir                 DBG_ERRORFILE("ScTable::UpdatePageBreaks: row heights overflow");
251cdf0e10cSrcweir #endif
252cdf0e10cSrcweir             nPageSizeY -= nHeights;
253cdf0e10cSrcweir             if (nY <= nRepeatEndY)
254cdf0e10cSrcweir                 RemoveRowPageBreaks(nY, nRepeatEndY);
255cdf0e10cSrcweir 			bRowFound = sal_True;
256cdf0e10cSrcweir 		}
257cdf0e10cSrcweir 
258cdf0e10cSrcweir         if (bThisRowHidden)
259cdf0e10cSrcweir         {
260cdf0e10cSrcweir             // Hidden row range.  Skip them unless there is a manual break.
261cdf0e10cSrcweir             SCROW nLastCommon = aIterHidden.getLastPos();
262cdf0e10cSrcweir             if (nNextManualBreak >= 0)
263cdf0e10cSrcweir                 nLastCommon = ::std::min(nLastCommon, nNextManualBreak-1);
264cdf0e10cSrcweir             nY = nLastCommon;
265cdf0e10cSrcweir         }
266cdf0e10cSrcweir         else
267cdf0e10cSrcweir         {
268cdf0e10cSrcweir             // Visible row range.
269cdf0e10cSrcweir 
270cdf0e10cSrcweir             SCROW nLastHidden = aIterHidden.getLastPos();
271cdf0e10cSrcweir             SCROW nLastHeight = aIterHeights.getLastPos();
272cdf0e10cSrcweir             SCROW nLastCommon = ::std::min(nLastHidden, nLastHeight);
273cdf0e10cSrcweir             if (nNextManualBreak >= 0)
274cdf0e10cSrcweir                 nLastCommon = ::std::min(nLastCommon, nNextManualBreak-1);
275cdf0e10cSrcweir 
276cdf0e10cSrcweir             if (nLastCommon > nY)
277cdf0e10cSrcweir             {
278cdf0e10cSrcweir                 long nMaxMultiple = static_cast<long>(nLastCommon - nY);
279cdf0e10cSrcweir                 long nMultiple = (nPageSizeY - nSizeY) / nThisY;
280cdf0e10cSrcweir                 if (nMultiple > nMaxMultiple)
281cdf0e10cSrcweir                     nMultiple = nMaxMultiple;
282cdf0e10cSrcweir                 if (nMultiple > 1)
283cdf0e10cSrcweir                 {
284cdf0e10cSrcweir                     nSizeY += nThisY * (nMultiple - 1);
285cdf0e10cSrcweir                     nY += nMultiple - 1;
286cdf0e10cSrcweir                 }
287cdf0e10cSrcweir             }
288cdf0e10cSrcweir         }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 		nSizeY += nThisY;
291cdf0e10cSrcweir 	}
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 		//	Ende: Breaks loeschen
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 	if (nEndCol < MAXCOL)
296cdf0e10cSrcweir 	{
297cdf0e10cSrcweir         SetColBreak(nEndCol+1, true, false);  // AREABREAK
298cdf0e10cSrcweir 		for (nX=nEndCol+2; nX<=MAXCOL; nX++)
299cdf0e10cSrcweir             RemoveColBreak(nX, true, false);
300cdf0e10cSrcweir 	}
301cdf0e10cSrcweir 	if (nEndRow < MAXROW)
302cdf0e10cSrcweir 	{
303cdf0e10cSrcweir         SetRowBreak(nEndRow+1, true, false);  // AREABREAK
304cdf0e10cSrcweir 		if (nEndRow+2 <= MAXROW)
305cdf0e10cSrcweir             RemoveRowPageBreaks(nEndRow+2, MAXROW);
306cdf0e10cSrcweir 	}
307cdf0e10cSrcweir     mbPageBreaksValid = !pUserArea;     // #i116881# the valid flag can only apply to the "no user area" case
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
RemoveManualBreaks()310cdf0e10cSrcweir void ScTable::RemoveManualBreaks()
311cdf0e10cSrcweir {
312cdf0e10cSrcweir     maRowManualBreaks.clear();
313cdf0e10cSrcweir     maColManualBreaks.clear();
314cdf0e10cSrcweir     InvalidatePageBreaks();
315cdf0e10cSrcweir 
316cdf0e10cSrcweir     if (IsStreamValid())
317cdf0e10cSrcweir         SetStreamValid(sal_False);
318cdf0e10cSrcweir }
319cdf0e10cSrcweir 
HasManualBreaks() const320cdf0e10cSrcweir sal_Bool ScTable::HasManualBreaks() const
321cdf0e10cSrcweir {
322cdf0e10cSrcweir     return !maRowManualBreaks.empty() || !maColManualBreaks.empty();
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
SetRowManualBreaks(const::std::set<SCROW> & rBreaks)325cdf0e10cSrcweir void ScTable::SetRowManualBreaks( const ::std::set<SCROW>& rBreaks )
326cdf0e10cSrcweir {
327cdf0e10cSrcweir     maRowManualBreaks = rBreaks;
328cdf0e10cSrcweir     InvalidatePageBreaks();
329cdf0e10cSrcweir     if (IsStreamValid())
330cdf0e10cSrcweir         SetStreamValid(sal_False);
331cdf0e10cSrcweir }
332cdf0e10cSrcweir 
SetColManualBreaks(const::std::set<SCCOL> & rBreaks)333cdf0e10cSrcweir void ScTable::SetColManualBreaks( const ::std::set<SCCOL>& rBreaks )
334cdf0e10cSrcweir {
335cdf0e10cSrcweir     maColManualBreaks = rBreaks;
336cdf0e10cSrcweir     InvalidatePageBreaks();
337cdf0e10cSrcweir     if (IsStreamValid())
338cdf0e10cSrcweir         SetStreamValid(sal_False);
339cdf0e10cSrcweir }
340cdf0e10cSrcweir 
GetAllRowBreaks(set<SCROW> & rBreaks,bool bPage,bool bManual) const341cdf0e10cSrcweir void ScTable::GetAllRowBreaks(set<SCROW>& rBreaks, bool bPage, bool bManual) const
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     if (bPage)
344cdf0e10cSrcweir         rBreaks = maRowPageBreaks;
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     if (bManual)
347cdf0e10cSrcweir     {
348cdf0e10cSrcweir         using namespace std;
349cdf0e10cSrcweir         copy(maRowManualBreaks.begin(), maRowManualBreaks.end(), inserter(rBreaks, rBreaks.begin()));
350cdf0e10cSrcweir     }
351cdf0e10cSrcweir }
352cdf0e10cSrcweir 
GetAllColBreaks(set<SCCOL> & rBreaks,bool bPage,bool bManual) const353cdf0e10cSrcweir void ScTable::GetAllColBreaks(set<SCCOL>& rBreaks, bool bPage, bool bManual) const
354cdf0e10cSrcweir {
355cdf0e10cSrcweir     if (bPage)
356cdf0e10cSrcweir         rBreaks = maColPageBreaks;
357cdf0e10cSrcweir 
358cdf0e10cSrcweir     if (bManual)
359cdf0e10cSrcweir     {
360cdf0e10cSrcweir         using namespace std;
361cdf0e10cSrcweir         copy(maColManualBreaks.begin(), maColManualBreaks.end(), inserter(rBreaks, rBreaks.begin()));
362cdf0e10cSrcweir     }
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
HasRowPageBreak(SCROW nRow) const365cdf0e10cSrcweir bool ScTable::HasRowPageBreak(SCROW nRow) const
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     if (!ValidRow(nRow))
368cdf0e10cSrcweir         return false;
369cdf0e10cSrcweir 
370cdf0e10cSrcweir     return maRowPageBreaks.find(nRow) != maRowPageBreaks.end();
371cdf0e10cSrcweir }
372cdf0e10cSrcweir 
HasColPageBreak(SCCOL nCol) const373cdf0e10cSrcweir bool ScTable::HasColPageBreak(SCCOL nCol) const
374cdf0e10cSrcweir {
375cdf0e10cSrcweir     if (!ValidCol(nCol))
376cdf0e10cSrcweir         return false;
377cdf0e10cSrcweir 
378cdf0e10cSrcweir     return maColPageBreaks.find(nCol) != maColPageBreaks.end();
379cdf0e10cSrcweir }
380cdf0e10cSrcweir 
HasRowManualBreak(SCROW nRow) const381cdf0e10cSrcweir bool ScTable::HasRowManualBreak(SCROW nRow) const
382cdf0e10cSrcweir {
383cdf0e10cSrcweir     if (!ValidRow(nRow))
384cdf0e10cSrcweir         return false;
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     return maRowManualBreaks.find(nRow) != maRowManualBreaks.end();
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
HasColManualBreak(SCCOL nCol) const389cdf0e10cSrcweir bool ScTable::HasColManualBreak(SCCOL nCol) const
390cdf0e10cSrcweir {
391cdf0e10cSrcweir     if (!ValidCol(nCol))
392cdf0e10cSrcweir         return false;
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     return maColManualBreaks.find(nCol) != maColManualBreaks.end();
395cdf0e10cSrcweir }
396cdf0e10cSrcweir 
GetNextManualBreak(SCROW nRow) const397cdf0e10cSrcweir SCROW ScTable::GetNextManualBreak(SCROW nRow) const
398cdf0e10cSrcweir {
399cdf0e10cSrcweir     set<SCROW>::const_iterator itr = maRowManualBreaks.lower_bound(nRow);
400cdf0e10cSrcweir     return itr == maRowManualBreaks.end() ? -1 : *itr;
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
RemoveRowPageBreaks(SCROW nStartRow,SCROW nEndRow)403cdf0e10cSrcweir void ScTable::RemoveRowPageBreaks(SCROW nStartRow, SCROW nEndRow)
404cdf0e10cSrcweir {
405cdf0e10cSrcweir     using namespace std;
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     if (!ValidRow(nStartRow) || !ValidRow(nEndRow))
408cdf0e10cSrcweir         return;
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     set<SCROW>::iterator low  = maRowPageBreaks.lower_bound(nStartRow);
411cdf0e10cSrcweir     set<SCROW>::iterator high = maRowPageBreaks.upper_bound(nEndRow);
412cdf0e10cSrcweir     maRowPageBreaks.erase(low, high);
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
RemoveRowBreak(SCROW nRow,bool bPage,bool bManual)415cdf0e10cSrcweir void ScTable::RemoveRowBreak(SCROW nRow, bool bPage, bool bManual)
416cdf0e10cSrcweir {
417cdf0e10cSrcweir     if (!ValidRow(nRow))
418cdf0e10cSrcweir         return;
419cdf0e10cSrcweir 
420cdf0e10cSrcweir     if (bPage)
421cdf0e10cSrcweir         maRowPageBreaks.erase(nRow);
422cdf0e10cSrcweir 
423cdf0e10cSrcweir     if (bManual)
424cdf0e10cSrcweir     {
425cdf0e10cSrcweir         maRowManualBreaks.erase(nRow);
426cdf0e10cSrcweir         InvalidatePageBreaks();
427cdf0e10cSrcweir     }
428cdf0e10cSrcweir }
429cdf0e10cSrcweir 
RemoveColBreak(SCCOL nCol,bool bPage,bool bManual)430cdf0e10cSrcweir void ScTable::RemoveColBreak(SCCOL nCol, bool bPage, bool bManual)
431cdf0e10cSrcweir {
432cdf0e10cSrcweir     if (!ValidCol(nCol))
433cdf0e10cSrcweir         return;
434cdf0e10cSrcweir 
435cdf0e10cSrcweir     if (bPage)
436cdf0e10cSrcweir         maColPageBreaks.erase(nCol);
437cdf0e10cSrcweir 
438cdf0e10cSrcweir     if (bManual)
439cdf0e10cSrcweir     {
440cdf0e10cSrcweir         maColManualBreaks.erase(nCol);
441cdf0e10cSrcweir         InvalidatePageBreaks();
442cdf0e10cSrcweir     }
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
SetRowBreak(SCROW nRow,bool bPage,bool bManual)445cdf0e10cSrcweir void ScTable::SetRowBreak(SCROW nRow, bool bPage, bool bManual)
446cdf0e10cSrcweir {
447cdf0e10cSrcweir     if (!ValidRow(nRow))
448cdf0e10cSrcweir         return;
449cdf0e10cSrcweir 
450cdf0e10cSrcweir     if (bPage)
451cdf0e10cSrcweir         maRowPageBreaks.insert(nRow);
452cdf0e10cSrcweir 
453cdf0e10cSrcweir     if (bManual)
454cdf0e10cSrcweir     {
455cdf0e10cSrcweir         maRowManualBreaks.insert(nRow);
456cdf0e10cSrcweir         InvalidatePageBreaks();
457cdf0e10cSrcweir     }
458cdf0e10cSrcweir }
459cdf0e10cSrcweir 
SetColBreak(SCCOL nCol,bool bPage,bool bManual)460cdf0e10cSrcweir void ScTable::SetColBreak(SCCOL nCol, bool bPage, bool bManual)
461cdf0e10cSrcweir {
462cdf0e10cSrcweir     if (!ValidCol(nCol))
463cdf0e10cSrcweir         return;
464cdf0e10cSrcweir 
465cdf0e10cSrcweir     if (bPage)
466cdf0e10cSrcweir         maColPageBreaks.insert(nCol);
467cdf0e10cSrcweir 
468cdf0e10cSrcweir     if (bManual)
469cdf0e10cSrcweir     {
470cdf0e10cSrcweir         maColManualBreaks.insert(nCol);
471cdf0e10cSrcweir         InvalidatePageBreaks();
472cdf0e10cSrcweir     }
473cdf0e10cSrcweir }
474cdf0e10cSrcweir 
GetRowBreakData() const475cdf0e10cSrcweir Sequence<TablePageBreakData> ScTable::GetRowBreakData() const
476cdf0e10cSrcweir {
477cdf0e10cSrcweir     using ::std::copy;
478cdf0e10cSrcweir     using ::std::inserter;
479cdf0e10cSrcweir 
480cdf0e10cSrcweir     set<SCROW> aRowBreaks = maRowPageBreaks;
481cdf0e10cSrcweir     copy(maRowManualBreaks.begin(), maRowManualBreaks.end(), inserter(aRowBreaks, aRowBreaks.begin()));
482cdf0e10cSrcweir 
483cdf0e10cSrcweir     set<SCROW>::const_iterator itr = aRowBreaks.begin(), itrEnd = aRowBreaks.end();
484cdf0e10cSrcweir     Sequence<TablePageBreakData> aSeq(aRowBreaks.size());
485cdf0e10cSrcweir 
486cdf0e10cSrcweir     for (sal_Int32 i = 0; itr != itrEnd; ++itr, ++i)
487cdf0e10cSrcweir     {
488cdf0e10cSrcweir         SCROW nRow = *itr;
489cdf0e10cSrcweir         TablePageBreakData aData;
490cdf0e10cSrcweir         aData.Position = nRow;
491cdf0e10cSrcweir         aData.ManualBreak = HasRowManualBreak(nRow);
492cdf0e10cSrcweir         aSeq[i] = aData;
493cdf0e10cSrcweir     }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir     return aSeq;
496cdf0e10cSrcweir }
497cdf0e10cSrcweir 
RowHidden(SCROW nRow,SCROW * pFirstRow,SCROW * pLastRow) const498cdf0e10cSrcweir bool ScTable::RowHidden(SCROW nRow, SCROW* pFirstRow, SCROW* pLastRow) const
499cdf0e10cSrcweir {
500cdf0e10cSrcweir     if (!ValidRow(nRow))
501cdf0e10cSrcweir     {
502cdf0e10cSrcweir         if (pFirstRow)
503cdf0e10cSrcweir             *pFirstRow = nRow;
504cdf0e10cSrcweir         if (pLastRow)
505cdf0e10cSrcweir             *pLastRow = nRow;
506cdf0e10cSrcweir         return true;
507cdf0e10cSrcweir     }
508cdf0e10cSrcweir 
509cdf0e10cSrcweir     ScFlatBoolRowSegments::RangeData aData;
510cdf0e10cSrcweir     if (!mpHiddenRows->getRangeData(nRow, aData))
511cdf0e10cSrcweir     {
512cdf0e10cSrcweir         // search failed.
513cdf0e10cSrcweir         if (pFirstRow)
514cdf0e10cSrcweir             *pFirstRow = nRow;
515cdf0e10cSrcweir         if (pLastRow)
516cdf0e10cSrcweir             *pLastRow = nRow;
517cdf0e10cSrcweir         return true;
518cdf0e10cSrcweir     }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir     if (pFirstRow)
521cdf0e10cSrcweir         *pFirstRow = aData.mnRow1;
522cdf0e10cSrcweir     if (pLastRow)
523cdf0e10cSrcweir         *pLastRow = aData.mnRow2;
524cdf0e10cSrcweir 
525cdf0e10cSrcweir     return aData.mbValue;
526cdf0e10cSrcweir }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 
RowHidden(SCROW nRow,SCROW & rLastRow) const529cdf0e10cSrcweir bool ScTable::RowHidden(SCROW nRow, SCROW& rLastRow) const
530cdf0e10cSrcweir {
531cdf0e10cSrcweir     rLastRow = nRow;
532cdf0e10cSrcweir     if (!ValidRow(nRow))
533cdf0e10cSrcweir         return true;
534cdf0e10cSrcweir 
535cdf0e10cSrcweir     ScFlatBoolRowSegments::RangeData aData;
536cdf0e10cSrcweir     if (!mpHiddenRows->getRangeData(nRow, aData))
537cdf0e10cSrcweir         // search failed.
538cdf0e10cSrcweir         return true;
539cdf0e10cSrcweir 
540cdf0e10cSrcweir     rLastRow = aData.mnRow2;
541cdf0e10cSrcweir     return aData.mbValue;
542cdf0e10cSrcweir }
543cdf0e10cSrcweir 
HasHiddenRows(SCROW nStartRow,SCROW nEndRow) const544cdf0e10cSrcweir bool ScTable::HasHiddenRows(SCROW nStartRow, SCROW nEndRow) const
545cdf0e10cSrcweir {
546cdf0e10cSrcweir     SCROW nRow = nStartRow;
547cdf0e10cSrcweir     while (nRow <= nEndRow)
548cdf0e10cSrcweir     {
549cdf0e10cSrcweir         SCROW nLastRow = -1;
550cdf0e10cSrcweir         bool bHidden = RowHidden(nRow, nLastRow);
551cdf0e10cSrcweir         if (bHidden)
552cdf0e10cSrcweir             return true;
553cdf0e10cSrcweir 
554cdf0e10cSrcweir         nRow = nLastRow + 1;
555cdf0e10cSrcweir     }
556cdf0e10cSrcweir     return false;
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
ColHidden(SCCOL nCol,SCCOL & rLastCol) const559cdf0e10cSrcweir bool ScTable::ColHidden(SCCOL nCol, SCCOL& rLastCol) const
560cdf0e10cSrcweir {
561cdf0e10cSrcweir     rLastCol = nCol;
562cdf0e10cSrcweir     if (!ValidCol(nCol))
563cdf0e10cSrcweir         return true;
564cdf0e10cSrcweir 
565cdf0e10cSrcweir     ScFlatBoolColSegments::RangeData aData;
566cdf0e10cSrcweir     if (!mpHiddenCols->getRangeData(nCol, aData))
567cdf0e10cSrcweir         return true;
568cdf0e10cSrcweir 
569cdf0e10cSrcweir     rLastCol = aData.mnCol2;
570cdf0e10cSrcweir     return aData.mbValue;
571cdf0e10cSrcweir }
572cdf0e10cSrcweir 
ColHidden(SCCOL nCol,SCCOL * pFirstCol,SCCOL * pLastCol) const573cdf0e10cSrcweir bool ScTable::ColHidden(SCCOL nCol, SCCOL* pFirstCol, SCCOL* pLastCol) const
574cdf0e10cSrcweir {
575cdf0e10cSrcweir     if (!ValidCol(nCol))
576cdf0e10cSrcweir         return true;
577cdf0e10cSrcweir 
578cdf0e10cSrcweir     ScFlatBoolColSegments::RangeData aData;
579cdf0e10cSrcweir     if (!mpHiddenCols->getRangeData(nCol, aData))
580cdf0e10cSrcweir         return true;
581cdf0e10cSrcweir 
582cdf0e10cSrcweir     if (pFirstCol)
583cdf0e10cSrcweir         *pFirstCol = aData.mnCol1;
584cdf0e10cSrcweir     if (pLastCol)
585cdf0e10cSrcweir         *pLastCol = aData.mnCol2;
586cdf0e10cSrcweir 
587cdf0e10cSrcweir     return aData.mbValue;
588cdf0e10cSrcweir }
589cdf0e10cSrcweir 
SetRowHidden(SCROW nStartRow,SCROW nEndRow,bool bHidden)590cdf0e10cSrcweir void ScTable::SetRowHidden(SCROW nStartRow, SCROW nEndRow, bool bHidden)
591cdf0e10cSrcweir {
592cdf0e10cSrcweir     if (bHidden)
593cdf0e10cSrcweir         mpHiddenRows->setTrue(nStartRow, nEndRow);
594cdf0e10cSrcweir     else
595cdf0e10cSrcweir         mpHiddenRows->setFalse(nStartRow, nEndRow);
596cdf0e10cSrcweir }
597cdf0e10cSrcweir 
SetColHidden(SCCOL nStartCol,SCCOL nEndCol,bool bHidden)598cdf0e10cSrcweir void ScTable::SetColHidden(SCCOL nStartCol, SCCOL nEndCol, bool bHidden)
599cdf0e10cSrcweir {
600cdf0e10cSrcweir     if (bHidden)
601cdf0e10cSrcweir         mpHiddenCols->setTrue(nStartCol, nEndCol);
602cdf0e10cSrcweir     else
603cdf0e10cSrcweir         mpHiddenCols->setFalse(nStartCol, nEndCol);
604cdf0e10cSrcweir }
605cdf0e10cSrcweir 
CopyColHidden(ScTable & rTable,SCCOL nStartCol,SCCOL nEndCol)606cdf0e10cSrcweir void ScTable::CopyColHidden(ScTable& rTable, SCCOL nStartCol, SCCOL nEndCol)
607cdf0e10cSrcweir {
608cdf0e10cSrcweir     SCCOL nCol = nStartCol;
609cdf0e10cSrcweir     while (nCol <= nEndCol)
610cdf0e10cSrcweir     {
611cdf0e10cSrcweir         SCCOL nLastCol;
612cdf0e10cSrcweir         bool bHidden = rTable.ColHidden(nCol, NULL, &nLastCol);
613cdf0e10cSrcweir         if (nLastCol > nEndCol)
614cdf0e10cSrcweir             nLastCol = nEndCol;
615cdf0e10cSrcweir 
616cdf0e10cSrcweir         SetColHidden(nCol, nLastCol, bHidden);
617cdf0e10cSrcweir         nCol = nLastCol + 1;
618cdf0e10cSrcweir     }
619cdf0e10cSrcweir }
620cdf0e10cSrcweir 
CopyRowHidden(ScTable & rTable,SCROW nStartRow,SCROW nEndRow)621cdf0e10cSrcweir void ScTable::CopyRowHidden(ScTable& rTable, SCROW nStartRow, SCROW nEndRow)
622cdf0e10cSrcweir {
623cdf0e10cSrcweir     SCROW nRow = nStartRow;
624cdf0e10cSrcweir     while (nRow <= nEndRow)
625cdf0e10cSrcweir     {
626cdf0e10cSrcweir         SCROW nLastRow = -1;
627cdf0e10cSrcweir         bool bHidden = rTable.RowHidden(nRow, nLastRow);
628cdf0e10cSrcweir         if (nLastRow > nEndRow)
629cdf0e10cSrcweir             nLastRow = nEndRow;
630cdf0e10cSrcweir         SetRowHidden(nRow, nLastRow, bHidden);
631cdf0e10cSrcweir         nRow = nLastRow + 1;
632cdf0e10cSrcweir     }
633cdf0e10cSrcweir }
634cdf0e10cSrcweir 
CopyRowHeight(ScTable & rSrcTable,SCROW nStartRow,SCROW nEndRow,SCROW nSrcOffset)635cdf0e10cSrcweir void ScTable::CopyRowHeight(ScTable& rSrcTable, SCROW nStartRow, SCROW nEndRow, SCROW nSrcOffset)
636cdf0e10cSrcweir {
637cdf0e10cSrcweir     SCROW nRow = nStartRow;
638cdf0e10cSrcweir     ScFlatUInt16RowSegments::RangeData aSrcData;
639cdf0e10cSrcweir     while (nRow <= nEndRow)
640cdf0e10cSrcweir     {
641cdf0e10cSrcweir         if (!rSrcTable.mpRowHeights->getRangeData(nRow + nSrcOffset, aSrcData))
642cdf0e10cSrcweir             // Something is wrong !
643cdf0e10cSrcweir             return;
644cdf0e10cSrcweir 
645cdf0e10cSrcweir         SCROW nLastRow = aSrcData.mnRow2 - nSrcOffset;
646cdf0e10cSrcweir         if (nLastRow > nEndRow)
647cdf0e10cSrcweir             nLastRow = nEndRow;
648cdf0e10cSrcweir 
649cdf0e10cSrcweir         mpRowHeights->setValue(nRow, nLastRow, aSrcData.mnValue);
650cdf0e10cSrcweir         nRow = nLastRow + 1;
651cdf0e10cSrcweir     }
652cdf0e10cSrcweir }
653cdf0e10cSrcweir 
FirstVisibleRow(SCROW nStartRow,SCROW nEndRow) const654cdf0e10cSrcweir SCROW ScTable::FirstVisibleRow(SCROW nStartRow, SCROW nEndRow) const
655cdf0e10cSrcweir {
656cdf0e10cSrcweir     SCROW nRow = nStartRow;
657cdf0e10cSrcweir     ScFlatBoolRowSegments::RangeData aData;
658cdf0e10cSrcweir     while (nRow <= nEndRow)
659cdf0e10cSrcweir     {
660cdf0e10cSrcweir         if (!ValidRow(nRow))
661cdf0e10cSrcweir             break;
662cdf0e10cSrcweir 
663cdf0e10cSrcweir         if (!mpHiddenRows->getRangeData(nRow, aData))
664cdf0e10cSrcweir             // failed to get range data.
665cdf0e10cSrcweir             break;
666cdf0e10cSrcweir 
667cdf0e10cSrcweir         if (!aData.mbValue)
668cdf0e10cSrcweir             // visible row found
669cdf0e10cSrcweir             return nRow;
670cdf0e10cSrcweir 
671cdf0e10cSrcweir         nRow = aData.mnRow2 + 1;
672cdf0e10cSrcweir     }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir     return ::std::numeric_limits<SCROW>::max();
675cdf0e10cSrcweir }
676cdf0e10cSrcweir 
LastVisibleRow(SCROW nStartRow,SCROW nEndRow) const677cdf0e10cSrcweir SCROW ScTable::LastVisibleRow(SCROW nStartRow, SCROW nEndRow) const
678cdf0e10cSrcweir {
679cdf0e10cSrcweir     SCROW nRow = nEndRow;
680cdf0e10cSrcweir     ScFlatBoolRowSegments::RangeData aData;
681cdf0e10cSrcweir     while (nRow >= nStartRow)
682cdf0e10cSrcweir     {
683cdf0e10cSrcweir         if (!ValidRow(nRow))
684cdf0e10cSrcweir             break;
685cdf0e10cSrcweir 
686cdf0e10cSrcweir         if (!mpHiddenRows->getRangeData(nRow, aData))
687cdf0e10cSrcweir             // failed to get range data.
688cdf0e10cSrcweir             break;
689cdf0e10cSrcweir 
690cdf0e10cSrcweir         if (!aData.mbValue)
691cdf0e10cSrcweir             // visible row found
692cdf0e10cSrcweir             return nRow;
693cdf0e10cSrcweir 
694cdf0e10cSrcweir         nRow = aData.mnRow1 - 1;
695cdf0e10cSrcweir     }
696cdf0e10cSrcweir 
697cdf0e10cSrcweir     return ::std::numeric_limits<SCROW>::max();
698cdf0e10cSrcweir }
699cdf0e10cSrcweir 
CountVisibleRows(SCROW nStartRow,SCROW nEndRow) const700cdf0e10cSrcweir SCROW ScTable::CountVisibleRows(SCROW nStartRow, SCROW nEndRow) const
701cdf0e10cSrcweir {
702cdf0e10cSrcweir     SCROW nCount = 0;
703cdf0e10cSrcweir     SCROW nRow = nStartRow;
704cdf0e10cSrcweir     ScFlatBoolRowSegments::RangeData aData;
705cdf0e10cSrcweir     while (nRow <= nEndRow)
706cdf0e10cSrcweir     {
707cdf0e10cSrcweir         if (!mpHiddenRows->getRangeData(nRow, aData))
708cdf0e10cSrcweir             break;
709cdf0e10cSrcweir 
710cdf0e10cSrcweir         if (aData.mnRow2 > nEndRow)
711cdf0e10cSrcweir             aData.mnRow2 = nEndRow;
712cdf0e10cSrcweir 
713cdf0e10cSrcweir         if (!aData.mbValue)
714cdf0e10cSrcweir             nCount += aData.mnRow2 - nRow + 1;
715cdf0e10cSrcweir 
716cdf0e10cSrcweir         nRow = aData.mnRow2 + 1;
717cdf0e10cSrcweir     }
718cdf0e10cSrcweir     return nCount;
719cdf0e10cSrcweir }
720cdf0e10cSrcweir 
GetTotalRowHeight(SCROW nStartRow,SCROW nEndRow) const721cdf0e10cSrcweir sal_uInt32 ScTable::GetTotalRowHeight(SCROW nStartRow, SCROW nEndRow) const
722cdf0e10cSrcweir {
723cdf0e10cSrcweir     sal_uInt32 nHeight = 0;
724cdf0e10cSrcweir     SCROW nRow = nStartRow;
725cdf0e10cSrcweir     ScFlatBoolRowSegments::RangeData aData;
726cdf0e10cSrcweir     while (nRow <= nEndRow)
727cdf0e10cSrcweir     {
728cdf0e10cSrcweir         if (!mpHiddenRows->getRangeData(nRow, aData))
729cdf0e10cSrcweir             break;
730cdf0e10cSrcweir 
731cdf0e10cSrcweir         if (aData.mnRow2 > nEndRow)
732cdf0e10cSrcweir             aData.mnRow2 = nEndRow;
733cdf0e10cSrcweir 
734cdf0e10cSrcweir         if (!aData.mbValue)
735cdf0e10cSrcweir             // visible row range.
736cdf0e10cSrcweir             nHeight += mpRowHeights->getSumValue(nRow, aData.mnRow2);
737cdf0e10cSrcweir 
738cdf0e10cSrcweir         nRow = aData.mnRow2 + 1;
739cdf0e10cSrcweir     }
740cdf0e10cSrcweir 
741cdf0e10cSrcweir     return nHeight;
742cdf0e10cSrcweir }
743cdf0e10cSrcweir 
LastHiddenColRow(SCCOLROW nPos,bool bCol) const744cdf0e10cSrcweir SCCOLROW ScTable::LastHiddenColRow(SCCOLROW nPos, bool bCol) const
745cdf0e10cSrcweir {
746cdf0e10cSrcweir     if (bCol)
747cdf0e10cSrcweir     {
748cdf0e10cSrcweir         SCCOL nCol = static_cast<SCCOL>(nPos);
749cdf0e10cSrcweir         if (ColHidden(nCol))
750cdf0e10cSrcweir         {
751cdf0e10cSrcweir             for (SCCOL i = nCol+1; i <= MAXCOL; ++i)
752cdf0e10cSrcweir             {
753cdf0e10cSrcweir                 if (!ColHidden(nCol))
754cdf0e10cSrcweir                     return nCol - 1;
755cdf0e10cSrcweir             }
756cdf0e10cSrcweir         }
757cdf0e10cSrcweir     }
758cdf0e10cSrcweir     else
759cdf0e10cSrcweir     {
760cdf0e10cSrcweir         SCROW nRow = static_cast<SCROW>(nPos);
761cdf0e10cSrcweir         SCROW nLastRow;
762cdf0e10cSrcweir         if (RowHidden(nRow, NULL, &nLastRow))
763cdf0e10cSrcweir             return static_cast<SCCOLROW>(nLastRow);
764cdf0e10cSrcweir     }
765cdf0e10cSrcweir     return ::std::numeric_limits<SCCOLROW>::max();
766cdf0e10cSrcweir }
767cdf0e10cSrcweir 
RowFiltered(SCROW nRow,SCROW * pFirstRow,SCROW * pLastRow) const768cdf0e10cSrcweir bool ScTable::RowFiltered(SCROW nRow, SCROW* pFirstRow, SCROW* pLastRow) const
769cdf0e10cSrcweir {
770cdf0e10cSrcweir     if (!ValidRow(nRow))
771cdf0e10cSrcweir         return false;
772cdf0e10cSrcweir 
773cdf0e10cSrcweir     ScFlatBoolRowSegments::RangeData aData;
774cdf0e10cSrcweir     if (!mpFilteredRows->getRangeData(nRow, aData))
775cdf0e10cSrcweir         // search failed.
776cdf0e10cSrcweir         return false;
777cdf0e10cSrcweir 
778cdf0e10cSrcweir     if (pFirstRow)
779cdf0e10cSrcweir         *pFirstRow = aData.mnRow1;
780cdf0e10cSrcweir     if (pLastRow)
781cdf0e10cSrcweir         *pLastRow = aData.mnRow2;
782cdf0e10cSrcweir 
783cdf0e10cSrcweir     return aData.mbValue;
784cdf0e10cSrcweir }
785cdf0e10cSrcweir 
ColFiltered(SCCOL nCol,SCCOL * pFirstCol,SCCOL * pLastCol) const786cdf0e10cSrcweir bool ScTable::ColFiltered(SCCOL nCol, SCCOL* pFirstCol, SCCOL* pLastCol) const
787cdf0e10cSrcweir {
788cdf0e10cSrcweir     if (!ValidCol(nCol))
789cdf0e10cSrcweir         return false;
790cdf0e10cSrcweir 
791cdf0e10cSrcweir     ScFlatBoolColSegments::RangeData aData;
792cdf0e10cSrcweir     if (!mpFilteredCols->getRangeData(nCol, aData))
793cdf0e10cSrcweir         // search failed.
794cdf0e10cSrcweir         return false;
795cdf0e10cSrcweir 
796cdf0e10cSrcweir     if (pFirstCol)
797cdf0e10cSrcweir         *pFirstCol = aData.mnCol1;
798cdf0e10cSrcweir     if (pLastCol)
799cdf0e10cSrcweir         *pLastCol = aData.mnCol2;
800cdf0e10cSrcweir 
801cdf0e10cSrcweir     return aData.mbValue;
802cdf0e10cSrcweir }
803cdf0e10cSrcweir 
HasFilteredRows(SCROW nStartRow,SCROW nEndRow) const804cdf0e10cSrcweir bool ScTable::HasFilteredRows(SCROW nStartRow, SCROW nEndRow) const
805cdf0e10cSrcweir {
806cdf0e10cSrcweir     SCROW nRow = nStartRow;
807cdf0e10cSrcweir     while (nRow <= nEndRow)
808cdf0e10cSrcweir     {
809cdf0e10cSrcweir         SCROW nLastRow = nRow;
810cdf0e10cSrcweir         bool bFiltered = RowFiltered(nRow, NULL, &nLastRow);
811cdf0e10cSrcweir         if (bFiltered)
812cdf0e10cSrcweir             return true;
813cdf0e10cSrcweir 
814cdf0e10cSrcweir         nRow = nLastRow + 1;
815cdf0e10cSrcweir     }
816cdf0e10cSrcweir     return false;
817cdf0e10cSrcweir }
818cdf0e10cSrcweir 
CopyColFiltered(ScTable & rTable,SCCOL nStartCol,SCCOL nEndCol)819cdf0e10cSrcweir void ScTable::CopyColFiltered(ScTable& rTable, SCCOL nStartCol, SCCOL nEndCol)
820cdf0e10cSrcweir {
821cdf0e10cSrcweir     SCCOL nCol = nStartCol;
822cdf0e10cSrcweir     while (nCol <= nEndCol)
823cdf0e10cSrcweir     {
824cdf0e10cSrcweir         SCCOL nLastCol;
825cdf0e10cSrcweir         bool bFiltered = rTable.ColFiltered(nCol, NULL, &nLastCol);
826cdf0e10cSrcweir         if (nLastCol > nEndCol)
827cdf0e10cSrcweir             nLastCol = nEndCol;
828cdf0e10cSrcweir 
829cdf0e10cSrcweir         SetColFiltered(nCol, nLastCol, bFiltered);
830cdf0e10cSrcweir         nCol = nLastCol + 1;
831cdf0e10cSrcweir     }
832cdf0e10cSrcweir }
833cdf0e10cSrcweir 
CopyRowFiltered(ScTable & rTable,SCROW nStartRow,SCROW nEndRow)834cdf0e10cSrcweir void ScTable::CopyRowFiltered(ScTable& rTable, SCROW nStartRow, SCROW nEndRow)
835cdf0e10cSrcweir {
836cdf0e10cSrcweir     SCROW nRow = nStartRow;
837cdf0e10cSrcweir     while (nRow <= nEndRow)
838cdf0e10cSrcweir     {
839cdf0e10cSrcweir         SCROW nLastRow = -1;
840cdf0e10cSrcweir         bool bFiltered = rTable.RowFiltered(nRow, NULL, &nLastRow);
841cdf0e10cSrcweir         if (nLastRow > nEndRow)
842cdf0e10cSrcweir             nLastRow = nEndRow;
843cdf0e10cSrcweir         SetRowFiltered(nRow, nLastRow, bFiltered);
844cdf0e10cSrcweir         nRow = nLastRow + 1;
845cdf0e10cSrcweir     }
846cdf0e10cSrcweir }
847cdf0e10cSrcweir 
SetRowFiltered(SCROW nStartRow,SCROW nEndRow,bool bFiltered)848cdf0e10cSrcweir void ScTable::SetRowFiltered(SCROW nStartRow, SCROW nEndRow, bool bFiltered)
849cdf0e10cSrcweir {
850cdf0e10cSrcweir     if (bFiltered)
851cdf0e10cSrcweir         mpFilteredRows->setTrue(nStartRow, nEndRow);
852cdf0e10cSrcweir     else
853cdf0e10cSrcweir         mpFilteredRows->setFalse(nStartRow, nEndRow);
854cdf0e10cSrcweir }
855cdf0e10cSrcweir 
SetColFiltered(SCCOL nStartCol,SCCOL nEndCol,bool bFiltered)856cdf0e10cSrcweir void ScTable::SetColFiltered(SCCOL nStartCol, SCCOL nEndCol, bool bFiltered)
857cdf0e10cSrcweir {
858cdf0e10cSrcweir     if (bFiltered)
859cdf0e10cSrcweir         mpFilteredCols->setTrue(nStartCol, nEndCol);
860cdf0e10cSrcweir     else
861cdf0e10cSrcweir         mpFilteredCols->setFalse(nStartCol, nEndCol);
862cdf0e10cSrcweir }
863cdf0e10cSrcweir 
FirstNonFilteredRow(SCROW nStartRow,SCROW nEndRow) const864cdf0e10cSrcweir SCROW ScTable::FirstNonFilteredRow(SCROW nStartRow, SCROW nEndRow) const
865cdf0e10cSrcweir {
866cdf0e10cSrcweir     SCROW nRow = nStartRow;
867cdf0e10cSrcweir     ScFlatBoolRowSegments::RangeData aData;
868cdf0e10cSrcweir     while (nRow <= nEndRow)
869cdf0e10cSrcweir     {
870cdf0e10cSrcweir         if (!ValidRow(nRow))
871cdf0e10cSrcweir             break;
872cdf0e10cSrcweir 
873cdf0e10cSrcweir         if (!mpFilteredRows->getRangeData(nRow, aData))
874cdf0e10cSrcweir             // failed to get range data.
875cdf0e10cSrcweir             break;
876cdf0e10cSrcweir 
877cdf0e10cSrcweir         if (!aData.mbValue)
878cdf0e10cSrcweir             // non-filtered row found
879cdf0e10cSrcweir             return nRow;
880cdf0e10cSrcweir 
881cdf0e10cSrcweir         nRow = aData.mnRow2 + 1;
882cdf0e10cSrcweir     }
883cdf0e10cSrcweir 
884cdf0e10cSrcweir     return ::std::numeric_limits<SCROW>::max();
885cdf0e10cSrcweir }
886cdf0e10cSrcweir 
LastNonFilteredRow(SCROW nStartRow,SCROW nEndRow) const887cdf0e10cSrcweir SCROW ScTable::LastNonFilteredRow(SCROW nStartRow, SCROW nEndRow) const
888cdf0e10cSrcweir {
889cdf0e10cSrcweir     SCROW nRow = nEndRow;
890cdf0e10cSrcweir     ScFlatBoolRowSegments::RangeData aData;
891cdf0e10cSrcweir     while (nRow >= nStartRow)
892cdf0e10cSrcweir     {
893cdf0e10cSrcweir         if (!ValidRow(nRow))
894cdf0e10cSrcweir             break;
895cdf0e10cSrcweir 
896cdf0e10cSrcweir         if (!mpFilteredRows->getRangeData(nRow, aData))
897cdf0e10cSrcweir             // failed to get range data.
898cdf0e10cSrcweir             break;
899cdf0e10cSrcweir 
900cdf0e10cSrcweir         if (!aData.mbValue)
901cdf0e10cSrcweir             // non-filtered row found
902cdf0e10cSrcweir             return nRow;
903cdf0e10cSrcweir 
904cdf0e10cSrcweir         nRow = aData.mnRow1 - 1;
905cdf0e10cSrcweir     }
906cdf0e10cSrcweir 
907cdf0e10cSrcweir     return ::std::numeric_limits<SCROW>::max();
908cdf0e10cSrcweir }
909cdf0e10cSrcweir 
CountNonFilteredRows(SCROW nStartRow,SCROW nEndRow) const910cdf0e10cSrcweir SCROW ScTable::CountNonFilteredRows(SCROW nStartRow, SCROW nEndRow) const
911cdf0e10cSrcweir {
912cdf0e10cSrcweir     SCROW nCount = 0;
913cdf0e10cSrcweir     SCROW nRow = nStartRow;
914cdf0e10cSrcweir     ScFlatBoolRowSegments::RangeData aData;
915cdf0e10cSrcweir     while (nRow <= nEndRow)
916cdf0e10cSrcweir     {
917cdf0e10cSrcweir         if (!mpFilteredRows->getRangeData(nRow, aData))
918cdf0e10cSrcweir             break;
919cdf0e10cSrcweir 
920cdf0e10cSrcweir         if (aData.mnRow2 > nEndRow)
921cdf0e10cSrcweir             aData.mnRow2 = nEndRow;
922cdf0e10cSrcweir 
923cdf0e10cSrcweir         if (!aData.mbValue)
924cdf0e10cSrcweir             nCount += aData.mnRow2 - nRow + 1;
925cdf0e10cSrcweir 
926cdf0e10cSrcweir         nRow = aData.mnRow2 + 1;
927cdf0e10cSrcweir     }
928cdf0e10cSrcweir     return nCount;
929cdf0e10cSrcweir }
930cdf0e10cSrcweir 
931cdf0e10cSrcweir namespace {
932cdf0e10cSrcweir 
lcl_syncFlags(ScFlatBoolColSegments & rColSegments,ScFlatBoolRowSegments & rRowSegments,sal_uInt8 * pColFlags,ScBitMaskCompressedArray<SCROW,sal_uInt8> * pRowFlags,const sal_uInt8 nFlagMask)933cdf0e10cSrcweir void lcl_syncFlags(ScFlatBoolColSegments& rColSegments, ScFlatBoolRowSegments& rRowSegments,
934cdf0e10cSrcweir     sal_uInt8* pColFlags, ScBitMaskCompressedArray< SCROW, sal_uInt8>* pRowFlags, const sal_uInt8 nFlagMask)
935cdf0e10cSrcweir {
936cdf0e10cSrcweir     using ::sal::static_int_cast;
937cdf0e10cSrcweir 
938cdf0e10cSrcweir     pRowFlags->AndValue(0, MAXROW, static_int_cast<sal_uInt8>(~nFlagMask));
939cdf0e10cSrcweir     for (SCCOL i = 0; i <= MAXCOL; ++i)
940cdf0e10cSrcweir         pColFlags[i] &= static_int_cast<sal_uInt8>(~nFlagMask);
941cdf0e10cSrcweir 
942cdf0e10cSrcweir     {
943cdf0e10cSrcweir         // row hidden flags.
944cdf0e10cSrcweir 
945cdf0e10cSrcweir         SCROW nRow = 0;
946cdf0e10cSrcweir         ScFlatBoolRowSegments::RangeData aData;
947cdf0e10cSrcweir         while (nRow <= MAXROW)
948cdf0e10cSrcweir         {
949cdf0e10cSrcweir             if (!rRowSegments.getRangeData(nRow, aData))
950cdf0e10cSrcweir                 break;
951cdf0e10cSrcweir 
952cdf0e10cSrcweir             if (aData.mbValue)
953cdf0e10cSrcweir                 pRowFlags->OrValue(nRow, aData.mnRow2, static_int_cast<sal_uInt8>(nFlagMask));
954cdf0e10cSrcweir 
955cdf0e10cSrcweir             nRow = aData.mnRow2 + 1;
956cdf0e10cSrcweir         }
957cdf0e10cSrcweir     }
958cdf0e10cSrcweir 
959cdf0e10cSrcweir     {
960cdf0e10cSrcweir         // column hidden flags.
961cdf0e10cSrcweir 
962cdf0e10cSrcweir         SCCOL nCol = 0;
963cdf0e10cSrcweir         ScFlatBoolColSegments::RangeData aData;
964cdf0e10cSrcweir         while (nCol <= MAXCOL)
965cdf0e10cSrcweir         {
966cdf0e10cSrcweir             if (!rColSegments.getRangeData(nCol, aData))
967cdf0e10cSrcweir                 break;
968cdf0e10cSrcweir 
969cdf0e10cSrcweir             if (aData.mbValue)
970cdf0e10cSrcweir             {
971cdf0e10cSrcweir                 for (SCCOL i = nCol; i <= aData.mnCol2; ++i)
972cdf0e10cSrcweir                     pColFlags[i] |= nFlagMask;
973cdf0e10cSrcweir             }
974cdf0e10cSrcweir 
975cdf0e10cSrcweir             nCol = aData.mnCol2 + 1;
976cdf0e10cSrcweir         }
977cdf0e10cSrcweir     }
978cdf0e10cSrcweir }
979cdf0e10cSrcweir 
980cdf0e10cSrcweir }
981cdf0e10cSrcweir 
SyncColRowFlags()982cdf0e10cSrcweir void ScTable::SyncColRowFlags()
983cdf0e10cSrcweir {
984cdf0e10cSrcweir     using ::sal::static_int_cast;
985cdf0e10cSrcweir 
986cdf0e10cSrcweir     // Manual breaks.
987cdf0e10cSrcweir     pRowFlags->AndValue(0, MAXROW, static_int_cast<sal_uInt8>(~CR_MANUALBREAK));
988cdf0e10cSrcweir     for (SCCOL i = 0; i <= MAXCOL; ++i)
989cdf0e10cSrcweir         pColFlags[i] &= static_int_cast<sal_uInt8>(~CR_MANUALBREAK);
990cdf0e10cSrcweir 
991cdf0e10cSrcweir     if (!maRowManualBreaks.empty())
992cdf0e10cSrcweir     {
993cdf0e10cSrcweir         for (set<SCROW>::const_iterator itr = maRowManualBreaks.begin(), itrEnd = maRowManualBreaks.end();
994cdf0e10cSrcweir               itr != itrEnd; ++itr)
995cdf0e10cSrcweir             pRowFlags->OrValue(*itr, static_int_cast<sal_uInt8>(CR_MANUALBREAK));
996cdf0e10cSrcweir     }
997cdf0e10cSrcweir 
998cdf0e10cSrcweir     if (!maColManualBreaks.empty())
999cdf0e10cSrcweir     {
1000cdf0e10cSrcweir         for (set<SCCOL>::const_iterator itr = maColManualBreaks.begin(), itrEnd = maColManualBreaks.end();
1001cdf0e10cSrcweir               itr != itrEnd; ++itr)
1002cdf0e10cSrcweir             pColFlags[*itr] |= CR_MANUALBREAK;
1003cdf0e10cSrcweir     }
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir     // Hidden flags.
1006cdf0e10cSrcweir     lcl_syncFlags(*mpHiddenCols, *mpHiddenRows, pColFlags, pRowFlags, CR_HIDDEN);
1007cdf0e10cSrcweir     lcl_syncFlags(*mpFilteredCols, *mpFilteredRows, pColFlags, pRowFlags, CR_FILTERED);
1008cdf0e10cSrcweir }
1009cdf0e10cSrcweir 
SetPageSize(const Size & rSize)1010cdf0e10cSrcweir void ScTable::SetPageSize( const Size& rSize )
1011cdf0e10cSrcweir {
1012cdf0e10cSrcweir 	if ( rSize.Width() != 0 && rSize.Height() != 0 )
1013cdf0e10cSrcweir 	{
1014cdf0e10cSrcweir         if (aPageSizeTwips != rSize)
1015cdf0e10cSrcweir             InvalidatePageBreaks();
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir 		bPageSizeValid = sal_True;
1018cdf0e10cSrcweir 		aPageSizeTwips = rSize;
1019cdf0e10cSrcweir 	}
1020cdf0e10cSrcweir 	else
1021cdf0e10cSrcweir 		bPageSizeValid = sal_False;
1022cdf0e10cSrcweir }
1023cdf0e10cSrcweir 
IsProtected() const1024cdf0e10cSrcweir sal_Bool ScTable::IsProtected() const
1025cdf0e10cSrcweir {
1026cdf0e10cSrcweir     return pTabProtection.get() && pTabProtection->isProtected();
1027cdf0e10cSrcweir }
1028cdf0e10cSrcweir 
SetProtection(const ScTableProtection * pProtect)1029cdf0e10cSrcweir void ScTable::SetProtection(const ScTableProtection* pProtect)
1030cdf0e10cSrcweir {
1031cdf0e10cSrcweir     if (pProtect)
1032cdf0e10cSrcweir         pTabProtection.reset(new ScTableProtection(*pProtect));
1033cdf0e10cSrcweir     else
1034*3d762826SHerbert Dürr         pTabProtection.reset();
1035cdf0e10cSrcweir 
1036cdf0e10cSrcweir     if (IsStreamValid())
1037cdf0e10cSrcweir         SetStreamValid(sal_False);
1038cdf0e10cSrcweir }
1039cdf0e10cSrcweir 
GetProtection()1040cdf0e10cSrcweir ScTableProtection* ScTable::GetProtection()
1041cdf0e10cSrcweir {
1042cdf0e10cSrcweir     return pTabProtection.get();
1043cdf0e10cSrcweir }
1044cdf0e10cSrcweir 
GetPageSize() const1045cdf0e10cSrcweir Size ScTable::GetPageSize() const
1046cdf0e10cSrcweir {
1047cdf0e10cSrcweir 	if ( bPageSizeValid )
1048cdf0e10cSrcweir 		return aPageSizeTwips;
1049cdf0e10cSrcweir 	else
1050cdf0e10cSrcweir 		return Size();	// leer
1051cdf0e10cSrcweir }
1052cdf0e10cSrcweir 
SetRepeatArea(SCCOL nStartCol,SCCOL nEndCol,SCROW nStartRow,SCROW nEndRow)1053cdf0e10cSrcweir void ScTable::SetRepeatArea( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCROW nEndRow )
1054cdf0e10cSrcweir {
1055dcafab4fSMichael Stahl     // #i117952# page break calculation uses these values (set from ScPrintFunc), not pRepeatColRange/pRepeatRowRange
1056dcafab4fSMichael Stahl     if ( nStartCol != nRepeatStartX || nEndCol != nRepeatEndX || nStartRow != nRepeatStartY || nEndRow != nRepeatEndY )
1057dcafab4fSMichael Stahl         InvalidatePageBreaks();
1058dcafab4fSMichael Stahl 
1059cdf0e10cSrcweir 	nRepeatStartX = nStartCol;
1060cdf0e10cSrcweir 	nRepeatEndX   = nEndCol;
1061cdf0e10cSrcweir 	nRepeatStartY = nStartRow;
1062cdf0e10cSrcweir 	nRepeatEndY   = nEndRow;
1063cdf0e10cSrcweir }
1064cdf0e10cSrcweir 
StartListening(const ScAddress & rAddress,SvtListener * pListener)1065cdf0e10cSrcweir void ScTable::StartListening( const ScAddress& rAddress, SvtListener* pListener )
1066cdf0e10cSrcweir {
1067cdf0e10cSrcweir 	aCol[rAddress.Col()].StartListening( *pListener, rAddress.Row() );
1068cdf0e10cSrcweir }
1069cdf0e10cSrcweir 
EndListening(const ScAddress & rAddress,SvtListener * pListener)1070cdf0e10cSrcweir void ScTable::EndListening( const ScAddress& rAddress, SvtListener* pListener )
1071cdf0e10cSrcweir {
1072cdf0e10cSrcweir 	aCol[rAddress.Col()].EndListening( *pListener, rAddress.Row() );
1073cdf0e10cSrcweir }
1074cdf0e10cSrcweir 
SetPageStyle(const String & rName)1075cdf0e10cSrcweir void ScTable::SetPageStyle( const String& rName )
1076cdf0e10cSrcweir {
1077cdf0e10cSrcweir 	if ( aPageStyle != rName )
1078cdf0e10cSrcweir 	{
1079cdf0e10cSrcweir 		String					aStrNew    = rName;
1080cdf0e10cSrcweir 		SfxStyleSheetBasePool*	pStylePool = pDocument->GetStyleSheetPool();
1081cdf0e10cSrcweir 		SfxStyleSheetBase*		pNewStyle  = pStylePool->Find( aStrNew, SFX_STYLE_FAMILY_PAGE );
1082cdf0e10cSrcweir 
1083cdf0e10cSrcweir 		if ( !pNewStyle )
1084cdf0e10cSrcweir 		{
1085cdf0e10cSrcweir 			aStrNew = ScGlobal::GetRscString(STR_STYLENAME_STANDARD);
1086cdf0e10cSrcweir 			pNewStyle = pStylePool->Find( aStrNew, SFX_STYLE_FAMILY_PAGE );
1087cdf0e10cSrcweir 		}
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir 		if ( aPageStyle != aStrNew )
1090cdf0e10cSrcweir 		{
1091cdf0e10cSrcweir 			SfxStyleSheetBase* pOldStyle = pStylePool->Find( aPageStyle, SFX_STYLE_FAMILY_PAGE );
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir 			if ( pOldStyle && pNewStyle )
1094cdf0e10cSrcweir 			{
1095cdf0e10cSrcweir 				SfxItemSet&  rOldSet		  = pOldStyle->GetItemSet();
1096cdf0e10cSrcweir 				SfxItemSet&  rNewSet 		  = pNewStyle->GetItemSet();
1097cdf0e10cSrcweir 				const sal_uInt16 nOldScale		  = GET_SCALEVALUE(rOldSet,ATTR_PAGE_SCALE);
1098cdf0e10cSrcweir 				const sal_uInt16 nOldScaleToPages = GET_SCALEVALUE(rOldSet,ATTR_PAGE_SCALETOPAGES);
1099cdf0e10cSrcweir 				const sal_uInt16 nNewScale		  = GET_SCALEVALUE(rNewSet,ATTR_PAGE_SCALE);
1100cdf0e10cSrcweir 				const sal_uInt16 nNewScaleToPages = GET_SCALEVALUE(rNewSet,ATTR_PAGE_SCALETOPAGES);
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir 				if ( (nOldScale != nNewScale) || (nOldScaleToPages != nNewScaleToPages) )
1103cdf0e10cSrcweir                     InvalidateTextWidth(NULL, NULL, sal_False, sal_False);
1104cdf0e10cSrcweir 			}
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir 			if ( pNewStyle )			// auch ohne den alten (fuer UpdateStdNames)
1107cdf0e10cSrcweir 				aPageStyle = aStrNew;
1108cdf0e10cSrcweir 
1109cdf0e10cSrcweir             if (IsStreamValid())
1110cdf0e10cSrcweir                 SetStreamValid(sal_False);
1111cdf0e10cSrcweir 		}
1112cdf0e10cSrcweir 	}
1113cdf0e10cSrcweir }
1114cdf0e10cSrcweir 
PageStyleModified(const String & rNewName)1115cdf0e10cSrcweir void ScTable::PageStyleModified( const String& rNewName )
1116cdf0e10cSrcweir {
1117cdf0e10cSrcweir 	aPageStyle = rNewName;
1118cdf0e10cSrcweir     InvalidateTextWidth(NULL, NULL, sal_False, sal_False);      // don't know what was in the style before
1119cdf0e10cSrcweir }
1120cdf0e10cSrcweir 
InvalidateTextWidth(const ScAddress * pAdrFrom,const ScAddress * pAdrTo,sal_Bool bNumFormatChanged,sal_Bool bBroadcast)1121cdf0e10cSrcweir void ScTable::InvalidateTextWidth( const ScAddress* pAdrFrom, const ScAddress* pAdrTo,
1122cdf0e10cSrcweir                                    sal_Bool bNumFormatChanged, sal_Bool bBroadcast )
1123cdf0e10cSrcweir {
1124cdf0e10cSrcweir 	if ( pAdrFrom && !pAdrTo )
1125cdf0e10cSrcweir 	{
1126cdf0e10cSrcweir 		ScBaseCell* pCell = aCol[pAdrFrom->Col()].GetCell( pAdrFrom->Row() );
1127cdf0e10cSrcweir 		if ( pCell )
1128cdf0e10cSrcweir 		{
1129cdf0e10cSrcweir 			pCell->SetTextWidth( TEXTWIDTH_DIRTY );
1130cdf0e10cSrcweir             if ( bNumFormatChanged )
1131cdf0e10cSrcweir                 pCell->SetScriptType( SC_SCRIPTTYPE_UNKNOWN );
1132cdf0e10cSrcweir 			if ( bBroadcast )
1133cdf0e10cSrcweir 			{	// nur bei CalcAsShown
1134cdf0e10cSrcweir 				switch ( pCell->GetCellType() )
1135cdf0e10cSrcweir 				{
1136cdf0e10cSrcweir 					case CELLTYPE_VALUE :
1137cdf0e10cSrcweir 						pDocument->Broadcast( SC_HINT_DATACHANGED,
1138cdf0e10cSrcweir 							ScAddress( pAdrFrom->Col(), pAdrFrom->Row(), nTab ),
1139cdf0e10cSrcweir 							pCell );
1140cdf0e10cSrcweir 						break;
1141cdf0e10cSrcweir 					case CELLTYPE_FORMULA :
1142cdf0e10cSrcweir 						((ScFormulaCell*)pCell)->SetDirty();
1143cdf0e10cSrcweir 						break;
1144cdf0e10cSrcweir                     default:
1145cdf0e10cSrcweir                     {
1146cdf0e10cSrcweir                         // added to avoid warnings
1147cdf0e10cSrcweir                     }
1148cdf0e10cSrcweir 				}
1149cdf0e10cSrcweir 			}
1150cdf0e10cSrcweir 		}
1151cdf0e10cSrcweir 	}
1152cdf0e10cSrcweir 	else
1153cdf0e10cSrcweir 	{
1154cdf0e10cSrcweir 		const SCCOL nColStart = pAdrFrom ? pAdrFrom->Col() : 0;
1155cdf0e10cSrcweir 		const SCROW nRowStart = pAdrFrom ? pAdrFrom->Row() : 0;
1156cdf0e10cSrcweir 		const SCCOL nColEnd   = pAdrTo   ? pAdrTo->Col()   : MAXCOL;
1157cdf0e10cSrcweir 		const SCROW nRowEnd   = pAdrTo   ? pAdrTo->Row()   : MAXROW;
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir 		for ( SCCOL nCol=nColStart; nCol<=nColEnd; nCol++ )
1160cdf0e10cSrcweir 		{
1161cdf0e10cSrcweir 			ScColumnIterator aIter( &aCol[nCol], nRowStart, nRowEnd );
1162cdf0e10cSrcweir 			ScBaseCell*		 pCell = NULL;
1163cdf0e10cSrcweir 			SCROW			 nRow  = nRowStart;
1164cdf0e10cSrcweir 
1165cdf0e10cSrcweir 			while ( aIter.Next( nRow, pCell ) )
1166cdf0e10cSrcweir 			{
1167cdf0e10cSrcweir 				pCell->SetTextWidth( TEXTWIDTH_DIRTY );
1168cdf0e10cSrcweir                 if ( bNumFormatChanged )
1169cdf0e10cSrcweir                     pCell->SetScriptType( SC_SCRIPTTYPE_UNKNOWN );
1170cdf0e10cSrcweir 				if ( bBroadcast )
1171cdf0e10cSrcweir 				{	// nur bei CalcAsShown
1172cdf0e10cSrcweir 					switch ( pCell->GetCellType() )
1173cdf0e10cSrcweir 					{
1174cdf0e10cSrcweir 						case CELLTYPE_VALUE :
1175cdf0e10cSrcweir 							pDocument->Broadcast( SC_HINT_DATACHANGED,
1176cdf0e10cSrcweir 								ScAddress( nCol, nRow, nTab ), pCell );
1177cdf0e10cSrcweir 							break;
1178cdf0e10cSrcweir 						case CELLTYPE_FORMULA :
1179cdf0e10cSrcweir 							((ScFormulaCell*)pCell)->SetDirty();
1180cdf0e10cSrcweir 							break;
1181cdf0e10cSrcweir                         default:
1182cdf0e10cSrcweir                         {
1183cdf0e10cSrcweir                             // added to avoid warnings
1184cdf0e10cSrcweir                         }
1185cdf0e10cSrcweir 					}
1186cdf0e10cSrcweir 				}
1187cdf0e10cSrcweir 			}
1188cdf0e10cSrcweir 		}
1189cdf0e10cSrcweir 	}
1190cdf0e10cSrcweir }
1191cdf0e10cSrcweir 
1192cdf0e10cSrcweir 
1193cdf0e10cSrcweir 
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir 
1196