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:09:32 +00:00
|
|
|
|
Replace salhelper::SingletonRef with rtl::Static
When destroying the static vcl::CommandInfoProvider aProvider from
vcl::CommandInfoProvider::Instance (vcl/source/helper/commandinfoprovider.cxx)
during exit, it releases its mxCachedGlobalAcceleratorConfiguration reference on
GlobalAcceleratorConfiguration
(framework/source/accelerators/globalacceleratorconfiguration.cxx), which may
get destroyed, whose base class framework::XCUBasedAcceleratorConfiguration
(framework/source/inc/accelerators/acceleratorconfiguration.hxx) has a
salhelper::SingletonRef<framework::KeyMapping> member, whose destructor
(include/salhelper/singletonref.hxx) uses
salhelper::SingletonRef<framework::KeyMapping>::SingletonLockInit::operator ()'s
static osl::Mutex aInstance.
If, during construction, the instantiation of
salhelper::SingletonRef<framework::KeyMapping>::SingletonLockInit::operator ()'s
static osl::Mutex aInstance finishes before the instantiation of
vcl::CommandInfoProvider::Instance's static vcl::CommandInfoProvider aProvider,
the corresponding atexit cleanup actions will be recorded in the right order,
causing the above chain of calls to find the static Mutex still alive when used
from within the static CommandInfoProvider's destruction.
However, vcl::CommandInfoProvider's mxCachedGlobalAcceleratorConfiguration is
only set to css::ui::GlobalAcceleratorConfiguration::create in
vcl::CommandInfoProvider::GetGlobalAcceleratorConfiguration, so the
instantiation of the static Mutex instance can finish after the instantiation of
the static CommandInfoProvider instance, recording the atexit cleanup actions in
the wrong order, causing the static Mutex to be used after destruction.
This occasionally caused PythonTest_sfx2_python to hang during exit for me on
Linux, where trying to lock a destroyed pthread mutex can apparently deadlock.
rtl::Static does away with the need to do anything in the destructor, at the
expense of always keeping the instance alive until exit (and not being able to
recreate an already destroyed instance during exit, but code that would require
that behavior would probably already be broken to begin with), so the order of
creation of the CommandInfoProvider and GlobalAcceleratorConfiguration instances
becomes less of a concern.
Change-Id: Id6e3860ad9e5b7045980a0b9bf9eaef2e24129bb
2016-01-26 15:09:30 +01:00
|
|
|
#include <sal/config.h>
|
|
|
|
|
|
|
|
#include <accelerators/keymapping.hxx>
|
2004-09-20 09:09:32 +00:00
|
|
|
#include <xml/acceleratorconfigurationreader.hxx>
|
|
|
|
|
|
|
|
#include <acceleratorconst.h>
|
|
|
|
|
|
|
|
#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
|
2017-04-13 14:33:23 +02:00
|
|
|
#include <com/sun/star/xml/sax/SAXException.hpp>
|
2004-09-20 09:09:32 +00:00
|
|
|
#include <com/sun/star/awt/KeyModifier.hpp>
|
|
|
|
#include <com/sun/star/awt/KeyEvent.hpp>
|
|
|
|
#include <com/sun/star/awt/Key.hpp>
|
|
|
|
#include <com/sun/star/container/ElementExistException.hpp>
|
|
|
|
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
|
|
|
|
namespace framework{
|
|
|
|
|
2015-03-25 21:12:16 +01:00
|
|
|
/* Throws a SaxException in case a wrong formatted XML
|
2004-09-20 09:09:32 +00:00
|
|
|
structure was detected.
|
|
|
|
|
|
|
|
This macro combined the given comment with a generic
|
2010-12-04 13:16:21 +09:00
|
|
|
way to find out the XML line (where the error occurred)
|
2004-09-20 09:09:32 +00:00
|
|
|
to format a suitable message.
|
|
|
|
|
|
|
|
@param COMMENT
|
|
|
|
an ascii string, which describe the problem.
|
|
|
|
*/
|
|
|
|
#define THROW_PARSEEXCEPTION(COMMENT) \
|
|
|
|
{ \
|
|
|
|
throw css::xml::sax::SAXException( \
|
2017-02-01 12:24:07 +02:00
|
|
|
implts_getErrorLineString() + COMMENT, \
|
2004-09-20 09:09:32 +00:00
|
|
|
static_cast< css::xml::sax::XDocumentHandler* >(this), \
|
|
|
|
css::uno::Any()); \
|
|
|
|
}
|
|
|
|
|
|
|
|
AcceleratorConfigurationReader::AcceleratorConfigurationReader(AcceleratorCache& rContainer)
|
2014-03-19 17:44:03 +01:00
|
|
|
: m_rContainer (rContainer )
|
2014-04-04 15:53:21 +02:00
|
|
|
, m_bInsideAcceleratorList(false )
|
|
|
|
, m_bInsideAcceleratorItem(false )
|
2004-09-20 09:09:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AcceleratorConfigurationReader::~AcceleratorConfigurationReader()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL AcceleratorConfigurationReader::startDocument()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL AcceleratorConfigurationReader::endDocument()
|
|
|
|
{
|
|
|
|
// The xml file seems to be corrupted.
|
|
|
|
// Because we found no end-tags ... at least for
|
|
|
|
// one list or item.
|
|
|
|
if (
|
|
|
|
(m_bInsideAcceleratorList) ||
|
|
|
|
(m_bInsideAcceleratorItem)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
THROW_PARSEEXCEPTION("No matching start or end element 'acceleratorlist' found!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SAL_CALL AcceleratorConfigurationReader::startElement(const OUString& sElement ,
|
2004-09-20 09:09:32 +00:00
|
|
|
const css::uno::Reference< css::xml::sax::XAttributeList >& xAttributeList)
|
|
|
|
{
|
|
|
|
EXMLElement eElement = AcceleratorConfigurationReader::implst_classifyElement(sElement);
|
|
|
|
|
|
|
|
// Note: We handle "accel:item" before "accel:acceleratorlist" to perform this operation.
|
2013-09-26 11:44:54 +02:00
|
|
|
// Because an item occurs very often ... a list should occur one times only!
|
2004-09-20 09:09:32 +00:00
|
|
|
if (eElement == E_ELEMENT_ITEM)
|
|
|
|
{
|
|
|
|
if (!m_bInsideAcceleratorList)
|
2014-04-29 19:05:05 +00:00
|
|
|
THROW_PARSEEXCEPTION("An element \"accel:item\" must be embedded into 'accel:acceleratorlist'.")
|
2004-09-20 09:09:32 +00:00
|
|
|
if (m_bInsideAcceleratorItem)
|
|
|
|
THROW_PARSEEXCEPTION("An element \"accel:item\" is not a container.")
|
2014-04-04 15:53:21 +02:00
|
|
|
m_bInsideAcceleratorItem = true;
|
2004-09-20 09:09:32 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sCommand;
|
2014-04-06 19:36:08 +03:00
|
|
|
css::awt::KeyEvent aEvent;
|
2004-09-20 09:09:32 +00:00
|
|
|
|
|
|
|
sal_Int16 c = xAttributeList->getLength();
|
|
|
|
sal_Int16 i = 0;
|
|
|
|
for (i=0; i<c; ++i)
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sAttribute = xAttributeList->getNameByIndex(i);
|
|
|
|
OUString sValue = xAttributeList->getValueByIndex(i);
|
2004-09-20 09:09:32 +00:00
|
|
|
EXMLAttribute eAttribute = AcceleratorConfigurationReader::implst_classifyAttribute(sAttribute);
|
|
|
|
switch(eAttribute)
|
|
|
|
{
|
|
|
|
case E_ATTRIBUTE_URL :
|
2007-04-03 12:50:38 +00:00
|
|
|
sCommand = sValue.intern();
|
2004-09-20 09:09:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case E_ATTRIBUTE_KEYCODE :
|
Replace salhelper::SingletonRef with rtl::Static
When destroying the static vcl::CommandInfoProvider aProvider from
vcl::CommandInfoProvider::Instance (vcl/source/helper/commandinfoprovider.cxx)
during exit, it releases its mxCachedGlobalAcceleratorConfiguration reference on
GlobalAcceleratorConfiguration
(framework/source/accelerators/globalacceleratorconfiguration.cxx), which may
get destroyed, whose base class framework::XCUBasedAcceleratorConfiguration
(framework/source/inc/accelerators/acceleratorconfiguration.hxx) has a
salhelper::SingletonRef<framework::KeyMapping> member, whose destructor
(include/salhelper/singletonref.hxx) uses
salhelper::SingletonRef<framework::KeyMapping>::SingletonLockInit::operator ()'s
static osl::Mutex aInstance.
If, during construction, the instantiation of
salhelper::SingletonRef<framework::KeyMapping>::SingletonLockInit::operator ()'s
static osl::Mutex aInstance finishes before the instantiation of
vcl::CommandInfoProvider::Instance's static vcl::CommandInfoProvider aProvider,
the corresponding atexit cleanup actions will be recorded in the right order,
causing the above chain of calls to find the static Mutex still alive when used
from within the static CommandInfoProvider's destruction.
However, vcl::CommandInfoProvider's mxCachedGlobalAcceleratorConfiguration is
only set to css::ui::GlobalAcceleratorConfiguration::create in
vcl::CommandInfoProvider::GetGlobalAcceleratorConfiguration, so the
instantiation of the static Mutex instance can finish after the instantiation of
the static CommandInfoProvider instance, recording the atexit cleanup actions in
the wrong order, causing the static Mutex to be used after destruction.
This occasionally caused PythonTest_sfx2_python to hang during exit for me on
Linux, where trying to lock a destroyed pthread mutex can apparently deadlock.
rtl::Static does away with the need to do anything in the destructor, at the
expense of always keeping the instance alive until exit (and not being able to
recreate an already destroyed instance during exit, but code that would require
that behavior would probably already be broken to begin with), so the order of
creation of the CommandInfoProvider and GlobalAcceleratorConfiguration instances
becomes less of a concern.
Change-Id: Id6e3860ad9e5b7045980a0b9bf9eaef2e24129bb
2016-01-26 15:09:30 +01:00
|
|
|
aEvent.KeyCode = KeyMapping::get().mapIdentifierToCode(sValue);
|
2004-09-20 09:09:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case E_ATTRIBUTE_MOD_SHIFT :
|
|
|
|
aEvent.Modifiers |= css::awt::KeyModifier::SHIFT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_ATTRIBUTE_MOD_MOD1 :
|
|
|
|
aEvent.Modifiers |= css::awt::KeyModifier::MOD1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_ATTRIBUTE_MOD_MOD2 :
|
|
|
|
aEvent.Modifiers |= css::awt::KeyModifier::MOD2;
|
|
|
|
break;
|
2009-04-12 04:24:43 +00:00
|
|
|
|
|
|
|
case E_ATTRIBUTE_MOD_MOD3 :
|
|
|
|
aEvent.Modifiers |= css::awt::KeyModifier::MOD3;
|
2004-09-20 09:09:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate command and key event.
|
|
|
|
if (
|
2011-12-26 14:20:50 -02:00
|
|
|
sCommand.isEmpty() ||
|
2004-09-20 09:09:32 +00:00
|
|
|
(aEvent.KeyCode == 0 )
|
|
|
|
)
|
|
|
|
{
|
|
|
|
THROW_PARSEEXCEPTION("XML element does not describe a valid accelerator nor a valid command.")
|
|
|
|
}
|
|
|
|
|
|
|
|
// register key event + command inside cache ...
|
|
|
|
// Check for already existing items there.
|
|
|
|
if (!m_rContainer.hasKey(aEvent))
|
|
|
|
m_rContainer.setKeyCommandPair(aEvent, sCommand);
|
|
|
|
else
|
|
|
|
{
|
2016-10-02 00:28:47 +02:00
|
|
|
// Attention: It's not really a reason to throw an exception and kill the office, if the configuration contains
|
2004-09-20 09:09:32 +00:00
|
|
|
// multiple registrations for the same key :-) Show a warning ... and ignore the second item.
|
2014-08-01 16:56:25 +09:00
|
|
|
// THROW_PARSEEXCEPTION("Command is registered for the same key more than once.")
|
2013-09-08 21:49:45 +03:00
|
|
|
SAL_INFO("fwk",
|
|
|
|
"AcceleratorConfigurationReader::startElement(): Double registration detected. Command=\"" <<
|
|
|
|
sCommand <<
|
|
|
|
"\" KeyCode=" <<
|
|
|
|
aEvent.KeyCode <<
|
|
|
|
"Modifiers=" <<
|
|
|
|
aEvent.Modifiers);
|
2004-09-20 09:09:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eElement == E_ELEMENT_ACCELERATORLIST)
|
|
|
|
{
|
|
|
|
if (m_bInsideAcceleratorList)
|
|
|
|
THROW_PARSEEXCEPTION("An element \"accel:acceleratorlist\" cannot be used recursive.")
|
2014-04-04 15:53:21 +02:00
|
|
|
m_bInsideAcceleratorList = true;
|
2004-09-20 09:09:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SAL_CALL AcceleratorConfigurationReader::endElement(const OUString& sElement)
|
2004-09-20 09:09:32 +00:00
|
|
|
{
|
|
|
|
EXMLElement eElement = AcceleratorConfigurationReader::implst_classifyElement(sElement);
|
|
|
|
|
|
|
|
// Note: We handle "accel:item" before "accel:acceleratorlist" to perform this operation.
|
2013-09-26 11:44:54 +02:00
|
|
|
// Because an item occurs very often ... a list should occur one times only!
|
2004-09-20 09:09:32 +00:00
|
|
|
if (eElement == E_ELEMENT_ITEM)
|
|
|
|
{
|
|
|
|
if (!m_bInsideAcceleratorItem)
|
|
|
|
THROW_PARSEEXCEPTION("Found end element 'accel:item', but no start element.")
|
2014-04-04 15:53:21 +02:00
|
|
|
m_bInsideAcceleratorItem = false;
|
2004-09-20 09:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (eElement == E_ELEMENT_ACCELERATORLIST)
|
|
|
|
{
|
|
|
|
if (!m_bInsideAcceleratorList)
|
|
|
|
THROW_PARSEEXCEPTION("Found end element 'accel:acceleratorlist', but no start element.")
|
2014-04-04 15:53:21 +02:00
|
|
|
m_bInsideAcceleratorList = false;
|
2004-09-20 09:09:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SAL_CALL AcceleratorConfigurationReader::characters(const OUString&)
|
2004-09-20 09:09:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SAL_CALL AcceleratorConfigurationReader::ignorableWhitespace(const OUString&)
|
2004-09-20 09:09:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SAL_CALL AcceleratorConfigurationReader::processingInstruction(const OUString& /*sTarget*/,
|
|
|
|
const OUString& /*sData*/ )
|
2004-09-20 09:09:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL AcceleratorConfigurationReader::setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator >& xLocator)
|
|
|
|
{
|
|
|
|
m_xLocator = xLocator;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
AcceleratorConfigurationReader::EXMLElement AcceleratorConfigurationReader::implst_classifyElement(const OUString& sElement)
|
2004-09-20 09:09:32 +00:00
|
|
|
{
|
|
|
|
AcceleratorConfigurationReader::EXMLElement eElement;
|
|
|
|
|
2014-12-18 13:19:13 +01:00
|
|
|
if (sElement == "http://openoffice.org/2001/accel^acceleratorlist")
|
2004-09-20 09:09:32 +00:00
|
|
|
eElement = E_ELEMENT_ACCELERATORLIST;
|
2014-12-18 13:19:13 +01:00
|
|
|
else if (sElement == "http://openoffice.org/2001/accel^item")
|
2004-09-20 09:09:32 +00:00
|
|
|
eElement = E_ELEMENT_ITEM;
|
|
|
|
else
|
|
|
|
throw css::uno::RuntimeException(
|
2013-09-09 00:58:15 +03:00
|
|
|
"Unknown XML element detected!",
|
2004-09-20 09:09:32 +00:00
|
|
|
css::uno::Reference< css::xml::sax::XDocumentHandler >());
|
|
|
|
|
|
|
|
return eElement;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
AcceleratorConfigurationReader::EXMLAttribute AcceleratorConfigurationReader::implst_classifyAttribute(const OUString& sAttribute)
|
2004-09-20 09:09:32 +00:00
|
|
|
{
|
|
|
|
AcceleratorConfigurationReader::EXMLAttribute eAttribute;
|
|
|
|
|
2014-12-18 13:19:13 +01:00
|
|
|
if (sAttribute == "http://openoffice.org/2001/accel^code")
|
2004-09-20 09:09:32 +00:00
|
|
|
eAttribute = E_ATTRIBUTE_KEYCODE;
|
2014-12-18 13:19:13 +01:00
|
|
|
else if (sAttribute == "http://openoffice.org/2001/accel^shift")
|
2004-09-20 09:09:32 +00:00
|
|
|
eAttribute = E_ATTRIBUTE_MOD_SHIFT;
|
2014-12-18 13:19:13 +01:00
|
|
|
else if (sAttribute == "http://openoffice.org/2001/accel^mod1")
|
2004-09-20 09:09:32 +00:00
|
|
|
eAttribute = E_ATTRIBUTE_MOD_MOD1;
|
2014-12-18 13:19:13 +01:00
|
|
|
else if (sAttribute == "http://openoffice.org/2001/accel^mod2")
|
2004-09-20 09:09:32 +00:00
|
|
|
eAttribute = E_ATTRIBUTE_MOD_MOD2;
|
2014-12-18 13:19:13 +01:00
|
|
|
else if (sAttribute == "http://openoffice.org/2001/accel^mod3")
|
2009-04-12 04:24:43 +00:00
|
|
|
eAttribute = E_ATTRIBUTE_MOD_MOD3;
|
2014-12-18 13:19:13 +01:00
|
|
|
else if (sAttribute == "http://www.w3.org/1999/xlink^href")
|
2004-09-20 09:09:32 +00:00
|
|
|
eAttribute = E_ATTRIBUTE_URL;
|
|
|
|
else
|
|
|
|
throw css::uno::RuntimeException(
|
2013-09-09 00:58:15 +03:00
|
|
|
"Unknown XML attribute detected!",
|
2004-09-20 09:09:32 +00:00
|
|
|
css::uno::Reference< css::xml::sax::XDocumentHandler >());
|
|
|
|
|
|
|
|
return eAttribute;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString AcceleratorConfigurationReader::implts_getErrorLineString()
|
2004-09-20 09:09:32 +00:00
|
|
|
{
|
|
|
|
if (!m_xLocator.is())
|
2013-09-09 01:52:09 +03:00
|
|
|
return OUString("Error during parsing XML. (No further info available ...)");
|
2004-09-20 09:09:32 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringBuffer sMsg(256);
|
2015-08-31 08:03:15 +02:00
|
|
|
sMsg.append("Error during parsing XML in\nline = ");
|
2004-09-20 09:09:32 +00:00
|
|
|
sMsg.append (m_xLocator->getLineNumber() );
|
2015-08-31 08:03:15 +02:00
|
|
|
sMsg.append("\ncolumn = " );
|
2004-09-20 09:09:32 +00:00
|
|
|
sMsg.append (m_xLocator->getColumnNumber() );
|
2015-08-31 08:03:15 +02:00
|
|
|
sMsg.append("." );
|
2004-09-20 09:09:32 +00:00
|
|
|
return sMsg.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace framework
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|