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