LCOV - code coverage report
Current view: top level - svx/source/table - tablehandles.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 115 0.9 %
Date: 2015-06-13 12:38:46 Functions: 2 16 12.5 %
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             : 
      21             : #include "tablehandles.hxx"
      22             : 
      23             : #include <vcl/svapp.hxx>
      24             : #include <vcl/outdev.hxx>
      25             : #include <vcl/canvastools.hxx>
      26             : #include <vcl/hatch.hxx>
      27             : #include <basegfx/polygon/b2dpolygon.hxx>
      28             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      29             : #include <basegfx/range/b2drectangle.hxx>
      30             : #include <basegfx/polygon/b2dpolygontools.hxx>
      31             : #include <svx/sdr/overlay/overlayobject.hxx>
      32             : #include <svx/sdr/overlay/overlaymanager.hxx>
      33             : #include <svx/sdrpagewindow.hxx>
      34             : #include <svx/sdrpaintwindow.hxx>
      35             : #include <svx/svdmrkv.hxx>
      36             : #include <svx/svdpagv.hxx>
      37             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      38             : #include <sdr/overlay/overlayrectangle.hxx>
      39             : #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
      40             : 
      41             : namespace sdr { namespace table {
      42             : 
      43             : 
      44             : 
      45             : class OverlayTableEdge : public sdr::overlay::OverlayObject
      46             : {
      47             : protected:
      48             :     basegfx::B2DPolyPolygon maPolyPolygon;
      49             :     bool                    mbVisible;
      50             : 
      51             :     // geometry creation for OverlayObject
      52             :     virtual drawinglayer::primitive2d::Primitive2DSequence createOverlayObjectPrimitive2DSequence() SAL_OVERRIDE;
      53             : 
      54             : public:
      55             :     OverlayTableEdge( const basegfx::B2DPolyPolygon& rPolyPolygon, bool bVisible );
      56             :     virtual ~OverlayTableEdge();
      57             : };
      58             : 
      59             : 
      60             : 
      61           0 : TableEdgeHdl::TableEdgeHdl( const Point& rPnt, bool bHorizontal, sal_Int32 nMin, sal_Int32 nMax, sal_Int32 nEdges )
      62             : : SdrHdl( rPnt, HDL_USER )
      63             : , mbHorizontal( bHorizontal )
      64             : , mnMin( nMin )
      65             : , mnMax( nMax )
      66           0 : , maEdges(nEdges)
      67             : {
      68           0 : }
      69             : 
      70           0 : void TableEdgeHdl::SetEdge( sal_Int32 nEdge, sal_Int32 nStart, sal_Int32 nEnd, TableEdgeState eState )
      71             : {
      72           0 :     if( (nEdge >= 0) && (nEdge <= sal::static_int_cast<sal_Int32>(maEdges.size())) )
      73             :     {
      74           0 :         maEdges[nEdge].mnStart = nStart;
      75           0 :         maEdges[nEdge].mnEnd = nEnd;
      76           0 :         maEdges[nEdge].meState = eState;
      77             :     }
      78             :     else
      79             :     {
      80             :         OSL_FAIL( "sdr::table::TableEdgeHdl::SetEdge(), invalid edge!" );
      81             :     }
      82           0 : }
      83             : 
      84           0 : Pointer TableEdgeHdl::GetPointer() const
      85             : {
      86           0 :     if( mbHorizontal )
      87           0 :         return PointerStyle::VSplit;
      88             :     else
      89           0 :         return PointerStyle::HSplit;
      90             : }
      91             : 
      92           0 : sal_Int32 TableEdgeHdl::GetValidDragOffset( const SdrDragStat& rDrag ) const
      93             : {
      94           0 :     return std::min( std::max( static_cast<sal_Int32>(mbHorizontal ? rDrag.GetDY() : rDrag.GetDX()), mnMin ), mnMax );
      95             : }
      96             : 
      97           0 : basegfx::B2DPolyPolygon TableEdgeHdl::getSpecialDragPoly(const SdrDragStat& rDrag) const
      98             : {
      99           0 :     basegfx::B2DPolyPolygon aVisible;
     100           0 :     basegfx::B2DPolyPolygon aInvisible;
     101             : 
     102             :     // create and return visible and non-visible parts for drag
     103           0 :     getPolyPolygon(aVisible, aInvisible, &rDrag);
     104           0 :     aVisible.append(aInvisible);
     105             : 
     106           0 :     return aVisible;
     107             : }
     108             : 
     109           0 : void TableEdgeHdl::getPolyPolygon(basegfx::B2DPolyPolygon& rVisible, basegfx::B2DPolyPolygon& rInvisible, const SdrDragStat* pDrag) const
     110             : {
     111             :     // changed method to create visible and invisible partial polygons in one run in
     112             :     // separate PolyPolygons; both kinds are used
     113           0 :     basegfx::B2DPoint aOffset(aPos.X(), aPos.Y());
     114           0 :     rVisible.clear();
     115           0 :     rInvisible.clear();
     116             : 
     117           0 :     if( pDrag )
     118             :     {
     119           0 :         int n = mbHorizontal ? 1 : 0;
     120           0 :         aOffset[n] = aOffset[n] + GetValidDragOffset( *pDrag );
     121             :     }
     122             : 
     123           0 :     basegfx::B2DPoint aStart(aOffset), aEnd(aOffset);
     124           0 :     int nPos = mbHorizontal ? 0 : 1;
     125           0 :     TableEdgeVector::const_iterator aIter( maEdges.begin() );
     126             : 
     127           0 :     while( aIter != maEdges.end() )
     128             :     {
     129           0 :         TableEdge aEdge(*aIter++);
     130             : 
     131           0 :         aStart[nPos] = aOffset[nPos] + aEdge.mnStart;
     132           0 :         aEnd[nPos] = aOffset[nPos] + aEdge.mnEnd;
     133             : 
     134           0 :         basegfx::B2DPolygon aPolygon;
     135           0 :         aPolygon.append( aStart );
     136           0 :         aPolygon.append( aEnd );
     137             : 
     138           0 :         if(aEdge.meState == Visible)
     139             :         {
     140           0 :             rVisible.append(aPolygon);
     141             :         }
     142             :         else
     143             :         {
     144           0 :             rInvisible.append(aPolygon);
     145             :         }
     146           0 :     }
     147           0 : }
     148             : 
     149           0 : void TableEdgeHdl::CreateB2dIAObject()
     150             : {
     151           0 :     GetRidOfIAObject();
     152             : 
     153           0 :     if(pHdlList && pHdlList->GetView() && !pHdlList->GetView()->areMarkHandlesHidden())
     154             :     {
     155           0 :         SdrMarkView* pView = pHdlList->GetView();
     156           0 :         SdrPageView* pPageView = pView->GetSdrPageView();
     157             : 
     158           0 :         if(pPageView)
     159             :         {
     160           0 :             basegfx::B2DPolyPolygon aVisible;
     161           0 :             basegfx::B2DPolyPolygon aInvisible;
     162             : 
     163             :             // get visible and invisible parts
     164           0 :             getPolyPolygon(aVisible, aInvisible, 0);
     165             : 
     166           0 :             if(aVisible.count() || aInvisible.count())
     167             :             {
     168           0 :                 for(sal_uInt32 nWindow = 0; nWindow < pPageView->PageWindowCount(); nWindow++)
     169             :                 {
     170           0 :                     const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(nWindow);
     171             : 
     172           0 :                     if(rPageWindow.GetPaintWindow().OutputToWindow())
     173             :                     {
     174           0 :                         rtl::Reference< sdr::overlay::OverlayManager > xManager = rPageWindow.GetOverlayManager();
     175           0 :                         if (xManager.is())
     176             :                         {
     177           0 :                             if(aVisible.count())
     178             :                             {
     179             :                                 // create overlay object for visible parts
     180           0 :                                 sdr::overlay::OverlayObject* pOverlayObject = new OverlayTableEdge(aVisible, true);
     181           0 :                                 xManager->add(*pOverlayObject);
     182           0 :                                 maOverlayGroup.append(*pOverlayObject);
     183             :                             }
     184             : 
     185           0 :                             if(aInvisible.count())
     186             :                             {
     187             :                                 // also create overlay object vor invisible parts to allow
     188             :                                 // a standard HitTest using the primitives from that overlay object
     189             :                                 // (see OverlayTableEdge implementation)
     190           0 :                                 sdr::overlay::OverlayObject* pOverlayObject = new OverlayTableEdge(aInvisible, false);
     191           0 :                                 xManager->add(*pOverlayObject);
     192           0 :                                 maOverlayGroup.append(*pOverlayObject);
     193             :                             }
     194           0 :                         }
     195             :                     }
     196             :                 }
     197           0 :             }
     198             :         }
     199             :     }
     200           0 : }
     201             : 
     202             : 
     203             : 
     204           0 : OverlayTableEdge::OverlayTableEdge( const basegfx::B2DPolyPolygon& rPolyPolygon, bool bVisible )
     205             : :   OverlayObject(Color(COL_GRAY))
     206             : ,   maPolyPolygon( rPolyPolygon )
     207           0 : ,   mbVisible(bVisible)
     208             : {
     209           0 : }
     210             : 
     211           0 : OverlayTableEdge::~OverlayTableEdge()
     212             : {
     213           0 : }
     214             : 
     215           0 : drawinglayer::primitive2d::Primitive2DSequence OverlayTableEdge::createOverlayObjectPrimitive2DSequence()
     216             : {
     217           0 :     drawinglayer::primitive2d::Primitive2DSequence aRetval;
     218             : 
     219           0 :     if(maPolyPolygon.count())
     220             :     {
     221             :         // Discussed with CL. Currently i will leave the transparence out since this
     222             :         // a little bit expensive. We may check the look with drag polygons later
     223             :         const drawinglayer::primitive2d::Primitive2DReference aReference(
     224             :             new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
     225             :                 maPolyPolygon,
     226           0 :                 getBaseColor().getBColor()));
     227             : 
     228           0 :         if(mbVisible)
     229             :         {
     230             :             // visible, just return as sequence
     231           0 :             aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1);
     232             :         }
     233             :         else
     234             :         {
     235             :             // embed in HiddenGeometryPrimitive2D to support HitTest of this invisible
     236             :             // overlay object
     237           0 :             const drawinglayer::primitive2d::Primitive2DSequence aSequence(&aReference, 1);
     238             :             const drawinglayer::primitive2d::Primitive2DReference aNewReference(
     239           0 :                 new drawinglayer::primitive2d::HiddenGeometryPrimitive2D(aSequence));
     240           0 :             aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aNewReference, 1);
     241           0 :         }
     242             :     }
     243             : 
     244           0 :     return aRetval;
     245             : }
     246             : 
     247             : 
     248             : 
     249           0 : TableBorderHdl::TableBorderHdl(
     250             :     const Rectangle& rRect,
     251             :     bool bAnimate)
     252             : :   SdrHdl(rRect.TopLeft(), HDL_MOVE),
     253             :     maRectangle(rRect),
     254           0 :     mbAnimate(bAnimate)
     255             : {
     256           0 : }
     257             : 
     258           0 : Pointer TableBorderHdl::GetPointer() const
     259             : {
     260           0 :     return PointerStyle::Move;
     261             : }
     262             : 
     263             : // create marker for this kind
     264           0 : void TableBorderHdl::CreateB2dIAObject()
     265             : {
     266           0 :     GetRidOfIAObject();
     267             : 
     268           0 :     if (pHdlList && pHdlList->GetView() && !pHdlList->GetView()->areMarkHandlesHidden())
     269             :     {
     270           0 :         SdrMarkView* pView = pHdlList->GetView();
     271           0 :         SdrPageView* pPageView = pView->GetSdrPageView();
     272             : 
     273           0 :         if (!pPageView)
     274           0 :             return;
     275             : 
     276           0 :         for(sal_uInt32 nWindow = 0; nWindow < pPageView->PageWindowCount(); nWindow++)
     277             :         {
     278           0 :             const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(nWindow);
     279             : 
     280           0 :             if (rPageWindow.GetPaintWindow().OutputToWindow())
     281             :             {
     282           0 :                 rtl::Reference<sdr::overlay::OverlayManager> xManager = rPageWindow.GetOverlayManager();
     283             : 
     284           0 :                 if (xManager.is())
     285             :                 {
     286           0 :                     const basegfx::B2DRange aRange(vcl::unotools::b2DRectangleFromRectangle(maRectangle));
     287           0 :                     const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
     288           0 :                     const Color aHilightColor(aSvtOptionsDrawinglayer.getHilightColor());
     289           0 :                     const double fTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() * 0.01);
     290             :                     // make animation dependent from text edit active, because for tables
     291             :                     // this handle is also used when text edit *is* active for it. This
     292             :                     // interferes too much concerning repaint stuff (at least as long as
     293             :                     // text edit is not yet on the overlay)
     294           0 :                     const bool bAnimate = getAnimate();
     295             : 
     296           0 :                     OutputDevice& rOutDev = rPageWindow.GetPaintWindow().GetOutputDevice();
     297           0 :                     sal_Int32 nScaleFactor = rOutDev.GetDPIScaleFactor();
     298           0 :                     double fWidth = nScaleFactor * 6.0;
     299             : 
     300             :                     sdr::overlay::OverlayObject* pOverlayObject =
     301             :                         new sdr::overlay::OverlayRectangle(aRange.getMinimum(), aRange.getMaximum(),
     302             :                                                            aHilightColor, fTransparence,
     303           0 :                                                            fWidth, 0.0, 0.0, 500, bAnimate);
     304           0 :                     xManager->add(*pOverlayObject);
     305           0 :                     maOverlayGroup.append(*pOverlayObject);
     306           0 :                 }
     307             :             }
     308             :         }
     309             :     }
     310             : }
     311             : 
     312             : 
     313             : } // end of namespace table
     314         435 : } // end of namespace sdr
     315             : 
     316             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11