diff options
Diffstat (limited to 'framework/source/accelerators/acceleratorconfiguration.cxx')
-rw-r--r-- | framework/source/accelerators/acceleratorconfiguration.cxx | 142 |
1 files changed, 91 insertions, 51 deletions
diff --git a/framework/source/accelerators/acceleratorconfiguration.cxx b/framework/source/accelerators/acceleratorconfiguration.cxx index 971e4c00024b..d19032660de5 100644 --- a/framework/source/accelerators/acceleratorconfiguration.cxx +++ b/framework/source/accelerators/acceleratorconfiguration.cxx @@ -61,10 +61,6 @@ // other includes #include <vcl/svapp.hxx> -#ifndef __FRAMEWORK_ACCELERATORS_KEYMAPPING_HXX_ -#include <accelerators/keymapping.hxx> -#endif - #ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_ #include <com/sun/star/container/XNamed.hpp> #endif @@ -115,6 +111,23 @@ namespace framework namespace fpc = ::framework::pattern::configuration; #endif + ::rtl::OUString lcl_getKeyString(salhelper::SingletonRef<framework::KeyMapping>& _rKeyMapping, const css::awt::KeyEvent& aKeyEvent) + { + const sal_Int32 nBeginIndex = 4; // "KEY_" is the prefix of a identifier... + ::rtl::OUStringBuffer sKeyBuffer((_rKeyMapping->mapCodeToIdentifier(aKeyEvent.KeyCode)).copy(nBeginIndex)); + + if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT ) + sKeyBuffer.appendAscii("_SHIFT"); + if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 ) + sKeyBuffer.appendAscii("_MOD1"); + if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 ) + sKeyBuffer.appendAscii("_MOD2"); + if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 ) + sKeyBuffer.appendAscii("_MOD3"); + + return sKeyBuffer.makeStringAndClear(); + } + //----------------------------------------------- // XInterface, XTypeProvider DEFINE_XINTERFACE_6(XMLBasedAcceleratorConfiguration , @@ -285,7 +298,7 @@ css::uno::Sequence< css::uno::Any > SAL_CALL XMLBasedAcceleratorConfiguration::g continue; AcceleratorCache::TKeyList lKeys = rCache.getKeysByCommand(rCommand); - if (lKeys.size()<1) + if ( lKeys.empty() ) continue; css::uno::Any& rAny = lPreferredOnes[i]; @@ -694,6 +707,7 @@ XCUBasedAcceleratorConfiguration::XCUBasedAcceleratorConfiguration(const css::un , m_pPrimaryWriteCache(0 ) , m_pSecondaryWriteCache(0 ) { + static const ::rtl::OUString CFG_ENTRY_ACCELERATORS(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Accelerators")); m_xCfg = css::uno::Reference< css::container::XNameAccess > ( ::comphelper::ConfigurationHelper::openConfig( m_xSMGR, CFG_ENTRY_ACCELERATORS, ::comphelper::ConfigurationHelper::E_ALL_LOCALES ), css::uno::UNO_QUERY ); @@ -714,8 +728,10 @@ css::uno::Sequence< css::awt::KeyEvent > SAL_CALL XCUBasedAcceleratorConfigurati AcceleratorCache::TKeyList lKeys = impl_getCFG(sal_True).getAllKeys(); //get keys from PrimaryKeys set AcceleratorCache::TKeyList lSecondaryKeys = impl_getCFG(sal_False).getAllKeys(); //get keys from SecondaryKeys set + lKeys.reserve(lKeys.size()+lSecondaryKeys.size()); AcceleratorCache::TKeyList::const_iterator pIt; - for ( pIt = lSecondaryKeys.begin(); pIt != lSecondaryKeys.end(); ++pIt ) + AcceleratorCache::TKeyList::const_iterator pEnd = lSecondaryKeys.end(); + for ( pIt = lSecondaryKeys.begin(); pIt != pEnd; ++pIt ) lKeys.push_back(*pIt); return lKeys.getAsConstList(); @@ -753,7 +769,7 @@ void SAL_CALL XCUBasedAcceleratorConfiguration::setKeyEvent(const css::awt::KeyE throw(css::lang::IllegalArgumentException, css::uno::RuntimeException ) { - RTL_LOGFILE_PRODUCT_CONTEXT( aLog1, " start XCUBasedAcceleratorConfiguration::setKeyEvent" ); + RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::setKeyEvent" ); if ( (aKeyEvent.KeyCode == 0) && @@ -832,8 +848,6 @@ void SAL_CALL XCUBasedAcceleratorConfiguration::setKeyEvent(const css::awt::KeyE aWriteLock.unlock(); // <- SAFE ---------------------------------- - - RTL_LOGFILE_PRODUCT_CONTEXT( aLog2, " end XCUBasedAcceleratorConfiguration::setKeyEvent" ); } //----------------------------------------------- @@ -959,7 +973,7 @@ css::uno::Sequence< css::uno::Any > SAL_CALL XCUBasedAcceleratorConfiguration::g continue; AcceleratorCache::TKeyList lKeys = rCache.getKeysByCommand(rCommand); - if (lKeys.size()<1) + if ( lKeys.empty() ) continue; AcceleratorCache::TKeyList::const_iterator pPreferredKey = lcl_getPreferredKey(lKeys); @@ -1013,7 +1027,7 @@ void SAL_CALL XCUBasedAcceleratorConfiguration::reload() throw(css::uno::Exception , css::uno::RuntimeException) { - RTL_LOGFILE_PRODUCT_CONTEXT( aLog1, " start XCUBasedAcceleratorConfiguration::reload()" ); + RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::reload()" ); // SAFE -> ---------------------------------- WriteGuard aWriteLock(m_aLock); @@ -1047,8 +1061,6 @@ void SAL_CALL XCUBasedAcceleratorConfiguration::reload() aWriteLock.unlock(); // <- SAFE ---------------------------------- - - RTL_LOGFILE_PRODUCT_CONTEXT( aLog2, " end XCUBasedAcceleratorConfiguration::reload()" ); } //----------------------------------------------- @@ -1056,7 +1068,7 @@ void SAL_CALL XCUBasedAcceleratorConfiguration::store() throw(css::uno::Exception , css::uno::RuntimeException) { - RTL_LOGFILE_PRODUCT_CONTEXT( aLog1, " start XCUBasedAcceleratorConfiguration::store()" ); + RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::store()" ); // SAFE -> ---------------------------------- ReadGuard aReadLock(m_aLock); @@ -1078,17 +1090,73 @@ void SAL_CALL XCUBasedAcceleratorConfiguration::store() aReadLock.unlock(); // <- SAFE ---------------------------------- - - RTL_LOGFILE_PRODUCT_CONTEXT( aLog2, " end XCUBasedAcceleratorConfiguration::store()" ); } //----------------------------------------------- -void SAL_CALL XCUBasedAcceleratorConfiguration::storeToStorage(const css::uno::Reference< css::embed::XStorage >& /*xStorage*/) +void SAL_CALL XCUBasedAcceleratorConfiguration::storeToStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) throw(css::uno::Exception , css::uno::RuntimeException) { - // todo implement me // use m_aCache + old AcceleratorXMLWriter to store data directly on storage given as parameter ... + if (!xStorage.is()) + return; + + long nOpenModes = css::embed::ElementModes::READWRITE; + css::uno::Reference< css::embed::XStorage > xAcceleratorTypeStorage = xStorage->openStorageElement(::rtl::OUString::createFromAscii("accelerator"), nOpenModes); + if (!xAcceleratorTypeStorage.is()) + return; + + css::uno::Reference< css::io::XStream > xStream = xAcceleratorTypeStorage->openStreamElement(::rtl::OUString::createFromAscii("current"), nOpenModes); + css::uno::Reference< css::io::XOutputStream > xOut; + if (xStream.is()) + xOut = xStream->getOutputStream(); + if (!xOut.is()) + throw css::io::IOException( + ::rtl::OUString::createFromAscii("Could not open accelerator configuration for saving."), + static_cast< ::cppu::OWeakObject* >(this)); + + // the original m_aCache has been split into primay cache and secondary cache... + // we should merge them before storing to storage + // SAFE -> ---------------------------------- + WriteGuard aWriteLock(m_aLock); + + AcceleratorCache aCache; + if (m_pPrimaryWriteCache != 0) + aCache.takeOver(*m_pPrimaryWriteCache); + else + aCache.takeOver(m_aPrimaryReadCache); + + AcceleratorCache::TKeyList lKeys; + AcceleratorCache::TKeyList::const_iterator pIt; + if (m_pSecondaryWriteCache!=0) + { + lKeys = m_pSecondaryWriteCache->getAllKeys(); + for ( pIt=lKeys.begin(); pIt!=lKeys.end(); ++pIt ) + aCache.setKeyCommandPair(*pIt, m_pSecondaryWriteCache->getCommandByKey(*pIt)); + } + else + { + lKeys = m_aSecondaryReadCache.getAllKeys(); + for ( pIt=lKeys.begin(); pIt!=lKeys.end(); ++pIt ) + aCache.setKeyCommandPair(*pIt, m_aSecondaryReadCache.getCommandByKey(*pIt)); + } + + aWriteLock.unlock(); + // <- SAFE ---------------------------------- + + css::uno::Reference< css::io::XTruncate > xClearable(xOut, css::uno::UNO_QUERY_THROW); + xClearable->truncate(); + css::uno::Reference< css::io::XSeekable > xSeek(xOut, css::uno::UNO_QUERY); + if (xSeek.is()) + xSeek->seek(0); + + css::uno::Reference< css::xml::sax::XDocumentHandler > xWriter (m_xSMGR->createInstance(SERVICENAME_SAXWRITER), css::uno::UNO_QUERY_THROW); + css::uno::Reference< css::io::XActiveDataSource> xDataSource(xWriter , css::uno::UNO_QUERY_THROW); + xDataSource->setOutputStream(xOut); + + // write into the stream + AcceleratorConfigurationWriter aWriter(aCache, xWriter); + aWriter.flush(); } //----------------------------------------------- @@ -1174,7 +1242,7 @@ void SAL_CALL XCUBasedAcceleratorConfiguration::removeResetListener(const css::u void SAL_CALL XCUBasedAcceleratorConfiguration::changesOccurred(const css::util::ChangesEvent& aEvent) throw(css::uno::RuntimeException) { - RTL_LOGFILE_PRODUCT_CONTEXT( aLog1, " start XCUBasedAcceleratorConfiguration::changesOccurred()" ); + RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::changesOccurred()" ); css::uno::Reference< css::container::XHierarchicalNameAccess > xHAccess; aEvent.Base >>= xHAccess; @@ -1222,8 +1290,6 @@ void SAL_CALL XCUBasedAcceleratorConfiguration::changesOccurred(const css::util: reloadChanged(sPrimarySecondary, sGlobalModules, sModule, sKey); } } - - RTL_LOGFILE_PRODUCT_CONTEXT( aLog2, " end XCUBasedAcceleratorConfiguration::changesOccurred()" ); } //----------------------------------------------- @@ -1246,7 +1312,6 @@ void XCUBasedAcceleratorConfiguration::impl_ts_load( sal_Bool bPreferred, const xModules->getByName(m_sModuleCFG) >>= xAccess; } - static KeyMapping aKeyMapping; const ::rtl::OUString sIsoLang = impl_ts_getLocale().toISO(); const ::rtl::OUString sDefaultLocale = ::rtl::OUString::createFromAscii("en-US"); @@ -1298,7 +1363,7 @@ void XCUBasedAcceleratorConfiguration::impl_ts_load( sal_Bool bPreferred, const sal_Int32 nIndex = 0; ::rtl::OUString sKeyCommand = sKey.getToken(0, '_', nIndex); ::rtl::OUString sPrefix = ::rtl::OUString::createFromAscii("KEY_"); - aKeyEvent.KeyCode = aKeyMapping.mapIdentifierToCode(sPrefix + sKeyCommand); + aKeyEvent.KeyCode = m_rKeyMapping->mapIdentifierToCode(sPrefix + sKeyCommand); css::uno::Sequence< ::rtl::OUString > sToken(4); const sal_Int32 nToken = 4; @@ -1464,18 +1529,7 @@ void XCUBasedAcceleratorConfiguration::insertKeyToConfiguration( const css::awt: xModules->getByName(m_sModuleCFG) >>= xContainer; } - KeyMapping aKeyMapping; - const sal_Int32 nBeginIndex = 4; // "KEY_" is the prefix of a identifier... - ::rtl::OUString sKey = (aKeyMapping.mapCodeToIdentifier(aKeyEvent.KeyCode)).copy(nBeginIndex); - - if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT ) - sKey += ::rtl::OUString::createFromAscii("_SHIFT"); - if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 ) - sKey += ::rtl::OUString::createFromAscii("_MOD1"); - if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 ) - sKey += ::rtl::OUString::createFromAscii("_MOD2"); - if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 ) - sKey += ::rtl::OUString::createFromAscii("_MOD3"); + const ::rtl::OUString sKey = lcl_getKeyString(m_rKeyMapping,aKeyEvent); css::uno::Reference< css::container::XNameAccess > xKey; css::uno::Reference< css::container::XNameContainer > xCommand; if ( !xContainer->hasByName(sKey) ) @@ -1516,19 +1570,7 @@ void XCUBasedAcceleratorConfiguration::removeKeyFromConfiguration( const css::aw xModules->getByName(m_sModuleCFG) >>= xContainer; } - KeyMapping aKeyMapping; - const sal_Int32 nBeginIndex = 4; // "KEY_" is the prefix of a identifier... - ::rtl::OUString sKey = (aKeyMapping.mapCodeToIdentifier(aKeyEvent.KeyCode)).copy(nBeginIndex); - - if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT ) - sKey += ::rtl::OUString::createFromAscii("_SHIFT"); - if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 ) - sKey += ::rtl::OUString::createFromAscii("_MOD1"); - if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 ) - sKey += ::rtl::OUString::createFromAscii("_MOD2"); - if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 ) - sKey += ::rtl::OUString::createFromAscii("_MOD3"); - + const ::rtl::OUString sKey = lcl_getKeyString(m_rKeyMapping,aKeyEvent); xContainer->removeByName(sKey); } @@ -1550,13 +1592,12 @@ void XCUBasedAcceleratorConfiguration::reloadChanged( const ::rtl::OUString& sPr xModules->getByName(sModule) >>= xContainer; } - KeyMapping aKeyMapping; css::awt::KeyEvent aKeyEvent; ::rtl::OUString sKeyIdentifier; sal_Int32 nIndex = 0; sKeyIdentifier = sKey.getToken(0, '_', nIndex); - aKeyEvent.KeyCode = aKeyMapping.mapIdentifierToCode(::rtl::OUString::createFromAscii("KEY_")+sKeyIdentifier); + aKeyEvent.KeyCode = m_rKeyMapping->mapIdentifierToCode(::rtl::OUString::createFromAscii("KEY_")+sKeyIdentifier); css::uno::Sequence< ::rtl::OUString > sToken(3); const sal_Int32 nToken = 3; @@ -1677,4 +1718,3 @@ AcceleratorCache& XCUBasedAcceleratorConfiguration::impl_getCFG(sal_Bool bPrefer } } // namespace framework - |