2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-09-20 09:06:24 +00:00
|
|
|
|
2014-01-09 20:33:11 +01:00
|
|
|
#include <accelerators/acceleratorconfiguration.hxx>
|
|
|
|
#include <accelerators/presethandler.hxx>
|
2011-03-23 16:10:20 +00:00
|
|
|
#include "helper/mischelper.hxx"
|
2004-09-20 09:06:24 +00:00
|
|
|
|
|
|
|
#include <acceleratorconst.h>
|
|
|
|
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
2014-01-09 20:33:11 +01:00
|
|
|
#include <com/sun/star/lang/XServiceInfo.hpp>
|
2004-09-20 09:06:24 +00:00
|
|
|
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/embed/ElementModes.hpp>
|
|
|
|
|
2014-01-09 20:33:11 +01:00
|
|
|
#include <cppuhelper/supportsservice.hxx>
|
2004-09-20 09:06:24 +00:00
|
|
|
#include <comphelper/sequenceashashmap.hxx>
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
|
2008-12-01 13:46:00 +00:00
|
|
|
#include <com/sun/star/util/XChangesNotifier.hpp>
|
|
|
|
|
2014-01-09 20:33:11 +01:00
|
|
|
#include <cppuhelper/implbase1.hxx>
|
|
|
|
#include <rtl/ref.hxx>
|
2008-12-01 13:46:00 +00:00
|
|
|
#include <rtl/logfile.h>
|
|
|
|
|
2014-01-09 20:33:11 +01:00
|
|
|
using namespace framework;
|
2004-09-20 09:06:24 +00:00
|
|
|
|
2014-01-09 20:33:11 +01:00
|
|
|
namespace {
|
2004-09-20 09:06:24 +00:00
|
|
|
|
2014-01-09 20:33:11 +01:00
|
|
|
/**
|
|
|
|
implements a read/write access to a module
|
2014-04-09 12:44:22 +02:00
|
|
|
dependent accelerator configuration.
|
2014-01-09 20:33:11 +01:00
|
|
|
*/
|
|
|
|
typedef ::cppu::ImplInheritanceHelper1<
|
|
|
|
XCUBasedAcceleratorConfiguration,
|
|
|
|
css::lang::XServiceInfo > ModuleAcceleratorConfiguration_BASE;
|
2004-09-20 09:06:24 +00:00
|
|
|
|
2014-01-09 20:33:11 +01:00
|
|
|
class ModuleAcceleratorConfiguration : public ModuleAcceleratorConfiguration_BASE
|
2004-09-20 09:06:24 +00:00
|
|
|
{
|
2014-01-09 20:33:11 +01:00
|
|
|
private:
|
|
|
|
/** identify the application module, where this accelerator
|
|
|
|
configuration cache should work on. */
|
|
|
|
OUString m_sModule;
|
|
|
|
OUString m_sLocale;
|
2004-09-20 09:06:24 +00:00
|
|
|
|
2014-01-09 20:33:11 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
/** initialize this instance and fill the internal cache.
|
|
|
|
|
|
|
|
@param xSMGR
|
2014-02-09 10:12:07 +01:00
|
|
|
reference to an uno service manager, which is used internally.
|
2014-01-09 20:33:11 +01:00
|
|
|
*/
|
|
|
|
ModuleAcceleratorConfiguration(
|
2014-01-22 11:54:19 +01:00
|
|
|
const css::uno::Reference< css::uno::XComponentContext >& xContext,
|
|
|
|
const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& lArguments);
|
2014-01-09 20:33:11 +01:00
|
|
|
|
|
|
|
/** TODO */
|
|
|
|
virtual ~ModuleAcceleratorConfiguration();
|
|
|
|
|
|
|
|
virtual OUString SAL_CALL getImplementationName()
|
2014-03-26 16:37:00 +01:00
|
|
|
throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
|
2014-01-09 20:33:11 +01:00
|
|
|
{
|
|
|
|
return OUString("com.sun.star.comp.framework.ModuleAcceleratorConfiguration");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
|
2014-03-26 16:37:00 +01:00
|
|
|
throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
|
2014-01-09 20:33:11 +01:00
|
|
|
{
|
|
|
|
return cppu::supportsService(this, ServiceName);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
|
2014-03-26 16:37:00 +01:00
|
|
|
throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
|
2014-01-09 20:33:11 +01:00
|
|
|
{
|
|
|
|
css::uno::Sequence< OUString > aSeq(1);
|
|
|
|
aSeq[0] = OUString("com.sun.star.ui.ModuleAcceleratorConfiguration");
|
|
|
|
return aSeq;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XComponent
|
2014-03-26 16:37:00 +01:00
|
|
|
virtual void SAL_CALL dispose() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
|
2014-01-09 20:33:11 +01:00
|
|
|
|
2014-01-22 11:54:19 +01:00
|
|
|
/// This has to be called after when the instance is acquire()'d.
|
|
|
|
void SAL_CALL fillCache();
|
2014-01-09 20:33:11 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
/** helper to listen for configuration changes without ownership cycle problems */
|
|
|
|
css::uno::Reference< css::util::XChangesListener > m_xCfgListener;
|
|
|
|
};
|
|
|
|
|
|
|
|
ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration(
|
2014-01-22 11:54:19 +01:00
|
|
|
const css::uno::Reference< css::uno::XComponentContext >& xContext,
|
|
|
|
const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& lArguments)
|
2014-01-09 20:33:11 +01:00
|
|
|
: ModuleAcceleratorConfiguration_BASE(xContext)
|
2004-09-20 09:06:24 +00:00
|
|
|
{
|
2014-03-18 08:16:40 +01:00
|
|
|
SolarMutexGuard g;
|
2004-09-20 09:06:24 +00:00
|
|
|
|
2013-05-27 14:52:39 +02:00
|
|
|
OUString sModule;
|
|
|
|
if (lArguments.getLength() == 1 && (lArguments[0] >>= sModule))
|
|
|
|
{
|
|
|
|
m_sModule = sModule;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
::comphelper::SequenceAsHashMap lArgs(lArguments);
|
2013-06-29 21:24:12 +02:00
|
|
|
m_sModule = lArgs.getUnpackedValueOrDefault("ModuleIdentifier", OUString());
|
|
|
|
m_sLocale = lArgs.getUnpackedValueOrDefault("Locale", OUString("x-default"));
|
2013-05-27 14:52:39 +02:00
|
|
|
}
|
2004-09-20 09:06:24 +00:00
|
|
|
|
2011-12-26 14:20:50 -02:00
|
|
|
if (m_sModule.isEmpty())
|
2004-09-20 09:06:24 +00:00
|
|
|
throw css::uno::RuntimeException(
|
2014-04-09 12:44:22 +02:00
|
|
|
OUString("The module dependent accelerator configuration service was initialized with an empty module identifier!"),
|
2004-09-20 09:06:24 +00:00
|
|
|
static_cast< ::cppu::OWeakObject* >(this));
|
2014-01-22 11:54:19 +01:00
|
|
|
}
|
2004-09-20 09:06:24 +00:00
|
|
|
|
2014-01-22 11:54:19 +01:00
|
|
|
ModuleAcceleratorConfiguration::~ModuleAcceleratorConfiguration()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModuleAcceleratorConfiguration::fillCache()
|
|
|
|
{
|
2014-03-18 08:16:40 +01:00
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
m_sModuleCFG = m_sModule;
|
|
|
|
}
|
2004-09-20 09:06:24 +00:00
|
|
|
|
2013-03-28 00:13:14 +01:00
|
|
|
#if 0
|
2004-09-20 09:06:24 +00:00
|
|
|
// get current office locale ... but dont cache it.
|
|
|
|
// Otherwise we must be listener on the configuration layer
|
|
|
|
// which seems to superflous for this small implementation .-)
|
2013-03-28 00:13:14 +01:00
|
|
|
// XXX: what is this good for? it was a comphelper::Locale but unused
|
|
|
|
LanguageTag aLanguageTag(m_sLocale);
|
|
|
|
#endif
|
2004-09-20 09:06:24 +00:00
|
|
|
|
2004-10-14 08:26:22 +00:00
|
|
|
// May be the current app module does not have any
|
|
|
|
// accelerator config? Handle it gracefully :-)
|
|
|
|
try
|
|
|
|
{
|
2008-12-01 13:46:00 +00:00
|
|
|
m_sGlobalOrModules = CFG_ENTRY_MODULES;
|
|
|
|
XCUBasedAcceleratorConfiguration::reload();
|
|
|
|
|
|
|
|
css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
|
2011-03-23 16:10:20 +00:00
|
|
|
m_xCfgListener = new WeakChangesListener(this);
|
|
|
|
xBroadcaster->addChangesListener(m_xCfgListener);
|
2004-10-14 08:26:22 +00:00
|
|
|
}
|
2012-02-02 22:53:48 +01:00
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
2004-10-14 08:26:22 +00:00
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{}
|
2004-09-20 09:06:24 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 11:58:32 +00:00
|
|
|
// XComponent.dispose(), #i120029#, to release the cyclic reference
|
2014-02-25 18:54:02 +01:00
|
|
|
|
2012-06-20 11:58:32 +00:00
|
|
|
void SAL_CALL ModuleAcceleratorConfiguration::dispose()
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(css::uno::RuntimeException, std::exception)
|
2012-06-20 11:58:32 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
|
|
|
|
if ( xBroadcaster.is() )
|
|
|
|
xBroadcaster->removeChangesListener(static_cast< css::util::XChangesListener* >(this));
|
|
|
|
}
|
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
|
2014-01-09 20:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
|
|
|
|
com_sun_star_comp_framework_ModuleAcceleratorConfiguration_get_implementation(
|
|
|
|
css::uno::XComponentContext *context,
|
2014-01-22 11:54:19 +01:00
|
|
|
css::uno::Sequence<css::uno::Any> const &arguments)
|
2014-01-09 20:33:11 +01:00
|
|
|
{
|
2014-01-22 11:54:19 +01:00
|
|
|
ModuleAcceleratorConfiguration *inst = new ModuleAcceleratorConfiguration(context, arguments);
|
|
|
|
css::uno::XInterface *acquired_inst = cppu::acquire(inst);
|
|
|
|
|
|
|
|
inst->fillCache();
|
2014-01-21 15:45:43 +01:00
|
|
|
|
2014-01-22 11:54:19 +01:00
|
|
|
return acquired_inst;
|
2014-01-09 20:33:11 +01:00
|
|
|
}
|
2004-11-17 13:58:05 +00:00
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|