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

Generated by: LCOV version 1.10