Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_DRAWSHAPESUBSETTING_HXX
21 : #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_DRAWSHAPESUBSETTING_HXX
22 :
23 : #include <boost/shared_ptr.hpp>
24 : #include <boost/noncopyable.hpp>
25 :
26 : #include "doctreenode.hxx"
27 : #include "attributableshape.hxx"
28 :
29 :
30 : class GDIMetaFile;
31 :
32 : namespace slideshow
33 : {
34 : namespace internal
35 : {
36 : /** This class encapsulates the subsetting aspects of a
37 : DrawShape.
38 : */
39 0 : class DrawShapeSubsetting : private boost::noncopyable
40 : {
41 : public:
42 : /** Create empty shape subset handling.
43 :
44 : This method creates a subset handler which contains no
45 : subset information. All methods will return default
46 : values.
47 :
48 : @param rMtf
49 : Metafile to retrieve subset info from (must have been
50 : generated with verbose text comments switched on).
51 : */
52 : DrawShapeSubsetting();
53 :
54 : /** Create new shape subset handling.
55 :
56 : @param rShapeSubset
57 : The subset this object represents (can be empty, then
58 : denoting 'represents a whole shape')
59 :
60 : @param rMtf
61 : Metafile to retrieve subset info from (must have been
62 : generated with verbose text comments switched on).
63 : */
64 : DrawShapeSubsetting( const DocTreeNode& rShapeSubset,
65 : const ::boost::shared_ptr< GDIMetaFile >& rMtf );
66 :
67 : /** Reset metafile.
68 :
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
72 : added subset shapes!
73 :
74 : @param rMtf
75 : Metafile to retrieve subset info from (must have been
76 : generated with verbose text comments switched on).
77 : */
78 : void reset( const ::boost::shared_ptr< GDIMetaFile >& rMtf );
79 :
80 : // Shape subsetting methods
81 :
82 :
83 : /// Return subset node for this shape
84 : DocTreeNode getSubsetNode () const;
85 :
86 : /// Get subset shape for given node, if any
87 : AttributableShapeSharedPtr getSubsetShape ( const DocTreeNode& rTreeNode ) const;
88 :
89 : /// Add child subset shape (or increase use count, if already existent)
90 : void addSubsetShape ( const AttributableShapeSharedPtr& rShape );
91 :
92 : /** Revoke subset shape
93 :
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.
101 :
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
106 : first place).
107 : */
108 : bool revokeSubsetShape ( const AttributableShapeSharedPtr& rShape );
109 :
110 :
111 : // Doc tree methods
112 :
113 :
114 : /// Return overall number of nodes for given type
115 : sal_Int32 getNumberOfTreeNodes ( DocTreeNode::NodeType eNodeType ) const;
116 :
117 : /// Return tree node of given index and given type
118 : DocTreeNode getTreeNode ( sal_Int32 nNodeIndex,
119 : DocTreeNode::NodeType eNodeType ) const;
120 :
121 : /// Return number of nodes of given type, below parent node
122 : sal_Int32 getNumberOfSubsetTreeNodes ( const DocTreeNode& rParentNode,
123 : DocTreeNode::NodeType eNodeType ) const;
124 :
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;
129 :
130 : // Helper
131 :
132 :
133 : /** Return a vector of currently active subsets.
134 :
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
139 : shapes).
140 : */
141 0 : const VectorOfDocTreeNodes& getActiveSubsets() const { return maCurrentSubsets; }
142 :
143 : /** This enum classifies each action index in the
144 : metafile.
145 :
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'
149 : */
150 : enum IndexClassificator
151 : {
152 : CLASS_NOOP,
153 : CLASS_SHAPE_START,
154 : CLASS_SHAPE_END,
155 :
156 : CLASS_LINE_END,
157 : CLASS_PARAGRAPH_END,
158 : CLASS_SENTENCE_END,
159 : CLASS_WORD_END,
160 : CLASS_CHARACTER_CELL_END
161 : };
162 :
163 : typedef ::std::vector< IndexClassificator > IndexClassificatorVector;
164 :
165 : private:
166 : /** Entry for subset shape
167 :
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).
172 : */
173 0 : struct SubsetEntry
174 : {
175 : AttributableShapeSharedPtr mpShape;
176 : sal_Int32 mnStartActionIndex;
177 : sal_Int32 mnEndActionIndex;
178 :
179 : /// Number of times this subset was queried, and not yet revoked
180 : int mnSubsetQueriedCount;
181 :
182 0 : sal_Int32 getHashValue() const
183 : {
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 0 : return mnStartActionIndex*SAL_MAX_INT16 + mnEndActionIndex;
189 : }
190 :
191 : /// The shape set is ordered according to this method
192 0 : bool operator<(const SubsetEntry& rOther) const
193 : {
194 0 : return getHashValue() < rOther.getHashValue();
195 : }
196 :
197 : };
198 :
199 : typedef ::std::set< SubsetEntry > ShapeSet;
200 :
201 : void ensureInitializedNodeTree() const;
202 : void updateSubsetBounds( const SubsetEntry& rSubsetEntry );
203 : void updateSubsets();
204 : void initCurrentSubsets();
205 : void reset();
206 :
207 : sal_Int32 implGetNumberOfTreeNodes( const IndexClassificatorVector::const_iterator& rBegin,
208 : const IndexClassificatorVector::const_iterator& rEnd,
209 : DocTreeNode::NodeType eNodeType ) const;
210 : DocTreeNode implGetTreeNode( const IndexClassificatorVector::const_iterator& rBegin,
211 : const IndexClassificatorVector::const_iterator& rEnd,
212 : sal_Int32 nNodeIndex,
213 : DocTreeNode::NodeType eNodeType ) const;
214 :
215 : mutable IndexClassificatorVector maActionClassVector;
216 :
217 : /// Metafile to retrieve subset info from
218 : ::boost::shared_ptr< GDIMetaFile > mpMtf;
219 :
220 : /// Subset of the metafile represented by this object
221 : DocTreeNode maSubset;
222 :
223 : /// the list of subset shapes spawned from this one.
224 : ShapeSet maSubsetShapes;
225 :
226 : /// caches minimal subset index from maSubsetShapes
227 : sal_Int32 mnMinSubsetActionIndex;
228 :
229 : /// caches maximal subset index from maSubsetShapes
230 : sal_Int32 mnMaxSubsetActionIndex;
231 :
232 : /** Current number of subsets to render (calculated from
233 : maSubset and mnMin/MaxSubsetActionIndex).
234 :
235 : Note that this is generally _not_ equivalent to
236 : maSubset, as it excludes all active subset children!
237 : */
238 : mutable VectorOfDocTreeNodes maCurrentSubsets;
239 :
240 : /// Whether the shape's doc tree has been initialized successfully, or not
241 : mutable bool mbNodeTreeInitialized;
242 : };
243 :
244 : }
245 : }
246 :
247 : #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SHAPES_DRAWSHAPESUBSETTING_HXX
248 :
249 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|