1*f8e07b45SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f8e07b45SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f8e07b45SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f8e07b45SAndrew Rist * distributed with this work for additional information 6*f8e07b45SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f8e07b45SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f8e07b45SAndrew Rist * "License"); you may not use this file except in compliance 9*f8e07b45SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*f8e07b45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*f8e07b45SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f8e07b45SAndrew Rist * software distributed under the License is distributed on an 15*f8e07b45SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f8e07b45SAndrew Rist * KIND, either express or implied. See the License for the 17*f8e07b45SAndrew Rist * specific language governing permissions and limitations 18*f8e07b45SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*f8e07b45SAndrew Rist *************************************************************/ 21*f8e07b45SAndrew Rist 22*f8e07b45SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef __FRAMEWORK_ACCELERATORS_ACCELERATORCACHE_HXX_ 25cdf0e10cSrcweir #define __FRAMEWORK_ACCELERATORS_ACCELERATORCACHE_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir //__________________________________________ 28cdf0e10cSrcweir // own includes 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <threadhelp/threadhelpbase.hxx> 31cdf0e10cSrcweir #include <general.h> 32cdf0e10cSrcweir #include <stdtypes.h> 33cdf0e10cSrcweir 34cdf0e10cSrcweir //__________________________________________ 35cdf0e10cSrcweir // interface includes 36cdf0e10cSrcweir 37cdf0e10cSrcweir #ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_ 38cdf0e10cSrcweir #include <com/sun/star/awt/KeyEvent.hpp> 39cdf0e10cSrcweir #endif 40cdf0e10cSrcweir 41cdf0e10cSrcweir //__________________________________________ 42cdf0e10cSrcweir // other includes 43cdf0e10cSrcweir #include <comphelper/sequenceasvector.hxx> 44cdf0e10cSrcweir 45cdf0e10cSrcweir //__________________________________________ 46cdf0e10cSrcweir // definition 47cdf0e10cSrcweir 48cdf0e10cSrcweir namespace framework 49cdf0e10cSrcweir { 50cdf0e10cSrcweir 51cdf0e10cSrcweir //__________________________________________ 52cdf0e10cSrcweir /** 53cdf0e10cSrcweir @short implements a cache for any accelerator configuration. 54cdf0e10cSrcweir 55cdf0e10cSrcweir @descr Its implemented threadsafe, supports copy-on-write pattern 56cdf0e10cSrcweir and a flush mechansim to support concurrent access to the same 57cdf0e10cSrcweir configuration. 58cdf0e10cSrcweir 59cdf0e10cSrcweir copy-on-write ... How? Do the following: 60cdf0e10cSrcweir */ 61cdf0e10cSrcweir class AcceleratorCache : public ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ... 62cdf0e10cSrcweir { 63cdf0e10cSrcweir //______________________________________ 64cdf0e10cSrcweir // const, types 65cdf0e10cSrcweir 66cdf0e10cSrcweir public: 67cdf0e10cSrcweir 68cdf0e10cSrcweir //--------------------------------------- 69cdf0e10cSrcweir /** TODO document me 70cdf0e10cSrcweir commands -> keys 71cdf0e10cSrcweir */ 72cdf0e10cSrcweir typedef ::comphelper::SequenceAsVector< css::awt::KeyEvent > TKeyList; 73cdf0e10cSrcweir typedef BaseHash< TKeyList > TCommand2Keys; 74cdf0e10cSrcweir 75cdf0e10cSrcweir //--------------------------------------- 76cdf0e10cSrcweir /** TODO document me 77cdf0e10cSrcweir keys -> commands 78cdf0e10cSrcweir */ 79cdf0e10cSrcweir typedef ::std::hash_map< css::awt::KeyEvent , 80cdf0e10cSrcweir ::rtl::OUString , 81cdf0e10cSrcweir KeyEventHashCode , 82cdf0e10cSrcweir KeyEventEqualsFunc > TKey2Commands; 83cdf0e10cSrcweir 84cdf0e10cSrcweir //______________________________________ 85cdf0e10cSrcweir // member 86cdf0e10cSrcweir 87cdf0e10cSrcweir private: 88cdf0e10cSrcweir 89cdf0e10cSrcweir //--------------------------------------- 90cdf0e10cSrcweir /** map commands to keys in relation 1:n. 91cdf0e10cSrcweir First key is interpreted as preferred one! */ 92cdf0e10cSrcweir TCommand2Keys m_lCommand2Keys; 93cdf0e10cSrcweir 94cdf0e10cSrcweir //--------------------------------------- 95cdf0e10cSrcweir /** map keys to commands in relation 1:1. */ 96cdf0e10cSrcweir TKey2Commands m_lKey2Commands; 97cdf0e10cSrcweir 98cdf0e10cSrcweir //______________________________________ 99cdf0e10cSrcweir // interface 100cdf0e10cSrcweir 101cdf0e10cSrcweir public: 102cdf0e10cSrcweir 103cdf0e10cSrcweir //--------------------------------------- 104cdf0e10cSrcweir /** @short creates a new - but empty - cache instance. */ 105cdf0e10cSrcweir AcceleratorCache(); 106cdf0e10cSrcweir 107cdf0e10cSrcweir //--------------------------------------- 108cdf0e10cSrcweir /** @short make a copy of this cache. 109cdf0e10cSrcweir @descr Used for the copy-on-write feature. 110cdf0e10cSrcweir */ 111cdf0e10cSrcweir AcceleratorCache(const AcceleratorCache& rCopy); 112cdf0e10cSrcweir 113cdf0e10cSrcweir //--------------------------------------- 114cdf0e10cSrcweir /** @short does nothing real. */ 115cdf0e10cSrcweir virtual ~AcceleratorCache(); 116cdf0e10cSrcweir 117cdf0e10cSrcweir //--------------------------------------- 118cdf0e10cSrcweir /** @short write changes back to the original container. 119cdf0e10cSrcweir 120cdf0e10cSrcweir @param rCopy 121cdf0e10cSrcweir the (changed!) copy, which should be written 122cdf0e10cSrcweir back to this original container. 123cdf0e10cSrcweir */ 124cdf0e10cSrcweir virtual void takeOver(const AcceleratorCache& rCopy); 125cdf0e10cSrcweir 126cdf0e10cSrcweir //--------------------------------------- 127cdf0e10cSrcweir /** TODO document me */ 128cdf0e10cSrcweir virtual AcceleratorCache& operator=(const AcceleratorCache& rCopy); 129cdf0e10cSrcweir 130cdf0e10cSrcweir //--------------------------------------- 131cdf0e10cSrcweir /** @short checks if the specified key exists. 132cdf0e10cSrcweir 133cdf0e10cSrcweir @param aKey 134cdf0e10cSrcweir the key, which should be checked. 135cdf0e10cSrcweir 136cdf0e10cSrcweir @return [bool] 137cdf0e10cSrcweir sal_True if the speicfied key exists inside this container. 138cdf0e10cSrcweir */ 139cdf0e10cSrcweir virtual sal_Bool hasKey(const css::awt::KeyEvent& aKey) const; 140cdf0e10cSrcweir virtual sal_Bool hasCommand(const ::rtl::OUString& sCommand) const; 141cdf0e10cSrcweir 142cdf0e10cSrcweir //--------------------------------------- 143cdf0e10cSrcweir /** TODO document me */ 144cdf0e10cSrcweir virtual TKeyList getAllKeys() const; 145cdf0e10cSrcweir 146cdf0e10cSrcweir //--------------------------------------- 147cdf0e10cSrcweir /** @short add a new or change an existing key-command pair 148cdf0e10cSrcweir of this container. 149cdf0e10cSrcweir 150cdf0e10cSrcweir @param aKey 151cdf0e10cSrcweir describe the key. 152cdf0e10cSrcweir 153cdf0e10cSrcweir @param sCommand 154cdf0e10cSrcweir describe the command. 155cdf0e10cSrcweir */ 156cdf0e10cSrcweir virtual void setKeyCommandPair(const css::awt::KeyEvent& aKey , 157cdf0e10cSrcweir const ::rtl::OUString& sCommand); 158cdf0e10cSrcweir 159cdf0e10cSrcweir //--------------------------------------- 160cdf0e10cSrcweir /** @short returns the list of keys, which are registered 161cdf0e10cSrcweir for this command. 162cdf0e10cSrcweir 163cdf0e10cSrcweir @param sCommand 164cdf0e10cSrcweir describe the command. 165cdf0e10cSrcweir 166cdf0e10cSrcweir @return [TKeyList] 167cdf0e10cSrcweir the list of registered keys. Can be empty! 168cdf0e10cSrcweir */ 169cdf0e10cSrcweir virtual TKeyList getKeysByCommand(const ::rtl::OUString& sCommand) const; 170cdf0e10cSrcweir 171cdf0e10cSrcweir //--------------------------------------- 172cdf0e10cSrcweir /** TODO */ 173cdf0e10cSrcweir virtual ::rtl::OUString getCommandByKey(const css::awt::KeyEvent& aKey) const; 174cdf0e10cSrcweir 175cdf0e10cSrcweir //--------------------------------------- 176cdf0e10cSrcweir /** TODO */ 177cdf0e10cSrcweir virtual void removeKey(const css::awt::KeyEvent& aKey); 178cdf0e10cSrcweir virtual void removeCommand(const ::rtl::OUString& sCommand); 179cdf0e10cSrcweir }; 180cdf0e10cSrcweir 181cdf0e10cSrcweir } // namespace framework 182cdf0e10cSrcweir 183cdf0e10cSrcweir #endif // __FRAMEWORK_ACCELERATORS_ACCELERATORCACHE_HXX_ 184