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 #include <accelerators/acceleratorconfiguration.hxx>
21 #include <accelerators/keymapping.hxx>
22 #include <helper/mischelper.hxx>
24 #include <com/sun/star/util/XChangesNotifier.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <cppuhelper/implbase.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <rtl/ref.hxx>
31 using namespace framework
;
36 implements a read/write access to the global
37 accelerator configuration.
39 typedef ::cppu::ImplInheritanceHelper
<
40 XCUBasedAcceleratorConfiguration
,
41 css::lang::XServiceInfo
> GlobalAcceleratorConfiguration_BASE
;
42 class GlobalAcceleratorConfiguration
: public GlobalAcceleratorConfiguration_BASE
46 /** initialize this instance and fill the internal cache.
49 reference to a uno service manager, which is used internally.
51 explicit GlobalAcceleratorConfiguration(const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
53 virtual OUString SAL_CALL
getImplementationName() override
55 return "com.sun.star.comp.framework.GlobalAcceleratorConfiguration";
58 virtual sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
60 return cppu::supportsService(this, ServiceName
);
63 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
65 return {"com.sun.star.ui.GlobalAcceleratorConfiguration"};
68 /// This has to be called after when the instance is acquire()'d.
73 /** helper to listen for configuration changes without ownership cycle problems */
74 css::uno::Reference
< css::util::XChangesListener
> m_xCfgListener
;
77 GlobalAcceleratorConfiguration::GlobalAcceleratorConfiguration(const css::uno::Reference
< css::uno::XComponentContext
>& xContext
)
78 : GlobalAcceleratorConfiguration_BASE(xContext
)
80 // force keyboard string registration.
84 void GlobalAcceleratorConfiguration::fillCache()
86 /** read all data into the cache. */
89 // get current office locale ... but don't cache it.
90 // Otherwise we must be listener on the configuration layer
91 // which seems to superfluous for this small implementation .-)
92 // XXX: what is this good for? it was a comphelper::Locale but unused
93 LanguageTag
aLanguageTag(m_sLocale
);
96 // May be there exists no accelerator config? Handle it gracefully :-)
99 m_sGlobalOrModules
= CFG_ENTRY_GLOBAL
;
100 XCUBasedAcceleratorConfiguration::reload();
102 css::uno::Reference
< css::util::XChangesNotifier
> xBroadcaster(m_xCfg
, css::uno::UNO_QUERY_THROW
);
103 m_xCfgListener
= new WeakChangesListener(this);
104 xBroadcaster
->addChangesListener(m_xCfgListener
);
106 catch(const css::uno::RuntimeException
&)
108 catch(const css::uno::Exception
&)
114 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
115 com_sun_star_comp_framework_GlobalAcceleratorConfiguration_get_implementation(
116 css::uno::XComponentContext
*context
,
117 css::uno::Sequence
<css::uno::Any
> const &)
119 rtl::Reference
<GlobalAcceleratorConfiguration
> xGAC
= new GlobalAcceleratorConfiguration(context
);
121 return cppu::acquire(xGAC
.get());
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */