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