1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_drawinglayer.hxx" 30 31 #include <drawinglayer/primitive2d/backgroundcolorprimitive2d.hxx> 32 #include <basegfx/polygon/b2dpolygon.hxx> 33 #include <basegfx/polygon/b2dpolygontools.hxx> 34 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 35 #include <basegfx/tools/canvastools.hxx> 36 #include <drawinglayer/geometry/viewinformation2d.hxx> 37 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 38 39 ////////////////////////////////////////////////////////////////////////////// 40 41 using namespace com::sun::star; 42 43 ////////////////////////////////////////////////////////////////////////////// 44 45 namespace drawinglayer 46 { 47 namespace primitive2d 48 { 49 Primitive2DSequence BackgroundColorPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 50 { 51 if(!rViewInformation.getViewport().isEmpty()) 52 { 53 const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(rViewInformation.getViewport())); 54 const Primitive2DReference xRef(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aOutline), getBColor())); 55 return Primitive2DSequence(&xRef, 1L); 56 } 57 else 58 { 59 return Primitive2DSequence(); 60 } 61 } 62 63 BackgroundColorPrimitive2D::BackgroundColorPrimitive2D( 64 const basegfx::BColor& rBColor) 65 : BufferedDecompositionPrimitive2D(), 66 maBColor(rBColor), 67 maLastViewport() 68 { 69 } 70 71 bool BackgroundColorPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 72 { 73 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 74 { 75 const BackgroundColorPrimitive2D& rCompare = (BackgroundColorPrimitive2D&)rPrimitive; 76 77 return (getBColor() == rCompare.getBColor()); 78 } 79 80 return false; 81 } 82 83 basegfx::B2DRange BackgroundColorPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const 84 { 85 // always as big as the view 86 return rViewInformation.getViewport(); 87 } 88 89 Primitive2DSequence BackgroundColorPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 90 { 91 ::osl::MutexGuard aGuard( m_aMutex ); 92 93 if(getBuffered2DDecomposition().hasElements() && (maLastViewport != rViewInformation.getViewport())) 94 { 95 // conditions of last local decomposition have changed, delete 96 const_cast< BackgroundColorPrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DSequence()); 97 } 98 99 if(!getBuffered2DDecomposition().hasElements()) 100 { 101 // remember ViewRange 102 const_cast< BackgroundColorPrimitive2D* >(this)->maLastViewport = rViewInformation.getViewport(); 103 } 104 105 // use parent implementation 106 return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation); 107 } 108 109 // provide unique ID 110 ImplPrimitrive2DIDBlock(BackgroundColorPrimitive2D, PRIMITIVE2D_ID_BACKGROUNDCOLORPRIMITIVE2D) 111 112 } // end of namespace primitive2d 113 } // end of namespace drawinglayer 114 115 ////////////////////////////////////////////////////////////////////////////// 116 // eof 117