1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drawshapesubsetting.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_SLIDESHOW_DRAWSHAPESUBSETTING_HXX
32 #define INCLUDED_SLIDESHOW_DRAWSHAPESUBSETTING_HXX
34 #include <boost/shared_ptr.hpp>
35 #include <boost/noncopyable.hpp>
37 #include "doctreenode.hxx"
38 #include "attributableshape.hxx"
47 /** This class encapsulates the subsetting aspects of a
50 class DrawShapeSubsetting
: private boost::noncopyable
53 /** Create empty shape subset handling.
55 This method creates a subset handler which contains no
56 subset information. All methods will return default
60 Metafile to retrieve subset info from (must have been
61 generated with verbose text comments switched on).
63 DrawShapeSubsetting();
65 /** Create new shape subset handling.
67 This method creates a subset handler which initially
68 displays the whole shape.
71 Metafile to retrieve subset info from (must have been
72 generated with verbose text comments switched on).
74 explicit DrawShapeSubsetting( const ::boost::shared_ptr
< GDIMetaFile
>& rMtf
);
76 /** Create new shape subset handling.
79 The subset this object represents (can be empty, then
80 denoting 'represents a whole shape')
83 Metafile to retrieve subset info from (must have been
84 generated with verbose text comments switched on).
86 DrawShapeSubsetting( const DocTreeNode
& rShapeSubset
,
87 const ::boost::shared_ptr
< GDIMetaFile
>& rMtf
);
91 Use this method to completely reset the
92 ShapeSubsetting, with a new metafile. Note that any
93 information previously set will be lost, including
97 Metafile to retrieve subset info from (must have been
98 generated with verbose text comments switched on).
100 void reset( const ::boost::shared_ptr
< GDIMetaFile
>& rMtf
);
102 /** Reset metafile and subset.
104 Use this method to completely reset the
105 ShapeSubsetting, with a new metafile and subset
106 range. Note that any information previously set will
107 be lost, including added subset shapes!
110 The subset this object represents (can be empty, then
111 denoting 'represents a whole shape')
114 Metafile to retrieve subset info from (must have been
115 generated with verbose text comments switched on).
117 void reset( const DocTreeNode
& rShapeSubset
,
118 const ::boost::shared_ptr
< GDIMetaFile
>& rMtf
);
121 // Shape subsetting methods
122 // ========================================================
124 /// Return subset node for this shape
125 DocTreeNode
getSubsetNode () const;
127 /// Return true, if any child subset shapes exist
128 bool hasSubsetShapes () const;
130 /// Get subset shape for given node, if any
131 AttributableShapeSharedPtr
getSubsetShape ( const DocTreeNode
& rTreeNode
) const;
133 /// Add child subset shape (or increase use count, if already existent)
134 void addSubsetShape ( const AttributableShapeSharedPtr
& rShape
);
136 /** Revoke subset shape
138 This method revokes a subset shape, decrementing the
139 use count for this subset by one. If the use count
140 reaches zero (i.e. when the number of addSubsetShape()
141 matches the number of revokeSubsetShape() calls for
142 the same subset), the subset entry is removed from the
143 internal list, and subsequent getSubsetShape() calls
144 will return the empty pointer for this subset.
146 @return true, if the subset shape was physically
147 removed from the list (false is returned, when nothing
148 was removed, either because only the use count was
149 decremented, or there was no such subset found, in the
152 bool revokeSubsetShape ( const AttributableShapeSharedPtr
& rShape
);
156 // ========================================================
158 /// Return overall number of nodes for given type
159 sal_Int32
getNumberOfTreeNodes ( DocTreeNode::NodeType eNodeType
) const;
161 /// Return tree node of given index and given type
162 DocTreeNode
getTreeNode ( sal_Int32 nNodeIndex
,
163 DocTreeNode::NodeType eNodeType
) const;
165 /// Return number of nodes of given type, below parent node
166 sal_Int32
getNumberOfSubsetTreeNodes ( const DocTreeNode
& rParentNode
,
167 DocTreeNode::NodeType eNodeType
) const;
169 /// Return tree node of given index and given type, relative to parent node
170 DocTreeNode
getSubsetTreeNode ( const DocTreeNode
& rParentNode
,
171 sal_Int32 nNodeIndex
,
172 DocTreeNode::NodeType eNodeType
) const;
175 // ========================================================
177 /** Return a vector of currently active subsets.
179 Needed when rendering a shape, this method provides a
180 vector of subsets currently visible (the range as
181 returned by getEffectiveSubset(), minus the parts that
182 are currently hidden, because displayed by child
185 const VectorOfDocTreeNodes
& getActiveSubsets() const;
187 /** This enum classifies each action index in the
190 Of interest are, of course, the places where
191 structural shape and/or text elements end. The
192 remainder of the action gets classified as 'noop'
194 enum IndexClassificator
204 CLASS_CHARACTER_CELL_END
207 typedef ::std::vector
< IndexClassificator
> IndexClassificatorVector
;
210 /** Entry for subset shape
212 This struct contains data for every subset shape
213 generated. Note that for a given start/end action
214 index combination, only one subset instance is
215 generated (and reused for subsequent queries).
219 AttributableShapeSharedPtr mpShape
;
220 sal_Int32 mnStartActionIndex
;
221 sal_Int32 mnEndActionIndex
;
223 /// Number of times this subset was queried, and not yet revoked
224 int mnSubsetQueriedCount
;
226 sal_Int32
getHashValue() const
228 // TODO(Q3): That's a hack. We assume that start
229 // index will always be less than 65535 (if this
230 // assumption is violated, hash map performance
231 // will degrade severely)
232 return mnStartActionIndex
*SAL_MAX_INT16
+ mnEndActionIndex
;
235 /// The shape set is ordered according to this method
236 bool operator<(const SubsetEntry
& rOther
) const
238 return getHashValue() < rOther
.getHashValue();
243 typedef ::std::set
< SubsetEntry
> ShapeSet
;
245 void ensureInitializedNodeTree() const;
246 void updateSubsetBounds( const SubsetEntry
& rSubsetEntry
);
247 void updateSubsets();
248 void initCurrentSubsets();
251 sal_Int32
implGetNumberOfTreeNodes( const IndexClassificatorVector::const_iterator
& rBegin
,
252 const IndexClassificatorVector::const_iterator
& rEnd
,
253 DocTreeNode::NodeType eNodeType
) const;
254 DocTreeNode
implGetTreeNode( const IndexClassificatorVector::const_iterator
& rBegin
,
255 const IndexClassificatorVector::const_iterator
& rEnd
,
256 sal_Int32 nNodeIndex
,
257 DocTreeNode::NodeType eNodeType
) const;
259 mutable IndexClassificatorVector maActionClassVector
;
261 /// Metafile to retrieve subset info from
262 ::boost::shared_ptr
< GDIMetaFile
> mpMtf
;
264 /// Subset of the metafile represented by this object
265 DocTreeNode maSubset
;
267 /// the list of subset shapes spawned from this one.
268 ShapeSet maSubsetShapes
;
270 /// caches minimal subset index from maSubsetShapes
271 sal_Int32 mnMinSubsetActionIndex
;
273 /// caches maximal subset index from maSubsetShapes
274 sal_Int32 mnMaxSubsetActionIndex
;
276 /** Current number of subsets to render (calculated from
277 maSubset and mnMin/MaxSubsetActionIndex).
279 Note that this is generally _not_ equivalent to
280 maSubset, as it excludes all active subset children!
282 mutable VectorOfDocTreeNodes maCurrentSubsets
;
284 /// Whether the shape's doc tree has been initialized successfully, or not
285 mutable bool mbNodeTreeInitialized
;
291 #endif /* INCLUDED_SLIDESHOW_DRAWSHAPESUBSETTING_HXX */