1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_ACCELERATORCACHE_HXX
21 #define INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_ACCELERATORCACHE_HXX
26 #include <com/sun/star/awt/KeyEvent.hpp>
36 @short implements a cache for any accelerator configuration.
38 @descr Its implemented threadsafe, supports copy-on-write pattern
39 and a flush mechansim to support concurrent access to the same
42 copy-on-write ... How? Do the following:
44 class AcceleratorCache
54 typedef ::std::vector
< css::awt::KeyEvent
> TKeyList
;
55 typedef BaseHash
< TKeyList
> TCommand2Keys
;
60 typedef std::unordered_map
< css::awt::KeyEvent
,
63 KeyEventEqualsFunc
> TKey2Commands
;
69 /** map commands to keys in relation 1:n.
70 First key is interpreted as preferred one! */
71 TCommand2Keys m_lCommand2Keys
;
73 /** map keys to commands in relation 1:1. */
74 TKey2Commands m_lKey2Commands
;
80 /** @short creates a new - but empty - cache instance. */
83 /** @short make a copy of this cache.
84 @descr Used for the copy-on-write feature.
86 AcceleratorCache(const AcceleratorCache
& rCopy
);
88 /** @short does nothing real. */
89 virtual ~AcceleratorCache();
91 /** @short write changes back to the original container.
94 the (changed!) copy, which should be written
95 back to this original container.
97 void takeOver(const AcceleratorCache
& rCopy
);
99 /** TODO document me */
100 AcceleratorCache
& operator=(const AcceleratorCache
& rCopy
);
102 /** @short checks if the specified key exists.
105 the key, which should be checked.
108 sal_True if the speicfied key exists inside this container.
110 bool hasKey(const css::awt::KeyEvent
& aKey
) const;
111 bool hasCommand(const OUString
& sCommand
) const;
113 /** TODO document me */
114 TKeyList
getAllKeys() const;
116 /** @short add a new or change an existing key-command pair
123 describe the command.
125 void setKeyCommandPair(const css::awt::KeyEvent
& aKey
,
126 const OUString
& sCommand
);
128 /** @short returns the list of keys, which are registered
132 describe the command.
135 the list of registered keys. Can be empty!
137 TKeyList
getKeysByCommand(const OUString
& sCommand
) const;
140 OUString
getCommandByKey(const css::awt::KeyEvent
& aKey
) const;
143 void removeKey(const css::awt::KeyEvent
& aKey
);
144 void removeCommand(const OUString
& sCommand
);
147 } // namespace framework
149 #endif // INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_ACCELERATORCACHE_HXX
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */