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 //__________________________________________
34 #include <threadhelp/threadhelpbase.hxx>
38 //__________________________________________
41 #ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_
42 #include <com/sun/star/awt/KeyEvent.hpp>
45 //__________________________________________
47 #include <comphelper/sequenceasvector.hxx>
49 //__________________________________________
55 //__________________________________________
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
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 //______________________________________
72 //---------------------------------------
76 typedef ::comphelper::SequenceAsVector
< css::awt::KeyEvent
> TKeyList
;
77 typedef BaseHash
< TKeyList
> TCommand2Keys
;
79 //---------------------------------------
83 typedef ::std::hash_map
< css::awt::KeyEvent
,
86 KeyEventEqualsFunc
> TKey2Commands
;
88 //______________________________________
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 //______________________________________
107 //---------------------------------------
108 /** @short creates a new - but empty - cache instance. */
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.
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.
138 the key, which should be checked.
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
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
168 describe the command.
171 the list of registered keys. Can be empty!
173 virtual TKeyList
getKeysByCommand(const ::rtl::OUString
& sCommand
) const;
175 //---------------------------------------
177 virtual ::rtl::OUString
getCommandByKey(const css::awt::KeyEvent
& aKey
) const;
179 //---------------------------------------
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_