1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef __FRAMEWORK_ACCELERATORS_ACCELERATORCONFIGURATION_HXX_
29 #define __FRAMEWORK_ACCELERATORS_ACCELERATORCONFIGURATION_HXX_
31 //__________________________________________
34 #include <accelerators/istoragelistener.hxx>
35 #include <accelerators/presethandler.hxx>
36 #include <accelerators/acceleratorcache.hxx>
37 #include <accelerators/keymapping.hxx>
38 #include <macros/xinterface.hxx>
39 #include <macros/xtypeprovider.hxx>
40 #include <threadhelp/threadhelpbase.hxx>
44 //__________________________________________
47 #include <com/sun/star/container/XNameAccess.hpp>
48 #include <com/sun/star/lang/XTypeProvider.hpp>
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
51 #include <com/sun/star/ui/XUIConfiguration.hpp>
52 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
54 #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
55 #include <com/sun/star/io/XStream.hpp>
56 #include <com/sun/star/io/XInputStream.hpp>
57 #include <com/sun/star/io/XOutputStream.hpp>
58 #include <com/sun/star/util/XChangesListener.hpp>
60 // TODO use XPresetHandler interface instead if available
61 #include <com/sun/star/form/XReset.hpp>
63 //__________________________________________
65 #include <cppuhelper/propshlp.hxx>
66 #include <cppuhelper/weak.hxx>
67 #include <comphelper/locale.hxx>
68 #include <salhelper/singletonref.hxx>
70 //__________________________________________
75 //-----------------------------------------------
78 static const ::rtl::OUString CFG_ENTRY_PRIMARY
= ::rtl::OUString::createFromAscii("PrimaryKeys");
79 static const ::rtl::OUString CFG_ENTRY_SECONDARY
= ::rtl::OUString::createFromAscii("SecondaryKeys");
81 static const ::rtl::OUString CFG_ENTRY_GLOBAL
= ::rtl::OUString::createFromAscii("Global");
82 static const ::rtl::OUString CFG_ENTRY_MODULES
= ::rtl::OUString::createFromAscii("Modules");
84 static const ::rtl::OUString CFG_PROP_COMMAND
= ::rtl::OUString::createFromAscii("Command");
86 /** "global" type to make accelerator presets unique, so they can be used
87 in combination with the salhelper::SingletonRef mechanism! */
88 typedef PresetHandler AcceleratorPresets
;
90 //__________________________________________
92 implements a read/write access to the accelerator configuration.
94 class XMLBasedAcceleratorConfiguration
: protected ThreadHelpBase
// attention! Must be the first base class to guarentee right initialize lock ...
95 , public IStorageListener
96 , public ::cppu::OWeakObject
97 , public css::lang::XTypeProvider
98 , public css::form::XReset
// TODO use XPresetHandler instead if available
99 , public css::ui::XAcceleratorConfiguration
// => css::ui::XUIConfigurationPersistence
100 // css::ui::XUIConfigurationStorage
101 // css::ui::XUIConfiguration
103 //______________________________________
108 //---------------------------------------
109 /** the global uno service manager.
110 Must be used to create own needed services. */
111 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xSMGR
;
113 //---------------------------------------
115 i ) copy configuration files from the share to the user layer
116 ii ) provide access to these config files
117 iii) cache all sub storages on the path from the top to the bottom(!)
118 iv ) provide commit for changes. */
119 PresetHandler m_aPresetHandler
;
121 //---------------------------------------
122 /** contains the cached configuration data */
123 AcceleratorCache m_aReadCache
;
125 //---------------------------------------
126 /** used to implement the copy on write pattern! */
127 AcceleratorCache
* m_pWriteCache
;
129 //______________________________________
134 XMLBasedAcceleratorConfiguration( const css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
);
135 virtual ~XMLBasedAcceleratorConfiguration( );
137 //______________________________________
142 // XInterface, XTypeProvider
143 FWK_DECLARE_XINTERFACE
144 FWK_DECLARE_XTYPEPROVIDER
146 // XAcceleratorConfiguration
147 virtual css::uno::Sequence
< css::awt::KeyEvent
> SAL_CALL
getAllKeyEvents()
148 throw(css::uno::RuntimeException
);
150 virtual ::rtl::OUString SAL_CALL
getCommandByKeyEvent(const css::awt::KeyEvent
& aKeyEvent
)
151 throw(css::container::NoSuchElementException
,
152 css::uno::RuntimeException
);
154 virtual void SAL_CALL
setKeyEvent(const css::awt::KeyEvent
& aKeyEvent
,
155 const ::rtl::OUString
& sCommand
)
156 throw(css::lang::IllegalArgumentException
,
157 css::uno::RuntimeException
);
159 virtual void SAL_CALL
removeKeyEvent(const css::awt::KeyEvent
& aKeyEvent
)
160 throw(css::container::NoSuchElementException
,
161 css::uno::RuntimeException
);
163 virtual css::uno::Sequence
< css::awt::KeyEvent
> SAL_CALL
getKeyEventsByCommand(const ::rtl::OUString
& sCommand
)
164 throw(css::lang::IllegalArgumentException
,
165 css::container::NoSuchElementException
,
166 css::uno::RuntimeException
);
168 virtual css::uno::Sequence
< css::uno::Any
> SAL_CALL
getPreferredKeyEventsForCommandList(const css::uno::Sequence
< ::rtl::OUString
>& lCommandList
)
169 throw(css::lang::IllegalArgumentException
,
170 css::uno::RuntimeException
);
172 virtual void SAL_CALL
removeCommandFromAllKeyEvents(const ::rtl::OUString
& sCommand
)
173 throw(css::lang::IllegalArgumentException
,
174 css::container::NoSuchElementException
,
175 css::uno::RuntimeException
);
177 // XUIConfigurationPersistence
178 virtual void SAL_CALL
reload()
179 throw(css::uno::Exception
,
180 css::uno::RuntimeException
);
182 virtual void SAL_CALL
store()
183 throw(css::uno::Exception
,
184 css::uno::RuntimeException
);
186 virtual void SAL_CALL
storeToStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
)
187 throw(css::uno::Exception
,
188 css::uno::RuntimeException
);
190 virtual ::sal_Bool SAL_CALL
isModified()
191 throw(css::uno::RuntimeException
);
193 virtual ::sal_Bool SAL_CALL
isReadOnly()
194 throw(css::uno::RuntimeException
);
196 // XUIConfigurationStorage
197 virtual void SAL_CALL
setStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
)
198 throw(css::uno::RuntimeException
);
200 virtual ::sal_Bool SAL_CALL
hasStorage()
201 throw(css::uno::RuntimeException
);
204 virtual void SAL_CALL
addConfigurationListener(const css::uno::Reference
< css::ui::XUIConfigurationListener
>& xListener
)
205 throw(css::uno::RuntimeException
);
207 virtual void SAL_CALL
removeConfigurationListener(const css::uno::Reference
< css::ui::XUIConfigurationListener
>& xListener
)
208 throw(css::uno::RuntimeException
);
211 // TODO use XPresetHandler instead if available
212 virtual void SAL_CALL
reset()
213 throw(css::uno::RuntimeException
);
215 virtual void SAL_CALL
addResetListener(const css::uno::Reference
< css::form::XResetListener
>& xListener
)
216 throw(css::uno::RuntimeException
);
218 virtual void SAL_CALL
removeResetListener(const css::uno::Reference
< css::form::XResetListener
>& xListener
)
219 throw(css::uno::RuntimeException
);
222 virtual void changesOccured(const ::rtl::OUString
& sPath
);
224 //______________________________________
225 // helper for derived classes
229 //---------------------------------------
230 /** @short return the current office locale.
232 @descr We does not cache this value, because we are not listen
233 for changes on the configuration layer ...
235 @return ::comphelper::Locale
236 The current office locale.
238 ::comphelper::Locale
impl_ts_getLocale() const;
240 //______________________________________
245 //---------------------------------------
246 /** @short load a configuration set, using the given stream.
249 provides the XML structure as stream.
251 void impl_ts_load(const css::uno::Reference
< css::io::XInputStream
>& xStream
);
253 //---------------------------------------
254 /** @short save a configuration set, using the given stream.
257 the XML structure can be written there.
259 void impl_ts_save(const css::uno::Reference
< css::io::XOutputStream
>& xStream
);
261 //---------------------------------------
262 /** @short try to locate and open a sub storage.
264 @descr It search at the root storage for the specified
265 sub storage. If it exists - it will be opened.
266 By default this method tries to open the storage
267 for reading. But the calli can request a writeable
271 used to locate the sub storage.
274 relativ path of the sub storage.
277 force open of the sub storage in
278 write mode - instead of read mode, which
282 will be a css::io::XInpoutStream or a css::io::XOutputStream.
283 Depends from the parameter bWriteable!
285 css::uno::Reference
< css::uno::XInterface
> impl_ts_openSubStorage(const css::uno::Reference
< css::embed::XStorage
>& xRootStorage
,
286 const ::rtl::OUString
& sSubStorage
,
287 sal_Bool bOutStream
);
289 //---------------------------------------
290 /** @short returns a reference to one of our internal cache members.
292 @descr We implement the copy-on-write pattern. Doing so
293 we know two caches internaly. The second one is used
294 only, if the container was changed.
296 This method here returns access to one of these
297 caches - depending on the change state of this
298 configuration service.
300 @param bWriteAccessRequested
301 if the outside code whish to change the container
302 it must call this method with "TRUE". So the internal
303 cache can be prepared for that (means copy-on-write ...).
305 @return [AcceleratorCache]
306 c++ reference(!) to one of our internal caches.
308 AcceleratorCache
& impl_getCFG(sal_Bool bWriteAccessRequested
= sal_False
);
312 class XCUBasedAcceleratorConfiguration
: protected ThreadHelpBase
// attention! Must be the first base class to guarentee right initialize lock ...
313 , public ::cppu::OWeakObject
314 , public css::lang::XTypeProvider
315 , public css::util::XChangesListener
316 , public css::form::XReset
// TODO use XPresetHandler instead if available
317 , public css::ui::XAcceleratorConfiguration
// => css::ui::XUIConfigurationPersistence
318 // css::ui::XUIConfigurationStorage
319 // css::ui::XUIConfiguration
321 //______________________________________
326 //---------------------------------------
327 /** the global uno service manager.
328 Must be used to create own needed services. */
329 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xSMGR
;
331 css::uno::Reference
< css::container::XNameAccess
> m_xCfg
;
332 AcceleratorCache m_aPrimaryReadCache
;
333 AcceleratorCache m_aSecondaryReadCache
;
334 AcceleratorCache
* m_pPrimaryWriteCache
;
335 AcceleratorCache
* m_pSecondaryWriteCache
;
337 ::rtl::OUString m_sGlobalOrModules
;
338 ::rtl::OUString m_sModuleCFG
;
340 ::salhelper::SingletonRef
< KeyMapping
> m_rKeyMapping
;
342 //______________________________________
347 XCUBasedAcceleratorConfiguration( const css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
);
348 virtual ~XCUBasedAcceleratorConfiguration( );
350 //______________________________________
355 // XInterface, XTypeProvider
356 FWK_DECLARE_XINTERFACE
357 FWK_DECLARE_XTYPEPROVIDER
359 // XAcceleratorConfiguration
360 virtual css::uno::Sequence
< css::awt::KeyEvent
> SAL_CALL
getAllKeyEvents()
361 throw(css::uno::RuntimeException
);
363 virtual ::rtl::OUString SAL_CALL
getCommandByKeyEvent(const css::awt::KeyEvent
& aKeyEvent
)
364 throw(css::container::NoSuchElementException
,
365 css::uno::RuntimeException
);
367 virtual void SAL_CALL
setKeyEvent(const css::awt::KeyEvent
& aKeyEvent
,
368 const ::rtl::OUString
& sCommand
)
369 throw(css::lang::IllegalArgumentException
,
370 css::uno::RuntimeException
);
372 virtual void SAL_CALL
removeKeyEvent(const css::awt::KeyEvent
& aKeyEvent
)
373 throw(css::container::NoSuchElementException
,
374 css::uno::RuntimeException
);
376 virtual css::uno::Sequence
< css::awt::KeyEvent
> SAL_CALL
getKeyEventsByCommand(const ::rtl::OUString
& sCommand
)
377 throw(css::lang::IllegalArgumentException
,
378 css::container::NoSuchElementException
,
379 css::uno::RuntimeException
);
381 virtual css::uno::Sequence
< css::uno::Any
> SAL_CALL
getPreferredKeyEventsForCommandList(const css::uno::Sequence
< ::rtl::OUString
>& lCommandList
)
382 throw(css::lang::IllegalArgumentException
,
383 css::uno::RuntimeException
);
385 virtual void SAL_CALL
removeCommandFromAllKeyEvents(const ::rtl::OUString
& sCommand
)
386 throw(css::lang::IllegalArgumentException
,
387 css::container::NoSuchElementException
,
388 css::uno::RuntimeException
);
390 // XUIConfigurationPersistence
391 virtual void SAL_CALL
reload()
392 throw(css::uno::Exception
,
393 css::uno::RuntimeException
);
395 virtual void SAL_CALL
store()
396 throw(css::uno::Exception
,
397 css::uno::RuntimeException
);
399 virtual void SAL_CALL
storeToStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
)
400 throw(css::uno::Exception
,
401 css::uno::RuntimeException
);
403 virtual ::sal_Bool SAL_CALL
isModified()
404 throw(css::uno::RuntimeException
);
406 virtual ::sal_Bool SAL_CALL
isReadOnly()
407 throw(css::uno::RuntimeException
);
409 // XUIConfigurationStorage
410 virtual void SAL_CALL
setStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
)
411 throw(css::uno::RuntimeException
);
413 virtual ::sal_Bool SAL_CALL
hasStorage()
414 throw(css::uno::RuntimeException
);
417 virtual void SAL_CALL
addConfigurationListener(const css::uno::Reference
< css::ui::XUIConfigurationListener
>& xListener
)
418 throw(css::uno::RuntimeException
);
420 virtual void SAL_CALL
removeConfigurationListener(const css::uno::Reference
< css::ui::XUIConfigurationListener
>& xListener
)
421 throw(css::uno::RuntimeException
);
424 // TODO use XPresetHandler instead if available
425 virtual void SAL_CALL
reset()
426 throw(css::uno::RuntimeException
);
428 virtual void SAL_CALL
addResetListener(const css::uno::Reference
< css::form::XResetListener
>& xListener
)
429 throw(css::uno::RuntimeException
);
431 virtual void SAL_CALL
removeResetListener(const css::uno::Reference
< css::form::XResetListener
>& xListener
)
432 throw(css::uno::RuntimeException
);
434 // css.util.XChangesListener
435 virtual void SAL_CALL
changesOccurred(const css::util::ChangesEvent
& aEvent
)
436 throw(css::uno::RuntimeException
);
438 // css.lang.XEventListener
439 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
)
440 throw(css::uno::RuntimeException
);
442 //______________________________________
443 // helper for derived classes
447 //---------------------------------------
448 /** @short return the current office locale.
450 @descr We does not cache this value, because we are not listen
451 for changes on the configuration layer ...
453 @return ::comphelper::Locale
454 The current office locale.
456 ::comphelper::Locale
impl_ts_getLocale() const;
458 //______________________________________
463 void impl_ts_load(sal_Bool bPreferred
, const css::uno::Reference
< css::container::XNameAccess
>& xCfg
);
464 void impl_ts_save(sal_Bool bPreferred
, const css::uno::Reference
< css::container::XNameAccess
>& xCfg
);
466 void insertKeyToConfiguration(const css::awt::KeyEvent
& aKeyEvent
, const ::rtl::OUString
& sCommand
, const sal_Bool bPreferred
);
467 void removeKeyFromConfiguration(const css::awt::KeyEvent
& aKeyEvent
, const sal_Bool bPreferred
);
469 void reloadChanged(const ::rtl::OUString
& sPrimarySecondary
, const ::rtl::OUString
& sGlobalModules
, const ::rtl::OUString
& sModule
, const ::rtl::OUString
& sKey
);
470 AcceleratorCache
& impl_getCFG(sal_Bool bPreferred
, sal_Bool bWriteAccessRequested
= sal_False
);
474 } // namespace framework
476 #endif // __FRAMEWORK_ACCELERATORS_ACCELERATORCONFIGURATION_HXX_