1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: acceleratorcache.hxx,v $
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 //__________________________________________
37 #include <threadhelp/threadhelpbase.hxx>
41 //__________________________________________
44 #ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_
45 #include <com/sun/star/awt/KeyEvent.hpp>
48 //__________________________________________
50 #include <comphelper/sequenceasvector.hxx>
52 //__________________________________________
58 //__________________________________________
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
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 //______________________________________
75 //---------------------------------------
79 typedef ::comphelper::SequenceAsVector
< css::awt::KeyEvent
> TKeyList
;
80 typedef BaseHash
< TKeyList
> TCommand2Keys
;
82 //---------------------------------------
86 typedef ::std::hash_map
< css::awt::KeyEvent
,
89 KeyEventEqualsFunc
> TKey2Commands
;
91 //______________________________________
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 //______________________________________
110 //---------------------------------------
111 /** @short creates a new - but empty - cache instance. */
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.
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.
141 the key, which should be checked.
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
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
171 describe the command.
174 the list of registered keys. Can be empty!
176 virtual TKeyList
getKeysByCommand(const ::rtl::OUString
& sCommand
) const;
178 //---------------------------------------
180 virtual ::rtl::OUString
getCommandByKey(const css::awt::KeyEvent
& aKey
) const;
182 //---------------------------------------
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_