LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/svdraw - sdrpaintwindow.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 106 108 98.1 %
Date: 2013-07-09 Functions: 19 19 100.0 %
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 <svx/sdrpaintwindow.hxx>
      21             : #include <svx/sdr/overlay/overlaymanagerbuffered.hxx>
      22             : #include <svx/svdpntv.hxx>
      23             : #include <vcl/gdimtf.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : 
      26             : 
      27        4396 : void PaintTransparentChildren(Window & rWindow, Rectangle const& rPixelRect)
      28             : {
      29        4396 :     if (rWindow.IsChildTransparentModeEnabled())
      30             :     {
      31        4396 :         Window * pCandidate = rWindow.GetWindow( WINDOW_FIRSTCHILD );
      32        9297 :         while (pCandidate)
      33             :         {
      34         505 :             if (pCandidate->IsPaintTransparent())
      35             :             {
      36             :                 const Rectangle aCandidatePosSizePixel(
      37          88 :                                 pCandidate->GetPosPixel(),
      38         176 :                                 pCandidate->GetSizePixel());
      39             : 
      40          88 :                 if (aCandidatePosSizePixel.IsOver(rPixelRect))
      41             :                 {
      42             :                     pCandidate->Invalidate(
      43          81 :                         INVALIDATE_NOTRANSPARENT|INVALIDATE_CHILDREN );
      44             :                     // important: actually paint the child here!
      45          81 :                     pCandidate->Update();
      46             :                 }
      47             :             }
      48         505 :             pCandidate = pCandidate->GetWindow( WINDOW_NEXT );
      49             :         }
      50             :     }
      51        4396 : }
      52             : 
      53             : ////////////////////////////////////////////////////////////////////////////////////////////////////
      54             : 
      55         687 : SdrPreRenderDevice::SdrPreRenderDevice(OutputDevice& rOriginal)
      56         687 : :   mrOutputDevice(rOriginal)
      57             : {
      58         687 : }
      59             : 
      60         687 : SdrPreRenderDevice::~SdrPreRenderDevice()
      61             : {
      62         687 : }
      63             : 
      64        7839 : void SdrPreRenderDevice::PreparePreRenderDevice()
      65             : {
      66             :     // compare size of maPreRenderDevice with size of visible area
      67        7839 :     if(maPreRenderDevice.GetOutputSizePixel() != mrOutputDevice.GetOutputSizePixel())
      68             :     {
      69         729 :         maPreRenderDevice.SetOutputSizePixel(mrOutputDevice.GetOutputSizePixel());
      70             :     }
      71             : 
      72             :     // Also compare the MapModes for zoom/scroll changes
      73        7839 :     if(maPreRenderDevice.GetMapMode() != mrOutputDevice.GetMapMode())
      74             :     {
      75        1867 :         maPreRenderDevice.SetMapMode(mrOutputDevice.GetMapMode());
      76             :     }
      77             : 
      78             :     // #i29186#
      79        7839 :     maPreRenderDevice.SetDrawMode(mrOutputDevice.GetDrawMode());
      80        7839 :     maPreRenderDevice.SetSettings(mrOutputDevice.GetSettings());
      81        7839 : }
      82             : 
      83        7839 : void SdrPreRenderDevice::OutputPreRenderDevice(const Region& rExpandedRegion)
      84             : {
      85             :     // region to pixels
      86        7839 :     const Region aRegionPixel(mrOutputDevice.LogicToPixel(rExpandedRegion));
      87             :     //RegionHandle aRegionHandle(aRegionPixel.BeginEnumRects());
      88             :     //Rectangle aRegionRectanglePixel;
      89             : 
      90             :     // MapModes off
      91        7839 :     sal_Bool bMapModeWasEnabledDest(mrOutputDevice.IsMapModeEnabled());
      92        7839 :     sal_Bool bMapModeWasEnabledSource(maPreRenderDevice.IsMapModeEnabled());
      93        7839 :     mrOutputDevice.EnableMapMode(sal_False);
      94        7839 :     maPreRenderDevice.EnableMapMode(sal_False);
      95             : 
      96       15678 :     RectangleVector aRectangles;
      97        7839 :     aRegionPixel.GetRegionRectangles(aRectangles);
      98             : 
      99       16147 :     for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); ++aRectIter)
     100             :     {
     101             :         // for each rectangle, copy the area
     102        8308 :         const Point aTopLeft(aRectIter->TopLeft());
     103        8308 :         const Size aSize(aRectIter->GetSize());
     104             : 
     105             :         mrOutputDevice.DrawOutDev(
     106             :             aTopLeft, aSize,
     107             :             aTopLeft, aSize,
     108        8308 :             maPreRenderDevice);
     109             : 
     110             : #ifdef DBG_UTIL
     111             :         // #i74769#
     112             :         static bool bDoPaintForVisualControlRegion(false);
     113             : 
     114             :         if(bDoPaintForVisualControlRegion)
     115             :         {
     116             :             const Color aColor((((((rand()&0x7f)|0x80)<<8L)|((rand()&0x7f)|0x80))<<8L)|((rand()&0x7f)|0x80));
     117             : 
     118             :             mrOutputDevice.SetLineColor(aColor);
     119             :             mrOutputDevice.SetFillColor();
     120             :             mrOutputDevice.DrawRect(*aRectIter);
     121             :         }
     122             : #endif
     123             :     }
     124             : 
     125             : //  while(aRegionPixel.GetEnumRects(aRegionHandle, aRegionRectanglePixel))
     126             : //  {
     127             : //      // for each rectangle, copy the area
     128             : //      const Point aTopLeft(aRegionRectanglePixel.TopLeft());
     129             : //      const Size aSize(aRegionRectanglePixel.GetSize());
     130             : //
     131             : //      mrOutputDevice.DrawOutDev(
     132             : //          aTopLeft, aSize,
     133             : //          aTopLeft, aSize,
     134             : //          maPreRenderDevice);
     135             : //
     136             : //#ifdef DBG_UTIL
     137             : //      // #i74769#
     138             : //      static bool bDoPaintForVisualControlRegion(false);
     139             : //      if(bDoPaintForVisualControlRegion)
     140             : //      {
     141             : //          Color aColor((((((rand()&0x7f)|0x80)<<8L)|((rand()&0x7f)|0x80))<<8L)|((rand()&0x7f)|0x80));
     142             : //          mrOutputDevice.SetLineColor(aColor);
     143             : //          mrOutputDevice.SetFillColor();
     144             : //          mrOutputDevice.DrawRect(aRegionRectanglePixel);
     145             : //      }
     146             : //#endif
     147             : //  }
     148             : //
     149             : //  aRegionPixel.EndEnumRects(aRegionHandle);
     150             : 
     151        7839 :     mrOutputDevice.EnableMapMode(bMapModeWasEnabledDest);
     152       15678 :     maPreRenderDevice.EnableMapMode(bMapModeWasEnabledSource);
     153        7839 : }
     154             : 
     155             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     156             : 
     157        8244 : void SdrPaintWindow::impCreateOverlayManager()
     158             : {
     159             :     // not yet one created?
     160        8244 :     if(!mxOverlayManager.is())
     161             :     {
     162             :         // is it a window?
     163         885 :         if(OUTDEV_WINDOW == GetOutputDevice().GetOutDevType())
     164             :         {
     165             :             // decide which OverlayManager to use
     166         726 :             if(GetPaintView().IsBufferedOverlayAllowed() && mbUseBuffer)
     167             :             {
     168             :                 // buffered OverlayManager, buffers its background and refreshes from there
     169             :                 // for pure overlay changes (no system redraw). The 3rd parameter specifies
     170             :                 // whether that refresh itself will use a 2nd vdev to avoid flickering.
     171             :                 // Also hand over the old OverlayManager if existent; this means to take over
     172             :                 // the registered OverlayObjects from it
     173         717 :                 mxOverlayManager = ::sdr::overlay::OverlayManagerBuffered::create(GetOutputDevice(), true);
     174             :             }
     175             :             else
     176             :             {
     177             :                 // unbuffered OverlayManager, just invalidates places where changes
     178             :                 // take place
     179             :                 // Also hand over the old OverlayManager if existent; this means to take over
     180             :                 // the registered OverlayObjects from it
     181           9 :                 mxOverlayManager = ::sdr::overlay::OverlayManager::create(GetOutputDevice());
     182             :             }
     183             : 
     184             :             OSL_ENSURE(mxOverlayManager.is(), "SdrPaintWindow::SdrPaintWindow: Could not allocate an overlayManager (!)");
     185             : 
     186             :             // Request a repaint so that the buffered overlay manager fills
     187             :             // its buffer properly.  This is a workaround for missing buffer
     188             :             // updates.
     189         726 :             Window* pWindow = dynamic_cast<Window*>(&GetOutputDevice());
     190         726 :             if (pWindow != NULL)
     191         726 :                 pWindow->Invalidate();
     192             : 
     193         726 :             Color aColA(GetPaintView().getOptionsDrawinglayer().GetStripeColorA());
     194         726 :             Color aColB(GetPaintView().getOptionsDrawinglayer().GetStripeColorB());
     195             : 
     196         726 :             if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
     197             :             {
     198           0 :                 aColA = aColB = Application::GetSettings().GetStyleSettings().GetHighlightColor();
     199           0 :                 aColB.Invert();
     200             :             }
     201             : 
     202         726 :             mxOverlayManager->setStripeColorA(aColA);
     203         726 :             mxOverlayManager->setStripeColorB(aColB);
     204         726 :             mxOverlayManager->setStripeLengthPixel(GetPaintView().getOptionsDrawinglayer().GetStripeLength());
     205             :         }
     206             :     }
     207        8244 : }
     208             : 
     209       23086 : SdrPaintWindow::SdrPaintWindow(SdrPaintView& rNewPaintView, OutputDevice& rOut)
     210             : :   mrOutputDevice(rOut),
     211             :     mrPaintView(rNewPaintView),
     212             :     mpPreRenderDevice(0L),
     213             :     mbTemporaryTarget(false), // #i72889#
     214       23086 :     mbUseBuffer(true)
     215             : {
     216       23086 : }
     217             : 
     218       46166 : SdrPaintWindow::~SdrPaintWindow()
     219             : {
     220       23083 :     mxOverlayManager.clear();
     221             : 
     222       23083 :     DestroyPreRenderDevice();
     223       23083 : }
     224             : 
     225        3945 : rtl::Reference< ::sdr::overlay::OverlayManager > SdrPaintWindow::GetOverlayManager() const
     226             : {
     227        3945 :     if(!mxOverlayManager.is())
     228             :     {
     229             :         // Create buffered overlay manager by default.
     230         213 :         const_cast< SdrPaintWindow* >(this)->impCreateOverlayManager();
     231             :     }
     232             : 
     233        3945 :     return mxOverlayManager;
     234             : }
     235             : 
     236         534 : Rectangle SdrPaintWindow::GetVisibleArea() const
     237             : {
     238         534 :     Size aVisSizePixel(GetOutputDevice().GetOutputSizePixel());
     239         534 :     return Rectangle(GetOutputDevice().PixelToLogic(Rectangle(Point(0,0), aVisSizePixel)));
     240             : }
     241             : 
     242        7839 : bool SdrPaintWindow::OutputToRecordingMetaFile() const
     243             : {
     244        7839 :     GDIMetaFile* pMetaFile = mrOutputDevice.GetConnectMetaFile();
     245        7839 :     return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
     246             : }
     247             : 
     248        8031 : void SdrPaintWindow::PreparePreRenderDevice()
     249             : {
     250             :     const bool bPrepareBufferedOutput(
     251        8031 :         mrPaintView.IsBufferedOutputAllowed()
     252        7995 :         && !OutputToPrinter()
     253        7995 :         && !OutputToVirtualDevice()
     254       15870 :         && !OutputToRecordingMetaFile());
     255             : 
     256        8031 :     if(bPrepareBufferedOutput)
     257             :     {
     258        7839 :         if(!mpPreRenderDevice)
     259             :         {
     260         687 :             mpPreRenderDevice = new SdrPreRenderDevice(mrOutputDevice);
     261             :         }
     262             :     }
     263             :     else
     264             :     {
     265         192 :         DestroyPreRenderDevice();
     266             :     }
     267             : 
     268        8031 :     if(mpPreRenderDevice)
     269             :     {
     270        7839 :         mpPreRenderDevice->PreparePreRenderDevice();
     271             :     }
     272        8031 : }
     273             : 
     274       23275 : void SdrPaintWindow::DestroyPreRenderDevice()
     275             : {
     276       23275 :     if(mpPreRenderDevice)
     277             :     {
     278         687 :         delete mpPreRenderDevice;
     279         687 :         mpPreRenderDevice = 0L;
     280             :     }
     281       23275 : }
     282             : 
     283        8031 : void SdrPaintWindow::OutputPreRenderDevice(const Region& rExpandedRegion)
     284             : {
     285        8031 :     if(mpPreRenderDevice)
     286             :     {
     287        7839 :         mpPreRenderDevice->OutputPreRenderDevice(rExpandedRegion);
     288             :     }
     289        8031 : }
     290             : 
     291             : // #i73602# add flag if buffer shall be used
     292        8031 : void SdrPaintWindow::DrawOverlay(const Region& rRegion)
     293             : {
     294             :     // ## force creation of OverlayManager since the first repaint needs to
     295             :     // save the background to get a controlled start into overlay mechanism
     296        8031 :     impCreateOverlayManager();
     297             : 
     298        8031 :     if(mxOverlayManager.is() && !OutputToPrinter())
     299             :     {
     300        7872 :         if(mpPreRenderDevice)
     301             :         {
     302        7839 :             mxOverlayManager->completeRedraw(rRegion, &mpPreRenderDevice->GetPreRenderDevice());
     303             :         }
     304             :         else
     305             :         {
     306          33 :             mxOverlayManager->completeRedraw(rRegion);
     307             :         }
     308             :     }
     309        8031 : }
     310             : 
     311       60987 : const Region& SdrPaintWindow::GetRedrawRegion() const
     312             : {
     313       60987 :     return maRedrawRegion;
     314             : }
     315             : 
     316       45396 : void SdrPaintWindow::SetRedrawRegion(const Region& rNew)
     317             : {
     318       45396 :     maRedrawRegion = rNew;
     319       45654 : }
     320             : 
     321             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10