LCOV - code coverage report
Current view: top level - sc/source/ui/view - gridwin3.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 70 199 35.2 %
Date: 2015-06-13 12:38:46 Functions: 9 17 52.9 %
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 <editeng/eeitem.hxx>
      22             : 
      23             : #include <svx/svdoutl.hxx>
      24             : #include <svx/svdotext.hxx>
      25             : #include <svx/svdpagv.hxx>
      26             : #include <editeng/sizeitem.hxx>
      27             : #include <sfx2/bindings.hxx>
      28             : #include <svl/ptitem.hxx>
      29             : 
      30             : #include "tabvwsh.hxx"
      31             : #include "gridwin.hxx"
      32             : #include "dbfunc.hxx"
      33             : #include "viewdata.hxx"
      34             : #include "output.hxx"
      35             : #include "drawview.hxx"
      36             : #include "fupoor.hxx"
      37             : 
      38             : #include "drawutil.hxx"
      39             : #include "document.hxx"
      40             : #include "drwlayer.hxx"
      41             : #include <vcl/svapp.hxx>
      42             : #include "userdat.hxx"
      43             : #include "unitconv.hxx"
      44             : #include <svx/svdpage.hxx>
      45             : 
      46           0 : bool ScGridWindow::DrawMouseButtonDown(const MouseEvent& rMEvt)
      47             : {
      48           0 :     bool bRet = false;
      49           0 :     FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
      50           0 :     if (pDraw && !pViewData->IsRefMode())
      51             :     {
      52           0 :         pDraw->SetWindow( this );
      53           0 :         Point aLogicPos = PixelToLogic(rMEvt.GetPosPixel());
      54           0 :         if ( pDraw->IsDetectiveHit( aLogicPos ) )
      55             :         {
      56             :             //  auf Detektiv-Pfeilen gar nichts (Doppelklick wird bei ButtonUp ausgewertet)
      57           0 :             bRet = true;
      58             :         }
      59             :         else
      60             :         {
      61           0 :             bRet = pDraw->MouseButtonDown( rMEvt );
      62           0 :             if ( bRet )
      63           0 :                 UpdateStatusPosSize();
      64             :         }
      65             :     }
      66             : 
      67             :     // cancel draw with right key
      68           0 :     ScDrawView* pDrView = pViewData->GetScDrawView();
      69           0 :     if ( pDrView && !rMEvt.IsLeft() && !bRet )
      70             :     {
      71           0 :         pDrView->BrkAction();
      72           0 :         bRet = true;
      73             :     }
      74           0 :     return bRet;
      75             : }
      76             : 
      77           0 : bool ScGridWindow::DrawMouseButtonUp(const MouseEvent& rMEvt)
      78             : {
      79           0 :     ScViewFunc* pView = pViewData->GetView();
      80           0 :     bool bRet = false;
      81           0 :     FuPoor* pDraw = pView->GetDrawFuncPtr();
      82           0 :     if (pDraw && !pViewData->IsRefMode())
      83             :     {
      84           0 :         pDraw->SetWindow( this );
      85           0 :         bRet = pDraw->MouseButtonUp( rMEvt );
      86             : 
      87             :         // execute "format paint brush" for drawing objects
      88           0 :         SfxItemSet* pDrawBrush = pView->GetDrawBrushSet();
      89           0 :         if ( pDrawBrush )
      90             :         {
      91           0 :             ScDrawView* pDrView = pViewData->GetScDrawView();
      92           0 :             if ( pDrView )
      93             :             {
      94           0 :                 bool bReplaceAll = true;
      95           0 :                 pDrView->SetAttrToMarked(*pDrawBrush, bReplaceAll);
      96             :             }
      97             : 
      98           0 :             if ( !pView->IsPaintBrushLocked() )
      99           0 :                 pView->ResetBrushDocument(); // end paint brush mode if not locked
     100             :         }
     101             :     }
     102             : 
     103           0 :     return bRet;
     104             : }
     105             : 
     106           0 : bool ScGridWindow::DrawMouseMove(const MouseEvent& rMEvt)
     107             : {
     108           0 :     FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
     109           0 :     if (pDraw && !pViewData->IsRefMode())
     110             :     {
     111           0 :         pDraw->SetWindow( this );
     112           0 :         bool bRet = pDraw->MouseMove( rMEvt );
     113           0 :         if ( bRet )
     114           0 :             UpdateStatusPosSize();
     115           0 :         return bRet;
     116             :     }
     117             :     else
     118             :     {
     119           0 :         SetPointer( Pointer( PointerStyle::Arrow ) );
     120           0 :         return false;
     121             :     }
     122             : }
     123             : 
     124         689 : void ScGridWindow::DrawEndAction()
     125             : {
     126         689 :     ScDrawView* pDrView = pViewData->GetScDrawView();
     127         689 :     if ( pDrView && pDrView->IsAction() )
     128           0 :         pDrView->BrkAction();
     129             : 
     130         689 :     FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
     131         689 :     if (pDraw)
     132         689 :         pDraw->StopDragTimer();
     133             : 
     134             :     //  ReleaseMouse beim Aufruf
     135         689 : }
     136             : 
     137           0 : bool ScGridWindow::DrawCommand(const CommandEvent& rCEvt)
     138             : {
     139           0 :     ScDrawView* pDrView = pViewData->GetScDrawView();
     140           0 :     FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
     141           0 :     if (pDrView && pDraw && !pViewData->IsRefMode())
     142             :     {
     143           0 :         pDraw->SetWindow( this );
     144           0 :         sal_uInt8 nUsed = pDraw->Command( rCEvt );
     145           0 :         if( nUsed == SC_CMD_USED )
     146           0 :             nButtonDown = 0;  // MouseButtonUp  wird verschluckt...
     147           0 :         if( nUsed || pDrView->IsAction() )
     148           0 :             return true;
     149             :     }
     150             : 
     151           0 :     return false;
     152             : }
     153             : 
     154           0 : bool ScGridWindow::DrawKeyInput(const KeyEvent& rKEvt)
     155             : {
     156           0 :     ScDrawView* pDrView = pViewData->GetScDrawView();
     157           0 :     FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
     158           0 :     if (pDrView && pDraw && !pViewData->IsRefMode())
     159             :     {
     160           0 :         pDraw->SetWindow( this );
     161           0 :         bool bOldMarked = pDrView->AreObjectsMarked();
     162           0 :         if (pDraw->KeyInput( rKEvt ))
     163             :         {
     164           0 :             bool bLeaveDraw = false;
     165           0 :             bool bUsed = true;
     166           0 :             bool bNewMarked = pDrView->AreObjectsMarked();
     167           0 :             if ( !pViewData->GetView()->IsDrawSelMode() )
     168           0 :                 if ( !bNewMarked )
     169             :                 {
     170           0 :                     pViewData->GetViewShell()->SetDrawShell( false );
     171           0 :                     bLeaveDraw = true;
     172           0 :                     if ( !bOldMarked &&
     173           0 :                         rKEvt.GetKeyCode().GetCode() == KEY_DELETE )
     174           0 :                         bUsed = false; // nothing deleted
     175           0 :                     if(bOldMarked)
     176           0 :                         GetFocus();
     177             :                 }
     178           0 :             if (!bLeaveDraw)
     179           0 :                 UpdateStatusPosSize(); // for moving/resizing etc. by keyboard
     180           0 :             return bUsed;
     181             :         }
     182             :     }
     183             : 
     184           0 :     return false;
     185             : }
     186             : 
     187        5928 : void ScGridWindow::DrawRedraw( ScOutputData& rOutputData, ScUpdateMode eMode, sal_uLong nLayer )
     188             : {
     189             :     // #109985#
     190        5928 :     const ScViewOptions& rOpts = pViewData->GetOptions();
     191             : 
     192             :     // use new flags at SdrPaintView for hiding objects
     193        5928 :     const bool bDrawOle(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_OLE));
     194        5928 :     const bool bDrawChart(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_CHART));
     195        5928 :     const bool bDrawDraw(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_DRAW));
     196             : 
     197        5928 :     if(bDrawOle || bDrawChart || bDrawDraw)
     198             :     {
     199        5928 :         ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     200             : 
     201        5928 :         if(pDrView)
     202             :         {
     203        5928 :             pDrView->setHideOle(!bDrawOle);
     204        5928 :             pDrView->setHideChart(!bDrawChart);
     205        5928 :             pDrView->setHideDraw(!bDrawDraw);
     206        5928 :             pDrView->setHideFormControl(!bDrawDraw);
     207             :         }
     208             : 
     209        5928 :         if(SC_UPDATE_CHANGED == eMode)
     210             :         {
     211           0 :             rOutputData.DrawingSingle((sal_uInt16)nLayer);
     212             :         }
     213             :         else
     214             :         {
     215        5928 :             rOutputData.DrawSelectiveObjects((sal_uInt16)nLayer);
     216             :         }
     217             :     }
     218        5928 : }
     219             : 
     220        2964 : void ScGridWindow::DrawSdrGrid( const Rectangle& rDrawingRect, OutputDevice* pContentDev )
     221             : {
     222             :     // Draw grid lines
     223             : 
     224        2964 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     225        2964 :     if ( pDrView && pDrView->IsGridVisible() )
     226             :     {
     227           0 :         SdrPageView* pPV = pDrView->GetSdrPageView();
     228             :         OSL_ENSURE(pPV, "PageView not available");
     229           0 :         if (pPV)
     230             :         {
     231           0 :             pContentDev->SetLineColor(COL_GRAY);
     232             : 
     233           0 :             pPV->DrawPageViewGrid( *pContentDev, rDrawingRect );
     234             :         }
     235             :     }
     236        2964 : }
     237             : 
     238       26590 : MapMode ScGridWindow::GetDrawMapMode( bool bForce )
     239             : {
     240       26590 :     ScDocument* pDoc = pViewData->GetDocument();
     241             : 
     242             :     // FIXME this shouldn't be necessary once we change the entire Calc to
     243             :     // work in the logic coordinates (ideally 100ths of mm - so that it is
     244             :     // the same as editeng and drawinglayer), and get rid of all the
     245             :     // SetMapMode's and other unneccessary fun we have with pixels
     246       26590 :     if (pDoc->GetDrawLayer() && pDoc->GetDrawLayer()->isTiledRendering())
     247             :     {
     248           0 :         return pViewData->GetLogicMode();
     249             :     }
     250             : 
     251       26590 :     SCTAB nTab = pViewData->GetTabNo();
     252       26590 :     bool bNegativePage = pDoc->IsNegativePage( nTab );
     253             : 
     254       26590 :     MapMode aDrawMode = pViewData->GetLogicMode();
     255             : 
     256       26590 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     257       26590 :     if ( pDrView || bForce )
     258             :     {
     259       26038 :         Fraction aScaleX;
     260       52076 :         Fraction aScaleY;
     261       26038 :         if (pDrView)
     262       26038 :             pDrView->GetScale( aScaleX, aScaleY );
     263             :         else
     264             :         {
     265           0 :             SCCOL nEndCol = 0;
     266           0 :             SCROW nEndRow = 0;
     267           0 :             pDoc->GetTableArea( nTab, nEndCol, nEndRow );
     268           0 :             if (nEndCol<20) nEndCol = 20;
     269           0 :             if (nEndRow<20) nEndRow = 1000;
     270             :             ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, this,
     271           0 :                                     pViewData->GetZoomX(),pViewData->GetZoomY(),
     272             :                                     pViewData->GetPPTX(),pViewData->GetPPTY(),
     273           0 :                                     aScaleX,aScaleY );
     274             :         }
     275       26038 :         aDrawMode.SetScaleX(aScaleX);
     276       52076 :         aDrawMode.SetScaleY(aScaleY);
     277             :     }
     278       26590 :     aDrawMode.SetOrigin(Point());
     279       26590 :     Point aStartPos = pViewData->GetPixPos(eWhich);
     280       26590 :     if ( bNegativePage )
     281             :     {
     282             :         //  RTL uses negative positions for drawing objects
     283           8 :         aStartPos.X() = -aStartPos.X() + GetOutputSizePixel().Width() - 1;
     284             :     }
     285       26590 :     aDrawMode.SetOrigin( PixelToLogic( aStartPos, aDrawMode ) );
     286             : 
     287       26590 :     return aDrawMode;
     288             : }
     289             : 
     290         109 : void ScGridWindow::DrawAfterScroll()
     291             : {
     292         109 :     Update(); // always, so the behaviour with and without DrawingLayer is the same
     293             : 
     294         109 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     295         109 :     if (pDrView)
     296             :     {
     297         109 :         OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
     298         109 :         if (pOlView && pOlView->GetWindow() == this)
     299           0 :             pOlView->ShowCursor(false); // was removed at scrolling
     300             :     }
     301         109 : }
     302             : 
     303           1 : void ScGridWindow::CreateAnchorHandle(SdrHdlList& rHdl, const ScAddress& rAddress)
     304             : {
     305           1 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     306           1 :     if (pDrView)
     307             :     {
     308           1 :         const ScViewOptions& rOpts = pViewData->GetOptions();
     309           1 :         if(rOpts.GetOption( VOPT_ANCHOR ))
     310             :         {
     311           1 :             bool bNegativePage = pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() );
     312           1 :             Point aPos = pViewData->GetScrPos( rAddress.Col(), rAddress.Row(), eWhich, true );
     313           1 :             aPos = PixelToLogic(aPos);
     314           1 :             rHdl.AddHdl(new SdrHdl(aPos, bNegativePage ? HDL_ANCHOR_TR : HDL_ANCHOR));
     315             :         }
     316             :     }
     317           1 : }
     318             : 
     319        2964 : SdrObject* ScGridWindow::GetEditObject()
     320             : {
     321        2964 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     322        2964 :     if (pDrView)
     323             :     {
     324        2964 :         OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
     325        2964 :         if (pOlView && pOlView->GetWindow() == this)
     326           0 :             return pDrView->GetTextEditObject();
     327             :     }
     328             : 
     329        2964 :     return NULL;
     330             : }
     331             : 
     332           0 : void ScGridWindow::UpdateStatusPosSize()
     333             : {
     334           0 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     335           0 :     if (!pDrView)
     336           0 :         return; // shouldn't be called in that case
     337             : 
     338           0 :     SdrPageView* pPV = pDrView->GetSdrPageView();
     339           0 :     if (!pPV)
     340           0 :         return; // shouldn't be called in that case either
     341             : 
     342           0 :     SfxItemSet aSet(pViewData->GetViewShell()->GetPool(), SID_ATTR_POSITION, SID_ATTR_SIZE);
     343             : 
     344             :     //  Fill items for position and size:
     345             :     //  show action rectangle during action,
     346             :     //  position and size of selected object(s) if something is selected,
     347             :     //  mouse position otherwise
     348             : 
     349           0 :     bool bActionItem = false;
     350           0 :     if ( pDrView->IsAction() ) // action rectangle
     351             :     {
     352           0 :         Rectangle aRect;
     353           0 :         pDrView->TakeActionRect( aRect );
     354           0 :         if ( !aRect.IsEmpty() )
     355             :         {
     356             :             // mouse position will have been adjusted for offset
     357             :             // at current position and zoom, restore that adjustment here
     358             :             // so status shows correct value
     359           0 :             aRect -= pDrView->GetGridOffset();
     360           0 :             pPV->LogicToPagePos(aRect);
     361           0 :             aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
     362             :             aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
     363           0 :                     Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
     364           0 :             bActionItem = true;
     365             :         }
     366             :     }
     367           0 :     if ( !bActionItem )
     368             :     {
     369           0 :         if ( pDrView->AreObjectsMarked() ) // selected objects
     370             :         {
     371           0 :             Rectangle aRect = pDrView->GetAllMarkedRect();
     372             :             // mouse position will have been adjusted for offset
     373             :             // at current position and zoom, restore that adjustment here
     374             :             // so status shows correct value
     375           0 :             aRect -=  pDrView->GetGridOffset();
     376           0 :             pPV->LogicToPagePos(aRect);
     377           0 :             aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
     378             :             aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
     379           0 :                     Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
     380             :         }
     381             :         else // mouse position
     382             :         {
     383           0 :             Point aPos = PixelToLogic(aCurMousePos);
     384           0 :             pPV->LogicToPagePos(aPos);
     385           0 :             aSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
     386           0 :             aSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
     387             :         }
     388             :     }
     389             : 
     390           0 :     pViewData->GetBindings().SetState(aSet);
     391             : }
     392             : 
     393           0 : bool ScGridWindow::DrawHasMarkedObj()
     394             : {
     395           0 :     ScDrawView* p = pViewData->GetScDrawView();
     396           0 :     return p && p->AreObjectsMarked();
     397             : }
     398             : 
     399           0 : void ScGridWindow::DrawMarkDropObj( SdrObject* pObj )
     400             : {
     401           0 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     402           0 :     if (pDrView)
     403           0 :         pDrView->MarkDropObj(pObj);
     404         156 : }
     405             : 
     406             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11