LibreOffice Module framework (master) 1
acceleratorconfiguration.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <sal/config.h>
23
24#include <string_view>
25
28
29#include <com/sun/star/container/XNameAccess.hpp>
30#include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
31
32#include <com/sun/star/io/XInputStream.hpp>
33#include <com/sun/star/io/XOutputStream.hpp>
34#include <com/sun/star/util/XChangesListener.hpp>
35
36// TODO use XPresetHandler interface instead if available
37#include <com/sun/star/form/XReset.hpp>
38
40
41// definition
42
43namespace framework
44{
45
46inline constexpr OUStringLiteral CFG_ENTRY_PRIMARY = u"PrimaryKeys";
47inline constexpr OUStringLiteral CFG_ENTRY_GLOBAL = u"Global";
48inline constexpr OUStringLiteral CFG_ENTRY_MODULES = u"Modules";
49
53class 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
58{
59
60 // member
61
62 protected:
63
66 css::uno::Reference< css::uno::XComponentContext > m_xContext;
67
74
77
79 std::unique_ptr<AcceleratorCache> m_pWriteCache;
80
81 // native interface!
82
83 public:
84
85 XMLBasedAcceleratorConfiguration( const css::uno::Reference< css::uno::XComponentContext >& xContext);
86 virtual ~XMLBasedAcceleratorConfiguration( ) override;
87
88 // uno interface!
89
90 public:
91
92 // XAcceleratorConfiguration
93 virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getAllKeyEvents() override;
94
95 virtual OUString SAL_CALL getCommandByKeyEvent(const css::awt::KeyEvent& aKeyEvent) override;
96
97 virtual void SAL_CALL setKeyEvent(const css::awt::KeyEvent& aKeyEvent,
98 const OUString& sCommand ) override;
99
100 virtual void SAL_CALL removeKeyEvent(const css::awt::KeyEvent& aKeyEvent) override;
101
102 virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getKeyEventsByCommand(const OUString& sCommand) override;
103
104 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPreferredKeyEventsForCommandList(const css::uno::Sequence< OUString >& lCommandList) override;
105
106 virtual void SAL_CALL removeCommandFromAllKeyEvents(const OUString& sCommand) override;
107
108 // XUIConfigurationPersistence
109 virtual void SAL_CALL reload() override;
110
111 virtual void SAL_CALL store() override;
112
113 virtual void SAL_CALL storeToStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) override;
114
115 virtual sal_Bool SAL_CALL isModified() override;
116
117 virtual sal_Bool SAL_CALL isReadOnly() override;
118
119 // XUIConfigurationStorage
120 virtual void SAL_CALL setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) override;
121
122 virtual sal_Bool SAL_CALL hasStorage() override;
123
124 // XUIConfiguration
125 virtual void SAL_CALL addConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& xListener) override;
126
127 virtual void SAL_CALL removeConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& xListener) override;
128
129 // XReset
130 // TODO use XPresetHandler instead if available
131 virtual void SAL_CALL reset() override;
132
133 virtual void SAL_CALL addResetListener(const css::uno::Reference< css::form::XResetListener >& xListener) override;
134
135 virtual void SAL_CALL removeResetListener(const css::uno::Reference< css::form::XResetListener >& xListener) override;
136
137 // called when changes occurred in the storage
138 void changesOccurred();
139
140 // helper for derived classes
141
142 protected:
143
152 OUString impl_ts_getLocale() const;
153
154 // helper
155
156 private:
157
163 void impl_ts_load(const css::uno::Reference< css::io::XInputStream >& xStream);
164
170 void impl_ts_save(const css::uno::Reference< css::io::XOutputStream >& xStream);
171
190 AcceleratorCache& impl_getCFG(bool bWriteAccessRequested = false);
191
192};
193
194class 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
200{
201
202 // member
203
204 protected:
205
208 css::uno::Reference< css::uno::XComponentContext > m_xContext;
209
210 css::uno::Reference< css::container::XNameAccess > m_xCfg;
213 std::unique_ptr<AcceleratorCache> m_pPrimaryWriteCache;
214 std::unique_ptr<AcceleratorCache> m_pSecondaryWriteCache;
215
217 OUString m_sModuleCFG;
218
219 // native interface!
220
221 public:
222
223 XCUBasedAcceleratorConfiguration( css::uno::Reference< css::uno::XComponentContext > xContext );
224 virtual ~XCUBasedAcceleratorConfiguration( ) override;
225
226 // uno interface!
227
228 public:
229
230 // XAcceleratorConfiguration
231 virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getAllKeyEvents() override;
232
233 virtual OUString SAL_CALL getCommandByKeyEvent(const css::awt::KeyEvent& aKeyEvent) override;
234
235 virtual void SAL_CALL setKeyEvent(const css::awt::KeyEvent& aKeyEvent,
236 const OUString& sCommand ) override;
237
238 virtual void SAL_CALL removeKeyEvent(const css::awt::KeyEvent& aKeyEvent) override;
239
240 virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getKeyEventsByCommand(const OUString& sCommand) override;
241
242 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPreferredKeyEventsForCommandList(const css::uno::Sequence< OUString >& lCommandList) override;
243
244 virtual void SAL_CALL removeCommandFromAllKeyEvents(const OUString& sCommand) override;
245
246 // XUIConfigurationPersistence
247 virtual void SAL_CALL reload() override;
248
249 virtual void SAL_CALL store() override;
250
251 virtual void SAL_CALL storeToStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) override;
252
253 virtual sal_Bool SAL_CALL isModified() override;
254
255 virtual sal_Bool SAL_CALL isReadOnly() override;
256
257 // XUIConfigurationStorage
258 virtual void SAL_CALL setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) override;
259
260 virtual sal_Bool SAL_CALL hasStorage() override;
261
262 // XUIConfiguration
263 virtual void SAL_CALL addConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& xListener) override;
264
265 virtual void SAL_CALL removeConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& xListener) override;
266
267 // XReset
268 // TODO use XPresetHandler instead if available
269 virtual void SAL_CALL reset() override;
270
271 virtual void SAL_CALL addResetListener(const css::uno::Reference< css::form::XResetListener >& xListener) override;
272
273 virtual void SAL_CALL removeResetListener(const css::uno::Reference< css::form::XResetListener >& xListener) override;
274
275 // css.util.XChangesListener
276 virtual void SAL_CALL changesOccurred(const css::util::ChangesEvent& aEvent) override;
277
278 // css.lang.XEventListener
279 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
280
281 // helper for derived classes
282
283 protected:
284
293 OUString impl_ts_getLocale() const;
294
295 // helper
296
297 private:
298
299 void impl_ts_load(bool bPreferred, const css::uno::Reference< css::container::XNameAccess >& xCfg);
300 void impl_ts_save(bool bPreferred);
301
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);
304
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);
307
308};
309
310} // namespace framework
311
312/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
implements a cache for any accelerator configuration.
virtual OUString SAL_CALL getCommandByKeyEvent(const css::awt::KeyEvent &aKeyEvent) override
virtual void SAL_CALL removeConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener > &xListener) override
void reloadChanged(const OUString &sPrimarySecondary, std::u16string_view sGlobalModules, const OUString &sModule, const OUString &sKey)
virtual void SAL_CALL removeKeyEvent(const css::awt::KeyEvent &aKeyEvent) override
virtual void SAL_CALL addConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener > &xListener) override
virtual void SAL_CALL removeCommandFromAllKeyEvents(const OUString &sCommand) override
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPreferredKeyEventsForCommandList(const css::uno::Sequence< OUString > &lCommandList) override
virtual sal_Bool SAL_CALL isModified() override
virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getAllKeyEvents() override
virtual void SAL_CALL removeResetListener(const css::uno::Reference< css::form::XResetListener > &xListener) override
virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getKeyEventsByCommand(const OUString &sCommand) override
css::uno::Reference< css::container::XNameAccess > m_xCfg
virtual void SAL_CALL storeToStorage(const css::uno::Reference< css::embed::XStorage > &xStorage) override
std::unique_ptr< AcceleratorCache > m_pSecondaryWriteCache
void insertKeyToConfiguration(const css::awt::KeyEvent &aKeyEvent, const OUString &sCommand, const bool bPreferred)
virtual sal_Bool SAL_CALL hasStorage() override
virtual void SAL_CALL setKeyEvent(const css::awt::KeyEvent &aKeyEvent, const OUString &sCommand) override
void removeKeyFromConfiguration(const css::awt::KeyEvent &aKeyEvent, const bool bPreferred)
std::unique_ptr< AcceleratorCache > m_pPrimaryWriteCache
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
the global uno service manager.
AcceleratorCache & impl_getCFG(bool bPreferred, bool bWriteAccessRequested=false)
XCUBasedAcceleratorConfiguration(css::uno::Reference< css::uno::XComponentContext > xContext)
virtual void SAL_CALL addResetListener(const css::uno::Reference< css::form::XResetListener > &xListener) override
virtual sal_Bool SAL_CALL isReadOnly() override
virtual void SAL_CALL changesOccurred(const css::util::ChangesEvent &aEvent) override
OUString impl_ts_getLocale() const
return the current office locale.
void impl_ts_load(bool bPreferred, const css::uno::Reference< css::container::XNameAccess > &xCfg)
virtual void SAL_CALL setStorage(const css::uno::Reference< css::embed::XStorage > &xStorage) override
implements a read/write access to the accelerator configuration.
virtual void SAL_CALL removeCommandFromAllKeyEvents(const OUString &sCommand) override
virtual void SAL_CALL setStorage(const css::uno::Reference< css::embed::XStorage > &xStorage) override
virtual sal_Bool SAL_CALL isModified() override
std::unique_ptr< AcceleratorCache > m_pWriteCache
used to implement the copy on write pattern!
virtual void SAL_CALL removeResetListener(const css::uno::Reference< css::form::XResetListener > &xListener) override
virtual void SAL_CALL setKeyEvent(const css::awt::KeyEvent &aKeyEvent, const OUString &sCommand) override
virtual void SAL_CALL removeConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener > &xListener) override
virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getKeyEventsByCommand(const OUString &sCommand) override
AcceleratorCache & impl_getCFG(bool bWriteAccessRequested=false)
returns a reference to one of our internal cache members.
virtual void SAL_CALL addConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener > &xListener) override
PresetHandler m_aPresetHandler
used to: i ) copy configuration files from the share to the user layer ii ) provide access to these c...
virtual sal_Bool SAL_CALL hasStorage() override
virtual void SAL_CALL addResetListener(const css::uno::Reference< css::form::XResetListener > &xListener) override
OUString impl_ts_getLocale() const
return the current office locale.
void impl_ts_save(const css::uno::Reference< css::io::XOutputStream > &xStream)
save a configuration set, using the given stream.
XMLBasedAcceleratorConfiguration(const css::uno::Reference< css::uno::XComponentContext > &xContext)
css::uno::Reference< css::uno::XComponentContext > m_xContext
the global uno service manager.
virtual sal_Bool SAL_CALL isReadOnly() override
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPreferredKeyEventsForCommandList(const css::uno::Sequence< OUString > &lCommandList) override
virtual void SAL_CALL removeKeyEvent(const css::awt::KeyEvent &aKeyEvent) override
void impl_ts_load(const css::uno::Reference< css::io::XInputStream > &xStream)
load a configuration set, using the given stream.
virtual void SAL_CALL storeToStorage(const css::uno::Reference< css::embed::XStorage > &xStorage) override
AcceleratorCache m_aReadCache
contains the cached configuration data
virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getAllKeyEvents() override
virtual OUString SAL_CALL getCommandByKeyEvent(const css::awt::KeyEvent &aKeyEvent) override
float u
constexpr OUStringLiteral CFG_ENTRY_GLOBAL
constexpr OUStringLiteral CFG_ENTRY_MODULES
constexpr OUStringLiteral CFG_ENTRY_PRIMARY
unsigned char sal_Bool