LCOV - code coverage report
Current view: top level - libreoffice/svx/source/svdraw - sdrpaintwindow.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 94 105 89.5 %
Date: 2012-12-27 Functions: 15 16 93.8 %
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             : 
      28         130 : SdrPreRenderDevice::SdrPreRenderDevice(OutputDevice& rOriginal)
      29         130 : :   mrOutputDevice(rOriginal)
      30             : {
      31         130 : }
      32             : 
      33           5 : SdrPreRenderDevice::~SdrPreRenderDevice()
      34             : {
      35           5 : }
      36             : 
      37         262 : void SdrPreRenderDevice::PreparePreRenderDevice()
      38             : {
      39             :     // compare size of maPreRenderDevice with size of visible area
      40         262 :     if(maPreRenderDevice.GetOutputSizePixel() != mrOutputDevice.GetOutputSizePixel())
      41             :     {
      42         131 :         maPreRenderDevice.SetOutputSizePixel(mrOutputDevice.GetOutputSizePixel());
      43             :     }
      44             : 
      45             :     // Also compare the MapModes for zoom/scroll changes
      46         262 :     if(maPreRenderDevice.GetMapMode() != mrOutputDevice.GetMapMode())
      47             :     {
      48         137 :         maPreRenderDevice.SetMapMode(mrOutputDevice.GetMapMode());
      49             :     }
      50             : 
      51             :     // #i29186#
      52         262 :     maPreRenderDevice.SetDrawMode(mrOutputDevice.GetDrawMode());
      53         262 :     maPreRenderDevice.SetSettings(mrOutputDevice.GetSettings());
      54         262 : }
      55             : 
      56         262 : void SdrPreRenderDevice::OutputPreRenderDevice(const Region& rExpandedRegion)
      57             : {
      58             :     // region to pixels
      59         262 :     Region aRegionPixel(mrOutputDevice.LogicToPixel(rExpandedRegion));
      60         262 :     RegionHandle aRegionHandle(aRegionPixel.BeginEnumRects());
      61         262 :     Rectangle aRegionRectanglePixel;
      62             : 
      63             :     // MapModes off
      64         262 :     sal_Bool bMapModeWasEnabledDest(mrOutputDevice.IsMapModeEnabled());
      65         262 :     sal_Bool bMapModeWasEnabledSource(maPreRenderDevice.IsMapModeEnabled());
      66         262 :     mrOutputDevice.EnableMapMode(sal_False);
      67         262 :     maPreRenderDevice.EnableMapMode(sal_False);
      68             : 
      69         786 :     while(aRegionPixel.GetEnumRects(aRegionHandle, aRegionRectanglePixel))
      70             :     {
      71             :         // for each rectangle, copy the area
      72         262 :         const Point aTopLeft(aRegionRectanglePixel.TopLeft());
      73         262 :         const Size aSize(aRegionRectanglePixel.GetSize());
      74             : 
      75             :         mrOutputDevice.DrawOutDev(
      76             :             aTopLeft, aSize,
      77             :             aTopLeft, aSize,
      78         262 :             maPreRenderDevice);
      79             : 
      80             : #ifdef DBG_UTIL
      81             :         // #i74769#
      82             :         static bool bDoPaintForVisualControlRegion(false);
      83             :         if(bDoPaintForVisualControlRegion)
      84             :         {
      85             :             Color aColor((((((rand()&0x7f)|0x80)<<8L)|((rand()&0x7f)|0x80))<<8L)|((rand()&0x7f)|0x80));
      86             :             mrOutputDevice.SetLineColor(aColor);
      87             :             mrOutputDevice.SetFillColor();
      88             :             mrOutputDevice.DrawRect(aRegionRectanglePixel);
      89             :         }
      90             : #endif
      91             :     }
      92             : 
      93         262 :     aRegionPixel.EndEnumRects(aRegionHandle);
      94             : 
      95         262 :     mrOutputDevice.EnableMapMode(bMapModeWasEnabledDest);
      96         262 :     maPreRenderDevice.EnableMapMode(bMapModeWasEnabledSource);
      97         262 : }
      98             : 
      99             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     100             : 
     101         271 : void SdrPaintWindow::impCreateOverlayManager(const bool bUseBuffer)
     102             : {
     103             :     // When the buffer usage has changed then we have to create a new
     104             :     // overlay manager.  Save the current one so that later we can move its
     105             :     // overlay objects to the new one.
     106         271 :     rtl::Reference<sdr::overlay::OverlayManager> xOldOverlayManager;
     107             : 
     108         271 :     if(mbUseBuffer != bUseBuffer)
     109             :     {
     110           0 :         mbUseBuffer = bUseBuffer;
     111           0 :         xOldOverlayManager = mxOverlayManager;
     112           0 :         mxOverlayManager.clear();
     113             :     }
     114             : 
     115             :     // not yet one created?
     116         271 :     if(!mxOverlayManager.is())
     117             :     {
     118             :         // is it a window?
     119         136 :         if(OUTDEV_WINDOW == GetOutputDevice().GetOutDevType())
     120             :         {
     121             :             // decide which OverlayManager to use
     122         133 :             if(GetPaintView().IsBufferedOverlayAllowed() && mbUseBuffer)
     123             :             {
     124             :                 // buffered OverlayManager, buffers its background and refreshes from there
     125             :                 // for pure overlay changes (no system redraw). The 3rd parameter specifies
     126             :                 // whether that refresh itself will use a 2nd vdev to avoid flickering.
     127             :                 // Also hand over the old OverlayManager if existent; this means to take over
     128             :                 // the registered OverlayObjects from it
     129         133 :                 mxOverlayManager = ::sdr::overlay::OverlayManagerBuffered::create(GetOutputDevice(),
     130         266 :                     xOldOverlayManager.get(), true);
     131             :             }
     132             :             else
     133             :             {
     134             :                 // unbuffered OverlayManager, just invalidates places where changes
     135             :                 // take place
     136             :                 // Also hand over the old OverlayManager if existent; this means to take over
     137             :                 // the registered OverlayObjects from it
     138           0 :                 mxOverlayManager = ::sdr::overlay::OverlayManager::create(GetOutputDevice(),
     139           0 :                     xOldOverlayManager.get());
     140             :             }
     141             : 
     142             :             OSL_ENSURE(mxOverlayManager.is(), "SdrPaintWindow::SdrPaintWindow: Could not allocate an overlayManager (!)");
     143             : 
     144             :             // Request a repaint so that the buffered overlay manager fills
     145             :             // its buffer properly.  This is a workaround for missing buffer
     146             :             // updates.
     147         133 :             Window* pWindow = dynamic_cast<Window*>(&GetOutputDevice());
     148         133 :             if (pWindow != NULL)
     149         133 :                 pWindow->Invalidate();
     150             : 
     151         133 :             Color aColA(GetPaintView().getOptionsDrawinglayer().GetStripeColorA());
     152         133 :             Color aColB(GetPaintView().getOptionsDrawinglayer().GetStripeColorB());
     153             : 
     154         133 :             if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
     155             :             {
     156           0 :                 aColA = aColB = Application::GetSettings().GetStyleSettings().GetHighlightColor();
     157           0 :                 aColB.Invert();
     158             :             }
     159             : 
     160         133 :             mxOverlayManager->setStripeColorA(aColA);
     161         133 :             mxOverlayManager->setStripeColorB(aColB);
     162         133 :             mxOverlayManager->setStripeLengthPixel(GetPaintView().getOptionsDrawinglayer().GetStripeLength());
     163             :         }
     164         271 :     }
     165         271 : }
     166             : 
     167        1058 : SdrPaintWindow::SdrPaintWindow(SdrPaintView& rNewPaintView, OutputDevice& rOut)
     168             : :   mrOutputDevice(rOut),
     169             :     mrPaintView(rNewPaintView),
     170             :     mpPreRenderDevice(0L),
     171             :     mbTemporaryTarget(false), // #i72889#
     172        1058 :     mbUseBuffer(true)
     173             : {
     174        1058 : }
     175             : 
     176        1770 : SdrPaintWindow::~SdrPaintWindow()
     177             : {
     178         885 :     mxOverlayManager.clear();
     179             : 
     180         885 :     DestroyPreRenderDevice();
     181         885 : }
     182             : 
     183          12 : rtl::Reference< ::sdr::overlay::OverlayManager > SdrPaintWindow::GetOverlayManager() const
     184             : {
     185          12 :     if(!mxOverlayManager.is())
     186             :     {
     187             :         // Create buffered overlay manager by default.
     188           6 :         const_cast< SdrPaintWindow* >(this)->impCreateOverlayManager(true);
     189             :     }
     190             : 
     191          12 :     return mxOverlayManager;
     192             : }
     193             : 
     194           0 : Rectangle SdrPaintWindow::GetVisibleArea() const
     195             : {
     196           0 :     Size aVisSizePixel(GetOutputDevice().GetOutputSizePixel());
     197           0 :     return Rectangle(GetOutputDevice().PixelToLogic(Rectangle(Point(0,0), aVisSizePixel)));
     198             : }
     199             : 
     200         262 : sal_Bool SdrPaintWindow::OutputToRecordingMetaFile() const
     201             : {
     202         262 :     GDIMetaFile* pMetaFile = mrOutputDevice.GetConnectMetaFile();
     203         262 :     return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
     204             : }
     205             : 
     206         265 : void SdrPaintWindow::PreparePreRenderDevice()
     207             : {
     208             :     const sal_Bool bPrepareBufferedOutput(
     209         265 :         mrPaintView.IsBufferedOutputAllowed()
     210         264 :         && !OutputToPrinter()
     211         264 :         && !OutputToVirtualDevice()
     212         793 :         && !OutputToRecordingMetaFile());
     213             : 
     214         265 :     if(bPrepareBufferedOutput)
     215             :     {
     216         262 :         if(!mpPreRenderDevice)
     217             :         {
     218         130 :             mpPreRenderDevice = new SdrPreRenderDevice(mrOutputDevice);
     219             :         }
     220             :     }
     221             :     else
     222             :     {
     223           3 :         DestroyPreRenderDevice();
     224             :     }
     225             : 
     226         265 :     if(mpPreRenderDevice)
     227             :     {
     228         262 :         mpPreRenderDevice->PreparePreRenderDevice();
     229             :     }
     230         265 : }
     231             : 
     232         888 : void SdrPaintWindow::DestroyPreRenderDevice()
     233             : {
     234         888 :     if(mpPreRenderDevice)
     235             :     {
     236           5 :         delete mpPreRenderDevice;
     237           5 :         mpPreRenderDevice = 0L;
     238             :     }
     239         888 : }
     240             : 
     241         265 : void SdrPaintWindow::OutputPreRenderDevice(const Region& rExpandedRegion)
     242             : {
     243         265 :     if(mpPreRenderDevice)
     244             :     {
     245         262 :         mpPreRenderDevice->OutputPreRenderDevice(rExpandedRegion);
     246             :     }
     247         265 : }
     248             : 
     249             : // #i73602# add flag if buffer shall be used
     250         265 : void SdrPaintWindow::DrawOverlay(const Region& rRegion, bool bUseBuffer)
     251             : {
     252             :     // ## force creation of OverlayManager since the first repaint needs to
     253             :     // save the background to get a controlled start into overlay mechanism
     254         265 :     impCreateOverlayManager(bUseBuffer);
     255             : 
     256         265 :     if(mxOverlayManager.is() && !OutputToPrinter())
     257             :     {
     258         262 :         if(mpPreRenderDevice && bUseBuffer)
     259             :         {
     260         262 :             mxOverlayManager->completeRedraw(rRegion, &mpPreRenderDevice->GetPreRenderDevice());
     261             :         }
     262             :         else
     263             :         {
     264           0 :             mxOverlayManager->completeRedraw(rRegion);
     265             :         }
     266             :     }
     267         265 : }
     268             : 
     269        2152 : const Region& SdrPaintWindow::GetRedrawRegion() const
     270             : {
     271        2152 :     return maRedrawRegion;
     272             : }
     273             : 
     274        2649 : void SdrPaintWindow::SetRedrawRegion(const Region& rNew)
     275             : {
     276        2649 :     maRedrawRegion = rNew;
     277        2649 : }
     278             : 
     279             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10