Update git submodules
[LibreOffice.git] / framework / source / inc / accelerators / acceleratorcache.hxx
blobadfdf8fe5aa2f2b60eee80dfc205c8db5b6b3ac0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <stdtypes.h>
24 #include <com/sun/star/awt/KeyEvent.hpp>
26 #include <unordered_map>
27 #include <vector>
29 // definition
31 namespace framework
34 /**
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
39 configuration.
41 copy-on-write ... How? Do the following:
43 class AcceleratorCache
45 public:
47 /**
48 commands -> keys
50 typedef ::std::vector< css::awt::KeyEvent > TKeyList;
52 private:
54 typedef std::unordered_map<OUString, TKeyList> TCommand2Keys;
56 /**
57 keys -> commands
59 typedef std::unordered_map< css::awt::KeyEvent ,
60 OUString ,
61 KeyEventHashCode ,
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;
71 public:
72 /** @short checks if the specified key exists.
74 @param aKey
75 the key, which should be checked.
77 @return [bool]
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
86 of this container.
88 @param aKey
89 describe the key.
91 @param sCommand
92 describe the command.
94 void setKeyCommandPair(const css::awt::KeyEvent& aKey ,
95 const OUString& sCommand);
97 /** @short returns the list of keys, which are registered
98 for this command.
100 @param sCommand
101 describe the command.
103 @return [TKeyList]
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: */