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 .
24 #include <com/sun/star/awt/KeyEvent.hpp>
26 #include <unordered_map>
35 @short implements a cache for any accelerator configuration.
37 @descr It's implemented threadsafe, supports copy-on-write pattern
38 and a flush mechanism to support concurrent access to the same
41 copy-on-write ... How? Do the following:
43 class AcceleratorCache
50 typedef ::std::vector
< css::awt::KeyEvent
> TKeyList
;
54 typedef std::unordered_map
<OUString
, TKeyList
> TCommand2Keys
;
59 typedef std::unordered_map
< css::awt::KeyEvent
,
62 KeyEventEqualsFunc
> TKey2Commands
;
64 /** map commands to keys in relation 1:n.
65 First key is interpreted as preferred one! */
66 TCommand2Keys m_lCommand2Keys
;
68 /** map keys to commands in relation 1:1. */
69 TKey2Commands m_lKey2Commands
;
72 /** @short checks if the specified key exists.
75 the key, which should be checked.
78 sal_True if the specified key exists inside this container.
80 bool hasKey(const css::awt::KeyEvent
& aKey
) const;
81 bool hasCommand(const OUString
& sCommand
) const;
83 TKeyList
getAllKeys() const;
85 /** @short add a new or change an existing key-command pair
94 void setKeyCommandPair(const css::awt::KeyEvent
& aKey
,
95 const OUString
& sCommand
);
97 /** @short returns the list of keys, which are registered
101 describe the command.
104 the list of registered keys. Can be empty!
106 TKeyList
getKeysByCommand(const OUString
& sCommand
) const;
108 OUString
getCommandByKey(const css::awt::KeyEvent
& aKey
) const;
109 void removeKey(const css::awt::KeyEvent
& aKey
);
110 void removeCommand(const OUString
& sCommand
);
113 } // namespace framework
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */