1aaef562fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3aaef562fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4aaef562fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5aaef562fSAndrew Rist * distributed with this work for additional information 6aaef562fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7aaef562fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8aaef562fSAndrew Rist * "License"); you may not use this file except in compliance 9aaef562fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11aaef562fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13aaef562fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14aaef562fSAndrew Rist * software distributed under the License is distributed on an 15aaef562fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16aaef562fSAndrew Rist * KIND, either express or implied. See the License for the 17aaef562fSAndrew Rist * specific language governing permissions and limitations 18aaef562fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20aaef562fSAndrew Rist *************************************************************/ 21aaef562fSAndrew Rist 22aaef562fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYERHOLDER_HXX 25cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYERHOLDER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "attributableshape.hxx" 28cdf0e10cSrcweir #include "shapeattributelayer.hxx" 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <boost/noncopyable.hpp> 31cdf0e10cSrcweir 32cdf0e10cSrcweir namespace slideshow 33cdf0e10cSrcweir { 34cdf0e10cSrcweir namespace internal 35cdf0e10cSrcweir { 36cdf0e10cSrcweir /** Holds a ShapeAttributeLayer, together with the associated 37cdf0e10cSrcweir Shape 38cdf0e10cSrcweir 39cdf0e10cSrcweir Use this class to hold ShapeAttributeLayer objects the 40cdf0e10cSrcweir RAII way. When this object gets deleted, it will 41cdf0e10cSrcweir automatically revoke the attribute layer for the given 42cdf0e10cSrcweir shape (this encapsulates the somewhat clumsy notification 43cdf0e10cSrcweir process that is required for shape and attribute layer 44cdf0e10cSrcweir interaction). 45cdf0e10cSrcweir */ 46cdf0e10cSrcweir class ShapeAttributeLayerHolder : private boost::noncopyable 47cdf0e10cSrcweir { 48cdf0e10cSrcweir public: 49cdf0e10cSrcweir /** Create a ShapeAttributeLayerHolder instance. 50cdf0e10cSrcweir 51cdf0e10cSrcweir This constructor creates an empty attribute holder, to 52cdf0e10cSrcweir generate an attribute layer, you have to manually call 53cdf0e10cSrcweir createAttributeLayer(). 54cdf0e10cSrcweir */ ShapeAttributeLayerHolder()55cdf0e10cSrcweir ShapeAttributeLayerHolder() : 56cdf0e10cSrcweir mpShape(), 57cdf0e10cSrcweir mpAttributeLayer() 58cdf0e10cSrcweir { 59cdf0e10cSrcweir } 60cdf0e10cSrcweir ~ShapeAttributeLayerHolder()61cdf0e10cSrcweir ~ShapeAttributeLayerHolder() 62cdf0e10cSrcweir { 63cdf0e10cSrcweir reset(); // ensures that the last attribute layer is 64cdf0e10cSrcweir // correctly deregistered from the shape. 65cdf0e10cSrcweir } 66cdf0e10cSrcweir reset()67cdf0e10cSrcweir void reset() 68cdf0e10cSrcweir { 69cdf0e10cSrcweir if( mpShape && mpAttributeLayer ) 70cdf0e10cSrcweir mpShape->revokeAttributeLayer( mpAttributeLayer ); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir /** This constructor receives a pointer to the Shape, from 74cdf0e10cSrcweir which attribute layers should be generated. Initially, 75cdf0e10cSrcweir this object does not create an attribute layer, you 76cdf0e10cSrcweir have to manually call createAttributeLayer(). 77cdf0e10cSrcweir 78cdf0e10cSrcweir @param rShape 79cdf0e10cSrcweir Shape for which attribute layers should be generated. 80cdf0e10cSrcweir */ createAttributeLayer(const AttributableShapeSharedPtr & rShape)81cdf0e10cSrcweir bool createAttributeLayer( const AttributableShapeSharedPtr& rShape ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir reset(); 84cdf0e10cSrcweir 85cdf0e10cSrcweir mpShape = rShape; 86cdf0e10cSrcweir 87cdf0e10cSrcweir if( mpShape ) 88cdf0e10cSrcweir mpAttributeLayer = mpShape->createAttributeLayer(); 89cdf0e10cSrcweir 90*0ca1f900SHerbert Dürr return (mpAttributeLayer.get() != NULL); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir get() const93cdf0e10cSrcweir ShapeAttributeLayerSharedPtr get() const 94cdf0e10cSrcweir { 95cdf0e10cSrcweir return mpAttributeLayer; 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir private: 99cdf0e10cSrcweir AttributableShapeSharedPtr mpShape; 100cdf0e10cSrcweir ShapeAttributeLayerSharedPtr mpAttributeLayer; 101cdf0e10cSrcweir }; 102cdf0e10cSrcweir 103cdf0e10cSrcweir } 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYERHOLDER_HXX */ 107