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 .
22 #include <sal/config.h>
24 #include <string_view>
26 #include <accelerators/presethandler.hxx>
27 #include <accelerators/acceleratorcache.hxx>
29 #include <com/sun/star/container/XNameAccess.hpp>
30 #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
32 #include <com/sun/star/io/XInputStream.hpp>
33 #include <com/sun/star/io/XOutputStream.hpp>
34 #include <com/sun/star/util/XChangesListener.hpp>
36 // TODO use XPresetHandler interface instead if available
37 #include <com/sun/star/form/XReset.hpp>
39 #include <cppuhelper/implbase.hxx>
46 inline constexpr OUString CFG_ENTRY_PRIMARY
= u
"PrimaryKeys"_ustr
;
47 inline constexpr OUString CFG_ENTRY_GLOBAL
= u
"Global"_ustr
;
48 inline constexpr OUString CFG_ENTRY_MODULES
= u
"Modules"_ustr
;
51 implements a read/write access to the accelerator configuration.
53 class XMLBasedAcceleratorConfiguration
: public ::cppu::WeakImplHelper
<
54 css::form::XReset
, // TODO use XPresetHandler instead if available
55 css::ui::XAcceleratorConfiguration
> // => css::ui::XUIConfigurationPersistence
56 // css::ui::XUIConfigurationStorage
57 // css::ui::XUIConfiguration
64 /** the global uno service manager.
65 Must be used to create own needed services. */
66 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
69 i ) copy configuration files from the share to the user layer
70 ii ) provide access to these config files
71 iii) cache all sub storages on the path from the top to the bottom(!)
72 iv ) provide commit for changes. */
73 PresetHandler m_aPresetHandler
;
75 /** contains the cached configuration data */
76 AcceleratorCache m_aReadCache
;
78 /** used to implement the copy on write pattern! */
79 std::unique_ptr
<AcceleratorCache
> m_pWriteCache
;
85 XMLBasedAcceleratorConfiguration( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
86 virtual ~XMLBasedAcceleratorConfiguration( ) override
;
92 // XAcceleratorConfiguration
93 virtual css::uno::Sequence
< css::awt::KeyEvent
> SAL_CALL
getAllKeyEvents() override
;
95 virtual OUString SAL_CALL
getCommandByKeyEvent(const css::awt::KeyEvent
& aKeyEvent
) override
;
97 virtual void SAL_CALL
setKeyEvent(const css::awt::KeyEvent
& aKeyEvent
,
98 const OUString
& sCommand
) override
;
100 virtual void SAL_CALL
removeKeyEvent(const css::awt::KeyEvent
& aKeyEvent
) override
;
102 virtual css::uno::Sequence
< css::awt::KeyEvent
> SAL_CALL
getKeyEventsByCommand(const OUString
& sCommand
) override
;
104 virtual css::uno::Sequence
< css::uno::Any
> SAL_CALL
getPreferredKeyEventsForCommandList(const css::uno::Sequence
< OUString
>& lCommandList
) override
;
106 virtual void SAL_CALL
removeCommandFromAllKeyEvents(const OUString
& sCommand
) override
;
108 // XUIConfigurationPersistence
109 virtual void SAL_CALL
reload() override
;
111 virtual void SAL_CALL
store() override
;
113 virtual void SAL_CALL
storeToStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
) override
;
115 virtual sal_Bool SAL_CALL
isModified() override
;
117 virtual sal_Bool SAL_CALL
isReadOnly() override
;
119 // XUIConfigurationStorage
120 virtual void SAL_CALL
setStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
) override
;
122 virtual sal_Bool SAL_CALL
hasStorage() override
;
125 virtual void SAL_CALL
addConfigurationListener(const css::uno::Reference
< css::ui::XUIConfigurationListener
>& xListener
) override
;
127 virtual void SAL_CALL
removeConfigurationListener(const css::uno::Reference
< css::ui::XUIConfigurationListener
>& xListener
) override
;
130 // TODO use XPresetHandler instead if available
131 virtual void SAL_CALL
reset() override
;
133 virtual void SAL_CALL
addResetListener(const css::uno::Reference
< css::form::XResetListener
>& xListener
) override
;
135 virtual void SAL_CALL
removeResetListener(const css::uno::Reference
< css::form::XResetListener
>& xListener
) override
;
137 // called when changes occurred in the storage
138 void changesOccurred();
140 // helper for derived classes
144 /** @short return the current office locale.
146 @descr We do not cache this value, because we are not listen
147 for changes on the configuration layer ...
150 The current office locale as BCP47 string.
152 static OUString
impl_ts_getLocale();
158 /** @short load a configuration set, using the given stream.
161 provides the XML structure as stream.
163 void impl_ts_load(const css::uno::Reference
< css::io::XInputStream
>& xStream
);
165 /** @short save a configuration set, using the given stream.
168 the XML structure can be written there.
170 void impl_ts_save(const css::uno::Reference
< css::io::XOutputStream
>& xStream
);
172 /** @short returns a reference to one of our internal cache members.
174 @descr We implement the copy-on-write pattern. Doing so
175 we know two caches internally. The second one is used
176 only, if the container was changed.
178 This method here returns access to one of these
179 caches - depending on the change state of this
180 configuration service.
182 @param bWriteAccessRequested
183 if the outside code wish to change the container
184 it must call this method with "sal_True". So the internal
185 cache can be prepared for that (means copy-on-write ...).
187 @return [AcceleratorCache]
188 c++ reference(!) to one of our internal caches.
190 AcceleratorCache
& impl_getCFG(bool bWriteAccessRequested
= false);
194 class XCUBasedAcceleratorConfiguration
: public ::cppu::WeakImplHelper
<
195 css::util::XChangesListener
,
196 css::form::XReset
, // TODO use XPresetHandler instead if available
197 css::ui::XAcceleratorConfiguration
> // => css::ui::XUIConfigurationPersistence
198 // css::ui::XUIConfigurationStorage
199 // css::ui::XUIConfiguration
206 /** the global uno service manager.
207 Must be used to create own needed services. */
208 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
210 css::uno::Reference
< css::container::XNameAccess
> m_xCfg
;
211 AcceleratorCache m_aPrimaryReadCache
;
212 AcceleratorCache m_aSecondaryReadCache
;
213 std::unique_ptr
<AcceleratorCache
> m_pPrimaryWriteCache
;
214 std::unique_ptr
<AcceleratorCache
> m_pSecondaryWriteCache
;
216 OUString m_sGlobalOrModules
;
217 OUString m_sModuleCFG
;
223 XCUBasedAcceleratorConfiguration( css::uno::Reference
< css::uno::XComponentContext
> xContext
);
224 virtual ~XCUBasedAcceleratorConfiguration( ) override
;
230 // XAcceleratorConfiguration
231 virtual css::uno::Sequence
< css::awt::KeyEvent
> SAL_CALL
getAllKeyEvents() override
;
233 virtual OUString SAL_CALL
getCommandByKeyEvent(const css::awt::KeyEvent
& aKeyEvent
) override
;
235 virtual void SAL_CALL
setKeyEvent(const css::awt::KeyEvent
& aKeyEvent
,
236 const OUString
& sCommand
) override
;
238 virtual void SAL_CALL
removeKeyEvent(const css::awt::KeyEvent
& aKeyEvent
) override
;
240 virtual css::uno::Sequence
< css::awt::KeyEvent
> SAL_CALL
getKeyEventsByCommand(const OUString
& sCommand
) override
;
242 virtual css::uno::Sequence
< css::uno::Any
> SAL_CALL
getPreferredKeyEventsForCommandList(const css::uno::Sequence
< OUString
>& lCommandList
) override
;
244 virtual void SAL_CALL
removeCommandFromAllKeyEvents(const OUString
& sCommand
) override
;
246 // XUIConfigurationPersistence
247 virtual void SAL_CALL
reload() override
;
249 virtual void SAL_CALL
store() override
;
251 virtual void SAL_CALL
storeToStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
) override
;
253 virtual sal_Bool SAL_CALL
isModified() override
;
255 virtual sal_Bool SAL_CALL
isReadOnly() override
;
257 // XUIConfigurationStorage
258 virtual void SAL_CALL
setStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
) override
;
260 virtual sal_Bool SAL_CALL
hasStorage() override
;
263 virtual void SAL_CALL
addConfigurationListener(const css::uno::Reference
< css::ui::XUIConfigurationListener
>& xListener
) override
;
265 virtual void SAL_CALL
removeConfigurationListener(const css::uno::Reference
< css::ui::XUIConfigurationListener
>& xListener
) override
;
268 // TODO use XPresetHandler instead if available
269 virtual void SAL_CALL
reset() override
;
271 virtual void SAL_CALL
addResetListener(const css::uno::Reference
< css::form::XResetListener
>& xListener
) override
;
273 virtual void SAL_CALL
removeResetListener(const css::uno::Reference
< css::form::XResetListener
>& xListener
) override
;
275 // css.util.XChangesListener
276 virtual void SAL_CALL
changesOccurred(const css::util::ChangesEvent
& aEvent
) override
;
278 // css.lang.XEventListener
279 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
) override
;
281 // helper for derived classes
285 /** @short return the current office locale.
287 @descr We do not cache this value, because we are not listen
288 for changes on the configuration layer ...
291 The current office locale as BCP47 string.
293 static OUString
impl_ts_getLocale();
299 void impl_ts_load(bool bPreferred
, const css::uno::Reference
< css::container::XNameAccess
>& xCfg
);
300 void impl_ts_save(bool bPreferred
);
302 void insertKeyToConfiguration(const css::awt::KeyEvent
& aKeyEvent
, const OUString
& sCommand
, const bool bPreferred
);
303 void removeKeyFromConfiguration(const css::awt::KeyEvent
& aKeyEvent
, const bool bPreferred
);
305 void reloadChanged(const OUString
& sPrimarySecondary
, std::u16string_view sGlobalModules
, const OUString
& sModule
, const OUString
& sKey
);
306 AcceleratorCache
& impl_getCFG(bool bPreferred
, bool bWriteAccessRequested
= false);
310 } // namespace framework
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */