Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / shapes / drawshapesubsetting.hxx
blob68e541bf7fb110f7138926739421118670f68bf2
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;
29 namespace slideshow
31 namespace internal
33 /** This class encapsulates the subsetting aspects of a
34 DrawShape.
36 class DrawShapeSubsetting
38 public:
39 /** Create empty shape subset handling.
41 This method creates a subset handler which contains no
42 subset information. All methods will return default
43 values.
45 @param rMtf
46 Metafile to retrieve subset info from (must have been
47 generated with verbose text comments switched on).
49 DrawShapeSubsetting();
51 /** Create new shape subset handling.
53 @param rShapeSubset
54 The subset this object represents (can be empty, then
55 denoting 'represents a whole shape')
57 @param rMtf
58 Metafile to retrieve subset info from (must have been
59 generated with verbose text comments switched on).
61 DrawShapeSubsetting( const DocTreeNode& rShapeSubset,
62 const ::std::shared_ptr< GDIMetaFile >& rMtf );
64 /// Forbid copy construction
65 DrawShapeSubsetting(const DrawShapeSubsetting&) = delete;
67 /// Forbid copy assignment
68 DrawShapeSubsetting& operator=(const DrawShapeSubsetting&) = delete;
70 /** Reset metafile.
72 Use this method to completely reset the
73 ShapeSubsetting, with a new metafile. Note that any
74 information previously set will be lost, including
75 added subset shapes!
77 @param rMtf
78 Metafile to retrieve subset info from (must have been
79 generated with verbose text comments switched on).
81 void reset( const ::std::shared_ptr< GDIMetaFile >& rMtf );
83 // Shape subsetting methods
86 /// Return subset node for this shape
87 const DocTreeNode& getSubsetNode () const;
89 /// Get subset shape for given node, if any
90 AttributableShapeSharedPtr getSubsetShape ( const DocTreeNode& rTreeNode ) const;
92 /// Add child subset shape (or increase use count, if already existent)
93 void addSubsetShape ( const AttributableShapeSharedPtr& rShape );
95 /** Revoke subset shape
97 This method revokes a subset shape, decrementing the
98 use count for this subset by one. If the use count
99 reaches zero (i.e. when the number of addSubsetShape()
100 matches the number of revokeSubsetShape() calls for
101 the same subset), the subset entry is removed from the
102 internal list, and subsequent getSubsetShape() calls
103 will return the empty pointer for this subset.
105 @return true, if the subset shape was physically
106 removed from the list (false is returned, when nothing
107 was removed, either because only the use count was
108 decremented, or there was no such subset found, in the
109 first place).
111 bool revokeSubsetShape ( const AttributableShapeSharedPtr& rShape );
114 // Doc tree methods
117 /// Return overall number of nodes for given type
118 sal_Int32 getNumberOfTreeNodes ( DocTreeNode::NodeType eNodeType ) const;
120 /// Return tree node of given index and given type
121 DocTreeNode getTreeNode ( sal_Int32 nNodeIndex,
122 DocTreeNode::NodeType eNodeType ) const;
124 /// Return number of nodes of given type, below parent node
125 sal_Int32 getNumberOfSubsetTreeNodes ( const DocTreeNode& rParentNode,
126 DocTreeNode::NodeType eNodeType ) const;
128 /// Return tree node of given index and given type, relative to parent node
129 DocTreeNode getSubsetTreeNode ( const DocTreeNode& rParentNode,
130 sal_Int32 nNodeIndex,
131 DocTreeNode::NodeType eNodeType ) const;
133 // Helper
136 /** Return a vector of currently active subsets.
138 Needed when rendering a shape, this method provides a
139 vector of subsets currently visible (the range as
140 returned by getEffectiveSubset(), minus the parts that
141 are currently hidden, because displayed by child
142 shapes).
144 const VectorOfDocTreeNodes& getActiveSubsets() const { return maCurrentSubsets; }
146 /** This enum classifies each action index in the
147 metafile.
149 Of interest are, of course, the places where
150 structural shape and/or text elements end. The
151 remainder of the action gets classified as 'noop'
153 enum IndexClassificator
155 CLASS_NOOP,
156 CLASS_SHAPE_START,
157 CLASS_SHAPE_END,
159 CLASS_LINE_END,
160 CLASS_PARAGRAPH_END,
161 CLASS_SENTENCE_END,
162 CLASS_WORD_END,
163 CLASS_CHARACTER_CELL_END
166 typedef ::std::vector< IndexClassificator > IndexClassificatorVector;
168 private:
169 /** Entry for subset shape
171 This struct contains data for every subset shape
172 generated. Note that for a given start/end action
173 index combination, only one subset instance is
174 generated (and reused for subsequent queries).
176 struct SubsetEntry
178 AttributableShapeSharedPtr mpShape;
179 sal_Int32 mnStartActionIndex;
180 sal_Int32 mnEndActionIndex;
182 /// Number of times this subset was queried, and not yet revoked
183 int mnSubsetQueriedCount;
185 sal_Int32 getHashValue() const
187 // TODO(Q3): That's a hack. We assume that start
188 // index will always be less than 65535 (if this
189 // assumption is violated, hash map performance
190 // will degrade severely)
191 return mnStartActionIndex*SAL_MAX_INT16 + mnEndActionIndex;
194 /// The shape set is ordered according to this method
195 bool operator<(const SubsetEntry& rOther) const
197 return getHashValue() < rOther.getHashValue();
202 typedef ::std::set< SubsetEntry > ShapeSet;
204 void ensureInitializedNodeTree() const;
205 void excludeSubset(sal_Int32 nExcludedStart, sal_Int32 nExcludedEnd);
206 void updateSubsets();
207 void initCurrentSubsets();
208 void reset();
210 static sal_Int32 implGetNumberOfTreeNodes( const IndexClassificatorVector::const_iterator& rBegin,
211 const IndexClassificatorVector::const_iterator& rEnd,
212 DocTreeNode::NodeType eNodeType );
213 DocTreeNode implGetTreeNode( const IndexClassificatorVector::const_iterator& rBegin,
214 const IndexClassificatorVector::const_iterator& rEnd,
215 sal_Int32 nNodeIndex,
216 DocTreeNode::NodeType eNodeType ) const;
218 mutable IndexClassificatorVector maActionClassVector;
220 /// Metafile to retrieve subset info from
221 ::std::shared_ptr< GDIMetaFile > mpMtf;
223 /// Subset of the metafile represented by this object
224 DocTreeNode maSubset;
226 /// the list of subset shapes spawned from this one.
227 ShapeSet maSubsetShapes;
229 /** Current number of subsets to render (calculated from
230 maSubset and mnMin/MaxSubsetActionIndex).
232 Note that this is generally _not_ equivalent to
233 maSubset, as it excludes all active subset children!
235 mutable VectorOfDocTreeNodes maCurrentSubsets;
237 /// Whether the shape's doc tree has been initialized successfully, or not
238 mutable bool mbNodeTreeInitialized;
244 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_DRAWSHAPESUBSETTING_HXX
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */