merged tag ooo/OOO330_m14
[LibreOffice.git] / framework / source / inc / accelerators / acceleratorcache.hxx
blob23ec86df8a00342879741e8adb26fba0c6dea7dc
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_ACCELERATORCACHE_HXX_
29 #define __FRAMEWORK_ACCELERATORS_ACCELERATORCACHE_HXX_
31 //__________________________________________
32 // own includes
34 #include <threadhelp/threadhelpbase.hxx>
35 #include <general.h>
36 #include <stdtypes.h>
38 //__________________________________________
39 // interface includes
41 #ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_
42 #include <com/sun/star/awt/KeyEvent.hpp>
43 #endif
45 //__________________________________________
46 // other includes
47 #include <comphelper/sequenceasvector.hxx>
49 //__________________________________________
50 // definition
52 namespace framework
55 //__________________________________________
56 /**
57 @short implements a cache for any accelerator configuration.
59 @descr Its implemented threadsafe, supports copy-on-write pattern
60 and a flush mechansim to support concurrent access to the same
61 configuration.
63 copy-on-write ... How? Do the following:
65 class AcceleratorCache : public ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ...
67 //______________________________________
68 // const, types
70 public:
72 //---------------------------------------
73 /** TODO document me
74 commands -> keys
76 typedef ::comphelper::SequenceAsVector< css::awt::KeyEvent > TKeyList;
77 typedef BaseHash< TKeyList > TCommand2Keys;
79 //---------------------------------------
80 /** TODO document me
81 keys -> commands
83 typedef ::std::hash_map< css::awt::KeyEvent ,
84 ::rtl::OUString ,
85 KeyEventHashCode ,
86 KeyEventEqualsFunc > TKey2Commands;
88 //______________________________________
89 // member
91 private:
93 //---------------------------------------
94 /** map commands to keys in relation 1:n.
95 First key is interpreted as preferred one! */
96 TCommand2Keys m_lCommand2Keys;
98 //---------------------------------------
99 /** map keys to commands in relation 1:1. */
100 TKey2Commands m_lKey2Commands;
102 //______________________________________
103 // interface
105 public:
107 //---------------------------------------
108 /** @short creates a new - but empty - cache instance. */
109 AcceleratorCache();
111 //---------------------------------------
112 /** @short make a copy of this cache.
113 @descr Used for the copy-on-write feature.
115 AcceleratorCache(const AcceleratorCache& rCopy);
117 //---------------------------------------
118 /** @short does nothing real. */
119 virtual ~AcceleratorCache();
121 //---------------------------------------
122 /** @short write changes back to the original container.
124 @param rCopy
125 the (changed!) copy, which should be written
126 back to this original container.
128 virtual void takeOver(const AcceleratorCache& rCopy);
130 //---------------------------------------
131 /** TODO document me */
132 virtual AcceleratorCache& operator=(const AcceleratorCache& rCopy);
134 //---------------------------------------
135 /** @short checks if the specified key exists.
137 @param aKey
138 the key, which should be checked.
140 @return [bool]
141 TRUE if the speicfied key exists inside this container.
143 virtual sal_Bool hasKey(const css::awt::KeyEvent& aKey) const;
144 virtual sal_Bool hasCommand(const ::rtl::OUString& sCommand) const;
146 //---------------------------------------
147 /** TODO document me */
148 virtual TKeyList getAllKeys() const;
150 //---------------------------------------
151 /** @short add a new or change an existing key-command pair
152 of this container.
154 @param aKey
155 describe the key.
157 @param sCommand
158 describe the command.
160 virtual void setKeyCommandPair(const css::awt::KeyEvent& aKey ,
161 const ::rtl::OUString& sCommand);
163 //---------------------------------------
164 /** @short returns the list of keys, which are registered
165 for this command.
167 @param sCommand
168 describe the command.
170 @return [TKeyList]
171 the list of registered keys. Can be empty!
173 virtual TKeyList getKeysByCommand(const ::rtl::OUString& sCommand) const;
175 //---------------------------------------
176 /** TODO */
177 virtual ::rtl::OUString getCommandByKey(const css::awt::KeyEvent& aKey) const;
179 //---------------------------------------
180 /** TODO */
181 virtual void removeKey(const css::awt::KeyEvent& aKey);
182 virtual void removeCommand(const ::rtl::OUString& sCommand);
185 } // namespace framework
187 #endif // __FRAMEWORK_ACCELERATORS_ACCELERATORCACHE_HXX_