merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / treemgr / nodeimplobj.hxx
blob4aa2431958311c9ffa3ff927132aff85dff20e63
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: nodeimplobj.hxx,v $
10 * $Revision: 1.16 $
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_NODEIMPLOBJECTS_HXX_
32 #define CONFIGMGR_NODEIMPLOBJECTS_HXX_
34 #include "sal/config.h"
36 #include "salhelper/simplereferenceobject.hxx"
38 #include "node.hxx"
39 #include "nodeimpl.hxx"
40 #include "groupnodeimpl.hxx"
41 #include "setnodeimpl.hxx"
42 #include "valuenodeimpl.hxx"
43 #include "utility.hxx"
45 #ifndef INCLUDED_MEMORY
46 #include <memory>
47 #define INCLUDED_MEMORY
48 #endif
50 namespace configmgr
52 namespace configuration
54 //-----------------------------------------------------------------------------
56 // Specific types of nodes for direct or read only access
57 //-----------------------------------------------------------------------------
59 // Value Nodes
60 //-----------------------------------------------------------------------------
62 class ValueMemberNode::DeferredImpl : public salhelper::SimpleReferenceObject
64 sharable::ValueNode * m_valueNode;
66 com::sun::star::uno::Any m_aNewValue;
67 bool m_bToDefault;
68 bool m_bChange;
69 public:
70 explicit DeferredImpl(sharable::ValueNode * valueNode);
72 /// does this wrap a change
73 bool isChange() const { return m_bChange; }
75 /// retrieve the underlying (original) node
76 sharable::ValueNode * getOriginalNode() const
77 { return m_valueNode; }
79 /// Does this node change to default
80 bool isToDefault() const { return m_bToDefault; }
82 /// retrieve the current value of this node
83 com::sun::star::uno::Any getNewValue() const { return m_aNewValue; }
85 /// Set this node to a new value
86 void setValue(com::sun::star::uno::Any const& aNewValue, sharable::ValueNode * originalNode);
88 /// Set this node to assume its default value
89 void setValueToDefault(sharable::ValueNode * originalNode);
91 public:
92 // commit protocol
93 std::auto_ptr<ValueChange> preCommitChange();
94 void finishCommit(ValueChange& rChange);
95 void revertCommit(ValueChange& rChange);
96 void failedCommit(ValueChange& rChange);
98 ValueChangeImpl* collectChange();
99 ValueChangeImpl* adjustToChange(ValueChange const& rExternalChange);
101 // notification protocol
102 void adjustToChange(NodeChangesInformation& rLocalChange, ValueChange const& rExternalChange, Tree& rParentTree, unsigned int nParentPos, rtl::OUString const& aName);
104 //-----------------------------------------------------------------------------
107 //-----------------------------------------------------------------------------
109 // Group Nodes
110 //-----------------------------------------------------------------------------
112 class DeferredGroupNodeImpl : public GroupNodeImpl
114 public:
115 explicit
116 DeferredGroupNodeImpl(sharable::GroupNode * const& _aNodeRef);
117 explicit
118 DeferredGroupNodeImpl(sharable::GroupNode * const& _aNewAddress, GroupNodeImpl& rOriginal);
120 ~DeferredGroupNodeImpl();
122 public:
123 // commit protocol
124 std::auto_ptr<SubtreeChange> preCommitValueChanges();
125 void finishCommit(SubtreeChange& rChange);
126 void revertCommit(SubtreeChange& rChange);
127 void failedCommit(SubtreeChange& rChange);
129 void collectValueChanges(NodeChanges& rChanges, Tree* pParent, unsigned int nNode) const;
131 public:
132 // data access
133 bool hasChanges() const;
134 void markChanged();
136 rtl::Reference<ValueMemberNode::DeferredImpl> findValueChange(rtl::OUString const& aName);
138 using GroupNodeImpl::makeValueMember;
139 ValueMemberNode makeValueMember(rtl::OUString const& _aName, bool _bForUpdate);
141 private:
142 typedef std::map< rtl::OUString, rtl::Reference<ValueMemberNode::DeferredImpl> > MemberChanges;
144 MemberChanges m_aChanges;
146 //-----------------------------------------------------------------------------
148 // Set nodes
149 //-----------------------------------------------------------------------------
151 class DeferredSetNodeImpl : public SetNodeImpl
153 public:
154 explicit
155 DeferredSetNodeImpl(sharable::SetNode * const& _aNodeRef, Template* pTemplate);
157 public:
158 bool hasChanges() const;
159 void markChanged();
160 void collectElementChanges(NodeChanges& rChanges) const;
162 public:
163 std::auto_ptr<SubtreeChange> preCommitChanges(std::vector< rtl::Reference<ElementTree> >& _rRemovedElements);
164 void failedCommit(SubtreeChange& rChanges);
165 void finishCommit(SubtreeChange& rChanges);
166 void revertCommit(SubtreeChange& rChanges);
168 void insertNewElement(rtl::OUString const& aName, ElementTreeData const& aNewElement);
169 void removeOldElement(rtl::OUString const& aName);
170 // Base Overrideables
171 private:
172 // NodeImpl implementation
173 virtual bool doIsEmpty() const;
174 virtual ElementTree* doFindElement(rtl::OUString const& aName) ;
175 virtual SetNodeVisitor::Result doDispatchToElements(SetNodeVisitor& aVisitor);
177 virtual void doDifferenceToDefaultState(SubtreeChange& _rChangeToDefault, ISubtree& _rDefaultTree);
179 virtual SetElementChangeImpl* doAdjustToAddedElement(rtl::OUString const& aName, AddNode const& aAddNodeChange, ElementTreeData const & aNewElement);
180 virtual SetElementChangeImpl* doAdjustToRemovedElement(rtl::OUString const& aName, RemoveNode const& aRemoveNodeChange);
182 virtual SetElementChangeImpl* doAdjustChangedElement(NodeChangesInformation& rLocalChanges, rtl::OUString const& aName, Change const& aChange);
184 virtual void doTransferElements(ElementSet& rReplacement);
186 // Implementation
187 private:
188 void rebuildElement(rtl::OUString const& aName, ElementTreeData const& _aElement);
190 private:
191 ElementSet m_aChangedData;
192 bool m_bChanged;
193 bool m_bDefault;
195 //-----------------------------------------------------------------------------
197 //-----------------------------------------------------------------------------
201 #endif // CONFIGMGR_NODEIMPLOBJECTS_HXX_