Update git submodules
[LibreOffice.git] / framework / source / accelerators / moduleacceleratorconfiguration.cxx
blobab516b3d2416ef226f1cd84436d646beb6fc2708
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 #include <accelerators/acceleratorconfiguration.hxx>
21 #include <helper/mischelper.hxx>
23 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <comphelper/sequenceashashmap.hxx>
27 #include <vcl/svapp.hxx>
29 #include <com/sun/star/util/XChangesNotifier.hpp>
31 #include <cppuhelper/implbase.hxx>
33 using namespace framework;
35 namespace {
37 /**
38 implements a read/write access to a module
39 dependent accelerator configuration.
41 typedef ::cppu::ImplInheritanceHelper<
42 XCUBasedAcceleratorConfiguration,
43 css::lang::XServiceInfo > ModuleAcceleratorConfiguration_BASE;
45 class ModuleAcceleratorConfiguration : public ModuleAcceleratorConfiguration_BASE
47 private:
48 /** identify the application module, where this accelerator
49 configuration cache should work on. */
50 OUString m_sModule;
52 public:
54 /** initialize this instance and fill the internal cache.
56 @param xSMGR
57 reference to a uno service manager, which is used internally.
59 ModuleAcceleratorConfiguration(
60 const css::uno::Reference< css::uno::XComponentContext >& xContext,
61 const css::uno::Sequence< css::uno::Any >& lArguments);
63 virtual OUString SAL_CALL getImplementationName() override
65 return u"com.sun.star.comp.framework.ModuleAcceleratorConfiguration"_ustr;
68 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
70 return cppu::supportsService(this, ServiceName);
73 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
75 return {u"com.sun.star.ui.ModuleAcceleratorConfiguration"_ustr};
78 /// This has to be called after when the instance is acquire()'d.
79 void fillCache();
81 private:
82 /** helper to listen for configuration changes without ownership cycle problems */
83 rtl::Reference< WeakChangesListener > m_xCfgListener;
86 ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration(
87 const css::uno::Reference< css::uno::XComponentContext >& xContext,
88 const css::uno::Sequence< css::uno::Any >& lArguments)
89 : ModuleAcceleratorConfiguration_BASE(xContext)
91 SolarMutexGuard g;
93 OUString sModule;
94 if (lArguments.getLength() == 1 && (lArguments[0] >>= sModule))
96 m_sModule = sModule;
97 } else
99 ::comphelper::SequenceAsHashMap lArgs(lArguments);
100 m_sModule = lArgs.getUnpackedValueOrDefault(u"ModuleIdentifier"_ustr, OUString());
101 // OUString sLocale = lArgs.getUnpackedValueOrDefault("Locale", OUString("x-default"));
104 if (m_sModule.isEmpty())
105 throw css::uno::RuntimeException(
106 u"The module dependent accelerator configuration service was initialized with an empty module identifier!"_ustr,
107 static_cast< ::cppu::OWeakObject* >(this));
110 void ModuleAcceleratorConfiguration::fillCache()
113 SolarMutexGuard g;
114 m_sModuleCFG = m_sModule;
117 #if 0
118 // get current office locale ... but don't cache it.
119 // Otherwise we must be listener on the configuration layer
120 // which seems to superfluous for this small implementation .-)
121 // XXX: what is this good for? it was a comphelper::Locale but unused
122 LanguageTag aLanguageTag(m_sLocale);
123 #endif
125 // May be the current app module does not have any
126 // accelerator config? Handle it gracefully :-)
129 m_sGlobalOrModules = CFG_ENTRY_MODULES;
130 XCUBasedAcceleratorConfiguration::reload();
132 css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
133 m_xCfgListener = new WeakChangesListener(this);
134 xBroadcaster->addChangesListener(m_xCfgListener);
136 catch(const css::uno::RuntimeException&)
137 { throw; }
138 catch(const css::uno::Exception&)
144 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
145 com_sun_star_comp_framework_ModuleAcceleratorConfiguration_get_implementation(
146 css::uno::XComponentContext *context,
147 css::uno::Sequence<css::uno::Any> const &arguments)
149 rtl::Reference<ModuleAcceleratorConfiguration> inst = new ModuleAcceleratorConfiguration(context, arguments);
150 css::uno::XInterface *acquired_inst = cppu::acquire(inst.get());
152 inst->fillCache();
154 return acquired_inst;
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */