diff options
Diffstat (limited to 'framework/source/inc/accelerators')
9 files changed, 2033 insertions, 0 deletions
diff --git a/framework/source/inc/accelerators/acceleratorcache.hxx b/framework/source/inc/accelerators/acceleratorcache.hxx new file mode 100644 index 000000000000..23ec86df8a00 --- /dev/null +++ b/framework/source/inc/accelerators/acceleratorcache.hxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_ACCELERATORS_ACCELERATORCACHE_HXX_ +#define __FRAMEWORK_ACCELERATORS_ACCELERATORCACHE_HXX_ + +//__________________________________________ +// own includes + +#include <threadhelp/threadhelpbase.hxx> +#include <general.h> +#include <stdtypes.h> + +//__________________________________________ +// interface includes + +#ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_ +#include <com/sun/star/awt/KeyEvent.hpp> +#endif + +//__________________________________________ +// other includes +#include <comphelper/sequenceasvector.hxx> + +//__________________________________________ +// definition + +namespace framework +{ + +//__________________________________________ +/** + @short implements a cache for any accelerator configuration. + + @descr Its implemented threadsafe, supports copy-on-write pattern + and a flush mechansim to support concurrent access to the same + configuration. + + copy-on-write ... How? Do the following: + */ +class AcceleratorCache : public ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ... +{ + //______________________________________ + // const, types + + public: + + //--------------------------------------- + /** TODO document me + commands -> keys + */ + typedef ::comphelper::SequenceAsVector< css::awt::KeyEvent > TKeyList; + typedef BaseHash< TKeyList > TCommand2Keys; + + //--------------------------------------- + /** TODO document me + keys -> commands + */ + typedef ::std::hash_map< css::awt::KeyEvent , + ::rtl::OUString , + KeyEventHashCode , + KeyEventEqualsFunc > TKey2Commands; + + //______________________________________ + // member + + private: + + //--------------------------------------- + /** map commands to keys in relation 1:n. + First key is interpreted as preferred one! */ + TCommand2Keys m_lCommand2Keys; + + //--------------------------------------- + /** map keys to commands in relation 1:1. */ + TKey2Commands m_lKey2Commands; + + //______________________________________ + // interface + + public: + + //--------------------------------------- + /** @short creates a new - but empty - cache instance. */ + AcceleratorCache(); + + //--------------------------------------- + /** @short make a copy of this cache. + @descr Used for the copy-on-write feature. + */ + AcceleratorCache(const AcceleratorCache& rCopy); + + //--------------------------------------- + /** @short does nothing real. */ + virtual ~AcceleratorCache(); + + //--------------------------------------- + /** @short write changes back to the original container. + + @param rCopy + the (changed!) copy, which should be written + back to this original container. + */ + virtual void takeOver(const AcceleratorCache& rCopy); + + //--------------------------------------- + /** TODO document me */ + virtual AcceleratorCache& operator=(const AcceleratorCache& rCopy); + + //--------------------------------------- + /** @short checks if the specified key exists. + + @param aKey + the key, which should be checked. + + @return [bool] + TRUE if the speicfied key exists inside this container. + */ + virtual sal_Bool hasKey(const css::awt::KeyEvent& aKey) const; + virtual sal_Bool hasCommand(const ::rtl::OUString& sCommand) const; + + //--------------------------------------- + /** TODO document me */ + virtual TKeyList getAllKeys() const; + + //--------------------------------------- + /** @short add a new or change an existing key-command pair + of this container. + + @param aKey + describe the key. + + @param sCommand + describe the command. + */ + virtual void setKeyCommandPair(const css::awt::KeyEvent& aKey , + const ::rtl::OUString& sCommand); + + //--------------------------------------- + /** @short returns the list of keys, which are registered + for this command. + + @param sCommand + describe the command. + + @return [TKeyList] + the list of registered keys. Can be empty! + */ + virtual TKeyList getKeysByCommand(const ::rtl::OUString& sCommand) const; + + //--------------------------------------- + /** TODO */ + virtual ::rtl::OUString getCommandByKey(const css::awt::KeyEvent& aKey) const; + + //--------------------------------------- + /** TODO */ + virtual void removeKey(const css::awt::KeyEvent& aKey); + virtual void removeCommand(const ::rtl::OUString& sCommand); +}; + +} // namespace framework + +#endif // __FRAMEWORK_ACCELERATORS_ACCELERATORCACHE_HXX_ diff --git a/framework/source/inc/accelerators/acceleratorconfiguration.hxx b/framework/source/inc/accelerators/acceleratorconfiguration.hxx new file mode 100644 index 000000000000..36eed6a6d534 --- /dev/null +++ b/framework/source/inc/accelerators/acceleratorconfiguration.hxx @@ -0,0 +1,476 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_ACCELERATORS_ACCELERATORCONFIGURATION_HXX_ +#define __FRAMEWORK_ACCELERATORS_ACCELERATORCONFIGURATION_HXX_ + +//__________________________________________ +// own includes + +#include <accelerators/istoragelistener.hxx> +#include <accelerators/presethandler.hxx> +#include <accelerators/acceleratorcache.hxx> +#include <accelerators/keymapping.hxx> +#include <macros/xinterface.hxx> +#include <macros/xtypeprovider.hxx> +#include <threadhelp/threadhelpbase.hxx> +#include <general.h> +#include <stdtypes.h> + +//__________________________________________ +// interface includes + +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/ui/XAcceleratorConfiguration.hpp> +#include <com/sun/star/ui/XUIConfiguration.hpp> +#include <com/sun/star/ui/XUIConfigurationPersistence.hpp> + +#include <com/sun/star/ui/XUIConfigurationStorage.hpp> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/util/XChangesListener.hpp> + +// TODO use XPresetHandler interface instead if available +#include <com/sun/star/form/XReset.hpp> + +//__________________________________________ +// other includes +#include <cppuhelper/propshlp.hxx> +#include <cppuhelper/weak.hxx> +#include <comphelper/locale.hxx> +#include <salhelper/singletonref.hxx> + +//__________________________________________ +// definition + +namespace framework +{ +//----------------------------------------------- +// Accelerators.xcu + +static const ::rtl::OUString CFG_ENTRY_PRIMARY = ::rtl::OUString::createFromAscii("PrimaryKeys"); +static const ::rtl::OUString CFG_ENTRY_SECONDARY = ::rtl::OUString::createFromAscii("SecondaryKeys"); + +static const ::rtl::OUString CFG_ENTRY_GLOBAL = ::rtl::OUString::createFromAscii("Global"); +static const ::rtl::OUString CFG_ENTRY_MODULES = ::rtl::OUString::createFromAscii("Modules"); + +static const ::rtl::OUString CFG_PROP_COMMAND = ::rtl::OUString::createFromAscii("Command"); + +/** "global" type to make accelerator presets unique, so they can be used + in combination with the salhelper::SingletonRef mechanism! */ +typedef PresetHandler AcceleratorPresets; + +//__________________________________________ +/** + implements a read/write access to the accelerator configuration. + */ +class XMLBasedAcceleratorConfiguration : protected ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ... + , public IStorageListener + , public ::cppu::OWeakObject + , public css::lang::XTypeProvider + , public css::form::XReset // TODO use XPresetHandler instead if available + , public css::ui::XAcceleratorConfiguration // => css::ui::XUIConfigurationPersistence + // css::ui::XUIConfigurationStorage + // css::ui::XUIConfiguration +{ + //______________________________________ + // member + + protected: + + //--------------------------------------- + /** the global uno service manager. + Must be used to create own needed services. */ + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + + //--------------------------------------- + /** used to: + i ) copy configuration files from the share to the user layer + ii ) provide access to these config files + iii) cache all sub storages on the path from the top to the bottom(!) + iv ) provide commit for changes. */ + PresetHandler m_aPresetHandler; + + //--------------------------------------- + /** contains the cached configuration data */ + AcceleratorCache m_aReadCache; + + //--------------------------------------- + /** used to implement the copy on write pattern! */ + AcceleratorCache* m_pWriteCache; + + //______________________________________ + // native interface! + + public: + + XMLBasedAcceleratorConfiguration( const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR ); + virtual ~XMLBasedAcceleratorConfiguration( ); + + //______________________________________ + // uno interface! + + public: + + // XInterface, XTypeProvider + FWK_DECLARE_XINTERFACE + FWK_DECLARE_XTYPEPROVIDER + + // XAcceleratorConfiguration + virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getAllKeyEvents() + throw(css::uno::RuntimeException); + + virtual ::rtl::OUString SAL_CALL getCommandByKeyEvent(const css::awt::KeyEvent& aKeyEvent) + throw(css::container::NoSuchElementException, + css::uno::RuntimeException ); + + virtual void SAL_CALL setKeyEvent(const css::awt::KeyEvent& aKeyEvent, + const ::rtl::OUString& sCommand ) + throw(css::lang::IllegalArgumentException, + css::uno::RuntimeException ); + + virtual void SAL_CALL removeKeyEvent(const css::awt::KeyEvent& aKeyEvent) + throw(css::container::NoSuchElementException, + css::uno::RuntimeException ); + + virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getKeyEventsByCommand(const ::rtl::OUString& sCommand) + throw(css::lang::IllegalArgumentException , + css::container::NoSuchElementException, + css::uno::RuntimeException ); + + virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPreferredKeyEventsForCommandList(const css::uno::Sequence< ::rtl::OUString >& lCommandList) + throw(css::lang::IllegalArgumentException , + css::uno::RuntimeException ); + + virtual void SAL_CALL removeCommandFromAllKeyEvents(const ::rtl::OUString& sCommand) + throw(css::lang::IllegalArgumentException , + css::container::NoSuchElementException, + css::uno::RuntimeException ); + + // XUIConfigurationPersistence + virtual void SAL_CALL reload() + throw(css::uno::Exception , + css::uno::RuntimeException); + + virtual void SAL_CALL store() + throw(css::uno::Exception , + css::uno::RuntimeException); + + virtual void SAL_CALL storeToStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) + throw(css::uno::Exception , + css::uno::RuntimeException); + + virtual ::sal_Bool SAL_CALL isModified() + throw(css::uno::RuntimeException); + + virtual ::sal_Bool SAL_CALL isReadOnly() + throw(css::uno::RuntimeException); + + // XUIConfigurationStorage + virtual void SAL_CALL setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) + throw(css::uno::RuntimeException); + + virtual ::sal_Bool SAL_CALL hasStorage() + throw(css::uno::RuntimeException); + + // XUIConfiguration + virtual void SAL_CALL addConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& xListener) + throw(css::uno::RuntimeException); + + virtual void SAL_CALL removeConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& xListener) + throw(css::uno::RuntimeException); + + // XReset + // TODO use XPresetHandler instead if available + virtual void SAL_CALL reset() + throw(css::uno::RuntimeException); + + virtual void SAL_CALL addResetListener(const css::uno::Reference< css::form::XResetListener >& xListener) + throw(css::uno::RuntimeException); + + virtual void SAL_CALL removeResetListener(const css::uno::Reference< css::form::XResetListener >& xListener) + throw(css::uno::RuntimeException); + + // IStorageListener + virtual void changesOccured(const ::rtl::OUString& sPath); + + //______________________________________ + // helper for derived classes + + protected: + + //--------------------------------------- + /** @short return the current office locale. + + @descr We does not cache this value, because we are not listen + for changes on the configuration layer ... + + @return ::comphelper::Locale + The current office locale. + */ + ::comphelper::Locale impl_ts_getLocale() const; + + //______________________________________ + // helper + + private: + + //--------------------------------------- + /** @short load a configuration set, using the given stream. + + @param xStream + provides the XML structure as stream. + */ + void impl_ts_load(const css::uno::Reference< css::io::XInputStream >& xStream); + + //--------------------------------------- + /** @short save a configuration set, using the given stream. + + @param xStream + the XML structure can be written there. + */ + void impl_ts_save(const css::uno::Reference< css::io::XOutputStream >& xStream); + + //--------------------------------------- + /** @short try to locate and open a sub storage. + + @descr It search at the root storage for the specified + sub storage. If it exists - it will be opened. + By default this method tries to open the storage + for reading. But the calli can request a writeable + storage. + + @param xRooStorage + used to locate the sub storage. + + @param sSubStorage + relativ path of the sub storage. + + @param bOutStream + force open of the sub storage in + write mode - instead of read mode, which + is the default. + + @return [XInterface] + will be a css::io::XInpoutStream or a css::io::XOutputStream. + Depends from the parameter bWriteable! + */ + css::uno::Reference< css::uno::XInterface > impl_ts_openSubStorage(const css::uno::Reference< css::embed::XStorage >& xRootStorage, + const ::rtl::OUString& sSubStorage , + sal_Bool bOutStream ); + + //--------------------------------------- + /** @short returns a reference to one of our internal cache members. + + @descr We implement the copy-on-write pattern. Doing so + we know two caches internaly. The second one is used + only, if the container was changed. + + This method here returns access to one of these + caches - depending on the change state of this + configuration service. + + @param bWriteAccessRequested + if the outside code whish to change the container + it must call this method with "TRUE". So the internal + cache can be prepared for that (means copy-on-write ...). + + @return [AcceleratorCache] + c++ reference(!) to one of our internal caches. + */ + AcceleratorCache& impl_getCFG(sal_Bool bWriteAccessRequested = sal_False); + +}; + +class XCUBasedAcceleratorConfiguration : protected ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ... + , public ::cppu::OWeakObject + , public css::lang::XTypeProvider + , public css::util::XChangesListener + , public css::form::XReset // TODO use XPresetHandler instead if available + , public css::ui::XAcceleratorConfiguration // => css::ui::XUIConfigurationPersistence + // css::ui::XUIConfigurationStorage + // css::ui::XUIConfiguration +{ + //______________________________________ + // member + + protected: + + //--------------------------------------- + /** the global uno service manager. + Must be used to create own needed services. */ + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + + css::uno::Reference< css::container::XNameAccess > m_xCfg; + AcceleratorCache m_aPrimaryReadCache; + AcceleratorCache m_aSecondaryReadCache; + AcceleratorCache* m_pPrimaryWriteCache; + AcceleratorCache* m_pSecondaryWriteCache; + + ::rtl::OUString m_sGlobalOrModules; + ::rtl::OUString m_sModuleCFG; + + ::salhelper::SingletonRef< KeyMapping > m_rKeyMapping; + + //______________________________________ + // native interface! + + public: + + XCUBasedAcceleratorConfiguration( const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR ); + virtual ~XCUBasedAcceleratorConfiguration( ); + + //______________________________________ + // uno interface! + + public: + + // XInterface, XTypeProvider + FWK_DECLARE_XINTERFACE + FWK_DECLARE_XTYPEPROVIDER + + // XAcceleratorConfiguration + virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getAllKeyEvents() + throw(css::uno::RuntimeException); + + virtual ::rtl::OUString SAL_CALL getCommandByKeyEvent(const css::awt::KeyEvent& aKeyEvent) + throw(css::container::NoSuchElementException, + css::uno::RuntimeException ); + + virtual void SAL_CALL setKeyEvent(const css::awt::KeyEvent& aKeyEvent, + const ::rtl::OUString& sCommand ) + throw(css::lang::IllegalArgumentException, + css::uno::RuntimeException ); + + virtual void SAL_CALL removeKeyEvent(const css::awt::KeyEvent& aKeyEvent) + throw(css::container::NoSuchElementException, + css::uno::RuntimeException ); + + virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getKeyEventsByCommand(const ::rtl::OUString& sCommand) + throw(css::lang::IllegalArgumentException , + css::container::NoSuchElementException, + css::uno::RuntimeException ); + + virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPreferredKeyEventsForCommandList(const css::uno::Sequence< ::rtl::OUString >& lCommandList) + throw(css::lang::IllegalArgumentException , + css::uno::RuntimeException ); + + virtual void SAL_CALL removeCommandFromAllKeyEvents(const ::rtl::OUString& sCommand) + throw(css::lang::IllegalArgumentException , + css::container::NoSuchElementException, + css::uno::RuntimeException ); + + // XUIConfigurationPersistence + virtual void SAL_CALL reload() + throw(css::uno::Exception , + css::uno::RuntimeException); + + virtual void SAL_CALL store() + throw(css::uno::Exception , + css::uno::RuntimeException); + + virtual void SAL_CALL storeToStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) + throw(css::uno::Exception , + css::uno::RuntimeException); + + virtual ::sal_Bool SAL_CALL isModified() + throw(css::uno::RuntimeException); + + virtual ::sal_Bool SAL_CALL isReadOnly() + throw(css::uno::RuntimeException); + + // XUIConfigurationStorage + virtual void SAL_CALL setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) + throw(css::uno::RuntimeException); + + virtual ::sal_Bool SAL_CALL hasStorage() + throw(css::uno::RuntimeException); + + // XUIConfiguration + virtual void SAL_CALL addConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& xListener) + throw(css::uno::RuntimeException); + + virtual void SAL_CALL removeConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& xListener) + throw(css::uno::RuntimeException); + + // XReset + // TODO use XPresetHandler instead if available + virtual void SAL_CALL reset() + throw(css::uno::RuntimeException); + + virtual void SAL_CALL addResetListener(const css::uno::Reference< css::form::XResetListener >& xListener) + throw(css::uno::RuntimeException); + + virtual void SAL_CALL removeResetListener(const css::uno::Reference< css::form::XResetListener >& xListener) + throw(css::uno::RuntimeException); + + // css.util.XChangesListener + virtual void SAL_CALL changesOccurred(const css::util::ChangesEvent& aEvent) + throw(css::uno::RuntimeException); + + // css.lang.XEventListener + virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) + throw(css::uno::RuntimeException); + + //______________________________________ + // helper for derived classes + + protected: + + //--------------------------------------- + /** @short return the current office locale. + + @descr We does not cache this value, because we are not listen + for changes on the configuration layer ... + + @return ::comphelper::Locale + The current office locale. + */ + ::comphelper::Locale impl_ts_getLocale() const; + + //______________________________________ + // helper + + private: + + void impl_ts_load(sal_Bool bPreferred, const css::uno::Reference< css::container::XNameAccess >& xCfg); + void impl_ts_save(sal_Bool bPreferred, const css::uno::Reference< css::container::XNameAccess >& xCfg); + + void insertKeyToConfiguration(const css::awt::KeyEvent& aKeyEvent, const ::rtl::OUString& sCommand, const sal_Bool bPreferred); + void removeKeyFromConfiguration(const css::awt::KeyEvent& aKeyEvent, const sal_Bool bPreferred); + + void reloadChanged(const ::rtl::OUString& sPrimarySecondary, const ::rtl::OUString& sGlobalModules, const ::rtl::OUString& sModule, const ::rtl::OUString& sKey); + AcceleratorCache& impl_getCFG(sal_Bool bPreferred, sal_Bool bWriteAccessRequested = sal_False); + +}; + +} // namespace framework + +#endif // __FRAMEWORK_ACCELERATORS_ACCELERATORCONFIGURATION_HXX_ diff --git a/framework/source/inc/accelerators/documentacceleratorconfiguration.hxx b/framework/source/inc/accelerators/documentacceleratorconfiguration.hxx new file mode 100644 index 000000000000..43714abeee60 --- /dev/null +++ b/framework/source/inc/accelerators/documentacceleratorconfiguration.hxx @@ -0,0 +1,124 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_ACCELERATORS_DOCUMENTACCELERATORCONFIGURATION_HXX_ +#define __FRAMEWORK_ACCELERATORS_DOCUMENTACCELERATORCONFIGURATION_HXX_ + +//__________________________________________ +// own includes + +#include <accelerators/acceleratorconfiguration.hxx> +#include <accelerators/istoragelistener.hxx> +#include <accelerators/presethandler.hxx> + +#include <macros/xinterface.hxx> +#include <macros/xtypeprovider.hxx> +#include <macros/xserviceinfo.hxx> + +//__________________________________________ +// interface includes +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/ui/XUIConfigurationStorage.hpp> + +//__________________________________________ +// other includes + +//__________________________________________ +// definition + +namespace framework +{ + +//__________________________________________ +/** + implements a read/write access to a document + based accelerator configuration. + */ +class DocumentAcceleratorConfiguration : public XMLBasedAcceleratorConfiguration + , public css::lang::XServiceInfo + , public css::lang::XInitialization +// , public css::ui::XUIConfigurationStorage +{ + //______________________________________ + // member + + private: + + //---------------------------------- + /** points to the root storage of the outside document, + where we can read/save our configuration data. */ + css::uno::Reference< css::embed::XStorage > m_xDocumentRoot; + + //______________________________________ + // interface + + public: + + //---------------------------------- + /** initialize this instance and fill the internal cache. + + @param xSMGR + reference to an uno service manager, which is used internaly. + */ + DocumentAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR); + virtual ~DocumentAcceleratorConfiguration(); + + // XInterface, XTypeProvider, XServiceInfo + FWK_DECLARE_XINTERFACE + FWK_DECLARE_XTYPEPROVIDER + DECLARE_XSERVICEINFO + + // XInitialization + virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any >& lArguments) + throw(css::uno::Exception , + css::uno::RuntimeException); + + // XUIConfigurationStorage + virtual void SAL_CALL setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) + throw(css::uno::RuntimeException); + + virtual sal_Bool SAL_CALL hasStorage() + throw(css::uno::RuntimeException); + + //______________________________________ + // helper + + private: + + //---------------------------------- + /** read all data into the cache. */ + void impl_ts_fillCache(); + + //---------------------------------- + /** forget all currently cached data AND(!) + forget all currently used storages. */ + void impl_ts_clearCache(); +}; + +} // namespace framework + +#endif // __FRAMEWORK_ACCELERATORS_DOCUMENTACCELERATORCONFIGURATION_HXX_ diff --git a/framework/source/inc/accelerators/globalacceleratorconfiguration.hxx b/framework/source/inc/accelerators/globalacceleratorconfiguration.hxx new file mode 100644 index 000000000000..f2b0b1d6afb6 --- /dev/null +++ b/framework/source/inc/accelerators/globalacceleratorconfiguration.hxx @@ -0,0 +1,109 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_ACCELERATORS_GLOBALACCELERATORCONFIGURATION_HXX_ +#define __FRAMEWORK_ACCELERATORS_GLOBALACCELERATORCONFIGURATION_HXX_ + +//__________________________________________ +// own includes + +#include <accelerators/acceleratorconfiguration.hxx> +#include <accelerators/presethandler.hxx> + +#ifndef __FRAMEWORK_MACROS_XINTERFACE_HXX_ +#include <macros/interface.hxx> +#endif +#include <macros/xtypeprovider.hxx> +#include <macros/xserviceinfo.hxx> + +//__________________________________________ +// interface includes + +#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ +#include <com/sun/star/lang/XInitialization.hpp> +#endif + +//__________________________________________ +// other includes + +//__________________________________________ +// definition + +namespace framework +{ + +//__________________________________________ +/** + implements a read/write access to the global + accelerator configuration. + */ +class GlobalAcceleratorConfiguration : public XCUBasedAcceleratorConfiguration + , public css::lang::XServiceInfo + , public css::lang::XInitialization +{ + //______________________________________ + // interface + + public: + + //---------------------------------- + /** initialize this instance and fill the internal cache. + + @param xSMGR + reference to an uno service manager, which is used internaly. + */ + GlobalAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR); + + //---------------------------------- + /** TODO */ + virtual ~GlobalAcceleratorConfiguration(); + + // XInterface, XTypeProvider, XServiceInfo + FWK_DECLARE_XINTERFACE + FWK_DECLARE_XTYPEPROVIDER + DECLARE_XSERVICEINFO + + // XInitialization + virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any >& lArguments) + throw (css::uno::Exception , + css::uno::RuntimeException); + + //______________________________________ + // helper + + private: + + ::rtl::OUString m_sLocale; + + //---------------------------------- + /** read all data into the cache. */ + void impl_ts_fillCache(); +}; + +} // namespace framework + +#endif // __FRAMEWORK_ACCELERATORS_GLOBALACCELERATORCONFIGURATION_HXX_ diff --git a/framework/source/inc/accelerators/istoragelistener.hxx b/framework/source/inc/accelerators/istoragelistener.hxx new file mode 100644 index 000000000000..44f0cc3cd5c5 --- /dev/null +++ b/framework/source/inc/accelerators/istoragelistener.hxx @@ -0,0 +1,64 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_ACCELERATORS_ISTORAGELISTENER_HXX_ +#define __FRAMEWORK_ACCELERATORS_ISTORAGELISTENER_HXX_ + +//__________________________________________ +// own includes + +#include <general.h> +#include <stdtypes.h> + +//__________________________________________ +// interface includes + +//__________________________________________ +// other includes + +//__________________________________________ +// definition + +namespace framework +{ + +//__________________________________________ +/** + TODO document me + */ +class IStorageListener +{ + public: + + //-------------------------------------- + /** @short TODO */ + virtual void changesOccured(const ::rtl::OUString& sPath) = 0; +}; + +} // namespace framework + +#endif // __FRAMEWORK_ACCELERATORS_ISTORAGELISTENER_HXX_ diff --git a/framework/source/inc/accelerators/keymapping.hxx b/framework/source/inc/accelerators/keymapping.hxx new file mode 100644 index 000000000000..e254378867b6 --- /dev/null +++ b/framework/source/inc/accelerators/keymapping.hxx @@ -0,0 +1,162 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_ACCELERATORS_KEYMAPPING_HXX_ +#define __FRAMEWORK_ACCELERATORS_KEYMAPPING_HXX_ + +//__________________________________________ +// own includes + +#include <general.h> +#include <stdtypes.h> + +//__________________________________________ +// interface includes +#include <com/sun/star/lang/IllegalArgumentException.hpp> + +//__________________________________________ +// other includes + +//__________________________________________ +// definition + +namespace framework +{ + +//__________________________________________ +/** + can be used to map key identifier to the + corresponding key codes ... + */ +class KeyMapping +{ + //______________________________________ + // const, types + + private: + + //--------------------------------------- + /** @short is used to map a key code + to the right key identifier, which is + used to make the xml file "human readable" + */ + struct KeyIdentifierInfo + { + sal_Int16 Code ; + const char* Identifier; + }; + + //--------------------------------------- + /** @short hash structure to map identifier to key codes. */ + typedef BaseHash< sal_Int16 > Identifier2CodeHash; + + //--------------------------------------- + /** @short hash structure to map key codes to identifier. */ + typedef ::std::hash_map< sal_Int16 , + ::rtl::OUString , + ShortHashCode , + ::std::equal_to< sal_Int16 > > Code2IdentifierHash; + + //______________________________________ + // member + + private: + + static KeyIdentifierInfo KeyIdentifierMap[]; + + //--------------------------------------- + /** @short hash to map identifier to key codes. */ + Identifier2CodeHash m_lIdentifierHash; + + //--------------------------------------- + /** @short hash to map key codes to identifier. */ + Code2IdentifierHash m_lCodeHash; + + //______________________________________ + // interface + + public: + + KeyMapping(); + virtual ~KeyMapping(); + + //---------------------------------- + /** @short return a suitable key code + for the specified key identifier. + + @param sIdentifier + string value, which describe the key. + + @return [css::awt::KeyEvent] + the corresponding key code as + short value. + + @throw [css::lang::IllegalArgumentException] + if the given identifier does not describe + a well known key code. + */ + virtual sal_uInt16 mapIdentifierToCode(const ::rtl::OUString& sIdentifier) + throw(css::lang::IllegalArgumentException); + + //---------------------------------- + /** @short return a suitable key identifier + for the specified key code. + + @param nCode + short value, which describe the key. + + @return The corresponding string identifier. + */ + virtual ::rtl::OUString mapCodeToIdentifier(sal_uInt16 nCode); + + //______________________________________ + // helper + + private: + + //---------------------------------- + /** @short check if the given string describe a numeric + value ... and convert it. + + @param sIdentifier + the string value, which should be converted. + + + @param rCode + contains the converted code, but is defined only + if this method returns TRUE! + + @return [boolean] + TRUE if convertion was successfully. + */ + sal_Bool impl_st_interpretIdentifierAsPureKeyCode(const ::rtl::OUString& sIdentifier, + sal_uInt16& rCode ); +}; + +} // namespace framework + +#endif // __FRAMEWORK_ACCELERATORS_KEYMAPPING_HXX_ diff --git a/framework/source/inc/accelerators/moduleacceleratorconfiguration.hxx b/framework/source/inc/accelerators/moduleacceleratorconfiguration.hxx new file mode 100644 index 000000000000..8d83dcd459b3 --- /dev/null +++ b/framework/source/inc/accelerators/moduleacceleratorconfiguration.hxx @@ -0,0 +1,115 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_ACCELERATORS_MODULEACCELERATORCONFIGURATION_HXX_ +#define __FRAMEWORK_ACCELERATORS_MODULEACCELERATORCONFIGURATION_HXX_ + +//__________________________________________ +// own includes + +#include <accelerators/acceleratorconfiguration.hxx> +#include <accelerators/presethandler.hxx> + +#ifndef __FRAMEWORK_MACROS_XINTERFACE_HXX_ +#include <macros/interface.hxx> +#endif +#include <macros/xtypeprovider.hxx> +#include <macros/xserviceinfo.hxx> + +//__________________________________________ +// interface includes +#include <com/sun/star/lang/XInitialization.hpp> + +//__________________________________________ +// other includes + +//__________________________________________ +// definition + +namespace framework +{ + +//__________________________________________ +/** + implements a read/write access to a module + dependend accelerator configuration. + */ +class ModuleAcceleratorConfiguration : public XCUBasedAcceleratorConfiguration + , public css::lang::XServiceInfo + , public css::lang::XInitialization +{ + //______________________________________ + // member + + private: + + //---------------------------------- + /** identify the application module, where this accelerator + configuration cache should work on. */ + ::rtl::OUString m_sModule; + ::rtl::OUString m_sLocale; + + //______________________________________ + // interface + + public: + + //---------------------------------- + /** initialize this instance and fill the internal cache. + + @param xSMGR + reference to an uno service manager, which is used internaly. + */ + ModuleAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR); + + //---------------------------------- + /** TODO */ + virtual ~ModuleAcceleratorConfiguration(); + + // XInterface, XTypeProvider, XServiceInfo + FWK_DECLARE_XINTERFACE + FWK_DECLARE_XTYPEPROVIDER + DECLARE_XSERVICEINFO + + // XInitialization + virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any >& lArguments) + throw(css::uno::Exception , + css::uno::RuntimeException); + + //______________________________________ + // helper + + private: + + //---------------------------------- + /** read all data into the cache. */ + void impl_ts_fillCache(); +}; + +} // namespace framework + +#endif // __FRAMEWORK_ACCELERATORS_MODULEACCELERATORCONFIGURATION_HXX_ diff --git a/framework/source/inc/accelerators/presethandler.hxx b/framework/source/inc/accelerators/presethandler.hxx new file mode 100644 index 000000000000..2d8f3ea57920 --- /dev/null +++ b/framework/source/inc/accelerators/presethandler.hxx @@ -0,0 +1,535 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_ACCELERATORS_PRESETHANDLER_HXX_ +#define __FRAMEWORK_ACCELERATORS_PRESETHANDLER_HXX_ + +//__________________________________________ +// own includes + +#include <accelerators/storageholder.hxx> +#include <threadhelp/threadhelpbase.hxx> +#include <general.h> +#include <stdtypes.h> + +//__________________________________________ +// interface includes + +#ifndef __COM_SUN_STAR_EMBED_XSTORAGE_HPP_ +#include <com/sun/star/embed/XStorage.hpp> +#endif + +#ifndef __COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif + +//__________________________________________ +// other includes +#include <comphelper/processfactory.hxx> +#include <salhelper/singletonref.hxx> +#include <comphelper/locale.hxx> + +//__________________________________________ +// definition + +namespace framework +{ + +//__________________________________________ +/** + TODO document me + + <layer>/global/<resourcetype>/<preset>.xml + <layer>/modules/<moduleid>/<resourcetype>/<preset>.xml + + RESOURCETYPE PRESET TARGET + (share) (user) + "accelerator" "default" "current" + "word" + "excel" + + "menubar" "default" "menubar" + + */ +class PresetHandler : private ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ... +{ + //------------------------------------------- + // const + + public: + + static ::rtl::OUString PRESET_DEFAULT(); + static ::rtl::OUString TARGET_CURRENT(); + + static ::rtl::OUString RESOURCETYPE_MENUBAR(); + static ::rtl::OUString RESOURCETYPE_TOOLBAR(); + static ::rtl::OUString RESOURCETYPE_ACCELERATOR(); + static ::rtl::OUString RESOURCETYPE_STATUSBAR(); + + //------------------------------------------- + // types + + public: + + //--------------------------------------- + /** @short this handler can provide different + types of configuration. + + @descr Means: a global or a module dependend + or ... configuration. + */ + enum EConfigType + { + E_GLOBAL, + E_MODULES, + E_DOCUMENT + }; + + private: + + //--------------------------------------- + /** @short because a concurrent access to the same storage from different implementations + isnt supported, we have to share it with others. + + @descr This struct makes it possible to use any shared storage + in combination with a SingletonRef<> template ... + + Attention: Because these struct is shared it must be + used within a synchronized section. Thats why this struct + uses a base class ThreadHelpBase and can be locked + from outside doing so! + */ + struct TSharedStorages : public ThreadHelpBase + { + public: + + StorageHolder m_lStoragesShare; + StorageHolder m_lStoragesUser; + + TSharedStorages() + : m_lStoragesShare(::comphelper::getProcessServiceFactory()) + , m_lStoragesUser (::comphelper::getProcessServiceFactory()) + {}; + + virtual ~TSharedStorages() {}; + }; + + //------------------------------------------- + // member + + private: + + //--------------------------------------- + /** @short can be used to create on needed uno resources. */ + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + + //--------------------------------------- + /** @short knows the type of provided configuration. + + @descr e.g. global, modules, ... + */ + EConfigType m_eConfigType; + + //--------------------------------------- + /** @short specify the type of resource, which configuration sets + must be provided here. + + @descr e.g. menubars, toolbars, accelerators + */ + ::rtl::OUString m_sResourceType; + + //--------------------------------------- + /** @short specify the application module for a module + dependend configuration. + + @descr Will be used only, if m_sResourceType is set to + "module". Further it must be a valid module identifier + then ... + */ + ::rtl::OUString m_sModule; + + //--------------------------------------- + /** @short provides access to the: + a) shared root storages + b) shared "inbetween" storages + of the share and user layer. */ + ::salhelper::SingletonRef< TSharedStorages > m_aSharedStorages; + + //--------------------------------------- + /** @short if we run in document mode, we cant use the global root storages! + We have to use a special document storage explicitly. */ + StorageHolder m_lDocumentStorages; + + //--------------------------------------- + /** @short holds the folder storage of the share layer alive, + where the current configuration set exists. + + @descr Note: If this preset handler works in document mode + this member is meaned relative to the document root ... + not to the share layer root! + + Further is defined, that m_xWorkingStorageUser + is equals to m_xWorkingStorageShare then! + */ + css::uno::Reference< css::embed::XStorage > m_xWorkingStorageShare; + + //--------------------------------------- + /** @short global language-independent storage + */ + css::uno::Reference< css::embed::XStorage > m_xWorkingStorageNoLang; + + //--------------------------------------- + /** @short holds the folder storage of the user layer alive, + where the current configuration set exists. + + @descr Note: If this preset handler works in document mode + this member is meaned relative to the document root ... + not to the user layer root! + + Further is defined, that m_xWorkingStorageUser + is equals to m_xWorkingStorageShare then! + */ + css::uno::Reference< css::embed::XStorage > m_xWorkingStorageUser; + + //--------------------------------------- + /** @short knows the names of all presets inside the current + working storage of the share layer. */ + OUStringList m_lPresets; + + //--------------------------------------- + /** @short knows the names of all targets inside the current + working storage of the user layer. */ + OUStringList m_lTargets; + + //--------------------------------------- + /** @short its the current office locale and will be used + to handle localized presets. + + @descr Default is "x-notranslate" which disable any + localized handling inside this class! */ + ::comphelper::Locale m_aLocale; + + //--------------------------------------- + /** @short knows the relative path from the root. */ + ::rtl::OUString m_sRelPathShare; + ::rtl::OUString m_sRelPathNoLang; + ::rtl::OUString m_sRelPathUser; + + //------------------------------------------- + // native interface + + public: + + //--------------------------------------- + /** @short does nothing real. + + @descr Because this class should be useable in combination + with ::salhelper::SingletonRef template this ctor + cant have any special parameters! + + @param xSMGR + points to an uno service manager, which is used internaly + to create own needed uno resources. + */ + PresetHandler(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); + + //--------------------------------------- + /** @short copy ctor */ + PresetHandler(const PresetHandler& rCopy); + + //--------------------------------------- + /** @short closes all open storages ... if user forgot that .-) */ + virtual ~PresetHandler(); + + //--------------------------------------- + /** @short free all currently cache(!) storages. */ + void forgetCachedStorages(); + + //--------------------------------------- + /** @short return access to the internaly used and cached root storage. + + @descr These root storages are the base of all further opened + presets and targets. They are provided here only, to support + older implementations, which base on them ... + + getOrCreate...() - What does it mean? + Such root storage will be created one times only and + cached then internaly till the last instance of such PresetHandler + dies. + + @return com::sun::star::embed::XStorage + which represent a root storage. + */ + css::uno::Reference< css::embed::XStorage > getOrCreateRootStorageShare(); + css::uno::Reference< css::embed::XStorage > getOrCreateRootStorageUser(); + + //--------------------------------------- + /** @short provides access to the current working storages. + + @descr Working storages are the "lowest" storages, where the + preset and target files exists. + + @return com::sun::star::embed::XStorage + which the current working storage. + */ + css::uno::Reference< css::embed::XStorage > getWorkingStorageShare(); + css::uno::Reference< css::embed::XStorage > getWorkingStorageUser(); + + //--------------------------------------- + /** @short check if there is a parent storage well known for + the specified child storage and return it. + + @param xChild + the child storage where a paranet storage should be searched for. + + @return com::sun::star::embed::XStorage + A valid storage if a paranet exists. NULL otherwise. + */ + css::uno::Reference< css::embed::XStorage > getParentStorageShare(const css::uno::Reference< css::embed::XStorage >& xChild); + css::uno::Reference< css::embed::XStorage > getParentStorageUser (const css::uno::Reference< css::embed::XStorage >& xChild); + + //--------------------------------------- + /** @short free all internal structures and let this handler + work on a new type of configuration sets. + + @param eConfigType + differ between global or module dependend configuration. + + @param sResourceType + differ between menubar/toolbar/accelerator/... configuration. + + @param sModule + if sResourceType is set to a module dependend configuration, + it address the current application module. + + @param xDocumentRoot + if sResourceType is set to E_DOCUMENT, this value points to the + root storage inside the document, where we can save our + configuration files. Note: Thats not the real root of the document ... + its only a sub storage. But we interpret it as our root storage. + + @param aLocale + in case this configuration supports localized entries, + the current locale must be set. + + Localzation will be represented as directory structure + of provided presets. Means: you call us with a preset name "default"; + and we use e.g. "/en-US/default.xml" internaly. + + If no localization exists for this preset set, this class + will work in default mode - means "no locale" - automaticly. + e.g. "/default.xml" + + @throw com::sun::star::uno::RuntimeException(!) + if the specified resource couldn't be located. + */ + void connectToResource( EConfigType eConfigType , + const ::rtl::OUString& sResourceType , + const ::rtl::OUString& sModule , + const css::uno::Reference< css::embed::XStorage >& xDocumentRoot , + const ::comphelper::Locale& aLocale = ::comphelper::Locale(::comphelper::Locale::X_NOTRANSLATE())); + + //--------------------------------------- + /** @short try to copy the specified preset from the share + layer to the user layer and establish it as the + specified target. + + @descr Means: copy share/.../<preset>.xml user/.../<target>.xml + Note: The target will be overwritten completly or + created as new by this operation! + + @param sPreset + the ALIAS name of an existing preset. + + @param sTarget + the ALIAS name of the target. + + @throw com::sun::star::container::NoSuchElementException + if the specified preset does not exists. + + @throw com::sun::star::io::IOException + if copying failed. + */ + void copyPresetToTarget(const ::rtl::OUString& sPreset, + const ::rtl::OUString& sTarget); + + //--------------------------------------- + /** @short open the specified preset as stream object + and return it. + + @descr Note: Because presets resist inside the share + layer, they will be opened readonly everytimes. + + @param sPreset + the ALIAS name of an existing preset. + + @param bNoLangGlobal + access the global language-independent storage instead of the preset storage + + @return The opened preset stream ... or NULL if the preset does not exists. + */ + css::uno::Reference< css::io::XStream > openPreset(const ::rtl::OUString& sPreset, + sal_Bool bUseNoLangGlobal = sal_False); + + //--------------------------------------- + /** @short open the specified target as stream object + and return it. + + @descr Note: Targets resist inside the user + layer. Normaly they are opened in read/write mode. + But it will be opened readonly automaticly if that isnt possible + (may be the file is write protected on the system ...). + + @param sTarget + the ALIAS name of the target. + + @param bCreateIfMissing + create target file, if it does not still exists. + Note: That does not means reseting of an existing file! + + @return The opened target stream ... or NULL if the target does not exists + or couldnt be created as new one. + */ + css::uno::Reference< css::io::XStream > openTarget(const ::rtl::OUString& sTarget , + sal_Bool bCreateIfMissing); + + //--------------------------------------- + /** @short do anything which is neccessary to flush all changes + back to disk. + + @descr We have to call commit on all cached sub storages on the + path from the root storage upside down to the working storage + (which are not realy used, but required to be holded alive!). + */ + void commitUserChanges(); + + //--------------------------------------- + /** TODO */ + void addStorageListener(IStorageListener* pListener); + void removeStorageListener(IStorageListener* pListener); + + //------------------------------------------- + // helper + + private: + + //--------------------------------------- + /** @short open a config path ignoring errors (catching exceptions). + + @descr We catch only normal exceptions here - no runtime exceptions. + + @param sPath + the configuration path, which should be opened. + + @param eMode + the open mode (READ/READWRITE) + + @param bShare + force using of the share layer instead of the user layer. + + @return An opened storage in case method was successfully - null otherwise. + */ + css::uno::Reference< css::embed::XStorage > impl_openPathIgnoringErrors(const ::rtl::OUString& sPath , + sal_Int32 eMode , + sal_Bool bShare); + + //--------------------------------------- + /** @short try to find the specified locale inside list of possible ones. + + @descr The lits of possible locale values was e.g. retrieved from the system + (configuration, directory listing etcpp). The locale normaly represent + the current office locale. This method search for a suitable item by using + different algorithm. + a) exact search + b) search with using fallbacks + + @param lLocalizedValues + list of ISO locale codes + + @param aLocale + [IN ] the current office locale, which should be searched inside lLocalizedValues. + [OUT] in case fallbacks was allowed, it contains afterwards the fallback locale. + + @param bAllowFallbacks + enable/disable using of fallbacks + + @return An iterator, which points directly into lLocalizedValue list. + As a negative result the special iterator lLocalizedValues.end() will be returned. + */ + ::std::vector< ::rtl::OUString >::const_iterator impl_findMatchingLocalizedValue(const ::std::vector< ::rtl::OUString >& lLocalizedValues, + ::comphelper::Locale& aLocale , + sal_Bool bAllowFallbacks ); + + //--------------------------------------- + /** @short open a config path ignoring errors (catching exceptions). + + @descr We catch only normal exceptions here - no runtime exceptions. + Further the path itself is tries in different versions (using locale + specific attributes). + e.g. "path/e-US" => "path/en" => "path/de" + + @param sPath + the configuration path, which should be opened. + Its further used as out parameter too, so we can return the localized + path to the calli! + + @param eMode + the open mode (READ/READWRITE) + + @param bShare + force using of the share layer instead of the user layer. + + @param aLocale + [IN ] contains the start locale for searching localized sub dirs. + [OUT] contains the locale of a found localized sub dir + + @param bAllowFallback + enable/disable fallback handling for locales + + @return An opened storage in case method was successfully - null otherwise. + */ + css::uno::Reference< css::embed::XStorage > impl_openLocalizedPathIgnoringErrors(::rtl::OUString& sPath , + sal_Int32 eMode , + sal_Bool bShare , + ::comphelper::Locale& aLocale , + sal_Bool bAllowFallback); + + //--------------------------------------- + /** @short returns the names of all sub storages of specified storage. + + @param xFolder + the base storage for this operation. + + @return [vector< string >] + a list of folder names. + */ + ::std::vector< ::rtl::OUString > impl_getSubFolderNames(const css::uno::Reference< css::embed::XStorage >& xFolder); +}; + +} // namespace framework + +#endif // __FRAMEWORK_ACCELERATORS_PRESETHANDLER_HXX_ diff --git a/framework/source/inc/accelerators/storageholder.hxx b/framework/source/inc/accelerators/storageholder.hxx new file mode 100644 index 000000000000..291fc29675eb --- /dev/null +++ b/framework/source/inc/accelerators/storageholder.hxx @@ -0,0 +1,261 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_ +#define __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_ + +//=============================================== +// own includes + +#include <accelerators/istoragelistener.hxx> +#include <threadhelp/threadhelpbase.hxx> +#include <general.h> +#include <stdtypes.h> + +//=============================================== +// interface includes + +#ifndef __COM_SUN_STAR_EMBED_XSTORAGE_HPP_ +#include <com/sun/star/embed/XStorage.hpp> +#endif + +#ifndef __COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif + +//=============================================== +// other includes + + +//=============================================== +// namespace + +namespace framework +{ + +#ifdef css + #error "Who defines css? I will use it as namespace alias inside header." +#else + #define css ::com::sun::star +#endif + +//=============================================== +// definitions + +//----------------------------------------------- +/** + TODO document me + */ +class StorageHolder : private ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ... +{ + //------------------------------------------- + // types + public: + + /** @short TODO */ + typedef ::std::vector< css::uno::Reference< css::embed::XStorage > > TStorageList; + + typedef ::std::vector< IStorageListener* > TStorageListenerList; + + struct TStorageInfo + { + public: + css::uno::Reference< css::embed::XStorage > Storage; + sal_Int32 UseCount; + TStorageListenerList Listener; + + TStorageInfo() + : UseCount(0) + {} + }; + + /** @short TODO */ + typedef ::std::hash_map< ::rtl::OUString , + TStorageInfo , + ::rtl::OUStringHash , + ::std::equal_to< ::rtl::OUString > > TPath2StorageInfo; + + //------------------------------------------- + // member + private: + + /** @short TODO */ + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + + /** @short TODO */ + css::uno::Reference< css::embed::XStorage > m_xRoot; + + /** @short TODO */ + TPath2StorageInfo m_lStorages; + + //------------------------------------------- + // interface + public: + + //--------------------------------------- + /** @short TODO + */ + StorageHolder(); + + //--------------------------------------- + /** @short TODO + */ + StorageHolder(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); + + //--------------------------------------- + /** @short TODO + */ + virtual ~StorageHolder(); + + //--------------------------------------- + /** @short TODO + */ + virtual void forgetCachedStorages(); + + //--------------------------------------- + /** @short TODO + */ + virtual void setRootStorage(const css::uno::Reference< css::embed::XStorage >& xRoot); + + //--------------------------------------- + /** @short TODO + */ + virtual css::uno::Reference< css::embed::XStorage > getRootStorage() const; + + //--------------------------------------- + /** @short TODO + open or get! + */ + virtual css::uno::Reference< css::embed::XStorage > openPath(const ::rtl::OUString& sPath , + sal_Int32 nOpenMode); + + //--------------------------------------- + /** @short TODO + */ + virtual StorageHolder::TStorageList getAllPathStorages(const ::rtl::OUString& sPath); + + //--------------------------------------- + /** @short TODO + */ + virtual void commitPath(const ::rtl::OUString& sPath); + + //--------------------------------------- + /** @short TODO + */ + virtual void closePath(const ::rtl::OUString& sPath); + + //--------------------------------------- + /** @short TODO + */ + virtual void notifyPath(const ::rtl::OUString& sPath); + + //--------------------------------------- + /** @short TODO + */ + virtual void addStorageListener( IStorageListener* pListener, + const ::rtl::OUString& sPath ); + + //--------------------------------------- + /** @short TODO + */ + virtual void removeStorageListener( IStorageListener* pListener, + const ::rtl::OUString& sPath ); + + //--------------------------------------- + /** @short TODO + */ + virtual ::rtl::OUString getPathOfStorage(const css::uno::Reference< css::embed::XStorage >& xStorage); + + //--------------------------------------- + /** @short TODO + */ + virtual css::uno::Reference< css::embed::XStorage > getParentStorage(const css::uno::Reference< css::embed::XStorage >& xChild); + + //--------------------------------------- + /** @short TODO + */ + virtual css::uno::Reference< css::embed::XStorage > getParentStorage(const ::rtl::OUString& sChildPath); + + //--------------------------------------- + /** @short TODO + */ + virtual void operator=(const StorageHolder& rCopy); + + //--------------------------------------- + /** @short opens a sub element of the specified base storage. + + @descr First this method try to open the requested sub element + using the given open mode. If it failed there is second step, + which tries to do the same again ... but removing a might existing + WRITE flag from the open mode. The user can supress this fallback + handling by setting the parameter bAllowFallback to FALSE. + + @param xBaseStorage + the storage, where the sub element should be searched. + + @param sSubElement + the full name of the sub element. + e.g. "default.xml" + + @param eOpenMode + a flag field, which set the open mode for this operation. + + @param bAllowFallback + if eOpenMode contains an ELEMENT_WRITE flag this parameter + allow to remove it and try it with the rest of eOpenMode flags + again. + */ + static css::uno::Reference< css::embed::XStorage > openSubStorageWithFallback(const css::uno::Reference< css::embed::XStorage >& xBaseStorage , + const ::rtl::OUString& sSubStorage , + sal_Int32 eOpenMode , + sal_Bool bAllowFallback); + + static css::uno::Reference< css::io::XStream > openSubStreamWithFallback(const css::uno::Reference< css::embed::XStorage >& xBaseStorage , + const ::rtl::OUString& sSubStream , + sal_Int32 eOpenMode , + sal_Bool bAllowFallback); + + //--------------------------------------- + // helper + private: + + //----------------------------------- + /** @short TODO + */ + static ::rtl::OUString impl_st_normPath(const ::rtl::OUString& sPath); + + //----------------------------------- + /** @short TODO + */ + static OUStringList impl_st_parsePath(const ::rtl::OUString& sPath); +}; + +#undef css // dont let it out! + +} // namespace framework + +#endif // __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_ |