16d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 36d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 46d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 56d739b60SAndrew Rist * distributed with this work for additional information 66d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 76d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 86d739b60SAndrew Rist * "License"); you may not use this file except in compliance 96d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 116d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 136d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 146d739b60SAndrew Rist * software distributed under the License is distributed on an 156d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 166d739b60SAndrew Rist * KIND, either express or implied. See the License for the 176d739b60SAndrew Rist * specific language governing permissions and limitations 186d739b60SAndrew Rist * under the License. 19cdf0e10cSrcweir * 206d739b60SAndrew Rist *************************************************************/ 216d739b60SAndrew Rist 226d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir #include <accelerators/acceleratorconfiguration.hxx> 27cdf0e10cSrcweir 28cdf0e10cSrcweir //_______________________________________________ 29cdf0e10cSrcweir // own includes 30cdf0e10cSrcweir #include <pattern/configuration.hxx> 31cdf0e10cSrcweir #include <accelerators/presethandler.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <xml/saxnamespacefilter.hxx> 34cdf0e10cSrcweir #include <xml/acceleratorconfigurationreader.hxx> 35cdf0e10cSrcweir #include <xml/acceleratorconfigurationwriter.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <threadhelp/readguard.hxx> 38cdf0e10cSrcweir #include <threadhelp/writeguard.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <acceleratorconst.h> 41cdf0e10cSrcweir #include <services.h> 42cdf0e10cSrcweir 43cdf0e10cSrcweir //_______________________________________________ 44cdf0e10cSrcweir // interface includes 45cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp> 46cdf0e10cSrcweir #include <com/sun/star/xml/sax/InputSource.hpp> 47cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp> 48cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 49cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp> 50cdf0e10cSrcweir #include <com/sun/star/io/XTruncate.hpp> 51cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 52cdf0e10cSrcweir 53cdf0e10cSrcweir //_______________________________________________ 54cdf0e10cSrcweir // other includes 55cdf0e10cSrcweir #include <vcl/svapp.hxx> 56cdf0e10cSrcweir 57cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_ 58cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp> 59cdf0e10cSrcweir #endif 60cdf0e10cSrcweir 61cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_ 62cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 63cdf0e10cSrcweir #endif 64cdf0e10cSrcweir 65cdf0e10cSrcweir #ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_ 66cdf0e10cSrcweir #include <com/sun/star/awt/KeyEvent.hpp> 67cdf0e10cSrcweir #endif 68cdf0e10cSrcweir 69cdf0e10cSrcweir #ifndef __COM_SUN_STAR_AWT_KEYMODIFIER_HPP_ 70cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp> 71cdf0e10cSrcweir #endif 72cdf0e10cSrcweir 73cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ 74cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 75cdf0e10cSrcweir #endif 76cdf0e10cSrcweir 77cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_XCHANGESNOTIFIER_HPP_ 78cdf0e10cSrcweir #include <com/sun/star/util/XChangesNotifier.hpp> 79cdf0e10cSrcweir #endif 80cdf0e10cSrcweir 81cdf0e10cSrcweir #ifndef _COMPHELPER_CONFIGURATIONHELPER_HXX_ 82cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx> 83cdf0e10cSrcweir #endif 84cdf0e10cSrcweir 85cdf0e10cSrcweir #ifndef UNOTOOLS_CONFIGPATHES_HXX_INCLUDED 86cdf0e10cSrcweir #include <unotools/configpathes.hxx> 87cdf0e10cSrcweir #endif 88cdf0e10cSrcweir 89cdf0e10cSrcweir #ifndef _RTL_LOGFILE_HXX_ 90cdf0e10cSrcweir #include <rtl/logfile.hxx> 91cdf0e10cSrcweir #endif 92cdf0e10cSrcweir 93cdf0e10cSrcweir #include <svtools/acceleratorexecute.hxx> 94cdf0e10cSrcweir 95cdf0e10cSrcweir #include <stdio.h> 96cdf0e10cSrcweir 97cdf0e10cSrcweir //_______________________________________________ 98cdf0e10cSrcweir // const 99cdf0e10cSrcweir 100cdf0e10cSrcweir namespace framework 101cdf0e10cSrcweir { 102cdf0e10cSrcweir 103cdf0e10cSrcweir #ifdef fpc 104cdf0e10cSrcweir #error "Who exports this define? I use it as namespace alias ..." 105cdf0e10cSrcweir #else 106cdf0e10cSrcweir namespace fpc = ::framework::pattern::configuration; 107cdf0e10cSrcweir #endif 108cdf0e10cSrcweir 109cdf0e10cSrcweir ::rtl::OUString lcl_getKeyString(salhelper::SingletonRef<framework::KeyMapping>& _rKeyMapping, const css::awt::KeyEvent& aKeyEvent) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir const sal_Int32 nBeginIndex = 4; // "KEY_" is the prefix of a identifier... 112cdf0e10cSrcweir ::rtl::OUStringBuffer sKeyBuffer((_rKeyMapping->mapCodeToIdentifier(aKeyEvent.KeyCode)).copy(nBeginIndex)); 113cdf0e10cSrcweir 114cdf0e10cSrcweir if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT ) 115cdf0e10cSrcweir sKeyBuffer.appendAscii("_SHIFT"); 116cdf0e10cSrcweir if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 ) 117cdf0e10cSrcweir sKeyBuffer.appendAscii("_MOD1"); 118cdf0e10cSrcweir if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 ) 119cdf0e10cSrcweir sKeyBuffer.appendAscii("_MOD2"); 120cdf0e10cSrcweir if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 ) 121cdf0e10cSrcweir sKeyBuffer.appendAscii("_MOD3"); 122cdf0e10cSrcweir 123cdf0e10cSrcweir return sKeyBuffer.makeStringAndClear(); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir //----------------------------------------------- 127cdf0e10cSrcweir // XInterface, XTypeProvider 128cdf0e10cSrcweir DEFINE_XINTERFACE_6(XMLBasedAcceleratorConfiguration , 129cdf0e10cSrcweir OWeakObject , 130cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XTypeProvider ), 131cdf0e10cSrcweir DIRECT_INTERFACE(css::ui::XAcceleratorConfiguration ), 132cdf0e10cSrcweir DIRECT_INTERFACE(css::form::XReset ), 133cdf0e10cSrcweir DIRECT_INTERFACE(css::ui::XUIConfigurationPersistence), 134cdf0e10cSrcweir DIRECT_INTERFACE(css::ui::XUIConfigurationStorage ), 135cdf0e10cSrcweir DIRECT_INTERFACE(css::ui::XUIConfiguration )) 136cdf0e10cSrcweir 137cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_6(XMLBasedAcceleratorConfiguration , 138cdf0e10cSrcweir css::lang::XTypeProvider , 139cdf0e10cSrcweir css::ui::XAcceleratorConfiguration , 140cdf0e10cSrcweir css::form::XReset , 141cdf0e10cSrcweir css::ui::XUIConfigurationPersistence, 142cdf0e10cSrcweir css::ui::XUIConfigurationStorage , 143cdf0e10cSrcweir css::ui::XUIConfiguration ) 144cdf0e10cSrcweir 145cdf0e10cSrcweir //----------------------------------------------- 146cdf0e10cSrcweir XMLBasedAcceleratorConfiguration::XMLBasedAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR) 147cdf0e10cSrcweir : ThreadHelpBase (&Application::GetSolarMutex()) 148cdf0e10cSrcweir , m_xSMGR (xSMGR ) 149cdf0e10cSrcweir , m_aPresetHandler(xSMGR ) 150cdf0e10cSrcweir , m_pWriteCache (0 ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir //----------------------------------------------- 155cdf0e10cSrcweir XMLBasedAcceleratorConfiguration::~XMLBasedAcceleratorConfiguration() 156cdf0e10cSrcweir { 157cdf0e10cSrcweir LOG_ASSERT(!m_pWriteCache, "XMLBasedAcceleratorConfiguration::~XMLBasedAcceleratorConfiguration()\nChanges not flushed. Ignore it ...") 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir //----------------------------------------------- 161cdf0e10cSrcweir css::uno::Sequence< css::awt::KeyEvent > SAL_CALL XMLBasedAcceleratorConfiguration::getAllKeyEvents() 162cdf0e10cSrcweir throw(css::uno::RuntimeException) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir // SAFE -> ---------------------------------- 165cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 166cdf0e10cSrcweir 167cdf0e10cSrcweir AcceleratorCache& rCache = impl_getCFG(); 168cdf0e10cSrcweir AcceleratorCache::TKeyList lKeys = rCache.getAllKeys(); 169cdf0e10cSrcweir return lKeys.getAsConstList(); 170cdf0e10cSrcweir 171cdf0e10cSrcweir // <- SAFE ---------------------------------- 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir //----------------------------------------------- 175cdf0e10cSrcweir ::rtl::OUString SAL_CALL XMLBasedAcceleratorConfiguration::getCommandByKeyEvent(const css::awt::KeyEvent& aKeyEvent) 176cdf0e10cSrcweir throw(css::container::NoSuchElementException, 177cdf0e10cSrcweir css::uno::RuntimeException ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir // SAFE -> ---------------------------------- 180cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 181cdf0e10cSrcweir 182cdf0e10cSrcweir AcceleratorCache& rCache = impl_getCFG(); 183cdf0e10cSrcweir if (!rCache.hasKey(aKeyEvent)) 184cdf0e10cSrcweir throw css::container::NoSuchElementException( 185cdf0e10cSrcweir ::rtl::OUString(), 186cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 187cdf0e10cSrcweir return rCache.getCommandByKey(aKeyEvent); 188cdf0e10cSrcweir 189cdf0e10cSrcweir // <- SAFE ---------------------------------- 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir //----------------------------------------------- 193cdf0e10cSrcweir void SAL_CALL XMLBasedAcceleratorConfiguration::setKeyEvent(const css::awt::KeyEvent& aKeyEvent, 194cdf0e10cSrcweir const ::rtl::OUString& sCommand ) 195cdf0e10cSrcweir throw(css::lang::IllegalArgumentException, 196cdf0e10cSrcweir css::uno::RuntimeException ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir if ( 199cdf0e10cSrcweir (aKeyEvent.KeyCode == 0) && 200cdf0e10cSrcweir (aKeyEvent.KeyChar == 0) && 201cdf0e10cSrcweir (aKeyEvent.KeyFunc == 0) && 202cdf0e10cSrcweir (aKeyEvent.Modifiers == 0) 203cdf0e10cSrcweir ) 204cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 205cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Such key event seams not to be supported by any operating system."), 206cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 207cdf0e10cSrcweir 0); 208cdf0e10cSrcweir 209cdf0e10cSrcweir if (!sCommand.getLength()) 210cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 211cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Empty command strings are not allowed here."), 212cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 213cdf0e10cSrcweir 1); 214cdf0e10cSrcweir 215cdf0e10cSrcweir // SAFE -> ---------------------------------- 216cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 217cdf0e10cSrcweir 218cdf0e10cSrcweir AcceleratorCache& rCache = impl_getCFG(sal_True); // sal_True => force getting of a writeable cache! 219cdf0e10cSrcweir rCache.setKeyCommandPair(aKeyEvent, sCommand); 220cdf0e10cSrcweir 221cdf0e10cSrcweir aWriteLock.unlock(); 222cdf0e10cSrcweir // <- SAFE ---------------------------------- 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir //----------------------------------------------- 226cdf0e10cSrcweir void SAL_CALL XMLBasedAcceleratorConfiguration::removeKeyEvent(const css::awt::KeyEvent& aKeyEvent) 227cdf0e10cSrcweir throw(css::container::NoSuchElementException, 228cdf0e10cSrcweir css::uno::RuntimeException ) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir // SAFE -> ---------------------------------- 231cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 232cdf0e10cSrcweir 233cdf0e10cSrcweir AcceleratorCache& rCache = impl_getCFG(sal_True); // true => force using of a writeable cache 234cdf0e10cSrcweir if (!rCache.hasKey(aKeyEvent)) 235cdf0e10cSrcweir throw css::container::NoSuchElementException( 236cdf0e10cSrcweir ::rtl::OUString(), 237cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 238cdf0e10cSrcweir rCache.removeKey(aKeyEvent); 239cdf0e10cSrcweir 240cdf0e10cSrcweir // <- SAFE ---------------------------------- 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir //----------------------------------------------- 244cdf0e10cSrcweir css::uno::Sequence< css::awt::KeyEvent > SAL_CALL XMLBasedAcceleratorConfiguration::getKeyEventsByCommand(const ::rtl::OUString& sCommand) 245cdf0e10cSrcweir throw(css::lang::IllegalArgumentException , 246cdf0e10cSrcweir css::container::NoSuchElementException, 247cdf0e10cSrcweir css::uno::RuntimeException ) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir if (!sCommand.getLength()) 250cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 251cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Empty command strings are not allowed here."), 252cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 253cdf0e10cSrcweir 1); 254cdf0e10cSrcweir 255cdf0e10cSrcweir // SAFE -> ---------------------------------- 256cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 257cdf0e10cSrcweir 258cdf0e10cSrcweir AcceleratorCache& rCache = impl_getCFG(); 259cdf0e10cSrcweir if (!rCache.hasCommand(sCommand)) 260cdf0e10cSrcweir throw css::container::NoSuchElementException( 261cdf0e10cSrcweir ::rtl::OUString(), 262cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 263cdf0e10cSrcweir 264cdf0e10cSrcweir AcceleratorCache::TKeyList lKeys = rCache.getKeysByCommand(sCommand); 265cdf0e10cSrcweir return lKeys.getAsConstList(); 266cdf0e10cSrcweir 267cdf0e10cSrcweir // <- SAFE ---------------------------------- 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir //----------------------------------------------- 271cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > SAL_CALL XMLBasedAcceleratorConfiguration::getPreferredKeyEventsForCommandList(const css::uno::Sequence< ::rtl::OUString >& lCommandList) 272cdf0e10cSrcweir throw(css::lang::IllegalArgumentException , 273cdf0e10cSrcweir css::uno::RuntimeException ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir // SAFE -> ---------------------------------- 276cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 277cdf0e10cSrcweir 278cdf0e10cSrcweir sal_Int32 i = 0; 279cdf0e10cSrcweir sal_Int32 c = lCommandList.getLength(); 280cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > lPreferredOnes (c); // dont pack list! 281cdf0e10cSrcweir AcceleratorCache& rCache = impl_getCFG(); 282cdf0e10cSrcweir 283cdf0e10cSrcweir for (i=0; i<c; ++i) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir const ::rtl::OUString& rCommand = lCommandList[i]; 286cdf0e10cSrcweir if (!rCommand.getLength()) 287cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 288cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Empty command strings are not allowed here."), 289cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 290cdf0e10cSrcweir (sal_Int16)i); 291cdf0e10cSrcweir 292cdf0e10cSrcweir if (!rCache.hasCommand(rCommand)) 293cdf0e10cSrcweir continue; 294cdf0e10cSrcweir 295cdf0e10cSrcweir AcceleratorCache::TKeyList lKeys = rCache.getKeysByCommand(rCommand); 296cdf0e10cSrcweir if ( lKeys.empty() ) 297cdf0e10cSrcweir continue; 298cdf0e10cSrcweir 299cdf0e10cSrcweir css::uno::Any& rAny = lPreferredOnes[i]; 300cdf0e10cSrcweir rAny <<= *(lKeys.begin()); 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir aReadLock.unlock(); 304cdf0e10cSrcweir // <- SAFE ---------------------------------- 305cdf0e10cSrcweir 306cdf0e10cSrcweir return lPreferredOnes; 307cdf0e10cSrcweir } 308cdf0e10cSrcweir 309cdf0e10cSrcweir //----------------------------------------------- 310cdf0e10cSrcweir void SAL_CALL XMLBasedAcceleratorConfiguration::removeCommandFromAllKeyEvents(const ::rtl::OUString& sCommand) 311cdf0e10cSrcweir throw(css::lang::IllegalArgumentException , 312cdf0e10cSrcweir css::container::NoSuchElementException, 313cdf0e10cSrcweir css::uno::RuntimeException ) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir if (!sCommand.getLength()) 316cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 317cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Empty command strings are not allowed here."), 318cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 319cdf0e10cSrcweir 0); 320cdf0e10cSrcweir 321cdf0e10cSrcweir // SAFE -> ---------------------------------- 322cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 323cdf0e10cSrcweir 324cdf0e10cSrcweir AcceleratorCache& rCache = impl_getCFG(sal_True); // sal_True => force getting of a writeable cache! 325cdf0e10cSrcweir if (!rCache.hasCommand(sCommand)) 326cdf0e10cSrcweir throw css::container::NoSuchElementException( 327cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Command does not exists inside this container."), 328cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 329cdf0e10cSrcweir rCache.removeCommand(sCommand); 330cdf0e10cSrcweir 331cdf0e10cSrcweir aWriteLock.unlock(); 332cdf0e10cSrcweir // <- SAFE ---------------------------------- 333cdf0e10cSrcweir } 334cdf0e10cSrcweir 335cdf0e10cSrcweir //----------------------------------------------- 336cdf0e10cSrcweir void SAL_CALL XMLBasedAcceleratorConfiguration::reload() 337cdf0e10cSrcweir throw(css::uno::Exception , 338cdf0e10cSrcweir css::uno::RuntimeException) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir css::uno::Reference< css::io::XStream > xStreamNoLang; 341cdf0e10cSrcweir 342cdf0e10cSrcweir // SAFE -> ---------------------------------- 343cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 344cdf0e10cSrcweir css::uno::Reference< css::io::XStream > xStream = m_aPresetHandler.openTarget(PresetHandler::TARGET_CURRENT(), sal_True); // sal_True => open or create! 345cdf0e10cSrcweir try 346cdf0e10cSrcweir { 347cdf0e10cSrcweir xStreamNoLang = m_aPresetHandler.openPreset(PresetHandler::PRESET_DEFAULT(), sal_True); 348cdf0e10cSrcweir } 349cdf0e10cSrcweir catch(const css::io::IOException&) {} // does not have to exist 350cdf0e10cSrcweir aReadLock.unlock(); 351cdf0e10cSrcweir // <- SAFE ---------------------------------- 352cdf0e10cSrcweir 353cdf0e10cSrcweir css::uno::Reference< css::io::XInputStream > xIn; 354cdf0e10cSrcweir if (xStream.is()) 355cdf0e10cSrcweir xIn = xStream->getInputStream(); 356cdf0e10cSrcweir if (!xIn.is()) 357cdf0e10cSrcweir throw css::io::IOException( 358cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Could not open accelerator configuration for reading."), 359cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 360cdf0e10cSrcweir 361cdf0e10cSrcweir // impl_ts_load() does not clear the cache 362cdf0e10cSrcweir // SAFE -> ---------------------------------- 363cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 364cdf0e10cSrcweir m_aReadCache = AcceleratorCache(); 365cdf0e10cSrcweir aWriteLock.unlock(); 366cdf0e10cSrcweir // <- SAFE ---------------------------------- 367cdf0e10cSrcweir 368cdf0e10cSrcweir impl_ts_load(xIn); 369cdf0e10cSrcweir 370cdf0e10cSrcweir // Load also the general language independent default accelerators 371cdf0e10cSrcweir // (ignoring the already defined accelerators) 372cdf0e10cSrcweir if (xStreamNoLang.is()) 373cdf0e10cSrcweir { 374cdf0e10cSrcweir xIn = xStreamNoLang->getInputStream(); 375cdf0e10cSrcweir if (xIn.is()) 376cdf0e10cSrcweir impl_ts_load(xIn); 377cdf0e10cSrcweir } 378cdf0e10cSrcweir } 379cdf0e10cSrcweir 380cdf0e10cSrcweir //----------------------------------------------- 381cdf0e10cSrcweir void SAL_CALL XMLBasedAcceleratorConfiguration::store() 382cdf0e10cSrcweir throw(css::uno::Exception , 383cdf0e10cSrcweir css::uno::RuntimeException) 384cdf0e10cSrcweir { 385cdf0e10cSrcweir // SAFE -> ---------------------------------- 386cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 387cdf0e10cSrcweir css::uno::Reference< css::io::XStream > xStream = m_aPresetHandler.openTarget(PresetHandler::TARGET_CURRENT(), sal_True); // sal_True => open or create! 388cdf0e10cSrcweir aReadLock.unlock(); 389cdf0e10cSrcweir // <- SAFE ---------------------------------- 390cdf0e10cSrcweir 391cdf0e10cSrcweir css::uno::Reference< css::io::XOutputStream > xOut; 392cdf0e10cSrcweir if (xStream.is()) 393cdf0e10cSrcweir xOut = xStream->getOutputStream(); 394cdf0e10cSrcweir 395cdf0e10cSrcweir if (!xOut.is()) 396cdf0e10cSrcweir throw css::io::IOException( 397cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Could not open accelerator configuration for saving."), 398cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 399cdf0e10cSrcweir 400cdf0e10cSrcweir impl_ts_save(xOut); 401cdf0e10cSrcweir 402cdf0e10cSrcweir xOut.clear(); 403cdf0e10cSrcweir xStream.clear(); 404cdf0e10cSrcweir 405cdf0e10cSrcweir m_aPresetHandler.commitUserChanges(); 406cdf0e10cSrcweir } 407cdf0e10cSrcweir 408cdf0e10cSrcweir //----------------------------------------------- 409cdf0e10cSrcweir void SAL_CALL XMLBasedAcceleratorConfiguration::storeToStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) 410cdf0e10cSrcweir throw(css::uno::Exception , 411cdf0e10cSrcweir css::uno::RuntimeException) 412cdf0e10cSrcweir { 413cdf0e10cSrcweir css::uno::Reference< css::io::XStream > xStream = StorageHolder::openSubStreamWithFallback( 414cdf0e10cSrcweir xStorage, 415cdf0e10cSrcweir PresetHandler::TARGET_CURRENT(), 416cdf0e10cSrcweir css::embed::ElementModes::READWRITE, 417cdf0e10cSrcweir sal_False); // False => no fallback from read/write to readonly! 418cdf0e10cSrcweir css::uno::Reference< css::io::XOutputStream > xOut; 419cdf0e10cSrcweir if (xStream.is()) 420cdf0e10cSrcweir xOut = xStream->getOutputStream(); 421cdf0e10cSrcweir 422cdf0e10cSrcweir if (!xOut.is()) 423cdf0e10cSrcweir throw css::io::IOException( 424cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Could not open accelerator configuration for saving."), 425cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 426cdf0e10cSrcweir 427cdf0e10cSrcweir impl_ts_save(xOut); 428cdf0e10cSrcweir 429cdf0e10cSrcweir // TODO inform listener about success, so it can flush the root and sub storage of this stream! 430cdf0e10cSrcweir } 431cdf0e10cSrcweir 432cdf0e10cSrcweir //----------------------------------------------- 433cdf0e10cSrcweir ::sal_Bool SAL_CALL XMLBasedAcceleratorConfiguration::isModified() 434cdf0e10cSrcweir throw(css::uno::RuntimeException) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir // SAFE -> ---------------------------------- 437cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 438cdf0e10cSrcweir return (m_pWriteCache != 0); 439cdf0e10cSrcweir // <- SAFE ---------------------------------- 440cdf0e10cSrcweir } 441cdf0e10cSrcweir 442cdf0e10cSrcweir //----------------------------------------------- 443cdf0e10cSrcweir ::sal_Bool SAL_CALL XMLBasedAcceleratorConfiguration::isReadOnly() 444cdf0e10cSrcweir throw(css::uno::RuntimeException) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir // SAFE -> ---------------------------------- 447cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 448cdf0e10cSrcweir css::uno::Reference< css::io::XStream > xStream = m_aPresetHandler.openTarget(PresetHandler::TARGET_CURRENT(), sal_True); // sal_True => open or create! 449cdf0e10cSrcweir aReadLock.unlock(); 450cdf0e10cSrcweir // <- SAFE ---------------------------------- 451cdf0e10cSrcweir 452cdf0e10cSrcweir css::uno::Reference< css::io::XOutputStream > xOut; 453cdf0e10cSrcweir if (xStream.is()) 454cdf0e10cSrcweir xOut = xStream->getOutputStream(); 455cdf0e10cSrcweir return !(xOut.is()); 456cdf0e10cSrcweir } 457cdf0e10cSrcweir 458cdf0e10cSrcweir //----------------------------------------------- 459cdf0e10cSrcweir void SAL_CALL XMLBasedAcceleratorConfiguration::setStorage(const css::uno::Reference< css::embed::XStorage >& /*xStorage*/) 460cdf0e10cSrcweir throw(css::uno::RuntimeException) 461cdf0e10cSrcweir { 462cdf0e10cSrcweir LOG_WARNING("XMLBasedAcceleratorConfiguration::setStorage()", "TODO implement this HACK .-)") 463cdf0e10cSrcweir } 464cdf0e10cSrcweir 465cdf0e10cSrcweir //----------------------------------------------- 466cdf0e10cSrcweir ::sal_Bool SAL_CALL XMLBasedAcceleratorConfiguration::hasStorage() 467cdf0e10cSrcweir throw(css::uno::RuntimeException) 468cdf0e10cSrcweir { 469cdf0e10cSrcweir LOG_WARNING("XMLBasedAcceleratorConfiguration::hasStorage()", "TODO implement this HACK .-)") 470cdf0e10cSrcweir return sal_False; 471cdf0e10cSrcweir } 472cdf0e10cSrcweir 473cdf0e10cSrcweir //----------------------------------------------- 474cdf0e10cSrcweir void SAL_CALL XMLBasedAcceleratorConfiguration::addConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& /*xListener*/) 475cdf0e10cSrcweir throw(css::uno::RuntimeException) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir LOG_WARNING("XMLBasedAcceleratorConfiguration::addConfigurationListener()", "TODO implement me") 478cdf0e10cSrcweir } 479cdf0e10cSrcweir 480cdf0e10cSrcweir //----------------------------------------------- 481cdf0e10cSrcweir void SAL_CALL XMLBasedAcceleratorConfiguration::removeConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& /*xListener*/) 482cdf0e10cSrcweir throw(css::uno::RuntimeException) 483cdf0e10cSrcweir { 484cdf0e10cSrcweir LOG_WARNING("XMLBasedAcceleratorConfiguration::removeConfigurationListener()", "TODO implement me") 485cdf0e10cSrcweir } 486cdf0e10cSrcweir 487cdf0e10cSrcweir //----------------------------------------------- 488cdf0e10cSrcweir void SAL_CALL XMLBasedAcceleratorConfiguration::reset() 489cdf0e10cSrcweir throw(css::uno::RuntimeException) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir // SAFE -> ---------------------------------- 492cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 493cdf0e10cSrcweir m_aPresetHandler.copyPresetToTarget(PresetHandler::PRESET_DEFAULT(), PresetHandler::TARGET_CURRENT()); 494cdf0e10cSrcweir aWriteLock.unlock(); 495cdf0e10cSrcweir // <- SAFE ---------------------------------- 496cdf0e10cSrcweir 497cdf0e10cSrcweir reload(); 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500cdf0e10cSrcweir //----------------------------------------------- 501cdf0e10cSrcweir void SAL_CALL XMLBasedAcceleratorConfiguration::addResetListener(const css::uno::Reference< css::form::XResetListener >& /*xListener*/) 502cdf0e10cSrcweir throw(css::uno::RuntimeException) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir LOG_WARNING("XMLBasedAcceleratorConfiguration::addResetListener()", "TODO implement me") 505cdf0e10cSrcweir } 506cdf0e10cSrcweir 507cdf0e10cSrcweir //----------------------------------------------- 508cdf0e10cSrcweir void SAL_CALL XMLBasedAcceleratorConfiguration::removeResetListener(const css::uno::Reference< css::form::XResetListener >& /*xListener*/) 509cdf0e10cSrcweir throw(css::uno::RuntimeException) 510cdf0e10cSrcweir { 511cdf0e10cSrcweir LOG_WARNING("XMLBasedAcceleratorConfiguration::removeResetListener()", "TODO implement me") 512cdf0e10cSrcweir } 513cdf0e10cSrcweir 514cdf0e10cSrcweir //----------------------------------------------- 515cdf0e10cSrcweir // IStorageListener 516cdf0e10cSrcweir void XMLBasedAcceleratorConfiguration::changesOccured(const ::rtl::OUString& /*sPath*/) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir reload(); 519cdf0e10cSrcweir } 520cdf0e10cSrcweir 521cdf0e10cSrcweir //----------------------------------------------- 522cdf0e10cSrcweir void XMLBasedAcceleratorConfiguration::impl_ts_load(const css::uno::Reference< css::io::XInputStream >& xStream) 523cdf0e10cSrcweir { 524cdf0e10cSrcweir // SAFE -> ---------------------------------- 525cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 526cdf0e10cSrcweir 527cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 528cdf0e10cSrcweir if (m_pWriteCache) 529cdf0e10cSrcweir { 530cdf0e10cSrcweir // be aware of reentrance problems - use temp variable for calling delete ... :-) 531cdf0e10cSrcweir AcceleratorCache* pTemp = m_pWriteCache; 532cdf0e10cSrcweir m_pWriteCache = 0; 533cdf0e10cSrcweir delete pTemp; 534cdf0e10cSrcweir } 535cdf0e10cSrcweir 536cdf0e10cSrcweir aWriteLock.unlock(); 537cdf0e10cSrcweir // <- SAFE ---------------------------------- 538cdf0e10cSrcweir 539cdf0e10cSrcweir css::uno::Reference< css::io::XSeekable > xSeek(xStream, css::uno::UNO_QUERY); 540cdf0e10cSrcweir if (xSeek.is()) 541cdf0e10cSrcweir xSeek->seek(0); 542cdf0e10cSrcweir 543cdf0e10cSrcweir // add accelerators to the cache (the cache is not cleared) 544cdf0e10cSrcweir // SAFE -> ---------------------------------- 545cdf0e10cSrcweir aWriteLock.lock(); 546cdf0e10cSrcweir 547cdf0e10cSrcweir // create the parser queue 548cdf0e10cSrcweir // Note: Use special filter object between parser and reader 549cdf0e10cSrcweir // to get filtered xml with right namespaces ... 550cdf0e10cSrcweir // Use further a temp cache for reading! 551cdf0e10cSrcweir AcceleratorConfigurationReader* pReader = new AcceleratorConfigurationReader(m_aReadCache); 552cdf0e10cSrcweir css::uno::Reference< css::xml::sax::XDocumentHandler > xReader (static_cast< ::cppu::OWeakObject* >(pReader), css::uno::UNO_QUERY_THROW); 553cdf0e10cSrcweir SaxNamespaceFilter* pFilter = new SaxNamespaceFilter(xReader); 554cdf0e10cSrcweir css::uno::Reference< css::xml::sax::XDocumentHandler > xFilter (static_cast< ::cppu::OWeakObject* >(pFilter), css::uno::UNO_QUERY_THROW); 555cdf0e10cSrcweir 556cdf0e10cSrcweir // connect parser, filter and stream 557cdf0e10cSrcweir css::uno::Reference< css::xml::sax::XParser > xParser(xSMGR->createInstance(SERVICENAME_SAXPARSER), css::uno::UNO_QUERY_THROW); 558cdf0e10cSrcweir xParser->setDocumentHandler(xFilter); 559cdf0e10cSrcweir 560cdf0e10cSrcweir css::xml::sax::InputSource aSource; 561cdf0e10cSrcweir aSource.aInputStream = xStream; 562cdf0e10cSrcweir 563cdf0e10cSrcweir // TODO think about error handling 564cdf0e10cSrcweir xParser->parseStream(aSource); 565cdf0e10cSrcweir 566cdf0e10cSrcweir aWriteLock.unlock(); 567cdf0e10cSrcweir // <- SAFE ---------------------------------- 568cdf0e10cSrcweir } 569cdf0e10cSrcweir 570cdf0e10cSrcweir //----------------------------------------------- 571cdf0e10cSrcweir void XMLBasedAcceleratorConfiguration::impl_ts_save(const css::uno::Reference< css::io::XOutputStream >& xStream) 572cdf0e10cSrcweir { 573cdf0e10cSrcweir // SAFE -> ---------------------------------- 574cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 575cdf0e10cSrcweir 576cdf0e10cSrcweir AcceleratorCache aCache; 577cdf0e10cSrcweir sal_Bool bChanged = (m_pWriteCache != 0); 578cdf0e10cSrcweir if (bChanged) 579cdf0e10cSrcweir aCache.takeOver(*m_pWriteCache); 580cdf0e10cSrcweir else 581cdf0e10cSrcweir aCache.takeOver(m_aReadCache); 582cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 583cdf0e10cSrcweir 584cdf0e10cSrcweir aReadLock.unlock(); 585cdf0e10cSrcweir // <- SAFE ---------------------------------- 586cdf0e10cSrcweir 587cdf0e10cSrcweir css::uno::Reference< css::io::XTruncate > xClearable(xStream, css::uno::UNO_QUERY_THROW); 588cdf0e10cSrcweir xClearable->truncate(); 589cdf0e10cSrcweir 590cdf0e10cSrcweir // TODO can be removed if seek(0) is done by truncate() automaticly! 591cdf0e10cSrcweir css::uno::Reference< css::io::XSeekable > xSeek(xStream, css::uno::UNO_QUERY); 592cdf0e10cSrcweir if (xSeek.is()) 593cdf0e10cSrcweir xSeek->seek(0); 594cdf0e10cSrcweir 595cdf0e10cSrcweir // combine writer/cache/stream etcpp. 596cdf0e10cSrcweir css::uno::Reference< css::xml::sax::XDocumentHandler > xWriter (xSMGR->createInstance(SERVICENAME_SAXWRITER), css::uno::UNO_QUERY_THROW); 597cdf0e10cSrcweir css::uno::Reference< css::io::XActiveDataSource> xDataSource(xWriter , css::uno::UNO_QUERY_THROW); 598cdf0e10cSrcweir xDataSource->setOutputStream(xStream); 599cdf0e10cSrcweir 600cdf0e10cSrcweir // write into the stream 601cdf0e10cSrcweir AcceleratorConfigurationWriter aWriter(aCache, xWriter); 602cdf0e10cSrcweir aWriter.flush(); 603cdf0e10cSrcweir 604cdf0e10cSrcweir // take over all changes into the original container 605cdf0e10cSrcweir // SAFE -> ---------------------------------- 606cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 607cdf0e10cSrcweir 608cdf0e10cSrcweir // take over all changes into the readonly cache ... 609cdf0e10cSrcweir // and forget the copy-on-write copied cache 610cdf0e10cSrcweir if (bChanged) 611cdf0e10cSrcweir { 612cdf0e10cSrcweir m_aReadCache.takeOver(*m_pWriteCache); 613cdf0e10cSrcweir // live with reentrance .-) 614cdf0e10cSrcweir AcceleratorCache* pTemp = m_pWriteCache; 615cdf0e10cSrcweir m_pWriteCache = 0; 616cdf0e10cSrcweir delete pTemp; 617cdf0e10cSrcweir } 618cdf0e10cSrcweir 619cdf0e10cSrcweir aWriteLock.unlock(); 620cdf0e10cSrcweir // <- SAFE ---------------------------------- 621cdf0e10cSrcweir } 622cdf0e10cSrcweir 623cdf0e10cSrcweir //----------------------------------------------- 624cdf0e10cSrcweir AcceleratorCache& XMLBasedAcceleratorConfiguration::impl_getCFG(sal_Bool bWriteAccessRequested) 625cdf0e10cSrcweir { 626cdf0e10cSrcweir // SAFE -> ---------------------------------- 627cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 628cdf0e10cSrcweir 629cdf0e10cSrcweir //create copy of our readonly-cache, if write access is forced ... but 630cdf0e10cSrcweir //not still possible! 631cdf0e10cSrcweir if ( 632cdf0e10cSrcweir (bWriteAccessRequested) && 633cdf0e10cSrcweir (!m_pWriteCache ) 634cdf0e10cSrcweir ) 635cdf0e10cSrcweir { 636cdf0e10cSrcweir m_pWriteCache = new AcceleratorCache(m_aReadCache); 637cdf0e10cSrcweir } 638cdf0e10cSrcweir 639cdf0e10cSrcweir // in case, we have a writeable cache, we use it for reading too! 640cdf0e10cSrcweir // Otherwhise the API user cant find its own changes ... 641cdf0e10cSrcweir if (m_pWriteCache) 642cdf0e10cSrcweir return *m_pWriteCache; 643cdf0e10cSrcweir else 644cdf0e10cSrcweir return m_aReadCache; 645cdf0e10cSrcweir // <- SAFE ---------------------------------- 646cdf0e10cSrcweir } 647cdf0e10cSrcweir 648cdf0e10cSrcweir //----------------------------------------------- 649cdf0e10cSrcweir ::comphelper::Locale XMLBasedAcceleratorConfiguration::impl_ts_getLocale() const 650cdf0e10cSrcweir { 651cdf0e10cSrcweir static ::rtl::OUString LOCALE_PACKAGE = ::rtl::OUString::createFromAscii("/org.openoffice.Setup"); 652cdf0e10cSrcweir static ::rtl::OUString LOCALE_PATH = ::rtl::OUString::createFromAscii("L10N" ); 653cdf0e10cSrcweir static ::rtl::OUString LOCALE_KEY = ::rtl::OUString::createFromAscii("ooLocale" ); 654cdf0e10cSrcweir 655cdf0e10cSrcweir // SAFE -> ---------------------------------- 656cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 657cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 658cdf0e10cSrcweir aReadLock.unlock(); 659cdf0e10cSrcweir // <- SAFE ---------------------------------- 660cdf0e10cSrcweir 661cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xCFG = fpc::ConfigurationHelper::openConfig(xSMGR, LOCALE_PACKAGE, LOCALE_PATH, fpc::ConfigurationHelper::E_READONLY); 662cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xProp (xCFG, css::uno::UNO_QUERY_THROW); 663cdf0e10cSrcweir ::rtl::OUString sISOLocale; 664cdf0e10cSrcweir xProp->getPropertyValue(LOCALE_KEY) >>= sISOLocale; 665cdf0e10cSrcweir 666cdf0e10cSrcweir if (!sISOLocale.getLength()) 667cdf0e10cSrcweir return ::comphelper::Locale::EN_US(); 668cdf0e10cSrcweir return ::comphelper::Locale(sISOLocale); 669cdf0e10cSrcweir } 670cdf0e10cSrcweir 671cdf0e10cSrcweir /******************************************************************************* 672cdf0e10cSrcweir * 673cdf0e10cSrcweir * XCU based accelerator configuration 674cdf0e10cSrcweir * 675cdf0e10cSrcweir *******************************************************************************/ 676cdf0e10cSrcweir 677cdf0e10cSrcweir //----------------------------------------------- 678cdf0e10cSrcweir // XInterface, XTypeProvider 679*796936d9SAndre Fischer DEFINE_XINTERFACE_8(XCUBasedAcceleratorConfiguration , 680cdf0e10cSrcweir OWeakObject , 681cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XTypeProvider ), 682cdf0e10cSrcweir DIRECT_INTERFACE(css::ui::XAcceleratorConfiguration ), 683cdf0e10cSrcweir DIRECT_INTERFACE(css::util::XChangesListener ), 684cdf0e10cSrcweir DIRECT_INTERFACE(css::form::XReset ), 685*796936d9SAndre Fischer DIRECT_INTERFACE(css::lang::XComponent ), 686cdf0e10cSrcweir DIRECT_INTERFACE(css::ui::XUIConfigurationPersistence), 687cdf0e10cSrcweir DIRECT_INTERFACE(css::ui::XUIConfigurationStorage ), 688cdf0e10cSrcweir DIRECT_INTERFACE(css::ui::XUIConfiguration )) 689cdf0e10cSrcweir 690*796936d9SAndre Fischer DEFINE_XTYPEPROVIDER_8(XCUBasedAcceleratorConfiguration , 691cdf0e10cSrcweir css::lang::XTypeProvider , 692cdf0e10cSrcweir css::ui::XAcceleratorConfiguration , 693cdf0e10cSrcweir css::util::XChangesListener , 694cdf0e10cSrcweir css::form::XReset , 695*796936d9SAndre Fischer css::lang::XComponent , 696cdf0e10cSrcweir css::ui::XUIConfigurationPersistence, 697cdf0e10cSrcweir css::ui::XUIConfigurationStorage , 698cdf0e10cSrcweir css::ui::XUIConfiguration ) 699cdf0e10cSrcweir 700cdf0e10cSrcweir //----------------------------------------------- 701cdf0e10cSrcweir XCUBasedAcceleratorConfiguration::XCUBasedAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR) 702cdf0e10cSrcweir : ThreadHelpBase (&Application::GetSolarMutex()) 703cdf0e10cSrcweir , m_xSMGR (xSMGR ) 704cdf0e10cSrcweir , m_pPrimaryWriteCache(0 ) 705cdf0e10cSrcweir , m_pSecondaryWriteCache(0 ) 706cdf0e10cSrcweir { 707cdf0e10cSrcweir static const ::rtl::OUString CFG_ENTRY_ACCELERATORS(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Accelerators")); 708cdf0e10cSrcweir m_xCfg = css::uno::Reference< css::container::XNameAccess > ( 709cdf0e10cSrcweir ::comphelper::ConfigurationHelper::openConfig( m_xSMGR, CFG_ENTRY_ACCELERATORS, ::comphelper::ConfigurationHelper::E_ALL_LOCALES ), 710cdf0e10cSrcweir css::uno::UNO_QUERY ); 711cdf0e10cSrcweir } 712cdf0e10cSrcweir 713cdf0e10cSrcweir //----------------------------------------------- 714cdf0e10cSrcweir XCUBasedAcceleratorConfiguration::~XCUBasedAcceleratorConfiguration() 715cdf0e10cSrcweir { 716cdf0e10cSrcweir } 717cdf0e10cSrcweir 718cdf0e10cSrcweir //----------------------------------------------- 719cdf0e10cSrcweir css::uno::Sequence< css::awt::KeyEvent > SAL_CALL XCUBasedAcceleratorConfiguration::getAllKeyEvents() 720cdf0e10cSrcweir throw(css::uno::RuntimeException) 721cdf0e10cSrcweir { 722cdf0e10cSrcweir // SAFE -> ---------------------------------- 723cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 724cdf0e10cSrcweir 725cdf0e10cSrcweir AcceleratorCache::TKeyList lKeys = impl_getCFG(sal_True).getAllKeys(); //get keys from PrimaryKeys set 726cdf0e10cSrcweir 727cdf0e10cSrcweir AcceleratorCache::TKeyList lSecondaryKeys = impl_getCFG(sal_False).getAllKeys(); //get keys from SecondaryKeys set 728cdf0e10cSrcweir lKeys.reserve(lKeys.size()+lSecondaryKeys.size()); 729cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pIt; 730cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pEnd = lSecondaryKeys.end(); 731cdf0e10cSrcweir for ( pIt = lSecondaryKeys.begin(); pIt != pEnd; ++pIt ) 732cdf0e10cSrcweir lKeys.push_back(*pIt); 733cdf0e10cSrcweir 734cdf0e10cSrcweir return lKeys.getAsConstList(); 735cdf0e10cSrcweir 736cdf0e10cSrcweir // <- SAFE ---------------------------------- 737cdf0e10cSrcweir } 738cdf0e10cSrcweir 739cdf0e10cSrcweir //----------------------------------------------- 740cdf0e10cSrcweir ::rtl::OUString SAL_CALL XCUBasedAcceleratorConfiguration::getCommandByKeyEvent(const css::awt::KeyEvent& aKeyEvent) 741cdf0e10cSrcweir throw(css::container::NoSuchElementException, 742cdf0e10cSrcweir css::uno::RuntimeException ) 743cdf0e10cSrcweir { 744cdf0e10cSrcweir // SAFE -> ---------------------------------- 745cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 746cdf0e10cSrcweir 747cdf0e10cSrcweir AcceleratorCache& rPrimaryCache = impl_getCFG(sal_True ); 748cdf0e10cSrcweir AcceleratorCache& rSecondaryCache = impl_getCFG(sal_False); 749cdf0e10cSrcweir 750cdf0e10cSrcweir if (!rPrimaryCache.hasKey(aKeyEvent) && !rSecondaryCache.hasKey(aKeyEvent)) 751cdf0e10cSrcweir throw css::container::NoSuchElementException( 752cdf0e10cSrcweir ::rtl::OUString(), 753cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 754cdf0e10cSrcweir 755cdf0e10cSrcweir if (rPrimaryCache.hasKey(aKeyEvent)) 756cdf0e10cSrcweir return rPrimaryCache.getCommandByKey(aKeyEvent); 757cdf0e10cSrcweir else 758cdf0e10cSrcweir return rSecondaryCache.getCommandByKey(aKeyEvent); 759cdf0e10cSrcweir 760cdf0e10cSrcweir // <- SAFE ---------------------------------- 761cdf0e10cSrcweir } 762cdf0e10cSrcweir 763cdf0e10cSrcweir //----------------------------------------------- 764cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::setKeyEvent(const css::awt::KeyEvent& aKeyEvent, 765cdf0e10cSrcweir const ::rtl::OUString& sCommand ) 766cdf0e10cSrcweir throw(css::lang::IllegalArgumentException, 767cdf0e10cSrcweir css::uno::RuntimeException ) 768cdf0e10cSrcweir { 769cdf0e10cSrcweir RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::setKeyEvent" ); 770cdf0e10cSrcweir 771cdf0e10cSrcweir if ( 772cdf0e10cSrcweir (aKeyEvent.KeyCode == 0) && 773cdf0e10cSrcweir (aKeyEvent.KeyChar == 0) && 774cdf0e10cSrcweir (aKeyEvent.KeyFunc == 0) && 775cdf0e10cSrcweir (aKeyEvent.Modifiers == 0) 776cdf0e10cSrcweir ) 777cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 778cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Such key event seams not to be supported by any operating system."), 779cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 780cdf0e10cSrcweir 0); 781cdf0e10cSrcweir 782cdf0e10cSrcweir if (!sCommand.getLength()) 783cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 784cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Empty command strings are not allowed here."), 785cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 786cdf0e10cSrcweir 1); 787cdf0e10cSrcweir 788cdf0e10cSrcweir // SAFE -> ---------------------------------- 789cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 790cdf0e10cSrcweir 791cdf0e10cSrcweir AcceleratorCache& rPrimaryCache = impl_getCFG(sal_True, sal_True ); // sal_True => force getting of a writeable cache! 792cdf0e10cSrcweir AcceleratorCache& rSecondaryCache = impl_getCFG(sal_False, sal_True); // sal_True => force getting of a writeable cache! 793cdf0e10cSrcweir 794cdf0e10cSrcweir if ( rPrimaryCache.hasKey(aKeyEvent) ) 795cdf0e10cSrcweir { 796cdf0e10cSrcweir ::rtl::OUString sOriginalCommand = rPrimaryCache.getCommandByKey(aKeyEvent); 797cdf0e10cSrcweir if ( sCommand != sOriginalCommand ) 798cdf0e10cSrcweir { 799cdf0e10cSrcweir if (rSecondaryCache.hasCommand(sOriginalCommand)) 800cdf0e10cSrcweir { 801cdf0e10cSrcweir AcceleratorCache::TKeyList lSecondaryKeys = rSecondaryCache.getKeysByCommand(sOriginalCommand); 802cdf0e10cSrcweir rSecondaryCache.removeKey(lSecondaryKeys[0]); 803cdf0e10cSrcweir rPrimaryCache.setKeyCommandPair(lSecondaryKeys[0], sOriginalCommand); 804cdf0e10cSrcweir } 805cdf0e10cSrcweir 806cdf0e10cSrcweir if (rPrimaryCache.hasCommand(sCommand)) 807cdf0e10cSrcweir { 808cdf0e10cSrcweir AcceleratorCache::TKeyList lPrimaryKeys = rPrimaryCache.getKeysByCommand(sCommand); 809cdf0e10cSrcweir rPrimaryCache.removeKey(lPrimaryKeys[0]); 810cdf0e10cSrcweir rSecondaryCache.setKeyCommandPair(lPrimaryKeys[0], sCommand); 811cdf0e10cSrcweir } 812cdf0e10cSrcweir 813cdf0e10cSrcweir rPrimaryCache.setKeyCommandPair(aKeyEvent, sCommand); 814cdf0e10cSrcweir } 815cdf0e10cSrcweir } 816cdf0e10cSrcweir 817cdf0e10cSrcweir else if ( rSecondaryCache.hasKey(aKeyEvent) ) 818cdf0e10cSrcweir { 819cdf0e10cSrcweir ::rtl::OUString sOriginalCommand = rSecondaryCache.getCommandByKey(aKeyEvent); 820cdf0e10cSrcweir if (sCommand != sOriginalCommand) 821cdf0e10cSrcweir { 822cdf0e10cSrcweir if (rPrimaryCache.hasCommand(sCommand)) 823cdf0e10cSrcweir { 824cdf0e10cSrcweir AcceleratorCache::TKeyList lPrimaryKeys = rPrimaryCache.getKeysByCommand(sCommand); 825cdf0e10cSrcweir rPrimaryCache.removeKey(lPrimaryKeys[0]); 826cdf0e10cSrcweir rSecondaryCache.setKeyCommandPair(lPrimaryKeys[0], sCommand); 827cdf0e10cSrcweir } 828cdf0e10cSrcweir 829cdf0e10cSrcweir rSecondaryCache.removeKey(aKeyEvent); 830cdf0e10cSrcweir rPrimaryCache.setKeyCommandPair(aKeyEvent, sCommand); 831cdf0e10cSrcweir } 832cdf0e10cSrcweir } 833cdf0e10cSrcweir 834cdf0e10cSrcweir else 835cdf0e10cSrcweir { 836cdf0e10cSrcweir if (rPrimaryCache.hasCommand(sCommand)) 837cdf0e10cSrcweir { 838cdf0e10cSrcweir AcceleratorCache::TKeyList lPrimaryKeys = rPrimaryCache.getKeysByCommand(sCommand); 839cdf0e10cSrcweir rPrimaryCache.removeKey(lPrimaryKeys[0]); 840cdf0e10cSrcweir rSecondaryCache.setKeyCommandPair(lPrimaryKeys[0], sCommand); 841cdf0e10cSrcweir } 842cdf0e10cSrcweir 843cdf0e10cSrcweir rPrimaryCache.setKeyCommandPair(aKeyEvent, sCommand); 844cdf0e10cSrcweir } 845cdf0e10cSrcweir 846cdf0e10cSrcweir aWriteLock.unlock(); 847cdf0e10cSrcweir // <- SAFE ---------------------------------- 848cdf0e10cSrcweir } 849cdf0e10cSrcweir 850cdf0e10cSrcweir //----------------------------------------------- 851cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::removeKeyEvent(const css::awt::KeyEvent& aKeyEvent) 852cdf0e10cSrcweir throw(css::container::NoSuchElementException, 853cdf0e10cSrcweir css::uno::RuntimeException ) 854cdf0e10cSrcweir { 855cdf0e10cSrcweir // SAFE -> ---------------------------------- 856cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 857cdf0e10cSrcweir 858cdf0e10cSrcweir AcceleratorCache& rPrimaryCache = impl_getCFG(sal_True, sal_True ); 859cdf0e10cSrcweir AcceleratorCache& rSecondaryCache = impl_getCFG(sal_False, sal_True); 860cdf0e10cSrcweir 861cdf0e10cSrcweir if (!rPrimaryCache.hasKey(aKeyEvent) && !rSecondaryCache.hasKey(aKeyEvent)) 862cdf0e10cSrcweir throw css::container::NoSuchElementException( 863cdf0e10cSrcweir ::rtl::OUString(), 864cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 865cdf0e10cSrcweir 866cdf0e10cSrcweir if (rPrimaryCache.hasKey(aKeyEvent)) 867cdf0e10cSrcweir { 868cdf0e10cSrcweir ::rtl::OUString sDelCommand = rPrimaryCache.getCommandByKey(aKeyEvent); 869cdf0e10cSrcweir if (sDelCommand.getLength() > 0) 870cdf0e10cSrcweir { 871cdf0e10cSrcweir ::rtl::OUString sOriginalCommand = rPrimaryCache.getCommandByKey(aKeyEvent); 872cdf0e10cSrcweir if (rSecondaryCache.hasCommand(sOriginalCommand)) 873cdf0e10cSrcweir { 874cdf0e10cSrcweir AcceleratorCache::TKeyList lSecondaryKeys = rSecondaryCache.getKeysByCommand(sOriginalCommand); 875cdf0e10cSrcweir rSecondaryCache.removeKey(lSecondaryKeys[0]); 876cdf0e10cSrcweir rPrimaryCache.setKeyCommandPair(lSecondaryKeys[0], sOriginalCommand); 877cdf0e10cSrcweir } 878cdf0e10cSrcweir 879cdf0e10cSrcweir rPrimaryCache.removeKey(aKeyEvent); 880cdf0e10cSrcweir } 881cdf0e10cSrcweir 882cdf0e10cSrcweir } 883cdf0e10cSrcweir else 884cdf0e10cSrcweir { 885cdf0e10cSrcweir ::rtl::OUString sDelCommand = rSecondaryCache.getCommandByKey(aKeyEvent); 886cdf0e10cSrcweir if (sDelCommand.getLength() > 0) 887cdf0e10cSrcweir rSecondaryCache.removeKey(aKeyEvent); 888cdf0e10cSrcweir } 889cdf0e10cSrcweir 890cdf0e10cSrcweir // <- SAFE ---------------------------------- 891cdf0e10cSrcweir } 892cdf0e10cSrcweir 893cdf0e10cSrcweir //----------------------------------------------- 894cdf0e10cSrcweir css::uno::Sequence< css::awt::KeyEvent > SAL_CALL XCUBasedAcceleratorConfiguration::getKeyEventsByCommand(const ::rtl::OUString& sCommand) 895cdf0e10cSrcweir throw(css::lang::IllegalArgumentException , 896cdf0e10cSrcweir css::container::NoSuchElementException, 897cdf0e10cSrcweir css::uno::RuntimeException ) 898cdf0e10cSrcweir { 899cdf0e10cSrcweir if (!sCommand.getLength()) 900cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 901cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Empty command strings are not allowed here."), 902cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 903cdf0e10cSrcweir 1); 904cdf0e10cSrcweir 905cdf0e10cSrcweir // SAFE -> ---------------------------------- 906cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 907cdf0e10cSrcweir 908cdf0e10cSrcweir AcceleratorCache& rPrimaryCache = impl_getCFG(sal_True ); 909cdf0e10cSrcweir AcceleratorCache& rSecondaryCache = impl_getCFG(sal_False); 910cdf0e10cSrcweir 911cdf0e10cSrcweir if (!rPrimaryCache.hasCommand(sCommand) && !rSecondaryCache.hasCommand(sCommand)) 912cdf0e10cSrcweir throw css::container::NoSuchElementException( 913cdf0e10cSrcweir ::rtl::OUString(), 914cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 915cdf0e10cSrcweir 916cdf0e10cSrcweir AcceleratorCache::TKeyList lKeys = rPrimaryCache.getKeysByCommand(sCommand); 917cdf0e10cSrcweir 918cdf0e10cSrcweir AcceleratorCache::TKeyList lSecondaryKeys = rSecondaryCache.getKeysByCommand(sCommand); 919cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pIt; 920cdf0e10cSrcweir for (pIt = lSecondaryKeys.begin(); pIt != lSecondaryKeys.end(); ++pIt) 921cdf0e10cSrcweir lKeys.push_back(*pIt); 922cdf0e10cSrcweir 923cdf0e10cSrcweir return lKeys.getAsConstList(); 924cdf0e10cSrcweir 925cdf0e10cSrcweir // <- SAFE ---------------------------------- 926cdf0e10cSrcweir } 927cdf0e10cSrcweir 928cdf0e10cSrcweir //----------------------------------------------- 929cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator lcl_getPreferredKey(const AcceleratorCache::TKeyList& lKeys) 930cdf0e10cSrcweir { 931cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pIt; 932cdf0e10cSrcweir for ( pIt = lKeys.begin (); 933cdf0e10cSrcweir pIt != lKeys.end (); 934cdf0e10cSrcweir ++pIt ) 935cdf0e10cSrcweir { 936cdf0e10cSrcweir const css::awt::KeyEvent& rAWTKey = *pIt; 937cdf0e10cSrcweir const KeyCode aVCLKey = ::svt::AcceleratorExecute::st_AWTKey2VCLKey(rAWTKey); 938cdf0e10cSrcweir const String sName = aVCLKey.GetName(); 939cdf0e10cSrcweir 940cdf0e10cSrcweir if (sName.Len () > 0) 941cdf0e10cSrcweir return pIt; 942cdf0e10cSrcweir } 943cdf0e10cSrcweir 944cdf0e10cSrcweir return lKeys.end (); 945cdf0e10cSrcweir } 946cdf0e10cSrcweir 947cdf0e10cSrcweir //----------------------------------------------- 948cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > SAL_CALL XCUBasedAcceleratorConfiguration::getPreferredKeyEventsForCommandList(const css::uno::Sequence< ::rtl::OUString >& lCommandList) 949cdf0e10cSrcweir throw(css::lang::IllegalArgumentException , 950cdf0e10cSrcweir css::uno::RuntimeException ) 951cdf0e10cSrcweir { 952cdf0e10cSrcweir // SAFE -> ---------------------------------- 953cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 954cdf0e10cSrcweir 955cdf0e10cSrcweir sal_Int32 i = 0; 956cdf0e10cSrcweir sal_Int32 c = lCommandList.getLength(); 957cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > lPreferredOnes (c); // dont pack list! 958cdf0e10cSrcweir AcceleratorCache& rCache = impl_getCFG(sal_True); 959cdf0e10cSrcweir 960cdf0e10cSrcweir for (i=0; i<c; ++i) 961cdf0e10cSrcweir { 962cdf0e10cSrcweir const ::rtl::OUString& rCommand = lCommandList[i]; 963cdf0e10cSrcweir if (!rCommand.getLength()) 964cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 965cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Empty command strings are not allowed here."), 966cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 967cdf0e10cSrcweir (sal_Int16)i); 968cdf0e10cSrcweir 969cdf0e10cSrcweir if (!rCache.hasCommand(rCommand)) 970cdf0e10cSrcweir continue; 971cdf0e10cSrcweir 972cdf0e10cSrcweir AcceleratorCache::TKeyList lKeys = rCache.getKeysByCommand(rCommand); 973cdf0e10cSrcweir if ( lKeys.empty() ) 974cdf0e10cSrcweir continue; 975cdf0e10cSrcweir 976cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pPreferredKey = lcl_getPreferredKey(lKeys); 977cdf0e10cSrcweir if (pPreferredKey != lKeys.end ()) 978cdf0e10cSrcweir { 979cdf0e10cSrcweir css::uno::Any& rAny = lPreferredOnes[i]; 980cdf0e10cSrcweir rAny <<= *(pPreferredKey); 981cdf0e10cSrcweir } 982cdf0e10cSrcweir } 983cdf0e10cSrcweir 984cdf0e10cSrcweir aReadLock.unlock(); 985cdf0e10cSrcweir // <- SAFE ---------------------------------- 986cdf0e10cSrcweir 987cdf0e10cSrcweir return lPreferredOnes; 988cdf0e10cSrcweir } 989cdf0e10cSrcweir 990cdf0e10cSrcweir //----------------------------------------------- 991cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::removeCommandFromAllKeyEvents(const ::rtl::OUString& sCommand) 992cdf0e10cSrcweir throw(css::lang::IllegalArgumentException , 993cdf0e10cSrcweir css::container::NoSuchElementException, 994cdf0e10cSrcweir css::uno::RuntimeException ) 995cdf0e10cSrcweir { 996cdf0e10cSrcweir if (!sCommand.getLength()) 997cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 998cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Empty command strings are not allowed here."), 999cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 1000cdf0e10cSrcweir 0); 1001cdf0e10cSrcweir 1002cdf0e10cSrcweir // SAFE -> ---------------------------------- 1003cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir AcceleratorCache& rPrimaryCache = impl_getCFG(sal_True, sal_True ); 1006cdf0e10cSrcweir AcceleratorCache& rSecondaryCache = impl_getCFG(sal_False, sal_True); 1007cdf0e10cSrcweir 1008cdf0e10cSrcweir if (!rPrimaryCache.hasCommand(sCommand) && !rSecondaryCache.hasCommand(sCommand)) 1009cdf0e10cSrcweir throw css::container::NoSuchElementException( 1010cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Command does not exists inside this container."), 1011cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 1012cdf0e10cSrcweir 1013cdf0e10cSrcweir if (rPrimaryCache.hasCommand(sCommand)) 1014cdf0e10cSrcweir rPrimaryCache.removeCommand(sCommand); 1015cdf0e10cSrcweir if (rSecondaryCache.hasCommand(sCommand)) 1016cdf0e10cSrcweir rSecondaryCache.removeCommand(sCommand); 1017cdf0e10cSrcweir 1018cdf0e10cSrcweir aWriteLock.unlock(); 1019cdf0e10cSrcweir // <- SAFE ---------------------------------- 1020cdf0e10cSrcweir } 1021cdf0e10cSrcweir 1022cdf0e10cSrcweir //----------------------------------------------- 1023cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::reload() 1024cdf0e10cSrcweir throw(css::uno::Exception , 1025cdf0e10cSrcweir css::uno::RuntimeException) 1026cdf0e10cSrcweir { 1027cdf0e10cSrcweir RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::reload()" ); 1028cdf0e10cSrcweir 1029cdf0e10cSrcweir // SAFE -> ---------------------------------- 1030cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1031cdf0e10cSrcweir 1032cdf0e10cSrcweir sal_Bool bPreferred; 1033cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess; 1034cdf0e10cSrcweir 1035cdf0e10cSrcweir bPreferred = sal_True; 1036cdf0e10cSrcweir m_aPrimaryReadCache = AcceleratorCache(); 1037cdf0e10cSrcweir if (m_pPrimaryWriteCache) 1038cdf0e10cSrcweir { 1039cdf0e10cSrcweir // be aware of reentrance problems - use temp variable for calling delete ... :-) 1040cdf0e10cSrcweir AcceleratorCache* pTemp = m_pPrimaryWriteCache; 1041cdf0e10cSrcweir m_pPrimaryWriteCache = 0; 1042cdf0e10cSrcweir delete pTemp; 1043cdf0e10cSrcweir } 1044cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_PRIMARY) >>= xAccess; 1045cdf0e10cSrcweir impl_ts_load(bPreferred, xAccess); // load the preferred keys 1046cdf0e10cSrcweir 1047cdf0e10cSrcweir bPreferred = sal_False; 1048cdf0e10cSrcweir m_aSecondaryReadCache = AcceleratorCache(); 1049cdf0e10cSrcweir if (m_pSecondaryWriteCache) 1050cdf0e10cSrcweir { 1051cdf0e10cSrcweir // be aware of reentrance problems - use temp variable for calling delete ... :-) 1052cdf0e10cSrcweir AcceleratorCache* pTemp = m_pSecondaryWriteCache; 1053cdf0e10cSrcweir m_pSecondaryWriteCache = 0; 1054cdf0e10cSrcweir delete pTemp; 1055cdf0e10cSrcweir } 1056cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_SECONDARY) >>= xAccess; 1057cdf0e10cSrcweir impl_ts_load(bPreferred, xAccess); // load the secondary keys 1058cdf0e10cSrcweir 1059cdf0e10cSrcweir aWriteLock.unlock(); 1060cdf0e10cSrcweir // <- SAFE ---------------------------------- 1061cdf0e10cSrcweir } 1062cdf0e10cSrcweir 1063cdf0e10cSrcweir //----------------------------------------------- 1064cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::store() 1065cdf0e10cSrcweir throw(css::uno::Exception , 1066cdf0e10cSrcweir css::uno::RuntimeException) 1067cdf0e10cSrcweir { 1068cdf0e10cSrcweir RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::store()" ); 1069cdf0e10cSrcweir 1070cdf0e10cSrcweir // SAFE -> ---------------------------------- 1071cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 1072cdf0e10cSrcweir 1073cdf0e10cSrcweir sal_Bool bPreferred; 1074cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess; 1075cdf0e10cSrcweir 1076cdf0e10cSrcweir bPreferred = sal_True; 1077cdf0e10cSrcweir // on-demand creation of the primary write cache 1078cdf0e10cSrcweir impl_getCFG(bPreferred, sal_True); 1079cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_PRIMARY) >>= xAccess; 1080cdf0e10cSrcweir impl_ts_save(bPreferred, xAccess); 1081cdf0e10cSrcweir 1082cdf0e10cSrcweir bPreferred = sal_False; 1083cdf0e10cSrcweir // on-demand creation of the secondary write cache 1084cdf0e10cSrcweir impl_getCFG(bPreferred, sal_True); 1085cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_SECONDARY) >>= xAccess; 1086cdf0e10cSrcweir impl_ts_save(bPreferred, xAccess); 1087cdf0e10cSrcweir 1088cdf0e10cSrcweir aReadLock.unlock(); 1089cdf0e10cSrcweir // <- SAFE ---------------------------------- 1090cdf0e10cSrcweir } 1091cdf0e10cSrcweir 1092cdf0e10cSrcweir //----------------------------------------------- 1093cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::storeToStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) 1094cdf0e10cSrcweir throw(css::uno::Exception , 1095cdf0e10cSrcweir css::uno::RuntimeException) 1096cdf0e10cSrcweir { 1097cdf0e10cSrcweir // use m_aCache + old AcceleratorXMLWriter to store data directly on storage given as parameter ... 1098cdf0e10cSrcweir if (!xStorage.is()) 1099cdf0e10cSrcweir return; 1100cdf0e10cSrcweir 1101cdf0e10cSrcweir long nOpenModes = css::embed::ElementModes::READWRITE; 1102cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xAcceleratorTypeStorage = xStorage->openStorageElement(::rtl::OUString::createFromAscii("accelerator"), nOpenModes); 1103cdf0e10cSrcweir if (!xAcceleratorTypeStorage.is()) 1104cdf0e10cSrcweir return; 1105cdf0e10cSrcweir 1106cdf0e10cSrcweir css::uno::Reference< css::io::XStream > xStream = xAcceleratorTypeStorage->openStreamElement(::rtl::OUString::createFromAscii("current"), nOpenModes); 1107cdf0e10cSrcweir css::uno::Reference< css::io::XOutputStream > xOut; 1108cdf0e10cSrcweir if (xStream.is()) 1109cdf0e10cSrcweir xOut = xStream->getOutputStream(); 1110cdf0e10cSrcweir if (!xOut.is()) 1111cdf0e10cSrcweir throw css::io::IOException( 1112cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Could not open accelerator configuration for saving."), 1113cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 1114cdf0e10cSrcweir 1115cdf0e10cSrcweir // the original m_aCache has been split into primay cache and secondary cache... 1116cdf0e10cSrcweir // we should merge them before storing to storage 1117cdf0e10cSrcweir // SAFE -> ---------------------------------- 1118cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1119cdf0e10cSrcweir 1120cdf0e10cSrcweir AcceleratorCache aCache; 1121cdf0e10cSrcweir if (m_pPrimaryWriteCache != 0) 1122cdf0e10cSrcweir aCache.takeOver(*m_pPrimaryWriteCache); 1123cdf0e10cSrcweir else 1124cdf0e10cSrcweir aCache.takeOver(m_aPrimaryReadCache); 1125cdf0e10cSrcweir 1126cdf0e10cSrcweir AcceleratorCache::TKeyList lKeys; 1127cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pIt; 1128cdf0e10cSrcweir if (m_pSecondaryWriteCache!=0) 1129cdf0e10cSrcweir { 1130cdf0e10cSrcweir lKeys = m_pSecondaryWriteCache->getAllKeys(); 1131cdf0e10cSrcweir for ( pIt=lKeys.begin(); pIt!=lKeys.end(); ++pIt ) 1132cdf0e10cSrcweir aCache.setKeyCommandPair(*pIt, m_pSecondaryWriteCache->getCommandByKey(*pIt)); 1133cdf0e10cSrcweir } 1134cdf0e10cSrcweir else 1135cdf0e10cSrcweir { 1136cdf0e10cSrcweir lKeys = m_aSecondaryReadCache.getAllKeys(); 1137cdf0e10cSrcweir for ( pIt=lKeys.begin(); pIt!=lKeys.end(); ++pIt ) 1138cdf0e10cSrcweir aCache.setKeyCommandPair(*pIt, m_aSecondaryReadCache.getCommandByKey(*pIt)); 1139cdf0e10cSrcweir } 1140cdf0e10cSrcweir 1141cdf0e10cSrcweir aWriteLock.unlock(); 1142cdf0e10cSrcweir // <- SAFE ---------------------------------- 1143cdf0e10cSrcweir 1144cdf0e10cSrcweir css::uno::Reference< css::io::XTruncate > xClearable(xOut, css::uno::UNO_QUERY_THROW); 1145cdf0e10cSrcweir xClearable->truncate(); 1146cdf0e10cSrcweir css::uno::Reference< css::io::XSeekable > xSeek(xOut, css::uno::UNO_QUERY); 1147cdf0e10cSrcweir if (xSeek.is()) 1148cdf0e10cSrcweir xSeek->seek(0); 1149cdf0e10cSrcweir 1150cdf0e10cSrcweir css::uno::Reference< css::xml::sax::XDocumentHandler > xWriter (m_xSMGR->createInstance(SERVICENAME_SAXWRITER), css::uno::UNO_QUERY_THROW); 1151cdf0e10cSrcweir css::uno::Reference< css::io::XActiveDataSource> xDataSource(xWriter , css::uno::UNO_QUERY_THROW); 1152cdf0e10cSrcweir xDataSource->setOutputStream(xOut); 1153cdf0e10cSrcweir 1154cdf0e10cSrcweir // write into the stream 1155cdf0e10cSrcweir AcceleratorConfigurationWriter aWriter(aCache, xWriter); 1156cdf0e10cSrcweir aWriter.flush(); 1157cdf0e10cSrcweir } 1158cdf0e10cSrcweir 1159cdf0e10cSrcweir //----------------------------------------------- 1160cdf0e10cSrcweir ::sal_Bool SAL_CALL XCUBasedAcceleratorConfiguration::isModified() 1161cdf0e10cSrcweir throw(css::uno::RuntimeException) 1162cdf0e10cSrcweir { 1163cdf0e10cSrcweir return sal_False; 1164cdf0e10cSrcweir } 1165cdf0e10cSrcweir 1166cdf0e10cSrcweir //----------------------------------------------- 1167cdf0e10cSrcweir ::sal_Bool SAL_CALL XCUBasedAcceleratorConfiguration::isReadOnly() 1168cdf0e10cSrcweir throw(css::uno::RuntimeException) 1169cdf0e10cSrcweir { 1170cdf0e10cSrcweir return sal_False; 1171cdf0e10cSrcweir } 1172cdf0e10cSrcweir 1173cdf0e10cSrcweir //----------------------------------------------- 1174cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::setStorage(const css::uno::Reference< css::embed::XStorage >& /*xStorage*/) 1175cdf0e10cSrcweir throw(css::uno::RuntimeException) 1176cdf0e10cSrcweir { 1177cdf0e10cSrcweir LOG_WARNING("XCUBasedAcceleratorConfiguration::setStorage()", "TODO implement this HACK .-)") 1178cdf0e10cSrcweir } 1179cdf0e10cSrcweir 1180cdf0e10cSrcweir //----------------------------------------------- 1181cdf0e10cSrcweir ::sal_Bool SAL_CALL XCUBasedAcceleratorConfiguration::hasStorage() 1182cdf0e10cSrcweir throw(css::uno::RuntimeException) 1183cdf0e10cSrcweir { 1184cdf0e10cSrcweir LOG_WARNING("XCUBasedAcceleratorConfiguration::hasStorage()", "TODO implement this HACK .-)") 1185cdf0e10cSrcweir return sal_False; 1186cdf0e10cSrcweir } 1187cdf0e10cSrcweir 1188cdf0e10cSrcweir //----------------------------------------------- 1189cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::addConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& /*xListener*/) 1190cdf0e10cSrcweir throw(css::uno::RuntimeException) 1191cdf0e10cSrcweir { 1192cdf0e10cSrcweir LOG_WARNING("XCUBasedAcceleratorConfiguration::addConfigurationListener()", "TODO implement me") 1193cdf0e10cSrcweir } 1194cdf0e10cSrcweir 1195cdf0e10cSrcweir //----------------------------------------------- 1196cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::removeConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& /*xListener*/) 1197cdf0e10cSrcweir throw(css::uno::RuntimeException) 1198cdf0e10cSrcweir { 1199cdf0e10cSrcweir LOG_WARNING("XCUBasedAcceleratorConfiguration::removeConfigurationListener()", "TODO implement me") 1200cdf0e10cSrcweir } 1201cdf0e10cSrcweir 1202cdf0e10cSrcweir //----------------------------------------------- 1203cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::reset() 1204cdf0e10cSrcweir throw(css::uno::RuntimeException) 1205cdf0e10cSrcweir { 1206cdf0e10cSrcweir css::uno::Reference< css::container::XNamed > xNamed(m_xCfg, css::uno::UNO_QUERY); 1207cdf0e10cSrcweir ::rtl::OUString sConfig = xNamed->getName(); 1208cdf0e10cSrcweir if ( sConfig.equalsAscii("Global") ) 1209cdf0e10cSrcweir { 1210cdf0e10cSrcweir m_xCfg = css::uno::Reference< css::container::XNameAccess > ( 1211cdf0e10cSrcweir ::comphelper::ConfigurationHelper::openConfig( m_xSMGR, CFG_ENTRY_GLOBAL, ::comphelper::ConfigurationHelper::E_ALL_LOCALES ), 1212cdf0e10cSrcweir css::uno::UNO_QUERY ); 1213cdf0e10cSrcweir XCUBasedAcceleratorConfiguration::reload(); 1214cdf0e10cSrcweir } 1215cdf0e10cSrcweir else if ( sConfig.equalsAscii("Modules") ) 1216cdf0e10cSrcweir { 1217cdf0e10cSrcweir m_xCfg = css::uno::Reference< css::container::XNameAccess > ( 1218cdf0e10cSrcweir ::comphelper::ConfigurationHelper::openConfig( m_xSMGR, CFG_ENTRY_MODULES, ::comphelper::ConfigurationHelper::E_ALL_LOCALES ), 1219cdf0e10cSrcweir css::uno::UNO_QUERY ); 1220cdf0e10cSrcweir XCUBasedAcceleratorConfiguration::reload(); 1221cdf0e10cSrcweir } 1222cdf0e10cSrcweir } 1223cdf0e10cSrcweir 1224cdf0e10cSrcweir //----------------------------------------------- 1225cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::addResetListener(const css::uno::Reference< css::form::XResetListener >& /*xListener*/) 1226cdf0e10cSrcweir throw(css::uno::RuntimeException) 1227cdf0e10cSrcweir { 1228cdf0e10cSrcweir LOG_WARNING("XCUBasedAcceleratorConfiguration::addResetListener()", "TODO implement me") 1229cdf0e10cSrcweir } 1230cdf0e10cSrcweir 1231cdf0e10cSrcweir //----------------------------------------------- 1232cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::removeResetListener(const css::uno::Reference< css::form::XResetListener >& /*xListener*/) 1233cdf0e10cSrcweir throw(css::uno::RuntimeException) 1234cdf0e10cSrcweir { 1235cdf0e10cSrcweir LOG_WARNING("XCUBasedAcceleratorConfiguration::removeResetListener()", "TODO implement me") 1236cdf0e10cSrcweir } 1237cdf0e10cSrcweir 1238cdf0e10cSrcweir //----------------------------------------------- 1239cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::changesOccurred(const css::util::ChangesEvent& aEvent) 1240cdf0e10cSrcweir throw(css::uno::RuntimeException) 1241cdf0e10cSrcweir { 1242cdf0e10cSrcweir RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::changesOccurred()" ); 1243cdf0e10cSrcweir 1244cdf0e10cSrcweir css::uno::Reference< css::container::XHierarchicalNameAccess > xHAccess; 1245cdf0e10cSrcweir aEvent.Base >>= xHAccess; 1246cdf0e10cSrcweir if (! xHAccess.is ()) 1247cdf0e10cSrcweir return; 1248cdf0e10cSrcweir 1249cdf0e10cSrcweir css::util::ChangesEvent aReceivedEvents( aEvent ); 1250cdf0e10cSrcweir const sal_Int32 c = aReceivedEvents.Changes.getLength(); 1251cdf0e10cSrcweir sal_Int32 i = 0; 1252cdf0e10cSrcweir for (i=0; i<c; ++i) 1253cdf0e10cSrcweir { 1254cdf0e10cSrcweir const css::util::ElementChange& aChange = aReceivedEvents.Changes[i]; 1255cdf0e10cSrcweir 1256cdf0e10cSrcweir // Only path of form "PrimaryKeys/Modules/Module['<module_name>']/Key['<command_url>']/Command[<locale>]" will 1257cdf0e10cSrcweir // be interesting for use. Sometimes short path values are given also by the broadcaster ... but they must be ignored :-) 1258cdf0e10cSrcweir // So we try to split the path into 3 parts (module isnt important here, because we already know it ... because 1259cdf0e10cSrcweir // these instance is bound to a specific module configuration ... or it''s the global configuration where no module is given at all. 1260cdf0e10cSrcweir 1261cdf0e10cSrcweir ::rtl::OUString sOrgPath ; 1262cdf0e10cSrcweir ::rtl::OUString sPath ; 1263cdf0e10cSrcweir ::rtl::OUString sKey; 1264cdf0e10cSrcweir 1265cdf0e10cSrcweir aChange.Accessor >>= sOrgPath; 1266cdf0e10cSrcweir sPath = sOrgPath; 1267cdf0e10cSrcweir ::rtl::OUString sPrimarySecondary = ::utl::extractFirstFromConfigurationPath(sPath, &sPath); 1268cdf0e10cSrcweir ::rtl::OUString sGlobalModules = ::utl::extractFirstFromConfigurationPath(sPath, &sPath); 1269cdf0e10cSrcweir 1270cdf0e10cSrcweir if ( sGlobalModules.equals(CFG_ENTRY_GLOBAL) ) 1271cdf0e10cSrcweir { 1272cdf0e10cSrcweir ::rtl::OUString sModule; 1273cdf0e10cSrcweir sKey = ::utl::extractFirstFromConfigurationPath(sPath, &sPath); 1274cdf0e10cSrcweir if (( sKey.getLength() > 0 ) && ( sPath.getLength() > 0 )) 1275cdf0e10cSrcweir reloadChanged(sPrimarySecondary, sGlobalModules, sModule, sKey); 1276cdf0e10cSrcweir } 1277cdf0e10cSrcweir else if ( sGlobalModules.equals(CFG_ENTRY_MODULES) ) 1278cdf0e10cSrcweir { 1279cdf0e10cSrcweir ::rtl::OUString sModule = ::utl::extractFirstFromConfigurationPath(sPath, &sPath); 1280cdf0e10cSrcweir sKey = ::utl::extractFirstFromConfigurationPath(sPath, &sPath); 1281cdf0e10cSrcweir 1282cdf0e10cSrcweir if (( sKey.getLength() > 0 ) && ( sPath.getLength() > 0 )) 1283cdf0e10cSrcweir { 1284cdf0e10cSrcweir reloadChanged(sPrimarySecondary, sGlobalModules, sModule, sKey); 1285cdf0e10cSrcweir } 1286cdf0e10cSrcweir } 1287cdf0e10cSrcweir } 1288cdf0e10cSrcweir } 1289cdf0e10cSrcweir 1290cdf0e10cSrcweir //----------------------------------------------- 1291cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::disposing(const css::lang::EventObject& /*aSource*/) 1292cdf0e10cSrcweir throw(css::uno::RuntimeException) 1293cdf0e10cSrcweir { 1294cdf0e10cSrcweir } 1295cdf0e10cSrcweir 1296cdf0e10cSrcweir //----------------------------------------------- 1297*796936d9SAndre Fischer void SAL_CALL XCUBasedAcceleratorConfiguration::dispose() 1298*796936d9SAndre Fischer throw(css::uno::RuntimeException) 1299*796936d9SAndre Fischer { 1300*796936d9SAndre Fischer // nop 1301*796936d9SAndre Fischer } 1302*796936d9SAndre Fischer 1303*796936d9SAndre Fischer //----------------------------------------------- 1304*796936d9SAndre Fischer void SAL_CALL XCUBasedAcceleratorConfiguration::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) 1305*796936d9SAndre Fischer throw(css::uno::RuntimeException) 1306*796936d9SAndre Fischer { 1307*796936d9SAndre Fischer // nop 1308*796936d9SAndre Fischer } 1309*796936d9SAndre Fischer 1310*796936d9SAndre Fischer //----------------------------------------------- 1311*796936d9SAndre Fischer void SAL_CALL XCUBasedAcceleratorConfiguration::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) 1312*796936d9SAndre Fischer throw(css::uno::RuntimeException) 1313*796936d9SAndre Fischer { 1314*796936d9SAndre Fischer // nop 1315*796936d9SAndre Fischer } 1316*796936d9SAndre Fischer 1317*796936d9SAndre Fischer //----------------------------------------------- 1318cdf0e10cSrcweir void XCUBasedAcceleratorConfiguration::impl_ts_load( sal_Bool bPreferred, const css::uno::Reference< css::container::XNameAccess >& xCfg ) 1319cdf0e10cSrcweir { 1320cdf0e10cSrcweir AcceleratorCache aReadCache = AcceleratorCache(); 1321cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess; 1322cdf0e10cSrcweir if (m_sGlobalOrModules.equalsAscii("Global")) 1323cdf0e10cSrcweir xCfg->getByName(CFG_ENTRY_GLOBAL) >>= xAccess; 1324cdf0e10cSrcweir else if (m_sGlobalOrModules.equalsAscii("Modules")) 1325cdf0e10cSrcweir { 1326cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xModules; 1327cdf0e10cSrcweir xCfg->getByName(CFG_ENTRY_MODULES) >>= xModules; 1328cdf0e10cSrcweir xModules->getByName(m_sModuleCFG) >>= xAccess; 1329cdf0e10cSrcweir } 1330cdf0e10cSrcweir 1331cdf0e10cSrcweir const ::rtl::OUString sIsoLang = impl_ts_getLocale().toISO(); 1332cdf0e10cSrcweir const ::rtl::OUString sDefaultLocale = ::rtl::OUString::createFromAscii("en-US"); 1333cdf0e10cSrcweir 1334cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xKey; 1335cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xCommand; 1336cdf0e10cSrcweir if (xAccess.is()) 1337cdf0e10cSrcweir { 1338cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lKeys = xAccess->getElementNames(); 1339cdf0e10cSrcweir sal_Int32 nKeys = lKeys.getLength(); 1340cdf0e10cSrcweir for ( sal_Int32 i=0; i<nKeys; ++i ) 1341cdf0e10cSrcweir { 1342cdf0e10cSrcweir ::rtl::OUString sKey = lKeys[i]; 1343cdf0e10cSrcweir xAccess->getByName(sKey) >>= xKey; 1344cdf0e10cSrcweir xKey->getByName(CFG_PROP_COMMAND) >>= xCommand; 1345cdf0e10cSrcweir 1346cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lLocales = xCommand->getElementNames(); 1347cdf0e10cSrcweir sal_Int32 nLocales = lLocales.getLength(); 1348cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aLocales; 1349cdf0e10cSrcweir for ( sal_Int32 j=0; j<nLocales; ++j ) 1350cdf0e10cSrcweir aLocales.push_back(lLocales[j]); 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pFound; 1353cdf0e10cSrcweir for ( pFound = aLocales.begin(); pFound != aLocales.end(); ++pFound ) 1354cdf0e10cSrcweir { 1355cdf0e10cSrcweir if ( *pFound == sIsoLang ) 1356cdf0e10cSrcweir break; 1357cdf0e10cSrcweir } 1358cdf0e10cSrcweir 1359cdf0e10cSrcweir if ( pFound == aLocales.end() ) 1360cdf0e10cSrcweir { 1361cdf0e10cSrcweir for ( pFound = aLocales.begin(); pFound != aLocales.end(); ++pFound ) 1362cdf0e10cSrcweir { 1363cdf0e10cSrcweir if ( *pFound == sDefaultLocale ) 1364cdf0e10cSrcweir break; 1365cdf0e10cSrcweir } 1366cdf0e10cSrcweir 1367cdf0e10cSrcweir if ( pFound == aLocales.end() ) 1368cdf0e10cSrcweir continue; 1369cdf0e10cSrcweir } 1370cdf0e10cSrcweir 1371cdf0e10cSrcweir ::rtl::OUString sLocale = *pFound; 1372cdf0e10cSrcweir ::rtl::OUString sCommand; 1373cdf0e10cSrcweir xCommand->getByName(sLocale) >>= sCommand; 1374cdf0e10cSrcweir if (sCommand.getLength()<1) 1375cdf0e10cSrcweir continue; 1376cdf0e10cSrcweir 1377cdf0e10cSrcweir css::awt::KeyEvent aKeyEvent; 1378cdf0e10cSrcweir 1379cdf0e10cSrcweir sal_Int32 nIndex = 0; 1380cdf0e10cSrcweir ::rtl::OUString sKeyCommand = sKey.getToken(0, '_', nIndex); 1381cdf0e10cSrcweir ::rtl::OUString sPrefix = ::rtl::OUString::createFromAscii("KEY_"); 1382cdf0e10cSrcweir aKeyEvent.KeyCode = m_rKeyMapping->mapIdentifierToCode(sPrefix + sKeyCommand); 1383cdf0e10cSrcweir 1384cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > sToken(4); 1385cdf0e10cSrcweir const sal_Int32 nToken = 4; 1386cdf0e10cSrcweir sal_Bool bValid = sal_True; 1387cdf0e10cSrcweir sal_Int32 k; 1388cdf0e10cSrcweir for (k=0; k<nToken; ++k) 1389cdf0e10cSrcweir { 1390cdf0e10cSrcweir if (nIndex < 0) 1391cdf0e10cSrcweir break; 1392cdf0e10cSrcweir 1393cdf0e10cSrcweir sToken[k] = sKey.getToken(0, '_', nIndex); 1394cdf0e10cSrcweir ::rtl::OUString sTest = sToken[k]; 1395cdf0e10cSrcweir if (sToken[k].getLength() < 1) 1396cdf0e10cSrcweir { 1397cdf0e10cSrcweir bValid = sal_False; 1398cdf0e10cSrcweir break; 1399cdf0e10cSrcweir } 1400cdf0e10cSrcweir 1401cdf0e10cSrcweir if (sToken[k].equalsAscii("SHIFT")) 1402cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::SHIFT; 1403cdf0e10cSrcweir else if (sToken[k].equalsAscii("MOD1")) 1404cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD1; 1405cdf0e10cSrcweir else if (sToken[k].equalsAscii("MOD2")) 1406cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD2; 1407cdf0e10cSrcweir else if (sToken[k].equalsAscii("MOD3")) 1408cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD3; 1409cdf0e10cSrcweir else 1410cdf0e10cSrcweir { 1411cdf0e10cSrcweir bValid = sal_False; 1412cdf0e10cSrcweir break; 1413cdf0e10cSrcweir } 1414cdf0e10cSrcweir } 1415cdf0e10cSrcweir 1416cdf0e10cSrcweir if ( !aReadCache.hasKey(aKeyEvent) && bValid && k<nToken) 1417cdf0e10cSrcweir aReadCache.setKeyCommandPair(aKeyEvent, sCommand); 1418cdf0e10cSrcweir } 1419cdf0e10cSrcweir } 1420cdf0e10cSrcweir 1421cdf0e10cSrcweir if (bPreferred) 1422cdf0e10cSrcweir m_aPrimaryReadCache.takeOver(aReadCache); 1423cdf0e10cSrcweir else 1424cdf0e10cSrcweir m_aSecondaryReadCache.takeOver(aReadCache); 1425cdf0e10cSrcweir } 1426cdf0e10cSrcweir 1427cdf0e10cSrcweir //----------------------------------------------- 1428cdf0e10cSrcweir void XCUBasedAcceleratorConfiguration::impl_ts_save(sal_Bool bPreferred, const css::uno::Reference< css::container::XNameAccess >& /*xCfg*/) 1429cdf0e10cSrcweir { 1430cdf0e10cSrcweir if (bPreferred) 1431cdf0e10cSrcweir { 1432cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pIt; 1433cdf0e10cSrcweir AcceleratorCache::TKeyList lPrimaryReadKeys = m_aPrimaryReadCache.getAllKeys(); 1434cdf0e10cSrcweir AcceleratorCache::TKeyList lPrimaryWriteKeys = m_pPrimaryWriteCache->getAllKeys(); 1435cdf0e10cSrcweir 1436cdf0e10cSrcweir for ( pIt = lPrimaryReadKeys.begin(); pIt != lPrimaryReadKeys.end(); ++pIt ) 1437cdf0e10cSrcweir { 1438cdf0e10cSrcweir if (!m_pPrimaryWriteCache->hasKey(*pIt)) 1439cdf0e10cSrcweir removeKeyFromConfiguration(*pIt, sal_True); 1440cdf0e10cSrcweir } 1441cdf0e10cSrcweir 1442cdf0e10cSrcweir for ( pIt = lPrimaryWriteKeys.begin(); pIt != lPrimaryWriteKeys.end(); ++pIt ) 1443cdf0e10cSrcweir { 1444cdf0e10cSrcweir ::rtl::OUString sCommand = m_pPrimaryWriteCache->getCommandByKey(*pIt); 1445cdf0e10cSrcweir if (!m_aPrimaryReadCache.hasKey(*pIt)) 1446cdf0e10cSrcweir { 1447cdf0e10cSrcweir insertKeyToConfiguration(*pIt, sCommand, sal_True); 1448cdf0e10cSrcweir } 1449cdf0e10cSrcweir else 1450cdf0e10cSrcweir { 1451cdf0e10cSrcweir ::rtl::OUString sReadCommand = m_aPrimaryReadCache.getCommandByKey(*pIt); 1452cdf0e10cSrcweir if (sReadCommand != sCommand) 1453cdf0e10cSrcweir insertKeyToConfiguration(*pIt, sCommand, sal_True); 1454cdf0e10cSrcweir } 1455cdf0e10cSrcweir } 1456cdf0e10cSrcweir 1457cdf0e10cSrcweir // take over all changes into the original container 1458cdf0e10cSrcweir // SAFE -> ---------------------------------- 1459cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1460cdf0e10cSrcweir 1461cdf0e10cSrcweir if (m_pPrimaryWriteCache) 1462cdf0e10cSrcweir { 1463cdf0e10cSrcweir m_aPrimaryReadCache.takeOver(*m_pPrimaryWriteCache); 1464cdf0e10cSrcweir AcceleratorCache* pTemp = m_pPrimaryWriteCache; 1465cdf0e10cSrcweir m_pPrimaryWriteCache = 0; 1466cdf0e10cSrcweir delete pTemp; 1467cdf0e10cSrcweir } 1468cdf0e10cSrcweir 1469cdf0e10cSrcweir aWriteLock.unlock(); 1470cdf0e10cSrcweir // <- SAFE ---------------------------------- 1471cdf0e10cSrcweir } 1472cdf0e10cSrcweir 1473cdf0e10cSrcweir else 1474cdf0e10cSrcweir { 1475cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pIt; 1476cdf0e10cSrcweir AcceleratorCache::TKeyList lSecondaryReadKeys = m_aSecondaryReadCache.getAllKeys(); 1477cdf0e10cSrcweir AcceleratorCache::TKeyList lSecondaryWriteKeys = m_pSecondaryWriteCache->getAllKeys(); 1478cdf0e10cSrcweir 1479cdf0e10cSrcweir for ( pIt = lSecondaryReadKeys.begin(); pIt != lSecondaryReadKeys.end(); ++pIt) 1480cdf0e10cSrcweir { 1481cdf0e10cSrcweir if (!m_pSecondaryWriteCache->hasKey(*pIt)) 1482cdf0e10cSrcweir removeKeyFromConfiguration(*pIt, sal_False); 1483cdf0e10cSrcweir } 1484cdf0e10cSrcweir 1485cdf0e10cSrcweir 1486cdf0e10cSrcweir for ( pIt = lSecondaryWriteKeys.begin(); pIt != lSecondaryWriteKeys.end(); ++pIt ) 1487cdf0e10cSrcweir { 1488cdf0e10cSrcweir ::rtl::OUString sCommand = m_pSecondaryWriteCache->getCommandByKey(*pIt); 1489cdf0e10cSrcweir if (!m_aSecondaryReadCache.hasKey(*pIt)) 1490cdf0e10cSrcweir { 1491cdf0e10cSrcweir insertKeyToConfiguration(*pIt, sCommand, sal_False); 1492cdf0e10cSrcweir } 1493cdf0e10cSrcweir else 1494cdf0e10cSrcweir { 1495cdf0e10cSrcweir ::rtl::OUString sReadCommand = m_aSecondaryReadCache.getCommandByKey(*pIt); 1496cdf0e10cSrcweir if (sReadCommand != sCommand) 1497cdf0e10cSrcweir insertKeyToConfiguration(*pIt, sCommand, sal_False); 1498cdf0e10cSrcweir } 1499cdf0e10cSrcweir } 1500cdf0e10cSrcweir 1501cdf0e10cSrcweir // take over all changes into the original container 1502cdf0e10cSrcweir // SAFE -> ---------------------------------- 1503cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1504cdf0e10cSrcweir 1505cdf0e10cSrcweir if (m_pSecondaryWriteCache) 1506cdf0e10cSrcweir { 1507cdf0e10cSrcweir m_aSecondaryReadCache.takeOver(*m_pSecondaryWriteCache); 1508cdf0e10cSrcweir AcceleratorCache* pTemp = m_pSecondaryWriteCache; 1509cdf0e10cSrcweir m_pSecondaryWriteCache = 0; 1510cdf0e10cSrcweir delete pTemp; 1511cdf0e10cSrcweir } 1512cdf0e10cSrcweir 1513cdf0e10cSrcweir aWriteLock.unlock(); 1514cdf0e10cSrcweir // <- SAFE ---------------------------------- 1515cdf0e10cSrcweir } 1516cdf0e10cSrcweir 1517cdf0e10cSrcweir ::comphelper::ConfigurationHelper::flush(m_xCfg); 1518cdf0e10cSrcweir } 1519cdf0e10cSrcweir 1520cdf0e10cSrcweir //----------------------------------------------- 1521cdf0e10cSrcweir void XCUBasedAcceleratorConfiguration::insertKeyToConfiguration( const css::awt::KeyEvent& aKeyEvent, const ::rtl::OUString& sCommand, const sal_Bool bPreferred ) 1522cdf0e10cSrcweir { 1523cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess; 1524cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xContainer; 1525cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleServiceFactory > xFac; 1526cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xInst; 1527cdf0e10cSrcweir 1528cdf0e10cSrcweir if ( bPreferred ) 1529cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_PRIMARY) >>= xAccess; 1530cdf0e10cSrcweir else 1531cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_SECONDARY) >>= xAccess; 1532cdf0e10cSrcweir 1533cdf0e10cSrcweir if ( m_sGlobalOrModules.equals(CFG_ENTRY_GLOBAL) ) 1534cdf0e10cSrcweir xAccess->getByName(CFG_ENTRY_GLOBAL) >>= xContainer; 1535cdf0e10cSrcweir else if ( m_sGlobalOrModules.equals(CFG_ENTRY_MODULES) ) 1536cdf0e10cSrcweir { 1537cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xModules; 1538cdf0e10cSrcweir xAccess->getByName(CFG_ENTRY_MODULES) >>= xModules; 1539cdf0e10cSrcweir if ( !xModules->hasByName(m_sModuleCFG) ) 1540cdf0e10cSrcweir { 1541cdf0e10cSrcweir xFac = css::uno::Reference< css::lang::XSingleServiceFactory >(xModules, css::uno::UNO_QUERY); 1542cdf0e10cSrcweir xInst = xFac->createInstance(); 1543cdf0e10cSrcweir xModules->insertByName(m_sModuleCFG, css::uno::makeAny(xInst)); 1544cdf0e10cSrcweir } 1545cdf0e10cSrcweir xModules->getByName(m_sModuleCFG) >>= xContainer; 1546cdf0e10cSrcweir } 1547cdf0e10cSrcweir 1548cdf0e10cSrcweir const ::rtl::OUString sKey = lcl_getKeyString(m_rKeyMapping,aKeyEvent); 1549cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xKey; 1550cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xCommand; 1551cdf0e10cSrcweir if ( !xContainer->hasByName(sKey) ) 1552cdf0e10cSrcweir { 1553cdf0e10cSrcweir xFac = css::uno::Reference< css::lang::XSingleServiceFactory >(xContainer, css::uno::UNO_QUERY); 1554cdf0e10cSrcweir xInst = xFac->createInstance(); 1555cdf0e10cSrcweir xContainer->insertByName(sKey, css::uno::makeAny(xInst)); 1556cdf0e10cSrcweir } 1557cdf0e10cSrcweir xContainer->getByName(sKey) >>= xKey; 1558cdf0e10cSrcweir 1559cdf0e10cSrcweir xKey->getByName(CFG_PROP_COMMAND) >>= xCommand; 1560cdf0e10cSrcweir ::rtl::OUString sLocale = impl_ts_getLocale().toISO(); 1561cdf0e10cSrcweir if ( !xCommand->hasByName(sLocale) ) 1562cdf0e10cSrcweir xCommand->insertByName(sLocale, css::uno::makeAny(sCommand)); 1563cdf0e10cSrcweir else 1564cdf0e10cSrcweir xCommand->replaceByName(sLocale, css::uno::makeAny(sCommand)); 1565cdf0e10cSrcweir } 1566cdf0e10cSrcweir 1567cdf0e10cSrcweir //----------------------------------------------- 1568cdf0e10cSrcweir void XCUBasedAcceleratorConfiguration::removeKeyFromConfiguration( const css::awt::KeyEvent& aKeyEvent, const sal_Bool bPreferred ) 1569cdf0e10cSrcweir { 1570cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess; 1571cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xContainer; 1572cdf0e10cSrcweir 1573cdf0e10cSrcweir if ( bPreferred ) 1574cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_PRIMARY) >>= xAccess; 1575cdf0e10cSrcweir else 1576cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_SECONDARY) >>= xAccess; 1577cdf0e10cSrcweir 1578cdf0e10cSrcweir if ( m_sGlobalOrModules.equals(CFG_ENTRY_GLOBAL) ) 1579cdf0e10cSrcweir xAccess->getByName(CFG_ENTRY_GLOBAL) >>= xContainer; 1580cdf0e10cSrcweir else if ( m_sGlobalOrModules.equals(CFG_ENTRY_MODULES) ) 1581cdf0e10cSrcweir { 1582cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xModules; 1583cdf0e10cSrcweir xAccess->getByName(CFG_ENTRY_MODULES) >>= xModules; 1584cdf0e10cSrcweir if ( !xModules->hasByName(m_sModuleCFG) ) 1585cdf0e10cSrcweir return; 1586cdf0e10cSrcweir xModules->getByName(m_sModuleCFG) >>= xContainer; 1587cdf0e10cSrcweir } 1588cdf0e10cSrcweir 1589cdf0e10cSrcweir const ::rtl::OUString sKey = lcl_getKeyString(m_rKeyMapping,aKeyEvent); 1590cdf0e10cSrcweir xContainer->removeByName(sKey); 1591cdf0e10cSrcweir } 1592cdf0e10cSrcweir 1593cdf0e10cSrcweir //----------------------------------------------- 1594cdf0e10cSrcweir void XCUBasedAcceleratorConfiguration::reloadChanged( const ::rtl::OUString& sPrimarySecondary, const ::rtl::OUString& sGlobalModules, const ::rtl::OUString& sModule, const ::rtl::OUString& sKey ) 1595cdf0e10cSrcweir { 1596cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess; 1597cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xContainer; 1598cdf0e10cSrcweir 1599cdf0e10cSrcweir m_xCfg->getByName(sPrimarySecondary) >>= xAccess; 1600cdf0e10cSrcweir if ( sGlobalModules.equals(CFG_ENTRY_GLOBAL) ) 1601cdf0e10cSrcweir xAccess->getByName(CFG_ENTRY_GLOBAL) >>= xContainer; 1602cdf0e10cSrcweir else 1603cdf0e10cSrcweir { 1604cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xModules; 1605cdf0e10cSrcweir xAccess->getByName(CFG_ENTRY_MODULES) >>= xModules; 1606cdf0e10cSrcweir if ( !xModules->hasByName(sModule) ) 1607cdf0e10cSrcweir return; 1608cdf0e10cSrcweir xModules->getByName(sModule) >>= xContainer; 1609cdf0e10cSrcweir } 1610cdf0e10cSrcweir 1611cdf0e10cSrcweir css::awt::KeyEvent aKeyEvent; 1612cdf0e10cSrcweir ::rtl::OUString sKeyIdentifier; 1613cdf0e10cSrcweir 1614cdf0e10cSrcweir sal_Int32 nIndex = 0; 1615cdf0e10cSrcweir sKeyIdentifier = sKey.getToken(0, '_', nIndex); 1616cdf0e10cSrcweir aKeyEvent.KeyCode = m_rKeyMapping->mapIdentifierToCode(::rtl::OUString::createFromAscii("KEY_")+sKeyIdentifier); 1617cdf0e10cSrcweir 1618cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > sToken(3); 1619cdf0e10cSrcweir const sal_Int32 nToken = 3; 1620cdf0e10cSrcweir for (sal_Int32 i=0; i<nToken; ++i) 1621cdf0e10cSrcweir { 1622cdf0e10cSrcweir if ( nIndex < 0 ) 1623cdf0e10cSrcweir break; 1624cdf0e10cSrcweir 1625cdf0e10cSrcweir sToken[i] = sKey.getToken(0, '_', nIndex); 1626cdf0e10cSrcweir if (sToken[i].equalsAscii("SHIFT")) 1627cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::SHIFT; 1628cdf0e10cSrcweir else if (sToken[i].equalsAscii("MOD1")) 1629cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD1; 1630cdf0e10cSrcweir else if (sToken[i].equalsAscii("MOD2")) 1631cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD2; 1632cdf0e10cSrcweir else if (sToken[i].equalsAscii("MOD3")) 1633cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD3; 1634cdf0e10cSrcweir } 1635cdf0e10cSrcweir 1636cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xKey; 1637cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xCommand; 1638cdf0e10cSrcweir ::rtl::OUString sCommand; 1639cdf0e10cSrcweir 1640cdf0e10cSrcweir if (xContainer->hasByName(sKey)) 1641cdf0e10cSrcweir { 1642cdf0e10cSrcweir ::rtl::OUString sLocale = impl_ts_getLocale().toISO(); 1643cdf0e10cSrcweir xContainer->getByName(sKey) >>= xKey; 1644cdf0e10cSrcweir xKey->getByName(CFG_PROP_COMMAND) >>= xCommand; 1645cdf0e10cSrcweir xCommand->getByName(sLocale) >>= sCommand; 1646cdf0e10cSrcweir } 1647cdf0e10cSrcweir 1648cdf0e10cSrcweir if (sPrimarySecondary.equals(CFG_ENTRY_PRIMARY)) 1649cdf0e10cSrcweir { 1650cdf0e10cSrcweir if (sCommand.getLength() ==0) 1651cdf0e10cSrcweir m_aPrimaryReadCache.removeKey(aKeyEvent); 1652cdf0e10cSrcweir else 1653cdf0e10cSrcweir m_aPrimaryReadCache.setKeyCommandPair(aKeyEvent, sCommand); 1654cdf0e10cSrcweir } 1655cdf0e10cSrcweir else if (sPrimarySecondary.equals(CFG_ENTRY_SECONDARY)) 1656cdf0e10cSrcweir { 1657cdf0e10cSrcweir if (sCommand.getLength() ==0) 1658cdf0e10cSrcweir m_aSecondaryReadCache.removeKey(aKeyEvent); 1659cdf0e10cSrcweir else 1660cdf0e10cSrcweir m_aSecondaryReadCache.setKeyCommandPair(aKeyEvent, sCommand); 1661cdf0e10cSrcweir } 1662cdf0e10cSrcweir } 1663cdf0e10cSrcweir 1664cdf0e10cSrcweir //----------------------------------------------- 1665cdf0e10cSrcweir AcceleratorCache& XCUBasedAcceleratorConfiguration::impl_getCFG(sal_Bool bPreferred, sal_Bool bWriteAccessRequested) 1666cdf0e10cSrcweir { 1667cdf0e10cSrcweir // SAFE -> ---------------------------------- 1668cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1669cdf0e10cSrcweir 1670cdf0e10cSrcweir if (bPreferred) 1671cdf0e10cSrcweir { 1672cdf0e10cSrcweir //create copy of our readonly-cache, if write access is forced ... but 1673cdf0e10cSrcweir //not still possible! 1674cdf0e10cSrcweir if ( 1675cdf0e10cSrcweir (bWriteAccessRequested) && 1676cdf0e10cSrcweir (!m_pPrimaryWriteCache ) 1677cdf0e10cSrcweir ) 1678cdf0e10cSrcweir { 1679cdf0e10cSrcweir m_pPrimaryWriteCache = new AcceleratorCache(m_aPrimaryReadCache); 1680cdf0e10cSrcweir } 1681cdf0e10cSrcweir 1682cdf0e10cSrcweir // in case, we have a writeable cache, we use it for reading too! 1683cdf0e10cSrcweir // Otherwhise the API user cant find its own changes ... 1684cdf0e10cSrcweir if (m_pPrimaryWriteCache) 1685cdf0e10cSrcweir return *m_pPrimaryWriteCache; 1686cdf0e10cSrcweir else 1687cdf0e10cSrcweir return m_aPrimaryReadCache; 1688cdf0e10cSrcweir } 1689cdf0e10cSrcweir 1690cdf0e10cSrcweir else 1691cdf0e10cSrcweir { 1692cdf0e10cSrcweir //create copy of our readonly-cache, if write access is forced ... but 1693cdf0e10cSrcweir //not still possible! 1694cdf0e10cSrcweir if ( 1695cdf0e10cSrcweir (bWriteAccessRequested) && 1696cdf0e10cSrcweir (!m_pSecondaryWriteCache ) 1697cdf0e10cSrcweir ) 1698cdf0e10cSrcweir { 1699cdf0e10cSrcweir m_pSecondaryWriteCache = new AcceleratorCache(m_aSecondaryReadCache); 1700cdf0e10cSrcweir } 1701cdf0e10cSrcweir 1702cdf0e10cSrcweir // in case, we have a writeable cache, we use it for reading too! 1703cdf0e10cSrcweir // Otherwhise the API user cant find its own changes ... 1704cdf0e10cSrcweir if (m_pSecondaryWriteCache) 1705cdf0e10cSrcweir return *m_pSecondaryWriteCache; 1706cdf0e10cSrcweir else 1707cdf0e10cSrcweir return m_aSecondaryReadCache; 1708cdf0e10cSrcweir } 1709cdf0e10cSrcweir 1710cdf0e10cSrcweir // <- SAFE ---------------------------------- 1711cdf0e10cSrcweir } 1712cdf0e10cSrcweir 1713cdf0e10cSrcweir //----------------------------------------------- 1714cdf0e10cSrcweir ::comphelper::Locale XCUBasedAcceleratorConfiguration::impl_ts_getLocale() const 1715cdf0e10cSrcweir { 1716cdf0e10cSrcweir static ::rtl::OUString LOCALE_PACKAGE = ::rtl::OUString::createFromAscii("/org.openoffice.Setup"); 1717cdf0e10cSrcweir static ::rtl::OUString LOCALE_PATH = ::rtl::OUString::createFromAscii("L10N" ); 1718cdf0e10cSrcweir static ::rtl::OUString LOCALE_KEY = ::rtl::OUString::createFromAscii("ooLocale" ); 1719cdf0e10cSrcweir 1720cdf0e10cSrcweir // SAFE -> ---------------------------------- 1721cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 1722cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 1723cdf0e10cSrcweir aReadLock.unlock(); 1724cdf0e10cSrcweir // <- SAFE ---------------------------------- 1725cdf0e10cSrcweir 1726cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xCFG = fpc::ConfigurationHelper::openConfig(xSMGR, LOCALE_PACKAGE, LOCALE_PATH, fpc::ConfigurationHelper::E_READONLY); 1727cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xProp (xCFG, css::uno::UNO_QUERY_THROW); 1728cdf0e10cSrcweir ::rtl::OUString sISOLocale; 1729cdf0e10cSrcweir xProp->getPropertyValue(LOCALE_KEY) >>= sISOLocale; 1730cdf0e10cSrcweir 1731cdf0e10cSrcweir if (!sISOLocale.getLength()) 1732cdf0e10cSrcweir return ::comphelper::Locale::EN_US(); 1733cdf0e10cSrcweir return ::comphelper::Locale(sISOLocale); 1734cdf0e10cSrcweir } 1735cdf0e10cSrcweir 1736cdf0e10cSrcweir } // namespace framework 1737