fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / accelerators / moduleacceleratorconfiguration.cxx
blob3d42c8e0be71423d65e4ff8832656c69e1ef5d07
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 <accelerators/presethandler.hxx>
22 #include "helper/mischelper.hxx"
24 #include <acceleratorconst.h>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
29 #include <com/sun/star/embed/ElementModes.hpp>
31 #include <cppuhelper/supportsservice.hxx>
32 #include <comphelper/sequenceashashmap.hxx>
33 #include <vcl/svapp.hxx>
35 #include <com/sun/star/util/XChangesNotifier.hpp>
37 #include <cppuhelper/implbase1.hxx>
38 #include <rtl/ref.hxx>
40 using namespace framework;
42 namespace {
44 /**
45 implements a read/write access to a module
46 dependent accelerator configuration.
48 typedef ::cppu::ImplInheritanceHelper1<
49 XCUBasedAcceleratorConfiguration,
50 css::lang::XServiceInfo > ModuleAcceleratorConfiguration_BASE;
52 class ModuleAcceleratorConfiguration : public ModuleAcceleratorConfiguration_BASE
54 private:
55 /** identify the application module, where this accelerator
56 configuration cache should work on. */
57 OUString m_sModule;
58 OUString m_sLocale;
60 public:
62 /** initialize this instance and fill the internal cache.
64 @param xSMGR
65 reference to an uno service manager, which is used internally.
67 ModuleAcceleratorConfiguration(
68 const css::uno::Reference< css::uno::XComponentContext >& xContext,
69 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& lArguments);
71 /** TODO */
72 virtual ~ModuleAcceleratorConfiguration();
74 virtual OUString SAL_CALL getImplementationName()
75 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
77 return OUString("com.sun.star.comp.framework.ModuleAcceleratorConfiguration");
80 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
81 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
83 return cppu::supportsService(this, ServiceName);
86 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
87 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
89 css::uno::Sequence< OUString > aSeq(1);
90 aSeq[0] = "com.sun.star.ui.ModuleAcceleratorConfiguration";
91 return aSeq;
94 // XComponent
95 virtual void SAL_CALL dispose() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
97 /// This has to be called after when the instance is acquire()'d.
98 void SAL_CALL fillCache();
100 private:
101 /** helper to listen for configuration changes without ownership cycle problems */
102 css::uno::Reference< css::util::XChangesListener > m_xCfgListener;
105 ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration(
106 const css::uno::Reference< css::uno::XComponentContext >& xContext,
107 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& lArguments)
108 : ModuleAcceleratorConfiguration_BASE(xContext)
110 SolarMutexGuard g;
112 OUString sModule;
113 if (lArguments.getLength() == 1 && (lArguments[0] >>= sModule))
115 m_sModule = sModule;
116 } else
118 ::comphelper::SequenceAsHashMap lArgs(lArguments);
119 m_sModule = lArgs.getUnpackedValueOrDefault("ModuleIdentifier", OUString());
120 m_sLocale = lArgs.getUnpackedValueOrDefault("Locale", OUString("x-default"));
123 if (m_sModule.isEmpty())
124 throw css::uno::RuntimeException(
125 OUString("The module dependent accelerator configuration service was initialized with an empty module identifier!"),
126 static_cast< ::cppu::OWeakObject* >(this));
129 ModuleAcceleratorConfiguration::~ModuleAcceleratorConfiguration()
133 void ModuleAcceleratorConfiguration::fillCache()
136 SolarMutexGuard g;
137 m_sModuleCFG = m_sModule;
140 #if 0
141 // get current office locale ... but dont cache it.
142 // Otherwise we must be listener on the configuration layer
143 // which seems to superflous for this small implementation .-)
144 // XXX: what is this good for? it was a comphelper::Locale but unused
145 LanguageTag aLanguageTag(m_sLocale);
146 #endif
148 // May be the current app module does not have any
149 // accelerator config? Handle it gracefully :-)
152 m_sGlobalOrModules = CFG_ENTRY_MODULES;
153 XCUBasedAcceleratorConfiguration::reload();
155 css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
156 m_xCfgListener = new WeakChangesListener(this);
157 xBroadcaster->addChangesListener(m_xCfgListener);
159 catch(const css::uno::RuntimeException&)
160 { throw; }
161 catch(const css::uno::Exception&)
165 // XComponent.dispose(), #i120029#, to release the cyclic reference
167 void SAL_CALL ModuleAcceleratorConfiguration::dispose()
168 throw(css::uno::RuntimeException, std::exception)
172 css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
173 if ( xBroadcaster.is() )
174 xBroadcaster->removeChangesListener(static_cast< css::util::XChangesListener* >(this));
176 catch(const css::uno::RuntimeException&)
177 { throw; }
178 catch(const css::uno::Exception&)
184 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
185 com_sun_star_comp_framework_ModuleAcceleratorConfiguration_get_implementation(
186 css::uno::XComponentContext *context,
187 css::uno::Sequence<css::uno::Any> const &arguments)
189 ModuleAcceleratorConfiguration *inst = new ModuleAcceleratorConfiguration(context, arguments);
190 css::uno::XInterface *acquired_inst = cppu::acquire(inst);
192 inst->fillCache();
194 return acquired_inst;
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */