1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewnode.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef CONFIGMGR_VIEWNODE_HXX_
32 #define CONFIGMGR_VIEWNODE_HXX_
38 //-----------------------------------------------------------------------------
39 namespace configuration
41 struct ElementTreeData
;
43 namespace sharable
{ struct GroupNode
; }
44 //-----------------------------------------------------------------------------
47 //-------------------------------------------------------------------------
50 Node(configuration::Tree
* _tree
, configuration::NodeData
* _addr
)
51 : m_tree(_tree
), m_addr(_addr
)
54 Node(configuration::Tree
* _tree
, unsigned int _offs
)
55 : m_tree(_tree
), m_addr( _tree
->nodeData(_offs
))
58 bool is() const { return m_addr
!= 0; }
60 Node
getParent() const;
62 bool isSetNode() const { return is() && data().isSetNode(); }
63 bool isGroupNode() const { return is() && data().isGroupNode(); }
64 bool isValueNode() const { return is() && data().isValueElementNode(); }
67 // configuration::NodeImpl * operator->() const { return &data().nodeImpl(); }
69 configuration::NodeData
& data() const { return *m_addr
; }
71 configuration::NodeImpl
* get_impl() const
72 { return is() ? &data().nodeImpl() : NULL
; }
74 unsigned int get_offset() const
75 { return is() ? m_tree
->nodeOffset( this->data() ) : 0; }
77 configuration::Tree
* tree() const // has a tree
80 sharable::Node
* getAccessRef() const; // has a Node
83 configuration::Tree
* m_tree
; // has a Tree + Accessor
84 configuration::NodeData
* m_addr
; // has a configuration::NodeImpl *
86 //-------------------------------------------------------------------------
87 struct ValueNode
// has/is a Node
92 ValueNode(Node
const& _node
)
96 bool is() const { return m_node
.isValueNode(); }
99 // configuration::ValueElementNodeImpl* operator->() const { return &m_node.data().valueElementImpl(); }
101 configuration::ValueElementNodeImpl
* get_impl() const
102 { return is() ? &m_node
.data().valueElementImpl() : NULL
; }
104 Node
node() const // has a Node
107 configuration::Tree
* tree() const // has a tree
108 { return m_node
.tree(); }
110 //-------------------------------------------------------------------------
111 struct GroupNode
// has/is a Node
116 GroupNode(Node
const& _node
)
120 bool is() const { return m_node
.isGroupNode(); }
122 Node
findChild(rtl::OUString
const& _aName
) const;
123 Node
getFirstChild() const;
124 Node
getNextChild(Node
const& _aAfterNode
) const;
126 // configuration::GroupNodeImpl* operator->() const { return &m_node.data().groupImpl(); }
128 configuration::GroupNodeImpl
* get_impl() const
129 { return is() ? &m_node
.data().groupImpl() : NULL
; }
131 Node
node() const // has a Node
134 configuration::Tree
* tree() const // has a tree
135 { return m_node
.tree(); }
137 sharable::GroupNode
* getAccess() const; // has a GroupNode
139 //-------------------------------------------------------------------------
140 struct SetNode
// has/is a Node
145 SetNode(Node
const& _node
)
149 bool is() const { return m_node
.isSetNode(); }
151 // configuration::SetNodeImpl* operator->() const { return &m_node.data().setImpl(); }
153 configuration::SetNodeImpl
* get_impl() const
154 { return is() ? &m_node
.data().setImpl() : 0; }
156 Node
node() const // has a Node
159 configuration::Tree
* tree() const // has a tree
160 { return m_node
.tree(); }
162 sharable::SetNode
* getAccess() const; // has a SetNode
164 //-------------------------------------------------------------------------
166 Node
getRootNode(configuration::Tree
* _aTree
)
168 return Node(_aTree
,_aTree
->nodeData(configuration::Tree::ROOT
));
171 //-------------------------------------------------------------------------
173 rtl::OUString
getSimpleRootName(configuration::Tree
* _aTree
)
175 return _aTree
->getSimpleRootName();
178 //-------------------------------------------------------------------------
180 bool isValidNode(Node
const & _aNode
)
182 configuration::Tree
* pTreeData
= _aNode
.tree();
183 return pTreeData
->isValidNode(_aNode
.get_offset());
186 //-------------------------------------------------------------------------
188 rtl::OUString
getSimpleNodeName(Node
const & _aNode
)
190 configuration::Tree
* pTreeData
= _aNode
.tree();
191 return pTreeData
->getSimpleNodeName(_aNode
.get_offset());
194 //-------------------------------------------------------------------------
196 rtl::Reference
< view::ViewStrategy
> getViewBehavior(configuration::Tree
* _aTree
);
197 //-------------------------------------------------------------------------
199 //-----------------------------------------------------------------------------
201 //-----------------------------------------------------------------------------
203 #endif // CONFIGMGR_VIEWNODE_HXX_