PVS: V773 The return value of function 'lcl_CopyStyle'...
[LibreOffice.git] / include / unotools / configitem.hxx
blob649c05fdbe281a93d4874ae05e7b73c0508f85d6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_UNOTOOLS_CONFIGITEM_HXX
21 #define INCLUDED_UNOTOOLS_CONFIGITEM_HXX
23 #include <sal/types.h>
24 #include <rtl/ref.hxx>
25 #include <rtl/ustring.hxx>
26 #include <com/sun/star/uno/Sequence.h>
27 #include <com/sun/star/uno/Reference.h>
28 #include <unotools/unotoolsdllapi.h>
29 #include <unotools/options.hxx>
30 #include <o3tl/typed_flags_set.hxx>
32 namespace com::sun::star {
33 namespace uno{
34 class Any;
36 namespace beans{
37 struct PropertyValue;
39 namespace container{
40 class XHierarchicalNameAccess;
42 namespace util{
43 class XChangesListener;
47 enum class ConfigItemMode
49 NONE = 0x00,
50 AllLocales = 0x02,
51 ReleaseTree = 0x04,
54 namespace o3tl
56 template<> struct typed_flags<ConfigItemMode> : is_typed_flags<ConfigItemMode, 0x06> {};
59 namespace utl
61 class ConfigChangeListener_Impl;
63 enum class ConfigNameFormat
65 LocalNode, // local node name, for use in XNameAccess etc. ("Item", "Q & A")
66 LocalPath, // one-level relative path, for use when building paths etc. ("Item", "Typ['Q &amp; A']")
69 class UNOTOOLS_DLLPUBLIC ConfigItem : public ConfigurationBroadcaster
71 friend class ConfigChangeListener_Impl;
72 friend class ConfigManager;
74 const OUString sSubTree;
75 css::uno::Reference< css::container::XHierarchicalNameAccess>
76 m_xHierarchyAccess;
77 rtl::Reference< ConfigChangeListener_Impl >
78 xChangeLstnr;
79 ConfigItemMode m_nMode;
80 bool m_bIsModified;
81 bool m_bEnableInternalNotification;
82 sal_Int16 m_nInValueChange;
84 void RemoveChangesListener();
85 void CallNotify(
86 const css::uno::Sequence<OUString>& aPropertyNames);
88 css::uno::Reference< css::container::XHierarchicalNameAccess>
89 GetTree();
90 /** writes the changed values into the sub tree.
91 Private and only called from non-virtual public Commit(). */
92 virtual void ImplCommit() = 0;
94 protected:
95 explicit ConfigItem(OUString aSubTree,
96 ConfigItemMode nMode = ConfigItemMode::NONE);
98 void SetModified (); // mark item as modified
99 void ClearModified(); // reset state after commit!
101 css::uno::Sequence< css::uno::Any>
102 GetProperties(const css::uno::Sequence< OUString >& rNames);
104 css::uno::Sequence< sal_Bool >
105 GetReadOnlyStates(const css::uno::Sequence< OUString >& rNames);
107 bool PutProperties(
108 const css::uno::Sequence< OUString >& rNames,
109 const css::uno::Sequence< css::uno::Any>& rValues);
111 /** enables notifications about changes on selected sub nodes/values
113 Before calling this method a second time for a possibly changed node/value set,
114 you must disable the current notifications by calling DisableNotification.
116 @see Notify
117 @see DisableNotification
119 bool EnableNotification(const css::uno::Sequence< OUString >& rNames,
120 bool bEnableInternalNotification = false);
121 /** disables notifications about changes on sub nodes/values, which previously had
122 been enabled with EnableNotification
123 @see Notify
124 @see EnableNotification
126 void DisableNotification();
128 //returns all members of a node in a specific format
129 css::uno::Sequence< OUString >
130 GetNodeNames(const OUString& rNode);
131 //returns all members of a node in a specific format
132 css::uno::Sequence< OUString >
133 GetNodeNames(const OUString& rNode, ConfigNameFormat eFormat);
134 // remove all members of a set
135 bool ClearNodeSet(const OUString& rNode);
136 // remove selected members of a set
137 bool ClearNodeElements(const OUString& rNode,
138 css::uno::Sequence< OUString > const & rElements);
139 // change or add members to a set
140 bool SetSetProperties(const OUString& rNode, const css::uno::Sequence< css::beans::PropertyValue >& rValues);
141 // remove, change or add members of a set
142 bool ReplaceSetProperties(const OUString& rNode, const css::uno::Sequence< css::beans::PropertyValue >& rValues);
143 // add a new node without setting any properties
144 bool AddNode(const OUString& rNode, const OUString& rNewNode);
146 public:
147 virtual ~ConfigItem() override;
149 ConfigItem(ConfigItem const &);
150 ConfigItem(ConfigItem &&);
151 ConfigItem & operator =(ConfigItem const &) = delete; // due to const sSubTree
152 ConfigItem & operator =(ConfigItem &&) = delete; // due to const sSubTree
154 /** is called from the ConfigManager before application ends of from the
155 PropertyChangeListener if the sub tree broadcasts changes. */
156 virtual void Notify( const css::uno::Sequence<OUString>& aPropertyNames)=0;
158 const OUString& GetSubTreeName() const {return sSubTree;}
160 bool IsModified() const { return m_bIsModified;}
162 void Commit();
164 ConfigItemMode GetMode() const { return m_nMode;}
166 //returns all members of a node in a specific format
167 static css::uno::Sequence< OUString > GetNodeNames(
168 css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
169 const OUString& rNode, ConfigNameFormat eFormat);
170 static css::uno::Sequence< css::uno::Any> GetProperties(
171 css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
172 const css::uno::Sequence< OUString >& rNames,
173 bool bAllLocales);
174 static bool PutProperties(
175 css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
176 const css::uno::Sequence< OUString >& rNames,
177 const css::uno::Sequence< css::uno::Any>& rValues,
178 bool bAllLocales);
179 // remove all members of a set
180 static bool ClearNodeSet(
181 css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
182 const OUString& rNode);
183 // remove, change or add members of a set
184 static bool ReplaceSetProperties(
185 css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
186 const OUString& rNode,
187 const css::uno::Sequence< css::beans::PropertyValue >& rValues,
188 bool bAllLocales);
189 // change or add members to a set
190 static bool SetSetProperties(
191 css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
192 const OUString& rNode,
193 const css::uno::Sequence< css::beans::PropertyValue >& rValues);
195 }//namespace utl
196 #endif // INCLUDED_UNOTOOLS_CONFIGITEM_HXX
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */