merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / backend / updatedata.hxx
blobe3785e3781826890eba6a69e02b1e89a9091709c
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: updatedata.hxx,v $
10 * $Revision: 1.10 $
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_BACKEND_UPDATEDATA_HXX
32 #define CONFIGMGR_BACKEND_UPDATEDATA_HXX
34 #include <com/sun/star/uno/Any.hxx>
35 #include <com/sun/star/uno/Type.hxx>
36 #include <rtl/ref.hxx>
37 #include <rtl/ustring.hxx>
38 #include <salhelper/simplereferenceobject.hxx>
39 #include "utility.hxx"
41 #ifndef INCLUDED_SET
42 #include <set>
43 #define INCLUDED_SET
44 #endif
45 #ifndef INCLUDED_MAP
46 #include <map>
47 #define INCLUDED_MAP
48 #endif
50 namespace com { namespace sun { namespace star { namespace configuration { namespace backend {
51 class XLayerHandler;
52 } } } } }
53 // -----------------------------------------------------------------------------
55 namespace configmgr
57 // -----------------------------------------------------------------------------
58 namespace backend
60 // -----------------------------------------------------------------------------
61 namespace uno = ::com::sun::star::uno;
62 namespace backenduno = ::com::sun::star::configuration::backend;
63 // -----------------------------------------------------------------------------
64 class ElementUpdate;
65 class NodeUpdate;
66 class NodeModification;
67 class NodeReplace;
68 class NodeDrop;
69 class PropertyUpdate;
70 class PropertyAdd;
71 class PropertyReset;
73 // -----------------------------------------------------------------------------
75 class NamedUpdate : public salhelper::SimpleReferenceObject
77 rtl::OUString const m_aName;
79 protected:
80 explicit
81 NamedUpdate(rtl::OUString const & _aName)
82 : m_aName(_aName)
85 ~NamedUpdate() {};
87 public:
88 rtl::OUString const & getName() const { return m_aName; }
90 // -----------------------------------------------------------------------------
91 class ElementUpdate : public NamedUpdate
93 NodeUpdate * m_pParent;
94 sal_Int16 m_nFlags;
95 sal_Int16 m_nFlagsMask;
96 protected:
97 ElementUpdate(NodeUpdate * _pParent, rtl::OUString const & _aName, sal_Int16 _nFlags, sal_Int16 _nFlagsMask);
99 public:
100 virtual NodeUpdate * asNodeUpdate(bool _bMerged = false);
101 virtual PropertyUpdate * asPropertyUpdate();
103 virtual void writeToLayer(backenduno::XLayerHandler * _pLayer) = 0;
105 public:
106 NodeUpdate * getParent() const { return m_pParent; }
108 sal_Int16 changedFlags() const { return m_nFlagsMask; }
109 sal_Int16 updateFlags(sal_Int16 _nFlags = 0) const;
112 // -----------------------------------------------------------------------------
114 class NodeUpdate : public ElementUpdate
116 typedef std::map< rtl::OUString, rtl::Reference<ElementUpdate> > ElementList;
117 public:
118 enum Op { modify, reset, replace };
120 protected:
121 NodeUpdate(NodeUpdate * _pParent, rtl::OUString const & _aName, sal_Int16 _nFlags, sal_Int16 _nFlagsMask, Op _op);
123 virtual NodeUpdate * asNodeUpdate(bool _bMerged);
125 public:
126 bool addNodeUpdate (rtl::Reference<ElementUpdate> const & _aNode);
127 bool addPropertyUpdate (rtl::Reference<ElementUpdate> const & _aProp);
128 void removeNodeByName (rtl::OUString const & _aName);
129 void removePropertyByName (rtl::OUString const & _aName);
131 Op getOperation() const { return m_op; }
133 rtl::Reference<ElementUpdate> getNodeByName (rtl::OUString const & _aName) const;
134 rtl::Reference<ElementUpdate> getPropertyByName (rtl::OUString const & _aName) const;
136 ElementList::const_iterator beginNodes() const { return m_aNodes.begin(); }
137 ElementList::const_iterator endNodes() const { return m_aNodes.end(); };
138 ElementList::const_iterator beginProperties() const { return m_aProperties.begin(); };
139 ElementList::const_iterator endProperties() const { return m_aProperties.end(); };
141 bool hasChildren() const { return !m_aNodes.empty() || !m_aProperties.empty(); }
143 void writeChildrenToLayer(backenduno::XLayerHandler * _pLayer);
144 private:
145 ElementList m_aNodes;
146 ElementList m_aProperties;
147 ElementList m_aRemovedElements;
148 Op m_op;
150 // -----------------------------------------------------------------------------
152 class NodeModification : public NodeUpdate
154 public:
155 NodeModification(NodeUpdate * _pParent, rtl::OUString const & _aName, sal_Int16 _nFlags, sal_Int16 _nFlagsMask, sal_Bool _bReset);
156 virtual void writeToLayer(backenduno::XLayerHandler * _pLayer);
158 // -----------------------------------------------------------------------------
160 class NodeReplace : public NodeUpdate
162 public:
163 NodeReplace(NodeUpdate * _pParent, rtl::OUString const & _aName, sal_Int16 _nFlags);
164 NodeReplace(NodeUpdate * _pParent, rtl::OUString const & _aName, sal_Int16 _nFlags, rtl::OUString const & _aTemplateName, rtl::OUString const & _aTemplateComponent);
166 bool hasTemplate() const;
167 rtl::OUString getTemplateName() const { return m_aTemplateName; }
168 rtl::OUString getTemplateComponent() const { return m_aTemplateComponent; }
170 virtual void writeToLayer(backenduno::XLayerHandler * _pLayer);
171 private:
172 rtl::OUString m_aTemplateName;
173 rtl::OUString m_aTemplateComponent;
175 // -----------------------------------------------------------------------------
177 class NodeDrop : public ElementUpdate
179 public:
180 NodeDrop(NodeUpdate * _pParent, rtl::OUString const & _aName);
182 virtual void writeToLayer(backenduno::XLayerHandler * _pLayer);
184 // -----------------------------------------------------------------------------
186 class PropertyUpdate : public ElementUpdate
188 typedef std::map< rtl::OUString, uno::Any > ValueList;
190 ValueList m_aValues;
191 uno::Type m_aType;
192 public:
193 PropertyUpdate(NodeUpdate * _pParent, rtl::OUString const & _aName, sal_Int16 _nFlags, sal_Int16 _nFlagsMask, uno::Type const & _aType);
195 bool setValueFor(rtl::OUString const & _aLocale, uno::Any const & _aValueUpdate);
196 bool resetValueFor(rtl::OUString const & _aLocale);
197 void removeValueFor(rtl::OUString const & _aLocale);
199 bool setValue(uno::Any const & _aValueUpdate) { return setValueFor(primarySlot(), _aValueUpdate); }
200 bool resetValue() { return resetValueFor(primarySlot()); }
201 void removeValue() { removeValueFor(primarySlot()); }
203 void finishValue();
205 uno::Type const & getValueType() const { return m_aType; }
207 bool hasValueFor(rtl::OUString const & _aLocale) const;
208 bool hasValue() const { return hasValueFor(primarySlot()); }
210 bool hasResetFor(rtl::OUString const & _aLocale) const;
211 bool hasReset() const { return hasResetFor(primarySlot()); }
213 bool hasChangeFor(rtl::OUString const & _aLocale) const;
214 bool hasChange() const { return hasChangeFor(primarySlot()); }
216 uno::Any getValueFor(rtl::OUString const & _aLocale) const;
217 uno::Any getValue() const { return getValueFor(primarySlot()); }
219 ValueList::const_iterator beginValues() const { return m_aValues.begin(); }
220 ValueList::const_iterator endValues() const { return m_aValues.end(); }
222 void writeValueToLayerFor(backenduno::XLayerHandler * _pLayer, uno::Any const & _aValue, rtl::OUString const & _aLocale);
223 void writeValueToLayer(backenduno::XLayerHandler * _pLayer, uno::Any const & _aValue);
224 void writeValuesToLayer(backenduno::XLayerHandler * _pLayer);
225 virtual void writeToLayer(backenduno::XLayerHandler * _pLayer);
226 private:
227 rtl::OUString primarySlot() const { return rtl::OUString(); }
229 static uno::Any const & getResetMarker();
230 static inline bool isResetMarker(uno::Any const & _aValue);
232 virtual PropertyUpdate * asPropertyUpdate();
234 // -----------------------------------------------------------------------------
236 class PropertyAdd : public ElementUpdate
238 uno::Type m_aValueType;
239 uno::Any m_aValue;
240 public:
241 PropertyAdd(NodeUpdate * _pParent, rtl::OUString const & _aName, sal_Int16 _nFlags, uno::Type const & _aType);
242 PropertyAdd(NodeUpdate * _pParent, rtl::OUString const & _aName, sal_Int16 _nFlags, uno::Any const & _aValue);
244 bool hasValue() const { return !! m_aValue.hasValue(); }
245 uno::Any const & getValue() const { return m_aValue; }
246 uno::Type const & getValueType() const { return m_aValueType; }
248 virtual void writeToLayer(backenduno::XLayerHandler * _pLayer);
250 // -----------------------------------------------------------------------------
252 class PropertyReset : public ElementUpdate
254 public:
255 PropertyReset(NodeUpdate * _pParent, rtl::OUString const & _aName);
257 virtual void writeToLayer(backenduno::XLayerHandler * _pLayer);
259 // -----------------------------------------------------------------------------
261 } // namespace backend
262 // -----------------------------------------------------------------------------
264 } // namespace configmgr
265 #endif