101aa44aaSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 301aa44aaSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 401aa44aaSAndrew Rist * or more contributor license agreements. See the NOTICE file 501aa44aaSAndrew Rist * distributed with this work for additional information 601aa44aaSAndrew Rist * regarding copyright ownership. The ASF licenses this file 701aa44aaSAndrew Rist * to you under the Apache License, Version 2.0 (the 801aa44aaSAndrew Rist * "License"); you may not use this file except in compliance 901aa44aaSAndrew Rist * with the License. You may obtain a copy of the License at 1001aa44aaSAndrew Rist * 1101aa44aaSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1201aa44aaSAndrew Rist * 1301aa44aaSAndrew Rist * Unless required by applicable law or agreed to in writing, 1401aa44aaSAndrew Rist * software distributed under the License is distributed on an 1501aa44aaSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1601aa44aaSAndrew Rist * KIND, either express or implied. See the License for the 1701aa44aaSAndrew Rist * specific language governing permissions and limitations 1801aa44aaSAndrew Rist * under the License. 1901aa44aaSAndrew Rist * 2001aa44aaSAndrew Rist *************************************************************/ 2101aa44aaSAndrew Rist 2201aa44aaSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef INCLUDED_SVTOOLS_ACCELERATOREXECUTE_HXX 25cdf0e10cSrcweir #define INCLUDED_SVTOOLS_ACCELERATOREXECUTE_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir //=============================================== 28cdf0e10cSrcweir // includes 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include "svtools/svtdllapi.h" 31cdf0e10cSrcweir 32cdf0e10cSrcweir #ifndef INCLUDED_VECTOR 33cdf0e10cSrcweir #include <vector> 34cdf0e10cSrcweir #define INCLUDED_VECTOR 35cdf0e10cSrcweir #endif 36cdf0e10cSrcweir 37cdf0e10cSrcweir #ifndef __COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ 38cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 39cdf0e10cSrcweir #endif 40cdf0e10cSrcweir 41cdf0e10cSrcweir #ifndef __COM_SUN_STAR_FRAME_XFRAME_HPP_ 42cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 43cdf0e10cSrcweir #endif 44cdf0e10cSrcweir 45cdf0e10cSrcweir #ifndef __COM_SUN_STAR_FRAME_XDISPATCHPROVIDER_HPP_ 46cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 47cdf0e10cSrcweir #endif 48cdf0e10cSrcweir 49cdf0e10cSrcweir #ifndef __com_SUN_STAR_UI_XACCELERATORCONFIGURATION_HPP_ 50cdf0e10cSrcweir #include <com/sun/star/ui/XAcceleratorConfiguration.hpp> 51cdf0e10cSrcweir #endif 52cdf0e10cSrcweir 53cdf0e10cSrcweir #ifndef __COM_SUN_STAR_UTIL_XURLTRANSFORMER_HPP_ 54cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 55cdf0e10cSrcweir #endif 56cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp> 57cdf0e10cSrcweir 58cdf0e10cSrcweir #ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_ 59cdf0e10cSrcweir #include <com/sun/star/awt/KeyEvent.hpp> 60cdf0e10cSrcweir #endif 61cdf0e10cSrcweir #include <vcl/keycod.hxx> 62cdf0e10cSrcweir #include <vcl/evntpost.hxx> 63cdf0e10cSrcweir #include <osl/mutex.h> 64cdf0e10cSrcweir 65cdf0e10cSrcweir //=============================================== 66cdf0e10cSrcweir // namespace 67cdf0e10cSrcweir 68cdf0e10cSrcweir #ifdef css 69cdf0e10cSrcweir #error "Conflict on using css as namespace alias!" 70cdf0e10cSrcweir #else 71cdf0e10cSrcweir #define css ::com::sun::star 72cdf0e10cSrcweir #endif 73cdf0e10cSrcweir 74cdf0e10cSrcweir namespace svt 75cdf0e10cSrcweir { 76cdf0e10cSrcweir 77cdf0e10cSrcweir //=============================================== 78cdf0e10cSrcweir // definitions 79cdf0e10cSrcweir 80cdf0e10cSrcweir struct TMutexInit 81cdf0e10cSrcweir { 82cdf0e10cSrcweir ::osl::Mutex m_aLock; 83cdf0e10cSrcweir }; 84cdf0e10cSrcweir 85cdf0e10cSrcweir //=============================================== 86cdf0e10cSrcweir /** 87cdf0e10cSrcweir @descr implements a helper, which can be used to 88cdf0e10cSrcweir convert vcl key codes into awt key codes ... 89cdf0e10cSrcweir and reverse. 90cdf0e10cSrcweir 91cdf0e10cSrcweir Further such key code can be triggered. 92cdf0e10cSrcweir Doing so different accelerator 93cdf0e10cSrcweir configurations are merged together; a suitable 94cdf0e10cSrcweir command registered for the given key code is searched 95cdf0e10cSrcweir and will be dispatched. 96cdf0e10cSrcweir 97cdf0e10cSrcweir @attention 98cdf0e10cSrcweir 99cdf0e10cSrcweir Because exceution of an accelerator command can be dangerous 100cdf0e10cSrcweir (in case it force an office shutdown for key "ALT+F4"!) 101cdf0e10cSrcweir all internal dispatches are done asynchronous. 10286e1cf34SPedro Giffuni Menas that the trigger call doesn't wait till the dispatch 103cdf0e10cSrcweir is finished. You can call very often. All requests will be 104cdf0e10cSrcweir queued internal and dispatched ASAP. 105cdf0e10cSrcweir 106cdf0e10cSrcweir Of course this queue will be stopped if the environment 107cdf0e10cSrcweir will be destructed ... 108cdf0e10cSrcweir */ 109cdf0e10cSrcweir class SVT_DLLPUBLIC AcceleratorExecute : private TMutexInit 110cdf0e10cSrcweir { 111cdf0e10cSrcweir //------------------------------------------- 112cdf0e10cSrcweir // const, types 113cdf0e10cSrcweir private: 114cdf0e10cSrcweir 115cdf0e10cSrcweir /** @deprecated 116cdf0e10cSrcweir replaced by internal class AsyncAccelExec ... 117cdf0e10cSrcweir remove this resource here if we go forwards to next major */ 118cdf0e10cSrcweir typedef ::std::vector< ::std::pair< css::util::URL, css::uno::Reference< css::frame::XDispatch > > > TCommandQueue; 119cdf0e10cSrcweir 120cdf0e10cSrcweir //------------------------------------------- 121cdf0e10cSrcweir // member 122cdf0e10cSrcweir private: 123cdf0e10cSrcweir 124cdf0e10cSrcweir /** TODO document me */ 125cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; 126cdf0e10cSrcweir 127cdf0e10cSrcweir /** TODO document me */ 128cdf0e10cSrcweir css::uno::Reference< css::util::XURLTransformer > m_xURLParser; 129cdf0e10cSrcweir 130cdf0e10cSrcweir /** TODO document me */ 131cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatchProvider > m_xDispatcher; 132cdf0e10cSrcweir 133cdf0e10cSrcweir /** TODO document me */ 134cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xGlobalCfg; 135cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xModuleCfg; 136cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xDocCfg; 137cdf0e10cSrcweir 138cdf0e10cSrcweir /** @deprecated 139cdf0e10cSrcweir replaced by internal class AsyncAccelExec ... 140cdf0e10cSrcweir remove this resource here if we go forwards to next major */ 141cdf0e10cSrcweir TCommandQueue m_lCommandQueue; 142cdf0e10cSrcweir 143cdf0e10cSrcweir /** @deprecated 144cdf0e10cSrcweir replaced by internal class AsyncAccelExec ... 145cdf0e10cSrcweir remove this resource here if we go forwards to next major */ 146cdf0e10cSrcweir ::vcl::EventPoster m_aAsyncCallback; 147cdf0e10cSrcweir 148cdf0e10cSrcweir //------------------------------------------- 149cdf0e10cSrcweir // interface 150cdf0e10cSrcweir public: 151cdf0e10cSrcweir 152cdf0e10cSrcweir //--------------------------------------- 153cdf0e10cSrcweir /** @short factory method to create new accelerator 154cdf0e10cSrcweir helper instance. 155cdf0e10cSrcweir 156cdf0e10cSrcweir @descr Such helper instance must be initialized at first. 157cdf0e10cSrcweir So it can know its environment (global/module or 158cdf0e10cSrcweir document specific). 159cdf0e10cSrcweir 160cdf0e10cSrcweir Afterwards it can be used to execute incoming 161cdf0e10cSrcweir accelerator requests. 162cdf0e10cSrcweir 163cdf0e10cSrcweir The "end of life" of such helper can be reached as follow: 164cdf0e10cSrcweir 165cdf0e10cSrcweir - delete the object 166cdf0e10cSrcweir => If it stands currently in its execute method, they will 167cdf0e10cSrcweir be finished. All further queued requests will be removed 168cdf0e10cSrcweir and further not executed! 169cdf0e10cSrcweir 170cdf0e10cSrcweir - "let it stay alone" 171cdf0e10cSrcweir => All currently queued events will be finished. The 172cdf0e10cSrcweir helper kills itself afterwards. A shutdown of the 173cdf0e10cSrcweir environment will be recognized ... The helper stop its 17486e1cf34SPedro Giffuni work immediately then! 175cdf0e10cSrcweir */ 176cdf0e10cSrcweir static AcceleratorExecute* createAcceleratorHelper(); 177cdf0e10cSrcweir 178cdf0e10cSrcweir //--------------------------------------- 179cdf0e10cSrcweir /** @short fight against inlining ... */ 180cdf0e10cSrcweir virtual ~AcceleratorExecute(); 181cdf0e10cSrcweir 182cdf0e10cSrcweir //--------------------------------------- 183cdf0e10cSrcweir /** @short init this instance. 184cdf0e10cSrcweir 185cdf0e10cSrcweir @descr It must be called as first method after creation. 186*4e7d57d8Smseidel And further it can be called more than once ... 187*4e7d57d8Smseidel but at least it should be used one time only. 188*4e7d57d8Smseidel Otherwise nobody can say, which asynchronous 189cdf0e10cSrcweir executions will be used inside the old and which one 190cdf0e10cSrcweir will be used inside the new environment. 191cdf0e10cSrcweir 192cdf0e10cSrcweir @param xSMGR 193cdf0e10cSrcweir reference to an uno service manager. 194cdf0e10cSrcweir 195cdf0e10cSrcweir @param xEnv 196cdf0e10cSrcweir if it points to a valid frame it will be used 197cdf0e10cSrcweir to execute the dispatch there. Further the frame 198cdf0e10cSrcweir is used to locate the right module configuration 199cdf0e10cSrcweir and use it merged together with the document and 200cdf0e10cSrcweir the global configuration. 201cdf0e10cSrcweir 202cdf0e10cSrcweir If this parameter is set to NULL, the global configuration 203cdf0e10cSrcweir is used only. Further the global Desktop instance is 204cdf0e10cSrcweir used for dispatch. 205cdf0e10cSrcweir */ 206cdf0e10cSrcweir virtual void init(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR, 207cdf0e10cSrcweir const css::uno::Reference< css::frame::XFrame >& xEnv ); 208cdf0e10cSrcweir 209cdf0e10cSrcweir //--------------------------------------- 210cdf0e10cSrcweir /** @short trigger this accelerator. 211cdf0e10cSrcweir 212cdf0e10cSrcweir @descr The internal configuartions are used to find 213cdf0e10cSrcweir as suitable command for this key code. 214cdf0e10cSrcweir This command will be queued and executed later 215cdf0e10cSrcweir asynchronous. 216cdf0e10cSrcweir 217cdf0e10cSrcweir @param aKey 218cdf0e10cSrcweir specify the accelerator for execute. 219cdf0e10cSrcweir 220cdf0e10cSrcweir @return [sal_Bool] 221cdf0e10cSrcweir sal_True if this key is configured and match to a command. 222cdf0e10cSrcweir Attention: This state does not mean the success state 223cdf0e10cSrcweir of the corresponding execute. Because its done asynchronous! 224cdf0e10cSrcweir */ 225cdf0e10cSrcweir virtual sal_Bool execute(const KeyCode& aKey); 226cdf0e10cSrcweir virtual sal_Bool execute(const css::awt::KeyEvent& aKey); 227cdf0e10cSrcweir 228cdf0e10cSrcweir /** search the command for the given key event. 229cdf0e10cSrcweir * 230cdf0e10cSrcweir * @param aKey The key event 231cdf0e10cSrcweir * @return The command or an empty string if the key event could not be found. 232cdf0e10cSrcweir */ 233cdf0e10cSrcweir ::rtl::OUString findCommand(const ::com::sun::star::awt::KeyEvent& aKey); 234cdf0e10cSrcweir //--------------------------------------- 235cdf0e10cSrcweir /** TODO document me */ 236cdf0e10cSrcweir static css::awt::KeyEvent st_VCLKey2AWTKey(const KeyCode& aKey); 237cdf0e10cSrcweir static KeyCode st_AWTKey2VCLKey(const css::awt::KeyEvent& aKey); 238cdf0e10cSrcweir 239cdf0e10cSrcweir //--------------------------------------- 240cdf0e10cSrcweir /** TODO document me */ 241cdf0e10cSrcweir static css::uno::Reference< css::ui::XAcceleratorConfiguration > st_openGlobalConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); 242cdf0e10cSrcweir 243cdf0e10cSrcweir //--------------------------------------- 244cdf0e10cSrcweir /** TODO document me */ 245cdf0e10cSrcweir static css::uno::Reference< css::ui::XAcceleratorConfiguration > st_openModuleConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , 246cdf0e10cSrcweir const css::uno::Reference< css::frame::XFrame >& xFrame); 247cdf0e10cSrcweir 248cdf0e10cSrcweir //--------------------------------------- 249cdf0e10cSrcweir /** TODO document me */ 250cdf0e10cSrcweir static css::uno::Reference< css::ui::XAcceleratorConfiguration > st_openDocConfig(const css::uno::Reference< css::frame::XModel >& xModel); 251cdf0e10cSrcweir 252cdf0e10cSrcweir //------------------------------------------- 253cdf0e10cSrcweir // internal 254cdf0e10cSrcweir private: 255cdf0e10cSrcweir 256cdf0e10cSrcweir //--------------------------------------- 257cdf0e10cSrcweir /** @short allow creation of instances of this class 258cdf0e10cSrcweir by using our factory only! 259cdf0e10cSrcweir */ 260cdf0e10cSrcweir SVT_DLLPRIVATE AcceleratorExecute(); 261cdf0e10cSrcweir 262cdf0e10cSrcweir AcceleratorExecute(const AcceleratorExecute& rCopy); operator =(const AcceleratorExecute &)263cdf0e10cSrcweir void operator=(const AcceleratorExecute&) {}; 264cdf0e10cSrcweir //--------------------------------------- 265cdf0e10cSrcweir /** TODO document me */ 266cdf0e10cSrcweir SVT_DLLPRIVATE ::rtl::OUString impl_ts_findCommand(const css::awt::KeyEvent& aKey); 267cdf0e10cSrcweir 268cdf0e10cSrcweir //--------------------------------------- 269cdf0e10cSrcweir /** TODO document me */ 270cdf0e10cSrcweir SVT_DLLPRIVATE css::uno::Reference< css::util::XURLTransformer > impl_ts_getURLParser(); 271cdf0e10cSrcweir 272cdf0e10cSrcweir //--------------------------------------- 273cdf0e10cSrcweir /** @deprecated 274cdf0e10cSrcweir replaced by internal class AsyncAccelExec ... 275cdf0e10cSrcweir remove this resource here if we go forwards to next major */ 276cdf0e10cSrcweir DECL_DLLPRIVATE_LINK(impl_ts_asyncCallback, void*); 277cdf0e10cSrcweir }; 278cdf0e10cSrcweir 279cdf0e10cSrcweir } // namespace svt 280cdf0e10cSrcweir 281cdf0e10cSrcweir #undef css 282cdf0e10cSrcweir 283cdf0e10cSrcweir #endif // INCLUDED_SVTOOLS_ACCELERATOREXECUTE_HXX 284