LCOV - code coverage report
Current view: top level - sc/source/ui/view - gridwin3.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 59 197 29.9 %
Date: 2014-11-03 Functions: 8 17 47.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 <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             :     //  bei rechter Taste Draw-Aktion abbrechen
      68             : 
      69           0 :     ScDrawView* pDrView = pViewData->GetScDrawView();
      70           0 :     if ( pDrView && !rMEvt.IsLeft() && !bRet )
      71             :     {
      72           0 :         pDrView->BrkAction();
      73           0 :         bRet = true;
      74             :     }
      75           0 :     return bRet;
      76             : }
      77             : 
      78           0 : bool ScGridWindow::DrawMouseButtonUp(const MouseEvent& rMEvt)
      79             : {
      80           0 :     ScViewFunc* pView = pViewData->GetView();
      81           0 :     bool bRet = false;
      82           0 :     FuPoor* pDraw = pView->GetDrawFuncPtr();
      83           0 :     if (pDraw && !pViewData->IsRefMode())
      84             :     {
      85           0 :         pDraw->SetWindow( this );
      86           0 :         bRet = pDraw->MouseButtonUp( rMEvt );
      87             : 
      88             :         // execute "format paint brush" for drawing objects
      89           0 :         SfxItemSet* pDrawBrush = pView->GetDrawBrushSet();
      90           0 :         if ( pDrawBrush )
      91             :         {
      92           0 :             ScDrawView* pDrView = pViewData->GetScDrawView();
      93           0 :             if ( pDrView )
      94             :             {
      95           0 :                 bool bReplaceAll = true;
      96           0 :                 pDrView->SetAttrToMarked(*pDrawBrush, bReplaceAll);
      97             :             }
      98             : 
      99           0 :             if ( !pView->IsPaintBrushLocked() )
     100           0 :                 pView->ResetBrushDocument();        // end paint brush mode if not locked
     101             :         }
     102             :     }
     103             : 
     104           0 :     return bRet;
     105             : }
     106             : 
     107           0 : bool ScGridWindow::DrawMouseMove(const MouseEvent& rMEvt)
     108             : {
     109           0 :     FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
     110           0 :     if (pDraw && !pViewData->IsRefMode())
     111             :     {
     112           0 :         pDraw->SetWindow( this );
     113           0 :         bool bRet = pDraw->MouseMove( rMEvt );
     114           0 :         if ( bRet )
     115           0 :             UpdateStatusPosSize();
     116           0 :         return bRet;
     117             :     }
     118             :     else
     119             :     {
     120           0 :         SetPointer( Pointer( POINTER_ARROW ) );
     121           0 :         return false;
     122             :     }
     123             : }
     124             : 
     125        1104 : void ScGridWindow::DrawEndAction()
     126             : {
     127        1104 :     ScDrawView* pDrView = pViewData->GetScDrawView();
     128        1104 :     if ( pDrView && pDrView->IsAction() )
     129           0 :         pDrView->BrkAction();
     130             : 
     131        1104 :     FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
     132        1104 :     if (pDraw)
     133        1104 :         pDraw->StopDragTimer();
     134             : 
     135             :     //  ReleaseMouse beim Aufruf
     136        1104 : }
     137             : 
     138           0 : bool ScGridWindow::DrawCommand(const CommandEvent& rCEvt)
     139             : {
     140           0 :     ScDrawView* pDrView = pViewData->GetScDrawView();
     141           0 :     FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
     142           0 :     if (pDrView && pDraw && !pViewData->IsRefMode())
     143             :     {
     144           0 :         pDraw->SetWindow( this );
     145           0 :         sal_uInt8 nUsed = pDraw->Command( rCEvt );
     146           0 :         if( nUsed == SC_CMD_USED )
     147           0 :             nButtonDown = 0;                    // MouseButtonUp wird verschluckt...
     148           0 :         if( nUsed || pDrView->IsAction() )
     149           0 :             return true;
     150             :     }
     151             : 
     152           0 :     return false;
     153             : }
     154             : 
     155           0 : bool ScGridWindow::DrawKeyInput(const KeyEvent& rKEvt)
     156             : {
     157           0 :     ScDrawView* pDrView = pViewData->GetScDrawView();
     158           0 :     FuPoor* pDraw = pViewData->GetView()->GetDrawFuncPtr();
     159           0 :     if (pDrView && pDraw && !pViewData->IsRefMode())
     160             :     {
     161           0 :         pDraw->SetWindow( this );
     162           0 :         bool bOldMarked = pDrView->AreObjectsMarked();
     163           0 :         if (pDraw->KeyInput( rKEvt ))
     164             :         {
     165           0 :             bool bLeaveDraw = false;
     166           0 :             bool bUsed = true;
     167           0 :             bool bNewMarked = pDrView->AreObjectsMarked();
     168           0 :             if ( !pViewData->GetView()->IsDrawSelMode() )
     169           0 :                 if ( !bNewMarked )
     170             :                 {
     171           0 :                     pViewData->GetViewShell()->SetDrawShell( false );
     172           0 :                     bLeaveDraw = true;
     173           0 :                     if ( !bOldMarked &&
     174           0 :                         rKEvt.GetKeyCode().GetCode() == KEY_DELETE )
     175           0 :                         bUsed = false;                  // nichts geloescht
     176           0 :                     if(bOldMarked)
     177           0 :                         GetFocus();
     178             :                 }
     179           0 :             if (!bLeaveDraw)
     180           0 :                 UpdateStatusPosSize();      // for moving/resizing etc. by keyboard
     181           0 :             return bUsed;
     182             :         }
     183             :     }
     184             : 
     185           0 :     return false;
     186             : }
     187             : 
     188        2948 : void ScGridWindow::DrawRedraw( ScOutputData& rOutputData, ScUpdateMode eMode, sal_uLong nLayer )
     189             : {
     190             :     // #109985#
     191        2948 :     const ScViewOptions& rOpts = pViewData->GetOptions();
     192             : 
     193             :     // use new flags at SdrPaintView for hiding objects
     194        2948 :     const bool bDrawOle(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_OLE));
     195        2948 :     const bool bDrawChart(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_CHART));
     196        2948 :     const bool bDrawDraw(VOBJ_MODE_SHOW == rOpts.GetObjMode(VOBJ_TYPE_DRAW));
     197             : 
     198        2948 :     if(bDrawOle || bDrawChart || bDrawDraw)
     199             :     {
     200        2948 :         ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     201             : 
     202        2948 :         if(pDrView)
     203             :         {
     204        2948 :             pDrView->setHideOle(!bDrawOle);
     205        2948 :             pDrView->setHideChart(!bDrawChart);
     206        2948 :             pDrView->setHideDraw(!bDrawDraw);
     207        2948 :             pDrView->setHideFormControl(!bDrawDraw);
     208             :         }
     209             : 
     210        2948 :         if(SC_UPDATE_CHANGED == eMode)
     211             :         {
     212           0 :             rOutputData.DrawingSingle((sal_uInt16)nLayer);
     213             :         }
     214             :         else
     215             :         {
     216        2948 :             rOutputData.DrawSelectiveObjects((sal_uInt16)nLayer);
     217             :         }
     218             :     }
     219        2948 : }
     220             : 
     221        1474 : void ScGridWindow::DrawSdrGrid( const Rectangle& rDrawingRect, OutputDevice* pContentDev )
     222             : {
     223             :     //  Draw-Gitterlinien
     224             : 
     225        1474 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     226        1474 :     if ( pDrView && pDrView->IsGridVisible() )
     227             :     {
     228           0 :         SdrPageView* pPV = pDrView->GetSdrPageView();
     229             :         OSL_ENSURE(pPV, "keine PageView");
     230           0 :         if (pPV)
     231             :         {
     232           0 :             pContentDev->SetLineColor(COL_GRAY);
     233             : 
     234           0 :             pPV->DrawPageViewGrid( *pContentDev, rDrawingRect );
     235             :         }
     236             :     }
     237        1474 : }
     238             : 
     239       34204 : MapMode ScGridWindow::GetDrawMapMode( bool bForce )
     240             : {
     241       34204 :     ScDocument* pDoc = pViewData->GetDocument();
     242       34204 :     SCTAB nTab = pViewData->GetTabNo();
     243       34204 :     bool bNegativePage = pDoc->IsNegativePage( nTab );
     244             : 
     245       34204 :     MapMode aDrawMode = pViewData->GetLogicMode();
     246             : 
     247       34204 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     248       34204 :     if ( pDrView || bForce )
     249             :     {
     250       33270 :         Fraction aScaleX;
     251       33270 :         Fraction aScaleY;
     252       33270 :         if (pDrView)
     253       33270 :             pDrView->GetScale( aScaleX, aScaleY );
     254             :         else
     255             :         {
     256           0 :             SCCOL nEndCol = 0;
     257           0 :             SCROW nEndRow = 0;
     258           0 :             pDoc->GetTableArea( nTab, nEndCol, nEndRow );
     259           0 :             if (nEndCol<20) nEndCol = 20;
     260           0 :             if (nEndRow<20) nEndRow = 1000;
     261             :             ScDrawUtil::CalcScale( pDoc, nTab, 0,0, nEndCol,nEndRow, this,
     262           0 :                                     pViewData->GetZoomX(),pViewData->GetZoomY(),
     263             :                                     pViewData->GetPPTX(),pViewData->GetPPTY(),
     264           0 :                                     aScaleX,aScaleY );
     265             :         }
     266       33270 :         aDrawMode.SetScaleX(aScaleX);
     267       33270 :         aDrawMode.SetScaleY(aScaleY);
     268             :     }
     269       34204 :     aDrawMode.SetOrigin(Point());
     270       34204 :     Point aStartPos = pViewData->GetPixPos(eWhich);
     271       34204 :     if ( bNegativePage )
     272             :     {
     273             :         //  RTL uses negative positions for drawing objects
     274          15 :         aStartPos.X() = -aStartPos.X() + GetOutputSizePixel().Width() - 1;
     275             :     }
     276       34204 :     aDrawMode.SetOrigin( PixelToLogic( aStartPos, aDrawMode ) );
     277             : 
     278       34204 :     return aDrawMode;
     279             : }
     280             : 
     281         106 : void ScGridWindow::DrawAfterScroll()
     282             : {
     283         106 :     Update();       // immer, damit das Verhalten mit/ohne DrawingLayer gleich ist
     284             : 
     285         106 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     286         106 :     if (pDrView)
     287             :     {
     288         106 :         OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
     289         106 :         if (pOlView && pOlView->GetWindow() == this)
     290           0 :             pOlView->ShowCursor(false);                 // ist beim Scrollen weggekommen
     291             :     }
     292         106 : }
     293             : 
     294           0 : void ScGridWindow::CreateAnchorHandle(SdrHdlList& rHdl, const ScAddress& rAddress)
     295             : {
     296           0 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     297           0 :     if (pDrView)
     298             :     {
     299           0 :         const ScViewOptions& rOpts = pViewData->GetOptions();
     300           0 :         if(rOpts.GetOption( VOPT_ANCHOR ))
     301             :         {
     302           0 :             bool bNegativePage = pViewData->GetDocument()->IsNegativePage( pViewData->GetTabNo() );
     303           0 :             Point aPos = pViewData->GetScrPos( rAddress.Col(), rAddress.Row(), eWhich, true );
     304           0 :             aPos = PixelToLogic(aPos);
     305           0 :             rHdl.AddHdl(new SdrHdl(aPos, bNegativePage ? HDL_ANCHOR_TR : HDL_ANCHOR));
     306             :         }
     307             :     }
     308           0 : }
     309             : 
     310        1474 : SdrObject* ScGridWindow::GetEditObject()
     311             : {
     312        1474 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     313        1474 :     if (pDrView)
     314             :     {
     315        1474 :         OutlinerView* pOlView = pDrView->GetTextEditOutlinerView();
     316        1474 :         if (pOlView && pOlView->GetWindow() == this)
     317           0 :             return pDrView->GetTextEditObject();
     318             :     }
     319             : 
     320        1474 :     return NULL;
     321             : }
     322             : 
     323           0 : void ScGridWindow::UpdateStatusPosSize()
     324             : {
     325           0 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     326           0 :     if (!pDrView)
     327           0 :         return;         // shouldn't be called in that case
     328             : 
     329           0 :     SdrPageView* pPV = pDrView->GetSdrPageView();
     330           0 :     if (!pPV)
     331           0 :         return;         // shouldn't be called in that case either
     332             : 
     333           0 :     SfxItemSet aSet(pViewData->GetViewShell()->GetPool(), SID_ATTR_POSITION, SID_ATTR_SIZE);
     334             : 
     335             :     //  Fill items for position and size:
     336             :     //  show action rectangle during action,
     337             :     //  position and size of selected object(s) if something is selected,
     338             :     //  mouse position otherwise
     339             : 
     340           0 :     bool bActionItem = false;
     341           0 :     if ( pDrView->IsAction() )              // action rectangle
     342             :     {
     343           0 :         Rectangle aRect;
     344           0 :         pDrView->TakeActionRect( aRect );
     345           0 :         if ( !aRect.IsEmpty() )
     346             :         {
     347             :             // mouse position will have been adjusted for offset
     348             :             // at current position and zoom, restore that adjustment here
     349             :             // so status shows correct value
     350           0 :             aRect -= pDrView->GetGridOffset();
     351           0 :             pPV->LogicToPagePos(aRect);
     352           0 :             aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
     353             :             aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
     354           0 :                     Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
     355           0 :             bActionItem = true;
     356             :         }
     357             :     }
     358           0 :     if ( !bActionItem )
     359             :     {
     360           0 :         if ( pDrView->AreObjectsMarked() )      // selected objects
     361             :         {
     362           0 :             Rectangle aRect = pDrView->GetAllMarkedRect();
     363             :             // mouse position will have been adjusted for offset
     364             :             // at current position and zoom, restore that adjustment here
     365             :             // so status shows correct value
     366           0 :             aRect -=  pDrView->GetGridOffset();
     367           0 :             pPV->LogicToPagePos(aRect);
     368           0 :             aSet.Put( SfxPointItem( SID_ATTR_POSITION, aRect.TopLeft() ) );
     369             :             aSet.Put( SvxSizeItem( SID_ATTR_SIZE,
     370           0 :                     Size( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() ) ) );
     371             :         }
     372             :         else                                // mouse position
     373             :         {
     374           0 :             Point aPos = PixelToLogic(aCurMousePos);
     375           0 :             pPV->LogicToPagePos(aPos);
     376           0 :             aSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos ) );
     377           0 :             aSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
     378             :         }
     379             :     }
     380             : 
     381           0 :     pViewData->GetBindings().SetState(aSet);
     382             : }
     383             : 
     384           0 : bool ScGridWindow::DrawHasMarkedObj()
     385             : {
     386           0 :     ScDrawView* p = pViewData->GetScDrawView();
     387           0 :     return p && p->AreObjectsMarked();
     388             : }
     389             : 
     390           0 : void ScGridWindow::DrawMarkDropObj( SdrObject* pObj )
     391             : {
     392           0 :     ScDrawView* pDrView = pViewData->GetView()->GetScDrawView();
     393           0 :     if (pDrView)
     394           0 :         pDrView->MarkDropObj(pObj);
     395         228 : }
     396             : 
     397             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10