1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_DRAWSHAPESUBSETTING_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_DRAWSHAPESUBSETTING_HXX
23 #include <boost/shared_ptr.hpp>
24 #include <boost/noncopyable.hpp>
26 #include "doctreenode.hxx"
27 #include "attributableshape.hxx"
36 /** This class encapsulates the subsetting aspects of a
39 class DrawShapeSubsetting
: private boost::noncopyable
42 /** Create empty shape subset handling.
44 This method creates a subset handler which contains no
45 subset information. All methods will return default
49 Metafile to retrieve subset info from (must have been
50 generated with verbose text comments switched on).
52 DrawShapeSubsetting();
54 /** Create new shape subset handling.
57 The subset this object represents (can be empty, then
58 denoting 'represents a whole shape')
61 Metafile to retrieve subset info from (must have been
62 generated with verbose text comments switched on).
64 DrawShapeSubsetting( const DocTreeNode
& rShapeSubset
,
65 const ::boost::shared_ptr
< GDIMetaFile
>& rMtf
);
69 Use this method to completely reset the
70 ShapeSubsetting, with a new metafile. Note that any
71 information previously set will be lost, including
75 Metafile to retrieve subset info from (must have been
76 generated with verbose text comments switched on).
78 void reset( const ::boost::shared_ptr
< GDIMetaFile
>& rMtf
);
80 // Shape subsetting methods
83 /// Return subset node for this shape
84 DocTreeNode
getSubsetNode () const;
86 /// Get subset shape for given node, if any
87 AttributableShapeSharedPtr
getSubsetShape ( const DocTreeNode
& rTreeNode
) const;
89 /// Add child subset shape (or increase use count, if already existent)
90 void addSubsetShape ( const AttributableShapeSharedPtr
& rShape
);
92 /** Revoke subset shape
94 This method revokes a subset shape, decrementing the
95 use count for this subset by one. If the use count
96 reaches zero (i.e. when the number of addSubsetShape()
97 matches the number of revokeSubsetShape() calls for
98 the same subset), the subset entry is removed from the
99 internal list, and subsequent getSubsetShape() calls
100 will return the empty pointer for this subset.
102 @return true, if the subset shape was physically
103 removed from the list (false is returned, when nothing
104 was removed, either because only the use count was
105 decremented, or there was no such subset found, in the
108 bool revokeSubsetShape ( const AttributableShapeSharedPtr
& rShape
);
114 /// Return overall number of nodes for given type
115 sal_Int32
getNumberOfTreeNodes ( DocTreeNode::NodeType eNodeType
) const;
117 /// Return tree node of given index and given type
118 DocTreeNode
getTreeNode ( sal_Int32 nNodeIndex
,
119 DocTreeNode::NodeType eNodeType
) const;
121 /// Return number of nodes of given type, below parent node
122 sal_Int32
getNumberOfSubsetTreeNodes ( const DocTreeNode
& rParentNode
,
123 DocTreeNode::NodeType eNodeType
) const;
125 /// Return tree node of given index and given type, relative to parent node
126 DocTreeNode
getSubsetTreeNode ( const DocTreeNode
& rParentNode
,
127 sal_Int32 nNodeIndex
,
128 DocTreeNode::NodeType eNodeType
) const;
133 /** Return a vector of currently active subsets.
135 Needed when rendering a shape, this method provides a
136 vector of subsets currently visible (the range as
137 returned by getEffectiveSubset(), minus the parts that
138 are currently hidden, because displayed by child
141 const VectorOfDocTreeNodes
& getActiveSubsets() const { return maCurrentSubsets
; }
143 /** This enum classifies each action index in the
146 Of interest are, of course, the places where
147 structural shape and/or text elements end. The
148 remainder of the action gets classified as 'noop'
150 enum IndexClassificator
160 CLASS_CHARACTER_CELL_END
163 typedef ::std::vector
< IndexClassificator
> IndexClassificatorVector
;
166 /** Entry for subset shape
168 This struct contains data for every subset shape
169 generated. Note that for a given start/end action
170 index combination, only one subset instance is
171 generated (and reused for subsequent queries).
175 AttributableShapeSharedPtr mpShape
;
176 sal_Int32 mnStartActionIndex
;
177 sal_Int32 mnEndActionIndex
;
179 /// Number of times this subset was queried, and not yet revoked
180 int mnSubsetQueriedCount
;
182 sal_Int32
getHashValue() const
184 // TODO(Q3): That's a hack. We assume that start
185 // index will always be less than 65535 (if this
186 // assumption is violated, hash map performance
187 // will degrade severely)
188 return mnStartActionIndex
*SAL_MAX_INT16
+ mnEndActionIndex
;
191 /// The shape set is ordered according to this method
192 bool operator<(const SubsetEntry
& rOther
) const
194 return getHashValue() < rOther
.getHashValue();
199 typedef ::std::set
< SubsetEntry
> ShapeSet
;
201 void ensureInitializedNodeTree() const;
202 void updateSubsetBounds( const SubsetEntry
& rSubsetEntry
);
203 void updateSubsets();
204 void initCurrentSubsets();
207 static sal_Int32
implGetNumberOfTreeNodes( const IndexClassificatorVector::const_iterator
& rBegin
,
208 const IndexClassificatorVector::const_iterator
& rEnd
,
209 DocTreeNode::NodeType eNodeType
);
210 DocTreeNode
implGetTreeNode( const IndexClassificatorVector::const_iterator
& rBegin
,
211 const IndexClassificatorVector::const_iterator
& rEnd
,
212 sal_Int32 nNodeIndex
,
213 DocTreeNode::NodeType eNodeType
) const;
215 mutable IndexClassificatorVector maActionClassVector
;
217 /// Metafile to retrieve subset info from
218 ::boost::shared_ptr
< GDIMetaFile
> mpMtf
;
220 /// Subset of the metafile represented by this object
221 DocTreeNode maSubset
;
223 /// the list of subset shapes spawned from this one.
224 ShapeSet maSubsetShapes
;
226 /// caches minimal subset index from maSubsetShapes
227 sal_Int32 mnMinSubsetActionIndex
;
229 /// caches maximal subset index from maSubsetShapes
230 sal_Int32 mnMaxSubsetActionIndex
;
232 /** Current number of subsets to render (calculated from
233 maSubset and mnMin/MaxSubsetActionIndex).
235 Note that this is generally _not_ equivalent to
236 maSubset, as it excludes all active subset children!
238 mutable VectorOfDocTreeNodes maCurrentSubsets
;
240 /// Whether the shape's doc tree has been initialized successfully, or not
241 mutable bool mbNodeTreeInitialized
;
247 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_DRAWSHAPESUBSETTING_HXX
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */