LCOV - code coverage report
Current view: top level - svx/source/svdraw - sdrpaintwindow.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 100 105 95.2 %
Date: 2012-08-25 Functions: 16 16 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 83 142 58.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <svx/sdrpaintwindow.hxx>
      30                 :            : #include <svx/sdr/overlay/overlaymanagerbuffered.hxx>
      31                 :            : #include <svx/svdpntv.hxx>
      32                 :            : #include <vcl/gdimtf.hxx>
      33                 :            : #include <vcl/svapp.hxx>
      34                 :            : 
      35                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
      36                 :            : 
      37                 :       1221 : SdrPreRenderDevice::SdrPreRenderDevice(OutputDevice& rOriginal)
      38                 :       1221 : :   mrOutputDevice(rOriginal)
      39                 :            : {
      40                 :       1221 : }
      41                 :            : 
      42                 :       1134 : SdrPreRenderDevice::~SdrPreRenderDevice()
      43                 :            : {
      44                 :       1134 : }
      45                 :            : 
      46                 :      15571 : void SdrPreRenderDevice::PreparePreRenderDevice()
      47                 :            : {
      48                 :            :     // compare size of maPreRenderDevice with size of visible area
      49         [ +  + ]:      15571 :     if(maPreRenderDevice.GetOutputSizePixel() != mrOutputDevice.GetOutputSizePixel())
      50                 :            :     {
      51         [ +  - ]:       1271 :         maPreRenderDevice.SetOutputSizePixel(mrOutputDevice.GetOutputSizePixel());
      52                 :            :     }
      53                 :            : 
      54                 :            :     // Also compare the MapModes for zoom/scroll changes
      55         [ +  + ]:      15571 :     if(maPreRenderDevice.GetMapMode() != mrOutputDevice.GetMapMode())
      56                 :            :     {
      57                 :       2742 :         maPreRenderDevice.SetMapMode(mrOutputDevice.GetMapMode());
      58                 :            :     }
      59                 :            : 
      60                 :            :     // #i29186#
      61                 :      15571 :     maPreRenderDevice.SetDrawMode(mrOutputDevice.GetDrawMode());
      62                 :      15571 :     maPreRenderDevice.SetSettings(mrOutputDevice.GetSettings());
      63                 :      15571 : }
      64                 :            : 
      65                 :      15571 : void SdrPreRenderDevice::OutputPreRenderDevice(const Region& rExpandedRegion)
      66                 :            : {
      67                 :            :     // region to pixels
      68         [ +  - ]:      15571 :     Region aRegionPixel(mrOutputDevice.LogicToPixel(rExpandedRegion));
      69         [ +  - ]:      15571 :     RegionHandle aRegionHandle(aRegionPixel.BeginEnumRects());
      70         [ +  - ]:      15571 :     Rectangle aRegionRectanglePixel;
      71                 :            : 
      72                 :            :     // MapModes off
      73                 :      15571 :     sal_Bool bMapModeWasEnabledDest(mrOutputDevice.IsMapModeEnabled());
      74                 :      15571 :     sal_Bool bMapModeWasEnabledSource(maPreRenderDevice.IsMapModeEnabled());
      75         [ +  - ]:      15571 :     mrOutputDevice.EnableMapMode(sal_False);
      76         [ +  - ]:      15571 :     maPreRenderDevice.EnableMapMode(sal_False);
      77                 :            : 
      78 [ +  - ][ +  + ]:      31657 :     while(aRegionPixel.GetEnumRects(aRegionHandle, aRegionRectanglePixel))
      79                 :            :     {
      80                 :            :         // for each rectangle, copy the area
      81                 :      16086 :         const Point aTopLeft(aRegionRectanglePixel.TopLeft());
      82         [ +  - ]:      16086 :         const Size aSize(aRegionRectanglePixel.GetSize());
      83                 :            : 
      84                 :            :         mrOutputDevice.DrawOutDev(
      85                 :            :             aTopLeft, aSize,
      86                 :            :             aTopLeft, aSize,
      87         [ +  - ]:      16086 :             maPreRenderDevice);
      88                 :            : 
      89                 :            : #ifdef DBG_UTIL
      90                 :            :         // #i74769#
      91                 :            :         static bool bDoPaintForVisualControlRegion(false);
      92                 :            :         if(bDoPaintForVisualControlRegion)
      93                 :            :         {
      94                 :            :             Color aColor((((((rand()&0x7f)|0x80)<<8L)|((rand()&0x7f)|0x80))<<8L)|((rand()&0x7f)|0x80));
      95                 :            :             mrOutputDevice.SetLineColor(aColor);
      96                 :            :             mrOutputDevice.SetFillColor();
      97                 :            :             mrOutputDevice.DrawRect(aRegionRectanglePixel);
      98                 :            :         }
      99                 :            : #endif
     100                 :            :     }
     101                 :            : 
     102         [ +  - ]:      15571 :     aRegionPixel.EndEnumRects(aRegionHandle);
     103                 :            : 
     104         [ +  - ]:      15571 :     mrOutputDevice.EnableMapMode(bMapModeWasEnabledDest);
     105 [ +  - ][ +  - ]:      15571 :     maPreRenderDevice.EnableMapMode(bMapModeWasEnabledSource);
     106                 :      15571 : }
     107                 :            : 
     108                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
     109                 :            : 
     110                 :      16306 : void SdrPaintWindow::impCreateOverlayManager(const bool bUseBuffer)
     111                 :            : {
     112                 :            :     // When the buffer usage has changed then we have to create a new
     113                 :            :     // overlay manager.  Save the current one so that later we can move its
     114                 :            :     // overlay objects to the new one.
     115                 :      16306 :     rtl::Reference<sdr::overlay::OverlayManager> xOldOverlayManager;
     116                 :            : 
     117         [ -  + ]:      16306 :     if(mbUseBuffer != bUseBuffer)
     118                 :            :     {
     119                 :          0 :         mbUseBuffer = bUseBuffer;
     120         [ #  # ]:          0 :         xOldOverlayManager = mxOverlayManager;
     121         [ #  # ]:          0 :         mxOverlayManager.clear();
     122                 :            :     }
     123                 :            : 
     124                 :            :     // not yet one created?
     125         [ +  + ]:      16306 :     if(!mxOverlayManager.is())
     126                 :            :     {
     127                 :            :         // is it a window?
     128         [ +  + ]:       1669 :         if(OUTDEV_WINDOW == GetOutputDevice().GetOutDevType())
     129                 :            :         {
     130                 :            :             // decide which OverlayManager to use
     131 [ +  - ][ +  + ]:       1278 :             if(GetPaintView().IsBufferedOverlayAllowed() && mbUseBuffer)
         [ +  - ][ +  + ]
     132                 :            :             {
     133                 :            :                 // buffered OverlayManager, buffers its background and refreshes from there
     134                 :            :                 // for pure overlay changes (no system redraw). The 3rd parameter specifies
     135                 :            :                 // whether that refresh itself will use a 2nd vdev to avoid flickering.
     136                 :            :                 // Also hand over the old OverlayManager if existent; this means to take over
     137                 :            :                 // the registered OverlayObjects from it
     138                 :       1260 :                 mxOverlayManager = ::sdr::overlay::OverlayManagerBuffered::create(GetOutputDevice(),
     139 [ +  - ][ +  - ]:       2520 :                     xOldOverlayManager.get(), true);
                 [ +  - ]
     140                 :            :             }
     141                 :            :             else
     142                 :            :             {
     143                 :            :                 // unbuffered OverlayManager, just invalidates places where changes
     144                 :            :                 // take place
     145                 :            :                 // Also hand over the old OverlayManager if existent; this means to take over
     146                 :            :                 // the registered OverlayObjects from it
     147                 :         18 :                 mxOverlayManager = ::sdr::overlay::OverlayManager::create(GetOutputDevice(),
     148 [ +  - ][ +  - ]:         36 :                     xOldOverlayManager.get());
                 [ +  - ]
     149                 :            :             }
     150                 :            : 
     151                 :            :             OSL_ENSURE(mxOverlayManager.is(), "SdrPaintWindow::SdrPaintWindow: Could not allocate an overlayManager (!)");
     152                 :            : 
     153                 :            :             // Request a repaint so that the buffered overlay manager fills
     154                 :            :             // its buffer properly.  This is a workaround for missing buffer
     155                 :            :             // updates.
     156         [ -  + ]:       1278 :             Window* pWindow = dynamic_cast<Window*>(&GetOutputDevice());
     157         [ +  - ]:       1278 :             if (pWindow != NULL)
     158         [ +  - ]:       1278 :                 pWindow->Invalidate();
     159                 :            : 
     160         [ +  - ]:       1278 :             Color aColA(GetPaintView().getOptionsDrawinglayer().GetStripeColorA());
     161         [ +  - ]:       1278 :             Color aColB(GetPaintView().getOptionsDrawinglayer().GetStripeColorB());
     162                 :            : 
     163 [ +  - ][ -  + ]:       1278 :             if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
     164                 :            :             {
     165         [ #  # ]:          0 :                 aColA = aColB = Application::GetSettings().GetStyleSettings().GetHighlightColor();
     166         [ #  # ]:          0 :                 aColB.Invert();
     167                 :            :             }
     168                 :            : 
     169         [ +  - ]:       1278 :             mxOverlayManager->setStripeColorA(aColA);
     170         [ +  - ]:       1278 :             mxOverlayManager->setStripeColorB(aColB);
     171 [ +  - ][ +  - ]:       1278 :             mxOverlayManager->setStripeLengthPixel(GetPaintView().getOptionsDrawinglayer().GetStripeLength());
     172                 :            :         }
     173         [ +  - ]:      16306 :     }
     174                 :      16306 : }
     175                 :            : 
     176                 :      44943 : SdrPaintWindow::SdrPaintWindow(SdrPaintView& rNewPaintView, OutputDevice& rOut)
     177                 :            : :   mrOutputDevice(rOut),
     178                 :            :     mrPaintView(rNewPaintView),
     179                 :            :     mpPreRenderDevice(0L),
     180                 :            :     mbTemporaryTarget(false), // #i72889#
     181         [ +  - ]:      44943 :     mbUseBuffer(true)
     182                 :            : {
     183                 :      44943 : }
     184                 :            : 
     185         [ +  - ]:      44852 : SdrPaintWindow::~SdrPaintWindow()
     186                 :            : {
     187         [ +  - ]:      44852 :     mxOverlayManager.clear();
     188                 :            : 
     189         [ +  - ]:      44852 :     DestroyPreRenderDevice();
     190                 :      44852 : }
     191                 :            : 
     192                 :       8944 : rtl::Reference< ::sdr::overlay::OverlayManager > SdrPaintWindow::GetOverlayManager() const
     193                 :            : {
     194         [ +  + ]:       8944 :     if(!mxOverlayManager.is())
     195                 :            :     {
     196                 :            :         // Create buffered overlay manager by default.
     197                 :        281 :         const_cast< SdrPaintWindow* >(this)->impCreateOverlayManager(true);
     198                 :            :     }
     199                 :            : 
     200                 :       8944 :     return mxOverlayManager;
     201                 :            : }
     202                 :            : 
     203                 :       1068 : Rectangle SdrPaintWindow::GetVisibleArea() const
     204                 :            : {
     205                 :       1068 :     Size aVisSizePixel(GetOutputDevice().GetOutputSizePixel());
     206 [ +  - ][ +  - ]:       1068 :     return Rectangle(GetOutputDevice().PixelToLogic(Rectangle(Point(0,0), aVisSizePixel)));
     207                 :            : }
     208                 :            : 
     209                 :      15571 : sal_Bool SdrPaintWindow::OutputToRecordingMetaFile() const
     210                 :            : {
     211                 :      15571 :     GDIMetaFile* pMetaFile = mrOutputDevice.GetConnectMetaFile();
     212 [ #  # ][ #  # ]:      15571 :     return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
                 [ -  + ]
     213                 :            : }
     214                 :            : 
     215                 :      16025 : void SdrPaintWindow::PreparePreRenderDevice()
     216                 :            : {
     217                 :            :     const sal_Bool bPrepareBufferedOutput(
     218                 :      16025 :         mrPaintView.IsBufferedOutputAllowed()
     219                 :      15868 :         && !OutputToPrinter()
     220                 :      15868 :         && !OutputToVirtualDevice()
     221 [ +  - ][ +  +  :      47761 :         && !OutputToRecordingMetaFile());
             +  -  +  + ]
     222                 :            : 
     223         [ +  + ]:      16025 :     if(bPrepareBufferedOutput)
     224                 :            :     {
     225         [ +  + ]:      15571 :         if(!mpPreRenderDevice)
     226                 :            :         {
     227         [ +  - ]:       1221 :             mpPreRenderDevice = new SdrPreRenderDevice(mrOutputDevice);
     228                 :            :         }
     229                 :            :     }
     230                 :            :     else
     231                 :            :     {
     232                 :        454 :         DestroyPreRenderDevice();
     233                 :            :     }
     234                 :            : 
     235         [ +  + ]:      16025 :     if(mpPreRenderDevice)
     236                 :            :     {
     237                 :      15571 :         mpPreRenderDevice->PreparePreRenderDevice();
     238                 :            :     }
     239                 :      16025 : }
     240                 :            : 
     241                 :      45306 : void SdrPaintWindow::DestroyPreRenderDevice()
     242                 :            : {
     243         [ +  + ]:      45306 :     if(mpPreRenderDevice)
     244                 :            :     {
     245         [ +  - ]:       1134 :         delete mpPreRenderDevice;
     246                 :       1134 :         mpPreRenderDevice = 0L;
     247                 :            :     }
     248                 :      45306 : }
     249                 :            : 
     250                 :      16025 : void SdrPaintWindow::OutputPreRenderDevice(const Region& rExpandedRegion)
     251                 :            : {
     252         [ +  + ]:      16025 :     if(mpPreRenderDevice)
     253                 :            :     {
     254                 :      15571 :         mpPreRenderDevice->OutputPreRenderDevice(rExpandedRegion);
     255                 :            :     }
     256                 :      16025 : }
     257                 :            : 
     258                 :            : // #i73602# add flag if buffer shall be used
     259                 :      16025 : void SdrPaintWindow::DrawOverlay(const Region& rRegion, bool bUseBuffer)
     260                 :            : {
     261                 :            :     // ## force creation of OverlayManager since the first repaint needs to
     262                 :            :     // save the background to get a controlled start into overlay mechanism
     263                 :      16025 :     impCreateOverlayManager(bUseBuffer);
     264                 :            : 
     265 [ +  - ][ +  + ]:      16025 :     if(mxOverlayManager.is() && !OutputToPrinter())
                 [ +  + ]
     266                 :            :     {
     267 [ +  + ][ +  - ]:      15634 :         if(mpPreRenderDevice && bUseBuffer)
     268                 :            :         {
     269                 :      15571 :             mxOverlayManager->completeRedraw(rRegion, &mpPreRenderDevice->GetPreRenderDevice());
     270                 :            :         }
     271                 :            :         else
     272                 :            :         {
     273                 :      15634 :             mxOverlayManager->completeRedraw(rRegion);
     274                 :            :         }
     275                 :            :     }
     276                 :      16025 : }
     277                 :            : 
     278                 :     120603 : const Region& SdrPaintWindow::GetRedrawRegion() const
     279                 :            : {
     280                 :     120603 :     return maRedrawRegion;
     281                 :            : }
     282                 :            : 
     283                 :      91822 : void SdrPaintWindow::SetRedrawRegion(const Region& rNew)
     284                 :            : {
     285                 :      91822 :     maRedrawRegion = rNew;
     286                 :      91822 : }
     287                 :            : 
     288                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10