1f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5f6e50924SAndrew Rist * distributed with this work for additional information 6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14f6e50924SAndrew Rist * software distributed under the License is distributed on an 15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17f6e50924SAndrew Rist * specific language governing permissions and limitations 18f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20f6e50924SAndrew Rist *************************************************************/ 21f6e50924SAndrew Rist 22f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir #include <svx/sdrpaintwindow.hxx> 27cdf0e10cSrcweir #include <svx/sdr/overlay/overlaymanagerbuffered.hxx> 28cdf0e10cSrcweir #include <svx/svdpntv.hxx> 29cdf0e10cSrcweir #include <vcl/gdimtf.hxx> 30cdf0e10cSrcweir #include <vcl/svapp.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////////////// 33cdf0e10cSrcweir 34cdf0e10cSrcweir SdrPreRenderDevice::SdrPreRenderDevice(OutputDevice& rOriginal) 35cdf0e10cSrcweir : mrOutputDevice(rOriginal) 36cdf0e10cSrcweir { 37cdf0e10cSrcweir } 38cdf0e10cSrcweir 39cdf0e10cSrcweir SdrPreRenderDevice::~SdrPreRenderDevice() 40cdf0e10cSrcweir { 41cdf0e10cSrcweir } 42cdf0e10cSrcweir 43cdf0e10cSrcweir void SdrPreRenderDevice::PreparePreRenderDevice() 44cdf0e10cSrcweir { 45cdf0e10cSrcweir // compare size of maPreRenderDevice with size of visible area 46cdf0e10cSrcweir if(maPreRenderDevice.GetOutputSizePixel() != mrOutputDevice.GetOutputSizePixel()) 47cdf0e10cSrcweir { 48cdf0e10cSrcweir maPreRenderDevice.SetOutputSizePixel(mrOutputDevice.GetOutputSizePixel()); 49cdf0e10cSrcweir } 50cdf0e10cSrcweir 51cdf0e10cSrcweir // Also compare the MapModes for zoom/scroll changes 52cdf0e10cSrcweir if(maPreRenderDevice.GetMapMode() != mrOutputDevice.GetMapMode()) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir maPreRenderDevice.SetMapMode(mrOutputDevice.GetMapMode()); 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir // #i29186# 58cdf0e10cSrcweir maPreRenderDevice.SetDrawMode(mrOutputDevice.GetDrawMode()); 59cdf0e10cSrcweir maPreRenderDevice.SetSettings(mrOutputDevice.GetSettings()); 60cdf0e10cSrcweir } 61cdf0e10cSrcweir 62cdf0e10cSrcweir void SdrPreRenderDevice::OutputPreRenderDevice(const Region& rExpandedRegion) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir // region to pixels 65cdf0e10cSrcweir Region aRegionPixel(mrOutputDevice.LogicToPixel(rExpandedRegion)); 66cdf0e10cSrcweir RegionHandle aRegionHandle(aRegionPixel.BeginEnumRects()); 67cdf0e10cSrcweir Rectangle aRegionRectanglePixel; 68cdf0e10cSrcweir 69cdf0e10cSrcweir // MapModes off 70cdf0e10cSrcweir sal_Bool bMapModeWasEnabledDest(mrOutputDevice.IsMapModeEnabled()); 71cdf0e10cSrcweir sal_Bool bMapModeWasEnabledSource(maPreRenderDevice.IsMapModeEnabled()); 72cdf0e10cSrcweir mrOutputDevice.EnableMapMode(sal_False); 73cdf0e10cSrcweir maPreRenderDevice.EnableMapMode(sal_False); 74cdf0e10cSrcweir 75cdf0e10cSrcweir while(aRegionPixel.GetEnumRects(aRegionHandle, aRegionRectanglePixel)) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir // for each rectangle, copy the area 78cdf0e10cSrcweir const Point aTopLeft(aRegionRectanglePixel.TopLeft()); 79cdf0e10cSrcweir const Size aSize(aRegionRectanglePixel.GetSize()); 80cdf0e10cSrcweir 81cdf0e10cSrcweir mrOutputDevice.DrawOutDev( 82cdf0e10cSrcweir aTopLeft, aSize, 83cdf0e10cSrcweir aTopLeft, aSize, 84cdf0e10cSrcweir maPreRenderDevice); 85cdf0e10cSrcweir 86cdf0e10cSrcweir #ifdef DBG_UTIL 87cdf0e10cSrcweir // #i74769# 88cdf0e10cSrcweir static bool bDoPaintForVisualControlRegion(false); 89cdf0e10cSrcweir if(bDoPaintForVisualControlRegion) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir Color aColor((((((rand()&0x7f)|0x80)<<8L)|((rand()&0x7f)|0x80))<<8L)|((rand()&0x7f)|0x80)); 92cdf0e10cSrcweir mrOutputDevice.SetLineColor(aColor); 93cdf0e10cSrcweir mrOutputDevice.SetFillColor(); 94cdf0e10cSrcweir mrOutputDevice.DrawRect(aRegionRectanglePixel); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir #endif 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir aRegionPixel.EndEnumRects(aRegionHandle); 100cdf0e10cSrcweir 101cdf0e10cSrcweir mrOutputDevice.EnableMapMode(bMapModeWasEnabledDest); 102cdf0e10cSrcweir maPreRenderDevice.EnableMapMode(bMapModeWasEnabledSource); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////////////// 106cdf0e10cSrcweir 107*a56bd57bSArmin Le Grand void SdrPaintWindow::impCreateOverlayManager() 108cdf0e10cSrcweir { 109cdf0e10cSrcweir // not yet one created? 110cdf0e10cSrcweir if(!mpOverlayManager) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir // is it a window? 113cdf0e10cSrcweir if(OUTDEV_WINDOW == GetOutputDevice().GetOutDevType()) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir // decide which OverlayManager to use 116cdf0e10cSrcweir if(GetPaintView().IsBufferedOverlayAllowed() && mbUseBuffer) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir // buffered OverlayManager, buffers it's background and refreshes from there 119cdf0e10cSrcweir // for pure overlay changes (no system redraw). The 3rd parameter specifies 120cdf0e10cSrcweir // if that refresh itself will use a 2nd vdev to avoid flickering. 121cdf0e10cSrcweir // Also hand over the evtl. existing old OverlayManager; this means to take over 122cdf0e10cSrcweir // the registered OverlayObjects from it 123*a56bd57bSArmin Le Grand mpOverlayManager = new ::sdr::overlay::OverlayManagerBuffered(GetOutputDevice(), true); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir else 126cdf0e10cSrcweir { 127cdf0e10cSrcweir // unbuffered OverlayManager, just invalidates places where changes 128cdf0e10cSrcweir // take place 129cdf0e10cSrcweir // Also hand over the evtl. existing old OverlayManager; this means to take over 130cdf0e10cSrcweir // the registered OverlayObjects from it 131*a56bd57bSArmin Le Grand mpOverlayManager = new ::sdr::overlay::OverlayManager(GetOutputDevice()); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir OSL_ENSURE(mpOverlayManager, "SdrPaintWindow::SdrPaintWindow: Could not allocate an overlayManager (!)"); 135cdf0e10cSrcweir 136cdf0e10cSrcweir // Request a repaint so that the buffered overlay manager fills 137cdf0e10cSrcweir // its buffer properly. This is a workaround for missing buffer 138cdf0e10cSrcweir // updates. 139cdf0e10cSrcweir Window* pWindow = dynamic_cast<Window*>(&GetOutputDevice()); 140cdf0e10cSrcweir if (pWindow != NULL) 141cdf0e10cSrcweir pWindow->Invalidate(); 142cdf0e10cSrcweir 143cdf0e10cSrcweir Color aColA(GetPaintView().getOptionsDrawinglayer().GetStripeColorA()); 144cdf0e10cSrcweir Color aColB(GetPaintView().getOptionsDrawinglayer().GetStripeColorB()); 145cdf0e10cSrcweir 146cdf0e10cSrcweir if(Application::GetSettings().GetStyleSettings().GetHighContrastMode()) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir aColA = aColB = Application::GetSettings().GetStyleSettings().GetHighlightColor(); 149cdf0e10cSrcweir aColB.Invert(); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir mpOverlayManager->setStripeColorA(aColA); 153cdf0e10cSrcweir mpOverlayManager->setStripeColorB(aColB); 154cdf0e10cSrcweir mpOverlayManager->setStripeLengthPixel(GetPaintView().getOptionsDrawinglayer().GetStripeLength()); 155cdf0e10cSrcweir } 156cdf0e10cSrcweir } 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir SdrPaintWindow::SdrPaintWindow(SdrPaintView& rNewPaintView, OutputDevice& rOut) 160cdf0e10cSrcweir : mrOutputDevice(rOut), 161cdf0e10cSrcweir mrPaintView(rNewPaintView), 162cdf0e10cSrcweir mpOverlayManager(0L), 163cdf0e10cSrcweir mpPreRenderDevice(0L), 164cdf0e10cSrcweir mbTemporaryTarget(false), // #i72889# 165cdf0e10cSrcweir mbUseBuffer(true) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir SdrPaintWindow::~SdrPaintWindow() 170cdf0e10cSrcweir { 171cdf0e10cSrcweir if(mpOverlayManager) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir delete mpOverlayManager; 174cdf0e10cSrcweir mpOverlayManager = 0L; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir DestroyPreRenderDevice(); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir ::sdr::overlay::OverlayManager* SdrPaintWindow::GetOverlayManager() const 181cdf0e10cSrcweir { 182cdf0e10cSrcweir if(!mpOverlayManager) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir // Create buffered overlay manager by default. 185*a56bd57bSArmin Le Grand const_cast< SdrPaintWindow* >(this)->impCreateOverlayManager(); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir return mpOverlayManager; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir Rectangle SdrPaintWindow::GetVisibleArea() const 192cdf0e10cSrcweir { 193cdf0e10cSrcweir Size aVisSizePixel(GetOutputDevice().GetOutputSizePixel()); 194cdf0e10cSrcweir return Rectangle(GetOutputDevice().PixelToLogic(Rectangle(Point(0,0), aVisSizePixel))); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir sal_Bool SdrPaintWindow::OutputToRecordingMetaFile() const 198cdf0e10cSrcweir { 199cdf0e10cSrcweir GDIMetaFile* pMetaFile = mrOutputDevice.GetConnectMetaFile(); 200cdf0e10cSrcweir return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause()); 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir void SdrPaintWindow::PreparePreRenderDevice() 204cdf0e10cSrcweir { 205cdf0e10cSrcweir const sal_Bool bPrepareBufferedOutput( 206cdf0e10cSrcweir mrPaintView.IsBufferedOutputAllowed() 207cdf0e10cSrcweir && !OutputToPrinter() 208cdf0e10cSrcweir && !OutputToVirtualDevice() 209cdf0e10cSrcweir && !OutputToRecordingMetaFile()); 210cdf0e10cSrcweir 211cdf0e10cSrcweir if(bPrepareBufferedOutput) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir if(!mpPreRenderDevice) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir mpPreRenderDevice = new SdrPreRenderDevice(mrOutputDevice); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir } 218cdf0e10cSrcweir else 219cdf0e10cSrcweir { 220cdf0e10cSrcweir DestroyPreRenderDevice(); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir if(mpPreRenderDevice) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir mpPreRenderDevice->PreparePreRenderDevice(); 226cdf0e10cSrcweir } 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir void SdrPaintWindow::DestroyPreRenderDevice() 230cdf0e10cSrcweir { 231cdf0e10cSrcweir if(mpPreRenderDevice) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir delete mpPreRenderDevice; 234cdf0e10cSrcweir mpPreRenderDevice = 0L; 235cdf0e10cSrcweir } 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir void SdrPaintWindow::OutputPreRenderDevice(const Region& rExpandedRegion) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir if(mpPreRenderDevice) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir mpPreRenderDevice->OutputPreRenderDevice(rExpandedRegion); 243cdf0e10cSrcweir } 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir // #i73602# add flag if buffer shall be used 247*a56bd57bSArmin Le Grand void SdrPaintWindow::DrawOverlay(const Region& rRegion) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir // ## force creation of OverlayManager since the first repaint needs to 250cdf0e10cSrcweir // save the background to get a controlled start into overlay mechanism 251*a56bd57bSArmin Le Grand impCreateOverlayManager(); 252cdf0e10cSrcweir 253cdf0e10cSrcweir if(mpOverlayManager && !OutputToPrinter()) 254cdf0e10cSrcweir { 255*a56bd57bSArmin Le Grand if(mpPreRenderDevice) 256cdf0e10cSrcweir { 257cdf0e10cSrcweir mpOverlayManager->completeRedraw(rRegion, &mpPreRenderDevice->GetPreRenderDevice()); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir else 260cdf0e10cSrcweir { 261cdf0e10cSrcweir mpOverlayManager->completeRedraw(rRegion); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir } 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir void SdrPaintWindow::HideOverlay(const Region& rRegion) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir if(mpOverlayManager && !OutputToPrinter()) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir if(!mpPreRenderDevice) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir mpOverlayManager->restoreBackground(rRegion); 273cdf0e10cSrcweir } 274cdf0e10cSrcweir } 275cdf0e10cSrcweir } 276cdf0e10cSrcweir 277cdf0e10cSrcweir const Region& SdrPaintWindow::GetRedrawRegion() const 278cdf0e10cSrcweir { 279cdf0e10cSrcweir return maRedrawRegion; 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir void SdrPaintWindow::SetRedrawRegion(const Region& rNew) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir maRedrawRegion = rNew; 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////////////// 288cdf0e10cSrcweir // eof 289