Bump version to 6.4-15
[LibreOffice.git] / slideshow / source / engine / shapes / drawshapesubsetting.hxx
blobf9ea3f4d59818a2b2b8a6d481cc6b00399435635
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 class GDIMetaFile;
28 typedef ::std::shared_ptr< GDIMetaFile > GDIMetaFileSharedPtr;
30 namespace slideshow
32 namespace internal
34 /** This class encapsulates the subsetting aspects of a
35 DrawShape.
37 class DrawShapeSubsetting
39 public:
40 /** Create empty shape subset handling.
42 This method creates a subset handler which contains no
43 subset information. All methods will return default
44 values.
46 @param rMtf
47 Metafile to retrieve subset info from (must have been
48 generated with verbose text comments switched on).
50 DrawShapeSubsetting();
52 /** Create new shape subset handling.
54 @param rShapeSubset
55 The subset this object represents (can be empty, then
56 denoting 'represents a whole shape')
58 @param rMtf
59 Metafile to retrieve subset info from (must have been
60 generated with verbose text comments switched on).
62 DrawShapeSubsetting( const DocTreeNode& rShapeSubset,
63 GDIMetaFileSharedPtr rMtf );
65 /// Forbid copy construction
66 DrawShapeSubsetting(const DrawShapeSubsetting&) = delete;
68 /// Forbid copy assignment
69 DrawShapeSubsetting& operator=(const DrawShapeSubsetting&) = delete;
71 /** Reset metafile.
73 Use this method to completely reset the
74 ShapeSubsetting, with a new metafile. Note that any
75 information previously set will be lost, including
76 added subset shapes!
78 @param rMtf
79 Metafile to retrieve subset info from (must have been
80 generated with verbose text comments switched on).
82 void reset( const ::std::shared_ptr< GDIMetaFile >& rMtf );
84 // Shape subsetting methods
87 /// Return subset node for this shape
88 const DocTreeNode& getSubsetNode () const;
90 /// Get subset shape for given node, if any
91 AttributableShapeSharedPtr getSubsetShape ( const DocTreeNode& rTreeNode ) const;
93 /// Add child subset shape (or increase use count, if already existent)
94 void addSubsetShape ( const AttributableShapeSharedPtr& rShape );
96 /** Revoke subset shape
98 This method revokes a subset shape, decrementing the
99 use count for this subset by one. If the use count
100 reaches zero (i.e. when the number of addSubsetShape()
101 matches the number of revokeSubsetShape() calls for
102 the same subset), the subset entry is removed from the
103 internal list, and subsequent getSubsetShape() calls
104 will return the empty pointer for this subset.
106 @return true, if the subset shape was physically
107 removed from the list (false is returned, when nothing
108 was removed, either because only the use count was
109 decremented, or there was no such subset found, in the
110 first place).
112 bool revokeSubsetShape ( const AttributableShapeSharedPtr& rShape );
115 // Doc tree methods
118 /// Return overall number of nodes for given type
119 sal_Int32 getNumberOfTreeNodes ( DocTreeNode::NodeType eNodeType ) const;
121 /// Return tree node of given index and given type
122 DocTreeNode getTreeNode ( sal_Int32 nNodeIndex,
123 DocTreeNode::NodeType eNodeType ) const;
125 /// Return number of nodes of given type, below parent node
126 sal_Int32 getNumberOfSubsetTreeNodes ( const DocTreeNode& rParentNode,
127 DocTreeNode::NodeType eNodeType ) const;
129 /// Return tree node of given index and given type, relative to parent node
130 DocTreeNode getSubsetTreeNode ( const DocTreeNode& rParentNode,
131 sal_Int32 nNodeIndex,
132 DocTreeNode::NodeType eNodeType ) const;
134 // Helper
137 /** Return a vector of currently active subsets.
139 Needed when rendering a shape, this method provides a
140 vector of subsets currently visible (the range as
141 returned by getEffectiveSubset(), minus the parts that
142 are currently hidden, because displayed by child
143 shapes).
145 const VectorOfDocTreeNodes& getActiveSubsets() const { return maCurrentSubsets; }
147 /** This enum classifies each action index in the
148 metafile.
150 Of interest are, of course, the places where
151 structural shape and/or text elements end. The
152 remainder of the action gets classified as 'noop'
154 enum IndexClassificator
156 CLASS_NOOP,
157 CLASS_SHAPE_START,
158 CLASS_SHAPE_END,
160 CLASS_LINE_END,
161 CLASS_PARAGRAPH_END,
162 CLASS_SENTENCE_END,
163 CLASS_WORD_END,
164 CLASS_CHARACTER_CELL_END
167 typedef ::std::vector< IndexClassificator > IndexClassificatorVector;
169 private:
170 /** Entry for subset shape
172 This struct contains data for every subset shape
173 generated. Note that for a given start/end action
174 index combination, only one subset instance is
175 generated (and reused for subsequent queries).
177 struct SubsetEntry
179 AttributableShapeSharedPtr mpShape;
180 sal_Int32 mnStartActionIndex;
181 sal_Int32 mnEndActionIndex;
183 /// Number of times this subset was queried, and not yet revoked
184 int mnSubsetQueriedCount;
186 sal_Int32 getHashValue() const
188 // TODO(Q3): That's a hack. We assume that start
189 // index will always be less than 65535 (if this
190 // assumption is violated, hash map performance
191 // will degrade severely)
192 return mnStartActionIndex*SAL_MAX_INT16 + mnEndActionIndex;
195 /// The shape set is ordered according to this method
196 bool operator<(const SubsetEntry& rOther) const
198 return getHashValue() < rOther.getHashValue();
203 typedef ::std::set< SubsetEntry > ShapeSet;
205 void ensureInitializedNodeTree() const;
206 void excludeSubset(sal_Int32 nExcludedStart, sal_Int32 nExcludedEnd);
207 void updateSubsets();
208 void initCurrentSubsets();
209 void reset();
211 static sal_Int32 implGetNumberOfTreeNodes( const IndexClassificatorVector::const_iterator& rBegin,
212 const IndexClassificatorVector::const_iterator& rEnd,
213 DocTreeNode::NodeType eNodeType );
214 DocTreeNode implGetTreeNode( const IndexClassificatorVector::const_iterator& rBegin,
215 const IndexClassificatorVector::const_iterator& rEnd,
216 sal_Int32 nNodeIndex,
217 DocTreeNode::NodeType eNodeType ) const;
219 mutable IndexClassificatorVector maActionClassVector;
221 /// Metafile to retrieve subset info from
222 ::std::shared_ptr< GDIMetaFile > mpMtf;
224 /// Subset of the metafile represented by this object
225 DocTreeNode maSubset;
227 /// the list of subset shapes spawned from this one.
228 ShapeSet maSubsetShapes;
230 /** Current number of subsets to render (calculated from
231 maSubset and mnMin/MaxSubsetActionIndex).
233 Note that this is generally _not_ equivalent to
234 maSubset, as it excludes all active subset children!
236 mutable VectorOfDocTreeNodes maCurrentSubsets;
238 /// Whether the shape's doc tree has been initialized successfully, or not
239 mutable bool mbNodeTreeInitialized;
245 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_DRAWSHAPESUBSETTING_HXX
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */