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