LCOV - code coverage report
Current view: top level - sc/source/ui/view - gridwin2.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 20 575 3.5 %
Date: 2015-06-13 12:38:46 Functions: 3 27 11.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "scitems.hxx"
      21             : #include <vcl/msgbox.hxx>
      22             : #include <vcl/settings.hxx>
      23             : 
      24             : #include "gridwin.hxx"
      25             : #include "tabvwsh.hxx"
      26             : #include "docsh.hxx"
      27             : #include "viewdata.hxx"
      28             : #include "pivot.hxx"
      29             : #include "uiitems.hxx"
      30             : #include "scresid.hxx"
      31             : #include "sc.hrc"
      32             : #include "globstr.hrc"
      33             : #include "pagedata.hxx"
      34             : #include "dpobject.hxx"
      35             : #include "dpsave.hxx"
      36             : #include "dpoutput.hxx"
      37             : #include "dpshttab.hxx"
      38             : #include "dbdocfun.hxx"
      39             : #include "checklistmenu.hxx"
      40             : #include "dpcontrol.hxx"
      41             : #include "checklistmenu.hrc"
      42             : #include "strload.hxx"
      43             : #include "userlist.hxx"
      44             : #include "scabstdlg.hxx"
      45             : #include "spellcheckcontext.hxx"
      46             : 
      47             : #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
      48             : 
      49             : #include <unordered_map>
      50             : #include <vector>
      51             : 
      52             : using namespace css;
      53             : using namespace css::sheet;
      54             : using css::sheet::DataPilotFieldOrientation;
      55             : using std::vector;
      56             : using std::unique_ptr;
      57             : 
      58             : // STATIC DATA -----------------------------------------------------------
      59             : 
      60           0 : DataPilotFieldOrientation ScGridWindow::GetDPFieldOrientation( SCCOL nCol, SCROW nRow ) const
      61             : {
      62           0 :     ScDocument* pDoc = pViewData->GetDocument();
      63           0 :     SCTAB nTab = pViewData->GetTabNo();
      64           0 :     ScDPObject* pDPObj = pDoc->GetDPAtCursor(nCol, nRow, nTab);
      65           0 :     if (!pDPObj)
      66           0 :         return DataPilotFieldOrientation_HIDDEN;
      67             : 
      68           0 :     sal_uInt16 nOrient = DataPilotFieldOrientation_HIDDEN;
      69             : 
      70             :     // Check for page field first.
      71           0 :     if (nCol > 0)
      72             :     {
      73             :         // look for the dimension header left of the drop-down arrow
      74           0 :         long nField = pDPObj->GetHeaderDim( ScAddress( nCol-1, nRow, nTab ), nOrient );
      75           0 :         if ( nField >= 0 && nOrient == DataPilotFieldOrientation_PAGE )
      76             :         {
      77           0 :             bool bIsDataLayout = false;
      78           0 :             OUString aFieldName = pDPObj->GetDimName( nField, bIsDataLayout );
      79           0 :             if ( !aFieldName.isEmpty() && !bIsDataLayout )
      80           0 :                 return DataPilotFieldOrientation_PAGE;
      81             :         }
      82             :     }
      83             : 
      84           0 :     nOrient = DataPilotFieldOrientation_HIDDEN;
      85             : 
      86             :     // Now, check for row/column field.
      87           0 :     long nField = pDPObj->GetHeaderDim(ScAddress(nCol, nRow, nTab), nOrient);
      88           0 :     if (nField >= 0 && (nOrient == DataPilotFieldOrientation_COLUMN || nOrient == DataPilotFieldOrientation_ROW) )
      89             :     {
      90           0 :         bool bIsDataLayout = false;
      91           0 :         OUString aFieldName = pDPObj->GetDimName(nField, bIsDataLayout);
      92           0 :         if (!aFieldName.isEmpty() && !bIsDataLayout)
      93           0 :             return static_cast<DataPilotFieldOrientation>(nOrient);
      94             :     }
      95             : 
      96           0 :     return DataPilotFieldOrientation_HIDDEN;
      97             : }
      98             : 
      99             : // private method for mouse button handling
     100           0 : bool ScGridWindow::DoPageFieldSelection( SCCOL nCol, SCROW nRow )
     101             : {
     102           0 :     if (GetDPFieldOrientation( nCol, nRow ) == DataPilotFieldOrientation_PAGE)
     103             :     {
     104           0 :         LaunchPageFieldMenu( nCol, nRow );
     105           0 :         return true;
     106             :     }
     107           0 :     return false;
     108             : }
     109             : 
     110           0 : bool ScGridWindow::DoAutoFilterButton( SCCOL nCol, SCROW nRow, const MouseEvent& rMEvt )
     111             : {
     112           0 :     ScDocument* pDoc = pViewData->GetDocument();
     113           0 :     SCTAB nTab = pViewData->GetTabNo();
     114           0 :     Point aScrPos  = pViewData->GetScrPos(nCol, nRow, eWhich);
     115           0 :     Point aDiffPix = rMEvt.GetPosPixel();
     116             : 
     117           0 :     aDiffPix -= aScrPos;
     118           0 :     bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
     119           0 :     if ( bLayoutRTL )
     120           0 :         aDiffPix.X() = -aDiffPix.X();
     121             : 
     122             :     long nSizeX, nSizeY;
     123           0 :     pViewData->GetMergeSizePixel( nCol, nRow, nSizeX, nSizeY );
     124             :     // The button height should not use the merged cell height, should still use single row height
     125           0 :     nSizeY = ScViewData::ToPixel(pDoc->GetRowHeight(nRow, nTab), pViewData->GetPPTY());
     126           0 :     Size aScrSize(nSizeX-1, nSizeY-1);
     127             : 
     128             :     // Check if the mouse cursor is clicking on the popup arrow box.
     129           0 :     mpFilterButton.reset(new ScDPFieldButton(this, &GetSettings().GetStyleSettings(), &pViewData->GetZoomX(), &pViewData->GetZoomY(), pDoc));
     130           0 :     mpFilterButton->setBoundingBox(aScrPos, aScrSize, bLayoutRTL);
     131           0 :     mpFilterButton->setPopupLeft(bLayoutRTL);   // #i114944# AutoFilter button is left-aligned in RTL
     132           0 :     Point aPopupPos;
     133           0 :     Size aPopupSize;
     134           0 :     mpFilterButton->getPopupBoundingBox(aPopupPos, aPopupSize);
     135           0 :     Rectangle aRect(aPopupPos, aPopupSize);
     136           0 :     if (aRect.IsInside(rMEvt.GetPosPixel()))
     137             :     {
     138           0 :         if ( DoPageFieldSelection( nCol, nRow ) )
     139           0 :             return true;
     140             : 
     141           0 :         bool bFilterActive = IsAutoFilterActive(nCol, nRow, nTab);
     142           0 :         mpFilterButton->setHasHiddenMember(bFilterActive);
     143           0 :         mpFilterButton->setDrawBaseButton(false);
     144           0 :         mpFilterButton->setDrawPopupButton(true);
     145           0 :         mpFilterButton->setPopupPressed(true);
     146           0 :         mpFilterButton->draw();
     147           0 :         LaunchAutoFilterMenu(nCol, nRow);
     148           0 :         return true;
     149             :     }
     150             : 
     151           0 :     return false;
     152             : }
     153             : 
     154           0 : void ScGridWindow::DoPushPivotButton( SCCOL nCol, SCROW nRow, const MouseEvent& rMEvt, bool bButton, bool bPopup )
     155             : {
     156           0 :     ScDocument* pDoc = pViewData->GetDocument();
     157           0 :     SCTAB nTab = pViewData->GetTabNo();
     158             : 
     159           0 :     ScDPObject* pDPObj  = pDoc->GetDPAtCursor(nCol, nRow, nTab);
     160             : 
     161           0 :     if (pDPObj)
     162             :     {
     163           0 :         sal_uInt16 nOrient = DataPilotFieldOrientation_HIDDEN;
     164           0 :         ScAddress aPos( nCol, nRow, nTab );
     165           0 :         ScAddress aDimPos = aPos;
     166           0 :         if (!bButton && bPopup && aDimPos.Col() > 0)
     167             :             // For page field selection cell, the real field position is to the left.
     168           0 :             aDimPos.IncCol(-1);
     169             : 
     170           0 :         long nField = pDPObj->GetHeaderDim(aDimPos, nOrient);
     171           0 :         if ( nField >= 0 )
     172             :         {
     173           0 :             bDPMouse   = false;
     174           0 :             nDPField   = nField;
     175           0 :             pDragDPObj = pDPObj;
     176           0 :             if (bPopup && DPTestFieldPopupArrow(rMEvt, aPos, aDimPos, pDPObj))
     177             :             {
     178             :                 // field name pop up menu has been launched.  Don't activate
     179             :                 // field move.
     180           0 :                 return;
     181             :             }
     182             : 
     183           0 :             if (bButton)
     184             :             {
     185           0 :                 bDPMouse = true;
     186           0 :                 DPTestMouse( rMEvt, true );
     187           0 :                 StartTracking();
     188             :             }
     189             :         }
     190           0 :         else if ( pDPObj->IsFilterButton(aPos) )
     191             :         {
     192           0 :             ReleaseMouse();         // may have been captured in ButtonDown
     193             : 
     194           0 :             ScQueryParam aQueryParam;
     195           0 :             SCTAB nSrcTab = 0;
     196           0 :             const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc();
     197             :             OSL_ENSURE(pDesc, "no sheet source for filter button");
     198           0 :             if (pDesc)
     199             :             {
     200           0 :                 aQueryParam = pDesc->GetQueryParam();
     201           0 :                 nSrcTab = pDesc->GetSourceRange().aStart.Tab();
     202             :             }
     203             : 
     204           0 :             SfxItemSet aArgSet( pViewData->GetViewShell()->GetPool(),
     205           0 :                                         SCITEM_QUERYDATA, SCITEM_QUERYDATA );
     206           0 :             aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA, pViewData, &aQueryParam ) );
     207             : 
     208           0 :             ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
     209             :             OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
     210             : 
     211             :             const std::unique_ptr<AbstractScPivotFilterDlg> pDlg(
     212             :                 pFact->CreateScPivotFilterDlg(
     213           0 :                     pViewData->GetViewShell()->GetDialogParent(), aArgSet, nSrcTab));
     214             :             OSL_ENSURE(pDlg, "Dialog create fail!");
     215           0 :             if ( pDlg->Execute() == RET_OK )
     216             :             {
     217           0 :                 ScSheetSourceDesc aNewDesc(pDoc);
     218           0 :                 if (pDesc)
     219           0 :                     aNewDesc = *pDesc;
     220             : 
     221           0 :                 const ScQueryItem& rQueryItem = pDlg->GetOutputItem();
     222           0 :                 aNewDesc.SetQueryParam(rQueryItem.GetQueryData());
     223             : 
     224           0 :                 ScDPObject aNewObj( *pDPObj );
     225           0 :                 aNewObj.SetSheetDesc( aNewDesc );
     226           0 :                 ScDBDocFunc aFunc( *pViewData->GetDocShell() );
     227           0 :                 aFunc.DataPilotUpdate( pDPObj, &aNewObj, true, false );
     228           0 :                 pViewData->GetView()->CursorPosChanged();       // shells may be switched
     229           0 :             }
     230             :         }
     231             :     }
     232             :     else
     233             :     {
     234             :         OSL_FAIL("Da is ja garnix");
     235             :     }
     236             : }
     237             : 
     238             : //  Data Pilot interaction
     239             : 
     240           0 : void ScGridWindow::DPTestMouse( const MouseEvent& rMEvt, bool bMove )
     241             : {
     242             :     OSL_ENSURE(pDragDPObj, "pDragDPObj missing");
     243             : 
     244             :     //  scroll window if at edges
     245             :     //! move this to separate method
     246             : 
     247           0 :     bool bTimer = false;
     248           0 :     Point aPixel = rMEvt.GetPosPixel();
     249             : 
     250           0 :     SCsCOL nDx = 0;
     251           0 :     SCsROW nDy = 0;
     252           0 :     if ( aPixel.X() < 0 )
     253           0 :         nDx = -1;
     254           0 :     if ( aPixel.Y() < 0 )
     255           0 :         nDy = -1;
     256           0 :     Size aSize = GetOutputSizePixel();
     257           0 :     if ( aPixel.X() >= aSize.Width() )
     258           0 :         nDx = 1;
     259           0 :     if ( aPixel.Y() >= aSize.Height() )
     260           0 :         nDy = 1;
     261           0 :     if ( nDx != 0 || nDy != 0 )
     262             :     {
     263           0 :         UpdateDragRect( false, Rectangle() );
     264             : 
     265           0 :         if ( nDx  != 0)
     266           0 :             pViewData->GetView()->ScrollX( nDx, WhichH(eWhich) );
     267           0 :         if ( nDy != 0 )
     268           0 :             pViewData->GetView()->ScrollY( nDy, WhichV(eWhich) );
     269             : 
     270           0 :         bTimer = true;
     271             :     }
     272             : 
     273             :     SCsCOL  nPosX;
     274             :     SCsROW  nPosY;
     275           0 :     pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), eWhich, nPosX, nPosY );
     276             :     bool    bMouseLeft;
     277             :     bool    bMouseTop;
     278           0 :     pViewData->GetMouseQuadrant( aPixel, eWhich, nPosX, nPosY, bMouseLeft, bMouseTop );
     279             : 
     280           0 :     ScAddress aPos( nPosX, nPosY, pViewData->GetTabNo() );
     281             : 
     282           0 :     Rectangle aPosRect;
     283             :     sal_uInt16 nOrient;
     284             :     long nDimPos;
     285             :     bool bHasRange = pDragDPObj->GetHeaderDrag( aPos, bMouseLeft, bMouseTop, nDPField,
     286           0 :                                                 aPosRect, nOrient, nDimPos );
     287           0 :     UpdateDragRect( bHasRange && bMove, aPosRect );
     288             : 
     289             :     bool bIsDataLayout;
     290           0 :     sal_Int32 nDimFlags = 0;
     291           0 :     OUString aDimName = pDragDPObj->GetDimName( nDPField, bIsDataLayout, &nDimFlags );
     292           0 :     bool bAllowed = !bHasRange || ScDPObject::IsOrientationAllowed( nOrient, nDimFlags );
     293             : 
     294           0 :     if (bMove)          // set mouse pointer
     295             :     {
     296           0 :         PointerStyle ePointer = PointerStyle::PivotDelete;
     297           0 :         if ( !bAllowed )
     298           0 :             ePointer = PointerStyle::NotAllowed;
     299           0 :         else if ( bHasRange )
     300           0 :             switch (nOrient)
     301             :             {
     302           0 :                 case DataPilotFieldOrientation_COLUMN: ePointer = PointerStyle::PivotCol; break;
     303           0 :                 case DataPilotFieldOrientation_ROW:    ePointer = PointerStyle::PivotRow; break;
     304             :                 case DataPilotFieldOrientation_PAGE:
     305           0 :                 case DataPilotFieldOrientation_DATA:   ePointer = PointerStyle::PivotField;   break;
     306             :             }
     307           0 :         SetPointer( ePointer );
     308             :     }
     309             :     else                // execute change
     310             :     {
     311           0 :         if (!bHasRange)
     312           0 :             nOrient = DataPilotFieldOrientation_HIDDEN;
     313             : 
     314           0 :         if ( bIsDataLayout && ( nOrient != DataPilotFieldOrientation_COLUMN &&
     315           0 :                                 nOrient != DataPilotFieldOrientation_ROW ) )
     316             :         {
     317             :             //  removing data layout is not allowed
     318           0 :             pViewData->GetView()->ErrorMessage(STR_PIVOT_MOVENOTALLOWED);
     319             :         }
     320           0 :         else if ( bAllowed )
     321             :         {
     322           0 :             ScDPSaveData aSaveData( *pDragDPObj->GetSaveData() );
     323             : 
     324             :             ScDPSaveDimension* pDim;
     325           0 :             if ( bIsDataLayout )
     326           0 :                 pDim = aSaveData.GetDataLayoutDimension();
     327             :             else
     328           0 :                 pDim = aSaveData.GetDimensionByName(aDimName);
     329           0 :             pDim->SetOrientation( nOrient );
     330           0 :             aSaveData.SetPosition( pDim, nDimPos );
     331             : 
     332             :             //! docfunc method with ScDPSaveData as argument?
     333             : 
     334           0 :             ScDPObject aNewObj( *pDragDPObj );
     335           0 :             aNewObj.SetSaveData( aSaveData );
     336           0 :             ScDBDocFunc aFunc( *pViewData->GetDocShell() );
     337             :             // when dragging fields, allow re-positioning (bAllowMove)
     338           0 :             aFunc.DataPilotUpdate( pDragDPObj, &aNewObj, true, false, true );
     339           0 :             pViewData->GetView()->CursorPosChanged();       // shells may be switched
     340             :         }
     341             :     }
     342             : 
     343           0 :     if (bTimer && bMove)
     344           0 :         pViewData->GetView()->SetTimer( this, rMEvt );          // repeat event
     345             :     else
     346           0 :         pViewData->GetView()->ResetTimer();
     347           0 : }
     348             : 
     349           0 : bool ScGridWindow::DPTestFieldPopupArrow(
     350             :     const MouseEvent& rMEvt, const ScAddress& rPos, const ScAddress& rDimPos, ScDPObject* pDPObj)
     351             : {
     352           0 :     bool bLayoutRTL = pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );
     353             : 
     354             :     // Get the geometry of the cell.
     355           0 :     Point aScrPos = pViewData->GetScrPos(rPos.Col(), rPos.Row(), eWhich);
     356             :     long nSizeX, nSizeY;
     357           0 :     pViewData->GetMergeSizePixel(rPos.Col(), rPos.Row(), nSizeX, nSizeY);
     358           0 :     Size aScrSize(nSizeX-1, nSizeY-1);
     359             : 
     360             :     // Check if the mouse cursor is clicking on the popup arrow box.
     361           0 :     ScDPFieldButton aBtn(this, &GetSettings().GetStyleSettings());
     362           0 :     aBtn.setBoundingBox(aScrPos, aScrSize, bLayoutRTL);
     363           0 :     aBtn.setPopupLeft(false);   // DataPilot popup is always right-aligned for now
     364           0 :     Point aPopupPos;
     365           0 :     Size aPopupSize;
     366           0 :     aBtn.getPopupBoundingBox(aPopupPos, aPopupSize);
     367           0 :     Rectangle aRect(aPopupPos, aPopupSize);
     368           0 :     if (aRect.IsInside(rMEvt.GetPosPixel()))
     369             :     {
     370             :         // Mouse cursor inside the popup arrow box.  Launch the field menu.
     371           0 :         DPLaunchFieldPopupMenu(OutputToScreenPixel(aScrPos), aScrSize, rDimPos, pDPObj);
     372           0 :         return true;
     373             :     }
     374             : 
     375           0 :     return false;
     376             : }
     377             : 
     378             : namespace {
     379             : 
     380           0 : struct DPFieldPopupData : public ScCheckListMenuWindow::ExtendedData
     381             : {
     382             :     ScDPLabelData   maLabels;
     383             :     ScDPObject*     mpDPObj;
     384             :     long            mnDim;
     385             : };
     386             : 
     387           0 : class DPFieldPopupOKAction : public ScMenuFloatingWindow::Action
     388             : {
     389             : public:
     390           0 :     explicit DPFieldPopupOKAction(ScGridWindow* p) :
     391           0 :         mpGridWindow(p) {}
     392             : 
     393           0 :     virtual void execute() SAL_OVERRIDE
     394             :     {
     395           0 :         mpGridWindow->UpdateDPFromFieldPopupMenu();
     396           0 :     }
     397             : private:
     398             :     VclPtr<ScGridWindow> mpGridWindow;
     399             : };
     400             : 
     401           0 : class PopupSortAction : public ScMenuFloatingWindow::Action
     402             : {
     403             : public:
     404             :     enum SortType { ASCENDING, DESCENDING, CUSTOM };
     405             : 
     406           0 :     explicit PopupSortAction(const ScAddress& rPos, SortType eType, sal_uInt16 nUserListIndex, ScTabViewShell* pViewShell) :
     407           0 :         maPos(rPos), meType(eType), mnUserListIndex(nUserListIndex), mpViewShell(pViewShell) {}
     408             : 
     409           0 :     virtual void execute() SAL_OVERRIDE
     410             :     {
     411           0 :         switch (meType)
     412             :         {
     413             :             case ASCENDING:
     414           0 :                 mpViewShell->DataPilotSort(maPos, true);
     415           0 :             break;
     416             :             case DESCENDING:
     417           0 :                 mpViewShell->DataPilotSort(maPos, false);
     418           0 :             break;
     419             :             case CUSTOM:
     420           0 :                 mpViewShell->DataPilotSort(maPos, true, &mnUserListIndex);
     421           0 :             break;
     422             :             default:
     423             :                 ;
     424             :         }
     425           0 :     }
     426             : 
     427             : private:
     428             :     ScAddress       maPos;
     429             :     SortType        meType;
     430             :     sal_uInt16      mnUserListIndex;
     431             :     ScTabViewShell* mpViewShell;
     432             : };
     433             : 
     434             : }
     435             : 
     436           0 : void ScGridWindow::DPLaunchFieldPopupMenu(
     437             :     const Point& rScrPos, const Size& rScrSize, const ScAddress& rPos, ScDPObject* pDPObj)
     438             : {
     439           0 :     unique_ptr<DPFieldPopupData> pDPData(new DPFieldPopupData);
     440             :     sal_uInt16 nOrient;
     441           0 :     pDPData->mnDim = pDPObj->GetHeaderDim(rPos, nOrient);
     442             : 
     443             :     bool bIsDataLayout;
     444           0 :     OUString aDimName = pDPObj->GetDimName(pDPData->mnDim, bIsDataLayout);
     445           0 :     pDPObj->BuildAllDimensionMembers();
     446           0 :     const ScDPSaveData* pSaveData = pDPObj->GetSaveData();
     447           0 :     const ScDPSaveDimension* pDim = pSaveData->GetExistingDimensionByName(aDimName);
     448           0 :     if (!pDim)
     449             :         // This should never happen.
     450           0 :         return;
     451             : 
     452             :     // We need to get the list of field members.
     453           0 :     pDPObj->FillLabelData(pDPData->mnDim, pDPData->maLabels);
     454           0 :     pDPData->mpDPObj = pDPObj;
     455             : 
     456           0 :     const ScDPLabelData& rLabelData = pDPData->maLabels;
     457             : 
     458           0 :     mpDPFieldPopup.disposeAndClear();
     459           0 :     mpDPFieldPopup.reset(VclPtr<ScCheckListMenuWindow>::Create(this, pViewData->GetDocument()));
     460           0 :     mpDPFieldPopup->setName("DataPilot field member popup");
     461           0 :     mpDPFieldPopup->setExtendedData(pDPData.release());
     462           0 :     mpDPFieldPopup->setOKAction(new DPFieldPopupOKAction(this));
     463             :     {
     464             :         // Populate field members.
     465           0 :         size_t n = rLabelData.maMembers.size();
     466           0 :         mpDPFieldPopup->setMemberSize(n);
     467           0 :         for (size_t i = 0; i < n; ++i)
     468             :         {
     469           0 :             const ScDPLabelData::Member& rMem = rLabelData.maMembers[i];
     470           0 :             OUString aName = rMem.getDisplayName();
     471           0 :             if (aName.isEmpty())
     472             :                 // Use special string for an empty name.
     473           0 :                 mpDPFieldPopup->addMember(ScGlobal::GetRscString(STR_EMPTYDATA), rMem.mbVisible);
     474             :             else
     475           0 :                 mpDPFieldPopup->addMember(rMem.getDisplayName(), rMem.mbVisible);
     476           0 :         }
     477           0 :         mpDPFieldPopup->initMembers();
     478             :     }
     479             : 
     480           0 :     if (pDim->GetOrientation() != DataPilotFieldOrientation_PAGE)
     481             :     {
     482           0 :         vector<OUString> aUserSortNames;
     483           0 :         ScUserList* pUserList = ScGlobal::GetUserList();
     484           0 :         if (pUserList)
     485             :         {
     486           0 :             size_t n = pUserList->size();
     487           0 :             aUserSortNames.reserve(n);
     488           0 :             for (size_t i = 0; i < n; ++i)
     489             :             {
     490           0 :                 const ScUserListData* pData = (*pUserList)[i];
     491           0 :                 aUserSortNames.push_back(pData->GetString());
     492             :             }
     493             :         }
     494             : 
     495             :         // Populate the menus.
     496           0 :         ScTabViewShell* pViewShell = pViewData->GetViewShell();
     497           0 :         mpDPFieldPopup->addMenuItem(
     498           0 :             SC_STRLOAD(RID_POPUP_FILTER, STR_MENU_SORT_ASC), true,
     499           0 :             new PopupSortAction(rPos, PopupSortAction::ASCENDING, 0, pViewShell));
     500           0 :         mpDPFieldPopup->addMenuItem(
     501           0 :             SC_STRLOAD(RID_POPUP_FILTER, STR_MENU_SORT_DESC), true,
     502           0 :             new PopupSortAction(rPos, PopupSortAction::DESCENDING, 0, pViewShell));
     503           0 :         ScMenuFloatingWindow* pSubMenu = mpDPFieldPopup->addSubMenuItem(
     504           0 :             SC_STRLOAD(RID_POPUP_FILTER, STR_MENU_SORT_CUSTOM), !aUserSortNames.empty());
     505             : 
     506           0 :         if (pSubMenu && !aUserSortNames.empty())
     507             :         {
     508           0 :             size_t n = aUserSortNames.size();
     509           0 :             for (size_t i = 0; i < n; ++i)
     510             :             {
     511             :                 pSubMenu->addMenuItem(
     512           0 :                     aUserSortNames[i], true,
     513           0 :                     new PopupSortAction(rPos, PopupSortAction::CUSTOM, static_cast<sal_uInt16>(i), pViewShell));
     514             :             }
     515           0 :         }
     516             :     }
     517             : 
     518           0 :     Rectangle aCellRect(rScrPos, rScrSize);
     519             : 
     520           0 :     mpDPFieldPopup->SetPopupModeEndHdl( LINK(this, ScGridWindow, PopupModeEndHdl) );
     521           0 :     ScCheckListMenuWindow::Config aConfig;
     522           0 :     aConfig.mbAllowEmptySet = false;
     523           0 :     aConfig.mbRTL = pViewData->GetDocument()->IsLayoutRTL(pViewData->GetTabNo());
     524           0 :     mpDPFieldPopup->setConfig(aConfig);
     525           0 :     mpDPFieldPopup->launch(aCellRect);
     526             : }
     527             : 
     528           0 : void ScGridWindow::UpdateDPFromFieldPopupMenu()
     529             : {
     530             :     typedef std::unordered_map<OUString, OUString, OUStringHash> MemNameMapType;
     531             : 
     532           0 :     if (!mpDPFieldPopup)
     533           0 :         return;
     534             : 
     535           0 :     DPFieldPopupData* pDPData = static_cast<DPFieldPopupData*>(mpDPFieldPopup->getExtendedData());
     536           0 :     if (!pDPData)
     537           0 :         return;
     538             : 
     539           0 :     ScDPObject* pDPObj = pDPData->mpDPObj;
     540           0 :     ScDPSaveData* pSaveData = pDPObj->GetSaveData();
     541             : 
     542             :     bool bIsDataLayout;
     543           0 :     OUString aDimName = pDPObj->GetDimName(pDPData->mnDim, bIsDataLayout);
     544           0 :     ScDPSaveDimension* pDim = pSaveData->GetDimensionByName(aDimName);
     545           0 :     if (!pDim)
     546           0 :         return;
     547             : 
     548             :     // Build a map of layout names to original names.
     549           0 :     const ScDPLabelData& rLabelData = pDPData->maLabels;
     550           0 :     MemNameMapType aMemNameMap;
     551           0 :     for (vector<ScDPLabelData::Member>::const_iterator itr = rLabelData.maMembers.begin(), itrEnd = rLabelData.maMembers.end();
     552             :            itr != itrEnd; ++itr)
     553           0 :         aMemNameMap.insert(MemNameMapType::value_type(itr->maLayoutName, itr->maName));
     554             : 
     555             :     // The raw result may contain a mixture of layout names and original names.
     556           0 :     ScCheckListMenuWindow::ResultType aRawResult;
     557           0 :     mpDPFieldPopup->getResult(aRawResult);
     558             : 
     559           0 :     ScCheckListMenuWindow::ResultType aResult;
     560           0 :     ScCheckListMenuWindow::ResultType::const_iterator itr = aRawResult.begin(), itrEnd = aRawResult.end();
     561           0 :     for (; itr != itrEnd; ++itr)
     562             :     {
     563           0 :         MemNameMapType::const_iterator itrNameMap = aMemNameMap.find(itr->first);
     564           0 :         if (itrNameMap == aMemNameMap.end())
     565             :         {
     566             :             // This is an original member name.  Use it as-is.
     567           0 :             OUString aName = itr->first;
     568           0 :             if (aName.equals(ScGlobal::GetRscString(STR_EMPTYDATA)))
     569             :                 // Translate the special empty name into an empty string.
     570           0 :                 aName.clear();
     571             : 
     572             :             aResult.insert(
     573             :                 ScCheckListMenuWindow::ResultType::value_type(
     574           0 :                     aName, itr->second));
     575             :         }
     576             :         else
     577             :         {
     578             :             // This is a layout name.  Get the original member name and use it.
     579             :             aResult.insert(
     580             :                 ScCheckListMenuWindow::ResultType::value_type(
     581           0 :                     itrNameMap->second, itr->second));
     582             :         }
     583             :     }
     584           0 :     pDim->UpdateMemberVisibility(aResult);
     585             : 
     586           0 :     ScDBDocFunc aFunc(*pViewData->GetDocShell());
     587           0 :     aFunc.UpdatePivotTable(*pDPObj, true, false);
     588             : }
     589             : 
     590        6130 : bool ScGridWindow::UpdateVisibleRange()
     591             : {
     592        6130 :     ScDocument& rDoc = pViewData->GetDocShell()->GetDocument();
     593             : 
     594        6130 :     SCCOL nPosX = 0;
     595        6130 :     SCROW nPosY = 0;
     596        6130 :     SCCOL nXRight = MAXCOL;
     597        6130 :     SCROW nYBottom = MAXROW;
     598             : 
     599        6130 :     if (rDoc.GetDrawLayer()->isTiledRendering())
     600             :     {
     601             :         // entire table in the tiled rendering case
     602           0 :         SCTAB nTab = pViewData->GetTabNo();
     603           0 :         SCCOL nEndCol = 0;
     604           0 :         SCROW nEndRow = 0;
     605             : 
     606           0 :         if (rDoc.GetPrintArea(nTab, nEndCol, nEndRow, false))
     607             :         {
     608           0 :             nXRight = nEndCol;
     609           0 :             nYBottom = nEndRow;
     610             :         }
     611             :     }
     612             :     else
     613             :     {
     614        6130 :         nPosX = pViewData->GetPosX(eHWhich);
     615        6130 :         nPosY = pViewData->GetPosY(eVWhich);
     616        6130 :         nXRight = nPosX + pViewData->VisibleCellsX(eHWhich);
     617        6130 :         if (nXRight > MAXCOL)
     618          22 :             nXRight = MAXCOL;
     619        6130 :         nYBottom = nPosY + pViewData->VisibleCellsY(eVWhich);
     620        6130 :         if (nYBottom > MAXROW)
     621          24 :             nYBottom = MAXROW;
     622             :     }
     623             : 
     624             :     // Store the current visible range.
     625        6130 :     bool bChanged = maVisibleRange.set(nPosX, nPosY, nXRight, nYBottom);
     626        6130 :     if (bChanged)
     627        1365 :         ResetAutoSpell();
     628             : 
     629        6130 :     return bChanged;
     630             : }
     631             : 
     632           0 : void ScGridWindow::DPMouseMove( const MouseEvent& rMEvt )
     633             : {
     634           0 :     DPTestMouse( rMEvt, true );
     635           0 : }
     636             : 
     637           0 : void ScGridWindow::DPMouseButtonUp( const MouseEvent& rMEvt )
     638             : {
     639           0 :     bDPMouse = false;
     640           0 :     ReleaseMouse();
     641             : 
     642           0 :     DPTestMouse( rMEvt, false );
     643           0 :     SetPointer( Pointer( PointerStyle::Arrow ) );
     644           0 : }
     645             : 
     646           0 : void ScGridWindow::UpdateDragRect( bool bShowRange, const Rectangle& rPosRect )
     647             : {
     648           0 :     SCCOL nStartX = ( rPosRect.Left()   >= 0 ) ? static_cast<SCCOL>(rPosRect.Left())   : SCCOL_MAX;
     649           0 :     SCROW nStartY = ( rPosRect.Top()    >= 0 ) ? static_cast<SCROW>(rPosRect.Top())    : SCROW_MAX;
     650           0 :     SCCOL nEndX   = ( rPosRect.Right()  >= 0 ) ? static_cast<SCCOL>(rPosRect.Right())  : SCCOL_MAX;
     651           0 :     SCROW nEndY   = ( rPosRect.Bottom() >= 0 ) ? static_cast<SCROW>(rPosRect.Bottom()) : SCROW_MAX;
     652             : 
     653           0 :     if ( bShowRange == bDragRect && nDragStartX == nStartX && nDragEndX == nEndX &&
     654           0 :                                     nDragStartY == nStartY && nDragEndY == nEndY )
     655             :     {
     656           0 :         return;         // everything unchanged
     657             :     }
     658             : 
     659           0 :     if ( bShowRange )
     660             :     {
     661           0 :         nDragStartX = nStartX;
     662           0 :         nDragStartY = nStartY;
     663           0 :         nDragEndX = nEndX;
     664           0 :         nDragEndY = nEndY;
     665           0 :         bDragRect = true;
     666             :     }
     667             :     else
     668           0 :         bDragRect = false;
     669             : 
     670           0 :     UpdateDragRectOverlay();
     671             : }
     672             : 
     673             : //  Page-Break-Modus
     674             : 
     675           0 : sal_uInt16 ScGridWindow::HitPageBreak( const Point& rMouse, ScRange* pSource,
     676             :                                     SCCOLROW* pBreak, SCCOLROW* pPrev )
     677             : {
     678           0 :     sal_uInt16 nFound = SC_PD_NONE;     // 0
     679           0 :     ScRange aSource;
     680           0 :     SCCOLROW nBreak = 0;
     681           0 :     SCCOLROW nPrev = 0;
     682             : 
     683           0 :     ScPageBreakData* pPageData = pViewData->GetView()->GetPageBreakData();
     684           0 :     if ( pPageData )
     685             :     {
     686           0 :         bool bHori = false;
     687           0 :         bool bVert = false;
     688           0 :         SCCOL nHitX = 0;
     689           0 :         SCROW nHitY = 0;
     690             : 
     691           0 :         long nMouseX = rMouse.X();
     692           0 :         long nMouseY = rMouse.Y();
     693             :         SCsCOL nPosX;
     694             :         SCsROW nPosY;
     695           0 :         pViewData->GetPosFromPixel( nMouseX, nMouseY, eWhich, nPosX, nPosY );
     696           0 :         Point aTL = pViewData->GetScrPos( nPosX, nPosY, eWhich );
     697           0 :         Point aBR = pViewData->GetScrPos( nPosX+1, nPosY+1, eWhich );
     698             : 
     699             :         //  Horizontal mehr Toleranz als vertikal, weil mehr Platz ist
     700           0 :         if ( nMouseX <= aTL.X() + 4 )
     701             :         {
     702           0 :             bHori = true;
     703           0 :             nHitX = nPosX;
     704             :         }
     705           0 :         else if ( nMouseX >= aBR.X() - 6 )
     706             :         {
     707           0 :             bHori = true;
     708           0 :             nHitX = nPosX+1;                    // linker Rand der naechsten Zelle
     709             :         }
     710           0 :         if ( nMouseY <= aTL.Y() + 2 )
     711             :         {
     712           0 :             bVert = true;
     713           0 :             nHitY = nPosY;
     714             :         }
     715           0 :         else if ( nMouseY >= aBR.Y() - 4 )
     716             :         {
     717           0 :             bVert = true;
     718           0 :             nHitY = nPosY+1;                    // oberer Rand der naechsten Zelle
     719             :         }
     720             : 
     721           0 :         if ( bHori || bVert )
     722             :         {
     723           0 :             sal_uInt16 nCount = sal::static_int_cast<sal_uInt16>( pPageData->GetCount() );
     724           0 :             for (sal_uInt16 nPos=0; nPos<nCount && !nFound; nPos++)
     725             :             {
     726           0 :                 ScPrintRangeData& rData = pPageData->GetData(nPos);
     727           0 :                 ScRange aRange = rData.GetPrintRange();
     728           0 :                 bool bLHit = ( bHori && nHitX == aRange.aStart.Col() );
     729           0 :                 bool bRHit = ( bHori && nHitX == aRange.aEnd.Col() + 1 );
     730           0 :                 bool bTHit = ( bVert && nHitY == aRange.aStart.Row() );
     731           0 :                 bool bBHit = ( bVert && nHitY == aRange.aEnd.Row() + 1 );
     732           0 :                 bool bInsideH = ( nPosX >= aRange.aStart.Col() && nPosX <= aRange.aEnd.Col() );
     733           0 :                 bool bInsideV = ( nPosY >= aRange.aStart.Row() && nPosY <= aRange.aEnd.Row() );
     734             : 
     735           0 :                 if ( bLHit )
     736             :                 {
     737           0 :                     if ( bTHit )
     738           0 :                         nFound = SC_PD_RANGE_TL;
     739           0 :                     else if ( bBHit )
     740           0 :                         nFound = SC_PD_RANGE_BL;
     741           0 :                     else if ( bInsideV )
     742           0 :                         nFound = SC_PD_RANGE_L;
     743             :                 }
     744           0 :                 else if ( bRHit )
     745             :                 {
     746           0 :                     if ( bTHit )
     747           0 :                         nFound = SC_PD_RANGE_TR;
     748           0 :                     else if ( bBHit )
     749           0 :                         nFound = SC_PD_RANGE_BR;
     750           0 :                     else if ( bInsideV )
     751           0 :                         nFound = SC_PD_RANGE_R;
     752             :                 }
     753           0 :                 else if ( bTHit && bInsideH )
     754           0 :                     nFound = SC_PD_RANGE_T;
     755           0 :                 else if ( bBHit && bInsideH )
     756           0 :                     nFound = SC_PD_RANGE_B;
     757           0 :                 if (nFound)
     758           0 :                     aSource = aRange;
     759             : 
     760             :                 //  Umbrueche
     761             : 
     762           0 :                 if ( bVert && bInsideH && !nFound )
     763             :                 {
     764           0 :                     size_t nRowCount = rData.GetPagesY();
     765           0 :                     const SCROW* pRowEnd = rData.GetPageEndY();
     766           0 :                     for (size_t nRowPos=0; nRowPos+1<nRowCount; nRowPos++)
     767           0 :                         if ( pRowEnd[nRowPos]+1 == nHitY )
     768             :                         {
     769           0 :                             nFound = SC_PD_BREAK_V;
     770           0 :                             aSource = aRange;
     771           0 :                             nBreak = nHitY;
     772           0 :                             if ( nRowPos )
     773           0 :                                 nPrev = pRowEnd[nRowPos-1]+1;
     774             :                             else
     775           0 :                                 nPrev = aRange.aStart.Row();
     776             :                         }
     777             :                 }
     778           0 :                 if ( bHori && bInsideV && !nFound )
     779             :                 {
     780           0 :                     size_t nColCount = rData.GetPagesX();
     781           0 :                     const SCCOL* pColEnd = rData.GetPageEndX();
     782           0 :                     for (size_t nColPos=0; nColPos+1<nColCount; nColPos++)
     783           0 :                         if ( pColEnd[nColPos]+1 == nHitX )
     784             :                         {
     785           0 :                             nFound = SC_PD_BREAK_H;
     786           0 :                             aSource = aRange;
     787           0 :                             nBreak = nHitX;
     788           0 :                             if ( nColPos )
     789           0 :                                 nPrev = pColEnd[nColPos-1]+1;
     790             :                             else
     791           0 :                                 nPrev = aRange.aStart.Col();
     792             :                         }
     793             :                 }
     794             :             }
     795             :         }
     796             :     }
     797             : 
     798           0 :     if (pSource)
     799           0 :         *pSource = aSource;     // Druckbereich
     800           0 :     if (pBreak)
     801           0 :         *pBreak = nBreak;       // X/Y Position des verchobenen Seitenumbruchs
     802           0 :     if (pPrev)
     803           0 :         *pPrev = nPrev;         // X/Y Anfang der Seite, die am Umbruch zuende ist
     804           0 :     return nFound;
     805             : }
     806             : 
     807           0 : void ScGridWindow::PagebreakMove( const MouseEvent& rMEvt, bool bUp )
     808             : {
     809             :     //! Scrolling und Umschalten mit RFMouseMove zusammenfassen !
     810             :     //! (Weginvertieren vor dem Scrolling ist anders)
     811             : 
     812             :     //  Scrolling
     813             : 
     814           0 :     bool bTimer = false;
     815           0 :     Point aPos = rMEvt.GetPosPixel();
     816           0 :     SCsCOL nDx = 0;
     817           0 :     SCsROW nDy = 0;
     818           0 :     if ( aPos.X() < 0 ) nDx = -1;
     819           0 :     if ( aPos.Y() < 0 ) nDy = -1;
     820           0 :     Size aSize = GetOutputSizePixel();
     821           0 :     if ( aPos.X() >= aSize.Width() )
     822           0 :         nDx = 1;
     823           0 :     if ( aPos.Y() >= aSize.Height() )
     824           0 :         nDy = 1;
     825           0 :     if ( nDx != 0 || nDy != 0 )
     826             :     {
     827           0 :         if ( bPagebreakDrawn )          // weginvertieren
     828             :         {
     829           0 :             bPagebreakDrawn = false;
     830           0 :             UpdateDragRectOverlay();
     831             :         }
     832             : 
     833           0 :         if ( nDx != 0 ) pViewData->GetView()->ScrollX( nDx, WhichH(eWhich) );
     834           0 :         if ( nDy != 0 ) pViewData->GetView()->ScrollY( nDy, WhichV(eWhich) );
     835           0 :         bTimer = true;
     836             :     }
     837             : 
     838             :     //  Umschalten bei Fixierung (damit Scrolling funktioniert)
     839             : 
     840           0 :     if ( eWhich == pViewData->GetActivePart() )     //??
     841             :     {
     842           0 :         if ( pViewData->GetHSplitMode() == SC_SPLIT_FIX )
     843           0 :             if ( nDx > 0 )
     844             :             {
     845           0 :                 if ( eWhich == SC_SPLIT_TOPLEFT )
     846           0 :                     pViewData->GetView()->ActivatePart( SC_SPLIT_TOPRIGHT );
     847           0 :                 else if ( eWhich == SC_SPLIT_BOTTOMLEFT )
     848           0 :                     pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMRIGHT );
     849             :             }
     850             : 
     851           0 :         if ( pViewData->GetVSplitMode() == SC_SPLIT_FIX )
     852           0 :             if ( nDy > 0 )
     853             :             {
     854           0 :                 if ( eWhich == SC_SPLIT_TOPLEFT )
     855           0 :                     pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMLEFT );
     856           0 :                 else if ( eWhich == SC_SPLIT_TOPRIGHT )
     857           0 :                     pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMRIGHT );
     858             :             }
     859             :     }
     860             : 
     861             :     //  ab hier neu
     862             : 
     863             :     //  gesucht wird eine Position zwischen den Zellen (vor nPosX / nPosY)
     864             :     SCsCOL nPosX;
     865             :     SCsROW nPosY;
     866           0 :     pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
     867             :     bool bLeft, bTop;
     868           0 :     pViewData->GetMouseQuadrant( aPos, eWhich, nPosX, nPosY, bLeft, bTop );
     869           0 :     if ( !bLeft ) ++nPosX;
     870           0 :     if ( !bTop )  ++nPosY;
     871             : 
     872           0 :     bool bBreak = ( nPagebreakMouse == SC_PD_BREAK_H || nPagebreakMouse == SC_PD_BREAK_V );
     873           0 :     bool bHide = false;
     874           0 :     bool bToEnd = false;
     875           0 :     ScRange aDrawRange = aPagebreakSource;
     876           0 :     if ( bBreak )
     877             :     {
     878           0 :         if ( nPagebreakMouse == SC_PD_BREAK_H )
     879             :         {
     880           0 :             if ( nPosX > aPagebreakSource.aStart.Col() &&
     881           0 :                  nPosX <= aPagebreakSource.aEnd.Col() + 1 )     // ans Ende ist auch erlaubt
     882             :             {
     883           0 :                 bToEnd = ( nPosX == aPagebreakSource.aEnd.Col() + 1 );
     884           0 :                 aDrawRange.aStart.SetCol( nPosX );
     885           0 :                 aDrawRange.aEnd.SetCol( nPosX - 1 );
     886             :             }
     887             :             else
     888           0 :                 bHide = true;
     889             :         }
     890             :         else
     891             :         {
     892           0 :             if ( nPosY > aPagebreakSource.aStart.Row() &&
     893           0 :                  nPosY <= aPagebreakSource.aEnd.Row() + 1 )     // ans Ende ist auch erlaubt
     894             :             {
     895           0 :                 bToEnd = ( nPosY == aPagebreakSource.aEnd.Row() + 1 );
     896           0 :                 aDrawRange.aStart.SetRow( nPosY );
     897           0 :                 aDrawRange.aEnd.SetRow( nPosY - 1 );
     898             :             }
     899             :             else
     900           0 :                 bHide = true;
     901             :         }
     902             :     }
     903             :     else
     904             :     {
     905           0 :         if ( nPagebreakMouse & SC_PD_RANGE_L )
     906           0 :             aDrawRange.aStart.SetCol( nPosX );
     907           0 :         if ( nPagebreakMouse & SC_PD_RANGE_T )
     908           0 :             aDrawRange.aStart.SetRow( nPosY );
     909           0 :         if ( nPagebreakMouse & SC_PD_RANGE_R )
     910             :         {
     911           0 :             if ( nPosX > 0 )
     912           0 :                 aDrawRange.aEnd.SetCol( nPosX-1 );
     913             :             else
     914           0 :                 bHide = true;
     915             :         }
     916           0 :         if ( nPagebreakMouse & SC_PD_RANGE_B )
     917             :         {
     918           0 :             if ( nPosY > 0 )
     919           0 :                 aDrawRange.aEnd.SetRow( nPosY-1 );
     920             :             else
     921           0 :                 bHide = true;
     922             :         }
     923           0 :         if ( aDrawRange.aStart.Col() > aDrawRange.aEnd.Col() ||
     924           0 :              aDrawRange.aStart.Row() > aDrawRange.aEnd.Row() )
     925           0 :             bHide = true;
     926             :     }
     927             : 
     928           0 :     if ( !bPagebreakDrawn || bUp || aDrawRange != aPagebreakDrag )
     929             :     {
     930             :         //  zeichnen...
     931             : 
     932           0 :         if ( bPagebreakDrawn )
     933             :         {
     934             :             // weginvertieren
     935           0 :             bPagebreakDrawn = false;
     936             :         }
     937           0 :         aPagebreakDrag = aDrawRange;
     938           0 :         if ( !bUp && !bHide )
     939             :         {
     940             :             // hininvertieren
     941           0 :             bPagebreakDrawn = true;
     942             :         }
     943           0 :         UpdateDragRectOverlay();
     944             :     }
     945             : 
     946             :     //  bei ButtonUp die Aenderung ausfuehren
     947             : 
     948           0 :     if ( bUp )
     949             :     {
     950           0 :         ScViewFunc* pViewFunc = pViewData->GetView();
     951           0 :         ScDocShell* pDocSh = pViewData->GetDocShell();
     952           0 :         ScDocument& rDoc = pDocSh->GetDocument();
     953           0 :         SCTAB nTab = pViewData->GetTabNo();
     954           0 :         bool bUndo (rDoc.IsUndoEnabled());
     955             : 
     956           0 :         if ( bBreak )
     957             :         {
     958           0 :             bool bColumn = ( nPagebreakMouse == SC_PD_BREAK_H );
     959           0 :             SCCOLROW nNew = bColumn ? static_cast<SCCOLROW>(nPosX) : static_cast<SCCOLROW>(nPosY);
     960           0 :             if ( nNew != nPagebreakBreak )
     961             :             {
     962           0 :                 if (bUndo)
     963             :                 {
     964           0 :                     OUString aUndo = ScGlobal::GetRscString( STR_UNDO_DRAG_BREAK );
     965           0 :                     pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
     966             :                 }
     967             : 
     968           0 :                 bool bGrow = !bHide && nNew > nPagebreakBreak;
     969           0 :                 if ( bColumn )
     970             :                 {
     971           0 :                     if (rDoc.HasColBreak(static_cast<SCCOL>(nPagebreakBreak), nTab) & BREAK_MANUAL)
     972             :                     {
     973           0 :                         ScAddress aOldAddr( static_cast<SCCOL>(nPagebreakBreak), nPosY, nTab );
     974           0 :                         pViewFunc->DeletePageBreak( true, true, &aOldAddr, false );
     975             :                     }
     976           0 :                     if ( !bHide && !bToEnd )    // am Ende nicht
     977             :                     {
     978           0 :                         ScAddress aNewAddr( static_cast<SCCOL>(nNew), nPosY, nTab );
     979           0 :                         pViewFunc->InsertPageBreak( true, true, &aNewAddr, false );
     980             :                     }
     981           0 :                     if ( bGrow )
     982             :                     {
     983             :                         //  vorigen Break auf hart, und Skalierung aendern
     984           0 :                         bool bManualBreak = (rDoc.HasColBreak(static_cast<SCCOL>(nPagebreakPrev), nTab) & BREAK_MANUAL);
     985           0 :                         if ( static_cast<SCCOL>(nPagebreakPrev) > aPagebreakSource.aStart.Col() && !bManualBreak )
     986             :                         {
     987           0 :                             ScAddress aPrev( static_cast<SCCOL>(nPagebreakPrev), nPosY, nTab );
     988           0 :                             pViewFunc->InsertPageBreak( true, true, &aPrev, false );
     989             :                         }
     990             : 
     991           0 :                         if (!pDocSh->AdjustPrintZoom( ScRange(
     992           0 :                                       static_cast<SCCOL>(nPagebreakPrev),0,nTab, static_cast<SCCOL>(nNew-1),0,nTab ) ))
     993           0 :                             bGrow = false;
     994             :                     }
     995             :                 }
     996             :                 else
     997             :                 {
     998           0 :                     if (rDoc.HasRowBreak(nPagebreakBreak, nTab) & BREAK_MANUAL)
     999             :                     {
    1000           0 :                         ScAddress aOldAddr( nPosX, nPagebreakBreak, nTab );
    1001           0 :                         pViewFunc->DeletePageBreak( false, true, &aOldAddr, false );
    1002             :                     }
    1003           0 :                     if ( !bHide && !bToEnd )    // am Ende nicht
    1004             :                     {
    1005           0 :                         ScAddress aNewAddr( nPosX, nNew, nTab );
    1006           0 :                         pViewFunc->InsertPageBreak( false, true, &aNewAddr, false );
    1007             :                     }
    1008           0 :                     if ( bGrow )
    1009             :                     {
    1010             :                         //  vorigen Break auf hart, und Skalierung aendern
    1011           0 :                         bool bManualBreak = (rDoc.HasRowBreak(nPagebreakPrev, nTab) & BREAK_MANUAL);
    1012           0 :                         if ( nPagebreakPrev > aPagebreakSource.aStart.Row() && !bManualBreak )
    1013             :                         {
    1014           0 :                             ScAddress aPrev( nPosX, nPagebreakPrev, nTab );
    1015           0 :                             pViewFunc->InsertPageBreak( false, true, &aPrev, false );
    1016             :                         }
    1017             : 
    1018           0 :                         if (!pDocSh->AdjustPrintZoom( ScRange(
    1019           0 :                                       0,nPagebreakPrev,nTab, 0,nNew-1,nTab ) ))
    1020           0 :                             bGrow = false;
    1021             :                     }
    1022             :                 }
    1023             : 
    1024           0 :                 if (bUndo)
    1025             :                 {
    1026           0 :                     pDocSh->GetUndoManager()->LeaveListAction();
    1027             :                 }
    1028             : 
    1029           0 :                 if (!bGrow)     // sonst in AdjustPrintZoom schon passiert
    1030             :                 {
    1031           0 :                     pViewFunc->UpdatePageBreakData( true );
    1032           0 :                     pDocSh->SetDocumentModified();
    1033             :                 }
    1034             :             }
    1035             :         }
    1036           0 :         else if ( bHide || aPagebreakDrag != aPagebreakSource )
    1037             :         {
    1038             :             //  Druckbereich setzen
    1039             : 
    1040           0 :             OUString aNewRanges;
    1041           0 :             sal_uInt16 nOldCount = rDoc.GetPrintRangeCount( nTab );
    1042           0 :             if ( nOldCount )
    1043             :             {
    1044           0 :                 for (sal_uInt16 nPos=0; nPos<nOldCount; nPos++)
    1045             :                 {
    1046           0 :                     const ScRange* pOld = rDoc.GetPrintRange( nTab, nPos );
    1047           0 :                     if ( pOld )
    1048             :                     {
    1049           0 :                         OUString aTemp;
    1050           0 :                         if ( *pOld != aPagebreakSource )
    1051           0 :                             aTemp = pOld->Format(SCA_VALID);
    1052           0 :                         else if ( !bHide )
    1053           0 :                             aTemp = aPagebreakDrag.Format(SCA_VALID);
    1054           0 :                         if (!aTemp.isEmpty())
    1055             :                         {
    1056           0 :                             if ( !aNewRanges.isEmpty() )
    1057           0 :                                 aNewRanges += ";";
    1058           0 :                             aNewRanges += aTemp;
    1059           0 :                         }
    1060             :                     }
    1061             :                 }
    1062             :             }
    1063           0 :             else if (!bHide)
    1064           0 :                 aNewRanges = aPagebreakDrag.Format(SCA_VALID);
    1065             : 
    1066           0 :             pViewFunc->SetPrintRanges( rDoc.IsPrintEntireSheet( nTab ), &aNewRanges, NULL, NULL, false );
    1067             :         }
    1068             :     }
    1069             : 
    1070             :     //  Timer fuer Scrolling
    1071             : 
    1072           0 :     if (bTimer && !bUp)
    1073           0 :         pViewData->GetView()->SetTimer( this, rMEvt );          // Event wiederholen
    1074             :     else
    1075           0 :         pViewData->GetView()->ResetTimer();
    1076         156 : }
    1077             : 
    1078             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11