1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
{
40 class XHierarchicalNameAccess
;
43 class XChangesListener
;
47 enum class ConfigItemMode
56 template<> struct typed_flags
<ConfigItemMode
> : is_typed_flags
<ConfigItemMode
, 0x06> {};
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 & 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
>
77 rtl::Reference
< ConfigChangeListener_Impl
>
79 ConfigItemMode m_nMode
;
81 bool m_bEnableInternalNotification
;
82 sal_Int16 m_nInValueChange
;
84 void RemoveChangesListener();
86 const css::uno::Sequence
<OUString
>& aPropertyNames
);
88 css::uno::Reference
< css::container::XHierarchicalNameAccess
>
90 /** writes the changed values into the sub tree.
91 Private and only called from non-virtual public Commit(). */
92 virtual void ImplCommit() = 0;
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
);
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.
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
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
);
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
;}
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
,
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
,
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
,
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
);
196 #endif // INCLUDED_UNOTOOLS_CONFIGITEM_HXX
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */