1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_SLIDESHOW_DOCTREENODE_HXX
25 #define INCLUDED_SLIDESHOW_DOCTREENODE_HXX
26 
27 #include <sal/types.h>
28 #include <vector>
29 
30 
31 /* Definition of DocTreeNode class */
32 
33 namespace slideshow
34 {
35     namespace internal
36     {
37 
38         /** This class represents kind of a DOM tree node for shape
39             text
40 
41 			In order to animate subsets of shape text, we need
42 			information about the logical and formatting structure of
43 			that text (lines, paragraphs, words etc.). This is
44 			represented in a tree structure, with DocTreeNodes as the
45 			nodes. Instances of this class can be queried from the
46 			DocTreeNodeSupplier interface.
47 
48 			This class has nothing to do with the Draw document tree.
49          */
50         class DocTreeNode
51         {
52         public:
53             /// Type of shape entity represented by this node
54             enum NodeType
55             {
56                 NODETYPE_INVALID=0,
57 
58                 /// This node represents a full shape
59                 NODETYPE_FORMATTING_SHAPE=1,
60                 /// This node represents a line
61                 NODETYPE_FORMATTING_LINE=2,
62 
63                 /// This node represents a full shape
64                 NODETYPE_LOGICAL_SHAPE=128,
65                 /// This node represents a paragraph
66                 NODETYPE_LOGICAL_PARAGRAPH=129,
67                 /// This node represents a sentence
68                 NODETYPE_LOGICAL_SENTENCE=130,
69                 /// This node represents a word
70                 NODETYPE_LOGICAL_WORD=131,
71                 /// This node represents a character
72                 NODETYPE_LOGICAL_CHARACTER_CELL=132
73             };
74 
75             // classificators for above text entity types
isLogicalNodeType(NodeType eType)76             static bool isLogicalNodeType( NodeType eType ) { return eType > 127; }
isFormattingNodeType(NodeType eType)77             static bool isFormattingNodeType( NodeType eType ) { return eType > 0 && eType < 128; }
78 
79             /** Create empty tree node
80              */
DocTreeNode()81             DocTreeNode() :
82                 mnStartIndex(-1),
83                 mnEndIndex(-1),
84                 meType(NODETYPE_INVALID)
85             {
86             }
87 
88             /** Create tree node from start and end index.
89 
90             	Create a tree node for the given range and type.
91 
92                 @param nStartIndex
93                 Start index
94 
95                 @param nEndIndex
96                 End index (exclusive)
97 
98                 @param eType
99                 Node type
100              */
DocTreeNode(sal_Int32 nStartIndex,sal_Int32 nEndIndex,NodeType eType)101             DocTreeNode( sal_Int32 nStartIndex,
102                          sal_Int32 nEndIndex,
103                          NodeType  eType ) :
104                 mnStartIndex(nStartIndex),
105                 mnEndIndex(nEndIndex),
106                 meType(eType)
107             {
108             }
109 
isEmpty() const110             bool 				isEmpty() const { return mnStartIndex == mnEndIndex; }
111 
getStartIndex() const112             sal_Int32 			getStartIndex() const { return mnStartIndex; }
getEndIndex() const113             sal_Int32 			getEndIndex() const { return mnEndIndex; }
setStartIndex(sal_Int32 nIndex)114             void 				setStartIndex( sal_Int32 nIndex ) { mnStartIndex = nIndex; }
setEndIndex(sal_Int32 nIndex)115             void 				setEndIndex( sal_Int32 nIndex ) { mnEndIndex = nIndex; }
116 
getType() const117             NodeType			getType() const { return meType; }
118 
reset()119             void                reset()
120             {
121                 mnStartIndex = -1;
122                 mnEndIndex   = -1;
123                 meType = NODETYPE_INVALID;
124             }
125 
126         private:
127             sal_Int32	mnStartIndex;
128             sal_Int32	mnEndIndex;
129             NodeType 	meType;
130 
131         };
132 
133         typedef ::std::vector< DocTreeNode > VectorOfDocTreeNodes;
134     }
135 }
136 
137 #endif /* INCLUDED_SLIDESHOW_DOCTREENODE_HXX */
138