1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <scitems.hxx>
#include <editeng/boxitem.hxx>
#include <editeng/lineitem.hxx>
#include <editeng/shaditem.hxx>
#include <editeng/brushitem.hxx>
#include <svx/framelink.hxx>
#include <fillinfo.hxx>
#include <document.hxx>
#include <table.hxx>
#include <attrib.hxx>
#include <attarray.hxx>
#include <markarr.hxx>
#include <markdata.hxx>
#include <patattr.hxx>
#include <poolhelp.hxx>
#include <docpool.hxx>
#include <conditio.hxx>
#include <stlpool.hxx>
#include <cellvalue.hxx>
#include <mtvcellfunc.hxx>
#include <algorithm>
#include <limits>
#include <vector>
#include <memory>
// Similar as in output.cxx
static void lcl_GetMergeRange( SCCOL nX, SCROW nY, SCSIZE nArrY,
const ScDocument* pDoc, RowInfo* pRowInfo,
SCCOL nX1, SCROW nY1, SCTAB nTab,
SCCOL& rStartX, SCROW& rStartY, SCCOL& rEndX, SCROW& rEndY )
{
CellInfo* pInfo = &pRowInfo[nArrY].pCellInfo[nX+1];
rStartX = nX;
rStartY = nY;
bool bHOver = pInfo->bHOverlapped;
bool bVOver = pInfo->bVOverlapped;
SCCOL nLastCol;
SCROW nLastRow;
while (bHOver) // nY constant
{
--rStartX;
if (rStartX >= nX1 && !pDoc->ColHidden(rStartX, nTab, nullptr, &nLastCol))
{
bHOver = pRowInfo[nArrY].pCellInfo[rStartX+1].bHOverlapped;
bVOver = pRowInfo[nArrY].pCellInfo[rStartX+1].bVOverlapped;
}
else
{
ScMF nOverlap = pDoc->GetAttr( rStartX, rStartY, nTab, ATTR_MERGE_FLAG )->GetValue();
bHOver = bool(nOverlap & ScMF::Hor);
bVOver = bool(nOverlap & ScMF::Ver);
}
}
while (bVOver)
{
--rStartY;
if (nArrY>0)
--nArrY; // local copy !
if (rStartX >= nX1 && rStartY >= nY1 &&
!pDoc->ColHidden(rStartX, nTab, nullptr, &nLastCol) &&
!pDoc->RowHidden(rStartY, nTab, nullptr, &nLastRow) &&
pRowInfo[nArrY].nRowNo == rStartY)
{
bVOver = pRowInfo[nArrY].pCellInfo[rStartX+1].bVOverlapped;
}
else
{
ScMF nOverlap = pDoc->GetAttr(
rStartX, rStartY, nTab, ATTR_MERGE_FLAG )->GetValue();
bVOver = bool(nOverlap & ScMF::Ver);
}
}
const ScMergeAttr* pMerge;
if (rStartX >= nX1 && rStartY >= nY1 &&
!pDoc->ColHidden(rStartX, nTab, nullptr, &nLastCol) &&
!pDoc->RowHidden(rStartY, nTab, nullptr, &nLastRow) &&
pRowInfo[nArrY].nRowNo == rStartY)
{
pMerge = &pRowInfo[nArrY].pCellInfo[rStartX+1].pPatternAttr->
GetItem(ATTR_MERGE);
}
else
pMerge = pDoc->GetAttr(rStartX,rStartY,nTab,ATTR_MERGE);
rEndX = rStartX + pMerge->GetColMerge() - 1;
rEndY = rStartY + pMerge->GetRowMerge() - 1;
}
namespace {
class RowInfoFiller
{
ScDocument& mrDoc;
SCTAB mnTab;
RowInfo* mpRowInfo;
SCCOL mnArrX;
SCSIZE mnArrY;
SCROW mnHiddenEndRow;
bool mbHiddenRow;
bool isHidden(size_t nRow)
{
SCROW nThisRow = static_cast<SCROW>(nRow);
if (nThisRow > mnHiddenEndRow)
mbHiddenRow = mrDoc.RowHidden(nThisRow, mnTab, nullptr, &mnHiddenEndRow);
return mbHiddenRow;
}
void alignArray(size_t nRow)
{
while (mpRowInfo[mnArrY].nRowNo < static_cast<SCROW>(nRow))
++mnArrY;
}
void setInfo(size_t nRow, const ScRefCellValue& rCell)
{
alignArray(nRow);
RowInfo& rThisRowInfo = mpRowInfo[mnArrY];
CellInfo& rInfo = rThisRowInfo.pCellInfo[mnArrX];
rInfo.maCell = rCell;
rInfo.bEmptyCellText = false;
++mnArrY;
}
public:
RowInfoFiller(ScDocument& rDoc, SCTAB nTab, RowInfo* pRowInfo, SCCOL nArrX, SCSIZE nArrY) :
mrDoc(rDoc), mnTab(nTab), mpRowInfo(pRowInfo), mnArrX(nArrX), mnArrY(nArrY),
mnHiddenEndRow(-1), mbHiddenRow(false) {}
void operator() (size_t nRow, double fVal)
{
if (!isHidden(nRow))
setInfo(nRow, ScRefCellValue(fVal));
}
void operator() (size_t nRow, const svl::SharedString& rStr)
{
if (!isHidden(nRow))
setInfo(nRow, ScRefCellValue(&rStr));
}
void operator() (size_t nRow, const EditTextObject* p)
{
if (!isHidden(nRow))
setInfo(nRow, ScRefCellValue(p));
}
void operator() (size_t nRow, const ScFormulaCell* p)
{
if (!isHidden(nRow))
setInfo(nRow, ScRefCellValue(const_cast<ScFormulaCell*>(p)));
}
};
bool isRotateItemUsed(const ScDocumentPool *pPool)
{
return pPool->GetItemCount2( ATTR_ROTATE_VALUE ) > 0;
}
void initRowInfo(const ScDocument* pDoc, RowInfo* pRowInfo, const SCSIZE nMaxRow,
double fRowScale, SCROW nRow1, SCTAB nTab, SCROW& rYExtra, SCSIZE& rArrRow, SCROW& rRow2)
{
sal_uInt16 nDocHeight = ScGlobal::nStdRowHeight;
SCROW nDocHeightEndRow = -1;
for (SCROW nSignedY=nRow1-1; nSignedY<=rYExtra; nSignedY++)
{
SCROW nY;
if (nSignedY >= 0)
nY = nSignedY;
else
nY = MAXROW+1; // invalid
if (nY > nDocHeightEndRow)
{
if (pDoc->ValidRow(nY))
nDocHeight = pDoc->GetRowHeight( nY, nTab, nullptr, &nDocHeightEndRow );
else
nDocHeight = ScGlobal::nStdRowHeight;
}
if ( rArrRow==0 || nDocHeight || nY > MAXROW )
{
RowInfo* pThisRowInfo = &pRowInfo[rArrRow];
pThisRowInfo->pCellInfo = nullptr; // is loaded below
sal_uInt16 nHeight = static_cast<sal_uInt16>(
std::clamp(
nDocHeight * fRowScale, 1.0, double(std::numeric_limits<sal_uInt16>::max())));
pThisRowInfo->nRowNo = nY; //TODO: case < 0 ?
pThisRowInfo->nHeight = nHeight;
pThisRowInfo->bEmptyBack = true;
pThisRowInfo->bChanged = true;
pThisRowInfo->bAutoFilter = false;
pThisRowInfo->bPivotButton = false;
pThisRowInfo->nRotMaxCol = SC_ROTMAX_NONE;
++rArrRow;
if (rArrRow >= nMaxRow)
{
OSL_FAIL("FillInfo: Range too big" );
rYExtra = nSignedY; // End
rRow2 = rYExtra - 1; // Adjust range
}
}
else
if (nSignedY == rYExtra) // hidden additional line?
++rYExtra;
}
}
void initCellInfo(RowInfo* pRowInfo, SCSIZE nArrCount, SCCOL nRotMax,
const SvxShadowItem* pDefShadow)
{
for (SCSIZE nArrRow = 0; nArrRow < nArrCount; ++nArrRow)
{
RowInfo& rThisRowInfo = pRowInfo[nArrRow];
rThisRowInfo.pCellInfo = new CellInfo[nRotMax + 1 + 2]; // to delete the caller!
for (SCCOL nArrCol = 0; nArrCol <= nRotMax+2; ++nArrCol) // Preassign cell info
{
CellInfo& rInfo = rThisRowInfo.pCellInfo[nArrCol];
rInfo.bEmptyCellText = true;
rInfo.pShadowAttr = pDefShadow;
}
}
}
void initColWidths(RowInfo* pRowInfo, const ScDocument* pDoc, double fColScale, SCTAB nTab, SCCOL nCol2, SCCOL nRotMax)
{
for (SCCOL nArrCol=nCol2+3; nArrCol<=nRotMax+2; nArrCol++) // Add remaining widths
{
SCCOL nX = nArrCol-1;
if ( pDoc->ValidCol(nX) )
{
if (!pDoc->ColHidden(nX, nTab))
{
sal_uInt16 nThisWidth = static_cast<sal_uInt16>(pDoc->GetColWidth( nX, nTab ) * fColScale);
if (!nThisWidth)
nThisWidth = 1;
pRowInfo[0].pCellInfo[nArrCol].nWidth = nThisWidth;
}
}
}
}
bool handleConditionalFormat(ScConditionalFormatList& rCondFormList, const ScCondFormatIndexes& rCondFormats,
CellInfo* pInfo, ScStyleSheetPool* pStlPool,
const ScAddress& rAddr, bool& bHidden, bool& bHideFormula, bool bTabProtect)
{
bool bFound = false;
bool bAnyCondition = false;
for(const auto& rCondFormat : rCondFormats)
{
ScConditionalFormat* pCondForm = rCondFormList.GetFormat(rCondFormat);
if(!pCondForm)
continue;
ScCondFormatData aData = pCondForm->GetData(
pInfo->maCell, rAddr);
if (!aData.aStyleName.isEmpty())
{
SfxStyleSheetBase* pStyleSheet =
pStlPool->Find( aData.aStyleName, SfxStyleFamily::Para );
if ( pStyleSheet )
{
//TODO: cache Style-Sets !!!
pInfo->pConditionSet = &pStyleSheet->GetItemSet();
bAnyCondition = true;
// TODO: moggi: looks like there is a bug around bHidden and bHideFormula
// They are normally for the whole pattern and not for a single cell
// we need to check already here for protected cells
const SfxPoolItem* pItem;
if ( bTabProtect && pInfo->pConditionSet->GetItemState( ATTR_PROTECTION, true, &pItem ) == SfxItemState::SET )
{
const ScProtectionAttr* pProtAttr = static_cast<const ScProtectionAttr*>(pItem);
bHidden = pProtAttr->GetHideCell();
bHideFormula = pProtAttr->GetHideFormula();
}
bFound = true;
}
// if style is not there, treat like no condition
}
if(aData.mxColorScale)
{
pInfo->mxColorScale = aData.mxColorScale;
bFound = true;
}
if(aData.pDataBar)
{
pInfo->pDataBar = std::move(aData.pDataBar);
bFound = true;
}
if(aData.pIconSet)
{
pInfo->pIconSet = std::move(aData.pIconSet);
bFound = true;
}
if (bFound)
break;
}
return bAnyCondition;
}
}
void ScDocument::FillInfo(
ScTableInfo& rTabInfo, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
SCTAB nTab, double fColScale, double fRowScale, bool bPageMode, bool bFormulaMode,
const ScMarkData* pMarkData )
{
OSL_ENSURE( maTabs[nTab], "Table does not exist" );
bool bLayoutRTL = IsLayoutRTL( nTab );
ScDocumentPool* pPool = mxPoolHelper->GetDocPool();
ScStyleSheetPool* pStlPool = mxPoolHelper->GetStylePool();
RowInfo* pRowInfo = rTabInfo.mpRowInfo.get();
const SvxBrushItem* pDefBackground =
&pPool->GetDefaultItem( ATTR_BACKGROUND );
const ScMergeAttr* pDefMerge =
&pPool->GetDefaultItem( ATTR_MERGE );
const SvxShadowItem* pDefShadow =
&pPool->GetDefaultItem( ATTR_SHADOW );
SCSIZE nArrRow;
SCSIZE nArrCount;
bool bAnyMerged = false;
bool bAnyShadow = false;
bool bAnyCondition = false;
bool bAnyPreview = false;
bool bTabProtect = IsTabProtected(nTab);
// first only the entries for the entire column
nArrRow=0;
SCROW nYExtra = nRow2+1;
initRowInfo(this, pRowInfo, rTabInfo.mnArrCapacity, fRowScale, nRow1,
nTab, nYExtra, nArrRow, nRow2);
nArrCount = nArrRow; // incl. Dummys
// Rotated text...
// Is Attribute really used in document?
bool bAnyItem = isRotateItemUsed(pPool);
SCCOL nRotMax = nCol2;
if ( bAnyItem && HasAttrib( 0, nRow1, nTab, MAXCOL, nRow2+1, nTab,
HasAttrFlags::Rotate | HasAttrFlags::Conditional ) )
{
//TODO: check Conditionals also for HasAttrFlags::Rotate ????
OSL_ENSURE( nArrCount>2, "nArrCount too small" );
FindMaxRotCol( nTab, &pRowInfo[1], nArrCount-1, nCol1, nCol2 );
// FindMaxRotCol setzt nRotMaxCol
for (nArrRow=0; nArrRow<nArrCount; nArrRow++)
if (pRowInfo[nArrRow].nRotMaxCol != SC_ROTMAX_NONE && pRowInfo[nArrRow].nRotMaxCol > nRotMax)
nRotMax = pRowInfo[nArrRow].nRotMaxCol;
}
// Allocate cell information only after the test rotation
// to nRotMax due to nRotateDir Flag
initCellInfo(pRowInfo, nArrCount, nRotMax, pDefShadow);
initColWidths(pRowInfo, this, fColScale, nTab, nCol2, nRotMax);
ScConditionalFormatList* pCondFormList = GetCondFormList(nTab);
if (pCondFormList)
pCondFormList->startRendering();
for (SCCOL nArrCol=0; nArrCol<=nCol2+2; nArrCol++) // left & right + 1
{
SCCOL nX = (nArrCol>0) ? nArrCol-1 : MAXCOL+1; // negative -> invalid
if (ValidCol(nX))
{
// #i58049#, #i57939# Hidden columns must be skipped here, or their attributes
// will disturb the output
// TODO: Optimize this loop.
if (!ColHidden(nX, nTab))
{
sal_uInt16 nThisWidth = static_cast<sal_uInt16>(std::clamp(GetColWidth( nX, nTab ) * fColScale, 1.0, double(std::numeric_limits<sal_uInt16>::max())));
pRowInfo[0].pCellInfo[nArrCol].nWidth = nThisWidth; //TODO: this should be enough
const ScAttrArray* pThisAttrArr; // Attribute
if (nX < maTabs[nTab]->GetAllocatedColumnsCount())
{
ScColumn* pThisCol = &maTabs[nTab]->aCol[nX]; // Column data
nArrRow = 1;
// Iterate between rows nY1 and nY2 and pick up non-empty
// cells that are not hidden.
RowInfoFiller aFunc(*this, nTab, pRowInfo, nArrCol, nArrRow);
sc::ParseAllNonEmpty(pThisCol->maCells.begin(), pThisCol->maCells, nRow1, nRow2,
aFunc);
pThisAttrArr = pThisCol->pAttrArray.get();
}
else
pThisAttrArr = &maTabs[nTab]->aDefaultColAttrArray;
if (nX+1 >= nCol1) // Attribute/Blockmark from nX1-1
{
nArrRow = 0;
SCROW nCurRow=nRow1; // single rows
if (nCurRow>0)
--nCurRow; // 1 more on top
else
nArrRow = 1;
SCROW nThisRow;
SCSIZE nIndex;
if ( pThisAttrArr->Count() )
(void) pThisAttrArr->Search( nCurRow, nIndex );
else
nIndex = 0;
do
{
const ScPatternAttr* pPattern = nullptr;
if ( pThisAttrArr->Count() )
{
nThisRow = pThisAttrArr->mvData[nIndex].nEndRow; // End of range
pPattern = pThisAttrArr->mvData[nIndex].pPattern;
}
else
{
nThisRow = MAXROW;
pPattern = GetDefPattern();
}
const SvxBrushItem* pBackground = &pPattern->GetItem(ATTR_BACKGROUND);
const SvxBoxItem* pLinesAttr = &pPattern->GetItem(ATTR_BORDER);
const SvxLineItem* pTLBRLine = &pPattern->GetItem( ATTR_BORDER_TLBR );
const SvxLineItem* pBLTRLine = &pPattern->GetItem( ATTR_BORDER_BLTR );
const SvxShadowItem* pShadowAttr = &pPattern->GetItem(ATTR_SHADOW);
if (pShadowAttr != pDefShadow)
bAnyShadow = true;
const ScMergeAttr* pMergeAttr = &pPattern->GetItem(ATTR_MERGE);
bool bMerged = ( pMergeAttr != pDefMerge && *pMergeAttr != *pDefMerge );
ScMF nOverlap = pPattern->GetItemSet().
Get(ATTR_MERGE_FLAG).GetValue();
bool bHOverlapped(nOverlap & ScMF::Hor);
bool bVOverlapped(nOverlap & ScMF::Ver);
bool bAutoFilter(nOverlap & ScMF::Auto);
bool bPivotButton(nOverlap & ScMF::Button);
bool bScenario(nOverlap & ScMF::Scenario);
bool bPivotPopupButton(nOverlap & ScMF::ButtonPopup);
bool bFilterActive(nOverlap & ScMF::HiddenMember);
if (bMerged||bHOverlapped||bVOverlapped)
bAnyMerged = true; // internal
bool bHidden, bHideFormula;
if (bTabProtect)
{
const ScProtectionAttr& rProtAttr = pPattern->GetItem(ATTR_PROTECTION);
bHidden = rProtAttr.GetHideCell();
bHideFormula = rProtAttr.GetHideFormula();
}
else
bHidden = bHideFormula = false;
const ScCondFormatIndexes& rCondFormats = pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData();
bool bContainsCondFormat = !rCondFormats.empty();
do
{
SCROW nLastHiddenRow = -1;
bool bRowHidden = RowHidden(nCurRow, nTab, nullptr, &nLastHiddenRow);
if ( nArrRow==0 || !bRowHidden )
{
if ( GetPreviewCellStyle( nX, nCurRow, nTab ) != nullptr )
bAnyPreview = true;
RowInfo* pThisRowInfo = &pRowInfo[nArrRow];
if (pBackground != pDefBackground) // Column background == Default ?
pThisRowInfo->bEmptyBack = false;
if (bContainsCondFormat)
pThisRowInfo->bEmptyBack = false;
if (bAutoFilter)
pThisRowInfo->bAutoFilter = true;
if (bPivotButton || bPivotPopupButton)
pThisRowInfo->bPivotButton = true;
CellInfo* pInfo = &pThisRowInfo->pCellInfo[nArrCol];
pInfo->pBackground = pBackground;
pInfo->pPatternAttr = pPattern;
pInfo->bMerged = bMerged;
pInfo->bHOverlapped = bHOverlapped;
pInfo->bVOverlapped = bVOverlapped;
pInfo->bAutoFilter = bAutoFilter;
pInfo->bPivotButton = bPivotButton;
pInfo->bPivotPopupButton = bPivotPopupButton;
pInfo->bFilterActive = bFilterActive;
pInfo->pLinesAttr = pLinesAttr;
pInfo->mpTLBRLine = pTLBRLine;
pInfo->mpBLTRLine = pBLTRLine;
pInfo->pShadowAttr = pShadowAttr;
// nWidth is no longer set individually
if (bScenario)
{
pInfo->pBackground = ScGlobal::GetButtonBrushItem();
pThisRowInfo->bEmptyBack = false;
}
if (bContainsCondFormat && pCondFormList)
{
bAnyCondition |= handleConditionalFormat(*pCondFormList, rCondFormats, pInfo, pStlPool, ScAddress(nX, nCurRow, nTab),
bHidden, bHideFormula, bTabProtect);
}
if (bHidden || (bFormulaMode && bHideFormula && pInfo->maCell.meType == CELLTYPE_FORMULA))
pInfo->bEmptyCellText = true;
++nArrRow;
}
else if (nLastHiddenRow >= 0)
{
nCurRow = nLastHiddenRow;
if (nCurRow > nThisRow)
nCurRow = nThisRow;
}
++nCurRow;
}
while (nCurRow <= nThisRow && nCurRow <= nYExtra);
++nIndex;
}
while ( nIndex < pThisAttrArr->Count() && nThisRow < nYExtra );
if (pMarkData && pMarkData->IsMultiMarked())
{
// Block marks
ScMarkArray aThisMarkArr(pMarkData->GetMarkArray( nX ));
nArrRow = 1;
nCurRow = nRow1; // single rows
if ( aThisMarkArr.Search( nRow1, nIndex ) )
{
do
{
nThisRow=aThisMarkArr.mvData[nIndex].nRow; // End of range
do
{
if ( !RowHidden( nCurRow,nTab ) )
{
++nArrRow;
}
++nCurRow;
}
while (nCurRow <= nThisRow && nCurRow <= nRow2);
++nIndex;
}
while ( nIndex < aThisMarkArr.mvData.size() && nThisRow < nRow2 );
}
}
}
else // columns in front
{
for (nArrRow=1; nArrRow+1<nArrCount; nArrRow++)
{
RowInfo* pThisRowInfo = &pRowInfo[nArrRow];
CellInfo* pInfo = &pThisRowInfo->pCellInfo[nArrCol];
pInfo->nWidth = nThisWidth; //TODO: or check only 0 ??
}
}
}
}
else
pRowInfo[0].pCellInfo[nArrCol].nWidth = STD_COL_WIDTH;
// STD_COL_WIDTH farthest to the left and right is needed for DrawExtraShadow
}
if (pCondFormList)
pCondFormList->endRendering();
// evaluate conditional formatting
std::vector< std::unique_ptr<ScPatternAttr> > aAltPatterns;
// favour preview over condition
if (bAnyCondition || bAnyPreview)
{
for (nArrRow=0; nArrRow<nArrCount; nArrRow++)
{
for (SCCOL nArrCol=nCol1; nArrCol<=nCol2+2; nArrCol++) // 1 more left and right
{
CellInfo* pInfo = &pRowInfo[nArrRow].pCellInfo[nArrCol];
SCCOL nCol = (nArrCol>0) ? nArrCol-1 : MAXCOL+1;
ScPatternAttr* pModifiedPatt = nullptr;
if ( ValidCol(nCol) && pRowInfo[nArrRow].nRowNo <= MAXROW )
{
if ( ScStyleSheet* pPreviewStyle = GetPreviewCellStyle( nCol, pRowInfo[nArrRow].nRowNo, nTab ) )
{
aAltPatterns.push_back( std::make_unique<ScPatternAttr>( *pInfo->pPatternAttr ) );
pModifiedPatt = aAltPatterns.back().get();
pModifiedPatt->SetStyleSheet( pPreviewStyle );
}
}
// favour preview over condition
const SfxItemSet* pCondSet = pModifiedPatt ? &pModifiedPatt->GetItemSet() : pInfo->pConditionSet;
if (pCondSet)
{
const SfxPoolItem* pItem;
// Background
if ( pCondSet->GetItemState( ATTR_BACKGROUND, true, &pItem ) == SfxItemState::SET )
{
pInfo->pBackground = static_cast<const SvxBrushItem*>(pItem);
pRowInfo[nArrRow].bEmptyBack = false;
}
// Border
if ( pCondSet->GetItemState( ATTR_BORDER, true, &pItem ) == SfxItemState::SET )
pInfo->pLinesAttr = static_cast<const SvxBoxItem*>(pItem);
if ( pCondSet->GetItemState( ATTR_BORDER_TLBR, true, &pItem ) == SfxItemState::SET )
pInfo->mpTLBRLine = static_cast< const SvxLineItem* >( pItem );
if ( pCondSet->GetItemState( ATTR_BORDER_BLTR, true, &pItem ) == SfxItemState::SET )
pInfo->mpBLTRLine = static_cast< const SvxLineItem* >( pItem );
// Shadow
if ( pCondSet->GetItemState( ATTR_SHADOW, true, &pItem ) == SfxItemState::SET )
{
pInfo->pShadowAttr = static_cast<const SvxShadowItem*>(pItem);
bAnyShadow = true;
}
}
if( bAnyCondition && pInfo->mxColorScale)
{
pRowInfo[nArrRow].bEmptyBack = false;
pInfo->pBackground = new SvxBrushItem(*pInfo->mxColorScale, ATTR_BACKGROUND);
}
}
}
}
// End conditional formatting
// Adjust data from merged cells
if (bAnyMerged)
{
for (nArrRow=0; nArrRow<nArrCount; nArrRow++)
{
RowInfo* pThisRowInfo = &pRowInfo[nArrRow];
SCROW nSignedY = nArrRow ? pThisRowInfo->nRowNo : nRow1-1;
for (SCCOL nArrCol=nCol1; nArrCol<=nCol2+2; nArrCol++) // 1 more left and right
{
SCCOL nSignedX = nArrCol - 1;
CellInfo* pInfo = &pThisRowInfo->pCellInfo[nArrCol];
if (pInfo->bMerged || pInfo->bHOverlapped || pInfo->bVOverlapped)
{
SCCOL nStartX;
SCROW nStartY;
SCCOL nEndX;
SCROW nEndY;
lcl_GetMergeRange( nSignedX,nSignedY, nArrRow, this,pRowInfo, nCol1,nRow1,nTab,
nStartX,nStartY, nEndX,nEndY );
const ScPatternAttr* pStartPattern = GetPattern( nStartX,nStartY,nTab );
const SfxItemSet* pStartCond = GetCondResult( nStartX,nStartY,nTab );
const SfxPoolItem* pItem;
// Copy Background (or in output.cxx)
if ( !pStartCond || pStartCond->
GetItemState(ATTR_BACKGROUND,true,&pItem) != SfxItemState::SET )
pItem = &pStartPattern->GetItem(ATTR_BACKGROUND);
pInfo->pBackground = static_cast<const SvxBrushItem*>(pItem);
pRowInfo[nArrRow].bEmptyBack = false;
// Shadow
if ( !pStartCond || pStartCond->
GetItemState(ATTR_SHADOW,true,&pItem) != SfxItemState::SET )
pItem = &pStartPattern->GetItem(ATTR_SHADOW);
pInfo->pShadowAttr = static_cast<const SvxShadowItem*>(pItem);
if (pInfo->pShadowAttr != pDefShadow)
bAnyShadow = true;
}
}
}
}
if (bAnyShadow) // distribute Shadow
{
for (nArrRow=0; nArrRow<nArrCount; nArrRow++)
{
bool bTop = ( nArrRow == 0 );
bool bBottom = ( nArrRow+1 == nArrCount );
for (SCCOL nArrCol=nCol1; nArrCol<=nCol2+2; nArrCol++) // 1 more left and right
{
bool bLeft = ( nArrCol == nCol1 );
bool bRight = ( nArrCol == nCol2+2 );
CellInfo* pInfo = &pRowInfo[nArrRow].pCellInfo[nArrCol];
const SvxShadowItem* pThisAttr = pInfo->pShadowAttr;
SvxShadowLocation eLoc = pThisAttr ? pThisAttr->GetLocation() : SvxShadowLocation::NONE;
if (eLoc != SvxShadowLocation::NONE)
{
// or test on != eLoc
SCCOL nDxPos = 1;
SCCOL nDxNeg = -1;
while ( nArrCol+nDxPos < nCol2+2 && pRowInfo[0].pCellInfo[nArrCol+nDxPos].nWidth == 0 )
++nDxPos;
while ( nArrCol+nDxNeg > nCol1 && pRowInfo[0].pCellInfo[nArrCol+nDxNeg].nWidth == 0 )
--nDxNeg;
bool bLeftDiff = !bLeft &&
pRowInfo[nArrRow].pCellInfo[nArrCol+nDxNeg].pShadowAttr->GetLocation() == SvxShadowLocation::NONE;
bool bRightDiff = !bRight &&
pRowInfo[nArrRow].pCellInfo[nArrCol+nDxPos].pShadowAttr->GetLocation() == SvxShadowLocation::NONE;
bool bTopDiff = !bTop &&
pRowInfo[nArrRow-1].pCellInfo[nArrCol].pShadowAttr->GetLocation() == SvxShadowLocation::NONE;
bool bBottomDiff = !bBottom &&
pRowInfo[nArrRow+1].pCellInfo[nArrCol].pShadowAttr->GetLocation() == SvxShadowLocation::NONE;
if ( bLayoutRTL )
{
switch (eLoc)
{
case SvxShadowLocation::BottomRight: eLoc = SvxShadowLocation::BottomLeft; break;
case SvxShadowLocation::BottomLeft: eLoc = SvxShadowLocation::BottomRight; break;
case SvxShadowLocation::TopRight: eLoc = SvxShadowLocation::TopLeft; break;
case SvxShadowLocation::TopLeft: eLoc = SvxShadowLocation::TopRight; break;
default:
{
// added to avoid warnings
}
}
}
switch (eLoc)
{
case SvxShadowLocation::BottomRight:
if (bBottomDiff)
{
pRowInfo[nArrRow+1].pCellInfo[nArrCol].pHShadowOrigin = pThisAttr;
pRowInfo[nArrRow+1].pCellInfo[nArrCol].eHShadowPart =
bLeftDiff ? SC_SHADOW_HSTART : SC_SHADOW_HORIZ;
}
if (bRightDiff)
{
pRowInfo[nArrRow].pCellInfo[nArrCol+1].pVShadowOrigin = pThisAttr;
pRowInfo[nArrRow].pCellInfo[nArrCol+1].eVShadowPart =
bTopDiff ? SC_SHADOW_VSTART : SC_SHADOW_VERT;
}
if (bBottomDiff && bRightDiff)
{
pRowInfo[nArrRow+1].pCellInfo[nArrCol+1].pHShadowOrigin = pThisAttr;
pRowInfo[nArrRow+1].pCellInfo[nArrCol+1].eHShadowPart = SC_SHADOW_CORNER;
}
break;
case SvxShadowLocation::BottomLeft:
if (bBottomDiff)
{
pRowInfo[nArrRow+1].pCellInfo[nArrCol].pHShadowOrigin = pThisAttr;
pRowInfo[nArrRow+1].pCellInfo[nArrCol].eHShadowPart =
bRightDiff ? SC_SHADOW_HSTART : SC_SHADOW_HORIZ;
}
if (bLeftDiff)
{
pRowInfo[nArrRow].pCellInfo[nArrCol-1].pVShadowOrigin = pThisAttr;
pRowInfo[nArrRow].pCellInfo[nArrCol-1].eVShadowPart =
bTopDiff ? SC_SHADOW_VSTART : SC_SHADOW_VERT;
}
if (bBottomDiff && bLeftDiff)
{
pRowInfo[nArrRow+1].pCellInfo[nArrCol-1].pHShadowOrigin = pThisAttr;
pRowInfo[nArrRow+1].pCellInfo[nArrCol-1].eHShadowPart = SC_SHADOW_CORNER;
}
break;
case SvxShadowLocation::TopRight:
if (bTopDiff)
{
pRowInfo[nArrRow-1].pCellInfo[nArrCol].pHShadowOrigin = pThisAttr;
pRowInfo[nArrRow-1].pCellInfo[nArrCol].eHShadowPart =
bLeftDiff ? SC_SHADOW_HSTART : SC_SHADOW_HORIZ;
}
if (bRightDiff)
{
pRowInfo[nArrRow].pCellInfo[nArrCol+1].pVShadowOrigin = pThisAttr;
pRowInfo[nArrRow].pCellInfo[nArrCol+1].eVShadowPart =
bBottomDiff ? SC_SHADOW_VSTART : SC_SHADOW_VERT;
}
if (bTopDiff && bRightDiff)
{
pRowInfo[nArrRow-1].pCellInfo[nArrCol+1].pHShadowOrigin = pThisAttr;
pRowInfo[nArrRow-1].pCellInfo[nArrCol+1].eHShadowPart = SC_SHADOW_CORNER;
}
break;
case SvxShadowLocation::TopLeft:
if (bTopDiff)
{
pRowInfo[nArrRow-1].pCellInfo[nArrCol].pHShadowOrigin = pThisAttr;
pRowInfo[nArrRow-1].pCellInfo[nArrCol].eHShadowPart =
bRightDiff ? SC_SHADOW_HSTART : SC_SHADOW_HORIZ;
}
if (bLeftDiff)
{
pRowInfo[nArrRow].pCellInfo[nArrCol-1].pVShadowOrigin = pThisAttr;
pRowInfo[nArrRow].pCellInfo[nArrCol-1].eVShadowPart =
bBottomDiff ? SC_SHADOW_VSTART : SC_SHADOW_VERT;
}
if (bTopDiff && bLeftDiff)
{
pRowInfo[nArrRow-1].pCellInfo[nArrCol-1].pHShadowOrigin = pThisAttr;
pRowInfo[nArrRow-1].pCellInfo[nArrCol-1].eHShadowPart = SC_SHADOW_CORNER;
}
break;
default:
OSL_FAIL("wrong Shadow-Enum");
}
}
}
}
}
rTabInfo.mnArrCount = sal::static_int_cast<sal_uInt16>(nArrCount);
rTabInfo.mbPageMode = bPageMode;
// *** create the frame border array ***
// RowInfo structs are filled in the range [ 0 , nArrCount-1 ]
// each RowInfo contains CellInfo structs in the range [ nX1-1 , nX2+1 ]
size_t nColCount = nCol2 - nCol1 + 3;
size_t nRowCount = nArrCount;
svx::frame::Array& rArray = rTabInfo.maArray;
rArray.Initialize( nColCount, nRowCount );
for( size_t nRow = 0; nRow < nRowCount; ++nRow )
{
sal_uInt16 nCellInfoY = static_cast< sal_uInt16 >( nRow );
RowInfo& rThisRowInfo = pRowInfo[ nCellInfoY ];
for( size_t nCol = 0; nCol < nColCount; ++nCol )
{
sal_uInt16 nCellInfoX = static_cast< sal_uInt16 >( nCol + nCol1 );
const CellInfo& rInfo = rThisRowInfo.pCellInfo[ nCellInfoX ];
const SvxBoxItem* pBox = rInfo.pLinesAttr;
const SvxLineItem* pTLBR = rInfo.mpTLBRLine;
const SvxLineItem* pBLTR = rInfo.mpBLTRLine;
size_t nFirstCol = nCol;
size_t nFirstRow = nRow;
// *** merged cells *** -------------------------------------------
if( !rArray.IsMerged( nCol, nRow ) && (rInfo.bMerged || rInfo.bHOverlapped || rInfo.bVOverlapped) )
{
// *** insert merged range in svx::frame::Array ***
/* #i69369# top-left cell of a merged range may be located in
a hidden column or row. Use lcl_GetMergeRange() to find the
complete merged range, then calculate dimensions and
document position of the visible range. */
// note: document columns are always one less than CellInfoX coords
// note: document rows must be looked up in RowInfo structs
// current column and row in document coordinates
SCCOL nCurrDocCol = static_cast< SCCOL >( nCellInfoX - 1 );
SCROW nCurrDocRow = static_cast< SCROW >( (nCellInfoY > 0) ? rThisRowInfo.nRowNo : (nRow1 - 1) );
// find entire merged range in document, returns signed document coordinates
SCCOL nFirstRealDocColS, nLastRealDocColS;
SCROW nFirstRealDocRowS, nLastRealDocRowS;
lcl_GetMergeRange( nCurrDocCol, nCurrDocRow,
nCellInfoY, this, pRowInfo, nCol1,nRow1,nTab,
nFirstRealDocColS, nFirstRealDocRowS, nLastRealDocColS, nLastRealDocRowS );
// *complete* merged range in document coordinates
SCCOL nFirstRealDocCol = nFirstRealDocColS;
SCROW nFirstRealDocRow = nFirstRealDocRowS;
SCCOL nLastRealDocCol = nLastRealDocColS;
SCROW nLastRealDocRow = nLastRealDocRowS;
// first visible column (nX1-1 is first processed document column)
SCCOL nFirstDocCol = (nCol1 > 0) ? ::std::max< SCCOL >( nFirstRealDocCol, nCol1 - 1 ) : nFirstRealDocCol;
sal_uInt16 nFirstCellInfoX = static_cast< sal_uInt16 >( nFirstDocCol + 1 );
nFirstCol = static_cast< size_t >( nFirstCellInfoX - nCol1 );
// last visible column (nX2+1 is last processed document column)
SCCOL nLastDocCol = (nCol2 < MAXCOL) ? ::std::min< SCCOL >( nLastRealDocCol, nCol2 + 1 ) : nLastRealDocCol;
sal_uInt16 nLastCellInfoX = static_cast< sal_uInt16 >( nLastDocCol + 1 );
size_t nLastCol = static_cast< size_t >( nLastCellInfoX - nCol1 );
// first visible row
sal_uInt16 nFirstCellInfoY = nCellInfoY;
while( ((nFirstCellInfoY > 1) && (pRowInfo[ nFirstCellInfoY - 1 ].nRowNo >= nFirstRealDocRow)) ||
((nFirstCellInfoY == 1) && (static_cast< SCROW >( nRow1 - 1 ) >= nFirstRealDocRow)) )
--nFirstCellInfoY;
SCROW nFirstDocRow = (nFirstCellInfoY > 0) ? pRowInfo[ nFirstCellInfoY ].nRowNo : static_cast< SCROW >( nRow1 - 1 );
nFirstRow = static_cast< size_t >( nFirstCellInfoY );
// last visible row
sal_uInt16 nLastCellInfoY = nCellInfoY;
while( (sal::static_int_cast<SCSIZE>(nLastCellInfoY + 1) < nArrCount) &&
(pRowInfo[ nLastCellInfoY + 1 ].nRowNo <= nLastRealDocRow) )
++nLastCellInfoY;
SCROW nLastDocRow = (nLastCellInfoY > 0) ? pRowInfo[ nLastCellInfoY ].nRowNo : static_cast< SCROW >( nRow1 - 1 );
size_t nLastRow = static_cast< size_t >( nLastCellInfoY );
// insert merged range
rArray.SetMergedRange( nFirstCol, nFirstRow, nLastCol, nLastRow );
// *** find additional size not included in svx::frame::Array ***
// additional space before first column
if( nFirstCol == 0 )
{
long nSize = 0;
for( SCCOL nDocCol = nFirstRealDocCol; nDocCol < nFirstDocCol; ++nDocCol )
nSize += std::max( static_cast< long >( GetColWidth( nDocCol, nTab ) * fColScale ), 1L );
rArray.SetAddMergedLeftSize( nCol, nRow, nSize );
}
// additional space after last column
if( nLastCol + 1 == nColCount )
{
long nSize = 0;
for( SCCOL nDocCol = nLastDocCol + 1; nDocCol <= nLastRealDocCol; ++nDocCol )
nSize += std::max( static_cast< long >( GetColWidth( nDocCol, nTab ) * fColScale ), 1L );
rArray.SetAddMergedRightSize( nCol, nRow, nSize );
}
// additional space above first row
if( nFirstRow == 0 )
{
long nSize = 0;
for( SCROW nDocRow = nFirstRealDocRow; nDocRow < nFirstDocRow; ++nDocRow )
nSize += std::max( static_cast< long >( GetRowHeight( nDocRow, nTab ) * fRowScale ), 1L );
rArray.SetAddMergedTopSize( nCol, nRow, nSize );
}
// additional space beyond last row
if( nLastRow + 1 == nRowCount )
{
long nSize = 0;
for( SCROW nDocRow = nLastDocRow + 1; nDocRow <= nLastRealDocRow; ++nDocRow )
nSize += std::max( static_cast< long >( GetRowHeight( nDocRow, nTab ) * fRowScale ), 1L );
rArray.SetAddMergedBottomSize( nCol, nRow, nSize );
}
// *** use line attributes from real origin cell ***
if( (nFirstRealDocCol != nCurrDocCol) || (nFirstRealDocRow != nCurrDocRow) )
{
if( const ScPatternAttr* pPattern = GetPattern( nFirstRealDocCol, nFirstRealDocRow, nTab ) )
{
const SfxItemSet* pCond = GetCondResult( nFirstRealDocCol, nFirstRealDocRow, nTab );
pBox = &pPattern->GetItem( ATTR_BORDER, pCond );
pTLBR = &pPattern->GetItem( ATTR_BORDER_TLBR, pCond );
pBLTR = &pPattern->GetItem( ATTR_BORDER_BLTR, pCond );
}
else
{
pBox = nullptr;
pTLBR = pBLTR = nullptr;
}
}
}
// *** borders *** ------------------------------------------------
if( pBox )
{
rArray.SetCellStyleLeft( nFirstCol, nFirstRow, svx::frame::Style( pBox->GetLeft(), fColScale ) );
rArray.SetCellStyleRight( nFirstCol, nFirstRow, svx::frame::Style( pBox->GetRight(), fColScale ) );
rArray.SetCellStyleTop( nFirstCol, nFirstRow, svx::frame::Style( pBox->GetTop(), fRowScale ) );
rArray.SetCellStyleBottom( nFirstCol, nFirstRow, svx::frame::Style( pBox->GetBottom(), fRowScale ) );
}
if( pTLBR )
rArray.SetCellStyleTLBR( nFirstCol, nFirstRow, svx::frame::Style( pTLBR->GetLine(), fRowScale ) );
if( pBLTR )
rArray.SetCellStyleBLTR( nFirstCol, nFirstRow, svx::frame::Style( pBLTR->GetLine(), fRowScale ) );
}
}
/* Mirror the entire frame array. */
if( bLayoutRTL )
rArray.MirrorSelfX();
}
ScTableInfo::ScTableInfo(const SCSIZE capacity)
: mpRowInfo(new RowInfo[capacity])
, mnArrCount(0)
, mnArrCapacity(capacity)
, mbPageMode(false)
{
memset(static_cast<void*>(mpRowInfo.get()), 0, mnArrCapacity * sizeof(RowInfo));
}
ScTableInfo::~ScTableInfo()
{
for( SCSIZE nIdx = 0; nIdx < mnArrCapacity; ++nIdx )
delete [] mpRowInfo[ nIdx ].pCellInfo;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|