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:42 +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:42 +00:00
|
|
|
#include <xml/acceleratorconfigurationwriter.hxx>
|
|
|
|
|
|
|
|
#include <acceleratorconst.h>
|
|
|
|
|
|
|
|
#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
|
|
|
|
#include <com/sun/star/xml/sax/XAttributeList.hpp>
|
|
|
|
#include <com/sun/star/awt/KeyModifier.hpp>
|
|
|
|
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
|
INTEGRATION: CWS xmlfix2 (1.5.260); FILE MERGED
2008/05/15 17:20:04 mst 1.5.260.2: RESYNC: (1.5-1.6); FILE MERGED
2008/03/31 15:32:49 mst 1.5.260.1: remove duplicated XAttributeList implementations
- framework/inc/services/attributelist.hxx,
framework/source/services/attributelist.cxx,
framework/inc/xml/attributelist.hxx,
framework/source/xml/attributelist.cxx:
+ removed
- framework/source/xml/makefile.mk, framework/util/makefile.mk:
+ remove attributelist.cxx
- framework/source/xml/{acceleratorconfigurationwriter.cxx,
eventsdocumenthandler.cxx,imagesdocumenthandler.cxx,
menudocumenthandler.cxx,saxnamespacefilter.cxx,
statusbardocumenthandler.cxx,toolboxdocumenthandler.cxx,
toolboxlayoutdocumenthandler.cxx}
+ use comphelper/attributelist.hxx
2008-06-06 10:59:58 +00:00
|
|
|
#include <comphelper/attributelist.hxx>
|
|
|
|
|
2004-09-20 09:09:42 +00:00
|
|
|
namespace framework{
|
|
|
|
|
|
|
|
AcceleratorConfigurationWriter::AcceleratorConfigurationWriter(const AcceleratorCache& rContainer,
|
|
|
|
const css::uno::Reference< css::xml::sax::XDocumentHandler >& xConfig )
|
2014-03-19 17:26:52 +01:00
|
|
|
: m_xConfig (xConfig )
|
2006-06-19 10:44:47 +00:00
|
|
|
, m_rContainer (rContainer )
|
2004-09-20 09:09:42 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AcceleratorConfigurationWriter::~AcceleratorConfigurationWriter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void AcceleratorConfigurationWriter::flush()
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::xml::sax::XExtendedDocumentHandler > xExtendedCFG(m_xConfig, css::uno::UNO_QUERY_THROW);
|
|
|
|
|
|
|
|
// prepare attribute list
|
INTEGRATION: CWS xmlfix2 (1.5.260); FILE MERGED
2008/05/15 17:20:04 mst 1.5.260.2: RESYNC: (1.5-1.6); FILE MERGED
2008/03/31 15:32:49 mst 1.5.260.1: remove duplicated XAttributeList implementations
- framework/inc/services/attributelist.hxx,
framework/source/services/attributelist.cxx,
framework/inc/xml/attributelist.hxx,
framework/source/xml/attributelist.cxx:
+ removed
- framework/source/xml/makefile.mk, framework/util/makefile.mk:
+ remove attributelist.cxx
- framework/source/xml/{acceleratorconfigurationwriter.cxx,
eventsdocumenthandler.cxx,imagesdocumenthandler.cxx,
menudocumenthandler.cxx,saxnamespacefilter.cxx,
statusbardocumenthandler.cxx,toolboxdocumenthandler.cxx,
toolboxlayoutdocumenthandler.cxx}
+ use comphelper/attributelist.hxx
2008-06-06 10:59:58 +00:00
|
|
|
::comphelper::AttributeList* pAttribs = new ::comphelper::AttributeList;
|
2004-09-20 09:09:42 +00:00
|
|
|
css::uno::Reference< css::xml::sax::XAttributeList > xAttribs(static_cast< css::xml::sax::XAttributeList* >(pAttribs), css::uno::UNO_QUERY);
|
|
|
|
|
2016-04-19 08:49:06 +02:00
|
|
|
pAttribs->AddAttribute(
|
|
|
|
"xmlns:accel", ATTRIBUTE_TYPE_CDATA,
|
|
|
|
"http://openoffice.org/2001/accel");
|
|
|
|
pAttribs->AddAttribute(
|
|
|
|
"xmlns:xlink", ATTRIBUTE_TYPE_CDATA, "http://www.w3.org/1999/xlink");
|
2004-09-20 09:09:42 +00:00
|
|
|
|
|
|
|
// generate xml
|
2014-03-19 17:26:52 +01:00
|
|
|
xExtendedCFG->startDocument();
|
2004-09-20 09:09:42 +00:00
|
|
|
|
2016-04-18 17:36:43 +02:00
|
|
|
xExtendedCFG->unknown(
|
|
|
|
"<!DOCTYPE accel:acceleratorlist PUBLIC \"-//OpenOffice.org//DTD"
|
|
|
|
" OfficeDocument 1.0//EN\" \"accelerator.dtd\">");
|
2014-03-19 17:26:52 +01:00
|
|
|
xExtendedCFG->ignorableWhitespace(OUString());
|
2004-09-20 09:09:42 +00:00
|
|
|
|
2014-03-19 17:26:52 +01:00
|
|
|
xExtendedCFG->startElement(AL_ELEMENT_ACCELERATORLIST, xAttribs);
|
|
|
|
xExtendedCFG->ignorableWhitespace(OUString());
|
2004-09-20 09:09:42 +00:00
|
|
|
|
|
|
|
// TODO think about threadsafe using of cache
|
|
|
|
AcceleratorCache::TKeyList lKeys = m_rContainer.getAllKeys();
|
2018-03-17 21:42:27 +01:00
|
|
|
for (auto const& lKey : lKeys)
|
2004-09-20 09:09:42 +00:00
|
|
|
{
|
2018-03-17 21:42:27 +01:00
|
|
|
const OUString& rCommand = m_rContainer.getCommandByKey(lKey);
|
|
|
|
impl_ts_writeKeyCommandPair(lKey, rCommand, xExtendedCFG);
|
2004-09-20 09:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO write key-command list
|
2018-03-17 21:42:27 +01:00
|
|
|
for (auto const& writeAccelerator : m_aWriteAcceleratorList)
|
|
|
|
WriteAcceleratorItem(writeAccelerator);
|
2004-09-20 09:09:42 +00:00
|
|
|
*/
|
|
|
|
|
2014-03-19 17:26:52 +01:00
|
|
|
xExtendedCFG->ignorableWhitespace(OUString());
|
|
|
|
xExtendedCFG->endElement(AL_ELEMENT_ACCELERATORLIST);
|
|
|
|
xExtendedCFG->ignorableWhitespace(OUString());
|
|
|
|
xExtendedCFG->endDocument();
|
2004-09-20 09:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AcceleratorConfigurationWriter::impl_ts_writeKeyCommandPair(const css::awt::KeyEvent& aKey ,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& sCommand,
|
2004-09-20 09:09:42 +00:00
|
|
|
const css::uno::Reference< css::xml::sax::XDocumentHandler >& xConfig )
|
|
|
|
{
|
INTEGRATION: CWS xmlfix2 (1.5.260); FILE MERGED
2008/05/15 17:20:04 mst 1.5.260.2: RESYNC: (1.5-1.6); FILE MERGED
2008/03/31 15:32:49 mst 1.5.260.1: remove duplicated XAttributeList implementations
- framework/inc/services/attributelist.hxx,
framework/source/services/attributelist.cxx,
framework/inc/xml/attributelist.hxx,
framework/source/xml/attributelist.cxx:
+ removed
- framework/source/xml/makefile.mk, framework/util/makefile.mk:
+ remove attributelist.cxx
- framework/source/xml/{acceleratorconfigurationwriter.cxx,
eventsdocumenthandler.cxx,imagesdocumenthandler.cxx,
menudocumenthandler.cxx,saxnamespacefilter.cxx,
statusbardocumenthandler.cxx,toolboxdocumenthandler.cxx,
toolboxlayoutdocumenthandler.cxx}
+ use comphelper/attributelist.hxx
2008-06-06 10:59:58 +00:00
|
|
|
::comphelper::AttributeList* pAttribs = new ::comphelper::AttributeList;
|
2004-09-20 09:09:42 +00:00
|
|
|
css::uno::Reference< css::xml::sax::XAttributeList > xAttribs (static_cast< css::xml::sax::XAttributeList* >(pAttribs) , css::uno::UNO_QUERY_THROW);
|
|
|
|
|
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
|
|
|
OUString sKey = KeyMapping::get().mapCodeToIdentifier(aKey.KeyCode);
|
2004-09-20 09:09:42 +00:00
|
|
|
// TODO check if key is empty!
|
|
|
|
|
2016-04-19 08:49:06 +02:00
|
|
|
pAttribs->AddAttribute("accel:code", ATTRIBUTE_TYPE_CDATA, sKey );
|
|
|
|
pAttribs->AddAttribute("xlink:href", ATTRIBUTE_TYPE_CDATA, sCommand);
|
2004-09-20 09:09:42 +00:00
|
|
|
|
|
|
|
if ((aKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT)
|
2016-04-19 08:49:06 +02:00
|
|
|
pAttribs->AddAttribute("accel:shift", ATTRIBUTE_TYPE_CDATA, "true");
|
2004-09-20 09:09:42 +00:00
|
|
|
|
|
|
|
if ((aKey.Modifiers & css::awt::KeyModifier::MOD1) == css::awt::KeyModifier::MOD1)
|
2016-04-19 08:49:06 +02:00
|
|
|
pAttribs->AddAttribute("accel:mod1", ATTRIBUTE_TYPE_CDATA, "true");
|
2004-09-20 09:09:42 +00:00
|
|
|
|
|
|
|
if ((aKey.Modifiers & css::awt::KeyModifier::MOD2) == css::awt::KeyModifier::MOD2)
|
2016-04-19 08:49:06 +02:00
|
|
|
pAttribs->AddAttribute("accel:mod2", ATTRIBUTE_TYPE_CDATA, "true");
|
2004-09-20 09:09:42 +00:00
|
|
|
|
2009-04-12 04:24:43 +00:00
|
|
|
if ((aKey.Modifiers & css::awt::KeyModifier::MOD3) == css::awt::KeyModifier::MOD3)
|
2016-04-19 08:49:06 +02:00
|
|
|
pAttribs->AddAttribute("accel:mod3", ATTRIBUTE_TYPE_CDATA, "true");
|
2009-04-12 04:24:43 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
xConfig->ignorableWhitespace(OUString());
|
2004-09-20 09:09:42 +00:00
|
|
|
xConfig->startElement(AL_ELEMENT_ITEM, xAttribs);
|
2013-04-07 12:06:47 +02:00
|
|
|
xConfig->ignorableWhitespace(OUString());
|
2004-09-20 09:09:42 +00:00
|
|
|
xConfig->endElement(AL_ELEMENT_ITEM);
|
2013-04-07 12:06:47 +02:00
|
|
|
xConfig->ignorableWhitespace(OUString());
|
2004-09-20 09:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace framework
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|