1*6d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6d739b60SAndrew Rist * distributed with this work for additional information 6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance 9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6d739b60SAndrew Rist * software distributed under the License is distributed on an 15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the 17*6d739b60SAndrew Rist * specific language governing permissions and limitations 18*6d739b60SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*6d739b60SAndrew Rist *************************************************************/ 21*6d739b60SAndrew Rist 22*6d739b60SAndrew 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 679cdf0e10cSrcweir DEFINE_XINTERFACE_7(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 ), 685cdf0e10cSrcweir DIRECT_INTERFACE(css::ui::XUIConfigurationPersistence), 686cdf0e10cSrcweir DIRECT_INTERFACE(css::ui::XUIConfigurationStorage ), 687cdf0e10cSrcweir DIRECT_INTERFACE(css::ui::XUIConfiguration )) 688cdf0e10cSrcweir 689cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_7(XCUBasedAcceleratorConfiguration , 690cdf0e10cSrcweir css::lang::XTypeProvider , 691cdf0e10cSrcweir css::ui::XAcceleratorConfiguration , 692cdf0e10cSrcweir css::util::XChangesListener , 693cdf0e10cSrcweir css::form::XReset , 694cdf0e10cSrcweir css::ui::XUIConfigurationPersistence, 695cdf0e10cSrcweir css::ui::XUIConfigurationStorage , 696cdf0e10cSrcweir css::ui::XUIConfiguration ) 697cdf0e10cSrcweir 698cdf0e10cSrcweir //----------------------------------------------- 699cdf0e10cSrcweir XCUBasedAcceleratorConfiguration::XCUBasedAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR) 700cdf0e10cSrcweir : ThreadHelpBase (&Application::GetSolarMutex()) 701cdf0e10cSrcweir , m_xSMGR (xSMGR ) 702cdf0e10cSrcweir , m_pPrimaryWriteCache(0 ) 703cdf0e10cSrcweir , m_pSecondaryWriteCache(0 ) 704cdf0e10cSrcweir { 705cdf0e10cSrcweir static const ::rtl::OUString CFG_ENTRY_ACCELERATORS(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Accelerators")); 706cdf0e10cSrcweir m_xCfg = css::uno::Reference< css::container::XNameAccess > ( 707cdf0e10cSrcweir ::comphelper::ConfigurationHelper::openConfig( m_xSMGR, CFG_ENTRY_ACCELERATORS, ::comphelper::ConfigurationHelper::E_ALL_LOCALES ), 708cdf0e10cSrcweir css::uno::UNO_QUERY ); 709cdf0e10cSrcweir } 710cdf0e10cSrcweir 711cdf0e10cSrcweir //----------------------------------------------- 712cdf0e10cSrcweir XCUBasedAcceleratorConfiguration::~XCUBasedAcceleratorConfiguration() 713cdf0e10cSrcweir { 714cdf0e10cSrcweir } 715cdf0e10cSrcweir 716cdf0e10cSrcweir //----------------------------------------------- 717cdf0e10cSrcweir css::uno::Sequence< css::awt::KeyEvent > SAL_CALL XCUBasedAcceleratorConfiguration::getAllKeyEvents() 718cdf0e10cSrcweir throw(css::uno::RuntimeException) 719cdf0e10cSrcweir { 720cdf0e10cSrcweir // SAFE -> ---------------------------------- 721cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 722cdf0e10cSrcweir 723cdf0e10cSrcweir AcceleratorCache::TKeyList lKeys = impl_getCFG(sal_True).getAllKeys(); //get keys from PrimaryKeys set 724cdf0e10cSrcweir 725cdf0e10cSrcweir AcceleratorCache::TKeyList lSecondaryKeys = impl_getCFG(sal_False).getAllKeys(); //get keys from SecondaryKeys set 726cdf0e10cSrcweir lKeys.reserve(lKeys.size()+lSecondaryKeys.size()); 727cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pIt; 728cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pEnd = lSecondaryKeys.end(); 729cdf0e10cSrcweir for ( pIt = lSecondaryKeys.begin(); pIt != pEnd; ++pIt ) 730cdf0e10cSrcweir lKeys.push_back(*pIt); 731cdf0e10cSrcweir 732cdf0e10cSrcweir return lKeys.getAsConstList(); 733cdf0e10cSrcweir 734cdf0e10cSrcweir // <- SAFE ---------------------------------- 735cdf0e10cSrcweir } 736cdf0e10cSrcweir 737cdf0e10cSrcweir //----------------------------------------------- 738cdf0e10cSrcweir ::rtl::OUString SAL_CALL XCUBasedAcceleratorConfiguration::getCommandByKeyEvent(const css::awt::KeyEvent& aKeyEvent) 739cdf0e10cSrcweir throw(css::container::NoSuchElementException, 740cdf0e10cSrcweir css::uno::RuntimeException ) 741cdf0e10cSrcweir { 742cdf0e10cSrcweir // SAFE -> ---------------------------------- 743cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 744cdf0e10cSrcweir 745cdf0e10cSrcweir AcceleratorCache& rPrimaryCache = impl_getCFG(sal_True ); 746cdf0e10cSrcweir AcceleratorCache& rSecondaryCache = impl_getCFG(sal_False); 747cdf0e10cSrcweir 748cdf0e10cSrcweir if (!rPrimaryCache.hasKey(aKeyEvent) && !rSecondaryCache.hasKey(aKeyEvent)) 749cdf0e10cSrcweir throw css::container::NoSuchElementException( 750cdf0e10cSrcweir ::rtl::OUString(), 751cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 752cdf0e10cSrcweir 753cdf0e10cSrcweir if (rPrimaryCache.hasKey(aKeyEvent)) 754cdf0e10cSrcweir return rPrimaryCache.getCommandByKey(aKeyEvent); 755cdf0e10cSrcweir else 756cdf0e10cSrcweir return rSecondaryCache.getCommandByKey(aKeyEvent); 757cdf0e10cSrcweir 758cdf0e10cSrcweir // <- SAFE ---------------------------------- 759cdf0e10cSrcweir } 760cdf0e10cSrcweir 761cdf0e10cSrcweir //----------------------------------------------- 762cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::setKeyEvent(const css::awt::KeyEvent& aKeyEvent, 763cdf0e10cSrcweir const ::rtl::OUString& sCommand ) 764cdf0e10cSrcweir throw(css::lang::IllegalArgumentException, 765cdf0e10cSrcweir css::uno::RuntimeException ) 766cdf0e10cSrcweir { 767cdf0e10cSrcweir RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::setKeyEvent" ); 768cdf0e10cSrcweir 769cdf0e10cSrcweir if ( 770cdf0e10cSrcweir (aKeyEvent.KeyCode == 0) && 771cdf0e10cSrcweir (aKeyEvent.KeyChar == 0) && 772cdf0e10cSrcweir (aKeyEvent.KeyFunc == 0) && 773cdf0e10cSrcweir (aKeyEvent.Modifiers == 0) 774cdf0e10cSrcweir ) 775cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 776cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Such key event seams not to be supported by any operating system."), 777cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 778cdf0e10cSrcweir 0); 779cdf0e10cSrcweir 780cdf0e10cSrcweir if (!sCommand.getLength()) 781cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 782cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Empty command strings are not allowed here."), 783cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 784cdf0e10cSrcweir 1); 785cdf0e10cSrcweir 786cdf0e10cSrcweir // SAFE -> ---------------------------------- 787cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 788cdf0e10cSrcweir 789cdf0e10cSrcweir AcceleratorCache& rPrimaryCache = impl_getCFG(sal_True, sal_True ); // sal_True => force getting of a writeable cache! 790cdf0e10cSrcweir AcceleratorCache& rSecondaryCache = impl_getCFG(sal_False, sal_True); // sal_True => force getting of a writeable cache! 791cdf0e10cSrcweir 792cdf0e10cSrcweir if ( rPrimaryCache.hasKey(aKeyEvent) ) 793cdf0e10cSrcweir { 794cdf0e10cSrcweir ::rtl::OUString sOriginalCommand = rPrimaryCache.getCommandByKey(aKeyEvent); 795cdf0e10cSrcweir if ( sCommand != sOriginalCommand ) 796cdf0e10cSrcweir { 797cdf0e10cSrcweir if (rSecondaryCache.hasCommand(sOriginalCommand)) 798cdf0e10cSrcweir { 799cdf0e10cSrcweir AcceleratorCache::TKeyList lSecondaryKeys = rSecondaryCache.getKeysByCommand(sOriginalCommand); 800cdf0e10cSrcweir rSecondaryCache.removeKey(lSecondaryKeys[0]); 801cdf0e10cSrcweir rPrimaryCache.setKeyCommandPair(lSecondaryKeys[0], sOriginalCommand); 802cdf0e10cSrcweir } 803cdf0e10cSrcweir 804cdf0e10cSrcweir if (rPrimaryCache.hasCommand(sCommand)) 805cdf0e10cSrcweir { 806cdf0e10cSrcweir AcceleratorCache::TKeyList lPrimaryKeys = rPrimaryCache.getKeysByCommand(sCommand); 807cdf0e10cSrcweir rPrimaryCache.removeKey(lPrimaryKeys[0]); 808cdf0e10cSrcweir rSecondaryCache.setKeyCommandPair(lPrimaryKeys[0], sCommand); 809cdf0e10cSrcweir } 810cdf0e10cSrcweir 811cdf0e10cSrcweir rPrimaryCache.setKeyCommandPair(aKeyEvent, sCommand); 812cdf0e10cSrcweir } 813cdf0e10cSrcweir } 814cdf0e10cSrcweir 815cdf0e10cSrcweir else if ( rSecondaryCache.hasKey(aKeyEvent) ) 816cdf0e10cSrcweir { 817cdf0e10cSrcweir ::rtl::OUString sOriginalCommand = rSecondaryCache.getCommandByKey(aKeyEvent); 818cdf0e10cSrcweir if (sCommand != sOriginalCommand) 819cdf0e10cSrcweir { 820cdf0e10cSrcweir if (rPrimaryCache.hasCommand(sCommand)) 821cdf0e10cSrcweir { 822cdf0e10cSrcweir AcceleratorCache::TKeyList lPrimaryKeys = rPrimaryCache.getKeysByCommand(sCommand); 823cdf0e10cSrcweir rPrimaryCache.removeKey(lPrimaryKeys[0]); 824cdf0e10cSrcweir rSecondaryCache.setKeyCommandPair(lPrimaryKeys[0], sCommand); 825cdf0e10cSrcweir } 826cdf0e10cSrcweir 827cdf0e10cSrcweir rSecondaryCache.removeKey(aKeyEvent); 828cdf0e10cSrcweir rPrimaryCache.setKeyCommandPair(aKeyEvent, sCommand); 829cdf0e10cSrcweir } 830cdf0e10cSrcweir } 831cdf0e10cSrcweir 832cdf0e10cSrcweir else 833cdf0e10cSrcweir { 834cdf0e10cSrcweir if (rPrimaryCache.hasCommand(sCommand)) 835cdf0e10cSrcweir { 836cdf0e10cSrcweir AcceleratorCache::TKeyList lPrimaryKeys = rPrimaryCache.getKeysByCommand(sCommand); 837cdf0e10cSrcweir rPrimaryCache.removeKey(lPrimaryKeys[0]); 838cdf0e10cSrcweir rSecondaryCache.setKeyCommandPair(lPrimaryKeys[0], sCommand); 839cdf0e10cSrcweir } 840cdf0e10cSrcweir 841cdf0e10cSrcweir rPrimaryCache.setKeyCommandPair(aKeyEvent, sCommand); 842cdf0e10cSrcweir } 843cdf0e10cSrcweir 844cdf0e10cSrcweir aWriteLock.unlock(); 845cdf0e10cSrcweir // <- SAFE ---------------------------------- 846cdf0e10cSrcweir } 847cdf0e10cSrcweir 848cdf0e10cSrcweir //----------------------------------------------- 849cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::removeKeyEvent(const css::awt::KeyEvent& aKeyEvent) 850cdf0e10cSrcweir throw(css::container::NoSuchElementException, 851cdf0e10cSrcweir css::uno::RuntimeException ) 852cdf0e10cSrcweir { 853cdf0e10cSrcweir // SAFE -> ---------------------------------- 854cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 855cdf0e10cSrcweir 856cdf0e10cSrcweir AcceleratorCache& rPrimaryCache = impl_getCFG(sal_True, sal_True ); 857cdf0e10cSrcweir AcceleratorCache& rSecondaryCache = impl_getCFG(sal_False, sal_True); 858cdf0e10cSrcweir 859cdf0e10cSrcweir if (!rPrimaryCache.hasKey(aKeyEvent) && !rSecondaryCache.hasKey(aKeyEvent)) 860cdf0e10cSrcweir throw css::container::NoSuchElementException( 861cdf0e10cSrcweir ::rtl::OUString(), 862cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 863cdf0e10cSrcweir 864cdf0e10cSrcweir if (rPrimaryCache.hasKey(aKeyEvent)) 865cdf0e10cSrcweir { 866cdf0e10cSrcweir ::rtl::OUString sDelCommand = rPrimaryCache.getCommandByKey(aKeyEvent); 867cdf0e10cSrcweir if (sDelCommand.getLength() > 0) 868cdf0e10cSrcweir { 869cdf0e10cSrcweir ::rtl::OUString sOriginalCommand = rPrimaryCache.getCommandByKey(aKeyEvent); 870cdf0e10cSrcweir if (rSecondaryCache.hasCommand(sOriginalCommand)) 871cdf0e10cSrcweir { 872cdf0e10cSrcweir AcceleratorCache::TKeyList lSecondaryKeys = rSecondaryCache.getKeysByCommand(sOriginalCommand); 873cdf0e10cSrcweir rSecondaryCache.removeKey(lSecondaryKeys[0]); 874cdf0e10cSrcweir rPrimaryCache.setKeyCommandPair(lSecondaryKeys[0], sOriginalCommand); 875cdf0e10cSrcweir } 876cdf0e10cSrcweir 877cdf0e10cSrcweir rPrimaryCache.removeKey(aKeyEvent); 878cdf0e10cSrcweir } 879cdf0e10cSrcweir 880cdf0e10cSrcweir } 881cdf0e10cSrcweir else 882cdf0e10cSrcweir { 883cdf0e10cSrcweir ::rtl::OUString sDelCommand = rSecondaryCache.getCommandByKey(aKeyEvent); 884cdf0e10cSrcweir if (sDelCommand.getLength() > 0) 885cdf0e10cSrcweir rSecondaryCache.removeKey(aKeyEvent); 886cdf0e10cSrcweir } 887cdf0e10cSrcweir 888cdf0e10cSrcweir // <- SAFE ---------------------------------- 889cdf0e10cSrcweir } 890cdf0e10cSrcweir 891cdf0e10cSrcweir //----------------------------------------------- 892cdf0e10cSrcweir css::uno::Sequence< css::awt::KeyEvent > SAL_CALL XCUBasedAcceleratorConfiguration::getKeyEventsByCommand(const ::rtl::OUString& sCommand) 893cdf0e10cSrcweir throw(css::lang::IllegalArgumentException , 894cdf0e10cSrcweir css::container::NoSuchElementException, 895cdf0e10cSrcweir css::uno::RuntimeException ) 896cdf0e10cSrcweir { 897cdf0e10cSrcweir if (!sCommand.getLength()) 898cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 899cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Empty command strings are not allowed here."), 900cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 901cdf0e10cSrcweir 1); 902cdf0e10cSrcweir 903cdf0e10cSrcweir // SAFE -> ---------------------------------- 904cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 905cdf0e10cSrcweir 906cdf0e10cSrcweir AcceleratorCache& rPrimaryCache = impl_getCFG(sal_True ); 907cdf0e10cSrcweir AcceleratorCache& rSecondaryCache = impl_getCFG(sal_False); 908cdf0e10cSrcweir 909cdf0e10cSrcweir if (!rPrimaryCache.hasCommand(sCommand) && !rSecondaryCache.hasCommand(sCommand)) 910cdf0e10cSrcweir throw css::container::NoSuchElementException( 911cdf0e10cSrcweir ::rtl::OUString(), 912cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 913cdf0e10cSrcweir 914cdf0e10cSrcweir AcceleratorCache::TKeyList lKeys = rPrimaryCache.getKeysByCommand(sCommand); 915cdf0e10cSrcweir 916cdf0e10cSrcweir AcceleratorCache::TKeyList lSecondaryKeys = rSecondaryCache.getKeysByCommand(sCommand); 917cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pIt; 918cdf0e10cSrcweir for (pIt = lSecondaryKeys.begin(); pIt != lSecondaryKeys.end(); ++pIt) 919cdf0e10cSrcweir lKeys.push_back(*pIt); 920cdf0e10cSrcweir 921cdf0e10cSrcweir return lKeys.getAsConstList(); 922cdf0e10cSrcweir 923cdf0e10cSrcweir // <- SAFE ---------------------------------- 924cdf0e10cSrcweir } 925cdf0e10cSrcweir 926cdf0e10cSrcweir //----------------------------------------------- 927cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator lcl_getPreferredKey(const AcceleratorCache::TKeyList& lKeys) 928cdf0e10cSrcweir { 929cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pIt; 930cdf0e10cSrcweir for ( pIt = lKeys.begin (); 931cdf0e10cSrcweir pIt != lKeys.end (); 932cdf0e10cSrcweir ++pIt ) 933cdf0e10cSrcweir { 934cdf0e10cSrcweir const css::awt::KeyEvent& rAWTKey = *pIt; 935cdf0e10cSrcweir const KeyCode aVCLKey = ::svt::AcceleratorExecute::st_AWTKey2VCLKey(rAWTKey); 936cdf0e10cSrcweir const String sName = aVCLKey.GetName(); 937cdf0e10cSrcweir 938cdf0e10cSrcweir if (sName.Len () > 0) 939cdf0e10cSrcweir return pIt; 940cdf0e10cSrcweir } 941cdf0e10cSrcweir 942cdf0e10cSrcweir return lKeys.end (); 943cdf0e10cSrcweir } 944cdf0e10cSrcweir 945cdf0e10cSrcweir //----------------------------------------------- 946cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > SAL_CALL XCUBasedAcceleratorConfiguration::getPreferredKeyEventsForCommandList(const css::uno::Sequence< ::rtl::OUString >& lCommandList) 947cdf0e10cSrcweir throw(css::lang::IllegalArgumentException , 948cdf0e10cSrcweir css::uno::RuntimeException ) 949cdf0e10cSrcweir { 950cdf0e10cSrcweir // SAFE -> ---------------------------------- 951cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 952cdf0e10cSrcweir 953cdf0e10cSrcweir sal_Int32 i = 0; 954cdf0e10cSrcweir sal_Int32 c = lCommandList.getLength(); 955cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > lPreferredOnes (c); // dont pack list! 956cdf0e10cSrcweir AcceleratorCache& rCache = impl_getCFG(sal_True); 957cdf0e10cSrcweir 958cdf0e10cSrcweir for (i=0; i<c; ++i) 959cdf0e10cSrcweir { 960cdf0e10cSrcweir const ::rtl::OUString& rCommand = lCommandList[i]; 961cdf0e10cSrcweir if (!rCommand.getLength()) 962cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 963cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Empty command strings are not allowed here."), 964cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 965cdf0e10cSrcweir (sal_Int16)i); 966cdf0e10cSrcweir 967cdf0e10cSrcweir if (!rCache.hasCommand(rCommand)) 968cdf0e10cSrcweir continue; 969cdf0e10cSrcweir 970cdf0e10cSrcweir AcceleratorCache::TKeyList lKeys = rCache.getKeysByCommand(rCommand); 971cdf0e10cSrcweir if ( lKeys.empty() ) 972cdf0e10cSrcweir continue; 973cdf0e10cSrcweir 974cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pPreferredKey = lcl_getPreferredKey(lKeys); 975cdf0e10cSrcweir if (pPreferredKey != lKeys.end ()) 976cdf0e10cSrcweir { 977cdf0e10cSrcweir css::uno::Any& rAny = lPreferredOnes[i]; 978cdf0e10cSrcweir rAny <<= *(pPreferredKey); 979cdf0e10cSrcweir } 980cdf0e10cSrcweir } 981cdf0e10cSrcweir 982cdf0e10cSrcweir aReadLock.unlock(); 983cdf0e10cSrcweir // <- SAFE ---------------------------------- 984cdf0e10cSrcweir 985cdf0e10cSrcweir return lPreferredOnes; 986cdf0e10cSrcweir } 987cdf0e10cSrcweir 988cdf0e10cSrcweir //----------------------------------------------- 989cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::removeCommandFromAllKeyEvents(const ::rtl::OUString& sCommand) 990cdf0e10cSrcweir throw(css::lang::IllegalArgumentException , 991cdf0e10cSrcweir css::container::NoSuchElementException, 992cdf0e10cSrcweir css::uno::RuntimeException ) 993cdf0e10cSrcweir { 994cdf0e10cSrcweir if (!sCommand.getLength()) 995cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 996cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Empty command strings are not allowed here."), 997cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this), 998cdf0e10cSrcweir 0); 999cdf0e10cSrcweir 1000cdf0e10cSrcweir // SAFE -> ---------------------------------- 1001cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1002cdf0e10cSrcweir 1003cdf0e10cSrcweir AcceleratorCache& rPrimaryCache = impl_getCFG(sal_True, sal_True ); 1004cdf0e10cSrcweir AcceleratorCache& rSecondaryCache = impl_getCFG(sal_False, sal_True); 1005cdf0e10cSrcweir 1006cdf0e10cSrcweir if (!rPrimaryCache.hasCommand(sCommand) && !rSecondaryCache.hasCommand(sCommand)) 1007cdf0e10cSrcweir throw css::container::NoSuchElementException( 1008cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Command does not exists inside this container."), 1009cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 1010cdf0e10cSrcweir 1011cdf0e10cSrcweir if (rPrimaryCache.hasCommand(sCommand)) 1012cdf0e10cSrcweir rPrimaryCache.removeCommand(sCommand); 1013cdf0e10cSrcweir if (rSecondaryCache.hasCommand(sCommand)) 1014cdf0e10cSrcweir rSecondaryCache.removeCommand(sCommand); 1015cdf0e10cSrcweir 1016cdf0e10cSrcweir aWriteLock.unlock(); 1017cdf0e10cSrcweir // <- SAFE ---------------------------------- 1018cdf0e10cSrcweir } 1019cdf0e10cSrcweir 1020cdf0e10cSrcweir //----------------------------------------------- 1021cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::reload() 1022cdf0e10cSrcweir throw(css::uno::Exception , 1023cdf0e10cSrcweir css::uno::RuntimeException) 1024cdf0e10cSrcweir { 1025cdf0e10cSrcweir RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::reload()" ); 1026cdf0e10cSrcweir 1027cdf0e10cSrcweir // SAFE -> ---------------------------------- 1028cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1029cdf0e10cSrcweir 1030cdf0e10cSrcweir sal_Bool bPreferred; 1031cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess; 1032cdf0e10cSrcweir 1033cdf0e10cSrcweir bPreferred = sal_True; 1034cdf0e10cSrcweir m_aPrimaryReadCache = AcceleratorCache(); 1035cdf0e10cSrcweir if (m_pPrimaryWriteCache) 1036cdf0e10cSrcweir { 1037cdf0e10cSrcweir // be aware of reentrance problems - use temp variable for calling delete ... :-) 1038cdf0e10cSrcweir AcceleratorCache* pTemp = m_pPrimaryWriteCache; 1039cdf0e10cSrcweir m_pPrimaryWriteCache = 0; 1040cdf0e10cSrcweir delete pTemp; 1041cdf0e10cSrcweir } 1042cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_PRIMARY) >>= xAccess; 1043cdf0e10cSrcweir impl_ts_load(bPreferred, xAccess); // load the preferred keys 1044cdf0e10cSrcweir 1045cdf0e10cSrcweir bPreferred = sal_False; 1046cdf0e10cSrcweir m_aSecondaryReadCache = AcceleratorCache(); 1047cdf0e10cSrcweir if (m_pSecondaryWriteCache) 1048cdf0e10cSrcweir { 1049cdf0e10cSrcweir // be aware of reentrance problems - use temp variable for calling delete ... :-) 1050cdf0e10cSrcweir AcceleratorCache* pTemp = m_pSecondaryWriteCache; 1051cdf0e10cSrcweir m_pSecondaryWriteCache = 0; 1052cdf0e10cSrcweir delete pTemp; 1053cdf0e10cSrcweir } 1054cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_SECONDARY) >>= xAccess; 1055cdf0e10cSrcweir impl_ts_load(bPreferred, xAccess); // load the secondary keys 1056cdf0e10cSrcweir 1057cdf0e10cSrcweir aWriteLock.unlock(); 1058cdf0e10cSrcweir // <- SAFE ---------------------------------- 1059cdf0e10cSrcweir } 1060cdf0e10cSrcweir 1061cdf0e10cSrcweir //----------------------------------------------- 1062cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::store() 1063cdf0e10cSrcweir throw(css::uno::Exception , 1064cdf0e10cSrcweir css::uno::RuntimeException) 1065cdf0e10cSrcweir { 1066cdf0e10cSrcweir RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::store()" ); 1067cdf0e10cSrcweir 1068cdf0e10cSrcweir // SAFE -> ---------------------------------- 1069cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 1070cdf0e10cSrcweir 1071cdf0e10cSrcweir sal_Bool bPreferred; 1072cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess; 1073cdf0e10cSrcweir 1074cdf0e10cSrcweir bPreferred = sal_True; 1075cdf0e10cSrcweir // on-demand creation of the primary write cache 1076cdf0e10cSrcweir impl_getCFG(bPreferred, sal_True); 1077cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_PRIMARY) >>= xAccess; 1078cdf0e10cSrcweir impl_ts_save(bPreferred, xAccess); 1079cdf0e10cSrcweir 1080cdf0e10cSrcweir bPreferred = sal_False; 1081cdf0e10cSrcweir // on-demand creation of the secondary write cache 1082cdf0e10cSrcweir impl_getCFG(bPreferred, sal_True); 1083cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_SECONDARY) >>= xAccess; 1084cdf0e10cSrcweir impl_ts_save(bPreferred, xAccess); 1085cdf0e10cSrcweir 1086cdf0e10cSrcweir aReadLock.unlock(); 1087cdf0e10cSrcweir // <- SAFE ---------------------------------- 1088cdf0e10cSrcweir } 1089cdf0e10cSrcweir 1090cdf0e10cSrcweir //----------------------------------------------- 1091cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::storeToStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) 1092cdf0e10cSrcweir throw(css::uno::Exception , 1093cdf0e10cSrcweir css::uno::RuntimeException) 1094cdf0e10cSrcweir { 1095cdf0e10cSrcweir // use m_aCache + old AcceleratorXMLWriter to store data directly on storage given as parameter ... 1096cdf0e10cSrcweir if (!xStorage.is()) 1097cdf0e10cSrcweir return; 1098cdf0e10cSrcweir 1099cdf0e10cSrcweir long nOpenModes = css::embed::ElementModes::READWRITE; 1100cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage > xAcceleratorTypeStorage = xStorage->openStorageElement(::rtl::OUString::createFromAscii("accelerator"), nOpenModes); 1101cdf0e10cSrcweir if (!xAcceleratorTypeStorage.is()) 1102cdf0e10cSrcweir return; 1103cdf0e10cSrcweir 1104cdf0e10cSrcweir css::uno::Reference< css::io::XStream > xStream = xAcceleratorTypeStorage->openStreamElement(::rtl::OUString::createFromAscii("current"), nOpenModes); 1105cdf0e10cSrcweir css::uno::Reference< css::io::XOutputStream > xOut; 1106cdf0e10cSrcweir if (xStream.is()) 1107cdf0e10cSrcweir xOut = xStream->getOutputStream(); 1108cdf0e10cSrcweir if (!xOut.is()) 1109cdf0e10cSrcweir throw css::io::IOException( 1110cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Could not open accelerator configuration for saving."), 1111cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this)); 1112cdf0e10cSrcweir 1113cdf0e10cSrcweir // the original m_aCache has been split into primay cache and secondary cache... 1114cdf0e10cSrcweir // we should merge them before storing to storage 1115cdf0e10cSrcweir // SAFE -> ---------------------------------- 1116cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1117cdf0e10cSrcweir 1118cdf0e10cSrcweir AcceleratorCache aCache; 1119cdf0e10cSrcweir if (m_pPrimaryWriteCache != 0) 1120cdf0e10cSrcweir aCache.takeOver(*m_pPrimaryWriteCache); 1121cdf0e10cSrcweir else 1122cdf0e10cSrcweir aCache.takeOver(m_aPrimaryReadCache); 1123cdf0e10cSrcweir 1124cdf0e10cSrcweir AcceleratorCache::TKeyList lKeys; 1125cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pIt; 1126cdf0e10cSrcweir if (m_pSecondaryWriteCache!=0) 1127cdf0e10cSrcweir { 1128cdf0e10cSrcweir lKeys = m_pSecondaryWriteCache->getAllKeys(); 1129cdf0e10cSrcweir for ( pIt=lKeys.begin(); pIt!=lKeys.end(); ++pIt ) 1130cdf0e10cSrcweir aCache.setKeyCommandPair(*pIt, m_pSecondaryWriteCache->getCommandByKey(*pIt)); 1131cdf0e10cSrcweir } 1132cdf0e10cSrcweir else 1133cdf0e10cSrcweir { 1134cdf0e10cSrcweir lKeys = m_aSecondaryReadCache.getAllKeys(); 1135cdf0e10cSrcweir for ( pIt=lKeys.begin(); pIt!=lKeys.end(); ++pIt ) 1136cdf0e10cSrcweir aCache.setKeyCommandPair(*pIt, m_aSecondaryReadCache.getCommandByKey(*pIt)); 1137cdf0e10cSrcweir } 1138cdf0e10cSrcweir 1139cdf0e10cSrcweir aWriteLock.unlock(); 1140cdf0e10cSrcweir // <- SAFE ---------------------------------- 1141cdf0e10cSrcweir 1142cdf0e10cSrcweir css::uno::Reference< css::io::XTruncate > xClearable(xOut, css::uno::UNO_QUERY_THROW); 1143cdf0e10cSrcweir xClearable->truncate(); 1144cdf0e10cSrcweir css::uno::Reference< css::io::XSeekable > xSeek(xOut, css::uno::UNO_QUERY); 1145cdf0e10cSrcweir if (xSeek.is()) 1146cdf0e10cSrcweir xSeek->seek(0); 1147cdf0e10cSrcweir 1148cdf0e10cSrcweir css::uno::Reference< css::xml::sax::XDocumentHandler > xWriter (m_xSMGR->createInstance(SERVICENAME_SAXWRITER), css::uno::UNO_QUERY_THROW); 1149cdf0e10cSrcweir css::uno::Reference< css::io::XActiveDataSource> xDataSource(xWriter , css::uno::UNO_QUERY_THROW); 1150cdf0e10cSrcweir xDataSource->setOutputStream(xOut); 1151cdf0e10cSrcweir 1152cdf0e10cSrcweir // write into the stream 1153cdf0e10cSrcweir AcceleratorConfigurationWriter aWriter(aCache, xWriter); 1154cdf0e10cSrcweir aWriter.flush(); 1155cdf0e10cSrcweir } 1156cdf0e10cSrcweir 1157cdf0e10cSrcweir //----------------------------------------------- 1158cdf0e10cSrcweir ::sal_Bool SAL_CALL XCUBasedAcceleratorConfiguration::isModified() 1159cdf0e10cSrcweir throw(css::uno::RuntimeException) 1160cdf0e10cSrcweir { 1161cdf0e10cSrcweir return sal_False; 1162cdf0e10cSrcweir } 1163cdf0e10cSrcweir 1164cdf0e10cSrcweir //----------------------------------------------- 1165cdf0e10cSrcweir ::sal_Bool SAL_CALL XCUBasedAcceleratorConfiguration::isReadOnly() 1166cdf0e10cSrcweir throw(css::uno::RuntimeException) 1167cdf0e10cSrcweir { 1168cdf0e10cSrcweir return sal_False; 1169cdf0e10cSrcweir } 1170cdf0e10cSrcweir 1171cdf0e10cSrcweir //----------------------------------------------- 1172cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::setStorage(const css::uno::Reference< css::embed::XStorage >& /*xStorage*/) 1173cdf0e10cSrcweir throw(css::uno::RuntimeException) 1174cdf0e10cSrcweir { 1175cdf0e10cSrcweir LOG_WARNING("XCUBasedAcceleratorConfiguration::setStorage()", "TODO implement this HACK .-)") 1176cdf0e10cSrcweir } 1177cdf0e10cSrcweir 1178cdf0e10cSrcweir //----------------------------------------------- 1179cdf0e10cSrcweir ::sal_Bool SAL_CALL XCUBasedAcceleratorConfiguration::hasStorage() 1180cdf0e10cSrcweir throw(css::uno::RuntimeException) 1181cdf0e10cSrcweir { 1182cdf0e10cSrcweir LOG_WARNING("XCUBasedAcceleratorConfiguration::hasStorage()", "TODO implement this HACK .-)") 1183cdf0e10cSrcweir return sal_False; 1184cdf0e10cSrcweir } 1185cdf0e10cSrcweir 1186cdf0e10cSrcweir //----------------------------------------------- 1187cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::addConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& /*xListener*/) 1188cdf0e10cSrcweir throw(css::uno::RuntimeException) 1189cdf0e10cSrcweir { 1190cdf0e10cSrcweir LOG_WARNING("XCUBasedAcceleratorConfiguration::addConfigurationListener()", "TODO implement me") 1191cdf0e10cSrcweir } 1192cdf0e10cSrcweir 1193cdf0e10cSrcweir //----------------------------------------------- 1194cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::removeConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& /*xListener*/) 1195cdf0e10cSrcweir throw(css::uno::RuntimeException) 1196cdf0e10cSrcweir { 1197cdf0e10cSrcweir LOG_WARNING("XCUBasedAcceleratorConfiguration::removeConfigurationListener()", "TODO implement me") 1198cdf0e10cSrcweir } 1199cdf0e10cSrcweir 1200cdf0e10cSrcweir //----------------------------------------------- 1201cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::reset() 1202cdf0e10cSrcweir throw(css::uno::RuntimeException) 1203cdf0e10cSrcweir { 1204cdf0e10cSrcweir css::uno::Reference< css::container::XNamed > xNamed(m_xCfg, css::uno::UNO_QUERY); 1205cdf0e10cSrcweir ::rtl::OUString sConfig = xNamed->getName(); 1206cdf0e10cSrcweir if ( sConfig.equalsAscii("Global") ) 1207cdf0e10cSrcweir { 1208cdf0e10cSrcweir m_xCfg = css::uno::Reference< css::container::XNameAccess > ( 1209cdf0e10cSrcweir ::comphelper::ConfigurationHelper::openConfig( m_xSMGR, CFG_ENTRY_GLOBAL, ::comphelper::ConfigurationHelper::E_ALL_LOCALES ), 1210cdf0e10cSrcweir css::uno::UNO_QUERY ); 1211cdf0e10cSrcweir XCUBasedAcceleratorConfiguration::reload(); 1212cdf0e10cSrcweir } 1213cdf0e10cSrcweir else if ( sConfig.equalsAscii("Modules") ) 1214cdf0e10cSrcweir { 1215cdf0e10cSrcweir m_xCfg = css::uno::Reference< css::container::XNameAccess > ( 1216cdf0e10cSrcweir ::comphelper::ConfigurationHelper::openConfig( m_xSMGR, CFG_ENTRY_MODULES, ::comphelper::ConfigurationHelper::E_ALL_LOCALES ), 1217cdf0e10cSrcweir css::uno::UNO_QUERY ); 1218cdf0e10cSrcweir XCUBasedAcceleratorConfiguration::reload(); 1219cdf0e10cSrcweir } 1220cdf0e10cSrcweir } 1221cdf0e10cSrcweir 1222cdf0e10cSrcweir //----------------------------------------------- 1223cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::addResetListener(const css::uno::Reference< css::form::XResetListener >& /*xListener*/) 1224cdf0e10cSrcweir throw(css::uno::RuntimeException) 1225cdf0e10cSrcweir { 1226cdf0e10cSrcweir LOG_WARNING("XCUBasedAcceleratorConfiguration::addResetListener()", "TODO implement me") 1227cdf0e10cSrcweir } 1228cdf0e10cSrcweir 1229cdf0e10cSrcweir //----------------------------------------------- 1230cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::removeResetListener(const css::uno::Reference< css::form::XResetListener >& /*xListener*/) 1231cdf0e10cSrcweir throw(css::uno::RuntimeException) 1232cdf0e10cSrcweir { 1233cdf0e10cSrcweir LOG_WARNING("XCUBasedAcceleratorConfiguration::removeResetListener()", "TODO implement me") 1234cdf0e10cSrcweir } 1235cdf0e10cSrcweir 1236cdf0e10cSrcweir //----------------------------------------------- 1237cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::changesOccurred(const css::util::ChangesEvent& aEvent) 1238cdf0e10cSrcweir throw(css::uno::RuntimeException) 1239cdf0e10cSrcweir { 1240cdf0e10cSrcweir RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::changesOccurred()" ); 1241cdf0e10cSrcweir 1242cdf0e10cSrcweir css::uno::Reference< css::container::XHierarchicalNameAccess > xHAccess; 1243cdf0e10cSrcweir aEvent.Base >>= xHAccess; 1244cdf0e10cSrcweir if (! xHAccess.is ()) 1245cdf0e10cSrcweir return; 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir css::util::ChangesEvent aReceivedEvents( aEvent ); 1248cdf0e10cSrcweir const sal_Int32 c = aReceivedEvents.Changes.getLength(); 1249cdf0e10cSrcweir sal_Int32 i = 0; 1250cdf0e10cSrcweir for (i=0; i<c; ++i) 1251cdf0e10cSrcweir { 1252cdf0e10cSrcweir const css::util::ElementChange& aChange = aReceivedEvents.Changes[i]; 1253cdf0e10cSrcweir 1254cdf0e10cSrcweir // Only path of form "PrimaryKeys/Modules/Module['<module_name>']/Key['<command_url>']/Command[<locale>]" will 1255cdf0e10cSrcweir // be interesting for use. Sometimes short path values are given also by the broadcaster ... but they must be ignored :-) 1256cdf0e10cSrcweir // So we try to split the path into 3 parts (module isnt important here, because we already know it ... because 1257cdf0e10cSrcweir // these instance is bound to a specific module configuration ... or it''s the global configuration where no module is given at all. 1258cdf0e10cSrcweir 1259cdf0e10cSrcweir ::rtl::OUString sOrgPath ; 1260cdf0e10cSrcweir ::rtl::OUString sPath ; 1261cdf0e10cSrcweir ::rtl::OUString sKey; 1262cdf0e10cSrcweir 1263cdf0e10cSrcweir aChange.Accessor >>= sOrgPath; 1264cdf0e10cSrcweir sPath = sOrgPath; 1265cdf0e10cSrcweir ::rtl::OUString sPrimarySecondary = ::utl::extractFirstFromConfigurationPath(sPath, &sPath); 1266cdf0e10cSrcweir ::rtl::OUString sGlobalModules = ::utl::extractFirstFromConfigurationPath(sPath, &sPath); 1267cdf0e10cSrcweir 1268cdf0e10cSrcweir if ( sGlobalModules.equals(CFG_ENTRY_GLOBAL) ) 1269cdf0e10cSrcweir { 1270cdf0e10cSrcweir ::rtl::OUString sModule; 1271cdf0e10cSrcweir sKey = ::utl::extractFirstFromConfigurationPath(sPath, &sPath); 1272cdf0e10cSrcweir if (( sKey.getLength() > 0 ) && ( sPath.getLength() > 0 )) 1273cdf0e10cSrcweir reloadChanged(sPrimarySecondary, sGlobalModules, sModule, sKey); 1274cdf0e10cSrcweir } 1275cdf0e10cSrcweir else if ( sGlobalModules.equals(CFG_ENTRY_MODULES) ) 1276cdf0e10cSrcweir { 1277cdf0e10cSrcweir ::rtl::OUString sModule = ::utl::extractFirstFromConfigurationPath(sPath, &sPath); 1278cdf0e10cSrcweir sKey = ::utl::extractFirstFromConfigurationPath(sPath, &sPath); 1279cdf0e10cSrcweir 1280cdf0e10cSrcweir if (( sKey.getLength() > 0 ) && ( sPath.getLength() > 0 )) 1281cdf0e10cSrcweir { 1282cdf0e10cSrcweir reloadChanged(sPrimarySecondary, sGlobalModules, sModule, sKey); 1283cdf0e10cSrcweir } 1284cdf0e10cSrcweir } 1285cdf0e10cSrcweir } 1286cdf0e10cSrcweir } 1287cdf0e10cSrcweir 1288cdf0e10cSrcweir //----------------------------------------------- 1289cdf0e10cSrcweir void SAL_CALL XCUBasedAcceleratorConfiguration::disposing(const css::lang::EventObject& /*aSource*/) 1290cdf0e10cSrcweir throw(css::uno::RuntimeException) 1291cdf0e10cSrcweir { 1292cdf0e10cSrcweir } 1293cdf0e10cSrcweir 1294cdf0e10cSrcweir //----------------------------------------------- 1295cdf0e10cSrcweir void XCUBasedAcceleratorConfiguration::impl_ts_load( sal_Bool bPreferred, const css::uno::Reference< css::container::XNameAccess >& xCfg ) 1296cdf0e10cSrcweir { 1297cdf0e10cSrcweir AcceleratorCache aReadCache = AcceleratorCache(); 1298cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess; 1299cdf0e10cSrcweir if (m_sGlobalOrModules.equalsAscii("Global")) 1300cdf0e10cSrcweir xCfg->getByName(CFG_ENTRY_GLOBAL) >>= xAccess; 1301cdf0e10cSrcweir else if (m_sGlobalOrModules.equalsAscii("Modules")) 1302cdf0e10cSrcweir { 1303cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xModules; 1304cdf0e10cSrcweir xCfg->getByName(CFG_ENTRY_MODULES) >>= xModules; 1305cdf0e10cSrcweir xModules->getByName(m_sModuleCFG) >>= xAccess; 1306cdf0e10cSrcweir } 1307cdf0e10cSrcweir 1308cdf0e10cSrcweir const ::rtl::OUString sIsoLang = impl_ts_getLocale().toISO(); 1309cdf0e10cSrcweir const ::rtl::OUString sDefaultLocale = ::rtl::OUString::createFromAscii("en-US"); 1310cdf0e10cSrcweir 1311cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xKey; 1312cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xCommand; 1313cdf0e10cSrcweir if (xAccess.is()) 1314cdf0e10cSrcweir { 1315cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lKeys = xAccess->getElementNames(); 1316cdf0e10cSrcweir sal_Int32 nKeys = lKeys.getLength(); 1317cdf0e10cSrcweir for ( sal_Int32 i=0; i<nKeys; ++i ) 1318cdf0e10cSrcweir { 1319cdf0e10cSrcweir ::rtl::OUString sKey = lKeys[i]; 1320cdf0e10cSrcweir xAccess->getByName(sKey) >>= xKey; 1321cdf0e10cSrcweir xKey->getByName(CFG_PROP_COMMAND) >>= xCommand; 1322cdf0e10cSrcweir 1323cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lLocales = xCommand->getElementNames(); 1324cdf0e10cSrcweir sal_Int32 nLocales = lLocales.getLength(); 1325cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aLocales; 1326cdf0e10cSrcweir for ( sal_Int32 j=0; j<nLocales; ++j ) 1327cdf0e10cSrcweir aLocales.push_back(lLocales[j]); 1328cdf0e10cSrcweir 1329cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pFound; 1330cdf0e10cSrcweir for ( pFound = aLocales.begin(); pFound != aLocales.end(); ++pFound ) 1331cdf0e10cSrcweir { 1332cdf0e10cSrcweir if ( *pFound == sIsoLang ) 1333cdf0e10cSrcweir break; 1334cdf0e10cSrcweir } 1335cdf0e10cSrcweir 1336cdf0e10cSrcweir if ( pFound == aLocales.end() ) 1337cdf0e10cSrcweir { 1338cdf0e10cSrcweir for ( pFound = aLocales.begin(); pFound != aLocales.end(); ++pFound ) 1339cdf0e10cSrcweir { 1340cdf0e10cSrcweir if ( *pFound == sDefaultLocale ) 1341cdf0e10cSrcweir break; 1342cdf0e10cSrcweir } 1343cdf0e10cSrcweir 1344cdf0e10cSrcweir if ( pFound == aLocales.end() ) 1345cdf0e10cSrcweir continue; 1346cdf0e10cSrcweir } 1347cdf0e10cSrcweir 1348cdf0e10cSrcweir ::rtl::OUString sLocale = *pFound; 1349cdf0e10cSrcweir ::rtl::OUString sCommand; 1350cdf0e10cSrcweir xCommand->getByName(sLocale) >>= sCommand; 1351cdf0e10cSrcweir if (sCommand.getLength()<1) 1352cdf0e10cSrcweir continue; 1353cdf0e10cSrcweir 1354cdf0e10cSrcweir css::awt::KeyEvent aKeyEvent; 1355cdf0e10cSrcweir 1356cdf0e10cSrcweir sal_Int32 nIndex = 0; 1357cdf0e10cSrcweir ::rtl::OUString sKeyCommand = sKey.getToken(0, '_', nIndex); 1358cdf0e10cSrcweir ::rtl::OUString sPrefix = ::rtl::OUString::createFromAscii("KEY_"); 1359cdf0e10cSrcweir aKeyEvent.KeyCode = m_rKeyMapping->mapIdentifierToCode(sPrefix + sKeyCommand); 1360cdf0e10cSrcweir 1361cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > sToken(4); 1362cdf0e10cSrcweir const sal_Int32 nToken = 4; 1363cdf0e10cSrcweir sal_Bool bValid = sal_True; 1364cdf0e10cSrcweir sal_Int32 k; 1365cdf0e10cSrcweir for (k=0; k<nToken; ++k) 1366cdf0e10cSrcweir { 1367cdf0e10cSrcweir if (nIndex < 0) 1368cdf0e10cSrcweir break; 1369cdf0e10cSrcweir 1370cdf0e10cSrcweir sToken[k] = sKey.getToken(0, '_', nIndex); 1371cdf0e10cSrcweir ::rtl::OUString sTest = sToken[k]; 1372cdf0e10cSrcweir if (sToken[k].getLength() < 1) 1373cdf0e10cSrcweir { 1374cdf0e10cSrcweir bValid = sal_False; 1375cdf0e10cSrcweir break; 1376cdf0e10cSrcweir } 1377cdf0e10cSrcweir 1378cdf0e10cSrcweir if (sToken[k].equalsAscii("SHIFT")) 1379cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::SHIFT; 1380cdf0e10cSrcweir else if (sToken[k].equalsAscii("MOD1")) 1381cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD1; 1382cdf0e10cSrcweir else if (sToken[k].equalsAscii("MOD2")) 1383cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD2; 1384cdf0e10cSrcweir else if (sToken[k].equalsAscii("MOD3")) 1385cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD3; 1386cdf0e10cSrcweir else 1387cdf0e10cSrcweir { 1388cdf0e10cSrcweir bValid = sal_False; 1389cdf0e10cSrcweir break; 1390cdf0e10cSrcweir } 1391cdf0e10cSrcweir } 1392cdf0e10cSrcweir 1393cdf0e10cSrcweir if ( !aReadCache.hasKey(aKeyEvent) && bValid && k<nToken) 1394cdf0e10cSrcweir aReadCache.setKeyCommandPair(aKeyEvent, sCommand); 1395cdf0e10cSrcweir } 1396cdf0e10cSrcweir } 1397cdf0e10cSrcweir 1398cdf0e10cSrcweir if (bPreferred) 1399cdf0e10cSrcweir m_aPrimaryReadCache.takeOver(aReadCache); 1400cdf0e10cSrcweir else 1401cdf0e10cSrcweir m_aSecondaryReadCache.takeOver(aReadCache); 1402cdf0e10cSrcweir } 1403cdf0e10cSrcweir 1404cdf0e10cSrcweir //----------------------------------------------- 1405cdf0e10cSrcweir void XCUBasedAcceleratorConfiguration::impl_ts_save(sal_Bool bPreferred, const css::uno::Reference< css::container::XNameAccess >& /*xCfg*/) 1406cdf0e10cSrcweir { 1407cdf0e10cSrcweir if (bPreferred) 1408cdf0e10cSrcweir { 1409cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pIt; 1410cdf0e10cSrcweir AcceleratorCache::TKeyList lPrimaryReadKeys = m_aPrimaryReadCache.getAllKeys(); 1411cdf0e10cSrcweir AcceleratorCache::TKeyList lPrimaryWriteKeys = m_pPrimaryWriteCache->getAllKeys(); 1412cdf0e10cSrcweir 1413cdf0e10cSrcweir for ( pIt = lPrimaryReadKeys.begin(); pIt != lPrimaryReadKeys.end(); ++pIt ) 1414cdf0e10cSrcweir { 1415cdf0e10cSrcweir if (!m_pPrimaryWriteCache->hasKey(*pIt)) 1416cdf0e10cSrcweir removeKeyFromConfiguration(*pIt, sal_True); 1417cdf0e10cSrcweir } 1418cdf0e10cSrcweir 1419cdf0e10cSrcweir for ( pIt = lPrimaryWriteKeys.begin(); pIt != lPrimaryWriteKeys.end(); ++pIt ) 1420cdf0e10cSrcweir { 1421cdf0e10cSrcweir ::rtl::OUString sCommand = m_pPrimaryWriteCache->getCommandByKey(*pIt); 1422cdf0e10cSrcweir if (!m_aPrimaryReadCache.hasKey(*pIt)) 1423cdf0e10cSrcweir { 1424cdf0e10cSrcweir insertKeyToConfiguration(*pIt, sCommand, sal_True); 1425cdf0e10cSrcweir } 1426cdf0e10cSrcweir else 1427cdf0e10cSrcweir { 1428cdf0e10cSrcweir ::rtl::OUString sReadCommand = m_aPrimaryReadCache.getCommandByKey(*pIt); 1429cdf0e10cSrcweir if (sReadCommand != sCommand) 1430cdf0e10cSrcweir insertKeyToConfiguration(*pIt, sCommand, sal_True); 1431cdf0e10cSrcweir } 1432cdf0e10cSrcweir } 1433cdf0e10cSrcweir 1434cdf0e10cSrcweir // take over all changes into the original container 1435cdf0e10cSrcweir // SAFE -> ---------------------------------- 1436cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1437cdf0e10cSrcweir 1438cdf0e10cSrcweir if (m_pPrimaryWriteCache) 1439cdf0e10cSrcweir { 1440cdf0e10cSrcweir m_aPrimaryReadCache.takeOver(*m_pPrimaryWriteCache); 1441cdf0e10cSrcweir AcceleratorCache* pTemp = m_pPrimaryWriteCache; 1442cdf0e10cSrcweir m_pPrimaryWriteCache = 0; 1443cdf0e10cSrcweir delete pTemp; 1444cdf0e10cSrcweir } 1445cdf0e10cSrcweir 1446cdf0e10cSrcweir aWriteLock.unlock(); 1447cdf0e10cSrcweir // <- SAFE ---------------------------------- 1448cdf0e10cSrcweir } 1449cdf0e10cSrcweir 1450cdf0e10cSrcweir else 1451cdf0e10cSrcweir { 1452cdf0e10cSrcweir AcceleratorCache::TKeyList::const_iterator pIt; 1453cdf0e10cSrcweir AcceleratorCache::TKeyList lSecondaryReadKeys = m_aSecondaryReadCache.getAllKeys(); 1454cdf0e10cSrcweir AcceleratorCache::TKeyList lSecondaryWriteKeys = m_pSecondaryWriteCache->getAllKeys(); 1455cdf0e10cSrcweir 1456cdf0e10cSrcweir for ( pIt = lSecondaryReadKeys.begin(); pIt != lSecondaryReadKeys.end(); ++pIt) 1457cdf0e10cSrcweir { 1458cdf0e10cSrcweir if (!m_pSecondaryWriteCache->hasKey(*pIt)) 1459cdf0e10cSrcweir removeKeyFromConfiguration(*pIt, sal_False); 1460cdf0e10cSrcweir } 1461cdf0e10cSrcweir 1462cdf0e10cSrcweir 1463cdf0e10cSrcweir for ( pIt = lSecondaryWriteKeys.begin(); pIt != lSecondaryWriteKeys.end(); ++pIt ) 1464cdf0e10cSrcweir { 1465cdf0e10cSrcweir ::rtl::OUString sCommand = m_pSecondaryWriteCache->getCommandByKey(*pIt); 1466cdf0e10cSrcweir if (!m_aSecondaryReadCache.hasKey(*pIt)) 1467cdf0e10cSrcweir { 1468cdf0e10cSrcweir insertKeyToConfiguration(*pIt, sCommand, sal_False); 1469cdf0e10cSrcweir } 1470cdf0e10cSrcweir else 1471cdf0e10cSrcweir { 1472cdf0e10cSrcweir ::rtl::OUString sReadCommand = m_aSecondaryReadCache.getCommandByKey(*pIt); 1473cdf0e10cSrcweir if (sReadCommand != sCommand) 1474cdf0e10cSrcweir insertKeyToConfiguration(*pIt, sCommand, sal_False); 1475cdf0e10cSrcweir } 1476cdf0e10cSrcweir } 1477cdf0e10cSrcweir 1478cdf0e10cSrcweir // take over all changes into the original container 1479cdf0e10cSrcweir // SAFE -> ---------------------------------- 1480cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1481cdf0e10cSrcweir 1482cdf0e10cSrcweir if (m_pSecondaryWriteCache) 1483cdf0e10cSrcweir { 1484cdf0e10cSrcweir m_aSecondaryReadCache.takeOver(*m_pSecondaryWriteCache); 1485cdf0e10cSrcweir AcceleratorCache* pTemp = m_pSecondaryWriteCache; 1486cdf0e10cSrcweir m_pSecondaryWriteCache = 0; 1487cdf0e10cSrcweir delete pTemp; 1488cdf0e10cSrcweir } 1489cdf0e10cSrcweir 1490cdf0e10cSrcweir aWriteLock.unlock(); 1491cdf0e10cSrcweir // <- SAFE ---------------------------------- 1492cdf0e10cSrcweir } 1493cdf0e10cSrcweir 1494cdf0e10cSrcweir ::comphelper::ConfigurationHelper::flush(m_xCfg); 1495cdf0e10cSrcweir } 1496cdf0e10cSrcweir 1497cdf0e10cSrcweir //----------------------------------------------- 1498cdf0e10cSrcweir void XCUBasedAcceleratorConfiguration::insertKeyToConfiguration( const css::awt::KeyEvent& aKeyEvent, const ::rtl::OUString& sCommand, const sal_Bool bPreferred ) 1499cdf0e10cSrcweir { 1500cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess; 1501cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xContainer; 1502cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleServiceFactory > xFac; 1503cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xInst; 1504cdf0e10cSrcweir 1505cdf0e10cSrcweir if ( bPreferred ) 1506cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_PRIMARY) >>= xAccess; 1507cdf0e10cSrcweir else 1508cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_SECONDARY) >>= xAccess; 1509cdf0e10cSrcweir 1510cdf0e10cSrcweir if ( m_sGlobalOrModules.equals(CFG_ENTRY_GLOBAL) ) 1511cdf0e10cSrcweir xAccess->getByName(CFG_ENTRY_GLOBAL) >>= xContainer; 1512cdf0e10cSrcweir else if ( m_sGlobalOrModules.equals(CFG_ENTRY_MODULES) ) 1513cdf0e10cSrcweir { 1514cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xModules; 1515cdf0e10cSrcweir xAccess->getByName(CFG_ENTRY_MODULES) >>= xModules; 1516cdf0e10cSrcweir if ( !xModules->hasByName(m_sModuleCFG) ) 1517cdf0e10cSrcweir { 1518cdf0e10cSrcweir xFac = css::uno::Reference< css::lang::XSingleServiceFactory >(xModules, css::uno::UNO_QUERY); 1519cdf0e10cSrcweir xInst = xFac->createInstance(); 1520cdf0e10cSrcweir xModules->insertByName(m_sModuleCFG, css::uno::makeAny(xInst)); 1521cdf0e10cSrcweir } 1522cdf0e10cSrcweir xModules->getByName(m_sModuleCFG) >>= xContainer; 1523cdf0e10cSrcweir } 1524cdf0e10cSrcweir 1525cdf0e10cSrcweir const ::rtl::OUString sKey = lcl_getKeyString(m_rKeyMapping,aKeyEvent); 1526cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xKey; 1527cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xCommand; 1528cdf0e10cSrcweir if ( !xContainer->hasByName(sKey) ) 1529cdf0e10cSrcweir { 1530cdf0e10cSrcweir xFac = css::uno::Reference< css::lang::XSingleServiceFactory >(xContainer, css::uno::UNO_QUERY); 1531cdf0e10cSrcweir xInst = xFac->createInstance(); 1532cdf0e10cSrcweir xContainer->insertByName(sKey, css::uno::makeAny(xInst)); 1533cdf0e10cSrcweir } 1534cdf0e10cSrcweir xContainer->getByName(sKey) >>= xKey; 1535cdf0e10cSrcweir 1536cdf0e10cSrcweir xKey->getByName(CFG_PROP_COMMAND) >>= xCommand; 1537cdf0e10cSrcweir ::rtl::OUString sLocale = impl_ts_getLocale().toISO(); 1538cdf0e10cSrcweir if ( !xCommand->hasByName(sLocale) ) 1539cdf0e10cSrcweir xCommand->insertByName(sLocale, css::uno::makeAny(sCommand)); 1540cdf0e10cSrcweir else 1541cdf0e10cSrcweir xCommand->replaceByName(sLocale, css::uno::makeAny(sCommand)); 1542cdf0e10cSrcweir } 1543cdf0e10cSrcweir 1544cdf0e10cSrcweir //----------------------------------------------- 1545cdf0e10cSrcweir void XCUBasedAcceleratorConfiguration::removeKeyFromConfiguration( const css::awt::KeyEvent& aKeyEvent, const sal_Bool bPreferred ) 1546cdf0e10cSrcweir { 1547cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess; 1548cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xContainer; 1549cdf0e10cSrcweir 1550cdf0e10cSrcweir if ( bPreferred ) 1551cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_PRIMARY) >>= xAccess; 1552cdf0e10cSrcweir else 1553cdf0e10cSrcweir m_xCfg->getByName(CFG_ENTRY_SECONDARY) >>= xAccess; 1554cdf0e10cSrcweir 1555cdf0e10cSrcweir if ( m_sGlobalOrModules.equals(CFG_ENTRY_GLOBAL) ) 1556cdf0e10cSrcweir xAccess->getByName(CFG_ENTRY_GLOBAL) >>= xContainer; 1557cdf0e10cSrcweir else if ( m_sGlobalOrModules.equals(CFG_ENTRY_MODULES) ) 1558cdf0e10cSrcweir { 1559cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xModules; 1560cdf0e10cSrcweir xAccess->getByName(CFG_ENTRY_MODULES) >>= xModules; 1561cdf0e10cSrcweir if ( !xModules->hasByName(m_sModuleCFG) ) 1562cdf0e10cSrcweir return; 1563cdf0e10cSrcweir xModules->getByName(m_sModuleCFG) >>= xContainer; 1564cdf0e10cSrcweir } 1565cdf0e10cSrcweir 1566cdf0e10cSrcweir const ::rtl::OUString sKey = lcl_getKeyString(m_rKeyMapping,aKeyEvent); 1567cdf0e10cSrcweir xContainer->removeByName(sKey); 1568cdf0e10cSrcweir } 1569cdf0e10cSrcweir 1570cdf0e10cSrcweir //----------------------------------------------- 1571cdf0e10cSrcweir void XCUBasedAcceleratorConfiguration::reloadChanged( const ::rtl::OUString& sPrimarySecondary, const ::rtl::OUString& sGlobalModules, const ::rtl::OUString& sModule, const ::rtl::OUString& sKey ) 1572cdf0e10cSrcweir { 1573cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xAccess; 1574cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xContainer; 1575cdf0e10cSrcweir 1576cdf0e10cSrcweir m_xCfg->getByName(sPrimarySecondary) >>= xAccess; 1577cdf0e10cSrcweir if ( sGlobalModules.equals(CFG_ENTRY_GLOBAL) ) 1578cdf0e10cSrcweir xAccess->getByName(CFG_ENTRY_GLOBAL) >>= xContainer; 1579cdf0e10cSrcweir else 1580cdf0e10cSrcweir { 1581cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xModules; 1582cdf0e10cSrcweir xAccess->getByName(CFG_ENTRY_MODULES) >>= xModules; 1583cdf0e10cSrcweir if ( !xModules->hasByName(sModule) ) 1584cdf0e10cSrcweir return; 1585cdf0e10cSrcweir xModules->getByName(sModule) >>= xContainer; 1586cdf0e10cSrcweir } 1587cdf0e10cSrcweir 1588cdf0e10cSrcweir css::awt::KeyEvent aKeyEvent; 1589cdf0e10cSrcweir ::rtl::OUString sKeyIdentifier; 1590cdf0e10cSrcweir 1591cdf0e10cSrcweir sal_Int32 nIndex = 0; 1592cdf0e10cSrcweir sKeyIdentifier = sKey.getToken(0, '_', nIndex); 1593cdf0e10cSrcweir aKeyEvent.KeyCode = m_rKeyMapping->mapIdentifierToCode(::rtl::OUString::createFromAscii("KEY_")+sKeyIdentifier); 1594cdf0e10cSrcweir 1595cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > sToken(3); 1596cdf0e10cSrcweir const sal_Int32 nToken = 3; 1597cdf0e10cSrcweir for (sal_Int32 i=0; i<nToken; ++i) 1598cdf0e10cSrcweir { 1599cdf0e10cSrcweir if ( nIndex < 0 ) 1600cdf0e10cSrcweir break; 1601cdf0e10cSrcweir 1602cdf0e10cSrcweir sToken[i] = sKey.getToken(0, '_', nIndex); 1603cdf0e10cSrcweir if (sToken[i].equalsAscii("SHIFT")) 1604cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::SHIFT; 1605cdf0e10cSrcweir else if (sToken[i].equalsAscii("MOD1")) 1606cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD1; 1607cdf0e10cSrcweir else if (sToken[i].equalsAscii("MOD2")) 1608cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD2; 1609cdf0e10cSrcweir else if (sToken[i].equalsAscii("MOD3")) 1610cdf0e10cSrcweir aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD3; 1611cdf0e10cSrcweir } 1612cdf0e10cSrcweir 1613cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xKey; 1614cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xCommand; 1615cdf0e10cSrcweir ::rtl::OUString sCommand; 1616cdf0e10cSrcweir 1617cdf0e10cSrcweir if (xContainer->hasByName(sKey)) 1618cdf0e10cSrcweir { 1619cdf0e10cSrcweir ::rtl::OUString sLocale = impl_ts_getLocale().toISO(); 1620cdf0e10cSrcweir xContainer->getByName(sKey) >>= xKey; 1621cdf0e10cSrcweir xKey->getByName(CFG_PROP_COMMAND) >>= xCommand; 1622cdf0e10cSrcweir xCommand->getByName(sLocale) >>= sCommand; 1623cdf0e10cSrcweir } 1624cdf0e10cSrcweir 1625cdf0e10cSrcweir if (sPrimarySecondary.equals(CFG_ENTRY_PRIMARY)) 1626cdf0e10cSrcweir { 1627cdf0e10cSrcweir if (sCommand.getLength() ==0) 1628cdf0e10cSrcweir m_aPrimaryReadCache.removeKey(aKeyEvent); 1629cdf0e10cSrcweir else 1630cdf0e10cSrcweir m_aPrimaryReadCache.setKeyCommandPair(aKeyEvent, sCommand); 1631cdf0e10cSrcweir } 1632cdf0e10cSrcweir else if (sPrimarySecondary.equals(CFG_ENTRY_SECONDARY)) 1633cdf0e10cSrcweir { 1634cdf0e10cSrcweir if (sCommand.getLength() ==0) 1635cdf0e10cSrcweir m_aSecondaryReadCache.removeKey(aKeyEvent); 1636cdf0e10cSrcweir else 1637cdf0e10cSrcweir m_aSecondaryReadCache.setKeyCommandPair(aKeyEvent, sCommand); 1638cdf0e10cSrcweir } 1639cdf0e10cSrcweir } 1640cdf0e10cSrcweir 1641cdf0e10cSrcweir //----------------------------------------------- 1642cdf0e10cSrcweir AcceleratorCache& XCUBasedAcceleratorConfiguration::impl_getCFG(sal_Bool bPreferred, sal_Bool bWriteAccessRequested) 1643cdf0e10cSrcweir { 1644cdf0e10cSrcweir // SAFE -> ---------------------------------- 1645cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock); 1646cdf0e10cSrcweir 1647cdf0e10cSrcweir if (bPreferred) 1648cdf0e10cSrcweir { 1649cdf0e10cSrcweir //create copy of our readonly-cache, if write access is forced ... but 1650cdf0e10cSrcweir //not still possible! 1651cdf0e10cSrcweir if ( 1652cdf0e10cSrcweir (bWriteAccessRequested) && 1653cdf0e10cSrcweir (!m_pPrimaryWriteCache ) 1654cdf0e10cSrcweir ) 1655cdf0e10cSrcweir { 1656cdf0e10cSrcweir m_pPrimaryWriteCache = new AcceleratorCache(m_aPrimaryReadCache); 1657cdf0e10cSrcweir } 1658cdf0e10cSrcweir 1659cdf0e10cSrcweir // in case, we have a writeable cache, we use it for reading too! 1660cdf0e10cSrcweir // Otherwhise the API user cant find its own changes ... 1661cdf0e10cSrcweir if (m_pPrimaryWriteCache) 1662cdf0e10cSrcweir return *m_pPrimaryWriteCache; 1663cdf0e10cSrcweir else 1664cdf0e10cSrcweir return m_aPrimaryReadCache; 1665cdf0e10cSrcweir } 1666cdf0e10cSrcweir 1667cdf0e10cSrcweir else 1668cdf0e10cSrcweir { 1669cdf0e10cSrcweir //create copy of our readonly-cache, if write access is forced ... but 1670cdf0e10cSrcweir //not still possible! 1671cdf0e10cSrcweir if ( 1672cdf0e10cSrcweir (bWriteAccessRequested) && 1673cdf0e10cSrcweir (!m_pSecondaryWriteCache ) 1674cdf0e10cSrcweir ) 1675cdf0e10cSrcweir { 1676cdf0e10cSrcweir m_pSecondaryWriteCache = new AcceleratorCache(m_aSecondaryReadCache); 1677cdf0e10cSrcweir } 1678cdf0e10cSrcweir 1679cdf0e10cSrcweir // in case, we have a writeable cache, we use it for reading too! 1680cdf0e10cSrcweir // Otherwhise the API user cant find its own changes ... 1681cdf0e10cSrcweir if (m_pSecondaryWriteCache) 1682cdf0e10cSrcweir return *m_pSecondaryWriteCache; 1683cdf0e10cSrcweir else 1684cdf0e10cSrcweir return m_aSecondaryReadCache; 1685cdf0e10cSrcweir } 1686cdf0e10cSrcweir 1687cdf0e10cSrcweir // <- SAFE ---------------------------------- 1688cdf0e10cSrcweir } 1689cdf0e10cSrcweir 1690cdf0e10cSrcweir //----------------------------------------------- 1691cdf0e10cSrcweir ::comphelper::Locale XCUBasedAcceleratorConfiguration::impl_ts_getLocale() const 1692cdf0e10cSrcweir { 1693cdf0e10cSrcweir static ::rtl::OUString LOCALE_PACKAGE = ::rtl::OUString::createFromAscii("/org.openoffice.Setup"); 1694cdf0e10cSrcweir static ::rtl::OUString LOCALE_PATH = ::rtl::OUString::createFromAscii("L10N" ); 1695cdf0e10cSrcweir static ::rtl::OUString LOCALE_KEY = ::rtl::OUString::createFromAscii("ooLocale" ); 1696cdf0e10cSrcweir 1697cdf0e10cSrcweir // SAFE -> ---------------------------------- 1698cdf0e10cSrcweir ReadGuard aReadLock(m_aLock); 1699cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 1700cdf0e10cSrcweir aReadLock.unlock(); 1701cdf0e10cSrcweir // <- SAFE ---------------------------------- 1702cdf0e10cSrcweir 1703cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xCFG = fpc::ConfigurationHelper::openConfig(xSMGR, LOCALE_PACKAGE, LOCALE_PATH, fpc::ConfigurationHelper::E_READONLY); 1704cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xProp (xCFG, css::uno::UNO_QUERY_THROW); 1705cdf0e10cSrcweir ::rtl::OUString sISOLocale; 1706cdf0e10cSrcweir xProp->getPropertyValue(LOCALE_KEY) >>= sISOLocale; 1707cdf0e10cSrcweir 1708cdf0e10cSrcweir if (!sISOLocale.getLength()) 1709cdf0e10cSrcweir return ::comphelper::Locale::EN_US(); 1710cdf0e10cSrcweir return ::comphelper::Locale(sISOLocale); 1711cdf0e10cSrcweir } 1712cdf0e10cSrcweir 1713cdf0e10cSrcweir } // namespace framework 1714