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 10f6e50924SAndrew Rist * 11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12f6e50924SAndrew Rist * 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. 19f6e50924SAndrew Rist * 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/sdr/overlay/overlaymanager.hxx> 27cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx> 28cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx> 29cdf0e10cSrcweir #include <tools/gen.hxx> 30cdf0e10cSrcweir #include <vcl/salbtype.hxx> 31cdf0e10cSrcweir #include <vcl/outdev.hxx> 32cdf0e10cSrcweir #include <vcl/window.hxx> 33cdf0e10cSrcweir #include <svx/sdr/overlay/overlayobject.hxx> 34cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 35cdf0e10cSrcweir #include <drawinglayer/processor2d/baseprocessor2d.hxx> 36cdf0e10cSrcweir #include <svx/sdr/contact/objectcontacttools.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 39cdf0e10cSrcweir 40cdf0e10cSrcweir using namespace com::sun::star; 41cdf0e10cSrcweir 42cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 43cdf0e10cSrcweir 44cdf0e10cSrcweir namespace sdr 45cdf0e10cSrcweir { 46cdf0e10cSrcweir namespace overlay 47cdf0e10cSrcweir { 48cdf0e10cSrcweir void OverlayManager::ImpDrawMembers(const basegfx::B2DRange& rRange, OutputDevice& rDestinationDevice) const 49cdf0e10cSrcweir { 50cdf0e10cSrcweir const sal_uInt32 nSize(maOverlayObjects.size()); 51cdf0e10cSrcweir 52cdf0e10cSrcweir if(nSize) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir const sal_uInt16 nOriginalAA(rDestinationDevice.GetAntialiasing()); 55cdf0e10cSrcweir const bool bIsAntiAliasing(getDrawinglayerOpt().IsAntiAliasing()); 56cdf0e10cSrcweir 57cdf0e10cSrcweir // create processor 58cdf0e10cSrcweir drawinglayer::processor2d::BaseProcessor2D* pProcessor = ::sdr::contact::createBaseProcessor2DFromOutputDevice( 59cdf0e10cSrcweir rDestinationDevice, 60cdf0e10cSrcweir getCurrentViewInformation2D()); 61cdf0e10cSrcweir 62cdf0e10cSrcweir if(pProcessor) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir for(OverlayObjectVector::const_iterator aIter(maOverlayObjects.begin()); aIter != maOverlayObjects.end(); aIter++) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir OSL_ENSURE(*aIter, "Corrupted OverlayObject List (!)"); 67cdf0e10cSrcweir const OverlayObject& rCandidate = **aIter; 68cdf0e10cSrcweir 69cdf0e10cSrcweir if(rCandidate.isVisible()) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir const drawinglayer::primitive2d::Primitive2DSequence& rSequence = rCandidate.getOverlayObjectPrimitive2DSequence(); 72cdf0e10cSrcweir 73cdf0e10cSrcweir if(rSequence.hasElements()) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir if(rRange.overlaps(rCandidate.getBaseRange())) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir if(bIsAntiAliasing && rCandidate.allowsAntiAliase()) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir rDestinationDevice.SetAntialiasing(nOriginalAA | ANTIALIASING_ENABLE_B2DDRAW); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir else 82cdf0e10cSrcweir { 83cdf0e10cSrcweir rDestinationDevice.SetAntialiasing(nOriginalAA & ~ANTIALIASING_ENABLE_B2DDRAW); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir pProcessor->process(rSequence); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir } 89cdf0e10cSrcweir } 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir delete pProcessor; 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir // restore AA settings 96cdf0e10cSrcweir rDestinationDevice.SetAntialiasing(nOriginalAA); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir void OverlayManager::ImpStripeDefinitionChanged() 101cdf0e10cSrcweir { 102cdf0e10cSrcweir const sal_uInt32 nSize(maOverlayObjects.size()); 103cdf0e10cSrcweir 104cdf0e10cSrcweir if(nSize) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir for(OverlayObjectVector::iterator aIter(maOverlayObjects.begin()); aIter != maOverlayObjects.end(); aIter++) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir OSL_ENSURE(*aIter, "Corrupted OverlayObject List (!)"); 109cdf0e10cSrcweir OverlayObject& rCandidate = **aIter; 110cdf0e10cSrcweir rCandidate.stripeDefinitionHasChanged(); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir } 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir double OverlayManager::getDiscreteOne() const 116cdf0e10cSrcweir { 117cdf0e10cSrcweir if(basegfx::fTools::equalZero(mfDiscreteOne)) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir const basegfx::B2DVector aDiscreteInLogic(getOutputDevice().GetInverseViewTransformation() * basegfx::B2DVector(1.0, 0.0)); 120cdf0e10cSrcweir const_cast< OverlayManager* >(this)->mfDiscreteOne = aDiscreteInLogic.getLength(); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir return mfDiscreteOne; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126a56bd57bSArmin Le Grand OverlayManager::OverlayManager(OutputDevice& rOutputDevice) 127cdf0e10cSrcweir : Scheduler(), 128cdf0e10cSrcweir rmOutputDevice(rOutputDevice), 129cdf0e10cSrcweir maOverlayObjects(), 130cdf0e10cSrcweir maStripeColorA(Color(COL_BLACK)), 131cdf0e10cSrcweir maStripeColorB(Color(COL_WHITE)), 132cdf0e10cSrcweir mnStripeLengthPixel(5), 133cdf0e10cSrcweir maDrawinglayerOpt(), 134cdf0e10cSrcweir maViewTransformation(), 135cdf0e10cSrcweir maViewInformation2D(), 136cdf0e10cSrcweir mfDiscreteOne(0.0) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir // set Property 'ReducedDisplayQuality' to true to allow simpler interaction 139cdf0e10cSrcweir // visualisations 140cdf0e10cSrcweir static bool bUseReducedDisplayQualityForDrag(true); 141cdf0e10cSrcweir 142cdf0e10cSrcweir if(bUseReducedDisplayQualityForDrag) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > xProperties(1); 145cdf0e10cSrcweir xProperties[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedDisplayQuality")); 146cdf0e10cSrcweir xProperties[0].Value <<= true; 147cdf0e10cSrcweir maViewInformation2D = drawinglayer::geometry::ViewInformation2D(xProperties); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir const drawinglayer::geometry::ViewInformation2D OverlayManager::getCurrentViewInformation2D() const 152cdf0e10cSrcweir { 153cdf0e10cSrcweir if(getOutputDevice().GetViewTransformation() != maViewTransformation) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir basegfx::B2DRange aViewRange(maViewInformation2D.getViewport()); 156cdf0e10cSrcweir 157cdf0e10cSrcweir if(OUTDEV_WINDOW == getOutputDevice().GetOutDevType()) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir const Size aOutputSizePixel(getOutputDevice().GetOutputSizePixel()); 160*1cd65da9SArmin Le Grand 161*1cd65da9SArmin Le Grand // only set when we *have* a output size, else let aViewRange 162*1cd65da9SArmin Le Grand // stay on empty 163*1cd65da9SArmin Le Grand if(aOutputSizePixel.Width() && aOutputSizePixel.Height()) 164*1cd65da9SArmin Le Grand { 165*1cd65da9SArmin Le Grand aViewRange = basegfx::B2DRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight()); 166*1cd65da9SArmin Le Grand aViewRange.transform(getOutputDevice().GetInverseViewTransformation()); 167*1cd65da9SArmin Le Grand } 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir OverlayManager* pThis = const_cast< OverlayManager* >(this); 171cdf0e10cSrcweir 172cdf0e10cSrcweir pThis->maViewTransformation = getOutputDevice().GetViewTransformation(); 173cdf0e10cSrcweir pThis->maViewInformation2D = drawinglayer::geometry::ViewInformation2D( 174cdf0e10cSrcweir maViewInformation2D.getObjectTransformation(), 175cdf0e10cSrcweir maViewTransformation, 176cdf0e10cSrcweir aViewRange, 177cdf0e10cSrcweir maViewInformation2D.getVisualizedPage(), 178cdf0e10cSrcweir maViewInformation2D.getViewTime(), 179cdf0e10cSrcweir maViewInformation2D.getExtendedInformationSequence()); 180cdf0e10cSrcweir pThis->mfDiscreteOne = 0.0; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir return maViewInformation2D; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir void OverlayManager::impApplyRemoveActions(OverlayObject& rTarget) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir // handle evtl. animation 189cdf0e10cSrcweir if(rTarget.allowsAnimation()) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir // remove from event chain 192cdf0e10cSrcweir RemoveEvent(&rTarget); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir // make invisible 196cdf0e10cSrcweir invalidateRange(rTarget.getBaseRange()); 197cdf0e10cSrcweir 198cdf0e10cSrcweir // clear manager 199cdf0e10cSrcweir rTarget.mpOverlayManager = 0; 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir void OverlayManager::impApplyAddActions(OverlayObject& rTarget) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir // set manager 205cdf0e10cSrcweir rTarget.mpOverlayManager = this; 206cdf0e10cSrcweir 207cdf0e10cSrcweir // make visible 208cdf0e10cSrcweir invalidateRange(rTarget.getBaseRange()); 209cdf0e10cSrcweir 210cdf0e10cSrcweir // handle evtl. animation 211cdf0e10cSrcweir if(rTarget.allowsAnimation()) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir // Trigger at current time to get alive. This will do the 214cdf0e10cSrcweir // object-specific next time calculation and hand over adding 215cdf0e10cSrcweir // again to the scheduler to the animated object, too. This works for 216cdf0e10cSrcweir // a paused or non-paused animator. 217cdf0e10cSrcweir rTarget.Trigger(GetTime()); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir OverlayManager::~OverlayManager() 222cdf0e10cSrcweir { 223cdf0e10cSrcweir // The OverlayManager is not the owner of the OverlayObjects 224cdf0e10cSrcweir // and thus will not delete them, but remove them. Profit here 225cdf0e10cSrcweir // from knowing that all will be removed 226cdf0e10cSrcweir const sal_uInt32 nSize(maOverlayObjects.size()); 227cdf0e10cSrcweir 228cdf0e10cSrcweir if(nSize) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir for(OverlayObjectVector::iterator aIter(maOverlayObjects.begin()); aIter != maOverlayObjects.end(); aIter++) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir OSL_ENSURE(*aIter, "Corrupted OverlayObject List (!)"); 233cdf0e10cSrcweir OverlayObject& rCandidate = **aIter; 234cdf0e10cSrcweir impApplyRemoveActions(rCandidate); 235cdf0e10cSrcweir } 236cdf0e10cSrcweir 237cdf0e10cSrcweir // erase vector 238cdf0e10cSrcweir maOverlayObjects.clear(); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir void OverlayManager::completeRedraw(const Region& rRegion, OutputDevice* pPreRenderDevice) const 243cdf0e10cSrcweir { 244cdf0e10cSrcweir if(!rRegion.IsEmpty() && maOverlayObjects.size()) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir // check for changed MapModes. That may influence the 247cdf0e10cSrcweir // logical size of pixel based OverlayObjects (like BitmapHandles) 248cdf0e10cSrcweir //ImpCheckMapModeChange(); 249cdf0e10cSrcweir 250cdf0e10cSrcweir // paint members 251cdf0e10cSrcweir const Rectangle aRegionBoundRect(rRegion.GetBoundRect()); 252cdf0e10cSrcweir const basegfx::B2DRange aRegionRange( 253cdf0e10cSrcweir aRegionBoundRect.Left(), aRegionBoundRect.Top(), 254cdf0e10cSrcweir aRegionBoundRect.Right(), aRegionBoundRect.Bottom()); 255cdf0e10cSrcweir 256cdf0e10cSrcweir OutputDevice& rTarget = (pPreRenderDevice) ? *pPreRenderDevice : getOutputDevice(); 257cdf0e10cSrcweir ImpDrawMembers(aRegionRange, rTarget); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir void OverlayManager::flush() 262cdf0e10cSrcweir { 263cdf0e10cSrcweir // default has nothing to do 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir // #i68597# part of content gets copied, react on it 267cdf0e10cSrcweir void OverlayManager::copyArea(const Point& /*rDestPt*/, const Point& /*rSrcPt*/, const Size& /*rSrcSize*/) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir // unbuffered versions do nothing here 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir void OverlayManager::restoreBackground(const Region& /*rRegion*/) const 273cdf0e10cSrcweir { 274cdf0e10cSrcweir // unbuffered versions do nothing here 275cdf0e10cSrcweir } 276cdf0e10cSrcweir 277cdf0e10cSrcweir void OverlayManager::add(OverlayObject& rOverlayObject) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir OSL_ENSURE(0 == rOverlayObject.mpOverlayManager, "OverlayObject is added twice to an OverlayManager (!)"); 280cdf0e10cSrcweir 281cdf0e10cSrcweir // add to the end of chain to preserve display order in paint 282cdf0e10cSrcweir maOverlayObjects.push_back(&rOverlayObject); 283cdf0e10cSrcweir 284cdf0e10cSrcweir // execute add actions 285cdf0e10cSrcweir impApplyAddActions(rOverlayObject); 286cdf0e10cSrcweir } 287cdf0e10cSrcweir 288cdf0e10cSrcweir void OverlayManager::remove(OverlayObject& rOverlayObject) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir OSL_ENSURE(rOverlayObject.mpOverlayManager == this, "OverlayObject is removed from wrong OverlayManager (!)"); 291cdf0e10cSrcweir 292cdf0e10cSrcweir // execute remove actions 293cdf0e10cSrcweir impApplyRemoveActions(rOverlayObject); 294cdf0e10cSrcweir 295cdf0e10cSrcweir // remove from vector 296cdf0e10cSrcweir const OverlayObjectVector::iterator aFindResult = ::std::find(maOverlayObjects.begin(), maOverlayObjects.end(), &rOverlayObject); 297cdf0e10cSrcweir const bool bFound(aFindResult != maOverlayObjects.end()); 298cdf0e10cSrcweir OSL_ENSURE(bFound, "OverlayObject NOT found at OverlayManager (!)"); 299cdf0e10cSrcweir 300cdf0e10cSrcweir if(bFound) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir maOverlayObjects.erase(aFindResult); 303cdf0e10cSrcweir } 304cdf0e10cSrcweir } 305cdf0e10cSrcweir 306cdf0e10cSrcweir void OverlayManager::invalidateRange(const basegfx::B2DRange& rRange) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir if(OUTDEV_WINDOW == getOutputDevice().GetOutDevType()) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir if(getDrawinglayerOpt().IsAntiAliasing()) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir // assume AA needs one pixel more and invalidate one pixel more 313cdf0e10cSrcweir const double fDiscreteOne(getDiscreteOne()); 314cdf0e10cSrcweir const Rectangle aInvalidateRectangle( 315cdf0e10cSrcweir (sal_Int32)floor(rRange.getMinX() - fDiscreteOne), 316cdf0e10cSrcweir (sal_Int32)floor(rRange.getMinY() - fDiscreteOne), 317cdf0e10cSrcweir (sal_Int32)ceil(rRange.getMaxX() + fDiscreteOne), 318cdf0e10cSrcweir (sal_Int32)ceil(rRange.getMaxY() + fDiscreteOne)); 319cdf0e10cSrcweir 320cdf0e10cSrcweir // simply invalidate 321cdf0e10cSrcweir ((Window&)getOutputDevice()).Invalidate(aInvalidateRectangle, INVALIDATE_NOERASE); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir else 324cdf0e10cSrcweir { 325cdf0e10cSrcweir // #i77674# transform to rectangle. Use floor/ceil to get all covered 326cdf0e10cSrcweir // discrete pixels, see #i75163# and OverlayManagerBuffered::invalidateRange 327cdf0e10cSrcweir const Rectangle aInvalidateRectangle( 328cdf0e10cSrcweir (sal_Int32)floor(rRange.getMinX()), (sal_Int32)floor(rRange.getMinY()), 329cdf0e10cSrcweir (sal_Int32)ceil(rRange.getMaxX()), (sal_Int32)ceil(rRange.getMaxY())); 330cdf0e10cSrcweir 331cdf0e10cSrcweir // simply invalidate 332cdf0e10cSrcweir ((Window&)getOutputDevice()).Invalidate(aInvalidateRectangle, INVALIDATE_NOERASE); 333cdf0e10cSrcweir } 334cdf0e10cSrcweir } 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir // stripe support ColA 338cdf0e10cSrcweir void OverlayManager::setStripeColorA(Color aNew) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir if(aNew != maStripeColorA) 341cdf0e10cSrcweir { 342cdf0e10cSrcweir maStripeColorA = aNew; 343cdf0e10cSrcweir ImpStripeDefinitionChanged(); 344cdf0e10cSrcweir } 345cdf0e10cSrcweir } 346cdf0e10cSrcweir 347cdf0e10cSrcweir // stripe support ColB 348cdf0e10cSrcweir void OverlayManager::setStripeColorB(Color aNew) 349cdf0e10cSrcweir { 350cdf0e10cSrcweir if(aNew != maStripeColorB) 351cdf0e10cSrcweir { 352cdf0e10cSrcweir maStripeColorB = aNew; 353cdf0e10cSrcweir ImpStripeDefinitionChanged(); 354cdf0e10cSrcweir } 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir // stripe support StripeLengthPixel 358cdf0e10cSrcweir void OverlayManager::setStripeLengthPixel(sal_uInt32 nNew) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir if(nNew != mnStripeLengthPixel) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir mnStripeLengthPixel = nNew; 363cdf0e10cSrcweir ImpStripeDefinitionChanged(); 364cdf0e10cSrcweir } 365cdf0e10cSrcweir } 366cdf0e10cSrcweir } // end of namespace overlay 367cdf0e10cSrcweir } // end of namespace sdr 368cdf0e10cSrcweir 369cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 370cdf0e10cSrcweir // eof 371