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: nodechangeimpl.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_CONFIGCHANGEIMPL_HXX_
32 #define CONFIGMGR_CONFIGCHANGEIMPL_HXX_
34 #include "configexcept.hxx"
35 #include "configpath.hxx"
36 #include "viewaccess.hxx"
37 #include <rtl/ref.hxx>
38 #include <salhelper/simplereferenceobject.hxx>
39 #include "utility.hxx"
41 #ifndef INCLUDED_VECTOR
43 #define INCLUDED_VECTOR
46 #ifndef INCLUDED_MEMORY
48 #define INCLUDED_MEMORY
55 namespace view
{ class ViewTreeAccess
; struct Node
; struct GroupNode
; struct SetNode
; }
56 //-----------------------------------------------------------------------------
57 namespace configuration
59 //-----------------------------------------------------------------------------
61 class ValueMemberNode
;
62 class ValueMemberUpdate
;
63 //-----------------------------------------------------------------------------
65 class NodeChangeLocation
;
66 class NodeChangeInformation
;
67 //-----------------------------------------------------------------------------
68 struct ElementTreeChange
70 Path::Component m_aElementName
;
71 rtl::Reference
<ElementTree
> m_aAddedElement
;
72 rtl::Reference
<ElementTree
> m_aRemovedElement
;
75 Path::Component
const& _aElementName
,
76 rtl::Reference
<ElementTree
> const& _aAddedElement
,
77 rtl::Reference
<ElementTree
> const& _aRemovedElement
79 : m_aElementName(_aElementName
)
80 , m_aAddedElement(_aAddedElement
)
81 , m_aRemovedElement(_aRemovedElement
)
86 return !!(m_aAddedElement
!= m_aRemovedElement
);
89 //-----------------------------------------------------------------------------
92 /// represents a node position in some tree
94 : public salhelper::SimpleReferenceObject
98 NodeChangeImpl(bool bNoCheck
= false);
101 // related/affected nodes and trees
102 /// the tree within which the change occurs
103 rtl::Reference
<Tree
> getTargetTree() const;
105 /// the node that is affected by the change
106 unsigned int getTargetNode() const;
109 /// setup the 'target' node that is to be affected or changed
110 void setTarget(rtl::Reference
<Tree
> const& _aAffectedTree
, unsigned int _nAffectedNode
);
111 void setTarget(view::Node _aAffectedNode
);
113 view::ViewTreeAccess
getTargetView();
115 // getting information
116 /*static const sal_uInt32*/ enum { scCommonBase
= ~0u };
118 /// checks, if this represents an actual change - with or without requiring a preceding test
119 bool isChange(bool bAllowUntested
) const;
121 /// return the number of distict changes in this object
122 sal_uInt32
getChangeDataCount() const;
124 /// fills in base change location, returns whether it is set
125 bool fillChangeLocation(NodeChangeLocation
& rChange
, sal_uInt32 _ix
= scCommonBase
) const;
127 /// fills in pre- and post-change values, returns whether they may differ
128 bool fillChangeData(NodeChangeData
& rChange
, sal_uInt32 _ix
) const;
130 /// fills in change location and values, returns whether data may be changed
131 bool fillChangeInfo(NodeChangeInformation
& rChange
, sal_uInt32 _ix
) const;
133 /// test whether this really is a change to the stored 'changing' node
136 /// apply this change to the stored 'changing' node
140 /// virtual hooks for some of the public methods
141 /// return the number of distict changes in this object
142 sal_uInt32
doGetChangeCount() const;
144 /// the path from base to 'changing' node
145 virtual RelativePath
doGetChangingNodePath(sal_uInt32 _ix
) const = 0;
147 /// is the change really affecting a child (or children) of the affected node (true for values)
148 virtual bool doIsChangingSubnode() const = 0;
150 /// checks, if this represents an actual change (given whether the change has been applied or not)
151 virtual bool doIsChange() const = 0;
153 /// fills in pre- and post-change values, returns wether they differ
154 virtual bool doFillChange(NodeChangeData
& rChange
, sal_uInt32 _ix
) const = 0;
156 /// dry-check whether this is a change
157 virtual void doTest( view::Node
const& rTarget
) = 0;
158 /// do apply the actual change
159 virtual void doApply( view::Node
const& rTarget
) = 0;
162 rtl::Reference
<Tree
> m_aAffectedTree
;
163 unsigned int m_nAffectedNode
;
167 view::Node
implGetTarget();
169 //-----------------------------------------------------------------------------
171 /// represents a node position in some tree
172 class ValueChangeImpl
173 : public NodeChangeImpl
175 rtl::OUString m_aName
;
176 com::sun::star::uno::Any m_aNewValue
;
177 com::sun::star::uno::Any m_aOldValue
;
179 explicit ValueChangeImpl();
180 explicit ValueChangeImpl(com::sun::star::uno::Any
const& aNewValue
);
181 explicit ValueChangeImpl(com::sun::star::uno::Any
const& aNewValue
, com::sun::star::uno::Any
const& aOldValue
);
185 /// setup the 'target' node that is to be affected or changed
186 void setTarget(view::GroupNode
const& _aParentNode
, rtl::OUString
const& sNodeName
);
187 void setTarget(rtl::Reference
<Tree
> const& aAffectedTree
, unsigned int nParentNode
, rtl::OUString
const& sNodeName
);
190 /// get the name of the value
191 rtl::OUString
getValueName() const { return m_aName
; }
193 /// get the pre-change value (if known)
194 com::sun::star::uno::Any
getOldValue() const { return m_aOldValue
; }
195 /// get the post-change value (if known)
196 com::sun::star::uno::Any
getNewValue() const { return m_aNewValue
; }
199 using NodeChangeImpl::setTarget
;
200 // override information items
201 /// the path from base to 'affected' node - here is the name of the changing node
202 virtual RelativePath
doGetChangingNodePath(sal_uInt32 _ix
) const;
204 /// is the change really affecting a child of the affected node (true here)
205 virtual bool doIsChangingSubnode() const;
208 // override change information items
209 /// checks, if this represents an actual change (given whether the change has been applied or not)
210 virtual bool doIsChange() const;
212 /// fills in pre- and post-change values, returns wether they differ
213 virtual bool doFillChange(NodeChangeData
& rChange
, sal_uInt32 _ix
) const = 0;
216 // override apply functionality
217 /// retrieve the old value from the given node
218 virtual void doTest( view::Node
const& rTarget
);
219 /// do apply the actual change
220 virtual void doApply( view::Node
const& rTarget
);
224 /// extract the pre-change value from the target context
225 virtual void preCheckValue(ValueMemberNode
& rNode
, com::sun::star::uno::Any
& rOld
, com::sun::star::uno::Any
& rNew
);
226 /// extract the post-change value from the target context
227 virtual void postCheckValue(ValueMemberNode
& rNode
, com::sun::star::uno::Any
& rNew
);
228 /// apply the new value to the target context
229 virtual void doApplyChange(ValueMemberUpdate
& rNode
) = 0;
231 //-----------------------------------------------------------------------------
233 /// represents setting a value node to a given value
234 class ValueReplaceImpl
235 : public ValueChangeImpl
238 explicit ValueReplaceImpl(com::sun::star::uno::Any
const& aNewValue
);
239 explicit ValueReplaceImpl(com::sun::star::uno::Any
const& aNewValue
, com::sun::star::uno::Any
const& aOldValue
);
242 // implement: set the target to the new value
243 virtual void doApplyChange( ValueMemberUpdate
& rNode
);
245 /// fills in pre- and post-change values, returns wether they differ
246 virtual bool doFillChange(NodeChangeData
& rChange
, sal_uInt32 _ix
) const;
248 // friend class SetReplaceValueImpl;
250 //-----------------------------------------------------------------------------
252 /// represents resetting a value node to its default value
254 : public ValueChangeImpl
256 bool m_bTargetIsDefault
;
258 explicit ValueResetImpl();
259 explicit ValueResetImpl(com::sun::star::uno::Any
const& aNewValue
, com::sun::star::uno::Any
const& aOldValue
);
262 // override: set the new value as well and check the default state
263 virtual void preCheckValue(ValueMemberNode
& rNode
, com::sun::star::uno::Any
& rOld
, com::sun::star::uno::Any
& rNew
);
265 /// checks, if this represents an actual change (given whether the change has been applied or not)
266 virtual bool doIsChange() const;
268 // implement: set the target to default
269 virtual void doApplyChange( ValueMemberUpdate
& rNode
);
271 /// fills in pre- and post-change values, returns wether they differ
272 virtual bool doFillChange(NodeChangeData
& rChange
, sal_uInt32 _ix
) const;
274 //-----------------------------------------------------------------------------
277 /// represents a change to a set (as a container)
279 : public NodeChangeImpl
282 explicit SetChangeImpl(bool bNoCheck
= false);
284 using NodeChangeImpl::setTarget
;
287 /// virtual hooks for some of the public methods
288 /// is the change really affecting a child of the affected node (false here)
289 virtual bool doIsChangingSubnode() const;
291 //-----------------------------------------------------------------------------
292 class SetElementFactory
;
294 /// represents setting to its default state a set (as a container)
296 : public SetChangeImpl
298 std::auto_ptr
<ISubtree
> m_aDefaultData
;
299 SetElementFactory
& m_rElementFactory
;
300 std::vector
< ElementTreeChange
> m_aTreeChanges
;
302 explicit SetResetImpl(
303 SetElementFactory
& _rElementFactory
,
304 std::auto_ptr
<ISubtree
> _pDefaultData
,
305 bool _bNoCheck
= false);
310 /// virtual hooks for some of the public methods
311 /// retrieve the count of elements affected
312 sal_uInt32
doGetChangeCount() const;
314 /// the path from base to 'affected' node
315 virtual RelativePath
doGetChangingNodePath(sal_uInt32 _ix
) const;
317 /// checks, if this represents an actual change (given whether the change has been applied or not)
318 virtual bool doIsChange() const;
319 /// fills in pre- and post-change values, returns wether they differ
320 virtual bool doFillChange(NodeChangeData
& rChange
, sal_uInt32 _ix
) const;
323 /// retrieve the old value from the given node
324 virtual void doTest( view::Node
const& rTarget
);
325 /// do apply the actual change
326 virtual void doApply( view::Node
const& rTarget
);
328 //-----------------------------------------------------------------------------
330 /// represents a change to an element of a set (as a container)
331 class SetElementChangeImpl
332 : public SetChangeImpl
334 Path::Component m_aName
;
336 explicit SetElementChangeImpl(Path::Component
const& aName
, bool bNoCheck
= false);
338 /// the name of the element being changed
339 Path::Component
getFullElementName() const { return m_aName
; }
341 /// the name of the element being changed
342 rtl::OUString
getElementName() const { return m_aName
.getName(); }
345 /// virtual hooks for some of the public methods
346 /// the path from base to 'affected' node - use element name
347 virtual RelativePath
doGetChangingNodePath(sal_uInt32 _ix
) const;
349 /// retrieve the old value from the given node
350 virtual void doTest( view::Node
const& rTarget
);
351 /// do apply the actual change
352 virtual void doApply( view::Node
const& rTarget
);
355 /// new overridable: retrieve the old value from a properly typed node
356 virtual void doTestElement(view::SetNode
const& _aNode
, rtl::OUString
const& aName
) = 0;
357 /// new overridable: apply the change to a properly typed node
358 virtual void doApplyToElement(view::SetNode
const& _aNode
, rtl::OUString
const& aName
) = 0;
360 //-----------------------------------------------------------------------------
362 /// represents an insertion into a set of trees
364 : public SetElementChangeImpl
366 rtl::Reference
<ElementTree
> m_aNewTree
;
368 explicit SetInsertImpl(Path::Component
const& aName
, rtl::Reference
<ElementTree
> const& aNewTree
, bool bNoCheck
= false);
371 /// checks, if this represents an actual change (given whether the change has been applied or not)
372 virtual bool doIsChange() const;
373 /// fills in pre- and post-change values, returns wether they differ
374 virtual bool doFillChange(NodeChangeData
& rChange
, sal_uInt32 _ix
) const;
376 /// new overridable: retrieve the old value from a properly typed node
377 virtual void doTestElement(view::SetNode
const& _aNode
, rtl::OUString
const& aName
);
378 /// new overridable: apply the change to a properly typed node
379 virtual void doApplyToElement(view::SetNode
const& _aNode
, rtl::OUString
const& aName
);
381 //-----------------------------------------------------------------------------
383 /// represents a substitution within a set of trees
385 : public SetElementChangeImpl
387 rtl::Reference
<ElementTree
> m_aNewTree
;
388 rtl::Reference
<ElementTree
> m_aOldTree
;
390 explicit SetReplaceImpl(Path::Component
const& aName
, rtl::Reference
<ElementTree
> const& aNewTree
);
391 explicit SetReplaceImpl(Path::Component
const& aName
, rtl::Reference
<ElementTree
> const& aNewTree
, rtl::Reference
<ElementTree
> const& aOldTree
);
394 /// checks, if this represents an actual change (given whether the change has been applied or not)
395 virtual bool doIsChange() const;
396 /// fills in pre- and post-change values, returns wether they differ
397 virtual bool doFillChange(NodeChangeData
& rChange
, sal_uInt32 _ix
) const;
399 /// new overridable: retrieve the old value from a properly typed node
400 virtual void doTestElement(view::SetNode
const& _aNode
, rtl::OUString
const& aName
);
401 /// new overridable: apply the change to a properly typed node
402 virtual void doApplyToElement(view::SetNode
const& _aNode
, rtl::OUString
const& aName
);
404 //-----------------------------------------------------------------------------
406 /// represents a removal from of a set of trees
408 : public SetElementChangeImpl
410 rtl::Reference
<ElementTree
> m_aOldTree
;
412 explicit SetRemoveImpl(Path::Component
const& aName
);
413 explicit SetRemoveImpl(Path::Component
const& aName
, rtl::Reference
<ElementTree
> const& aOldTree
);
416 /// checks, if this represents an actual change (given whether the change has been applied or not)
417 virtual bool doIsChange() const;
418 /// fills in pre- and post-change values, returns wether they differ
419 virtual bool doFillChange(NodeChangeData
& rChange
, sal_uInt32 _ix
) const;
421 /// new overridable: retrieve the old value from a properly typed node
422 virtual void doTestElement(view::SetNode
const& _aNode
, rtl::OUString
const& aName
);
423 /// new overridable: apply the change to a properly typed node
424 virtual void doApplyToElement(view::SetNode
const& _aNode
, rtl::OUString
const& aName
);
426 //-----------------------------------------------------------------------------
428 //-----------------------------------------------------------------------------
432 #endif // CONFIGMGR_CONFIGCHANGEIMPL_HXX_