fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / accelerators / acceleratorcache.cxx
blob03cee4d7b1d7aabd1bf5baa7d6b9f53143bfc9f6
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 #include <accelerators/acceleratorcache.hxx>
22 #include <xml/acceleratorconfigurationreader.hxx>
24 #include <com/sun/star/container/ElementExistException.hpp>
26 #include <com/sun/star/container/NoSuchElementException.hpp>
28 #include <vcl/svapp.hxx>
30 namespace framework
33 AcceleratorCache::AcceleratorCache()
37 AcceleratorCache::AcceleratorCache(const AcceleratorCache& rCopy)
39 m_lCommand2Keys = rCopy.m_lCommand2Keys;
40 m_lKey2Commands = rCopy.m_lKey2Commands;
43 AcceleratorCache::~AcceleratorCache()
45 // Dont save anything automatically here.
46 // The user has to do that explicitly!
49 void AcceleratorCache::takeOver(const AcceleratorCache& rCopy)
51 SolarMutexGuard g;
52 m_lCommand2Keys = rCopy.m_lCommand2Keys;
53 m_lKey2Commands = rCopy.m_lKey2Commands;
56 AcceleratorCache& AcceleratorCache::operator=(const AcceleratorCache& rCopy)
58 takeOver(rCopy);
59 return *this;
62 bool AcceleratorCache::hasKey(const css::awt::KeyEvent& aKey) const
64 SolarMutexGuard g;
65 return (m_lKey2Commands.find(aKey) != m_lKey2Commands.end());
68 bool AcceleratorCache::hasCommand(const OUString& sCommand) const
70 SolarMutexGuard g;
71 return (m_lCommand2Keys.find(sCommand) != m_lCommand2Keys.end());
74 AcceleratorCache::TKeyList AcceleratorCache::getAllKeys() const
76 SolarMutexGuard g;
77 TKeyList lKeys;
78 lKeys.reserve(m_lKey2Commands.size());
80 TKey2Commands::const_iterator pIt;
81 TKey2Commands::const_iterator pEnd = m_lKey2Commands.end();
82 for ( pIt = m_lKey2Commands.begin();
83 pIt != pEnd;
84 ++pIt )
86 lKeys.push_back(pIt->first);
89 return lKeys;
92 void AcceleratorCache::setKeyCommandPair(const css::awt::KeyEvent& aKey ,
93 const OUString& sCommand)
95 SolarMutexGuard g;
97 // register command for the specified key
98 m_lKey2Commands[aKey] = sCommand;
100 // update optimized structure to bind multiple keys to one command
101 TKeyList& rKeyList = m_lCommand2Keys[sCommand];
102 rKeyList.push_back(aKey);
105 AcceleratorCache::TKeyList AcceleratorCache::getKeysByCommand(const OUString& sCommand) const
107 SolarMutexGuard g;
108 TCommand2Keys::const_iterator pCommand = m_lCommand2Keys.find(sCommand);
109 if (pCommand == m_lCommand2Keys.end())
110 throw css::container::NoSuchElementException();
111 return pCommand->second;
114 OUString AcceleratorCache::getCommandByKey(const css::awt::KeyEvent& aKey) const
116 SolarMutexGuard g;
117 TKey2Commands::const_iterator pKey = m_lKey2Commands.find(aKey);
118 if (pKey == m_lKey2Commands.end())
119 throw css::container::NoSuchElementException();
120 return pKey->second;
123 void AcceleratorCache::removeKey(const css::awt::KeyEvent& aKey)
125 SolarMutexGuard g;
127 // check if key exists
128 TKey2Commands::const_iterator pKey = m_lKey2Commands.find(aKey);
129 if (pKey == m_lKey2Commands.end())
130 return;
132 // get its registered command
133 // Because we must know its place inside the optimized
134 // structure, which bind keys to commands, too!
135 OUString sCommand = pKey->second;
136 pKey = m_lKey2Commands.end(); // nobody should use an undefined value .-)
138 // remove key from primary list
139 m_lKey2Commands.erase(aKey);
141 // remove key from optimized command list
142 m_lCommand2Keys.erase(sCommand);
145 void AcceleratorCache::removeCommand(const OUString& sCommand)
147 SolarMutexGuard g;
149 const TKeyList& lKeys = getKeysByCommand(sCommand);
150 AcceleratorCache::TKeyList::const_iterator pKey;
151 for ( pKey = lKeys.begin();
152 pKey != lKeys.end();
153 ++pKey )
155 const css::awt::KeyEvent& rKey = *pKey;
156 removeKey(rKey);
158 m_lCommand2Keys.erase(sCommand);
161 } // namespace framework
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */