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 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
|
/* -*- 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 <vcl/msgbox.hxx>
#include <vcl/settings.hxx>
#include <comphelper/lok.hxx>
#include "gridwin.hxx"
#include "tabvwsh.hxx"
#include "docsh.hxx"
#include "viewdata.hxx"
#include "pivot.hxx"
#include "uiitems.hxx"
#include "scresid.hxx"
#include "sc.hrc"
#include "globstr.hrc"
#include "pagedata.hxx"
#include "dpobject.hxx"
#include "dpsave.hxx"
#include "dpoutput.hxx"
#include "dpshttab.hxx"
#include "dbdocfun.hxx"
#include "checklistmenu.hxx"
#include "dpcontrol.hxx"
#include "checklistmenu.hrc"
#include "strload.hxx"
#include "userlist.hxx"
#include "scabstdlg.hxx"
#include "spellcheckcontext.hxx"
#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
#include <unordered_map>
#include <vector>
using namespace css;
using namespace css::sheet;
using css::sheet::DataPilotFieldOrientation;
using std::vector;
using std::unique_ptr;
DataPilotFieldOrientation ScGridWindow::GetDPFieldOrientation( SCCOL nCol, SCROW nRow ) const
{
ScDocument* pDoc = pViewData->GetDocument();
SCTAB nTab = pViewData->GetTabNo();
ScDPObject* pDPObj = pDoc->GetDPAtCursor(nCol, nRow, nTab);
if (!pDPObj)
return DataPilotFieldOrientation_HIDDEN;
sal_uInt16 nOrient = DataPilotFieldOrientation_HIDDEN;
// Check for page field first.
if (nCol > 0)
{
// look for the dimension header left of the drop-down arrow
long nField = pDPObj->GetHeaderDim( ScAddress( nCol-1, nRow, nTab ), nOrient );
if ( nField >= 0 && nOrient == DataPilotFieldOrientation_PAGE )
{
bool bIsDataLayout = false;
OUString aFieldName = pDPObj->GetDimName( nField, bIsDataLayout );
if ( !aFieldName.isEmpty() && !bIsDataLayout )
return DataPilotFieldOrientation_PAGE;
}
}
nOrient = DataPilotFieldOrientation_HIDDEN;
// Now, check for row/column field.
long nField = pDPObj->GetHeaderDim(ScAddress(nCol, nRow, nTab), nOrient);
if (nField >= 0 && (nOrient == DataPilotFieldOrientation_COLUMN || nOrient == DataPilotFieldOrientation_ROW) )
{
bool bIsDataLayout = false;
OUString aFieldName = pDPObj->GetDimName(nField, bIsDataLayout);
if (!aFieldName.isEmpty() && !bIsDataLayout)
return static_cast<DataPilotFieldOrientation>(nOrient);
}
return DataPilotFieldOrientation_HIDDEN;
}
// private method for mouse button handling
bool ScGridWindow::DoPageFieldSelection( SCCOL nCol, SCROW nRow )
{
if (GetDPFieldOrientation( nCol, nRow ) == DataPilotFieldOrientation_PAGE)
{
LaunchPageFieldMenu( nCol, nRow );
return true;
}
return false;
}
bool ScGridWindow::DoAutoFilterButton( SCCOL nCol, SCROW nRow, const MouseEvent& rMEvt )
{
ScDocument* pDoc = pViewData->GetDocument();
SCTAB nTab = pViewData->GetTabNo();
Point aScrPos = pViewData->GetScrPos(nCol, nRow, eWhich);
Point aDiffPix = rMEvt.GetPosPixel();
aDiffPix -= aScrPos;
bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
if ( bLayoutRTL )
aDiffPix.X() = -aDiffPix.X();
long nSizeX, nSizeY;
pViewData->GetMergeSizePixel( nCol, nRow, nSizeX, nSizeY );
// The button height should not use the merged cell height, should still use single row height
nSizeY = ScViewData::ToPixel(pDoc->GetRowHeight(nRow, nTab), pViewData->GetPPTY());
Size aScrSize(nSizeX-1, nSizeY-1);
// Check if the mouse cursor is clicking on the popup arrow box.
mpFilterButton.reset(new ScDPFieldButton(this, &GetSettings().GetStyleSettings(), &pViewData->GetZoomX(), &pViewData->GetZoomY(), pDoc));
mpFilterButton->setBoundingBox(aScrPos, aScrSize, bLayoutRTL);
mpFilterButton->setPopupLeft(bLayoutRTL); // #i114944# AutoFilter button is left-aligned in RTL
Point aPopupPos;
Size aPopupSize;
mpFilterButton->getPopupBoundingBox(aPopupPos, aPopupSize);
Rectangle aRect(aPopupPos, aPopupSize);
if (aRect.IsInside(rMEvt.GetPosPixel()))
{
if ( DoPageFieldSelection( nCol, nRow ) )
return true;
bool bFilterActive = IsAutoFilterActive(nCol, nRow, nTab);
mpFilterButton->setHasHiddenMember(bFilterActive);
mpFilterButton->setDrawBaseButton(false);
mpFilterButton->setDrawPopupButton(true);
mpFilterButton->setPopupPressed(true);
mpFilterButton->draw();
LaunchAutoFilterMenu(nCol, nRow);
return true;
}
return false;
}
void ScGridWindow::DoPushPivotButton( SCCOL nCol, SCROW nRow, const MouseEvent& rMEvt, bool bButton, bool bPopup )
{
ScDocument* pDoc = pViewData->GetDocument();
SCTAB nTab = pViewData->GetTabNo();
ScDPObject* pDPObj = pDoc->GetDPAtCursor(nCol, nRow, nTab);
if (pDPObj)
{
sal_uInt16 nOrient = DataPilotFieldOrientation_HIDDEN;
ScAddress aPos( nCol, nRow, nTab );
ScAddress aDimPos = aPos;
if (!bButton && bPopup && aDimPos.Col() > 0)
// For page field selection cell, the real field position is to the left.
aDimPos.IncCol(-1);
long nField = pDPObj->GetHeaderDim(aDimPos, nOrient);
if ( nField >= 0 )
{
bDPMouse = false;
nDPField = nField;
pDragDPObj = pDPObj;
if (bPopup && DPTestFieldPopupArrow(rMEvt, aPos, aDimPos, pDPObj))
{
// field name pop up menu has been launched. Don't activate
// field move.
return;
}
if (bButton)
{
bDPMouse = true;
DPTestMouse( rMEvt, true );
StartTracking();
}
}
else if ( pDPObj->IsFilterButton(aPos) )
{
ReleaseMouse(); // may have been captured in ButtonDown
ScQueryParam aQueryParam;
SCTAB nSrcTab = 0;
const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc();
OSL_ENSURE(pDesc, "no sheet source for filter button");
if (pDesc)
{
aQueryParam = pDesc->GetQueryParam();
nSrcTab = pDesc->GetSourceRange().aStart.Tab();
}
SfxItemSet aArgSet( pViewData->GetViewShell()->GetPool(),
SCITEM_QUERYDATA, SCITEM_QUERYDATA );
aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA, pViewData, &aQueryParam ) );
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
const std::unique_ptr<AbstractScPivotFilterDlg> pDlg(
pFact->CreateScPivotFilterDlg(
pViewData->GetViewShell()->GetDialogParent(), aArgSet, nSrcTab));
OSL_ENSURE(pDlg, "Dialog create fail!");
if ( pDlg->Execute() == RET_OK )
{
ScSheetSourceDesc aNewDesc(pDoc);
if (pDesc)
aNewDesc = *pDesc;
const ScQueryItem& rQueryItem = pDlg->GetOutputItem();
aNewDesc.SetQueryParam(rQueryItem.GetQueryData());
ScDPObject aNewObj( *pDPObj );
aNewObj.SetSheetDesc( aNewDesc );
ScDBDocFunc aFunc( *pViewData->GetDocShell() );
aFunc.DataPilotUpdate( pDPObj, &aNewObj, true, false );
pViewData->GetView()->CursorPosChanged(); // shells may be switched
}
}
}
else
{
OSL_FAIL("Nothing here");
}
}
// Data Pilot interaction
void ScGridWindow::DPTestMouse( const MouseEvent& rMEvt, bool bMove )
{
OSL_ENSURE(pDragDPObj, "pDragDPObj missing");
// scroll window if at edges
//! move this to separate method
bool bTimer = false;
Point aPixel = rMEvt.GetPosPixel();
SCsCOL nDx = 0;
SCsROW nDy = 0;
if ( aPixel.X() < 0 )
nDx = -1;
if ( aPixel.Y() < 0 )
nDy = -1;
Size aSize = GetOutputSizePixel();
if ( aPixel.X() >= aSize.Width() )
nDx = 1;
if ( aPixel.Y() >= aSize.Height() )
nDy = 1;
if ( nDx != 0 || nDy != 0 )
{
UpdateDragRect( false, Rectangle() );
if ( nDx != 0)
pViewData->GetView()->ScrollX( nDx, WhichH(eWhich) );
if ( nDy != 0 )
pViewData->GetView()->ScrollY( nDy, WhichV(eWhich) );
bTimer = true;
}
SCsCOL nPosX;
SCsROW nPosY;
pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), eWhich, nPosX, nPosY );
bool bMouseLeft;
bool bMouseTop;
pViewData->GetMouseQuadrant( aPixel, eWhich, nPosX, nPosY, bMouseLeft, bMouseTop );
ScAddress aPos( nPosX, nPosY, pViewData->GetTabNo() );
Rectangle aPosRect;
sal_uInt16 nOrient;
long nDimPos;
bool bHasRange = pDragDPObj->GetHeaderDrag( aPos, bMouseLeft, bMouseTop, nDPField,
aPosRect, nOrient, nDimPos );
UpdateDragRect( bHasRange && bMove, aPosRect );
bool bIsDataLayout;
sal_Int32 nDimFlags = 0;
OUString aDimName = pDragDPObj->GetDimName( nDPField, bIsDataLayout, &nDimFlags );
bool bAllowed = !bHasRange || ScDPObject::IsOrientationAllowed( nOrient, nDimFlags );
if (bMove) // set mouse pointer
{
PointerStyle ePointer = PointerStyle::PivotDelete;
if ( !bAllowed )
ePointer = PointerStyle::NotAllowed;
else if ( bHasRange )
switch (nOrient)
{
case DataPilotFieldOrientation_COLUMN: ePointer = PointerStyle::PivotCol; break;
case DataPilotFieldOrientation_ROW: ePointer = PointerStyle::PivotRow; break;
case DataPilotFieldOrientation_PAGE:
case DataPilotFieldOrientation_DATA: ePointer = PointerStyle::PivotField; break;
}
SetPointer( ePointer );
}
else // execute change
{
if (!bHasRange)
nOrient = DataPilotFieldOrientation_HIDDEN;
if ( bIsDataLayout && ( nOrient != DataPilotFieldOrientation_COLUMN &&
nOrient != DataPilotFieldOrientation_ROW ) )
{
// removing data layout is not allowed
pViewData->GetView()->ErrorMessage(STR_PIVOT_MOVENOTALLOWED);
}
else if ( bAllowed )
{
ScDPSaveData aSaveData( *pDragDPObj->GetSaveData() );
ScDPSaveDimension* pDim;
if ( bIsDataLayout )
pDim = aSaveData.GetDataLayoutDimension();
else
pDim = aSaveData.GetDimensionByName(aDimName);
pDim->SetOrientation( nOrient );
aSaveData.SetPosition( pDim, nDimPos );
//! docfunc method with ScDPSaveData as argument?
ScDPObject aNewObj( *pDragDPObj );
aNewObj.SetSaveData( aSaveData );
ScDBDocFunc aFunc( *pViewData->GetDocShell() );
// when dragging fields, allow re-positioning (bAllowMove)
aFunc.DataPilotUpdate( pDragDPObj, &aNewObj, true, false, true );
pViewData->GetView()->CursorPosChanged(); // shells may be switched
}
}
if (bTimer && bMove)
pViewData->GetView()->SetTimer( this, rMEvt ); // repeat event
else
pViewData->GetView()->ResetTimer();
}
bool ScGridWindow::DPTestFieldPopupArrow(
const MouseEvent& rMEvt, const ScAddress& rPos, const ScAddress& rDimPos, ScDPObject* pDPObj)
{
bool bLayoutRTL = pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );
// Get the geometry of the cell.
Point aScrPos = pViewData->GetScrPos(rPos.Col(), rPos.Row(), eWhich);
long nSizeX, nSizeY;
pViewData->GetMergeSizePixel(rPos.Col(), rPos.Row(), nSizeX, nSizeY);
Size aScrSize(nSizeX-1, nSizeY-1);
// Check if the mouse cursor is clicking on the popup arrow box.
ScDPFieldButton aBtn(this, &GetSettings().GetStyleSettings());
aBtn.setBoundingBox(aScrPos, aScrSize, bLayoutRTL);
aBtn.setPopupLeft(false); // DataPilot popup is always right-aligned for now
Point aPopupPos;
Size aPopupSize;
aBtn.getPopupBoundingBox(aPopupPos, aPopupSize);
Rectangle aRect(aPopupPos, aPopupSize);
if (aRect.IsInside(rMEvt.GetPosPixel()))
{
// Mouse cursor inside the popup arrow box. Launch the field menu.
DPLaunchFieldPopupMenu(OutputToScreenPixel(aScrPos), aScrSize, rDimPos, pDPObj);
return true;
}
return false;
}
namespace {
struct DPFieldPopupData : public ScCheckListMenuWindow::ExtendedData
{
ScDPLabelData maLabels;
ScDPObject* mpDPObj;
long mnDim;
};
class DPFieldPopupOKAction : public ScMenuFloatingWindow::Action
{
public:
explicit DPFieldPopupOKAction(ScGridWindow* p) :
mpGridWindow(p) {}
virtual void execute() override
{
mpGridWindow->UpdateDPFromFieldPopupMenu();
}
private:
VclPtr<ScGridWindow> mpGridWindow;
};
class PopupSortAction : public ScMenuFloatingWindow::Action
{
public:
enum SortType { ASCENDING, DESCENDING, CUSTOM };
explicit PopupSortAction(const ScAddress& rPos, SortType eType, sal_uInt16 nUserListIndex, ScTabViewShell* pViewShell) :
maPos(rPos), meType(eType), mnUserListIndex(nUserListIndex), mpViewShell(pViewShell) {}
virtual void execute() override
{
switch (meType)
{
case ASCENDING:
mpViewShell->DataPilotSort(maPos, true);
break;
case DESCENDING:
mpViewShell->DataPilotSort(maPos, false);
break;
case CUSTOM:
mpViewShell->DataPilotSort(maPos, true, &mnUserListIndex);
break;
default:
;
}
}
private:
ScAddress maPos;
SortType meType;
sal_uInt16 mnUserListIndex;
ScTabViewShell* mpViewShell;
};
}
void ScGridWindow::DPLaunchFieldPopupMenu(
const Point& rScrPos, const Size& rScrSize, const ScAddress& rPos, ScDPObject* pDPObj)
{
unique_ptr<DPFieldPopupData> pDPData(new DPFieldPopupData);
sal_uInt16 nOrient;
pDPData->mnDim = pDPObj->GetHeaderDim(rPos, nOrient);
bool bIsDataLayout;
OUString aDimName = pDPObj->GetDimName(pDPData->mnDim, bIsDataLayout);
pDPObj->BuildAllDimensionMembers();
const ScDPSaveData* pSaveData = pDPObj->GetSaveData();
const ScDPSaveDimension* pDim = pSaveData->GetExistingDimensionByName(aDimName);
if (!pDim)
// This should never happen.
return;
// We need to get the list of field members.
pDPObj->FillLabelData(pDPData->mnDim, pDPData->maLabels);
pDPData->mpDPObj = pDPObj;
const ScDPLabelData& rLabelData = pDPData->maLabels;
mpDPFieldPopup.disposeAndClear();
mpDPFieldPopup.reset(VclPtr<ScCheckListMenuWindow>::Create(this, pViewData->GetDocument()));
mpDPFieldPopup->setName("DataPilot field member popup");
mpDPFieldPopup->setExtendedData(pDPData.release());
mpDPFieldPopup->setOKAction(new DPFieldPopupOKAction(this));
{
// Populate field members.
size_t n = rLabelData.maMembers.size();
mpDPFieldPopup->setMemberSize(n);
for (size_t i = 0; i < n; ++i)
{
const ScDPLabelData::Member& rMem = rLabelData.maMembers[i];
OUString aName = rMem.getDisplayName();
if (aName.isEmpty())
// Use special string for an empty name.
mpDPFieldPopup->addMember(ScGlobal::GetRscString(STR_EMPTYDATA), rMem.mbVisible);
else
mpDPFieldPopup->addMember(rMem.getDisplayName(), rMem.mbVisible);
}
mpDPFieldPopup->initMembers();
}
if (pDim->GetOrientation() != DataPilotFieldOrientation_PAGE)
{
vector<OUString> aUserSortNames;
ScUserList* pUserList = ScGlobal::GetUserList();
if (pUserList)
{
size_t n = pUserList->size();
aUserSortNames.reserve(n);
for (size_t i = 0; i < n; ++i)
{
const ScUserListData& rData = (*pUserList)[i];
aUserSortNames.push_back(rData.GetString());
}
}
// Populate the menus.
ScTabViewShell* pViewShell = pViewData->GetViewShell();
mpDPFieldPopup->addMenuItem(
SC_STRLOAD(RID_POPUP_FILTER, STR_MENU_SORT_ASC),
new PopupSortAction(rPos, PopupSortAction::ASCENDING, 0, pViewShell));
mpDPFieldPopup->addMenuItem(
SC_STRLOAD(RID_POPUP_FILTER, STR_MENU_SORT_DESC),
new PopupSortAction(rPos, PopupSortAction::DESCENDING, 0, pViewShell));
ScMenuFloatingWindow* pSubMenu = mpDPFieldPopup->addSubMenuItem(
SC_STRLOAD(RID_POPUP_FILTER, STR_MENU_SORT_CUSTOM), !aUserSortNames.empty());
if (pSubMenu && !aUserSortNames.empty())
{
size_t n = aUserSortNames.size();
for (size_t i = 0; i < n; ++i)
{
pSubMenu->addMenuItem(
aUserSortNames[i],
new PopupSortAction(rPos, PopupSortAction::CUSTOM, static_cast<sal_uInt16>(i), pViewShell));
}
}
}
Rectangle aCellRect(rScrPos, rScrSize);
mpDPFieldPopup->SetPopupModeEndHdl( LINK(this, ScGridWindow, PopupModeEndHdl) );
ScCheckListMenuWindow::Config aConfig;
aConfig.mbAllowEmptySet = false;
aConfig.mbRTL = pViewData->GetDocument()->IsLayoutRTL(pViewData->GetTabNo());
mpDPFieldPopup->setConfig(aConfig);
mpDPFieldPopup->launch(aCellRect);
}
void ScGridWindow::UpdateDPFromFieldPopupMenu()
{
typedef std::unordered_map<OUString, OUString, OUStringHash> MemNameMapType;
if (!mpDPFieldPopup)
return;
DPFieldPopupData* pDPData = static_cast<DPFieldPopupData*>(mpDPFieldPopup->getExtendedData());
if (!pDPData)
return;
ScDPObject* pDPObj = pDPData->mpDPObj;
ScDPSaveData* pSaveData = pDPObj->GetSaveData();
bool bIsDataLayout;
OUString aDimName = pDPObj->GetDimName(pDPData->mnDim, bIsDataLayout);
ScDPSaveDimension* pDim = pSaveData->GetDimensionByName(aDimName);
if (!pDim)
return;
// Build a map of layout names to original names.
const ScDPLabelData& rLabelData = pDPData->maLabels;
MemNameMapType aMemNameMap;
for (vector<ScDPLabelData::Member>::const_iterator itr = rLabelData.maMembers.begin(), itrEnd = rLabelData.maMembers.end();
itr != itrEnd; ++itr)
aMemNameMap.insert(MemNameMapType::value_type(itr->maLayoutName, itr->maName));
// The raw result may contain a mixture of layout names and original names.
ScCheckListMenuWindow::ResultType aRawResult;
mpDPFieldPopup->getResult(aRawResult);
ScCheckListMenuWindow::ResultType aResult;
ScCheckListMenuWindow::ResultType::const_iterator itr = aRawResult.begin(), itrEnd = aRawResult.end();
for (; itr != itrEnd; ++itr)
{
MemNameMapType::const_iterator itrNameMap = aMemNameMap.find(itr->first);
if (itrNameMap == aMemNameMap.end())
{
// This is an original member name. Use it as-is.
OUString aName = itr->first;
if (aName.equals(ScGlobal::GetRscString(STR_EMPTYDATA)))
// Translate the special empty name into an empty string.
aName.clear();
aResult.insert(
ScCheckListMenuWindow::ResultType::value_type(
aName, itr->second));
}
else
{
// This is a layout name. Get the original member name and use it.
aResult.insert(
ScCheckListMenuWindow::ResultType::value_type(
itrNameMap->second, itr->second));
}
}
pDim->UpdateMemberVisibility(aResult);
ScDBDocFunc aFunc(*pViewData->GetDocShell());
aFunc.UpdatePivotTable(*pDPObj, true, false);
}
bool ScGridWindow::UpdateVisibleRange()
{
ScDocument& rDoc = pViewData->GetDocShell()->GetDocument();
SCCOL nPosX = 0;
SCROW nPosY = 0;
SCCOL nXRight = MAXCOL;
SCROW nYBottom = MAXROW;
if (comphelper::LibreOfficeKit::isActive())
{
// entire table in the tiled rendering case
SCTAB nTab = pViewData->GetTabNo();
SCCOL nEndCol = 0;
SCROW nEndRow = 0;
if (rDoc.GetPrintArea(nTab, nEndCol, nEndRow, false))
{
nXRight = nEndCol;
nYBottom = nEndRow;
}
}
else
{
nPosX = pViewData->GetPosX(eHWhich);
nPosY = pViewData->GetPosY(eVWhich);
nXRight = nPosX + pViewData->VisibleCellsX(eHWhich);
if (nXRight > MAXCOL)
nXRight = MAXCOL;
nYBottom = nPosY + pViewData->VisibleCellsY(eVWhich);
if (nYBottom > MAXROW)
nYBottom = MAXROW;
}
// Store the current visible range.
bool bChanged = maVisibleRange.set(nPosX, nPosY, nXRight, nYBottom);
if (bChanged)
ResetAutoSpell();
return bChanged;
}
void ScGridWindow::DPMouseMove( const MouseEvent& rMEvt )
{
DPTestMouse( rMEvt, true );
}
void ScGridWindow::DPMouseButtonUp( const MouseEvent& rMEvt )
{
bDPMouse = false;
ReleaseMouse();
DPTestMouse( rMEvt, false );
SetPointer( Pointer( PointerStyle::Arrow ) );
}
void ScGridWindow::UpdateDragRect( bool bShowRange, const Rectangle& rPosRect )
{
SCCOL nStartX = ( rPosRect.Left() >= 0 ) ? static_cast<SCCOL>(rPosRect.Left()) : SCCOL_MAX;
SCROW nStartY = ( rPosRect.Top() >= 0 ) ? static_cast<SCROW>(rPosRect.Top()) : SCROW_MAX;
SCCOL nEndX = ( rPosRect.Right() >= 0 ) ? static_cast<SCCOL>(rPosRect.Right()) : SCCOL_MAX;
SCROW nEndY = ( rPosRect.Bottom() >= 0 ) ? static_cast<SCROW>(rPosRect.Bottom()) : SCROW_MAX;
if ( bShowRange == bDragRect && nDragStartX == nStartX && nDragEndX == nEndX &&
nDragStartY == nStartY && nDragEndY == nEndY )
{
return; // everything unchanged
}
if ( bShowRange )
{
nDragStartX = nStartX;
nDragStartY = nStartY;
nDragEndX = nEndX;
nDragEndY = nEndY;
bDragRect = true;
}
else
bDragRect = false;
UpdateDragRectOverlay();
}
// Page-Break Mode
sal_uInt16 ScGridWindow::HitPageBreak( const Point& rMouse, ScRange* pSource,
SCCOLROW* pBreak, SCCOLROW* pPrev )
{
sal_uInt16 nFound = SC_PD_NONE; // 0
ScRange aSource;
SCCOLROW nBreak = 0;
SCCOLROW nPrev = 0;
ScPageBreakData* pPageData = pViewData->GetView()->GetPageBreakData();
if ( pPageData )
{
bool bHori = false;
bool bVert = false;
SCCOL nHitX = 0;
SCROW nHitY = 0;
long nMouseX = rMouse.X();
long nMouseY = rMouse.Y();
SCsCOL nPosX;
SCsROW nPosY;
pViewData->GetPosFromPixel( nMouseX, nMouseY, eWhich, nPosX, nPosY );
Point aTL = pViewData->GetScrPos( nPosX, nPosY, eWhich );
Point aBR = pViewData->GetScrPos( nPosX+1, nPosY+1, eWhich );
// Horizontal more tolerances as for vertical, because there is more space
if ( nMouseX <= aTL.X() + 4 )
{
bHori = true;
nHitX = nPosX;
}
else if ( nMouseX >= aBR.X() - 6 )
{
bHori = true;
nHitX = nPosX+1; // left edge of the next cell
}
if ( nMouseY <= aTL.Y() + 2 )
{
bVert = true;
nHitY = nPosY;
}
else if ( nMouseY >= aBR.Y() - 4 )
{
bVert = true;
nHitY = nPosY+1; // upper edge of the next cell
}
if ( bHori || bVert )
{
sal_uInt16 nCount = sal::static_int_cast<sal_uInt16>( pPageData->GetCount() );
for (sal_uInt16 nPos=0; nPos<nCount && !nFound; nPos++)
{
ScPrintRangeData& rData = pPageData->GetData(nPos);
ScRange aRange = rData.GetPrintRange();
bool bLHit = ( bHori && nHitX == aRange.aStart.Col() );
bool bRHit = ( bHori && nHitX == aRange.aEnd.Col() + 1 );
bool bTHit = ( bVert && nHitY == aRange.aStart.Row() );
bool bBHit = ( bVert && nHitY == aRange.aEnd.Row() + 1 );
bool bInsideH = ( nPosX >= aRange.aStart.Col() && nPosX <= aRange.aEnd.Col() );
bool bInsideV = ( nPosY >= aRange.aStart.Row() && nPosY <= aRange.aEnd.Row() );
if ( bLHit )
{
if ( bTHit )
nFound = SC_PD_RANGE_TL;
else if ( bBHit )
nFound = SC_PD_RANGE_BL;
else if ( bInsideV )
nFound = SC_PD_RANGE_L;
}
else if ( bRHit )
{
if ( bTHit )
nFound = SC_PD_RANGE_TR;
else if ( bBHit )
nFound = SC_PD_RANGE_BR;
else if ( bInsideV )
nFound = SC_PD_RANGE_R;
}
else if ( bTHit && bInsideH )
nFound = SC_PD_RANGE_T;
else if ( bBHit && bInsideH )
nFound = SC_PD_RANGE_B;
if (nFound)
aSource = aRange;
// breaks
if ( bVert && bInsideH && !nFound )
{
size_t nRowCount = rData.GetPagesY();
const SCROW* pRowEnd = rData.GetPageEndY();
for (size_t nRowPos=0; nRowPos+1<nRowCount; nRowPos++)
if ( pRowEnd[nRowPos]+1 == nHitY )
{
nFound = SC_PD_BREAK_V;
aSource = aRange;
nBreak = nHitY;
if ( nRowPos )
nPrev = pRowEnd[nRowPos-1]+1;
else
nPrev = aRange.aStart.Row();
}
}
if ( bHori && bInsideV && !nFound )
{
size_t nColCount = rData.GetPagesX();
const SCCOL* pColEnd = rData.GetPageEndX();
for (size_t nColPos=0; nColPos+1<nColCount; nColPos++)
if ( pColEnd[nColPos]+1 == nHitX )
{
nFound = SC_PD_BREAK_H;
aSource = aRange;
nBreak = nHitX;
if ( nColPos )
nPrev = pColEnd[nColPos-1]+1;
else
nPrev = aRange.aStart.Col();
}
}
}
}
}
if (pSource)
*pSource = aSource; // print break
if (pBreak)
*pBreak = nBreak; // X/Y position of the moved page break
if (pPrev)
*pPrev = nPrev; // X/Y beginning of the page, which is above the break
return nFound;
}
void ScGridWindow::PagebreakMove( const MouseEvent& rMEvt, bool bUp )
{
//! Combine scrolling and switching with RFMouseMove !
//! (Inverting before scrolling is different)
// Scrolling
bool bTimer = false;
Point aPos = rMEvt.GetPosPixel();
SCsCOL nDx = 0;
SCsROW nDy = 0;
if ( aPos.X() < 0 ) nDx = -1;
if ( aPos.Y() < 0 ) nDy = -1;
Size aSize = GetOutputSizePixel();
if ( aPos.X() >= aSize.Width() )
nDx = 1;
if ( aPos.Y() >= aSize.Height() )
nDy = 1;
if ( nDx != 0 || nDy != 0 )
{
if ( bPagebreakDrawn ) // invert
{
bPagebreakDrawn = false;
UpdateDragRectOverlay();
}
if ( nDx != 0 ) pViewData->GetView()->ScrollX( nDx, WhichH(eWhich) );
if ( nDy != 0 ) pViewData->GetView()->ScrollY( nDy, WhichV(eWhich) );
bTimer = true;
}
// Switching when fixating (so Scrolling works)
if ( eWhich == pViewData->GetActivePart() ) //??
{
if ( pViewData->GetHSplitMode() == SC_SPLIT_FIX )
if ( nDx > 0 )
{
if ( eWhich == SC_SPLIT_TOPLEFT )
pViewData->GetView()->ActivatePart( SC_SPLIT_TOPRIGHT );
else if ( eWhich == SC_SPLIT_BOTTOMLEFT )
pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMRIGHT );
}
if ( pViewData->GetVSplitMode() == SC_SPLIT_FIX )
if ( nDy > 0 )
{
if ( eWhich == SC_SPLIT_TOPLEFT )
pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMLEFT );
else if ( eWhich == SC_SPLIT_TOPRIGHT )
pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMRIGHT );
}
}
// from here new
// Searching for a position between the cells (before nPosX / nPosY)
SCsCOL nPosX;
SCsROW nPosY;
pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
bool bLeft, bTop;
pViewData->GetMouseQuadrant( aPos, eWhich, nPosX, nPosY, bLeft, bTop );
if ( !bLeft ) ++nPosX;
if ( !bTop ) ++nPosY;
bool bBreak = ( nPagebreakMouse == SC_PD_BREAK_H || nPagebreakMouse == SC_PD_BREAK_V );
bool bHide = false;
bool bToEnd = false;
ScRange aDrawRange = aPagebreakSource;
if ( bBreak )
{
if ( nPagebreakMouse == SC_PD_BREAK_H )
{
if ( nPosX > aPagebreakSource.aStart.Col() &&
nPosX <= aPagebreakSource.aEnd.Col() + 1 ) // ans Ende ist auch erlaubt
{
bToEnd = ( nPosX == aPagebreakSource.aEnd.Col() + 1 );
aDrawRange.aStart.SetCol( nPosX );
aDrawRange.aEnd.SetCol( nPosX - 1 );
}
else
bHide = true;
}
else
{
if ( nPosY > aPagebreakSource.aStart.Row() &&
nPosY <= aPagebreakSource.aEnd.Row() + 1 ) // ans Ende ist auch erlaubt
{
bToEnd = ( nPosY == aPagebreakSource.aEnd.Row() + 1 );
aDrawRange.aStart.SetRow( nPosY );
aDrawRange.aEnd.SetRow( nPosY - 1 );
}
else
bHide = true;
}
}
else
{
if ( nPagebreakMouse & SC_PD_RANGE_L )
aDrawRange.aStart.SetCol( nPosX );
if ( nPagebreakMouse & SC_PD_RANGE_T )
aDrawRange.aStart.SetRow( nPosY );
if ( nPagebreakMouse & SC_PD_RANGE_R )
{
if ( nPosX > 0 )
aDrawRange.aEnd.SetCol( nPosX-1 );
else
bHide = true;
}
if ( nPagebreakMouse & SC_PD_RANGE_B )
{
if ( nPosY > 0 )
aDrawRange.aEnd.SetRow( nPosY-1 );
else
bHide = true;
}
if ( aDrawRange.aStart.Col() > aDrawRange.aEnd.Col() ||
aDrawRange.aStart.Row() > aDrawRange.aEnd.Row() )
bHide = true;
}
if ( !bPagebreakDrawn || bUp || aDrawRange != aPagebreakDrag )
{
// draw...
if ( bPagebreakDrawn )
{
// invert
bPagebreakDrawn = false;
}
aPagebreakDrag = aDrawRange;
if ( !bUp && !bHide )
{
// revert
bPagebreakDrawn = true;
}
UpdateDragRectOverlay();
}
// when ButtonUp execute the changes
if ( bUp )
{
ScViewFunc* pViewFunc = pViewData->GetView();
ScDocShell* pDocSh = pViewData->GetDocShell();
ScDocument& rDoc = pDocSh->GetDocument();
SCTAB nTab = pViewData->GetTabNo();
bool bUndo (rDoc.IsUndoEnabled());
if ( bBreak )
{
bool bColumn = ( nPagebreakMouse == SC_PD_BREAK_H );
SCCOLROW nNew = bColumn ? static_cast<SCCOLROW>(nPosX) : static_cast<SCCOLROW>(nPosY);
if ( nNew != nPagebreakBreak )
{
if (bUndo)
{
OUString aUndo = ScGlobal::GetRscString( STR_UNDO_DRAG_BREAK );
pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
}
bool bGrow = !bHide && nNew > nPagebreakBreak;
if ( bColumn )
{
if (rDoc.HasColBreak(static_cast<SCCOL>(nPagebreakBreak), nTab) & BREAK_MANUAL)
{
ScAddress aOldAddr( static_cast<SCCOL>(nPagebreakBreak), nPosY, nTab );
pViewFunc->DeletePageBreak( true, true, &aOldAddr, false );
}
if ( !bHide && !bToEnd ) // not at the end
{
ScAddress aNewAddr( static_cast<SCCOL>(nNew), nPosY, nTab );
pViewFunc->InsertPageBreak( true, true, &aNewAddr, false );
}
if ( bGrow )
{
// change last break to hard, and change scaleing
bool bManualBreak = (rDoc.HasColBreak(static_cast<SCCOL>(nPagebreakPrev), nTab) & BREAK_MANUAL);
if ( static_cast<SCCOL>(nPagebreakPrev) > aPagebreakSource.aStart.Col() && !bManualBreak )
{
ScAddress aPrev( static_cast<SCCOL>(nPagebreakPrev), nPosY, nTab );
pViewFunc->InsertPageBreak( true, true, &aPrev, false );
}
if (!pDocSh->AdjustPrintZoom( ScRange(
static_cast<SCCOL>(nPagebreakPrev),0,nTab, static_cast<SCCOL>(nNew-1),0,nTab ) ))
bGrow = false;
}
}
else
{
if (rDoc.HasRowBreak(nPagebreakBreak, nTab) & BREAK_MANUAL)
{
ScAddress aOldAddr( nPosX, nPagebreakBreak, nTab );
pViewFunc->DeletePageBreak( false, true, &aOldAddr, false );
}
if ( !bHide && !bToEnd ) // not at the end
{
ScAddress aNewAddr( nPosX, nNew, nTab );
pViewFunc->InsertPageBreak( false, true, &aNewAddr, false );
}
if ( bGrow )
{
// change last break to hard, and change scaleing
bool bManualBreak = (rDoc.HasRowBreak(nPagebreakPrev, nTab) & BREAK_MANUAL);
if ( nPagebreakPrev > aPagebreakSource.aStart.Row() && !bManualBreak )
{
ScAddress aPrev( nPosX, nPagebreakPrev, nTab );
pViewFunc->InsertPageBreak( false, true, &aPrev, false );
}
if (!pDocSh->AdjustPrintZoom( ScRange(
0,nPagebreakPrev,nTab, 0,nNew-1,nTab ) ))
bGrow = false;
}
}
if (bUndo)
{
pDocSh->GetUndoManager()->LeaveListAction();
}
if (!bGrow) // otherwise has already happened in AdjustPrintZoom
{
pViewFunc->UpdatePageBreakData( true );
pDocSh->SetDocumentModified();
}
}
}
else if ( bHide || aPagebreakDrag != aPagebreakSource )
{
// set print range
OUString aNewRanges;
sal_uInt16 nOldCount = rDoc.GetPrintRangeCount( nTab );
if ( nOldCount )
{
for (sal_uInt16 nPos=0; nPos<nOldCount; nPos++)
{
const ScRange* pOld = rDoc.GetPrintRange( nTab, nPos );
if ( pOld )
{
OUString aTemp;
if ( *pOld != aPagebreakSource )
aTemp = pOld->Format(ScRefFlags::VALID);
else if ( !bHide )
aTemp = aPagebreakDrag.Format(ScRefFlags::VALID);
if (!aTemp.isEmpty())
{
if ( !aNewRanges.isEmpty() )
aNewRanges += ";";
aNewRanges += aTemp;
}
}
}
}
else if (!bHide)
aNewRanges = aPagebreakDrag.Format(ScRefFlags::VALID);
pViewFunc->SetPrintRanges( rDoc.IsPrintEntireSheet( nTab ), &aNewRanges, nullptr, nullptr, false );
}
}
// Timer for Scrolling
if (bTimer && !bUp)
pViewData->GetView()->SetTimer( this, rMEvt ); // repeat event
else
pViewData->GetView()->ResetTimer();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|