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