15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
35900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file
55900e8ecSAndrew Rist * distributed with this work for additional information
65900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file
75900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at
105900e8ecSAndrew Rist *
115900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
125900e8ecSAndrew Rist *
135900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist * software distributed under the License is distributed on an
155900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist * KIND, either express or implied. See the License for the
175900e8ecSAndrew Rist * specific language governing permissions and limitations
185900e8ecSAndrew Rist * under the License.
195900e8ecSAndrew Rist *
205900e8ecSAndrew Rist *************************************************************/
215900e8ecSAndrew Rist
225900e8ecSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir #include <svtools/acceleratorexecute.hxx>
27cdf0e10cSrcweir
28cdf0e10cSrcweir //===============================================
29cdf0e10cSrcweir // includes
30cdf0e10cSrcweir
31cdf0e10cSrcweir #ifndef __COM_SUN_STAR_FRAME_XMODULEMANAGER_HPP_
32cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir
35cdf0e10cSrcweir #ifndef __COM_SUN_STAR_FRAME_XDESKTOP_HPP_
36cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir
39cdf0e10cSrcweir #ifndef __COM_SUN_STAR_UI_XUICONFIGURATIONMANAGER_HPP_
40cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationManager.hpp>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir
43cdf0e10cSrcweir #ifndef __COM_SUN_STAR_UI_XMODULEUICONFIGURATIONMANAGERSUPPLIER_HPP_
44cdf0e10cSrcweir #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir
47cdf0e10cSrcweir #ifndef __COM_SUN_STAR_UI_XUICONFIGURATIONMANAGERSUPPLIER_HPP_
48cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir
51cdf0e10cSrcweir #ifndef __COM_SUN_STAR_AWT_XTOPWINDOW_HPP_
52cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir
55cdf0e10cSrcweir #ifndef __COM_SUN_STAR_AWT_KEYMODIFIER_HPP_
56cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp>
57cdf0e10cSrcweir #endif
58cdf0e10cSrcweir
59cdf0e10cSrcweir #ifndef __COM_SUN_STAR_UNO_SEQUENCE_HXX_
60cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir
63cdf0e10cSrcweir #ifndef __COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
64cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
65cdf0e10cSrcweir #endif
66cdf0e10cSrcweir
67cdf0e10cSrcweir #ifndef __COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
68cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
69cdf0e10cSrcweir #endif
70cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
71cdf0e10cSrcweir
72cdf0e10cSrcweir #include <vcl/window.hxx>
73cdf0e10cSrcweir #include <vcl/svapp.hxx>
74cdf0e10cSrcweir #include <vos/mutex.hxx>
75*2bfcd321SSteve Yin #include <comphelper/uieventslogger.hxx>
76cdf0e10cSrcweir
77cdf0e10cSrcweir //===============================================
78cdf0e10cSrcweir // namespace
79cdf0e10cSrcweir
80cdf0e10cSrcweir namespace css = ::com::sun::star;
81cdf0e10cSrcweir
82cdf0e10cSrcweir namespace svt
83cdf0e10cSrcweir {
84cdf0e10cSrcweir
85cdf0e10cSrcweir //===============================================
86cdf0e10cSrcweir // definitions
87cdf0e10cSrcweir
88cdf0e10cSrcweir //-----------------------------------------------
89cdf0e10cSrcweir class SVT_DLLPRIVATE AsyncAccelExec
90cdf0e10cSrcweir {
91cdf0e10cSrcweir public:
92cdf0e10cSrcweir
93cdf0e10cSrcweir //---------------------------------------
94cdf0e10cSrcweir /** creates a new instance of this class, which can be used
95cdf0e10cSrcweir one times only!
96cdf0e10cSrcweir
97cdf0e10cSrcweir This instance can be forced to execute it's internal set request
98cdf0e10cSrcweir asynchronous. After that it deletes itself !
99cdf0e10cSrcweir */
100cdf0e10cSrcweir static AsyncAccelExec* createOnShotInstance(const css::uno::Reference< css::frame::XDispatch >& xDispatch,
101cdf0e10cSrcweir const css::util::URL& aURL );
102cdf0e10cSrcweir
103cdf0e10cSrcweir void execAsync();
104cdf0e10cSrcweir
105cdf0e10cSrcweir private:
106cdf0e10cSrcweir
107cdf0e10cSrcweir //---------------------------------------
108cdf0e10cSrcweir /** @short allow creation of instances of this class
109cdf0e10cSrcweir by using our factory only!
110cdf0e10cSrcweir */
111cdf0e10cSrcweir SVT_DLLPRIVATE AsyncAccelExec(const css::uno::Reference< css::frame::XDispatch >& xDispatch,
112cdf0e10cSrcweir const css::util::URL& aURL );
113cdf0e10cSrcweir
114cdf0e10cSrcweir DECL_DLLPRIVATE_LINK(impl_ts_asyncCallback, void*);
115cdf0e10cSrcweir
116cdf0e10cSrcweir private:
117cdf0e10cSrcweir
118cdf0e10cSrcweir ::vcl::EventPoster m_aAsyncCallback;
119cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > m_xDispatch;
120cdf0e10cSrcweir css::util::URL m_aURL;
121cdf0e10cSrcweir };
122cdf0e10cSrcweir
123cdf0e10cSrcweir //-----------------------------------------------
AcceleratorExecute()124cdf0e10cSrcweir AcceleratorExecute::AcceleratorExecute()
125cdf0e10cSrcweir : TMutexInit ( )
126cdf0e10cSrcweir , m_aAsyncCallback(LINK(this, AcceleratorExecute, impl_ts_asyncCallback))
127cdf0e10cSrcweir {
128cdf0e10cSrcweir }
129cdf0e10cSrcweir
130cdf0e10cSrcweir //-----------------------------------------------
AcceleratorExecute(const AcceleratorExecute &)131cdf0e10cSrcweir AcceleratorExecute::AcceleratorExecute(const AcceleratorExecute&)
132cdf0e10cSrcweir : TMutexInit ( )
133cdf0e10cSrcweir , m_aAsyncCallback(LINK(this, AcceleratorExecute, impl_ts_asyncCallback))
134cdf0e10cSrcweir {
135cdf0e10cSrcweir // copy construction sint supported in real ...
136cdf0e10cSrcweir // but we need this ctor to init our async callback ...
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir //-----------------------------------------------
~AcceleratorExecute()140cdf0e10cSrcweir AcceleratorExecute::~AcceleratorExecute()
141cdf0e10cSrcweir {
142cdf0e10cSrcweir // does nothing real
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir //-----------------------------------------------
createAcceleratorHelper()146cdf0e10cSrcweir AcceleratorExecute* AcceleratorExecute::createAcceleratorHelper()
147cdf0e10cSrcweir {
148cdf0e10cSrcweir AcceleratorExecute* pNew = new AcceleratorExecute();
149cdf0e10cSrcweir return pNew;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
152cdf0e10cSrcweir //-----------------------------------------------
init(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR,const css::uno::Reference<css::frame::XFrame> & xEnv)153cdf0e10cSrcweir void AcceleratorExecute::init(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR,
154cdf0e10cSrcweir const css::uno::Reference< css::frame::XFrame >& xEnv )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir // SAFE -> ----------------------------------
157cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
158cdf0e10cSrcweir
159cdf0e10cSrcweir // take over the uno service manager
160cdf0e10cSrcweir m_xSMGR = xSMGR;
161cdf0e10cSrcweir
162cdf0e10cSrcweir // specify our internal dispatch provider
163cdf0e10cSrcweir // frame or desktop?! => document or global config.
164cdf0e10cSrcweir sal_Bool bDesktopIsUsed = sal_False;
165cdf0e10cSrcweir m_xDispatcher = css::uno::Reference< css::frame::XDispatchProvider >(xEnv, css::uno::UNO_QUERY);
166cdf0e10cSrcweir if (!m_xDispatcher.is())
167cdf0e10cSrcweir {
168cdf0e10cSrcweir aLock.clear();
169cdf0e10cSrcweir // <- SAFE ------------------------------
170cdf0e10cSrcweir
171cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatchProvider > xDispatcher(
172cdf0e10cSrcweir xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop")),
173cdf0e10cSrcweir css::uno::UNO_QUERY_THROW);
174cdf0e10cSrcweir
175cdf0e10cSrcweir // SAFE -> ------------------------------
176cdf0e10cSrcweir aLock.reset();
177cdf0e10cSrcweir
178cdf0e10cSrcweir m_xDispatcher = xDispatcher;
179cdf0e10cSrcweir bDesktopIsUsed = sal_True;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir
182cdf0e10cSrcweir aLock.clear();
183cdf0e10cSrcweir // <- SAFE ----------------------------------
184cdf0e10cSrcweir
185cdf0e10cSrcweir // open all needed configuration objects
186cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > xGlobalCfg;
187cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > xModuleCfg;
188cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > xDocCfg ;
189cdf0e10cSrcweir
190cdf0e10cSrcweir // global cfg
191cdf0e10cSrcweir xGlobalCfg = AcceleratorExecute::st_openGlobalConfig(xSMGR);
192cdf0e10cSrcweir if (!bDesktopIsUsed)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir // module cfg
195cdf0e10cSrcweir xModuleCfg = AcceleratorExecute::st_openModuleConfig(xSMGR, xEnv);
196cdf0e10cSrcweir
197cdf0e10cSrcweir // doc cfg
198cdf0e10cSrcweir css::uno::Reference< css::frame::XController > xController;
199cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xModel;
200cdf0e10cSrcweir xController = xEnv->getController();
201cdf0e10cSrcweir if (xController.is())
202cdf0e10cSrcweir xModel = xController->getModel();
203cdf0e10cSrcweir if (xModel.is())
204cdf0e10cSrcweir xDocCfg = AcceleratorExecute::st_openDocConfig(xModel);
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
207cdf0e10cSrcweir // SAFE -> ------------------------------
208cdf0e10cSrcweir aLock.reset();
209cdf0e10cSrcweir
210cdf0e10cSrcweir m_xGlobalCfg = xGlobalCfg;
211cdf0e10cSrcweir m_xModuleCfg = xModuleCfg;
212cdf0e10cSrcweir m_xDocCfg = xDocCfg ;
213cdf0e10cSrcweir
214cdf0e10cSrcweir aLock.clear();
215cdf0e10cSrcweir // <- SAFE ----------------------------------
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
218cdf0e10cSrcweir //-----------------------------------------------
execute(const KeyCode & aVCLKey)219cdf0e10cSrcweir sal_Bool AcceleratorExecute::execute(const KeyCode& aVCLKey)
220cdf0e10cSrcweir {
221cdf0e10cSrcweir css::awt::KeyEvent aAWTKey = AcceleratorExecute::st_VCLKey2AWTKey(aVCLKey);
222cdf0e10cSrcweir return execute(aAWTKey);
223cdf0e10cSrcweir }
224cdf0e10cSrcweir
225cdf0e10cSrcweir //-----------------------------------------------
execute(const css::awt::KeyEvent & aAWTKey)226cdf0e10cSrcweir sal_Bool AcceleratorExecute::execute(const css::awt::KeyEvent& aAWTKey)
227cdf0e10cSrcweir {
228cdf0e10cSrcweir ::rtl::OUString sCommand = impl_ts_findCommand(aAWTKey);
229cdf0e10cSrcweir
230cdf0e10cSrcweir // No Command found? Do nothing! User isnt interested on any error handling .-)
231cdf0e10cSrcweir if (!sCommand.getLength())
232cdf0e10cSrcweir return sal_False;
233cdf0e10cSrcweir
234cdf0e10cSrcweir // SAFE -> ----------------------------------
235cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
236cdf0e10cSrcweir
237cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatchProvider > xProvider = m_xDispatcher;
238cdf0e10cSrcweir
239cdf0e10cSrcweir aLock.clear();
240cdf0e10cSrcweir // <- SAFE ----------------------------------
241cdf0e10cSrcweir
242cdf0e10cSrcweir // convert command in URL structure
243cdf0e10cSrcweir css::uno::Reference< css::util::XURLTransformer > xParser = impl_ts_getURLParser();
244cdf0e10cSrcweir css::util::URL aURL;
245cdf0e10cSrcweir aURL.Complete = sCommand;
246cdf0e10cSrcweir xParser->parseStrict(aURL);
247cdf0e10cSrcweir
248cdf0e10cSrcweir // ask for dispatch object
249cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > xDispatch = xProvider->queryDispatch(aURL, ::rtl::OUString(), 0);
250cdf0e10cSrcweir sal_Bool bRet = xDispatch.is();
251cdf0e10cSrcweir if ( bRet )
252cdf0e10cSrcweir {
253*2bfcd321SSteve Yin if(::comphelper::UiEventsLogger::isEnabled() && m_xSMGR.is() && m_xDispatcher.is()) //#i88653#
254*2bfcd321SSteve Yin {
255*2bfcd321SSteve Yin try
256*2bfcd321SSteve Yin {
257*2bfcd321SSteve Yin css::uno::Reference< css::frame::XModuleManager > xModuleDetection(
258*2bfcd321SSteve Yin m_xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager")),
259*2bfcd321SSteve Yin css::uno::UNO_QUERY_THROW);
260*2bfcd321SSteve Yin
261*2bfcd321SSteve Yin const ::rtl::OUString sModule = xModuleDetection->identify(m_xDispatcher);
262*2bfcd321SSteve Yin css::uno::Sequence<css::beans::PropertyValue> source;
263*2bfcd321SSteve Yin ::comphelper::UiEventsLogger::appendDispatchOrigin(source, sModule, ::rtl::OUString::createFromAscii("AcceleratorExecute"));
264*2bfcd321SSteve Yin ::comphelper::UiEventsLogger::logDispatch(aURL, source);
265*2bfcd321SSteve Yin }
266*2bfcd321SSteve Yin catch(const css::uno::Exception&)
267*2bfcd321SSteve Yin { }
268*2bfcd321SSteve Yin }
269cdf0e10cSrcweir // Note: Such instance can be used one times only and destroy itself afterwards .-)
270cdf0e10cSrcweir AsyncAccelExec* pExec = AsyncAccelExec::createOnShotInstance(xDispatch, aURL);
271cdf0e10cSrcweir pExec->execAsync();
272cdf0e10cSrcweir }
273cdf0e10cSrcweir
274cdf0e10cSrcweir return bRet;
275cdf0e10cSrcweir }
276cdf0e10cSrcweir
277cdf0e10cSrcweir //-----------------------------------------------
st_VCLKey2AWTKey(const KeyCode & aVCLKey)278cdf0e10cSrcweir css::awt::KeyEvent AcceleratorExecute::st_VCLKey2AWTKey(const KeyCode& aVCLKey)
279cdf0e10cSrcweir {
280cdf0e10cSrcweir css::awt::KeyEvent aAWTKey;
281cdf0e10cSrcweir aAWTKey.Modifiers = 0;
282cdf0e10cSrcweir aAWTKey.KeyCode = (sal_Int16)aVCLKey.GetCode();
283cdf0e10cSrcweir
284cdf0e10cSrcweir if (aVCLKey.IsShift())
285cdf0e10cSrcweir aAWTKey.Modifiers |= css::awt::KeyModifier::SHIFT;
286cdf0e10cSrcweir if (aVCLKey.IsMod1())
287cdf0e10cSrcweir aAWTKey.Modifiers |= css::awt::KeyModifier::MOD1;
288cdf0e10cSrcweir if (aVCLKey.IsMod2())
289cdf0e10cSrcweir aAWTKey.Modifiers |= css::awt::KeyModifier::MOD2;
290cdf0e10cSrcweir if (aVCLKey.IsMod3())
291cdf0e10cSrcweir aAWTKey.Modifiers |= css::awt::KeyModifier::MOD3;
292cdf0e10cSrcweir return aAWTKey;
293cdf0e10cSrcweir }
294cdf0e10cSrcweir
295cdf0e10cSrcweir //-----------------------------------------------
st_AWTKey2VCLKey(const css::awt::KeyEvent & aAWTKey)296cdf0e10cSrcweir KeyCode AcceleratorExecute::st_AWTKey2VCLKey(const css::awt::KeyEvent& aAWTKey)
297cdf0e10cSrcweir {
298cdf0e10cSrcweir sal_Bool bShift = ((aAWTKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT );
299cdf0e10cSrcweir sal_Bool bMod1 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 );
300cdf0e10cSrcweir sal_Bool bMod2 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 );
301cdf0e10cSrcweir sal_Bool bMod3 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 );
302cdf0e10cSrcweir sal_uInt16 nKey = (sal_uInt16)aAWTKey.KeyCode;
303cdf0e10cSrcweir
304cdf0e10cSrcweir return KeyCode(nKey, bShift, bMod1, bMod2, bMod3);
305cdf0e10cSrcweir }
306cdf0e10cSrcweir //-----------------------------------------------
findCommand(const css::awt::KeyEvent & aKey)307cdf0e10cSrcweir ::rtl::OUString AcceleratorExecute::findCommand(const css::awt::KeyEvent& aKey)
308cdf0e10cSrcweir {
309cdf0e10cSrcweir return impl_ts_findCommand(aKey);
310cdf0e10cSrcweir }
311cdf0e10cSrcweir //-----------------------------------------------
impl_ts_findCommand(const css::awt::KeyEvent & aKey)312cdf0e10cSrcweir ::rtl::OUString AcceleratorExecute::impl_ts_findCommand(const css::awt::KeyEvent& aKey)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir // SAFE -> ----------------------------------
315cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
316cdf0e10cSrcweir
317cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > xGlobalCfg = m_xGlobalCfg;
318cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > xModuleCfg = m_xModuleCfg;
319cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > xDocCfg = m_xDocCfg ;
320cdf0e10cSrcweir
321cdf0e10cSrcweir aLock.clear();
322cdf0e10cSrcweir // <- SAFE ----------------------------------
323cdf0e10cSrcweir
324cdf0e10cSrcweir ::rtl::OUString sCommand;
325cdf0e10cSrcweir
326cdf0e10cSrcweir try
327cdf0e10cSrcweir {
328cdf0e10cSrcweir if (xDocCfg.is())
329cdf0e10cSrcweir sCommand = xDocCfg->getCommandByKeyEvent(aKey);
330cdf0e10cSrcweir if (sCommand.getLength())
331cdf0e10cSrcweir return sCommand;
332cdf0e10cSrcweir }
333cdf0e10cSrcweir catch(const css::container::NoSuchElementException&)
334cdf0e10cSrcweir {}
335cdf0e10cSrcweir
336cdf0e10cSrcweir try
337cdf0e10cSrcweir {
338cdf0e10cSrcweir if (xModuleCfg.is())
339cdf0e10cSrcweir sCommand = xModuleCfg->getCommandByKeyEvent(aKey);
340cdf0e10cSrcweir if (sCommand.getLength())
341cdf0e10cSrcweir return sCommand;
342cdf0e10cSrcweir }
343cdf0e10cSrcweir catch(const css::container::NoSuchElementException&)
344cdf0e10cSrcweir {}
345cdf0e10cSrcweir
346cdf0e10cSrcweir try
347cdf0e10cSrcweir {
348cdf0e10cSrcweir if (xGlobalCfg.is())
349cdf0e10cSrcweir sCommand = xGlobalCfg->getCommandByKeyEvent(aKey);
350cdf0e10cSrcweir if (sCommand.getLength())
351cdf0e10cSrcweir return sCommand;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir catch(const css::container::NoSuchElementException&)
354cdf0e10cSrcweir {}
355cdf0e10cSrcweir
356cdf0e10cSrcweir // fall back to functional key codes
357cdf0e10cSrcweir if( aKey.Modifiers == 0 )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir switch( aKey.KeyCode )
360cdf0e10cSrcweir {
361cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_TO_BEGIN_OF_LINE:
362cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:DelToStartOfLine" ) );
363cdf0e10cSrcweir
364cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_TO_END_OF_LINE:
365cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:DelToEndOfLine" ) );
366cdf0e10cSrcweir
367cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_TO_BEGIN_OF_PARAGRAPH:
368cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:DelToStartOfPara" ) );
369cdf0e10cSrcweir
370cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_TO_END_OF_PARAGRAPH:
371cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:DelToEndOfPara" ) );
372cdf0e10cSrcweir
373cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_WORD_BACKWARD:
374cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:DelToStartOfWord" ) );
375cdf0e10cSrcweir
376cdf0e10cSrcweir case com::sun::star::awt::Key::DELETE_WORD_FORWARD:
377cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:DelToEndOfWord" ) );
378cdf0e10cSrcweir
379cdf0e10cSrcweir case com::sun::star::awt::Key::INSERT_LINEBREAK:
380cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:InsertLinebreak" ) );
381cdf0e10cSrcweir
382cdf0e10cSrcweir case com::sun::star::awt::Key::INSERT_PARAGRAPH:
383cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:InsertPara" ) );
384cdf0e10cSrcweir
385cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_WORD_BACKWARD:
386cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToPrevWord" ) );
387cdf0e10cSrcweir
388cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_WORD_FORWARD:
389cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToNextWord" ) );
390cdf0e10cSrcweir
391cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_LINE:
392cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToStartOfLine" ) );
393cdf0e10cSrcweir
394cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_LINE:
395cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToEndOfLine" ) );
396cdf0e10cSrcweir
397cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_PARAGRAPH:
398cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToStartOfPara" ) );
399cdf0e10cSrcweir
400cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_PARAGRAPH:
401cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToEndOfPara" ) );
402cdf0e10cSrcweir
403cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_BEGIN_OF_DOCUMENT:
404cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToStartOfDoc" ) );
405cdf0e10cSrcweir
406cdf0e10cSrcweir case com::sun::star::awt::Key::MOVE_TO_END_OF_DOCUMENT:
407cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GoToEndOfDoc" ) );
408cdf0e10cSrcweir
409cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_BACKWARD:
410cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CharLeftSel" ) );
411cdf0e10cSrcweir
412cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_FORWARD:
413cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CharRightSel" ) );
414cdf0e10cSrcweir
415cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_WORD_BACKWARD:
416cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:WordLeftSel" ) );
417cdf0e10cSrcweir
418cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_WORD_FORWARD:
419cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:WordRightSel" ) );
420cdf0e10cSrcweir
421cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_WORD:
422cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SelectWord" ) );
423cdf0e10cSrcweir
424cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_LINE:
425cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "" ) );
426cdf0e10cSrcweir
427cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_PARAGRAPH:
428cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SelectText" ) );
429cdf0e10cSrcweir
430cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_LINE:
431cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StartOfLineSel" ) );
432cdf0e10cSrcweir
433cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_LINE:
434cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:EndOfLineSel" ) );
435cdf0e10cSrcweir
436cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_PARAGRAPH:
437cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StartOfParaSel" ) );
438cdf0e10cSrcweir
439cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_PARAGRAPH:
440cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:EndOfParaSel" ) );
441cdf0e10cSrcweir
442cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_BEGIN_OF_DOCUMENT:
443cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StartOfDocumentSel" ) );
444cdf0e10cSrcweir
445cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_TO_END_OF_DOCUMENT:
446cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:EndOfDocumentSel" ) );
447cdf0e10cSrcweir
448cdf0e10cSrcweir case com::sun::star::awt::Key::SELECT_ALL:
449cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SelectAll" ) );
450cdf0e10cSrcweir default:
451cdf0e10cSrcweir break;
452cdf0e10cSrcweir }
453cdf0e10cSrcweir }
454cdf0e10cSrcweir
455cdf0e10cSrcweir return ::rtl::OUString();
456cdf0e10cSrcweir }
457cdf0e10cSrcweir
458cdf0e10cSrcweir //-----------------------------------------------
st_openGlobalConfig(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)459cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > AcceleratorExecute::st_openGlobalConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
460cdf0e10cSrcweir {
461cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > xAccCfg(
462cdf0e10cSrcweir xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.ui.GlobalAcceleratorConfiguration")),
463cdf0e10cSrcweir css::uno::UNO_QUERY_THROW);
464cdf0e10cSrcweir return xAccCfg;
465cdf0e10cSrcweir }
466cdf0e10cSrcweir
467cdf0e10cSrcweir //-----------------------------------------------
st_openModuleConfig(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR,const css::uno::Reference<css::frame::XFrame> & xFrame)468cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > AcceleratorExecute::st_openModuleConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
469cdf0e10cSrcweir const css::uno::Reference< css::frame::XFrame >& xFrame)
470cdf0e10cSrcweir {
471cdf0e10cSrcweir css::uno::Reference< css::frame::XModuleManager > xModuleDetection(
472cdf0e10cSrcweir xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager")),
473cdf0e10cSrcweir css::uno::UNO_QUERY_THROW);
474cdf0e10cSrcweir
475cdf0e10cSrcweir ::rtl::OUString sModule;
476cdf0e10cSrcweir try
477cdf0e10cSrcweir {
478cdf0e10cSrcweir sModule = xModuleDetection->identify(xFrame);
479cdf0e10cSrcweir }
480cdf0e10cSrcweir catch(const css::uno::RuntimeException&rEx)
481cdf0e10cSrcweir { (void) rEx; throw; }
482cdf0e10cSrcweir catch(const css::uno::Exception&)
483cdf0e10cSrcweir { return css::uno::Reference< css::ui::XAcceleratorConfiguration >(); }
484cdf0e10cSrcweir
485cdf0e10cSrcweir css::uno::Reference< css::ui::XModuleUIConfigurationManagerSupplier > xUISupplier(
486cdf0e10cSrcweir xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")),
487cdf0e10cSrcweir css::uno::UNO_QUERY_THROW);
488cdf0e10cSrcweir
489cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > xAccCfg;
490cdf0e10cSrcweir try
491cdf0e10cSrcweir {
492cdf0e10cSrcweir css::uno::Reference< css::ui::XUIConfigurationManager > xUIManager = xUISupplier->getUIConfigurationManager(sModule);
493cdf0e10cSrcweir xAccCfg = css::uno::Reference< css::ui::XAcceleratorConfiguration >(xUIManager->getShortCutManager(), css::uno::UNO_QUERY_THROW);
494cdf0e10cSrcweir }
495cdf0e10cSrcweir catch(const css::container::NoSuchElementException&)
496cdf0e10cSrcweir {}
497cdf0e10cSrcweir return xAccCfg;
498cdf0e10cSrcweir }
499cdf0e10cSrcweir
500cdf0e10cSrcweir //-----------------------------------------------
st_openDocConfig(const css::uno::Reference<css::frame::XModel> & xModel)501cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > AcceleratorExecute::st_openDocConfig(const css::uno::Reference< css::frame::XModel >& xModel)
502cdf0e10cSrcweir {
503cdf0e10cSrcweir css::uno::Reference< css::ui::XAcceleratorConfiguration > xAccCfg;
504cdf0e10cSrcweir css::uno::Reference< css::ui::XUIConfigurationManagerSupplier > xUISupplier(xModel, css::uno::UNO_QUERY);
505cdf0e10cSrcweir if (xUISupplier.is())
506cdf0e10cSrcweir {
507cdf0e10cSrcweir css::uno::Reference< css::ui::XUIConfigurationManager > xUIManager = xUISupplier->getUIConfigurationManager();
508cdf0e10cSrcweir xAccCfg.set(xUIManager->getShortCutManager(), css::uno::UNO_QUERY_THROW);
509cdf0e10cSrcweir }
510cdf0e10cSrcweir return xAccCfg;
511cdf0e10cSrcweir }
512cdf0e10cSrcweir
513cdf0e10cSrcweir //-----------------------------------------------
impl_ts_getURLParser()514cdf0e10cSrcweir css::uno::Reference< css::util::XURLTransformer > AcceleratorExecute::impl_ts_getURLParser()
515cdf0e10cSrcweir {
516cdf0e10cSrcweir // SAFE -> ----------------------------------
517cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
518cdf0e10cSrcweir
519cdf0e10cSrcweir if (m_xURLParser.is())
520cdf0e10cSrcweir return m_xURLParser;
521cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
522cdf0e10cSrcweir
523cdf0e10cSrcweir aLock.clear();
524cdf0e10cSrcweir // <- SAFE ----------------------------------
525cdf0e10cSrcweir
526cdf0e10cSrcweir css::uno::Reference< css::util::XURLTransformer > xParser(
527cdf0e10cSrcweir xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer")),
528cdf0e10cSrcweir css::uno::UNO_QUERY_THROW);
529cdf0e10cSrcweir
530cdf0e10cSrcweir // SAFE -> ----------------------------------
531cdf0e10cSrcweir aLock.reset();
532cdf0e10cSrcweir m_xURLParser = xParser;
533cdf0e10cSrcweir aLock.clear();
534cdf0e10cSrcweir // <- SAFE ----------------------------------
535cdf0e10cSrcweir
536cdf0e10cSrcweir return xParser;
537cdf0e10cSrcweir }
538cdf0e10cSrcweir
539cdf0e10cSrcweir //-----------------------------------------------
IMPL_LINK(AcceleratorExecute,impl_ts_asyncCallback,void *,EMPTYARG)540cdf0e10cSrcweir IMPL_LINK(AcceleratorExecute, impl_ts_asyncCallback, void*, EMPTYARG)
541cdf0e10cSrcweir {
542cdf0e10cSrcweir // replaced by AsyncAccelExec!
543cdf0e10cSrcweir return 0;
544cdf0e10cSrcweir }
545cdf0e10cSrcweir
546cdf0e10cSrcweir //-----------------------------------------------
AsyncAccelExec(const css::uno::Reference<css::frame::XDispatch> & xDispatch,const css::util::URL & aURL)547cdf0e10cSrcweir AsyncAccelExec::AsyncAccelExec(const css::uno::Reference< css::frame::XDispatch >& xDispatch,
548cdf0e10cSrcweir const css::util::URL& aURL )
549cdf0e10cSrcweir : m_aAsyncCallback(LINK(this, AsyncAccelExec, impl_ts_asyncCallback))
550cdf0e10cSrcweir , m_xDispatch (xDispatch )
551cdf0e10cSrcweir , m_aURL (aURL )
552cdf0e10cSrcweir {
553cdf0e10cSrcweir }
554cdf0e10cSrcweir
555cdf0e10cSrcweir //-----------------------------------------------
createOnShotInstance(const css::uno::Reference<css::frame::XDispatch> & xDispatch,const css::util::URL & aURL)556cdf0e10cSrcweir AsyncAccelExec* AsyncAccelExec::createOnShotInstance(const css::uno::Reference< css::frame::XDispatch >& xDispatch,
557cdf0e10cSrcweir const css::util::URL& aURL )
558cdf0e10cSrcweir {
559cdf0e10cSrcweir AsyncAccelExec* pExec = new AsyncAccelExec(xDispatch, aURL);
560cdf0e10cSrcweir return pExec;
561cdf0e10cSrcweir }
562cdf0e10cSrcweir
563cdf0e10cSrcweir //-----------------------------------------------
execAsync()564cdf0e10cSrcweir void AsyncAccelExec::execAsync()
565cdf0e10cSrcweir {
566cdf0e10cSrcweir m_aAsyncCallback.Post(0);
567cdf0e10cSrcweir }
568cdf0e10cSrcweir
569cdf0e10cSrcweir //-----------------------------------------------
570cdf0e10cSrcweir IMPL_LINK(AsyncAccelExec, impl_ts_asyncCallback, void*,)
571cdf0e10cSrcweir {
572cdf0e10cSrcweir if (! m_xDispatch.is())
573cdf0e10cSrcweir return 0;
574cdf0e10cSrcweir
575cdf0e10cSrcweir try
576cdf0e10cSrcweir {
577cdf0e10cSrcweir m_xDispatch->dispatch(m_aURL, css::uno::Sequence< css::beans::PropertyValue >());
578cdf0e10cSrcweir }
579cdf0e10cSrcweir catch(const css::lang::DisposedException&)
580cdf0e10cSrcweir {}
581cdf0e10cSrcweir catch(const css::uno::RuntimeException& )
582cdf0e10cSrcweir { throw; }
583cdf0e10cSrcweir catch(const css::uno::Exception&)
584cdf0e10cSrcweir {}
585cdf0e10cSrcweir
586cdf0e10cSrcweir delete this;
587cdf0e10cSrcweir
588cdf0e10cSrcweir return 0;
589cdf0e10cSrcweir }
590cdf0e10cSrcweir
591cdf0e10cSrcweir } // namespace svt
592