LibreOffice Module framework (master) 1
documentacceleratorconfiguration.cxx
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
22
23#include <com/sun/star/lang/XServiceInfo.hpp>
24
29#include <vcl/svapp.hxx>
30
31using namespace framework;
32
33constexpr OUStringLiteral RESOURCETYPE_ACCELERATOR = u"accelerator";
34
35namespace {
36
42typedef ::cppu::ImplInheritanceHelper<
44 css::lang::XServiceInfo> DocumentAcceleratorConfiguration_BASE;
45
46class DocumentAcceleratorConfiguration : public DocumentAcceleratorConfiguration_BASE
47{
48private:
49
52 css::uno::Reference< css::embed::XStorage > m_xDocumentRoot;
53
54public:
55
61 DocumentAcceleratorConfiguration(
62 const css::uno::Reference< css::uno::XComponentContext >& xContext,
63 const css::uno::Sequence< css::uno::Any >& lArguments);
64
65 virtual ~DocumentAcceleratorConfiguration() override;
66
67 virtual OUString SAL_CALL getImplementationName() override
68 {
69 return "com.sun.star.comp.framework.DocumentAcceleratorConfiguration";
70 }
71
72 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
73 {
75 }
76
77 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
78 {
79 return {"com.sun.star.ui.DocumentAcceleratorConfiguration"};
80 }
81
82 // XUIConfigurationStorage
83 virtual void SAL_CALL setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) override;
84
85 virtual sal_Bool SAL_CALL hasStorage() override;
86
88 void fillCache();
89};
90
91DocumentAcceleratorConfiguration::DocumentAcceleratorConfiguration(
92 const css::uno::Reference< css::uno::XComponentContext >& xContext,
93 const css::uno::Sequence< css::uno::Any >& lArguments)
94 : DocumentAcceleratorConfiguration_BASE(xContext)
95{
97 css::uno::Reference<css::embed::XStorage> xRoot;
98 if (lArguments.getLength() == 1 && (lArguments[0] >>= xRoot))
99 {
100 m_xDocumentRoot = xRoot;
101 }
102 else
103 {
104 ::comphelper::SequenceAsHashMap lArgs(lArguments);
105 m_xDocumentRoot = lArgs.getUnpackedValueOrDefault(
106 "DocumentRoot",
107 css::uno::Reference< css::embed::XStorage >());
108 }
109}
110
111DocumentAcceleratorConfiguration::~DocumentAcceleratorConfiguration()
112{
113 m_aPresetHandler.removeStorageListener(this);
114}
115
116void SAL_CALL DocumentAcceleratorConfiguration::setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage)
117{
118 // Attention! xStorage must be accepted too, if it's NULL !
119
120 bool bForgetOldStorages;
121 {
123 bForgetOldStorages = m_xDocumentRoot.is();
124 m_xDocumentRoot = xStorage;
125 }
126
127 if (bForgetOldStorages)
128 /* forget all currently cached data AND(!) forget all currently used storages. */
129 m_aPresetHandler.forgetCachedStorages();
130
131 if (xStorage.is())
132 fillCache();
133}
134
135sal_Bool SAL_CALL DocumentAcceleratorConfiguration::hasStorage()
136{
138 return m_xDocumentRoot.is();
139}
140
141void DocumentAcceleratorConfiguration::fillCache()
142{
143 css::uno::Reference< css::embed::XStorage > xDocumentRoot;
144 {
146 xDocumentRoot = m_xDocumentRoot;
147 }
148
149 // Sometimes we must live without a document root.
150 // E.g. if the document is readonly ...
151 if (!xDocumentRoot.is())
152 return;
153
154 // get current office locale ... but don't cache it.
155 // Otherwise we must be listener on the configuration layer
156 // which seems to superfluous for this small implementation .-)
157 LanguageTag aLanguageTag( impl_ts_getLocale());
158
159 // May be the current document does not contain any
160 // accelerator config? Handle it gracefully :-)
161 try
162 {
163 // Note: The used preset class is threadsafe by itself ... and live if we live!
164 // We do not need any mutex here.
165
166 // open the folder, where the configuration exists
167 m_aPresetHandler.connectToResource(
168 PresetHandler::E_DOCUMENT,
170 u"",
171 xDocumentRoot,
172 aLanguageTag);
173
174 DocumentAcceleratorConfiguration::reload();
175 m_aPresetHandler.addStorageListener(this);
176 }
177 catch(const css::uno::Exception&)
178 {}
179}
180
181} // namespace framework
182
183extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
185 css::uno::XComponentContext *context,
186 css::uno::Sequence<css::uno::Any> const &arguments)
187{
188 rtl::Reference<DocumentAcceleratorConfiguration> inst = new DocumentAcceleratorConfiguration(context, arguments);
189 css::uno::XInterface *acquired_inst = cppu::acquire(inst.get());
190
191 inst->fillCache();
192
193 return acquired_inst;
194}
195
196/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
implements a read/write access to the accelerator configuration.
constexpr OUStringLiteral RESOURCETYPE_ACCELERATOR
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_framework_DocumentAcceleratorConfiguration_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &arguments)
float u
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool