merge the formfield patch from ooo-build
[ooovba.git] / framework / source / inc / accelerators / acceleratorcache.hxx
blob24a71a679f34bfac08a165fe56628598ea68a098
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: acceleratorcache.hxx,v $
10 * $Revision: 1.4 $
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_ACCELERATORCACHE_HXX_
32 #define __FRAMEWORK_ACCELERATORS_ACCELERATORCACHE_HXX_
34 //__________________________________________
35 // own includes
37 #include <threadhelp/threadhelpbase.hxx>
38 #include <general.h>
39 #include <stdtypes.h>
41 //__________________________________________
42 // interface includes
44 #ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_
45 #include <com/sun/star/awt/KeyEvent.hpp>
46 #endif
48 //__________________________________________
49 // other includes
50 #include <comphelper/sequenceasvector.hxx>
52 //__________________________________________
53 // definition
55 namespace framework
58 //__________________________________________
59 /**
60 @short implements a cache for any accelerator configuration.
62 @descr Its implemented threadsafe, supports copy-on-write pattern
63 and a flush mechansim to support concurrent access to the same
64 configuration.
66 copy-on-write ... How? Do the following:
68 class AcceleratorCache : public ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ...
70 //______________________________________
71 // const, types
73 public:
75 //---------------------------------------
76 /** TODO document me
77 commands -> keys
79 typedef ::comphelper::SequenceAsVector< css::awt::KeyEvent > TKeyList;
80 typedef BaseHash< TKeyList > TCommand2Keys;
82 //---------------------------------------
83 /** TODO document me
84 keys -> commands
86 typedef ::std::hash_map< css::awt::KeyEvent ,
87 ::rtl::OUString ,
88 KeyEventHashCode ,
89 KeyEventEqualsFunc > TKey2Commands;
91 //______________________________________
92 // member
94 private:
96 //---------------------------------------
97 /** map commands to keys in relation 1:n.
98 First key is interpreted as preferred one! */
99 TCommand2Keys m_lCommand2Keys;
101 //---------------------------------------
102 /** map keys to commands in relation 1:1. */
103 TKey2Commands m_lKey2Commands;
105 //______________________________________
106 // interface
108 public:
110 //---------------------------------------
111 /** @short creates a new - but empty - cache instance. */
112 AcceleratorCache();
114 //---------------------------------------
115 /** @short make a copy of this cache.
116 @descr Used for the copy-on-write feature.
118 AcceleratorCache(const AcceleratorCache& rCopy);
120 //---------------------------------------
121 /** @short does nothing real. */
122 virtual ~AcceleratorCache();
124 //---------------------------------------
125 /** @short write changes back to the original container.
127 @param rCopy
128 the (changed!) copy, which should be written
129 back to this original container.
131 virtual void takeOver(const AcceleratorCache& rCopy);
133 //---------------------------------------
134 /** TODO document me */
135 virtual AcceleratorCache& operator=(const AcceleratorCache& rCopy);
137 //---------------------------------------
138 /** @short checks if the specified key exists.
140 @param aKey
141 the key, which should be checked.
143 @return [bool]
144 TRUE if the speicfied key exists inside this container.
146 virtual sal_Bool hasKey(const css::awt::KeyEvent& aKey) const;
147 virtual sal_Bool hasCommand(const ::rtl::OUString& sCommand) const;
149 //---------------------------------------
150 /** TODO document me */
151 virtual TKeyList getAllKeys() const;
153 //---------------------------------------
154 /** @short add a new or change an existing key-command pair
155 of this container.
157 @param aKey
158 describe the key.
160 @param sCommand
161 describe the command.
163 virtual void setKeyCommandPair(const css::awt::KeyEvent& aKey ,
164 const ::rtl::OUString& sCommand);
166 //---------------------------------------
167 /** @short returns the list of keys, which are registered
168 for this command.
170 @param sCommand
171 describe the command.
173 @return [TKeyList]
174 the list of registered keys. Can be empty!
176 virtual TKeyList getKeysByCommand(const ::rtl::OUString& sCommand) const;
178 //---------------------------------------
179 /** TODO */
180 virtual ::rtl::OUString getCommandByKey(const css::awt::KeyEvent& aKey) const;
182 //---------------------------------------
183 /** TODO */
184 virtual void removeKey(const css::awt::KeyEvent& aKey);
185 virtual void removeCommand(const ::rtl::OUString& sCommand);
188 } // namespace framework
190 #endif // __FRAMEWORK_ACCELERATORS_ACCELERATORCACHE_HXX_