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 <doctreenode.hxx>
24 #include <attributableshape.hxx>
28 typedef ::std::shared_ptr
< GDIMetaFile
> GDIMetaFileSharedPtr
;
30 namespace slideshow::internal
32 /** This class encapsulates the subsetting aspects of a
35 class DrawShapeSubsetting
38 /** Create empty shape subset handling.
40 This method creates a subset handler which contains no
41 subset information. All methods will return default
45 Metafile to retrieve subset info from (must have been
46 generated with verbose text comments switched on).
48 DrawShapeSubsetting();
50 /** Create new shape subset handling.
53 The subset this object represents (can be empty, then
54 denoting 'represents a whole shape')
57 Metafile to retrieve subset info from (must have been
58 generated with verbose text comments switched on).
60 DrawShapeSubsetting( const DocTreeNode
& rShapeSubset
,
61 GDIMetaFileSharedPtr rMtf
);
63 /// Forbid copy construction
64 DrawShapeSubsetting(const DrawShapeSubsetting
&) = delete;
66 /// Forbid copy assignment
67 DrawShapeSubsetting
& operator=(const DrawShapeSubsetting
&) = delete;
71 Use this method to completely reset the
72 ShapeSubsetting, with a new metafile. Note that any
73 information previously set will be lost, including
77 Metafile to retrieve subset info from (must have been
78 generated with verbose text comments switched on).
80 void reset( const ::std::shared_ptr
< GDIMetaFile
>& rMtf
);
82 // Shape subsetting methods
85 /// Return subset node for this shape
86 const DocTreeNode
& getSubsetNode () const;
88 /// Get subset shape for given node, if any
89 AttributableShapeSharedPtr
getSubsetShape ( const DocTreeNode
& rTreeNode
) const;
91 /// Add child subset shape (or increase use count, if already existent)
92 void addSubsetShape ( const AttributableShapeSharedPtr
& rShape
);
94 /** Revoke subset shape
96 This method revokes a subset shape, decrementing the
97 use count for this subset by one. If the use count
98 reaches zero (i.e. when the number of addSubsetShape()
99 matches the number of revokeSubsetShape() calls for
100 the same subset), the subset entry is removed from the
101 internal list, and subsequent getSubsetShape() calls
102 will return the empty pointer for this subset.
104 @return true, if the subset shape was physically
105 removed from the list (false is returned, when nothing
106 was removed, either because only the use count was
107 decremented, or there was no such subset found, in the
110 bool revokeSubsetShape ( const AttributableShapeSharedPtr
& rShape
);
116 /// Return overall number of nodes for given type
117 sal_Int32
getNumberOfTreeNodes ( DocTreeNode::NodeType eNodeType
) const;
119 /// Return tree node of given index and given type
120 DocTreeNode
getTreeNode ( sal_Int32 nNodeIndex
,
121 DocTreeNode::NodeType eNodeType
) const;
123 /// Return number of nodes of given type, below parent node
124 sal_Int32
getNumberOfSubsetTreeNodes ( const DocTreeNode
& rParentNode
,
125 DocTreeNode::NodeType eNodeType
) const;
127 /// Return tree node of given index and given type, relative to parent node
128 DocTreeNode
getSubsetTreeNode ( const DocTreeNode
& rParentNode
,
129 sal_Int32 nNodeIndex
,
130 DocTreeNode::NodeType eNodeType
) const;
135 /** Return a vector of currently active subsets.
137 Needed when rendering a shape, this method provides a
138 vector of subsets currently visible (the range as
139 returned by getEffectiveSubset(), minus the parts that
140 are currently hidden, because displayed by child
143 const VectorOfDocTreeNodes
& getActiveSubsets() const { return maCurrentSubsets
; }
145 /** This enum classifies each action index in the
148 Of interest are, of course, the places where
149 structural shape and/or text elements end. The
150 remainder of the action gets classified as 'noop'
152 enum IndexClassificator
162 CLASS_CHARACTER_CELL_END
165 typedef ::std::vector
< IndexClassificator
> IndexClassificatorVector
;
168 /** Entry for subset shape
170 This struct contains data for every subset shape
171 generated. Note that for a given start/end action
172 index combination, only one subset instance is
173 generated (and reused for subsequent queries).
177 AttributableShapeSharedPtr mpShape
;
178 sal_Int32 mnStartActionIndex
;
179 sal_Int32 mnEndActionIndex
;
181 /// Number of times this subset was queried, and not yet revoked
182 int mnSubsetQueriedCount
;
184 sal_Int32
getHashValue() const
186 // TODO(Q3): That's a hack. We assume that start
187 // index will always be less than 65535 (if this
188 // assumption is violated, hash map performance
189 // will degrade severely)
190 return mnStartActionIndex
*SAL_MAX_INT16
+ mnEndActionIndex
;
193 /// The shape set is ordered according to this method
194 bool operator<(const SubsetEntry
& rOther
) const
196 return getHashValue() < rOther
.getHashValue();
201 typedef ::std::set
< SubsetEntry
> ShapeSet
;
203 void ensureInitializedNodeTree() const;
204 void excludeSubset(sal_Int32 nExcludedStart
, sal_Int32 nExcludedEnd
);
205 void updateSubsets();
206 void initCurrentSubsets();
209 static sal_Int32
implGetNumberOfTreeNodes( const IndexClassificatorVector::const_iterator
& rBegin
,
210 const IndexClassificatorVector::const_iterator
& rEnd
,
211 DocTreeNode::NodeType eNodeType
);
212 DocTreeNode
implGetTreeNode( const IndexClassificatorVector::const_iterator
& rBegin
,
213 const IndexClassificatorVector::const_iterator
& rEnd
,
214 sal_Int32 nNodeIndex
,
215 DocTreeNode::NodeType eNodeType
) const;
217 mutable IndexClassificatorVector maActionClassVector
;
219 /// Metafile to retrieve subset info from
220 ::std::shared_ptr
< GDIMetaFile
> mpMtf
;
222 /// Subset of the metafile represented by this object
223 DocTreeNode maSubset
;
225 /// the list of subset shapes spawned from this one.
226 ShapeSet maSubsetShapes
;
228 /** Current number of subsets to render (calculated from
229 maSubset and mnMin/MaxSubsetActionIndex).
231 Note that this is generally _not_ equivalent to
232 maSubset, as it excludes all active subset children!
234 mutable VectorOfDocTreeNodes maCurrentSubsets
;
236 /// Whether the shape's doc tree has been initialized successfully, or not
237 mutable bool mbNodeTreeInitialized
;
242 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_DRAWSHAPESUBSETTING_HXX
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */