1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: acceleratorconfiguration.hxx,v $
10 * $Revision: 1.5.300.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_ACCELERATORS_ACCELERATORCONFIGURATION_HXX_
32 #define __FRAMEWORK_ACCELERATORS_ACCELERATORCONFIGURATION_HXX_
34 //__________________________________________
37 #include <accelerators/istoragelistener.hxx>
38 #include <accelerators/presethandler.hxx>
39 #include <accelerators/acceleratorcache.hxx>
40 #include <accelerators/keymapping.hxx>
41 #include <macros/xinterface.hxx>
42 #include <macros/xtypeprovider.hxx>
43 #include <threadhelp/threadhelpbase.hxx>
47 //__________________________________________
50 #include <com/sun/star/container/XNameAccess.hpp>
51 #include <com/sun/star/lang/XTypeProvider.hpp>
52 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53 #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
54 #include <com/sun/star/ui/XUIConfiguration.hpp>
55 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
57 #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
58 #include <com/sun/star/io/XStream.hpp>
59 #include <com/sun/star/io/XInputStream.hpp>
60 #include <com/sun/star/io/XOutputStream.hpp>
61 #include <com/sun/star/util/XChangesListener.hpp>
63 // TODO use XPresetHandler interface instead if available
64 #include <com/sun/star/form/XReset.hpp>
66 //__________________________________________
68 #include <cppuhelper/propshlp.hxx>
69 #include <cppuhelper/weak.hxx>
70 #include <comphelper/locale.hxx>
71 #include <salhelper/singletonref.hxx>
73 //__________________________________________
78 //-----------------------------------------------
81 static const ::rtl::OUString CFG_ENTRY_PRIMARY
= ::rtl::OUString::createFromAscii("PrimaryKeys");
82 static const ::rtl::OUString CFG_ENTRY_SECONDARY
= ::rtl::OUString::createFromAscii("SecondaryKeys");
84 static const ::rtl::OUString CFG_ENTRY_GLOBAL
= ::rtl::OUString::createFromAscii("Global");
85 static const ::rtl::OUString CFG_ENTRY_MODULES
= ::rtl::OUString::createFromAscii("Modules");
87 static const ::rtl::OUString CFG_PROP_COMMAND
= ::rtl::OUString::createFromAscii("Command");
89 /** "global" type to make accelerator presets unique, so they can be used
90 in combination with the salhelper::SingletonRef mechanism! */
91 typedef PresetHandler AcceleratorPresets
;
93 //__________________________________________
95 implements a read/write access to the accelerator configuration.
97 class XMLBasedAcceleratorConfiguration
: protected ThreadHelpBase
// attention! Must be the first base class to guarentee right initialize lock ...
98 , public IStorageListener
99 , public ::cppu::OWeakObject
100 , public css::lang::XTypeProvider
101 , public css::form::XReset
// TODO use XPresetHandler instead if available
102 , public css::ui::XAcceleratorConfiguration
// => css::ui::XUIConfigurationPersistence
103 // css::ui::XUIConfigurationStorage
104 // css::ui::XUIConfiguration
106 //______________________________________
111 //---------------------------------------
112 /** the global uno service manager.
113 Must be used to create own needed services. */
114 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xSMGR
;
116 //---------------------------------------
118 i ) copy configuration files from the share to the user layer
119 ii ) provide access to these config files
120 iii) cache all sub storages on the path from the top to the bottom(!)
121 iv ) provide commit for changes. */
122 PresetHandler m_aPresetHandler
;
124 //---------------------------------------
125 /** contains the cached configuration data */
126 AcceleratorCache m_aReadCache
;
128 //---------------------------------------
129 /** used to implement the copy on write pattern! */
130 AcceleratorCache
* m_pWriteCache
;
132 //______________________________________
137 XMLBasedAcceleratorConfiguration( const css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
);
138 virtual ~XMLBasedAcceleratorConfiguration( );
140 //______________________________________
145 // XInterface, XTypeProvider
146 FWK_DECLARE_XINTERFACE
147 FWK_DECLARE_XTYPEPROVIDER
149 // XAcceleratorConfiguration
150 virtual css::uno::Sequence
< css::awt::KeyEvent
> SAL_CALL
getAllKeyEvents()
151 throw(css::uno::RuntimeException
);
153 virtual ::rtl::OUString SAL_CALL
getCommandByKeyEvent(const css::awt::KeyEvent
& aKeyEvent
)
154 throw(css::container::NoSuchElementException
,
155 css::uno::RuntimeException
);
157 virtual void SAL_CALL
setKeyEvent(const css::awt::KeyEvent
& aKeyEvent
,
158 const ::rtl::OUString
& sCommand
)
159 throw(css::lang::IllegalArgumentException
,
160 css::uno::RuntimeException
);
162 virtual void SAL_CALL
removeKeyEvent(const css::awt::KeyEvent
& aKeyEvent
)
163 throw(css::container::NoSuchElementException
,
164 css::uno::RuntimeException
);
166 virtual css::uno::Sequence
< css::awt::KeyEvent
> SAL_CALL
getKeyEventsByCommand(const ::rtl::OUString
& sCommand
)
167 throw(css::lang::IllegalArgumentException
,
168 css::container::NoSuchElementException
,
169 css::uno::RuntimeException
);
171 virtual css::uno::Sequence
< css::uno::Any
> SAL_CALL
getPreferredKeyEventsForCommandList(const css::uno::Sequence
< ::rtl::OUString
>& lCommandList
)
172 throw(css::lang::IllegalArgumentException
,
173 css::uno::RuntimeException
);
175 virtual void SAL_CALL
removeCommandFromAllKeyEvents(const ::rtl::OUString
& sCommand
)
176 throw(css::lang::IllegalArgumentException
,
177 css::container::NoSuchElementException
,
178 css::uno::RuntimeException
);
180 // XUIConfigurationPersistence
181 virtual void SAL_CALL
reload()
182 throw(css::uno::Exception
,
183 css::uno::RuntimeException
);
185 virtual void SAL_CALL
store()
186 throw(css::uno::Exception
,
187 css::uno::RuntimeException
);
189 virtual void SAL_CALL
storeToStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
)
190 throw(css::uno::Exception
,
191 css::uno::RuntimeException
);
193 virtual ::sal_Bool SAL_CALL
isModified()
194 throw(css::uno::RuntimeException
);
196 virtual ::sal_Bool SAL_CALL
isReadOnly()
197 throw(css::uno::RuntimeException
);
199 // XUIConfigurationStorage
200 virtual void SAL_CALL
setStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
)
201 throw(css::uno::RuntimeException
);
203 virtual ::sal_Bool SAL_CALL
hasStorage()
204 throw(css::uno::RuntimeException
);
207 virtual void SAL_CALL
addConfigurationListener(const css::uno::Reference
< css::ui::XUIConfigurationListener
>& xListener
)
208 throw(css::uno::RuntimeException
);
210 virtual void SAL_CALL
removeConfigurationListener(const css::uno::Reference
< css::ui::XUIConfigurationListener
>& xListener
)
211 throw(css::uno::RuntimeException
);
214 // TODO use XPresetHandler instead if available
215 virtual void SAL_CALL
reset()
216 throw(css::uno::RuntimeException
);
218 virtual void SAL_CALL
addResetListener(const css::uno::Reference
< css::form::XResetListener
>& xListener
)
219 throw(css::uno::RuntimeException
);
221 virtual void SAL_CALL
removeResetListener(const css::uno::Reference
< css::form::XResetListener
>& xListener
)
222 throw(css::uno::RuntimeException
);
225 virtual void changesOccured(const ::rtl::OUString
& sPath
);
227 //______________________________________
228 // helper for derived classes
232 //---------------------------------------
233 /** @short return the current office locale.
235 @descr We does not cache this value, because we are not listen
236 for changes on the configuration layer ...
238 @return ::comphelper::Locale
239 The current office locale.
241 ::comphelper::Locale
impl_ts_getLocale() const;
243 //______________________________________
248 //---------------------------------------
249 /** @short load a configuration set, using the given stream.
252 provides the XML structure as stream.
254 void impl_ts_load(const css::uno::Reference
< css::io::XInputStream
>& xStream
);
256 //---------------------------------------
257 /** @short save a configuration set, using the given stream.
260 the XML structure can be written there.
262 void impl_ts_save(const css::uno::Reference
< css::io::XOutputStream
>& xStream
);
264 //---------------------------------------
265 /** @short try to locate and open a sub storage.
267 @descr It search at the root storage for the specified
268 sub storage. If it exists - it will be opened.
269 By default this method tries to open the storage
270 for reading. But the calli can request a writeable
274 used to locate the sub storage.
277 relativ path of the sub storage.
280 force open of the sub storage in
281 write mode - instead of read mode, which
285 will be a css::io::XInpoutStream or a css::io::XOutputStream.
286 Depends from the parameter bWriteable!
288 css::uno::Reference
< css::uno::XInterface
> impl_ts_openSubStorage(const css::uno::Reference
< css::embed::XStorage
>& xRootStorage
,
289 const ::rtl::OUString
& sSubStorage
,
290 sal_Bool bOutStream
);
292 //---------------------------------------
293 /** @short returns a reference to one of our internal cache members.
295 @descr We implement the copy-on-write pattern. Doing so
296 we know two caches internaly. The second one is used
297 only, if the container was changed.
299 This method here returns access to one of these
300 caches - depending on the change state of this
301 configuration service.
303 @param bWriteAccessRequested
304 if the outside code whish to change the container
305 it must call this method with "TRUE". So the internal
306 cache can be prepared for that (means copy-on-write ...).
308 @return [AcceleratorCache]
309 c++ reference(!) to one of our internal caches.
311 AcceleratorCache
& impl_getCFG(sal_Bool bWriteAccessRequested
= sal_False
);
315 class XCUBasedAcceleratorConfiguration
: protected ThreadHelpBase
// attention! Must be the first base class to guarentee right initialize lock ...
316 , public ::cppu::OWeakObject
317 , public css::lang::XTypeProvider
318 , public css::util::XChangesListener
319 , public css::form::XReset
// TODO use XPresetHandler instead if available
320 , public css::ui::XAcceleratorConfiguration
// => css::ui::XUIConfigurationPersistence
321 // css::ui::XUIConfigurationStorage
322 // css::ui::XUIConfiguration
324 //______________________________________
329 //---------------------------------------
330 /** the global uno service manager.
331 Must be used to create own needed services. */
332 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xSMGR
;
334 css::uno::Reference
< css::container::XNameAccess
> m_xCfg
;
335 AcceleratorCache m_aPrimaryReadCache
;
336 AcceleratorCache m_aSecondaryReadCache
;
337 AcceleratorCache
* m_pPrimaryWriteCache
;
338 AcceleratorCache
* m_pSecondaryWriteCache
;
340 ::rtl::OUString m_sGlobalOrModules
;
341 ::rtl::OUString m_sModuleCFG
;
343 ::salhelper::SingletonRef
< KeyMapping
> m_rKeyMapping
;
345 //______________________________________
350 XCUBasedAcceleratorConfiguration( const css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
);
351 virtual ~XCUBasedAcceleratorConfiguration( );
353 //______________________________________
358 // XInterface, XTypeProvider
359 FWK_DECLARE_XINTERFACE
360 FWK_DECLARE_XTYPEPROVIDER
362 // XAcceleratorConfiguration
363 virtual css::uno::Sequence
< css::awt::KeyEvent
> SAL_CALL
getAllKeyEvents()
364 throw(css::uno::RuntimeException
);
366 virtual ::rtl::OUString SAL_CALL
getCommandByKeyEvent(const css::awt::KeyEvent
& aKeyEvent
)
367 throw(css::container::NoSuchElementException
,
368 css::uno::RuntimeException
);
370 virtual void SAL_CALL
setKeyEvent(const css::awt::KeyEvent
& aKeyEvent
,
371 const ::rtl::OUString
& sCommand
)
372 throw(css::lang::IllegalArgumentException
,
373 css::uno::RuntimeException
);
375 virtual void SAL_CALL
removeKeyEvent(const css::awt::KeyEvent
& aKeyEvent
)
376 throw(css::container::NoSuchElementException
,
377 css::uno::RuntimeException
);
379 virtual css::uno::Sequence
< css::awt::KeyEvent
> SAL_CALL
getKeyEventsByCommand(const ::rtl::OUString
& sCommand
)
380 throw(css::lang::IllegalArgumentException
,
381 css::container::NoSuchElementException
,
382 css::uno::RuntimeException
);
384 virtual css::uno::Sequence
< css::uno::Any
> SAL_CALL
getPreferredKeyEventsForCommandList(const css::uno::Sequence
< ::rtl::OUString
>& lCommandList
)
385 throw(css::lang::IllegalArgumentException
,
386 css::uno::RuntimeException
);
388 virtual void SAL_CALL
removeCommandFromAllKeyEvents(const ::rtl::OUString
& sCommand
)
389 throw(css::lang::IllegalArgumentException
,
390 css::container::NoSuchElementException
,
391 css::uno::RuntimeException
);
393 // XUIConfigurationPersistence
394 virtual void SAL_CALL
reload()
395 throw(css::uno::Exception
,
396 css::uno::RuntimeException
);
398 virtual void SAL_CALL
store()
399 throw(css::uno::Exception
,
400 css::uno::RuntimeException
);
402 virtual void SAL_CALL
storeToStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
)
403 throw(css::uno::Exception
,
404 css::uno::RuntimeException
);
406 virtual ::sal_Bool SAL_CALL
isModified()
407 throw(css::uno::RuntimeException
);
409 virtual ::sal_Bool SAL_CALL
isReadOnly()
410 throw(css::uno::RuntimeException
);
412 // XUIConfigurationStorage
413 virtual void SAL_CALL
setStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
)
414 throw(css::uno::RuntimeException
);
416 virtual ::sal_Bool SAL_CALL
hasStorage()
417 throw(css::uno::RuntimeException
);
420 virtual void SAL_CALL
addConfigurationListener(const css::uno::Reference
< css::ui::XUIConfigurationListener
>& xListener
)
421 throw(css::uno::RuntimeException
);
423 virtual void SAL_CALL
removeConfigurationListener(const css::uno::Reference
< css::ui::XUIConfigurationListener
>& xListener
)
424 throw(css::uno::RuntimeException
);
427 // TODO use XPresetHandler instead if available
428 virtual void SAL_CALL
reset()
429 throw(css::uno::RuntimeException
);
431 virtual void SAL_CALL
addResetListener(const css::uno::Reference
< css::form::XResetListener
>& xListener
)
432 throw(css::uno::RuntimeException
);
434 virtual void SAL_CALL
removeResetListener(const css::uno::Reference
< css::form::XResetListener
>& xListener
)
435 throw(css::uno::RuntimeException
);
437 // css.util.XChangesListener
438 virtual void SAL_CALL
changesOccurred(const css::util::ChangesEvent
& aEvent
)
439 throw(css::uno::RuntimeException
);
441 // css.lang.XEventListener
442 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
)
443 throw(css::uno::RuntimeException
);
445 //______________________________________
446 // helper for derived classes
450 //---------------------------------------
451 /** @short return the current office locale.
453 @descr We does not cache this value, because we are not listen
454 for changes on the configuration layer ...
456 @return ::comphelper::Locale
457 The current office locale.
459 ::comphelper::Locale
impl_ts_getLocale() const;
461 //______________________________________
466 void impl_ts_load(sal_Bool bPreferred
, const css::uno::Reference
< css::container::XNameAccess
>& xCfg
);
467 void impl_ts_save(sal_Bool bPreferred
, const css::uno::Reference
< css::container::XNameAccess
>& xCfg
);
469 void insertKeyToConfiguration(const css::awt::KeyEvent
& aKeyEvent
, const ::rtl::OUString
& sCommand
, const sal_Bool bPreferred
);
470 void removeKeyFromConfiguration(const css::awt::KeyEvent
& aKeyEvent
, const sal_Bool bPreferred
);
472 void reloadChanged(const ::rtl::OUString
& sPrimarySecondary
, const ::rtl::OUString
& sGlobalModules
, const ::rtl::OUString
& sModule
, const ::rtl::OUString
& sKey
);
473 AcceleratorCache
& impl_getCFG(sal_Bool bPreferred
, sal_Bool bWriteAccessRequested
= sal_False
);
477 } // namespace framework
479 #endif // __FRAMEWORK_ACCELERATORS_ACCELERATORCONFIGURATION_HXX_