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 #ifndef INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYERHOLDER_HXX
29 #define INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYERHOLDER_HXX
30 
31 #include "attributableshape.hxx"
32 #include "shapeattributelayer.hxx"
33 
34 #include <boost/noncopyable.hpp>
35 
36 namespace slideshow
37 {
38     namespace internal
39     {
40         /** Holds a ShapeAttributeLayer, together with the associated
41             Shape
42 
43             Use this class to hold ShapeAttributeLayer objects the
44             RAII way. When this object gets deleted, it will
45             automatically revoke the attribute layer for the given
46             shape (this encapsulates the somewhat clumsy notification
47             process that is required for shape and attribute layer
48             interaction).
49          */
50         class ShapeAttributeLayerHolder : private boost::noncopyable
51         {
52         public:
53             /** Create a ShapeAttributeLayerHolder instance.
54 
55             	This constructor creates an empty attribute holder, to
56             	generate an attribute layer, you have to manually call
57             	createAttributeLayer().
58              */
59             ShapeAttributeLayerHolder() :
60                 mpShape(),
61                 mpAttributeLayer()
62             {
63             }
64 
65             ~ShapeAttributeLayerHolder()
66             {
67                 reset(); // ensures that the last attribute layer is
68                          // correctly deregistered from the shape.
69             }
70 
71             void reset()
72             {
73                 if( mpShape && mpAttributeLayer )
74                     mpShape->revokeAttributeLayer( mpAttributeLayer );
75             }
76 
77             /** This constructor receives a pointer to the Shape, from
78             	which attribute layers should be generated. Initially,
79             	this object does not create an attribute layer, you
80             	have to manually call createAttributeLayer().
81 
82                 @param rShape
83                 Shape for which attribute layers should be generated.
84             */
85             bool createAttributeLayer( const AttributableShapeSharedPtr& rShape )
86             {
87                 reset();
88 
89                 mpShape = rShape;
90 
91                 if( mpShape )
92                     mpAttributeLayer = mpShape->createAttributeLayer();
93 
94                 return mpAttributeLayer;
95             }
96 
97             ShapeAttributeLayerSharedPtr get() const
98             {
99                 return mpAttributeLayer;
100             }
101 
102         private:
103             AttributableShapeSharedPtr		mpShape;
104             ShapeAttributeLayerSharedPtr	mpAttributeLayer;
105         };
106 
107     }
108 }
109 
110 #endif /* INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYERHOLDER_HXX */
111